Changeset 4164 for trunk/src/win32k/ldr/ldr.cpp
- Timestamp:
- Sep 2, 2000, 11:08:23 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/ldr/ldr.cpp
r2501 r4164 1 /* $Id: ldr.cpp,v 1. 7 2000-01-22 18:21:01bird Exp $1 /* $Id: ldr.cpp,v 1.8 2000-09-02 21:08:06 bird Exp $ 2 2 * 3 3 * ldr.cpp - Loader helpers. … … 14 14 #define INCL_DOSERRORS 15 15 #define INCL_NOPMAPI 16 16 #define INCL_OS2KRNL_SEM 17 #define INCL_OS2KRNL_PTDA 17 18 18 19 /******************************************************************************* … … 21 22 #include <os2.h> 22 23 24 #include "devSegDf.h" 23 25 #include "malloc.h" 24 26 #include "new.h" … … 26 28 #include <stdlib.h> 27 29 #include <stddef.h> 30 #include <string.h> 28 31 29 32 #include "log.h" 33 #include "avl.h" 30 34 #include <peexe.h> 31 35 #include <exe386.h> 32 36 #include "OS2Krnl.h" 37 #include "ldr.h" 38 #include "ldrCalls.h" 33 39 #include "ModuleBase.h" 34 40 #include "pe2lx.h" 35 #include "avl.h"36 #include "ldr.h"37 41 #include "options.h" 38 42 … … 41 45 * Global Variables * 42 46 *******************************************************************************/ 43 PAVLNODECORE pSFNRoot = NULL; 44 PAVLNODECORE pMTERoot = NULL; 45 47 static PAVLNODECORE pSFNRoot = NULL; 48 static PAVLNODECORE pMTERoot = NULL; 49 50 51 /* 52 * Loader State. (See ldr.h for more info.) 53 */ 54 ULONG ulLdrState = LDRSTATE_UNKNOWN; 55 56 57 /* 58 * Pointer to the executable module being loaded. 59 * This pointer is set by ldrOpen and cleared by tkExecPgm. 60 * It's hence only valid at tkExecPgm time. (isLdrStateExecPgm() == TRUE). 61 */ 62 PMODULE pExeModule = NULL; 63 64 65 /* 66 * Filehandle bitmap. 67 */ 46 68 unsigned char achHandleStates[MAX_FILE_HANDLES/8]; 69 70 47 71 48 72 … … 64 88 * Gets a module by the MTE. 65 89 * @returns Pointer to module node. If not found NULL. 66 * @param pMTE Pointer a nModule Table Entry.90 * @param pMTE Pointer a Module Table Entry. 67 91 * @sketch Try find it in the MTE tree. 68 92 * IF not found THEN … … 124 148 125 149 /** 150 * Gets a module by the hMTE. 151 * @returns Pointer to module node. If not found NULL. 152 * @param hMTE Handle to a Module Table Entry. 153 * @sketch Convert hMte to an pMTE (pointer to MTE). 154 * Call getModuleByMTE with MTE pointer. 155 * @status completely implemented. 156 * @author knut st. osmundsen 157 */ 158 PMODULE getModuleByhMTE(HMTE hMTE) 159 { 160 PMTE pMTE; 161 162 pMTE = ldrValidateMteHandle(hMTE); 163 if (pMTE != NULL) 164 return getModuleByMTE(pMTE); 165 166 return NULL; 167 } 168 169 170 /** 126 171 * Get a module by filename. 127 172 * @returns Pointer to module node. If not found NULL. … … 236 281 delete pMod->Data.pPe2Lx; 237 282 break; 238 283 /* 239 284 case MOD_TYPE_ELF2LX: 240 case MOD_TYPE_SCRIPT: 241 case MOD_TYPE_PE: 285 break; 286 */ 287 #ifdef DEBUG 242 288 default: 243 289 kprintf(("removeModule: Unknown type, %#x\n", pMod->fFlags & MOD_TYPE_MASK)); 290 #endif 244 291 } 245 292 … … 248 295 249 296 return NO_ERROR; 297 } 298 299 300 /** 301 * Gets the path of the executable being executed. 302 * @returns Pointer to pszPath on success. Path has _NOT_ a trailing slash. 303 * NULL pointer on error. 304 * @param pszPath Pointer to path buffer. Expects CCHMAXPATH length. 305 * @param fExecChild Use hMTE of the PTDAExecChild if present. 306 * @sketch 307 * @status completely implemented. 308 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 309 * @remark The path from the pExeModule might not be fully qualified. 310 */ 311 PSZ ldrGetExePath(PSZ pszPath, BOOL fExecChild) 312 { 313 PCSZ pszFilename; 314 PCSZ psz; 315 316 #if 0 /* getFilename not implemented */ 317 if (pExeModule != NULL) 318 /* 319 * We have the executable object pointer. Let's use it! 320 */ 321 pszFilename = pExeModule->Data.pModule->getFilename(); 322 else 323 #endif 324 { 325 /* 326 * Get the hMTE for the executable using the pPTDAExecChild 327 * Then get the pMTE, and access the smte_path to get a pointer to the executable path. 328 */ 329 PPTDA pPTDACur; /* Pointer to the current (system context) PTDA */ 330 PPTDA pPTDA; /* PTDA in question. */ 331 HMTE hMTE = NULLHANDLE; /* Modulehandle of the executable module. */ 332 PMTE pMTE; /* Pointer to ModuleTableEntry of the executable module. */ 333 334 /* 335 * Get the current PTDA. (Fail if this call failes.) 336 * IF pPTDAExecChild isn't NULL THEN get hMTE for that. 337 * IF no pPTDAExecChild THEN get hMte for the current PTDA. 338 */ 339 pPTDACur = ptdaGetCur(); 340 if (pPTDACur != NULL) 341 { 342 pPTDA = ptdaGet_pPTDAExecChild(pPTDACur); 343 if (pPTDA != NULL && fExecChild) 344 hMTE = ptdaGet_ptda_module(pPTDA); 345 if (hMTE == NULLHANDLE) 346 hMTE = ptdaGet_ptda_module(pPTDACur); 347 } 348 else 349 { /* Not called at task time? No current task! */ 350 kprintf(("ldrGetExePath: Failed to get current PTDA.\n")); 351 return NULL; 352 } 353 354 /* fail if hMTE is NULLHANDLE ie. not found / invalid */ 355 if (hMTE == NULLHANDLE) 356 { 357 kprintf(("ldrGetExePath: Failed to get hMTE from the PTDAs.\n")); 358 return NULL; 359 } 360 361 /* get the pMTE for this hMTE */ 362 pMTE = ldrASMpMTEFromHandle(hMTE); 363 if (pMTE == NULL) 364 { 365 kprintf(("ldrGetExePath: ldrASMpMTEFromHandle failed for hMTE=0x%04.\n", hMTE)); 366 return NULL; 367 } 368 if (pMTE->mte_swapmte == NULL) /* paranoia */ 369 { 370 kprintf(("ldrGetExePath: mte_swapmte is NULL.\n")); 371 return NULL; 372 } 373 374 /* take the filename from the swappable MTE */ 375 pszFilename = pMTE->mte_swapmte->smte_path; 376 if (pszFilename == NULL) 377 { 378 kprintf(("ldrGetExePath: smte_path is NULL.\n")); 379 return NULL; 380 } 381 } 382 383 /* paranoia... */ 384 if (*pszFilename == '\0') 385 { 386 kprintf(("ldrGetExePath: pszFilename is empty!\n")); 387 return NULL; 388 } 389 390 /* 391 * Skip back over the filename. (stops pointing at the slash or ':') 392 */ 393 psz = pszFilename + strlen(pszFilename)-1; 394 while (psz >= pszFilename && *psz != '\\' && *psz != '/' && *psz != ':') 395 psz--; 396 397 /* 398 * If no path the fail. 399 */ 400 if (psz <= pszFilename) 401 { 402 kprintf(("ldrGetExePath: Exepath is empty.\n")); 403 return NULL; 404 } 405 406 /* 407 * Copy path and return. 408 */ 409 memcpy(pszPath, pszFilename, psz - pszFilename); 410 pszPath[psz - pszFilename] = '\0'; 411 return pszPath; 250 412 } 251 413
Note:
See TracChangeset
for help on using the changeset viewer.