1 | /* $Id: tstLdrObjR0.cpp 4071 2007-08-07 17:07:59Z 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-2007 innotek 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 |
|
---|
23 |
|
---|
24 |
|
---|
25 | /*******************************************************************************
|
---|
26 | * Header Files *
|
---|
27 | *******************************************************************************/
|
---|
28 | #ifndef IN_RING0
|
---|
29 | # error "not IN_RING0!"
|
---|
30 | #endif
|
---|
31 | #include <VBox/dis.h>
|
---|
32 | #include <VBox/disopcode.h>
|
---|
33 | #include <iprt/string.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | /*******************************************************************************
|
---|
37 | * Global Variables *
|
---|
38 | *******************************************************************************/
|
---|
39 | static const char szStr1[] = "some readonly string";
|
---|
40 | static char szStr2[6000] = "some read/write string";
|
---|
41 | static char achBss[8192];
|
---|
42 |
|
---|
43 | #ifdef VBOX_SOME_IMPORT_FUNCTION
|
---|
44 | extern "C" DECLIMPORT(int) SomeImportFunction(void);
|
---|
45 | #endif
|
---|
46 |
|
---|
47 |
|
---|
48 | extern "C" DECLEXPORT(int) Entrypoint(void)
|
---|
49 | {
|
---|
50 | strcpy(achBss, szStr2);
|
---|
51 | memcpy(achBss, szStr1, sizeof(szStr1));
|
---|
52 | memcpy(achBss, (void *)(uintptr_t)&Entrypoint, 32);
|
---|
53 | #ifdef VBOX_SOME_IMPORT_FUNCTION
|
---|
54 | memcpy(achBss, (void *)(uintptr_t)&SomeImportFunction, 32);
|
---|
55 | return SomeImportFunction();
|
---|
56 | #else
|
---|
57 | return 0;
|
---|
58 | #endif
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | extern "C" DECLEXPORT(uint32_t) SomeExportFunction1(void *pvBuf)
|
---|
63 | {
|
---|
64 | return achBss[0] + achBss[16384];
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | extern "C" DECLEXPORT(char *) SomeExportFunction2(void *pvBuf)
|
---|
69 | {
|
---|
70 | return (char *)memcpy(achBss, szStr1, sizeof(szStr1));
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | extern "C" DECLEXPORT(char *) SomeExportFunction3(void *pvBuf)
|
---|
75 | {
|
---|
76 | return (char *)memcpy(achBss, szStr2, strlen(szStr2));
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | extern "C" DECLEXPORT(void *) SomeExportFunction4(void)
|
---|
81 | {
|
---|
82 | static unsigned cb;
|
---|
83 | DISCPUSTATE Cpu = {0};
|
---|
84 | DISCoreOne(&Cpu, (uintptr_t)SomeExportFunction3, &cb);
|
---|
85 | return (void *)(uintptr_t)&SomeExportFunction1;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | extern "C" DECLEXPORT(uintptr_t) SomeExportFunction5(void)
|
---|
90 | {
|
---|
91 | return (uintptr_t)SomeExportFunction3(NULL) + (uintptr_t)SomeExportFunction2(NULL)
|
---|
92 | + (uintptr_t)SomeExportFunction1(NULL) + (uintptr_t)&SomeExportFunction4;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|