linux: Add CheckedLinuxAddressRange and make CheckedAddressRanges copyable

Bug: crashpad:30
Change-Id: Ied2b8659315c09c77054c0a5a82ac37284f27334
Reviewed-on: https://chromium-review.googlesource.com/481036
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Joshua Peraza 2017-04-19 13:45:41 -07:00 committed by Commit Bot
parent f487da4ff2
commit 2815dbdf8e
5 changed files with 47 additions and 10 deletions

View File

@ -0,0 +1,37 @@
// Copyright 2017 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_LINUX_CHECKED_LINUX_ADDRESS_RANGE_H_
#define CRASHPAD_UTIL_LINUX_CHECKED_LINUX_ADDRESS_RANGE_H_
#include "util/linux/address_types.h"
#include "util/numeric/checked_address_range.h"
namespace crashpad {
//! \brief Ensures that a range, composed of a base and a size, does not
//! overflow the pointer type of the process it describes a range in.
//!
//! This class checks bases of type #LinuxVMAddress and sizes of type
//! #LinuxVMSize against a process whose pointer type is either 32 or 64
//! bits wide.
//!
//! Aside from varying the overall range on the basis of a process pointer type
//! width, this class functions very similarly to CheckedRange.
using CheckedLinuxAddressRange =
internal::CheckedAddressRangeGeneric<LinuxVMAddress, LinuxVMSize>;
} // namespace crashpad
#endif // CRASHPAD_UTIL_LINUX_CHECKED_LINUX_ADDRESS_RANGE_H_

View File

@ -14,12 +14,15 @@
#include "util/numeric/checked_address_range.h"
#include "base/format_macros.h"
#include "base/strings/stringprintf.h"
#if defined(OS_MACOSX)
#include <mach/mach.h>
#elif defined(OS_WIN)
#include "util/win/address_types.h"
#elif defined(OS_LINUX) || defined(OS_ANDROID)
#include "util/linux/address_types.h"
#endif // OS_MACOSX
namespace crashpad {
@ -113,8 +116,10 @@ bool CheckedAddressRangeGeneric<ValueType, SizeType>::ContainsRange(
template <class ValueType, class SizeType>
std::string CheckedAddressRangeGeneric<ValueType, SizeType>::AsString() const {
return base::StringPrintf(
"0x%llx + 0x%llx (%s)", Base(), Size(), Is64Bit() ? "64" : "32");
return base::StringPrintf("0x%" PRIx64 " + 0x%" PRIx64 " (%s)",
uint64_t{Base()},
uint64_t{Size()},
Is64Bit() ? "64" : "32");
}
// Explicit instantiations for the cases we use.
@ -122,6 +127,8 @@ std::string CheckedAddressRangeGeneric<ValueType, SizeType>::AsString() const {
template class CheckedAddressRangeGeneric<mach_vm_address_t, mach_vm_size_t>;
#elif defined(OS_WIN)
template class CheckedAddressRangeGeneric<WinVMAddress, WinVMSize>;
#elif defined(OS_LINUX) || defined(OS_ANDROID)
template class CheckedAddressRangeGeneric<LinuxVMAddress, LinuxVMSize>;
#endif // OS_MACOSX
} // namespace internal

View File

@ -143,8 +143,6 @@ class CheckedAddressRangeGeneric {
// uniformly, but these types are too wide for the underlying pointer and size
// types in 32-bit processes.
bool range_ok_;
DISALLOW_COPY_AND_ASSIGN(CheckedAddressRangeGeneric);
};
} // namespace internal

View File

@ -45,6 +45,7 @@
'file/string_file.cc',
'file/string_file.h',
'linux/address_types.h',
'linux/checked_address_range.h',
'linux/process_memory.cc',
'linux/process_memory.h',
'linux/scoped_ptrace_attach.cc',

View File

@ -135,12 +135,6 @@
['exclude', '^net/http_transport_test\\.cc$'],
]
}],
['OS=="android" or OS=="linux"' , {
# Things not yet ported to Android or Linux
'sources/' : [
['exclude', '^numeric/checked_address_range_test\\.cc$'],
]
}],
],
'target_conditions': [
['OS=="android"', {