Commit cbbd217b authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

Update Crashpad to 311a5a2fdd5b6be8cee01b66991933397094204f

6835b8e29db1 Roll buildtools/ afc5b798c..4164a3056 (9 commits)
9a31d3f8e981 Print thread state after failure to suspend
4e2a190ad6e6 [ios] Bring up first draft thread and memory snapshot
296501351816 Prepare crashpad mig stuff for -Wunreachable-code in
             chromium_code
af2be80bdb8a android: configure a native test suite
b75c5783735e linux: disable arguments test on old kernels
311a5a2fdd5b Fix chromium build

Change-Id: I031f48b23b71e68eb306918240dffe3851591184
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119550
Commit-Queue: Mark Mentovai <mark@chromium.org>
Auto-Submit: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753228}
parent 5016701f
...@@ -2,7 +2,7 @@ Name: Crashpad ...@@ -2,7 +2,7 @@ Name: Crashpad
Short Name: crashpad Short Name: crashpad
URL: https://crashpad.chromium.org/ URL: https://crashpad.chromium.org/
Version: unknown Version: unknown
Revision: 1d75af9bf5918fa1c365a4ac696f038e6028a30b Revision: 311a5a2fdd5b6be8cee01b66991933397094204f
License: Apache 2.0 License: Apache 2.0
License File: crashpad/LICENSE License File: crashpad/LICENSE
Security Critical: yes Security Critical: yes
...@@ -37,4 +37,3 @@ $ git am --3way --message-id -p4 /tmp/patchdir ...@@ -37,4 +37,3 @@ $ git am --3way --message-id -p4 /tmp/patchdir
Local Modifications: Local Modifications:
- codereview.settings has been excluded. - codereview.settings has been excluded.
- elf_image_reader_fuzzer is enabled only when use_fuzzing_engine is true. - elf_image_reader_fuzzer is enabled only when use_fuzzing_engine is true.
- cherry-pick upstream 296501351816
...@@ -52,6 +52,30 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { ...@@ -52,6 +52,30 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) {
# TODO(fuchsia:46559): Fix the leaks and remove this. # TODO(fuchsia:46559): Fix the leaks and remove this.
deps += [ "//build/config/sanitizers:suppress-lsan.DO-NOT-USE-THIS" ] deps += [ "//build/config/sanitizers:suppress-lsan.DO-NOT-USE-THIS" ]
} }
if (crashpad_is_android) {
use_raw_android_executable = true
copy("crashpad_test_data") {
testonly = true
sources = [
"test/test_paths_test_data_root.txt",
"util/net/testdata/ascii_http_body.txt",
"util/net/testdata/binary_http_body.dat",
]
outputs = [
"$root_out_dir/crashpad_test_data/{{source}}",
]
}
deps += [ ":crashpad_test_data" ]
extra_dist_files = [
"$root_out_dir/crashpad_handler",
"$root_out_dir/crashpad_test_test_multiprocess_exec_test_child",
"$root_out_dir/crashpad_test_data",
]
}
} }
if (crashpad_is_in_fuchsia) { if (crashpad_is_in_fuchsia) {
......
...@@ -25,7 +25,7 @@ vars = { ...@@ -25,7 +25,7 @@ vars = {
deps = { deps = {
'buildtools': 'buildtools':
Var('chromium_git') + '/chromium/src/buildtools.git@' + Var('chromium_git') + '/chromium/src/buildtools.git@' +
'afc5b798c72905e85f9991152be878714c579958', '4164a305626786b1912d467003acf4c4995bec7d',
'crashpad/third_party/edo/edo': { 'crashpad/third_party/edo/edo': {
'url': Var('chromium_git') + '/external/github.com/google/eDistantObject.git@' + 'url': Var('chromium_git') + '/external/github.com/google/eDistantObject.git@' +
'243fc89ae95b24717d41f3786f6a9abeeef87c92', '243fc89ae95b24717d41f3786f6a9abeeef87c92',
......
...@@ -17,6 +17,9 @@ import("../build/crashpad_fuzzer_test.gni") ...@@ -17,6 +17,9 @@ import("../build/crashpad_fuzzer_test.gni")
if (crashpad_is_in_chromium) { if (crashpad_is_in_chromium) {
import("//build/config/compiler/compiler.gni") import("//build/config/compiler/compiler.gni")
# Prevent Chromium source assignment filters from being inherited.
set_sources_assignment_filter([])
} }
static_library("snapshot") { static_library("snapshot") {
...@@ -110,15 +113,20 @@ static_library("snapshot") { ...@@ -110,15 +113,20 @@ static_library("snapshot") {
if (crashpad_is_ios) { if (crashpad_is_ios) {
sources += [ sources += [
"ios/memory_snapshot_ios.cc",
"ios/memory_snapshot_ios.h",
"ios/module_snapshot_ios.cc", "ios/module_snapshot_ios.cc",
"ios/module_snapshot_ios.h", "ios/module_snapshot_ios.h",
"ios/process_snapshot_ios.cc", "ios/process_snapshot_ios.cc",
"ios/process_snapshot_ios.h", "ios/process_snapshot_ios.h",
"ios/thread_snapshot_ios.cc",
"ios/thread_snapshot_ios.h",
"mac/cpu_context_mac.cc",
"mac/cpu_context_mac.h",
] ]
} }
if (crashpad_is_linux || crashpad_is_android) { if (crashpad_is_linux || crashpad_is_android) {
set_sources_assignment_filter([])
sources += [ sources += [
"linux/cpu_context_linux.cc", "linux/cpu_context_linux.cc",
"linux/cpu_context_linux.h", "linux/cpu_context_linux.h",
......
// Copyright 2020 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 "snapshot/ios/memory_snapshot_ios.h"
namespace crashpad {
namespace internal {
void MemorySnapshotIOS::Initialize(vm_address_t address, vm_size_t size) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
address_ = address;
size_ = base::checked_cast<size_t>(size);
// TODO(justincohen): This is temporary, as MemorySnapshotIOS will likely be
// able to point directly to the deserialized data dump rather than copying
// data around.
buffer_ = std::unique_ptr<uint8_t[]>(new uint8_t[size_]);
memcpy(buffer_.get(), reinterpret_cast<void*>(address_), size_);
INITIALIZATION_STATE_SET_VALID(initialized_);
}
uint64_t MemorySnapshotIOS::Address() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
return address_;
}
size_t MemorySnapshotIOS::Size() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
return size_;
}
bool MemorySnapshotIOS::Read(Delegate* delegate) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
if (size_ == 0) {
return delegate->MemorySnapshotDelegateRead(nullptr, size_);
}
return delegate->MemorySnapshotDelegateRead(buffer_.get(), size_);
}
const MemorySnapshot* MemorySnapshotIOS::MergeWithOtherSnapshot(
const MemorySnapshot* other) const {
CheckedRange<uint64_t, size_t> merged(0, 0);
if (!LoggingDetermineMergedRange(this, other, &merged))
return nullptr;
auto result = std::make_unique<MemorySnapshotIOS>();
result->Initialize(merged.base(), merged.size());
return result.release();
}
} // namespace internal
} // namespace crashpad
// Copyright 2020 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_SNAPSHOT_IOS_MEMORY_SNAPSHOT_IOS_H_
#define CRASHPAD_SNAPSHOT_IOS_MEMORY_SNAPSHOT_IOS_H_
#include "base/macros.h"
#include "snapshot/memory_snapshot.h"
#include "util/misc/address_types.h"
#include "util/misc/initialization_state_dcheck.h"
namespace crashpad {
namespace internal {
//! \brief A MemorySnapshot of a memory region.
class MemorySnapshotIOS final : public MemorySnapshot {
public:
MemorySnapshotIOS() = default;
~MemorySnapshotIOS() = default;
//! \brief Initializes the object.
//!
//! \param[in] address The base address of the memory region to snapshot.
//! \param[in] size The size of the memory region to snapshot.
void Initialize(vm_address_t address, vm_size_t size);
// MemorySnapshot:
uint64_t Address() const override;
size_t Size() const override;
bool Read(Delegate* delegate) const override;
const MemorySnapshot* MergeWithOtherSnapshot(
const MemorySnapshot* other) const override;
private:
template <class T>
friend const MemorySnapshot* MergeWithOtherSnapshotImpl(
const T* self,
const MemorySnapshot* other);
// TODO(justincohen): This is temporary until deserialization is worked out.
std::unique_ptr<uint8_t[]> buffer_;
vm_address_t address_;
vm_size_t size_;
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(MemorySnapshotIOS);
};
} // namespace internal
} // namespace crashpad
#endif // CRASHPAD_SNAPSHOT_IOS_MEMORY_SNAPSHOT_IOS_H_
...@@ -26,6 +26,7 @@ namespace crashpad { ...@@ -26,6 +26,7 @@ namespace crashpad {
ProcessSnapshotIOS::ProcessSnapshotIOS() ProcessSnapshotIOS::ProcessSnapshotIOS()
: ProcessSnapshot(), : ProcessSnapshot(),
threads_(),
modules_(), modules_(),
report_id_(), report_id_(),
client_id_(), client_id_(),
...@@ -43,6 +44,7 @@ bool ProcessSnapshotIOS::Initialize() { ...@@ -43,6 +44,7 @@ bool ProcessSnapshotIOS::Initialize() {
return false; return false;
} }
InitializeThreads();
InitializeModules(); InitializeModules();
INITIALIZATION_STATE_SET_VALID(initialized_); INITIALIZATION_STATE_SET_VALID(initialized_);
...@@ -96,7 +98,11 @@ const SystemSnapshot* ProcessSnapshotIOS::System() const { ...@@ -96,7 +98,11 @@ const SystemSnapshot* ProcessSnapshotIOS::System() const {
std::vector<const ThreadSnapshot*> ProcessSnapshotIOS::Threads() const { std::vector<const ThreadSnapshot*> ProcessSnapshotIOS::Threads() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_); INITIALIZATION_STATE_DCHECK_VALID(initialized_);
return std::vector<const ThreadSnapshot*>(); std::vector<const ThreadSnapshot*> threads;
for (const auto& thread : threads_) {
threads.push_back(thread.get());
}
return threads;
} }
std::vector<const ModuleSnapshot*> ProcessSnapshotIOS::Modules() const { std::vector<const ModuleSnapshot*> ProcessSnapshotIOS::Modules() const {
...@@ -140,6 +146,25 @@ const ProcessMemory* ProcessSnapshotIOS::Memory() const { ...@@ -140,6 +146,25 @@ const ProcessMemory* ProcessSnapshotIOS::Memory() const {
return nullptr; return nullptr;
} }
void ProcessSnapshotIOS::InitializeThreads() {
mach_msg_type_number_t thread_count = 0;
const thread_act_array_t threads =
internal::ThreadSnapshotIOS::GetThreads(&thread_count);
for (uint32_t thread_index = 0; thread_index < thread_count; ++thread_index) {
thread_t thread = threads[thread_index];
auto thread_snapshot = std::make_unique<internal::ThreadSnapshotIOS>();
if (thread_snapshot->Initialize(thread)) {
threads_.push_back(std::move(thread_snapshot));
}
mach_port_deallocate(mach_task_self(), thread);
}
// TODO(justincohen): This dealloc above and below needs to move with the
// call to task_threads inside internal::ThreadSnapshotIOS::GetThreads.
vm_deallocate(mach_task_self(),
reinterpret_cast<vm_address_t>(threads),
sizeof(thread_t) * thread_count);
}
void ProcessSnapshotIOS::InitializeModules() { void ProcessSnapshotIOS::InitializeModules() {
const dyld_all_image_infos* image_infos = const dyld_all_image_infos* image_infos =
internal::ModuleSnapshotIOS::DyldAllImageInfo(); internal::ModuleSnapshotIOS::DyldAllImageInfo();
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#include <vector> #include <vector>
#include "snapshot/ios/module_snapshot_ios.h" #include "snapshot/ios/module_snapshot_ios.h"
#include "snapshot/ios/thread_snapshot_ios.h"
#include "snapshot/process_snapshot.h" #include "snapshot/process_snapshot.h"
#include "snapshot/thread_snapshot.h"
#include "snapshot/unloaded_module_snapshot.h" #include "snapshot/unloaded_module_snapshot.h"
namespace crashpad { namespace crashpad {
...@@ -60,6 +62,10 @@ class ProcessSnapshotIOS final : public ProcessSnapshot { ...@@ -60,6 +62,10 @@ class ProcessSnapshotIOS final : public ProcessSnapshot {
// Initializes modules_ on behalf of Initialize(). // Initializes modules_ on behalf of Initialize().
void InitializeModules(); void InitializeModules();
// Initializes threads_ on behalf of Initialize().
void InitializeThreads();
std::vector<std::unique_ptr<internal::ThreadSnapshotIOS>> threads_;
std::vector<std::unique_ptr<internal::ModuleSnapshotIOS>> modules_; std::vector<std::unique_ptr<internal::ModuleSnapshotIOS>> modules_;
UUID report_id_; UUID report_id_;
UUID client_id_; UUID client_id_;
......
// Copyright 2020 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_SNAPSHOT_IOS_THREAD_SNAPSHOT_IOS_H_
#define CRASHPAD_SNAPSHOT_IOS_THREAD_SNAPSHOT_IOS_H_
#include "base/macros.h"
#include "build/build_config.h"
#include "snapshot/cpu_context.h"
#include "snapshot/ios/memory_snapshot_ios.h"
#include "snapshot/thread_snapshot.h"
#include "util/misc/initialization_state_dcheck.h"
namespace crashpad {
namespace internal {
//! \brief A ThreadSnapshot of a thread on an iOS system.
class ThreadSnapshotIOS final : public ThreadSnapshot {
public:
ThreadSnapshotIOS();
~ThreadSnapshotIOS() override;
//! \brief Initializes the object.
//!
//! \brief thread The mach thread used to initialize this object.
bool Initialize(thread_t thread);
//! \brief Returns an array of thread_t threads.
//!
//! \param[out] count The number of threads returned.
//!
//! \return An array of of size \a count threads.
static thread_act_array_t GetThreads(mach_msg_type_number_t* count);
// ThreadSnapshot:
const CPUContext* Context() const override;
const MemorySnapshot* Stack() const override;
uint64_t ThreadID() const override;
int SuspendCount() const override;
int Priority() const override;
uint64_t ThreadSpecificDataAddress() const override;
std::vector<const MemorySnapshot*> ExtraMemory() const override;
private:
#if defined(ARCH_CPU_X86_64)
CPUContextX86_64 context_x86_64_;
#elif defined(ARCH_CPU_ARM64)
CPUContextARM64 context_arm64_;
#else
#error Port.
#endif // ARCH_CPU_X86_64
CPUContext context_;
MemorySnapshotIOS stack_;
uint64_t thread_id_;
uint64_t thread_specific_data_address_;
int suspend_count_;
int priority_;
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(ThreadSnapshotIOS);
};
} // namespace internal
} // namespace crashpad
#endif // CRASHPAD_SNAPSHOT_IOS_THREAD_SNAPSHOT_IOS_H_
...@@ -436,6 +436,32 @@ void InitializeCPUContextX86_64(CPUContextX86_64* context, ...@@ -436,6 +436,32 @@ void InitializeCPUContextX86_64(CPUContextX86_64* context,
} // namespace internal } // namespace internal
#elif defined(ARCH_CPU_ARM_FAMILY)
namespace internal {
void InitializeCPUContextARM64(CPUContextARM64* context,
const arm_thread_state64_t* arm_thread_state64,
const arm_neon_state64_t* arm_neon_state64) {
// The structures of context->regs and arm_thread_state64->__x are laid out
// identically for this copy, even though the members are organized
// differently. Because of this difference, there can't be a static assert
// similar to the one below for fpsimd.
memcpy(context->regs, arm_thread_state64->__x, sizeof(context->regs));
context->sp = arm_thread_state64->__sp;
context->pc = arm_thread_state64->__pc;
context->spsr =
static_cast<decltype(context->spsr)>(arm_thread_state64->__cpsr);
static_assert(sizeof(context->fpsimd) == sizeof(arm_neon_state64->__v),
"fpsimd context size mismatch");
memcpy(context->fpsimd, arm_neon_state64->__v, sizeof(arm_neon_state64->__v));
context->fpsr = arm_neon_state64->__fpsr;
context->fpcr = arm_neon_state64->__fpcr;
}
} // namespace internal
#endif #endif
} // namespace crashpad } // namespace crashpad
...@@ -108,6 +108,17 @@ void InitializeCPUContextX86_64(CPUContextX86_64* context, ...@@ -108,6 +108,17 @@ void InitializeCPUContextX86_64(CPUContextX86_64* context,
const x86_float_state64_t* x86_float_state64, const x86_float_state64_t* x86_float_state64,
const x86_debug_state64_t* x86_debug_state64); const x86_debug_state64_t* x86_debug_state64);
#elif defined(ARCH_CPU_ARM_FAMILY) || DOXYGEN
//! \brief Initializes a CPUContextARM64 structure from native context
//! structures.
//!
//! \param[out] context The CPUContextARM64 structure to initialize.
//! \param[in] arm_thread_state64 The state of the thread’s integer registers.
//! \param[in] arm_neon_state64 The state of the thread’s floating-point
//! registers.
void InitializeCPUContextARM64(CPUContextARM64* context,
const arm_thread_state64_t* arm_thread_state64,
const arm_neon_state64_t* arm_neon_state64);
#endif #endif
} // namespace internal } // namespace internal
......
...@@ -73,6 +73,8 @@ int main(int argc, char* argv[]) { ...@@ -73,6 +73,8 @@ int main(int argc, char* argv[]) {
// runner. // runner.
const bool use_chromium_test_launcher = const bool use_chromium_test_launcher =
!crashpad::test::WinChildProcess::IsChildProcess(); !crashpad::test::WinChildProcess::IsChildProcess();
#elif defined(OS_ANDROID)
constexpr bool use_chromium_test_launcher = false;
#else // OS_WIN #else // OS_WIN
constexpr bool use_chromium_test_launcher = true; constexpr bool use_chromium_test_launcher = true;
#endif // OS_WIN #endif // OS_WIN
......
...@@ -69,10 +69,15 @@ base::FilePath TestDataRootInternal() { ...@@ -69,10 +69,15 @@ base::FilePath TestDataRootInternal() {
// out/{Debug,Release} relative to the Crashpad root. // out/{Debug,Release} relative to the Crashpad root.
base::FilePath executable_path; base::FilePath executable_path;
if (Paths::Executable(&executable_path)) { if (Paths::Executable(&executable_path)) {
#if defined(OS_ANDROID)
base::FilePath candidate = executable_path.DirName()
.Append("crashpad_test_data");
#else
base::FilePath candidate = base::FilePath candidate =
base::FilePath(executable_path.DirName() base::FilePath(executable_path.DirName()
.Append(base::FilePath::kParentDirectory) .Append(base::FilePath::kParentDirectory)
.Append(base::FilePath::kParentDirectory)); .Append(base::FilePath::kParentDirectory));
#endif
if (IsTestDataRoot(candidate)) { if (IsTestDataRoot(candidate)) {
return candidate; return candidate;
} }
......
...@@ -41,7 +41,7 @@ ScopedTaskSuspend::ScopedTaskSuspend(const zx::process& process) { ...@@ -41,7 +41,7 @@ ScopedTaskSuspend::ScopedTaskSuspend(const zx::process& process) {
for (const auto& thread : GetThreadHandles(process)) { for (const auto& thread : GetThreadHandles(process)) {
// We omit the crashed thread (blocked in an exception) as it is technically // We omit the crashed thread (blocked in an exception) as it is technically
// not suspended, cf. ZX-3772. // not suspended, cf. ZX-3772.
zx_info_thread info; zx_info_thread_t info;
if (thread.get_info( if (thread.get_info(
ZX_INFO_THREAD, &info, sizeof(info), nullptr, nullptr) == ZX_OK) { ZX_INFO_THREAD, &info, sizeof(info), nullptr, nullptr) == ZX_OK) {
if (info.state == ZX_THREAD_STATE_BLOCKED_EXCEPTION) { if (info.state == ZX_THREAD_STATE_BLOCKED_EXCEPTION) {
...@@ -52,8 +52,16 @@ ScopedTaskSuspend::ScopedTaskSuspend(const zx::process& process) { ...@@ -52,8 +52,16 @@ ScopedTaskSuspend::ScopedTaskSuspend(const zx::process& process) {
zx_signals_t observed = 0u; zx_signals_t observed = 0u;
const zx_status_t wait_status = thread.wait_one( const zx_status_t wait_status = thread.wait_one(
ZX_THREAD_SUSPENDED, zx::deadline_after(zx::msec(50)), &observed); ZX_THREAD_SUSPENDED, zx::deadline_after(zx::msec(50)), &observed);
ZX_LOG_IF(ERROR, wait_status != ZX_OK, wait_status) if (wait_status != ZX_OK) {
<< "thread failed to suspend"; zx_info_thread_t info = {};
zx_status_t info_status = thread.get_info(
ZX_INFO_THREAD, &info, sizeof(info), nullptr, nullptr);
ZX_LOG(ERROR, wait_status) << "thread failed to suspend";
LOG(ERROR) << "Thread info status " << info_status;
if (info_status == ZX_OK) {
LOG(ERROR) << "Thread state " << info.state;
}
}
} }
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "util/posix/process_info.h" #include "util/posix/process_info.h"
#include <sys/utsname.h>
#include <time.h> #include <time.h>
#include <algorithm> #include <algorithm>
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -29,6 +31,7 @@ ...@@ -29,6 +31,7 @@
#include "test/multiprocess.h" #include "test/multiprocess.h"
#include "util/file/file_io.h" #include "util/file/file_io.h"
#include "util/misc/implicit_cast.h" #include "util/misc/implicit_cast.h"
#include "util/string/split_string.h"
#if defined(OS_LINUX) || defined(OS_ANDROID) #if defined(OS_LINUX) || defined(OS_ANDROID)
#include "util/linux/direct_ptrace_connection.h" #include "util/linux/direct_ptrace_connection.h"
...@@ -93,11 +96,39 @@ void TestProcessSelfOrClone(const ProcessInfo& process_info) { ...@@ -93,11 +96,39 @@ void TestProcessSelfOrClone(const ProcessInfo& process_info) {
time(&now); time(&now);
EXPECT_LE(start_time.tv_sec, now); EXPECT_LE(start_time.tv_sec, now);
const std::vector<std::string>& expect_argv = GetMainArguments();
#if defined(OS_ANDROID) || defined(OS_LINUX)
// Prior to Linux 4.2, the kernel only allowed reading a single page from
// /proc/<pid>/cmdline, causing any further arguments to be truncated. Disable
// testing arguments in this case.
// TODO(jperaza): The main arguments are stored on the main thread's stack
// (and so should be included in dumps automatically), and
// ProcessInfo::Arguments() might be updated to read the arguments directly,
// rather than via procfs on older kernels.
utsname uts;
ASSERT_EQ(uname(&uts), 0) << ErrnoMessage("uname");
std::vector<std::string> parts = SplitString(uts.release, '.');
ASSERT_GE(parts.size(), 2u);
int major, minor;
ASSERT_TRUE(base::StringToInt(parts[0], &major));
ASSERT_TRUE(base::StringToInt(parts[1], &minor));
size_t argv_size = 0;
for (const auto& arg : expect_argv) {
argv_size += arg.size() + 1;
}
if ((major < 4 || (major == 4 && minor < 2)) &&
argv_size > static_cast<size_t>(getpagesize())) {
return;
}
#endif // OS_ANDROID || OS_LINUX
std::vector<std::string> argv; std::vector<std::string> argv;
ASSERT_TRUE(process_info.Arguments(&argv)); ASSERT_TRUE(process_info.Arguments(&argv));
const std::vector<std::string>& expect_argv = GetMainArguments();
// expect_argv always contains the initial view of the arguments at the time // expect_argv always contains the initial view of the arguments at the time
// the program was invoked. argv may contain this view, or it may contain the // the program was invoked. argv may contain this view, or it may contain the
// current view of arguments after gtest argv processing. argv may be a subset // current view of arguments after gtest argv processing. argv may be a subset
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment