VirtualBox

source: vbox/trunk/include/VBox/SUPR0StackWrapper.mac@ 91780

Last change on this file since 91780 was 91780, checked in by vboxsync, 4 years ago

SUPDrv/darwin: Another build fix for the switch-back-to-kernel-stack change. [scm] bugref:10124

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1; $Id: SUPR0StackWrapper.mac 91780 2021-10-17 11:13:41Z vboxsync $
2;; @file
3; SUP - Support Library, ring-0 stack switching wrappers.
4;
5
6;
7; Copyright (C) 2006-2021 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; The contents of this file may alternatively be used under the terms
18; of the Common Development and Distribution License Version 1.0
19; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20; VirtualBox OSE distribution, in which case the provisions of the
21; CDDL are applicable instead of those of the GPL.
22;
23; You may elect to license modified versions of this file under the
24; terms and conditions of either the GPL or the CDDL or both.
25;
26
27%ifndef ___VBox_SUPR0StackWrapper_mac
28%define ___VBox_SUPR0StackWrapper_mac
29
30%include "VBox/asmdefs.mac"
31
32;; VBox's own Stack
33%define SUPR0STACKINFO_MAGIC0 0786f4256h ; VBox
34%define SUPR0STACKINFO_MAGIC1 06f207327h ; 's o
35%define SUPR0STACKINFO_MAGIC2 053206e77h ; wn S
36%define SUPR0STACKINFO_MAGIC3 06b636174h ; tack
37
38;;
39; Stack info located before the start of the stack, at the top of the page.
40;
41struc SUPR0STACKINFO
42 .magic0 resd 1
43 .magic1 resd 1
44 .magic2 resd 1
45 .magic3 resd 1
46 .pResumeKernelStack resq 1
47 .pSelf resq 1
48endstruc
49
50;;
51; Generic stack switching wrapper.
52;
53; This supports up to 16 arguments on the stack in addition to the 6 GPR
54; and 6 FPR arguments, which should be enough for most functions, even
55; RTLogCreateExV.
56;
57%macro SUPR0StackWrapperGeneric 1
58BEGINCODE
59extern NAME(StkBack_ %+ %1)
60
61BEGINPROC %1
62 ;
63 ; Check for the stack info.
64 ;
65 mov rax, rsp
66 or rax, 0fffh
67 sub rax, SUPR0STACKINFO_size - 1
68
69 ; Check for the magic.
70 cmp dword [rax + SUPR0STACKINFO.magic0], SUPR0STACKINFO_MAGIC0
71 jne .regular
72 cmp dword [rax + SUPR0STACKINFO.magic1], SUPR0STACKINFO_MAGIC1
73 jne .regular
74 cmp dword [rax + SUPR0STACKINFO.magic2], SUPR0STACKINFO_MAGIC2
75 jne .regular
76 cmp dword [rax + SUPR0STACKINFO.magic3], SUPR0STACKINFO_MAGIC3
77 jne .regular
78
79 ; Verify the self pointer.
80 cmp [rax + SUPR0STACKINFO.pSelf], rax
81 jne .regular
82
83 ;
84 ; Perform a stack switch. We set up a RBP frame on the old stack so we
85 ; can use leave to restore the incoming stack upon return.
86 ;
87 push rbp
88 mov rbp, rsp
89
90 ; The actual switch.
91 mov r10, 0ffffffffffffffe0h ; shuts up warning on 'and rsp, 0ffffffffffffffe0h'
92 and r10, [rax + SUPR0STACKINFO.pResumeKernelStack]
93 mov rsp, r10
94
95 ;
96 ; Copy over 16 stack arguments (128 bytes).
97 ;
98 ; We kind of ASSUME no function takes more arguments than that, and we ASSUME
99 ; the code setting up the info makes sure rbp+88h won't underflow the stack.
100 ;
101
102 push qword [rbp + 88h]
103 push qword [rbp + 80h]
104 push qword [rbp + 78h]
105 push qword [rbp + 70h]
106 push qword [rbp + 68h]
107 push qword [rbp + 60h]
108 push qword [rbp + 58h]
109 push qword [rbp + 50h]
110 push qword [rbp + 48h]
111 push qword [rbp + 40h]
112 push qword [rbp + 38h]
113 push qword [rbp + 30h]
114 push qword [rbp + 28h]
115 push qword [rbp + 20h]
116 push qword [rbp + 18h]
117 push qword [rbp + 10h]
118
119 call NAME(StkBack_ %+ %1)
120
121 leave
122 ret
123
124.regular:
125 jmp NAME(StkBack_ %+ %1)
126ENDPROC %1
127%endmacro
128
129
130%endif
131
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette