1 | ; $Id: NEMR0NativeA-win.asm 91676 2021-10-11 20:46:03Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; NEM/win - Ring-0 Assembly Routines.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 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 |
|
---|
18 |
|
---|
19 | ;*******************************************************************************
|
---|
20 | ;* Header Files *
|
---|
21 | ;*******************************************************************************
|
---|
22 | %define RT_ASM_WITH_SEH64
|
---|
23 | %include "iprt/asmdefs.mac"
|
---|
24 |
|
---|
25 |
|
---|
26 | ;*********************************************************************************************************************************
|
---|
27 | ;* External Symbols *
|
---|
28 | ;*********************************************************************************************************************************
|
---|
29 | BEGINDATA
|
---|
30 | extern NAME(g_pfnWinHvGetPartitionProperty)
|
---|
31 | extern NAME(g_idVidSysFoundPartition)
|
---|
32 | extern NAME(g_hVidSysMatchThread)
|
---|
33 | extern NAME(g_enmVidSysMatchProperty)
|
---|
34 | ;extern NAME(g_pfnHvrWinHvGetPartitionPropertyLeadIn)
|
---|
35 |
|
---|
36 | BEGINCODE
|
---|
37 | extern NAME(RTThreadNativeSelf)
|
---|
38 |
|
---|
39 |
|
---|
40 | ;;
|
---|
41 | ; This is a replacement for WinHvGetPartitionProperty that we slot into VID.SYS's
|
---|
42 | ; import table so we can fish out the partition ID (first parameter).
|
---|
43 | ;
|
---|
44 | BEGINPROC nemR0VidSysWinHvGetPartitionProperty
|
---|
45 | ;
|
---|
46 | ; Code is shared with nemR0WinHvrWinHvGetPartitionProperty.
|
---|
47 | ;
|
---|
48 | %macro WinHvGetPartitionPropertyHookBody 0
|
---|
49 | ;
|
---|
50 | ; Create a frame and save all volatile registers.
|
---|
51 | ;
|
---|
52 | push xBP
|
---|
53 | SEH64_PUSH_xBP
|
---|
54 | mov xBP, xSP
|
---|
55 | SEH64_SET_FRAME_xBP 0
|
---|
56 | sub xSP, 0x100+0x20
|
---|
57 | SEH64_ALLOCATE_STACK 0x100+0x20
|
---|
58 | movdqa [rbp - 10h], xmm0
|
---|
59 | movdqa [rbp - 20h], xmm1
|
---|
60 | movdqa [rbp - 30h], xmm2
|
---|
61 | movdqa [rbp - 40h], xmm3
|
---|
62 | movdqa [rbp - 50h], xmm4
|
---|
63 | movdqa [rbp - 60h], xmm5
|
---|
64 | mov [rbp - 70h], rcx
|
---|
65 | mov [rbp - 78h], rdx
|
---|
66 | mov [rbp - 80h], r8
|
---|
67 | mov [rbp - 88h], r9
|
---|
68 | mov [rbp - 90h], r10
|
---|
69 | mov [rbp - 98h], r11
|
---|
70 | SEH64_END_PROLOGUE
|
---|
71 |
|
---|
72 | ;
|
---|
73 | ; Check if the property matches the one we're querying
|
---|
74 | ;
|
---|
75 | cmp edx, [NAME(g_enmVidSysMatchProperty) wrt rip] ; It is really 32-bit.
|
---|
76 | jne .return
|
---|
77 |
|
---|
78 | ;
|
---|
79 | ; Get the current thread and compare that to g_hVidSysTargetThread,
|
---|
80 | ; making sure it's not NULL or NIL.
|
---|
81 | ;
|
---|
82 | call NAME(RTThreadNativeSelf)
|
---|
83 | or rax, rax ; check that it isn't zero.
|
---|
84 | jz .return
|
---|
85 |
|
---|
86 | cmp rax, [NAME(g_hVidSysMatchThread) wrt rip]
|
---|
87 | jne .return
|
---|
88 |
|
---|
89 | inc rax ; check for ~0.
|
---|
90 | jz .return
|
---|
91 |
|
---|
92 | ;
|
---|
93 | ; Got a match, save the partition ID.
|
---|
94 | ;
|
---|
95 | mov rcx, [rbp - 70h]
|
---|
96 | mov [NAME(g_idVidSysFoundPartition) wrt rip], rcx
|
---|
97 |
|
---|
98 | ;
|
---|
99 | ; Restore the volatile registers.
|
---|
100 | ;
|
---|
101 | .return:
|
---|
102 | movdqa xmm0, [rbp - 10h]
|
---|
103 | movdqa xmm1, [rbp - 20h]
|
---|
104 | movdqa xmm2, [rbp - 30h]
|
---|
105 | movdqa xmm3, [rbp - 40h]
|
---|
106 | movdqa xmm4, [rbp - 50h]
|
---|
107 | movdqa xmm5, [rbp - 60h]
|
---|
108 | mov rcx, [rbp - 70h]
|
---|
109 | mov rdx, [rbp - 78h]
|
---|
110 | mov r8, [rbp - 80h]
|
---|
111 | mov r9, [rbp - 88h]
|
---|
112 | mov r10, [rbp - 90h]
|
---|
113 | mov r11, [rbp - 98h]
|
---|
114 | leave
|
---|
115 | %endmacro
|
---|
116 |
|
---|
117 | ;
|
---|
118 | ; Identical to nemR0WinHvrWinHvGetPartitionProperty except for the
|
---|
119 | ; resuming of the real code.
|
---|
120 | ;
|
---|
121 | WinHvGetPartitionPropertyHookBody
|
---|
122 |
|
---|
123 | ;
|
---|
124 | ; Instead of returning, jump to the real WinHvGetPartitionProperty code.
|
---|
125 | ;
|
---|
126 | mov rax, [NAME(g_pfnWinHvGetPartitionProperty) wrt rip]
|
---|
127 | jmp rax
|
---|
128 | ENDPROC nemR0VidSysWinHvGetPartitionProperty
|
---|
129 |
|
---|
130 |
|
---|
131 | section .textrwx code page execute read write
|
---|
132 |
|
---|
133 | ;;
|
---|
134 | ; This is where we jump to from a WinHvr.sys jmp patch.
|
---|
135 | ;
|
---|
136 | ; This is used if the import table patching doesn't work because the indirect
|
---|
137 | ; call was converted into a direct call by the the retpoline patching code.
|
---|
138 | ;
|
---|
139 | ALIGNCODE(16)
|
---|
140 | BEGINPROC nemR0WinHvrWinHvGetPartitionProperty
|
---|
141 |
|
---|
142 | ;
|
---|
143 | ; Identical to nemR0VidSysWinHvGetPartitionProperty except for the
|
---|
144 | ; resuming of the real code.
|
---|
145 | ;
|
---|
146 | WinHvGetPartitionPropertyHookBody
|
---|
147 |
|
---|
148 | ;
|
---|
149 | ; Now back to the orignal code.
|
---|
150 | ;
|
---|
151 | ; We reserve 64 bytes of space for the lead-in code that we replaced
|
---|
152 | ; from WinHvGetPartitionProperty and additional 12 for the jump back.
|
---|
153 | ;
|
---|
154 | GLOBALNAME g_abNemR0WinHvrWinHvGetPartitionProperty_OriginalProlog
|
---|
155 | times 64 int3 ; IMPORTANT! Must be at least as big as the 'Org' variable in the C code.
|
---|
156 | mov rax, 01234567890abcdefh
|
---|
157 | jmp rax
|
---|
158 | ENDPROC nemR0WinHvrWinHvGetPartitionProperty
|
---|
159 |
|
---|