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 | /* \file |
michael@0 | 13 | * \brief Provides portable memory access primitives |
michael@0 | 14 | * |
michael@0 | 15 | * This function provides portable primitives for getting and setting of |
michael@0 | 16 | * signed and unsigned integers in 16, 24, and 32 bit sizes. The operations |
michael@0 | 17 | * can be performed on unaligned data regardless of hardware support for |
michael@0 | 18 | * unaligned accesses. |
michael@0 | 19 | * |
michael@0 | 20 | * The type used to pass the integral values may be changed by defining |
michael@0 | 21 | * MEM_VALUE_T with the appropriate type. The type given must be an integral |
michael@0 | 22 | * numeric type. |
michael@0 | 23 | * |
michael@0 | 24 | * The actual functions instantiated have the MEM_VALUE_T type name pasted |
michael@0 | 25 | * on to the symbol name. This allows the developer to instantiate these |
michael@0 | 26 | * operations for multiple types within the same translation unit. This is |
michael@0 | 27 | * of somewhat questionable utility, but the capability exists nonetheless. |
michael@0 | 28 | * Users not making use of this functionality should call the functions |
michael@0 | 29 | * without the type name appended, and the preprocessor will take care of |
michael@0 | 30 | * it. |
michael@0 | 31 | * |
michael@0 | 32 | * NOTE: This code is not supported on platforms where char > 1 octet ATM. |
michael@0 | 33 | */ |
michael@0 | 34 | |
michael@0 | 35 | #ifndef MAU_T |
michael@0 | 36 | /* Minimum Access Unit for this target */ |
michael@0 | 37 | #define MAU_T unsigned char |
michael@0 | 38 | #endif |
michael@0 | 39 | |
michael@0 | 40 | #ifndef MEM_VALUE_T |
michael@0 | 41 | #define MEM_VALUE_T int |
michael@0 | 42 | #endif |
michael@0 | 43 | |
michael@0 | 44 | #undef MEM_VALUE_T_SZ_BITS |
michael@0 | 45 | #define MEM_VALUE_T_SZ_BITS (sizeof(MEM_VALUE_T) << 3) |
michael@0 | 46 | |
michael@0 | 47 | #undef mem_ops_wrap_symbol |
michael@0 | 48 | #define mem_ops_wrap_symbol(fn) mem_ops_wrap_symbol2(fn, MEM_VALUE_T) |
michael@0 | 49 | #undef mem_ops_wrap_symbol2 |
michael@0 | 50 | #define mem_ops_wrap_symbol2(fn,typ) mem_ops_wrap_symbol3(fn,typ) |
michael@0 | 51 | #undef mem_ops_wrap_symbol3 |
michael@0 | 52 | #define mem_ops_wrap_symbol3(fn,typ) fn##_as_##typ |
michael@0 | 53 | |
michael@0 | 54 | /* |
michael@0 | 55 | * Include aligned access routines |
michael@0 | 56 | */ |
michael@0 | 57 | #define INCLUDED_BY_MEM_OPS_H |
michael@0 | 58 | #include "mem_ops_aligned.h" |
michael@0 | 59 | #undef INCLUDED_BY_MEM_OPS_H |
michael@0 | 60 | |
michael@0 | 61 | #undef mem_get_be16 |
michael@0 | 62 | #define mem_get_be16 mem_ops_wrap_symbol(mem_get_be16) |
michael@0 | 63 | static unsigned MEM_VALUE_T mem_get_be16(const void *vmem) { |
michael@0 | 64 | unsigned MEM_VALUE_T val; |
michael@0 | 65 | const MAU_T *mem = (const MAU_T *)vmem; |
michael@0 | 66 | |
michael@0 | 67 | val = mem[0] << 8; |
michael@0 | 68 | val |= mem[1]; |
michael@0 | 69 | return val; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | #undef mem_get_be24 |
michael@0 | 73 | #define mem_get_be24 mem_ops_wrap_symbol(mem_get_be24) |
michael@0 | 74 | static unsigned MEM_VALUE_T mem_get_be24(const void *vmem) { |
michael@0 | 75 | unsigned MEM_VALUE_T val; |
michael@0 | 76 | const MAU_T *mem = (const MAU_T *)vmem; |
michael@0 | 77 | |
michael@0 | 78 | val = mem[0] << 16; |
michael@0 | 79 | val |= mem[1] << 8; |
michael@0 | 80 | val |= mem[2]; |
michael@0 | 81 | return val; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | #undef mem_get_be32 |
michael@0 | 85 | #define mem_get_be32 mem_ops_wrap_symbol(mem_get_be32) |
michael@0 | 86 | static unsigned MEM_VALUE_T mem_get_be32(const void *vmem) { |
michael@0 | 87 | unsigned MEM_VALUE_T val; |
michael@0 | 88 | const MAU_T *mem = (const MAU_T *)vmem; |
michael@0 | 89 | |
michael@0 | 90 | val = mem[0] << 24; |
michael@0 | 91 | val |= mem[1] << 16; |
michael@0 | 92 | val |= mem[2] << 8; |
michael@0 | 93 | val |= mem[3]; |
michael@0 | 94 | return val; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | #undef mem_get_le16 |
michael@0 | 98 | #define mem_get_le16 mem_ops_wrap_symbol(mem_get_le16) |
michael@0 | 99 | static unsigned MEM_VALUE_T mem_get_le16(const void *vmem) { |
michael@0 | 100 | unsigned MEM_VALUE_T val; |
michael@0 | 101 | const MAU_T *mem = (const MAU_T *)vmem; |
michael@0 | 102 | |
michael@0 | 103 | val = mem[1] << 8; |
michael@0 | 104 | val |= mem[0]; |
michael@0 | 105 | return val; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | #undef mem_get_le24 |
michael@0 | 109 | #define mem_get_le24 mem_ops_wrap_symbol(mem_get_le24) |
michael@0 | 110 | static unsigned MEM_VALUE_T mem_get_le24(const void *vmem) { |
michael@0 | 111 | unsigned MEM_VALUE_T val; |
michael@0 | 112 | const MAU_T *mem = (const MAU_T *)vmem; |
michael@0 | 113 | |
michael@0 | 114 | val = mem[2] << 16; |
michael@0 | 115 | val |= mem[1] << 8; |
michael@0 | 116 | val |= mem[0]; |
michael@0 | 117 | return val; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | #undef mem_get_le32 |
michael@0 | 121 | #define mem_get_le32 mem_ops_wrap_symbol(mem_get_le32) |
michael@0 | 122 | static unsigned MEM_VALUE_T mem_get_le32(const void *vmem) { |
michael@0 | 123 | unsigned MEM_VALUE_T val; |
michael@0 | 124 | const MAU_T *mem = (const MAU_T *)vmem; |
michael@0 | 125 | |
michael@0 | 126 | val = mem[3] << 24; |
michael@0 | 127 | val |= mem[2] << 16; |
michael@0 | 128 | val |= mem[1] << 8; |
michael@0 | 129 | val |= mem[0]; |
michael@0 | 130 | return val; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | #define mem_get_s_generic(end,sz) \ |
michael@0 | 134 | static signed MEM_VALUE_T mem_get_s##end##sz(const void *vmem) {\ |
michael@0 | 135 | const MAU_T *mem = (const MAU_T*)vmem;\ |
michael@0 | 136 | signed MEM_VALUE_T val = mem_get_##end##sz(mem);\ |
michael@0 | 137 | return (val << (MEM_VALUE_T_SZ_BITS - sz)) >> (MEM_VALUE_T_SZ_BITS - sz);\ |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | #undef mem_get_sbe16 |
michael@0 | 141 | #define mem_get_sbe16 mem_ops_wrap_symbol(mem_get_sbe16) |
michael@0 | 142 | mem_get_s_generic(be, 16) |
michael@0 | 143 | |
michael@0 | 144 | #undef mem_get_sbe24 |
michael@0 | 145 | #define mem_get_sbe24 mem_ops_wrap_symbol(mem_get_sbe24) |
michael@0 | 146 | mem_get_s_generic(be, 24) |
michael@0 | 147 | |
michael@0 | 148 | #undef mem_get_sbe32 |
michael@0 | 149 | #define mem_get_sbe32 mem_ops_wrap_symbol(mem_get_sbe32) |
michael@0 | 150 | mem_get_s_generic(be, 32) |
michael@0 | 151 | |
michael@0 | 152 | #undef mem_get_sle16 |
michael@0 | 153 | #define mem_get_sle16 mem_ops_wrap_symbol(mem_get_sle16) |
michael@0 | 154 | mem_get_s_generic(le, 16) |
michael@0 | 155 | |
michael@0 | 156 | #undef mem_get_sle24 |
michael@0 | 157 | #define mem_get_sle24 mem_ops_wrap_symbol(mem_get_sle24) |
michael@0 | 158 | mem_get_s_generic(le, 24) |
michael@0 | 159 | |
michael@0 | 160 | #undef mem_get_sle32 |
michael@0 | 161 | #define mem_get_sle32 mem_ops_wrap_symbol(mem_get_sle32) |
michael@0 | 162 | mem_get_s_generic(le, 32) |
michael@0 | 163 | |
michael@0 | 164 | #undef mem_put_be16 |
michael@0 | 165 | #define mem_put_be16 mem_ops_wrap_symbol(mem_put_be16) |
michael@0 | 166 | static void mem_put_be16(void *vmem, MEM_VALUE_T val) { |
michael@0 | 167 | MAU_T *mem = (MAU_T *)vmem; |
michael@0 | 168 | |
michael@0 | 169 | mem[0] = (val >> 8) & 0xff; |
michael@0 | 170 | mem[1] = (val >> 0) & 0xff; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | #undef mem_put_be24 |
michael@0 | 174 | #define mem_put_be24 mem_ops_wrap_symbol(mem_put_be24) |
michael@0 | 175 | static void mem_put_be24(void *vmem, MEM_VALUE_T val) { |
michael@0 | 176 | MAU_T *mem = (MAU_T *)vmem; |
michael@0 | 177 | |
michael@0 | 178 | mem[0] = (val >> 16) & 0xff; |
michael@0 | 179 | mem[1] = (val >> 8) & 0xff; |
michael@0 | 180 | mem[2] = (val >> 0) & 0xff; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | #undef mem_put_be32 |
michael@0 | 184 | #define mem_put_be32 mem_ops_wrap_symbol(mem_put_be32) |
michael@0 | 185 | static void mem_put_be32(void *vmem, MEM_VALUE_T val) { |
michael@0 | 186 | MAU_T *mem = (MAU_T *)vmem; |
michael@0 | 187 | |
michael@0 | 188 | mem[0] = (val >> 24) & 0xff; |
michael@0 | 189 | mem[1] = (val >> 16) & 0xff; |
michael@0 | 190 | mem[2] = (val >> 8) & 0xff; |
michael@0 | 191 | mem[3] = (val >> 0) & 0xff; |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | #undef mem_put_le16 |
michael@0 | 195 | #define mem_put_le16 mem_ops_wrap_symbol(mem_put_le16) |
michael@0 | 196 | static void mem_put_le16(void *vmem, MEM_VALUE_T val) { |
michael@0 | 197 | MAU_T *mem = (MAU_T *)vmem; |
michael@0 | 198 | |
michael@0 | 199 | mem[0] = (val >> 0) & 0xff; |
michael@0 | 200 | mem[1] = (val >> 8) & 0xff; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | #undef mem_put_le24 |
michael@0 | 204 | #define mem_put_le24 mem_ops_wrap_symbol(mem_put_le24) |
michael@0 | 205 | static void mem_put_le24(void *vmem, MEM_VALUE_T val) { |
michael@0 | 206 | MAU_T *mem = (MAU_T *)vmem; |
michael@0 | 207 | |
michael@0 | 208 | mem[0] = (val >> 0) & 0xff; |
michael@0 | 209 | mem[1] = (val >> 8) & 0xff; |
michael@0 | 210 | mem[2] = (val >> 16) & 0xff; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | #undef mem_put_le32 |
michael@0 | 214 | #define mem_put_le32 mem_ops_wrap_symbol(mem_put_le32) |
michael@0 | 215 | static void mem_put_le32(void *vmem, MEM_VALUE_T val) { |
michael@0 | 216 | MAU_T *mem = (MAU_T *)vmem; |
michael@0 | 217 | |
michael@0 | 218 | mem[0] = (val >> 0) & 0xff; |
michael@0 | 219 | mem[1] = (val >> 8) & 0xff; |
michael@0 | 220 | mem[2] = (val >> 16) & 0xff; |
michael@0 | 221 | mem[3] = (val >> 24) & 0xff; |
michael@0 | 222 | } |