| 1 | /* $Id: LdrCalls.h,v 1.6 2000-09-22 09:22:37 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * Prototypes for the loader overrided function.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 1998-1999 knut st. osmundsen
|
|---|
| 6 | *
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 | #ifndef _ldrCalls_h_
|
|---|
| 11 | #define _ldrCalls_h_
|
|---|
| 12 |
|
|---|
| 13 | #ifdef __cplusplus
|
|---|
| 14 | extern "C" {
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | /*******************************************************************************
|
|---|
| 18 | * Defined Constants And Macros *
|
|---|
| 19 | *******************************************************************************/
|
|---|
| 20 | #define LDRCALL __stdcall
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * _ldrClose
|
|---|
| 25 | */
|
|---|
| 26 | extern ULONG LDRCALL ldrClose( /* retd 0x04 */
|
|---|
| 27 | SFN p1 /* ebp + 0x08 */
|
|---|
| 28 | );
|
|---|
| 29 |
|
|---|
| 30 | ULONG LDRCALL myldrClose(SFN);
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * _ldrOpen
|
|---|
| 35 | */
|
|---|
| 36 | extern ULONG LDRCALL ldrOpen( /* retd 0x0c */
|
|---|
| 37 | PSFN p1, /* ebp + 0x08 */
|
|---|
| 38 | PCHAR p2, /* ebp + 0x0c */
|
|---|
| 39 | PULONG p3 /* ebp + 0x10 */
|
|---|
| 40 | );
|
|---|
| 41 |
|
|---|
| 42 | ULONG LDRCALL myldrOpen(PSFN phFile, PSZ pszFilename, PULONG pfl);
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | /**
|
|---|
| 46 | * _ldrRead
|
|---|
| 47 | */
|
|---|
| 48 | extern ULONG LDRCALL ldrRead( /* retd 0x18 */
|
|---|
| 49 | SFN hFile, /* ebp + 0x08 */
|
|---|
| 50 | ULONG ulOffset, /* ebp + 0x0c */
|
|---|
| 51 | PVOID pvBuffer, /* ebp + 0x10 */
|
|---|
| 52 | ULONG fpBuffer, /* ebp + 0x14 */
|
|---|
| 53 | ULONG cbToRead, /* ebp + 0x18 */
|
|---|
| 54 | PMTE pMTE /* ebp + 0x1c */
|
|---|
| 55 | );
|
|---|
| 56 |
|
|---|
| 57 | ULONG LDRCALL myldrRead(
|
|---|
| 58 | SFN hFile,
|
|---|
| 59 | ULONG ulOffset,
|
|---|
| 60 | PVOID pvBuffer,
|
|---|
| 61 | ULONG fpBuffer,
|
|---|
| 62 | ULONG cbToRead,
|
|---|
| 63 | PMTE pMTE
|
|---|
| 64 | );
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | /**
|
|---|
| 69 | * _LDRQAppType
|
|---|
| 70 | */
|
|---|
| 71 | extern ULONG LDRCALL LDRQAppType( /* retd 0x08 */
|
|---|
| 72 | ULONG p1, /* ebp + 0x08 */
|
|---|
| 73 | ULONG p2 /* ebp + 0x0c */
|
|---|
| 74 | );
|
|---|
| 75 |
|
|---|
| 76 | ULONG LDRCALL myLDRQAppType(ULONG,ULONG);
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | /**
|
|---|
| 80 | * ldrEnum32bitRelRecs
|
|---|
| 81 | * @param pMTE Pointer to MTE for this module.
|
|---|
| 82 | * @param iObject Object index. 0-based!
|
|---|
| 83 | * @param iPageTabl Page index. 0-based!
|
|---|
| 84 | * @param pvPage Pointer to page buffer.
|
|---|
| 85 | * @param ulPageAddress Note! Page is not present.
|
|---|
| 86 | * @param pPTDA
|
|---|
| 87 | *
|
|---|
| 88 | */
|
|---|
| 89 | extern ULONG LDRCALL ldrEnum32bitRelRecs( /* retd 0x20 */
|
|---|
| 90 | PMTE pMTE, /* ebp + 0x08 */
|
|---|
| 91 | ULONG iObject, /* ebp + 0x0c */
|
|---|
| 92 | ULONG iPageTable, /* ebp + 0x10 */
|
|---|
| 93 | PVOID pvPage, /* ebp + 0x14 */
|
|---|
| 94 | ULONG ulPageAddress, /* ebp + 0x18 */
|
|---|
| 95 | PVOID pvPTDA /* ebp + 0x1c */
|
|---|
| 96 | );
|
|---|
| 97 |
|
|---|
| 98 | ULONG LDRCALL myldrEnum32bitRelRecs(PMTE, ULONG, ULONG, PVOID, ULONG, PVOID);
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | /**
|
|---|
| 103 | * Loader local variables from KERNEL.SDF.
|
|---|
| 104 | */
|
|---|
| 105 | typedef struct ldrlv_s /* #memb 12 size 39 (0x027) */
|
|---|
| 106 | {
|
|---|
| 107 | PMTE lv_pmte; /* Pointer to mte. (ldrCreateMte/ldrXXX) */
|
|---|
| 108 | ULONG lv_lbufaddr;
|
|---|
| 109 | ULONG lv_sbufaddr;
|
|---|
| 110 | ULONG lv_lrecbufaddr;
|
|---|
| 111 | ULONG lv_srecbufaddr;
|
|---|
| 112 | ULONG lv_new_exe_off;
|
|---|
| 113 | USHORT lv_sfn; /* Handle to the module being loaded */
|
|---|
| 114 | USHORT lv_hobmte;
|
|---|
| 115 | ULONG lv_objnum;
|
|---|
| 116 | ULONG lv_csmte; /* size of the swappable mte heap block. (ldrCreateMte) */
|
|---|
| 117 | USHORT lv_class; /* Object class CLASS_* defines in OS2Krnl (mteflags1) it seems. */
|
|---|
| 118 | /* CLASS_PROGRAM Program class. */
|
|---|
| 119 | /* CLASS_GLOBAL Global class. */
|
|---|
| 120 | /* CLASS_SPECIFIC Specific class, as against global. */
|
|---|
| 121 | /* CLASS_ALL (0) Nonspecific class all modules. */
|
|---|
| 122 | /* CLASS_MASK Class mask. */
|
|---|
| 123 | UCHAR lv_type; /* Type of executable image expected loaded. */
|
|---|
| 124 | } ldrlv_t;
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | /*
|
|---|
| 128 | * Values of the lv_type byte. (Qualified guesses.)
|
|---|
| 129 | */
|
|---|
| 130 | #define LVTYPE_EXE 0 /* Executable program. */
|
|---|
| 131 | #define LVTYPE_DLL 1 /* Dynamic Link Library. */
|
|---|
| 132 | #define LVTYPE_DD 2 /* Device Driver. */
|
|---|
| 133 | #define LVTYPE_IFS 3 /* Installable Filesystem. */
|
|---|
| 134 | #define LVTYPE_VDD 4 /* Virtual Device Driver (for VDMs). */
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | /**
|
|---|
| 139 | * ldrOpenPath
|
|---|
| 140 | * pre 14053.
|
|---|
| 141 | * @returns OS2 return code.
|
|---|
| 142 | * pLdrLv->lv_sfn is set to filename handle.
|
|---|
| 143 | * @param pachModname Pointer to modulename. Not zero terminated!
|
|---|
| 144 | * @param cchModname Modulename length.
|
|---|
| 145 | * @param pLdrLv Loader local variables? (Struct from KERNEL.SDF)
|
|---|
| 146 | * @param pfl Pointer to flags which are passed on to ldrOpen.
|
|---|
| 147 | * @sketch
|
|---|
| 148 | * if !CLASS_GLOBAL or miniifs then
|
|---|
| 149 | * ldrOpen(pachModName)
|
|---|
| 150 | * else
|
|---|
| 151 | * loop until no more libpath elements
|
|---|
| 152 | * get next libpath element and add it to the modname.
|
|---|
| 153 | * try open the modname
|
|---|
| 154 | * if successfull then break the loop.
|
|---|
| 155 | * endloop
|
|---|
| 156 | * endif
|
|---|
| 157 | */
|
|---|
| 158 | extern ULONG LDRCALL ldrOpenPath_old( /* retd 0x10 */
|
|---|
| 159 | PCHAR pachFilename, /* ebp + 0x08 */
|
|---|
| 160 | USHORT cchFilename, /* ebp + 0x0c */
|
|---|
| 161 | ldrlv_t * plv, /* ebp + 0x10 */
|
|---|
| 162 | PULONG pful /* ebp + 0x14 */
|
|---|
| 163 | );
|
|---|
| 164 |
|
|---|
| 165 | ULONG LDRCALL myldrOpenPath_old(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful);
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | /**
|
|---|
| 169 | * ldrOpenPath - ldrOpenPath for build 14053 and above.
|
|---|
| 170 | *
|
|---|
| 171 | * @returns OS2 return code.
|
|---|
| 172 | * plv->lv_sfn is set to filename handle.
|
|---|
| 173 | * @param pachFilename Pointer to modulename. Not zero terminated!
|
|---|
| 174 | * @param cchFilename Modulename length.
|
|---|
| 175 | * @param plv Loader local variables? (Struct from KERNEL.SDF)
|
|---|
| 176 | * @param pful Pointer to flags which are passed on to ldrOpen.
|
|---|
| 177 | * @param lLibPath New parameter in build 14053.
|
|---|
| 178 | * ldrGetMte calls with 1
|
|---|
| 179 | * ldrOpenNewExe calls with 3
|
|---|
| 180 | * This is compared to the initial libpath index.
|
|---|
| 181 | * The libpath index is:
|
|---|
| 182 | * BEGINLIBPATH 1
|
|---|
| 183 | * LIBPATH 2
|
|---|
| 184 | * ENDLIBPATH 3
|
|---|
| 185 | * The initial libpath index is either 1 or 2.
|
|---|
| 186 | *
|
|---|
| 187 | * @sketch
|
|---|
| 188 | * This is roughly what the original ldrOpenPath does:
|
|---|
| 189 | * Save pTCBCur->TCBFailErr.
|
|---|
| 190 | * if !CLASS_GLOBAL or miniifs then
|
|---|
| 191 | * ldrOpen(pachFilename)
|
|---|
| 192 | * else
|
|---|
| 193 | * if beglibpath != NULL then path = 1 else path = 2
|
|---|
| 194 | * if (lLibPath < path)
|
|---|
| 195 | * return ERROR_FILE_NOT_FOUND; (2)
|
|---|
| 196 | * Allocate buffer.
|
|---|
| 197 | * loop until no more libpath elements
|
|---|
| 198 | * get next libpath element and add it to the modname.
|
|---|
| 199 | * try open the modname
|
|---|
| 200 | * if successfull then break the loop.
|
|---|
| 201 | * endloop
|
|---|
| 202 | * Free buffer.
|
|---|
| 203 | * endif
|
|---|
| 204 | * Restore pTCBCur->TCBFailErr.
|
|---|
| 205 | */
|
|---|
| 206 | extern ULONG LDRCALL ldrOpenPath( /* retd 0x14 */
|
|---|
| 207 | PCHAR pachFilename, /* ebp + 0x08 */
|
|---|
| 208 | USHORT cchFilename, /* ebp + 0x0c */
|
|---|
| 209 | ldrlv_t * plv, /* ebp + 0x10 */
|
|---|
| 210 | PULONG pful, /* ebp + 0x14 */
|
|---|
| 211 | ULONG lLibPath /* ebp + 0x18 */
|
|---|
| 212 | );
|
|---|
| 213 |
|
|---|
| 214 | ULONG LDRCALL myldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | /**
|
|---|
| 218 | * Finds a module if it's loaded.
|
|---|
| 219 | * @returns NO_ERROR on success.
|
|---|
| 220 | * OS/2 errorcode on error.
|
|---|
| 221 | * @param pachFilename Pointer to module filename.
|
|---|
| 222 | * @param cchFilename Length of modulefilename.
|
|---|
| 223 | * @param usClass Module class. (CLASS_*)
|
|---|
| 224 | * @param ppMTE Pointer to pMTE found.
|
|---|
| 225 | * @sketch
|
|---|
| 226 | */
|
|---|
| 227 | ULONG LDRCALL ldrFindModule(PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE);
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | /**
|
|---|
| 231 | * LDRClearSem - Clears the loader semaphore.
|
|---|
| 232 | * (It does some garbage collection on release.)
|
|---|
| 233 | * @returns NO_ERROR on success.
|
|---|
| 234 | * OS/2 error on failure. (ERROR_INTERRUPT?)
|
|---|
| 235 | */
|
|---|
| 236 | extern ULONG LDRCALL LDRClearSem(void);
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 | /**
|
|---|
| 240 | * LDRRequestSem - Requests the loader semaphore..
|
|---|
| 241 | * @returns NO_ERROR if succesfully.
|
|---|
| 242 | * OS2 errorcode on failure. (ERROR_INTERRUPT?)
|
|---|
| 243 | */
|
|---|
| 244 | #define LDRRequestSem() KSEMRequestMutex(pLdrSem, (ULONG)-1)
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 | /*
|
|---|
| 248 | * Pointer to the loader semaphore.
|
|---|
| 249 | */
|
|---|
| 250 | #ifdef _OS2KSEM_h_
|
|---|
| 251 | extern PKSEMMTX pLdrSem;
|
|---|
| 252 | #endif
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 | /**
|
|---|
| 256 | * Validates an hMTE and gets the MTE pointer.
|
|---|
| 257 | * @returns Pointer to MTE on success.
|
|---|
| 258 | * NULL on error.
|
|---|
| 259 | * @param hMTE MTE handle.
|
|---|
| 260 | * @remark If you wan't to this faster:
|
|---|
| 261 | * Use the hMTE as a HOB and get the HOB address (by using VMGetHandleInfo).
|
|---|
| 262 | */
|
|---|
| 263 | extern PMTE LDRCALL ldrValidateMteHandle(HMTE hMTE);
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | /**
|
|---|
| 267 | * Gets the pMTE from a hMTE. No checks.
|
|---|
| 268 | * @returns Pointer to the pMTE for a given hMTE.
|
|---|
| 269 | * @param hMTE Module handle.
|
|---|
| 270 | * @sketch
|
|---|
| 271 | */
|
|---|
| 272 | extern PMTE KRNLCALL ldrASMpMTEFromHandle(HMTE hMTE);
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 | /**
|
|---|
| 276 | * Sets the VM flags for an executable object.
|
|---|
| 277 | * @returns void
|
|---|
| 278 | * @param pMTE Pointer to the module table entry.
|
|---|
| 279 | * @param flObj LX Object flags.
|
|---|
| 280 | * @param pflFlags1 Pointer to the flFlags1 of VMAllocMem (out).
|
|---|
| 281 | * @param pflFlags2 Pointer to the flFlags2 of VMAllocMem (out).
|
|---|
| 282 | */
|
|---|
| 283 | extern VOID LDRCALL ldrSetVMflags( /* retd 0x10 */
|
|---|
| 284 | PMTE pMTE, /* ebp + 0x08 */
|
|---|
| 285 | ULONG flObj, /* ebp + 0x0c */
|
|---|
| 286 | PULONG pflFlags1, /* ebp + 0x10 */
|
|---|
| 287 | PULONG pflFlags2 /* ebp + 0x14 */
|
|---|
| 288 | );
|
|---|
| 289 |
|
|---|
| 290 | VOID LDRCALL myldrSetVMflags(PMTE pMTE, ULONG flObj, PULONG pflFlags1, PULONG pflFlags2);
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 | /**
|
|---|
| 294 | * Pointer to the loader filename buffer.
|
|---|
| 295 | * Upon return from ldrOpen (and ldrOpenPath which calls ldrOpen) this is
|
|---|
| 296 | * set to the fully qualified filename of the file last opened (successfully).
|
|---|
| 297 | */
|
|---|
| 298 | extern PSZ *pldrpFileNameBuf;
|
|---|
| 299 | #define ldrpFileNameBuf (*pldrpFileNameBuf)
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 | #ifdef __cplusplus
|
|---|
| 303 | } /* extern "C" */
|
|---|
| 304 | #endif
|
|---|
| 305 |
|
|---|
| 306 | #endif
|
|---|
| 307 |
|
|---|