Commit 74e20c48 authored by Joshua Peraza's avatar Joshua Peraza Committed by Commit Bot

Update Crashpad to b71bde32e7f9f5c9efaae0f6d41db738b55bda11

498c36b82a03 mac arm64: Provide something more useful from
             SystemSnapshot::CPURevison
e3c94b87f0ef [fuchsia] Move //zircon/system/ulib/fdio to //sdk/lib/fdio
fd001f792eb7 build: Make crashpad_dependencies="external" work in the GN
             build
ef8a063055c6 Fuchsia: Propagate failure to initialize exception snapshot
06a688ddc1bc linux: setup a signal stack
9f66d569fb87 linux: put test attachment in temp directory
070b18d326b6 linux: fix alt-stack tests with asan
b71bde32e7f9 linux: fix tests with msan

Change-Id: I509b8ba9053a71709f8ae24a81dc24d8da4e8fcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309758
Commit-Queue: Mark Mentovai <mark@chromium.org>
Auto-Submit: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790529}
parent 472e63c9
...@@ -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: 030c58c2959aa839d247e117ac7b28a71e7dd98c Revision: b71bde32e7f9f5c9efaae0f6d41db738b55bda11
License: Apache 2.0 License: Apache 2.0
License File: crashpad/LICENSE License File: crashpad/LICENSE
Security Critical: yes Security Critical: yes
......
...@@ -175,7 +175,7 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { ...@@ -175,7 +175,7 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) {
] ]
} }
} }
} else if (crashpad_is_standalone) { } else if (crashpad_is_standalone || crashpad_is_external) {
test("crashpad_client_test") { test("crashpad_client_test") {
deps = [ deps = [
"client:client_test", "client:client_test",
......
...@@ -33,12 +33,18 @@ if (current_cpu == "") { ...@@ -33,12 +33,18 @@ if (current_cpu == "") {
current_cpu = target_cpu current_cpu = target_cpu
} }
import("//build/crashpad_buildconfig.gni")
if (crashpad_is_standalone) {
_mini_chromium_dir = "//third_party/mini_chromium/mini_chromium"
} else if (crashpad_is_external) {
_mini_chromium_dir = "//../../mini_chromium/mini_chromium"
}
if (current_os == "win") { if (current_os == "win") {
set_default_toolchain( set_default_toolchain("$_mini_chromium_dir/build:msvc_toolchain_$current_cpu")
"//third_party/mini_chromium/mini_chromium/build:msvc_toolchain_$current_cpu")
} else { } else {
set_default_toolchain( set_default_toolchain("$_mini_chromium_dir/build:gcc_like_toolchain")
"//third_party/mini_chromium/mini_chromium/build:gcc_like_toolchain")
} }
declare_args() { declare_args() {
...@@ -53,20 +59,19 @@ declare_args() { ...@@ -53,20 +59,19 @@ declare_args() {
} }
_default_configs = [ _default_configs = [
"//third_party/mini_chromium/mini_chromium/build:default", "$_mini_chromium_dir/build:default",
"//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors", "$_mini_chromium_dir/build:Wexit_time_destructors",
"//third_party/mini_chromium/mini_chromium/build:Wimplicit_fallthrough", "$_mini_chromium_dir/build:Wimplicit_fallthrough",
] ]
if (crashpad_use_libfuzzer) { if (crashpad_use_libfuzzer) {
_default_configs += [ "//build:crashpad_fuzzer_flags" ] _default_configs += [ "//build:crashpad_fuzzer_flags" ]
} }
_default_executable_configs = _default_executable_configs = _default_configs + [
_default_configs + [ "$_mini_chromium_dir/build:executable",
"//third_party/mini_chromium/mini_chromium/build:executable", "$_mini_chromium_dir/build:win_console",
"//third_party/mini_chromium/mini_chromium/build:win_console", ]
]
set_defaults("source_set") { set_defaults("source_set") {
configs = _default_configs configs = _default_configs
......
...@@ -115,7 +115,7 @@ static_library("client") { ...@@ -115,7 +115,7 @@ static_library("client") {
if (crashpad_is_fuchsia) { if (crashpad_is_fuchsia) {
deps += [ "../third_party/fuchsia" ] deps += [ "../third_party/fuchsia" ]
if (crashpad_is_in_fuchsia) { if (crashpad_is_in_fuchsia) {
deps += [ "//zircon/public/lib/fdio" ] deps += [ "//sdk/lib/fdio" ]
} }
} }
} }
...@@ -175,3 +175,11 @@ source_set("client_test") { ...@@ -175,3 +175,11 @@ source_set("client_test") {
data_deps += [ "../handler:crashpad_handler_console" ] data_deps += [ "../handler:crashpad_handler_console" ]
} }
} }
if (crashpad_is_linux || crashpad_is_android) {
source_set("pthread_create") {
sources = [ "pthread_create_linux.cc" ]
deps = [ ":client" ]
}
}
...@@ -143,6 +143,29 @@ class CrashpadClient { ...@@ -143,6 +143,29 @@ class CrashpadClient {
//! handler as this process' ptracer. -1 indicates that the handler's //! handler as this process' ptracer. -1 indicates that the handler's
//! process ID should be determined by communicating over the socket. //! process ID should be determined by communicating over the socket.
bool SetHandlerSocket(ScopedFileHandle sock, pid_t pid); bool SetHandlerSocket(ScopedFileHandle sock, pid_t pid);
//! \brief Uses `sigaltstack()` to allocate a signal stack for the calling
//! thread.
//!
//! This method allocates an alternate stack to handle signals delivered to
//! the calling thread and should be called early in the lifetime of each
//! thread. Installing an alternate stack allows signals to be delivered in
//! the event that the call stack's stack pointer points to invalid memory,
//! as in the case of stack overflow.
//!
//! This method is called automatically by SetHandlerSocket() and
//! the various StartHandler() methods. It is harmless to call multiple times.
//! A new signal stack will be allocated only if there is no existing stack or
//! the existing stack is too small. The stack will be automatically freed
//! when the thread exits.
//!
//! An application might choose to diligently call this method from the start
//! routine for each thread, call it from a `pthread_create()` wrapper which
//! the application provides, or link the provided "client:pthread_create"
//! target.
//!
//! \return `true` on success. Otherwise `false` with a message logged.
static bool InitializeSignalStackForThread();
#endif // OS_ANDROID || OS_LINUX || DOXYGEN #endif // OS_ANDROID || OS_LINUX || DOXYGEN
#if defined(OS_ANDROID) || DOXYGEN #if defined(OS_ANDROID) || DOXYGEN
......
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
#include "client/crashpad_client.h" #include "client/crashpad_client.h"
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/mman.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/syscall.h> #include <sys/syscall.h>
...@@ -34,8 +37,10 @@ ...@@ -34,8 +37,10 @@
#include "util/linux/scoped_pr_set_dumpable.h" #include "util/linux/scoped_pr_set_dumpable.h"
#include "util/linux/scoped_pr_set_ptracer.h" #include "util/linux/scoped_pr_set_ptracer.h"
#include "util/linux/socket.h" #include "util/linux/socket.h"
#include "util/misc/address_sanitizer.h"
#include "util/misc/from_pointer_cast.h" #include "util/misc/from_pointer_cast.h"
#include "util/posix/double_fork_and_exec.h" #include "util/posix/double_fork_and_exec.h"
#include "util/posix/scoped_mmap.h"
#include "util/posix/signals.h" #include "util/posix/signals.h"
namespace crashpad { namespace crashpad {
...@@ -167,10 +172,14 @@ class SignalHandler { ...@@ -167,10 +172,14 @@ class SignalHandler {
~SignalHandler() = default; ~SignalHandler() = default;
bool Install(const std::set<int>* unhandled_signals) { bool Install(const std::set<int>* unhandled_signals) {
bool signal_stack_initialized =
CrashpadClient::InitializeSignalStackForThread();
DCHECK(signal_stack_initialized);
DCHECK(!handler_); DCHECK(!handler_);
handler_ = this; handler_ = this;
return Signals::InstallCrashHandlers( return Signals::InstallCrashHandlers(
HandleOrReraiseSignal, 0, &old_actions_, unhandled_signals); HandleOrReraiseSignal, SA_ONSTACK, &old_actions_, unhandled_signals);
} }
const ExceptionInformation& GetExceptionInfo() { const ExceptionInformation& GetExceptionInfo() {
...@@ -413,6 +422,99 @@ bool CrashpadClient::SetHandlerSocket(ScopedFileHandle sock, pid_t pid) { ...@@ -413,6 +422,99 @@ bool CrashpadClient::SetHandlerSocket(ScopedFileHandle sock, pid_t pid) {
auto signal_handler = RequestCrashDumpHandler::Get(); auto signal_handler = RequestCrashDumpHandler::Get();
return signal_handler->Initialize(std::move(sock), pid, &unhandled_signals_); return signal_handler->Initialize(std::move(sock), pid, &unhandled_signals_);
} }
// static
bool CrashpadClient::InitializeSignalStackForThread() {
stack_t stack;
if (sigaltstack(nullptr, &stack) != 0) {
PLOG(ERROR) << "sigaltstack";
return false;
}
DCHECK_EQ(stack.ss_flags & SS_ONSTACK, 0);
const size_t page_size = getpagesize();
#if defined(ADDRESS_SANITIZER)
const size_t kStackSize = 2 * ((SIGSTKSZ + page_size - 1) & ~(page_size - 1));
#else
const size_t kStackSize = (SIGSTKSZ + page_size - 1) & ~(page_size - 1);
#endif // ADDRESS_SANITIZER
if (stack.ss_flags & SS_DISABLE || stack.ss_size < kStackSize) {
const size_t kGuardPageSize = page_size;
const size_t kStackAllocSize = kStackSize + 2 * kGuardPageSize;
static void (*stack_destructor)(void*) = [](void* stack_mem) {
const size_t page_size = getpagesize();
const size_t kGuardPageSize = page_size;
#if defined(ADDRESS_SANITIZER)
const size_t kStackSize =
2 * ((SIGSTKSZ + page_size - 1) & ~(page_size - 1));
#else
const size_t kStackSize = (SIGSTKSZ + page_size - 1) & ~(page_size - 1);
#endif // ADDRESS_SANITIZER
const size_t kStackAllocSize = kStackSize + 2 * kGuardPageSize;
stack_t stack;
stack.ss_flags = SS_DISABLE;
if (sigaltstack(&stack, &stack) != 0) {
PLOG(ERROR) << "sigaltstack";
} else if (stack.ss_sp !=
static_cast<char*>(stack_mem) + kGuardPageSize) {
PLOG_IF(ERROR, sigaltstack(&stack, nullptr) != 0) << "sigaltstack";
}
if (munmap(stack_mem, kStackAllocSize) != 0) {
PLOG(ERROR) << "munmap";
}
};
static pthread_key_t stack_key;
static int key_error = []() {
errno = pthread_key_create(&stack_key, stack_destructor);
PLOG_IF(ERROR, errno) << "pthread_key_create";
return errno;
}();
if (key_error) {
return false;
}
auto old_stack = static_cast<char*>(pthread_getspecific(stack_key));
if (old_stack) {
stack.ss_sp = old_stack + kGuardPageSize;
} else {
ScopedMmap stack_mem;
if (!stack_mem.ResetMmap(nullptr,
kStackAllocSize,
PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0)) {
return false;
}
if (mprotect(stack_mem.addr_as<char*>() + kGuardPageSize,
kStackSize,
PROT_READ | PROT_WRITE) != 0) {
PLOG(ERROR) << "mprotect";
return false;
}
stack.ss_sp = stack_mem.addr_as<char*>() + kGuardPageSize;
errno = pthread_setspecific(stack_key, stack_mem.release());
PCHECK(errno == 0) << "pthread_setspecific";
}
stack.ss_size = kStackSize;
stack.ss_flags =
(stack.ss_flags & SS_DISABLE) ? 0 : stack.ss_flags & SS_AUTODISARM;
if (sigaltstack(&stack, nullptr) != 0) {
PLOG(ERROR) << "sigaltstack";
return false;
}
}
return true;
}
#endif // OS_ANDROID || OS_LINUX #endif // OS_ANDROID || OS_LINUX
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
// 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 <dlfcn.h>
#include <pthread.h>
#include "base/logging.h"
#include "client/crashpad_client.h"
namespace {
using StartRoutineType = void* (*)(void*);
struct StartParams {
StartRoutineType start_routine;
void* arg;
};
void* InitializeSignalStackAndStart(StartParams* params) {
crashpad::CrashpadClient::InitializeSignalStackForThread();
StartParams local_params = *params;
delete params;
return local_params.start_routine(local_params.arg);
}
} // namespace
extern "C" {
__attribute__((visibility("default"))) int pthread_create(
pthread_t* thread,
const pthread_attr_t* attr,
StartRoutineType start_routine,
void* arg) {
static const auto next_pthread_create = []() {
const auto next_pthread_create =
reinterpret_cast<decltype(pthread_create)*>(
dlsym(RTLD_NEXT, "pthread_create"));
CHECK(next_pthread_create) << "dlsym: " << dlerror();
return next_pthread_create;
}();
StartParams* params = new StartParams;
params->start_routine = start_routine;
params->arg = arg;
int result = next_pthread_create(
thread,
attr,
reinterpret_cast<StartRoutineType>(InitializeSignalStackAndStart),
params);
if (result != 0) {
delete params;
}
return result;
}
} // extern "C"
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
#include_next <signal.h> #include_next <signal.h>
// Missing from glibc and bionic
#if !defined(SS_AUTODISARM)
#define SS_AUTODISARM (1u << 31)
#endif
// Missing from glibc and bionic-x86_64 // Missing from glibc and bionic-x86_64
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
......
...@@ -156,6 +156,10 @@ if (!crashpad_is_ios) { ...@@ -156,6 +156,10 @@ if (!crashpad_is_ios) {
[ "//third_party/mini_chromium/mini_chromium/build:win_windowed" ] [ "//third_party/mini_chromium/mini_chromium/build:win_windowed" ]
} }
} }
if (crashpad_is_linux) {
deps += [ "../client:pthread_create" ]
}
} }
} }
......
...@@ -24,7 +24,7 @@ namespace internal { ...@@ -24,7 +24,7 @@ namespace internal {
ExceptionSnapshotFuchsia::ExceptionSnapshotFuchsia() = default; ExceptionSnapshotFuchsia::ExceptionSnapshotFuchsia() = default;
ExceptionSnapshotFuchsia::~ExceptionSnapshotFuchsia() = default; ExceptionSnapshotFuchsia::~ExceptionSnapshotFuchsia() = default;
void ExceptionSnapshotFuchsia::Initialize( bool ExceptionSnapshotFuchsia::Initialize(
ProcessReaderFuchsia* process_reader, ProcessReaderFuchsia* process_reader,
zx_koid_t thread_id, zx_koid_t thread_id,
const zx_exception_report_t& exception_report) { const zx_exception_report_t& exception_report) {
...@@ -61,22 +61,26 @@ void ExceptionSnapshotFuchsia::Initialize( ...@@ -61,22 +61,26 @@ void ExceptionSnapshotFuchsia::Initialize(
[thread_id](const ProcessReaderFuchsia::Thread& thread) { [thread_id](const ProcessReaderFuchsia::Thread& thread) {
return thread.id == thread_id; return thread.id == thread_id;
}); });
if (t != threads.end()) { if (t == threads.end()) {
// If no threads have been read, then context_ can't be initalized, and the
// exception snapshot can't be considered initialized_.
return false;
}
#if defined(ARCH_CPU_X86_64) #if defined(ARCH_CPU_X86_64)
context_.architecture = kCPUArchitectureX86_64; context_.architecture = kCPUArchitectureX86_64;
context_.x86_64 = &context_arch_; context_.x86_64 = &context_arch_;
// TODO(fxbug.dev/5496): Add float context once saved in |t|. // TODO(fxbug.dev/5496): Add float context once saved in |t|.
InitializeCPUContextX86_64_NoFloatingPoint(t->general_registers, InitializeCPUContextX86_64_NoFloatingPoint(t->general_registers,
context_.x86_64); context_.x86_64);
#elif defined(ARCH_CPU_ARM64) #elif defined(ARCH_CPU_ARM64)
context_.architecture = kCPUArchitectureARM64; context_.architecture = kCPUArchitectureARM64;
context_.arm64 = &context_arch_; context_.arm64 = &context_arch_;
InitializeCPUContextARM64( InitializeCPUContextARM64(
t->general_registers, t->vector_registers, context_.arm64); t->general_registers, t->vector_registers, context_.arm64);
#else #else
#error Port. #error Port.
#endif #endif
}
if (context_.InstructionPointer() != 0 && if (context_.InstructionPointer() != 0 &&
(exception_ == ZX_EXCP_UNDEFINED_INSTRUCTION || (exception_ == ZX_EXCP_UNDEFINED_INSTRUCTION ||
...@@ -94,6 +98,7 @@ void ExceptionSnapshotFuchsia::Initialize( ...@@ -94,6 +98,7 @@ void ExceptionSnapshotFuchsia::Initialize(
} }
INITIALIZATION_STATE_SET_VALID(initialized_); INITIALIZATION_STATE_SET_VALID(initialized_);
return true;
} }
const CPUContext* ExceptionSnapshotFuchsia::Context() const { const CPUContext* ExceptionSnapshotFuchsia::Context() const {
......
...@@ -44,7 +44,10 @@ class ExceptionSnapshotFuchsia final : public ExceptionSnapshot { ...@@ -44,7 +44,10 @@ class ExceptionSnapshotFuchsia final : public ExceptionSnapshot {
//! \param[in] thread_id The koid of the thread that sustained the exception. //! \param[in] thread_id The koid of the thread that sustained the exception.
//! \param[in] exception_report The `zx_exception_report_t` retrieved from the //! \param[in] exception_report The `zx_exception_report_t` retrieved from the
//! thread in the exception state, corresponding to \a thread_id. //! thread in the exception state, corresponding to \a thread_id.
void Initialize(ProcessReaderFuchsia* process_reader, //!
//! \return `true` if the exception data was initialized, `false` otherwise
//! with an error logged.
bool Initialize(ProcessReaderFuchsia* process_reader,
zx_koid_t thread_id, zx_koid_t thread_id,
const zx_exception_report_t& exception_report); const zx_exception_report_t& exception_report);
...@@ -63,7 +66,7 @@ class ExceptionSnapshotFuchsia final : public ExceptionSnapshot { ...@@ -63,7 +66,7 @@ class ExceptionSnapshotFuchsia final : public ExceptionSnapshot {
#elif defined(ARCH_CPU_ARM64) #elif defined(ARCH_CPU_ARM64)
CPUContextARM64 context_arch_; CPUContextARM64 context_arch_;
#endif #endif
CPUContext context_ = {}; CPUContext context_;
std::vector<uint64_t> codes_; std::vector<uint64_t> codes_;
zx_koid_t thread_id_; zx_koid_t thread_id_;
zx_vaddr_t exception_address_; zx_vaddr_t exception_address_;
......
...@@ -59,9 +59,14 @@ bool ProcessSnapshotFuchsia::InitializeException( ...@@ -59,9 +59,14 @@ bool ProcessSnapshotFuchsia::InitializeException(
zx_koid_t thread_id, zx_koid_t thread_id,
const zx_exception_report_t& report) { const zx_exception_report_t& report) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_); INITIALIZATION_STATE_DCHECK_VALID(initialized_);
exception_.reset(new internal::ExceptionSnapshotFuchsia());
exception_->Initialize(&process_reader_, thread_id, report); std::unique_ptr<internal::ExceptionSnapshotFuchsia> exception(
return true; new internal::ExceptionSnapshotFuchsia());
if (exception->Initialize(&process_reader_, thread_id, report)) {
exception_.swap(exception);
return true;
}
return false;
} }
void ProcessSnapshotFuchsia::GetCrashpadOptions( void ProcessSnapshotFuchsia::GetCrashpadOptions(
......
...@@ -178,10 +178,8 @@ uint32_t SystemSnapshotMac::CPURevision() const { ...@@ -178,10 +178,8 @@ uint32_t SystemSnapshotMac::CPURevision() const {
return (family << 16) | (model << 8) | stepping; return (family << 16) | (model << 8) | stepping;
#elif defined(ARCH_CPU_ARM64) #elif defined(ARCH_CPU_ARM64)
// TODO(macos_arm64): Verify that this is correct, and pack more information // TODO(macos_arm64): Verify and test.
// if feasible. The Apple A12Z returns hw.cputype = 0x100000c and return CastIntSysctlByName<uint32_t>("hw.cpufamily", 0);
// hw.cpusubtype = 2.
return CastIntSysctlByName<uint32_t>("hw.cputype", 0);
#else #else
#error port to your architecture #error port to your architecture
#endif #endif
......
...@@ -152,7 +152,7 @@ static_library("test") { ...@@ -152,7 +152,7 @@ static_library("test") {
if (crashpad_is_fuchsia) { if (crashpad_is_fuchsia) {
public_deps = [ "../third_party/fuchsia" ] public_deps = [ "../third_party/fuchsia" ]
if (crashpad_is_in_fuchsia) { if (crashpad_is_in_fuchsia) {
deps += [ "//zircon/public/lib/fdio" ] deps += [ "//sdk/lib/fdio" ]
} }
} }
} }
......
...@@ -16,4 +16,5 @@ source_set("cpp-httplib") { ...@@ -16,4 +16,5 @@ source_set("cpp-httplib") {
testonly = true testonly = true
include_dirs = [ "cpp-httplib" ] include_dirs = [ "cpp-httplib" ]
sources = [ "cpp-httplib/httplib.h" ] sources = [ "cpp-httplib/httplib.h" ]
deps = [ "../zlib" ]
} }
...@@ -17,7 +17,7 @@ import("../../build/crashpad_buildconfig.gni") ...@@ -17,7 +17,7 @@ import("../../build/crashpad_buildconfig.gni")
if (crashpad_is_in_fuchsia) { if (crashpad_is_in_fuchsia) {
group("fuchsia") { group("fuchsia") {
public_deps = [ public_deps = [
"//zircon/public/lib/fdio", "//sdk/lib/fdio",
"//zircon/public/lib/zx", "//zircon/public/lib/zx",
] ]
} }
......
...@@ -19,6 +19,8 @@ group("base") { ...@@ -19,6 +19,8 @@ group("base") {
public_deps = [ "//base" ] public_deps = [ "//base" ]
} else if (crashpad_is_standalone || crashpad_is_in_fuchsia) { } else if (crashpad_is_standalone || crashpad_is_in_fuchsia) {
public_deps = [ "mini_chromium/base" ] public_deps = [ "mini_chromium/base" ]
} else if (crashpad_is_external) {
public_deps = [ "../../../../mini_chromium/mini_chromium/base" ]
} else if (crashpad_is_in_dart) { } else if (crashpad_is_in_dart) {
public_deps = [ "//third_party/mini_chromium/mini_chromium/base" ] public_deps = [ "//third_party/mini_chromium/mini_chromium/base" ]
} }
......
...@@ -18,8 +18,10 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia || crashpad_is_in_dart) { ...@@ -18,8 +18,10 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia || crashpad_is_in_dart) {
zlib_source = "external" zlib_source = "external"
} else if (!crashpad_is_win && !crashpad_is_fuchsia) { } else if (!crashpad_is_win && !crashpad_is_fuchsia) {
zlib_source = "system" zlib_source = "system"
} else { } else if (crashpad_is_standalone) {
zlib_source = "embedded" zlib_source = "embedded"
} else if (crashpad_is_external) {
zlib_source = "external_with_embedded_build"
} }
config("zlib_config") { config("zlib_config") {
...@@ -30,6 +32,9 @@ config("zlib_config") { ...@@ -30,6 +32,9 @@ config("zlib_config") {
} else if (zlib_source == "embedded") { } else if (zlib_source == "embedded") {
defines = [ "CRASHPAD_ZLIB_SOURCE_EMBEDDED" ] defines = [ "CRASHPAD_ZLIB_SOURCE_EMBEDDED" ]
include_dirs = [ "zlib" ] include_dirs = [ "zlib" ]
} else if (zlib_source == "external_with_embedded_build") {
defines = [ "CRASHPAD_ZLIB_SOURCE_EXTERNAL_WITH_EMBEDDED_BUILD" ]
include_dirs = [ "../../../../zlib/src" ]
} }
} }
...@@ -43,36 +48,41 @@ if (zlib_source == "external") { ...@@ -43,36 +48,41 @@ if (zlib_source == "external") {
public_configs = [ ":zlib_config" ] public_configs = [ ":zlib_config" ]
libs = [ "z" ] libs = [ "z" ]
} }
} else if (zlib_source == "embedded") { } else if (zlib_source == "embedded" ||
zlib_source == "external_with_embedded_build") {
static_library("zlib") { static_library("zlib") {
if (zlib_source == "embedded") {
zlib_dir = "zlib"
} else if (zlib_source == "external_with_embedded_build") {
zlib_dir = "../../../../zlib/src"
}
sources = [ sources = [
"zlib/adler32.c", "$zlib_dir/adler32.c",
"zlib/compress.c", "$zlib_dir/compress.c",
"zlib/crc32.c", "$zlib_dir/crc32.c",
"zlib/crc32.h", "$zlib_dir/crc32.h",
"zlib/deflate.c", "$zlib_dir/deflate.c",
"zlib/deflate.h", "$zlib_dir/deflate.h",
"zlib/gzclose.c", "$zlib_dir/gzclose.c",
"zlib/gzguts.h", "$zlib_dir/gzguts.h",
"zlib/gzlib.c", "$zlib_dir/gzlib.c",
"zlib/gzread.c", "$zlib_dir/gzread.c",
"zlib/gzwrite.c", "$zlib_dir/gzwrite.c",
"zlib/infback.c", "$zlib_dir/infback.c",
"zlib/inffast.c", "$zlib_dir/inffast.c",
"zlib/inffast.h", "$zlib_dir/inffast.h",
"zlib/inffixed.h", "$zlib_dir/inffixed.h",
"zlib/inflate.c", "$zlib_dir/inflate.c",
"zlib/inflate.h", "$zlib_dir/inflate.h",
"zlib/inftrees.c", "$zlib_dir/inftrees.c",
"zlib/inftrees.h", "$zlib_dir/inftrees.h",
"zlib/names.h", "$zlib_dir/trees.c",
"zlib/trees.c", "$zlib_dir/trees.h",
"zlib/trees.h", "$zlib_dir/uncompr.c",
"zlib/uncompr.c", "$zlib_dir/zconf.h",
"zlib/zconf.h", "$zlib_dir/zlib.h",
"zlib/zlib.h", "$zlib_dir/zutil.c",
"zlib/zutil.c", "$zlib_dir/zutil.h",
"zlib/zutil.h",
"zlib_crashpad.h", "zlib_crashpad.h",
] ]
...@@ -102,28 +112,37 @@ if (zlib_source == "external") { ...@@ -102,28 +112,37 @@ if (zlib_source == "external") {
] ]
} }
configs -= [ if (crashpad_is_standalone) {
"//third_party/mini_chromium/mini_chromium/build:Wimplicit_fallthrough", configs -= [
] "//third_party/mini_chromium/mini_chromium/build:Wimplicit_fallthrough",
if (current_cpu == "x86" || current_cpu == "x64") {
sources += [
"zlib/crc_folding.c",
"zlib/fill_window_sse.c",
"zlib/x86.c",
"zlib/x86.h",
] ]
if (!crashpad_is_win || crashpad_is_clang) { } else if (crashpad_is_external) {
cflags += [ configs -=
"-msse4.2", [ "//../../mini_chromium/mini_chromium/build:Wimplicit_fallthrough" ]
"-mpclmul", }
if (zlib_source == "embedded") {
sources += [ "$zlib_dir/names.h" ]
if (current_cpu == "x86" || current_cpu == "x64") {
sources += [
"$zlib_dir/crc_folding.c",
"$zlib_dir/fill_window_sse.c",
"$zlib_dir/x86.c",
"$zlib_dir/x86.h",
] ]
if (!crashpad_is_win || crashpad_is_clang) {
cflags += [
"-msse4.2",
"-mpclmul",
]
}
if (crashpad_is_clang) {
cflags += [ "-Wno-incompatible-pointer-types" ]
}
} else {
sources += [ "$zlib_dir/simd_stub.c" ]
} }
if (crashpad_is_clang) {
cflags += [ "-Wno-incompatible-pointer-types" ]
}
} else {
sources += [ "zlib/simd_stub.c" ]
} }
} }
} }
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
// available at any other location in the source tree. It will #include the // available at any other location in the source tree. It will #include the
// proper <zlib.h> depending on how the build has been configured. // proper <zlib.h> depending on how the build has been configured.
#if defined(CRASHPAD_ZLIB_SOURCE_SYSTEM) || \ #if defined(CRASHPAD_ZLIB_SOURCE_SYSTEM) || \
defined(CRASHPAD_ZLIB_SOURCE_EXTERNAL) defined(CRASHPAD_ZLIB_SOURCE_EXTERNAL) || \
defined(CRASHPAD_ZLIB_SOURCE_EXTERNAL_WITH_EMBEDDED_BUILD)
#include <zlib.h> #include <zlib.h>
#elif defined(CRASHPAD_ZLIB_SOURCE_EMBEDDED) #elif defined(CRASHPAD_ZLIB_SOURCE_EMBEDDED)
#include "third_party/zlib/zlib/zlib.h" #include "third_party/zlib/zlib/zlib.h"
......
...@@ -25,6 +25,8 @@ if (crashpad_is_in_chromium) { ...@@ -25,6 +25,8 @@ if (crashpad_is_in_chromium) {
if (crashpad_is_mac || crashpad_is_ios) { if (crashpad_is_mac || crashpad_is_ios) {
if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) {
import("//build/config/sysroot.gni") import("//build/config/sysroot.gni")
} else if (crashpad_is_external) {
import("../../../mini_chromium/mini_chromium/build/sysroot.gni")
} else { } else {
import("//third_party/mini_chromium/mini_chromium/build/sysroot.gni") import("//third_party/mini_chromium/mini_chromium/build/sysroot.gni")
} }
...@@ -627,6 +629,9 @@ if (!crashpad_is_android && !crashpad_is_ios) { ...@@ -627,6 +629,9 @@ if (!crashpad_is_android && !crashpad_is_ios) {
if (crashpad_is_standalone) { if (crashpad_is_standalone) {
remove_configs = [ "//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors" ] remove_configs = [ "//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors" ]
} else if (crashpad_is_external) {
remove_configs =
[ "//../../mini_chromium/mini_chromium/build:Wexit_time_destructors" ]
} }
if (crashpad_is_win) { if (crashpad_is_win) {
......
...@@ -121,4 +121,11 @@ bool ScopedMmap::Mprotect(int prot) { ...@@ -121,4 +121,11 @@ bool ScopedMmap::Mprotect(int prot) {
return true; return true;
} }
void* ScopedMmap::release() {
void* retval = addr_;
addr_ = MAP_FAILED;
len_ = 0;
return retval;
}
} // namespace crashpad } // namespace crashpad
...@@ -77,6 +77,10 @@ class ScopedMmap { ...@@ -77,6 +77,10 @@ class ScopedMmap {
//! \return `true` on success. `false` on failure, with a message logged. //! \return `true` on success. `false` on failure, with a message logged.
bool Mprotect(int prot); bool Mprotect(int prot);
//! \brief Returns the base address of the memory-mapped region and releases
//! ownership.
void* release();
//! \return Whether this object is managing a valid memory-mapped region. //! \return Whether this object is managing a valid memory-mapped region.
bool is_valid() const { return addr_ != MAP_FAILED; } bool is_valid() const { return addr_ != MAP_FAILED; }
......
...@@ -403,6 +403,19 @@ TEST(ScopedMmapDeathTest, Mprotect) { ...@@ -403,6 +403,19 @@ TEST(ScopedMmapDeathTest, Mprotect) {
*addr = 2; *addr = 2;
} }
TEST(ScopedMmapTest, Release) {
ScopedMmap mapping;
const size_t kPageSize = base::checked_cast<size_t>(getpagesize());
ASSERT_TRUE(ScopedMmapResetMmap(&mapping, kPageSize));
ASSERT_TRUE(mapping.is_valid());
ScopedMmap mapping2;
ASSERT_TRUE(mapping2.ResetAddrLen(mapping.release(), kPageSize));
EXPECT_TRUE(mapping2.is_valid());
EXPECT_FALSE(mapping.is_valid());
}
} // namespace } // namespace
} // namespace test } // namespace test
} // namespace crashpad } // namespace crashpad
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