Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // Copyright (c) 2010, Google Inc. |
michael@0 | 2 | // All rights reserved. |
michael@0 | 3 | // |
michael@0 | 4 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 5 | // modification, are permitted provided that the following conditions are |
michael@0 | 6 | // met: |
michael@0 | 7 | // |
michael@0 | 8 | // * Redistributions of source code must retain the above copyright |
michael@0 | 9 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 10 | // * Redistributions in binary form must reproduce the above |
michael@0 | 11 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 12 | // in the documentation and/or other materials provided with the |
michael@0 | 13 | // distribution. |
michael@0 | 14 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 15 | // contributors may be used to endorse or promote products derived from |
michael@0 | 16 | // this software without specific prior written permission. |
michael@0 | 17 | // |
michael@0 | 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 29 | // |
michael@0 | 30 | // module_serializer.cc: ModuleSerializer implementation. |
michael@0 | 31 | // |
michael@0 | 32 | // See module_serializer.h for documentation. |
michael@0 | 33 | // |
michael@0 | 34 | // Author: Siyang Xie (lambxsy@google.com) |
michael@0 | 35 | |
michael@0 | 36 | #include "processor/module_serializer.h" |
michael@0 | 37 | |
michael@0 | 38 | #include <map> |
michael@0 | 39 | #include <string> |
michael@0 | 40 | |
michael@0 | 41 | #include "processor/basic_code_module.h" |
michael@0 | 42 | #include "processor/logging.h" |
michael@0 | 43 | |
michael@0 | 44 | namespace google_breakpad { |
michael@0 | 45 | |
michael@0 | 46 | // Definition of static member variable in SimplerSerializer<Funcion>, which |
michael@0 | 47 | // is declared in file "simple_serializer-inl.h" |
michael@0 | 48 | RangeMapSerializer< MemAddr, linked_ptr<BasicSourceLineResolver::Line> > |
michael@0 | 49 | SimpleSerializer<BasicSourceLineResolver::Function>::range_map_serializer_; |
michael@0 | 50 | |
michael@0 | 51 | size_t ModuleSerializer::SizeOf(const BasicSourceLineResolver::Module &module) { |
michael@0 | 52 | size_t total_size_alloc_ = 0; |
michael@0 | 53 | |
michael@0 | 54 | // Compute memory size for each map component in Module class. |
michael@0 | 55 | int map_index = 0; |
michael@0 | 56 | map_sizes_[map_index++] = files_serializer_.SizeOf(module.files_); |
michael@0 | 57 | map_sizes_[map_index++] = functions_serializer_.SizeOf(module.functions_); |
michael@0 | 58 | map_sizes_[map_index++] = pubsym_serializer_.SizeOf(module.public_symbols_); |
michael@0 | 59 | for (int i = 0; i < WindowsFrameInfo::STACK_INFO_LAST; ++i) |
michael@0 | 60 | map_sizes_[map_index++] = |
michael@0 | 61 | wfi_serializer_.SizeOf(&(module.windows_frame_info_[i])); |
michael@0 | 62 | map_sizes_[map_index++] = cfi_init_rules_serializer_.SizeOf( |
michael@0 | 63 | module.cfi_initial_rules_); |
michael@0 | 64 | map_sizes_[map_index++] = cfi_delta_rules_serializer_.SizeOf( |
michael@0 | 65 | module.cfi_delta_rules_); |
michael@0 | 66 | |
michael@0 | 67 | // Header size. |
michael@0 | 68 | total_size_alloc_ = kNumberMaps_ * sizeof(uint32_t); |
michael@0 | 69 | |
michael@0 | 70 | for (int i = 0; i < kNumberMaps_; ++i) |
michael@0 | 71 | total_size_alloc_ += map_sizes_[i]; |
michael@0 | 72 | |
michael@0 | 73 | // Extra one byte for null terminator for C-string copy safety. |
michael@0 | 74 | ++total_size_alloc_; |
michael@0 | 75 | |
michael@0 | 76 | return total_size_alloc_; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | char *ModuleSerializer::Write(const BasicSourceLineResolver::Module &module, |
michael@0 | 80 | char *dest) { |
michael@0 | 81 | // Write header. |
michael@0 | 82 | memcpy(dest, map_sizes_, kNumberMaps_ * sizeof(uint32_t)); |
michael@0 | 83 | dest += kNumberMaps_ * sizeof(uint32_t); |
michael@0 | 84 | // Write each map. |
michael@0 | 85 | dest = files_serializer_.Write(module.files_, dest); |
michael@0 | 86 | dest = functions_serializer_.Write(module.functions_, dest); |
michael@0 | 87 | dest = pubsym_serializer_.Write(module.public_symbols_, dest); |
michael@0 | 88 | for (int i = 0; i < WindowsFrameInfo::STACK_INFO_LAST; ++i) |
michael@0 | 89 | dest = wfi_serializer_.Write(&(module.windows_frame_info_[i]), dest); |
michael@0 | 90 | dest = cfi_init_rules_serializer_.Write(module.cfi_initial_rules_, dest); |
michael@0 | 91 | dest = cfi_delta_rules_serializer_.Write(module.cfi_delta_rules_, dest); |
michael@0 | 92 | // Write a null terminator. |
michael@0 | 93 | dest = SimpleSerializer<char>::Write(0, dest); |
michael@0 | 94 | return dest; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | char* ModuleSerializer::Serialize( |
michael@0 | 98 | const BasicSourceLineResolver::Module &module, unsigned int *size) { |
michael@0 | 99 | // Compute size of memory to allocate. |
michael@0 | 100 | unsigned int size_to_alloc = SizeOf(module); |
michael@0 | 101 | |
michael@0 | 102 | // Allocate memory for serialized data. |
michael@0 | 103 | char *serialized_data = new char[size_to_alloc]; |
michael@0 | 104 | if (!serialized_data) { |
michael@0 | 105 | BPLOG(ERROR) << "ModuleSerializer: memory allocation failed, " |
michael@0 | 106 | << "size to alloc: " << size_to_alloc; |
michael@0 | 107 | if (size) *size = 0; |
michael@0 | 108 | return NULL; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | // Write serialized data to allocated memory chunk. |
michael@0 | 112 | char *end_address = Write(module, serialized_data); |
michael@0 | 113 | // Verify the allocated memory size is equal to the size of data been written. |
michael@0 | 114 | unsigned int size_written = |
michael@0 | 115 | static_cast<unsigned int>(end_address - serialized_data); |
michael@0 | 116 | if (size_to_alloc != size_written) { |
michael@0 | 117 | BPLOG(ERROR) << "size_to_alloc differs from size_written: " |
michael@0 | 118 | << size_to_alloc << " vs " << size_written; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | // Set size and return the start address of memory chunk. |
michael@0 | 122 | if (size) |
michael@0 | 123 | *size = size_to_alloc; |
michael@0 | 124 | return serialized_data; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | bool ModuleSerializer::SerializeModuleAndLoadIntoFastResolver( |
michael@0 | 128 | const BasicSourceLineResolver::ModuleMap::const_iterator &iter, |
michael@0 | 129 | FastSourceLineResolver *fast_resolver) { |
michael@0 | 130 | BPLOG(INFO) << "Converting symbol " << iter->first.c_str(); |
michael@0 | 131 | |
michael@0 | 132 | // Cast SourceLineResolverBase::Module* to BasicSourceLineResolver::Module*. |
michael@0 | 133 | BasicSourceLineResolver::Module* basic_module = |
michael@0 | 134 | dynamic_cast<BasicSourceLineResolver::Module*>(iter->second); |
michael@0 | 135 | |
michael@0 | 136 | unsigned int size = 0; |
michael@0 | 137 | scoped_array<char> symbol_data(Serialize(*basic_module, &size)); |
michael@0 | 138 | if (!symbol_data.get()) { |
michael@0 | 139 | BPLOG(ERROR) << "Serialization failed for module: " << basic_module->name_; |
michael@0 | 140 | return false; |
michael@0 | 141 | } |
michael@0 | 142 | BPLOG(INFO) << "Serialized Symbol Size " << size; |
michael@0 | 143 | |
michael@0 | 144 | // Copy the data into string. |
michael@0 | 145 | // Must pass string to LoadModuleUsingMapBuffer(), instead of passing char* to |
michael@0 | 146 | // LoadModuleUsingMemoryBuffer(), becaused of data ownership/lifetime issue. |
michael@0 | 147 | string symbol_data_string(symbol_data.get(), size); |
michael@0 | 148 | symbol_data.reset(); |
michael@0 | 149 | |
michael@0 | 150 | scoped_ptr<CodeModule> code_module( |
michael@0 | 151 | new BasicCodeModule(0, 0, iter->first, "", "", "", "")); |
michael@0 | 152 | |
michael@0 | 153 | return fast_resolver->LoadModuleUsingMapBuffer(code_module.get(), |
michael@0 | 154 | symbol_data_string); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | void ModuleSerializer::ConvertAllModules( |
michael@0 | 158 | const BasicSourceLineResolver *basic_resolver, |
michael@0 | 159 | FastSourceLineResolver *fast_resolver) { |
michael@0 | 160 | // Check for NULL pointer. |
michael@0 | 161 | if (!basic_resolver || !fast_resolver) |
michael@0 | 162 | return; |
michael@0 | 163 | |
michael@0 | 164 | // Traverse module list in basic resolver. |
michael@0 | 165 | BasicSourceLineResolver::ModuleMap::const_iterator iter; |
michael@0 | 166 | iter = basic_resolver->modules_->begin(); |
michael@0 | 167 | for (; iter != basic_resolver->modules_->end(); ++iter) |
michael@0 | 168 | SerializeModuleAndLoadIntoFastResolver(iter, fast_resolver); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | bool ModuleSerializer::ConvertOneModule( |
michael@0 | 172 | const string &moduleid, |
michael@0 | 173 | const BasicSourceLineResolver *basic_resolver, |
michael@0 | 174 | FastSourceLineResolver *fast_resolver) { |
michael@0 | 175 | // Check for NULL pointer. |
michael@0 | 176 | if (!basic_resolver || !fast_resolver) |
michael@0 | 177 | return false; |
michael@0 | 178 | |
michael@0 | 179 | BasicSourceLineResolver::ModuleMap::const_iterator iter; |
michael@0 | 180 | iter = basic_resolver->modules_->find(moduleid); |
michael@0 | 181 | if (iter == basic_resolver->modules_->end()) |
michael@0 | 182 | return false; |
michael@0 | 183 | |
michael@0 | 184 | return SerializeModuleAndLoadIntoFastResolver(iter, fast_resolver); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | char* ModuleSerializer::SerializeSymbolFileData( |
michael@0 | 188 | const string &symbol_data, unsigned int *size) { |
michael@0 | 189 | scoped_ptr<BasicSourceLineResolver::Module> module( |
michael@0 | 190 | new BasicSourceLineResolver::Module("no name")); |
michael@0 | 191 | scoped_array<char> buffer(new char[symbol_data.size() + 1]); |
michael@0 | 192 | strcpy(buffer.get(), symbol_data.c_str()); |
michael@0 | 193 | if (!module->LoadMapFromMemory(buffer.get())) { |
michael@0 | 194 | return NULL; |
michael@0 | 195 | } |
michael@0 | 196 | buffer.reset(NULL); |
michael@0 | 197 | return Serialize(*(module.get()), size); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | } // namespace google_breakpad |