VirtualBox

source: vbox/trunk/src/recompiler/VBoxREMWrapper.cpp@ 4663

Last change on this file since 4663 was 4616, checked in by vboxsync, 17 years ago

Ditto for REM(R3)NotifyHandlerPhysicalDeregister.

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