/* $Id: kLdrDyldOS.c 2883 2006-11-18 11:21:33Z bird $ */ /** @file * * kLdr - The Dynamic Loader, OS specific operations. * * Copyright (c) 2006 knut st. osmundsen * * * This file is part of kLdr. * * kLdr 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; either version 2 of the License, or * (at your option) any later version. * * kLdr is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with kLdr; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /******************************************************************************* * Header Files * *******************************************************************************/ #ifdef __OS2__ # define INCL_BASE # define INCL_ERRORS # include #elif defined(__WIN__) # include #else # error "port me" #endif #include #include "kLdrHlp.h" #include "kLdrInternal.h" /** * Allocates a stack. * * @returns Pointer to the stack. NULL on allocation failure (assumes out of memory). * @param cb The size of the stack. This shall be page aligned. * If 0, a OS specific default stack size will be employed. */ void *kldrDyldOSAllocStack(size_t cb) { #ifdef __OS2__ APIRET rc; PVOID pv; if (!cb) cb = 1 * 1024*1024; /* 1MB */ rc = DosAllocMem(&pv, cb, OBJ_TILE | PAG_COMMIT | PAG_WRITE | PAG_READ); if (rc == NO_ERROR) return pv; return NULL; #elif defined(__WIN__) if (!cb) cb = 1 *1024*1024; /* 1MB */ return VirtualAlloc(NULL, cb, MEM_COMMIT, PAGE_READWRITE); #else # error "Port me" #endif } /** * Invokes the main executable entry point with whatever * parameters specific to the host OS and/or module format. * * @returns * @param uMainEPAddress The address of the main entry point. * @param pvStack Pointer to the stack object. * @param cbStack The size of the stack object. */ int kldrDyldOSStartExe(uintptr_t uMainEPAddress, void *pvStack, size_t cbStack) { #if defined(__OS2__) #elif defined(__WIN__) /* * Invoke the entrypoint on the current stack for now. * Deal with other formats and stack switching another day. */ int rc; int (*pfnEP)(void); pfnEP = (int (*)(void))uMainEPAddress; rc = pfnEP(); TerminateProcess(GetCurrentProcess(), rc); kldrHlpAssert(!"TerminateProcess failed"); for (;;) TerminateProcess(GetCurrentProcess(), rc); /*#elif defined(__NT__)*/ #else # error "Port me" #endif return -1; } void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, size_t cbStack) { /*kldrHlpAssert(!"not implemented");*/ /** @todo implement this properly! */ kldrDyldDoLoadExe(pExe); }