Merge "Stop including <sys/sysmacros.h> from <sys/types.h>."
diff --git a/libc/Android.bp b/libc/Android.bp
index 3877145..cda9eaa 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1984,14 +1984,6 @@
srcs: ["arch-common/bionic/crtbegin.c"],
arch: {
- arm64: {
- srcs: [
- "arch-arm64/bionic/crtbegin.c",
- ],
- exclude_srcs: [
- "arch-common/bionic/crtbegin.c",
- ],
- },
mips: {
srcs: [
"arch-mips/bionic/crtbegin.c",
@@ -2029,14 +2021,6 @@
srcs: ["arch-common/bionic/crtbegin.c"],
arch: {
- arm64: {
- srcs: [
- "arch-arm64/bionic/crtbegin.c",
- ],
- exclude_srcs: [
- "arch-common/bionic/crtbegin.c",
- ],
- },
mips: {
srcs: [
"arch-mips/bionic/crtbegin.c",
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
index da40f6c..ca29715 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
index 026adcc..2679c02 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy.S b/libc/arch-arm/cortex-a15/bionic/memcpy.S
index 9407a08..7ad0093 100644
--- a/libc/arch-arm/cortex-a15/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a15/bionic/memcpy.S
@@ -59,6 +59,10 @@
.syntax unified
.fpu neon
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(__memcpy_chk)
cmp r2, r3
bls memcpy
diff --git a/libc/arch-arm/cortex-a15/bionic/memset.S b/libc/arch-arm/cortex-a15/bionic/memset.S
index 2542f3f..4b4388e 100644
--- a/libc/arch-arm/cortex-a15/bionic/memset.S
+++ b/libc/arch-arm/cortex-a15/bionic/memset.S
@@ -37,6 +37,10 @@
.fpu neon
.syntax unified
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(__memset_chk)
cmp r2, r3
bls memset
diff --git a/libc/arch-arm/cortex-a15/bionic/strcmp.S b/libc/arch-arm/cortex-a15/bionic/strcmp.S
index 5c8914b..d8993d5 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcmp.S
@@ -57,6 +57,10 @@
.thumb_func
#endif
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(strcmp)
/* Use LDRD whenever possible. */
diff --git a/libc/arch-arm/cortex-a53/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a53/bionic/__strcat_chk.S
index da40f6c..ca29715 100644
--- a/libc/arch-arm/cortex-a53/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a53/bionic/__strcat_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
diff --git a/libc/arch-arm/cortex-a53/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a53/bionic/__strcpy_chk.S
index 026adcc..2679c02 100644
--- a/libc/arch-arm/cortex-a53/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a53/bionic/__strcpy_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
diff --git a/libc/arch-arm/cortex-a53/bionic/memcpy.S b/libc/arch-arm/cortex-a53/bionic/memcpy.S
index 9407a08..7ad0093 100644
--- a/libc/arch-arm/cortex-a53/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a53/bionic/memcpy.S
@@ -59,6 +59,10 @@
.syntax unified
.fpu neon
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(__memcpy_chk)
cmp r2, r3
bls memcpy
diff --git a/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S
index da40f6c..ca29715 100644
--- a/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
diff --git a/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S
index 026adcc..2679c02 100644
--- a/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
diff --git a/libc/arch-arm/cortex-a7/bionic/memcpy.S b/libc/arch-arm/cortex-a7/bionic/memcpy.S
index 9407a08..7ad0093 100644
--- a/libc/arch-arm/cortex-a7/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a7/bionic/memcpy.S
@@ -59,6 +59,10 @@
.syntax unified
.fpu neon
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(__memcpy_chk)
cmp r2, r3
bls memcpy
diff --git a/libc/arch-arm/cortex-a7/bionic/memset.S b/libc/arch-arm/cortex-a7/bionic/memset.S
index e4fb1b4..72ee613 100644
--- a/libc/arch-arm/cortex-a7/bionic/memset.S
+++ b/libc/arch-arm/cortex-a7/bionic/memset.S
@@ -37,6 +37,10 @@
.fpu neon
.syntax unified
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(__memset_chk)
cmp r2, r3
bls memset
diff --git a/libc/arch-arm/denver/bionic/__strcat_chk.S b/libc/arch-arm/denver/bionic/__strcat_chk.S
index 9f7db59..d4f651c 100644
--- a/libc/arch-arm/denver/bionic/__strcat_chk.S
+++ b/libc/arch-arm/denver/bionic/__strcat_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
diff --git a/libc/arch-arm/denver/bionic/__strcpy_chk.S b/libc/arch-arm/denver/bionic/__strcpy_chk.S
index 9b7ea91..9295a00 100644
--- a/libc/arch-arm/denver/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/denver/bionic/__strcpy_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
diff --git a/libc/arch-arm/denver/bionic/memcpy.S b/libc/arch-arm/denver/bionic/memcpy.S
index d4e0fb4..743c74b 100644
--- a/libc/arch-arm/denver/bionic/memcpy.S
+++ b/libc/arch-arm/denver/bionic/memcpy.S
@@ -61,6 +61,10 @@
.syntax unified
.fpu neon
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
ENTRY(__memcpy_chk)
cmp r2, r3
bls memcpy
diff --git a/libc/arch-arm/krait/bionic/__strcat_chk.S b/libc/arch-arm/krait/bionic/__strcat_chk.S
index a46ff98..32fa82d 100644
--- a/libc/arch-arm/krait/bionic/__strcat_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcat_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of src string, then get the source of the dst string.
// Check that the two lengths together don't exceed the threshold, then
// do a memcpy of the data.
diff --git a/libc/arch-arm/krait/bionic/__strcpy_chk.S b/libc/arch-arm/krait/bionic/__strcpy_chk.S
index 9c2f66a..ca4cf7f 100644
--- a/libc/arch-arm/krait/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcpy_chk.S
@@ -33,6 +33,10 @@
.thumb
.thumb_func
+ // To avoid warning about deprecated instructions, add an explicit
+ // arch. The code generated is exactly the same.
+ .arch armv7-a
+
// Get the length of the source string first, then do a memcpy of the data
// instead of a strcpy.
ENTRY(__strcpy_chk)
diff --git a/libc/arch-arm64/bionic/crtbegin.c b/libc/arch-arm64/bionic/crtbegin.c
deleted file mode 100644
index 7e2c5d7..0000000
--- a/libc/arch-arm64/bionic/crtbegin.c
+++ /dev/null
@@ -1,70 +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.
- */
-
-#include "../../bionic/libc_init_common.h"
-#include <stddef.h>
-#include <stdint.h>
-
-__attribute__ ((section (".preinit_array")))
-void (*__PREINIT_ARRAY__)(void) = (void (*)(void)) -1;
-
-__attribute__ ((section (".init_array")))
-void (*__INIT_ARRAY__)(void) = (void (*)(void)) -1;
-
-__attribute__ ((section (".fini_array")))
-void (*__FINI_ARRAY__)(void) = (void (*)(void)) -1;
-
-
-__LIBC_HIDDEN__ void do_arm64_start(void* raw_args) {
- structors_array_t array;
- array.preinit_array = &__PREINIT_ARRAY__;
- array.init_array = &__INIT_ARRAY__;
- array.fini_array = &__FINI_ARRAY__;
- __libc_init(raw_args, NULL, &main, &array);
-}
-
-/*
- * Put the value of sp in x0 and call do_arm64_init(). The latter will then
- * then be able to access the stack as prepared by the kernel's execve system
- * call (via the first argument).
- */
-__asm__ (
-" .text \n"
-" .align 2 \n"
-" .global _start \n"
-" .hidden _start \n"
-" .type _start, %function \n"
-"_start: \n"
-" add x0, sp, xzr \n"
-" b do_arm64_start \n"
-" .size _start, .-_start \n"
-);
-
-#include "../../arch-common/bionic/__dso_handle.h"
-#include "../../arch-common/bionic/atexit.h"
-#include "../../arch-common/bionic/pthread_atfork.h"
diff --git a/libc/arch-common/bionic/crtbegin.c b/libc/arch-common/bionic/crtbegin.c
index c46405c..d3a0f07 100644
--- a/libc/arch-common/bionic/crtbegin.c
+++ b/libc/arch-common/bionic/crtbegin.c
@@ -30,36 +30,42 @@
#include <stddef.h>
#include <stdint.h>
-__attribute__ ((section (".preinit_array")))
+__attribute__((__section__(".preinit_array")))
void (*__PREINIT_ARRAY__)(void) = (void (*)(void)) -1;
-__attribute__ ((section (".init_array")))
+__attribute__((__section__(".init_array")))
void (*__INIT_ARRAY__)(void) = (void (*)(void)) -1;
-__attribute__ ((section (".fini_array")))
+__attribute__((__section__(".fini_array")))
void (*__FINI_ARRAY__)(void) = (void (*)(void)) -1;
-__LIBC_HIDDEN__
-#ifdef __i386__
-__attribute__((force_align_arg_pointer))
-#endif
-void _start() {
+static void _start_main(void* raw_args) {
structors_array_t array;
array.preinit_array = &__PREINIT_ARRAY__;
array.init_array = &__INIT_ARRAY__;
array.fini_array = &__FINI_ARRAY__;
- void* raw_args = (void*) ((uintptr_t) __builtin_frame_address(0) + sizeof(void*));
-#ifdef __x86_64__
- // 16-byte stack alignment is required by x86_64 ABI
- asm("andq $~15, %rsp");
-#endif
__libc_init(raw_args, NULL, &main, &array);
}
+#define PRE ".text; .global _start; .type _start,%function; _start:"
+#define POST "; .size _start, .-_start"
+
+#if defined(__aarch64__)
+__asm__(PRE "mov x0,sp; b _start_main" POST);
+#elif defined(__arm__)
+__asm__(PRE "mov r0,sp; b _start_main" POST);
+#elif defined(__i386__)
+__asm__(PRE "movl %esp,%eax; andl $~0xf,%esp; pushl %eax; calll _start_main" POST);
+#elif defined(__x86_64__)
+__asm__(PRE "movq %rsp,%rdi; andq $~0xf,%rsp; callq _start_main" POST);
+#else
+#error unsupported architecture
+#endif
+
+#undef PRE
+#undef POST
+
#include "__dso_handle.h"
#include "atexit.h"
#include "pthread_atfork.h"
-#ifdef __i386__
-# include "../../arch-x86/bionic/__stack_chk_fail_local.h"
-#endif
diff --git a/libc/arch-common/bionic/crtbegin_so.c b/libc/arch-common/bionic/crtbegin_so.c
index 3754363..258a6cd 100644
--- a/libc/arch-common/bionic/crtbegin_so.c
+++ b/libc/arch-common/bionic/crtbegin_so.c
@@ -57,6 +57,3 @@
# include "atexit.h"
#endif
#include "pthread_atfork.h"
-#ifdef __i386__
-# include "../../arch-x86/bionic/__stack_chk_fail_local.h"
-#endif
diff --git a/libc/arch-x86/bionic/__stack_chk_fail_local.h b/libc/arch-x86/bionic/__stack_chk_fail_local.h
deleted file mode 100644
index 0b0fd7f..0000000
--- a/libc/arch-x86/bionic/__stack_chk_fail_local.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#include <sys/cdefs.h>
-
-/*
- __stack_chk_fail routine is runtime part of stack protector compiler
- feature. It's implemented in libc and represents die routine when stack
- corruption is detected.
-
- Calls are generated by compiler and injected into user functions when
- -fstack-protector* options are used.
-
- __stack_chk_fail_local is wrapper for __stack_chk_fail. Compiler generates
- wrapper calls instead for PIC code only and only on IA32 for optimization
- purpose (see gcc/config/i386/i386.c). Wrapper body is always included into
- executable or library. This is the idea of optimization.
-
- Glibc is doing this via libc_nonshared.a which is linked automatically
- everytime with libc.so. In bionic we have to bring it within crtfiles
- because libc.so is real library and not a link script like libc.so at glibc.
-
- For x86_64 or non-PIC code compiler always generates __stack_chk_fail calls.
-*/
-
-#ifdef __i386__
-extern void __stack_chk_fail();
-
-__LIBC_HIDDEN__ void __stack_chk_fail_local() {
- __stack_chk_fail();
-}
-#endif
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 711792b..3b2f4da 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -86,6 +86,7 @@
* explore_fqdn() dispatch table method, with the below function only making DNS calls.
*/
struct hostent *android_gethostbyaddrfornetcontext(const void *, socklen_t, int, const struct android_net_context *) __used_in_netd;
+struct hostent *android_gethostbynamefornetcontext(const char *, int, const struct android_net_context *) __used_in_netd;
int android_getaddrinfofornetcontext(const char *, const char *, const struct addrinfo *,
const struct android_net_context *, struct addrinfo **) __used_in_netd;
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 284270c..77b03bf 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -504,8 +504,8 @@
__LIBC_HIDDEN__ int res_getservers(res_state,
union res_sockaddr_union *, int);
-__LIBC_HIDDEN__ void res_setnetid(res_state, unsigned);
-__LIBC_HIDDEN__ void res_setmark(res_state, unsigned);
+struct android_net_context; /* forward */
+__LIBC_HIDDEN__ void res_setnetcontext(res_state, const struct android_net_context *);
// We use the OpenBSD __res_randomid...
u_int __res_randomid(void);
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 4215963..418bf6d 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -1981,8 +1981,7 @@
* fully populate the thread private data here, but if we get down there
* and have a cache hit that would be wasted, so we do the rest there on miss
*/
- res_setnetid(res, netcontext->dns_netid);
- res_setmark(res, netcontext->dns_mark);
+ res_setnetcontext(res, netcontext);
if (res_searchN(name, &q, res) < 0) {
__res_put_state(res);
free(buf);
diff --git a/libc/dns/net/gethnamaddr.c b/libc/dns/net/gethnamaddr.c
index 036ad1d..4e416fd 100644
--- a/libc/dns/net/gethnamaddr.c
+++ b/libc/dns/net/gethnamaddr.c
@@ -160,7 +160,7 @@
static int _dns_gethtbyname(void *, void *, va_list);
static struct hostent *gethostbyname_internal(const char *, int, res_state,
- struct hostent *, char *, size_t, int *, unsigned, unsigned);
+ struct hostent *, char *, size_t, int *, const struct android_net_context *);
static struct hostent* android_gethostbyaddrfornetcontext_proxy_internal(const void*, socklen_t,
int, struct hostent *, char *, size_t, int *, const struct android_net_context *);
@@ -529,15 +529,15 @@
_DIAGASSERT(name != NULL);
if (res->options & RES_USE_INET6) {
- *result = gethostbyname_internal(name, AF_INET6, res, hp, buf, buflen, errorp, NETID_UNSET,
- MARK_UNSET);
+ *result = gethostbyname_internal(name, AF_INET6, res, hp, buf, buflen, errorp,
+ &NETCONTEXT_UNSET);
if (*result) {
__res_put_state(res);
return 0;
}
}
- *result = gethostbyname_internal(name, AF_INET, res, hp, buf, buflen, errorp, NETID_UNSET,
- MARK_UNSET);
+ *result = gethostbyname_internal(name, AF_INET, res, hp, buf, buflen, errorp,
+ &NETCONTEXT_UNSET);
__res_put_state(res);
if (!*result && errno == ENOSPC) {
errno = ERANGE;
@@ -558,8 +558,8 @@
*errorp = NETDB_INTERNAL;
return -1;
}
- *result = gethostbyname_internal(name, af, res, hp, buf, buflen, errorp, NETID_UNSET,
- MARK_UNSET);
+ *result = gethostbyname_internal(name, af, res, hp, buf, buflen, errorp,
+ &NETCONTEXT_UNSET);
__res_put_state(res);
if (!*result && errno == ENOSPC) {
errno = ERANGE;
@@ -822,17 +822,16 @@
// very similar in proxy-ness to android_getaddrinfo_proxy
static struct hostent *
gethostbyname_internal(const char *name, int af, res_state res, struct hostent *hp, char *hbuf,
- size_t hbuflen, int *errorp, unsigned netid, unsigned mark)
+ size_t hbuflen, int *errorp, const struct android_net_context *netcontext)
{
FILE* proxy = android_open_proxy();
if (proxy == NULL) {
// Either we're not supposed to be using the proxy or the proxy is unavailable.
- res_setnetid(res, netid);
- res_setmark(res, mark);
+ res_setnetcontext(res, netcontext);
return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen, errorp);
}
- netid = __netdClientDispatch.netIdForResolv(netid);
+ unsigned netid = __netdClientDispatch.netIdForResolv(netcontext->app_netid);
// This is writing to system/netd/server/DnsProxyListener.cpp and changes
// here need to be matched there.
@@ -1296,8 +1295,7 @@
free(buf);
return NS_NOTFOUND;
}
- res_setnetid(res, netcontext->dns_netid);
- res_setmark(res, netcontext->dns_mark);
+ res_setnetcontext(res, netcontext);
n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf));
if (n < 0) {
free(buf);
@@ -1611,13 +1609,21 @@
struct hostent *
android_gethostbynamefornet(const char *name, int af, unsigned netid, unsigned mark)
{
+ const struct android_net_context netcontext = make_context(netid, mark);
+ return android_gethostbynamefornetcontext(name, af, &netcontext);
+}
+
+struct hostent *
+android_gethostbynamefornetcontext(const char *name, int af,
+ const struct android_net_context *netcontext)
+{
struct hostent *hp;
res_state res = __res_get_state();
if (res == NULL)
return NULL;
res_static rs = __res_get_static(); /* Use res_static to provide thread-safety. */
hp = gethostbyname_internal(name, af, res, &rs->host, rs->hostbuf, sizeof(rs->hostbuf),
- &h_errno, netid, mark);
+ &h_errno, netcontext);
__res_put_state(res);
return hp;
}
diff --git a/libc/dns/resolv/res_init.c b/libc/dns/resolv/res_init.c
index b9fc131..302a62b 100644
--- a/libc/dns/resolv/res_init.c
+++ b/libc/dns/resolv/res_init.c
@@ -768,17 +768,12 @@
}
#ifdef ANDROID_CHANGES
-void res_setnetid(res_state statp, unsigned netid)
+void res_setnetcontext(res_state statp, const struct android_net_context *netcontext)
{
if (statp != NULL) {
- statp->netid = netid;
- }
-}
-
-void res_setmark(res_state statp, unsigned mark)
-{
- if (statp != NULL) {
- statp->_mark = mark;
+ statp->netid = netcontext->dns_netid;
+ statp->_mark = netcontext->dns_mark;
+ statp->qhook = netcontext->qhook;
}
}
diff --git a/libc/include/bits/posix_limits.h b/libc/include/bits/posix_limits.h
index db09bd7..cfc46f5 100644
--- a/libc/include/bits/posix_limits.h
+++ b/libc/include/bits/posix_limits.h
@@ -99,7 +99,7 @@
#define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L
#define _POSIX_THREAD_PRIO_INHERIT -1 /* not implemented */
#define _POSIX_THREAD_PRIO_PROTECT -1 /* not implemented */
-#define _POSIX_THREAD_PROCESS_SHARED -1 /* not implemented */
+#define _POSIX_THREAD_PROCESS_SHARED 200809L /* PTHREAD_PROCESS_SHARED supported. */
#define _POSIX_THREAD_ROBUST_PRIO_INHERIT -1 /* not implemented */
#define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1 /* not implemented */
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
diff --git a/libc/include/sys/epoll.h b/libc/include/sys/epoll.h
index b7fdd4d..5e92fdc 100644
--- a/libc/include/sys/epoll.h
+++ b/libc/include/sys/epoll.h
@@ -75,6 +75,22 @@
int epoll_create(int);
int epoll_create1(int) __INTRODUCED_IN(21);
+
+/*
+ * Some third-party code uses the existence of EPOLL_CLOEXEC to detect the
+ * availability of epoll_create1. This is not correct, since having up-to-date
+ * UAPI headers says nothing about the C library, but for the time being we
+ * don't want to harm adoption to the unified headers. We'll undef EPOLL_CLOEXEC
+ * if we don't have epoll_create1 for the time being, and maybe revisit this
+ * later.
+ *
+ * https://github.com/android-ndk/ndk/issues/302
+ * https://github.com/android-ndk/ndk/issues/394
+ */
+#if __ANDROID_API__ < __ANDROID_API_L__ && defined(EPOLL_CLOEXEC)
+#undef EPOLL_CLOEXEC
+#endif
+
int epoll_ctl(int, int, int, struct epoll_event*);
int epoll_wait(int, struct epoll_event*, int, int);
int epoll_pwait(int, struct epoll_event*, int, int, const sigset_t*) __INTRODUCED_IN(21);
diff --git a/libc/include/sys/inotify.h b/libc/include/sys/inotify.h
index 2e99144..98f7198 100644
--- a/libc/include/sys/inotify.h
+++ b/libc/include/sys/inotify.h
@@ -37,8 +37,21 @@
__BEGIN_DECLS
+/*
+ * Some third-party code uses the existence of IN_CLOEXEC/IN_NONBLOCK to detect
+ * the availability of inotify_init1. This is not correct, since
+ * `syscall(__NR_inotify_init1, IN_CLOEXEC)` is still valid even if the C
+ * library doesn't have that function, but for the time being we don't want to
+ * harm adoption to the unified headers. We'll avoid defining IN_CLOEXEC and
+ * IN_NONBLOCK if we don't have inotify_init1 for the time being, and maybe
+ * revisit this later.
+ *
+ * https://github.com/android-ndk/ndk/issues/394
+ */
+#if __ANDROID_API__ >= __ANDROID_API_L__
#define IN_CLOEXEC O_CLOEXEC
#define IN_NONBLOCK O_NONBLOCK
+#endif
int inotify_init(void);
int inotify_init1(int) __INTRODUCED_IN(21);
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index a74027a..b32f769 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1496,6 +1496,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
arc4random_addrandom; # arm x86 mips
arc4random_stir; # arm x86 mips
atexit; # arm
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 34d3429..afcf8bb 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1244,6 +1244,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
free_malloc_leak_info;
get_malloc_leak_info;
gMallocLeakZygoteChild;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 90929f5..f05e7eb 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1522,6 +1522,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
arc4random_addrandom; # arm x86 mips
arc4random_stir; # arm x86 mips
atexit; # arm
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index aac876d..a472214 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1339,6 +1339,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
arc4random_addrandom; # arm x86 mips
arc4random_stir; # arm x86 mips
bcopy; # arm x86 mips
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 34d3429..afcf8bb 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1244,6 +1244,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
free_malloc_leak_info;
get_malloc_leak_info;
gMallocLeakZygoteChild;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index 682f2c4..27a597f 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1338,6 +1338,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
arc4random_addrandom; # arm x86 mips
arc4random_stir; # arm x86 mips
bcopy; # arm x86 mips
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 34d3429..afcf8bb 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1244,6 +1244,7 @@
android_gethostbyaddrfornet;
android_gethostbyaddrfornetcontext;
android_gethostbynamefornet;
+ android_gethostbynamefornetcontext;
free_malloc_leak_info;
get_malloc_leak_info;
gMallocLeakZygoteChild;
diff --git a/linker/arch/x86/begin.c b/linker/arch/x86/begin.c
index 051a16a..a734f25 100644
--- a/linker/arch/x86/begin.c
+++ b/linker/arch/x86/begin.c
@@ -48,9 +48,3 @@
/* Unreachable */
}
-
-/* Since linker has its own version of crtbegin (this file) it should have */
-/* own version of __stack_chk_fail_local for the case when it's built with */
-/* stack protector feature */
-
-#include "arch-x86/bionic/__stack_chk_fail_local.h"
diff --git a/tests/libs/Android.build.dlext_testzip.mk b/tests/libs/Android.build.dlext_testzip.mk
index 0220ae2..4b6d099 100644
--- a/tests/libs/Android.build.dlext_testzip.mk
+++ b/tests/libs/Android.build.dlext_testzip.mk
@@ -22,7 +22,7 @@
include $(CLEAR_VARS)
-LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_CLASS := NATIVE_TESTS
LOCAL_MODULE := libdlext_test_zip_zipaligned
LOCAL_MODULE_SUFFIX := .zip
LOCAL_MODULE_PATH := $($(bionic_2nd_arch_prefix)TARGET_OUT_DATA_NATIVE_TESTS)/bionic-loader-test-libs/libdlext_test_zip
@@ -44,7 +44,7 @@
include $(CLEAR_VARS)
-LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_CLASS := NATIVE_TESTS
LOCAL_MODULE := libdlext_test_runpath_zip_zipaligned
LOCAL_MODULE_SUFFIX := .zip
LOCAL_MODULE_PATH := $($(bionic_2nd_arch_prefix)TARGET_OUT_DATA_NATIVE_TESTS)/bionic-loader-test-libs/libdlext_test_runpath_zip
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 9eae06e..109b92c 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -742,6 +742,7 @@
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIORITY_SCHEDULING);
EXPECT_EQ(-1, _POSIX_THREAD_PRIO_INHERIT);
EXPECT_EQ(-1, _POSIX_THREAD_PRIO_PROTECT);
+ EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PROCESS_SHARED);
EXPECT_EQ(-1, _POSIX_THREAD_ROBUST_PRIO_PROTECT);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_SAFE_FUNCTIONS);
EXPECT_EQ(-1, _POSIX_THREAD_SPORADIC_SERVER);
@@ -781,7 +782,6 @@
EXPECT_EQ(-1, _POSIX_PRIORITIZED_IO);
EXPECT_EQ(-1, _POSIX_SHARED_MEMORY_OBJECTS);
EXPECT_EQ(-1, _POSIX_SPAWN);
- EXPECT_EQ(-1, _POSIX_THREAD_PROCESS_SHARED);
EXPECT_EQ(-1, _POSIX_THREAD_ROBUST_PRIO_INHERIT);
EXPECT_EQ(-1, _POSIX2_VERSION);
@@ -908,6 +908,7 @@
VERIFY_SYSCONF_UNSUPPORTED(_SC_SPORADIC_SERVER);
VERIFY_SYSCONF_POSITIVE(_SC_SYMLOOP_MAX);
VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_CPUTIME);
+ VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_PROCESS_SHARED);
VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_SPORADIC_SERVER);
VERIFY_SYSCONF_POSIX_VERSION(_SC_TIMEOUTS);
VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE);
@@ -944,7 +945,6 @@
VERIFY_SYSCONF_UNSUPPORTED(_SC_PRIORITIZED_IO);
VERIFY_SYSCONF_UNSUPPORTED(_SC_SHARED_MEMORY_OBJECTS);
VERIFY_SYSCONF_UNSUPPORTED(_SC_SPAWN);
- VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_PROCESS_SHARED);
VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_ROBUST_PRIO_INHERIT);
VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_ROBUST_PRIO_PROTECT);