scoped_file_android.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/files/scoped_file.h"
  5. #include <stdint.h>
  6. // Copied from <android/fdsan.h>.
  7. // This can go away once this header is included in our copy of the NDK.
  8. extern "C" {
  9. void android_fdsan_exchange_owner_tag(int fd,
  10. uint64_t expected_tag,
  11. uint64_t new_tag)
  12. __attribute__((__weak__));
  13. }
  14. namespace base {
  15. namespace internal {
  16. static uint64_t ScopedFDToTag(const ScopedFD& owner) {
  17. return reinterpret_cast<uint64_t>(&owner);
  18. }
  19. // static
  20. void ScopedFDCloseTraits::Acquire(const ScopedFD& owner, int fd) {
  21. if (android_fdsan_exchange_owner_tag) {
  22. android_fdsan_exchange_owner_tag(fd, 0, ScopedFDToTag(owner));
  23. }
  24. }
  25. // static
  26. void ScopedFDCloseTraits::Release(const ScopedFD& owner, int fd) {
  27. if (android_fdsan_exchange_owner_tag) {
  28. android_fdsan_exchange_owner_tag(fd, ScopedFDToTag(owner), 0);
  29. }
  30. }
  31. } // namespace internal
  32. } // namespace base