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 |vp8cx_pack_mb_row_tokens_armv5| |
michael@0 | 13 | IMPORT |vp8_validate_buffer_arm| |
michael@0 | 14 | |
michael@0 | 15 | INCLUDE vp8_asm_enc_offsets.asm |
michael@0 | 16 | |
michael@0 | 17 | ARM |
michael@0 | 18 | REQUIRE8 |
michael@0 | 19 | PRESERVE8 |
michael@0 | 20 | |
michael@0 | 21 | AREA |.text|, CODE, READONLY |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | ; macro for validating write buffer position |
michael@0 | 25 | ; needs vp8_writer in r0 |
michael@0 | 26 | ; start shall not be in r1 |
michael@0 | 27 | MACRO |
michael@0 | 28 | VALIDATE_POS $start, $pos |
michael@0 | 29 | push {r0-r3, r12, lr} ; rest of regs are preserved by subroutine call |
michael@0 | 30 | ldr r2, [r0, #vp8_writer_buffer_end] |
michael@0 | 31 | ldr r3, [r0, #vp8_writer_error] |
michael@0 | 32 | mov r1, $pos |
michael@0 | 33 | mov r0, $start |
michael@0 | 34 | bl vp8_validate_buffer_arm |
michael@0 | 35 | pop {r0-r3, r12, lr} |
michael@0 | 36 | MEND |
michael@0 | 37 | |
michael@0 | 38 | ; r0 VP8_COMP *cpi |
michael@0 | 39 | ; r1 vp8_writer *w |
michael@0 | 40 | ; r2 vp8_coef_encodings |
michael@0 | 41 | ; r3 vp8_extra_bits |
michael@0 | 42 | ; s0 vp8_coef_tree |
michael@0 | 43 | |
michael@0 | 44 | |vp8cx_pack_mb_row_tokens_armv5| PROC |
michael@0 | 45 | push {r4-r12, lr} |
michael@0 | 46 | sub sp, sp, #24 |
michael@0 | 47 | |
michael@0 | 48 | ; Compute address of cpi->common.mb_rows |
michael@0 | 49 | ldr r4, _VP8_COMP_common_ |
michael@0 | 50 | ldr r6, _VP8_COMMON_MBrows_ |
michael@0 | 51 | add r4, r0, r4 |
michael@0 | 52 | |
michael@0 | 53 | ldr r5, [r4, r6] ; load up mb_rows |
michael@0 | 54 | |
michael@0 | 55 | str r2, [sp, #20] ; save vp8_coef_encodings |
michael@0 | 56 | str r5, [sp, #12] ; save mb_rows |
michael@0 | 57 | str r3, [sp, #8] ; save vp8_extra_bits |
michael@0 | 58 | |
michael@0 | 59 | ldr r4, _VP8_COMP_tplist_ |
michael@0 | 60 | add r4, r0, r4 |
michael@0 | 61 | ldr r7, [r4, #0] ; dereference cpi->tp_list |
michael@0 | 62 | |
michael@0 | 63 | mov r0, r1 ; keep same as other loops |
michael@0 | 64 | |
michael@0 | 65 | ldr r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 66 | ldr r5, [r0, #vp8_writer_range] |
michael@0 | 67 | ldr r3, [r0, #vp8_writer_count] |
michael@0 | 68 | |
michael@0 | 69 | mb_row_loop |
michael@0 | 70 | |
michael@0 | 71 | ldr r1, [r7, #tokenlist_start] |
michael@0 | 72 | ldr r9, [r7, #tokenlist_stop] |
michael@0 | 73 | str r9, [sp, #0] ; save stop for later comparison |
michael@0 | 74 | str r7, [sp, #16] ; tokenlist address for next time |
michael@0 | 75 | |
michael@0 | 76 | b check_p_lt_stop |
michael@0 | 77 | |
michael@0 | 78 | ; actuall work gets done here! |
michael@0 | 79 | |
michael@0 | 80 | while_p_lt_stop |
michael@0 | 81 | ldrb r6, [r1, #tokenextra_token] ; t |
michael@0 | 82 | ldr r4, [sp, #20] ; vp8_coef_encodings |
michael@0 | 83 | mov lr, #0 |
michael@0 | 84 | add r4, r4, r6, lsl #3 ; a = vp8_coef_encodings + t |
michael@0 | 85 | ldr r9, [r1, #tokenextra_context_tree] ; pp |
michael@0 | 86 | |
michael@0 | 87 | ldrb r7, [r1, #tokenextra_skip_eob_node] |
michael@0 | 88 | |
michael@0 | 89 | ldr r6, [r4, #vp8_token_value] ; v |
michael@0 | 90 | ldr r8, [r4, #vp8_token_len] ; n |
michael@0 | 91 | |
michael@0 | 92 | ; vp8 specific skip_eob_node |
michael@0 | 93 | cmp r7, #0 |
michael@0 | 94 | movne lr, #2 ; i = 2 |
michael@0 | 95 | subne r8, r8, #1 ; --n |
michael@0 | 96 | |
michael@0 | 97 | rsb r4, r8, #32 ; 32-n |
michael@0 | 98 | ldr r10, [sp, #64] ; vp8_coef_tree |
michael@0 | 99 | |
michael@0 | 100 | ; v is kept in r12 during the token pack loop |
michael@0 | 101 | lsl r12, r6, r4 ; r12 = v << 32 - n |
michael@0 | 102 | |
michael@0 | 103 | ; loop start |
michael@0 | 104 | token_loop |
michael@0 | 105 | ldrb r4, [r9, lr, asr #1] ; pp [i>>1] |
michael@0 | 106 | sub r7, r5, #1 ; range-1 |
michael@0 | 107 | |
michael@0 | 108 | ; Decisions are made based on the bit value shifted |
michael@0 | 109 | ; off of v, so set a flag here based on this. |
michael@0 | 110 | ; This value is refered to as "bb" |
michael@0 | 111 | lsls r12, r12, #1 ; bb = v >> n |
michael@0 | 112 | mul r6, r4, r7 ; ((range-1) * pp[i>>1])) |
michael@0 | 113 | |
michael@0 | 114 | ; bb can only be 0 or 1. So only execute this statement |
michael@0 | 115 | ; if bb == 1, otherwise it will act like i + 0 |
michael@0 | 116 | addcs lr, lr, #1 ; i + bb |
michael@0 | 117 | |
michael@0 | 118 | mov r7, #1 |
michael@0 | 119 | ldrsb lr, [r10, lr] ; i = vp8_coef_tree[i+bb] |
michael@0 | 120 | add r4, r7, r6, lsr #8 ; 1 + (((range-1) * pp[i>>1]) >> 8) |
michael@0 | 121 | |
michael@0 | 122 | addcs r2, r2, r4 ; if (bb) lowvalue += split |
michael@0 | 123 | subcs r4, r5, r4 ; if (bb) range = range-split |
michael@0 | 124 | |
michael@0 | 125 | ; Counting the leading zeros is used to normalize range. |
michael@0 | 126 | clz r6, r4 |
michael@0 | 127 | sub r6, r6, #24 ; shift |
michael@0 | 128 | |
michael@0 | 129 | ; Flag is set on the sum of count. This flag is used later |
michael@0 | 130 | ; to determine if count >= 0 |
michael@0 | 131 | adds r3, r3, r6 ; count += shift |
michael@0 | 132 | lsl r5, r4, r6 ; range <<= shift |
michael@0 | 133 | bmi token_count_lt_zero ; if(count >= 0) |
michael@0 | 134 | |
michael@0 | 135 | sub r6, r6, r3 ; offset = shift - count |
michael@0 | 136 | sub r4, r6, #1 ; offset-1 |
michael@0 | 137 | lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) |
michael@0 | 138 | bpl token_high_bit_not_set |
michael@0 | 139 | |
michael@0 | 140 | ldr r4, [r0, #vp8_writer_pos] ; x |
michael@0 | 141 | sub r4, r4, #1 ; x = w->pos-1 |
michael@0 | 142 | b token_zero_while_start |
michael@0 | 143 | token_zero_while_loop |
michael@0 | 144 | mov r10, #0 |
michael@0 | 145 | strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 |
michael@0 | 146 | sub r4, r4, #1 ; x-- |
michael@0 | 147 | token_zero_while_start |
michael@0 | 148 | cmp r4, #0 |
michael@0 | 149 | ldrge r7, [r0, #vp8_writer_buffer] |
michael@0 | 150 | ldrb r11, [r7, r4] |
michael@0 | 151 | cmpge r11, #0xff |
michael@0 | 152 | beq token_zero_while_loop |
michael@0 | 153 | |
michael@0 | 154 | ldr r7, [r0, #vp8_writer_buffer] |
michael@0 | 155 | ldrb r10, [r7, r4] ; w->buffer[x] |
michael@0 | 156 | add r10, r10, #1 |
michael@0 | 157 | strb r10, [r7, r4] ; w->buffer[x] + 1 |
michael@0 | 158 | token_high_bit_not_set |
michael@0 | 159 | rsb r4, r6, #24 ; 24-offset |
michael@0 | 160 | ldr r10, [r0, #vp8_writer_buffer] |
michael@0 | 161 | lsr r7, r2, r4 ; lowvalue >> (24-offset) |
michael@0 | 162 | ldr r4, [r0, #vp8_writer_pos] ; w->pos |
michael@0 | 163 | lsl r2, r2, r6 ; lowvalue <<= offset |
michael@0 | 164 | mov r6, r3 ; shift = count |
michael@0 | 165 | add r11, r4, #1 ; w->pos++ |
michael@0 | 166 | bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff |
michael@0 | 167 | str r11, [r0, #vp8_writer_pos] |
michael@0 | 168 | sub r3, r3, #8 ; count -= 8 |
michael@0 | 169 | |
michael@0 | 170 | VALIDATE_POS r10, r11 ; validate_buffer at pos |
michael@0 | 171 | |
michael@0 | 172 | strb r7, [r10, r4] ; w->buffer[w->pos++] |
michael@0 | 173 | |
michael@0 | 174 | ; r10 is used earlier in the loop, but r10 is used as |
michael@0 | 175 | ; temp variable here. So after r10 is used, reload |
michael@0 | 176 | ; vp8_coef_tree_dcd into r10 |
michael@0 | 177 | ldr r10, [sp, #64] ; vp8_coef_tree |
michael@0 | 178 | |
michael@0 | 179 | token_count_lt_zero |
michael@0 | 180 | lsl r2, r2, r6 ; lowvalue <<= shift |
michael@0 | 181 | |
michael@0 | 182 | subs r8, r8, #1 ; --n |
michael@0 | 183 | bne token_loop |
michael@0 | 184 | |
michael@0 | 185 | ldrb r6, [r1, #tokenextra_token] ; t |
michael@0 | 186 | ldr r7, [sp, #8] ; vp8_extra_bits |
michael@0 | 187 | ; Add t * sizeof (vp8_extra_bit_struct) to get the desired |
michael@0 | 188 | ; element. Here vp8_extra_bit_struct == 16 |
michael@0 | 189 | add r12, r7, r6, lsl #4 ; b = vp8_extra_bits + t |
michael@0 | 190 | |
michael@0 | 191 | ldr r4, [r12, #vp8_extra_bit_struct_base_val] |
michael@0 | 192 | cmp r4, #0 |
michael@0 | 193 | beq skip_extra_bits |
michael@0 | 194 | |
michael@0 | 195 | ; if( b->base_val) |
michael@0 | 196 | ldr r8, [r12, #vp8_extra_bit_struct_len] ; L |
michael@0 | 197 | ldrsh lr, [r1, #tokenextra_extra] ; e = p->Extra |
michael@0 | 198 | cmp r8, #0 ; if( L) |
michael@0 | 199 | beq no_extra_bits |
michael@0 | 200 | |
michael@0 | 201 | ldr r9, [r12, #vp8_extra_bit_struct_prob] |
michael@0 | 202 | asr r7, lr, #1 ; v=e>>1 |
michael@0 | 203 | |
michael@0 | 204 | ldr r10, [r12, #vp8_extra_bit_struct_tree] |
michael@0 | 205 | str r10, [sp, #4] ; b->tree |
michael@0 | 206 | |
michael@0 | 207 | rsb r4, r8, #32 |
michael@0 | 208 | lsl r12, r7, r4 |
michael@0 | 209 | |
michael@0 | 210 | mov lr, #0 ; i = 0 |
michael@0 | 211 | |
michael@0 | 212 | extra_bits_loop |
michael@0 | 213 | ldrb r4, [r9, lr, asr #1] ; pp[i>>1] |
michael@0 | 214 | sub r7, r5, #1 ; range-1 |
michael@0 | 215 | lsls r12, r12, #1 ; v >> n |
michael@0 | 216 | mul r6, r4, r7 ; (range-1) * pp[i>>1] |
michael@0 | 217 | addcs lr, lr, #1 ; i + bb |
michael@0 | 218 | |
michael@0 | 219 | mov r7, #1 |
michael@0 | 220 | ldrsb lr, [r10, lr] ; i = b->tree[i+bb] |
michael@0 | 221 | add r4, r7, r6, lsr #8 ; split = 1 + (((range-1) * pp[i>>1]) >> 8) |
michael@0 | 222 | |
michael@0 | 223 | addcs r2, r2, r4 ; if (bb) lowvalue += split |
michael@0 | 224 | subcs r4, r5, r4 ; if (bb) range = range-split |
michael@0 | 225 | |
michael@0 | 226 | clz r6, r4 |
michael@0 | 227 | sub r6, r6, #24 |
michael@0 | 228 | |
michael@0 | 229 | adds r3, r3, r6 ; count += shift |
michael@0 | 230 | lsl r5, r4, r6 ; range <<= shift |
michael@0 | 231 | bmi extra_count_lt_zero ; if(count >= 0) |
michael@0 | 232 | |
michael@0 | 233 | sub r6, r6, r3 ; offset= shift - count |
michael@0 | 234 | sub r4, r6, #1 ; offset-1 |
michael@0 | 235 | lsls r4, r2, r4 ; if((lowvalue<<(offset-1)) & 0x80000000 ) |
michael@0 | 236 | bpl extra_high_bit_not_set |
michael@0 | 237 | |
michael@0 | 238 | ldr r4, [r0, #vp8_writer_pos] ; x |
michael@0 | 239 | sub r4, r4, #1 ; x = w->pos - 1 |
michael@0 | 240 | b extra_zero_while_start |
michael@0 | 241 | extra_zero_while_loop |
michael@0 | 242 | mov r10, #0 |
michael@0 | 243 | strb r10, [r7, r4] ; w->buffer[x] =(unsigned char)0 |
michael@0 | 244 | sub r4, r4, #1 ; x-- |
michael@0 | 245 | extra_zero_while_start |
michael@0 | 246 | cmp r4, #0 |
michael@0 | 247 | ldrge r7, [r0, #vp8_writer_buffer] |
michael@0 | 248 | ldrb r11, [r7, r4] |
michael@0 | 249 | cmpge r11, #0xff |
michael@0 | 250 | beq extra_zero_while_loop |
michael@0 | 251 | |
michael@0 | 252 | ldr r7, [r0, #vp8_writer_buffer] |
michael@0 | 253 | ldrb r10, [r7, r4] |
michael@0 | 254 | add r10, r10, #1 |
michael@0 | 255 | strb r10, [r7, r4] |
michael@0 | 256 | extra_high_bit_not_set |
michael@0 | 257 | rsb r4, r6, #24 ; 24-offset |
michael@0 | 258 | ldr r10, [r0, #vp8_writer_buffer] |
michael@0 | 259 | lsr r7, r2, r4 ; lowvalue >> (24-offset) |
michael@0 | 260 | ldr r4, [r0, #vp8_writer_pos] |
michael@0 | 261 | lsl r2, r2, r6 ; lowvalue <<= offset |
michael@0 | 262 | mov r6, r3 ; shift = count |
michael@0 | 263 | add r11, r4, #1 ; w->pos++ |
michael@0 | 264 | bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff |
michael@0 | 265 | str r11, [r0, #vp8_writer_pos] |
michael@0 | 266 | sub r3, r3, #8 ; count -= 8 |
michael@0 | 267 | |
michael@0 | 268 | VALIDATE_POS r10, r11 ; validate_buffer at pos |
michael@0 | 269 | |
michael@0 | 270 | strb r7, [r10, r4] ; w->buffer[w->pos++]=(lowvalue >> (24-offset)) |
michael@0 | 271 | ldr r10, [sp, #4] ; b->tree |
michael@0 | 272 | extra_count_lt_zero |
michael@0 | 273 | lsl r2, r2, r6 |
michael@0 | 274 | |
michael@0 | 275 | subs r8, r8, #1 ; --n |
michael@0 | 276 | bne extra_bits_loop ; while (n) |
michael@0 | 277 | |
michael@0 | 278 | no_extra_bits |
michael@0 | 279 | ldr lr, [r1, #4] ; e = p->Extra |
michael@0 | 280 | add r4, r5, #1 ; range + 1 |
michael@0 | 281 | tst lr, #1 |
michael@0 | 282 | lsr r4, r4, #1 ; split = (range + 1) >> 1 |
michael@0 | 283 | addne r2, r2, r4 ; lowvalue += split |
michael@0 | 284 | subne r4, r5, r4 ; range = range-split |
michael@0 | 285 | tst r2, #0x80000000 ; lowvalue & 0x80000000 |
michael@0 | 286 | lsl r5, r4, #1 ; range <<= 1 |
michael@0 | 287 | beq end_high_bit_not_set |
michael@0 | 288 | |
michael@0 | 289 | ldr r4, [r0, #vp8_writer_pos] |
michael@0 | 290 | mov r7, #0 |
michael@0 | 291 | sub r4, r4, #1 |
michael@0 | 292 | b end_zero_while_start |
michael@0 | 293 | end_zero_while_loop |
michael@0 | 294 | strb r7, [r6, r4] |
michael@0 | 295 | sub r4, r4, #1 ; x-- |
michael@0 | 296 | end_zero_while_start |
michael@0 | 297 | cmp r4, #0 |
michael@0 | 298 | ldrge r6, [r0, #vp8_writer_buffer] |
michael@0 | 299 | ldrb r12, [r6, r4] |
michael@0 | 300 | cmpge r12, #0xff |
michael@0 | 301 | beq end_zero_while_loop |
michael@0 | 302 | |
michael@0 | 303 | ldr r6, [r0, #vp8_writer_buffer] |
michael@0 | 304 | ldrb r7, [r6, r4] |
michael@0 | 305 | add r7, r7, #1 |
michael@0 | 306 | strb r7, [r6, r4] |
michael@0 | 307 | end_high_bit_not_set |
michael@0 | 308 | adds r3, r3, #1 ; ++count |
michael@0 | 309 | lsl r2, r2, #1 ; lowvalue <<= 1 |
michael@0 | 310 | bne end_count_zero |
michael@0 | 311 | |
michael@0 | 312 | ldr r4, [r0, #vp8_writer_pos] |
michael@0 | 313 | mvn r3, #7 |
michael@0 | 314 | ldr r7, [r0, #vp8_writer_buffer] |
michael@0 | 315 | lsr r6, r2, #24 ; lowvalue >> 24 |
michael@0 | 316 | add r12, r4, #1 ; w->pos++ |
michael@0 | 317 | bic r2, r2, #0xff000000 ; lowvalue &= 0xffffff |
michael@0 | 318 | str r12, [r0, #vp8_writer_pos] |
michael@0 | 319 | |
michael@0 | 320 | VALIDATE_POS r7, r12 ; validate_buffer at pos |
michael@0 | 321 | |
michael@0 | 322 | strb r6, [r7, r4] |
michael@0 | 323 | end_count_zero |
michael@0 | 324 | skip_extra_bits |
michael@0 | 325 | add r1, r1, #TOKENEXTRA_SZ ; ++p |
michael@0 | 326 | check_p_lt_stop |
michael@0 | 327 | ldr r4, [sp, #0] ; stop |
michael@0 | 328 | cmp r1, r4 ; while( p < stop) |
michael@0 | 329 | bcc while_p_lt_stop |
michael@0 | 330 | |
michael@0 | 331 | ldr r6, [sp, #12] ; mb_rows |
michael@0 | 332 | ldr r7, [sp, #16] ; tokenlist address |
michael@0 | 333 | subs r6, r6, #1 |
michael@0 | 334 | add r7, r7, #TOKENLIST_SZ ; next element in the array |
michael@0 | 335 | str r6, [sp, #12] |
michael@0 | 336 | bne mb_row_loop |
michael@0 | 337 | |
michael@0 | 338 | str r2, [r0, #vp8_writer_lowvalue] |
michael@0 | 339 | str r5, [r0, #vp8_writer_range] |
michael@0 | 340 | str r3, [r0, #vp8_writer_count] |
michael@0 | 341 | add sp, sp, #24 |
michael@0 | 342 | pop {r4-r12, pc} |
michael@0 | 343 | ENDP |
michael@0 | 344 | |
michael@0 | 345 | _VP8_COMP_common_ |
michael@0 | 346 | DCD vp8_comp_common |
michael@0 | 347 | _VP8_COMMON_MBrows_ |
michael@0 | 348 | DCD vp8_common_mb_rows |
michael@0 | 349 | _VP8_COMP_tplist_ |
michael@0 | 350 | DCD vp8_comp_tplist |
michael@0 | 351 | |
michael@0 | 352 | END |