tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

blname.c (3063B)


      1 /*
      2 *  blname.c - determine the freebl library name.
      3 *  This Source Code Form is subject to the terms of the Mozilla Public
      4 *  License, v. 2.0. If a copy of the MPL was not distributed with this
      5 *  file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #if defined(FREEBL_LOWHASH)
      8 static const char* default_name =
      9    SHLIB_PREFIX "freeblpriv" SHLIB_VERSION "." SHLIB_SUFFIX;
     10 #else
     11 static const char* default_name =
     12    SHLIB_PREFIX "freebl" SHLIB_VERSION "." SHLIB_SUFFIX;
     13 #endif
     14 
     15 /* getLibName() returns the name of the library to load. */
     16 
     17 #if defined(SOLARIS) && defined(__sparc)
     18 #include <stddef.h>
     19 #include <strings.h>
     20 #include <sys/systeminfo.h>
     21 
     22 #if defined(NSS_USE_64)
     23 
     24 const static char fpu_hybrid_shared_lib[] = "libfreebl_64fpu_3.so";
     25 const static char int_hybrid_shared_lib[] = "libfreebl_64int_3.so";
     26 const static char non_hybrid_shared_lib[] = "libfreebl_64fpu_3.so";
     27 
     28 const static char int_hybrid_isa[] = "sparcv9";
     29 const static char fpu_hybrid_isa[] = "sparcv9+vis";
     30 
     31 #else
     32 
     33 const static char fpu_hybrid_shared_lib[] = "libfreebl_32fpu_3.so";
     34 const static char int_hybrid_shared_lib[] = "libfreebl_32int64_3.so";
     35 /* This was for SPARC V8, now obsolete. */
     36 const static char* const non_hybrid_shared_lib = NULL;
     37 
     38 const static char int_hybrid_isa[] = "sparcv8plus";
     39 const static char fpu_hybrid_isa[] = "sparcv8plus+vis";
     40 
     41 #endif
     42 
     43 static const char*
     44 getLibName(void)
     45 {
     46    char* found_int_hybrid;
     47    char* found_fpu_hybrid;
     48    long buflen;
     49    char buf[256];
     50 
     51    buflen = sysinfo(SI_ISALIST, buf, sizeof buf);
     52    if (buflen <= 0)
     53        return NULL;
     54    /* sysinfo output is always supposed to be NUL terminated, but ... */
     55    if (buflen < sizeof buf)
     56        buf[buflen] = '\0';
     57    else
     58        buf[(sizeof buf) - 1] = '\0';
     59    /* The ISA list is a space separated string of names of ISAs and
     60     * ISA extensions, in order of decreasing performance.
     61     * There are two different ISAs with which NSS's crypto code can be
     62     * accelerated. If both are in the list, we take the first one.
     63     * If one is in the list, we use it, and if neither then we use
     64     * the base unaccelerated code.
     65     */
     66    found_int_hybrid = strstr(buf, int_hybrid_isa);
     67    found_fpu_hybrid = strstr(buf, fpu_hybrid_isa);
     68    if (found_fpu_hybrid &&
     69        (!found_int_hybrid ||
     70         (found_int_hybrid - found_fpu_hybrid) >= 0)) {
     71        return fpu_hybrid_shared_lib;
     72    }
     73    if (found_int_hybrid) {
     74        return int_hybrid_shared_lib;
     75    }
     76    return non_hybrid_shared_lib;
     77 }
     78 
     79 #elif defined(HPUX) && !defined(NSS_USE_64) && !defined(__ia64)
     80 #include <unistd.h>
     81 
     82 /* This code tests to see if we're running on a PA2.x CPU.
     83 ** It returns true (1) if so, and false (0) otherwise.
     84 */
     85 static const char*
     86 getLibName(void)
     87 {
     88    long cpu = sysconf(_SC_CPU_VERSION);
     89    return (cpu == CPU_PA_RISC2_0)
     90               ? "libfreebl_32fpu_3.sl"
     91               : "libfreebl_32int_3.sl";
     92 }
     93 #else
     94 /* default case, for platforms/ABIs that have only one freebl shared lib. */
     95 static const char*
     96 getLibName(void)
     97 {
     98    return default_name;
     99 }
    100 #endif