1 | ; $Id: SUPR0StackWrapper.mac 91784 2021-10-17 12:28:07Z 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 | ;
|
---|
41 | struc 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
|
---|
48 | endstruc
|
---|
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
|
---|
58 | BEGINCODE
|
---|
59 | extern NAME(StkBack_ %+ %1)
|
---|
60 |
|
---|
61 | BEGINPROC %1
|
---|
62 | %ifdef RT_ARCH_AMD64 ; Only for amd64 for now.
|
---|
63 | ;
|
---|
64 | ; Check for the stack info.
|
---|
65 | ;
|
---|
66 | mov rax, rsp
|
---|
67 | or rax, 0fffh
|
---|
68 | sub rax, SUPR0STACKINFO_size - 1
|
---|
69 |
|
---|
70 | ; Check for the magic.
|
---|
71 | cmp dword [rax + SUPR0STACKINFO.magic0], SUPR0STACKINFO_MAGIC0
|
---|
72 | jne .regular
|
---|
73 | cmp dword [rax + SUPR0STACKINFO.magic1], SUPR0STACKINFO_MAGIC1
|
---|
74 | jne .regular
|
---|
75 | cmp dword [rax + SUPR0STACKINFO.magic2], SUPR0STACKINFO_MAGIC2
|
---|
76 | jne .regular
|
---|
77 | cmp dword [rax + SUPR0STACKINFO.magic3], SUPR0STACKINFO_MAGIC3
|
---|
78 | jne .regular
|
---|
79 |
|
---|
80 | ; Verify the self pointer.
|
---|
81 | cmp [rax + SUPR0STACKINFO.pSelf], rax
|
---|
82 | jne .regular
|
---|
83 |
|
---|
84 | ;
|
---|
85 | ; Perform a stack switch. We set up a RBP frame on the old stack so we
|
---|
86 | ; can use leave to restore the incoming stack upon return.
|
---|
87 | ;
|
---|
88 | push rbp
|
---|
89 | mov rbp, rsp
|
---|
90 |
|
---|
91 | ; The actual switch.
|
---|
92 | mov r10, 0ffffffffffffffe0h ; shuts up warning on 'and rsp, 0ffffffffffffffe0h'
|
---|
93 | and r10, [rax + SUPR0STACKINFO.pResumeKernelStack]
|
---|
94 | mov rsp, r10
|
---|
95 |
|
---|
96 | ;
|
---|
97 | ; Copy over 16 stack arguments (128 bytes).
|
---|
98 | ;
|
---|
99 | ; We kind of ASSUME no function takes more arguments than that, and we ASSUME
|
---|
100 | ; the code setting up the info makes sure rbp+88h won't underflow the stack.
|
---|
101 | ;
|
---|
102 |
|
---|
103 | push qword [rbp + 88h]
|
---|
104 | push qword [rbp + 80h]
|
---|
105 | push qword [rbp + 78h]
|
---|
106 | push qword [rbp + 70h]
|
---|
107 | push qword [rbp + 68h]
|
---|
108 | push qword [rbp + 60h]
|
---|
109 | push qword [rbp + 58h]
|
---|
110 | push qword [rbp + 50h]
|
---|
111 | push qword [rbp + 48h]
|
---|
112 | push qword [rbp + 40h]
|
---|
113 | push qword [rbp + 38h]
|
---|
114 | push qword [rbp + 30h]
|
---|
115 | push qword [rbp + 28h]
|
---|
116 | push qword [rbp + 20h]
|
---|
117 | push qword [rbp + 18h]
|
---|
118 | push qword [rbp + 10h]
|
---|
119 |
|
---|
120 | call NAME(StkBack_ %+ %1)
|
---|
121 |
|
---|
122 | leave
|
---|
123 | ret
|
---|
124 |
|
---|
125 | .regular:
|
---|
126 | %endif ; RT_ARCH_AMD64
|
---|
127 | jmp NAME(StkBack_ %+ %1)
|
---|
128 | ENDPROC %1
|
---|
129 | %endmacro
|
---|
130 |
|
---|
131 |
|
---|
132 | %endif
|
---|
133 |
|
---|