| 6 |
| 7 | #include <stdint.h> |
| 8 |
| 9 | // Copied from <android/fdsan.h>. |
| 10 | // This can go away once this header is included in our copy of the NDK. |
| 11 | extern "C" { |
| 12 | void android_fdsan_exchange_owner_tag(int fd, |
| 13 | uint64_t expected_tag, |
| 14 | uint64_t new_tag) |
| 15 | __attribute__((__weak__)); |
| 16 | } |
| 17 |
| 18 | namespace base { |
| 19 | namespace internal { |
| 20 |
| 21 | static uint64_t ScopedFDToTag(const ScopedFD& owner) { |
| 22 | return reinterpret_cast<uint64_t>(&owner); |
| 23 | } |
| 24 |
| 25 | // static |
| 26 | void ScopedFDCloseTraits::Acquire(const ScopedFD& owner, int fd) { |
| 27 | if (android_fdsan_exchange_owner_tag) { |
| 28 | android_fdsan_exchange_owner_tag(fd, 0, ScopedFDToTag(owner)); |
| 29 | } |
| 30 | } |
| 31 |
| 32 | // static |
| 33 | void ScopedFDCloseTraits::Release(const ScopedFD& owner, int fd) { |
| 34 | if (android_fdsan_exchange_owner_tag) { |
| 35 | android_fdsan_exchange_owner_tag(fd, ScopedFDToTag(owner), 0); |
| 36 | } |
| 37 | } |
| 38 |
| 39 | } // namespace internal |
| 40 | } // namespace base |
| 41 |