VirtualBox

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

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

Import jump glue is required for GCC on Linux/GNU.

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

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