summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/Android.mk1
-rw-r--r--libc/arch-arm/include/machine/endian.h4
-rw-r--r--libc/arch-arm64/include/machine/endian.h9
-rw-r--r--libc/arch-mips/bionic/atexit.h36
-rw-r--r--libc/arch-mips/bionic/crtbegin.c2
-rw-r--r--libc/arch-mips/include/machine/endian.h4
-rw-r--r--libc/arch-mips/include/sgidefs.h (renamed from libc/include/sgidefs.h)0
-rw-r--r--libc/arch-mips64/bionic/atexit.h36
-rw-r--r--libc/arch-mips64/bionic/crtbegin.c2
-rw-r--r--libc/arch-mips64/bionic/crtbegin_so.c38
-rw-r--r--libc/arch-mips64/include/machine/endian.h4
-rw-r--r--libc/arch-x86_64/include/machine/endian.h1
-rw-r--r--libc/bionic/flockfile.cpp12
-rw-r--r--libc/bionic/fts.c39
-rw-r--r--libc/bionic/locale.cpp1
-rw-r--r--libc/bionic/mntent.cpp1
-rw-r--r--libc/bionic/pthread_atfork.cpp1
-rw-r--r--libc/bionic/pthread_internals.cpp2
-rw-r--r--libc/bionic/pthread_key.cpp1
-rw-r--r--libc/bionic/raise.cpp1
-rw-r--r--libc/bionic/stubs.cpp120
-rw-r--r--libc/include/machine/pthread_types.h (renamed from libc/arch-mips/bionic/crtbegin_so.c)28
-rw-r--r--libc/include/pthread.h24
-rw-r--r--libc/include/sched.h3
-rw-r--r--libc/include/signal.h10
-rw-r--r--libc/private/kernel_sigset_t.h2
-rw-r--r--libc/stdio/fileext.h4
-rw-r--r--libc/stdio/glue.h6
-rw-r--r--libc/stdio/local.h4
-rw-r--r--libc/stdio/wcio.h6
-rw-r--r--libc/upstream-openbsd/android/include/openbsd-compat.h3
-rw-r--r--libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c38
32 files changed, 202 insertions, 241 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index 3e37ca7..ef1fb9b 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -479,6 +479,7 @@ libc_upstream_openbsd_src_files := \
upstream-openbsd/lib/libc/stdlib/getenv.c \
upstream-openbsd/lib/libc/stdlib/insque.c \
upstream-openbsd/lib/libc/stdlib/lsearch.c \
+ upstream-openbsd/lib/libc/stdlib/reallocarray.c \
upstream-openbsd/lib/libc/stdlib/remque.c \
upstream-openbsd/lib/libc/stdlib/setenv.c \
upstream-openbsd/lib/libc/stdlib/strtoimax.c \
diff --git a/libc/arch-arm/include/machine/endian.h b/libc/arch-arm/include/machine/endian.h
index 8d9723d..04bba20 100644
--- a/libc/arch-arm/include/machine/endian.h
+++ b/libc/arch-arm/include/machine/endian.h
@@ -67,11 +67,7 @@
#endif /* __GNUC__ */
-#if defined(__ARMEB__)
-#define _BYTE_ORDER _BIG_ENDIAN
-#else
#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
#define __STRICT_ALIGNMENT
#include <sys/types.h>
#include <sys/endian.h>
diff --git a/libc/arch-arm64/include/machine/endian.h b/libc/arch-arm64/include/machine/endian.h
index 87a038d..4743733 100644
--- a/libc/arch-arm64/include/machine/endian.h
+++ b/libc/arch-arm64/include/machine/endian.h
@@ -29,9 +29,6 @@
#ifndef _AARCH64_ENDIAN_H_
#define _AARCH64_ENDIAN_H_
-#include <sys/types.h>
-#include <sys/endian.h>
-
#ifdef __GNUC__
#define __swap16md(x) ({ \
@@ -49,10 +46,8 @@
#endif /* __GNUC__ */
-#if defined(__AARCH64EB__)
-#define _BYTE_ORDER _BIG_ENDIAN
-#else
#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
+#include <sys/types.h>
+#include <sys/endian.h>
#endif /* _AARCH64_ENDIAN_H_ */
diff --git a/libc/arch-mips/bionic/atexit.h b/libc/arch-mips/bionic/atexit.h
deleted file mode 100644
index 759008c..0000000
--- a/libc/arch-mips/bionic/atexit.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-extern void *__dso_handle;
-extern int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
-
-__attribute__ ((visibility ("hidden")))
-int atexit(void (*func)(void))
-{
- return (__cxa_atexit((void (*)(void *))func, (void *)0, &__dso_handle));
-}
diff --git a/libc/arch-mips/bionic/crtbegin.c b/libc/arch-mips/bionic/crtbegin.c
index 28e8817..50e9eeb 100644
--- a/libc/arch-mips/bionic/crtbegin.c
+++ b/libc/arch-mips/bionic/crtbegin.c
@@ -91,4 +91,4 @@ __asm__ (
);
#include "../../arch-common/bionic/__dso_handle.h"
-#include "atexit.h"
+#include "../../arch-common/bionic/atexit.h"
diff --git a/libc/arch-mips/include/machine/endian.h b/libc/arch-mips/include/machine/endian.h
index 41a9004..9270e9d 100644
--- a/libc/arch-mips/include/machine/endian.h
+++ b/libc/arch-mips/include/machine/endian.h
@@ -58,11 +58,7 @@
#endif /* __mips32r2__ */
#endif /* __GNUC__ */
-#if defined(__MIPSEB__)
-#define _BYTE_ORDER _BIG_ENDIAN
-#else
#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
#define __STRICT_ALIGNMENT
#include <sys/types.h>
#include <sys/endian.h>
diff --git a/libc/include/sgidefs.h b/libc/arch-mips/include/sgidefs.h
index 8b37bf0..8b37bf0 100644
--- a/libc/include/sgidefs.h
+++ b/libc/arch-mips/include/sgidefs.h
diff --git a/libc/arch-mips64/bionic/atexit.h b/libc/arch-mips64/bionic/atexit.h
deleted file mode 100644
index 759008c..0000000
--- a/libc/arch-mips64/bionic/atexit.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-extern void *__dso_handle;
-extern int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
-
-__attribute__ ((visibility ("hidden")))
-int atexit(void (*func)(void))
-{
- return (__cxa_atexit((void (*)(void *))func, (void *)0, &__dso_handle));
-}
diff --git a/libc/arch-mips64/bionic/crtbegin.c b/libc/arch-mips64/bionic/crtbegin.c
index 2ea31ad..1374fea 100644
--- a/libc/arch-mips64/bionic/crtbegin.c
+++ b/libc/arch-mips64/bionic/crtbegin.c
@@ -91,4 +91,4 @@ __asm__ (
);
#include "../../arch-common/bionic/__dso_handle.h"
-#include "atexit.h"
+#include "../../arch-common/bionic/atexit.h"
diff --git a/libc/arch-mips64/bionic/crtbegin_so.c b/libc/arch-mips64/bionic/crtbegin_so.c
deleted file mode 100644
index d664ce6..0000000
--- a/libc/arch-mips64/bionic/crtbegin_so.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-extern void __cxa_finalize(void *);
-extern void *__dso_handle;
-
-__attribute__((visibility("hidden"),destructor))
-void __on_dlclose() {
- __cxa_finalize(&__dso_handle);
-}
-
-#include "../../arch-common/bionic/__dso_handle_so.h"
-#include "atexit.h"
diff --git a/libc/arch-mips64/include/machine/endian.h b/libc/arch-mips64/include/machine/endian.h
index 41a9004..9270e9d 100644
--- a/libc/arch-mips64/include/machine/endian.h
+++ b/libc/arch-mips64/include/machine/endian.h
@@ -58,11 +58,7 @@
#endif /* __mips32r2__ */
#endif /* __GNUC__ */
-#if defined(__MIPSEB__)
-#define _BYTE_ORDER _BIG_ENDIAN
-#else
#define _BYTE_ORDER _LITTLE_ENDIAN
-#endif
#define __STRICT_ALIGNMENT
#include <sys/types.h>
#include <sys/endian.h>
diff --git a/libc/arch-x86_64/include/machine/endian.h b/libc/arch-x86_64/include/machine/endian.h
index 7889a37..8a3b0c5 100644
--- a/libc/arch-x86_64/include/machine/endian.h
+++ b/libc/arch-x86_64/include/machine/endian.h
@@ -56,6 +56,7 @@
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+#include <sys/types.h>
#include <sys/endian.h>
#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/libc/bionic/flockfile.cpp b/libc/bionic/flockfile.cpp
index 3381e8e..b73907c 100644
--- a/libc/bionic/flockfile.cpp
+++ b/libc/bionic/flockfile.cpp
@@ -36,12 +36,20 @@
// struct __sfileext (see fileext.h).
void flockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
if (fp != NULL) {
pthread_mutex_lock(&_FLOCK(fp));
}
}
int ftrylockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
// The specification for ftrylockfile() says it returns 0 on success,
// or non-zero on error. So return an errno code directly on error.
if (fp == NULL) {
@@ -52,6 +60,10 @@ int ftrylockfile(FILE* fp) {
}
void funlockfile(FILE* fp) {
+ if (!__sdidinit) {
+ __sinit();
+ }
+
if (fp != NULL) {
pthread_mutex_unlock(&_FLOCK(fp));
}
diff --git a/libc/bionic/fts.c b/libc/bionic/fts.c
index c491b6a..31a4b2f 100644
--- a/libc/bionic/fts.c
+++ b/libc/bionic/fts.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fts.c,v 1.46 2014/05/25 17:47:04 tedu Exp $ */
+/* $OpenBSD: fts.c,v 1.48 2014/11/20 04:14:15 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -49,11 +49,12 @@ static size_t fts_maxarglen(char * const *);
static void fts_padjust(FTS *, FTSENT *);
static int fts_palloc(FTS *, size_t);
static FTSENT *fts_sort(FTS *, FTSENT *, int);
-static u_short fts_stat(FTS *, FTSENT *, int);
+static u_short fts_stat(FTS *, FTSENT *, int, int);
static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
+void* reallocarray(void*, size_t, size_t);
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
@@ -119,7 +120,7 @@ fts_open(char * const *argv, int options,
p->fts_level = FTS_ROOTLEVEL;
p->fts_parent = parent;
p->fts_accpath = p->fts_name;
- p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
+ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW), -1);
/* Command-line "." and ".." are real directories. */
if (p->fts_info == FTS_DOT)
@@ -273,7 +274,7 @@ fts_read(FTS *sp)
/* Any type of file may be re-visited; re-stat and re-turn. */
if (instr == FTS_AGAIN) {
- p->fts_info = fts_stat(sp, p, 0);
+ p->fts_info = fts_stat(sp, p, 0, -1);
return (p);
}
@@ -285,7 +286,7 @@ fts_read(FTS *sp)
*/
if (instr == FTS_FOLLOW &&
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
- p->fts_info = fts_stat(sp, p, 1);
+ p->fts_info = fts_stat(sp, p, 1, -1);
if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
if ((p->fts_symfd = open(".", O_RDONLY, 0)) < 0) {
p->fts_errno = errno;
@@ -374,7 +375,7 @@ next: tmp = p;
if (p->fts_instr == FTS_SKIP)
goto next;
if (p->fts_instr == FTS_FOLLOW) {
- p->fts_info = fts_stat(sp, p, 1);
+ p->fts_info = fts_stat(sp, p, 1, -1);
if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
if ((p->fts_symfd =
open(".", O_RDONLY, 0)) < 0) {
@@ -719,10 +720,11 @@ mem1: saved_errno = errno;
if (ISSET(FTS_NOCHDIR)) {
p->fts_accpath = p->fts_path;
memmove(cp, p->fts_name, p->fts_namelen + 1);
- } else
+ p->fts_info = fts_stat(sp, p, 0, dirfd(dirp));
+ } else {
p->fts_accpath = p->fts_name;
- /* Stat it. */
- p->fts_info = fts_stat(sp, p, 0);
+ p->fts_info = fts_stat(sp, p, 0, -1);
+ }
/* Decrement link count if applicable. */
if (nlinks > 0 && (p->fts_info == FTS_D ||
@@ -789,13 +791,20 @@ mem1: saved_errno = errno;
}
static u_short
-fts_stat(FTS *sp, FTSENT *p, int follow)
+fts_stat(FTS *sp, FTSENT *p, int follow, int dfd)
{
FTSENT *t;
dev_t dev;
ino_t ino;
struct stat *sbp, sb;
int saved_errno;
+ const char *path;
+
+ if (dfd == -1) {
+ path = p->fts_accpath;
+ dfd = AT_FDCWD;
+ } else
+ path = p->fts_name;
/* If user needs stat info, stat buffer already allocated. */
sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
@@ -806,16 +815,16 @@ fts_stat(FTS *sp, FTSENT *p, int follow)
* fail, set the errno from the stat call.
*/
if (ISSET(FTS_LOGICAL) || follow) {
- if (stat(p->fts_accpath, sbp)) {
+ if (fstatat(dfd, path, sbp, 0)) {
saved_errno = errno;
- if (!lstat(p->fts_accpath, sbp)) {
+ if (!fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
errno = 0;
return (FTS_SLNONE);
}
p->fts_errno = saved_errno;
goto err;
}
- } else if (lstat(p->fts_accpath, sbp)) {
+ } else if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
p->fts_errno = errno;
err: memset(sbp, 0, sizeof(struct stat));
return (FTS_NS);
@@ -873,8 +882,8 @@ fts_sort(FTS *sp, FTSENT *head, int nitems)
struct _ftsent **a;
sp->fts_nitems = nitems + 40;
- if ((a = realloc(sp->fts_array,
- sp->fts_nitems * sizeof(FTSENT *))) == NULL) {
+ if ((a = reallocarray(sp->fts_array,
+ sp->fts_nitems, sizeof(FTSENT *))) == NULL) {
if (sp->fts_array)
free(sp->fts_array);
sp->fts_array = NULL;
diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp
index 681e038..90aa7b8 100644
--- a/libc/bionic/locale.cpp
+++ b/libc/bionic/locale.cpp
@@ -26,6 +26,7 @@
* SUCH DAMAGE.
*/
+#include <errno.h>
#include <locale.h>
#include <pthread.h>
#include <stdlib.h>
diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp
index f5a8eaa..4afacda 100644
--- a/libc/bionic/mntent.cpp
+++ b/libc/bionic/mntent.cpp
@@ -27,6 +27,7 @@
*/
#include <mntent.h>
+#include <string.h>
#include "private/ThreadLocalBuffer.h"
diff --git a/libc/bionic/pthread_atfork.cpp b/libc/bionic/pthread_atfork.cpp
index b845f7d..82e2b59 100644
--- a/libc/bionic/pthread_atfork.cpp
+++ b/libc/bionic/pthread_atfork.cpp
@@ -28,6 +28,7 @@
#include <errno.h>
#include <pthread.h>
+#include <stdlib.h>
struct atfork_t {
atfork_t* next;
diff --git a/libc/bionic/pthread_internals.cpp b/libc/bionic/pthread_internals.cpp
index 19c00d4..2270d96 100644
--- a/libc/bionic/pthread_internals.cpp
+++ b/libc/bionic/pthread_internals.cpp
@@ -28,6 +28,8 @@
#include "pthread_internal.h"
+#include <stdlib.h>
+
#include "private/bionic_futex.h"
#include "private/bionic_tls.h"
#include "private/ScopedPthreadMutexLocker.h"
diff --git a/libc/bionic/pthread_key.cpp b/libc/bionic/pthread_key.cpp
index 27eab27..b47ef22 100644
--- a/libc/bionic/pthread_key.cpp
+++ b/libc/bionic/pthread_key.cpp
@@ -26,6 +26,7 @@
* SUCH DAMAGE.
*/
+#include <errno.h>
#include <pthread.h>
#include "private/bionic_tls.h"
diff --git a/libc/bionic/raise.cpp b/libc/bionic/raise.cpp
index f69d90b..0dd0ad7 100644
--- a/libc/bionic/raise.cpp
+++ b/libc/bionic/raise.cpp
@@ -27,6 +27,7 @@
*/
#include <pthread.h>
+#include <signal.h>
int raise(int sig) {
int rc = pthread_kill(pthread_self(), sig);
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp
index b1e38be..88e5ac5 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/stubs.cpp
@@ -40,10 +40,10 @@
#include "private/android_filesystem_config.h"
#include "private/ErrnoRestorer.h"
#include "private/libc_logging.h"
+#include "private/ThreadLocalBuffer.h"
+
+GLOBAL_INIT_THREAD_LOCAL_BUFFER(stubs);
-// Thread-specific state for the non-reentrant functions.
-static pthread_once_t stubs_once = PTHREAD_ONCE_INIT;
-static pthread_key_t stubs_key;
struct stubs_state_t {
passwd passwd_;
group group_;
@@ -113,39 +113,14 @@ int getpwuid_r(uid_t uid, passwd* pwd,
return do_getpw_r(0, NULL, uid, pwd, buf, byte_count, result);
}
-static stubs_state_t* stubs_state_alloc() {
- stubs_state_t* s = static_cast<stubs_state_t*>(calloc(1, sizeof(*s)));
- if (s != NULL) {
- s->group_.gr_mem = s->group_members_;
- }
- return s;
-}
-
-static void stubs_state_free(void* ptr) {
- stubs_state_t* state = static_cast<stubs_state_t*>(ptr);
- free(state);
-}
-
-static void __stubs_key_init() {
- pthread_key_create(&stubs_key, stubs_state_free);
-}
-
static stubs_state_t* __stubs_state() {
- pthread_once(&stubs_once, __stubs_key_init);
- stubs_state_t* s = static_cast<stubs_state_t*>(pthread_getspecific(stubs_key));
- if (s == NULL) {
- s = stubs_state_alloc();
- if (s == NULL) {
- errno = ENOMEM; // Just in case.
- } else {
- if (pthread_setspecific(stubs_key, s) != 0) {
- stubs_state_free(s);
- errno = ENOMEM;
- s = NULL;
- }
- }
+ LOCAL_INIT_THREAD_LOCAL_BUFFER(stubs_state_t*, stubs, sizeof(stubs_state_t));
+
+ if (stubs_tls_buffer != NULL) {
+ memset(stubs_tls_buffer, 0, sizeof(stubs_state_t));
+ stubs_tls_buffer->group_.gr_mem = stubs_tls_buffer->group_members_;
}
- return s;
+ return stubs_tls_buffer;
}
static passwd* android_iinfo_to_passwd(stubs_state_t* state,
@@ -167,7 +142,6 @@ static group* android_iinfo_to_group(group* gr,
gr->gr_name = (char*) iinfo->name;
gr->gr_gid = iinfo->aid;
gr->gr_mem[0] = gr->gr_name;
- gr->gr_mem[1] = NULL;
return gr;
}
@@ -208,18 +182,27 @@ static group* android_name_to_group(group* gr, const char* name) {
}
// Translate a user/group name to the corresponding user/group id.
+// all_a1234 -> 0 * AID_USER + AID_SHARED_GID_START + 1234 (group name only)
// u0_a1234 -> 0 * AID_USER + AID_APP + 1234
// u2_i1000 -> 2 * AID_USER + AID_ISOLATED_START + 1000
// u1_system -> 1 * AID_USER + android_ids['system']
// returns 0 and sets errno to ENOENT in case of error
-static unsigned app_id_from_name(const char* name) {
- if (name[0] != 'u' || !isdigit(name[1])) {
+static unsigned app_id_from_name(const char* name, bool is_group) {
+ char* end;
+ unsigned long userid;
+ bool is_shared_gid = false;
+
+ if (is_group && name[0] == 'a' && name[1] == 'l' && name[2] == 'l') {
+ end = const_cast<char*>(name+3);
+ userid = 0;
+ is_shared_gid = true;
+ } else if (name[0] == 'u' && isdigit(name[1])) {
+ userid = strtoul(name+1, &end, 10);
+ } else {
errno = ENOENT;
return 0;
}
- char* end;
- unsigned long userid = strtoul(name+1, &end, 10);
if (end[0] != '_' || end[1] == 0) {
errno = ENOENT;
return 0;
@@ -227,8 +210,17 @@ static unsigned app_id_from_name(const char* name) {
unsigned long appid = 0;
if (end[1] == 'a' && isdigit(end[2])) {
- // end will point to \0 if the strtoul below succeeds.
- appid = strtoul(end+2, &end, 10) + AID_APP;
+ if (is_shared_gid) {
+ // end will point to \0 if the strtoul below succeeds.
+ appid = strtoul(end+2, &end, 10) + AID_SHARED_GID_START;
+ if (appid > AID_SHARED_GID_END) {
+ errno = ENOENT;
+ return 0;
+ }
+ } else {
+ // end will point to \0 if the strtoul below succeeds.
+ appid = strtoul(end+2, &end, 10) + AID_APP;
+ }
} else if (end[1] == 'i' && isdigit(end[2])) {
// end will point to \0 if the strtoul below succeeds.
appid = strtoul(end+2, &end, 10) + AID_ISOLATED_START;
@@ -263,12 +255,11 @@ static unsigned app_id_from_name(const char* name) {
return (unsigned)(appid + userid*AID_USER);
}
-static void print_app_name_from_appid_userid(const uid_t appid,
- const uid_t userid, char* buffer, const int bufferlen) {
+static void print_app_name_from_uid(const uid_t uid, char* buffer, const int bufferlen) {
+ const uid_t appid = uid % AID_USER;
+ const uid_t userid = uid / AID_USER;
if (appid >= AID_ISOLATED_START) {
snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
- } else if (userid == 0 && appid >= AID_SHARED_GID_START) {
- snprintf(buffer, bufferlen, "all_a%u", appid - AID_SHARED_GID_START);
} else if (appid < AID_APP) {
for (size_t n = 0; n < android_id_count; n++) {
if (android_ids[n].aid == appid) {
@@ -281,10 +272,23 @@ static void print_app_name_from_appid_userid(const uid_t appid,
}
}
-static void print_app_name_from_uid(const uid_t uid, char* buffer, const int bufferlen) {
- const uid_t appid = uid % AID_USER;
- const uid_t userid = uid / AID_USER;
- return print_app_name_from_appid_userid(appid, userid, buffer, bufferlen);
+static void print_app_name_from_gid(const gid_t gid, char* buffer, const int bufferlen) {
+ const uid_t appid = gid % AID_USER;
+ const uid_t userid = gid / AID_USER;
+ if (appid >= AID_ISOLATED_START) {
+ snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START);
+ } else if (userid == 0 && appid >= AID_SHARED_GID_START && appid <= AID_SHARED_GID_END) {
+ snprintf(buffer, bufferlen, "all_a%u", appid - AID_SHARED_GID_START);
+ } else if (appid < AID_APP) {
+ for (size_t n = 0; n < android_id_count; n++) {
+ if (android_ids[n].aid == appid) {
+ snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name);
+ return;
+ }
+ }
+ } else {
+ snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP);
+ }
}
// Translate a uid into the corresponding name.
@@ -301,12 +305,9 @@ static passwd* app_id_to_passwd(uid_t uid, stubs_state_t* state) {
return NULL;
}
- const uid_t appid = uid % AID_USER;
- const uid_t userid = uid / AID_USER;
-
- print_app_name_from_appid_userid(appid, userid, state->app_name_buffer_,
- sizeof(state->app_name_buffer_));
+ print_app_name_from_uid(uid, state->app_name_buffer_, sizeof(state->app_name_buffer_));
+ const uid_t appid = uid % AID_USER;
if (appid < AID_APP) {
snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
} else {
@@ -332,14 +333,13 @@ static group* app_id_to_group(gid_t gid, stubs_state_t* state) {
return NULL;
}
- print_app_name_from_uid(gid, state->group_name_buffer_,
- sizeof(state->group_name_buffer_));
+ print_app_name_from_gid(gid, state->group_name_buffer_, sizeof(state->group_name_buffer_));
group* gr = &state->group_;
gr->gr_name = state->group_name_buffer_;
gr->gr_gid = gid;
gr->gr_mem[0] = gr->gr_name;
- gr->gr_mem[1] = NULL;
+
return gr;
}
@@ -367,7 +367,7 @@ passwd* getpwnam(const char* login) { // NOLINT: implementing bad function.
if (pw != NULL) {
return pw;
}
- return app_id_to_passwd(app_id_from_name(login), state);
+ return app_id_to_passwd(app_id_from_name(login, false), state);
}
// All users are in just one group, the one passed in.
@@ -395,7 +395,6 @@ group* getgrgid(gid_t gid) { // NOLINT: implementing bad function.
if (gr != NULL) {
return gr;
}
-
return app_id_to_group(gid, state);
}
@@ -408,8 +407,7 @@ group* getgrnam(const char* name) { // NOLINT: implementing bad function.
if (android_name_to_group(&state->group_, name) != 0) {
return &state->group_;
}
-
- return app_id_to_group(app_id_from_name(name), state);
+ return app_id_to_group(app_id_from_name(name, true), state);
}
// We don't have an /etc/networks, so all inputs return NULL.
diff --git a/libc/arch-mips/bionic/crtbegin_so.c b/libc/include/machine/pthread_types.h
index d664ce6..900541c 100644
--- a/libc/arch-mips/bionic/crtbegin_so.c
+++ b/libc/include/machine/pthread_types.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2008 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,13 +26,23 @@
* SUCH DAMAGE.
*/
-extern void __cxa_finalize(void *);
-extern void *__dso_handle;
+#ifndef _MACHINE_PTHREAD_TYPES_H_
+#define _MACHINE_PTHREAD_TYPES_H_
-__attribute__((visibility("hidden"),destructor))
-void __on_dlclose() {
- __cxa_finalize(&__dso_handle);
-}
+#include <sys/types.h>
-#include "../../arch-common/bionic/__dso_handle_so.h"
-#include "atexit.h"
+typedef long pthread_t;
+
+typedef struct {
+ uint32_t flags;
+ void* stack_base;
+ size_t stack_size;
+ size_t guard_size;
+ int32_t sched_policy;
+ int32_t sched_priority;
+#ifdef __LP64__
+ char __reserved[16];
+#endif
+} pthread_attr_t;
+
+#endif /* _MACHINE_PTHREAD_TYPES_H_ */
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 86a1005..24dba1b 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -29,11 +29,12 @@
#ifndef _PTHREAD_H_
#define _PTHREAD_H_
-#include <time.h>
-#include <signal.h>
-#include <sched.h>
#include <limits.h>
+#include <machine/pthread_types.h>
+#include <sched.h>
+#include <sys/cdefs.h>
#include <sys/types.h>
+#include <time.h>
#if defined(__LP64__)
#define __RESERVED_INITIALIZER , {0}
@@ -76,18 +77,6 @@ typedef struct {
#define PTHREAD_COND_INITIALIZER {0 __RESERVED_INITIALIZER}
-typedef struct {
- uint32_t flags;
- void* stack_base;
- size_t stack_size;
- size_t guard_size;
- int32_t sched_policy;
- int32_t sched_priority;
-#ifdef __LP64__
- char __reserved[16];
-#endif
-} pthread_attr_t;
-
typedef long pthread_mutexattr_t;
typedef long pthread_condattr_t;
@@ -118,7 +107,6 @@ typedef struct {
#endif
typedef int pthread_key_t;
-typedef long pthread_t;
typedef volatile int pthread_once_t;
@@ -195,8 +183,6 @@ int pthread_join(pthread_t, void**);
int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));
int pthread_key_delete(pthread_key_t);
-int pthread_kill(pthread_t, int);
-
int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1));
int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2));
@@ -236,8 +222,6 @@ int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull((
int pthread_setspecific(pthread_key_t, const void*);
-int pthread_sigmask(int, const sigset_t*, sigset_t*);
-
typedef void (*__pthread_cleanup_func_t)(void*);
typedef struct __pthread_cleanup_t {
diff --git a/libc/include/sched.h b/libc/include/sched.h
index 6155ab7..4f9e2a6 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -39,9 +39,8 @@ __BEGIN_DECLS
#define SCHED_OTHER SCHED_NORMAL
struct sched_param {
- int __sched_priority;
+ int sched_priority;
};
-#define sched_priority __sched_priority
extern int sched_setscheduler(pid_t, int, const struct sched_param*);
extern int sched_getscheduler(pid_t);
diff --git a/libc/include/signal.h b/libc/include/signal.h
index e23e65b..6d89ef7 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -29,12 +29,13 @@
#ifndef _SIGNAL_H_
#define _SIGNAL_H_
+#include <asm/sigcontext.h>
#include <errno.h>
+#include <limits.h>
+#include <machine/pthread_types.h>
+#include <string.h>
#include <sys/cdefs.h>
-#include <limits.h> /* For LONG_BIT */
-#include <string.h> /* For memset() */
#include <sys/types.h>
-#include <asm/sigcontext.h>
#if defined(__LP64__) || defined(__mips__)
/* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one,
@@ -129,6 +130,9 @@ extern int sigaltstack(const stack_t*, stack_t*);
extern void psiginfo(const siginfo_t*, const char*);
extern void psignal(int, const char*);
+extern int pthread_kill(pthread_t, int);
+extern int pthread_sigmask(int, const sigset_t*, sigset_t*);
+
__END_DECLS
#endif /* _SIGNAL_H_ */
diff --git a/libc/private/kernel_sigset_t.h b/libc/private/kernel_sigset_t.h
index b2d6386..9415fcf 100644
--- a/libc/private/kernel_sigset_t.h
+++ b/libc/private/kernel_sigset_t.h
@@ -17,6 +17,8 @@
#ifndef LIBC_PRIVATE_KERNEL_SIGSET_T_H_
#define LIBC_PRIVATE_KERNEL_SIGSET_T_H_
+#include <signal.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.
// In the meantime, we can use this union to pass an appropriately-sized block of memory
diff --git a/libc/stdio/fileext.h b/libc/stdio/fileext.h
index dc89fff..25b7bda 100644
--- a/libc/stdio/fileext.h
+++ b/libc/stdio/fileext.h
@@ -34,6 +34,8 @@
#include <pthread.h>
+__BEGIN_DECLS
+
/*
* file extension
*/
@@ -61,4 +63,6 @@ do { \
_FILEEXT_INIT(f); \
} while (0)
+__END_DECLS
+
#endif /* _FILEEXT_H_ */
diff --git a/libc/stdio/glue.h b/libc/stdio/glue.h
index 4ead20a..a9e5d10 100644
--- a/libc/stdio/glue.h
+++ b/libc/stdio/glue.h
@@ -32,6 +32,10 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
/*
* The first few FILEs are statically allocated; others are dynamically
* allocated and linked in via this glue structure.
@@ -44,3 +48,5 @@ struct glue {
/* This was referenced by a couple of different pieces of middleware and the Crystax NDK. */
__LIBC64_HIDDEN__ extern struct glue __sglue;
+
+__END_DECLS
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 13188ee..46b11f1 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -41,6 +41,8 @@
#include "wcio.h"
#include "fileext.h"
+__BEGIN_DECLS
+
/*
* Android <= KitKat had getc/putc macros in <stdio.h> that referred
* to __srget/__swbuf, so those symbols need to be public for LP32
@@ -137,3 +139,5 @@ extern int __sfvwrite(FILE *, struct __suio *);
wint_t __fputwc_unlock(wchar_t wc, FILE *fp);
#pragma GCC visibility pop
+
+__END_DECLS
diff --git a/libc/stdio/wcio.h b/libc/stdio/wcio.h
index 584a3f2..2c1fa3c 100644
--- a/libc/stdio/wcio.h
+++ b/libc/stdio/wcio.h
@@ -32,6 +32,10 @@
#ifndef _WCIO_H_
#define _WCIO_H_
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
/* minimal requirement of SUSv2 */
#define WCIO_UNGETWC_BUFSIZE 1
@@ -78,4 +82,6 @@ do {\
#define WCIO_INIT(fp) \
memset(&(_EXT(fp)->_wcio), 0, sizeof(struct wchar_io_data))
+__END_DECLS
+
#endif /*_WCIO_H_*/
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index 268b3b6..8386ba5 100644
--- a/libc/upstream-openbsd/android/include/openbsd-compat.h
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -59,6 +59,9 @@
/* We have OpenBSD's getentropy_linux.c, but we don't mention getentropy in any header. */
__LIBC_HIDDEN__ extern int getentropy(void*, size_t);
+/* OpenBSD has this as API, but we just use it internally. */
+__LIBC_HIDDEN__ void* reallocarray(void*, size_t, size_t);
+
/* LP32 NDK ctype.h contained references to these. */
__LIBC64_HIDDEN__ extern const short* _tolower_tab_;
__LIBC64_HIDDEN__ extern const short* _toupper_tab_;
diff --git a/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c b/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c
new file mode 100644
index 0000000..7accd99
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c
@@ -0,0 +1,38 @@
+/* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}