VirtualBox

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

Last change on this file since 942 was 942, checked in by vboxsync, 18 years ago

RTAssertDoBreakpoint

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

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