diff --git a/DEPS b/DEPS index 4da972fa..c27021cd 100644 --- a/DEPS +++ b/DEPS @@ -28,7 +28,7 @@ deps = { '46282cedf40ff7fe803be4af357b9d59050f02e4', # svn r1977 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '313bd83d6d9dc276bd48743fddc0295fc08f9478', + 'ba9b15f1b6a7616ac0cb26069201a479e81845c3', } hooks = [ diff --git a/util/numeric/int128.h b/util/numeric/int128.h new file mode 100644 index 00000000..7335e775 --- /dev/null +++ b/util/numeric/int128.h @@ -0,0 +1,50 @@ +// Copyright 2014 The Crashpad Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CRASHPAD_UTIL_NUMERIC_INT128_H_ +#define CRASHPAD_UTIL_NUMERIC_INT128_H_ + +#include + +#include "build/build_config.h" + +namespace crashpad { + +//! \brief Stores a 128-bit quantity. +//! +//! This structure is organized so that 128-bit quantities are laid out in +//! memory according to the system’s natural byte order. If a system offers a +//! native 128-bit type, it should be possible to bit_cast<> between that type +//! and this one. +//! +//! This structure is designed to have the same layout, although not the same +//! field names, as the Windows SDK’s `M128A` type from ``. It is +//! provided here instead of in `compat` because it is useful outside of the +//! scope of data structures defined by the Windows SDK. +struct uint128_struct { +#if defined(ARCH_CPU_LITTLE_ENDIAN) || DOXYGEN + //! \brief The low 64 bits of the 128-bit quantity. + uint64_t lo; + + //! \brief The high 64 bits of the 128-bit quantity. + uint64_t hi; +#else + uint64_t hi; + uint64_t lo; +#endif +}; + +} // namespace crashpad + +#endif // CRASHPAD_UTIL_NUMERIC_INT128_H_ diff --git a/util/numeric/int128_test.cc b/util/numeric/int128_test.cc new file mode 100644 index 00000000..a9f5448b --- /dev/null +++ b/util/numeric/int128_test.cc @@ -0,0 +1,42 @@ +// Copyright 2014 The Crashpad Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "util/numeric/int128.h" + +#include "base/basictypes.h" +#include "gtest/gtest.h" + +namespace { + +using namespace crashpad; + +TEST(Int128, UInt128) { +#if defined(ARCH_CPU_LITTLE_ENDIAN) + const uint8_t kBytes[] = + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; +#else + const uint8_t kBytes[] = + {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; +#endif + + uint128_struct uint128; + COMPILE_ASSERT(sizeof(uint128) == sizeof(kBytes), sizes_must_be_equal); + + uint128 = bit_cast(kBytes); + + EXPECT_EQ(0x0706050403020100u, uint128.lo); + EXPECT_EQ(0x0f0e0d0c0b0a0908u, uint128.hi); +} + +} // namespace diff --git a/util/util.gyp b/util/util.gyp index 90228432..ed177776 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -92,6 +92,7 @@ 'misc/uuid.h', 'numeric/checked_range.h', 'numeric/in_range_cast.h', + 'numeric/int128.h', 'numeric/safe_assignment.h', 'posix/process_util.h', 'posix/process_util_mac.cc', @@ -219,6 +220,7 @@ 'misc/uuid_test.cc', 'numeric/checked_range_test.cc', 'numeric/in_range_cast_test.cc', + 'numeric/int128_test.cc', 'posix/process_util_test.cc', 'posix/symbolic_constants_posix_test.cc', 'stdlib/string_number_conversion_test.cc',