Revert "Revert "Make sem_wait able to return errno EINTR for sdk > 23.""
This reverts commit 6d5108520225fd2c4b10ca63565545ec120aab4a.
And add missing bionic_sdk_version.h.
Change-Id: I24cc738b1fd1d26234c52afbc787f5b3c4a9c9cb
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index c34daef..ab48fb8 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -108,3 +108,9 @@
exit(slingshot(args.argc, args.argv, args.envp));
}
+
+extern "C" uint32_t android_get_application_target_sdk_version();
+
+uint32_t bionic_get_application_target_sdk_version() {
+ return android_get_application_target_sdk_version();
+}
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index 3cda1a2..d1494d7 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -26,6 +26,7 @@
* SUCH DAMAGE.
*/
+#include <android/api-level.h>
#include <elf.h>
#include <errno.h>
#include <stddef.h>
@@ -106,3 +107,7 @@
exit(slingshot(args.argc, args.argv, args.envp));
}
+
+uint32_t bionic_get_application_target_sdk_version() {
+ return __ANDROID_API__;
+}
diff --git a/libc/bionic/semaphore.cpp b/libc/bionic/semaphore.cpp
index b30c0b0..1981647 100644
--- a/libc/bionic/semaphore.cpp
+++ b/libc/bionic/semaphore.cpp
@@ -41,6 +41,7 @@
#include "private/bionic_constants.h"
#include "private/bionic_futex.h"
+#include "private/bionic_sdk_version.h"
#include "private/bionic_time_conversions.h"
// In this implementation, a semaphore contains a
@@ -220,7 +221,13 @@
return 0;
}
- __futex_wait_ex(sem_count_ptr, shared, shared | SEMCOUNT_MINUS_ONE, false, nullptr);
+ int result = __futex_wait_ex(sem_count_ptr, shared, shared | SEMCOUNT_MINUS_ONE, false, nullptr);
+ if (bionic_get_application_target_sdk_version() > 23) {
+ if (result ==-EINTR) {
+ errno = EINTR;
+ return -1;
+ }
+ }
}
}