VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm@ 52943

最後變更 在這個檔案從52943是 52943,由 vboxsync 提交於 10 年 前

SUP: The child side of early VM process init.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.0 KB
 
1; $Id: SUPR3HardenedMainA-win.asm 52943 2014-10-04 01:54:58Z vboxsync $
2;; @file
3; VirtualBox Support Library - Hardened main(), Windows assembly bits.
4;
5
6;
7; Copyright (C) 2012-2014 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.alldomusa.eu.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;*******************************************************************************
28;* Header Files *
29;*******************************************************************************
30%define RT_ASM_WITH_SEH64
31%include "iprt/asmdefs.mac"
32
33
34; External data.
35extern NAME(g_pfnNtCreateSectionJmpBack)
36
37; External code.
38extern NAME(supR3HardenedVmProcessInit)
39
40
41BEGINCODE
42
43;
44; 64-bit
45;
46%ifdef RT_ARCH_AMD64
47 %macro supR3HardenedJmpBack_NtCreateSection_Xxx 1
48 BEGINPROC supR3HardenedJmpBack_NtCreateSection_ %+ %1
49 SEH64_END_PROLOGUE
50 ; The code we replaced.
51 mov r10, rcx
52 mov eax, %1
53
54 ; Jump back to the original code.
55 jmp [NAME(g_pfnNtCreateSectionJmpBack) wrt RIP]
56 ENDPROC supR3HardenedJmpBack_NtCreateSection_ %+ %1
57 %endm
58 %define SYSCALL(a_Num) supR3HardenedJmpBack_NtCreateSection_Xxx a_Num
59 %include "NtCreateSection-template-amd64-syscall-type-1.h"
60
61%endif
62
63
64;
65; 32-bit.
66;
67%ifdef RT_ARCH_X86
68 %macro supR3HardenedJmpBack_NtCreateSection_Xxx 1
69 BEGINPROC supR3HardenedJmpBack_NtCreateSection_ %+ %1
70 ; The code we replaced.
71 mov eax, %1
72
73 ; Jump back to the original code.
74 jmp [NAME(g_pfnNtCreateSectionJmpBack)]
75 ENDPROC supR3HardenedJmpBack_NtCreateSection_ %+ %1
76 %endm
77 %define SYSCALL(a_Num) supR3HardenedJmpBack_NtCreateSection_Xxx a_Num
78 %include "NtCreateSection-template-x86-syscall-type-1.h"
79
80%endif
81
82
83
84;;
85; Alternative code for LdrInitializeThunk that performs the VM process startup.
86;
87; This does not concern itself with any arguments on stack or in registers that
88; may be passed to the LdrIntializeThunk routine as we just save and restore
89; them all before we restart the restored LdrInitializeThunk routine.
90;
91BEGINPROC supR3HardenedVmProcessInitThunk
92 ;
93 ; Prologue.
94 ;
95
96 ; Reserve space for the "return" address.
97 push 0
98
99 ; Create a stack frame, saving xBP.
100 push xBP
101 SEH64_PUSH_xBP
102 mov xBP, xSP
103 SEH64_SET_FRAME_xBP 0 ; probably wrong...
104
105 ; Save all volatile registers.
106 push xAX
107 push xCX
108 push xDX
109%ifdef RT_ARCH_AMD64
110 push r8
111 push r9
112 push r10
113 push r11
114%endif
115
116 ; Reserve spill space and align the stack.
117 sub xSP, 20h
118 and xSP, ~0fh
119 SEH64_END_PROLOGUE
120
121 ;
122 ; Call the C/C++ code that does the actual work. This returns the
123 ; resume address in xAX, which we put in the "return" stack position.
124 ;
125 call NAME(supR3HardenedVmProcessInit)
126 mov [xBP + xCB], xAX
127
128 ;
129 ; Restore volatile registers.
130 ;
131 mov xAX, [xBP - xCB*1]
132 mov xCX, [xBP - xCB*2]
133 mov xDX, [xBP - xCB*3]
134%ifdef RT_ARCH_AMD64
135 mov r8, [xBP - xCB*4]
136 mov r9, [xBP - xCB*5]
137 mov r10, [xBP - xCB*6]
138 mov r11, [xBP - xCB*7]
139%endif
140 ;
141 ; Use the leave instruction to restore xBP and set up xSP to point at
142 ; the resume address. Then use the 'ret' instruction to resume process
143 ; initializaton.
144 ;
145 leave
146 ret
147ENDPROC supR3HardenedVmProcessInitThunk
148
149
150
151;;
152; Composes a standard call name.
153%ifdef RT_ARCH_X86
154 %define SUPHNTIMP_STDCALL_NAME(a,b) _ %+ a %+ @ %+ b
155%else
156 %define SUPHNTIMP_STDCALL_NAME(a,b) NAME(a)
157%endif
158
159
160;;
161; Import data and code for an API call.
162;
163; @param 1 The plain API name.
164; @param 2 The parameter frame size on x86. Multiple of dword.
165; @param 3 Non-zero expression if system call.
166; @param 4 Non-zero expression if early available call
167;
168%define SUPHNTIMP_SYSCALL 1
169%macro SupHardNtImport 4
170 ;
171 ; The data.
172 ;
173BEGINDATA
174global __imp_ %+ SUPHNTIMP_STDCALL_NAME(%1,%2) ; The import name used via dllimport.
175__imp_ %+ SUPHNTIMP_STDCALL_NAME(%1,%2):
176GLOBALNAME g_pfn %+ %1 ; The name we like to refer to.
177 RTCCPTR_DEF 0
178%if %3
179GLOBALNAME g_uApiNo %+ %1
180 RTCCPTR_DEF 0
181%endif
182
183 ;
184 ; The code: First a call stub.
185 ;
186BEGINCODE
187global SUPHNTIMP_STDCALL_NAME(%1, %2)
188SUPHNTIMP_STDCALL_NAME(%1, %2):
189 jmp RTCCPTR_PRE [NAME(g_pfn %+ %1) xWrtRIP]
190
191%if %3
192 ;
193 ; Make system calls.
194 ;
195 %ifdef RT_ARCH_AMD64
196BEGINPROC %1 %+ _SyscallType1
197 SEH64_END_PROLOGUE
198 mov eax, [NAME(g_uApiNo %+ %1) xWrtRIP]
199 mov r10, rcx
200 syscall
201 ret
202ENDPROC %1 %+ _SyscallType1
203 %else
204BEGINPROC %1 %+ _SyscallType1
205 mov edx, 07ffe0300h ; SharedUserData!SystemCallStub
206 mov eax, [NAME(g_uApiNo %+ %1) xWrtRIP]
207 call dword [edx]
208 ret %2
209ENDPROC %1 %+ _SyscallType1
210BEGINPROC %1 %+ _SyscallType2
211 push .return
212 mov edx, esp
213 mov eax, [NAME(g_uApiNo %+ %1) xWrtRIP]
214 sysenter
215 add esp, 4
216.return:
217 ret %2
218ENDPROC %1 %+ _SyscallType2
219 %endif
220%endif
221
222%if %4 == 0
223global SUPHNTIMP_STDCALL_NAME(%1, %2) %+ _Early
224SUPHNTIMP_STDCALL_NAME(%1, %2) %+ _Early:
225 int3
226 %ifdef RT_ARCH_AMD64
227 ret
228 %else
229 ret %2
230 %endif
231%endif
232%endmacro
233
234%define SUPHARNT_COMMENT(a_Comment)
235%define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, SUPHNTIMP_SYSCALL, 1
236%define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, 0, 0
237%define SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, 0, 1
238%define SUPHARNT_IMPORT_STDCALL_EARLY_OPTIONAL(a_Name, a_cbParamsX86) SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86)
239%include "import-template-ntdll.h"
240%include "import-template-kernel32.h"
241
242
243;
244; For simplified LdrLoadDll patching we define a special writable, readable and
245; exectuable section of 4KB where we can put jump back code.
246;
247section .rwxpg bss execute read write align=4096
248GLOBALNAME g_abSupHardReadWriteExecPage
249 resb 4096
250
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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