blob: 38eb2191435f5907070f807d5c54fd86f40f80e7 [file] [log] [blame]
Josh Gao97271922019-11-06 13:15:00 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <stdatomic.h>
30
31#include <android/fdtrack.h>
32
33#include <platform/bionic/reserved_signals.h>
34
35#include "private/bionic_fdtrack.h"
36#include "private/bionic_tls.h"
37#include "private/bionic_globals.h"
38
39_Atomic(android_fdtrack_hook_t) __android_fdtrack_hook;
40
41bool android_fdtrack_get_enabled() {
42 return !__get_bionic_tls().fdtrack_disabled;
43}
44
45bool android_fdtrack_set_enabled(bool new_value) {
46 auto& tls = __get_bionic_tls();
47 bool prev = !tls.fdtrack_disabled;
48 tls.fdtrack_disabled = !new_value;
49 return prev;
50}
51
52bool android_fdtrack_compare_exchange_hook(android_fdtrack_hook_t* expected,
53 android_fdtrack_hook_t value) {
54 return atomic_compare_exchange_strong(&__android_fdtrack_hook, expected, value);
55}
56
57void __libc_init_fdtrack() {
58 // Register a no-op signal handler.
59 signal(BIONIC_SIGNAL_FDTRACK, [](int) {});
60}