VirtualBox

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

Last change on this file since 11497 was 11312, checked in by vboxsync, 16 years ago

REM: ELEMENTS -> RT_ELEMENTS.

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