Thu, 15 Jan 2015 15:59:08 +0100
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.
michael@0 | 1 | #!/usr/bin/perl |
michael@0 | 2 | ## |
michael@0 | 3 | ## Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 4 | ## |
michael@0 | 5 | ## Use of this source code is governed by a BSD-style license |
michael@0 | 6 | ## that can be found in the LICENSE file in the root of the source |
michael@0 | 7 | ## tree. An additional intellectual property rights grant can be found |
michael@0 | 8 | ## in the file PATENTS. All contributing project authors may |
michael@0 | 9 | ## be found in the AUTHORS file in the root of the source tree. |
michael@0 | 10 | ## |
michael@0 | 11 | |
michael@0 | 12 | |
michael@0 | 13 | # ads2gas.pl |
michael@0 | 14 | # Author: Eric Fung (efung (at) acm.org) |
michael@0 | 15 | # |
michael@0 | 16 | # Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format |
michael@0 | 17 | # |
michael@0 | 18 | # Usage: cat inputfile | perl ads2gas.pl > outputfile |
michael@0 | 19 | # |
michael@0 | 20 | |
michael@0 | 21 | use FindBin; |
michael@0 | 22 | use lib $FindBin::Bin; |
michael@0 | 23 | use thumb; |
michael@0 | 24 | |
michael@0 | 25 | my $thumb = 0; |
michael@0 | 26 | |
michael@0 | 27 | foreach my $arg (@ARGV) { |
michael@0 | 28 | $thumb = 1 if ($arg eq "-thumb"); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | print "@ This file was created from a .asm file\n"; |
michael@0 | 32 | print "@ using the ads2gas.pl script.\n"; |
michael@0 | 33 | print "\t.equ DO1STROUNDING, 0\n"; |
michael@0 | 34 | if ($thumb) { |
michael@0 | 35 | print "\t.syntax unified\n"; |
michael@0 | 36 | print "\t.thumb\n"; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | # Stack of procedure names. |
michael@0 | 40 | @proc_stack = (); |
michael@0 | 41 | |
michael@0 | 42 | while (<STDIN>) |
michael@0 | 43 | { |
michael@0 | 44 | undef $comment; |
michael@0 | 45 | undef $line; |
michael@0 | 46 | $comment_char = ";"; |
michael@0 | 47 | $comment_sub = "@"; |
michael@0 | 48 | |
michael@0 | 49 | # Handle comments. |
michael@0 | 50 | if (/$comment_char/) |
michael@0 | 51 | { |
michael@0 | 52 | $comment = ""; |
michael@0 | 53 | ($line, $comment) = /(.*?)$comment_char(.*)/; |
michael@0 | 54 | $_ = $line; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | # Load and store alignment |
michael@0 | 58 | s/@/,:/g; |
michael@0 | 59 | |
michael@0 | 60 | # Hexadecimal constants prefaced by 0x |
michael@0 | 61 | s/#&/#0x/g; |
michael@0 | 62 | |
michael@0 | 63 | # Convert :OR: to | |
michael@0 | 64 | s/:OR:/ | /g; |
michael@0 | 65 | |
michael@0 | 66 | # Convert :AND: to & |
michael@0 | 67 | s/:AND:/ & /g; |
michael@0 | 68 | |
michael@0 | 69 | # Convert :NOT: to ~ |
michael@0 | 70 | s/:NOT:/ ~ /g; |
michael@0 | 71 | |
michael@0 | 72 | # Convert :SHL: to << |
michael@0 | 73 | s/:SHL:/ << /g; |
michael@0 | 74 | |
michael@0 | 75 | # Convert :SHR: to >> |
michael@0 | 76 | s/:SHR:/ >> /g; |
michael@0 | 77 | |
michael@0 | 78 | # Convert ELSE to .else |
michael@0 | 79 | s/\bELSE\b/.else/g; |
michael@0 | 80 | |
michael@0 | 81 | # Convert ENDIF to .endif |
michael@0 | 82 | s/\bENDIF\b/.endif/g; |
michael@0 | 83 | |
michael@0 | 84 | # Convert ELSEIF to .elseif |
michael@0 | 85 | s/\bELSEIF\b/.elseif/g; |
michael@0 | 86 | |
michael@0 | 87 | # Convert LTORG to .ltorg |
michael@0 | 88 | s/\bLTORG\b/.ltorg/g; |
michael@0 | 89 | |
michael@0 | 90 | # Convert endfunc to nothing. |
michael@0 | 91 | s/\bendfunc\b//ig; |
michael@0 | 92 | |
michael@0 | 93 | # Convert FUNCTION to nothing. |
michael@0 | 94 | s/\bFUNCTION\b//g; |
michael@0 | 95 | s/\bfunction\b//g; |
michael@0 | 96 | |
michael@0 | 97 | s/\bENTRY\b//g; |
michael@0 | 98 | s/\bMSARMASM\b/0/g; |
michael@0 | 99 | s/^\s+end\s+$//g; |
michael@0 | 100 | |
michael@0 | 101 | # Convert IF :DEF:to .if |
michael@0 | 102 | # gcc doesn't have the ability to do a conditional |
michael@0 | 103 | # if defined variable that is set by IF :DEF: on |
michael@0 | 104 | # armasm, so convert it to a normal .if and then |
michael@0 | 105 | # make sure to define a value elesewhere |
michael@0 | 106 | if (s/\bIF :DEF:\b/.if /g) |
michael@0 | 107 | { |
michael@0 | 108 | s/=/==/g; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | # Convert IF to .if |
michael@0 | 112 | if (s/\bIF\b/.if/g) |
michael@0 | 113 | { |
michael@0 | 114 | s/=+/==/g; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | # Convert INCLUDE to .INCLUDE "file" |
michael@0 | 118 | s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/; |
michael@0 | 119 | |
michael@0 | 120 | # Code directive (ARM vs Thumb) |
michael@0 | 121 | s/CODE([0-9][0-9])/.code $1/; |
michael@0 | 122 | |
michael@0 | 123 | # No AREA required |
michael@0 | 124 | # But ALIGNs in AREA must be obeyed |
michael@0 | 125 | s/^\s*AREA.*ALIGN=([0-9])$/.text\n.p2align $1/; |
michael@0 | 126 | # If no ALIGN, strip the AREA and align to 4 bytes |
michael@0 | 127 | s/^\s*AREA.*$/.text\n.p2align 2/; |
michael@0 | 128 | |
michael@0 | 129 | # DCD to .word |
michael@0 | 130 | # This one is for incoming symbols |
michael@0 | 131 | s/DCD\s+\|(\w*)\|/.long $1/; |
michael@0 | 132 | |
michael@0 | 133 | # DCW to .short |
michael@0 | 134 | s/DCW\s+\|(\w*)\|/.short $1/; |
michael@0 | 135 | s/DCW(.*)/.short $1/; |
michael@0 | 136 | |
michael@0 | 137 | # Constants defined in scope |
michael@0 | 138 | s/DCD(.*)/.long $1/; |
michael@0 | 139 | s/DCB(.*)/.byte $1/; |
michael@0 | 140 | |
michael@0 | 141 | # RN to .req |
michael@0 | 142 | if (s/RN\s+([Rr]\d+|lr)/.req $1/) |
michael@0 | 143 | { |
michael@0 | 144 | print; |
michael@0 | 145 | print "$comment_sub$comment\n" if defined $comment; |
michael@0 | 146 | next; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | # Make function visible to linker, and make additional symbol with |
michael@0 | 150 | # prepended underscore |
michael@0 | 151 | s/EXPORT\s+\|([\$\w]*)\|/.global $1 \n\t.type $1, function/; |
michael@0 | 152 | s/IMPORT\s+\|([\$\w]*)\|/.global $1/; |
michael@0 | 153 | |
michael@0 | 154 | s/EXPORT\s+([\$\w]*)/.global $1/; |
michael@0 | 155 | s/export\s+([\$\w]*)/.global $1/; |
michael@0 | 156 | |
michael@0 | 157 | # No vertical bars required; make additional symbol with prepended |
michael@0 | 158 | # underscore |
michael@0 | 159 | s/^\|(\$?\w+)\|/_$1\n\t$1:/g; |
michael@0 | 160 | |
michael@0 | 161 | # Labels need trailing colon |
michael@0 | 162 | # s/^(\w+)/$1:/ if !/EQU/; |
michael@0 | 163 | # put the colon at the end of the line in the macro |
michael@0 | 164 | s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/; |
michael@0 | 165 | |
michael@0 | 166 | # ALIGN directive |
michael@0 | 167 | s/\bALIGN\b/.balign/g; |
michael@0 | 168 | |
michael@0 | 169 | if ($thumb) { |
michael@0 | 170 | # ARM code - we force everything to thumb with the declaration in the header |
michael@0 | 171 | s/\sARM//g; |
michael@0 | 172 | } else { |
michael@0 | 173 | # ARM code |
michael@0 | 174 | s/\sARM/.arm/g; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | # push/pop |
michael@0 | 178 | s/(push\s+)(r\d+)/stmdb sp\!, \{$2\}/g; |
michael@0 | 179 | s/(pop\s+)(r\d+)/ldmia sp\!, \{$2\}/g; |
michael@0 | 180 | |
michael@0 | 181 | # NEON code |
michael@0 | 182 | s/(vld1.\d+\s+)(q\d+)/$1\{$2\}/g; |
michael@0 | 183 | s/(vtbl.\d+\s+[^,]+),([^,]+)/$1,\{$2\}/g; |
michael@0 | 184 | |
michael@0 | 185 | if ($thumb) { |
michael@0 | 186 | thumb::FixThumbInstructions($_, 0); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | # eabi_attributes numerical equivalents can be found in the |
michael@0 | 190 | # "ARM IHI 0045C" document. |
michael@0 | 191 | |
michael@0 | 192 | # REQUIRE8 Stack is required to be 8-byte aligned |
michael@0 | 193 | s/\sREQUIRE8/.eabi_attribute 24, 1 \@Tag_ABI_align_needed/g; |
michael@0 | 194 | |
michael@0 | 195 | # PRESERVE8 Stack 8-byte align is preserved |
michael@0 | 196 | s/\sPRESERVE8/.eabi_attribute 25, 1 \@Tag_ABI_align_preserved/g; |
michael@0 | 197 | |
michael@0 | 198 | # Use PROC and ENDP to give the symbols a .size directive. |
michael@0 | 199 | # This makes them show up properly in debugging tools like gdb and valgrind. |
michael@0 | 200 | if (/\bPROC\b/) |
michael@0 | 201 | { |
michael@0 | 202 | my $proc; |
michael@0 | 203 | /^_([\.0-9A-Z_a-z]\w+)\b/; |
michael@0 | 204 | $proc = $1; |
michael@0 | 205 | push(@proc_stack, $proc) if ($proc); |
michael@0 | 206 | s/\bPROC\b/@ $&/; |
michael@0 | 207 | } |
michael@0 | 208 | if (/\bENDP\b/) |
michael@0 | 209 | { |
michael@0 | 210 | my $proc; |
michael@0 | 211 | s/\bENDP\b/@ $&/; |
michael@0 | 212 | $proc = pop(@proc_stack); |
michael@0 | 213 | $_ = "\t.size $proc, .-$proc".$_ if ($proc); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | # EQU directive |
michael@0 | 217 | s/(\S+\s+)EQU(\s+\S+)/.equ $1, $2/; |
michael@0 | 218 | |
michael@0 | 219 | # Begin macro definition |
michael@0 | 220 | if (/\bMACRO\b/) { |
michael@0 | 221 | $_ = <STDIN>; |
michael@0 | 222 | s/^/.macro/; |
michael@0 | 223 | s/\$//g; # remove formal param reference |
michael@0 | 224 | s/;/@/g; # change comment characters |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | # For macros, use \ to reference formal params |
michael@0 | 228 | s/\$/\\/g; # End macro definition |
michael@0 | 229 | s/\bMEND\b/.endm/; # No need to tell it where to stop assembling |
michael@0 | 230 | next if /^\s*END\s*$/; |
michael@0 | 231 | print; |
michael@0 | 232 | print "$comment_sub$comment\n" if defined $comment; |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | # Mark that this object doesn't need an executable stack. |
michael@0 | 236 | printf ("\t.section\t.note.GNU-stack,\"\",\%\%progbits\n"); |