VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstLdrObjR0.cpp@ 96781

Last change on this file since 96781 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.9 KB
Line 
1/* $Id: tstLdrObjR0.cpp 96407 2022-08-22 17:43:14Z 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-2022 Oracle and/or its affiliates.
13 *
14 * This file is part of VirtualBox base platform packages, as
15 * available from https://www.virtualbox.org.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation, in version 3 of the
20 * License.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, see <https://www.gnu.org/licenses>.
29 *
30 * The contents of this file may alternatively be used under the terms
31 * of the Common Development and Distribution License Version 1.0
32 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
33 * in the VirtualBox distribution, in which case the provisions of the
34 * CDDL are applicable instead of those of the GPL.
35 *
36 * You may elect to license modified versions of this file under the
37 * terms and conditions of either the GPL or the CDDL or both.
38 *
39 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
40 */
41
42
43
44/*********************************************************************************************************************************
45* Header Files *
46*********************************************************************************************************************************/
47#ifndef IN_RING0
48# error "not IN_RING0!"
49#endif
50#include <VBox/dis.h>
51#include <VBox/disopcode.h>
52#include <iprt/string.h>
53
54
55/*********************************************************************************************************************************
56* Global Variables *
57*********************************************************************************************************************************/
58static const char szStr1[] = "some readonly string";
59static char szStr2[6000] = "some read/write string";
60static char achBss[8192];
61
62#ifdef VBOX_SOME_IMPORT_FUNCTION
63extern "C" DECLIMPORT(int) SomeImportFunction(void);
64#endif
65
66
67extern "C" DECLEXPORT(int) Entrypoint(void)
68{
69 strcpy(achBss, szStr2);
70 memcpy(achBss, szStr1, sizeof(szStr1));
71 memcpy(achBss, (void *)(uintptr_t)&Entrypoint, 32);
72#ifdef VBOX_SOME_IMPORT_FUNCTION
73 memcpy(achBss, (void *)(uintptr_t)&SomeImportFunction, 32);
74 return SomeImportFunction();
75#else
76 return 0;
77#endif
78}
79
80
81extern "C" DECLEXPORT(uint32_t) SomeExportFunction1(void *pvBuf)
82{
83 NOREF(pvBuf);
84 return achBss[0] + achBss[16384];
85}
86
87
88extern "C" DECLEXPORT(char *) SomeExportFunction2(void *pvBuf)
89{
90 NOREF(pvBuf);
91 return (char *)memcpy(achBss, szStr1, sizeof(szStr1));
92}
93
94
95extern "C" DECLEXPORT(char *) SomeExportFunction3(void *pvBuf)
96{
97 NOREF(pvBuf);
98 return (char *)memcpy(achBss, szStr2, strlen(szStr2));
99}
100
101
102extern "C" DECLEXPORT(void *) SomeExportFunction4(void)
103{
104 static unsigned cb;
105 DISCPUSTATE Cpu;
106
107 memset(&Cpu, 0, sizeof(Cpu));
108
109 DISInstr((void *)(uintptr_t)SomeExportFunction3, DISCPUMODE_32BIT, &Cpu, &cb);
110 return (void *)(uintptr_t)&SomeExportFunction1;
111}
112
113
114extern "C" DECLEXPORT(uintptr_t) SomeExportFunction5(void)
115{
116 return (uintptr_t)SomeExportFunction3(NULL) + (uintptr_t)SomeExportFunction2(NULL)
117 + (uintptr_t)SomeExportFunction1(NULL) + (uintptr_t)&SomeExportFunction4;
118}
119
Note: See TracBrowser for help on using the repository browser.

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