VirtualBox

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

Last change on this file since 12246 was 11897, checked in by vboxsync, 16 years ago

Resync the whole CPU state after saved state restore.

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