Changeset 101987 in vbox for trunk/src/libs/xpcom18a4
- Timestamp:
- Nov 8, 2023 4:58:53 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/components/nsNativeComponentLoader.cpp
r101875 r101987 60 60 #include "nsIObserverService.h" 61 61 62 #if defined(XP_MAC) // sdagley dougt fix 63 #include <Files.h> 64 #include <Errors.h> 65 #include "nsILocalFileMac.h" 66 #endif 67 68 #include "prlog.h" 69 extern PRLogModuleInfo *nsComponentManagerLog; 62 #include <iprt/assert.h> 63 #include <VBox/log.h> 70 64 71 65 static PRBool PR_CALLBACK … … 112 106 113 107 if (!dll->IsLoaded()) { 114 #ifdef PR_LOGGING108 #ifdef LOG_ENABLED 115 109 nsXPIDLCString displayPath; 116 110 dll->GetDisplayPath(displayPath); 117 111 118 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, 119 ("nsNativeComponentLoader: loading \"%s\"", 120 displayPath.get())); 112 Log(("nsNativeComponentLoader: loading \"%s\"\n", displayPath.get())); 121 113 #endif 122 114 if (!dll->Load()) { 123 115 124 PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, 125 ("nsNativeComponentLoader: load FAILED")); 116 Log(("nsNativeComponentLoader: load FAILED\n")); 126 117 127 118 char errorMsg[1024] = "<unknown; can't get error from NSPR>"; … … 144 135 rv = GetFactoryFromModule(dll, aCID, _retval); 145 136 146 PR_LOG(nsComponentManagerLog, NS_SUCCEEDED(rv) ? PR_LOG_DEBUG : PR_LOG_ERROR, 147 ("nsNativeComponentLoader: Factory creation %s for %s", 148 (NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"), 149 aLocation)); 137 Log(("nsNativeComponentLoader: Factory creation %s for %s", 138 (NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"), 139 aLocation)); 150 140 151 141 // If the dll failed to get us a factory. But the dll registered that … … 176 166 nsIFile *aDirectory) 177 167 { 178 #ifdef DEBUG 179 /* do we _really_ want to print this every time? */ 180 fprintf(stderr, "nsNativeComponentLoader: autoregistering begins.\n"); 181 #endif 168 Log(("nsNativeComponentLoader: autoregistering begins.\n")); 182 169 183 170 nsresult rv = RegisterComponentsInDir(aWhen, aDirectory); 184 171 185 #ifdef DEBUG 186 fprintf(stderr, "nsNativeComponentLoader: autoregistering %s\n", 187 NS_FAILED(rv) ? "FAILED" : "succeeded"); 188 #endif 189 172 Log(("nsNativeComponentLoader: autoregistering %s\n", 173 NS_FAILED(rv) ? "FAILED" : "succeeded")); 190 174 return rv; 191 175 } … … 197 181 nsresult rv = NS_ERROR_FAILURE; 198 182 PRBool isDir = PR_FALSE; 199 200 #if 0201 // Going to many of these checks is a performance hit on the mac.202 // Since these routines are called relatively infrequently and203 // we will fail anyway down the line if a directory aint there,204 // we are commenting this check out.205 206 // Make sure we are dealing with a directory207 rv = dir->IsDirectory(&isDir);208 if (NS_FAILED(rv)) return rv;209 210 if (!isDir)211 return NS_ERROR_INVALID_ARG;212 #endif /* 0 */213 183 214 184 // Create a directory iterator … … 259 229 } 260 230 231 DECLINLINE(void) nsLogDllMsg(nsDll *dll, const char *pszWhat) 232 { 233 #ifdef LOG_ENABLED 234 nsXPIDLCString displayPath; 235 dll->GetDisplayPath(displayPath); 236 237 Log(("nsNativeComponentLoader: %s \"%s\".\n", pszWhat, displayPath.get())); 238 #endif 239 } 240 261 241 static nsresult PR_CALLBACK 262 242 nsFreeLibrary(nsDll *dll, nsIServiceManager *serviceMgr, PRInt32 when) … … 299 279 if (NS_FAILED(rv)) 300 280 { 301 #ifdef PR_LOGGING 302 nsXPIDLCString displayPath; 303 dll->GetDisplayPath(displayPath); 304 305 PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, 306 ("nsNativeComponentLoader: nsIModule::CanUnload() returned error for %s.", 307 displayPath.get())); 308 #endif 281 nsLogDllMsg(dll, "nsIModule::CanUnload() returned error for"); 309 282 return rv; 310 283 } … … 314 287 if (dllMarkedForUnload) 315 288 { 316 #ifdef PR_LOGGING 317 nsXPIDLCString displayPath; 318 dll->GetDisplayPath(displayPath); 319 320 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, 321 ("nsNativeComponentLoader: + Unloading \"%s\".", displayPath.get())); 322 #endif 289 nsLogDllMsg(dll, "+ Unloading"); 323 290 324 291 #ifdef DEBUG_dougt … … 329 296 } 330 297 else 331 { 332 #ifdef PR_LOGGING 333 nsXPIDLCString displayPath; 334 dll->GetDisplayPath(displayPath); 335 336 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, 337 ("nsNativeComponentLoader: Ready for unload \"%s\".", displayPath.get())); 338 #endif 339 } 298 nsLogDllMsg(dll, "Ready for unload"); 340 299 } 341 300 else 342 301 { 343 #ifdef PR_LOGGING 344 nsXPIDLCString displayPath; 345 dll->GetDisplayPath(displayPath); 346 347 PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, 348 ("nsNativeComponentLoader: NOT ready for unload %s", displayPath.get())); 349 #endif 302 nsLogDllMsg(dll, "NOT ready for unload"); 350 303 rv = NS_ERROR_FAILURE; 351 304 } … … 383 336 { 384 337 // Precondition: dll is not loaded already, unless we're deferred 385 PR_ASSERT(deferred || dll->IsLoaded() == PR_FALSE);338 Assert(deferred || dll->IsLoaded() == PR_FALSE); 386 339 387 340 nsresult res; … … 402 355 } 403 356 404 #ifdef PR_LOGGING 405 nsXPIDLCString displayPath; 406 dll->GetDisplayPath(displayPath); 407 408 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, 409 ("nsNativeComponentLoader: Loaded \"%s\".", displayPath.get())); 410 #endif 357 nsLogDllMsg(dll, "Loaded"); 411 358 412 359 // Tell the module to self register … … 436 383 { 437 384 res = res2; // don't take this out -- see warning, above 438 439 #ifdef PR_LOGGING 440 nsXPIDLCString displayPath; 441 dll->GetDisplayPath(displayPath); 442 PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, 443 ("nsNativeComponentLoader: dll->GetDllSpec() on %s FAILED.", 444 displayPath.get())); 445 #endif 385 nsLogDllMsg(dll, "dll->GetDllSpec() FAILED on"); 446 386 } 447 387 mobj = NULL; // Force a release of the Module object before unload() … … 472 412 } 473 413 474 //475 // MOZ_DEMANGLE_SYMBOLS is only a linux + MOZ_DEBUG thing.476 //477 478 #if defined(MOZ_DEMANGLE_SYMBOLS)479 #include "nsTraceRefcntImpl.h" // for nsTraceRefcntImpl::DemangleSymbol()480 #endif481 482 414 nsresult 483 415 nsNativeComponentLoader::DumpLoadError(nsDll *dll, … … 485 417 const char *aNsprErrorMsg) 486 418 { 487 PR_ASSERT(aCallerName != NULL);419 Assert(aCallerName != NULL); 488 420 489 421 if (nsnull == dll || nsnull == aNsprErrorMsg) … … 492 424 nsCAutoString errorMsg(aNsprErrorMsg); 493 425 494 #if defined(MOZ_DEMANGLE_SYMBOLS)495 // Demangle undefined symbols496 nsCAutoString undefinedMagicString("undefined symbol:");497 498 PRInt32 offset = errorMsg.Find(undefinedMagicString, PR_TRUE);499 500 if (offset != kNotFound)501 {502 nsCAutoString symbol(errorMsg);503 nsCAutoString demangledSymbol;504 505 symbol.Cut(0,offset);506 507 symbol.Cut(0,undefinedMagicString.Length());508 509 symbol.StripWhitespace();510 511 char demangled[4096] = "\0";512 513 nsTraceRefcntImpl::DemangleSymbol(symbol.get(),demangled,sizeof(demangled));514 515 if (demangled && *demangled != '\0')516 demangledSymbol = demangled;517 518 if (!demangledSymbol.IsEmpty())519 {520 nsCAutoString tmp(errorMsg);521 522 523 tmp.Cut(offset + undefinedMagicString.Length(),524 tmp.Length() - offset - undefinedMagicString.Length());525 526 tmp += " \n";527 528 tmp += demangledSymbol;529 530 errorMsg = tmp;531 }532 }533 #endif // MOZ_DEMANGLE_SYMBOLS534 426 nsXPIDLCString displayPath; 535 427 dll->GetDisplayPath(displayPath); … … 543 435 #endif 544 436 545 // Do NSPR log 546 #ifdef PR_LOGGING 547 PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS, 548 ("nsNativeComponentLoader: %s(%s) Load FAILED with error: %s", 549 aCallerName, 550 displayPath.get(), 551 errorMsg.get())); 552 #endif 437 Log(("nsNativeComponentLoader: %s(%s) Load FAILED with error: %s", 438 aCallerName, displayPath.get(), errorMsg.get())); 553 439 return NS_OK; 554 440 } … … 573 459 if (NS_SUCCEEDED(res)) 574 460 { 575 #ifdef PR_LOGGING 576 nsXPIDLCString displayPath; 577 dll->GetDisplayPath(displayPath); 578 579 PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, 580 ("nsNativeComponentLoader: %s using nsIModule to unregister self.", displayPath.get())); 581 #endif 461 nsLogDllMsg(dll, "using nsIModule to unregister self on"); 462 582 463 nsCOMPtr<nsIFile> fs; 583 464 res = dll->GetDllSpec(getter_AddRefs(fs)); … … 638 519 rv = SelfUnregisterDll(dll); 639 520 640 #ifdef PR_LOGGING 641 nsXPIDLCString displayPath; 642 dll->GetDisplayPath(displayPath); 643 644 PR_LOG(nsComponentManagerLog, NS_SUCCEEDED(rv) ? PR_LOG_DEBUG : PR_LOG_ERROR, 645 ("nsNativeComponentLoader: AutoUnregistration for %s %s.", 646 (NS_FAILED(rv) ? "FAILED" : "succeeded"), displayPath.get())); 647 #endif 521 if (NS_SUCCEEDED(rv)) 522 nsLogDllMsg(dll, "AutoUnregistration succeeded for"); 523 else 524 nsLogDllMsg(dll, "AutoUnregistration FAILED for"); 648 525 649 526 if (NS_FAILED(rv)) … … 674 551 *registered = PR_FALSE; 675 552 676 #ifndef VBOX677 /* this should be a pref or registry entry, or something */678 static const char *ValidDllExtensions[] = {679 ".dll", /* Windows */680 ".so", /* Unix */681 ".shlb", /* Mac ? */682 ".dso", /* Unix ? */683 ".dylib", /* Unix: Mach */684 ".so.1.0", /* Unix: BSD */685 ".sl", /* Unix: HP-UX */686 #if defined(VMS)687 ".exe", /* Open VMS */688 #endif689 ".dlm", /* new for all platforms */690 NULL691 };692 693 *registered = PR_FALSE;694 695 #if 0696 // This is a performance hit on mac. Since we have already checked697 // this; plus is we dont, load will fail anyway later on, this698 // is being commented out.699 700 // Ensure we are dealing with a file as opposed to a dir701 PRBool b = PR_FALSE;702 703 rv = component->IsFile(&b);704 if (NS_FAILED(rv) || !b)705 return rv;706 #endif /* 0 */707 708 // deal only with files that have a valid extension709 PRBool validExtension = PR_FALSE;710 711 #if defined(XP_MAC) // sdagley dougt fix712 // rjc - on Mac, check the file's type code (skip checking the creator code)713 714 nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface(component);715 if (localFileMac)716 {717 OSType type;718 rv = localFileMac->GetFileType(&type);719 if (NS_SUCCEEDED(rv))720 {721 // on Mac, Mozilla shared libraries are of type 'shlb'722 // Note: we don't check the creator (which for Mozilla is 'MOZZ')723 // so that 3rd party shared libraries will be noticed!724 validExtension = ((type == 'shlb') || (type == 'NSPL'));725 }726 }727 728 #else729 nsCAutoString leafName;730 rv = component->GetNativeLeafName(leafName);731 if (NS_FAILED(rv)) return rv;732 int flen = leafName.Length();733 for (int i=0; ValidDllExtensions[i] != NULL; i++)734 {735 int extlen = PL_strlen(ValidDllExtensions[i]);736 737 // Does fullname end with this extension738 if (flen >= extlen &&739 !PL_strcasecmp(leafName.get() + (flen - extlen), ValidDllExtensions[i])740 )741 {742 validExtension = PR_TRUE;743 break;744 }745 }746 #endif747 748 if (validExtension == PR_FALSE)749 // Skip invalid extensions750 return NS_OK;751 752 #else /* VBOX */753 553 /* VBox: Only one valid suffix exist, so dispense with the the list. */ 754 # 755 # 554 #ifdef RT_OS_DARWIN 555 # ifdef VBOX_IN_32_ON_64_MAIN_API 756 556 static const char s_szSuff[] = "-x86.dylib"; 757 # 557 # else 758 558 static const char s_szSuff[] = ".dylib"; 759 559 static const char s_szSuffInvalid[] = "-x86.dylib"; 760 # 761 # 762 # 560 # endif 561 #elif defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) 562 # ifdef VBOX_IN_32_ON_64_MAIN_API 763 563 static const char s_szSuff[] = "-x86.dll"; 764 # else564 # else 765 565 static const char s_szSuff[] = ".dll"; 766 566 static const char s_szSuffInvalid[] = "-x86.dll"; 767 # endif 567 # endif 568 #else 569 # ifdef VBOX_IN_32_ON_64_MAIN_API 570 static const char s_szSuff[] = "-x86.so"; 768 571 # else 769 # ifdef VBOX_IN_32_ON_64_MAIN_API770 static const char s_szSuff[] = "-x86.so";771 #else772 572 static const char s_szSuff[] = ".so"; 773 573 static const char s_szSuffInvalid[] = "-x86.so"; 774 # endif775 574 # endif 575 #endif 776 576 777 577 nsCAutoString strLeafName; … … 783 583 || PL_strcasecmp(strLeafName.get() + cchLeafName - sizeof(s_szSuff) + 1, s_szSuff)) 784 584 { 785 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,("Skipping '%s'...", strLeafName.get()));585 Log(("Skipping '%s'...", strLeafName.get())); 786 586 return NS_OK; /* skip */ 787 587 } 788 # 588 #ifndef VBOX_IN_32_ON_64_MAIN_API 789 589 if ( cchLeafName >= sizeof(s_szSuffInvalid) 790 590 && !PL_strcasecmp(strLeafName.get() + cchLeafName - sizeof(s_szSuffInvalid) + 1, s_szSuffInvalid)) 791 591 { 792 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,("Skipping '%s' (#2)...", strLeafName.get()));592 Log(("Skipping '%s' (#2)...", strLeafName.get())); 793 593 return NS_OK; /* skip */ 794 594 } 795 # endif 796 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("... '%s'", strLeafName.get())); 797 #endif /* VBOX */ 595 #endif 596 Log(("... '%s'", strLeafName.get())); 798 597 799 598 nsXPIDLCString persistentDescriptor; … … 820 619 if (!dll->HasChanged()) 821 620 { 822 #ifdef PR_LOGGING823 nsXPIDLCString displayPath;824 dll->GetDisplayPath(displayPath);825 826 621 // Dll hasn't changed. Skip. 827 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, 828 ("nsNativeComponentLoader: + nsDll not changed \"%s\". Skipping...", 829 displayPath.get())); 830 #endif 622 nsLogDllMsg(dll, "Skipping because nsDll has not changed"); 831 623 *registered = PR_TRUE; 832 624 return NS_OK; … … 880 672 // Dll doesn't want to be unloaded. Cannot re-register 881 673 // this dll. 882 #ifdef PR_LOGGING 883 nsXPIDLCString displayPath; 884 dll->GetDisplayPath(displayPath); 885 886 PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, 887 ("nsNativeComponentLoader: *** Dll already loaded. " 888 "Cannot unload either. Hence cannot re-register " 889 "\"%s\". Skipping...", displayPath.get())); 890 #endif 674 nsLogDllMsg(dll, "Skipping because Dll already loaded. " 675 "Cannot unload either. Hence cannot re-register"); 891 676 return rv; 892 677 } … … 895 680 // ok to unload it. 896 681 dll->Unload(); 897 #ifdef PR_LOGGING 898 nsXPIDLCString displayPath; 899 dll->GetDisplayPath(displayPath); 900 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, 901 ("nsNativeComponentLoader: + Unloading \"%s\". (no CanUnloadProc).", 902 displayPath.get())); 903 #endif 682 nsLogDllMsg(dll, "+ Unloading (no canUnloadProc)"); 904 683 } 905 684 … … 912 691 // is unloaded. And here we are with the dll still 913 692 // loaded. Whoever taught dp programming... 914 #ifdef PR_LOGGING 915 nsXPIDLCString displayPath; 916 dll->GetDisplayPath(displayPath); 917 PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, 918 ("nsNativeComponentLoader: Dll still loaded. Cannot re-register " 919 "\"%s\". Skipping...", displayPath.get())); 920 #endif 693 nsLogDllMsg(dll, "Skipping because Dll still loaded. Cannot re-register"); 921 694 return NS_ERROR_FAILURE; 922 695 } … … 947 720 return NS_OK; 948 721 } else { 949 #ifdef PR_LOGGING 950 nsXPIDLCString displayPath; 951 dll->GetDisplayPath(displayPath); 952 953 PR_LOG(nsComponentManagerLog, PR_LOG_ERROR, 954 ("nsNativeComponentLoader: Autoregistration FAILED for " 955 "\"%s\". Skipping...", displayPath.get())); 956 #endif 722 nsLogDllMsg(dll, "Skipping because Autoregistration FAILED for"); 957 723 return NS_ERROR_FACTORY_NOT_REGISTERED; 958 724 } … … 960 726 else 961 727 { 962 #ifdef PR_LOGGING 963 nsXPIDLCString displayPath; 964 dll->GetDisplayPath(displayPath); 965 966 PR_LOG(nsComponentManagerLog, PR_LOG_WARNING, 967 ("nsNativeComponentLoader: Autoregistration Passed for " 968 "\"%s\".", displayPath.get())); 969 #endif 728 nsLogDllMsg(dll, "Autoregistration Passed for"); 970 729 // Marking dll along with modified time and size in the 971 730 // registry happens at PlatformRegister(). No need to do it … … 980 739 PRBool *aRegistered) 981 740 { 982 #ifdef DEBUG 983 fprintf(stderr, "nNCL: registering deferred (%d)\n", 984 mDeferredComponents.Count()); 985 #endif 741 Log(("nNCL: registering deferred (%d)\n", mDeferredComponents.Count())); 742 986 743 *aRegistered = PR_FALSE; 987 744 if (!mDeferredComponents.Count()) … … 999 756 } 1000 757 } 1001 #ifdef DEBUG 758 1002 759 if (*aRegistered) 1003 fprintf(stderr, "nNCL: registered deferred, %d left\n", 1004 mDeferredComponents.Count()); 760 Log(("nNCL: registered deferred, %d left\n", mDeferredComponents.Count())); 1005 761 else 1006 fprintf(stderr, "nNCL: didn't register any components, %d left\n", 1007 mDeferredComponents.Count()); 1008 #endif 762 Log(("nNCL: didn't register any components, %d left\n", mDeferredComponents.Count())); 763 1009 764 /* are there any fatal errors? */ 1010 765 return NS_OK; … … 1025 780 nsNativeComponentLoader::UnloadAll(PRInt32 aWhen) 1026 781 { 1027 PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,("nsNativeComponentLoader: Unloading...."));782 Log(("nsNativeComponentLoader: Unloading....")); 1028 783 1029 784 struct freeLibrariesClosure callData;
Note:
See TracChangeset
for help on using the changeset viewer.