toolkit/crashreporter/google-breakpad/src/common/dwarf/cfi_assembler.cc

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
michael@0 31
michael@0 32 // cfi_assembler.cc: Implementation of google_breakpad::CFISection class.
michael@0 33 // See cfi_assembler.h for details.
michael@0 34
michael@0 35 #include "common/dwarf/cfi_assembler.h"
michael@0 36
michael@0 37 #include <assert.h>
michael@0 38 #include <stdlib.h>
michael@0 39
michael@0 40 namespace google_breakpad {
michael@0 41
michael@0 42 using dwarf2reader::DwarfPointerEncoding;
michael@0 43
michael@0 44 CFISection &CFISection::CIEHeader(uint64_t code_alignment_factor,
michael@0 45 int data_alignment_factor,
michael@0 46 unsigned return_address_register,
michael@0 47 uint8_t version,
michael@0 48 const string &augmentation,
michael@0 49 bool dwarf64) {
michael@0 50 assert(!entry_length_);
michael@0 51 entry_length_ = new PendingLength();
michael@0 52 in_fde_ = false;
michael@0 53
michael@0 54 if (dwarf64) {
michael@0 55 D32(kDwarf64InitialLengthMarker);
michael@0 56 D64(entry_length_->length);
michael@0 57 entry_length_->start = Here();
michael@0 58 D64(eh_frame_ ? kEHFrame64CIEIdentifier : kDwarf64CIEIdentifier);
michael@0 59 } else {
michael@0 60 D32(entry_length_->length);
michael@0 61 entry_length_->start = Here();
michael@0 62 D32(eh_frame_ ? kEHFrame32CIEIdentifier : kDwarf32CIEIdentifier);
michael@0 63 }
michael@0 64 D8(version);
michael@0 65 AppendCString(augmentation);
michael@0 66 ULEB128(code_alignment_factor);
michael@0 67 LEB128(data_alignment_factor);
michael@0 68 if (version == 1)
michael@0 69 D8(return_address_register);
michael@0 70 else
michael@0 71 ULEB128(return_address_register);
michael@0 72 return *this;
michael@0 73 }
michael@0 74
michael@0 75 CFISection &CFISection::FDEHeader(Label cie_pointer,
michael@0 76 uint64_t initial_location,
michael@0 77 uint64_t address_range,
michael@0 78 bool dwarf64) {
michael@0 79 assert(!entry_length_);
michael@0 80 entry_length_ = new PendingLength();
michael@0 81 in_fde_ = true;
michael@0 82 fde_start_address_ = initial_location;
michael@0 83
michael@0 84 if (dwarf64) {
michael@0 85 D32(0xffffffff);
michael@0 86 D64(entry_length_->length);
michael@0 87 entry_length_->start = Here();
michael@0 88 if (eh_frame_)
michael@0 89 D64(Here() - cie_pointer);
michael@0 90 else
michael@0 91 D64(cie_pointer);
michael@0 92 } else {
michael@0 93 D32(entry_length_->length);
michael@0 94 entry_length_->start = Here();
michael@0 95 if (eh_frame_)
michael@0 96 D32(Here() - cie_pointer);
michael@0 97 else
michael@0 98 D32(cie_pointer);
michael@0 99 }
michael@0 100 EncodedPointer(initial_location);
michael@0 101 // The FDE length in an .eh_frame section uses the same encoding as the
michael@0 102 // initial location, but ignores the base address (selected by the upper
michael@0 103 // nybble of the encoding), as it's a length, not an address that can be
michael@0 104 // made relative.
michael@0 105 EncodedPointer(address_range,
michael@0 106 DwarfPointerEncoding(pointer_encoding_ & 0x0f));
michael@0 107 return *this;
michael@0 108 }
michael@0 109
michael@0 110 CFISection &CFISection::FinishEntry() {
michael@0 111 assert(entry_length_);
michael@0 112 Align(address_size_, dwarf2reader::DW_CFA_nop);
michael@0 113 entry_length_->length = Here() - entry_length_->start;
michael@0 114 delete entry_length_;
michael@0 115 entry_length_ = NULL;
michael@0 116 in_fde_ = false;
michael@0 117 return *this;
michael@0 118 }
michael@0 119
michael@0 120 CFISection &CFISection::EncodedPointer(uint64_t address,
michael@0 121 DwarfPointerEncoding encoding,
michael@0 122 const EncodedPointerBases &bases) {
michael@0 123 // Omitted data is extremely easy to emit.
michael@0 124 if (encoding == dwarf2reader::DW_EH_PE_omit)
michael@0 125 return *this;
michael@0 126
michael@0 127 // If (encoding & dwarf2reader::DW_EH_PE_indirect) != 0, then we assume
michael@0 128 // that ADDRESS is the address at which the pointer is stored --- in
michael@0 129 // other words, that bit has no effect on how we write the pointer.
michael@0 130 encoding = DwarfPointerEncoding(encoding & ~dwarf2reader::DW_EH_PE_indirect);
michael@0 131
michael@0 132 // Find the base address to which this pointer is relative. The upper
michael@0 133 // nybble of the encoding specifies this.
michael@0 134 uint64_t base;
michael@0 135 switch (encoding & 0xf0) {
michael@0 136 case dwarf2reader::DW_EH_PE_absptr: base = 0; break;
michael@0 137 case dwarf2reader::DW_EH_PE_pcrel: base = bases.cfi + Size(); break;
michael@0 138 case dwarf2reader::DW_EH_PE_textrel: base = bases.text; break;
michael@0 139 case dwarf2reader::DW_EH_PE_datarel: base = bases.data; break;
michael@0 140 case dwarf2reader::DW_EH_PE_funcrel: base = fde_start_address_; break;
michael@0 141 case dwarf2reader::DW_EH_PE_aligned: base = 0; break;
michael@0 142 default: abort();
michael@0 143 };
michael@0 144
michael@0 145 // Make ADDRESS relative. Yes, this is appropriate even for "absptr"
michael@0 146 // values; see gcc/unwind-pe.h.
michael@0 147 address -= base;
michael@0 148
michael@0 149 // Align the pointer, if required.
michael@0 150 if ((encoding & 0xf0) == dwarf2reader::DW_EH_PE_aligned)
michael@0 151 Align(AddressSize());
michael@0 152
michael@0 153 // Append ADDRESS to this section in the appropriate form. For the
michael@0 154 // fixed-width forms, we don't need to differentiate between signed and
michael@0 155 // unsigned encodings, because ADDRESS has already been extended to 64
michael@0 156 // bits before it was passed to us.
michael@0 157 switch (encoding & 0x0f) {
michael@0 158 case dwarf2reader::DW_EH_PE_absptr:
michael@0 159 Address(address);
michael@0 160 break;
michael@0 161
michael@0 162 case dwarf2reader::DW_EH_PE_uleb128:
michael@0 163 ULEB128(address);
michael@0 164 break;
michael@0 165
michael@0 166 case dwarf2reader::DW_EH_PE_sleb128:
michael@0 167 LEB128(address);
michael@0 168 break;
michael@0 169
michael@0 170 case dwarf2reader::DW_EH_PE_udata2:
michael@0 171 case dwarf2reader::DW_EH_PE_sdata2:
michael@0 172 D16(address);
michael@0 173 break;
michael@0 174
michael@0 175 case dwarf2reader::DW_EH_PE_udata4:
michael@0 176 case dwarf2reader::DW_EH_PE_sdata4:
michael@0 177 D32(address);
michael@0 178 break;
michael@0 179
michael@0 180 case dwarf2reader::DW_EH_PE_udata8:
michael@0 181 case dwarf2reader::DW_EH_PE_sdata8:
michael@0 182 D64(address);
michael@0 183 break;
michael@0 184
michael@0 185 default:
michael@0 186 abort();
michael@0 187 }
michael@0 188
michael@0 189 return *this;
michael@0 190 };
michael@0 191
michael@0 192 const uint32_t CFISection::kDwarf64InitialLengthMarker;
michael@0 193 const uint32_t CFISection::kDwarf32CIEIdentifier;
michael@0 194 const uint64_t CFISection::kDwarf64CIEIdentifier;
michael@0 195 const uint32_t CFISection::kEHFrame32CIEIdentifier;
michael@0 196 const uint64_t CFISection::kEHFrame64CIEIdentifier;
michael@0 197
michael@0 198 } // namespace google_breakpad

mercurial