Introduce api to track fd ownership in libc.
Add two functions to allow objects that own a file descriptor to
enforce that only they can close their file descriptor.
Use them in FILE* and DIR*.
Bug: http://b/110100358
Test: bionic_unit_tests
Test: aosp/master boots without errors
Test: treehugger
Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 1ff6603..5c54341 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -56,6 +56,7 @@
extern "C" int __system_properties_init(void);
__LIBC_HIDDEN__ WriteProtected<libc_globals> __libc_globals;
+__LIBC_HIDDEN__ libc_shared_globals* __libc_shared_globals;
// Not public, but well-known in the BSDs.
const char* __progname;
@@ -75,6 +76,9 @@
});
}
+void __libc_init_shared_globals(libc_shared_globals*) {
+}
+
#if !defined(__LP64__)
static void __check_max_thread_id() {
if (gettid() > 65535) {
@@ -113,6 +117,7 @@
pthread_atfork(arc4random_fork_handler, _thread_arc4_unlock, _thread_arc4_unlock);
__system_properties_init(); // Requires 'environ'.
+ __libc_init_fdsan(); // Requires system properties (for debug.fdsan).
}
__noreturn static void __early_abort(int line) {