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 | ; |
michael@0 | 2 | ; Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | ; |
michael@0 | 4 | ; Use of this source code is governed by a BSD-style license |
michael@0 | 5 | ; that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | ; tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | ; in the file PATENTS. All contributing project authors may |
michael@0 | 8 | ; be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | ; |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | EXPORT |vp8_start_encode| |
michael@0 | 13 | EXPORT |vp8_encode_bool| |
michael@0 | 14 | EXPORT |vp8_stop_encode| |
michael@0 | 15 | EXPORT |vp8_encode_value| |
michael@0 | 16 | IMPORT |vp8_validate_buffer_arm| |
michael@0 | 17 | |
michael@0 | 18 | INCLUDE vp8_asm_enc_offsets.asm |
michael@0 | 19 | |
michael@0 | 20 | ARM |
michael@0 | 21 | REQUIRE8 |
michael@0 | 22 | PRESERVE8 |
michael@0 | 23 | |
michael@0 | 24 | AREA |.text|, CODE, READONLY |
michael@0 | 25 | |
michael@0 | 26 | ; macro for validating write buffer position |
michael@0 | 27 | ; needs vp8_writer in r0 |
michael@0 | 28 | ; start shall not be in r1 |
michael@0 | 29 | MACRO |
michael@0 | 30 | VALIDATE_POS $start, $pos |
michael@0 | 31 | push {r0-r3, r12, lr} ; rest of regs are preserved by subroutine call |
michael@0 | 32 | ldr r2, [r0, #vp8_writer_buffer_end] |
michael@0 | 33 | ldr r3, [r0, #vp8_writer_error] |
michael@0 | 34 | mov r1, $pos |
michael@0 | 35 | mov r0, $start |
michael@0 | 36 | bl vp8_validate_buffer_arm |
michael@0 | 37 | pop {r0-r3, r12, lr} |
michael@0 | 38 | MEND |
michael@0 | 39 | |
michael@0 | 40 | ; r0 BOOL_CODER *br |
michael@0 | 41 | ; r1 unsigned char *source |
michael@0 | 42 | ; r2 unsigned char *source_end |
michael@0 | 43 | |vp8_start_encode| PROC |
michael@0 | 44 | str r2, [r0, #vp8_writer_buffer_end] |
michael@0 | 45 | mov r12, #0 |
michael@0 | 46 | mov r3, #255 |
michael@0 | 47 | mvn r2, #23 |
michael@0 | 48 | str r12, [r0, #vp8_writer_lowvalue] |
michael@0 | 49 | str r3, [r0, #vp8_writer_range] |
michael@0 | 50 | str r2, [r0, #vp8_writer_count] |
michael@0 | 51 | str r12, [r0, #vp8_writer_pos] |
michael@0 | 52 | str r1, [r0, #vp8_writer_buffer] |
michael@0 | 53 | bx lr |
michael@0 | 54 | ENDP |
michael@0 | 55 | |
michael@0 | 56 | ; r0 BOOL_CODER *br |
michael@0 | 57 | ; r1 int bit |
michael@0 | 58 | ; r2 int probability |
michael@0 | 59 | |vp8_encode_bool| PROC |
michael@0 | 60 | push {r4-r10, lr} |
michael@0 | 61 | |
michael@0 | 62 | mov r4, r2 |
michael@0 | 63 | |
michael@0 | 64 | ldr r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 65 | ldr r5, [r0, #vp8_writer_range] |
michael@0 | 66 | ldr r3, [r0, #vp8_writer_count] |
michael@0 | 67 | |
michael@0 | 68 | sub r7, r5, #1 ; range-1 |
michael@0 | 69 | |
michael@0 | 70 | cmp r1, #0 |
michael@0 | 71 | mul r6, r4, r7 ; ((range-1) * probability) |
michael@0 | 72 | |
michael@0 | 73 | mov r7, #1 |
michael@0 | 74 | add r4, r7, r6, lsr #8 ; 1 + (((range-1) * probability) >> 8) |
michael@0 | 75 | |
michael@0 | 76 | addne r2, r2, r4 ; if (bit) lowvalue += split |
michael@0 | 77 | subne r4, r5, r4 ; if (bit) range = range-split |
michael@0 | 78 | |
michael@0 | 79 | ; Counting the leading zeros is used to normalize range. |
michael@0 | 80 | clz r6, r4 |
michael@0 | 81 | sub r6, r6, #24 ; shift |
michael@0 | 82 | |
michael@0 | 83 | ; Flag is set on the sum of count. This flag is used later |
michael@0 | 84 | ; to determine if count >= 0 |
michael@0 | 85 | adds r3, r3, r6 ; count += shift |
michael@0 | 86 | lsl r5, r4, r6 ; range <<= shift |
michael@0 | 87 | bmi token_count_lt_zero ; if(count >= 0) |
michael@0 | 88 | |
michael@0 | 89 | sub r6, r6, r3 ; offset = shift - count |
michael@0 | 90 | sub r4, r6, #1 ; offset-1 |
michael@0 | 91 | lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) |
michael@0 | 92 | bpl token_high_bit_not_set |
michael@0 | 93 | |
michael@0 | 94 | ldr r4, [r0, #vp8_writer_pos] ; x |
michael@0 | 95 | sub r4, r4, #1 ; x = w->pos-1 |
michael@0 | 96 | b token_zero_while_start |
michael@0 | 97 | token_zero_while_loop |
michael@0 | 98 | mov r9, #0 |
michael@0 | 99 | strb r9, [r7, r4] ; w->buffer[x] =(unsigned char)0 |
michael@0 | 100 | sub r4, r4, #1 ; x-- |
michael@0 | 101 | token_zero_while_start |
michael@0 | 102 | cmp r4, #0 |
michael@0 | 103 | ldrge r7, [r0, #vp8_writer_buffer] |
michael@0 | 104 | ldrb r1, [r7, r4] |
michael@0 | 105 | cmpge r1, #0xff |
michael@0 | 106 | beq token_zero_while_loop |
michael@0 | 107 | |
michael@0 | 108 | ldr r7, [r0, #vp8_writer_buffer] |
michael@0 | 109 | ldrb r9, [r7, r4] ; w->buffer[x] |
michael@0 | 110 | add r9, r9, #1 |
michael@0 | 111 | strb r9, [r7, r4] ; w->buffer[x] + 1 |
michael@0 | 112 | token_high_bit_not_set |
michael@0 | 113 | rsb r4, r6, #24 ; 24-offset |
michael@0 | 114 | ldr r9, [r0, #vp8_writer_buffer] |
michael@0 | 115 | lsr r7, r2, r4 ; lowvalue >> (24-offset) |
michael@0 | 116 | ldr r4, [r0, #vp8_writer_pos] ; w->pos |
michael@0 | 117 | lsl r2, r2, r6 ; lowvalue <<= offset |
michael@0 | 118 | mov r6, r3 ; shift = count |
michael@0 | 119 | add r1, r4, #1 ; w->pos++ |
michael@0 | 120 | bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff |
michael@0 | 121 | str r1, [r0, #vp8_writer_pos] |
michael@0 | 122 | sub r3, r3, #8 ; count -= 8 |
michael@0 | 123 | |
michael@0 | 124 | VALIDATE_POS r9, r1 ; validate_buffer at pos |
michael@0 | 125 | |
michael@0 | 126 | strb r7, [r9, r4] ; w->buffer[w->pos++] |
michael@0 | 127 | |
michael@0 | 128 | token_count_lt_zero |
michael@0 | 129 | lsl r2, r2, r6 ; lowvalue <<= shift |
michael@0 | 130 | |
michael@0 | 131 | str r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 132 | str r5, [r0, #vp8_writer_range] |
michael@0 | 133 | str r3, [r0, #vp8_writer_count] |
michael@0 | 134 | pop {r4-r10, pc} |
michael@0 | 135 | ENDP |
michael@0 | 136 | |
michael@0 | 137 | ; r0 BOOL_CODER *br |
michael@0 | 138 | |vp8_stop_encode| PROC |
michael@0 | 139 | push {r4-r10, lr} |
michael@0 | 140 | |
michael@0 | 141 | ldr r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 142 | ldr r5, [r0, #vp8_writer_range] |
michael@0 | 143 | ldr r3, [r0, #vp8_writer_count] |
michael@0 | 144 | |
michael@0 | 145 | mov r10, #32 |
michael@0 | 146 | |
michael@0 | 147 | stop_encode_loop |
michael@0 | 148 | sub r7, r5, #1 ; range-1 |
michael@0 | 149 | |
michael@0 | 150 | mov r4, r7, lsl #7 ; ((range-1) * 128) |
michael@0 | 151 | |
michael@0 | 152 | mov r7, #1 |
michael@0 | 153 | add r4, r7, r4, lsr #8 ; 1 + (((range-1) * 128) >> 8) |
michael@0 | 154 | |
michael@0 | 155 | ; Counting the leading zeros is used to normalize range. |
michael@0 | 156 | clz r6, r4 |
michael@0 | 157 | sub r6, r6, #24 ; shift |
michael@0 | 158 | |
michael@0 | 159 | ; Flag is set on the sum of count. This flag is used later |
michael@0 | 160 | ; to determine if count >= 0 |
michael@0 | 161 | adds r3, r3, r6 ; count += shift |
michael@0 | 162 | lsl r5, r4, r6 ; range <<= shift |
michael@0 | 163 | bmi token_count_lt_zero_se ; if(count >= 0) |
michael@0 | 164 | |
michael@0 | 165 | sub r6, r6, r3 ; offset = shift - count |
michael@0 | 166 | sub r4, r6, #1 ; offset-1 |
michael@0 | 167 | lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) |
michael@0 | 168 | bpl token_high_bit_not_set_se |
michael@0 | 169 | |
michael@0 | 170 | ldr r4, [r0, #vp8_writer_pos] ; x |
michael@0 | 171 | sub r4, r4, #1 ; x = w->pos-1 |
michael@0 | 172 | b token_zero_while_start_se |
michael@0 | 173 | token_zero_while_loop_se |
michael@0 | 174 | mov r9, #0 |
michael@0 | 175 | strb r9, [r7, r4] ; w->buffer[x] =(unsigned char)0 |
michael@0 | 176 | sub r4, r4, #1 ; x-- |
michael@0 | 177 | token_zero_while_start_se |
michael@0 | 178 | cmp r4, #0 |
michael@0 | 179 | ldrge r7, [r0, #vp8_writer_buffer] |
michael@0 | 180 | ldrb r1, [r7, r4] |
michael@0 | 181 | cmpge r1, #0xff |
michael@0 | 182 | beq token_zero_while_loop_se |
michael@0 | 183 | |
michael@0 | 184 | ldr r7, [r0, #vp8_writer_buffer] |
michael@0 | 185 | ldrb r9, [r7, r4] ; w->buffer[x] |
michael@0 | 186 | add r9, r9, #1 |
michael@0 | 187 | strb r9, [r7, r4] ; w->buffer[x] + 1 |
michael@0 | 188 | token_high_bit_not_set_se |
michael@0 | 189 | rsb r4, r6, #24 ; 24-offset |
michael@0 | 190 | ldr r9, [r0, #vp8_writer_buffer] |
michael@0 | 191 | lsr r7, r2, r4 ; lowvalue >> (24-offset) |
michael@0 | 192 | ldr r4, [r0, #vp8_writer_pos] ; w->pos |
michael@0 | 193 | lsl r2, r2, r6 ; lowvalue <<= offset |
michael@0 | 194 | mov r6, r3 ; shift = count |
michael@0 | 195 | add r1, r4, #1 ; w->pos++ |
michael@0 | 196 | bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff |
michael@0 | 197 | str r1, [r0, #vp8_writer_pos] |
michael@0 | 198 | sub r3, r3, #8 ; count -= 8 |
michael@0 | 199 | |
michael@0 | 200 | VALIDATE_POS r9, r1 ; validate_buffer at pos |
michael@0 | 201 | |
michael@0 | 202 | strb r7, [r9, r4] ; w->buffer[w->pos++] |
michael@0 | 203 | |
michael@0 | 204 | token_count_lt_zero_se |
michael@0 | 205 | lsl r2, r2, r6 ; lowvalue <<= shift |
michael@0 | 206 | |
michael@0 | 207 | subs r10, r10, #1 |
michael@0 | 208 | bne stop_encode_loop |
michael@0 | 209 | |
michael@0 | 210 | str r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 211 | str r5, [r0, #vp8_writer_range] |
michael@0 | 212 | str r3, [r0, #vp8_writer_count] |
michael@0 | 213 | pop {r4-r10, pc} |
michael@0 | 214 | |
michael@0 | 215 | ENDP |
michael@0 | 216 | |
michael@0 | 217 | ; r0 BOOL_CODER *br |
michael@0 | 218 | ; r1 int data |
michael@0 | 219 | ; r2 int bits |
michael@0 | 220 | |vp8_encode_value| PROC |
michael@0 | 221 | push {r4-r12, lr} |
michael@0 | 222 | |
michael@0 | 223 | mov r10, r2 |
michael@0 | 224 | |
michael@0 | 225 | ldr r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 226 | ldr r5, [r0, #vp8_writer_range] |
michael@0 | 227 | ldr r3, [r0, #vp8_writer_count] |
michael@0 | 228 | |
michael@0 | 229 | rsb r4, r10, #32 ; 32-n |
michael@0 | 230 | |
michael@0 | 231 | ; v is kept in r1 during the token pack loop |
michael@0 | 232 | lsl r1, r1, r4 ; r1 = v << 32 - n |
michael@0 | 233 | |
michael@0 | 234 | encode_value_loop |
michael@0 | 235 | sub r7, r5, #1 ; range-1 |
michael@0 | 236 | |
michael@0 | 237 | ; Decisions are made based on the bit value shifted |
michael@0 | 238 | ; off of v, so set a flag here based on this. |
michael@0 | 239 | ; This value is refered to as "bb" |
michael@0 | 240 | lsls r1, r1, #1 ; bit = v >> n |
michael@0 | 241 | mov r4, r7, lsl #7 ; ((range-1) * 128) |
michael@0 | 242 | |
michael@0 | 243 | mov r7, #1 |
michael@0 | 244 | add r4, r7, r4, lsr #8 ; 1 + (((range-1) * 128) >> 8) |
michael@0 | 245 | |
michael@0 | 246 | addcs r2, r2, r4 ; if (bit) lowvalue += split |
michael@0 | 247 | subcs r4, r5, r4 ; if (bit) range = range-split |
michael@0 | 248 | |
michael@0 | 249 | ; Counting the leading zeros is used to normalize range. |
michael@0 | 250 | clz r6, r4 |
michael@0 | 251 | sub r6, r6, #24 ; shift |
michael@0 | 252 | |
michael@0 | 253 | ; Flag is set on the sum of count. This flag is used later |
michael@0 | 254 | ; to determine if count >= 0 |
michael@0 | 255 | adds r3, r3, r6 ; count += shift |
michael@0 | 256 | lsl r5, r4, r6 ; range <<= shift |
michael@0 | 257 | bmi token_count_lt_zero_ev ; if(count >= 0) |
michael@0 | 258 | |
michael@0 | 259 | sub r6, r6, r3 ; offset = shift - count |
michael@0 | 260 | sub r4, r6, #1 ; offset-1 |
michael@0 | 261 | lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) |
michael@0 | 262 | bpl token_high_bit_not_set_ev |
michael@0 | 263 | |
michael@0 | 264 | ldr r4, [r0, #vp8_writer_pos] ; x |
michael@0 | 265 | sub r4, r4, #1 ; x = w->pos-1 |
michael@0 | 266 | b token_zero_while_start_ev |
michael@0 | 267 | token_zero_while_loop_ev |
michael@0 | 268 | mov r9, #0 |
michael@0 | 269 | strb r9, [r7, r4] ; w->buffer[x] =(unsigned char)0 |
michael@0 | 270 | sub r4, r4, #1 ; x-- |
michael@0 | 271 | token_zero_while_start_ev |
michael@0 | 272 | cmp r4, #0 |
michael@0 | 273 | ldrge r7, [r0, #vp8_writer_buffer] |
michael@0 | 274 | ldrb r11, [r7, r4] |
michael@0 | 275 | cmpge r11, #0xff |
michael@0 | 276 | beq token_zero_while_loop_ev |
michael@0 | 277 | |
michael@0 | 278 | ldr r7, [r0, #vp8_writer_buffer] |
michael@0 | 279 | ldrb r9, [r7, r4] ; w->buffer[x] |
michael@0 | 280 | add r9, r9, #1 |
michael@0 | 281 | strb r9, [r7, r4] ; w->buffer[x] + 1 |
michael@0 | 282 | token_high_bit_not_set_ev |
michael@0 | 283 | rsb r4, r6, #24 ; 24-offset |
michael@0 | 284 | ldr r9, [r0, #vp8_writer_buffer] |
michael@0 | 285 | lsr r7, r2, r4 ; lowvalue >> (24-offset) |
michael@0 | 286 | ldr r4, [r0, #vp8_writer_pos] ; w->pos |
michael@0 | 287 | lsl r2, r2, r6 ; lowvalue <<= offset |
michael@0 | 288 | mov r6, r3 ; shift = count |
michael@0 | 289 | add r11, r4, #1 ; w->pos++ |
michael@0 | 290 | bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff |
michael@0 | 291 | str r11, [r0, #vp8_writer_pos] |
michael@0 | 292 | sub r3, r3, #8 ; count -= 8 |
michael@0 | 293 | |
michael@0 | 294 | VALIDATE_POS r9, r11 ; validate_buffer at pos |
michael@0 | 295 | |
michael@0 | 296 | strb r7, [r9, r4] ; w->buffer[w->pos++] |
michael@0 | 297 | |
michael@0 | 298 | token_count_lt_zero_ev |
michael@0 | 299 | lsl r2, r2, r6 ; lowvalue <<= shift |
michael@0 | 300 | |
michael@0 | 301 | subs r10, r10, #1 |
michael@0 | 302 | bne encode_value_loop |
michael@0 | 303 | |
michael@0 | 304 | str r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 305 | str r5, [r0, #vp8_writer_range] |
michael@0 | 306 | str r3, [r0, #vp8_writer_count] |
michael@0 | 307 | pop {r4-r12, pc} |
michael@0 | 308 | ENDP |
michael@0 | 309 | |
michael@0 | 310 | END |