mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Add uint128_struct and its test.
This will be used in the upcoming Minidump context structures. This also updates mini_chromium to ba9b15f1b6a7 to pick up: ba9b15f1b6a7 Make bit_cast available in C++11 mode. R=rsesek@chromium.org Review URL: https://codereview.chromium.org/583283003
This commit is contained in:
parent
0d8f67c1f5
commit
fee5d8aea9
2
DEPS
2
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 = [
|
||||
|
50
util/numeric/int128.h
Normal file
50
util/numeric/int128.h
Normal file
@ -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 <stdint.h>
|
||||
|
||||
#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 `<winnt.h>`. 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_
|
42
util/numeric/int128_test.cc
Normal file
42
util/numeric/int128_test.cc
Normal file
@ -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<uint128_struct>(kBytes);
|
||||
|
||||
EXPECT_EQ(0x0706050403020100u, uint128.lo);
|
||||
EXPECT_EQ(0x0f0e0d0c0b0a0908u, uint128.hi);
|
||||
}
|
||||
|
||||
} // namespace
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user