build/unix/elfhack/test.c

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifdef DEF
     6 DEF(This)
     7 DEF(is)
     8 DEF(a)
     9 DEF(test)
    10 DEF(of)
    11 DEF(string)
    12 DEF(array)
    13 DEF(for)
    14 DEF(use)
    15 DEF(with)
    16 DEF(elfhack)
    17 DEF(to)
    18 DEF(see)
    19 DEF(whether)
    20 DEF(it)
    21 DEF(breaks)
    22 DEF(anything)
    23 DEF(but)
    24 DEF(one)
    25 DEF(needs)
    26 DEF(quite)
    27 DEF(some)
    28 DEF(strings)
    29 DEF(before)
    30 DEF(the)
    31 DEF(program)
    32 DEF(can)
    33 DEF(do)
    34 DEF(its)
    35 DEF(work)
    36 DEF(efficiently)
    37 DEF(Without)
    38 DEF(enough)
    39 DEF(data)
    40 DEF(relocation)
    41 DEF(sections)
    42 DEF(are)
    43 DEF(not)
    44 DEF(sufficiently)
    45 DEF(large)
    46 DEF(and)
    47 DEF(injected)
    48 DEF(code)
    49 DEF(wouldnt)
    50 DEF(fit)
    51 DEF(Said)
    52 DEF(otherwise)
    53 DEF(we)
    54 DEF(need)
    55 DEF(more)
    56 DEF(words)
    57 DEF(than)
    58 DEF(up)
    59 DEF(here)
    60 DEF(so)
    61 DEF(that)
    62 DEF(relocations)
    63 DEF(take)
    64 DEF(significant)
    65 DEF(bytes)
    66 DEF(amounts)
    67 DEF(which)
    68 DEF(isnt)
    69 DEF(exactly)
    70 DEF(easily)
    71 DEF(achieved)
    72 DEF(like)
    73 DEF(this)
    74 DEF(Actually)
    75 DEF(I)
    76 DEF(must)
    77 DEF(cheat)
    78 DEF(by)
    79 DEF(including)
    80 DEF(these)
    81 DEF(phrases)
    82 DEF(several)
    83 DEF(times)
    85 #else
    86 #pragma GCC visibility push(default)
    87 #include <stdlib.h>
    88 #include <stdio.h>
    90 #define DEF(w) static const char str_ ## w[] = #w;
    91 #include "test.c"
    92 #undef DEF
    94 const char *strings[] = {
    95 #define DEF(w) str_ ## w,
    96 #include "test.c"
    97 #include "test.c"
    98 #include "test.c"
    99 };
   101 /* Create a hole between two zones of relative relocations */
   102 const int hole[] = {
   103     42, 42, 42, 42
   104 };
   106 const char *strings2[] = {
   107 #include "test.c"
   108 #include "test.c"
   109 #include "test.c"
   110 #include "test.c"
   111 #include "test.c"
   112 #undef DEF
   113 };
   115 static int ret = 1;
   117 int print_status() {
   118     fprintf(stderr, "%s\n", ret ? "FAIL" : "PASS");
   119     return ret;
   120 }
   122 /* On ARM, this creates a .tbss section before .init_array, which
   123  * elfhack could then pick instead of .init_array.
   124  * Also, when .tbss is big enough, elfhack may wrongfully consider
   125  * following sections as part of the PT_TLS segment.
   126  * Finally, gold makes TLS segments end on an aligned virtual address,
   127  * even when the underlying section ends before that, and elfhack
   128  * sanity checks may yield an error. */
   129 __thread int foo;
   130 __thread long long int bar[512];
   132 void end_test() {
   133     static int count = 0;
   134     /* Only exit when both constructors have been called */
   135     if (++count == 2)
   136         ret = 0;
   137 }
   139 void test() {
   140     int i = 0, j = 0;
   141 #define DEF_(a,i,w) \
   142     if (a[i++] != str_ ## w) return;
   143 #define DEF(w) DEF_(strings,i,w)
   144 #include "test.c"
   145 #include "test.c"
   146 #include "test.c"
   147 #undef DEF
   148 #define DEF(w) DEF_(strings2,j,w)
   149 #include "test.c"
   150 #include "test.c"
   151 #include "test.c"
   152 #include "test.c"
   153 #include "test.c"
   154 #undef DEF
   155     if (i != sizeof(strings)/sizeof(strings[0]) &&
   156         j != sizeof(strings2)/sizeof(strings2[0]))
   157         fprintf(stderr, "WARNING: Test doesn't cover the whole array\n");
   158     end_test();
   159 }
   161 #pragma GCC visibility pop
   162 #endif

mercurial