/* $Id: tstLdrObj.cpp 1 1970-01-01 00:00:00Z vboxsync $ */ /** @file * InnoTek Portable Runtime - RTLdr test object. * * We use precompiled versions of this object for testing all the loaders. * * This is not supposed to be pretty or usable code, just something which * make life difficult for the loader. */ /* * Copyright (C) 2006 InnoTek Systemberatung GmbH * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation, * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE * distribution. VirtualBox OSE is distributed in the hope that it will * be useful, but WITHOUT ANY WARRANTY of any kind. * * If you received this file as part of a commercial VirtualBox * distribution, then only the terms of your commercial VirtualBox * license agreement apply instead of the previous paragraph. */ /******************************************************************************* * Header Files * *******************************************************************************/ #ifndef IN_GC # error "not IN_GC!" #endif #include #include #include /******************************************************************************* * Global Variables * *******************************************************************************/ static const char szStr1[] = "some readonly string"; static char szStr2[6000] = "some read/write string"; static char achBss[8192]; #ifdef VBOX_SOME_IMPORT_FUNCTION extern "C" DECLIMPORT(int) SomeImportFunction(void); #endif extern "C" DECLEXPORT(int) Entrypoint(void) { g_VM.fRawR0Enabled = true; g_VM.fRawR3Enabled = true; g_VM.fForcedActions = 0; strcpy(achBss, szStr2); memcpy(achBss, szStr1, sizeof(szStr1)); memcpy(achBss, &g_VM, RT_MIN(sizeof(g_VM), sizeof(achBss))); memcpy(achBss, (void *)(uintptr_t)&Entrypoint, 32); #ifdef VBOX_SOME_IMPORT_FUNCTION memcpy(achBss, (void *)(uintptr_t)&SomeImportFunction, 32); return SomeImportFunction(); #else return 0; #endif } extern "C" DECLEXPORT(uint32_t) SomeExportFunction1(void *pvBuf) { memcpy(pvBuf, &g_VM, sizeof(g_VM)); return g_VM.fForcedActions; } extern "C" DECLEXPORT(char *) SomeExportFunction2(void *pvBuf) { return (char *)memcpy(achBss, szStr1, sizeof(szStr1)); } extern "C" DECLEXPORT(char *) SomeExportFunction3(void *pvBuf) { return (char *)memcpy(achBss, szStr2, strlen(szStr2)); } extern "C" DECLEXPORT(void *) SomeExportFunction4(void) { static unsigned cb; DISCPUSTATE Cpu = {0}; DISCoreOne(&Cpu, (RTGCUINTPTR)SomeExportFunction3, &cb); return (void *)(uintptr_t)&SomeExportFunction1; } extern "C" DECLEXPORT(uintptr_t) SomeExportFunction5(void) { return (uintptr_t)SomeExportFunction3(NULL) + (uintptr_t)SomeExportFunction2(NULL) + (uintptr_t)SomeExportFunction1(NULL) + (uintptr_t)&SomeExportFunction4; }