Commit 913a828a authored by Josh Gao's avatar Josh Gao Committed by Commit Bot

Use fdsan on Android.

When available, use ScopedGeneric's ownership tracking to guard its
file descriptors with fdsan.

Bug: 882733
Change-Id: Ibe600465d6bb7e3032e23ed813dea3d8f8ededa8
Reviewed-on: https://chromium-review.googlesource.com/c/1225309
Commit-Queue: Josh Gao <jmgao@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604083}
parent ba73cfc8
...@@ -303,6 +303,7 @@ jumbo_component("base") { ...@@ -303,6 +303,7 @@ jumbo_component("base") {
"files/platform_file.h", "files/platform_file.h",
"files/scoped_file.cc", "files/scoped_file.cc",
"files/scoped_file.h", "files/scoped_file.h",
"files/scoped_file_android.cc",
"files/scoped_temp_dir.cc", "files/scoped_temp_dir.cc",
"files/scoped_temp_dir.h", "files/scoped_temp_dir.h",
"format_macros.h", "format_macros.h",
......
...@@ -18,7 +18,15 @@ namespace base { ...@@ -18,7 +18,15 @@ namespace base {
namespace internal { namespace internal {
#if defined(OS_POSIX) || defined(OS_FUCHSIA) #if defined(OS_ANDROID)
// Use fdsan on android.
struct BASE_EXPORT ScopedFDCloseTraits : public ScopedGenericOwnershipTracking {
static int InvalidValue() { return -1; }
static void Free(int);
static void Acquire(const ScopedGeneric<int, ScopedFDCloseTraits>&, int);
static void Release(const ScopedGeneric<int, ScopedFDCloseTraits>&, int);
};
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
struct BASE_EXPORT ScopedFDCloseTraits { struct BASE_EXPORT ScopedFDCloseTraits {
static int InvalidValue() { static int InvalidValue() {
return -1; return -1;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/files/scoped_file.h"
#include <stdint.h>
// Copied from <android/fdsan.h>.
// This can go away once this header is included in our copy of the NDK.
extern "C" {
void android_fdsan_exchange_owner_tag(int fd,
uint64_t expected_tag,
uint64_t new_tag)
__attribute__((__weak__));
}
namespace base {
namespace internal {
static uint64_t ScopedFDToTag(const ScopedFD& owner) {
return reinterpret_cast<uint64_t>(&owner);
}
// static
void ScopedFDCloseTraits::Acquire(const ScopedFD& owner, int fd) {
if (android_fdsan_exchange_owner_tag) {
android_fdsan_exchange_owner_tag(fd, 0, ScopedFDToTag(owner));
}
}
// static
void ScopedFDCloseTraits::Release(const ScopedFD& owner, int fd) {
if (android_fdsan_exchange_owner_tag) {
android_fdsan_exchange_owner_tag(fd, ScopedFDToTag(owner), 0);
}
}
} // namespace internal
} // namespace base
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