Revert "Remove __sinit and __sdidinit."
This reverts commit 4371961e00ad83fca033992c8a19c7d262fe6f84.
This broke booting; ueventd crashes with a null pointer dereference
somewhere in __sfp (but the kernel doesn't unwind, so I don't know
what was calling __sfp).
Change-Id: I65375fdfdf1d339a06558b4057b580cacd6324e2
diff --git a/libc/bionic/flockfile.cpp b/libc/bionic/flockfile.cpp
index db53828..db68801 100644
--- a/libc/bionic/flockfile.cpp
+++ b/libc/bionic/flockfile.cpp
@@ -36,12 +36,20 @@
// struct __sfileext (see fileext.h).
void flockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
if (fp != nullptr) {
pthread_mutex_lock(&_FLOCK(fp));
}
}
int ftrylockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
// The specification for ftrylockfile() says it returns 0 on success,
// or non-zero on error. So return an errno code directly on error.
if (fp == nullptr) {
@@ -52,6 +60,10 @@
}
void funlockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
if (fp != nullptr) {
pthread_mutex_unlock(&_FLOCK(fp));
}
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 8f210ea..91e210e 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -54,7 +54,7 @@
extern "C" int __system_properties_init(void);
extern "C" int __set_tls(void* ptr);
extern "C" int __set_tid_address(int* tid_address);
-extern "C" int __libc_init_stdio(void);
+extern "C" int __sinit(void);
__LIBC_HIDDEN__ WriteProtected<libc_globals> __libc_globals;
@@ -134,9 +134,9 @@
__pthread_internal_add(main_thread);
__system_properties_init(); // Requires 'environ'.
-
- // Initialize stdio to avoid data races caused by BSD-style lazy initialization.
- __libc_init_stdio();
+ // Initialize stdio here to get rid of data races caused by lazy initialization.
+ // TODO: Remove other calls to __sinit().
+ __sinit();
}
__noreturn static void __early_abort(int line) {
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 0af9d5b..d6b8e8f 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -286,13 +286,6 @@
return r.rlim_cur;
}
-// A leaked BSD stdio implementation detail that's now a no-op.
-// (GCC doesn't like 'extern "C"' on a definition.)
-extern "C" {
-void __sinit() {}
-int __sdidinit = 1;
-}
-
// Only used by ftime, which was removed from POSIX 2008.
struct timeb {
time_t time;