Changeset 4164 for trunk/src/win32k/include/ldr.h
- Timestamp:
- Sep 2, 2000, 11:08:23 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/include/ldr.h
r2501 r4164 1 /* $Id: ldr.h,v 1. 5 2000-01-22 18:20:59bird Exp $2 * 3 * ldr - loaderheader file.4 * 5 * Copyright (c) 1999 knut St. osmundsen1 /* $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 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT … … 12 12 #ifndef _ldr_h_ 13 13 #define _ldr_h_ 14 #ifndef LDR_INCL_INITONLY 15 /* state variable */ 16 extern BOOL fQAppType; 17 18 /* 19 * handle state - Array of handle states. Eight state per byte! 20 */ 21 #define MAX_FILE_HANDLES 0x10000 22 23 extern unsigned char achHandleStates[MAX_FILE_HANDLES/8]; 24 25 #define HSTATE_UNUSED 0x00 /* Handle not used (or OS/2). */ 26 #define HSTATE_OS2 0x00 /* OS/2 module filehandle. */ 27 #define HSTATE_OUR 0x01 /* Our module filehandle. */ 28 #define HSTATE_MASK 0xFE 29 #define HSTATE_UMASK 0x01 30 31 #define GetState(a) (HSTATE_UMASK & (achHandleStates[(a)/8] >> ((a)%8))) 32 #define SetState(a,b) (achHandleStates[(a)/8] = (achHandleStates[(a)/8] & (HSTATE_MASK << ((a)%8) | HSTATE_MASK >> 8-((a)%8)) | ((b) & 0x1) << ((a)%8))) 33 34 35 /* 36 * Module struct. 37 */ 38 typedef struct _Module 39 { 40 AVLNODECORE coreKey; /* Key is hFile. */ 41 AVLNODECORE coreMTE; /* Key is pMTE. */ 42 43 SFN hFile; /* System file number or file handle if you prefer that. */ 44 PMTE pMTE; /* Pointer to MTE if we got one - NULL is allowed. */ 45 46 ULONG fFlags; /* Flags. Flags if coreMte is in use and what Data contains. */ 47 union 48 { 49 ModuleBase *pModule; /* Pointer to a Pe2Lx object. (Win32 executables) */ 50 #if defined(_PE2LX_H_) 51 Pe2Lx * pPe2Lx; /* Pointer to a Pe2Lx object. (Win32 executables) */ 52 #endif 53 #if defined(_ELF2LX_H_) 54 Elf2Lx * pElf2Lx; /* Pointer to a Elf2Lx object. (ELF executables) */ 55 #endif 56 #if defined(_SCRIPT_H_) 57 Script * pScript; /* Pointer to a Script object. (Shell scripts) */ 58 #endif 59 #if defined(_PE_H_) 60 Pe * pPe; /* Pointer to a Pe object. (Ring3 loader) */ 61 #endif 62 } Data; /* Pointer to data. Currently it's allways a Pe2Lx object! */ 63 } MODULE, *PMODULE; 64 65 #define MOD_FLAGS_IN_MTETREE 0x00000010UL /* The node is present in the MTE-tree. */ 66 #define MOD_TYPE_MASK 0x0000000FUL /* Type mask. */ 67 #define MOD_TYPE_PE2LX 0x00000001UL /* Pe2Lx module. */ 68 #define MOD_TYPE_ELF2LX 0x00000002UL /* Elf2Lx module. */ 69 #define MOD_TYPE_SCRIPT 0x00000003UL /* Script module. */ 70 #define MOD_TYPE_PE 0x00000004UL /* Pe module. */ 71 72 73 /* 74 * Modules operations. 75 */ 76 PMODULE getModuleBySFN(SFN hFile); 77 PMODULE getModuleByMTE(PMTE pMTE); 78 PMODULE getModuleByFilename(PCSZ pszFilename); 79 80 ULONG addModule(SFN hFile, PMTE pMTE, ULONG fFlags, ModuleBase *pModObj); 81 ULONG removeModule(SFN hFile); 82 83 #endif 84 85 /*************/ 86 /* functions */ 87 /*************/ 88 #ifdef __cplusplus 89 extern "C" { 90 #endif 91 92 ULONG ldrInit(void); 93 94 #ifdef __cplusplus 14 15 #ifdef __cplusplus 16 extern "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 */ 60 extern 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 } \ 95 126 } 96 #endif 97 98 #pragma pack() 99 100 #endif 127 128 129 /* 130 * handle state - Array of handle states. Eight state per byte! 131 */ 132 #define MAX_FILE_HANDLES 0x10000 133 134 extern 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 150 class ModuleBase; 151 class Pe2Lx; 152 class Elf2Lx; 153 #else 154 typedef char ModuleBase; 155 typedef char Pe2Lx; 156 typedef char Elf2Lx; 157 #endif 158 159 160 /* 161 * Module struct. 162 */ 163 typedef 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 */ 196 extern PMODULE pExeModule; 197 198 199 /* 200 * Modules operations. 201 */ 202 PMODULE getModuleBySFN(SFN hFile); 203 PMODULE getModuleByMTE(PMTE pMTE); 204 PMODULE getModuleByhMTE(HMTE hMTE); 205 PMODULE getModuleByFilename(PCSZ pszFilename); 206 207 ULONG addModule(SFN hFile, PMTE pMTE, ULONG fFlags, ModuleBase *pModObj); 208 ULONG 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. */ 219 extern const char fTkExecPgm; 220 extern char achTkExecPgmFilename[CCHFILENAME]; 221 extern char achTkExecPgmArguments[CCHARGUMENTS]; 222 #endif 223 ULONG _Optlink tkExecPgmEnvLength(void); 224 ULONG _Optlink tkExecPgmCopyEnv(char *pachBuffer, unsigned cchBuffer); 225 226 227 228 /* 229 * functions 230 */ 231 PSZ ldrGetExePath(PSZ pszPath, BOOL fExecChild); 232 ULONG ldrInit(void); 233 234 #ifdef __cplusplus 235 } 236 #endif 237 238 #pragma pack() 239 240 #endif
Note:
See TracChangeset
for help on using the changeset viewer.