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 | // -*- mode: C++ -*- |
michael@0 | 2 | |
michael@0 | 3 | // Copyright (c) 2010, Google Inc. |
michael@0 | 4 | // All rights reserved. |
michael@0 | 5 | // |
michael@0 | 6 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | // modification, are permitted provided that the following conditions are |
michael@0 | 8 | // met: |
michael@0 | 9 | // |
michael@0 | 10 | // * Redistributions of source code must retain the above copyright |
michael@0 | 11 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | // * Redistributions in binary form must reproduce the above |
michael@0 | 13 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 14 | // in the documentation and/or other materials provided with the |
michael@0 | 15 | // distribution. |
michael@0 | 16 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 17 | // contributors may be used to endorse or promote products derived from |
michael@0 | 18 | // this software without specific prior written permission. |
michael@0 | 19 | // |
michael@0 | 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | |
michael@0 | 32 | // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
michael@0 | 33 | |
michael@0 | 34 | // cfi_assembler.h: Define CFISection, a class for creating properly |
michael@0 | 35 | // (and improperly) formatted DWARF CFI data for unit tests. |
michael@0 | 36 | |
michael@0 | 37 | #ifndef PROCESSOR_CFI_ASSEMBLER_H_ |
michael@0 | 38 | #define PROCESSOR_CFI_ASSEMBLER_H_ |
michael@0 | 39 | |
michael@0 | 40 | #include <string> |
michael@0 | 41 | |
michael@0 | 42 | #include "common/dwarf/dwarf2enums.h" |
michael@0 | 43 | #include "common/test_assembler.h" |
michael@0 | 44 | #include "common/using_std_string.h" |
michael@0 | 45 | #include "google_breakpad/common/breakpad_types.h" |
michael@0 | 46 | |
michael@0 | 47 | namespace google_breakpad { |
michael@0 | 48 | |
michael@0 | 49 | using dwarf2reader::DwarfPointerEncoding; |
michael@0 | 50 | using google_breakpad::test_assembler::Endianness; |
michael@0 | 51 | using google_breakpad::test_assembler::Label; |
michael@0 | 52 | using google_breakpad::test_assembler::Section; |
michael@0 | 53 | |
michael@0 | 54 | class CFISection: public Section { |
michael@0 | 55 | public: |
michael@0 | 56 | |
michael@0 | 57 | // CFI augmentation strings beginning with 'z', defined by the |
michael@0 | 58 | // Linux/IA-64 C++ ABI, can specify interesting encodings for |
michael@0 | 59 | // addresses appearing in FDE headers and call frame instructions (and |
michael@0 | 60 | // for additional fields whose presence the augmentation string |
michael@0 | 61 | // specifies). In particular, pointers can be specified to be relative |
michael@0 | 62 | // to various base address: the start of the .text section, the |
michael@0 | 63 | // location holding the address itself, and so on. These allow the |
michael@0 | 64 | // frame data to be position-independent even when they live in |
michael@0 | 65 | // write-protected pages. These variants are specified at the |
michael@0 | 66 | // following two URLs: |
michael@0 | 67 | // |
michael@0 | 68 | // http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/dwarfext.html |
michael@0 | 69 | // http://refspecs.linux-foundation.org/LSB_4.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html |
michael@0 | 70 | // |
michael@0 | 71 | // CFISection leaves the production of well-formed 'z'-augmented CIEs and |
michael@0 | 72 | // FDEs to the user, but does provide EncodedPointer, to emit |
michael@0 | 73 | // properly-encoded addresses for a given pointer encoding. |
michael@0 | 74 | // EncodedPointer uses an instance of this structure to find the base |
michael@0 | 75 | // addresses it should use; you can establish a default for all encoded |
michael@0 | 76 | // pointers appended to this section with SetEncodedPointerBases. |
michael@0 | 77 | struct EncodedPointerBases { |
michael@0 | 78 | EncodedPointerBases() : cfi(), text(), data() { } |
michael@0 | 79 | |
michael@0 | 80 | // The starting address of this CFI section in memory, for |
michael@0 | 81 | // DW_EH_PE_pcrel. DW_EH_PE_pcrel pointers may only be used in data |
michael@0 | 82 | // that has is loaded into the program's address space. |
michael@0 | 83 | uint64_t cfi; |
michael@0 | 84 | |
michael@0 | 85 | // The starting address of this file's .text section, for DW_EH_PE_textrel. |
michael@0 | 86 | uint64_t text; |
michael@0 | 87 | |
michael@0 | 88 | // The starting address of this file's .got or .eh_frame_hdr section, |
michael@0 | 89 | // for DW_EH_PE_datarel. |
michael@0 | 90 | uint64_t data; |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | // Create a CFISection whose endianness is ENDIANNESS, and where |
michael@0 | 94 | // machine addresses are ADDRESS_SIZE bytes long. If EH_FRAME is |
michael@0 | 95 | // true, use the .eh_frame format, as described by the Linux |
michael@0 | 96 | // Standards Base Core Specification, instead of the DWARF CFI |
michael@0 | 97 | // format. |
michael@0 | 98 | CFISection(Endianness endianness, size_t address_size, |
michael@0 | 99 | bool eh_frame = false) |
michael@0 | 100 | : Section(endianness), address_size_(address_size), eh_frame_(eh_frame), |
michael@0 | 101 | pointer_encoding_(dwarf2reader::DW_EH_PE_absptr), |
michael@0 | 102 | encoded_pointer_bases_(), entry_length_(NULL), in_fde_(false) { |
michael@0 | 103 | // The 'start', 'Here', and 'Mark' members of a CFISection all refer |
michael@0 | 104 | // to section offsets. |
michael@0 | 105 | start() = 0; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | // Return this CFISection's address size. |
michael@0 | 109 | size_t AddressSize() const { return address_size_; } |
michael@0 | 110 | |
michael@0 | 111 | // Return true if this CFISection uses the .eh_frame format, or |
michael@0 | 112 | // false if it contains ordinary DWARF CFI data. |
michael@0 | 113 | bool ContainsEHFrame() const { return eh_frame_; } |
michael@0 | 114 | |
michael@0 | 115 | // Use ENCODING for pointers in calls to FDEHeader and EncodedPointer. |
michael@0 | 116 | void SetPointerEncoding(DwarfPointerEncoding encoding) { |
michael@0 | 117 | pointer_encoding_ = encoding; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | // Use the addresses in BASES as the base addresses for encoded |
michael@0 | 121 | // pointers in subsequent calls to FDEHeader or EncodedPointer. |
michael@0 | 122 | // This function makes a copy of BASES. |
michael@0 | 123 | void SetEncodedPointerBases(const EncodedPointerBases &bases) { |
michael@0 | 124 | encoded_pointer_bases_ = bases; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | // Append a Common Information Entry header to this section with the |
michael@0 | 128 | // given values. If dwarf64 is true, use the 64-bit DWARF initial |
michael@0 | 129 | // length format for the CIE's initial length. Return a reference to |
michael@0 | 130 | // this section. You should call FinishEntry after writing the last |
michael@0 | 131 | // instruction for the CIE. |
michael@0 | 132 | // |
michael@0 | 133 | // Before calling this function, you will typically want to use Mark |
michael@0 | 134 | // or Here to make a label to pass to FDEHeader that refers to this |
michael@0 | 135 | // CIE's position in the section. |
michael@0 | 136 | CFISection &CIEHeader(uint64_t code_alignment_factor, |
michael@0 | 137 | int data_alignment_factor, |
michael@0 | 138 | unsigned return_address_register, |
michael@0 | 139 | uint8_t version = 3, |
michael@0 | 140 | const string &augmentation = "", |
michael@0 | 141 | bool dwarf64 = false); |
michael@0 | 142 | |
michael@0 | 143 | // Append a Frame Description Entry header to this section with the |
michael@0 | 144 | // given values. If dwarf64 is true, use the 64-bit DWARF initial |
michael@0 | 145 | // length format for the CIE's initial length. Return a reference to |
michael@0 | 146 | // this section. You should call FinishEntry after writing the last |
michael@0 | 147 | // instruction for the CIE. |
michael@0 | 148 | // |
michael@0 | 149 | // This function doesn't support entries that are longer than |
michael@0 | 150 | // 0xffffff00 bytes. (The "initial length" is always a 32-bit |
michael@0 | 151 | // value.) Nor does it support .debug_frame sections longer than |
michael@0 | 152 | // 0xffffff00 bytes. |
michael@0 | 153 | CFISection &FDEHeader(Label cie_pointer, |
michael@0 | 154 | uint64_t initial_location, |
michael@0 | 155 | uint64_t address_range, |
michael@0 | 156 | bool dwarf64 = false); |
michael@0 | 157 | |
michael@0 | 158 | // Note the current position as the end of the last CIE or FDE we |
michael@0 | 159 | // started, after padding with DW_CFA_nops for alignment. This |
michael@0 | 160 | // defines the label representing the entry's length, cited in the |
michael@0 | 161 | // entry's header. Return a reference to this section. |
michael@0 | 162 | CFISection &FinishEntry(); |
michael@0 | 163 | |
michael@0 | 164 | // Append the contents of BLOCK as a DW_FORM_block value: an |
michael@0 | 165 | // unsigned LEB128 length, followed by that many bytes of data. |
michael@0 | 166 | CFISection &Block(const string &block) { |
michael@0 | 167 | ULEB128(block.size()); |
michael@0 | 168 | Append(block); |
michael@0 | 169 | return *this; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | // Append ADDRESS to this section, in the appropriate size and |
michael@0 | 173 | // endianness. Return a reference to this section. |
michael@0 | 174 | CFISection &Address(uint64_t address) { |
michael@0 | 175 | Section::Append(endianness(), address_size_, address); |
michael@0 | 176 | return *this; |
michael@0 | 177 | } |
michael@0 | 178 | CFISection &Address(Label address) { |
michael@0 | 179 | Section::Append(endianness(), address_size_, address); |
michael@0 | 180 | return *this; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | // Append ADDRESS to this section, using ENCODING and BASES. ENCODING |
michael@0 | 184 | // defaults to this section's default encoding, established by |
michael@0 | 185 | // SetPointerEncoding. BASES defaults to this section's bases, set by |
michael@0 | 186 | // SetEncodedPointerBases. If the DW_EH_PE_indirect bit is set in the |
michael@0 | 187 | // encoding, assume that ADDRESS is where the true address is stored. |
michael@0 | 188 | // Return a reference to this section. |
michael@0 | 189 | // |
michael@0 | 190 | // (C++ doesn't let me use default arguments here, because I want to |
michael@0 | 191 | // refer to members of *this in the default argument expression.) |
michael@0 | 192 | CFISection &EncodedPointer(uint64_t address) { |
michael@0 | 193 | return EncodedPointer(address, pointer_encoding_, encoded_pointer_bases_); |
michael@0 | 194 | } |
michael@0 | 195 | CFISection &EncodedPointer(uint64_t address, DwarfPointerEncoding encoding) { |
michael@0 | 196 | return EncodedPointer(address, encoding, encoded_pointer_bases_); |
michael@0 | 197 | } |
michael@0 | 198 | CFISection &EncodedPointer(uint64_t address, DwarfPointerEncoding encoding, |
michael@0 | 199 | const EncodedPointerBases &bases); |
michael@0 | 200 | |
michael@0 | 201 | // Restate some member functions, to keep chaining working nicely. |
michael@0 | 202 | CFISection &Mark(Label *label) { Section::Mark(label); return *this; } |
michael@0 | 203 | CFISection &D8(uint8_t v) { Section::D8(v); return *this; } |
michael@0 | 204 | CFISection &D16(uint16_t v) { Section::D16(v); return *this; } |
michael@0 | 205 | CFISection &D16(Label v) { Section::D16(v); return *this; } |
michael@0 | 206 | CFISection &D32(uint32_t v) { Section::D32(v); return *this; } |
michael@0 | 207 | CFISection &D32(const Label &v) { Section::D32(v); return *this; } |
michael@0 | 208 | CFISection &D64(uint64_t v) { Section::D64(v); return *this; } |
michael@0 | 209 | CFISection &D64(const Label &v) { Section::D64(v); return *this; } |
michael@0 | 210 | CFISection &LEB128(long long v) { Section::LEB128(v); return *this; } |
michael@0 | 211 | CFISection &ULEB128(uint64_t v) { Section::ULEB128(v); return *this; } |
michael@0 | 212 | |
michael@0 | 213 | private: |
michael@0 | 214 | // A length value that we've appended to the section, but is not yet |
michael@0 | 215 | // known. LENGTH is the appended value; START is a label referring |
michael@0 | 216 | // to the start of the data whose length was cited. |
michael@0 | 217 | struct PendingLength { |
michael@0 | 218 | Label length; |
michael@0 | 219 | Label start; |
michael@0 | 220 | }; |
michael@0 | 221 | |
michael@0 | 222 | // Constants used in CFI/.eh_frame data: |
michael@0 | 223 | |
michael@0 | 224 | // If the first four bytes of an "initial length" are this constant, then |
michael@0 | 225 | // the data uses the 64-bit DWARF format, and the length itself is the |
michael@0 | 226 | // subsequent eight bytes. |
michael@0 | 227 | static const uint32_t kDwarf64InitialLengthMarker = 0xffffffffU; |
michael@0 | 228 | |
michael@0 | 229 | // The CIE identifier for 32- and 64-bit DWARF CFI and .eh_frame data. |
michael@0 | 230 | static const uint32_t kDwarf32CIEIdentifier = ~(uint32_t)0; |
michael@0 | 231 | static const uint64_t kDwarf64CIEIdentifier = ~(uint64_t)0; |
michael@0 | 232 | static const uint32_t kEHFrame32CIEIdentifier = 0; |
michael@0 | 233 | static const uint64_t kEHFrame64CIEIdentifier = 0; |
michael@0 | 234 | |
michael@0 | 235 | // The size of a machine address for the data in this section. |
michael@0 | 236 | size_t address_size_; |
michael@0 | 237 | |
michael@0 | 238 | // If true, we are generating a Linux .eh_frame section, instead of |
michael@0 | 239 | // a standard DWARF .debug_frame section. |
michael@0 | 240 | bool eh_frame_; |
michael@0 | 241 | |
michael@0 | 242 | // The encoding to use for FDE pointers. |
michael@0 | 243 | DwarfPointerEncoding pointer_encoding_; |
michael@0 | 244 | |
michael@0 | 245 | // The base addresses to use when emitting encoded pointers. |
michael@0 | 246 | EncodedPointerBases encoded_pointer_bases_; |
michael@0 | 247 | |
michael@0 | 248 | // The length value for the current entry. |
michael@0 | 249 | // |
michael@0 | 250 | // Oddly, this must be dynamically allocated. Labels never get new |
michael@0 | 251 | // values; they only acquire constraints on the value they already |
michael@0 | 252 | // have, or assert if you assign them something incompatible. So |
michael@0 | 253 | // each header needs truly fresh Label objects to cite in their |
michael@0 | 254 | // headers and track their positions. The alternative is explicit |
michael@0 | 255 | // destructor invocation and a placement new. Ick. |
michael@0 | 256 | PendingLength *entry_length_; |
michael@0 | 257 | |
michael@0 | 258 | // True if we are currently emitting an FDE --- that is, we have |
michael@0 | 259 | // called FDEHeader but have not yet called FinishEntry. |
michael@0 | 260 | bool in_fde_; |
michael@0 | 261 | |
michael@0 | 262 | // If in_fde_ is true, this is its starting address. We use this for |
michael@0 | 263 | // emitting DW_EH_PE_funcrel pointers. |
michael@0 | 264 | uint64_t fde_start_address_; |
michael@0 | 265 | }; |
michael@0 | 266 | |
michael@0 | 267 | } // namespace google_breakpad |
michael@0 | 268 | |
michael@0 | 269 | #endif // PROCESSOR_CFI_ASSEMBLER_H_ |