source: trunk/src/win32k/include/ldr.h@ 4164

Last change on this file since 4164 was 4164, checked in by bird, 25 years ago

Merged in the Grace branch. New Win32k!

File size: 8.8 KB
Line 
1/* $Id: ldr.h,v 1.6 2000-09-02 21:08:02 bird Exp $
2 *
3 * ldr - Our loader "subsystem" public header file.
4 *
5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11
12#ifndef _ldr_h_
13#define _ldr_h_
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19
20#ifndef LDR_INCL_INITONLY
21
22/*
23 * Fail if dependent header files is missing
24 */
25#ifndef _AVL_H_
26#error "You'll have to include avl.h before ldr.h!"
27#endif
28
29
30/** @design Loader State.
31 *
32 * Used to determin behaviour in different cases.
33 * Use the isLdrState<State> macros to query current state.
34 * IMPORTANT! Don't change this variable if you don't really mean it!
35 * And only change it thru the setLdrState* macros!
36 *
37 * The state is changing as follows:
38 * 1) Load a new program
39 * mytkExecPgm will set the state to LDRSTATE_TKEXECPGM on successful overloading.
40 * myldrOpenPath will set the type part of the loaderbits. (EXE,DLL or UNSUPPORTED)
41 * (NB! myldrOpenPath is called several times. First for the EXE then for imported modules.)
42 * IF executable THEN myLdrOpen might set the LDRSTATE_OUR flag.
43 * myldrOpenPath will reset the type part of the loaderbits upon return.
44 * mytkExecPgm resets the state to LDRSTATE_UNKNOWN upon return.
45 *
46 * 2) Query program type.
47 * myLDRQAppType will set the state to LDRSTATE_LDRQAPPTYPE on entry.
48 * myldrOpenPath will set the type part of the loaderbits. (EXE,DLL or UNSUPPORTED)
49 * (NB! myldrOpenPath may be called several times.)
50 * IF executable THEN myLdrOpen might set the LDRSTATE_OUR flag.
51 * myldrOpenPath will reset the type part of the loaderbits upon return.
52 * myLDRQAppType resets the state to LDRSTATE_UNKNOWN upon return.
53 *
54 * 3) Unknown invocation - probably DosLoadModule. Base state is LDRSTATE_UNKNOWN.
55 * myldrOpenPath will set the type part of the loaderbits. (EXE,DLL or UNSUPPORTED)
56 * (NB! myldrOpenPath is probably called several times. Import modules.)
57 * myldrOpenPath will reset the type part of the loaderbits upon return.
58 *
59 */
60extern ULONG ulLdrState;
61
62#define LDRSTATE_UNKNOWN 0 /* Default state - undertermined. */
63#define LDRSTATE_TKEXECPGM 1 /* A program is being loaded. */
64#define LDRSTATE_LDRQAPPTYPE 2 /* Loader called from LDRQAPPTYPE */
65/*#define LDRSTATE_LOADMODULE 3 */ /* A module is being loaded by DosLoadModule. Not implemented! */
66#define LDRSTATE_MASK 0x00FF /* State mask. */
67
68/*
69 * The following flags are only valid when myldrOpenPath is on the stack!, ie. in ldrOpen.
70 * These flags is the "loading-bits".
71 */
72#define LDRSTATE_EXE 0x0100 /* Flags telling that an executable is being opened. */
73#define LDRSTATE_DLL 0x0200 /* Flags telling that an dll is being opened. */
74#define LDRSTATE_UNSUPPORTED 0x0300 /* Flags telling to not override this open call. */
75#define LDRSTATE_TYPE_MASK 0x0f00 /* Load Type Mask. */
76/* The following flag will tell us if the executable which is loading is ours or not. */
77#define LDRSTATE_OUREXE 0x1000
78#define LDRSTATE_LOADERBITS 0xff00 /* Mask */
79
80
81/*
82 * Query macros.
83 */
84#define isLdrStateUnknown() ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_UNKNOWN)
85#define isLdrStateExecPgm() ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_TKEXECPGM)
86#define isLdrStateQAppType() ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_LDRQAPPTYPE)
87/*#define isLdrStateLoadModule() ((ulLdrState & LDRSTATE_MASK) == LDRSTATE_LOADMODULE)*/
88
89#define isLdrStateLoadingEXE() ((ulLdrState & LDRSTATE_TYPE_MASK) == LDRSTATE_EXE)
90#define isLdrStateLoadingDLL() ((ulLdrState & LDRSTATE_TYPE_MASK) == LDRSTATE_DLL)
91#define isLdrStateLoadingUnsupported() ((ulLdrState & LDRSTATE_TYPE_MASK) == LDRSTATE_UNSUPPORTED)
92
93#define isLdrStateLoadingOurEXE() (ulLdrState & LDRSTATE_OUREXE)
94
95
96/*
97 * Set macros.
98 */
99#define setLdrStateQAppType() ulLdrState = LDRSTATE_LDRQAPPTYPE
100#define setLdrStateUnknown() ulLdrState = LDRSTATE_UNKNOWN
101/* setLdrStateExecPgm() isn't needed as this is in assembly source! */
102/*#define setLdrStateLoadModule() ulLdrState = LDRSTATE_LOADMODULE */
103
104#define setLdrStateLoadingEXE() ulLdrState = (ulLdrState & (ULONG)(~LDRSTATE_TYPE_MASK)) | LDRSTATE_EXE
105#define setLdrStateLoadingDLL() ulLdrState = (ulLdrState & (ULONG)(~LDRSTATE_TYPE_MASK)) | LDRSTATE_DLL
106#define setLdrStateLoadingUnsupported() ulLdrState = (ulLdrState & (ULONG)(~LDRSTATE_TYPE_MASK)) | LDRSTATE_UNSUPPORTED
107#define setLdrStateClearLoadingType() ulLdrState &= (ULONG)(~LDRSTATE_TYPE_MASK)
108
109#define setLdrStateLoadingOurEXE() ulLdrState |= LDRSTATE_OUREXE
110
111
112/*
113 * Loader State assert macros.
114 */
115#define ASSERT_LdrStateUnknown(fn) ASSERT_LdrState(fn, LDRSTATE_UNKNOWN)
116#define ASSERT_LdrStateExecPgm(fn) ASSERT_LdrState(fn, LDRSTATE_TKEXECPGM)
117#define ASSERT_LdrStateQAppType(fn) ASSERT_LdrState(fn, LDRSTATE_LDRQAPPTYPE)
118
119#define ASSERT_LdrState(fn, state) \
120 { \
121 if ((ulLdrState & LDRSTATE_MASK) != (state)) \
122 { \
123 kprintf((fn ": assertion incorrect loader state. ulLdrState (%d) != " #state "(%d)", \
124 ulLdrState, state)); \
125 } \
126 }
127
128
129/*
130 * handle state - Array of handle states. Eight state per byte!
131 */
132#define MAX_FILE_HANDLES 0x10000
133
134extern unsigned char achHandleStates[MAX_FILE_HANDLES/8];
135
136#define HSTATE_UNUSED 0x00 /* Handle not used (or OS/2). */
137#define HSTATE_OS2 0x00 /* OS/2 module filehandle. */
138#define HSTATE_OUR 0x01 /* Our module filehandle. */
139#define HSTATE_MASK 0xFE
140#define HSTATE_UMASK 0x01
141
142#define GetState(a) (HSTATE_UMASK & (achHandleStates[(a)/8] >> ((a)%8)))
143#define SetState(a,b) (achHandleStates[(a)/8] = (achHandleStates[(a)/8] & (HSTATE_MASK << ((a)%8) | HSTATE_MASK >> 8-((a)%8)) | ((b) & 0x1) << ((a)%8)))
144
145
146/*
147 * Declare the module classes used below in case they aren't declared yet.
148 */
149#ifdef __cplusplus
150class ModuleBase;
151class Pe2Lx;
152class Elf2Lx;
153#else
154typedef char ModuleBase;
155typedef char Pe2Lx;
156typedef char Elf2Lx;
157#endif
158
159
160/*
161 * Module struct.
162 */
163typedef struct _Module
164{
165 AVLNODECORE coreKey; /* Key is hFile. */
166 AVLNODECORE coreMTE; /* Key is pMTE. */
167
168 SFN hFile; /* System file number or file handle if you prefer that. */
169 PMTE pMTE; /* Pointer to MTE if we got one - NULL is allowed. */
170
171 ULONG fFlags; /* Flags. Flags if coreMte is in use and what Data contains. */
172 union
173 {
174 ModuleBase *pModule; /* Pointer to base module. */
175 Pe2Lx * pPe2Lx; /* Pointer to a Pe2Lx object. (Win32 executables) */
176 Elf2Lx * pElf2Lx; /* Pointer to a Elf2Lx object. (ELF executables) */
177 #if 0
178 Script * pScript; /* Pointer to a Script object. (Shell scripts) */
179 Pe * pPe; /* Pointer to a Pe object. (Ring3 loader) */
180 #endif
181 } Data; /* Pointer to data. Currently it's allways a Pe2Lx object! */
182} MODULE, *PMODULE;
183
184#define MOD_FLAGS_IN_MTETREE 0x00000010UL /* The node is present in the MTE-tree. */
185#define MOD_TYPE_MASK 0x0000000FUL /* Type mask. */
186#define MOD_TYPE_PE2LX 0x00000001UL /* Pe2Lx module. */
187#define MOD_TYPE_ELF2LX 0x00000002UL /* Elf2Lx module. */
188#define MOD_TYPE_SCRIPT 0x00000003UL /* Script module. */
189#define MOD_TYPE_PE 0x00000004UL /* Pe module. */
190
191
192/*
193 * Pointer to the currently loading executable module.
194 * Available at tkExecPgm time when loading a converted module.
195 */
196extern PMODULE pExeModule;
197
198
199/*
200 * Modules operations.
201 */
202PMODULE getModuleBySFN(SFN hFile);
203PMODULE getModuleByMTE(PMTE pMTE);
204PMODULE getModuleByhMTE(HMTE hMTE);
205PMODULE getModuleByFilename(PCSZ pszFilename);
206
207ULONG addModule(SFN hFile, PMTE pMTE, ULONG fFlags, ModuleBase *pModObj);
208ULONG removeModule(SFN hFile);
209
210
211
212/*
213 * mytkExecPgm variables and functions
214 *
215 * (See ldr\mytkExecPgm.asm for further info on these variabels and functions.)
216 */
217#define CCHFILENAME 261 /* This is defined in mytkExecPgm.asm too. */
218#define CCHARGUMENTS 1536 /* This is defined in mytkExecPgm.asm too. */
219extern const char fTkExecPgm;
220extern char achTkExecPgmFilename[CCHFILENAME];
221extern char achTkExecPgmArguments[CCHARGUMENTS];
222#endif
223ULONG _Optlink tkExecPgmEnvLength(void);
224ULONG _Optlink tkExecPgmCopyEnv(char *pachBuffer, unsigned cchBuffer);
225
226
227
228/*
229 * functions
230 */
231PSZ ldrGetExePath(PSZ pszPath, BOOL fExecChild);
232ULONG ldrInit(void);
233
234#ifdef __cplusplus
235}
236#endif
237
238#pragma pack()
239
240#endif
Note: See TracBrowser for help on using the repository browser.