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 | // stackwalker.h: Generic stackwalker. |
michael@0 | 31 | // |
michael@0 | 32 | // The Stackwalker class is an abstract base class providing common generic |
michael@0 | 33 | // methods that apply to stacks from all systems. Specific implementations |
michael@0 | 34 | // will extend this class by providing GetContextFrame and GetCallerFrame |
michael@0 | 35 | // methods to fill in system-specific data in a StackFrame structure. |
michael@0 | 36 | // Stackwalker assembles these StackFrame strucutres into a CallStack. |
michael@0 | 37 | // |
michael@0 | 38 | // Author: Mark Mentovai |
michael@0 | 39 | |
michael@0 | 40 | |
michael@0 | 41 | #ifndef GOOGLE_BREAKPAD_PROCESSOR_STACKWALKER_H__ |
michael@0 | 42 | #define GOOGLE_BREAKPAD_PROCESSOR_STACKWALKER_H__ |
michael@0 | 43 | |
michael@0 | 44 | #include <set> |
michael@0 | 45 | #include <string> |
michael@0 | 46 | #include <vector> |
michael@0 | 47 | |
michael@0 | 48 | #include "common/using_std_string.h" |
michael@0 | 49 | #include "google_breakpad/common/breakpad_types.h" |
michael@0 | 50 | #include "google_breakpad/processor/code_modules.h" |
michael@0 | 51 | #include "google_breakpad/processor/memory_region.h" |
michael@0 | 52 | #include "google_breakpad/processor/stack_frame_symbolizer.h" |
michael@0 | 53 | |
michael@0 | 54 | namespace google_breakpad { |
michael@0 | 55 | |
michael@0 | 56 | class CallStack; |
michael@0 | 57 | class MinidumpContext; |
michael@0 | 58 | class StackFrameSymbolizer; |
michael@0 | 59 | |
michael@0 | 60 | using std::set; |
michael@0 | 61 | using std::vector; |
michael@0 | 62 | |
michael@0 | 63 | class Stackwalker { |
michael@0 | 64 | public: |
michael@0 | 65 | virtual ~Stackwalker() {} |
michael@0 | 66 | |
michael@0 | 67 | // Populates the given CallStack by calling GetContextFrame and |
michael@0 | 68 | // GetCallerFrame. The frames are further processed to fill all available |
michael@0 | 69 | // data. Returns true if the stackwalk completed, or false if it was |
michael@0 | 70 | // interrupted by SymbolSupplier::GetSymbolFile(). |
michael@0 | 71 | // Upon return, modules_without_symbols will be populated with pointers to |
michael@0 | 72 | // the code modules (CodeModule*) that DON'T have symbols. |
michael@0 | 73 | // modules_without_symbols DOES NOT take ownership of the code modules. |
michael@0 | 74 | // The lifetime of these code modules is the same as the lifetime of the |
michael@0 | 75 | // CodeModules passed to the StackWalker constructor (which currently |
michael@0 | 76 | // happens to be the lifetime of the Breakpad's ProcessingState object). |
michael@0 | 77 | // There is a check for duplicate modules so no duplicates are expected. |
michael@0 | 78 | bool Walk(CallStack* stack, |
michael@0 | 79 | vector<const CodeModule*>* modules_without_symbols); |
michael@0 | 80 | |
michael@0 | 81 | // Returns a new concrete subclass suitable for the CPU that a stack was |
michael@0 | 82 | // generated on, according to the CPU type indicated by the context |
michael@0 | 83 | // argument. If no suitable concrete subclass exists, returns NULL. |
michael@0 | 84 | static Stackwalker* StackwalkerForCPU( |
michael@0 | 85 | const SystemInfo* system_info, |
michael@0 | 86 | MinidumpContext* context, |
michael@0 | 87 | MemoryRegion* memory, |
michael@0 | 88 | const CodeModules* modules, |
michael@0 | 89 | StackFrameSymbolizer* resolver_helper); |
michael@0 | 90 | |
michael@0 | 91 | static void set_max_frames(uint32_t max_frames) { |
michael@0 | 92 | max_frames_ = max_frames; |
michael@0 | 93 | max_frames_set_ = true; |
michael@0 | 94 | } |
michael@0 | 95 | static uint32_t max_frames() { return max_frames_; } |
michael@0 | 96 | |
michael@0 | 97 | static void set_max_frames_scanned(uint32_t max_frames_scanned) { |
michael@0 | 98 | max_frames_scanned_ = max_frames_scanned; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | protected: |
michael@0 | 102 | // system_info identifies the operating system, NULL or empty if unknown. |
michael@0 | 103 | // memory identifies a MemoryRegion that provides the stack memory |
michael@0 | 104 | // for the stack to walk. modules, if non-NULL, is a CodeModules |
michael@0 | 105 | // object that is used to look up which code module each stack frame is |
michael@0 | 106 | // associated with. frame_symbolizer is a StackFrameSymbolizer object that |
michael@0 | 107 | // encapsulates the logic of how source line resolver interacts with symbol |
michael@0 | 108 | // supplier to symbolize stack frame and look up caller frame information |
michael@0 | 109 | // (see stack_frame_symbolizer.h). |
michael@0 | 110 | // frame_symbolizer MUST NOT be NULL (asserted). |
michael@0 | 111 | Stackwalker(const SystemInfo* system_info, |
michael@0 | 112 | MemoryRegion* memory, |
michael@0 | 113 | const CodeModules* modules, |
michael@0 | 114 | StackFrameSymbolizer* frame_symbolizer); |
michael@0 | 115 | |
michael@0 | 116 | // This can be used to filter out potential return addresses when |
michael@0 | 117 | // the stack walker resorts to stack scanning. |
michael@0 | 118 | // Returns true if any of: |
michael@0 | 119 | // * This address is within a loaded module, but we don't have symbols |
michael@0 | 120 | // for that module. |
michael@0 | 121 | // * This address is within a loaded module for which we have symbols, |
michael@0 | 122 | // and falls inside a function in that module. |
michael@0 | 123 | // Returns false otherwise. |
michael@0 | 124 | bool InstructionAddressSeemsValid(uint64_t address); |
michael@0 | 125 | |
michael@0 | 126 | // The default number of words to search through on the stack |
michael@0 | 127 | // for a return address. |
michael@0 | 128 | static const int kRASearchWords; |
michael@0 | 129 | |
michael@0 | 130 | template<typename InstructionType> |
michael@0 | 131 | bool ScanForReturnAddress(InstructionType location_start, |
michael@0 | 132 | InstructionType* location_found, |
michael@0 | 133 | InstructionType* ip_found) { |
michael@0 | 134 | return ScanForReturnAddress(location_start, location_found, ip_found, |
michael@0 | 135 | kRASearchWords); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // Scan the stack starting at location_start, looking for an address |
michael@0 | 139 | // that looks like a valid instruction pointer. Addresses must |
michael@0 | 140 | // 1) be contained in the current stack memory |
michael@0 | 141 | // 2) pass the checks in InstructionAddressSeemsValid |
michael@0 | 142 | // |
michael@0 | 143 | // Returns true if a valid-looking instruction pointer was found. |
michael@0 | 144 | // When returning true, sets location_found to the address at which |
michael@0 | 145 | // the value was found, and ip_found to the value contained at that |
michael@0 | 146 | // location in memory. |
michael@0 | 147 | template<typename InstructionType> |
michael@0 | 148 | bool ScanForReturnAddress(InstructionType location_start, |
michael@0 | 149 | InstructionType* location_found, |
michael@0 | 150 | InstructionType* ip_found, |
michael@0 | 151 | int searchwords) { |
michael@0 | 152 | for (InstructionType location = location_start; |
michael@0 | 153 | location <= location_start + searchwords * sizeof(InstructionType); |
michael@0 | 154 | location += sizeof(InstructionType)) { |
michael@0 | 155 | InstructionType ip; |
michael@0 | 156 | if (!memory_->GetMemoryAtAddress(location, &ip)) |
michael@0 | 157 | break; |
michael@0 | 158 | |
michael@0 | 159 | if (modules_ && modules_->GetModuleForAddress(ip) && |
michael@0 | 160 | InstructionAddressSeemsValid(ip)) { |
michael@0 | 161 | *ip_found = ip; |
michael@0 | 162 | *location_found = location; |
michael@0 | 163 | return true; |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | // nothing found |
michael@0 | 167 | return false; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | // Information about the system that produced the minidump. Subclasses |
michael@0 | 171 | // and the SymbolSupplier may find this information useful. |
michael@0 | 172 | const SystemInfo* system_info_; |
michael@0 | 173 | |
michael@0 | 174 | // The stack memory to walk. Subclasses will require this region to |
michael@0 | 175 | // get information from the stack. |
michael@0 | 176 | MemoryRegion* memory_; |
michael@0 | 177 | |
michael@0 | 178 | // A list of modules, for populating each StackFrame's module information. |
michael@0 | 179 | // This field is optional and may be NULL. |
michael@0 | 180 | const CodeModules* modules_; |
michael@0 | 181 | |
michael@0 | 182 | protected: |
michael@0 | 183 | // The StackFrameSymbolizer implementation. |
michael@0 | 184 | StackFrameSymbolizer* frame_symbolizer_; |
michael@0 | 185 | |
michael@0 | 186 | private: |
michael@0 | 187 | // Obtains the context frame, the innermost called procedure in a stack |
michael@0 | 188 | // trace. Returns NULL on failure. GetContextFrame allocates a new |
michael@0 | 189 | // StackFrame (or StackFrame subclass), ownership of which is taken by |
michael@0 | 190 | // the caller. |
michael@0 | 191 | virtual StackFrame* GetContextFrame() = 0; |
michael@0 | 192 | |
michael@0 | 193 | // Obtains a caller frame. Each call to GetCallerFrame should return the |
michael@0 | 194 | // frame that called the last frame returned by GetContextFrame or |
michael@0 | 195 | // GetCallerFrame. To aid this purpose, stack contains the CallStack |
michael@0 | 196 | // made of frames that have already been walked. GetCallerFrame should |
michael@0 | 197 | // return NULL on failure or when there are no more caller frames (when |
michael@0 | 198 | // the end of the stack has been reached). GetCallerFrame allocates a new |
michael@0 | 199 | // StackFrame (or StackFrame subclass), ownership of which is taken by |
michael@0 | 200 | // the caller. |stack_scan_allowed| controls whether stack scanning is |
michael@0 | 201 | // an allowable frame-recovery method, since it is desirable to be able to |
michael@0 | 202 | // disable stack scanning in performance-critical use cases. |
michael@0 | 203 | virtual StackFrame* GetCallerFrame(const CallStack* stack, |
michael@0 | 204 | bool stack_scan_allowed) = 0; |
michael@0 | 205 | |
michael@0 | 206 | // The maximum number of frames Stackwalker will walk through. |
michael@0 | 207 | // This defaults to 1024 to prevent infinite loops. |
michael@0 | 208 | static uint32_t max_frames_; |
michael@0 | 209 | |
michael@0 | 210 | // Keep track of whether max_frames_ has been set by the user, since |
michael@0 | 211 | // it affects whether or not an error message is printed in the case |
michael@0 | 212 | // where an unwind got stopped by the limit. |
michael@0 | 213 | static bool max_frames_set_; |
michael@0 | 214 | |
michael@0 | 215 | // The maximum number of stack-scanned and otherwise untrustworthy |
michael@0 | 216 | // frames allowed. Stack-scanning can be expensive, so the option to |
michael@0 | 217 | // disable or limit it is helpful in cases where unwind performance is |
michael@0 | 218 | // important. This defaults to 1024, the same as max_frames_. |
michael@0 | 219 | static uint32_t max_frames_scanned_; |
michael@0 | 220 | }; |
michael@0 | 221 | |
michael@0 | 222 | } // namespace google_breakpad |
michael@0 | 223 | |
michael@0 | 224 | |
michael@0 | 225 | #endif // GOOGLE_BREAKPAD_PROCESSOR_STACKWALKER_H__ |