Merge "Revert "Skip Clang's integrated-as for hand-coded assembly""
diff --git a/libc/bionic/getpid.cpp b/libc/bionic/getpid.cpp
index a3d5b35..779b147 100644
--- a/libc/bionic/getpid.cpp
+++ b/libc/bionic/getpid.cpp
@@ -35,10 +35,12 @@
pid_t getpid() {
pthread_internal_t* self = __get_thread();
- // Do we have a valid cached pid?
- pid_t cached_pid;
- if (__predict_true(self->get_cached_pid(&cached_pid))) {
- return cached_pid;
+ if (__predict_true(self)) {
+ // Do we have a valid cached pid?
+ pid_t cached_pid;
+ if (__predict_true(self->get_cached_pid(&cached_pid))) {
+ return cached_pid;
+ }
}
// We're still in the dynamic linker or we're in the middle of forking, so ask the kernel.
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 0c9e87b..2070c9c 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -41,13 +41,14 @@
#include <sys/time.h>
#include <unistd.h>
+#include "private/KernelArgumentBlock.h"
+#include "private/WriteProtected.h"
#include "private/bionic_auxv.h"
#include "private/bionic_globals.h"
#include "private/bionic_ssp.h"
#include "private/bionic_tls.h"
-#include "private/KernelArgumentBlock.h"
#include "private/libc_logging.h"
-#include "private/WriteProtected.h"
+#include "private/thread_private.h"
#include "pthread_internal.h"
extern "C" abort_msg_t** __abort_message_ptr;
@@ -108,6 +109,11 @@
}
#endif
+static void arc4random_fork_handler() {
+ _rs_forked = 1;
+ _thread_arc4_lock();
+}
+
void __libc_init_common(KernelArgumentBlock& args) {
// Initialize various globals.
environ = args.envp;
@@ -123,6 +129,9 @@
pthread_internal_t* main_thread = __get_thread();
__pthread_internal_add(main_thread);
+ // Register atfork handlers to take and release the arc4random lock.
+ pthread_atfork(arc4random_fork_handler, _thread_arc4_unlock, _thread_arc4_unlock);
+
__system_properties_init(); // Requires 'environ'.
}
diff --git a/libc/include/error.h b/libc/include/error.h
index 205890f..18ce379 100644
--- a/libc/include/error.h
+++ b/libc/include/error.h
@@ -33,8 +33,8 @@
__BEGIN_DECLS
-void error(int, int, const char*, ...) __printflike(3, 4) __INTRODUCED_IN(23);
-void error_at_line(int, int, const char*, unsigned int, const char*, ...) __printflike(5, 6)
+void error(int, int, const char* _Nonnull, ...) __printflike(3, 4) __INTRODUCED_IN(23);
+void error_at_line(int, int, const char*, unsigned int, const char* _Nonnull, ...) __printflike(5, 6)
__INTRODUCED_IN(23);
extern void (*error_print_progname)(void) __INTRODUCED_IN(23);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index ef660d8..3e666d4 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -105,13 +105,11 @@
int fflush(FILE *);
int fgetc(FILE *);
char *fgets(char * __restrict, int, FILE * __restrict);
-int fprintf(FILE * __restrict , const char * __restrict, ...)
- __printflike(2, 3);
+int fprintf(FILE * __restrict , const char * __restrict _Nonnull, ...) __printflike(2, 3);
int fputc(int, FILE *);
int fputs(const char * __restrict, FILE * __restrict);
size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
-int fscanf(FILE * __restrict, const char * __restrict, ...)
- __scanflike(2, 3);
+int fscanf(FILE * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3);
size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
int getc(FILE *);
int getchar(void);
@@ -119,35 +117,28 @@
ssize_t getline(char** __restrict, size_t* __restrict, FILE* __restrict) __INTRODUCED_IN(18);
void perror(const char *);
-int printf(const char * __restrict, ...)
- __printflike(1, 2);
+int printf(const char * __restrict _Nonnull, ...) __printflike(1, 2);
int putc(int, FILE *);
int putchar(int);
int puts(const char *);
int remove(const char *);
void rewind(FILE *);
-int scanf(const char * __restrict, ...)
- __scanflike(1, 2);
+int scanf(const char * __restrict _Nonnull, ...) __scanflike(1, 2);
void setbuf(FILE * __restrict, char * __restrict);
int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
-int sscanf(const char * __restrict, const char * __restrict, ...)
- __scanflike(2, 3);
+int sscanf(const char * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3);
int ungetc(int, FILE *);
-int vfprintf(FILE * __restrict, const char * __restrict, __va_list)
- __printflike(2, 0);
-int vprintf(const char * __restrict, __va_list)
- __printflike(1, 0);
+int vfprintf(FILE * __restrict, const char * __restrict _Nonnull, __va_list) __printflike(2, 0);
+int vprintf(const char * __restrict _Nonnull, __va_list) __printflike(1, 0);
-int dprintf(int, const char* __restrict, ...) __printflike(2, 3) __INTRODUCED_IN(21);
-int vdprintf(int, const char* __restrict, __va_list) __printflike(2, 0) __INTRODUCED_IN(21);
+int dprintf(int, const char* __restrict _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21);
+int vdprintf(int, const char* __restrict _Nonnull, __va_list) __printflike(2, 0) __INTRODUCED_IN(21);
#if __STDC_VERSION__ < 201112L
char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
#endif
-int sprintf(char* __restrict, const char* __restrict, ...)
- __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");
-int vsprintf(char* __restrict, const char* __restrict, __va_list)
- __printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
+int sprintf(char* __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");
+int vsprintf(char* __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
char* tmpnam(char*) __attribute__((deprecated("tmpnam is unsafe, use mkstemp or tmpfile instead")));
#if defined(__USE_BSD) || defined(__USE_GNU)
#define P_tmpdir "/tmp/" /* deprecated */
@@ -203,11 +194,11 @@
FILE* tmpfile(void);
FILE* tmpfile64(void) __INTRODUCED_IN(24);
-int snprintf(char* __restrict, size_t, const char* __restrict, ...) __printflike(3, 4);
-int vfscanf(FILE* __restrict, const char* __restrict, __va_list) __scanflike(2, 0);
-int vscanf(const char*, __va_list) __scanflike(1, 0);
-int vsnprintf(char* __restrict, size_t, const char* __restrict, __va_list) __printflike(3, 0);
-int vsscanf(const char* __restrict, const char* __restrict, __va_list) __scanflike(2, 0);
+int snprintf(char* __restrict, size_t, const char* __restrict _Nonnull, ...) __printflike(3, 4);
+int vfscanf(FILE* __restrict, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0);
+int vscanf(const char* _Nonnull , __va_list) __scanflike(1, 0);
+int vsnprintf(char* __restrict, size_t, const char* __restrict _Nonnull, __va_list) __printflike(3, 0);
+int vsscanf(const char* __restrict _Nonnull, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0);
#define L_ctermid 1024 /* size for ctermid() */
char* ctermid(char*) __INTRODUCED_IN_FUTURE;
@@ -228,12 +219,12 @@
FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
-int asprintf(char** __restrict, const char* __restrict, ...) __printflike(2, 3);
+int asprintf(char** __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3);
char* fgetln(FILE* __restrict, size_t* __restrict);
int fpurge(FILE*);
void setbuffer(FILE*, char*, int);
int setlinebuf(FILE*);
-int vasprintf(char** __restrict, const char* __restrict, __va_list) __printflike(2, 0);
+int vasprintf(char** __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0);
void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
int feof_unlocked(FILE*) __INTRODUCED_IN(23);
int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
@@ -262,16 +253,12 @@
#if defined(__BIONIC_FORTIFY)
__BIONIC_FORTIFY_INLINE
-__printflike(3, 0)
-int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
-{
+__printflike(3, 0) int vsnprintf(char* dest, size_t size, const char* _Nonnull format, __va_list ap) {
return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
}
__BIONIC_FORTIFY_INLINE
-__printflike(2, 0)
-int vsprintf(char *dest, const char *format, __va_list ap)
-{
+__printflike(2, 0) int vsprintf(char* dest, const char* _Nonnull format, __va_list ap) {
return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
}
@@ -282,11 +269,8 @@
#endif
#else
__BIONIC_FORTIFY_INLINE
-__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());
+__printflike(3, 4) int snprintf(char* dest, size_t size, const char* _Nonnull format, ...) {
+ return __builtin___snprintf_chk(dest, size, 0, __bos(dest), format, __builtin_va_arg_pack());
}
#endif
@@ -297,11 +281,8 @@
#endif
#else
__BIONIC_FORTIFY_INLINE
-__printflike(2, 3)
-int sprintf(char *dest, const char *format, ...)
-{
- return __builtin___sprintf_chk(dest, 0,
- __bos(dest), format, __builtin_va_arg_pack());
+__printflike(2, 3) int sprintf(char* dest, const char* _Nonnull format, ...) {
+ return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack());
}
#endif
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 8cde1c7..26d0382 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -140,7 +140,7 @@
* // The following null check will be elided because nonnull attribute
* // means that, since we call foo with p, p can be assumed to not be
* // null. Thus this will crash if we are called with a null pointer.
- * if (src != NULL) {
+ * if (p != NULL) {
* return *p;
* }
* return 0;
@@ -156,10 +156,8 @@
#define _Nonnull
#endif
-#define __nonnull(args) __attribute__((__nonnull__ args))
-
-#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x))
-#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
+#define __printflike(x, y) __attribute__((__format__(printf, x, y)))
+#define __scanflike(x, y) __attribute__((__format__(scanf, x, y)))
/*
* GNU C version 2.96 added explicit branch prediction so that
diff --git a/libc/include/syslog.h b/libc/include/syslog.h
index 8000f03..d51c9f2 100644
--- a/libc/include/syslog.h
+++ b/libc/include/syslog.h
@@ -88,8 +88,8 @@
void closelog(void);
void openlog(const char*, int, int);
int setlogmask(int);
-void syslog(int, const char*, ...) __printflike(2, 3);
-void vsyslog(int, const char*, va_list) __printflike(2, 0);
+void syslog(int, const char* _Nonnull, ...) __printflike(2, 3);
+void vsyslog(int, const char* _Nonnull, va_list) __printflike(2, 0);
__END_DECLS
diff --git a/libc/private/libc_logging.h b/libc/private/libc_logging.h
index 4aa3ece..aa96090 100644
--- a/libc/private/libc_logging.h
+++ b/libc/private/libc_logging.h
@@ -68,29 +68,25 @@
};
// Formats a message to the log (priority 'fatal'), then aborts.
-__LIBC_HIDDEN__ __noreturn void __libc_fatal(const char* fmt, ...) __printflike(1, 2);
+__noreturn void __libc_fatal(const char* _Nonnull, ...) __printflike(1, 2);
// Formats a message to the log (priority 'fatal'), prefixed by "FORTIFY: ", then aborts.
-__LIBC_HIDDEN__ __noreturn void __fortify_fatal(const char* fmt, ...) __printflike(1, 2);
+__noreturn void __fortify_fatal(const char* _Nonnull, ...) __printflike(1, 2);
//
// Formatting routines for the C library's internal debugging.
// Unlike the usual alternatives, these don't allocate, and they don't drag in all of stdio.
//
-__LIBC_HIDDEN__ int __libc_format_buffer(char* buffer, size_t buffer_size, const char* format, ...)
- __printflike(3, 4);
-
-__LIBC_HIDDEN__ int __libc_format_fd(int fd, const char* format, ...)
- __printflike(2, 3);
-
-__LIBC_HIDDEN__ int __libc_format_log(int priority, const char* tag, const char* format, ...)
- __printflike(3, 4);
-
-__LIBC_HIDDEN__ int __libc_format_log_va_list(int priority, const char* tag, const char* format,
- va_list ap);
-
-__LIBC_HIDDEN__ int __libc_write_log(int priority, const char* tag, const char* msg);
+int __libc_format_buffer(char* _Nonnull buf, size_t size, const char* _Nonnull fmt, ...) __printflike(3, 4);
+int __libc_format_fd(int fd, const char* _Nonnull format , ...) __printflike(2, 3);
+int __libc_format_log(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, ...) __printflike(3, 4);
+#if defined(__arm__) || defined(__aarch64__)
+int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list ap);
+#else
+int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list _Nonnull ap);
+#endif
+int __libc_write_log(int pri, const char* _Nonnull tag, const char* _Nonnull msg);
__END_DECLS
diff --git a/libc/private/thread_private.h b/libc/private/thread_private.h
index 2e3ac3d..0081ad0 100644
--- a/libc/private/thread_private.h
+++ b/libc/private/thread_private.h
@@ -50,6 +50,8 @@
#define _ARC4_UNLOCK() _thread_arc4_unlock()
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+extern volatile sig_atomic_t _rs_forked;
+
__END_DECLS
#endif /* _THREAD_PRIVATE_H_ */
diff --git a/libc/upstream-openbsd/android/include/arc4random.h b/libc/upstream-openbsd/android/include/arc4random.h
index 96d9c9a..8d965e0 100644
--- a/libc/upstream-openbsd/android/include/arc4random.h
+++ b/libc/upstream-openbsd/android/include/arc4random.h
@@ -49,13 +49,7 @@
raise(SIGKILL);
}
-static volatile sig_atomic_t _rs_forked;
-
-static inline void
-_rs_forkhandler(void)
-{
- _rs_forked = 1;
-}
+volatile sig_atomic_t _rs_forked;
static inline void
_rs_forkdetect(void)
@@ -90,6 +84,5 @@
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, *rsxp, sizeof(**rsxp),
"arc4random _rsx structure");
- _ARC4_ATFORK(_rs_forkhandler);
return (0);
}
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index 5229797..e161cec 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ