VirtualBox

source: vbox/trunk/src/recompiler/new/VBoxREMWrapper.cpp@ 88

最後變更 在這個檔案從88是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:keywords 設為 Id
檔案大小: 89.2 KB
 
1/* $Id: VBoxREMWrapper.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 *
4 * VBoxREM Win64 DLL Wrapper.
5 *
6 * InnoTek Systemberatung GmbH confidential
7 *
8 * Copyright (c) 2006 InnoTek Systemberatung GmbH
9 *
10 * Author: knut st. osmundsen <[email protected]>
11 *
12 * All Rights Reserved
13 *
14 */
15
16
17/** @page pg_vboxrem_amd64 VBoxREM Hacks on AMD64
18 *
19 * There are problems with building BoxREM both on WIN64 and 64-bit linux.
20 *
21 * On linux binutils refuses to link shared objects without -fPIC compiled code
22 * (bitches about some fixup types). But when trying to build with -fPIC dyngen
23 * doesn't like the code anymore. Sweet. The current solution is to build the
24 * VBoxREM code as a relocatable module and use our ELF loader to load it.
25 *
26 * On WIN64 we're not aware of any GCC port which can emit code using the MSC
27 * calling convention. So, we're in for some real fun here. The choice is between
28 * porting GCC to AMD64 WIN64 and comming up with some kind of wrapper around
29 * either the win32 build or the 64-bit linux build.
30 *
31 * -# Porting GCC will be a lot of work. For one thing the calling convention differs
32 * and messing with such stuff can easily create ugly bugs. We would also have to
33 * do some binutils changes, but I think those are rather small compared to GCC.
34 * (That said, the MSC calling convention is far simpler than the linux one, it
35 * reminds me of _Optlink which we have working already.)
36 * -# Wrapping win32 code will work, but addresses outside the first 4GB are
37 * inaccessible and we will have to create 32-64 thunks for all imported functions.
38 * (To switch between 32-bit and 64-bit is load the right CS using far jmps (32->64)
39 * or far returns (both).)
40 * -# Wrapping 64-bit linux code might be the easier solution. The requirements here
41 * are:
42 * - Remove all CRT references we possibly, either by using intrinsics or using
43 * IPRT. Part of IPRT will be linked into VBoxREM2.rel, this will be yet another
44 * IPRT mode which I've dubbed 'no-crt'. The no-crt mode provide basic non-system
45 * dependent stuff.
46 * - Compile and link it into a relocatable object (include the gcc intrinsics
47 * in libgcc). Call this VBoxREM2.rel.
48 * - Write a wrapper dll, VBoxREM.dll, for which during REMR3Init() will load
49 * VBoxREM2.rel (using IPRT) and generate calling convention wrappers
50 * for all IPRT functions and VBoxVMM functions that it uses. All exports
51 * will be wrapped vice versa.
52 * - For building on windows hosts, we will use a mingw32 hosted cross compiler.
53 * and add a 'no-crt' mode to IPRT where it provides the necessary CRT headers
54 * and function implementations.
55 *
56 * The 3rd solution will be tried out first since it requires the least effort and
57 * will let us make use of the full 64-bit register set.
58 *
59 *
60 *
61 * @section sec_vboxrem_amd64_compare Comparing the GCC and MSC calling conventions
62 *
63 * GCC expects the following (cut & past from page 20 in the ABI draft 0.96):
64 *
65 * %rax temporary register; with variable arguments passes information about the
66 * number of SSE registers used; 1st return register.
67 * [Not preserved]
68 * %rbx callee-saved register; optionally used as base pointer.
69 * [Preserved]
70 * %rcx used to pass 4th integer argument to functions.
71 * [Not preserved]
72 * %rdx used to pass 3rd argument to functions; 2nd return register
73 * [Not preserved]
74 * %rsp stack pointer
75 * [Preserved]
76 * %rbp callee-saved register; optionally used as frame pointer
77 * [Preserved]
78 * %rsi used to pass 2nd argument to functions
79 * [Not preserved]
80 * %rdi used to pass 1st argument to functions
81 * [Not preserved]
82 * %r8 used to pass 5th argument to functions
83 * [Not preserved]
84 * %r9 used to pass 6th argument to functions
85 * [Not preserved]
86 * %r10 temporary register, used for passing a function’s static chain pointer
87 * [Not preserved]
88 * %r11 temporary register
89 * [Not preserved]
90 * %r12-r15 callee-saved registers
91 * [Preserved]
92 * %xmm0–%xmm1 used to pass and return floating point arguments
93 * [Not preserved]
94 * %xmm2–%xmm7 used to pass floating point arguments
95 * [Not preserved]
96 * %xmm8–%xmm15 temporary registers
97 * [Not preserved]
98 * %mmx0–%mmx7 temporary registers
99 * [Not preserved]
100 * %st0 temporary register; used to return long double arguments
101 * [Not preserved]
102 * %st1 temporary registers; used to return long double arguments
103 * [Not preserved]
104 * %st2–%st7 temporary registers
105 * [Not preserved]
106 * %fs Reserved for system use (as thread specific data register)
107 * [Not preserved]
108 *
109 * Direction flag is preserved as cleared.
110 * The stack must be aligned on a 16-byte boundrary before the 'call/jmp' instruction.
111 *
112 *
113 *
114 * MSC expects the following:
115 * rax return value, not preserved.
116 * rbx preserved.
117 * rcx 1st argument, integer, not preserved.
118 * rdx 2nd argument, integer, not preserved.
119 * rbp preserved.
120 * rsp preserved.
121 * rsi preserved.
122 * rdi preserved.
123 * r8 3rd argument, integer, not preserved.
124 * r9 4th argument, integer, not preserved.
125 * r10 scratch register, not preserved.
126 * r11 scratch register, not preserved.
127 * r12-r15 preserved.
128 * xmm0 1st argument, fp, return value, not preserved.
129 * xmm1 2st argument, fp, not preserved.
130 * xmm2 3st argument, fp, not preserved.
131 * xmm3 4st argument, fp, not preserved.
132 * xmm4-xmm5 scratch, not preserved.
133 * xmm6-xmm15 preserved.
134 *
135 * Dunno what the direction flag is...
136 * The stack must be aligned on a 16-byte boundrary before the 'call/jmp' instruction.
137 *
138 *
139 * Thus, When GCC code is calling MSC code we don't really have to preserve
140 * anything. But but MSC code is calling GCC code, we'll have to save esi and edi.
141 *
142 *
143 */
144
145
146/*******************************************************************************
147* Defined Constants And Macros *
148*******************************************************************************/
149/** @def USE_REM_STUBS
150 * Define USE_REM_STUBS to stub the entire REM stuff. This is useful during
151 * early porting (before we start running stuff).
152 */
153#if defined(__DOXYGEN__)
154# define USE_REM_STUBS
155#endif
156
157/** @def USE_REM_CALLING_CONVENTION_GLUE
158 * Define USE_REM_CALLING_CONVENTION_GLUE for platforms where it's necessary to
159 * use calling convention wrappers.
160 */
161#if defined(__WIN64__) || defined(__DOXYGEN__)
162# define USE_REM_CALLING_CONVENTION_GLUE
163#endif
164
165
166/*******************************************************************************
167* Header Files *
168*******************************************************************************/
169#define LOG_GROUP LOG_GROUP_REM
170#include <VBox/rem.h>
171#include <VBox/vmm.h>
172#include <VBox/dbgf.h>
173#include <VBox/mm.h>
174#include <VBox/em.h>
175#include <VBox/ssm.h>
176#include <VBox/hwaccm.h>
177#include <VBox/patm.h>
178#include <VBox/pdm.h>
179#include <VBox/pgm.h>
180#include <VBox/iom.h>
181#include <VBox/vm.h>
182#include <VBox/err.h>
183#include <VBox/log.h>
184#include <VBox/dis.h>
185
186#include <iprt/alloc.h>
187#include <iprt/assert.h>
188#include <iprt/ldr.h>
189#include <iprt/param.h>
190#include <iprt/path.h>
191#include <iprt/string.h>
192
193
194/*******************************************************************************
195* Structures and Typedefs *
196*******************************************************************************/
197/**
198 * Parameter descriptor.
199 */
200typedef struct REMPARMDESC
201{
202 /** Parameter flags (REMPARMDESC_FLAGS_*). */
203 uint8_t fFlags;
204 /** The parameter size if REMPARMDESC_FLAGS_SIZE is set. */
205 uint8_t cb;
206} REMPARMDESC, *PREMPARMDESC;
207/** Pointer to a constant parameter descriptor. */
208typedef const REMPARMDESC *PCREMPARMDESC;
209
210/** @name Parameter descriptor flags.
211 * @{ */
212/** The parameter type is a kind of integer which could fit in a register. This includes pointers. */
213#define REMPARMDESC_FLAGS_INT 0
214/** The parameter is a GC pointer. */
215#define REMPARMDESC_FLAGS_GCPTR 1
216/** The parameter is a GC physical address. */
217#define REMPARMDESC_FLAGS_GCPHYS 2
218/** The parameter is a HC physical address. */
219#define REMPARMDESC_FLAGS_HCPHYS 3
220/** The parameter type is a kind of floating point. */
221#define REMPARMDESC_FLAGS_FLOAT 4
222/** The parameter value is a struct. This type takes a size. */
223#define REMPARMDESC_FLAGS_STRUCT 5
224/** The parameter is an elipsis. */
225#define REMPARMDESC_FLAGS_ELLIPSIS 6
226/** The parameter is a va_list. */
227#define REMPARMDESC_FLAGS_VALIST 7
228/** The parameter type mask. */
229#define REMPARMDESC_FLAGS_TYPE_MASK 7
230/** The parameter size field is valid. */
231#define REMPARMDESC_FLAGS_SIZE BIT(7)
232/** @} */
233
234/**
235 * Function descriptor.
236 */
237typedef struct REMFNDESC
238{
239 /** The function name. */
240 const char *pszName;
241 /** Exports: Pointer to the function pointer.
242 * Imports: Pointer to the function. */
243 void *pv;
244 /** Array of parameter descriptors. */
245 PCREMPARMDESC paParams;
246 /** The number of parameter descriptors pointed to by paParams. */
247 uint8_t cParams;
248 /** Function flags (REMFNDESC_FLAGS_*). */
249 uint8_t fFlags;
250 /** The size of the return value. */
251 uint8_t cbReturn;
252 /** Pointer to the wrapper code for imports. */
253 void *pvWrapper;
254} REMFNDESC, *PREMFNDESC;
255/** Pointer to a constant function descriptor. */
256typedef const REMFNDESC *PCREMFNDESC;
257
258/** @name Function descriptor flags.
259 * @{ */
260/** The return type is void. */
261#define REMFNDESC_FLAGS_RET_VOID 0
262/** The return type is a kind of integer passed in rax/eax. This includes pointers. */
263#define REMFNDESC_FLAGS_RET_INT 1
264/** The return type is a kind of floating point. */
265#define REMFNDESC_FLAGS_RET_FLOAT 2
266/** The return value is a struct. This type take a size. */
267#define REMFNDESC_FLAGS_RET_STRUCT 3
268/** The return type mask. */
269#define REMFNDESC_FLAGS_RET_TYPE_MASK 7
270/** The argument list contains one or more va_list arguments (i.e. problems). */
271#define REMFNDESC_FLAGS_VALIST BIT(6)
272/** The function has an ellipsis (i.e. a problem). */
273#define REMFNDESC_FLAGS_ELLIPSIS BIT(7)
274/** @} */
275
276/**
277 * Chunk of read-write-executable memory.
278 */
279typedef struct REMEXECMEM
280{
281 /** The number of bytes left. */
282 struct REMEXECMEM *pNext;
283 /** The size of this chunk. */
284 uint32_t cb;
285 /** The offset of the next code block. */
286 uint32_t off;
287#if ARCH_BITS == 32
288 uint32_t padding;
289#endif
290} REMEXECMEM, *PREMEXECMEM;
291
292
293/*******************************************************************************
294* Global Variables *
295*******************************************************************************/
296#ifndef USE_REM_STUBS
297/** Loader handle of the REM object/DLL. */
298static RTLDRMOD g_ModREM2;
299/** Pointer to the memory containing the loaded REM2 object/DLL. */
300static void *g_pvREM2;
301
302/** Linux object export addresses.
303 * These are references from the assembly wrapper code.
304 * @{ */
305static DECLCALLBACKPTR(int, pfnREMR3Init)(PVM);
306static DECLCALLBACKPTR(int, pfnREMR3Term)(PVM);
307static DECLCALLBACKPTR(void, pfnREMR3Reset)(PVM);
308static DECLCALLBACKPTR(int, pfnREMR3Step)(PVM);
309static DECLCALLBACKPTR(int, pfnREMR3BreakpointSet)(PVM, RTGCUINTPTR);
310static DECLCALLBACKPTR(int, pfnREMR3BreakpointClear)(PVM, RTGCUINTPTR);
311static DECLCALLBACKPTR(int, pfnREMR3EmulateInstruction)(PVM);
312static DECLCALLBACKPTR(int, pfnREMR3Run)(PVM);
313static DECLCALLBACKPTR(int, pfnREMR3State)(PVM);
314static DECLCALLBACKPTR(int, pfnREMR3StateBack)(PVM);
315static DECLCALLBACKPTR(void, pfnREMR3StateUpdate)(PVM);
316static DECLCALLBACKPTR(void, pfnREMR3A20Set)(PVM, bool);
317static DECLCALLBACKPTR(void, pfnREMR3ReplayInvalidatedPages)(PVM);
318static DECLCALLBACKPTR(void, pfnREMR3NotifyPhysRamRegister)(PVM, RTGCPHYS, RTUINT, void *, unsigned);
319static DECLCALLBACKPTR(void, pfnREMR3NotifyPhysReserve)(PVM, RTGCPHYS, RTUINT);
320static DECLCALLBACKPTR(void, pfnREMR3NotifyPhysRomRegister)(PVM, RTGCPHYS, RTUINT, void *);
321static DECLCALLBACKPTR(void, pfnREMR3NotifyHandlerPhysicalModify)(PVM, PGMPHYSHANDLERTYPE, RTGCPHYS, RTGCPHYS, RTGCPHYS, bool, void *);
322static DECLCALLBACKPTR(void, pfnREMR3NotifyHandlerPhysicalRegister)(PVM, PGMPHYSHANDLERTYPE, RTGCPHYS, RTGCPHYS, bool);
323static DECLCALLBACKPTR(void, pfnREMR3NotifyHandlerPhysicalDeregister)(PVM, PGMPHYSHANDLERTYPE, RTGCPHYS, RTGCPHYS, bool, void *);
324static DECLCALLBACKPTR(void, pfnREMR3NotifyInterruptSet)(PVM);
325static DECLCALLBACKPTR(void, pfnREMR3NotifyInterruptClear)(PVM);
326static DECLCALLBACKPTR(void, pfnREMR3NotifyTimerPending)(PVM);
327static DECLCALLBACKPTR(void, pfnREMR3NotifyDmaPending)(PVM);
328static DECLCALLBACKPTR(void, pfnREMR3NotifyQueuePending)(PVM);
329static DECLCALLBACKPTR(void, pfnREMR3NotifyFF)(PVM);
330static DECLCALLBACKPTR(int, pfnREMR3NotifyCodePageChanged)(PVM, RTGCPTR);
331static DECLCALLBACKPTR(void, pfnREMR3NotifyPendingInterrupt)(PVM, uint8_t);
332static DECLCALLBACKPTR(uint32_t, pfnREMR3QueryPendingInterrupt)(PVM);
333static DECLCALLBACKPTR(int, pfnREMR3DisasEnableStepping)(PVM, bool);
334static DECLCALLBACKPTR(bool, pfnREMR3IsPageAccessHandled)(PVM, RTGCPHYS);
335/** @} */
336
337/** Export and import parameter descriptors.
338 * @{
339 */
340/* Common args. */
341static const REMPARMDESC g_aArgsSIZE_T[] =
342{
343 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
344};
345static const REMPARMDESC g_aArgsPTR[] =
346{
347 { REMPARMDESC_FLAGS_INT, sizeof(void *) }
348};
349static const REMPARMDESC g_aArgsVM[] =
350{
351 { REMPARMDESC_FLAGS_INT, sizeof(PVM) }
352};
353
354/* REM args */
355static const REMPARMDESC g_aArgsBreakpoint[] =
356{
357 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
358 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINTPTR) }
359};
360static const REMPARMDESC g_aArgsA20Set[] =
361{
362 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
363 { REMPARMDESC_FLAGS_INT, sizeof(bool) }
364};
365static const REMPARMDESC g_aArgsNotifyPhysRamRegister[] =
366{
367 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
368 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
369 { REMPARMDESC_FLAGS_INT, sizeof(RTUINT) },
370 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
371 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) }
372};
373static const REMPARMDESC g_aArgsNotifyPhysReserve[] =
374{
375 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
376 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
377 { REMPARMDESC_FLAGS_INT, sizeof(RTUINT) }
378};
379static const REMPARMDESC g_aArgsNotifyPhysRomRegister[] =
380{
381 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
382 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
383 { REMPARMDESC_FLAGS_INT, sizeof(RTUINT) },
384 { REMPARMDESC_FLAGS_INT, sizeof(void *) }
385};
386static const REMPARMDESC g_aArgsNotifyHandlerPhysicalModify[] =
387{
388 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
389 { REMPARMDESC_FLAGS_INT, sizeof(PGMPHYSHANDLERTYPE) },
390 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
391 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
392 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
393 { REMPARMDESC_FLAGS_INT, sizeof(bool) },
394 { REMPARMDESC_FLAGS_INT, sizeof(void *) }
395};
396static const REMPARMDESC g_aArgsNotifyHandlerPhysicalRegister[] =
397{
398 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
399 { REMPARMDESC_FLAGS_INT, sizeof(PGMPHYSHANDLERTYPE) },
400 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
401 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
402 { REMPARMDESC_FLAGS_INT, sizeof(bool) }
403};
404static const REMPARMDESC g_aArgsNotifyHandlerPhysicalDeregister[] =
405{
406 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
407 { REMPARMDESC_FLAGS_INT, sizeof(PGMPHYSHANDLERTYPE) },
408 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
409 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
410 { REMPARMDESC_FLAGS_INT, sizeof(bool) },
411 { REMPARMDESC_FLAGS_INT, sizeof(void *) }
412};
413static const REMPARMDESC g_aArgsNotifyCodePageChanged[] =
414{
415 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
416 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINTPTR) }
417};
418static const REMPARMDESC g_aArgsNotifyPendingInterrupt[] =
419{
420 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
421 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t) }
422};
423static const REMPARMDESC g_aArgsDisasEnableStepping[] =
424{
425 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
426 { REMPARMDESC_FLAGS_INT, sizeof(bool) }
427};
428static const REMPARMDESC g_aArgsIsPageAccessHandled[] =
429{
430 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
431 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) }
432};
433
434
435/* VMM args */
436static const REMPARMDESC g_aArgsCPUMGetGuestCpuId[] =
437{
438 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
439 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
440 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) },
441 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) },
442 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) },
443 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) }
444};
445static const REMPARMDESC g_aArgsCPUMQueryGuestCtxPtr[] =
446{
447 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
448 { REMPARMDESC_FLAGS_INT, sizeof(PCPUMCTX *) }
449};
450static const REMPARMDESC g_aArgsDBGFR3Info[] =
451{
452 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
453 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
454 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
455 { REMPARMDESC_FLAGS_INT, sizeof(PCDBGFINFOHLP) }
456};
457static const REMPARMDESC g_aArgsDBGFR3SymbolByAddr[] =
458{
459 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
460 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINTPTR) },
461 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCINTPTR) },
462 { REMPARMDESC_FLAGS_INT, sizeof(PDBGFSYMBOL) }
463};
464static const REMPARMDESC g_aArgsDISInstr[] =
465{
466 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
467 { REMPARMDESC_FLAGS_INT, sizeof(RTUINTPTR) },
468 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
469 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) },
470 { REMPARMDESC_FLAGS_INT, sizeof(char *) }
471};
472static const REMPARMDESC g_aArgsEMR3FatalError[] =
473{
474 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
475 { REMPARMDESC_FLAGS_INT, sizeof(int) }
476};
477static const REMPARMDESC g_aArgsHWACCMR3CanExecuteGuest[] =
478{
479 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
480 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
481 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
482 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
483};
484static const REMPARMDESC g_aArgsIOMIOPortRead[] =
485{
486 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
487 { REMPARMDESC_FLAGS_INT, sizeof(RTIOPORT) },
488 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) },
489 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
490};
491static const REMPARMDESC g_aArgsIOMIOPortWrite[] =
492{
493 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
494 { REMPARMDESC_FLAGS_INT, sizeof(RTIOPORT) },
495 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
496 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
497};
498static const REMPARMDESC g_aArgsIOMMMIORead[] =
499{
500 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
501 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
502 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) },
503 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
504};
505static const REMPARMDESC g_aArgsIOMMMIOWrite[] =
506{
507 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
508 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
509 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
510 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
511};
512static const REMPARMDESC g_aArgsMMR3HeapAlloc[] =
513{
514 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
515 { REMPARMDESC_FLAGS_INT, sizeof(MMTAG) },
516 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
517};
518static const REMPARMDESC g_aArgsPATMIsPatchGCAddr[] =
519{
520 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
521 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR) }
522};
523static const REMPARMDESC g_aArgsPATMR3QueryOpcode[] =
524{
525 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
526 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR) },
527 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *) }
528};
529static const REMPARMDESC g_aArgsPATMR3QueryPatchMem[] =
530{
531 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
532 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) }
533};
534static const REMPARMDESC g_aArgsPDMApicGetBase[] =
535{
536 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
537 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t *) }
538};
539static const REMPARMDESC g_aArgsPDMApicGetTPR[] =
540{
541 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
542 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *) }
543};
544static const REMPARMDESC g_aArgsPDMApicSetBase[] =
545{
546 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
547 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t) }
548};
549static const REMPARMDESC g_aArgsPDMApicSetTPR[] =
550{
551 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
552 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t) }
553};
554static const REMPARMDESC g_aArgsPDMGetInterrupt[] =
555{
556 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
557 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *) }
558};
559static const REMPARMDESC g_aArgsPDMIsaSetIrq[] =
560{
561 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
562 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t) },
563 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t) }
564};
565static const REMPARMDESC g_aArgsPGMGstGetPage[] =
566{
567 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
568 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR) },
569 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t *) },
570 { REMPARMDESC_FLAGS_INT, sizeof(PRTGCPHYS) }
571};
572static const REMPARMDESC g_aArgsPGMInvalidatePage[] =
573{
574 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
575 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR) }
576};
577static const REMPARMDESC g_aArgsPGMPhysGCPhys2HCPtr[] =
578{
579 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
580 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
581 { REMPARMDESC_FLAGS_INT, sizeof(PRTHCPTR) }
582};
583static const REMPARMDESC g_aArgsPGMPhysGCPtr2HCPtrByGstCR3[] =
584{
585 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
586 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
587 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
588 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
589 { REMPARMDESC_FLAGS_INT, sizeof(PRTHCPTR) }
590};
591static const REMPARMDESC g_aArgsPGMPhysRead[] =
592{
593 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
594 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
595 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
596 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
597};
598static const REMPARMDESC g_aArgsPGMPhysReadGCPtr[] =
599{
600 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
601 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
602 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR) },
603 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
604};
605static const REMPARMDESC g_aArgsPGMPhysWrite[] =
606{
607 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
608 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
609 { REMPARMDESC_FLAGS_INT, sizeof(const void *) },
610 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
611};
612static const REMPARMDESC g_aArgsPGMChangeMode[] =
613{
614 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
615 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
616 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
617 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t) }
618};
619static const REMPARMDESC g_aArgsPGMFlushTLB[] =
620{
621 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
622 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
623 { REMPARMDESC_FLAGS_INT, sizeof(bool) }
624};
625static const REMPARMDESC g_aArgsPGMR3PhysReadUxx[] =
626{
627 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
628 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) }
629};
630static const REMPARMDESC g_aArgsPGMR3PhysWriteU8[] =
631{
632 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
633 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
634 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t) }
635};
636static const REMPARMDESC g_aArgsPGMR3PhysWriteU16[] =
637{
638 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
639 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
640 { REMPARMDESC_FLAGS_INT, sizeof(uint16_t) }
641};
642static const REMPARMDESC g_aArgsPGMR3PhysWriteU32[] =
643{
644 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
645 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
646 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) }
647};
648static const REMPARMDESC g_aArgsPGMR3PhysWriteU64[] =
649{
650 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
651 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS) },
652 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t) }
653};
654static const REMPARMDESC g_aArgsSSMR3GetGCPtr[] =
655{
656 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
657 { REMPARMDESC_FLAGS_INT, sizeof(PRTGCPTR) }
658};
659static const REMPARMDESC g_aArgsSSMR3GetMem[] =
660{
661 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
662 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
663 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
664};
665static const REMPARMDESC g_aArgsSSMR3GetU32[] =
666{
667 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
668 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *) }
669};
670static const REMPARMDESC g_aArgsSSMR3GetUInt[] =
671{
672 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
673 { REMPARMDESC_FLAGS_INT, sizeof(PRTUINT) }
674};
675static const REMPARMDESC g_aArgsSSMR3PutGCPtr[] =
676{
677 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
678 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR) }
679};
680static const REMPARMDESC g_aArgsSSMR3PutMem[] =
681{
682 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
683 { REMPARMDESC_FLAGS_INT, sizeof(const void *) },
684 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
685};
686static const REMPARMDESC g_aArgsSSMR3PutU32[] =
687{
688 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
689 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
690};
691static const REMPARMDESC g_aArgsSSMR3PutUInt[] =
692{
693 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE) },
694 { REMPARMDESC_FLAGS_INT, sizeof(RTUINT) },
695};
696static const REMPARMDESC g_aArgsSSMR3RegisterInternal[] =
697{
698 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
699 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
700 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
701 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t) },
702 { REMPARMDESC_FLAGS_INT, sizeof(size_t) },
703 { REMPARMDESC_FLAGS_INT, sizeof(PFNSSMINTSAVEPREP) },
704 { REMPARMDESC_FLAGS_INT, sizeof(PFNSSMINTSAVEEXEC) },
705 { REMPARMDESC_FLAGS_INT, sizeof(PFNSSMINTSAVEDONE) },
706 { REMPARMDESC_FLAGS_INT, sizeof(PFNSSMINTLOADPREP) },
707 { REMPARMDESC_FLAGS_INT, sizeof(PFNSSMINTLOADEXEC) },
708 { REMPARMDESC_FLAGS_INT, sizeof(PFNSSMINTLOADDONE) },
709};
710static const REMPARMDESC g_aArgsSTAMR3Register[] =
711{
712 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
713 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
714 { REMPARMDESC_FLAGS_INT, sizeof(STAMTYPE) },
715 { REMPARMDESC_FLAGS_INT, sizeof(STAMVISIBILITY) },
716 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
717 { REMPARMDESC_FLAGS_INT, sizeof(STAMUNIT) },
718 { REMPARMDESC_FLAGS_INT, sizeof(const char *) }
719};
720static const REMPARMDESC g_aArgsTRPMAssertTrap[] =
721{
722 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
723 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t) },
724 { REMPARMDESC_FLAGS_INT, sizeof(bool) }
725};
726static const REMPARMDESC g_aArgsTRPMQueryTrap[] =
727{
728 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
729 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *) },
730 { REMPARMDESC_FLAGS_INT, sizeof(bool *) }
731};
732static const REMPARMDESC g_aArgsTRPMSetErrorCode[] =
733{
734 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
735 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINT) }
736};
737static const REMPARMDESC g_aArgsTRPMSetFaultAddress[] =
738{
739 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
740 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINT) }
741};
742static const REMPARMDESC g_aArgsVMR3ReqCall[] =
743{
744 { REMPARMDESC_FLAGS_INT, sizeof(PVM) },
745 { REMPARMDESC_FLAGS_INT, sizeof(PVMREQ *) },
746 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
747 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
748 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
749 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
750};
751static const REMPARMDESC g_aArgsVMR3ReqFree[] =
752{
753 { REMPARMDESC_FLAGS_INT, sizeof(PVMREQ) }
754};
755
756
757/* IPRT args */
758static const REMPARMDESC g_aArgsAssertMsg1[] =
759{
760 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
761 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
762 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
763 { REMPARMDESC_FLAGS_INT, sizeof(const char *) }
764};
765static const REMPARMDESC g_aArgsAssertMsg2[] =
766{
767 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
768 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
769};
770static const REMPARMDESC g_aArgsRTLogFlags[] =
771{
772 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER) },
773 { REMPARMDESC_FLAGS_INT, sizeof(const char *) }
774};
775static const REMPARMDESC g_aArgsRTLogLoggerEx[] =
776{
777 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER) },
778 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
779 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
780 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
781 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
782};
783static const REMPARMDESC g_aArgsRTLogLoggerExV[] =
784{
785 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER) },
786 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
787 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) },
788 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
789 { REMPARMDESC_FLAGS_VALIST, 0 }
790};
791static const REMPARMDESC g_aArgsRTLogPrintf[] =
792{
793 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
794 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
795};
796static const REMPARMDESC g_aArgsRTMemProtect[] =
797{
798 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
799 { REMPARMDESC_FLAGS_INT, sizeof(size_t) },
800 { REMPARMDESC_FLAGS_INT, sizeof(unsigned) }
801};
802static const REMPARMDESC g_aArgsRTStrPrintf[] =
803{
804 { REMPARMDESC_FLAGS_INT, sizeof(char *) },
805 { REMPARMDESC_FLAGS_INT, sizeof(size_t) },
806 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
807 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
808};
809static const REMPARMDESC g_aArgsRTStrPrintfV[] =
810{
811 { REMPARMDESC_FLAGS_INT, sizeof(char *) },
812 { REMPARMDESC_FLAGS_INT, sizeof(size_t) },
813 { REMPARMDESC_FLAGS_INT, sizeof(const char *) },
814 { REMPARMDESC_FLAGS_VALIST, 0 }
815};
816
817
818/* CRT args */
819static const REMPARMDESC g_aArgsmemcpy[] =
820{
821 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
822 { REMPARMDESC_FLAGS_INT, sizeof(const void *) },
823 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
824};
825static const REMPARMDESC g_aArgsmemset[] =
826{
827 { REMPARMDESC_FLAGS_INT, sizeof(void *) },
828 { REMPARMDESC_FLAGS_INT, sizeof(int) },
829 { REMPARMDESC_FLAGS_INT, sizeof(size_t) }
830};
831
832
833/** @} */
834
835/**
836 * Descriptors for the exported functions.
837 */
838static const REMFNDESC g_aExports[] =
839{ /* pszName, (void *)pv, pParams, cParams, fFlags, cb, pvWrapper. */
840 { "REMR3Init", (void *)&pfnREMR3Init, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
841 { "REMR3Term", (void *)&pfnREMR3Term, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
842 { "REMR3Reset", (void *)&pfnREMR3Reset, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
843 { "REMR3Step", (void *)&pfnREMR3Step, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
844 { "REMR3BreakpointSet", (void *)&pfnREMR3BreakpointSet, &g_aArgsBreakpoint[0], ELEMENTS(g_aArgsBreakpoint), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
845 { "REMR3BreakpointClear", (void *)&pfnREMR3BreakpointClear, &g_aArgsBreakpoint[0], ELEMENTS(g_aArgsBreakpoint), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
846 { "REMR3EmulateInstruction", (void *)&pfnREMR3EmulateInstruction, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
847 { "REMR3Run", (void *)&pfnREMR3Run, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
848 { "REMR3State", (void *)&pfnREMR3State, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
849 { "REMR3StateBack", (void *)&pfnREMR3StateBack, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
850 { "REMR3StateUpdate", (void *)&pfnREMR3StateUpdate, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
851 { "REMR3A20Set", (void *)&pfnREMR3A20Set, &g_aArgsA20Set[0], ELEMENTS(g_aArgsA20Set), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
852 { "REMR3ReplayInvalidatedPages", (void *)&pfnREMR3ReplayInvalidatedPages, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
853 { "REMR3NotifyPhysRamRegister", (void *)&pfnREMR3NotifyPhysRamRegister, &g_aArgsNotifyPhysRamRegister[0], ELEMENTS(g_aArgsNotifyPhysRamRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
854 { "REMR3NotifyPhysReserve", (void *)&pfnREMR3NotifyPhysReserve, &g_aArgsNotifyPhysReserve[0], ELEMENTS(g_aArgsNotifyPhysReserve), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
855 { "REMR3NotifyPhysRomRegister", (void *)&pfnREMR3NotifyPhysRomRegister, &g_aArgsNotifyPhysRomRegister[0], ELEMENTS(g_aArgsNotifyPhysRomRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
856 { "REMR3NotifyHandlerPhysicalModify", (void *)&pfnREMR3NotifyHandlerPhysicalModify, &g_aArgsNotifyHandlerPhysicalModify[0], ELEMENTS(g_aArgsNotifyHandlerPhysicalModify), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
857 { "REMR3NotifyHandlerPhysicalRegister", (void *)&pfnREMR3NotifyHandlerPhysicalRegister, &g_aArgsNotifyHandlerPhysicalRegister[0], ELEMENTS(g_aArgsNotifyHandlerPhysicalRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
858 { "REMR3NotifyHandlerPhysicalDeregister", (void *)&pfnREMR3NotifyHandlerPhysicalDeregister, &g_aArgsNotifyHandlerPhysicalDeregister[0], ELEMENTS(g_aArgsNotifyHandlerPhysicalDeregister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
859 { "REMR3NotifyInterruptSet", (void *)&pfnREMR3NotifyInterruptSet, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
860 { "REMR3NotifyInterruptClear", (void *)&pfnREMR3NotifyInterruptClear, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
861 { "REMR3NotifyTimerPending", (void *)&pfnREMR3NotifyTimerPending, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
862 { "REMR3NotifyDmaPending", (void *)&pfnREMR3NotifyDmaPending, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
863 { "REMR3NotifyQueuePending", (void *)&pfnREMR3NotifyQueuePending, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
864 { "REMR3NotifyFF", (void *)&pfnREMR3NotifyFF, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
865 { "REMR3NotifyCodePageChanged", (void *)&pfnREMR3NotifyCodePageChanged, &g_aArgsNotifyCodePageChanged[0], ELEMENTS(g_aArgsNotifyCodePageChanged), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
866 { "REMR3NotifyPendingInterrupt", (void *)&pfnREMR3NotifyPendingInterrupt, &g_aArgsNotifyPendingInterrupt[0], ELEMENTS(g_aArgsNotifyPendingInterrupt), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
867 { "REMR3QueryPendingInterrupt", (void *)&pfnREMR3QueryPendingInterrupt, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
868 { "REMR3DisasEnableStepping", (void *)&pfnREMR3DisasEnableStepping, &g_aArgsDisasEnableStepping[0], ELEMENTS(g_aArgsDisasEnableStepping), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
869 { "REMR3IsPageAccessHandled", (void *)&pfnREMR3IsPageAccessHandled, &g_aArgsIsPageAccessHandled[0], ELEMENTS(g_aArgsIsPageAccessHandled), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL }
870};
871
872
873/**
874 * Descriptors for the functions imported from VBoxVMM.
875 */
876static REMFNDESC g_aVMMImports[] =
877{
878 { "CPUMGetAndClearChangedFlagsREM", (void *)(uintptr_t)&CPUMGetAndClearChangedFlagsREM, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(unsigned), NULL },
879 { "CPUMGetGuestCpuId", (void *)(uintptr_t)&CPUMGetGuestCpuId, &g_aArgsCPUMGetGuestCpuId[0], ELEMENTS(g_aArgsCPUMGetGuestCpuId), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
880 { "CPUMGetGuestEAX", (void *)(uintptr_t)&CPUMGetGuestEAX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
881 { "CPUMGetGuestEBP", (void *)(uintptr_t)&CPUMGetGuestEBP, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
882 { "CPUMGetGuestEBX", (void *)(uintptr_t)&CPUMGetGuestEBX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
883 { "CPUMGetGuestECX", (void *)(uintptr_t)&CPUMGetGuestECX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
884 { "CPUMGetGuestEDI", (void *)(uintptr_t)&CPUMGetGuestEDI, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
885 { "CPUMGetGuestEDX", (void *)(uintptr_t)&CPUMGetGuestEDX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
886 { "CPUMGetGuestEIP", (void *)(uintptr_t)&CPUMGetGuestEIP, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
887 { "CPUMGetGuestESI", (void *)(uintptr_t)&CPUMGetGuestESI, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
888 { "CPUMGetGuestESP", (void *)(uintptr_t)&CPUMGetGuestESP, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
889 { "CPUMQueryGuestCtxPtr", (void *)(uintptr_t)&CPUMQueryGuestCtxPtr, &g_aArgsCPUMQueryGuestCtxPtr[0], ELEMENTS(g_aArgsCPUMQueryGuestCtxPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
890 { "DBGFR3Info", (void *)(uintptr_t)&DBGFR3Info, &g_aArgsDBGFR3Info[0], ELEMENTS(g_aArgsDBGFR3Info), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
891 { "DBGFR3SymbolByAddr", (void *)(uintptr_t)&DBGFR3SymbolByAddr, &g_aArgsDBGFR3SymbolByAddr[0], ELEMENTS(g_aArgsDBGFR3SymbolByAddr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
892 { "DISInstr", (void *)(uintptr_t)&DISInstr, &g_aArgsDISInstr[0], ELEMENTS(g_aArgsDISInstr), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
893 { "EMR3FatalError", (void *)(uintptr_t)&EMR3FatalError, &g_aArgsEMR3FatalError[0], ELEMENTS(g_aArgsEMR3FatalError), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
894 { "HWACCMR3CanExecuteGuest", (void *)(uintptr_t)&HWACCMR3CanExecuteGuest, &g_aArgsHWACCMR3CanExecuteGuest[0], ELEMENTS(g_aArgsHWACCMR3CanExecuteGuest), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
895 { "IOMIOPortRead", (void *)(uintptr_t)&IOMIOPortRead, &g_aArgsIOMIOPortRead[0], ELEMENTS(g_aArgsIOMIOPortRead), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
896 { "IOMIOPortWrite", (void *)(uintptr_t)&IOMIOPortWrite, &g_aArgsIOMIOPortWrite[0], ELEMENTS(g_aArgsIOMIOPortWrite), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
897 { "IOMMMIORead", (void *)(uintptr_t)&IOMMMIORead, &g_aArgsIOMMMIORead[0], ELEMENTS(g_aArgsIOMMMIORead), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
898 { "IOMMMIOWrite", (void *)(uintptr_t)&IOMMMIOWrite, &g_aArgsIOMMMIOWrite[0], ELEMENTS(g_aArgsIOMMMIOWrite), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
899 { "MMR3HeapAlloc", (void *)(uintptr_t)&MMR3HeapAlloc, &g_aArgsMMR3HeapAlloc[0], ELEMENTS(g_aArgsMMR3HeapAlloc), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
900 { "MMR3PhysGetRamSize", (void *)(uintptr_t)&MMR3PhysGetRamSize, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint64_t), NULL },
901 { "PATMIsPatchGCAddr", (void *)(uintptr_t)&PATMIsPatchGCAddr, &g_aArgsPATMIsPatchGCAddr[0], ELEMENTS(g_aArgsPATMIsPatchGCAddr), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
902 { "PATMR3QueryOpcode", (void *)(uintptr_t)&PATMR3QueryOpcode, &g_aArgsPATMR3QueryOpcode[0], ELEMENTS(g_aArgsPATMR3QueryOpcode), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
903 { "PATMR3QueryPatchMemGC", (void *)(uintptr_t)&PATMR3QueryPatchMemGC, &g_aArgsPATMR3QueryPatchMem[0], ELEMENTS(g_aArgsPATMR3QueryPatchMem), REMFNDESC_FLAGS_RET_INT, sizeof(RTGCPTR), NULL },
904 { "PATMR3QueryPatchMemHC", (void *)(uintptr_t)&PATMR3QueryPatchMemHC, &g_aArgsPATMR3QueryPatchMem[0], ELEMENTS(g_aArgsPATMR3QueryPatchMem), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
905 { "PDMApicGetBase", (void *)(uintptr_t)&PDMApicGetBase, &g_aArgsPDMApicGetBase[0], ELEMENTS(g_aArgsPDMApicGetBase), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
906 { "PDMApicGetTPR", (void *)(uintptr_t)&PDMApicGetTPR, &g_aArgsPDMApicGetTPR[0], ELEMENTS(g_aArgsPDMApicGetTPR), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
907 { "PDMApicSetBase", (void *)(uintptr_t)&PDMApicSetBase, &g_aArgsPDMApicSetBase[0], ELEMENTS(g_aArgsPDMApicSetBase), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
908 { "PDMApicSetTPR", (void *)(uintptr_t)&PDMApicSetTPR, &g_aArgsPDMApicSetTPR[0], ELEMENTS(g_aArgsPDMApicSetTPR), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
909 { "PDMR3DmaRun", (void *)(uintptr_t)&PDMR3DmaRun, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
910 { "PDMGetInterrupt", (void *)(uintptr_t)&PDMGetInterrupt, &g_aArgsPDMGetInterrupt[0], ELEMENTS(g_aArgsPDMGetInterrupt), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
911 { "PDMIsaSetIrq", (void *)(uintptr_t)&PDMIsaSetIrq, &g_aArgsPDMIsaSetIrq[0], ELEMENTS(g_aArgsPDMIsaSetIrq), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
912 { "PGMGstGetPage", (void *)(uintptr_t)&PGMGstGetPage, &g_aArgsPGMGstGetPage[0], ELEMENTS(g_aArgsPGMGstGetPage), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
913 { "PGMInvalidatePage", (void *)(uintptr_t)&PGMInvalidatePage, &g_aArgsPGMInvalidatePage[0], ELEMENTS(g_aArgsPGMInvalidatePage), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
914 { "PGMPhysGCPhys2HCPtr", (void *)(uintptr_t)&PGMPhysGCPhys2HCPtr, &g_aArgsPGMPhysGCPhys2HCPtr[0], ELEMENTS(g_aArgsPGMPhysGCPhys2HCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
915 { "PGMPhysGCPtr2HCPtrByGstCR3", (void *)(uintptr_t)&PGMPhysGCPtr2HCPtrByGstCR3, &g_aArgsPGMPhysGCPtr2HCPtrByGstCR3[0], ELEMENTS(g_aArgsPGMPhysGCPtr2HCPtrByGstCR3), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
916 { "PGMPhysIsA20Enabled", (void *)(uintptr_t)&PGMPhysIsA20Enabled, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
917 { "PGMPhysRead", (void *)(uintptr_t)&PGMPhysRead, &g_aArgsPGMPhysRead[0], ELEMENTS(g_aArgsPGMPhysRead), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
918 { "PGMPhysReadGCPtr", (void *)(uintptr_t)&PGMPhysReadGCPtr, &g_aArgsPGMPhysReadGCPtr[0], ELEMENTS(g_aArgsPGMPhysReadGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
919 { "PGMPhysReadGCPtr", (void *)(uintptr_t)&PGMPhysReadGCPtr, &g_aArgsPGMPhysReadGCPtr[0], ELEMENTS(g_aArgsPGMPhysReadGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
920 { "PGMPhysWrite", (void *)(uintptr_t)&PGMPhysWrite, &g_aArgsPGMPhysWrite[0], ELEMENTS(g_aArgsPGMPhysWrite), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
921 { "PGMChangeMode", (void *)(uintptr_t)&PGMChangeMode, &g_aArgsPGMChangeMode[0], ELEMENTS(g_aArgsPGMChangeMode), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
922 { "PGMFlushTLB", (void *)(uintptr_t)&PGMFlushTLB, &g_aArgsPGMFlushTLB[0], ELEMENTS(g_aArgsPGMFlushTLB), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
923 { "PGMR3PhysReadByte", (void *)(uintptr_t)&PGMR3PhysReadByte, &g_aArgsPGMR3PhysReadUxx[0], ELEMENTS(g_aArgsPGMR3PhysReadUxx), REMFNDESC_FLAGS_RET_INT, sizeof(uint8_t), NULL },
924 { "PGMR3PhysReadDword", (void *)(uintptr_t)&PGMR3PhysReadDword, &g_aArgsPGMR3PhysReadUxx[0], ELEMENTS(g_aArgsPGMR3PhysReadUxx), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
925 { "PGMR3PhysReadWord", (void *)(uintptr_t)&PGMR3PhysReadWord, &g_aArgsPGMR3PhysReadUxx[0], ELEMENTS(g_aArgsPGMR3PhysReadUxx), REMFNDESC_FLAGS_RET_INT, sizeof(uint16_t), NULL },
926 { "PGMR3PhysWriteByte", (void *)(uintptr_t)&PGMR3PhysWriteByte, &g_aArgsPGMR3PhysWriteU8[0], ELEMENTS(g_aArgsPGMR3PhysWriteU8), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
927 { "PGMR3PhysWriteDword", (void *)(uintptr_t)&PGMR3PhysWriteDword, &g_aArgsPGMR3PhysWriteU32[0], ELEMENTS(g_aArgsPGMR3PhysWriteU32), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
928 { "PGMR3PhysWriteWord", (void *)(uintptr_t)&PGMR3PhysWriteWord, &g_aArgsPGMR3PhysWriteU16[0], ELEMENTS(g_aArgsPGMR3PhysWriteU16), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
929 { "SSMR3GetGCPtr", (void *)(uintptr_t)&SSMR3GetGCPtr, &g_aArgsSSMR3GetGCPtr[0], ELEMENTS(g_aArgsSSMR3GetGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
930 { "SSMR3GetMem", (void *)(uintptr_t)&SSMR3GetMem, &g_aArgsSSMR3GetMem[0], ELEMENTS(g_aArgsSSMR3GetMem), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
931 { "SSMR3GetU32", (void *)(uintptr_t)&SSMR3GetU32, &g_aArgsSSMR3GetU32[0], ELEMENTS(g_aArgsSSMR3GetU32), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
932 { "SSMR3GetUInt", (void *)(uintptr_t)&SSMR3GetUInt, &g_aArgsSSMR3GetUInt[0], ELEMENTS(g_aArgsSSMR3GetUInt), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
933 { "SSMR3PutGCPtr", (void *)(uintptr_t)&SSMR3PutGCPtr, &g_aArgsSSMR3PutGCPtr[0], ELEMENTS(g_aArgsSSMR3PutGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
934 { "SSMR3PutMem", (void *)(uintptr_t)&SSMR3PutMem, &g_aArgsSSMR3PutMem[0], ELEMENTS(g_aArgsSSMR3PutMem), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
935 { "SSMR3PutU32", (void *)(uintptr_t)&SSMR3PutU32, &g_aArgsSSMR3PutU32[0], ELEMENTS(g_aArgsSSMR3PutU32), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
936 { "SSMR3PutUInt", (void *)(uintptr_t)&SSMR3PutUInt, &g_aArgsSSMR3PutUInt[0], ELEMENTS(g_aArgsSSMR3PutUInt), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
937 { "SSMR3RegisterInternal", (void *)(uintptr_t)&SSMR3RegisterInternal, &g_aArgsSSMR3RegisterInternal[0], ELEMENTS(g_aArgsSSMR3RegisterInternal), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
938 { "STAMR3Register", (void *)(uintptr_t)&STAMR3Register, &g_aArgsSTAMR3Register[0], ELEMENTS(g_aArgsSTAMR3Register), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
939 { "TMCpuTickGet", (void *)(uintptr_t)&TMCpuTickGet, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint64_t), NULL },
940 { "TMCpuTickPause", (void *)(uintptr_t)&TMCpuTickPause, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
941 { "TMCpuTickResume", (void *)(uintptr_t)&TMCpuTickResume, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
942 { "TMTimerPoll", (void *)(uintptr_t)&TMTimerPoll, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint64_t), NULL },
943 { "TMR3TimerQueuesDo", (void *)(uintptr_t)&TMR3TimerQueuesDo, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
944 { "TMVirtualPause", (void *)(uintptr_t)&TMVirtualPause, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
945 { "TMVirtualResume", (void *)(uintptr_t)&TMVirtualResume, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
946 { "TRPMAssertTrap", (void *)(uintptr_t)&TRPMAssertTrap, &g_aArgsTRPMAssertTrap[0], ELEMENTS(g_aArgsTRPMAssertTrap), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
947 { "TRPMGetErrorCode", (void *)(uintptr_t)&TRPMGetErrorCode, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(RTGCUINT), NULL },
948 { "TRPMGetFaultAddress", (void *)(uintptr_t)&TRPMGetFaultAddress, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(RTGCUINTPTR),NULL },
949 { "TRPMQueryTrap", (void *)(uintptr_t)&TRPMQueryTrap, &g_aArgsTRPMQueryTrap[0], ELEMENTS(g_aArgsTRPMQueryTrap), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
950 { "TRPMResetTrap", (void *)(uintptr_t)&TRPMResetTrap, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
951 { "TRPMSetErrorCode", (void *)(uintptr_t)&TRPMSetErrorCode, &g_aArgsTRPMSetErrorCode[0], ELEMENTS(g_aArgsTRPMSetErrorCode), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
952 { "TRPMSetFaultAddress", (void *)(uintptr_t)&TRPMSetFaultAddress, &g_aArgsTRPMSetFaultAddress[0], ELEMENTS(g_aArgsTRPMSetFaultAddress), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
953 { "VMMR3Lock", (void *)(uintptr_t)&VMMR3Lock, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
954 { "VMMR3Unlock", (void *)(uintptr_t)&VMMR3Unlock, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
955 { "VMR3ReqCall", (void *)(uintptr_t)&VMR3ReqCall, &g_aArgsVMR3ReqCall[0], ELEMENTS(g_aArgsVMR3ReqCall), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
956 { "VMR3ReqFree", (void *)(uintptr_t)&VMR3ReqFree, &g_aArgsVMR3ReqFree[0], ELEMENTS(g_aArgsVMR3ReqFree), REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_ELLIPSIS, sizeof(int), NULL },
957// { "", (void *)(uintptr_t)&, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
958
959};
960
961
962/**
963 * Descriptors for the functions imported from VBoxRT.
964 */
965static REMFNDESC g_aRTImports[] =
966{
967 { "AssertMsg1", (void *)(uintptr_t)&AssertMsg1, &g_aArgsAssertMsg1[0], ELEMENTS(g_aArgsAssertMsg1), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
968 { "AssertMsg2", (void *)(uintptr_t)&AssertMsg2, &g_aArgsAssertMsg2[0], ELEMENTS(g_aArgsAssertMsg2), REMFNDESC_FLAGS_RET_VOID | REMFNDESC_FLAGS_ELLIPSIS, 0, NULL },
969 { "RTLogDefaultInstance", (void *)(uintptr_t)&RTLogDefaultInstance, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(PRTLOGGER), NULL },
970 { "RTLogFlags", (void *)(uintptr_t)&RTLogFlags, &g_aArgsRTLogFlags[0], ELEMENTS(g_aArgsRTLogFlags), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
971 { "RTLogLoggerEx", (void *)(uintptr_t)&RTLogLoggerEx, &g_aArgsRTLogLoggerEx[0], ELEMENTS(g_aArgsRTLogLoggerEx), REMFNDESC_FLAGS_RET_VOID | REMFNDESC_FLAGS_ELLIPSIS, 0, NULL },
972 { "RTLogLoggerExV", (void *)(uintptr_t)&RTLogLoggerExV, &g_aArgsRTLogLoggerExV[0], ELEMENTS(g_aArgsRTLogLoggerExV), REMFNDESC_FLAGS_RET_VOID | REMFNDESC_FLAGS_VALIST, 0, NULL },
973 { "RTLogPrintf", (void *)(uintptr_t)&RTLogPrintf, &g_aArgsRTLogPrintf[0], ELEMENTS(g_aArgsRTLogPrintf), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
974 { "RTMemAlloc", (void *)(uintptr_t)&RTMemAlloc, &g_aArgsSIZE_T[0], ELEMENTS(g_aArgsSIZE_T), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
975 { "RTMemExecAlloc", (void *)(uintptr_t)&RTMemExecAlloc, &g_aArgsSIZE_T[0], ELEMENTS(g_aArgsSIZE_T), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
976 { "RTMemExecFree", (void *)(uintptr_t)&RTMemExecFree, &g_aArgsPTR[0], ELEMENTS(g_aArgsPTR), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
977 { "RTMemFree", (void *)(uintptr_t)&RTMemFree, &g_aArgsPTR[0], ELEMENTS(g_aArgsPTR), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
978 { "RTMemPageAlloc", (void *)(uintptr_t)&RTMemPageAlloc, &g_aArgsSIZE_T[0], ELEMENTS(g_aArgsSIZE_T), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
979 { "RTMemPageFree", (void *)(uintptr_t)&RTMemPageFree, &g_aArgsPTR[0], ELEMENTS(g_aArgsPTR), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
980 { "RTMemProtect", (void *)(uintptr_t)&RTMemProtect, &g_aArgsRTMemProtect[0], ELEMENTS(g_aArgsRTMemProtect), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
981 { "RTStrPrintf", (void *)(uintptr_t)&RTStrPrintf, &g_aArgsRTStrPrintf[0], ELEMENTS(g_aArgsRTStrPrintf), REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_ELLIPSIS, sizeof(size_t), NULL },
982 { "RTStrPrintfV", (void *)(uintptr_t)&RTStrPrintfV, &g_aArgsRTStrPrintfV[0], ELEMENTS(g_aArgsRTStrPrintfV), REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_VALIST, sizeof(size_t), NULL },
983 { "RTThreadNativeSelf", (void *)(uintptr_t)&RTThreadNativeSelf, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(RTNATIVETHREAD), NULL },
984};
985
986
987/**
988 * Descriptors for the functions imported from VBoxRT.
989 */
990static REMFNDESC g_aCRTImports[] =
991{
992 { "memcpy", (void *)(uintptr_t)&memcpy, &g_aArgsmemcpy[0], ELEMENTS(g_aArgsmemcpy), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
993 { "memset", (void *)(uintptr_t)&memset, &g_aArgsmemset[0], ELEMENTS(g_aArgsmemset), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL }
994/*
995floor floor
996memcpy memcpy
997sqrt sqrt
998sqrtf sqrtf
999*/
1000};
1001
1002
1003# ifdef USE_REM_CALLING_CONVENTION_GLUE
1004/** LIFO of read-write-executable memory chunks used for wrappers. */
1005static PREMEXECMEM g_pExecMemHead;
1006# endif
1007
1008
1009/*******************************************************************************
1010* Internal Functions *
1011*******************************************************************************/
1012# ifdef USE_REM_CALLING_CONVENTION_GLUE
1013DECLASM(int) WrapGCC2MSC0Int(void); DECLASM(int) WrapGCC2MSC0Int_EndProc(void);
1014DECLASM(int) WrapGCC2MSC1Int(void); DECLASM(int) WrapGCC2MSC1Int_EndProc(void);
1015DECLASM(int) WrapGCC2MSC2Int(void); DECLASM(int) WrapGCC2MSC2Int_EndProc(void);
1016DECLASM(int) WrapGCC2MSC3Int(void); DECLASM(int) WrapGCC2MSC3Int_EndProc(void);
1017DECLASM(int) WrapGCC2MSC4Int(void); DECLASM(int) WrapGCC2MSC4Int_EndProc(void);
1018DECLASM(int) WrapGCC2MSC5Int(void); DECLASM(int) WrapGCC2MSC5Int_EndProc(void);
1019DECLASM(int) WrapGCC2MSC6Int(void); DECLASM(int) WrapGCC2MSC6Int_EndProc(void);
1020DECLASM(int) WrapGCC2MSC7Int(void); DECLASM(int) WrapGCC2MSC7Int_EndProc(void);
1021DECLASM(int) WrapGCC2MSC8Int(void); DECLASM(int) WrapGCC2MSC8Int_EndProc(void);
1022DECLASM(int) WrapGCC2MSC9Int(void); DECLASM(int) WrapGCC2MSC9Int_EndProc(void);
1023DECLASM(int) WrapGCC2MSC10Int(void); DECLASM(int) WrapGCC2MSC10Int_EndProc(void);
1024DECLASM(int) WrapGCC2MSC11Int(void); DECLASM(int) WrapGCC2MSC11Int_EndProc(void);
1025DECLASM(int) WrapGCC2MSC12Int(void); DECLASM(int) WrapGCC2MSC12Int_EndProc(void);
1026DECLASM(int) WrapGCC2MSCVariadictInt(void); DECLASM(int) WrapGCC2MSCVariadictInt_EndProc(void);
1027
1028DECLASM(int) WrapMSC2GCC0Int(void); DECLASM(int) WrapMSC2GCC0Int_EndProc(void);
1029DECLASM(int) WrapMSC2GCC1Int(void); DECLASM(int) WrapMSC2GCC1Int_EndProc(void);
1030DECLASM(int) WrapMSC2GCC2Int(void); DECLASM(int) WrapMSC2GCC2Int_EndProc(void);
1031DECLASM(int) WrapMSC2GCC3Int(void); DECLASM(int) WrapMSC2GCC3Int_EndProc(void);
1032DECLASM(int) WrapMSC2GCC4Int(void); DECLASM(int) WrapMSC2GCC4Int_EndProc(void);
1033DECLASM(int) WrapMSC2GCC5Int(void); DECLASM(int) WrapMSC2GCC5Int_EndProc(void);
1034DECLASM(int) WrapMSC2GCC6Int(void); DECLASM(int) WrapMSC2GCC6Int_EndProc(void);
1035DECLASM(int) WrapMSC2GCC7Int(void); DECLASM(int) WrapMSC2GCC7Int_EndProc(void);
1036DECLASM(int) WrapMSC2GCC8Int(void); DECLASM(int) WrapMSC2GCC8Int_EndProc(void);
1037DECLASM(int) WrapMSC2GCC9Int(void); DECLASM(int) WrapMSC2GCC9Int_EndProc(void);
1038# endif
1039
1040
1041# ifdef USE_REM_CALLING_CONVENTION_GLUE
1042/**
1043 * Allocates a block of memory for glue code.
1044 *
1045 * The returned memory is padded with INT3s.
1046 *
1047 * @returns Pointer to the allocated memory.
1048 * @param The amount of memory to allocate.
1049 */
1050static void *remAllocGlue(size_t cb)
1051{
1052 PREMEXECMEM pCur = g_pExecMemHead;
1053 uint32_t cbAligned = (uint32_t)RT_ALIGN_32(cb, 32);
1054 while (pCur)
1055 {
1056 if (pCur->cb - pCur->off >= cbAligned)
1057 {
1058 void *pv = (uint8_t *)pCur + pCur->off;
1059 pCur->off += cbAligned;
1060 return memset(pv, 0xcc, cbAligned);
1061 }
1062 pCur = pCur->pNext;
1063 }
1064
1065 /* add a new chunk */
1066 AssertReturn(_64K - RT_ALIGN_Z(sizeof(*pCur), 32) > cbAligned, NULL);
1067 pCur = (PREMEXECMEM)RTMemExecAlloc(_64K);
1068 AssertReturn(pCur, NULL);
1069 pCur->cb = _64K;
1070 pCur->off = RT_ALIGN_32(sizeof(*pCur), 32) + cbAligned;
1071 pCur->pNext = g_pExecMemHead;
1072 g_pExecMemHead = pCur;
1073 return memset((uint8_t *)pCur + RT_ALIGN_Z(sizeof(*pCur), 32), 0xcc, cbAligned);
1074}
1075
1076
1077/**
1078 * Checks if a function is all straight forward integers.
1079 *
1080 * @returns True if it's simple, false if it's bothersome.
1081 * @param pDesc The function descriptor.
1082 */
1083static bool remIsFunctionAllInts(PCREMFNDESC pDesc)
1084{
1085 if ( ( (pDesc->fFlags & REMFNDESC_FLAGS_RET_TYPE_MASK) != REMFNDESC_FLAGS_RET_INT
1086 || pDesc->cbReturn > sizeof(uint64_t))
1087 && (pDesc->fFlags & REMFNDESC_FLAGS_RET_TYPE_MASK) != REMFNDESC_FLAGS_RET_VOID)
1088 return false;
1089 unsigned i = pDesc->cParams;
1090 while (i-- > 0)
1091 switch (pDesc->paParams[i].fFlags & REMPARMDESC_FLAGS_TYPE_MASK)
1092 {
1093 case REMPARMDESC_FLAGS_INT:
1094 case REMPARMDESC_FLAGS_GCPTR:
1095 case REMPARMDESC_FLAGS_GCPHYS:
1096 case REMPARMDESC_FLAGS_HCPHYS:
1097 break;
1098
1099 default:
1100 AssertReleaseMsgFailed(("Invalid param flags %#x for #%d of %s!\n", pDesc->paParams[i].fFlags, i, pDesc->pszName));
1101 case REMPARMDESC_FLAGS_VALIST:
1102 case REMPARMDESC_FLAGS_ELLIPSIS:
1103 case REMPARMDESC_FLAGS_FLOAT:
1104 case REMPARMDESC_FLAGS_STRUCT:
1105 return false;
1106 }
1107 return true;
1108}
1109
1110
1111/**
1112 * Checks if the function has an ellipsis (...) argument.
1113 *
1114 * @returns true if it has an ellipsis, otherwise false.
1115 * @param pDesc The function descriptor.
1116 */
1117static bool remHasFunctionEllipsis(PCREMFNDESC pDesc)
1118{
1119 unsigned i = pDesc->cParams;
1120 while (i-- > 0)
1121 if ((pDesc->paParams[i].fFlags & REMPARMDESC_FLAGS_TYPE_MASK) == REMPARMDESC_FLAGS_ELLIPSIS)
1122 return true;
1123 return false;
1124}
1125
1126
1127/**
1128 * Checks if the function uses floating point (FP) arguments or return value.
1129 *
1130 * @returns true if it uses floating point, otherwise false.
1131 * @param pDesc The function descriptor.
1132 */
1133static bool remIsFunctionUsingFP(PCREMFNDESC pDesc)
1134{
1135 if ((pDesc->fFlags & REMFNDESC_FLAGS_RET_TYPE_MASK) == REMFNDESC_FLAGS_RET_FLOAT)
1136 return true;
1137 unsigned i = pDesc->cParams;
1138 while (i-- > 0)
1139 if ((pDesc->paParams[i].fFlags & REMPARMDESC_FLAGS_TYPE_MASK) == REMPARMDESC_FLAGS_FLOAT)
1140 return true;
1141 return false;
1142}
1143
1144
1145/**
1146 * Fixes export glue.
1147 *
1148 * @param pvGlue The glue code.
1149 * @param cb The size of the glue code.
1150 * @param pvExport The address of the export we're wrapping.
1151 * @param pDesc The export descriptor.
1152 */
1153static void remGenerateExportGlueFixup(void *pvGlue, size_t cb, uintptr_t uExport, PCREMFNDESC pDesc)
1154{
1155 union
1156 {
1157 uint8_t *pu8;
1158 int32_t *pi32;
1159 uint32_t *pu32;
1160 uint64_t *pu64;
1161 void *pv;
1162 } u;
1163 u.pv = pvGlue;
1164
1165 while (cb >= 4)
1166 {
1167 if (*u.pu32 == 0xdeadbeef)
1168 {
1169 /* 32-bit rel jmp/call to real export. */
1170 *u.pi32 = uExport - (uintptr_t)(u.pi32 + 1);
1171 Assert((uintptr_t)(u.pi32 + 1) + *u.pi32 == uExport);
1172 u.pi32++;
1173 cb -= 4;
1174 continue;
1175 }
1176 if (cb >= 8 && *u.pu64 == UINT64_C(0xdeadf00df00ddead))
1177 {
1178 /* 64-bit address to the real export. */
1179 *u.pu64++ = uExport;
1180 cb -= 8;
1181 continue;
1182 }
1183
1184 /* move on. */
1185 u.pu8++;
1186 cb--;
1187 }
1188}
1189
1190
1191/**
1192 * Fixes import glue.
1193 *
1194 * @param pvGlue The glue code.
1195 * @param cb The size of the glue code.
1196 * @param pDesc The import descriptor.
1197 */
1198static void remGenerateImportGlueFixup(void *pvGlue, size_t cb, PCREMFNDESC pDesc)
1199{
1200 union
1201 {
1202 uint8_t *pu8;
1203 int32_t *pi32;
1204 uint32_t *pu32;
1205 uint64_t *pu64;
1206 void *pv;
1207 } u;
1208 u.pv = pvGlue;
1209
1210 while (cb >= 4)
1211 {
1212 if (*u.pu32 == 0xdeadbeef)
1213 {
1214 /* 32-bit rel jmp/call to real function. */
1215 *u.pi32 = (uintptr_t)pDesc->pv - (uintptr_t)(u.pi32 + 1);
1216 Assert((uintptr_t)(u.pi32 + 1) + *u.pi32 == (uintptr_t)pDesc->pv);
1217 u.pi32++;
1218 cb -= 4;
1219 continue;
1220 }
1221 if (cb >= 8 && *u.pu64 == UINT64_C(0xdeadf00df00ddead))
1222 {
1223 /* 64-bit address to the real function. */
1224 *u.pu64++ = (uintptr_t)pDesc->pv;
1225 cb -= 8;
1226 continue;
1227 }
1228
1229 /* move on. */
1230 u.pu8++;
1231 cb--;
1232 }
1233}
1234
1235# endif /* USE_REM_CALLING_CONVENTION_GLUE */
1236
1237
1238/**
1239 * Generate wrapper glue code for an export.
1240 *
1241 * This is only used on win64 when loading a 64-bit linux module. So, on other
1242 * platforms it will not do anything.
1243 *
1244 * @returns VBox status code.
1245 * @param pValue IN: Where to get the address of the function to wrap.
1246 * OUT: Where to store the glue address.
1247 * @param pDesc The export descriptor.
1248 */
1249static int remGenerateExportGlue(PRTUINTPTR pValue, PCREMFNDESC pDesc)
1250{
1251# ifdef USE_REM_CALLING_CONVENTION_GLUE
1252 uintptr_t *ppfn = (uintptr_t *)pDesc->pv;
1253 if (!*ppfn)
1254 {
1255 if (remIsFunctionAllInts(pDesc))
1256 {
1257 static const struct { void *pvStart, *pvEnd; } s_aTemplates[] =
1258 {
1259 { (void *)&WrapMSC2GCC0Int, (void *)&WrapMSC2GCC0Int_EndProc },
1260 { (void *)&WrapMSC2GCC1Int, (void *)&WrapMSC2GCC1Int_EndProc },
1261 { (void *)&WrapMSC2GCC2Int, (void *)&WrapMSC2GCC2Int_EndProc },
1262 { (void *)&WrapMSC2GCC3Int, (void *)&WrapMSC2GCC3Int_EndProc },
1263 { (void *)&WrapMSC2GCC4Int, (void *)&WrapMSC2GCC4Int_EndProc },
1264 { (void *)&WrapMSC2GCC5Int, (void *)&WrapMSC2GCC5Int_EndProc },
1265 { (void *)&WrapMSC2GCC6Int, (void *)&WrapMSC2GCC6Int_EndProc },
1266 { (void *)&WrapMSC2GCC7Int, (void *)&WrapMSC2GCC7Int_EndProc },
1267 { (void *)&WrapMSC2GCC8Int, (void *)&WrapMSC2GCC8Int_EndProc },
1268 { (void *)&WrapMSC2GCC9Int, (void *)&WrapMSC2GCC9Int_EndProc },
1269 };
1270 const unsigned i = pDesc->cParams;
1271 AssertReleaseMsg(i < ELEMENTS(s_aTemplates), ("%d (%s)\n", i, pDesc->pszName));
1272
1273 /* duplicate the patch. */
1274 const size_t cb = (uintptr_t)s_aTemplates[i].pvEnd - (uintptr_t)s_aTemplates[i].pvStart;
1275 uint8_t *pb = (uint8_t *)remAllocGlue(cb);
1276 AssertReturn(pb, VERR_NO_MEMORY);
1277 memcpy(pb, s_aTemplates[i].pvStart, cb);
1278
1279 /* fix it up. */
1280 remGenerateExportGlueFixup(pb, cb, *pValue, pDesc);
1281 *ppfn = (uintptr_t)pb;
1282 }
1283 else
1284 {
1285 /* annoying stuff, later. */
1286#if 1
1287 AssertReleaseMsgFailed(("Not implemented! %s\n", pDesc->pszName));
1288 return VERR_NOT_IMPLEMENTED;
1289#else
1290 AssertMsg2("annoying: %s\n", pDesc->pszName);
1291 uint8_t *pb;
1292 pb = (uint8_t *)remAllocGlue(3);
1293 AssertReturn(pb, VERR_NO_MEMORY);
1294 *pb++ = 0xcc;
1295 *pb++ = 0x90;
1296 *pb++ = 0xc3;
1297 *ppfn = (uintptr_t)pb;
1298#endif
1299 }
1300 }
1301 *pValue = *ppfn;
1302 return VINF_SUCCESS;
1303# else /* !USE_REM_CALLING_CONVENTION_GLUE */
1304 return VINF_SUCCESS;
1305# endif /* !USE_REM_CALLING_CONVENTION_GLUE */
1306}
1307
1308
1309/**
1310 * Generate wrapper glue code for an import.
1311 *
1312 * This is only used on win64 when loading a 64-bit linux module. So, on other
1313 * platforms it will simply return the address of the imported function
1314 * without generating any glue code.
1315 *
1316 * @returns VBox status code.
1317 * @param pValue Where to store the glue address.
1318 * @param pDesc The export descriptor.
1319 */
1320static int remGenerateImportGlue(PRTUINTPTR pValue, PREMFNDESC pDesc)
1321{
1322# ifdef USE_REM_CALLING_CONVENTION_GLUE
1323 if (!pDesc->pvWrapper)
1324 {
1325 if (remIsFunctionAllInts(pDesc))
1326 {
1327 static const struct { void *pvStart, *pvEnd; } s_aTemplates[] =
1328 {
1329 { (void *)&WrapGCC2MSC0Int, (void *)&WrapGCC2MSC0Int_EndProc },
1330 { (void *)&WrapGCC2MSC1Int, (void *)&WrapGCC2MSC1Int_EndProc },
1331 { (void *)&WrapGCC2MSC2Int, (void *)&WrapGCC2MSC2Int_EndProc },
1332 { (void *)&WrapGCC2MSC3Int, (void *)&WrapGCC2MSC3Int_EndProc },
1333 { (void *)&WrapGCC2MSC4Int, (void *)&WrapGCC2MSC4Int_EndProc },
1334 { (void *)&WrapGCC2MSC5Int, (void *)&WrapGCC2MSC5Int_EndProc },
1335 { (void *)&WrapGCC2MSC6Int, (void *)&WrapGCC2MSC6Int_EndProc },
1336 { (void *)&WrapGCC2MSC7Int, (void *)&WrapGCC2MSC7Int_EndProc },
1337 { (void *)&WrapGCC2MSC8Int, (void *)&WrapGCC2MSC8Int_EndProc },
1338 { (void *)&WrapGCC2MSC9Int, (void *)&WrapGCC2MSC9Int_EndProc },
1339 { (void *)&WrapGCC2MSC10Int, (void *)&WrapGCC2MSC10Int_EndProc },
1340 { (void *)&WrapGCC2MSC11Int, (void *)&WrapGCC2MSC11Int_EndProc },
1341 { (void *)&WrapGCC2MSC12Int, (void *)&WrapGCC2MSC12Int_EndProc }
1342 };
1343 const unsigned i = pDesc->cParams;
1344 AssertReleaseMsg(i < ELEMENTS(s_aTemplates), ("%d (%s)\n", i, pDesc->pszName));
1345
1346 /* duplicate the patch. */
1347 const size_t cb = (uintptr_t)s_aTemplates[i].pvEnd - (uintptr_t)s_aTemplates[i].pvStart;
1348 pDesc->pvWrapper = remAllocGlue(cb);
1349 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1350 memcpy(pDesc->pvWrapper, s_aTemplates[i].pvStart, cb);
1351
1352 /* fix it up. */
1353 remGenerateImportGlueFixup((uint8_t *)pDesc->pvWrapper, cb, pDesc);
1354 }
1355 else if ( remHasFunctionEllipsis(pDesc)
1356 && !remIsFunctionUsingFP(pDesc))
1357 {
1358 /* duplicate the patch. */
1359 const size_t cb = (uintptr_t)&WrapGCC2MSCVariadictInt_EndProc - (uintptr_t)&WrapGCC2MSCVariadictInt;
1360 pDesc->pvWrapper = remAllocGlue(cb);
1361 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1362 memcpy(pDesc->pvWrapper, (void *)&WrapGCC2MSCVariadictInt, cb);
1363
1364 /* fix it up. */
1365 remGenerateImportGlueFixup((uint8_t *)pDesc->pvWrapper, cb, pDesc);
1366 }
1367 else
1368 {
1369 /* annoying stuff, later. */
1370#if 0
1371 AssertReleaseMsgFailed(("Not implemented! %s\n", pDesc->pszName));
1372 return VERR_NOT_IMPLEMENTED;
1373#else
1374 AssertMsg2("annoying: %s\n", pDesc->pszName);
1375 uint8_t *pb;
1376 pDesc->pvWrapper = pb = (uint8_t *)remAllocGlue(3);
1377 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1378 *pb++ = 0xcc;
1379 *pb++ = 0x90;
1380 *pb++ = 0xc3;
1381#endif
1382 }
1383 }
1384 *pValue = (uintptr_t)pDesc->pvWrapper;
1385
1386# else /* !USE_REM_CALLING_CONVENTION_GLUE */
1387 *pValue = (uintptr_t)pDesc->pv;
1388# endif /* !USE_REM_CALLING_CONVENTION_GLUE */
1389 return VINF_SUCCESS;
1390}
1391
1392
1393/**
1394 * Resolve an external symbol during RTLdrGetBits().
1395 *
1396 * @returns iprt status code.
1397 * @param hLdrMod The loader module handle.
1398 * @param pszModule Module name.
1399 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
1400 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
1401 * @param pValue Where to store the symbol value (address).
1402 * @param pvUser User argument.
1403 */
1404static DECLCALLBACK(int) remGetImport(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser)
1405{
1406 unsigned i;
1407 for (i = 0; i < ELEMENTS(g_aVMMImports); i++)
1408 if (!strcmp(g_aVMMImports[i].pszName, pszSymbol))
1409 return remGenerateImportGlue(pValue, &g_aVMMImports[i]);
1410 for (i = 0; i < ELEMENTS(g_aRTImports); i++)
1411 if (!strcmp(g_aRTImports[i].pszName, pszSymbol))
1412 return remGenerateImportGlue(pValue, &g_aRTImports[i]);
1413 for (i = 0; i < ELEMENTS(g_aCRTImports); i++)
1414 if (!strcmp(g_aCRTImports[i].pszName, pszSymbol))
1415 return remGenerateImportGlue(pValue, &g_aCRTImports[i]);
1416#if 1
1417 AssertMsg2("missing: %s\n", pszSymbol);
1418 return remGenerateImportGlue(pValue, &g_aCRTImports[0]);
1419#else
1420 *pValue = 0;
1421 AssertMsgFailed(("%s.%s\n", pszModule, pszSymbol));
1422 return VERR_SYMBOL_NOT_FOUND;
1423#endif
1424}
1425
1426/**
1427 * Loads the linux object, resolves all imports and exports.
1428 *
1429 * @returns VBox status code.
1430 */
1431static int remLoadLinuxObj(void)
1432{
1433 size_t offFilename;
1434 char szPath[RTPATH_MAX];
1435 int rc = RTPathProgram(szPath, sizeof(szPath) - 32);
1436 AssertRCReturn(rc, rc);
1437 offFilename = strlen(szPath);
1438
1439 /*
1440 * Load the VBoxREM2.rel object/DLL.
1441 */
1442 strcpy(&szPath[offFilename], "/VBoxREM2.rel");
1443 rc = RTLdrOpen(szPath, &g_ModREM2);
1444 if (VBOX_SUCCESS(rc))
1445 {
1446 g_pvREM2 = RTMemExecAlloc(RTLdrSize(g_ModREM2));
1447 if (g_pvREM2)
1448 {
1449 rc = RTLdrGetBits(g_ModREM2, g_pvREM2, (RTUINTPTR)g_pvREM2, remGetImport, NULL);
1450 if (VBOX_SUCCESS(rc))
1451 {
1452 /*
1453 * Resolve exports.
1454 */
1455 unsigned i;
1456 for (i = 0; i < ELEMENTS(g_aExports); i++)
1457 {
1458 RTUINTPTR Value;
1459 rc = RTLdrGetSymbolEx(g_ModREM2, g_pvREM2, (RTUINTPTR)g_pvREM2, g_aExports[i].pszName, &Value);
1460 AssertMsgRC(rc, ("%s rc=%VRc\n", g_aExports[i].pszName, rc));
1461 if (VBOX_FAILURE(rc))
1462 break;
1463 rc = remGenerateExportGlue(&Value, &g_aExports[i]);
1464 if (VBOX_FAILURE(rc))
1465 break;
1466 *(void **)g_aExports[i].pv = (void *)(uintptr_t)Value;
1467 }
1468 return rc;
1469 }
1470 RTMemExecFree(g_pvREM2);
1471 }
1472 RTLdrClose(g_ModREM2);
1473 g_ModREM2 = NIL_RTLDRMOD;
1474 }
1475 return rc;
1476}
1477
1478
1479/**
1480 * Unloads the linux object, freeing up all resources (dlls and
1481 * import glue) we allocated during remLoadLinuxObj().
1482 */
1483static void remUnloadLinuxObj(void)
1484{
1485 unsigned i;
1486
1487 /* close modules. */
1488 RTLdrClose(g_ModREM2);
1489 g_ModREM2 = NIL_RTLDRMOD;
1490 RTMemExecFree(g_pvREM2);
1491 g_pvREM2 = NULL;
1492
1493 /* clear the pointers. */
1494 for (i = 0; i < ELEMENTS(g_aExports); i++)
1495 *(void **)g_aExports[i].pv = NULL;
1496# ifdef USE_REM_CALLING_CONVENTION_GLUE
1497 for (i = 0; i < ELEMENTS(g_aVMMImports); i++)
1498 g_aVMMImports[i].pvWrapper = NULL;
1499 for (i = 0; i < ELEMENTS(g_aRTImports); i++)
1500 g_aRTImports[i].pvWrapper = NULL;
1501 for (i = 0; i < ELEMENTS(g_aCRTImports); i++)
1502 g_aCRTImports[i].pvWrapper = NULL;
1503
1504 /* free wrapper memory. */
1505 while (g_pExecMemHead)
1506 {
1507 PREMEXECMEM pCur = g_pExecMemHead;
1508 g_pExecMemHead = pCur->pNext;
1509 memset(pCur, 0xcc, pCur->cb);
1510 RTMemExecFree(pCur);
1511 }
1512# endif
1513}
1514#endif
1515
1516
1517REMR3DECL(int) REMR3Init(PVM pVM)
1518{
1519#ifdef USE_REM_STUBS
1520 return VINF_SUCCESS;
1521#else
1522 if (!pfnREMR3Init)
1523 {
1524 int rc = remLoadLinuxObj();
1525 if (VBOX_FAILURE(rc))
1526 return rc;
1527 }
1528 return pfnREMR3Init(pVM);
1529#endif
1530}
1531
1532REMR3DECL(int) REMR3Term(PVM pVM)
1533{
1534#ifdef USE_REM_STUBS
1535 return VINF_SUCCESS;
1536#else
1537 int rc;
1538 Assert(VALID_PTR(pfnREMR3Term));
1539 rc = pfnREMR3Term(pVM);
1540 remUnloadLinuxObj();
1541 return rc;
1542#endif
1543}
1544
1545REMR3DECL(void) REMR3Reset(PVM pVM)
1546{
1547#ifndef USE_REM_STUBS
1548 Assert(VALID_PTR(pfnREMR3Reset));
1549 pfnREMR3Reset(pVM);
1550#endif
1551}
1552
1553REMR3DECL(int) REMR3Step(PVM pVM)
1554{
1555#ifdef USE_REM_STUBS
1556 return VERR_NOT_IMPLEMENTED;
1557#else
1558 Assert(VALID_PTR(pfnREMR3Step));
1559 return pfnREMR3Step(pVM);
1560#endif
1561}
1562
1563REMR3DECL(int) REMR3BreakpointSet(PVM pVM, RTGCUINTPTR Address)
1564{
1565#ifdef USE_REM_STUBS
1566 return VERR_REM_NO_MORE_BP_SLOTS;
1567#else
1568 Assert(VALID_PTR(pfnREMR3BreakpointSet));
1569 return pfnREMR3BreakpointSet(pVM, Address);
1570#endif
1571}
1572
1573REMR3DECL(int) REMR3BreakpointClear(PVM pVM, RTGCUINTPTR Address)
1574{
1575#ifdef USE_REM_STUBS
1576 return VERR_NOT_IMPLEMENTED;
1577#else
1578 Assert(VALID_PTR(pfnREMR3BreakpointClear));
1579 return pfnREMR3BreakpointClear(pVM, Address);
1580#endif
1581}
1582
1583REMR3DECL(int) REMR3EmulateInstruction(PVM pVM)
1584{
1585#ifdef USE_REM_STUBS
1586 return VERR_NOT_IMPLEMENTED;
1587#else
1588 Assert(VALID_PTR(pfnREMR3EmulateInstruction));
1589 return pfnREMR3EmulateInstruction(pVM);
1590#endif
1591}
1592
1593REMR3DECL(int) REMR3Run(PVM pVM)
1594{
1595#ifdef USE_REM_STUBS
1596 return VERR_NOT_IMPLEMENTED;
1597#else
1598 Assert(VALID_PTR(pfnREMR3Run));
1599 return pfnREMR3Run(pVM);
1600#endif
1601}
1602
1603REMR3DECL(int) REMR3State(PVM pVM)
1604{
1605#ifdef USE_REM_STUBS
1606 return VERR_NOT_IMPLEMENTED;
1607#else
1608 Assert(VALID_PTR(pfnREMR3State));
1609 return pfnREMR3State(pVM);
1610#endif
1611}
1612
1613REMR3DECL(int) REMR3StateBack(PVM pVM)
1614{
1615#ifdef USE_REM_STUBS
1616 return VERR_NOT_IMPLEMENTED;
1617#else
1618 Assert(VALID_PTR(pfnREMR3StateBack));
1619 return pfnREMR3StateBack(pVM);
1620#endif
1621}
1622
1623REMR3DECL(void) REMR3StateUpdate(PVM pVM)
1624{
1625#ifndef USE_REM_STUBS
1626 Assert(VALID_PTR(pfnREMR3StateUpdate));
1627 pfnREMR3StateUpdate(pVM);
1628#endif
1629}
1630
1631REMR3DECL(void) REMR3A20Set(PVM pVM, bool fEnable)
1632{
1633#ifndef USE_REM_STUBS
1634 Assert(VALID_PTR(pfnREMR3A20Set));
1635 pfnREMR3A20Set(pVM, fEnable);
1636#endif
1637}
1638
1639REMR3DECL(void) REMR3ReplayInvalidatedPages(PVM pVM)
1640{
1641#ifndef USE_REM_STUBS
1642 Assert(VALID_PTR(pfnREMR3ReplayInvalidatedPages));
1643 pfnREMR3ReplayInvalidatedPages(pVM);
1644#endif
1645}
1646
1647REMR3DECL(int) REMR3NotifyCodePageChanged(PVM pVM, RTGCPTR pvCodePage)
1648{
1649#ifdef USE_REM_STUBS
1650 return VINF_SUCCESS;
1651#else
1652 Assert(VALID_PTR(pfnREMR3NotifyCodePageChanged));
1653 return pfnREMR3NotifyCodePageChanged(pVM, pvCodePage);
1654#endif
1655}
1656
1657REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, void *pvRam, unsigned fFlags)
1658{
1659#ifndef USE_REM_STUBS
1660 Assert(VALID_PTR(pfnREMR3NotifyPhysRamRegister));
1661 pfnREMR3NotifyPhysRamRegister(pVM, GCPhys, cb, pvRam, fFlags);
1662#endif
1663}
1664
1665REMR3DECL(void) REMR3NotifyPhysRomRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, void *pvCopy)
1666{
1667#ifndef USE_REM_STUBS
1668 Assert(VALID_PTR(pfnREMR3NotifyPhysRomRegister));
1669 pfnREMR3NotifyPhysRomRegister(pVM, GCPhys, cb, pvCopy);
1670#endif
1671}
1672
1673REMR3DECL(void) REMR3NotifyPhysReserve(PVM pVM, RTGCPHYS GCPhys, RTUINT cb)
1674{
1675#ifndef USE_REM_STUBS
1676 Assert(VALID_PTR(pfnREMR3NotifyPhysReserve));
1677 pfnREMR3NotifyPhysReserve(pVM, GCPhys, cb);
1678#endif
1679}
1680
1681REMR3DECL(void) REMR3NotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler)
1682{
1683#ifndef USE_REM_STUBS
1684 Assert(VALID_PTR(pfnREMR3NotifyHandlerPhysicalRegister));
1685 pfnREMR3NotifyHandlerPhysicalRegister(pVM, enmType, GCPhys, cb, fHasHCHandler);
1686#endif
1687}
1688
1689REMR3DECL(void) REMR3NotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler, void *pvHCPtr)
1690{
1691#ifndef USE_REM_STUBS
1692 Assert(VALID_PTR(pfnREMR3NotifyHandlerPhysicalDeregister));
1693 pfnREMR3NotifyHandlerPhysicalDeregister(pVM, enmType, GCPhys, cb, fHasHCHandler, pvHCPtr);
1694#endif
1695}
1696
1697REMR3DECL(void) REMR3NotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fHasHCHandler, void *pvHCPtr)
1698{
1699#ifndef USE_REM_STUBS
1700 Assert(VALID_PTR(pfnREMR3NotifyHandlerPhysicalModify));
1701 pfnREMR3NotifyHandlerPhysicalModify(pVM, enmType, GCPhysOld, GCPhysNew, cb, fHasHCHandler, pvHCPtr);
1702#endif
1703}
1704
1705REMDECL(bool) REMR3IsPageAccessHandled(PVM pVM, RTGCPHYS GCPhys)
1706{
1707#ifdef USE_REM_STUBS
1708 return false;
1709#else
1710 Assert(VALID_PTR(pfnREMR3IsPageAccessHandled));
1711 return pfnREMR3IsPageAccessHandled(pVM, GCPhys);
1712#endif
1713}
1714
1715REMR3DECL(int) REMR3DisasEnableStepping(PVM pVM, bool fEnable)
1716{
1717#ifdef USE_REM_STUBS
1718 return VERR_NOT_IMPLEMENTED;
1719#else
1720 Assert(VALID_PTR(pfnREMR3DisasEnableStepping));
1721 return pfnREMR3DisasEnableStepping(pVM, fEnable);
1722#endif
1723}
1724
1725REMR3DECL(void) REMR3NotifyPendingInterrupt(PVM pVM, uint8_t u8Interrupt)
1726{
1727#ifndef USE_REM_STUBS
1728 Assert(VALID_PTR(pfnREMR3NotifyPendingInterrupt));
1729 pfnREMR3NotifyPendingInterrupt(pVM, u8Interrupt);
1730#endif
1731}
1732
1733REMR3DECL(uint32_t) REMR3QueryPendingInterrupt(PVM pVM)
1734{
1735#ifdef USE_REM_STUBS
1736 return REM_NO_PENDING_IRQ;
1737#else
1738 Assert(VALID_PTR(pfnREMR3QueryPendingInterrupt));
1739 return pfnREMR3QueryPendingInterrupt(pVM);
1740#endif
1741}
1742
1743REMR3DECL(void) REMR3NotifyInterruptSet(PVM pVM)
1744{
1745#ifndef USE_REM_STUBS
1746 Assert(VALID_PTR(pfnREMR3NotifyInterruptSet));
1747 pfnREMR3NotifyInterruptSet(pVM);
1748#endif
1749}
1750
1751REMR3DECL(void) REMR3NotifyInterruptClear(PVM pVM)
1752{
1753#ifndef USE_REM_STUBS
1754 Assert(VALID_PTR(pfnREMR3NotifyInterruptClear));
1755 pfnREMR3NotifyInterruptClear(pVM);
1756#endif
1757}
1758
1759REMR3DECL(void) REMR3NotifyTimerPending(PVM pVM)
1760{
1761#ifndef USE_REM_STUBS
1762 Assert(VALID_PTR(pfnREMR3NotifyTimerPending));
1763 pfnREMR3NotifyTimerPending(pVM);
1764#endif
1765}
1766
1767REMR3DECL(void) REMR3NotifyDmaPending(PVM pVM)
1768{
1769#ifndef USE_REM_STUBS
1770 Assert(VALID_PTR(pfnREMR3NotifyDmaPending));
1771 pfnREMR3NotifyDmaPending(pVM);
1772#endif
1773}
1774
1775REMR3DECL(void) REMR3NotifyQueuePending(PVM pVM)
1776{
1777#ifndef USE_REM_STUBS
1778 Assert(VALID_PTR(pfnREMR3NotifyQueuePending));
1779 pfnREMR3NotifyQueuePending(pVM);
1780#endif
1781}
1782
1783REMR3DECL(void) REMR3NotifyFF(PVM pVM)
1784{
1785#ifndef USE_REM_STUBS
1786 /* the timer can call this early on, so don't be picky. */
1787 if (pfnREMR3NotifyFF)
1788 pfnREMR3NotifyFF(pVM);
1789#endif
1790}
1791
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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