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

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

WIN* DARWIN and OS2 removal.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/* $Id: kLdrDyldOS.c 3582 2007-09-02 22:26:42Z 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#include <k/kLdr.h>
32#include "kLdrInternal.h"
33
34#if K_OS == K_OS_OS2
35# define INCL_BASE
36# define INCL_ERRORS
37# include <os2.h>
38
39#elif K_OS == K_OS_WINDOWS
40# undef IMAGE_DOS_SIGNATURE
41# undef IMAGE_NT_SIGNATURE
42# include <Windows.h>
43
44#else
45# error "port me"
46#endif
47
48
49/**
50 * Allocates a stack.
51 *
52 * @returns Pointer to the stack. NULL on allocation failure (assumes out of memory).
53 * @param cb The size of the stack. This shall be page aligned.
54 * If 0, a OS specific default stack size will be employed.
55 */
56void *kldrDyldOSAllocStack(KSIZE cb)
57{
58#if K_OS == K_OS_OS2
59 APIRET rc;
60 PVOID pv;
61
62 if (!cb)
63 cb = 1 * 1024*1024; /* 1MB */
64
65 rc = DosAllocMem(&pv, cb, OBJ_TILE | PAG_COMMIT | PAG_WRITE | PAG_READ);
66 if (rc == NO_ERROR)
67 return pv;
68 return NULL;
69
70#elif K_OS == K_OS_WINDOWS
71
72 if (!cb)
73 cb = 1 *1024*1024; /* 1MB */
74
75 return VirtualAlloc(NULL, cb, MEM_COMMIT, PAGE_READWRITE);
76
77#else
78# error "Port me"
79#endif
80}
81
82
83/**
84 * Invokes the main executable entry point with whatever
85 * parameters specific to the host OS and/or module format.
86 *
87 * @returns
88 * @param uMainEPAddress The address of the main entry point.
89 * @param pvStack Pointer to the stack object.
90 * @param cbStack The size of the stack object.
91 */
92int kldrDyldOSStartExe(KUPTR uMainEPAddress, void *pvStack, KSIZE cbStack)
93{
94#if defined(__OS2__)
95
96#elif K_OS == K_OS_WINDOWS
97 /*
98 * Invoke the entrypoint on the current stack for now.
99 * Deal with other formats and stack switching another day.
100 */
101 int rc;
102 int (*pfnEP)(void);
103 pfnEP = (int (*)(void))uMainEPAddress;
104
105 rc = pfnEP();
106
107 TerminateProcess(GetCurrentProcess(), rc);
108 kHlpAssert(!"TerminateProcess failed");
109 for (;;)
110 TerminateProcess(GetCurrentProcess(), rc);
111
112/*#elif defined(__NT__)*/
113#else
114# error "Port me"
115#endif
116
117 return -1;
118}
119
120
121void kldrDyldDoLoadExeStackSwitch(PKLDRDYLDMOD pExe, void *pvStack, KSIZE cbStack)
122{
123 /*kHlpAssert(!"not implemented");*/
124
125 /** @todo implement this properly! */
126 kldrDyldDoLoadExe(pExe);
127}
Note: See TracBrowser for help on using the repository browser.