1 | /* $Id: tstLdrObj.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * InnoTek Portable Runtime - RTLdr test object.
|
---|
4 | *
|
---|
5 | * We use precompiled versions of this object for testing all the loaders.
|
---|
6 | *
|
---|
7 | * This is not supposed to be pretty or usable code, just something which
|
---|
8 | * make life difficult for the loader.
|
---|
9 | */
|
---|
10 |
|
---|
11 | /*
|
---|
12 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
13 | *
|
---|
14 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
15 | * available from http://www.virtualbox.org. This file is free software;
|
---|
16 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
17 | * General Public License as published by the Free Software Foundation,
|
---|
18 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
19 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
20 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
21 | *
|
---|
22 | * If you received this file as part of a commercial VirtualBox
|
---|
23 | * distribution, then only the terms of your commercial VirtualBox
|
---|
24 | * license agreement apply instead of the previous paragraph.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | /*******************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *******************************************************************************/
|
---|
32 | #ifndef IN_GC
|
---|
33 | # error "not IN_GC!"
|
---|
34 | #endif
|
---|
35 | #include <VBox/dis.h>
|
---|
36 | #include <VBox/vm.h>
|
---|
37 | #include <iprt/string.h>
|
---|
38 |
|
---|
39 |
|
---|
40 | /*******************************************************************************
|
---|
41 | * Global Variables *
|
---|
42 | *******************************************************************************/
|
---|
43 | static const char szStr1[] = "some readonly string";
|
---|
44 | static char szStr2[6000] = "some read/write string";
|
---|
45 | static char achBss[8192];
|
---|
46 |
|
---|
47 | #ifdef VBOX_SOME_IMPORT_FUNCTION
|
---|
48 | extern "C" DECLIMPORT(int) SomeImportFunction(void);
|
---|
49 | #endif
|
---|
50 |
|
---|
51 |
|
---|
52 | extern "C" DECLEXPORT(int) Entrypoint(void)
|
---|
53 | {
|
---|
54 | g_VM.fRawR0Enabled = true;
|
---|
55 | g_VM.fRawR3Enabled = true;
|
---|
56 | g_VM.fForcedActions = 0;
|
---|
57 | strcpy(achBss, szStr2);
|
---|
58 | memcpy(achBss, szStr1, sizeof(szStr1));
|
---|
59 | memcpy(achBss, &g_VM, RT_MIN(sizeof(g_VM), sizeof(achBss)));
|
---|
60 | memcpy(achBss, (void *)(uintptr_t)&Entrypoint, 32);
|
---|
61 | #ifdef VBOX_SOME_IMPORT_FUNCTION
|
---|
62 | memcpy(achBss, (void *)(uintptr_t)&SomeImportFunction, 32);
|
---|
63 | return SomeImportFunction();
|
---|
64 | #else
|
---|
65 | return 0;
|
---|
66 | #endif
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | extern "C" DECLEXPORT(uint32_t) SomeExportFunction1(void *pvBuf)
|
---|
71 | {
|
---|
72 | memcpy(pvBuf, &g_VM, sizeof(g_VM));
|
---|
73 | return g_VM.fForcedActions;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | extern "C" DECLEXPORT(char *) SomeExportFunction2(void *pvBuf)
|
---|
78 | {
|
---|
79 | return (char *)memcpy(achBss, szStr1, sizeof(szStr1));
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | extern "C" DECLEXPORT(char *) SomeExportFunction3(void *pvBuf)
|
---|
84 | {
|
---|
85 | return (char *)memcpy(achBss, szStr2, strlen(szStr2));
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | extern "C" DECLEXPORT(void *) SomeExportFunction4(void)
|
---|
90 | {
|
---|
91 | static unsigned cb;
|
---|
92 | DISCPUSTATE Cpu = {0};
|
---|
93 | DISCoreOne(&Cpu, (RTGCUINTPTR)SomeExportFunction3, &cb);
|
---|
94 | return (void *)(uintptr_t)&SomeExportFunction1;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | extern "C" DECLEXPORT(uintptr_t) SomeExportFunction5(void)
|
---|
99 | {
|
---|
100 | return (uintptr_t)SomeExportFunction3(NULL) + (uintptr_t)SomeExportFunction2(NULL)
|
---|
101 | + (uintptr_t)SomeExportFunction1(NULL) + (uintptr_t)&SomeExportFunction4;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|