Changeset 2832
- Timestamp:
- Oct 25, 2006, 12:26:01 AM (19 years ago)
- Location:
- trunk/kLdr
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdr.h
r2830 r2832 260 260 typedef struct KLDRSEG 261 261 { 262 /** The segment load address. */ 263 void *pv; 262 /** Variable free to use for the kLdr user. */ 263 void *pvUser; 264 /** The segment name. */ 265 const char *pszName; 264 266 /** The size of the segment. */ 265 267 size_t cb; 266 /** The segment is readable. */ 267 uint32_t fRead : 1; 268 /** The segment is writable. */ 269 uint32_t fWrite : 1; 270 /** The segment is executable. */ 271 uint32_t fExecute : 1; 272 /** Reserved for future use. */ 273 uint32_t fReserved : 29; 274 /** Reserved for future use. */ 275 uint32_t u32Reserved; 268 /** The link time load address. */ 269 void *pvLink; 270 /** The actual load address (if loaded). */ 271 void *pv; 272 /** The segment protection. */ 273 KLDRPROT enmProt; 276 274 } KLDRSEG, *PKLDRSEG; 275 276 277 /** 278 * Loader module format. 279 */ 280 typedef enum KLDRFMT 281 { 282 /** The usual invalid 0 format. */ 283 KLDRFMT_INVALID = 0, 284 /** The native OS loader. */ 285 KLDRFMT_NATIVE, 286 /** The AOUT loader. */ 287 KLDRFMT_AOUT, 288 /** The ELF loader. */ 289 KLDRFMT_ELF, 290 /** The LX loader. */ 291 KLDRFMT_LX, 292 /** The mach-o loader. */ 293 KLDRFMT_MACHO, 294 /** The LX loader. */ 295 KLDRFMT_PE, 296 /** The end of the valid format values (exclusive). */ 297 KLDRFMT_END, 298 /** Hack to blow the type up to 32-bit. */ 299 KLDRFMT_32BIT_HACK = 0x7fffffff 300 } KLDRFMT; 277 301 278 302 … … 284 308 /** The usual invalid 0 type. */ 285 309 KLDRTYPE_INVALID = 0, 286 /** The native OS loader. */ 287 KLDRTYPE_NATIVE, 288 /** The LX loader. */ 289 KLDRTYPE_LX, 290 /** The end type (not included). */ 310 /** Object file. */ 311 KLDRTYPE_OBJECT, 312 /** Executable module, fixed load address. */ 313 KLDRTYPE_EXECUTABLE_FIXED, 314 /** Executable module, relocatable, non-fixed load address. */ 315 KLDRTYPE_EXECUTABLE_RELOCATABLE, 316 /** Executable module, position independent code, non-fixed load address. */ 317 KLDRTYPE_EXECUTABLE_PIC, 318 /** Shared library, fixed load address. 319 * Typically a system library. */ 320 KLDRTYPE_SHARED_LIBRARY_FIXED, 321 /** Shared library, relocatable, non-fixed load address. */ 322 KLDRTYPE_SHARED_LIBRARY_RELOCATABLE, 323 /** Shared library, position independent code, non-fixed load address. */ 324 KLDRTYPE_SHARED_LIBRARY_PIC, 325 /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */ 326 KLDRTYPE_FORWARDER_DLL, 327 /** Core or dump. */ 328 KLDRTYPE_CORE, 329 /** The end of the valid types values (exclusive). */ 291 330 KLDRTYPE_END, 292 331 /** Hack to blow the type up to 32-bit. */ … … 296 335 297 336 /** 337 * CPU Architecture. 338 * @todo Double check the non intel architectures. 339 */ 340 typedef enum KLDRARCH 341 { 342 /** The usual invalid one. */ 343 KLDRARCH_INVALID = 0, 344 /** Clone or Intel 16-bit x86. */ 345 KLDRARCH_X86_16, 346 /** Clone or Intel 32-bit x86. */ 347 KLDRARCH_X86_32, 348 /** AMD64 (including clones). */ 349 KLDRARCH_AMD64, 350 /** Itanic (64-bit). */ 351 KLDRARCH_IA64, 352 /** ALPHA (64-bit). */ 353 KLDRARCH_ALPHA, 354 /** ALPHA limited to 32-bit. */ 355 KLDRARCH_ALPHA_32, 356 /** 32-bit ARM. */ 357 KLDRARCH_ARM_32, 358 /** 64-bit ARM. */ 359 KLDRARCH_ARM_64, 360 /** 32-bit MIPS. */ 361 KLDRARCH_MIPS_32, 362 /** 64-bit MIPS. */ 363 KLDRARCH_MIPS_64, 364 /** 32-bit PowerPC. */ 365 KLDRARCH_POWERPC_32, 366 /** 64-bit PowerPC. */ 367 KLDRARCH_POWERPC_64, 368 /** 32-bit SPARC. */ 369 KLDRARCH_SPARC_32, 370 /** 64-bit SPARC. */ 371 KLDRARCH_SPARC_64, 372 /** The end of the valid architecture values (exclusive). */ 373 KLDRARCH_END, 374 /** Hack to blow the type up to 32-bit. */ 375 KLDRARCH_32BIT_HACK = 0x7fffffff 376 } KLDRARCH; 377 378 /** 379 * CPU models. 380 */ 381 typedef enum KLDRCPU 382 { 383 /** The usual invalid cpu. */ 384 KLDRCPU_INVALID = 0, 385 /** @name KLDRARCH_X86_16 386 * @{ */ 387 KLDRCPU_I8086, 388 KLDRCPU_I8088, 389 KLDRCPU_I80186, 390 KLDRCPU_I80286, 391 KLDRCPU_I386_16, 392 KLDRCPU_I486_16, 393 KLDRCPU_I486SX_16, 394 KLDRCPU_I586_16, 395 KLDRCPU_I686_16, 396 KLDRCPU_K6_16, 397 KLDRCPU_K7_16, 398 KLDRCPU_K8_16, 399 /** @} */ 400 401 /** @name KLDRARCH_X86_32 402 * @{ */ 403 KLDRCPU_I386, 404 KLDRCPU_I486, 405 KLDRCPU_I486SX, 406 KLDRCPU_I586, 407 KLDRCPU_I686, 408 KLDRCPU_P4, 409 KLDRCPU_CORE2_32, 410 KLDRCPU_K6, 411 KLDRCPU_K7, 412 KLDRCPU_K8_32, 413 /** @} */ 414 415 /** @name KLDRARCH_AMD64 416 * @{ */ 417 KLDRCPU_K8, 418 KLDRCPU_P4_64, 419 KLDRCPU_CORE2, 420 /** @} */ 421 422 /** The end of the valid cpu values (exclusive). */ 423 KLDRCPU_END, 424 /** Hack to blow the type up to 32-bit. */ 425 KLDRCPU_32BIT_HACK = 0x7fffffff 426 } KLDRCPU; 427 428 429 /** 430 * Loader endian indicator. 431 */ 432 typedef enum KLDRENDIAN 433 { 434 /** The usual invalid endian. */ 435 KLDRENDIAN_INVALID, 436 /** Little endian. */ 437 KLDRENDIAN_LITTLE, 438 /** Bit endian. */ 439 KLDRENDIAN_BIG, 440 /** Endianness doesn't have a meaning in the context. */ 441 KLDRENDIAN_NA, 442 /** The end of the valid endian values (exclusive). */ 443 KLDRENDIAN_END, 444 /** Hack to blow the type up to 32-bit. */ 445 KLDRENDIAN_32BIT_HACK = 0x7fffffff 446 } KLDRENDIAN; 447 448 449 /** 298 450 * Loader module. 299 451 */ … … 302 454 /** Magic number. */ 303 455 uint32_t u32Magic; 304 /** The type of module this is. */ 456 /** The format of this module. */ 457 KLDRFMT enmFmt; 458 /** The type of module. */ 305 459 KLDRTYPE enmType; 306 /** The module data. */ 307 void *pvData; 460 /** The architecture this module was built for. */ 461 KLDRARCH enmArch; 462 /** The minium cpu this module was built for. 463 * This might not be accurate, so use kLdrModCanExecuteOn() to check. */ 464 KLDRARCH enmCpu; 465 /** The endian used by the module. */ 466 KLDRENDIAN enmEndian; 308 467 /** The filename length (bytes). */ 309 468 uint32_t cchFilename; … … 316 475 /** The number of segments in the module. */ 317 476 uint32_t cSegments; 477 /** The module data. */ 478 void *pvData; 318 479 /** Segments. (variable size, can be zero) */ 319 480 KLDRSEG aSegments[1]; … … 321 482 322 483 323 int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod); 324 int kLdrModClose(PKLDRMOD pMod); 325 int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, unsigned *pfType); 326 int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, unsigned *pfType); 327 328 size_t kLdrModSize(PKLDRMOD pMod); 329 330 typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, uintmax_t *pValue, void *pvUser); 331 typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT; 332 int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, uintmax_t BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 333 int kLdrModRelocate(PKLDRMOD pMod, void *pvBits, uintmax_t NewBaseAddress, uintmax_t OldBaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 334 335 typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, const char *pszSymbol, unsigned uSymbol, uintmax_t Value, void *pvUser); 336 typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS; 337 int kLdrModEnumSymbols(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, uintmax_t BaseAddress, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser); 484 /** Special base address value alias for the link address. */ 485 #define KLDRMOD_BASEADDRESS_LINK (~(uintmax_t)1) 486 /** Special base address value alias for the actual load address (must be mapped). */ 487 #define KLDRMOD_BASEADDRESS_MAP (~(uintmax_t)2) 488 489 /** @name Load symbol kind flags. 490 * @{ */ 491 /** The bitness doesn't matter. */ 492 #define KLDRSYMKIND_NO_BIT 0x00000000 493 /** 16-bit symbol. */ 494 #define KLDRSYMKIND_16BIT 0x00000001 495 /** 32-bit symbol. */ 496 #define KLDRSYMKIND_32BIT 0x00000002 497 /** 64-bit symbol. */ 498 #define KLDRSYMKIND_64BIT 0x00000003 499 /** Mask out the bit.*/ 500 #define KLDRSYMKIND_BIT_MASK 0x00000003 501 /** We don't know the type of symbol. */ 502 #define KLDRSYMKIND_NO_TYPE 0x00000000 503 /** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */ 504 #define KLDRSYMKIND_CODE 0x00000010 505 /** The symbol is a data object. */ 506 #define KLDRSYMKIND_DATA 0x00000020 507 /** Mask out the symbol type. */ 508 #define KLDRSYMKIND_TYPE_MASK 0x00000030 509 /** Valid symbol kind mask. */ 510 #define KLDRSYMKIND_MASK 0x00000033 511 /** @} */ 512 338 513 /** @name kLdrModEnumSymbols flags. 339 514 * @{ */ … … 342 517 /** @} */ 343 518 344 /** @} */ 345 346 347 348 349 /** @defgroup grp_kLdrDy kLdrDy - The dynamic loader 350 * @{ */ 351 352 /** The h*/ 353 typedef struct KLDRDY *PKLDRDY; 354 355 /* 356 int kLdrLoadDll(const char *pszFilename, unsigned fFlags, unsigned long *pvmod); 357 */ 519 520 typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, const char *pszModule, const char *pszSymbol, uint32_t uSymbol, 521 uintmax_t *pValue, uint32_t *pfKind, void *pvModuleUser, void *pvUser); 522 typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT; 523 typedef int FNKLDRMODENUMIMPMODS(PKLDRMOD pMod, const char *pszImpMod, unsigned fFlags, void *pvUser); 524 typedef FNKLDRMODENUMIMPMODS *PFNKLDRMODENUMIMPMODS; 525 typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, const char *pszSymbol, unsigned uSymbol, uintmax_t Value, uint32_t fKind, void *pvUser); 526 typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS; 527 528 int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod); 529 int kLdrModClose(PKLDRMOD pMod); 530 int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, uint32_t *pfKind); 531 int kLdrModEnumSymbols(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, uintmax_t BaseAddress, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser); 532 int kLdrModEnumImportModules(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, FNKLDRMODENUMIMPMODS pfnCallback, void *pvUser); 533 int kLdrModMap(PKLDRMOD pMod); 534 int kLdrModUnmap(PKLDRMOD pMod); 535 int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 536 size_t kLdrModSize(PKLDRMOD pMod); 537 int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, uintmax_t BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 538 int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, uintmax_t NewBaseAddress, uintmax_t OldBaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 539 int kLdrModCanExecuteOn(PKLDRMOD pMod, KLDRARCH enmArch, KLDRCPU enmCpu); 540 541 /** @} */ 542 543 544 545 546 /** @defgroup grp_kLdrDyld kLdrDyld - The dynamic loader 547 * @{ */ 548 549 /** The handle to a dynamic loader module. */ 550 typedef struct KLDRDYLD *HKLDRMOD; 551 /** Pointer to the handle to a dynamic loader module. */ 552 typedef HKLDRMOD *PHKLDRMOD; 553 554 555 /** 556 * File search method. 557 * 558 * In addition to it's own way of finding files, kLdr emulates 559 * the methods employed by the most popular systems. 560 */ 561 typedef enum KLDRDYLDSEARCH 562 { 563 /** The usual invalid file search method. */ 564 KLDRDYLD_SEARCH_INVALID = 0, 565 /** Uses the kLdr file search method. 566 * @todo invent me. */ 567 KLDRDYLD_SEARCH_KLDR, 568 /** Use the emulation closest to the host system. */ 569 KLDRDYLD_SEARCH_HOST, 570 /** Emulate the OS/2 file search method. 571 * On non-OS/2 systems, BEGINLIBPATH, LIBPATH, ENDLIBPATH and LIBPATHSTRICT are 572 * taken form the environment. */ 573 KLDRDYLD_SEARCH_OS2, 574 /** Emulate the standard window file search method. */ 575 KLDRDYLD_SEARCH_WINDOWS, 576 /** Emulate the alternative window file search method. */ 577 KLDRDYLD_SEARCH_WINDOWS_ALTERED, 578 /** Emulate the most common UNIX file search method. */ 579 KLDRDYLD_SEARCH_UNIX_COMMON, 580 } KLDRDYLDSEARCH; 581 582 /** @name kLdrLoadDll flags. 583 * @{ */ 584 /** The symbols in the module should be loaded into the global unix namespace. 585 * If not specified, the symbols are local and can only be referenced directly. */ 586 #define KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS 0x00000001 587 /** The module shouldn't be found by a global module search. 588 * If not specified, the module can be found by unspecified module searches, 589 * typical used when loading import/dep modules. */ 590 #define KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE 0x00000002 591 /** @todo more to come. */ 592 /** @} */ 593 594 595 int kLdrDyldLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, unsigned fFlags, 596 PHKLDRMOD phMod, char *pszErr, size_t cchErr); 597 int kLdrDyldUnload(HKLDRMOD hMod); 598 int kLdrDyldFindByName(const char *pszDll, PHKLDRMOD *phMod); 599 int kLdrDyldFindByPC(uintptr_t PC, PHKLDRMOD *phMod, uint32_t *piSegment, uintptr_t *poffSegment); 600 int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, size_t cchName); 601 int kLdrDyldGetFilename(HKLDRMOD hMod, char *pszName, size_t cchName); 602 int kLdrDyldQuerySymbol(HKLDRMOD hMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind); 603 604 /** @name OS/2 like API 605 * @{ */ 606 int kLdrDosLoadModule(char *pszObject, size_t cbObject, const char *pszModule, PHKLDRMOD phMod); 607 int kLdrDosFreeModule(HKLDRMOD hMod); 608 int kLdrDosQueryModuleHandle(const char *pszModname, PHKLDRMOD phMod); 609 int kLdrDosQueryModuleName(HKLDRMOD hMod, size_t cchName, char *pszName); 610 int kLdrDosQueryProcAddr(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, void **ppvProcAddr); 611 int kLdrDosQueryProcType(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, uint32_t *pfProcType); 612 int kLdrDosQueryModFromEIP(PHKLDRMOD phMod, uint32_t *piObject, size_t cbName, char *pszName, uintptr_t *poffObject, uintptr_t ulEIP); 613 int kLdrDosReplaceModule(const char *pszOldModule, const char *pszNewModule, const char *pszBackupModule); 614 int kLdrDosGetResource(HKLDRMOD hMod, uint32_t idType, uint32_t idName, void **pvResAddr); 615 int kLdrDosQueryResourceSize(HKLDRMOD hMod, uint32_t idTypeID, uint32_t idName, uint32_t *pcb); 616 int kLdrDosFreeResource(void *pvResAddr); 617 /** @} */ 618 619 /** @name POSIX like API 620 * @{ */ 621 HKLDRMOD kLdrDlOpen(const char *pszLibrary, int fFlags); 622 const char *kLdrDlError(void); 623 void * kLdrDlSym(HKLDRMOD hMod, const char *pszSymbol); 624 int kLdrDlClose(HKLDRMOD hMod); 625 /** @} */ 626 627 /** @name Win32 like API 628 * @{ */ 629 HKLDRMOD kLdrWLoadLibrary(const char *pszFilename); 630 HKLDRMOD kLdrWLoadLibraryEx(const char *pszFilename, void *hFileReserved, uint32_t fFlags); 631 uint32_t kLdrWGetModuleFileName(HKLDRMOD hMod, char *pszModName, size_t cchModName); 632 HKLDRMOD kLdrWGetModuleHandle(const char *pszFilename); 633 int kLdrWGetModuleHandleEx(uint32_t fFlags, const char *pszFilename, HKLDRMOD hMod); 634 void * kLdrWGetProcAddress(HKLDRMOD hMod, const char *pszProcName); 635 uint32_t kLdrWGetDllDirectory(size_t cchDir, char *pszDir); 636 int kLdrWSetDllDirectory(const char *pszDir); 637 int kLdrWFreeLibrary(HKLDRMOD hMod); 638 int kLdrWDisableThreadLibraryCalls(HKLDRMOD hMod); 639 640 /** @} */ 641 358 642 359 643 /** @name Process Bootstrapping … … 373 657 } KLDREXEARGS, *PKLDREXEARGS; 374 658 375 void kLdrLoadExe(PKLDREXEARGS pArgs); 659 void kLdrLoadExe(PKLDREXEARGS pArgs, void *pvOS); 660 376 661 /** @} */ 377 662 -
trunk/kLdr/kLdrHlp.c
r2831 r2832 507 507 508 508 /** 509 * Writes a assert string with unix lineendings. 510 * 511 * @param pszMsg The string. 512 */ 513 static void kldrHlpAssertWrite(const char *pszMsg) 514 { 515 #if defined(__OS2__) || defined(__WIN__) 516 /* 517 * Line by line. 518 */ 519 ULONG cbWritten; 520 const char *pszNl = kLdrHlpStrChr(pszMsg, '\n'); 521 while (pszNl || *pszMsg) 522 { 523 cbWritten = pszNl - pszMsg; 524 525 #ifdef __OS2__ 526 if (cbWritten) 527 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten); 528 DosWrite((HFILE)2, "\r\n", 2, &cbWritten); 529 #else /* __WIN32__ */ 530 if (cbWritten) 531 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL); 532 WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL); 533 #endif 534 535 /* next */ 536 pszMsg = pszNl + 1; 537 pszNl = kLdrHlpStrChr(pszMsg, '\n'); 538 } 539 540 /* 541 * Remaining incomplete line. 542 */ 543 if (*pszMsg) 544 { 545 cbWritten = kLdrHlpStrLen(pszMsg); 546 #ifdef __OS2__ 547 DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten); 548 #else /* __WIN32__ */ 549 WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL); 550 #endif 551 } 552 553 #else 554 # error "port me" 555 #endif 556 } 557 558 559 /** 509 560 * Internal worker for the kLdrHlpAssert() macro. 510 561 * … … 516 567 void kldrHlpAssertMsg(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction) 517 568 { 518 #ifdef __OS2__ 519 static const char s_szMsg1[] = "\r\n!!!kLdr Assertion Failed!!!\n\rExpression: "; 520 static const char s_szMsg2[] = "\r\nAt: "; 521 static const char s_szMsg3[] = "\r\n"; 522 ULONG cbWritten; 523 char szLine[16]; 524 525 DosWrite((HFILE)2, s_szMsg1, sizeof(s_szMsg1) - 1, &cbWritten); 526 DosWrite((HFILE)2, pszExpr, kLdrHlpStrLen(pszExpr), &cbWritten); 527 DosWrite((HFILE)2, s_szMsg2, sizeof(s_szMsg2) - 1, &cbWritten); 528 DosWrite((HFILE)2, pszFile, kLdrHlpStrLen(pszFile), &cbWritten); 529 DosWrite((HFILE)2, "(", sizeof("(") - 1, &cbWritten); 569 char szLine[16]; 570 571 kldrHlpAssertWrite("\n!!!kLdr Assertion Failed!!!\nExpression: "); 572 kldrHlpAssertWrite(pszExpr); 573 kldrHlpAssertWrite("\nAt: "); 574 kldrHlpAssertWrite(pszFile); 575 kldrHlpAssertWrite("("); 530 576 int2dec(szLine, iLine); 531 DosWrite((HFILE)2, szLine, kLdrHlpStrLen(szLine), &cbWritten); 532 DosWrite((HFILE)2, ") ", sizeof(") ") - 1, &cbWritten); 533 DosWrite((HFILE)2, pszFunction, kLdrHlpStrLen(pszFunction), &cbWritten); 534 DosWrite((HFILE)2, s_szMsg3, sizeof(s_szMsg3) - 1, &cbWritten); 535 536 #elif defined(__WIN__) 537 static const char s_szMsg1[] = "\r\n!!!kLdr Assertion Failed!!!\n\rExpression: "; 538 static const char s_szMsg2[] = "\r\nAt: "; 539 static const char s_szMsg3[] = "\r\n"; 540 DWORD cbWritten; 541 char szLine[16]; 542 const HANDLE hStdErr = (HANDLE)STD_ERROR_HANDLE; 543 544 WriteFile(hStdErr, s_szMsg1, sizeof(s_szMsg1) - 1, &cbWritten, NULL); 545 WriteFile(hStdErr, pszExpr, kLdrHlpStrLen(pszExpr), &cbWritten, NULL); 546 WriteFile(hStdErr, s_szMsg2, sizeof(s_szMsg2) - 1, &cbWritten, NULL); 547 WriteFile(hStdErr, pszFile, kLdrHlpStrLen(pszFile), &cbWritten, NULL); 548 WriteFile(hStdErr, "(", sizeof("(") - 1, &cbWritten, NULL); 549 int2dec(szLine, iLine); 550 WriteFile(hStdErr, szLine, kLdrHlpStrLen(szLine), &cbWritten, NULL); 551 WriteFile(hStdErr, ") ", sizeof(") ") - 1, &cbWritten, NULL); 552 WriteFile(hStdErr, pszFunction, kLdrHlpStrLen(pszFunction), &cbWritten, NULL); 553 WriteFile(hStdErr, s_szMsg3, sizeof(s_szMsg3) - 1, &cbWritten, NULL); 554 555 #else 556 # error "Port me" 557 #endif 558 } 559 577 kldrHlpAssertWrite(szLine); 578 kldrHlpAssertWrite(") "); 579 kldrHlpAssertWrite(pszFunction); 580 kldrHlpAssertWrite("\n"); 581 } 582 583 584 #ifdef kLdrHlpStrChr_needed 585 char *kLdrHlpStrChr(const char *psz, int ch) 586 { 587 while (*psz) 588 { 589 if (*psz == ch) 590 return (char *)psz; 591 psz++; 592 } 593 return NULL; 594 } 595 #endif 596 597 598 #ifdef kLdrHlpStrChr_needed 599 void *kLdrHlpMemChr(const void *pv, int ch, size_t cb) 600 { 601 const uint8_t *pb = (const uint8_t *)pv; 602 const uint8_t b = (uint8_t)ch; 603 while (cb) 604 { 605 if (*pb == b) 606 return (void *)pb; 607 pb++; 608 } 609 return NULL; 610 } 611 #endif 612 -
trunk/kLdr/kLdrHlp.h
r2830 r2832 62 62 */ 63 63 #ifdef __GNUC__ 64 /** memchr */ 65 # define kLdrHlpMemChr(a,b,c) __builtin_memchr(a,b,c) 64 66 /** memcmp */ 65 67 # define kLdrHlpMemComp(a,b,c) __builtin_memcmp(a,b,c) … … 68 70 /** memset */ 69 71 # define kLdrHlpMemSet(a,b,c) __builtin_memset(a,b,c) 72 /** strchr */ 73 # define kLdrHlpStrChr(a, b) __builtin_strchr(a, b) 70 74 /** strlen */ 71 75 # define kLdrHlpStrLen(a) __builtin_strlen(a) … … 84 88 # include <malloc.h> 85 89 # pragma intrinsic(memcmp, memcpy, memset, strlen, __debugbreak) 90 /** memchr */ 91 # define kLdrHlpMemChr_needed 86 92 /** memcmp */ 87 93 # define kLdrHlpMemComp(a,b,c) memcmp(a,b,c) … … 92 98 /** strlen */ 93 99 # define kLdrHlpStrLen(a) strlen(a) 100 /** strchr */ 101 # define kLdrHlpStrChr_needed 94 102 /** alloca */ 95 103 # define kLdrHlpAllocA(a) alloca(a) … … 102 110 #endif 103 111 104 #if !defined(kLdrHlpMemComp) \ 112 #ifdef kLdrHlpStrChr_needed 113 char *kLdrHlpStrChr(const char *psz, int ch); 114 #endif 115 #ifdef kLdrHlpStrChr_needed 116 void *kLdrHlpMemChr(const void *pv, int ch, size_t cb); 117 #endif 118 119 #if (!defined(kLdrHlpMemChr) && !defined(kLdrHlpStrChr_needed))\ 120 || !defined(kLdrHlpMemComp) \ 105 121 || !defined(kLdrHlpMemCopy) \ 106 122 || !defined(kLdrHlpMemSet) \ 123 || (!defined(kLdrHlpStrChr) && !defined(kLdrHlpStrChr_needed)) \ 107 124 || !defined(kLdrHlpStrLen) \ 108 125 || !defined(kLdrHlpAllocA) \ … … 110 127 # error "Needs porting to your compiler." 111 128 #endif 112 113 129 114 130 int kldrHlpSemInit(void); -
trunk/kLdr/kLdrInternal.h
r2827 r2832 86 86 * Dynamic loader module. 87 87 */ 88 typedef struct KLDRDY 88 typedef struct KLDRDYMOD 89 89 { 90 90 /** The next module in the list. */ 91 PKLDRDYpNext;91 struct KLDRDYMOD *pNext; 92 92 /** The prev module in the list. */ 93 PKLDRDYpPrev;93 struct KLDRDYMOD *pPrev; 94 94 /** The module. */ 95 95 PKLDRMOD pMod; … … 110 110 /** Reserved for future use. */ 111 111 uint32_t fReserved : 29; 112 } KLDRDY ;112 } KLDRDYMOD, *PKLDRDYMOD; 113 113 114 114 115 115 /** Pointer to the head module (the executable). */ 116 extern PKLDRDY 116 extern PKLDRDYMOD kLdrModuleHead; 117 117 /** Pointer to the tail module. */ 118 extern PKLDRDY 118 extern PKLDRDYMOD kLdrModuleTail; 119 119 /** The Library search path. */ 120 120 extern char kLdrLibraryPath[4096];
Note:
See TracChangeset
for help on using the changeset viewer.