1 | /* $Id: LdrCalls.h,v 1.8 2000-12-17 22:46:32 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 | /** Additional ldrFindModule flag. Or together with the class. */
|
---|
23 | #define SEARCH_FULL_NAME 0x0001
|
---|
24 |
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * _ldrClose
|
---|
28 | */
|
---|
29 | extern ULONG LDRCALL ldrClose( /* retd 0x04 */
|
---|
30 | SFN p1 /* ebp + 0x08 */
|
---|
31 | );
|
---|
32 |
|
---|
33 | ULONG LDRCALL myldrClose(SFN);
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * _ldrOpen
|
---|
38 | */
|
---|
39 | extern ULONG LDRCALL ldrOpen( /* retd 0x0c */
|
---|
40 | PSFN p1, /* ebp + 0x08 */
|
---|
41 | PCHAR p2, /* ebp + 0x0c */
|
---|
42 | PULONG p3 /* ebp + 0x10 */
|
---|
43 | );
|
---|
44 |
|
---|
45 | ULONG LDRCALL myldrOpen(PSFN phFile, PSZ pszFilename, PULONG pfl);
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * _ldrRead
|
---|
50 | */
|
---|
51 | extern ULONG LDRCALL ldrRead( /* retd 0x18 */
|
---|
52 | SFN hFile, /* ebp + 0x08 */
|
---|
53 | ULONG ulOffset, /* ebp + 0x0c */
|
---|
54 | PVOID pvBuffer, /* ebp + 0x10 */
|
---|
55 | ULONG fpBuffer, /* ebp + 0x14 */
|
---|
56 | ULONG cbToRead, /* ebp + 0x18 */
|
---|
57 | PMTE pMTE /* ebp + 0x1c */
|
---|
58 | );
|
---|
59 |
|
---|
60 | ULONG LDRCALL myldrRead(
|
---|
61 | SFN hFile,
|
---|
62 | ULONG ulOffset,
|
---|
63 | PVOID pvBuffer,
|
---|
64 | ULONG fpBuffer,
|
---|
65 | ULONG cbToRead,
|
---|
66 | PMTE pMTE
|
---|
67 | );
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * _LDRQAppType
|
---|
73 | */
|
---|
74 | extern ULONG LDRCALL LDRQAppType( /* retd 0x08 */
|
---|
75 | ULONG p1, /* ebp + 0x08 */
|
---|
76 | ULONG p2 /* ebp + 0x0c */
|
---|
77 | );
|
---|
78 |
|
---|
79 | ULONG LDRCALL myLDRQAppType(ULONG,ULONG);
|
---|
80 |
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * ldrEnum32bitRelRecs
|
---|
84 | * @param pMTE Pointer to MTE for this module.
|
---|
85 | * @param iObject Object index. 0-based!
|
---|
86 | * @param iPageTabl Page index. 0-based!
|
---|
87 | * @param pvPage Pointer to page buffer.
|
---|
88 | * @param ulPageAddress Note! Page is not present.
|
---|
89 | * @param pPTDA
|
---|
90 | *
|
---|
91 | */
|
---|
92 | extern ULONG LDRCALL ldrEnum32bitRelRecs( /* retd 0x20 */
|
---|
93 | PMTE pMTE, /* ebp + 0x08 */
|
---|
94 | ULONG iObject, /* ebp + 0x0c */
|
---|
95 | ULONG iPageTable, /* ebp + 0x10 */
|
---|
96 | PVOID pvPage, /* ebp + 0x14 */
|
---|
97 | ULONG ulPageAddress, /* ebp + 0x18 */
|
---|
98 | PVOID pvPTDA /* ebp + 0x1c */
|
---|
99 | );
|
---|
100 |
|
---|
101 | ULONG LDRCALL myldrEnum32bitRelRecs(PMTE, ULONG, ULONG, PVOID, ULONG, PVOID);
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Loader local variables from KERNEL.SDF.
|
---|
107 | */
|
---|
108 | typedef struct ldrlv_s /* #memb 12 size 39 (0x027) */
|
---|
109 | {
|
---|
110 | PMTE lv_pmte; /* Pointer to mte. (ldrCreateMte/ldrXXX) */
|
---|
111 | ULONG lv_lbufaddr;
|
---|
112 | ULONG lv_sbufaddr;
|
---|
113 | ULONG lv_lrecbufaddr;
|
---|
114 | ULONG lv_srecbufaddr;
|
---|
115 | ULONG lv_new_exe_off;
|
---|
116 | USHORT lv_sfn; /* Handle to the module being loaded */
|
---|
117 | USHORT lv_hobmte;
|
---|
118 | ULONG lv_objnum;
|
---|
119 | ULONG lv_csmte; /* size of the swappable mte heap block. (ldrCreateMte) */
|
---|
120 | USHORT lv_class; /* Object class CLASS_* defines in OS2Krnl (mteflags1) it seems. */
|
---|
121 | /* CLASS_PROGRAM Program class. */
|
---|
122 | /* CLASS_GLOBAL Global class. */
|
---|
123 | /* CLASS_SPECIFIC Specific class, as against global. */
|
---|
124 | /* CLASS_ALL (0) Nonspecific class all modules. */
|
---|
125 | /* CLASS_MASK Class mask. */
|
---|
126 | UCHAR lv_type; /* Type of executable image expected loaded. */
|
---|
127 | } ldrlv_t;
|
---|
128 |
|
---|
129 |
|
---|
130 | /*
|
---|
131 | * Values of the lv_type byte. (Qualified guesses.)
|
---|
132 | */
|
---|
133 | #define LVTYPE_EXE 0 /* Executable program. */
|
---|
134 | #define LVTYPE_DLL 1 /* Dynamic Link Library. */
|
---|
135 | #define LVTYPE_DD 2 /* Device Driver. */
|
---|
136 | #define LVTYPE_IFS 3 /* Installable Filesystem. */
|
---|
137 | #define LVTYPE_VDD 4 /* Virtual Device Driver (for VDMs). */
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * ldrOpenPath
|
---|
143 | * pre 14053.
|
---|
144 | * @returns OS2 return code.
|
---|
145 | * pLdrLv->lv_sfn is set to filename handle.
|
---|
146 | * @param pachModname Pointer to modulename. Not zero terminated!
|
---|
147 | * @param cchModname Modulename length.
|
---|
148 | * @param pLdrLv Loader local variables? (Struct from KERNEL.SDF)
|
---|
149 | * @param pfl Pointer to flags which are passed on to ldrOpen.
|
---|
150 | * @sketch
|
---|
151 | * if !CLASS_GLOBAL or miniifs then
|
---|
152 | * ldrOpen(pachModName)
|
---|
153 | * else
|
---|
154 | * loop until no more libpath elements
|
---|
155 | * get next libpath element and add it to the modname.
|
---|
156 | * try open the modname
|
---|
157 | * if successfull then break the loop.
|
---|
158 | * endloop
|
---|
159 | * endif
|
---|
160 | */
|
---|
161 | extern ULONG LDRCALL ldrOpenPath_old( /* retd 0x10 */
|
---|
162 | PCHAR pachFilename, /* ebp + 0x08 */
|
---|
163 | USHORT cchFilename, /* ebp + 0x0c */
|
---|
164 | ldrlv_t * plv, /* ebp + 0x10 */
|
---|
165 | PULONG pful /* ebp + 0x14 */
|
---|
166 | );
|
---|
167 |
|
---|
168 | ULONG LDRCALL myldrOpenPath_old(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful);
|
---|
169 |
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * ldrOpenPath - ldrOpenPath for build 14053 and above.
|
---|
173 | *
|
---|
174 | * @returns OS2 return code.
|
---|
175 | * plv->lv_sfn is set to filename handle.
|
---|
176 | * @param pachFilename Pointer to modulename. Not zero terminated!
|
---|
177 | * @param cchFilename Modulename length.
|
---|
178 | * @param plv Loader local variables? (Struct from KERNEL.SDF)
|
---|
179 | * @param pful Pointer to flags which are passed on to ldrOpen.
|
---|
180 | * @param lLibPath New parameter in build 14053.
|
---|
181 | * ldrGetMte calls with 1
|
---|
182 | * ldrOpenNewExe calls with 3
|
---|
183 | * This is compared to the initial libpath index.
|
---|
184 | * The libpath index is:
|
---|
185 | * BEGINLIBPATH 1
|
---|
186 | * LIBPATH 2
|
---|
187 | * ENDLIBPATH 3
|
---|
188 | * The initial libpath index is either 1 or 2.
|
---|
189 | *
|
---|
190 | * @sketch
|
---|
191 | * This is roughly what the original ldrOpenPath does:
|
---|
192 | * Save pTCBCur->TCBFailErr.
|
---|
193 | * if !CLASS_GLOBAL or miniifs then
|
---|
194 | * ldrOpen(pachFilename)
|
---|
195 | * else
|
---|
196 | * if beglibpath != NULL then path = 1 else path = 2
|
---|
197 | * if (lLibPath < path)
|
---|
198 | * return ERROR_FILE_NOT_FOUND; (2)
|
---|
199 | * Allocate buffer.
|
---|
200 | * loop until no more libpath elements
|
---|
201 | * get next libpath element and add it to the modname.
|
---|
202 | * try open the modname
|
---|
203 | * if successfull then break the loop.
|
---|
204 | * endloop
|
---|
205 | * Free buffer.
|
---|
206 | * endif
|
---|
207 | * Restore pTCBCur->TCBFailErr.
|
---|
208 | */
|
---|
209 | extern ULONG LDRCALL ldrOpenPath( /* retd 0x14 */
|
---|
210 | PCHAR pachFilename, /* ebp + 0x08 */
|
---|
211 | USHORT cchFilename, /* ebp + 0x0c */
|
---|
212 | ldrlv_t * plv, /* ebp + 0x10 */
|
---|
213 | PULONG pful, /* ebp + 0x14 */
|
---|
214 | ULONG lLibPath /* ebp + 0x18 */
|
---|
215 | );
|
---|
216 |
|
---|
217 | ULONG LDRCALL myldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Finds a module if it's loaded.
|
---|
222 | * @returns NO_ERROR on success.
|
---|
223 | * OS/2 errorcode on error.
|
---|
224 | * @param pachFilename Pointer to module filename.
|
---|
225 | * @param cchFilename Length of modulefilename.
|
---|
226 | * @param usClass Module class. (CLASS_*)
|
---|
227 | * @param ppMTE Pointer to pMTE found.
|
---|
228 | * @sketch
|
---|
229 | */
|
---|
230 | ULONG LDRCALL ldrFindModule( /* retd 0x10 */
|
---|
231 | PCHAR pachFilename, /* ebp + 0x08 */
|
---|
232 | USHORT cchFilename, /* ebp + 0x0c */
|
---|
233 | USHORT usClass, /* ebp + 0x10 */
|
---|
234 | PPMTE ppMTE /* ebp + 0x14 */
|
---|
235 | );
|
---|
236 |
|
---|
237 | ULONG LDRCALL myldrFindModule(PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE);
|
---|
238 |
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Checks if a module was loaded using DosLoadModule.
|
---|
242 | * This is called from LDRGetProcAddr and LDRFreeModule.
|
---|
243 | * @returns NO_ERROR if the module was LoadModuled or executable.
|
---|
244 | * ERROR_INVALID_HANDLE if not LoadModuled.
|
---|
245 | * @param hmte MTE handle.
|
---|
246 | * @param pptda Pointer to the PTDA of the process calling. (current)
|
---|
247 | * @param pcUsage Pointer to usage variable. (output)
|
---|
248 | * The usage count is returned.
|
---|
249 | * @sketch
|
---|
250 | */
|
---|
251 | #ifdef _ptda_h_
|
---|
252 | ULONG LDRCALL ldrWasLoadModuled( /* retd 0x0c */
|
---|
253 | HMTE hmte, /* ebp + 0x08 */
|
---|
254 | PPTDA pptda, /* ebp + 0x0c */
|
---|
255 | PULONG pcUsage); /* ebp + 0x10 */
|
---|
256 |
|
---|
257 | ULONG LDRCALL myldrWasLoadModuled(HMTE hmte, PPTDA pptda, PULONG pcUsage);
|
---|
258 | #endif
|
---|
259 |
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * LDRGetProcAddr gets address and proctype for a entry point to a module.
|
---|
263 | * @returns NO_ERROR if the module was LoadModuled.
|
---|
264 | * ERROR_INVALID_HANDLE if not LoadModuled.
|
---|
265 | * @param hmte Handle of module.
|
---|
266 | * @param ulOrdinal Procedure ordinal.
|
---|
267 | * @param pszName Pointer to procedure name.
|
---|
268 | * NULL is allowed. Ignored if ulOrdinal is not zero.
|
---|
269 | * @param pulAddress Pointer to address variable. (output)
|
---|
270 | * @param fFlat TRUE if a flat 0:32 address is to be returned.
|
---|
271 | * FALSE if a far 16:16 address is to be returned.
|
---|
272 | * @param pulProcType Pointer to procedure type variable. (output)
|
---|
273 | * NULL is allowed. (DosQueryProcAddr uses NULL)
|
---|
274 | * In user space.
|
---|
275 | * @sketch
|
---|
276 | */
|
---|
277 | ULONG LDRCALL LDRGetProcAddr( /* retd 0x14 */
|
---|
278 | HMTE hmte, /* ebp + 0x08 */
|
---|
279 | ULONG ulOrdinal, /* ebp + 0x0c */
|
---|
280 | PCSZ pszName, /* ebp + 0x10 */
|
---|
281 | PULONG pulAddress, /* ebp + 0x14 */
|
---|
282 | BOOL fFlat, /* ebp + 0x18 */
|
---|
283 | PULONG pulProcType); /* ebp + 0x1c */
|
---|
284 |
|
---|
285 | ULONG LDRCALL myLDRGetProcAddr(HMTE hmte, ULONG ulOrdinal, PCSZ pszName, PULONG pulAddress, BOOL fFlat, PULONG pulProcType);
|
---|
286 |
|
---|
287 |
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * LDRClearSem - Clears the loader semaphore.
|
---|
291 | * (It does some garbage collection on release.)
|
---|
292 | * @returns NO_ERROR on success.
|
---|
293 | * OS/2 error on failure. (ERROR_INTERRUPT?)
|
---|
294 | */
|
---|
295 | extern ULONG LDRCALL LDRClearSem(void);
|
---|
296 |
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * LDRRequestSem - Requests the loader semaphore..
|
---|
300 | * @returns NO_ERROR if succesfully.
|
---|
301 | * OS2 errorcode on failure. (ERROR_INTERRUPT?)
|
---|
302 | */
|
---|
303 | #define LDRRequestSem() KSEMRequestMutex(pLdrSem, (ULONG)-1)
|
---|
304 |
|
---|
305 |
|
---|
306 | /*
|
---|
307 | * Pointer to the loader semaphore.
|
---|
308 | */
|
---|
309 | #ifdef _OS2KSEM_h_
|
---|
310 | extern PKSEMMTX pLdrSem;
|
---|
311 | #endif
|
---|
312 |
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Validates an hMTE and gets the MTE pointer.
|
---|
316 | * @returns Pointer to MTE on success.
|
---|
317 | * NULL on error.
|
---|
318 | * @param hMTE MTE handle.
|
---|
319 | * @remark If you wan't to this faster:
|
---|
320 | * Use the hMTE as a HOB and get the HOB address (by using VMGetHandleInfo).
|
---|
321 | */
|
---|
322 | extern PMTE LDRCALL ldrValidateMteHandle(HMTE hMTE);
|
---|
323 |
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Gets the pMTE from a hMTE. No checks.
|
---|
327 | * @returns Pointer to the pMTE for a given hMTE.
|
---|
328 | * @param hMTE Module handle.
|
---|
329 | * @sketch
|
---|
330 | */
|
---|
331 | extern PMTE KRNLCALL ldrASMpMTEFromHandle(HMTE hMTE);
|
---|
332 |
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * Translates a relative filename to a full qualified filename.
|
---|
336 | * @returns NO_ERROR on success.
|
---|
337 | * Errorcode on error.
|
---|
338 | * @param pszFilename Pointer to nullterminated filename.
|
---|
339 | */
|
---|
340 | extern ULONG LDRCALL ldrTransPath(PSZ pszFilename);
|
---|
341 |
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * Sets the VM flags for an executable object.
|
---|
345 | * @returns void
|
---|
346 | * @param pMTE Pointer to the module table entry.
|
---|
347 | * @param flObj LX Object flags.
|
---|
348 | * @param pflFlags1 Pointer to the flFlags1 of VMAllocMem (out).
|
---|
349 | * @param pflFlags2 Pointer to the flFlags2 of VMAllocMem (out).
|
---|
350 | */
|
---|
351 | extern VOID LDRCALL ldrSetVMflags( /* retd 0x10 */
|
---|
352 | PMTE pMTE, /* ebp + 0x08 */
|
---|
353 | ULONG flObj, /* ebp + 0x0c */
|
---|
354 | PULONG pflFlags1, /* ebp + 0x10 */
|
---|
355 | PULONG pflFlags2 /* ebp + 0x14 */
|
---|
356 | );
|
---|
357 |
|
---|
358 | VOID LDRCALL myldrSetVMflags(PMTE pMTE, ULONG flObj, PULONG pflFlags1, PULONG pflFlags2);
|
---|
359 |
|
---|
360 |
|
---|
361 | /**
|
---|
362 | * Checks if the internal name (first name in the resident nametable) matches
|
---|
363 | * the filename.
|
---|
364 | * @returns NO_ERROR on success (the name matched).
|
---|
365 | * ERROR_INVALID_NAME if mismatch.
|
---|
366 | * @param pMTE Pointer to the MTE of the module to check.<br>
|
---|
367 | * Assumes! that the filename for this module is present in ldrpFileNameBuf.
|
---|
368 | */
|
---|
369 | extern ULONG LDRCALL ldrCheckInternalName( /* retd 0x04 */
|
---|
370 | PMTE pMTE /* ebp + 0x08 */
|
---|
371 | );
|
---|
372 |
|
---|
373 | ULONG LDRCALL myldrCheckInternalName(PMTE pMTE);
|
---|
374 |
|
---|
375 |
|
---|
376 | /**
|
---|
377 | * Parses a filename to find the name and extention.
|
---|
378 | * @returns Length of the filename without the extention.
|
---|
379 | * @param pachFilename Pointer to filename to parse - must have path!
|
---|
380 | * @param ppachName Pointer to pointer which should hold the name pointer upon successfull return.
|
---|
381 | * @param ppachExt Pointer to pointer which should hold the extention pointer upon successfull return.
|
---|
382 | */
|
---|
383 | extern ULONG LDRCALL ldrGetFileName(PSZ pszFilename, PCHAR *ppchName, PCHAR *ppchExt);
|
---|
384 |
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * Parses a filename to find the name and extention.
|
---|
388 | * @returns Length of the filename without the extention.
|
---|
389 | * @param pachFilename Pointer to filename to parse - path not needed.
|
---|
390 | * @param ppachName Pointer to pointer which should hold the name pointer upon successfull return.
|
---|
391 | * @param ppachExt Pointer to pointer which should hold the extention pointer upon successfull return.
|
---|
392 | */
|
---|
393 | extern ULONG LDRCALL ldrGetFileName2(PSZ pszFilename, PCHAR *ppchName, PCHAR *ppchExt);
|
---|
394 |
|
---|
395 |
|
---|
396 | /**
|
---|
397 | * Uppercase a string.
|
---|
398 | * @returns void
|
---|
399 | * @param pach String to uppercase.
|
---|
400 | * @param cch Length of string. (may include terminator)
|
---|
401 | */
|
---|
402 | extern VOID LDRCALL ldrUCaseString(PCHAR pch, unsigned cch);
|
---|
403 |
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Pointer to the loader filename buffer.
|
---|
407 | * Upon return from ldrOpen (and ldrOpenPath which calls ldrOpen) this is
|
---|
408 | * set to the fully qualified filename of the file last opened (successfully).
|
---|
409 | */
|
---|
410 | extern PSZ *pldrpFileNameBuf;
|
---|
411 | #define ldrpFileNameBuf (*pldrpFileNameBuf)
|
---|
412 |
|
---|
413 |
|
---|
414 | #ifdef __cplusplus
|
---|
415 | } /* extern "C" */
|
---|
416 | #endif
|
---|
417 |
|
---|
418 | #endif
|
---|
419 |
|
---|