Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /** |
michael@0 | 6 | * A script for GCC-dehydra to analyze the Mozilla codebase and catch |
michael@0 | 7 | * patterns that are incorrect, but which cannot be detected by a compiler. */ |
michael@0 | 8 | |
michael@0 | 9 | /** |
michael@0 | 10 | * Activate Treehydra outparams analysis if running in Treehydra. |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | function treehydra_enabled() { |
michael@0 | 14 | return this.hasOwnProperty('TREE_CODE'); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | sys.include_path.push(options.topsrcdir); |
michael@0 | 18 | |
michael@0 | 19 | include('string-format.js'); |
michael@0 | 20 | |
michael@0 | 21 | let modules = []; |
michael@0 | 22 | |
michael@0 | 23 | function LoadModules(modulelist) |
michael@0 | 24 | { |
michael@0 | 25 | if (modulelist == "") |
michael@0 | 26 | return; |
michael@0 | 27 | |
michael@0 | 28 | let modulenames = modulelist.split(','); |
michael@0 | 29 | for each (let modulename in modulenames) { |
michael@0 | 30 | let module = { __proto__: this }; |
michael@0 | 31 | include(modulename, module); |
michael@0 | 32 | modules.push(module); |
michael@0 | 33 | } |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | LoadModules(options['dehydra-modules']); |
michael@0 | 37 | if (treehydra_enabled()) |
michael@0 | 38 | LoadModules(options['treehydra-modules']); |
michael@0 | 39 | |
michael@0 | 40 | function process_type(c) |
michael@0 | 41 | { |
michael@0 | 42 | for each (let module in modules) |
michael@0 | 43 | if (module.hasOwnProperty('process_type')) |
michael@0 | 44 | module.process_type(c); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function hasAttribute(c, attrname) |
michael@0 | 48 | { |
michael@0 | 49 | var attr; |
michael@0 | 50 | |
michael@0 | 51 | if (c.attributes === undefined) |
michael@0 | 52 | return false; |
michael@0 | 53 | |
michael@0 | 54 | for each (attr in c.attributes) |
michael@0 | 55 | if (attr.name == 'user' && attr.value[0] == attrname) |
michael@0 | 56 | return true; |
michael@0 | 57 | |
michael@0 | 58 | return false; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // This is useful for detecting method overrides |
michael@0 | 62 | function signaturesMatch(m1, m2) |
michael@0 | 63 | { |
michael@0 | 64 | if (m1.shortName != m2.shortName) |
michael@0 | 65 | return false; |
michael@0 | 66 | |
michael@0 | 67 | if ((!!m1.isVirtual) != (!!m2.isVirtual)) |
michael@0 | 68 | return false; |
michael@0 | 69 | |
michael@0 | 70 | if (m1.isStatic != m2.isStatic) |
michael@0 | 71 | return false; |
michael@0 | 72 | |
michael@0 | 73 | let p1 = m1.type.parameters; |
michael@0 | 74 | let p2 = m2.type.parameters; |
michael@0 | 75 | |
michael@0 | 76 | if (p1.length != p2.length) |
michael@0 | 77 | return false; |
michael@0 | 78 | |
michael@0 | 79 | for (let i = 0; i < p1.length; ++i) |
michael@0 | 80 | if (!params_match(p1[i], p2[i])) |
michael@0 | 81 | return false; |
michael@0 | 82 | |
michael@0 | 83 | return true; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function params_match(p1, p2) |
michael@0 | 87 | { |
michael@0 | 88 | [p1, p2] = unwrap_types(p1, p2); |
michael@0 | 89 | |
michael@0 | 90 | for (let i in p1) |
michael@0 | 91 | if (i == "type" && !types_match(p1.type, p2.type)) |
michael@0 | 92 | return false; |
michael@0 | 93 | else if (i != "type" && p1[i] !== p2[i]) |
michael@0 | 94 | return false; |
michael@0 | 95 | |
michael@0 | 96 | for (let i in p2) |
michael@0 | 97 | if (!(i in p1)) |
michael@0 | 98 | return false; |
michael@0 | 99 | |
michael@0 | 100 | return true; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function types_match(t1, t2) |
michael@0 | 104 | { |
michael@0 | 105 | if (!t1 || !t2) |
michael@0 | 106 | return false; |
michael@0 | 107 | |
michael@0 | 108 | [t1, t2] = unwrap_types(t1, t2); |
michael@0 | 109 | |
michael@0 | 110 | return t1 === t2; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | function unwrap_types(t1, t2) |
michael@0 | 114 | { |
michael@0 | 115 | while (t1.variantOf) |
michael@0 | 116 | t1 = t1.variantOf; |
michael@0 | 117 | |
michael@0 | 118 | while (t2.variantOf) |
michael@0 | 119 | t2 = t2.variantOf; |
michael@0 | 120 | |
michael@0 | 121 | return [t1, t2]; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | const forward_functions = [ |
michael@0 | 125 | 'process_type', |
michael@0 | 126 | 'process_tree_type', |
michael@0 | 127 | 'process_decl', |
michael@0 | 128 | 'process_tree_decl', |
michael@0 | 129 | 'process_function', |
michael@0 | 130 | 'process_tree', |
michael@0 | 131 | 'process_cp_pre_genericize', |
michael@0 | 132 | 'input_end' |
michael@0 | 133 | ]; |
michael@0 | 134 | |
michael@0 | 135 | function setup_forwarding(n) |
michael@0 | 136 | { |
michael@0 | 137 | this[n] = function() { |
michael@0 | 138 | for each (let module in modules) { |
michael@0 | 139 | if (module.hasOwnProperty(n)) { |
michael@0 | 140 | module[n].apply(this, arguments); |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | for each (let n in forward_functions) |
michael@0 | 147 | setup_forwarding(n); |