Commit 452bf634 authored by Mostyn Bramley-Moore's avatar Mostyn Bramley-Moore Committed by Commit Bot

[jumbo] use RunningOnValgrind from dynamic_annotations

dynamic_annotations is a small library intended to help tsan code
coexist with valgrind.  This CL makes the linux sandbox code use
the RunningOnValgrind() function instead of (multiply) defining its
own version, and does not use the annotations which are being phased
out.

TODO: remove valgrind checks that are no longer needed (perhaps
all of these?)

Bug: 786831,349861
Change-Id: I39f83d5dc839c54c5bc9297e9a92bd3f84ead726
Reviewed-on: https://chromium-review.googlesource.com/778881
Commit-Queue: Mostyn Bramley-Moore <mostynb@vewd.com>
Reviewed-by: default avatarJulien Tinnes <jln@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519858}
parent 56d85f95
......@@ -693,10 +693,6 @@ bool GetAppOutputWithExitCode(const CommandLine& cl,
#if defined(OS_LINUX) || defined(OS_NACL_NONSFI) || defined(OS_AIX)
namespace {
bool IsRunningOnValgrind() {
return RUNNING_ON_VALGRIND;
}
// This function runs on the stack specified on the clone call. It uses longjmp
// to switch back to the original stack so the child can return from sys_clone.
int CloneHelper(void* arg) {
......@@ -759,7 +755,7 @@ pid_t ForkWithFlags(unsigned long flags, pid_t* ptid, pid_t* ctid) {
// without CLONE_VM, so we cannot use libc's clone wrapper when running under
// Valgrind. As a result, the libc pid cache may be incorrect under Valgrind.
// See crbug.com/442817 for more details.
if (IsRunningOnValgrind()) {
if (RunningOnValgrind()) {
// See kernel/fork.c in Linux. There is different ordering of sys_clone
// parameters depending on CONFIG_CLONE_BACKWARDS* configuration options.
#if defined(ARCH_CPU_X86_64)
......
......@@ -112,6 +112,7 @@ source_set("sandbox_linux_unittests_sources") {
":sandbox",
":sandbox_linux_test_utils",
"//base",
"//base/third_party/dynamic_annotations",
"//testing/gtest",
]
......@@ -250,6 +251,7 @@ component("seccomp_bpf") {
deps = [
":sandbox_services",
"//base",
"//base/third_party/dynamic_annotations",
]
if (is_nacl_nonsfi) {
......@@ -374,6 +376,7 @@ component("sandbox_services") {
]
deps = [
"//base",
"//base/third_party/dynamic_annotations",
]
if (compile_credentials || is_nacl_nonsfi) {
......@@ -457,6 +460,7 @@ if (compile_suid_client || is_nacl_nonsfi) {
deps = [
":sandbox_services",
"//base",
"//base/third_party/dynamic_annotations",
]
if (is_nacl_nonsfi) {
......
......@@ -15,6 +15,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/third_party/valgrind/valgrind.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "sandbox/linux/bpf_dsl/codegen.h"
......@@ -36,8 +37,6 @@ namespace sandbox {
namespace {
bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; }
// Check if the kernel supports seccomp-filter (a.k.a. seccomp mode 2) via
// prctl().
bool KernelSupportsSeccompBPF() {
......@@ -125,7 +124,7 @@ SandboxBPF::~SandboxBPF() {
bool SandboxBPF::SupportsSeccompSandbox(SeccompLevel level) {
// Never pretend to support seccomp with Valgrind, as it
// throws the tool off.
if (IsRunningOnValgrind()) {
if (RunningOnValgrind()) {
return false;
}
......
......@@ -9,6 +9,7 @@
#include <memory>
#include "base/logging.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "sandbox/linux/bpf_dsl/policy.h"
#include "sandbox/linux/seccomp-bpf/die.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
......@@ -45,7 +46,7 @@ void SandboxBPFTestRunner::Run() {
printf("This BPF test is not fully running in this configuration!\n");
// Android and Valgrind are the only configurations where we accept not
// having kernel BPF support.
if (!IsAndroid() && !IsRunningOnValgrind()) {
if (!IsAndroid() && !RunningOnValgrind()) {
const bool seccomp_bpf_is_supported = false;
SANDBOX_ASSERT(seccomp_bpf_is_supported);
}
......
......@@ -23,6 +23,7 @@
#include "base/macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/launch.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/third_party/valgrind/valgrind.h"
#include "build/build_config.h"
#include "sandbox/linux/services/namespace_utils.h"
......@@ -36,8 +37,6 @@ namespace sandbox {
namespace {
bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; }
const int kExitSuccess = 0;
#if defined(__clang__)
......@@ -259,7 +258,7 @@ bool Credentials::HasCapability(Capability cap) {
bool Credentials::CanCreateProcessInNewUserNS() {
// Valgrind will let clone(2) pass-through, but doesn't support unshare(),
// so always consider UserNS unsupported there.
if (IsRunningOnValgrind()) {
if (RunningOnValgrind()) {
return false;
}
......
......@@ -20,15 +20,12 @@
#include "base/posix/eintr_wrapper.h"
#include "base/process/launch.h"
#include "base/strings/safe_sprintf.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/third_party/valgrind/valgrind.h"
namespace sandbox {
namespace {
bool IsRunningOnValgrind() {
return RUNNING_ON_VALGRIND;
}
const char kProcSelfSetgroups[] = "/proc/self/setgroups";
} // namespace
......@@ -57,7 +54,7 @@ bool NamespaceUtils::WriteToIdMapFile(const char* map_file, generic_id_t id) {
bool NamespaceUtils::KernelSupportsUnprivilegedNamespace(int type) {
// Valgrind will let clone(2) pass-through, but doesn't support unshare(),
// so always consider namespaces unsupported there.
if (IsRunningOnValgrind()) {
if (RunningOnValgrind()) {
return false;
}
......
......@@ -14,6 +14,7 @@
#include "base/macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/process_metrics.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
......@@ -30,7 +31,7 @@ namespace {
#if !defined(THREAD_SANITIZER)
int GetRaceTestIterations() {
if (IsRunningOnValgrind()) {
if (RunningOnValgrind()) {
return 2;
} else {
return 1000;
......
......@@ -22,6 +22,7 @@
#include "base/pickle.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/unix_domain_socket.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/third_party/valgrind/valgrind.h"
#include "sandbox/linux/syscall_broker/broker_common.h"
#include "sandbox/linux/syscall_broker/broker_policy.h"
......@@ -33,10 +34,6 @@ namespace syscall_broker {
namespace {
bool IsRunningOnValgrind() {
return RUNNING_ON_VALGRIND;
}
// A little open(2) wrapper to handle some oddities for us. In the general case
// make a direct system call since we want to keep in control of the broker
// process' system calls profile to be able to loosely sandbox it.
......@@ -48,7 +45,7 @@ int sys_open(const char* pathname, int flags) {
} else {
mode = 0;
}
if (IsRunningOnValgrind()) {
if (RunningOnValgrind()) {
// Valgrind does not support AT_FDCWD, just use libc's open() in this case.
return open(pathname, flags, mode);
} else {
......
......@@ -17,6 +17,7 @@
#include "base/debug/leak_annotations.h"
#include "base/files/file_util.h"
#include "base/posix/eintr_wrapper.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/third_party/valgrind/valgrind.h"
#include "build/build_config.h"
#include "sandbox/linux/tests/unit_tests.h"
......@@ -75,10 +76,6 @@ bool IsArchitectureArm() {
#endif
}
// TODO(jln): figure out why base/.../dynamic_annotations.h's
// RunningOnValgrind() cannot link.
bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; }
static const int kExpectedValue = 42;
static const int kIgnoreThisTest = 43;
static const int kExitWithAssertionFailure = 1;
......@@ -184,7 +181,7 @@ void UnitTests::RunTestInProcess(SandboxTestRunner* test_runner,
// Don't set a timeout if running on Valgrind, since it's generally much
// slower.
if (!IsRunningOnValgrind()) {
if (!RunningOnValgrind()) {
#if !defined(OS_NACL_NONSFI)
SetProcessTimeout(GetSubProcessTimeoutTimeInSeconds());
#endif
......
......@@ -27,9 +27,6 @@ bool IsAndroid();
bool IsArchitectureArm();
// Is Valgrind currently being used?
bool IsRunningOnValgrind();
#if defined(ADDRESS_SANITIZER)
#define DISABLE_ON_ASAN(test_name) DISABLED_##test_name
#else
......
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