VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstLdrObj.cpp@ 102335

Last change on this file since 102335 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.9 KB
Line 
1/* $Id: tstLdrObj.cpp 98103 2023-01-17 14:15:46Z 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-2023 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_RC
48# error "not IN_RC!"
49#endif
50#include <VBox/dis.h>
51#include <VBox/vmm/vm.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 g_VM.fGlobalForcedActions = 0;
70 strcpy(achBss, szStr2);
71 memcpy(achBss, szStr1, sizeof(szStr1));
72 memcpy(achBss, &g_VM, RT_MIN(sizeof(g_VM), sizeof(achBss)));
73 memcpy(achBss, (void *)(uintptr_t)&Entrypoint, 32);
74#ifdef VBOX_SOME_IMPORT_FUNCTION
75 memcpy(achBss, (void *)(uintptr_t)&SomeImportFunction, 32);
76 return SomeImportFunction();
77#else
78 return 0;
79#endif
80}
81
82
83extern "C" DECLEXPORT(uint32_t) SomeExportFunction1(void *pvBuf)
84{
85 memcpy(pvBuf, &g_VM, sizeof(g_VM));
86 return g_VM.fGlobalForcedActions;
87}
88
89
90extern "C" DECLEXPORT(char *) SomeExportFunction2(void *pvBuf)
91{
92 NOREF(pvBuf);
93 return (char *)memcpy(achBss, szStr1, sizeof(szStr1));
94}
95
96
97extern "C" DECLEXPORT(char *) SomeExportFunction3(void *pvBuf)
98{
99 NOREF(pvBuf);
100 return (char *)memcpy(achBss, szStr2, strlen(szStr2));
101}
102
103
104extern "C" DECLEXPORT(void *) SomeExportFunction4(void)
105{
106 static unsigned cb;
107 DISCPUSTATE Cpu;
108 DISInstr((void *)(uintptr_t)SomeExportFunction3, DISCPUMODE_32BIT, &Cpu, &cb);
109 return (void *)(uintptr_t)&SomeExportFunction1;
110}
111
112
113extern "C" DECLEXPORT(uintptr_t) SomeExportFunction5(void)
114{
115 return (uintptr_t)SomeExportFunction3(NULL) + (uintptr_t)SomeExportFunction2(NULL)
116 + (uintptr_t)SomeExportFunction1(NULL) + (uintptr_t)&SomeExportFunction4;
117}
118
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