js/src/jit/arm/Architecture-arm.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     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/. */
     7 #include "jit/arm/Architecture-arm.h"
     9 #ifndef JS_ARM_SIMULATOR
    10 #include <elf.h>
    11 #endif
    13 #include <fcntl.h>
    14 #include <unistd.h>
    16 #include "jit/arm/Assembler-arm.h"
    18 #define HWCAP_USE_HARDFP_ABI (1 << 28)
    20 #if !(defined(ANDROID) || defined(MOZ_B2G)) && !defined(JS_ARM_SIMULATOR)
    21 #define HWCAP_ARMv7 (1 << 29)
    22 #include <asm/hwcap.h>
    23 #else
    24 #define HWCAP_VFP      (1<<0)
    25 #define HWCAP_VFPv3    (1<<1)
    26 #define HWCAP_VFPv3D16 (1<<2)
    27 #define HWCAP_VFPv4    (1<<3)
    28 #define HWCAP_IDIVA    (1<<4)
    29 #define HWCAP_IDIVT    (1<<5)
    30 #define HWCAP_NEON     (1<<6)
    31 #define HWCAP_ARMv7    (1<<7)
    32 #endif
    34 namespace js {
    35 namespace jit {
    37 uint32_t GetARMFlags()
    38 {
    39     static bool isSet = false;
    40     static uint32_t flags = 0;
    41     if (isSet)
    42         return flags;
    44 #ifdef JS_CODEGEN_ARM_HARDFP
    45     flags |= HWCAP_USE_HARDFP_ABI;
    46 #endif
    48     static const char *env = getenv("ARMHWCAP");
    50     if (env && env[0]) {
    51         if (strstr(env, "help")) {
    52             fflush(NULL);
    53             printf(
    54                    "\n"
    55                    "usage: ARMHWCAP=option,option,option,... where options can be:\n"
    56                    "\n"
    57                    "  armv7    \n"
    58                    "  vfp      \n"
    59                    "  neon     \n"
    60                    "  vfpv3    \n"
    61                    "  vfpv3d16 \n"
    62                    "  vfpv4    \n"
    63                    "  idiva    \n"
    64                    "  idivt    \n"
    65 #if defined(JS_ARM_SIMULATOR)
    66                    "  hardfp   \n"
    67 #endif
    68                    "\n"
    69                    );
    70             exit(0);
    71             /*NOTREACHED*/
    72         } else {
    73             // Canonicalize each token to have a leading and trailing space.
    74             const char *start = env;  // Token start.
    75             for (;;) {
    76                 char  ch = *start;
    77                 if (!ch) {
    78                     // End of string.
    79                     break;
    80                 }
    81                 if (ch == ' ' || ch == ',') {
    82                     // Skip separator characters.
    83                     start++;
    84                     continue;
    85                 }
    86                 // Find the end of the token.
    87                 const char *end = start + 1;
    88                 for (; ; end++) {
    89                     ch = *end;
    90                     if (!ch || ch == ' ' || ch == ',')
    91                         break;
    92                 }
    93                 size_t count = end - start;
    94                 if (count == 3 && strncmp(start, "vfp", 3) == 0)
    95                     flags |= HWCAP_VFP;
    96                 else if (count == 5 && strncmp(start, "vfpv3", 5) == 0)
    97                     flags |= HWCAP_VFPv3;
    98                 else if (count == 8 && strncmp(start, "vfpv3d16", 8) == 0)
    99                     flags |= HWCAP_VFPv3D16;
   100                 else if (count == 5 && strncmp(start, "vfpv4", 5) == 0)
   101                     flags |= HWCAP_VFPv4;
   102                 else if (count == 5 && strncmp(start, "idiva", 5) == 0)
   103                     flags |= HWCAP_IDIVA;
   104                 else if (count == 5 && strncmp(start, "idivt", 5) == 0)
   105                     flags |= HWCAP_IDIVT;
   106                 else if (count == 4 && strncmp(start, "neon", 4) == 0)
   107                     flags |= HWCAP_NEON;
   108                 else if (count == 5 && strncmp(start, "armv7", 5) == 0)
   109                     flags |= HWCAP_ARMv7;
   110 #if defined(JS_ARM_SIMULATOR)
   111                 else if (count == 6 && strncmp(start, "hardfp", 6) == 0)
   112                     flags |= HWCAP_USE_HARDFP_ABI;
   113 #endif
   114                 else
   115                     fprintf(stderr, "Warning: unexpected ARMHWCAP flag at: %s\n", start);
   116                 start = end;
   117             }
   118 #ifdef DEBUG
   119             IonSpew(IonSpew_Codegen, "ARMHWCAP: '%s'\n   flags: 0x%x\n", env, flags);
   120 #endif
   121             isSet = true;
   122             return flags;
   123         }
   124     }
   126 #ifdef JS_ARM_SIMULATOR
   127     isSet = true;
   128     flags = HWCAP_ARMv7 | HWCAP_VFP | HWCAP_VFPv3 | HWCAP_VFPv4 | HWCAP_NEON;
   129     return flags;
   130 #else
   132 #if WTF_OS_LINUX
   133     int fd = open("/proc/self/auxv", O_RDONLY);
   134     if (fd > 0) {
   135         Elf32_auxv_t aux;
   136         while (read(fd, &aux, sizeof(Elf32_auxv_t))) {
   137             if (aux.a_type == AT_HWCAP) {
   138                 close(fd);
   139                 flags = aux.a_un.a_val;
   140                 isSet = true;
   141 #if defined(__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
   142                 // this should really be detected at runtime, but
   143                 // /proc/*/auxv doesn't seem to carry the ISA
   144                 // I could look in /proc/cpuinfo as well, but
   145                 // the chances that it will be different from this
   146                 // are low.
   147                 flags |= HWCAP_ARMv7;
   148 #endif
   149                 return flags;
   150             }
   151         }
   152         close(fd);
   153     }
   155 #if defined(__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
   156     flags = HWCAP_ARMv7;
   157 #endif
   158     isSet = true;
   159     return flags;
   161 #elif defined(WTF_OS_ANDROID) || defined(MOZ_B2G)
   162     FILE *fp = fopen("/proc/cpuinfo", "r");
   163     if (!fp)
   164         return false;
   166     char buf[1024];
   167     memset(buf, 0, sizeof(buf));
   168     size_t len = fread(buf, sizeof(char), sizeof(buf) - 2, fp);
   169     fclose(fp);
   170     // Canonicalize each token to have a leading and trailing space.
   171     buf[len] = ' ';
   172     buf[len + 1] = '\0';
   173     for (size_t i = 0; i < len; i++) {
   174         char  ch = buf[i];
   175         if (!ch)
   176             break;
   177         else if (ch == '\n')
   178             buf[i] = 0x20;
   179         else
   180             buf[i] = ch;
   181     }
   183     if (strstr(buf, " vfp "))
   184         flags |= HWCAP_VFP;
   186     if (strstr(buf, " vfpv3 "))
   187         flags |= HWCAP_VFPv3;
   189     if (strstr(buf, " vfpv3d16 "))
   190         flags |= HWCAP_VFPv3D16;
   192     if (strstr(buf, " vfpv4 "))
   193         flags |= HWCAP_VFPv4;
   195     if (strstr(buf, " idiva "))
   196         flags |= HWCAP_IDIVA;
   198     if (strstr(buf, " idivt "))
   199         flags |= HWCAP_IDIVT;
   201     if (strstr(buf, " neon "))
   202         flags |= HWCAP_NEON;
   204     // not part of the HWCAP flag, but I need to know this, and we're not using
   205     //  that bit, so... I'm using it
   206     if (strstr(buf, "ARMv7"))
   207         flags |= HWCAP_ARMv7;
   209 #ifdef DEBUG
   210     IonSpew(IonSpew_Codegen, "ARMHWCAP: '%s'\n   flags: 0x%x\n", buf, flags);
   211 #endif
   213     isSet = true;
   214     return flags;
   215 #endif
   217     return 0;
   218 #endif // JS_ARM_SIMULATOR
   219 }
   221 bool hasMOVWT()
   222 {
   223     return GetARMFlags() & HWCAP_ARMv7;
   224 }
   225 bool hasVFPv3()
   226 {
   227     return GetARMFlags() & HWCAP_VFPv3;
   228 }
   229 bool hasVFP()
   230 {
   231     return GetARMFlags() & HWCAP_VFP;
   232 }
   234 bool has32DP()
   235 {
   236     return !(GetARMFlags() & HWCAP_VFPv3D16 && !(GetARMFlags() & HWCAP_NEON));
   237 }
   238 bool useConvReg()
   239 {
   240     return has32DP();
   241 }
   243 bool hasIDIV()
   244 {
   245 #if defined HWCAP_IDIVA
   246     return GetARMFlags() & HWCAP_IDIVA;
   247 #else
   248     return false;
   249 #endif
   250 }
   252 // This is defined in the header and inlined when not using the simulator.
   253 #if defined(JS_ARM_SIMULATOR)
   254 bool useHardFpABI()
   255 {
   256     return GetARMFlags() & HWCAP_USE_HARDFP_ABI;
   257 }
   258 #endif
   260 Registers::Code
   261 Registers::FromName(const char *name)
   262 {
   263     // Check for some register aliases first.
   264     if (strcmp(name, "ip") == 0)
   265         return ip;
   266     if (strcmp(name, "r13") == 0)
   267         return r13;
   268     if (strcmp(name, "lr") == 0)
   269         return lr;
   270     if (strcmp(name, "r15") == 0)
   271         return r15;
   273     for (size_t i = 0; i < Total; i++) {
   274         if (strcmp(GetName(i), name) == 0)
   275             return Code(i);
   276     }
   278     return Invalid;
   279 }
   281 FloatRegisters::Code
   282 FloatRegisters::FromName(const char *name)
   283 {
   284     for (size_t i = 0; i < Total; i++) {
   285         if (strcmp(GetName(i), name) == 0)
   286             return Code(i);
   287     }
   289     return Invalid;
   290 }
   292 } // namespace jit
   293 } // namespace js

mercurial