VirtualBox

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

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

Updated headers

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

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