VirtualBox

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

Last change on this file since 7233 was 6546, checked in by vboxsync, 17 years ago

VBOX_WITH_NEW_PHYS_CODE changes mostly realted to REM. Killed a warning in cpu-exec.c.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 104.8 KB
Line 
1/* $Id: VBoxREMWrapper.cpp 6546 2008-01-28 21:58:59Z 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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/** @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 RT_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 RT_BIT(6)
290/** The function has an ellipsis (i.e. a problem). */
291#define REMFNDESC_FLAGS_ELLIPSIS RT_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, 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
492static const REMPARMDESC g_aArgsCSAMR3RecordCallAddress[] =
493{
494 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
495 { REMPARMDESC_FLAGS_INT, sizeof(RTGCPTR), NULL }
496};
497
498#if defined(VBOX_WITH_DEBUGGER) && !(defined(RT_OS_WINDOWS) && defined(RT_ARCH_AMD64)) /* the callbacks are problematic */
499static const REMPARMDESC g_aArgsDBGCRegisterCommands[] =
500{
501 { REMPARMDESC_FLAGS_INT, sizeof(PCDBGCCMD), NULL },
502 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL }
503};
504#endif
505static const REMPARMDESC g_aArgsDBGFR3DisasInstrEx[] =
506{
507 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
508 { REMPARMDESC_FLAGS_INT, sizeof(RTSEL), NULL },
509 { REMPARMDESC_FLAGS_INT, sizeof(RTGCPTR), NULL },
510 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
511 { REMPARMDESC_FLAGS_INT, sizeof(char *), NULL },
512 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
513 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *), NULL }
514};
515static const REMPARMDESC g_aArgsDBGFR3Info[] =
516{
517 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
518 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
519 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
520 { REMPARMDESC_FLAGS_INT, sizeof(PCDBGFINFOHLP), NULL }
521};
522static const REMPARMDESC g_aArgsDBGFR3SymbolByAddr[] =
523{
524 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
525 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINTPTR), NULL },
526 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCINTPTR), NULL },
527 { REMPARMDESC_FLAGS_INT, sizeof(PDBGFSYMBOL), NULL }
528};
529static const REMPARMDESC g_aArgsDISInstr[] =
530{
531 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
532 { REMPARMDESC_FLAGS_INT, sizeof(RTUINTPTR), NULL },
533 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
534 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *), NULL },
535 { REMPARMDESC_FLAGS_INT, sizeof(char *), NULL }
536};
537static const REMPARMDESC g_aArgsEMR3FatalError[] =
538{
539 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
540 { REMPARMDESC_FLAGS_INT, sizeof(int), NULL }
541};
542static const REMPARMDESC g_aArgsHWACCMR3CanExecuteGuest[] =
543{
544 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
545 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
546 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
547 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL }
548};
549static const REMPARMDESC g_aArgsIOMIOPortRead[] =
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_aArgsIOMIOPortWrite[] =
557{
558 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
559 { REMPARMDESC_FLAGS_INT, sizeof(RTIOPORT), NULL },
560 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
561 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL }
562};
563static const REMPARMDESC g_aArgsIOMMMIORead[] =
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_aArgsIOMMMIOWrite[] =
571{
572 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
573 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
574 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
575 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL }
576};
577static const REMPARMDESC g_aArgsMMR3HeapAlloc[] =
578{
579 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
580 { REMPARMDESC_FLAGS_INT, sizeof(MMTAG), NULL },
581 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL }
582};
583static const REMPARMDESC g_aArgsMMR3HeapAllocZ[] =
584{
585 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
586 { REMPARMDESC_FLAGS_INT, sizeof(MMTAG), NULL },
587 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL }
588};
589static const REMPARMDESC g_aArgsPATMIsPatchGCAddr[] =
590{
591 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
592 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR), NULL }
593};
594static const REMPARMDESC g_aArgsPATMR3QueryOpcode[] =
595{
596 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
597 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR), NULL },
598 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *), NULL }
599};
600static const REMPARMDESC g_aArgsPATMR3QueryPatchMem[] =
601{
602 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
603 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *), NULL }
604};
605static const REMPARMDESC g_aArgsPDMApicGetBase[] =
606{
607 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
608 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t *), NULL }
609};
610static const REMPARMDESC g_aArgsPDMApicGetTPR[] =
611{
612 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
613 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *), NULL }
614};
615static const REMPARMDESC g_aArgsPDMApicSetBase[] =
616{
617 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
618 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t), NULL }
619};
620static const REMPARMDESC g_aArgsPDMApicSetTPR[] =
621{
622 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
623 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t), NULL }
624};
625static const REMPARMDESC g_aArgsPDMGetInterrupt[] =
626{
627 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
628 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *), NULL }
629};
630static const REMPARMDESC g_aArgsPDMIsaSetIrq[] =
631{
632 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
633 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t), NULL },
634 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t), NULL }
635};
636static const REMPARMDESC g_aArgsPGMGstGetPage[] =
637{
638 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
639 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR), NULL },
640 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t *), NULL },
641 { REMPARMDESC_FLAGS_INT, sizeof(PRTGCPHYS), NULL }
642};
643static const REMPARMDESC g_aArgsPGMInvalidatePage[] =
644{
645 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
646 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR), NULL }
647};
648static const REMPARMDESC g_aArgsPGMPhysGCPhys2HCPtr[] =
649{
650 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
651 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
652 { REMPARMDESC_FLAGS_INT, sizeof(RTUINT), NULL },
653 { REMPARMDESC_FLAGS_INT, sizeof(PRTHCPTR), NULL }
654};
655static const REMPARMDESC g_aArgsPGMPhysGCPtr2HCPtrByGstCR3[] =
656{
657 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
658 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
659 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
660 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
661 { REMPARMDESC_FLAGS_INT, sizeof(PRTHCPTR), NULL }
662};
663static const REMPARMDESC g_aArgsPGM3PhysGrowRange[] =
664{
665 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
666 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL }
667};
668static const REMPARMDESC g_aArgsPGMPhysIsGCPhysValid[] =
669{
670 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
671 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL }
672};
673static const REMPARMDESC g_aArgsPGMPhysRead[] =
674{
675 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
676 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
677 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
678 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
679};
680static const REMPARMDESC g_aArgsPGMPhysReadGCPtr[] =
681{
682 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
683 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
684 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR), NULL },
685 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
686};
687static const REMPARMDESC g_aArgsPGMPhysWrite[] =
688{
689 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
690 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
691 { REMPARMDESC_FLAGS_INT, sizeof(const void *), NULL },
692 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
693};
694static const REMPARMDESC g_aArgsPGMChangeMode[] =
695{
696 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
697 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
698 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
699 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t), NULL }
700};
701static const REMPARMDESC g_aArgsPGMFlushTLB[] =
702{
703 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
704 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
705 { REMPARMDESC_FLAGS_INT, sizeof(bool), NULL }
706};
707static const REMPARMDESC g_aArgsPGMR3PhysReadUxx[] =
708{
709 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
710 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL }
711};
712static const REMPARMDESC g_aArgsPGMR3PhysWriteU8[] =
713{
714 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
715 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
716 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t), NULL }
717};
718static const REMPARMDESC g_aArgsPGMR3PhysWriteU16[] =
719{
720 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
721 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
722 { REMPARMDESC_FLAGS_INT, sizeof(uint16_t), NULL }
723};
724static const REMPARMDESC g_aArgsPGMR3PhysWriteU32[] =
725{
726 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
727 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
728 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL }
729};
730static const REMPARMDESC g_aArgsPGMR3PhysWriteU64[] =
731{
732 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
733 { REMPARMDESC_FLAGS_GCPHYS, sizeof(RTGCPHYS), NULL },
734 { REMPARMDESC_FLAGS_INT, sizeof(uint64_t), NULL }
735};
736static const REMPARMDESC g_aArgsSSMR3GetGCPtr[] =
737{
738 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
739 { REMPARMDESC_FLAGS_INT, sizeof(PRTGCPTR), NULL }
740};
741static const REMPARMDESC g_aArgsSSMR3GetMem[] =
742{
743 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
744 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
745 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
746};
747static const REMPARMDESC g_aArgsSSMR3GetU32[] =
748{
749 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
750 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t *), NULL }
751};
752static const REMPARMDESC g_aArgsSSMR3GetUInt[] =
753{
754 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
755 { REMPARMDESC_FLAGS_INT, sizeof(PRTUINT), NULL }
756};
757static const REMPARMDESC g_aArgsSSMR3PutGCPtr[] =
758{
759 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
760 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCPTR), NULL }
761};
762static const REMPARMDESC g_aArgsSSMR3PutMem[] =
763{
764 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
765 { REMPARMDESC_FLAGS_INT, sizeof(const void *), NULL },
766 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
767};
768static const REMPARMDESC g_aArgsSSMR3PutU32[] =
769{
770 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
771 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
772};
773static const REMPARMDESC g_aArgsSSMR3PutUInt[] =
774{
775 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
776 { REMPARMDESC_FLAGS_INT, sizeof(RTUINT), NULL },
777};
778
779static const REMPARMDESC g_aArgsSSMIntCallback[] =
780{
781 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
782 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
783};
784static REMFNDESC g_SSMIntCallback =
785{
786 "SSMIntCallback", NULL, &g_aArgsSSMIntCallback[0], ELEMENTS(g_aArgsSSMIntCallback), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL
787};
788
789static const REMPARMDESC g_aArgsSSMIntLoadExecCallback[] =
790{
791 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
792 { REMPARMDESC_FLAGS_INT, sizeof(PSSMHANDLE), NULL },
793 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
794};
795static REMFNDESC g_SSMIntLoadExecCallback =
796{
797 "SSMIntLoadExecCallback", NULL, &g_aArgsSSMIntLoadExecCallback[0], ELEMENTS(g_aArgsSSMIntLoadExecCallback), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL
798};
799static const REMPARMDESC g_aArgsSSMR3RegisterInternal[] =
800{
801 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
802 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
803 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
804 { REMPARMDESC_FLAGS_INT, sizeof(uint32_t), NULL },
805 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL },
806 { REMPARMDESC_FLAGS_PFN, sizeof(PFNSSMINTSAVEPREP), &g_SSMIntCallback },
807 { REMPARMDESC_FLAGS_PFN, sizeof(PFNSSMINTSAVEEXEC), &g_SSMIntCallback },
808 { REMPARMDESC_FLAGS_PFN, sizeof(PFNSSMINTSAVEDONE), &g_SSMIntCallback },
809 { REMPARMDESC_FLAGS_PFN, sizeof(PFNSSMINTLOADPREP), &g_SSMIntCallback },
810 { REMPARMDESC_FLAGS_PFN, sizeof(PFNSSMINTLOADEXEC), &g_SSMIntLoadExecCallback },
811 { REMPARMDESC_FLAGS_PFN, sizeof(PFNSSMINTLOADDONE), &g_SSMIntCallback },
812};
813
814static const REMPARMDESC g_aArgsSTAMR3Register[] =
815{
816 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
817 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
818 { REMPARMDESC_FLAGS_INT, sizeof(STAMTYPE), NULL },
819 { REMPARMDESC_FLAGS_INT, sizeof(STAMVISIBILITY), NULL },
820 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
821 { REMPARMDESC_FLAGS_INT, sizeof(STAMUNIT), NULL },
822 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL }
823};
824static const REMPARMDESC g_aArgsTRPMAssertTrap[] =
825{
826 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
827 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t), NULL },
828 { REMPARMDESC_FLAGS_INT, sizeof(TRPMEVENT), NULL }
829};
830static const REMPARMDESC g_aArgsTRPMQueryTrap[] =
831{
832 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
833 { REMPARMDESC_FLAGS_INT, sizeof(uint8_t *), NULL },
834 { REMPARMDESC_FLAGS_INT, sizeof(TRPMEVENT *), NULL }
835};
836static const REMPARMDESC g_aArgsTRPMSetErrorCode[] =
837{
838 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
839 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINT), NULL }
840};
841static const REMPARMDESC g_aArgsTRPMSetFaultAddress[] =
842{
843 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
844 { REMPARMDESC_FLAGS_GCPTR, sizeof(RTGCUINT), NULL }
845};
846static const REMPARMDESC g_aArgsVMR3ReqCall[] =
847{
848 { REMPARMDESC_FLAGS_INT, sizeof(PVM), NULL },
849 { REMPARMDESC_FLAGS_INT, sizeof(PVMREQ *), NULL },
850 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
851 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
852 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
853 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
854};
855static const REMPARMDESC g_aArgsVMR3ReqFree[] =
856{
857 { REMPARMDESC_FLAGS_INT, sizeof(PVMREQ), NULL }
858};
859
860
861/* IPRT args */
862static const REMPARMDESC g_aArgsAssertMsg1[] =
863{
864 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
865 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
866 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
867 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL }
868};
869static const REMPARMDESC g_aArgsAssertMsg2[] =
870{
871 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
872 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
873};
874static const REMPARMDESC g_aArgsRTLogFlags[] =
875{
876 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER), NULL },
877 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL }
878};
879static const REMPARMDESC g_aArgsRTLogFlush[] =
880{
881 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER), NULL }
882};
883static const REMPARMDESC g_aArgsRTLogLoggerEx[] =
884{
885 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER), NULL },
886 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
887 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
888 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
889 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
890};
891static const REMPARMDESC g_aArgsRTLogLoggerExV[] =
892{
893 { REMPARMDESC_FLAGS_INT, sizeof(PRTLOGGER), NULL },
894 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
895 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL },
896 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
897 { REMPARMDESC_FLAGS_VALIST, 0 }
898};
899static const REMPARMDESC g_aArgsRTLogPrintf[] =
900{
901 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
902 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
903};
904static const REMPARMDESC g_aArgsRTMemProtect[] =
905{
906 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
907 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL },
908 { REMPARMDESC_FLAGS_INT, sizeof(unsigned), NULL }
909};
910static const REMPARMDESC g_aArgsRTStrPrintf[] =
911{
912 { REMPARMDESC_FLAGS_INT, sizeof(char *), NULL },
913 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL },
914 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
915 { REMPARMDESC_FLAGS_ELLIPSIS, 0 }
916};
917static const REMPARMDESC g_aArgsRTStrPrintfV[] =
918{
919 { REMPARMDESC_FLAGS_INT, sizeof(char *), NULL },
920 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL },
921 { REMPARMDESC_FLAGS_INT, sizeof(const char *), NULL },
922 { REMPARMDESC_FLAGS_VALIST, 0 }
923};
924
925
926/* CRT args */
927static const REMPARMDESC g_aArgsmemcpy[] =
928{
929 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
930 { REMPARMDESC_FLAGS_INT, sizeof(const void *), NULL },
931 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
932};
933static const REMPARMDESC g_aArgsmemset[] =
934{
935 { REMPARMDESC_FLAGS_INT, sizeof(void *), NULL },
936 { REMPARMDESC_FLAGS_INT, sizeof(int), NULL },
937 { REMPARMDESC_FLAGS_INT, sizeof(size_t), NULL }
938};
939
940
941/** @} */
942
943/**
944 * Descriptors for the exported functions.
945 */
946static const REMFNDESC g_aExports[] =
947{ /* pszName, (void *)pv, pParams, cParams, fFlags, cb, pvWrapper. */
948 { "REMR3Init", (void *)&pfnREMR3Init, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
949 { "REMR3Term", (void *)&pfnREMR3Term, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
950 { "REMR3Reset", (void *)&pfnREMR3Reset, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
951 { "REMR3Step", (void *)&pfnREMR3Step, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
952 { "REMR3BreakpointSet", (void *)&pfnREMR3BreakpointSet, &g_aArgsBreakpoint[0], ELEMENTS(g_aArgsBreakpoint), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
953 { "REMR3BreakpointClear", (void *)&pfnREMR3BreakpointClear, &g_aArgsBreakpoint[0], ELEMENTS(g_aArgsBreakpoint), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
954 { "REMR3EmulateInstruction", (void *)&pfnREMR3EmulateInstruction, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
955 { "REMR3Run", (void *)&pfnREMR3Run, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
956 { "REMR3State", (void *)&pfnREMR3State, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
957 { "REMR3StateBack", (void *)&pfnREMR3StateBack, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
958 { "REMR3StateUpdate", (void *)&pfnREMR3StateUpdate, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
959 { "REMR3A20Set", (void *)&pfnREMR3A20Set, &g_aArgsA20Set[0], ELEMENTS(g_aArgsA20Set), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
960 { "REMR3ReplayInvalidatedPages", (void *)&pfnREMR3ReplayInvalidatedPages, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
961 { "REMR3ReplayHandlerNotifications", (void *)&pfnREMR3ReplayHandlerNotifications, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
962 { "REMR3NotifyPhysRamRegister", (void *)&pfnREMR3NotifyPhysRamRegister, &g_aArgsNotifyPhysRamRegister[0], ELEMENTS(g_aArgsNotifyPhysRamRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
963 { "REMR3NotifyPhysRamChunkRegister", (void *)&pfnREMR3NotifyPhysRamChunkRegister, &g_aArgsNotifyPhysRamChunkRegister[0], ELEMENTS(g_aArgsNotifyPhysRamChunkRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
964 { "REMR3NotifyPhysReserve", (void *)&pfnREMR3NotifyPhysReserve, &g_aArgsNotifyPhysReserve[0], ELEMENTS(g_aArgsNotifyPhysReserve), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
965 { "REMR3NotifyPhysRomRegister", (void *)&pfnREMR3NotifyPhysRomRegister, &g_aArgsNotifyPhysRomRegister[0], ELEMENTS(g_aArgsNotifyPhysRomRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
966 { "REMR3NotifyHandlerPhysicalModify", (void *)&pfnREMR3NotifyHandlerPhysicalModify, &g_aArgsNotifyHandlerPhysicalModify[0], ELEMENTS(g_aArgsNotifyHandlerPhysicalModify), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
967 { "REMR3NotifyHandlerPhysicalRegister", (void *)&pfnREMR3NotifyHandlerPhysicalRegister, &g_aArgsNotifyHandlerPhysicalRegister[0], ELEMENTS(g_aArgsNotifyHandlerPhysicalRegister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
968 { "REMR3NotifyHandlerPhysicalDeregister", (void *)&pfnREMR3NotifyHandlerPhysicalDeregister, &g_aArgsNotifyHandlerPhysicalDeregister[0], ELEMENTS(g_aArgsNotifyHandlerPhysicalDeregister), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
969 { "REMR3NotifyInterruptSet", (void *)&pfnREMR3NotifyInterruptSet, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
970 { "REMR3NotifyInterruptClear", (void *)&pfnREMR3NotifyInterruptClear, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
971 { "REMR3NotifyTimerPending", (void *)&pfnREMR3NotifyTimerPending, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
972 { "REMR3NotifyDmaPending", (void *)&pfnREMR3NotifyDmaPending, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
973 { "REMR3NotifyQueuePending", (void *)&pfnREMR3NotifyQueuePending, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
974 { "REMR3NotifyFF", (void *)&pfnREMR3NotifyFF, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
975 { "REMR3NotifyCodePageChanged", (void *)&pfnREMR3NotifyCodePageChanged, &g_aArgsNotifyCodePageChanged[0], ELEMENTS(g_aArgsNotifyCodePageChanged), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
976 { "REMR3NotifyPendingInterrupt", (void *)&pfnREMR3NotifyPendingInterrupt, &g_aArgsNotifyPendingInterrupt[0], ELEMENTS(g_aArgsNotifyPendingInterrupt), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
977 { "REMR3QueryPendingInterrupt", (void *)&pfnREMR3QueryPendingInterrupt, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
978 { "REMR3DisasEnableStepping", (void *)&pfnREMR3DisasEnableStepping, &g_aArgsDisasEnableStepping[0], ELEMENTS(g_aArgsDisasEnableStepping), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
979 { "REMR3IsPageAccessHandled", (void *)&pfnREMR3IsPageAccessHandled, &g_aArgsIsPageAccessHandled[0], ELEMENTS(g_aArgsIsPageAccessHandled), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL }
980};
981
982
983/**
984 * Descriptors for the functions imported from VBoxVMM.
985 */
986static REMFNDESC g_aVMMImports[] =
987{
988 { "CPUMAreHiddenSelRegsValid", (void *)(uintptr_t)&CPUMAreHiddenSelRegsValid, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
989 { "CPUMGetAndClearChangedFlagsREM", (void *)(uintptr_t)&CPUMGetAndClearChangedFlagsREM, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(unsigned), NULL },
990 { "CPUMGetGuestCPL", (void *)(uintptr_t)&CPUMGetGuestCPL, &g_aArgsCPUMGetGuestCpl[0], ELEMENTS(g_aArgsCPUMGetGuestCpl), REMFNDESC_FLAGS_RET_INT, sizeof(unsigned), NULL },
991 { "CPUMGetGuestCpuId", (void *)(uintptr_t)&CPUMGetGuestCpuId, &g_aArgsCPUMGetGuestCpuId[0], ELEMENTS(g_aArgsCPUMGetGuestCpuId), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
992 { "CPUMGetGuestEAX", (void *)(uintptr_t)&CPUMGetGuestEAX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
993 { "CPUMGetGuestEBP", (void *)(uintptr_t)&CPUMGetGuestEBP, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
994 { "CPUMGetGuestEBX", (void *)(uintptr_t)&CPUMGetGuestEBX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
995 { "CPUMGetGuestECX", (void *)(uintptr_t)&CPUMGetGuestECX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
996 { "CPUMGetGuestEDI", (void *)(uintptr_t)&CPUMGetGuestEDI, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
997 { "CPUMGetGuestEDX", (void *)(uintptr_t)&CPUMGetGuestEDX, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
998 { "CPUMGetGuestEIP", (void *)(uintptr_t)&CPUMGetGuestEIP, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
999 { "CPUMGetGuestESI", (void *)(uintptr_t)&CPUMGetGuestESI, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
1000 { "CPUMGetGuestESP", (void *)(uintptr_t)&CPUMGetGuestESP, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
1001 { "CPUMQueryGuestCtxPtr", (void *)(uintptr_t)&CPUMQueryGuestCtxPtr, &g_aArgsCPUMQueryGuestCtxPtr[0], ELEMENTS(g_aArgsCPUMQueryGuestCtxPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1002 { "CSAMR3MonitorPage", (void *)(uintptr_t)&CSAMR3MonitorPage, &g_aArgsCSAMR3MonitorPage[0], ELEMENTS(g_aArgsCSAMR3MonitorPage), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1003 { "CSAMR3RecordCallAddress", (void *)(uintptr_t)&CSAMR3RecordCallAddress, &g_aArgsCSAMR3RecordCallAddress[0], ELEMENTS(g_aArgsCSAMR3RecordCallAddress), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1004#if defined(VBOX_WITH_DEBUGGER) && !(defined(RT_OS_WINDOWS) && defined(RT_ARCH_AMD64)) /* the callbacks are problematic */
1005 { "DBGCRegisterCommands", (void *)(uintptr_t)&DBGCRegisterCommands, &g_aArgsDBGCRegisterCommands[0], ELEMENTS(g_aArgsDBGCRegisterCommands), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1006#endif
1007 { "DBGFR3DisasInstrEx", (void *)(uintptr_t)&DBGFR3DisasInstrEx, &g_aArgsDBGFR3DisasInstrEx[0], ELEMENTS(g_aArgsDBGFR3DisasInstrEx), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1008 { "DBGFR3Info", (void *)(uintptr_t)&DBGFR3Info, &g_aArgsDBGFR3Info[0], ELEMENTS(g_aArgsDBGFR3Info), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1009 { "DBGFR3InfoLogRelHlp", (void *)(uintptr_t)&DBGFR3InfoLogRelHlp, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1010 { "DBGFR3SymbolByAddr", (void *)(uintptr_t)&DBGFR3SymbolByAddr, &g_aArgsDBGFR3SymbolByAddr[0], ELEMENTS(g_aArgsDBGFR3SymbolByAddr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1011 { "DISInstr", (void *)(uintptr_t)&DISInstr, &g_aArgsDISInstr[0], ELEMENTS(g_aArgsDISInstr), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
1012 { "EMR3FatalError", (void *)(uintptr_t)&EMR3FatalError, &g_aArgsEMR3FatalError[0], ELEMENTS(g_aArgsEMR3FatalError), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1013 { "HWACCMR3CanExecuteGuest", (void *)(uintptr_t)&HWACCMR3CanExecuteGuest, &g_aArgsHWACCMR3CanExecuteGuest[0], ELEMENTS(g_aArgsHWACCMR3CanExecuteGuest), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1014 { "IOMIOPortRead", (void *)(uintptr_t)&IOMIOPortRead, &g_aArgsIOMIOPortRead[0], ELEMENTS(g_aArgsIOMIOPortRead), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1015 { "IOMIOPortWrite", (void *)(uintptr_t)&IOMIOPortWrite, &g_aArgsIOMIOPortWrite[0], ELEMENTS(g_aArgsIOMIOPortWrite), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1016 { "IOMMMIORead", (void *)(uintptr_t)&IOMMMIORead, &g_aArgsIOMMMIORead[0], ELEMENTS(g_aArgsIOMMMIORead), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1017 { "IOMMMIOWrite", (void *)(uintptr_t)&IOMMMIOWrite, &g_aArgsIOMMMIOWrite[0], ELEMENTS(g_aArgsIOMMMIOWrite), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1018 { "MMR3HeapAlloc", (void *)(uintptr_t)&MMR3HeapAlloc, &g_aArgsMMR3HeapAlloc[0], ELEMENTS(g_aArgsMMR3HeapAlloc), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1019 { "MMR3HeapAllocZ", (void *)(uintptr_t)&MMR3HeapAllocZ, &g_aArgsMMR3HeapAllocZ[0], ELEMENTS(g_aArgsMMR3HeapAllocZ), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1020 { "MMR3PhysGetRamSize", (void *)(uintptr_t)&MMR3PhysGetRamSize, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint64_t), NULL },
1021 { "PATMIsPatchGCAddr", (void *)(uintptr_t)&PATMIsPatchGCAddr, &g_aArgsPATMIsPatchGCAddr[0], ELEMENTS(g_aArgsPATMIsPatchGCAddr), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
1022 { "PATMR3QueryOpcode", (void *)(uintptr_t)&PATMR3QueryOpcode, &g_aArgsPATMR3QueryOpcode[0], ELEMENTS(g_aArgsPATMR3QueryOpcode), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1023 { "PATMR3QueryPatchMemGC", (void *)(uintptr_t)&PATMR3QueryPatchMemGC, &g_aArgsPATMR3QueryPatchMem[0], ELEMENTS(g_aArgsPATMR3QueryPatchMem), REMFNDESC_FLAGS_RET_INT, sizeof(RTGCPTR), NULL },
1024 { "PATMR3QueryPatchMemHC", (void *)(uintptr_t)&PATMR3QueryPatchMemHC, &g_aArgsPATMR3QueryPatchMem[0], ELEMENTS(g_aArgsPATMR3QueryPatchMem), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1025 { "PDMApicGetBase", (void *)(uintptr_t)&PDMApicGetBase, &g_aArgsPDMApicGetBase[0], ELEMENTS(g_aArgsPDMApicGetBase), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1026 { "PDMApicGetTPR", (void *)(uintptr_t)&PDMApicGetTPR, &g_aArgsPDMApicGetTPR[0], ELEMENTS(g_aArgsPDMApicGetTPR), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1027 { "PDMApicSetBase", (void *)(uintptr_t)&PDMApicSetBase, &g_aArgsPDMApicSetBase[0], ELEMENTS(g_aArgsPDMApicSetBase), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1028 { "PDMApicSetTPR", (void *)(uintptr_t)&PDMApicSetTPR, &g_aArgsPDMApicSetTPR[0], ELEMENTS(g_aArgsPDMApicSetTPR), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1029 { "PDMR3DmaRun", (void *)(uintptr_t)&PDMR3DmaRun, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1030 { "PDMGetInterrupt", (void *)(uintptr_t)&PDMGetInterrupt, &g_aArgsPDMGetInterrupt[0], ELEMENTS(g_aArgsPDMGetInterrupt), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1031 { "PDMIsaSetIrq", (void *)(uintptr_t)&PDMIsaSetIrq, &g_aArgsPDMIsaSetIrq[0], ELEMENTS(g_aArgsPDMIsaSetIrq), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1032 { "PGMGstGetPage", (void *)(uintptr_t)&PGMGstGetPage, &g_aArgsPGMGstGetPage[0], ELEMENTS(g_aArgsPGMGstGetPage), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1033 { "PGMInvalidatePage", (void *)(uintptr_t)&PGMInvalidatePage, &g_aArgsPGMInvalidatePage[0], ELEMENTS(g_aArgsPGMInvalidatePage), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1034 { "PGMPhysGCPhys2HCPtr", (void *)(uintptr_t)&PGMPhysGCPhys2HCPtr, &g_aArgsPGMPhysGCPhys2HCPtr[0], ELEMENTS(g_aArgsPGMPhysGCPhys2HCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1035 { "PGMPhysGCPtr2HCPtrByGstCR3", (void *)(uintptr_t)&PGMPhysGCPtr2HCPtrByGstCR3, &g_aArgsPGMPhysGCPtr2HCPtrByGstCR3[0], ELEMENTS(g_aArgsPGMPhysGCPtr2HCPtrByGstCR3), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1036#ifndef VBOX_WITH_NEW_PHYS_CODE
1037 { "PGM3PhysGrowRange", (void *)(uintptr_t)&PGM3PhysGrowRange, &g_aArgsPGM3PhysGrowRange[0], ELEMENTS(g_aArgsPGM3PhysGrowRange), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1038#endif
1039 { "PGMPhysIsGCPhysValid", (void *)(uintptr_t)&PGMPhysIsGCPhysValid, &g_aArgsPGMPhysIsGCPhysValid[0], ELEMENTS(g_aArgsPGMPhysIsGCPhysValid), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
1040 { "PGMPhysIsA20Enabled", (void *)(uintptr_t)&PGMPhysIsA20Enabled, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
1041 { "PGMPhysRead", (void *)(uintptr_t)&PGMPhysRead, &g_aArgsPGMPhysRead[0], ELEMENTS(g_aArgsPGMPhysRead), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1042 { "PGMPhysReadGCPtr", (void *)(uintptr_t)&PGMPhysReadGCPtr, &g_aArgsPGMPhysReadGCPtr[0], ELEMENTS(g_aArgsPGMPhysReadGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1043 { "PGMPhysReadGCPtr", (void *)(uintptr_t)&PGMPhysReadGCPtr, &g_aArgsPGMPhysReadGCPtr[0], ELEMENTS(g_aArgsPGMPhysReadGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1044 { "PGMPhysWrite", (void *)(uintptr_t)&PGMPhysWrite, &g_aArgsPGMPhysWrite[0], ELEMENTS(g_aArgsPGMPhysWrite), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1045 { "PGMChangeMode", (void *)(uintptr_t)&PGMChangeMode, &g_aArgsPGMChangeMode[0], ELEMENTS(g_aArgsPGMChangeMode), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1046 { "PGMFlushTLB", (void *)(uintptr_t)&PGMFlushTLB, &g_aArgsPGMFlushTLB[0], ELEMENTS(g_aArgsPGMFlushTLB), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1047 { "PGMR3PhysReadByte", (void *)(uintptr_t)&PGMR3PhysReadByte, &g_aArgsPGMR3PhysReadUxx[0], ELEMENTS(g_aArgsPGMR3PhysReadUxx), REMFNDESC_FLAGS_RET_INT, sizeof(uint8_t), NULL },
1048 { "PGMR3PhysReadDword", (void *)(uintptr_t)&PGMR3PhysReadDword, &g_aArgsPGMR3PhysReadUxx[0], ELEMENTS(g_aArgsPGMR3PhysReadUxx), REMFNDESC_FLAGS_RET_INT, sizeof(uint32_t), NULL },
1049 { "PGMR3PhysReadWord", (void *)(uintptr_t)&PGMR3PhysReadWord, &g_aArgsPGMR3PhysReadUxx[0], ELEMENTS(g_aArgsPGMR3PhysReadUxx), REMFNDESC_FLAGS_RET_INT, sizeof(uint16_t), NULL },
1050 { "PGMR3PhysWriteByte", (void *)(uintptr_t)&PGMR3PhysWriteByte, &g_aArgsPGMR3PhysWriteU8[0], ELEMENTS(g_aArgsPGMR3PhysWriteU8), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1051 { "PGMR3PhysWriteDword", (void *)(uintptr_t)&PGMR3PhysWriteDword, &g_aArgsPGMR3PhysWriteU32[0], ELEMENTS(g_aArgsPGMR3PhysWriteU32), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1052 { "PGMR3PhysWriteWord", (void *)(uintptr_t)&PGMR3PhysWriteWord, &g_aArgsPGMR3PhysWriteU16[0], ELEMENTS(g_aArgsPGMR3PhysWriteU16), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1053 { "SSMR3GetGCPtr", (void *)(uintptr_t)&SSMR3GetGCPtr, &g_aArgsSSMR3GetGCPtr[0], ELEMENTS(g_aArgsSSMR3GetGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1054 { "SSMR3GetMem", (void *)(uintptr_t)&SSMR3GetMem, &g_aArgsSSMR3GetMem[0], ELEMENTS(g_aArgsSSMR3GetMem), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1055 { "SSMR3GetU32", (void *)(uintptr_t)&SSMR3GetU32, &g_aArgsSSMR3GetU32[0], ELEMENTS(g_aArgsSSMR3GetU32), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1056 { "SSMR3GetUInt", (void *)(uintptr_t)&SSMR3GetUInt, &g_aArgsSSMR3GetUInt[0], ELEMENTS(g_aArgsSSMR3GetUInt), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1057 { "SSMR3PutGCPtr", (void *)(uintptr_t)&SSMR3PutGCPtr, &g_aArgsSSMR3PutGCPtr[0], ELEMENTS(g_aArgsSSMR3PutGCPtr), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1058 { "SSMR3PutMem", (void *)(uintptr_t)&SSMR3PutMem, &g_aArgsSSMR3PutMem[0], ELEMENTS(g_aArgsSSMR3PutMem), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1059 { "SSMR3PutU32", (void *)(uintptr_t)&SSMR3PutU32, &g_aArgsSSMR3PutU32[0], ELEMENTS(g_aArgsSSMR3PutU32), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1060 { "SSMR3PutUInt", (void *)(uintptr_t)&SSMR3PutUInt, &g_aArgsSSMR3PutUInt[0], ELEMENTS(g_aArgsSSMR3PutUInt), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1061 { "SSMR3RegisterInternal", (void *)(uintptr_t)&SSMR3RegisterInternal, &g_aArgsSSMR3RegisterInternal[0], ELEMENTS(g_aArgsSSMR3RegisterInternal), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1062 { "STAMR3Register", (void *)(uintptr_t)&STAMR3Register, &g_aArgsSTAMR3Register[0], ELEMENTS(g_aArgsSTAMR3Register), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1063 { "TMCpuTickGet", (void *)(uintptr_t)&TMCpuTickGet, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint64_t), NULL },
1064 { "TMCpuTickPause", (void *)(uintptr_t)&TMCpuTickPause, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1065 { "TMCpuTickResume", (void *)(uintptr_t)&TMCpuTickResume, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1066 { "TMTimerPoll", (void *)(uintptr_t)&TMTimerPoll, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(uint64_t), NULL },
1067 { "TMR3TimerQueuesDo", (void *)(uintptr_t)&TMR3TimerQueuesDo, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1068 { "TMVirtualPause", (void *)(uintptr_t)&TMVirtualPause, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1069 { "TMVirtualResume", (void *)(uintptr_t)&TMVirtualResume, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1070 { "TRPMAssertTrap", (void *)(uintptr_t)&TRPMAssertTrap, &g_aArgsTRPMAssertTrap[0], ELEMENTS(g_aArgsTRPMAssertTrap), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1071 { "TRPMGetErrorCode", (void *)(uintptr_t)&TRPMGetErrorCode, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(RTGCUINT), NULL },
1072 { "TRPMGetFaultAddress", (void *)(uintptr_t)&TRPMGetFaultAddress, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(RTGCUINTPTR),NULL },
1073 { "TRPMQueryTrap", (void *)(uintptr_t)&TRPMQueryTrap, &g_aArgsTRPMQueryTrap[0], ELEMENTS(g_aArgsTRPMQueryTrap), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1074 { "TRPMResetTrap", (void *)(uintptr_t)&TRPMResetTrap, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1075 { "TRPMSetErrorCode", (void *)(uintptr_t)&TRPMSetErrorCode, &g_aArgsTRPMSetErrorCode[0], ELEMENTS(g_aArgsTRPMSetErrorCode), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1076 { "TRPMSetFaultAddress", (void *)(uintptr_t)&TRPMSetFaultAddress, &g_aArgsTRPMSetFaultAddress[0], ELEMENTS(g_aArgsTRPMSetFaultAddress), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1077 { "VMMR3Lock", (void *)(uintptr_t)&VMMR3Lock, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1078 { "VMMR3Unlock", (void *)(uintptr_t)&VMMR3Unlock, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1079 { "VMR3ReqCall", (void *)(uintptr_t)&VMR3ReqCall, &g_aArgsVMR3ReqCall[0], ELEMENTS(g_aArgsVMR3ReqCall), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1080 { "VMR3ReqFree", (void *)(uintptr_t)&VMR3ReqFree, &g_aArgsVMR3ReqFree[0], ELEMENTS(g_aArgsVMR3ReqFree), REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_ELLIPSIS, sizeof(int), NULL },
1081// { "", (void *)(uintptr_t)&, &g_aArgsVM[0], ELEMENTS(g_aArgsVM), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1082};
1083
1084
1085/**
1086 * Descriptors for the functions imported from VBoxRT.
1087 */
1088static REMFNDESC g_aRTImports[] =
1089{
1090 { "AssertMsg1", (void *)(uintptr_t)&AssertMsg1, &g_aArgsAssertMsg1[0], ELEMENTS(g_aArgsAssertMsg1), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1091 { "AssertMsg2", (void *)(uintptr_t)&AssertMsg2, &g_aArgsAssertMsg2[0], ELEMENTS(g_aArgsAssertMsg2), REMFNDESC_FLAGS_RET_VOID | REMFNDESC_FLAGS_ELLIPSIS, 0, NULL },
1092 { "RTAssertDoBreakpoint", (void *)(uintptr_t)&RTAssertDoBreakpoint, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(bool), NULL },
1093 { "RTLogDefaultInstance", (void *)(uintptr_t)&RTLogDefaultInstance, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(PRTLOGGER), NULL },
1094 { "RTLogRelDefaultInstance", (void *)(uintptr_t)&RTLogRelDefaultInstance, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(PRTLOGGER), NULL },
1095 { "RTLogFlags", (void *)(uintptr_t)&RTLogFlags, &g_aArgsRTLogFlags[0], ELEMENTS(g_aArgsRTLogFlags), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1096 { "RTLogFlush", (void *)(uintptr_t)&RTLogFlush, &g_aArgsRTLogFlush[0], ELEMENTS(g_aArgsRTLogFlush), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1097 { "RTLogLoggerEx", (void *)(uintptr_t)&RTLogLoggerEx, &g_aArgsRTLogLoggerEx[0], ELEMENTS(g_aArgsRTLogLoggerEx), REMFNDESC_FLAGS_RET_VOID | REMFNDESC_FLAGS_ELLIPSIS, 0, NULL },
1098 { "RTLogLoggerExV", (void *)(uintptr_t)&RTLogLoggerExV, &g_aArgsRTLogLoggerExV[0], ELEMENTS(g_aArgsRTLogLoggerExV), REMFNDESC_FLAGS_RET_VOID | REMFNDESC_FLAGS_VALIST, 0, NULL },
1099 { "RTLogPrintf", (void *)(uintptr_t)&RTLogPrintf, &g_aArgsRTLogPrintf[0], ELEMENTS(g_aArgsRTLogPrintf), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1100 { "RTMemAlloc", (void *)(uintptr_t)&RTMemAlloc, &g_aArgsSIZE_T[0], ELEMENTS(g_aArgsSIZE_T), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1101 { "RTMemExecAlloc", (void *)(uintptr_t)&RTMemExecAlloc, &g_aArgsSIZE_T[0], ELEMENTS(g_aArgsSIZE_T), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1102 { "RTMemExecFree", (void *)(uintptr_t)&RTMemExecFree, &g_aArgsPTR[0], ELEMENTS(g_aArgsPTR), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1103 { "RTMemFree", (void *)(uintptr_t)&RTMemFree, &g_aArgsPTR[0], ELEMENTS(g_aArgsPTR), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1104 { "RTMemPageAlloc", (void *)(uintptr_t)&RTMemPageAlloc, &g_aArgsSIZE_T[0], ELEMENTS(g_aArgsSIZE_T), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1105 { "RTMemPageFree", (void *)(uintptr_t)&RTMemPageFree, &g_aArgsPTR[0], ELEMENTS(g_aArgsPTR), REMFNDESC_FLAGS_RET_VOID, 0, NULL },
1106 { "RTMemProtect", (void *)(uintptr_t)&RTMemProtect, &g_aArgsRTMemProtect[0], ELEMENTS(g_aArgsRTMemProtect), REMFNDESC_FLAGS_RET_INT, sizeof(int), NULL },
1107 { "RTStrPrintf", (void *)(uintptr_t)&RTStrPrintf, &g_aArgsRTStrPrintf[0], ELEMENTS(g_aArgsRTStrPrintf), REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_ELLIPSIS, sizeof(size_t), NULL },
1108 { "RTStrPrintfV", (void *)(uintptr_t)&RTStrPrintfV, &g_aArgsRTStrPrintfV[0], ELEMENTS(g_aArgsRTStrPrintfV), REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_VALIST, sizeof(size_t), NULL },
1109 { "RTThreadNativeSelf", (void *)(uintptr_t)&RTThreadNativeSelf, NULL, 0, REMFNDESC_FLAGS_RET_INT, sizeof(RTNATIVETHREAD), NULL },
1110};
1111
1112
1113/**
1114 * Descriptors for the functions imported from VBoxRT.
1115 */
1116static REMFNDESC g_aCRTImports[] =
1117{
1118 { "memcpy", (void *)(uintptr_t)&memcpy, &g_aArgsmemcpy[0], ELEMENTS(g_aArgsmemcpy), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL },
1119 { "memset", (void *)(uintptr_t)&memset, &g_aArgsmemset[0], ELEMENTS(g_aArgsmemset), REMFNDESC_FLAGS_RET_INT, sizeof(void *), NULL }
1120/*
1121floor floor
1122memcpy memcpy
1123sqrt sqrt
1124sqrtf sqrtf
1125*/
1126};
1127
1128
1129# if defined(USE_REM_CALLING_CONVENTION_GLUE) || defined(USE_REM_IMPORT_JUMP_GLUE)
1130/** LIFO of read-write-executable memory chunks used for wrappers. */
1131static PREMEXECMEM g_pExecMemHead;
1132# endif
1133
1134
1135/*******************************************************************************
1136* Internal Functions *
1137*******************************************************************************/
1138static int remGenerateExportGlue(PRTUINTPTR pValue, PCREMFNDESC pDesc);
1139
1140# ifdef USE_REM_CALLING_CONVENTION_GLUE
1141DECLASM(int) WrapGCC2MSC0Int(void); DECLASM(int) WrapGCC2MSC0Int_EndProc(void);
1142DECLASM(int) WrapGCC2MSC1Int(void); DECLASM(int) WrapGCC2MSC1Int_EndProc(void);
1143DECLASM(int) WrapGCC2MSC2Int(void); DECLASM(int) WrapGCC2MSC2Int_EndProc(void);
1144DECLASM(int) WrapGCC2MSC3Int(void); DECLASM(int) WrapGCC2MSC3Int_EndProc(void);
1145DECLASM(int) WrapGCC2MSC4Int(void); DECLASM(int) WrapGCC2MSC4Int_EndProc(void);
1146DECLASM(int) WrapGCC2MSC5Int(void); DECLASM(int) WrapGCC2MSC5Int_EndProc(void);
1147DECLASM(int) WrapGCC2MSC6Int(void); DECLASM(int) WrapGCC2MSC6Int_EndProc(void);
1148DECLASM(int) WrapGCC2MSC7Int(void); DECLASM(int) WrapGCC2MSC7Int_EndProc(void);
1149DECLASM(int) WrapGCC2MSC8Int(void); DECLASM(int) WrapGCC2MSC8Int_EndProc(void);
1150DECLASM(int) WrapGCC2MSC9Int(void); DECLASM(int) WrapGCC2MSC9Int_EndProc(void);
1151DECLASM(int) WrapGCC2MSC10Int(void); DECLASM(int) WrapGCC2MSC10Int_EndProc(void);
1152DECLASM(int) WrapGCC2MSC11Int(void); DECLASM(int) WrapGCC2MSC11Int_EndProc(void);
1153DECLASM(int) WrapGCC2MSC12Int(void); DECLASM(int) WrapGCC2MSC12Int_EndProc(void);
1154DECLASM(int) WrapGCC2MSCVariadictInt(void); DECLASM(int) WrapGCC2MSCVariadictInt_EndProc(void);
1155DECLASM(int) WrapGCC2MSC_SSMR3RegisterInternal(void); DECLASM(int) WrapGCC2MSC_SSMR3RegisterInternal_EndProc(void);
1156
1157DECLASM(int) WrapMSC2GCC0Int(void); DECLASM(int) WrapMSC2GCC0Int_EndProc(void);
1158DECLASM(int) WrapMSC2GCC1Int(void); DECLASM(int) WrapMSC2GCC1Int_EndProc(void);
1159DECLASM(int) WrapMSC2GCC2Int(void); DECLASM(int) WrapMSC2GCC2Int_EndProc(void);
1160DECLASM(int) WrapMSC2GCC3Int(void); DECLASM(int) WrapMSC2GCC3Int_EndProc(void);
1161DECLASM(int) WrapMSC2GCC4Int(void); DECLASM(int) WrapMSC2GCC4Int_EndProc(void);
1162DECLASM(int) WrapMSC2GCC5Int(void); DECLASM(int) WrapMSC2GCC5Int_EndProc(void);
1163DECLASM(int) WrapMSC2GCC6Int(void); DECLASM(int) WrapMSC2GCC6Int_EndProc(void);
1164DECLASM(int) WrapMSC2GCC7Int(void); DECLASM(int) WrapMSC2GCC7Int_EndProc(void);
1165DECLASM(int) WrapMSC2GCC8Int(void); DECLASM(int) WrapMSC2GCC8Int_EndProc(void);
1166DECLASM(int) WrapMSC2GCC9Int(void); DECLASM(int) WrapMSC2GCC9Int_EndProc(void);
1167# endif
1168
1169
1170# if defined(USE_REM_CALLING_CONVENTION_GLUE) || defined(USE_REM_IMPORT_JUMP_GLUE)
1171/**
1172 * Allocates a block of memory for glue code.
1173 *
1174 * The returned memory is padded with INT3s.
1175 *
1176 * @returns Pointer to the allocated memory.
1177 * @param The amount of memory to allocate.
1178 */
1179static void *remAllocGlue(size_t cb)
1180{
1181 PREMEXECMEM pCur = g_pExecMemHead;
1182 uint32_t cbAligned = (uint32_t)RT_ALIGN_32(cb, 32);
1183 while (pCur)
1184 {
1185 if (pCur->cb - pCur->off >= cbAligned)
1186 {
1187 void *pv = (uint8_t *)pCur + pCur->off;
1188 pCur->off += cbAligned;
1189 return memset(pv, 0xcc, cbAligned);
1190 }
1191 pCur = pCur->pNext;
1192 }
1193
1194 /* add a new chunk */
1195 AssertReturn(_64K - RT_ALIGN_Z(sizeof(*pCur), 32) > cbAligned, NULL);
1196 pCur = (PREMEXECMEM)RTMemExecAlloc(_64K);
1197 AssertReturn(pCur, NULL);
1198 pCur->cb = _64K;
1199 pCur->off = RT_ALIGN_32(sizeof(*pCur), 32) + cbAligned;
1200 pCur->pNext = g_pExecMemHead;
1201 g_pExecMemHead = pCur;
1202 return memset((uint8_t *)pCur + RT_ALIGN_Z(sizeof(*pCur), 32), 0xcc, cbAligned);
1203}
1204# endif /* USE_REM_CALLING_CONVENTION_GLUE || USE_REM_IMPORT_JUMP_GLUE */
1205
1206
1207# ifdef USE_REM_CALLING_CONVENTION_GLUE
1208/**
1209 * Checks if a function is all straight forward integers.
1210 *
1211 * @returns True if it's simple, false if it's bothersome.
1212 * @param pDesc The function descriptor.
1213 */
1214static bool remIsFunctionAllInts(PCREMFNDESC pDesc)
1215{
1216 if ( ( (pDesc->fFlags & REMFNDESC_FLAGS_RET_TYPE_MASK) != REMFNDESC_FLAGS_RET_INT
1217 || pDesc->cbReturn > sizeof(uint64_t))
1218 && (pDesc->fFlags & REMFNDESC_FLAGS_RET_TYPE_MASK) != REMFNDESC_FLAGS_RET_VOID)
1219 return false;
1220 unsigned i = pDesc->cParams;
1221 while (i-- > 0)
1222 switch (pDesc->paParams[i].fFlags & REMPARMDESC_FLAGS_TYPE_MASK)
1223 {
1224 case REMPARMDESC_FLAGS_INT:
1225 case REMPARMDESC_FLAGS_GCPTR:
1226 case REMPARMDESC_FLAGS_GCPHYS:
1227 case REMPARMDESC_FLAGS_HCPHYS:
1228 break;
1229
1230 default:
1231 AssertReleaseMsgFailed(("Invalid param flags %#x for #%d of %s!\n", pDesc->paParams[i].fFlags, i, pDesc->pszName));
1232 case REMPARMDESC_FLAGS_VALIST:
1233 case REMPARMDESC_FLAGS_ELLIPSIS:
1234 case REMPARMDESC_FLAGS_FLOAT:
1235 case REMPARMDESC_FLAGS_STRUCT:
1236 case REMPARMDESC_FLAGS_PFN:
1237 return false;
1238 }
1239 return true;
1240}
1241
1242
1243/**
1244 * Checks if the function has an ellipsis (...) argument.
1245 *
1246 * @returns true if it has an ellipsis, otherwise false.
1247 * @param pDesc The function descriptor.
1248 */
1249static bool remHasFunctionEllipsis(PCREMFNDESC pDesc)
1250{
1251 unsigned i = pDesc->cParams;
1252 while (i-- > 0)
1253 if ((pDesc->paParams[i].fFlags & REMPARMDESC_FLAGS_TYPE_MASK) == REMPARMDESC_FLAGS_ELLIPSIS)
1254 return true;
1255 return false;
1256}
1257
1258
1259/**
1260 * Checks if the function uses floating point (FP) arguments or return value.
1261 *
1262 * @returns true if it uses floating point, otherwise false.
1263 * @param pDesc The function descriptor.
1264 */
1265static bool remIsFunctionUsingFP(PCREMFNDESC pDesc)
1266{
1267 if ((pDesc->fFlags & REMFNDESC_FLAGS_RET_TYPE_MASK) == REMFNDESC_FLAGS_RET_FLOAT)
1268 return true;
1269 unsigned i = pDesc->cParams;
1270 while (i-- > 0)
1271 if ((pDesc->paParams[i].fFlags & REMPARMDESC_FLAGS_TYPE_MASK) == REMPARMDESC_FLAGS_FLOAT)
1272 return true;
1273 return false;
1274}
1275
1276
1277/** @name The export and import fixups.
1278 * @{ */
1279#define REM_FIXUP_32_REAL_STUFF UINT32_C(0xdeadbeef)
1280#define REM_FIXUP_64_REAL_STUFF UINT64_C(0xdeadf00df00ddead)
1281#define REM_FIXUP_64_DESC UINT64_C(0xdead00010001dead)
1282#define REM_FIXUP_64_LOG_ENTRY UINT64_C(0xdead00020002dead)
1283#define REM_FIXUP_64_LOG_EXIT UINT64_C(0xdead00030003dead)
1284#define REM_FIXUP_64_WRAP_GCC_CB UINT64_C(0xdead00040004dead)
1285/** @} */
1286
1287
1288/**
1289 * Entry logger function.
1290 *
1291 * @param pDesc The description.
1292 */
1293DECLASM(void) remLogEntry(PCREMFNDESC pDesc)
1294{
1295 RTPrintf("calling %s\n", pDesc->pszName);
1296}
1297
1298
1299/**
1300 * Exit logger function.
1301 *
1302 * @param pDesc The description.
1303 * @param pvRet The return code.
1304 */
1305DECLASM(void) remLogExit(PCREMFNDESC pDesc, void *pvRet)
1306{
1307 RTPrintf("returning %p from %s\n", pvRet, pDesc->pszName);
1308}
1309
1310
1311/**
1312 * Creates a wrapper for the specified callback function at run time.
1313 *
1314 * @param pDesc The function descriptor.
1315 * @param pValue Upon entry *pValue contains the address of the function to be wrapped.
1316 * Upon return *pValue contains the address of the wrapper glue function.
1317 * @param iParam The parameter index in the function descriptor (0 based).
1318 * If UINT32_MAX pDesc is the descriptor for *pValue.
1319 */
1320DECLASM(void) remWrapGCCCallback(PCREMFNDESC pDesc, PRTUINTPTR pValue, uint32_t iParam)
1321{
1322 AssertPtr(pDesc);
1323 AssertPtr(pValue);
1324
1325 /*
1326 * Simple?
1327 */
1328 if (!*pValue)
1329 return;
1330
1331 /*
1332 * Locate the right function descriptor.
1333 */
1334 if (iParam != UINT32_MAX)
1335 {
1336 AssertRelease(iParam < pDesc->cParams);
1337 pDesc = (PCREMFNDESC)pDesc->paParams[iParam].pvExtra;
1338 AssertPtr(pDesc);
1339 }
1340
1341 /*
1342 * When we get serious, here is where to insert the hash table lookup.
1343 */
1344
1345 /*
1346 * Create a new glue patch.
1347 */
1348#ifdef RT_OS_WINDOWS
1349 int rc = remGenerateExportGlue(pValue, pDesc);
1350#else
1351#error "port me"
1352#endif
1353 AssertReleaseRC(rc);
1354
1355 /*
1356 * Add it to the hash (later)
1357 */
1358}
1359
1360
1361/**
1362 * Fixes export glue.
1363 *
1364 * @param pvGlue The glue code.
1365 * @param cb The size of the glue code.
1366 * @param pvExport The address of the export we're wrapping.
1367 * @param pDesc The export descriptor.
1368 */
1369static void remGenerateExportGlueFixup(void *pvGlue, size_t cb, uintptr_t uExport, PCREMFNDESC pDesc)
1370{
1371 union
1372 {
1373 uint8_t *pu8;
1374 int32_t *pi32;
1375 uint32_t *pu32;
1376 uint64_t *pu64;
1377 void *pv;
1378 } u;
1379 u.pv = pvGlue;
1380
1381 while (cb >= 4)
1382 {
1383 /** @todo add defines for the fixup constants... */
1384 if (*u.pu32 == REM_FIXUP_32_REAL_STUFF)
1385 {
1386 /* 32-bit rel jmp/call to real export. */
1387 *u.pi32 = uExport - (uintptr_t)(u.pi32 + 1);
1388 Assert((uintptr_t)(u.pi32 + 1) + *u.pi32 == uExport);
1389 u.pi32++;
1390 cb -= 4;
1391 continue;
1392 }
1393 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_REAL_STUFF)
1394 {
1395 /* 64-bit address to the real export. */
1396 *u.pu64++ = uExport;
1397 cb -= 8;
1398 continue;
1399 }
1400 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_DESC)
1401 {
1402 /* 64-bit address to the descriptor. */
1403 *u.pu64++ = (uintptr_t)pDesc;
1404 cb -= 8;
1405 continue;
1406 }
1407 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_WRAP_GCC_CB)
1408 {
1409 /* 64-bit address to the entry logger function. */
1410 *u.pu64++ = (uintptr_t)remWrapGCCCallback;
1411 cb -= 8;
1412 continue;
1413 }
1414 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_LOG_ENTRY)
1415 {
1416 /* 64-bit address to the entry logger function. */
1417 *u.pu64++ = (uintptr_t)remLogEntry;
1418 cb -= 8;
1419 continue;
1420 }
1421 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_LOG_EXIT)
1422 {
1423 /* 64-bit address to the entry logger function. */
1424 *u.pu64++ = (uintptr_t)remLogExit;
1425 cb -= 8;
1426 continue;
1427 }
1428
1429 /* move on. */
1430 u.pu8++;
1431 cb--;
1432 }
1433}
1434
1435
1436/**
1437 * Fixes import glue.
1438 *
1439 * @param pvGlue The glue code.
1440 * @param cb The size of the glue code.
1441 * @param pDesc The import descriptor.
1442 */
1443static void remGenerateImportGlueFixup(void *pvGlue, size_t cb, PCREMFNDESC pDesc)
1444{
1445 union
1446 {
1447 uint8_t *pu8;
1448 int32_t *pi32;
1449 uint32_t *pu32;
1450 uint64_t *pu64;
1451 void *pv;
1452 } u;
1453 u.pv = pvGlue;
1454
1455 while (cb >= 4)
1456 {
1457 if (*u.pu32 == REM_FIXUP_32_REAL_STUFF)
1458 {
1459 /* 32-bit rel jmp/call to real function. */
1460 *u.pi32 = (uintptr_t)pDesc->pv - (uintptr_t)(u.pi32 + 1);
1461 Assert((uintptr_t)(u.pi32 + 1) + *u.pi32 == (uintptr_t)pDesc->pv);
1462 u.pi32++;
1463 cb -= 4;
1464 continue;
1465 }
1466 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_REAL_STUFF)
1467 {
1468 /* 64-bit address to the real function. */
1469 *u.pu64++ = (uintptr_t)pDesc->pv;
1470 cb -= 8;
1471 continue;
1472 }
1473 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_DESC)
1474 {
1475 /* 64-bit address to the descriptor. */
1476 *u.pu64++ = (uintptr_t)pDesc;
1477 cb -= 8;
1478 continue;
1479 }
1480 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_WRAP_GCC_CB)
1481 {
1482 /* 64-bit address to the entry logger function. */
1483 *u.pu64++ = (uintptr_t)remWrapGCCCallback;
1484 cb -= 8;
1485 continue;
1486 }
1487 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_LOG_ENTRY)
1488 {
1489 /* 64-bit address to the entry logger function. */
1490 *u.pu64++ = (uintptr_t)remLogEntry;
1491 cb -= 8;
1492 continue;
1493 }
1494 if (cb >= 8 && *u.pu64 == REM_FIXUP_64_LOG_EXIT)
1495 {
1496 /* 64-bit address to the entry logger function. */
1497 *u.pu64++ = (uintptr_t)remLogExit;
1498 cb -= 8;
1499 continue;
1500 }
1501
1502 /* move on. */
1503 u.pu8++;
1504 cb--;
1505 }
1506}
1507
1508# endif /* USE_REM_CALLING_CONVENTION_GLUE */
1509
1510
1511/**
1512 * Generate wrapper glue code for an export.
1513 *
1514 * This is only used on win64 when loading a 64-bit linux module. So, on other
1515 * platforms it will not do anything.
1516 *
1517 * @returns VBox status code.
1518 * @param pValue IN: Where to get the address of the function to wrap.
1519 * OUT: Where to store the glue address.
1520 * @param pDesc The export descriptor.
1521 */
1522static int remGenerateExportGlue(PRTUINTPTR pValue, PCREMFNDESC pDesc)
1523{
1524# ifdef USE_REM_CALLING_CONVENTION_GLUE
1525 uintptr_t *ppfn = (uintptr_t *)pDesc->pv;
1526
1527 uintptr_t pfn = 0; /* a little hack for the callback glue */
1528 if (!ppfn)
1529 ppfn = &pfn;
1530
1531 if (!*ppfn)
1532 {
1533 if (remIsFunctionAllInts(pDesc))
1534 {
1535 static const struct { void *pvStart, *pvEnd; } s_aTemplates[] =
1536 {
1537 { (void *)&WrapMSC2GCC0Int, (void *)&WrapMSC2GCC0Int_EndProc },
1538 { (void *)&WrapMSC2GCC1Int, (void *)&WrapMSC2GCC1Int_EndProc },
1539 { (void *)&WrapMSC2GCC2Int, (void *)&WrapMSC2GCC2Int_EndProc },
1540 { (void *)&WrapMSC2GCC3Int, (void *)&WrapMSC2GCC3Int_EndProc },
1541 { (void *)&WrapMSC2GCC4Int, (void *)&WrapMSC2GCC4Int_EndProc },
1542 { (void *)&WrapMSC2GCC5Int, (void *)&WrapMSC2GCC5Int_EndProc },
1543 { (void *)&WrapMSC2GCC6Int, (void *)&WrapMSC2GCC6Int_EndProc },
1544 { (void *)&WrapMSC2GCC7Int, (void *)&WrapMSC2GCC7Int_EndProc },
1545 { (void *)&WrapMSC2GCC8Int, (void *)&WrapMSC2GCC8Int_EndProc },
1546 { (void *)&WrapMSC2GCC9Int, (void *)&WrapMSC2GCC9Int_EndProc },
1547 };
1548 const unsigned i = pDesc->cParams;
1549 AssertReleaseMsg(i < ELEMENTS(s_aTemplates), ("%d (%s)\n", i, pDesc->pszName));
1550
1551 /* duplicate the patch. */
1552 const size_t cb = (uintptr_t)s_aTemplates[i].pvEnd - (uintptr_t)s_aTemplates[i].pvStart;
1553 uint8_t *pb = (uint8_t *)remAllocGlue(cb);
1554 AssertReturn(pb, VERR_NO_MEMORY);
1555 memcpy(pb, s_aTemplates[i].pvStart, cb);
1556
1557 /* fix it up. */
1558 remGenerateExportGlueFixup(pb, cb, *pValue, pDesc);
1559 *ppfn = (uintptr_t)pb;
1560 }
1561 else
1562 {
1563 /* custom hacks - it's simpler to make assembly templates than writing a more generic code generator... */
1564 static const struct { const char *pszName; PFNRT pvStart, pvEnd; } s_aTemplates[] =
1565 {
1566 { "somefunction", (PFNRT)&WrapMSC2GCC9Int, (PFNRT)&WrapMSC2GCC9Int_EndProc },
1567 };
1568 unsigned i;
1569 for (i = 0; i < RT_ELEMENTS(s_aTemplates); i++)
1570 if (!strcmp(pDesc->pszName, s_aTemplates[i].pszName))
1571 break;
1572 AssertReleaseMsgReturn(i < RT_ELEMENTS(s_aTemplates), ("Not implemented! %s\n", pDesc->pszName), VERR_NOT_IMPLEMENTED);
1573
1574 /* duplicate the patch. */
1575 const size_t cb = (uintptr_t)s_aTemplates[i].pvEnd - (uintptr_t)s_aTemplates[i].pvStart;
1576 uint8_t *pb = (uint8_t *)remAllocGlue(cb);
1577 AssertReturn(pb, VERR_NO_MEMORY);
1578 memcpy(pb, s_aTemplates[i].pvStart, cb);
1579
1580 /* fix it up. */
1581 remGenerateExportGlueFixup(pb, cb, *pValue, pDesc);
1582 *ppfn = (uintptr_t)pb;
1583 }
1584 }
1585 *pValue = *ppfn;
1586 return VINF_SUCCESS;
1587# else /* !USE_REM_CALLING_CONVENTION_GLUE */
1588 return VINF_SUCCESS;
1589# endif /* !USE_REM_CALLING_CONVENTION_GLUE */
1590}
1591
1592
1593/**
1594 * Generate wrapper glue code for an import.
1595 *
1596 * This is only used on win64 when loading a 64-bit linux module. So, on other
1597 * platforms it will simply return the address of the imported function
1598 * without generating any glue code.
1599 *
1600 * @returns VBox status code.
1601 * @param pValue Where to store the glue address.
1602 * @param pDesc The export descriptor.
1603 */
1604static int remGenerateImportGlue(PRTUINTPTR pValue, PREMFNDESC pDesc)
1605{
1606# if defined(USE_REM_CALLING_CONVENTION_GLUE) || defined(USE_REM_IMPORT_JUMP_GLUE)
1607 if (!pDesc->pvWrapper)
1608 {
1609# ifdef USE_REM_CALLING_CONVENTION_GLUE
1610 if (remIsFunctionAllInts(pDesc))
1611 {
1612 static const struct { void *pvStart, *pvEnd; } s_aTemplates[] =
1613 {
1614 { (void *)&WrapGCC2MSC0Int, (void *)&WrapGCC2MSC0Int_EndProc },
1615 { (void *)&WrapGCC2MSC1Int, (void *)&WrapGCC2MSC1Int_EndProc },
1616 { (void *)&WrapGCC2MSC2Int, (void *)&WrapGCC2MSC2Int_EndProc },
1617 { (void *)&WrapGCC2MSC3Int, (void *)&WrapGCC2MSC3Int_EndProc },
1618 { (void *)&WrapGCC2MSC4Int, (void *)&WrapGCC2MSC4Int_EndProc },
1619 { (void *)&WrapGCC2MSC5Int, (void *)&WrapGCC2MSC5Int_EndProc },
1620 { (void *)&WrapGCC2MSC6Int, (void *)&WrapGCC2MSC6Int_EndProc },
1621 { (void *)&WrapGCC2MSC7Int, (void *)&WrapGCC2MSC7Int_EndProc },
1622 { (void *)&WrapGCC2MSC8Int, (void *)&WrapGCC2MSC8Int_EndProc },
1623 { (void *)&WrapGCC2MSC9Int, (void *)&WrapGCC2MSC9Int_EndProc },
1624 { (void *)&WrapGCC2MSC10Int, (void *)&WrapGCC2MSC10Int_EndProc },
1625 { (void *)&WrapGCC2MSC11Int, (void *)&WrapGCC2MSC11Int_EndProc },
1626 { (void *)&WrapGCC2MSC12Int, (void *)&WrapGCC2MSC12Int_EndProc }
1627 };
1628 const unsigned i = pDesc->cParams;
1629 AssertReleaseMsg(i < ELEMENTS(s_aTemplates), ("%d (%s)\n", i, pDesc->pszName));
1630
1631 /* duplicate the patch. */
1632 const size_t cb = (uintptr_t)s_aTemplates[i].pvEnd - (uintptr_t)s_aTemplates[i].pvStart;
1633 pDesc->pvWrapper = remAllocGlue(cb);
1634 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1635 memcpy(pDesc->pvWrapper, s_aTemplates[i].pvStart, cb);
1636
1637 /* fix it up. */
1638 remGenerateImportGlueFixup((uint8_t *)pDesc->pvWrapper, cb, pDesc);
1639 }
1640 else if ( remHasFunctionEllipsis(pDesc)
1641 && !remIsFunctionUsingFP(pDesc))
1642 {
1643 /* duplicate the patch. */
1644 const size_t cb = (uintptr_t)&WrapGCC2MSCVariadictInt_EndProc - (uintptr_t)&WrapGCC2MSCVariadictInt;
1645 pDesc->pvWrapper = remAllocGlue(cb);
1646 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1647 memcpy(pDesc->pvWrapper, (void *)&WrapGCC2MSCVariadictInt, cb);
1648
1649 /* fix it up. */
1650 remGenerateImportGlueFixup((uint8_t *)pDesc->pvWrapper, cb, pDesc);
1651 }
1652 else
1653 {
1654 /* custom hacks - it's simpler to make assembly templates than writing a more generic code generator... */
1655 static const struct { const char *pszName; PFNRT pvStart, pvEnd; } s_aTemplates[] =
1656 {
1657 { "SSMR3RegisterInternal", (PFNRT)&WrapGCC2MSC_SSMR3RegisterInternal, (PFNRT)&WrapGCC2MSC_SSMR3RegisterInternal_EndProc },
1658 };
1659 unsigned i;
1660 for (i = 0; i < RT_ELEMENTS(s_aTemplates); i++)
1661 if (!strcmp(pDesc->pszName, s_aTemplates[i].pszName))
1662 break;
1663 AssertReleaseMsgReturn(i < RT_ELEMENTS(s_aTemplates), ("Not implemented! %s\n", pDesc->pszName), VERR_NOT_IMPLEMENTED);
1664
1665 /* duplicate the patch. */
1666 const size_t cb = (uintptr_t)s_aTemplates[i].pvEnd - (uintptr_t)s_aTemplates[i].pvStart;
1667 pDesc->pvWrapper = remAllocGlue(cb);
1668 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1669 memcpy(pDesc->pvWrapper, s_aTemplates[i].pvStart, cb);
1670
1671 /* fix it up. */
1672 remGenerateImportGlueFixup((uint8_t *)pDesc->pvWrapper, cb, pDesc);
1673 }
1674# else /* !USE_REM_CALLING_CONVENTION_GLUE */
1675
1676 /*
1677 * Generate a jump patch.
1678 */
1679 uint8_t *pb;
1680# ifdef RT_ARCH_AMD64
1681 pDesc->pvWrapper = pb = (uint8_t *)remAllocGlue(32);
1682 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1683 /**pb++ = 0xcc;*/
1684 *pb++ = 0xff;
1685 *pb++ = 0x24;
1686 *pb++ = 0x25;
1687 *(uint32_t *)pb = (uintptr_t)pb + 5;
1688 pb += 5;
1689 *(uint64_t *)pb = (uint64_t)pDesc->pv;
1690# else
1691 pDesc->pvWrapper = pb = (uint8_t *)remAllocGlue(8);
1692 AssertReturn(pDesc->pvWrapper, VERR_NO_MEMORY);
1693 *pb++ = 0xea;
1694 *(uint32_t *)pb = (uint32_t)pDesc->pv;
1695# endif
1696# endif /* !USE_REM_CALLING_CONVENTION_GLUE */
1697 }
1698 *pValue = (uintptr_t)pDesc->pvWrapper;
1699# else /* !USE_REM_CALLING_CONVENTION_GLUE */
1700 *pValue = (uintptr_t)pDesc->pv;
1701# endif /* !USE_REM_CALLING_CONVENTION_GLUE */
1702 return VINF_SUCCESS;
1703}
1704
1705
1706/**
1707 * Resolve an external symbol during RTLdrGetBits().
1708 *
1709 * @returns iprt status code.
1710 * @param hLdrMod The loader module handle.
1711 * @param pszModule Module name.
1712 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
1713 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
1714 * @param pValue Where to store the symbol value (address).
1715 * @param pvUser User argument.
1716 */
1717static DECLCALLBACK(int) remGetImport(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser)
1718{
1719 unsigned i;
1720 for (i = 0; i < ELEMENTS(g_aVMMImports); i++)
1721 if (!strcmp(g_aVMMImports[i].pszName, pszSymbol))
1722 return remGenerateImportGlue(pValue, &g_aVMMImports[i]);
1723 for (i = 0; i < ELEMENTS(g_aRTImports); i++)
1724 if (!strcmp(g_aRTImports[i].pszName, pszSymbol))
1725 return remGenerateImportGlue(pValue, &g_aRTImports[i]);
1726 for (i = 0; i < ELEMENTS(g_aCRTImports); i++)
1727 if (!strcmp(g_aCRTImports[i].pszName, pszSymbol))
1728 return remGenerateImportGlue(pValue, &g_aCRTImports[i]);
1729 LogRel(("Missing REM Import: %s\n", pszSymbol));
1730#if 1
1731 *pValue = 0;
1732 AssertMsgFailed(("%s.%s\n", pszModule, pszSymbol));
1733 return VERR_SYMBOL_NOT_FOUND;
1734#else
1735 return remGenerateImportGlue(pValue, &g_aCRTImports[0]);
1736#endif
1737}
1738
1739/**
1740 * Loads the linux object, resolves all imports and exports.
1741 *
1742 * @returns VBox status code.
1743 */
1744static int remLoadLinuxObj(void)
1745{
1746 size_t offFilename;
1747 char szPath[RTPATH_MAX];
1748 int rc = RTPathAppPrivateArch(szPath, sizeof(szPath) - 32);
1749 AssertRCReturn(rc, rc);
1750 offFilename = strlen(szPath);
1751
1752 /*
1753 * Load the VBoxREM2.rel object/DLL.
1754 */
1755 strcpy(&szPath[offFilename], "/VBoxREM2.rel");
1756 rc = RTLdrOpen(szPath, &g_ModREM2);
1757 if (VBOX_SUCCESS(rc))
1758 {
1759 g_pvREM2 = RTMemExecAlloc(RTLdrSize(g_ModREM2));
1760 if (g_pvREM2)
1761 {
1762#ifdef DEBUG /* How to load the VBoxREM2.rel symbols into the GNU debugger. */
1763 RTPrintf("VBoxREMWrapper: (gdb) add-symbol-file %s 0x%p\n", szPath, g_pvREM2);
1764#endif
1765 LogRel(("REM: Loading %s at 0x%p (%d bytes)\n"
1766 "REM: (gdb) add-symbol-file %s 0x%p\n",
1767 szPath, g_pvREM2, RTLdrSize(g_ModREM2), szPath, g_pvREM2));
1768 rc = RTLdrGetBits(g_ModREM2, g_pvREM2, (RTUINTPTR)g_pvREM2, remGetImport, NULL);
1769 if (VBOX_SUCCESS(rc))
1770 {
1771 /*
1772 * Resolve exports.
1773 */
1774 unsigned i;
1775 for (i = 0; i < ELEMENTS(g_aExports); i++)
1776 {
1777 RTUINTPTR Value;
1778 rc = RTLdrGetSymbolEx(g_ModREM2, g_pvREM2, (RTUINTPTR)g_pvREM2, g_aExports[i].pszName, &Value);
1779 AssertMsgRC(rc, ("%s rc=%Vrc\n", g_aExports[i].pszName, rc));
1780 if (VBOX_FAILURE(rc))
1781 break;
1782 rc = remGenerateExportGlue(&Value, &g_aExports[i]);
1783 if (VBOX_FAILURE(rc))
1784 break;
1785 *(void **)g_aExports[i].pv = (void *)(uintptr_t)Value;
1786 }
1787 return rc;
1788 }
1789 RTMemExecFree(g_pvREM2);
1790 }
1791 RTLdrClose(g_ModREM2);
1792 g_ModREM2 = NIL_RTLDRMOD;
1793 }
1794 LogRel(("REM: failed loading '%s', rc=%Vrc\n", szPath, rc));
1795 return rc;
1796}
1797
1798
1799/**
1800 * Unloads the linux object, freeing up all resources (dlls and
1801 * import glue) we allocated during remLoadLinuxObj().
1802 */
1803static void remUnloadLinuxObj(void)
1804{
1805 unsigned i;
1806
1807 /* close modules. */
1808 RTLdrClose(g_ModREM2);
1809 g_ModREM2 = NIL_RTLDRMOD;
1810 RTMemExecFree(g_pvREM2);
1811 g_pvREM2 = NULL;
1812
1813 /* clear the pointers. */
1814 for (i = 0; i < ELEMENTS(g_aExports); i++)
1815 *(void **)g_aExports[i].pv = NULL;
1816# if defined(USE_REM_CALLING_CONVENTION_GLUE) || defined(USE_REM_IMPORT_JUMP_GLUE)
1817 for (i = 0; i < ELEMENTS(g_aVMMImports); i++)
1818 g_aVMMImports[i].pvWrapper = NULL;
1819 for (i = 0; i < ELEMENTS(g_aRTImports); i++)
1820 g_aRTImports[i].pvWrapper = NULL;
1821 for (i = 0; i < ELEMENTS(g_aCRTImports); i++)
1822 g_aCRTImports[i].pvWrapper = NULL;
1823
1824 /* free wrapper memory. */
1825 while (g_pExecMemHead)
1826 {
1827 PREMEXECMEM pCur = g_pExecMemHead;
1828 g_pExecMemHead = pCur->pNext;
1829 memset(pCur, 0xcc, pCur->cb);
1830 RTMemExecFree(pCur);
1831 }
1832# endif
1833}
1834#endif
1835
1836
1837REMR3DECL(int) REMR3Init(PVM pVM)
1838{
1839#ifdef USE_REM_STUBS
1840 return VINF_SUCCESS;
1841#else
1842 if (!pfnREMR3Init)
1843 {
1844 int rc = remLoadLinuxObj();
1845 if (VBOX_FAILURE(rc))
1846 return rc;
1847 }
1848 return pfnREMR3Init(pVM);
1849#endif
1850}
1851
1852REMR3DECL(int) REMR3Term(PVM pVM)
1853{
1854#ifdef USE_REM_STUBS
1855 return VINF_SUCCESS;
1856#else
1857 int rc;
1858 Assert(VALID_PTR(pfnREMR3Term));
1859 rc = pfnREMR3Term(pVM);
1860 remUnloadLinuxObj();
1861 return rc;
1862#endif
1863}
1864
1865REMR3DECL(void) REMR3Reset(PVM pVM)
1866{
1867#ifndef USE_REM_STUBS
1868 Assert(VALID_PTR(pfnREMR3Reset));
1869 pfnREMR3Reset(pVM);
1870#endif
1871}
1872
1873REMR3DECL(int) REMR3Step(PVM pVM)
1874{
1875#ifdef USE_REM_STUBS
1876 return VERR_NOT_IMPLEMENTED;
1877#else
1878 Assert(VALID_PTR(pfnREMR3Step));
1879 return pfnREMR3Step(pVM);
1880#endif
1881}
1882
1883REMR3DECL(int) REMR3BreakpointSet(PVM pVM, RTGCUINTPTR Address)
1884{
1885#ifdef USE_REM_STUBS
1886 return VERR_REM_NO_MORE_BP_SLOTS;
1887#else
1888 Assert(VALID_PTR(pfnREMR3BreakpointSet));
1889 return pfnREMR3BreakpointSet(pVM, Address);
1890#endif
1891}
1892
1893REMR3DECL(int) REMR3BreakpointClear(PVM pVM, RTGCUINTPTR Address)
1894{
1895#ifdef USE_REM_STUBS
1896 return VERR_NOT_IMPLEMENTED;
1897#else
1898 Assert(VALID_PTR(pfnREMR3BreakpointClear));
1899 return pfnREMR3BreakpointClear(pVM, Address);
1900#endif
1901}
1902
1903REMR3DECL(int) REMR3EmulateInstruction(PVM pVM)
1904{
1905#ifdef USE_REM_STUBS
1906 return VERR_NOT_IMPLEMENTED;
1907#else
1908 Assert(VALID_PTR(pfnREMR3EmulateInstruction));
1909 return pfnREMR3EmulateInstruction(pVM);
1910#endif
1911}
1912
1913REMR3DECL(int) REMR3Run(PVM pVM)
1914{
1915#ifdef USE_REM_STUBS
1916 return VERR_NOT_IMPLEMENTED;
1917#else
1918 Assert(VALID_PTR(pfnREMR3Run));
1919 return pfnREMR3Run(pVM);
1920#endif
1921}
1922
1923REMR3DECL(int) REMR3State(PVM pVM)
1924{
1925#ifdef USE_REM_STUBS
1926 return VERR_NOT_IMPLEMENTED;
1927#else
1928 Assert(VALID_PTR(pfnREMR3State));
1929 return pfnREMR3State(pVM);
1930#endif
1931}
1932
1933REMR3DECL(int) REMR3StateBack(PVM pVM)
1934{
1935#ifdef USE_REM_STUBS
1936 return VERR_NOT_IMPLEMENTED;
1937#else
1938 Assert(VALID_PTR(pfnREMR3StateBack));
1939 return pfnREMR3StateBack(pVM);
1940#endif
1941}
1942
1943REMR3DECL(void) REMR3StateUpdate(PVM pVM)
1944{
1945#ifndef USE_REM_STUBS
1946 Assert(VALID_PTR(pfnREMR3StateUpdate));
1947 pfnREMR3StateUpdate(pVM);
1948#endif
1949}
1950
1951REMR3DECL(void) REMR3A20Set(PVM pVM, bool fEnable)
1952{
1953#ifndef USE_REM_STUBS
1954 Assert(VALID_PTR(pfnREMR3A20Set));
1955 pfnREMR3A20Set(pVM, fEnable);
1956#endif
1957}
1958
1959REMR3DECL(void) REMR3ReplayInvalidatedPages(PVM pVM)
1960{
1961#ifndef USE_REM_STUBS
1962 Assert(VALID_PTR(pfnREMR3ReplayInvalidatedPages));
1963 pfnREMR3ReplayInvalidatedPages(pVM);
1964#endif
1965}
1966
1967REMR3DECL(void) REMR3ReplayHandlerNotifications(PVM pVM)
1968{
1969#ifndef USE_REM_STUBS
1970 Assert(VALID_PTR(pfnREMR3ReplayHandlerNotifications));
1971 pfnREMR3ReplayHandlerNotifications(pVM);
1972#endif
1973}
1974
1975REMR3DECL(int) REMR3NotifyCodePageChanged(PVM pVM, RTGCPTR pvCodePage)
1976{
1977#ifdef USE_REM_STUBS
1978 return VINF_SUCCESS;
1979#else
1980 Assert(VALID_PTR(pfnREMR3NotifyCodePageChanged));
1981 return pfnREMR3NotifyCodePageChanged(pVM, pvCodePage);
1982#endif
1983}
1984
1985REMR3DECL(void) REMR3NotifyPhysRamRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, unsigned fFlags)
1986{
1987#ifndef USE_REM_STUBS
1988 Assert(VALID_PTR(pfnREMR3NotifyPhysRamRegister));
1989 pfnREMR3NotifyPhysRamRegister(pVM, GCPhys, cb, fFlags);
1990#endif
1991}
1992
1993#ifndef VBOX_WITH_NEW_PHYS_CODE
1994REMR3DECL(void) REMR3NotifyPhysRamChunkRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, RTHCUINTPTR pvRam, unsigned fFlags)
1995{
1996#ifndef USE_REM_STUBS
1997 Assert(VALID_PTR(pfnREMR3NotifyPhysRamChunkRegister));
1998 pfnREMR3NotifyPhysRamChunkRegister(pVM, GCPhys, cb, pvRam, fFlags);
1999#endif
2000}
2001#endif
2002
2003REMR3DECL(void) REMR3NotifyPhysRomRegister(PVM pVM, RTGCPHYS GCPhys, RTUINT cb, void *pvCopy, bool fShadow)
2004{
2005#ifndef USE_REM_STUBS
2006 Assert(VALID_PTR(pfnREMR3NotifyPhysRomRegister));
2007 pfnREMR3NotifyPhysRomRegister(pVM, GCPhys, cb, pvCopy, fShadow);
2008#endif
2009}
2010
2011REMR3DECL(void) REMR3NotifyPhysReserve(PVM pVM, RTGCPHYS GCPhys, RTUINT cb)
2012{
2013#ifndef USE_REM_STUBS
2014 Assert(VALID_PTR(pfnREMR3NotifyPhysReserve));
2015 pfnREMR3NotifyPhysReserve(pVM, GCPhys, cb);
2016#endif
2017}
2018
2019REMR3DECL(void) REMR3NotifyHandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler)
2020{
2021#ifndef USE_REM_STUBS
2022 Assert(VALID_PTR(pfnREMR3NotifyHandlerPhysicalRegister));
2023 pfnREMR3NotifyHandlerPhysicalRegister(pVM, enmType, GCPhys, cb, fHasHCHandler);
2024#endif
2025}
2026
2027REMR3DECL(void) REMR3NotifyHandlerPhysicalDeregister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS cb, bool fHasHCHandler, bool fRestoreAsRAM)
2028{
2029#ifndef USE_REM_STUBS
2030 Assert(VALID_PTR(pfnREMR3NotifyHandlerPhysicalDeregister));
2031 pfnREMR3NotifyHandlerPhysicalDeregister(pVM, enmType, GCPhys, cb, fHasHCHandler, fRestoreAsRAM);
2032#endif
2033}
2034
2035REMR3DECL(void) REMR3NotifyHandlerPhysicalModify(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, RTGCPHYS cb, bool fHasHCHandler, bool fRestoreAsRAM)
2036{
2037#ifndef USE_REM_STUBS
2038 Assert(VALID_PTR(pfnREMR3NotifyHandlerPhysicalModify));
2039 pfnREMR3NotifyHandlerPhysicalModify(pVM, enmType, GCPhysOld, GCPhysNew, cb, fHasHCHandler, fRestoreAsRAM);
2040#endif
2041}
2042
2043REMDECL(bool) REMR3IsPageAccessHandled(PVM pVM, RTGCPHYS GCPhys)
2044{
2045#ifdef USE_REM_STUBS
2046 return false;
2047#else
2048 Assert(VALID_PTR(pfnREMR3IsPageAccessHandled));
2049 return pfnREMR3IsPageAccessHandled(pVM, GCPhys);
2050#endif
2051}
2052
2053REMR3DECL(int) REMR3DisasEnableStepping(PVM pVM, bool fEnable)
2054{
2055#ifdef USE_REM_STUBS
2056 return VERR_NOT_IMPLEMENTED;
2057#else
2058 Assert(VALID_PTR(pfnREMR3DisasEnableStepping));
2059 return pfnREMR3DisasEnableStepping(pVM, fEnable);
2060#endif
2061}
2062
2063REMR3DECL(void) REMR3NotifyPendingInterrupt(PVM pVM, uint8_t u8Interrupt)
2064{
2065#ifndef USE_REM_STUBS
2066 Assert(VALID_PTR(pfnREMR3NotifyPendingInterrupt));
2067 pfnREMR3NotifyPendingInterrupt(pVM, u8Interrupt);
2068#endif
2069}
2070
2071REMR3DECL(uint32_t) REMR3QueryPendingInterrupt(PVM pVM)
2072{
2073#ifdef USE_REM_STUBS
2074 return REM_NO_PENDING_IRQ;
2075#else
2076 Assert(VALID_PTR(pfnREMR3QueryPendingInterrupt));
2077 return pfnREMR3QueryPendingInterrupt(pVM);
2078#endif
2079}
2080
2081REMR3DECL(void) REMR3NotifyInterruptSet(PVM pVM)
2082{
2083#ifndef USE_REM_STUBS
2084 Assert(VALID_PTR(pfnREMR3NotifyInterruptSet));
2085 pfnREMR3NotifyInterruptSet(pVM);
2086#endif
2087}
2088
2089REMR3DECL(void) REMR3NotifyInterruptClear(PVM pVM)
2090{
2091#ifndef USE_REM_STUBS
2092 Assert(VALID_PTR(pfnREMR3NotifyInterruptClear));
2093 pfnREMR3NotifyInterruptClear(pVM);
2094#endif
2095}
2096
2097REMR3DECL(void) REMR3NotifyTimerPending(PVM pVM)
2098{
2099#ifndef USE_REM_STUBS
2100 Assert(VALID_PTR(pfnREMR3NotifyTimerPending));
2101 pfnREMR3NotifyTimerPending(pVM);
2102#endif
2103}
2104
2105REMR3DECL(void) REMR3NotifyDmaPending(PVM pVM)
2106{
2107#ifndef USE_REM_STUBS
2108 Assert(VALID_PTR(pfnREMR3NotifyDmaPending));
2109 pfnREMR3NotifyDmaPending(pVM);
2110#endif
2111}
2112
2113REMR3DECL(void) REMR3NotifyQueuePending(PVM pVM)
2114{
2115#ifndef USE_REM_STUBS
2116 Assert(VALID_PTR(pfnREMR3NotifyQueuePending));
2117 pfnREMR3NotifyQueuePending(pVM);
2118#endif
2119}
2120
2121REMR3DECL(void) REMR3NotifyFF(PVM pVM)
2122{
2123#ifndef USE_REM_STUBS
2124 /* the timer can call this early on, so don't be picky. */
2125 if (pfnREMR3NotifyFF)
2126 pfnREMR3NotifyFF(pVM);
2127#endif
2128}
2129
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