Changeset 16390 in vbox
- Timestamp:
- Jan 29, 2009 10:19:49 PM (16 years ago)
- Location:
- trunk/src/libs/xpcom18a4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/Makefile.kmk
r16389 r16390 706 706 VBox-xpcom-nspr_DEFS += \ 707 707 VBOX_USE_IPRT_IN_NSPR 708 VBox-xpcom-nspr_DEFS.darwin.amd64 = \ 709 VBOX_USE_MORE_IPRT_IN_NSPR 708 710 VBox-xpcom-nspr_DEFS.darwin = \ 709 711 HAVE_BSD_FLOCK=1 \ -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c
r11551 r16390 1 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* 2 /* 3 3 * The contents of this file are subject to the Mozilla Public 4 4 * License Version 1.1 (the "License"); you may not use this file 5 5 * except in compliance with the License. You may obtain a copy of 6 6 * the License at http://www.mozilla.org/MPL/ 7 * 7 * 8 8 * Software distributed under the License is distributed on an "AS 9 9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 10 10 * implied. See the License for the specific language governing 11 11 * rights and limitations under the License. 12 * 12 * 13 13 * The Original Code is the Netscape Portable Runtime (NSPR). 14 * 14 * 15 15 * The Initial Developer of the Original Code is Netscape 16 * Communications Corporation. Portions created by Netscape are 16 * Communications Corporation. Portions created by Netscape are 17 17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All 18 18 * Rights Reserved. 19 * 19 * 20 20 * Contributor(s): Steve Streeter (Hewlett-Packard Company) 21 * 21 * 22 22 * Alternatively, the contents of this file may be used under the 23 23 * terms of the GNU General Public License Version 2 or later (the 24 * "GPL"), in which case the provisions of the GPL are applicable 25 * instead of those above. If you wish to allow use of your 24 * "GPL"), in which case the provisions of the GPL are applicable 25 * instead of those above. If you wish to allow use of your 26 26 * version of this file only under the terms of the GPL and not to 27 27 * allow others to use your version of this file under the MPL, … … 41 41 #include <string.h> 42 42 43 #ifdef VBOX_USE_MORE_IPRT_IN_NSPR 44 # include <iprt/ldr.h> 45 # include <iprt/path.h> 46 # include <iprt/err.h> 47 48 # if defined(XP_MACOSX) /** @todo Add some equivalent to PR_GetLibraryFilePathname. */ 49 # include <mach-o/dyld.h> 50 # endif 51 52 # ifdef XP_MAC 53 # error "Misconfiguration: XP_MAC && VBOX_USE_MORE_IPRT_IN_NSPR are not intended to work together" 54 # endif 55 56 #else /* ! VBOX_USE_MORE_IPRT_IN_NSPR */ 57 43 58 #ifdef XP_BEOS 44 59 #include <image.h> … … 96 111 #endif 97 112 #endif /* XP_UNIX */ 113 114 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 98 115 99 116 #define _PR_DEFAULT_LD_FLAGS PR_LD_LAZY … … 111 128 #include <unixlib.h> 112 129 113 #pragma __nostandard 130 #pragma __nostandard 114 131 #pragma __member_alignment __save 115 132 #pragma __nomember_alignment 116 133 #ifdef __INITIAL_POINTER_SIZE 117 #pragma __required_pointer_size __save 134 #pragma __required_pointer_size __save 118 135 #pragma __required_pointer_size __short 119 136 #endif 120 137 121 138 typedef struct _imcb { 122 struct _imcb *imcb$l_flink; 123 struct _imcb *imcb$l_blink; 124 unsigned short int imcb$w_size; 125 unsigned char imcb$b_type; 126 char imcb$b_resv_1; 127 unsigned char imcb$b_access_mode; 128 unsigned char imcb$b_act_code; 129 unsigned short int imcb$w_chan; 130 unsigned int imcb$l_flags; 131 char imcb$t_image_name [40]; 132 unsigned int imcb$l_symvec_size; 139 struct _imcb *imcb$l_flink; 140 struct _imcb *imcb$l_blink; 141 unsigned short int imcb$w_size; 142 unsigned char imcb$b_type; 143 char imcb$b_resv_1; 144 unsigned char imcb$b_access_mode; 145 unsigned char imcb$b_act_code; 146 unsigned short int imcb$w_chan; 147 unsigned int imcb$l_flags; 148 char imcb$t_image_name [40]; 149 unsigned int imcb$l_symvec_size; 133 150 unsigned __int64 imcb$q_ident; 134 151 void *imcb$l_starting_address; 135 152 void *imcb$l_end_address; 136 153 } IMCB; 137 154 138 155 #pragma __member_alignment __restore 139 #ifdef __INITIAL_POINTER_SIZE 156 #ifdef __INITIAL_POINTER_SIZE 140 157 #pragma __required_pointer_size __restore 141 158 #endif 142 159 #pragma __standard 143 160 144 161 typedef struct { 145 162 short buflen; … … 166 183 * On these platforms, symbols have a leading '_'. 167 184 */ 185 #ifndef VBOX_USE_MORE_IPRT_IN_NSPR /* RTLdr hides this. */ 168 186 #if defined(SUNOS4) || defined(DARWIN) || defined(NEXTSTEP) \ 169 187 || defined(WIN16) || defined(XP_OS2) \ … … 171 189 #define NEED_LEADING_UNDERSCORE 172 190 #endif 191 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 173 192 174 193 #ifdef XP_PC … … 184 203 const PRStaticLinkTable* staticTable; 185 204 205 #ifdef VBOX_USE_MORE_IPRT_IN_NSPR 206 RTLDRMOD dlh; 207 #else /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 208 186 209 #ifdef XP_PC 187 210 #ifdef XP_OS2 … … 214 237 #else 215 238 void* dlh; 216 #endif 217 #endif 239 #endif 240 #endif 218 241 219 242 #ifdef XP_BEOS … … 221 244 void* stub_dlh; 222 245 #endif 246 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 223 247 }; 224 248 … … 238 262 /************************************************************************/ 239 263 240 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) 264 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) && !defined(VBOX_USE_MORE_IPRT_IN_NSPR) 241 265 static char* errStrBuf = NULL; 242 266 #define ERR_STR_BUF_LENGTH 20 … … 271 295 void _PR_InitLinker(void) 272 296 { 273 #if !defined(XP_MAC) && !defined(XP_BEOS)297 #if (!defined(XP_MAC) && !defined(XP_BEOS)) || defined(VBOX_USE_MORE_IPRT_IN_NSPR) 274 298 PRLibrary *lm; 275 299 #endif … … 283 307 PR_EnterMonitor(pr_linker_lock); 284 308 285 #if defined(XP_PC) 309 #if defined(XP_PC) || defined(VBOX_USE_MORE_IPRT_IN_NSPR) 286 310 lm = PR_NEWZAP(PRLibrary); 287 311 lm->name = strdup("Executable"); 288 /* 312 #ifdef VBOX_USE_MORE_IPRT_IN_NSPR 313 lm->dlh = NIL_RTLDRMOD; 314 #else /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 315 /* 289 316 ** In WIN32, GetProcAddress(...) expects a module handle in order to 290 317 ** get exported symbols from the executable... 291 318 ** 292 ** However, in WIN16 this is accomplished by passing NULL to 319 ** However, in WIN16 this is accomplished by passing NULL to 293 320 ** GetProcAddress(...) 294 321 */ … … 298 325 lm->dlh = (HINSTANCE)NULL; 299 326 #endif /* ! _WIN32 */ 327 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 300 328 301 329 lm->refCount = 1; … … 310 338 if (!h) { 311 339 char *error; 312 340 313 341 DLLErrorInternal(_MD_ERRNO()); 314 342 error = (char*)PR_MALLOC(PR_GetErrorTextLength()); … … 340 368 #endif /* XP_UNIX */ 341 369 342 #if !defined(XP_MAC) && !defined(XP_BEOS) 370 #if !defined(XP_MAC) && !defined(XP_BEOS) || defined(VBOX_USE_MORE_IPRT_IN_NSPR) 343 371 PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (init)", lm?lm->name:"NULL")); 344 372 #endif … … 366 394 PR_UnloadLibrary(pr_loadmap); 367 395 } 368 396 369 397 PR_ExitMonitor(pr_linker_lock); 370 398 … … 385 413 { 386 414 /* FIXME: pr_exe_loadmap should be destroyed. */ 387 415 388 416 PR_DestroyMonitor(pr_linker_lock); 389 417 pr_linker_lock = NULL; … … 394 422 } 395 423 396 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) 424 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) && !defined(VBOX_USE_MORE_IPRT_IN_NSPR) 397 425 PR_DELETE(errStrBuf); 398 426 #endif … … 427 455 ** Return the library path for finding shared libraries. 428 456 */ 429 PR_IMPLEMENT(char *) 457 PR_IMPLEMENT(char *) 430 458 PR_GetLibraryPath(void) 431 459 { … … 455 483 456 484 ev = getenv("LD_LIBRARY_PATH"); 457 485 458 486 if (!ev) 459 487 ev = ""; 460 488 461 489 len = strlen(ev) + 1; /* +1 for the null */ 462 490 p = (char*) malloc(len); … … 480 508 } 481 509 #else 510 # if defined(VBOX) && defined(XP_MACOSX) 511 ev = getenv("DYLD_LIBRARY_PATH"); 512 # else 482 513 ev = getenv("LD_LIBRARY_PATH"); 514 # endif 483 515 if (!ev) { 484 516 ev = "/usr/lib:/lib"; … … 520 552 ** Build library name from path, lib and extensions 521 553 */ 522 PR_IMPLEMENT(char*) 554 PR_IMPLEMENT(char*) 523 555 PR_GetLibraryName(const char *path, const char *lib) 524 556 { … … 570 602 ** Free the memory allocated, for the caller, by PR_GetLibraryName 571 603 */ 572 PR_IMPLEMENT(void) 604 PR_IMPLEMENT(void) 573 605 PR_FreeLibraryName(char *mem) 574 606 { … … 576 608 } 577 609 578 static PRLibrary* 610 static PRLibrary* 579 611 pr_UnlockedFindLibrary(const char *name) 580 612 { … … 587 619 #ifdef WIN32 588 620 /* Windows DLL names are case insensitive... */ 589 if (strcmpi(np, cp) == 0) 621 if (strcmpi(np, cp) == 0) 590 622 #elif defined(XP_OS2) 591 623 if (stricmp(np, cp) == 0) 592 624 #else 593 if (strcmp(np, cp) == 0) 625 if (strcmp(np, cp) == 0) 594 626 #endif 595 627 { … … 630 662 } 631 663 } 632 633 PR_IMPLEMENT(PRLibrary*) 664 665 PR_IMPLEMENT(PRLibrary*) 634 666 PR_LoadLibrary(const char *name) 635 667 { … … 641 673 } 642 674 675 #ifndef VBOX_USE_MORE_IPRT_IN_NSPR /* exclude big chunk */ 643 676 #if defined(USE_MACH_DYLD) 644 677 static NSModule … … 699 732 } 700 733 } 701 734 702 735 return newGlue; 703 736 } … … 720 753 char cName[64]; 721 754 Str255 errName; 722 755 723 756 #if !defined(XP_MACOSX) 724 757 Str255 pName; … … 845 878 CFURLRef bundleURL; 846 879 CFBundleRef bundle = NULL; 847 880 848 881 #ifdef XP_MACOSX 849 882 char pathBuf[PATH_MAX]; … … 855 888 if (!resolvedPath) 856 889 return PR_FAILURE; 857 890 858 891 pathRef = CFStringCreateWithCString(NULL, pathBuf, kCFStringEncodingUTF8); 859 892 if (pathRef) { … … 911 944 912 945 #endif /* defined(XP_MAC) || defined(XP_MACOSX) */ 946 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 913 947 914 948 /* … … 938 972 lm->staticTable = NULL; 939 973 974 #ifdef VBOX_USE_MORE_IPRT_IN_NSPR 975 oserr = RTLdrOpen(name, &lm->dlh); 976 if (RT_FAILURE(oserr)) 977 goto unlock; 978 lm->name = strdup(name); 979 lm->refCount = 1; 980 lm->next = pr_loadmap; 981 pr_loadmap = lm; 982 983 #else /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 940 984 #ifdef XP_OS2 /* Why isn't all this stuff in MD code?! */ 941 985 { … … 1006 1050 oserr = cfragNoLibraryErr; 1007 1051 PR_DELETE(lm); 1008 goto unlock; 1052 goto unlock; 1009 1053 } 1010 1054 lm->name = strdup(name); … … 1114 1158 mozilla components), but allows 256M to be used by 1115 1159 shared libraries. 1116 1160 1117 1161 unfortunately, mozilla is too large to fit into the 1118 1162 "add-on" space, so we must trick the loader into … … 1139 1183 const char *endOfSystemName = strrchr(info.name, '/'); 1140 1184 const char *endOfPassedName = strrchr(name, '/'); 1141 if( 0 == endOfSystemName ) 1185 if( 0 == endOfSystemName ) 1142 1186 endOfSystemName = info.name; 1143 1187 else … … 1174 1218 } 1175 1219 #endif 1220 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 1176 1221 1177 1222 result = lm; /* success */ … … 1187 1232 } 1188 1233 1189 PR_IMPLEMENT(PRLibrary*) 1234 PR_IMPLEMENT(PRLibrary*) 1190 1235 PR_FindLibrary(const char *name) 1191 1236 { … … 1211 1256 Boolean isFolder, wasAlias; 1212 1257 OSErr err = noErr; 1213 1258 1214 1259 if (!_pr_initialized) _PR_ImplicitInitialization(); 1215 1260 1216 1261 /* See if library is already loaded */ 1217 1262 PR_EnterMonitor(pr_linker_lock); 1218 1263 1219 1264 result = pr_UnlockedFindLibrary(fragmentName); 1220 1265 if (result != NULL) goto unlock; … … 1235 1280 goto unlock; 1236 1281 } 1237 1282 1238 1283 /* Finally, try to load the library */ 1239 1284 err = NSLoadNamedFragment(&resolvedSpec, fragmentName, &connectionID); … … 1268 1313 FSSpec resolvedSpec = *fileSpec; 1269 1314 char* fragmentName = NULL; 1270 UInt32 fragOffset, fragLength; 1315 UInt32 fragOffset, fragLength; 1271 1316 CFragConnectionID connectionID = 0; 1272 1317 Boolean isFolder, wasAlias; … … 1290 1335 err = GetIndexedFragmentOffsets(&resolvedSpec, fragIndex, &fragOffset, &fragLength, &fragmentName); 1291 1336 if (err != noErr) goto unlock; 1292 1337 1293 1338 result = pr_UnlockedFindLibrary(fragmentName); 1294 1339 free(fragmentName); … … 1299 1344 if (newLib == NULL) goto unlock; 1300 1345 newLib->staticTable = NULL; 1301 1346 1302 1347 /* Finally, try to load the library */ 1303 1348 err = NSLoadIndexedFragment(&resolvedSpec, fragIndex, &fragmentName, &connectionID); … … 1332 1377 ** Unload a shared library which was loaded via PR_LoadLibrary 1333 1378 */ 1334 PR_IMPLEMENT(PRStatus) 1379 PR_IMPLEMENT(PRStatus) 1335 1380 PR_UnloadLibrary(PRLibrary *lib) 1336 1381 { … … 1351 1396 } 1352 1397 1398 #ifdef VBOX_USE_MORE_IPRT_IN_NSPR 1399 result = RTLdrClose(lib->dlh); 1400 lib->dlh = NIL_RTLDRMOD; 1401 1402 #else /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 1353 1403 #ifdef XP_BEOS 1354 1404 if(((image_id)lib->stub_dlh) == B_ERROR) … … 1392 1442 #endif 1393 1443 #endif 1444 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 1394 1445 1395 1446 /* unlink from library search list */ … … 1438 1489 } 1439 1490 1440 static void* 1491 static void* 1441 1492 pr_FindSymbolInLib(PRLibrary *lm, const char *name) 1442 1493 { … … 1453 1504 } 1454 1505 } 1455 /* 1506 /* 1456 1507 ** If the symbol was not found in the static table then check if 1457 1508 ** the symbol was exported in the DLL... Win16 only!! … … 1462 1513 #endif 1463 1514 } 1464 1515 1516 #ifdef VBOX_USE_MORE_IPRT_IN_NSPR 1517 if (RT_FAILURE(RTLdrGetSymbol(lm->dlh, name, &f))) 1518 f = NULL; 1519 1520 #else /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 1465 1521 #ifdef XP_OS2 1466 1522 rc = DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f); … … 1500 1556 CFragSymbolClass symClass; 1501 1557 Str255 pName; 1502 1558 1503 1559 PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Looking up symbol: %s", name + SYM_OFFSET)); 1504 1560 1505 1561 PStrFromCStr(name + SYM_OFFSET, pName); 1506 1562 1507 1563 #if defined(XP_MACOSX) 1508 1564 f = (FindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL; … … 1510 1566 f = (NSFindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL; 1511 1567 #endif 1512 1568 1513 1569 #if defined(XP_MACOSX) 1514 1570 /* callers expect mach-o function pointers, so must wrap tvectors with glue. */ … … 1517 1573 } 1518 1574 #endif 1519 1575 1520 1576 if (f == NULL && strcmp(name + SYM_OFFSET, "main") == 0) f = lm->main; 1521 1577 } … … 1561 1617 #endif /* HAVE_DLL */ 1562 1618 #endif /* XP_UNIX */ 1619 #endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */ 1563 1620 if (f == NULL) { 1564 1621 PR_SetError(PR_FIND_SYMBOL_ERROR, _MD_ERRNO()); … … 1571 1628 ** Called by class loader to resolve missing native's 1572 1629 */ 1573 PR_IMPLEMENT(void*) 1630 PR_IMPLEMENT(void*) 1574 1631 PR_FindSymbol(PRLibrary *lib, const char *raw_name) 1575 1632 { … … 1612 1669 ** Return the address of the function 'raw_name' in the library 'lib' 1613 1670 */ 1614 PR_IMPLEMENT(PRFuncPtr) 1671 PR_IMPLEMENT(PRFuncPtr) 1615 1672 PR_FindFunctionSymbol(PRLibrary *lib, const char *raw_name) 1616 1673 { … … 1618 1675 } 1619 1676 1620 PR_IMPLEMENT(void*) 1677 PR_IMPLEMENT(void*) 1621 1678 PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib) 1622 1679 { … … 1669 1726 } 1670 1727 1671 PR_IMPLEMENT(PRFuncPtr) 1728 PR_IMPLEMENT(PRFuncPtr) 1672 1729 PR_FindFunctionSymbolAndLibrary(const char *raw_name, PRLibrary* *lib) 1673 1730 { … … 1679 1736 ** is called with the name then we will pretend it was already loaded 1680 1737 */ 1681 PR_IMPLEMENT(PRLibrary*) 1738 PR_IMPLEMENT(PRLibrary*) 1682 1739 PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt) 1683 1740 { … … 1704 1761 lm->name = strdup(name); 1705 1762 lm->refCount = 1; 1706 #if defined(XP_MAC) 1763 #if defined(XP_MAC) && !defined(VBOX_USE_MORE_IPRT_IN_NSPR) 1707 1764 lm->connection = pr_exe_loadmap ? pr_exe_loadmap->connection : 0; 1708 1765 #else … … 1740 1797 #elif defined(USE_MACH_DYLD) 1741 1798 char *result; 1742 char *image_name;1799 char const *image_name; 1743 1800 int i, count = _dyld_image_count(); 1744 1801 … … 1875 1932 $DESCRIPTOR (device_name_desc, device_name); 1876 1933 struct fibdef fib; 1877 struct dsc$descriptor_s fib_desc = 1934 struct dsc$descriptor_s fib_desc = 1878 1935 { sizeof(struct fibdef), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *)&fib } ; 1879 1936 IOSB iosb; … … 1884 1941 char file_name[MAX_FILNAM+1]; 1885 1942 char *result = NULL; 1886 struct dsc$descriptor_s file_name_desc = 1943 struct dsc$descriptor_s file_name_desc = 1887 1944 { MAX_FILNAM, DSC$K_DTYPE_T, DSC$K_CLASS_S, (char *) &file_name[0] } ; 1888 1945 … … 1904 1961 icb != IAC$GL_IMAGE_LIST; 1905 1962 icb = icb->imcb$l_flink) { 1906 if (((void *)addr >= icb->imcb$l_starting_address) && 1963 if (((void *)addr >= icb->imcb$l_starting_address) && 1907 1964 ((void *)addr <= icb->imcb$l_end_address)) { 1908 1965 /*
Note:
See TracChangeset
for help on using the changeset viewer.