Merge "linker: simpler encoding for SHT_RELR sections."
diff --git a/docs/status.md b/docs/status.md
index d4ca913..8cef5b7 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -48,10 +48,12 @@
* `hcreate`/`hcreate_r`/`hdestroy`/`hdestroy_r`/`hsearch`/`hsearch_r` (completing <search.h>)
* `iconv`/`iconv_close`/`iconv_open` (adding <iconv.h>)
* `pthread_attr_getinheritsched`/`pthread_attr_setinheritsched`/`pthread_setschedprio`
+ * `pthread_mutexattr_getprotocol`/`pthread_mutexattr_setprotocol` (mutex priority inheritance)
* <spawn.h>
* `swab`
* `syncfs`
- * %C and %S support in the printf family (previously only the wprintf family supported these).
+ * `%C` and `%S` support in the printf family (previously only the wprintf family supported these).
+ * `%mc`/`%ms`/`%m[` support in the scanf family.
New libc functions in O:
* `sendto` FORTIFY support
diff --git a/libc/bionic/abort.cpp b/libc/bionic/abort.cpp
index f401cab..9f1c31f 100644
--- a/libc/bionic/abort.cpp
+++ b/libc/bionic/abort.cpp
@@ -32,6 +32,8 @@
#include <sys/syscall.h>
#include <unistd.h>
+#include "private/kernel_sigset_t.h"
+
// We call tgkill(2) directly instead of raise (or even the libc tgkill wrapper), to reduce the
// number of uninteresting stack frames at the top of a crash.
static inline __always_inline void inline_tgkill(pid_t pid, pid_t tid, int sig) {
@@ -60,10 +62,10 @@
// Don't block SIGABRT to give any signal handler a chance; we ignore
// any errors -- X311J doesn't allow abort to return anyway.
- sigset_t mask;
- sigfillset(&mask);
- sigdelset(&mask, SIGABRT);
- sigprocmask(SIG_SETMASK, &mask, NULL);
+ kernel_sigset_t mask;
+ mask.fill();
+ mask.clear(SIGABRT);
+ __rt_sigprocmask(SIG_SETMASK, &mask, nullptr, sizeof(mask));
inline_tgkill(pid, tid, SIGABRT);
@@ -74,7 +76,7 @@
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
sigaction(SIGABRT, &sa, &sa);
- sigprocmask(SIG_SETMASK, &mask, NULL);
+ __rt_sigprocmask(SIG_SETMASK, &mask, nullptr, sizeof(mask));
inline_tgkill(pid, tid, SIGABRT);
diff --git a/libc/bionic/pause.cpp b/libc/bionic/pause.cpp
index 94a16fb..2a0779a 100644
--- a/libc/bionic/pause.cpp
+++ b/libc/bionic/pause.cpp
@@ -30,13 +30,8 @@
#include "private/kernel_sigset_t.h"
-extern "C" int __rt_sigprocmask(int, const kernel_sigset_t*, kernel_sigset_t*, size_t);
-extern "C" int __rt_sigsuspend(const kernel_sigset_t*, size_t);
-
int pause() {
kernel_sigset_t mask;
- if (__rt_sigprocmask(SIG_SETMASK, NULL, &mask, sizeof(mask)) == -1) {
- return -1;
- }
+ if (__rt_sigprocmask(SIG_SETMASK, nullptr, &mask, sizeof(mask)) == -1) return -1;
return __rt_sigsuspend(&mask, sizeof(mask));
}
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
index c46965f..e3bb112 100644
--- a/libc/bionic/posix_timers.cpp
+++ b/libc/bionic/posix_timers.cpp
@@ -74,8 +74,7 @@
static void* __timer_thread_start(void* arg) {
PosixTimer* timer = reinterpret_cast<PosixTimer*>(arg);
- kernel_sigset_t sigset;
- sigaddset(sigset.get(), TIMER_SIGNAL);
+ kernel_sigset_t sigset{TIMER_SIGNAL};
while (true) {
// Wait for a signal...
@@ -150,14 +149,13 @@
// We start the thread with TIMER_SIGNAL blocked by blocking the signal here and letting it
// inherit. If it tried to block the signal itself, there would be a race.
- kernel_sigset_t sigset;
- sigaddset(sigset.get(), TIMER_SIGNAL);
+ kernel_sigset_t sigset{TIMER_SIGNAL};
kernel_sigset_t old_sigset;
- pthread_sigmask(SIG_BLOCK, sigset.get(), old_sigset.get());
+ __rt_sigprocmask(SIG_BLOCK, &sigset, &old_sigset, sizeof(sigset));
int rc = pthread_create(&timer->callback_thread, &thread_attributes, __timer_thread_start, timer);
- pthread_sigmask(SIG_SETMASK, old_sigset.get(), NULL);
+ __rt_sigprocmask(SIG_SETMASK, &old_sigset, nullptr, sizeof(sigset));
if (rc != 0) {
free(timer);
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index 8b4c44e..f1b65fd 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -34,6 +34,7 @@
#include <sys/mman.h>
#include "private/bionic_defs.h"
+#include "private/ScopedSignalBlocker.h"
#include "pthread_internal.h"
extern "C" __noreturn void _exit_with_stack_teardown(void*, size_t);
@@ -63,6 +64,12 @@
}
}
+static void __pthread_unmap_tls(pthread_internal_t* thread) {
+ // Unmap the bionic TLS, including guard pages.
+ void* allocation = reinterpret_cast<char*>(thread->bionic_tls) - PTHREAD_GUARD_SIZE;
+ munmap(allocation, BIONIC_TLS_SIZE + 2 * PTHREAD_GUARD_SIZE);
+}
+
__BIONIC_WEAK_FOR_NATIVE_BRIDGE
void pthread_exit(void* return_value) {
// Call dtors for thread_local objects first.
@@ -96,10 +103,6 @@
thread->alternate_signal_stack = NULL;
}
- // Unmap the bionic TLS, including guard pages.
- void* allocation = reinterpret_cast<char*>(thread->bionic_tls) - PTHREAD_GUARD_SIZE;
- munmap(allocation, BIONIC_TLS_SIZE + 2 * PTHREAD_GUARD_SIZE);
-
ThreadJoinState old_state = THREAD_NOT_JOINED;
while (old_state == THREAD_NOT_JOINED &&
!atomic_compare_exchange_weak(&thread->join_state, &old_state, THREAD_EXITED_NOT_JOINED)) {
@@ -120,16 +123,15 @@
// That's not something we can do in C.
// We don't want to take a signal after we've unmapped the stack.
- // That's one last thing we can handle in C.
- sigset_t mask;
- sigfillset(&mask);
- sigprocmask(SIG_SETMASK, &mask, NULL);
-
+ // That's one last thing we can do before dropping to assembler.
+ ScopedSignalBlocker ssb;
+ __pthread_unmap_tls(thread);
_exit_with_stack_teardown(thread->attr.stack_base, thread->mmap_size);
}
}
// No need to free mapped space. Either there was no space mapped, or it is left for
// the pthread_join caller to clean up.
+ __pthread_unmap_tls(thread);
__exit(0);
}
diff --git a/libc/bionic/sigblock.c b/libc/bionic/sigblock.c
index 176bc13..cc47d5d 100644
--- a/libc/bionic/sigblock.c
+++ b/libc/bionic/sigblock.c
@@ -25,26 +25,18 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#include <signal.h>
-/* this function is called from the ARM assembly setjmp fragments */
-int
-sigblock(int mask)
-{
- int n;
- union {
- int the_mask;
- sigset_t the_sigset;
- } in, out;
+int sigblock(int mask) {
+ union {
+ int mask;
+ sigset_t set;
+ } in, out;
- sigemptyset(&in.the_sigset);
- in.the_mask = mask;
+ sigemptyset(&in.set);
+ in.mask = mask;
- n = sigprocmask(SIG_BLOCK, &in.the_sigset, &out.the_sigset);
- if (n)
- return n;
-
- return out.the_mask;
+ if (sigprocmask(SIG_BLOCK, &in.set, &out.set) == -1) return -1;
+ return out.mask;
}
-
-
diff --git a/libc/bionic/sighold.cpp b/libc/bionic/sighold.cpp
index e9c8ca1..2800d10 100644
--- a/libc/bionic/sighold.cpp
+++ b/libc/bionic/sighold.cpp
@@ -28,9 +28,11 @@
#include <signal.h>
+#include "private/kernel_sigset_t.h"
+
int sighold(int sig) {
- sigset_t set;
- if (sigemptyset(&set) == -1) return -1;
- if (sigaddset(&set, sig) == -1) return -1;
- return sigprocmask(SIG_BLOCK, &set, nullptr);
+ kernel_sigset_t set;
+ set.clear();
+ if (!set.set(sig)) return -1;
+ return __rt_sigprocmask(SIG_BLOCK, &set, nullptr, sizeof(set));
}
diff --git a/libc/bionic/sigpause.cpp b/libc/bionic/sigpause.cpp
index 8ba42d4..6b5d74a 100644
--- a/libc/bionic/sigpause.cpp
+++ b/libc/bionic/sigpause.cpp
@@ -28,9 +28,12 @@
#include <signal.h>
+#include "private/kernel_sigset_t.h"
+
int sigpause(int sig) {
- sigset_t set;
- if (sigprocmask(SIG_SETMASK, nullptr, &set) == -1) return -1;
- if (sigdelset(&set, sig) == -1) return -1;
- return sigsuspend(&set);
+ kernel_sigset_t set;
+ set.clear();
+ if (__rt_sigprocmask(SIG_SETMASK, nullptr, &set, sizeof(set)) == -1) return -1;
+ if (!set.clear(sig)) return -1;
+ return __rt_sigsuspend(&set, sizeof(set));
}
diff --git a/libc/bionic/sigpending.cpp b/libc/bionic/sigpending.cpp
index b6e503c..8a02de6 100644
--- a/libc/bionic/sigpending.cpp
+++ b/libc/bionic/sigpending.cpp
@@ -30,8 +30,6 @@
#include "private/kernel_sigset_t.h"
-extern "C" int __rt_sigpending(const kernel_sigset_t*, size_t);
-
int sigpending(sigset_t* bionic_set) {
kernel_sigset_t set;
int result = __rt_sigpending(&set, sizeof(set));
diff --git a/libc/bionic/sigprocmask.cpp b/libc/bionic/sigprocmask.cpp
index 61e2c63..c34e42e 100644
--- a/libc/bionic/sigprocmask.cpp
+++ b/libc/bionic/sigprocmask.cpp
@@ -32,8 +32,6 @@
#include "private/kernel_sigset_t.h"
-extern "C" int __rt_sigprocmask(int, const kernel_sigset_t*, kernel_sigset_t*, size_t);
-
int sigprocmask(int how, const sigset_t* bionic_new_set, sigset_t* bionic_old_set) {
kernel_sigset_t new_set;
kernel_sigset_t* new_set_ptr = NULL;
diff --git a/libc/bionic/sigrelse.cpp b/libc/bionic/sigrelse.cpp
index ab5554e..c4a484a 100644
--- a/libc/bionic/sigrelse.cpp
+++ b/libc/bionic/sigrelse.cpp
@@ -28,9 +28,11 @@
#include <signal.h>
+#include "private/kernel_sigset_t.h"
+
int sigrelse(int sig) {
- sigset_t set;
- if (sigemptyset(&set) == -1) return -1;
- if (sigaddset(&set, sig) == -1) return -1;
- return sigprocmask(SIG_UNBLOCK, &set, nullptr);
+ kernel_sigset_t set;
+ set.clear();
+ if (!set.set(sig)) return -1;
+ return __rt_sigprocmask(SIG_UNBLOCK, &set, nullptr, sizeof(set));
}
diff --git a/libc/bionic/sigset.cpp b/libc/bionic/sigset.cpp
index e3f3e72..52820f2 100644
--- a/libc/bionic/sigset.cpp
+++ b/libc/bionic/sigset.cpp
@@ -29,6 +29,8 @@
#include <signal.h>
#include <string.h>
+#include "private/kernel_sigset_t.h"
+
sighandler_t sigset(int sig, sighandler_t disp) {
struct sigaction new_sa;
if (disp != SIG_HOLD) {
@@ -38,19 +40,16 @@
}
struct sigaction old_sa;
- if (sigaction(sig, disp == SIG_HOLD ? nullptr : &new_sa, &old_sa) == -1) {
+ if (sigaction(sig, (disp == SIG_HOLD) ? nullptr : &new_sa, &old_sa) == -1) {
return SIG_ERR;
}
- sigset_t new_proc_mask;
- sigemptyset(&new_proc_mask);
- sigaddset(&new_proc_mask, sig);
-
- sigset_t old_proc_mask;
- if (sigprocmask(disp == SIG_HOLD ? SIG_BLOCK : SIG_UNBLOCK,
- &new_proc_mask, &old_proc_mask) == -1) {
+ kernel_sigset_t new_mask{sig};
+ kernel_sigset_t old_mask;
+ if (__rt_sigprocmask(disp == SIG_HOLD ? SIG_BLOCK : SIG_UNBLOCK, &new_mask, &old_mask,
+ sizeof(new_mask)) == -1) {
return SIG_ERR;
}
- return sigismember(&old_proc_mask, sig) ? SIG_HOLD : old_sa.sa_handler;
+ return old_mask.is_set(sig) ? SIG_HOLD : old_sa.sa_handler;
}
diff --git a/libc/bionic/sigsetmask.c b/libc/bionic/sigsetmask.c
index 7842bf1..6a3b1d2 100644
--- a/libc/bionic/sigsetmask.c
+++ b/libc/bionic/sigsetmask.c
@@ -25,26 +25,18 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#include <signal.h>
-/* called from setjmp assembly fragment */
-int
-sigsetmask(int mask)
-{
- int n;
+int sigsetmask(int mask) {
+ union {
+ int mask;
+ sigset_t set;
+ } in, out;
- union {
- int the_mask;
- sigset_t the_sigset;
- } in, out;
+ sigemptyset(&in.set);
+ in.mask = mask;
- sigemptyset(&in.the_sigset);
- in.the_mask = mask;
-
- n = sigprocmask(SIG_SETMASK, &in.the_sigset, &out.the_sigset);
- if (n)
- return n;
-
- return out.the_mask;
+ if (sigprocmask(SIG_SETMASK, &in.set, &out.set) == -1) return -1;
+ return out.mask;
}
-
diff --git a/libc/bionic/sigsuspend.cpp b/libc/bionic/sigsuspend.cpp
index fb846b8..1d89d4f 100644
--- a/libc/bionic/sigsuspend.cpp
+++ b/libc/bionic/sigsuspend.cpp
@@ -30,8 +30,6 @@
#include "private/kernel_sigset_t.h"
-extern "C" int __rt_sigsuspend(const kernel_sigset_t*, size_t);
-
int sigsuspend(const sigset_t* bionic_set) {
kernel_sigset_t set(bionic_set);
return __rt_sigsuspend(&set, sizeof(set));
diff --git a/libc/include/android/dlext.h b/libc/include/android/dlext.h
index c824544..2b4169e 100644
--- a/libc/include/android/dlext.h
+++ b/libc/include/android/dlext.h
@@ -23,88 +23,116 @@
#include <sys/cdefs.h>
#include <sys/types.h> /* for off64_t */
+/**
+ * \file
+ * Advanced dynamic library opening support. Most users will want to use
+ * the standard [dlopen(3)](http://man7.org/linux/man-pages/man3/dlopen.3.html)
+ * functionality in `<dlfcn.h>` instead.
+ */
+
__BEGIN_DECLS
-/* bitfield definitions for android_dlextinfo.flags */
+/** Bitfield definitions for `android_dlextinfo::flags`. */
enum {
- /* When set, the reserved_addr and reserved_size fields must point to an
+ /**
+ * When set, the `reserved_addr` and `reserved_size` fields must point to an
* already-reserved region of address space which will be used to load the
- * library if it fits. If the reserved region is not large enough, the load
- * will fail.
+ * library if it fits.
+ *
+ * If the reserved region is not large enough, loading will fail.
*/
ANDROID_DLEXT_RESERVED_ADDRESS = 0x1,
- /* As DLEXT_RESERVED_ADDRESS, but if the reserved region is not large enough,
+ /**
+ * Like `ANDROID_DLEXT_RESERVED_ADDRESS`, but if the reserved region is not large enough,
* the linker will choose an available address instead.
*/
ANDROID_DLEXT_RESERVED_ADDRESS_HINT = 0x2,
- /* When set, write the GNU RELRO section of the mapped library to relro_fd
+ /**
+ * When set, write the GNU RELRO section of the mapped library to `relro_fd`
* after relocation has been performed, to allow it to be reused by another
* process loading the same library at the same address. This implies
- * ANDROID_DLEXT_USE_RELRO.
+ * `ANDROID_DLEXT_USE_RELRO`.
+ *
+ * This is mainly useful for the system WebView implementation.
*/
ANDROID_DLEXT_WRITE_RELRO = 0x4,
- /* When set, compare the GNU RELRO section of the mapped library to relro_fd
+ /**
+ * When set, compare the GNU RELRO section of the mapped library to `relro_fd`
* after relocation has been performed, and replace any relocated pages that
* are identical with a version mapped from the file.
+ *
+ * This is mainly useful for the system WebView implementation.
*/
ANDROID_DLEXT_USE_RELRO = 0x8,
- /* Instruct dlopen to use library_fd instead of opening file by name.
+ /**
+ * Use `library_fd` instead of opening the file by name.
* The filename parameter is still used to identify the library.
*/
ANDROID_DLEXT_USE_LIBRARY_FD = 0x10,
- /* If opening a library using library_fd read it starting at library_fd_offset.
- * This flag is only valid when ANDROID_DLEXT_USE_LIBRARY_FD is set.
+ /**
+ * If opening a library using `library_fd` read it starting at `library_fd_offset`.
+ * This is mainly useful for loading a library stored within another file (such as uncompressed
+ * inside a ZIP archive).
+ * This flag is only valid when `ANDROID_DLEXT_USE_LIBRARY_FD` is set.
*/
ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET = 0x20,
- /* When set, do not check if the library has already been loaded by file stat(2)s.
+ /**
+ * When set, do not use `stat(2)` to check if the library has already been loaded.
*
* This flag allows forced loading of the library in the case when for some
* reason multiple ELF files share the same filename (because the already-loaded
* library has been removed and overwritten, for example).
*
- * Note that if the library has the same dt_soname as an old one and some other
- * library has the soname in DT_NEEDED list, the first one will be used to resolve any
+ * Note that if the library has the same `DT_SONAME` as an old one and some other
+ * library has the soname in its `DT_NEEDED` list, the first one will be used to resolve any
* dependencies.
*/
ANDROID_DLEXT_FORCE_LOAD = 0x40,
- /* When set, if the minimum p_vaddr of the ELF file's PT_LOAD segments is non-zero,
+ /**
+ * When set, if the minimum `p_vaddr` of the ELF file's `PT_LOAD` segments is non-zero,
* the dynamic linker will load it at that address.
*
* This flag is for ART internal use only.
*/
ANDROID_DLEXT_FORCE_FIXED_VADDR = 0x80,
- /* Instructs dlopen to load the library at the address specified by reserved_addr.
+ /**
+ * Instructs dlopen to load the library at the address specified by reserved_addr.
*
- * The difference between ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS and ANDROID_DLEXT_RESERVED_ADDRESS
- * is that for ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS the linker reserves memory at reserved_addr
- * whereas for ANDROID_DLEXT_RESERVED_ADDRESS the linker relies on the caller to reserve the memory.
+ * The difference between `ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS` and
+ * `ANDROID_DLEXT_RESERVED_ADDRESS` is that for `ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS` the linker
+ * reserves memory at `reserved_addr` whereas for `ANDROID_DLEXT_RESERVED_ADDRESS` the linker
+ * relies on the caller to reserve the memory.
*
- * This flag can be used with ANDROID_DLEXT_FORCE_FIXED_VADDR; when ANDROID_DLEXT_FORCE_FIXED_VADDR
- * is set and load_bias is not 0 (load_bias is min(p_vaddr) of PT_LOAD segments) this flag is ignored.
- * This is implemented this way because the linker has to pick one address over the other and this
- * way is more convenient for art. Note that ANDROID_DLEXT_FORCE_FIXED_VADDR does not generate
- * an error when min(p_vaddr) is 0.
+ * This flag can be used with `ANDROID_DLEXT_FORCE_FIXED_VADDR`. When
+ * `ANDROID_DLEXT_FORCE_FIXED_VADDR` is set and `load_bias` is not 0 (`load_bias` is the
+ * minimum `p_vaddr` of all `PT_LOAD` segments) this flag is ignored because the linker has to
+ * pick one address over the other and this way is more convenient for ART.
+ * Note that `ANDROID_DLEXT_FORCE_FIXED_VADDR` does not generate an error when the minimum
+ * `p_vaddr` is 0.
*
- * Cannot be used with ANDROID_DLEXT_RESERVED_ADDRESS or ANDROID_DLEXT_RESERVED_ADDRESS_HINT.
+ * Cannot be used with `ANDROID_DLEXT_RESERVED_ADDRESS` or `ANDROID_DLEXT_RESERVED_ADDRESS_HINT`.
*
* This flag is for ART internal use only.
*/
ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS = 0x100,
- /* This flag used to load library in a different namespace. The namespace is
- * specified in library_namespace.
+ /**
+ * This flag used to load library in a different namespace. The namespace is
+ * specified in `library_namespace`.
+ *
+ * This flag is for internal use only (since there is no NDK API for namespaces).
*/
ANDROID_DLEXT_USE_NAMESPACE = 0x200,
- /* Mask of valid bits */
+ /** Mask of valid bits. */
ANDROID_DLEXT_VALID_FLAG_BITS = ANDROID_DLEXT_RESERVED_ADDRESS |
ANDROID_DLEXT_RESERVED_ADDRESS_HINT |
ANDROID_DLEXT_WRITE_RELRO |
@@ -119,19 +147,36 @@
struct android_namespace_t;
+/** Used to pass Android-specific arguments to `android_dlopen_ext`. */
typedef struct {
+ /** A bitmask of `ANDROID_DLEXT_` enum values. */
uint64_t flags;
+
+ /** Used by `ANDROID_DLEXT_RESERVED_ADDRESS` and `ANDROID_DLEXT_RESERVED_ADDRESS_HINT`. */
void* reserved_addr;
+ /** Used by `ANDROID_DLEXT_RESERVED_ADDRESS` and `ANDROID_DLEXT_RESERVED_ADDRESS_HINT`. */
size_t reserved_size;
+
+ /** Used by `ANDROID_DLEXT_WRITE_RELRO` and `ANDROID_DLEXT_USE_RELRO`. */
int relro_fd;
+
+ /** Used by `ANDROID_DLEXT_USE_LIBRARY_FD`. */
int library_fd;
+ /** Used by `ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET` */
off64_t library_fd_offset;
+
+ /** Used by `ANDROID_DLEXT_USE_NAMESPACE`. */
struct android_namespace_t* library_namespace;
} android_dlextinfo;
+/**
+ * Opens the given library. The `__filename` and `__flags` arguments are
+ * the same as for [dlopen(3)](http://man7.org/linux/man-pages/man3/dlopen.3.html),
+ * with the Android-specific flags supplied via the `flags` member of `__info`.
+ */
void* android_dlopen_ext(const char* __filename, int __flags, const android_dlextinfo* __info)
__INTRODUCED_IN(21);
__END_DECLS
-#endif /* __ANDROID_DLEXT_H__ */
+#endif
diff --git a/libc/include/bits/fortify/fcntl.h b/libc/include/bits/fortify/fcntl.h
index 6d90341..75cd4f2 100644
--- a/libc/include/bits/fortify/fcntl.h
+++ b/libc/include/bits/fortify/fcntl.h
@@ -98,7 +98,7 @@
__errordecl(__creat_too_many_args, __open_too_many_args_error);
#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
-__BIONIC_FORTIFY_INLINE
+__BIONIC_FORTIFY_VARIADIC
int open(const char* pathname, int flags, ...) {
if (__builtin_constant_p(flags)) {
if (__open_modes_useful(flags) && __builtin_va_arg_pack_len() == 0) {
@@ -117,7 +117,7 @@
return __open_real(pathname, flags, __builtin_va_arg_pack());
}
-__BIONIC_FORTIFY_INLINE
+__BIONIC_FORTIFY_VARIADIC
int openat(int dirfd, const char* pathname, int flags, ...) {
if (__builtin_constant_p(flags)) {
if (__open_modes_useful(flags) && __builtin_va_arg_pack_len() == 0) {
diff --git a/libc/include/bits/fortify/stdio.h b/libc/include/bits/fortify/stdio.h
index cfc78d7..6a6b433 100644
--- a/libc/include/bits/fortify/stdio.h
+++ b/libc/include/bits/fortify/stdio.h
@@ -63,8 +63,7 @@
"format string will always overflow destination buffer")
__errorattr("format string will always overflow destination buffer");
-__BIONIC_FORTIFY_INLINE
-__printflike(3, 4)
+__BIONIC_FORTIFY_VARIADIC __printflike(3, 4)
int snprintf(char* const __pass_object_size dest, size_t size, const char* format, ...)
__overloadable {
va_list va;
@@ -82,8 +81,7 @@
"format string will always overflow destination buffer")
__errorattr("format string will always overflow destination buffer");
-__BIONIC_FORTIFY_INLINE
-__printflike(2, 3)
+__BIONIC_FORTIFY_VARIADIC __printflike(2, 3)
int sprintf(char* const __pass_object_size dest, const char* format, ...) __overloadable {
va_list va;
va_start(va, format);
@@ -159,12 +157,12 @@
#if __ANDROID_API__ >= __ANDROID_API_J_MR1__
-__BIONIC_FORTIFY_INLINE __printflike(3, 4)
+__BIONIC_FORTIFY_VARIADIC __printflike(3, 4)
int snprintf(char* dest, size_t size, const char* format, ...) {
return __builtin___snprintf_chk(dest, size, 0, __bos(dest), format, __builtin_va_arg_pack());
}
-__BIONIC_FORTIFY_INLINE __printflike(2, 3)
+__BIONIC_FORTIFY_VARIADIC __printflike(2, 3)
int sprintf(char* dest, const char* format, ...) {
return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack());
}
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 3cf6723..be07007 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -300,6 +300,13 @@
* inline` without making them available externally.
*/
# define __BIONIC_FORTIFY_INLINE static __inline__ __always_inline
+/*
+ * We should use __BIONIC_FORTIFY_VARIADIC instead of __BIONIC_FORTIFY_INLINE
+ * for variadic functions because compilers cannot inline them.
+ * The __always_inline attribute is useless, misleading, and could trigger
+ * clang compiler bug to incorrectly inline variadic functions.
+ */
+# define __BIONIC_FORTIFY_VARIADIC static __inline__
/* Error functions don't have bodies, so they can just be static. */
# define __BIONIC_ERROR_FUNCTION_VISIBILITY static
# else
@@ -311,6 +318,8 @@
# define __call_bypassing_fortify(fn) (fn)
/* __BIONIC_FORTIFY_NONSTATIC_INLINE is pointless in GCC's FORTIFY */
# define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
+/* __always_inline is probably okay and ignored by gcc in __BIONIC_FORTIFY_VARIADIC */
+# define __BIONIC_FORTIFY_VARIADIC __BIONIC_FORTIFY_INLINE
# endif
#else
/* Further increase sharing for some inline functions */
diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h
index 76dc1ff..b48b7f9 100644
--- a/libc/include/sys/ioctl.h
+++ b/libc/include/sys/ioctl.h
@@ -36,8 +36,6 @@
* terminal-related ioctl data structures such as struct winsize.
*/
#include <linux/termios.h>
-#include <asm/ioctls.h>
-#include <asm/termbits.h>
#include <linux/tty.h>
#include <bits/ioctl.h>
diff --git a/libc/private/ScopedSignalBlocker.h b/libc/private/ScopedSignalBlocker.h
index 35d1c58..c3ab307 100644
--- a/libc/private/ScopedSignalBlocker.h
+++ b/libc/private/ScopedSignalBlocker.h
@@ -20,13 +20,14 @@
#include <signal.h>
#include "bionic_macros.h"
+#include "kernel_sigset_t.h"
class ScopedSignalBlocker {
public:
explicit ScopedSignalBlocker() {
- sigset_t set;
- sigfillset(&set);
- sigprocmask(SIG_BLOCK, &set, &old_set_);
+ kernel_sigset_t set;
+ set.fill();
+ __rt_sigprocmask(SIG_SETMASK, &set, &old_set_, sizeof(set));
}
~ScopedSignalBlocker() {
@@ -34,11 +35,11 @@
}
void reset() {
- sigprocmask(SIG_SETMASK, &old_set_, nullptr);
+ __rt_sigprocmask(SIG_SETMASK, &old_set_, nullptr, sizeof(old_set_));
}
private:
- sigset_t old_set_;
+ kernel_sigset_t old_set_;
DISALLOW_COPY_AND_ASSIGN(ScopedSignalBlocker);
};
diff --git a/libc/private/kernel_sigset_t.h b/libc/private/kernel_sigset_t.h
index 9415fcf..bdfb729 100644
--- a/libc/private/kernel_sigset_t.h
+++ b/libc/private/kernel_sigset_t.h
@@ -17,18 +17,27 @@
#ifndef LIBC_PRIVATE_KERNEL_SIGSET_T_H_
#define LIBC_PRIVATE_KERNEL_SIGSET_T_H_
+#include <errno.h>
#include <signal.h>
+#include <async_safe/log.h>
+
// Our sigset_t is wrong for ARM and x86. It's 32-bit but the kernel expects 64 bits.
-// This means we can't support real-time signals correctly until we can change the ABI.
+// This means we can't support real-time signals correctly without breaking the ABI.
// In the meantime, we can use this union to pass an appropriately-sized block of memory
-// to the kernel, at the cost of not being able to refer to real-time signals.
+// to the kernel, at the cost of not being able to refer to real-time signals when
+// initializing from a sigset_t on LP32.
union kernel_sigset_t {
+ public:
kernel_sigset_t() {
- clear();
}
- kernel_sigset_t(const sigset_t* value) {
+ explicit kernel_sigset_t(int signal_number) {
+ clear();
+ if (!set(signal_number)) async_safe_fatal("kernel_sigset_t(%d)", signal_number);
+ }
+
+ explicit kernel_sigset_t(const sigset_t* value) {
clear();
set(value);
}
@@ -37,7 +46,32 @@
__builtin_memset(this, 0, sizeof(*this));
}
+ bool clear(int signal_number) {
+ int bit = bit_of(signal_number);
+ if (bit == -1) return false;
+ bits[bit / LONG_BIT] &= ~(1UL << (bit % LONG_BIT));
+ return true;
+ }
+
+ void fill() {
+ __builtin_memset(this, 0xff, sizeof(*this));
+ }
+
+ bool is_set(int signal_number) {
+ int bit = bit_of(signal_number);
+ if (bit == -1) return false;
+ return ((bits[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1) == 1;
+ }
+
+ bool set(int signal_number) {
+ int bit = bit_of(signal_number);
+ if (bit == -1) return false;
+ bits[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
+ return true;
+ }
+
void set(const sigset_t* value) {
+ clear();
bionic = *value;
}
@@ -46,9 +80,21 @@
}
sigset_t bionic;
-#ifndef __mips__
- uint32_t kernel[2];
-#endif
+ unsigned long bits[_KERNEL__NSIG/LONG_BIT];
+
+ private:
+ int bit_of(int signal_number) {
+ int bit = signal_number - 1; // Signal numbers start at 1, but bit positions start at 0.
+ if (bit < 0 || bit >= static_cast<int>(8*sizeof(*this))) {
+ errno = EINVAL;
+ return -1;
+ }
+ return bit;
+ }
};
+extern "C" int __rt_sigpending(const kernel_sigset_t*, size_t);
+extern "C" int __rt_sigprocmask(int, const kernel_sigset_t*, kernel_sigset_t*, size_t);
+extern "C" int __rt_sigsuspend(const kernel_sigset_t*, size_t);
+
#endif
diff --git a/libdl/libdl.arm.map b/libdl/libdl.arm.map
index 1fcfc58..7ed9503 100644
--- a/libdl/libdl.arm.map
+++ b/libdl/libdl.arm.map
@@ -41,6 +41,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/libdl/libdl.arm64.map b/libdl/libdl.arm64.map
index 8d4019c..199f2e3 100644
--- a/libdl/libdl.arm64.map
+++ b/libdl/libdl.arm64.map
@@ -40,6 +40,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/libdl/libdl.cpp b/libdl/libdl.cpp
index c834088..4c2415f 100644
--- a/libdl/libdl.cpp
+++ b/libdl/libdl.cpp
@@ -93,6 +93,11 @@
const char* shared_libs_sonames);
__attribute__((__weak__, visibility("default")))
+bool __loader_android_link_namespaces_all_libs(
+ struct android_namespace_t* namespace_from,
+ struct android_namespace_t* namespace_to);
+
+__attribute__((__weak__, visibility("default")))
void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*));
__attribute__((__weak__, visibility("default")))
@@ -205,6 +210,12 @@
}
__attribute__((__weak__))
+bool android_link_namespaces_all_libs(struct android_namespace_t* namespace_from,
+ struct android_namespace_t* namespace_to) {
+ return __loader_android_link_namespaces_all_libs(namespace_from, namespace_to);
+}
+
+__attribute__((__weak__))
void android_dlwarning(void* obj, void (*f)(void*, const char*)) {
__loader_android_dlwarning(obj, f);
}
diff --git a/libdl/libdl.map.txt b/libdl/libdl.map.txt
index 002e9f8..579ffa7 100644
--- a/libdl/libdl.map.txt
+++ b/libdl/libdl.map.txt
@@ -40,6 +40,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/libdl/libdl.mips.map b/libdl/libdl.mips.map
index 8d4019c..199f2e3 100644
--- a/libdl/libdl.mips.map
+++ b/libdl/libdl.mips.map
@@ -40,6 +40,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/libdl/libdl.mips64.map b/libdl/libdl.mips64.map
index 8d4019c..199f2e3 100644
--- a/libdl/libdl.mips64.map
+++ b/libdl/libdl.mips64.map
@@ -40,6 +40,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/libdl/libdl.x86.map b/libdl/libdl.x86.map
index 8d4019c..199f2e3 100644
--- a/libdl/libdl.x86.map
+++ b/libdl/libdl.x86.map
@@ -40,6 +40,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/libdl/libdl.x86_64.map b/libdl/libdl.x86_64.map
index 8d4019c..199f2e3 100644
--- a/libdl/libdl.x86_64.map
+++ b/libdl/libdl.x86_64.map
@@ -40,6 +40,11 @@
__cfi_slowpath_diag;
} LIBC_N;
+LIBC_PRIVATE {
+ global:
+ android_link_namespaces_all_libs;
+} LIBC_OMR1;
+
LIBC_PLATFORM {
global:
__cfi_init;
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 7f40f90..4b84537 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -65,6 +65,8 @@
bool __loader_android_link_namespaces(android_namespace_t* namespace_from,
android_namespace_t* namespace_to,
const char* shared_libs_sonames) __LINKER_PUBLIC__;
+bool __loader_android_link_namespaces_all_libs(android_namespace_t* namespace_from,
+ android_namespace_t* namespace_to) __LINKER_PUBLIC__;
void __loader_android_set_application_target_sdk_version(uint32_t target) __LINKER_PUBLIC__;
void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path) __LINKER_PUBLIC__;
void __loader_cfi_fail(uint64_t CallSiteTypeId,
@@ -266,6 +268,19 @@
return success;
}
+bool __loader_android_link_namespaces_all_libs(android_namespace_t* namespace_from,
+ android_namespace_t* namespace_to) {
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
+
+ bool success = link_namespaces_all_libs(namespace_from, namespace_to);
+
+ if (!success) {
+ __bionic_format_dlerror("android_link_namespaces_all_libs failed", linker_get_error_buffer());
+ }
+
+ return success;
+}
+
android_namespace_t* __loader_android_get_exported_namespace(const char* name) {
return get_exported_namespace(name);
}
diff --git a/linker/ld_android.cpp b/linker/ld_android.cpp
index c4ce1b9..4a05772 100644
--- a/linker/ld_android.cpp
+++ b/linker/ld_android.cpp
@@ -49,6 +49,7 @@
__strong_alias(__loader_android_get_exported_namespace, __internal_linker_error);
__strong_alias(__loader_android_init_anonymous_namespace, __internal_linker_error);
__strong_alias(__loader_android_link_namespaces, __internal_linker_error);
+__strong_alias(__loader_android_link_namespaces_all_libs, __internal_linker_error);
__strong_alias(__loader_android_set_application_target_sdk_version, __internal_linker_error);
__strong_alias(__loader_android_update_LD_LIBRARY_PATH, __internal_linker_error);
__strong_alias(__loader_cfi_fail, __internal_linker_error);
diff --git a/linker/linker.arm.map b/linker/linker.arm.map
index 4a3f177..a58e7c8 100644
--- a/linker/linker.arm.map
+++ b/linker/linker.arm.map
@@ -17,6 +17,7 @@
__loader_android_dlwarning;
__loader_cfi_fail;
__loader_android_link_namespaces;
+ __loader_android_link_namespaces_all_libs;
__loader_android_get_exported_namespace;
__loader_dl_unwind_find_exidx;
__loader_add_thread_local_dtor;
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 7489721..3f898ba 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1430,7 +1430,7 @@
}
// returning true with empty soinfo means that the library is okay to be
- // loaded in the namespace buy has not yet been loaded there before.
+ // loaded in the namespace but has not yet been loaded there before.
task->set_soinfo(nullptr);
return true;
}
@@ -2363,7 +2363,8 @@
add_soinfos_to_namespace(parent_namespace->soinfo_list(), ns);
// and copy parent namespace links
for (auto& link : parent_namespace->linked_namespaces()) {
- ns->add_linked_namespace(link.linked_namespace(), link.shared_lib_sonames());
+ ns->add_linked_namespace(link.linked_namespace(), link.shared_lib_sonames(),
+ link.allow_all_shared_libs());
}
} else {
// If not shared - copy only the shared group
@@ -2399,7 +2400,25 @@
std::unordered_set<std::string> sonames_set(sonames.begin(), sonames.end());
ProtectedDataGuard guard;
- namespace_from->add_linked_namespace(namespace_to, sonames_set);
+ namespace_from->add_linked_namespace(namespace_to, sonames_set, false);
+
+ return true;
+}
+
+bool link_namespaces_all_libs(android_namespace_t* namespace_from,
+ android_namespace_t* namespace_to) {
+ if (namespace_from == nullptr) {
+ DL_ERR("error linking namespaces: namespace_from is null.");
+ return false;
+ }
+
+ if (namespace_to == nullptr) {
+ DL_ERR("error linking namespaces: namespace_to is null.");
+ return false;
+ }
+
+ ProtectedDataGuard guard;
+ namespace_from->add_linked_namespace(namespace_to, std::unordered_set<std::string>(), true);
return true;
}
@@ -3778,7 +3797,11 @@
auto it_to = namespaces.find(ns_link.ns_name());
CHECK(it_to != namespaces.end());
android_namespace_t* namespace_to = it_to->second;
- link_namespaces(namespace_from, namespace_to, ns_link.shared_libs().c_str());
+ if (ns_link.allow_all_shared_libs()) {
+ link_namespaces_all_libs(namespace_from, namespace_to);
+ } else {
+ link_namespaces(namespace_from, namespace_to, ns_link.shared_libs().c_str());
+ }
}
}
// we can no longer rely on the fact that libdl.so is part of default namespace
diff --git a/linker/linker.generic.map b/linker/linker.generic.map
index 04f4c8a..45bb0b5 100644
--- a/linker/linker.generic.map
+++ b/linker/linker.generic.map
@@ -17,6 +17,7 @@
__loader_android_dlwarning;
__loader_cfi_fail;
__loader_android_link_namespaces;
+ __loader_android_link_namespaces_all_libs;
__loader_android_get_exported_namespace;
__loader_add_thread_local_dtor;
__loader_remove_thread_local_dtor;
diff --git a/linker/linker.h b/linker/linker.h
index 6ebca4c..29d40fa 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -180,6 +180,9 @@
android_namespace_t* namespace_to,
const char* shared_lib_sonames);
+bool link_namespaces_all_libs(android_namespace_t* namespace_from,
+ android_namespace_t* namespace_to);
+
android_namespace_t* get_exported_namespace(const char* name);
void increment_dso_handle_reference_counter(void* dso_handle);
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index 60b7ad9..83c2f36 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -489,12 +489,15 @@
return false;
}
+ bool allow_all_shared_libs = properties.get_bool(property_name_prefix + ".link." +
+ linked_ns_name + ".allow_all_shared_libs");
+
std::string shared_libs = properties.get_string(property_name_prefix +
".link." +
linked_ns_name +
".shared_libs", &lineno);
- if (shared_libs.empty()) {
+ if (!allow_all_shared_libs && shared_libs.empty()) {
*error_msg = create_error_msg(ld_config_file_path,
lineno,
std::string("list of shared_libs for ") +
@@ -505,7 +508,15 @@
return false;
}
- ns_config->add_namespace_link(linked_ns_name, shared_libs);
+ if (allow_all_shared_libs && !shared_libs.empty()) {
+ *error_msg = create_error_msg(ld_config_file_path, lineno,
+ std::string("both shared_libs and allow_all_shared_libs "
+ "are set for ") +
+ name + "->" + linked_ns_name + " link.");
+ return false;
+ }
+
+ ns_config->add_namespace_link(linked_ns_name, shared_libs, allow_all_shared_libs);
}
ns_config->set_isolated(properties.get_bool(property_name_prefix + ".isolated"));
diff --git a/linker/linker_config.h b/linker/linker_config.h
index dde9362..0c50d57 100644
--- a/linker/linker_config.h
+++ b/linker/linker_config.h
@@ -43,8 +43,10 @@
class NamespaceLinkConfig {
public:
NamespaceLinkConfig() = default;
- NamespaceLinkConfig(const std::string& ns_name, const std::string& shared_libs)
- : ns_name_(ns_name), shared_libs_(shared_libs) {}
+ NamespaceLinkConfig(const std::string& ns_name, const std::string& shared_libs,
+ bool allow_all_shared_libs)
+ : ns_name_(ns_name), shared_libs_(shared_libs),
+ allow_all_shared_libs_(allow_all_shared_libs) {}
const std::string& ns_name() const {
return ns_name_;
@@ -54,9 +56,14 @@
return shared_libs_;
}
+ bool allow_all_shared_libs() const {
+ return allow_all_shared_libs_;
+ }
+
private:
std::string ns_name_;
std::string shared_libs_;
+ bool allow_all_shared_libs_;
};
class NamespaceConfig {
@@ -89,8 +96,9 @@
return namespace_links_;
}
- void add_namespace_link(const std::string& ns_name, const std::string& shared_libs) {
- namespace_links_.push_back(NamespaceLinkConfig(ns_name, shared_libs));
+ void add_namespace_link(const std::string& ns_name, const std::string& shared_libs,
+ bool allow_all_shared_libs) {
+ namespace_links_.push_back(NamespaceLinkConfig(ns_name, shared_libs, allow_all_shared_libs));
}
void set_isolated(bool isolated) {
diff --git a/linker/linker_namespaces.h b/linker/linker_namespaces.h
index 16906d6..a7fe0d5 100644
--- a/linker/linker_namespaces.h
+++ b/linker/linker_namespaces.h
@@ -40,8 +40,10 @@
struct android_namespace_link_t {
public:
android_namespace_link_t(android_namespace_t* linked_namespace,
- const std::unordered_set<std::string>& shared_lib_sonames)
- : linked_namespace_(linked_namespace), shared_lib_sonames_(shared_lib_sonames)
+ const std::unordered_set<std::string>& shared_lib_sonames,
+ bool allow_all_shared_libs)
+ : linked_namespace_(linked_namespace), shared_lib_sonames_(shared_lib_sonames),
+ allow_all_shared_libs_(allow_all_shared_libs)
{}
android_namespace_t* linked_namespace() const {
@@ -53,12 +55,17 @@
}
bool is_accessible(const char* soname) const {
- return shared_lib_sonames_.find(soname) != shared_lib_sonames_.end();
+ return allow_all_shared_libs_ || shared_lib_sonames_.find(soname) != shared_lib_sonames_.end();
+ }
+
+ bool allow_all_shared_libs() const {
+ return allow_all_shared_libs_;
}
private:
android_namespace_t* const linked_namespace_;
const std::unordered_set<std::string> shared_lib_sonames_;
+ bool allow_all_shared_libs_;
};
struct android_namespace_t {
@@ -105,8 +112,10 @@
return linked_namespaces_;
}
void add_linked_namespace(android_namespace_t* linked_namespace,
- const std::unordered_set<std::string>& shared_lib_sonames) {
- linked_namespaces_.push_back(android_namespace_link_t(linked_namespace, shared_lib_sonames));
+ const std::unordered_set<std::string>& shared_lib_sonames,
+ bool allow_all_shared_libs) {
+ linked_namespaces_.push_back(
+ android_namespace_link_t(linked_namespace, shared_lib_sonames, allow_all_shared_libs));
}
void add_soinfo(soinfo* si) {
diff --git a/linker/tests/linker_config_test.cpp b/linker/tests/linker_config_test.cpp
index 4c0dcdd..e716879 100644
--- a/linker/tests/linker_config_test.cpp
+++ b/linker/tests/linker_config_test.cpp
@@ -81,6 +81,8 @@
"namespace.vndk.search.paths = /system/${LIB}/vndk\n"
"namespace.vndk.asan.search.paths = /data\n"
"namespace.vndk.asan.search.paths += /system/${LIB}/vndk\n"
+ "namespace.vndk.links = default\n"
+ "namespace.vndk.link.default.allow_all_shared_libs = true\n"
"\n";
static bool write_version(const std::string& path, uint32_t version) {
@@ -154,10 +156,14 @@
const auto& default_ns_links = default_ns_config->links();
ASSERT_EQ(2U, default_ns_links.size());
+
ASSERT_EQ("system", default_ns_links[0].ns_name());
ASSERT_EQ("libc.so:libm.so:libdl.so:libstdc++.so", default_ns_links[0].shared_libs());
+ ASSERT_FALSE(default_ns_links[0].allow_all_shared_libs());
+
ASSERT_EQ("vndk", default_ns_links[1].ns_name());
ASSERT_EQ("libcutils.so:libbase.so", default_ns_links[1].shared_libs());
+ ASSERT_FALSE(default_ns_links[1].allow_all_shared_libs());
auto& ns_configs = config->namespace_configs();
ASSERT_EQ(3U, ns_configs.size());
@@ -187,8 +193,13 @@
ASSERT_TRUE(ns_vndk != nullptr) << "vndk namespace was not found";
ASSERT_FALSE(ns_vndk->isolated()); // malformed bool property
- ASSERT_FALSE(ns_vndk->visible()); // undefined bool property
+ ASSERT_FALSE(ns_vndk->visible()); // undefined bool property
ASSERT_EQ(kExpectedVndkSearchPath, ns_vndk->search_paths());
+
+ const auto& ns_vndk_links = ns_vndk->links();
+ ASSERT_EQ(1U, ns_vndk_links.size());
+ ASSERT_EQ("default", ns_vndk_links[0].ns_name());
+ ASSERT_TRUE(ns_vndk_links[0].allow_all_shared_libs());
}
TEST(linker_config, smoke) {
@@ -198,3 +209,40 @@
TEST(linker_config, asan_smoke) {
run_linker_config_smoke_test(true);
}
+
+TEST(linker_config, ns_link_shared_libs_invalid_settings) {
+ // This unit test ensures an error is emitted when a namespace link in ld.config.txt specifies
+ // both shared_libs and allow_all_shared_libs.
+
+ static const char config_str[] =
+ "dir.test = /data/local/tmp\n"
+ "\n"
+ "[test]\n"
+ "additional.namespaces = system\n"
+ "namespace.default.links = system\n"
+ "namespace.default.link.system.shared_libs = libc.so:libm.so\n"
+ "namespace.default.link.system.allow_all_shared_libs = true\n"
+ "\n";
+
+ TemporaryFile tmp_file;
+ close(tmp_file.fd);
+ tmp_file.fd = -1;
+
+ android::base::WriteStringToFile(config_str, tmp_file.path);
+
+ TemporaryDir tmp_dir;
+
+ std::string executable_path = std::string(tmp_dir.path) + "/some-binary";
+
+ const Config* config = nullptr;
+ std::string error_msg;
+ ASSERT_FALSE(Config::read_binary_config(tmp_file.path,
+ executable_path.c_str(),
+ false,
+ &config,
+ &error_msg));
+ ASSERT_TRUE(config == nullptr);
+ ASSERT_EQ(std::string(tmp_file.path) + ":6: "
+ "error: both shared_libs and allow_all_shared_libs are set for default->system link.",
+ error_msg);
+}
diff --git a/tests/Android.bp b/tests/Android.bp
index c1e455d..1521b73 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -554,6 +554,10 @@
"libnstest_root",
"libnstest_public",
"libnstest_public_internal",
+ "libnstest_ns_a_public1",
+ "libnstest_ns_a_public1_internal",
+ "libnstest_ns_b_public2",
+ "libnstest_ns_b_public3",
],
}
diff --git a/tests/ScopedSignalHandler.h b/tests/ScopedSignalHandler.h
index 8998d0d..71f22dc 100644
--- a/tests/ScopedSignalHandler.h
+++ b/tests/ScopedSignalHandler.h
@@ -53,13 +53,13 @@
const int signal_number_;
};
-class ScopedSignalMask {
+class SignalMaskRestorer {
public:
- ScopedSignalMask() {
+ SignalMaskRestorer() {
sigprocmask(SIG_SETMASK, nullptr, &old_mask_);
}
- ~ScopedSignalMask() {
+ ~SignalMaskRestorer() {
sigprocmask(SIG_SETMASK, &old_mask_, nullptr);
}
diff --git a/tests/dlext_private.h b/tests/dlext_private.h
index dea92ee..2621a68 100644
--- a/tests/dlext_private.h
+++ b/tests/dlext_private.h
@@ -95,6 +95,9 @@
android_namespace_t* to,
const char* shared_libs_sonames);
+extern bool android_link_namespaces_all_libs(android_namespace_t* from,
+ android_namespace_t* to);
+
extern void android_set_application_target_sdk_version(uint32_t target);
__END_DECLS
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 64cfa08..bb2d8a3 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -1737,6 +1737,123 @@
ASSERT_EQ(expected_dlerror, dlerror());
}
+TEST(dlext, ns_link_namespaces_invalid_arguments) {
+ ASSERT_TRUE(android_init_anonymous_namespace(g_core_shared_libs.c_str(), nullptr));
+
+ android_namespace_t* ns =
+ android_create_namespace("private",
+ nullptr,
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
+ ANDROID_NAMESPACE_TYPE_REGULAR,
+ nullptr,
+ nullptr);
+ ASSERT_TRUE(ns != nullptr) << dlerror();
+
+ // Test android_link_namespaces()
+ ASSERT_FALSE(android_link_namespaces(nullptr, nullptr, "libc.so"));
+ ASSERT_STREQ("android_link_namespaces failed: error linking namespaces: namespace_from is null.",
+ dlerror());
+
+ ASSERT_FALSE(android_link_namespaces(ns, nullptr, nullptr));
+ ASSERT_STREQ("android_link_namespaces failed: "
+ "error linking namespaces \"private\"->\"(default)\": "
+ "the list of shared libraries is empty.", dlerror());
+
+ ASSERT_FALSE(android_link_namespaces(ns, nullptr, ""));
+ ASSERT_STREQ("android_link_namespaces failed: "
+ "error linking namespaces \"private\"->\"(default)\": "
+ "the list of shared libraries is empty.", dlerror());
+
+ // Test android_link_namespaces_all_libs()
+ ASSERT_FALSE(android_link_namespaces_all_libs(nullptr, nullptr));
+ ASSERT_STREQ("android_link_namespaces_all_libs failed: "
+ "error linking namespaces: namespace_from is null.", dlerror());
+
+ ASSERT_FALSE(android_link_namespaces_all_libs(nullptr, ns));
+ ASSERT_STREQ("android_link_namespaces_all_libs failed: "
+ "error linking namespaces: namespace_from is null.", dlerror());
+
+ ASSERT_FALSE(android_link_namespaces_all_libs(ns, nullptr));
+ ASSERT_STREQ("android_link_namespaces_all_libs failed: "
+ "error linking namespaces: namespace_to is null.", dlerror());
+}
+
+TEST(dlext, ns_allow_all_shared_libs) {
+ ASSERT_TRUE(android_init_anonymous_namespace(g_core_shared_libs.c_str(), nullptr));
+
+ android_namespace_t* ns_a =
+ android_create_namespace("ns_a",
+ nullptr,
+ (get_testlib_root() + "/ns_a").c_str(),
+ ANDROID_NAMESPACE_TYPE_ISOLATED,
+ nullptr,
+ nullptr);
+ ASSERT_TRUE(ns_a != nullptr) << dlerror();
+ ASSERT_TRUE(android_link_namespaces(ns_a, nullptr, g_core_shared_libs.c_str())) << dlerror();
+
+ android_namespace_t* ns_b =
+ android_create_namespace("ns_b",
+ nullptr,
+ (get_testlib_root() + "/ns_b").c_str(),
+ ANDROID_NAMESPACE_TYPE_ISOLATED,
+ nullptr,
+ nullptr);
+ ASSERT_TRUE(ns_b != nullptr) << dlerror();
+ ASSERT_TRUE(android_link_namespaces(ns_b, nullptr, g_core_shared_libs.c_str())) << dlerror();
+
+ ASSERT_TRUE(android_link_namespaces(ns_b, ns_a, "libnstest_ns_a_public1.so")) << dlerror();
+ ASSERT_TRUE(android_link_namespaces_all_libs(ns_a, ns_b)) << dlerror();
+
+ // Load libs with android_dlopen_ext() from namespace b
+ android_dlextinfo extinfo;
+ extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE;
+ extinfo.library_namespace = ns_b;
+
+ void* ns_b_handle1 = android_dlopen_ext("libnstest_ns_a_public1.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_b_handle1 != nullptr) << dlerror();
+
+ void* ns_b_handle1_internal =
+ android_dlopen_ext("libnstest_ns_a_public1_internal.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_b_handle1_internal == nullptr);
+
+ void* ns_b_handle2 = android_dlopen_ext("libnstest_ns_b_public2.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_b_handle2 != nullptr) << dlerror();
+
+ void* ns_b_handle3 = android_dlopen_ext("libnstest_ns_b_public3.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_b_handle3 != nullptr) << dlerror();
+
+ // Load libs with android_dlopen_ext() from namespace a
+ extinfo.library_namespace = ns_a;
+
+ void* ns_a_handle1 = android_dlopen_ext("libnstest_ns_a_public1.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_a_handle1 != nullptr) << dlerror();
+
+ void* ns_a_handle1_internal =
+ android_dlopen_ext("libnstest_ns_a_public1_internal.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_a_handle1_internal != nullptr) << dlerror();
+
+ void* ns_a_handle2 = android_dlopen_ext("libnstest_ns_b_public2.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_a_handle2 != nullptr) << dlerror();
+
+ void* ns_a_handle3 = android_dlopen_ext("libnstest_ns_b_public3.so", RTLD_NOW, &extinfo);
+ ASSERT_TRUE(ns_a_handle3 != nullptr) << dlerror();
+
+ // Compare the dlopen handle
+ ASSERT_EQ(ns_b_handle1, ns_a_handle1);
+ ASSERT_EQ(ns_b_handle2, ns_a_handle2);
+ ASSERT_EQ(ns_b_handle3, ns_a_handle3);
+
+ // Close libs
+ dlclose(ns_b_handle1);
+ dlclose(ns_b_handle2);
+ dlclose(ns_b_handle3);
+
+ dlclose(ns_a_handle1);
+ dlclose(ns_a_handle1_internal);
+ dlclose(ns_a_handle2);
+ dlclose(ns_a_handle3);
+}
+
TEST(dlext, ns_anonymous) {
static const char* root_lib = "libnstest_root.so";
std::string shared_libs = g_core_shared_libs + ":" + g_public_lib;
diff --git a/tests/headers/posix/pthread_h.c b/tests/headers/posix/pthread_h.c
index 4fa5b9d..4be822c 100644
--- a/tests/headers/posix/pthread_h.c
+++ b/tests/headers/posix/pthread_h.c
@@ -57,9 +57,9 @@
MACRO(PTHREAD_ONCE_INIT);
-#if !defined(__BIONIC__) // No robust mutexes on Android.
MACRO(PTHREAD_PRIO_INHERIT);
MACRO(PTHREAD_PRIO_NONE);
+#if !defined(__BIONIC__)
MACRO(PTHREAD_PRIO_PROTECT);
#endif
@@ -158,8 +158,8 @@
FUNCTION(pthread_mutexattr_destroy, int (*f)(pthread_mutexattr_t*));
#if !defined(__BIONIC__) // No robust mutexes on Android.
FUNCTION(pthread_mutexattr_getprioceiling, int (*f)(const pthread_mutexattr_t*, int*));
- FUNCTION(pthread_mutexattr_getprotocol, int (*f)(const pthread_mutexattr_t*, int*));
#endif
+ FUNCTION(pthread_mutexattr_getprotocol, int (*f)(const pthread_mutexattr_t*, int*));
FUNCTION(pthread_mutexattr_getpshared, int (*f)(const pthread_mutexattr_t*, int*));
#if !defined(__BIONIC__) // No robust mutexes on Android.
FUNCTION(pthread_mutexattr_getrobust, int (*f)(const pthread_mutexattr_t*, int*));
@@ -168,8 +168,8 @@
FUNCTION(pthread_mutexattr_init, int (*f)(pthread_mutexattr_t*));
#if !defined(__BIONIC__) // No robust mutexes on Android.
FUNCTION(pthread_mutexattr_setprioceiling, int (*f)(pthread_mutexattr_t*, int));
- FUNCTION(pthread_mutexattr_setprotocol, int (*f)(pthread_mutexattr_t*, int));
#endif
+ FUNCTION(pthread_mutexattr_setprotocol, int (*f)(pthread_mutexattr_t*, int));
FUNCTION(pthread_mutexattr_setpshared, int (*f)(pthread_mutexattr_t*, int));
#if !defined(__BIONIC__) // No robust mutexes on Android.
FUNCTION(pthread_mutexattr_setrobust, int (*f)(pthread_mutexattr_t*, int));
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 61a837f..cae30b5 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -259,6 +259,58 @@
}
// -----------------------------------------------------------------------------
+// Build test helper libraries for linker namespaces for allow all shared libs
+//
+// This set of libraries is used to verify linker namespaces for allow all
+// shared libs.
+//
+// Test cases
+// 1. Check that namespace a exposes libnstest_ns_a_public1 to
+// namespace b while keeping libnstest_ns_a_public1_internal as an
+// internal lib.
+// 2. Check that namespace b exposes all libraries to namespace a.
+//
+// Dependency tree (visibility)
+// libnstest_ns_b_public2.so (ns:b)
+// +-> libnstest_ns_a_public1.so (ns:a)
+// +-> libnstest_ns_a_public2_internal.so (ns:a)
+// +-> libnstest_ns_b_public3.so (ns:b)
+//
+// -----------------------------------------------------------------------------
+cc_test_library {
+ name: "libnstest_ns_a_public1",
+ defaults: ["bionic_testlib_defaults"],
+ srcs: ["libnstest_ns_a_public1.cpp"],
+ relative_install_path: "bionic-loader-test-libs/ns_a",
+ shared_libs: [
+ "libnstest_ns_a_public1_internal",
+ "libnstest_ns_b_public3",
+ ],
+}
+
+cc_test_library {
+ name: "libnstest_ns_a_public1_internal",
+ defaults: ["bionic_testlib_defaults"],
+ srcs: ["libnstest_ns_a_public1_internal.cpp"],
+ relative_install_path: "bionic-loader-test-libs/ns_a",
+}
+
+cc_test_library {
+ name: "libnstest_ns_b_public2",
+ defaults: ["bionic_testlib_defaults"],
+ srcs: ["libnstest_ns_b_public2.cpp"],
+ relative_install_path: "bionic-loader-test-libs/ns_b",
+ shared_libs: ["libnstest_ns_a_public1"],
+}
+
+cc_test_library {
+ name: "libnstest_ns_b_public3",
+ defaults: ["bionic_testlib_defaults"],
+ srcs: ["libnstest_ns_b_public3.cpp"],
+ relative_install_path: "bionic-loader-test-libs/ns_b",
+}
+
+// -----------------------------------------------------------------------------
// Build DT_RUNPATH test helper libraries
// -----------------------------------------------------------------------------
// include $(LOCAL_PATH)/Android.build.dt_runpath.mk
diff --git a/tests/libs/libnstest_ns_a_public1.cpp b/tests/libs/libnstest_ns_a_public1.cpp
new file mode 100644
index 0000000..c095e60
--- /dev/null
+++ b/tests/libs/libnstest_ns_a_public1.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+static const char ns_a_public1_string[] = "libnstest_ns_a_public1.so";
+
+extern "C" const char* get_ns_a_public1_string() {
+ return ns_a_public1_string;
+}
+
+
+extern "C" const char *get_ns_a_public1_internal_string();
+
+extern "C" const char *delegate_get_ns_a_public1_internal_string() {
+ return get_ns_a_public1_internal_string();
+}
+
+
+extern "C" const char *get_ns_b_public3_string();
+
+extern "C" const char *delegate_get_ns_b_public3_string() {
+ return get_ns_b_public3_string();
+}
diff --git a/tests/libs/libnstest_ns_a_public1_internal.cpp b/tests/libs/libnstest_ns_a_public1_internal.cpp
new file mode 100644
index 0000000..6529936
--- /dev/null
+++ b/tests/libs/libnstest_ns_a_public1_internal.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+static const char ns_a_public1_internal_string[] = "libnstest_ns_a_public1_internal.so";
+
+extern "C" const char* get_ns_a_public1_internal_string() {
+ return ns_a_public1_internal_string;
+}
diff --git a/tests/libs/libnstest_ns_b_public2.cpp b/tests/libs/libnstest_ns_b_public2.cpp
new file mode 100644
index 0000000..6251a8d
--- /dev/null
+++ b/tests/libs/libnstest_ns_b_public2.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+static const char ns_b_public2_string[] = "libnstest_ns_b_public2.so";
+
+extern "C" const char* get_ns_b_public2_string() {
+ return ns_b_public2_string;
+}
+
+
+extern "C" const char* get_ns_a_public1_string();
+
+extern "C" const char* delegate_get_ns_a_public1_string() {
+ return get_ns_a_public1_string();
+}
diff --git a/tests/libs/libnstest_ns_b_public3.cpp b/tests/libs/libnstest_ns_b_public3.cpp
new file mode 100644
index 0000000..b332445
--- /dev/null
+++ b/tests/libs/libnstest_ns_b_public3.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+static const char ns_b_public3_string[] = "libnstest_ns_b_public3.so";
+
+extern "C" const char* get_ns_b_public3_string() {
+ return ns_b_public3_string;
+}
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 207c156..5cbec88 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -464,33 +464,45 @@
ASSERT_EQ(EINVAL, errno);
}
-TEST(signal, sighold_sigpause_sigrelse) {
- static int sigalrm_handler_call_count;
- auto sigalrm_handler = [](int) { sigalrm_handler_call_count++; };
- ScopedSignalHandler sigalrm{SIGALRM, sigalrm_handler};
- ScopedSignalMask mask;
+static void TestSigholdSigpauseSigrelse(int sig) {
+ static int signal_handler_call_count = 0;
+ ScopedSignalHandler ssh{sig, [](int) { signal_handler_call_count++; }};
+ SignalMaskRestorer mask_restorer;
sigset_t set;
- // sighold(SIGALRM) should add SIGALRM to the signal mask ...
- ASSERT_EQ(0, sighold(SIGALRM));
+ // sighold(SIGALRM/SIGRTMIN) should add SIGALRM/SIGRTMIN to the signal mask ...
+ ASSERT_EQ(0, sighold(sig));
ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
- EXPECT_TRUE(sigismember(&set, SIGALRM));
+ EXPECT_TRUE(sigismember(&set, sig));
- // ... preventing our SIGALRM handler from running ...
- raise(SIGALRM);
- ASSERT_EQ(0, sigalrm_handler_call_count);
- // ... until sigpause(SIGALRM) temporarily unblocks it.
- ASSERT_EQ(-1, sigpause(SIGALRM));
+ // ... preventing our SIGALRM/SIGRTMIN handler from running ...
+ raise(sig);
+ ASSERT_EQ(0, signal_handler_call_count);
+ // ... until sigpause(SIGALRM/SIGRTMIN) temporarily unblocks it.
+ ASSERT_EQ(-1, sigpause(sig));
ASSERT_EQ(EINTR, errno);
- ASSERT_EQ(1, sigalrm_handler_call_count);
+ ASSERT_EQ(1, signal_handler_call_count);
- // But sigpause(SIGALRM) shouldn't permanently unblock SIGALRM.
- ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
- EXPECT_TRUE(sigismember(&set, SIGALRM));
+ if (sig >= SIGRTMIN && sizeof(void*) == 8) {
+ // But sigpause(SIGALRM/SIGRTMIN) shouldn't permanently unblock SIGALRM/SIGRTMIN.
+ ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+ EXPECT_TRUE(sigismember(&set, sig));
- ASSERT_EQ(0, sigrelse(SIGALRM));
- ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
- EXPECT_FALSE(sigismember(&set, SIGALRM));
+ // Whereas sigrelse(SIGALRM/SIGRTMIN) should.
+ ASSERT_EQ(0, sigrelse(sig));
+ ASSERT_EQ(0, sigprocmask(SIG_SETMASK, 0, &set));
+ EXPECT_FALSE(sigismember(&set, sig));
+ } else {
+ // sigismember won't work for SIGRTMIN on LP32.
+ }
+}
+
+TEST(signal, sighold_sigpause_sigrelse) {
+ TestSigholdSigpauseSigrelse(SIGALRM);
+}
+
+TEST(signal, sighold_sigpause_sigrelse_RT) {
+ TestSigholdSigpauseSigrelse(SIGRTMIN);
}
TEST(signal, sigset_EINVAL) {
@@ -499,23 +511,48 @@
ASSERT_EQ(EINVAL, errno);
}
-TEST(signal, sigset) {
- auto sigalrm_handler = [](int) { };
- ScopedSignalHandler sigalrm{SIGALRM, sigalrm_handler};
- ScopedSignalMask mask;
+TEST(signal, sigset_RT) {
+ static int signal_handler_call_count = 0;
+ auto signal_handler = [](int) { signal_handler_call_count++; };
+ ScopedSignalHandler ssh{SIGRTMIN, signal_handler};
+ SignalMaskRestorer mask_restorer;
- // block SIGALRM so the next sigset(SIGARLM) call will return SIG_HOLD
- sigset_t sigalrm_set;
- sigemptyset(&sigalrm_set);
- sigaddset(&sigalrm_set, SIGALRM);
- ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigalrm_set, nullptr));
-
+ ASSERT_EQ(signal_handler, sigset(SIGRTMIN, SIG_HOLD));
+#if defined(__LP64__)
sigset_t set;
- ASSERT_EQ(SIG_HOLD, sigset(SIGALRM, sigalrm_handler));
+ ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
+ ASSERT_TRUE(sigismember(&set, SIGRTMIN));
+#endif
+
+ ASSERT_EQ(SIG_HOLD, sigset(SIGRTMIN, signal_handler));
+ ASSERT_EQ(signal_handler, sigset(SIGRTMIN, signal_handler));
+ ASSERT_EQ(0, signal_handler_call_count);
+ raise(SIGRTMIN);
+ ASSERT_EQ(1, signal_handler_call_count);
+}
+
+TEST(signal, sigset) {
+ static int signal_handler_call_count = 0;
+ auto signal_handler = [](int) { signal_handler_call_count++; };
+ ScopedSignalHandler ssh{SIGALRM, signal_handler};
+ SignalMaskRestorer mask_restorer;
+
+ ASSERT_EQ(0, signal_handler_call_count);
+ raise(SIGALRM);
+ ASSERT_EQ(1, signal_handler_call_count);
+
+ // Block SIGALRM so the next sigset(SIGARLM) call will return SIG_HOLD.
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGALRM);
+ ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &set, nullptr));
+
+ sigemptyset(&set);
+ ASSERT_EQ(SIG_HOLD, sigset(SIGALRM, signal_handler));
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
EXPECT_FALSE(sigismember(&set, SIGALRM));
- ASSERT_EQ(sigalrm_handler, sigset(SIGALRM, SIG_IGN));
+ ASSERT_EQ(signal_handler, sigset(SIGALRM, SIG_IGN));
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set));
EXPECT_FALSE(sigismember(&set, SIGALRM));
diff --git a/tests/spawn_test.cpp b/tests/spawn_test.cpp
index d2e4ea1..dfce0dc 100644
--- a/tests/spawn_test.cpp
+++ b/tests/spawn_test.cpp
@@ -376,6 +376,7 @@
sigset_t just_SIGALRM;
sigemptyset(&just_SIGALRM);
sigaddset(&just_SIGALRM, SIGALRM);
+
ASSERT_EQ(0, posix_spawnattr_setsigdefault(&sa, &just_SIGALRM));
ASSERT_EQ(0, posix_spawnattr_setflags(&sa, POSIX_SPAWN_SETSIGDEF));
@@ -393,15 +394,18 @@
// child without first defaulting any caught signals (http://b/68707996).
static pid_t parent = getpid();
+ setpgid(0, 0);
+
pid_t pid = fork();
ASSERT_NE(-1, pid);
if (pid == 0) {
+ signal(SIGRTMIN, SIG_IGN);
for (size_t i = 0; i < 1024; ++i) {
- kill(0, SIGWINCH);
+ kill(0, SIGRTMIN);
usleep(10);
}
- return;
+ _exit(99);
}
// We test both with and without attributes, because they used to be
@@ -417,11 +421,15 @@
posix_spawnattr_t* attrs[] = { nullptr, &attr1, &attr2 };
- ScopedSignalHandler ssh(SIGWINCH, [](int) { ASSERT_EQ(getpid(), parent); });
+ // We use a real-time signal because that's a tricky case for LP32
+ // because our sigset_t was too small.
+ ScopedSignalHandler ssh(SIGRTMIN, [](int) { ASSERT_EQ(getpid(), parent); });
ExecTestHelper eth;
eth.SetArgs({"true", nullptr});
for (size_t i = 0; i < 128; ++i) {
posix_spawn(nullptr, "true", nullptr, attrs[i % 3], eth.GetArgs(), nullptr);
}
+
+ AssertChildExited(pid, 99);
}