1 | /* $Id: tstLdrObj.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - 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-2020 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
18 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
19 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
20 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
21 | *
|
---|
22 | * The contents of this file may alternatively be used under the terms
|
---|
23 | * of the Common Development and Distribution License Version 1.0
|
---|
24 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
25 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
26 | * CDDL are applicable instead of those of the GPL.
|
---|
27 | *
|
---|
28 | * You may elect to license modified versions of this file under the
|
---|
29 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
30 | */
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 | /*********************************************************************************************************************************
|
---|
35 | * Header Files *
|
---|
36 | *********************************************************************************************************************************/
|
---|
37 | #ifndef IN_RC
|
---|
38 | # error "not IN_RC!"
|
---|
39 | #endif
|
---|
40 | #include <VBox/dis.h>
|
---|
41 | #include <VBox/vmm/vm.h>
|
---|
42 | #include <iprt/string.h>
|
---|
43 |
|
---|
44 |
|
---|
45 | /*********************************************************************************************************************************
|
---|
46 | * Global Variables *
|
---|
47 | *********************************************************************************************************************************/
|
---|
48 | static const char szStr1[] = "some readonly string";
|
---|
49 | static char szStr2[6000] = "some read/write string";
|
---|
50 | static char achBss[8192];
|
---|
51 |
|
---|
52 | #ifdef VBOX_SOME_IMPORT_FUNCTION
|
---|
53 | extern "C" DECLIMPORT(int) SomeImportFunction(void);
|
---|
54 | #endif
|
---|
55 |
|
---|
56 |
|
---|
57 | extern "C" DECLEXPORT(int) Entrypoint(void)
|
---|
58 | {
|
---|
59 | g_VM.fGlobalForcedActions = 0;
|
---|
60 | strcpy(achBss, szStr2);
|
---|
61 | memcpy(achBss, szStr1, sizeof(szStr1));
|
---|
62 | memcpy(achBss, &g_VM, RT_MIN(sizeof(g_VM), sizeof(achBss)));
|
---|
63 | memcpy(achBss, (void *)(uintptr_t)&Entrypoint, 32);
|
---|
64 | #ifdef VBOX_SOME_IMPORT_FUNCTION
|
---|
65 | memcpy(achBss, (void *)(uintptr_t)&SomeImportFunction, 32);
|
---|
66 | return SomeImportFunction();
|
---|
67 | #else
|
---|
68 | return 0;
|
---|
69 | #endif
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | extern "C" DECLEXPORT(uint32_t) SomeExportFunction1(void *pvBuf)
|
---|
74 | {
|
---|
75 | memcpy(pvBuf, &g_VM, sizeof(g_VM));
|
---|
76 | return g_VM.fGlobalForcedActions;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | extern "C" DECLEXPORT(char *) SomeExportFunction2(void *pvBuf)
|
---|
81 | {
|
---|
82 | NOREF(pvBuf);
|
---|
83 | return (char *)memcpy(achBss, szStr1, sizeof(szStr1));
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | extern "C" DECLEXPORT(char *) SomeExportFunction3(void *pvBuf)
|
---|
88 | {
|
---|
89 | NOREF(pvBuf);
|
---|
90 | return (char *)memcpy(achBss, szStr2, strlen(szStr2));
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | extern "C" DECLEXPORT(void *) SomeExportFunction4(void)
|
---|
95 | {
|
---|
96 | static unsigned cb;
|
---|
97 | DISCPUSTATE Cpu;
|
---|
98 | DISInstr((void *)(uintptr_t)SomeExportFunction3, DISCPUMODE_32BIT, &Cpu, &cb);
|
---|
99 | return (void *)(uintptr_t)&SomeExportFunction1;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | extern "C" DECLEXPORT(uintptr_t) SomeExportFunction5(void)
|
---|
104 | {
|
---|
105 | return (uintptr_t)SomeExportFunction3(NULL) + (uintptr_t)SomeExportFunction2(NULL)
|
---|
106 | + (uintptr_t)SomeExportFunction1(NULL) + (uintptr_t)&SomeExportFunction4;
|
---|
107 | }
|
---|
108 |
|
---|