/* $Id: tstLdrObjR0.cpp 2981 2007-06-01 16:01:28Z 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-2007 innotek 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_RING0 # error "not IN_RING0!" #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) { strcpy(achBss, szStr2); memcpy(achBss, szStr1, sizeof(szStr1)); 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) { return achBss[0] + achBss[16384]; } 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, (uintptr_t)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; }