source: trunk/kLdr/kLdr.h@ 2821

Last change on this file since 2821 was 2821, checked in by bird, 19 years ago

kLdr backup commit.

File size: 5.3 KB
RevLine 
[2821]1/* $Id: $ */
2/** @file
3 *
4 * kLdr - The Dynamic Loader.
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#ifndef __kLdr_h__
28#define __kLdr_h__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <sys/types.h>
35#include <stdint.h>
36
37/** A KLDRMOD handle. */
38typedef struct KLDRMOD *HKLDRMOD;
39
40/**
41 * Loader segment.
42 */
43typedef struct KLDRSEG
44{
45 /** The segment load address. */
46 void *pv;
47 /** The size of the segment. */
48 size_t cb;
49 /** The segment is readable. */
50 uint32_t fRead : 1;
51 /** The segment is writable. */
52 uint32_t fWrite : 1;
53 /** The segment is executable. */
54 uint32_t fExecute : 1;
55 /** Reserved for future use. */
56 uint32_t fReserved : 29;
57 /** Reserved for future use. */
58 uint32_t u32Reserved;
59} KLDRSEG, *PKLDRSEG;
60
61
62/**
63 * Loader module type.
64 */
65typedef enum KLDRTYPE
66{
67 /** The usual invalid 0 type. */
68 KLDRTYPE_INVALID = 0,
69 /** The native OS loader. */
70 KLDRTYPE_NATIVE,
71 /** The LX loader. */
72 KLDRTYPE_LX,
73 /** The end type (not included). */
74 KLDRTYPE_END,
75 /** Hack to blow the type up to 32-bit. */
76 KLDRTYPE_32BIT_HACK = 0x7fffffff
77} KLDRTYPE;
78
79
80/**
81 * The state of a module.
82 */
83typedef enum KLDRSTATE
84{
85 /** The usual invalid 0 enum. */
86 KLDRSTATE_INVALID = 0,
87 /** kldrOpen succeeded.
88 * Modules in this state will be freed at */
89 KLDRSTATE_OPEN,
90 /** Dependencies has been loaded. */
91 KLDRSTATE_DEPS,
92 /** Fixups has been applied. */
93 KLDRSTATE_FIXED,
94 /** The module has been initialized. */
95 KLDRSTATE_INITED,
96 /** The module is loaded successfully. */
97 KLDRSTATE_LOADED,
98 /** The end of valid states (exclusive) */
99 KLDRSTATE_END,
100 /** The usual 32-bit blowup. */
101 KLDRSTATE_32BIT_HACK = 0x7fffffff
102} KLDRSTATE;
103
104
105/**
106 * Loader module.
107 */
108typedef struct KLDRMOD
109{
110 /** Pointer to the next module. */
111 struct KLDRMOD *pNext;
112 /** Pointer to the previous module. */
113 struct KLDRMOD *pPrev;
114 /** Our module handle. */
115 HKLDRMOD hmod;
116 /** The module data. */
117 void *pvData;
118 /** The type of module this is. */
119 KLDRTYPE enmType;
120 /** The module state. */
121 KLDRSTATE enmState;
122 /** The number of references. */
123 uint32_t cRefs;
124 /** The number of dynamic references. */
125 uint32_t cDynRefs;
126 /** Magic number. */
127 uint32_t u32Magic;
128 /** Set if this is the executable module. */
129 uint32_t fExecutable : 1;
130 /** Global DLL (set) or specific DLL (clear). */
131 uint32_t fGlobal : 1;
132 /** Load stage one. */
133 uint32_t fLoadStageOne : 1;
134 /** Reserved for future use. */
135 uint32_t fReserved : 29;
136 /** The filename length (bytes). */
137 uint32_t cchFilename;
138 /** The filename. */
139 const char *pszFilename;
140 /** The module name. */
141 const char *pszName;
142 /** The module name length (bytes). */
143 uint32_t cchName;
144 /** The number of segments in the module. */
145 uint32_t cSegments;
146 /** Segments. (variable size, can be zero) */
147 KLDRSEG aSegments[1];
148} KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
149
150/** Pointer to the head module (the executable). */
151extern PKLDRMOD kLdrModuleHead;
152/** Pointer to the tail module. */
153extern PKLDRMOD kLdrModuleTail;
154/** The Library search path. */
155extern char kLdrLibraryPath[4096];
156
157/** @name Process Bootstrapping
158 * @{ */
159
160/**
161 * Argument package from the stub.
162 */
163typedef struct KLDREXEARGS
164{
165 /** Flags. (Currently unused, MBZ.) */
166 uint32_t fFlags;
167 /** The executable file that the stub is supposed to load. */
168 char szExecutable[260];
169 /** The LD_LIBRARY_PATH prefix for the process.. */
170 char szLibPath[4096 - 260 - sizeof(uint32_t)];
171} KLDREXEARGS, *PKLDREXEARGS;
172
173void kLdrLoadExe(PKLDREXEARGS pArgs);
174/** @} */
175
176/** @name The Internal APIs
177 * @internal
178 * @{ */
179int kldrOpenExe(const char *pszFilename, PPKLDRMOD ppMod)
180int kldrOpen(const char *pszFilename, unsigned fFlags, PPKLDRMOD ppMod);
181int kldrClose(PKLDRMOD pMod);
182
183void kldrFailure(const char *pszFilename, ...);
184/** @} */
185
186/*
187int kLdrLoadDll(const char *pszFilename, unsigned fFlags, unsigned long *pvmod);
188*/
189
190#ifndef NULL
191# define NULL 0
192#endif
193
194#ifdef __cplusplus
195}
196#endif
197
198#endif
199
Note: See TracBrowser for help on using the repository browser.