source: trunk/kStuff/kLdr/kLdrDyldOS.c@ 3573

Last change on this file since 3573 was 3573, checked in by bird, 18 years ago

kHlp work...

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1/* $Id: kLdrDyldOS.c 3573 2007-08-31 04:09:23Z bird $ */
2/** @file
3 *
4 * kLdr - The Dynamic Loader, OS specific operations.
5 *
6 * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
7 *
8 *
9 * This file is part of kLdr.
10 *
11 * kLdr is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * kLdr is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with kLdr; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#ifdef __OS2__
32# define INCL_BASE
33# define INCL_ERRORS
34# include <os2.h>
35#elif defined(__WIN__)
36# include <Windows.h>
37#else
38# error "port me"
39#endif
40
41#include <k/kLdr.h>
42#include "kLdrInternal.h"
43
44
45/**
46 * Allocates a stack.
47 *
48 * @returns Pointer to the stack. NULL on allocation failure (assumes out of memory).
49 * @param cb The size of the stack. This shall be page aligned.
50 * If 0, a OS specific default stack size will be employed.
51 */
52void *kldrDyldOSAllocStack(KSIZE cb)
53{
54#ifdef __OS2__
55 APIRET rc;
56 PVOID pv;
57
58 if (!cb)
59 cb = 1 * 1024*1024; /* 1MB */
60
61 rc = DosAllocMem(&pv, cb, OBJ_TILE | PAG_COMMIT | PAG_WRITE | PAG_READ);
62 if (rc == NO_ERROR)
63 return pv;
64 return NULL;
65
66#elif defined(__WIN__)
67
68 if (!cb)
69 cb = 1 *1024*1024; /* 1MB */
70
71 return VirtualAlloc(NULL, cb, MEM_COMMIT, PAGE_READWRITE);
72
73#else
74# error "Port me"
75#endif
76}
77
78
79/**
80 * Invokes the main executable entry point with whatever
81 * parameters specific to the host OS and/or module format.
82 *
83 * @returns
84 * @param uMainEPAddress The address of the main entry point.
85 * @param pvStack Pointer to the stack object.
86 * @param cbStack The size of the stack object.
87 */
88int kldrDyldOSStartExe(KUPTR uMainEPAddress, void *pvStack, KSIZE cbStack)
89{
90#if defined(__OS2__)
91
92#elif defined(__WIN__)
93 /*
94 * Invoke the entrypoint on the current stack for now.
95 * Deal with other formats and stack switching another day.
96 */
97 int rc;
98 int (*pfnEP)(void);
99 pfnEP = (int (*)(void))uMainEPAddress;
100
101 rc = pfnEP();
102
103 TerminateProcess(GetCurrentProcess(), rc);
104 kHlpAssert(!"TerminateProcess failed");
105 for (;;)
106 TerminateProcess(GetCurrentProcess(), rc);
107
108/*#elif defined(__NT__)*/
109#else
110# error "Port me"
111#endif
112
113 return -1;
114}
115
116
117void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, KSIZE cbStack)
118{
119 /*kHlpAssert(!"not implemented");*/
120
121 /** @todo implement this properly! */
122 kldrDyldDoLoadExe(pExe);
123}
Note: See TracBrowser for help on using the repository browser.