Merge "Add sanity checks for e_shentsize and e_shstrndx"
diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp
index 01bb9bb..2643eee 100644
--- a/libc/bionic/__libc_init_main_thread.cpp
+++ b/libc/bionic/__libc_init_main_thread.cpp
@@ -28,14 +28,24 @@
#include "libc_init_common.h"
+#include "private/KernelArgumentBlock.h"
#include "private/bionic_auxv.h"
#include "private/bionic_globals.h"
-#include "private/KernelArgumentBlock.h"
+#include "private/bionic_ssp.h"
#include "pthread_internal.h"
extern "C" int __set_tls(void* ptr);
extern "C" int __set_tid_address(int* tid_address);
+// Declared in "private/bionic_ssp.h".
+uintptr_t __stack_chk_guard = 0;
+
+void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args) {
+ // AT_RANDOM is a pointer to 16 bytes of randomness on the stack.
+ // Take the first 4/8 for the -fstack-protector implementation.
+ __stack_chk_guard = *reinterpret_cast<uintptr_t*>(args.getauxval(AT_RANDOM));
+}
+
// Setup for the main thread. For dynamic executables, this is called by the
// linker _before_ libc is mapped in memory. This means that all writes to
// globals from this function will apply to linker-private copies and will not
@@ -78,7 +88,8 @@
// TODO: the main thread's sched_policy and sched_priority need to be queried.
// The TLS stack guard is set from the global, so ensure that we've initialized the global
- // before we initialize the TLS.
+ // before we initialize the TLS. Dynamic executables will initialize their copy of the global
+ // stack protector from the one in the main thread's TLS.
__libc_init_global_stack_chk_guard(args);
__init_thread(&main_thread);
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 2070c9c..919080b 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -45,7 +45,6 @@
#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/libc_logging.h"
#include "private/thread_private.h"
@@ -62,15 +61,6 @@
// Declared in <unistd.h>.
char** environ;
-// Declared in "private/bionic_ssp.h".
-uintptr_t __stack_chk_guard = 0;
-
-void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args) {
- // AT_RANDOM is a pointer to 16 bytes of randomness on the stack.
- // Take the first 4/8 for the -fstack-protector implementation.
- __stack_chk_guard = *reinterpret_cast<uintptr_t*>(args.getauxval(AT_RANDOM));
-}
-
#if defined(__i386__)
__LIBC_HIDDEN__ void* __libc_sysinfo = nullptr;
@@ -91,7 +81,6 @@
// Initialize libc globals that are needed in both the linker and in libc.
// In dynamic binaries, this is run at least twice for different copies of the
// globals, once for the linker's copy and once for the one in libc.so.
- __libc_init_global_stack_chk_guard(args);
__libc_auxv = args.auxv;
__libc_globals.initialize();
__libc_globals.mutate([&args](libc_globals* globals) {
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index ab48fb8..43bca30 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -52,6 +52,7 @@
#include "libc_init_common.h"
#include "private/bionic_globals.h"
+#include "private/bionic_ssp.h"
#include "private/bionic_tls.h"
#include "private/KernelArgumentBlock.h"
@@ -74,6 +75,10 @@
// __libc_init_common() will change the TLS area so the old one won't be accessible anyway.
*args_slot = NULL;
+ // The linker has initialized its copy of the global stack_chk_guard, and filled in the main
+ // thread's TLS slot with that value. Initialize the local global stack guard with its value.
+ __stack_chk_guard = reinterpret_cast<uintptr_t>(tls[TLS_SLOT_STACK_GUARD]);
+
__libc_init_globals(*args);
__libc_init_common(*args);
diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp
index d1494d7..5e06d39 100644
--- a/libc/bionic/libc_init_static.cpp
+++ b/libc/bionic/libc_init_static.cpp
@@ -39,6 +39,7 @@
#include "libc_init_common.h"
#include "pthread_internal.h"
+#include "private/bionic_globals.h"
#include "private/bionic_page.h"
#include "private/bionic_tls.h"
#include "private/KernelArgumentBlock.h"
@@ -85,6 +86,7 @@
__libc_init_main_thread(args);
// Initializing the globals requires TLS to be available for errno.
+ __init_thread_stack_guard(__get_thread());
__libc_init_globals(args);
__libc_init_AT_SECURE(args);
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index 08d9bed..1956a8f 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -56,6 +56,10 @@
// Slot 0 must point to itself. The x86 Linux kernel reads the TLS from %fs:0.
thread->tls[TLS_SLOT_SELF] = thread->tls;
thread->tls[TLS_SLOT_THREAD_ID] = thread;
+ __init_thread_stack_guard(thread);
+}
+
+void __init_thread_stack_guard(pthread_internal_t* thread) {
// GCC looks in the TLS for the stack guard on x86, so copy it there from our global.
thread->tls[TLS_SLOT_STACK_GUARD] = reinterpret_cast<void*>(__stack_chk_guard);
}
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index 1d9e03e..d2abea0 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -114,6 +114,7 @@
__LIBC_HIDDEN__ int __init_thread(pthread_internal_t* thread);
__LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread);
+__LIBC_HIDDEN__ void __init_thread_stack_guard(pthread_internal_t* thread);
__LIBC_HIDDEN__ void __init_alternate_signal_stack(pthread_internal_t*);
__LIBC_HIDDEN__ pthread_t __pthread_internal_add(pthread_internal_t* thread);
@@ -123,7 +124,13 @@
// Make __get_thread() inlined for performance reason. See http://b/19825434.
static inline __always_inline pthread_internal_t* __get_thread() {
- return reinterpret_cast<pthread_internal_t*>(__get_tls()[TLS_SLOT_THREAD_ID]);
+ void** tls = __get_tls();
+ if (__predict_true(tls)) {
+ return reinterpret_cast<pthread_internal_t*>(tls[TLS_SLOT_THREAD_ID]);
+ }
+
+ // This happens when called during libc initialization before TLS has been initialized.
+ return nullptr;
}
__LIBC_HIDDEN__ void pthread_key_clean_all(void);
diff --git a/libc/include/bits/sa_family_t.h b/libc/include/bits/sa_family_t.h
new file mode 100644
index 0000000..51ea51f
--- /dev/null
+++ b/libc/include/bits/sa_family_t.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _BITS_SA_FAMILY_T_H_
+#define _BITS_SA_FAMILY_T_H_
+
+typedef unsigned short sa_family_t;
+
+#endif
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index 5dc8350..a53f664 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -25,6 +25,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#ifndef __DLFCN_H__
#define __DLFCN_H__
@@ -32,24 +33,28 @@
__BEGIN_DECLS
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
typedef struct {
- const char *dli_fname; /* Pathname of shared object that
- contains address */
- void *dli_fbase; /* Address at which shared object
- is loaded */
- const char *dli_sname; /* Name of nearest symbol with address
- lower than addr */
- void *dli_saddr; /* Exact address of symbol named
- in dli_sname */
+ /* Pathname of shared object that contains address. */
+ const char* dli_fname;
+ /* Address at which shared object is loaded. */
+ void* dli_fbase;
+ /* Name of nearest symbol with address lower than addr. */
+ const char* dli_sname;
+ /* Exact address of symbol named in dli_sname. */
+ void* dli_saddr;
} Dl_info;
-extern void* dlopen(const char* filename, int flag);
-extern int dlclose(void* handle);
-extern const char* dlerror(void);
-extern void* dlsym(void* handle, const char* _Nonnull symbol);
-extern void* dlvsym(void* handle, const char* _Nonnull symbol, const char* _Nonnull version)
- __INTRODUCED_IN(24);
-extern int dladdr(const void* addr, Dl_info *info);
+void* dlopen(const char* filename, int flag);
+int dlclose(void* _Nonnull handle);
+const char* dlerror(void);
+void* dlsym(void* handle, const char* _Nonnull symbol);
+void* dlvsym(void* handle, const char* _Nonnull symbol, const char* _Nonnull version) __INTRODUCED_IN(24);
+int dladdr(const void* addr, Dl_info* _Nonnull info);
enum {
#if defined(__LP64__)
@@ -70,11 +75,15 @@
};
#if defined (__LP64__)
-#define RTLD_DEFAULT ((void*) 0)
-#define RTLD_NEXT ((void*) -1L)
+#define RTLD_DEFAULT __BIONIC_CAST(reinterpret_cast, void*, 0)
+#define RTLD_NEXT __BIONIC_CAST(reinterpret_cast, void*, -1L)
#else
-#define RTLD_DEFAULT ((void*) 0xffffffff)
-#define RTLD_NEXT ((void*) 0xfffffffe)
+#define RTLD_DEFAULT __BIONIC_CAST(reinterpret_cast, void*, 0xffffffff)
+#define RTLD_NEXT __BIONIC_CAST(reinterpret_cast, void*, 0xfffffffe)
+#endif
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
#endif
__END_DECLS
diff --git a/libc/include/error.h b/libc/include/error.h
index 18ce379..05ce35d 100644
--- a/libc/include/error.h
+++ b/libc/include/error.h
@@ -33,14 +33,14 @@
__BEGIN_DECLS
-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);
+extern void (* _Nullable error_print_progname)(void) __INTRODUCED_IN(23);
extern unsigned int error_message_count __INTRODUCED_IN(23);
extern int error_one_per_line __INTRODUCED_IN(23);
+void error(int, int, const char* _Nonnull, ...) __printflike(3, 4) __INTRODUCED_IN(23);
+void error_at_line(int, int, const char* _Nullable, unsigned int, const char* _Nonnull, ...)
+ __printflike(5, 6) __INTRODUCED_IN(23);
+
__END_DECLS
#endif
diff --git a/libc/include/grp.h b/libc/include/grp.h
index 498d1b8..1d38265 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -39,19 +39,19 @@
#include <sys/types.h>
struct group {
- char* gr_name; /* group name */
- char* gr_passwd; /* group password */
- gid_t gr_gid; /* group id */
- char** gr_mem; /* group members */
+ char* gr_name; /* group name */
+ char* gr_passwd; /* group password */
+ gid_t gr_gid; /* group id */
+ char** gr_mem; /* group members */
};
__BEGIN_DECLS
+
struct group* getgrgid(gid_t);
struct group* getgrnam(const char*);
-/* Android has thousands and thousands of ids to iterate through. */
-struct group* getgrent(void)
- __attribute__((warning("getgrent is inefficient on Android"))) __INTRODUCED_IN_FUTURE;
+/* Note: Android has thousands and thousands of ids to iterate through. */
+struct group* getgrent(void) __INTRODUCED_IN_FUTURE;
void setgrent(void) __INTRODUCED_IN_FUTURE;
void endgrent(void) __INTRODUCED_IN_FUTURE;
diff --git a/libc/include/locale.h b/libc/include/locale.h
index daef18f..a8f03bc 100644
--- a/libc/include/locale.h
+++ b/libc/include/locale.h
@@ -25,6 +25,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#ifndef _LOCALE_H_
#define _LOCALE_H_
@@ -66,30 +67,30 @@
LC_IDENTIFICATION_MASK)
struct lconv {
- char* decimal_point;
- char* thousands_sep;
- char* grouping;
- char* int_curr_symbol;
- char* currency_symbol;
- char* mon_decimal_point;
- char* mon_thousands_sep;
- char* mon_grouping;
- char* positive_sign;
- char* negative_sign;
- char int_frac_digits;
- char frac_digits;
- char p_cs_precedes;
- char p_sep_by_space;
- char n_cs_precedes;
- char n_sep_by_space;
- char p_sign_posn;
- char n_sign_posn;
- char int_p_cs_precedes;
- char int_p_sep_by_space;
- char int_n_cs_precedes;
- char int_n_sep_by_space;
- char int_p_sign_posn;
- char int_n_sign_posn;
+ char* decimal_point;
+ char* thousands_sep;
+ char* grouping;
+ char* int_curr_symbol;
+ char* currency_symbol;
+ char* mon_decimal_point;
+ char* mon_thousands_sep;
+ char* mon_grouping;
+ char* positive_sign;
+ char* negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_cs_precedes;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
};
struct lconv* localeconv(void) __INTRODUCED_IN(21);
@@ -100,7 +101,7 @@
char* setlocale(int, const char*);
locale_t uselocale(locale_t) __INTRODUCED_IN(21);
-#define LC_GLOBAL_LOCALE ((locale_t) -1L)
+#define LC_GLOBAL_LOCALE __BIONIC_CAST(reinterpret_cast, locale_t, -1L)
__END_DECLS
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 8e6cef9..d9bb315 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -23,12 +23,12 @@
__BEGIN_DECLS
-extern void* malloc(size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(1)));
-extern void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur __attribute__((alloc_size(1,2)));
-extern void* realloc(void* p, size_t byte_count) __wur __attribute__((alloc_size(2)));
+extern void* malloc(size_t byte_count) __mallocfunc __wur;
+extern void* calloc(size_t item_count, size_t item_size) __mallocfunc __wur;
+extern void* realloc(void* p, size_t byte_count) __wur;
extern void free(void* p);
-extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur __attribute__((alloc_size(2)));
+extern void* memalign(size_t alignment, size_t byte_count) __mallocfunc __wur;
extern size_t malloc_usable_size(const void* p) __INTRODUCED_IN(17);
#ifndef STRUCT_MALLINFO_DECLARED
diff --git a/libc/include/netinet/in6.h b/libc/include/netinet/in6.h
index 879ac75..ae20f83 100644
--- a/libc/include/netinet/in6.h
+++ b/libc/include/netinet/in6.h
@@ -29,33 +29,34 @@
#ifndef _NETINET_IN6_H
#define _NETINET_IN6_H
+#include <sys/cdefs.h>
+
#include <linux/in6.h>
#define IN6_IS_ADDR_UNSPECIFIED(a) \
- ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[8]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[12]) == 0))
+ ((((a)->s6_addr32[0]) == 0) && \
+ (((a)->s6_addr32[1]) == 0) && \
+ (((a)->s6_addr32[2]) == 0) && \
+ (((a)->s6_addr32[3]) == 0))
#define IN6_IS_ADDR_LOOPBACK(a) \
- ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[8]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[12]) == ntohl(1)))
+ ((((a)->s6_addr32[0]) == 0) && \
+ (((a)->s6_addr32[1]) == 0) && \
+ (((a)->s6_addr32[2]) == 0) && \
+ (((a)->s6_addr32[3]) == ntohl(1)))
#define IN6_IS_ADDR_V4COMPAT(a) \
- ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[8]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[12]) != 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[12]) != ntohl(1)))
+ ((((a)->s6_addr32[0]) == 0) && \
+ (((a)->s6_addr32[1]) == 0) && \
+ (((a)->s6_addr32[2]) == 0) && \
+ (((a)->s6_addr32[3]) != 0) && (((a)->s6_addr32[3]) != ntohl(1)))
#define IN6_IS_ADDR_V4MAPPED(a) \
- ((*(const uint32_t*)(&(a)->s6_addr[0]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[4]) == 0) && \
- (*(const uint32_t*)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))
+ ((((a)->s6_addr32[0]) == 0) && \
+ (((a)->s6_addr32[1]) == 0) && \
+ (((a)->s6_addr32[2]) == ntohl(0x0000ffff)))
-#define __bionic_s6_addr(a) ((const uint8_t*)(a))
+#define __bionic_s6_addr(a) __BIONIC_CAST(reinterpret_cast, const uint8_t*, a)
#define IN6_IS_ADDR_LINKLOCAL(a) \
((__bionic_s6_addr(a)[0] == 0xfe) && ((__bionic_s6_addr(a)[1] & 0xc0) == 0x80))
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 3262bd1..1153695 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -36,6 +36,13 @@
#include <sys/types.h>
#include <time.h>
+__BEGIN_DECLS
+
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
typedef struct {
#if defined(__LP64__)
int32_t __private[10];
@@ -131,8 +138,6 @@
#define PTHREAD_SCOPE_SYSTEM 0
#define PTHREAD_SCOPE_PROCESS 1
-__BEGIN_DECLS
-
int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) __INTRODUCED_IN(12);
int pthread_attr_destroy(pthread_attr_t* _Nonnull);
@@ -263,8 +268,8 @@
void* __cleanup_arg;
} __pthread_cleanup_t;
-extern void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*);
-extern void __pthread_cleanup_pop(__pthread_cleanup_t*, int);
+void __pthread_cleanup_push(__pthread_cleanup_t* c, __pthread_cleanup_func_t, void*);
+void __pthread_cleanup_pop(__pthread_cleanup_t*, int);
/* Believe or not, the definitions of pthread_cleanup_push and
* pthread_cleanup_pop below are correct. Posix states that these
@@ -281,6 +286,10 @@
__pthread_cleanup_pop( &__cleanup, (execute)); \
} while (0); \
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
__END_DECLS
#endif /* _PTHREAD_H_ */
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index 0b39a78..a686d05 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -63,6 +63,8 @@
#include <sys/cdefs.h>
#include <sys/types.h>
+__BEGIN_DECLS
+
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_MASTERPASSWD "/etc/master.passwd"
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
@@ -96,8 +98,7 @@
#define _PASSWORD_WARNDAYS 14 /* days to warn about expiry */
#define _PASSWORD_CHGNOW -1 /* special day to force password change at next login */
-struct passwd
-{
+struct passwd {
char* pw_name;
char* pw_passwd;
uid_t pw_uid;
@@ -112,13 +113,12 @@
char* pw_shell;
};
-__BEGIN_DECLS
-
struct passwd* getpwnam(const char*);
struct passwd* getpwuid(uid_t);
-/* Android has thousands and thousands of ids to iterate through */
-struct passwd* getpwent(void)
- __attribute__((warning("getpwent is inefficient on Android"))) __INTRODUCED_IN_FUTURE;
+
+/* Note: Android has thousands and thousands of ids to iterate through */
+struct passwd* getpwent(void) __INTRODUCED_IN_FUTURE;
+
void setpwent(void) __INTRODUCED_IN_FUTURE;
void endpwent(void) __INTRODUCED_IN_FUTURE;
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 3905d86..8d9d63f 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -53,6 +53,11 @@
__BEGIN_DECLS
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
typedef int sig_atomic_t;
/* The arm and x86 kernel header files don't define _NSIG. */
@@ -67,16 +72,16 @@
/* The kernel headers define SIG_DFL (0) and SIG_IGN (1) but not SIG_HOLD, since
* SIG_HOLD is only used by the deprecated SysV signal API.
*/
-#define SIG_HOLD ((sighandler_t)(uintptr_t)2)
+#define SIG_HOLD __BIONIC_CAST(reinterpret_cast, sighandler_t, 2)
/* We take a few real-time signals for ourselves. May as well use the same names as glibc. */
#define SIGRTMIN (__libc_current_sigrtmin())
#define SIGRTMAX (__libc_current_sigrtmax())
-extern int __libc_current_sigrtmin(void) __INTRODUCED_IN(21);
-extern int __libc_current_sigrtmax(void) __INTRODUCED_IN(21);
+int __libc_current_sigrtmin(void) __INTRODUCED_IN(21);
+int __libc_current_sigrtmax(void) __INTRODUCED_IN(21);
-extern const char* const sys_siglist[];
-extern const char* const sys_signame[]; /* BSD compatibility. */
+extern const char* const sys_siglist[_NSIG];
+extern const char* const sys_signame[_NSIG]; /* BSD compatibility. */
typedef __sighandler_t sig_t; /* BSD compatibility. */
typedef __sighandler_t sighandler_t; /* glibc compatibility. */
@@ -108,51 +113,55 @@
#endif
-extern int sigaction(int, const struct sigaction*, struct sigaction*);
+int sigaction(int, const struct sigaction*, struct sigaction*);
__BIONIC_LEGACY_INLINE sighandler_t signal(int, sighandler_t);
-extern int siginterrupt(int, int);
+int siginterrupt(int, int);
-__BIONIC_LEGACY_INLINE int sigaddset(sigset_t*, int);
-__BIONIC_LEGACY_INLINE int sigdelset(sigset_t*, int);
-__BIONIC_LEGACY_INLINE int sigemptyset(sigset_t*);
-__BIONIC_LEGACY_INLINE int sigfillset(sigset_t*);
-__BIONIC_LEGACY_INLINE int sigismember(const sigset_t*, int);
+__BIONIC_LEGACY_INLINE int sigaddset(sigset_t* _Nonnull, int);
+__BIONIC_LEGACY_INLINE int sigdelset(sigset_t* _Nonnull, int);
+__BIONIC_LEGACY_INLINE int sigemptyset(sigset_t* _Nonnull);
+__BIONIC_LEGACY_INLINE int sigfillset(sigset_t* _Nonnull);
+__BIONIC_LEGACY_INLINE int sigismember(const sigset_t* _Nonnull, int);
-extern int sigpending(sigset_t* _Nonnull);
-extern int sigprocmask(int, const sigset_t*, sigset_t*);
-extern int sigsuspend(const sigset_t* _Nonnull);
-extern int sigwait(const sigset_t* _Nonnull, int* _Nonnull);
+int sigpending(sigset_t* _Nonnull);
+int sigprocmask(int, const sigset_t*, sigset_t*);
+int sigsuspend(const sigset_t* _Nonnull);
+int sigwait(const sigset_t* _Nonnull, int* _Nonnull);
-extern int sighold(int)
+int sighold(int)
__attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
__INTRODUCED_IN_FUTURE;
-extern int sigignore(int)
+int sigignore(int)
__attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE;
-extern int sigpause(int)
+int sigpause(int)
__attribute__((deprecated("use sigsuspend() instead"))) __INTRODUCED_IN_FUTURE;
-extern int sigrelse(int)
+int sigrelse(int)
__attribute__((deprecated("use sigprocmask() or pthread_sigmask() instead")))
__INTRODUCED_IN_FUTURE;
-extern sighandler_t sigset(int, sighandler_t)
+sighandler_t sigset(int, sighandler_t)
__attribute__((deprecated("use sigaction() instead"))) __INTRODUCED_IN_FUTURE;
-extern int raise(int);
-extern int kill(pid_t, int);
-extern int killpg(int, int);
+int raise(int);
+int kill(pid_t, int);
+int killpg(int, int);
-extern int sigaltstack(const stack_t*, stack_t*);
+int sigaltstack(const stack_t*, stack_t*);
-extern void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17);
-extern void psignal(int, const char*) __INTRODUCED_IN(17);
+void psiginfo(const siginfo_t*, const char*) __INTRODUCED_IN(17);
+void psignal(int, const char*) __INTRODUCED_IN(17);
-extern int pthread_kill(pthread_t, int);
-extern int pthread_sigmask(int, const sigset_t*, sigset_t*);
+int pthread_kill(pthread_t, int);
+int pthread_sigmask(int, const sigset_t*, sigset_t*);
-extern int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23);
-extern int sigtimedwait(const sigset_t*, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23);
-extern int sigwaitinfo(const sigset_t*, siginfo_t*) __INTRODUCED_IN(23);
+int sigqueue(pid_t, int, const union sigval) __INTRODUCED_IN(23);
+int sigtimedwait(const sigset_t* _Nonnull, siginfo_t*, const struct timespec*) __INTRODUCED_IN(23);
+int sigwaitinfo(const sigset_t* _Nonnull, siginfo_t*) __INTRODUCED_IN(23);
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
__END_DECLS
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index a66e21e..0ad27f1 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -32,7 +32,7 @@
#include <bits/wchar_limits.h>
#include <stddef.h>
-typedef __signed char __int8_t;
+typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef short __int16_t;
typedef unsigned short __uint16_t;
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 621caa8..c876b0f 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -49,6 +49,11 @@
__BEGIN_DECLS
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
typedef off_t fpos_t;
typedef off64_t fpos64_t;
@@ -147,8 +152,8 @@
#if __STDC_VERSION__ < 201112L
char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
#endif
-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");
+int sprintf(char* __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3);
+int vsprintf(char* __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0);
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 */
@@ -243,20 +248,20 @@
#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
#endif /* __USE_BSD */
-extern char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17);
-extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
+char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17);
+char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
-extern size_t __fread_chk(void* __restrict, size_t, size_t, FILE* __restrict, size_t)
+size_t __fread_chk(void* __restrict, size_t, size_t, FILE* __restrict, size_t)
__INTRODUCED_IN(24);
-extern size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread);
+size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread);
__errordecl(__fread_too_big_error, "fread called with size * count bigger than buffer");
__errordecl(__fread_overflow, "fread called with overflowing size * count");
-extern size_t __fwrite_chk(const void* __restrict, size_t, size_t, FILE* __restrict, size_t)
+size_t __fwrite_chk(const void* __restrict, size_t, size_t, FILE* __restrict, size_t)
__INTRODUCED_IN(24);
-extern size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite);
+size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite);
__errordecl(__fwrite_too_big_error, "fwrite called with size * count bigger than buffer");
__errordecl(__fwrite_overflow, "fwrite called with overflowing size * count");
@@ -384,6 +389,10 @@
#endif /* defined(__BIONIC_FORTIFY) */
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
__END_DECLS
#endif /* _STDIO_H_ */
diff --git a/libc/include/string.h b/libc/include/string.h
index b3ea9d6..c5bcd22 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -37,117 +37,119 @@
__BEGIN_DECLS
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+#endif
+
#if defined(__USE_BSD)
#include <strings.h>
#endif
-extern void* memccpy(void* __restrict, const void* __restrict, int, size_t);
-extern void* memchr(const void *, int, size_t) __purefunc;
-extern void* memrchr(const void *, int, size_t) __purefunc;
-extern int memcmp(const void *, const void *, size_t) __purefunc;
-extern void* memcpy(void* __restrict, const void* __restrict, size_t);
+void* memccpy(void* _Nonnull __restrict, const void* _Nonnull __restrict, int, size_t);
+void* memchr(const void* _Nonnull, int, size_t) __purefunc;
+void* memrchr(const void* _Nonnull, int, size_t) __purefunc;
+int memcmp(const void* _Nonnull, const void* _Nonnull, size_t) __purefunc;
+void* memcpy(void* _Nonnull __restrict, const void* _Nonnull __restrict, size_t);
#if defined(__USE_GNU)
-extern void* mempcpy(void* __restrict, const void* __restrict, size_t) __INTRODUCED_IN(23);
+void* mempcpy(void* _Nonnull __restrict, const void* _Nonnull __restrict, size_t) __INTRODUCED_IN(23);
#endif
-extern void* memmove(void *, const void *, size_t);
-extern void* memset(void *, int, size_t);
-extern void* memmem(const void *, size_t, const void *, size_t) __purefunc;
+void* memmove(void* _Nonnull, const void* _Nonnull, size_t);
+void* memset(void* _Nonnull, int, size_t);
+void* memmem(const void* _Nonnull, size_t, const void* _Nonnull, size_t) __purefunc;
-extern char* strchr(const char *, int) __purefunc;
-extern char* __strchr_chk(const char*, int, size_t) __INTRODUCED_IN(18);
+char* strchr(const char* _Nonnull, int) __purefunc;
+char* __strchr_chk(const char* _Nonnull, int, size_t) __INTRODUCED_IN(18);
#if defined(__USE_GNU)
#if defined(__cplusplus)
-extern "C++" char* strchrnul(char*, int) __RENAME(strchrnul) __purefunc;
-extern "C++" const char* strchrnul(const char*, int) __RENAME(strchrnul) __purefunc;
+extern "C++" char* strchrnul(char* _Nonnull, int) __RENAME(strchrnul) __purefunc;
+extern "C++" const char* strchrnul(const char* _Nonnull, int) __RENAME(strchrnul) __purefunc;
#else
-char* strchrnul(const char*, int) __purefunc __INTRODUCED_IN(24);
+char* strchrnul(const char* _Nonnull, int) __purefunc __INTRODUCED_IN(24);
#endif
#endif
-extern char* strrchr(const char *, int) __purefunc;
-extern char* __strrchr_chk(const char*, int, size_t) __INTRODUCED_IN(18);
+char* strrchr(const char* _Nonnull, int) __purefunc;
+char* __strrchr_chk(const char* _Nonnull, int, size_t) __INTRODUCED_IN(18);
-extern size_t strlen(const char *) __purefunc;
-extern size_t __strlen_chk(const char*, size_t) __INTRODUCED_IN(17);
-extern int strcmp(const char *, const char *) __purefunc;
-extern char* stpcpy(char* __restrict, const char* __restrict) __INTRODUCED_IN(21);
-extern char* strcpy(char* __restrict, const char* __restrict);
-extern char* strcat(char* __restrict, const char* __restrict);
+size_t strlen(const char* _Nonnull) __purefunc;
+size_t __strlen_chk(const char* _Nonnull, size_t) __INTRODUCED_IN(17);
+int strcmp(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* stpcpy(char* _Nonnull __restrict, const char* _Nonnull__restrict) __INTRODUCED_IN(21);
+char* strcpy(char* _Nonnull __restrict, const char* _Nonnull __restrict);
+char* strcat(char* _Nonnull __restrict, const char* _Nonnull __restrict);
-extern char* strdup(const char *);
+char* strdup(const char* _Nonnull);
-extern char* strstr(const char *, const char *) __purefunc;
-extern char* strcasestr(const char *haystack, const char *needle) __purefunc;
-extern char* strtok(char* __restrict, const char* __restrict);
-extern char* strtok_r(char* __restrict, const char* __restrict, char** __restrict);
+char* strstr(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strcasestr(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strtok(char* __restrict, const char* _Nonnull __restrict);
+char* strtok_r(char* __restrict, const char* _Nonnull __restrict, char** _Nonnull __restrict);
-extern char* strerror(int);
-extern char* strerror_l(int, locale_t) __INTRODUCED_IN(23);
+char* strerror(int);
+char* strerror_l(int, locale_t) __INTRODUCED_IN(23);
#if defined(__USE_GNU)
-extern char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r) __INTRODUCED_IN(23);
+char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r) __INTRODUCED_IN(23);
#else /* POSIX */
-extern int strerror_r(int, char*, size_t);
+int strerror_r(int, char*, size_t);
#endif
-extern size_t strnlen(const char *, size_t) __purefunc;
-extern char* strncat(char* __restrict, const char* __restrict, size_t);
-extern char* strndup(const char *, size_t);
-extern int strncmp(const char *, const char *, size_t) __purefunc;
-extern char* stpncpy(char* __restrict, const char* __restrict, size_t) __INTRODUCED_IN(21);
-extern char* strncpy(char* __restrict, const char* __restrict, size_t);
+size_t strnlen(const char* _Nonnull, size_t) __purefunc;
+char* strncat(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
+char* strndup(const char* _Nonnull, size_t);
+int strncmp(const char* _Nonnull, const char* _Nonnull, size_t) __purefunc;
+char* stpncpy(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t) __INTRODUCED_IN(21);
+char* strncpy(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
-extern size_t strlcat(char* __restrict, const char* __restrict, size_t);
-extern size_t strlcpy(char* __restrict, const char* __restrict, size_t);
+size_t strlcat(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
+size_t strlcpy(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t);
-extern size_t strcspn(const char *, const char *) __purefunc;
-extern char* strpbrk(const char *, const char *) __purefunc;
-extern char* strsep(char** __restrict, const char* __restrict);
-extern size_t strspn(const char *, const char *);
+size_t strcspn(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strpbrk(const char* _Nonnull, const char* _Nonnull) __purefunc;
+char* strsep(char** _Nonnull __restrict, const char* _Nonnull __restrict);
+size_t strspn(const char* _Nonnull, const char* _Nonnull);
-extern char* strsignal(int sig);
+char* strsignal(int);
-extern int strcoll(const char *, const char *) __purefunc;
-extern size_t strxfrm(char* __restrict, const char* __restrict, size_t);
+int strcoll(const char* _Nonnull, const char* _Nonnull) __purefunc;
+size_t strxfrm(char* __restrict, const char* _Nonnull __restrict, size_t);
-extern int strcoll_l(const char*, const char*, locale_t) __purefunc __INTRODUCED_IN(21);
-extern size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t)
- __INTRODUCED_IN(21);
+int strcoll_l(const char* _Nonnull, const char* _Nonnull, locale_t) __purefunc __INTRODUCED_IN(21);
+size_t strxfrm_l(char* __restrict, const char* _Nonnull __restrict, size_t, locale_t) __INTRODUCED_IN(21);
#if defined(__USE_GNU) && !defined(basename)
/*
* glibc has a basename in <string.h> that's different to the POSIX one in <libgen.h>.
* It doesn't modify its argument, and in C++ it's const-correct.
*/
-
#if defined(__cplusplus)
extern "C++" char* basename(char* _Nonnull) __RENAME(__gnu_basename);
extern "C++" const char* basename(const char* _Nonnull) __RENAME(__gnu_basename);
#else
-extern char* basename(const char* _Nonnull) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
+char* basename(const char* _Nonnull) __RENAME(__gnu_basename) __INTRODUCED_IN(23);
#endif
#endif
-extern void* __memchr_chk(const void*, int, size_t, size_t) __INTRODUCED_IN(23);
+void* __memchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
__errordecl(__memchr_buf_size_error, "memchr called with size bigger than buffer");
-extern void* __memrchr_chk(const void*, int, size_t, size_t) __INTRODUCED_IN(23);
+void* __memrchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
__errordecl(__memrchr_buf_size_error, "memrchr called with size bigger than buffer");
-extern void* __memrchr_real(const void*, int, size_t) __RENAME(memrchr);
+void* __memrchr_real(const void* _Nonnull, int, size_t) __RENAME(memrchr);
-extern char* __stpncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t)
+char* __stpncpy_chk2(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t, size_t)
__INTRODUCED_IN(21);
-extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t)
+char* __strncpy_chk2(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t, size_t)
__INTRODUCED_IN(21);
-extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcpy);
-extern size_t __strlcpy_chk(char*, const char*, size_t, size_t) __INTRODUCED_IN(17);
-extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcat);
-extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t)
- __INTRODUCED_IN(17);
+size_t __strlcpy_real(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t) __RENAME(strlcpy);
+size_t __strlcpy_chk(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t) __INTRODUCED_IN(17);
+size_t __strlcat_real(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t) __RENAME(strlcat);
+size_t __strlcat_chk(char* _Nonnull __restrict, const char* _Nonnull __restrict, size_t, size_t) __INTRODUCED_IN(17);
#if defined(__BIONIC_FORTIFY)
__BIONIC_FORTIFY_INLINE
-void* memchr(const void *s, int c, size_t n) {
+void* memchr(const void* s, int c, size_t n) {
size_t bos = __bos(s);
#if !defined(__clang__)
@@ -168,7 +170,7 @@
}
__BIONIC_FORTIFY_INLINE
-void* memrchr(const void *s, int c, size_t n) {
+void* memrchr(const void* s, int c, size_t n) {
size_t bos = __bos(s);
#if !defined(__clang__)
@@ -189,125 +191,125 @@
}
__BIONIC_FORTIFY_INLINE
-void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) {
- return __builtin___memcpy_chk(dest, src, copy_amount, __bos0(dest));
+void* memcpy(void* _Nonnull __restrict dst, const void* _Nonnull __restrict src, size_t copy_amount) {
+ return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst));
}
__BIONIC_FORTIFY_INLINE
-void* memmove(void *dest, const void *src, size_t len) {
- return __builtin___memmove_chk(dest, src, len, __bos0(dest));
+void* memmove(void* _Nonnull dst, const void* _Nonnull src, size_t len) {
+ return __builtin___memmove_chk(dst, src, len, __bos0(dst));
}
__BIONIC_FORTIFY_INLINE
-char* stpcpy(char* __restrict dest, const char* __restrict src) {
- return __builtin___stpcpy_chk(dest, src, __bos(dest));
+char* stpcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
+ return __builtin___stpcpy_chk(dst, src, __bos(dst));
}
__BIONIC_FORTIFY_INLINE
-char* strcpy(char* __restrict dest, const char* __restrict src) {
- return __builtin___strcpy_chk(dest, src, __bos(dest));
+char* strcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
+ return __builtin___strcpy_chk(dst, src, __bos(dst));
}
__BIONIC_FORTIFY_INLINE
-char* stpncpy(char* __restrict dest, const char* __restrict src, size_t n) {
- size_t bos_dest = __bos(dest);
+char* stpncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
+ size_t bos_dst = __bos(dst);
size_t bos_src = __bos(src);
if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
- return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+ return __builtin___stpncpy_chk(dst, src, n, bos_dst);
}
if (__builtin_constant_p(n) && (n <= bos_src)) {
- return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+ return __builtin___stpncpy_chk(dst, src, n, bos_dst);
}
size_t slen = __builtin_strlen(src);
if (__builtin_constant_p(slen)) {
- return __builtin___stpncpy_chk(dest, src, n, bos_dest);
+ return __builtin___stpncpy_chk(dst, src, n, bos_dst);
}
- return __stpncpy_chk2(dest, src, n, bos_dest, bos_src);
+ return __stpncpy_chk2(dst, src, n, bos_dst, bos_src);
}
__BIONIC_FORTIFY_INLINE
-char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
- size_t bos_dest = __bos(dest);
+char* strncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
+ size_t bos_dst = __bos(dst);
size_t bos_src = __bos(src);
if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
- return __builtin___strncpy_chk(dest, src, n, bos_dest);
+ return __builtin___strncpy_chk(dst, src, n, bos_dst);
}
if (__builtin_constant_p(n) && (n <= bos_src)) {
- return __builtin___strncpy_chk(dest, src, n, bos_dest);
+ return __builtin___strncpy_chk(dst, src, n, bos_dst);
}
size_t slen = __builtin_strlen(src);
if (__builtin_constant_p(slen)) {
- return __builtin___strncpy_chk(dest, src, n, bos_dest);
+ return __builtin___strncpy_chk(dst, src, n, bos_dst);
}
- return __strncpy_chk2(dest, src, n, bos_dest, bos_src);
+ return __strncpy_chk2(dst, src, n, bos_dst, bos_src);
}
__BIONIC_FORTIFY_INLINE
-char* strcat(char* __restrict dest, const char* __restrict src) {
- return __builtin___strcat_chk(dest, src, __bos(dest));
+char* strcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) {
+ return __builtin___strcat_chk(dst, src, __bos(dst));
}
__BIONIC_FORTIFY_INLINE
-char *strncat(char* __restrict dest, const char* __restrict src, size_t n) {
- return __builtin___strncat_chk(dest, src, n, __bos(dest));
+char *strncat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) {
+ return __builtin___strncat_chk(dst, src, n, __bos(dst));
}
__BIONIC_FORTIFY_INLINE
-void* memset(void *s, int c, size_t n) {
+void* memset(void* _Nonnull s, int c, size_t n) {
return __builtin___memset_chk(s, c, n, __bos0(s));
}
__BIONIC_FORTIFY_INLINE
-size_t strlcpy(char* __restrict dest, const char* __restrict src, size_t size) {
- size_t bos = __bos(dest);
+size_t strlcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t size) {
+ size_t bos = __bos(dst);
#if !defined(__clang__)
// Compiler doesn't know destination size. Don't call __strlcpy_chk
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
- return __strlcpy_real(dest, src, size);
+ return __strlcpy_real(dst, src, size);
}
// Compiler can prove, at compile time, that the passed in size
// is always <= the actual object size. Don't call __strlcpy_chk
if (__builtin_constant_p(size) && (size <= bos)) {
- return __strlcpy_real(dest, src, size);
+ return __strlcpy_real(dst, src, size);
}
#endif /* !defined(__clang__) */
- return __strlcpy_chk(dest, src, size, bos);
+ return __strlcpy_chk(dst, src, size, bos);
}
__BIONIC_FORTIFY_INLINE
-size_t strlcat(char* __restrict dest, const char* __restrict src, size_t size) {
- size_t bos = __bos(dest);
+size_t strlcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t size) {
+ size_t bos = __bos(dst);
#if !defined(__clang__)
// Compiler doesn't know destination size. Don't call __strlcat_chk
if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
- return __strlcat_real(dest, src, size);
+ return __strlcat_real(dst, src, size);
}
// Compiler can prove, at compile time, that the passed in size
// is always <= the actual object size. Don't call __strlcat_chk
if (__builtin_constant_p(size) && (size <= bos)) {
- return __strlcat_real(dest, src, size);
+ return __strlcat_real(dst, src, size);
}
#endif /* !defined(__clang__) */
- return __strlcat_chk(dest, src, size, bos);
+ return __strlcat_chk(dst, src, size, bos);
}
__BIONIC_FORTIFY_INLINE
-size_t strlen(const char *s) {
+size_t strlen(const char* _Nonnull s) {
size_t bos = __bos(s);
#if !defined(__clang__)
@@ -326,7 +328,7 @@
}
__BIONIC_FORTIFY_INLINE
-char* strchr(const char *s, int c) {
+char* strchr(const char* _Nonnull s, int c) {
size_t bos = __bos(s);
#if !defined(__clang__)
@@ -345,7 +347,7 @@
}
__BIONIC_FORTIFY_INLINE
-char* strrchr(const char *s, int c) {
+char* strrchr(const char* _Nonnull s, int c) {
size_t bos = __bos(s);
#if !defined(__clang__)
@@ -366,6 +368,10 @@
#endif /* defined(__BIONIC_FORTIFY) */
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
__END_DECLS
#endif /* _STRING_H */
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 89061b6..2688626 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -72,6 +72,12 @@
#define __static_cast(x,y) (x)y
#endif
+#if defined(__cplusplus)
+#define __BIONIC_CAST(_k,_t,_v) (_k<_t>(_v))
+#else
+#define __BIONIC_CAST(_k,_t,_v) ((_t) (_v))
+#endif
+
/*
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
@@ -88,9 +94,6 @@
#define __CONCAT(x,y) x ## y
#define __STRING(x) #x
-#define __const const /* define reserved names to standard */
-#define __signed signed
-#define __volatile volatile
#if defined(__cplusplus)
#define __inline inline /* convert to C++ keyword */
#endif /* !__cplusplus */
@@ -102,17 +105,6 @@
#endif /* !(__STDC__ || __cplusplus) */
-/*
- * The following macro is used to remove const cast-away warnings
- * from gcc -Wcast-qual; it should be used with caution because it
- * can hide valid errors; in particular most valid uses are in
- * situations where the API requires it, not to cast away string
- * constants. We don't use *intptr_t on purpose here and we are
- * explicit about unsigned long so that we don't have additional
- * dependencies.
- */
-#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
-
#define __always_inline __attribute__((__always_inline__))
#define __dead __attribute__((__noreturn__))
#define __noreturn __attribute__((__noreturn__))
@@ -154,6 +146,7 @@
*/
#if !(defined(__clang__) && __has_feature(nullability))
#define _Nonnull
+#define _Nullable
#endif
#define __printflike(x, y) __attribute__((__format__(printf, x, y)))
@@ -198,8 +191,6 @@
#define __errorattr(msg) __attribute__((__error__(msg)))
#endif
-#define __warnattr(msg) __attribute__((__warning__(msg)))
-
#define __errordecl(name, msg) extern void name(void) __errorattr(msg)
/*
@@ -274,9 +265,13 @@
# define __bos(s) __builtin_object_size((s), 0)
# endif
# define __bos0(s) __builtin_object_size((s), 0)
-# define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
+# if defined(__clang__)
+# define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline))
+# else
+# define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
+# endif
#endif
-#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
+#define __BIONIC_FORTIFY_UNKNOWN_SIZE __BIONIC_CAST(static_cast, size_t, -1)
/* Used to tag non-static symbols that are private and never exposed by the shared library. */
#define __LIBC_HIDDEN__ __attribute__((visibility("hidden")))
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index 7a8aa89..934963f 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -38,7 +38,7 @@
#define MAP_ANON MAP_ANONYMOUS
#endif
-#define MAP_FAILED ((void *)-1)
+#define MAP_FAILED __BIONIC_CAST(reinterpret_cast, void*, -1)
#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED 2
@@ -50,26 +50,26 @@
#define POSIX_MADV_DONTNEED MADV_DONTNEED
#if defined(__USE_FILE_OFFSET64)
-extern void* mmap(void*, size_t, int, int, int, off_t) __RENAME(mmap64) __INTRODUCED_IN(21);
+void* mmap(void*, size_t, int, int, int, off_t) __RENAME(mmap64) __INTRODUCED_IN(21);
#else
-extern void* mmap(void*, size_t, int, int, int, off_t);
+void* mmap(void*, size_t, int, int, int, off_t);
#endif
-extern void* mmap64(void*, size_t, int, int, int, off64_t) __INTRODUCED_IN(21);
+void* mmap64(void*, size_t, int, int, int, off64_t) __INTRODUCED_IN(21);
-extern int munmap(void*, size_t);
-extern int msync(const void*, size_t, int);
-extern int mprotect(const void*, size_t, int);
-extern void* mremap(void*, size_t, size_t, int, ...);
+int munmap(void*, size_t);
+int msync(const void*, size_t, int);
+int mprotect(const void*, size_t, int);
+void* mremap(void*, size_t, size_t, int, ...);
-extern int mlockall(int) __INTRODUCED_IN(17);
-extern int munlockall(void) __INTRODUCED_IN(17);
-extern int mlock(const void*, size_t);
-extern int munlock(const void*, size_t);
+int mlockall(int) __INTRODUCED_IN(17);
+int munlockall(void) __INTRODUCED_IN(17);
+int mlock(const void*, size_t);
+int munlock(const void*, size_t);
-extern int mincore(void*, size_t, unsigned char*);
+int mincore(void*, size_t, unsigned char*);
-extern int madvise(void*, size_t, int);
-extern int posix_madvise(void*, size_t, int) __INTRODUCED_IN(23);
+int madvise(void*, size_t, int);
+int posix_madvise(void*, size_t, int) __INTRODUCED_IN(23);
__END_DECLS
diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h
index 06c1c72..96d735e 100644
--- a/libc/include/sys/select.h
+++ b/libc/include/sys/select.h
@@ -46,7 +46,7 @@
#define __FDELT(fd) ((fd) / NFDBITS)
#define __FDMASK(fd) (1UL << ((fd) % NFDBITS))
-#define __FDS_BITS(set) (((fd_set*)(set))->fds_bits)
+#define __FDS_BITS(set) (__BIONIC_CAST(static_cast, fd_set*, set)->fds_bits)
/* Inline loop so we don't have to declare memset. */
#define FD_ZERO(set) \
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index 85999f3..9736ba8 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -40,10 +40,11 @@
#include <linux/types.h>
#include <linux/compiler.h>
+#include <bits/sa_family_t.h>
+
__BEGIN_DECLS
#define sockaddr_storage __kernel_sockaddr_storage
-typedef unsigned short sa_family_t;
struct timespec;
diff --git a/libc/include/sys/un.h b/libc/include/sys/un.h
index 65ffbdcf..421b900 100644
--- a/libc/include/sys/un.h
+++ b/libc/include/sys/un.h
@@ -25,11 +25,11 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#ifndef _SYS_UN_H_
#define _SYS_UN_H_
-typedef unsigned short sa_family_t;
-
+#include <bits/sa_family_t.h>
#include <linux/un.h>
-#endif /* _SYS_UN_H_ */
+#endif
diff --git a/libc/include/sys/xattr.h b/libc/include/sys/xattr.h
index 63605c5..7e437e9 100644
--- a/libc/include/sys/xattr.h
+++ b/libc/include/sys/xattr.h
@@ -25,36 +25,33 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#ifndef _SYS_XATTR_H_
#define _SYS_XATTR_H_
+#include <linux/xattr.h>
#include <sys/types.h>
__BEGIN_DECLS
-#define XATTR_CREATE 1
-#define XATTR_REPLACE 2
-
-extern int fsetxattr(int fd, const char* name, const void* value, size_t size, int flags)
+int fsetxattr(int fd, const char* name, const void* value, size_t size, int flags)
__INTRODUCED_IN(16);
-extern int setxattr(const char* path, const char* name, const void* value, size_t size, int flags)
+int setxattr(const char* path, const char* name, const void* value, size_t size, int flags)
__INTRODUCED_IN(16);
-extern int lsetxattr(const char* path, const char* name, const void* value, size_t size, int flags)
+int lsetxattr(const char* path, const char* name, const void* value, size_t size, int flags)
__INTRODUCED_IN(16);
-extern ssize_t fgetxattr(int fd, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
-extern ssize_t getxattr(const char* path, const char* name, void* value, size_t size)
- __INTRODUCED_IN(16);
-extern ssize_t lgetxattr(const char* path, const char* name, void* value, size_t size)
- __INTRODUCED_IN(16);
+ssize_t fgetxattr(int fd, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
+ssize_t getxattr(const char* path, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
+ssize_t lgetxattr(const char* path, const char* name, void* value, size_t size) __INTRODUCED_IN(16);
-extern ssize_t listxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
-extern ssize_t llistxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
-extern ssize_t flistxattr(int fd, char* list, size_t size) __INTRODUCED_IN(16);
+ssize_t listxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
+ssize_t llistxattr(const char* path, char* list, size_t size) __INTRODUCED_IN(16);
+ssize_t flistxattr(int fd, char* list, size_t size) __INTRODUCED_IN(16);
-extern int removexattr(const char* path, const char* name) __INTRODUCED_IN(16);
-extern int lremovexattr(const char* path, const char* name) __INTRODUCED_IN(16);
-extern int fremovexattr(int fd, const char* name) __INTRODUCED_IN(16);
+int removexattr(const char* path, const char* name) __INTRODUCED_IN(16);
+int lremovexattr(const char* path, const char* name) __INTRODUCED_IN(16);
+int fremovexattr(int fd, const char* name) __INTRODUCED_IN(16);
__END_DECLS
diff --git a/libc/include/syslog.h b/libc/include/syslog.h
index d51c9f2..ee288e5 100644
--- a/libc/include/syslog.h
+++ b/libc/include/syslog.h
@@ -86,7 +86,7 @@
#define LOG_PERROR 0x20
void closelog(void);
-void openlog(const char*, int, int);
+void openlog(const char* _Nullable, int, int);
int setlogmask(int);
void syslog(int, const char* _Nonnull, ...) __printflike(2, 3);
void vsyslog(int, const char* _Nonnull, va_list) __printflike(2, 0);
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
index b45c0c3..94dd7e8 100644
--- a/libc/private/bionic_globals.h
+++ b/libc/private/bionic_globals.h
@@ -44,7 +44,6 @@
__LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals;
class KernelArgumentBlock;
-__LIBC_HIDDEN__ void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args);
__LIBC_HIDDEN__ void __libc_init_malloc(libc_globals* globals);
__LIBC_HIDDEN__ void __libc_init_setjmp_cookie(libc_globals* globals, KernelArgumentBlock& args);
__LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args);
diff --git a/libc/upstream-netbsd/android/include/netbsd-compat.h b/libc/upstream-netbsd/android/include/netbsd-compat.h
index 665d65e..cc0f71f 100644
--- a/libc/upstream-netbsd/android/include/netbsd-compat.h
+++ b/libc/upstream-netbsd/android/include/netbsd-compat.h
@@ -25,6 +25,17 @@
// that they don't actually test or ship with this.
#define _DIAGASSERT(e) /* nothing */
+/*
+ * The following macro is used to remove const cast-away warnings
+ * from gcc -Wcast-qual; it should be used with caution because it
+ * can hide valid errors; in particular most valid uses are in
+ * situations where the API requires it, not to cast away string
+ * constants. We don't use *intptr_t on purpose here and we are
+ * explicit about unsigned long so that we don't have additional
+ * dependencies.
+ */
+#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
+
// TODO: we don't yet have thread-safe environment variables.
#define __readlockenv() 0
#define __unlockenv() 0
diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c
index 64c2b7a..09b4386 100644
--- a/libm/i387/fenv.c
+++ b/libm/i387/fenv.c
@@ -70,18 +70,18 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } /*__other*/
};
-#define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw))
-#define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env))
-#define __fldenvx(__env) __asm __volatile("fldenv %0" : : "m" (__env) \
+#define __fldcw(__cw) __asm volatile("fldcw %0" : : "m" (__cw))
+#define __fldenv(__env) __asm volatile("fldenv %0" : : "m" (__env))
+#define __fldenvx(__env) __asm volatile("fldenv %0" : : "m" (__env) \
: "st", "st(1)", "st(2)", "st(3)", "st(4)", \
"st(5)", "st(6)", "st(7)")
-#define __fnclex() __asm __volatile("fnclex")
-#define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env)))
-#define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw)))
-#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw)))
-#define __fwait() __asm __volatile("fwait")
-#define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr))
-#define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr)))
+#define __fnclex() __asm volatile("fnclex")
+#define __fnstenv(__env) __asm volatile("fnstenv %0" : "=m" (*(__env)))
+#define __fnstcw(__cw) __asm volatile("fnstcw %0" : "=m" (*(__cw)))
+#define __fnstsw(__sw) __asm volatile("fnstsw %0" : "=am" (*(__sw)))
+#define __fwait() __asm volatile("fwait")
+#define __ldmxcsr(__csr) __asm volatile("ldmxcsr %0" : : "m" (__csr))
+#define __stmxcsr(__csr) __asm volatile("stmxcsr %0" : "=m" (*(__csr)))
/* After testing for SSE support once, we cache the result in __has_sse. */
enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK };
@@ -100,9 +100,9 @@
#endif
#ifndef __SSE__
-#define getfl(x) __asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
-#define setfl(x) __asm __volatile("pushl %0\n\tpopfl" : : "g" (x))
-#define cpuid_dx(x) __asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t" \
+#define getfl(x) __asm volatile("pushfl\n\tpopl %0" : "=mr" (*(x)))
+#define setfl(x) __asm volatile("pushl %0\n\tpopfl" : : "g" (x))
+#define cpuid_dx(x) __asm volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t" \
"cpuid\n\tpopl %%ebx" \
: "=d" (*(x)) : : "eax", "ecx")