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 2006 Google Inc. All Rights Reserved. |
michael@0 | 2 | // |
michael@0 | 3 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 4 | // modification, are permitted provided that the following conditions are |
michael@0 | 5 | // met: |
michael@0 | 6 | // |
michael@0 | 7 | // * Redistributions of source code must retain the above copyright |
michael@0 | 8 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 9 | // * Redistributions in binary form must reproduce the above |
michael@0 | 10 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 11 | // in the documentation and/or other materials provided with the |
michael@0 | 12 | // distribution. |
michael@0 | 13 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 14 | // contributors may be used to endorse or promote products derived from |
michael@0 | 15 | // this software without specific prior written permission. |
michael@0 | 16 | // |
michael@0 | 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 28 | |
michael@0 | 29 | #ifndef UTIL_DEBUGINFO_BYTEREADER_INL_H__ |
michael@0 | 30 | #define UTIL_DEBUGINFO_BYTEREADER_INL_H__ |
michael@0 | 31 | |
michael@0 | 32 | #include "common/dwarf/bytereader.h" |
michael@0 | 33 | |
michael@0 | 34 | #include <assert.h> |
michael@0 | 35 | |
michael@0 | 36 | namespace dwarf2reader { |
michael@0 | 37 | |
michael@0 | 38 | inline uint8 ByteReader::ReadOneByte(const char* buffer) const { |
michael@0 | 39 | return buffer[0]; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | inline uint16 ByteReader::ReadTwoBytes(const char* signed_buffer) const { |
michael@0 | 43 | const unsigned char *buffer |
michael@0 | 44 | = reinterpret_cast<const unsigned char *>(signed_buffer); |
michael@0 | 45 | const uint16 buffer0 = buffer[0]; |
michael@0 | 46 | const uint16 buffer1 = buffer[1]; |
michael@0 | 47 | if (endian_ == ENDIANNESS_LITTLE) { |
michael@0 | 48 | return buffer0 | buffer1 << 8; |
michael@0 | 49 | } else { |
michael@0 | 50 | return buffer1 | buffer0 << 8; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | inline uint64 ByteReader::ReadFourBytes(const char* signed_buffer) const { |
michael@0 | 55 | const unsigned char *buffer |
michael@0 | 56 | = reinterpret_cast<const unsigned char *>(signed_buffer); |
michael@0 | 57 | const uint32 buffer0 = buffer[0]; |
michael@0 | 58 | const uint32 buffer1 = buffer[1]; |
michael@0 | 59 | const uint32 buffer2 = buffer[2]; |
michael@0 | 60 | const uint32 buffer3 = buffer[3]; |
michael@0 | 61 | if (endian_ == ENDIANNESS_LITTLE) { |
michael@0 | 62 | return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24; |
michael@0 | 63 | } else { |
michael@0 | 64 | return buffer3 | buffer2 << 8 | buffer1 << 16 | buffer0 << 24; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | inline uint64 ByteReader::ReadEightBytes(const char* signed_buffer) const { |
michael@0 | 69 | const unsigned char *buffer |
michael@0 | 70 | = reinterpret_cast<const unsigned char *>(signed_buffer); |
michael@0 | 71 | const uint64 buffer0 = buffer[0]; |
michael@0 | 72 | const uint64 buffer1 = buffer[1]; |
michael@0 | 73 | const uint64 buffer2 = buffer[2]; |
michael@0 | 74 | const uint64 buffer3 = buffer[3]; |
michael@0 | 75 | const uint64 buffer4 = buffer[4]; |
michael@0 | 76 | const uint64 buffer5 = buffer[5]; |
michael@0 | 77 | const uint64 buffer6 = buffer[6]; |
michael@0 | 78 | const uint64 buffer7 = buffer[7]; |
michael@0 | 79 | if (endian_ == ENDIANNESS_LITTLE) { |
michael@0 | 80 | return buffer0 | buffer1 << 8 | buffer2 << 16 | buffer3 << 24 | |
michael@0 | 81 | buffer4 << 32 | buffer5 << 40 | buffer6 << 48 | buffer7 << 56; |
michael@0 | 82 | } else { |
michael@0 | 83 | return buffer7 | buffer6 << 8 | buffer5 << 16 | buffer4 << 24 | |
michael@0 | 84 | buffer3 << 32 | buffer2 << 40 | buffer1 << 48 | buffer0 << 56; |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | // Read an unsigned LEB128 number. Each byte contains 7 bits of |
michael@0 | 89 | // information, plus one bit saying whether the number continues or |
michael@0 | 90 | // not. |
michael@0 | 91 | |
michael@0 | 92 | inline uint64 ByteReader::ReadUnsignedLEB128(const char* buffer, |
michael@0 | 93 | size_t* len) const { |
michael@0 | 94 | uint64 result = 0; |
michael@0 | 95 | size_t num_read = 0; |
michael@0 | 96 | unsigned int shift = 0; |
michael@0 | 97 | unsigned char byte; |
michael@0 | 98 | |
michael@0 | 99 | do { |
michael@0 | 100 | byte = *buffer++; |
michael@0 | 101 | num_read++; |
michael@0 | 102 | |
michael@0 | 103 | result |= (static_cast<uint64>(byte & 0x7f)) << shift; |
michael@0 | 104 | |
michael@0 | 105 | shift += 7; |
michael@0 | 106 | |
michael@0 | 107 | } while (byte & 0x80); |
michael@0 | 108 | |
michael@0 | 109 | *len = num_read; |
michael@0 | 110 | |
michael@0 | 111 | return result; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | // Read a signed LEB128 number. These are like regular LEB128 |
michael@0 | 115 | // numbers, except the last byte may have a sign bit set. |
michael@0 | 116 | |
michael@0 | 117 | inline int64 ByteReader::ReadSignedLEB128(const char* buffer, |
michael@0 | 118 | size_t* len) const { |
michael@0 | 119 | int64 result = 0; |
michael@0 | 120 | unsigned int shift = 0; |
michael@0 | 121 | size_t num_read = 0; |
michael@0 | 122 | unsigned char byte; |
michael@0 | 123 | |
michael@0 | 124 | do { |
michael@0 | 125 | byte = *buffer++; |
michael@0 | 126 | num_read++; |
michael@0 | 127 | result |= (static_cast<uint64>(byte & 0x7f) << shift); |
michael@0 | 128 | shift += 7; |
michael@0 | 129 | } while (byte & 0x80); |
michael@0 | 130 | |
michael@0 | 131 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
michael@0 | 132 | result |= -((static_cast<int64>(1)) << shift); |
michael@0 | 133 | *len = num_read; |
michael@0 | 134 | return result; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | inline uint64 ByteReader::ReadOffset(const char* buffer) const { |
michael@0 | 138 | assert(this->offset_reader_); |
michael@0 | 139 | return (this->*offset_reader_)(buffer); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | inline uint64 ByteReader::ReadAddress(const char* buffer) const { |
michael@0 | 143 | assert(this->address_reader_); |
michael@0 | 144 | return (this->*address_reader_)(buffer); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | inline void ByteReader::SetCFIDataBase(uint64 section_base, |
michael@0 | 148 | const char *buffer_base) { |
michael@0 | 149 | section_base_ = section_base; |
michael@0 | 150 | buffer_base_ = buffer_base; |
michael@0 | 151 | have_section_base_ = true; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | inline void ByteReader::SetTextBase(uint64 text_base) { |
michael@0 | 155 | text_base_ = text_base; |
michael@0 | 156 | have_text_base_ = true; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | inline void ByteReader::SetDataBase(uint64 data_base) { |
michael@0 | 160 | data_base_ = data_base; |
michael@0 | 161 | have_data_base_ = true; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | inline void ByteReader::SetFunctionBase(uint64 function_base) { |
michael@0 | 165 | function_base_ = function_base; |
michael@0 | 166 | have_function_base_ = true; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | inline void ByteReader::ClearFunctionBase() { |
michael@0 | 170 | have_function_base_ = false; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | } // namespace dwarf2reader |
michael@0 | 174 | |
michael@0 | 175 | #endif // UTIL_DEBUGINFO_BYTEREADER_INL_H__ |