am cf342653: am 8d79fd1c: Merge "libc x86: Remove index.S, strcpy.S, strchr.S"
* commit 'cf342653388682c96b3c4eec6a5ed4dbcb6112ef':
libc x86: Remove index.S, strcpy.S, strchr.S
diff --git a/libc/arch-arm/krait/bionic/memcpy.S b/libc/arch-arm/krait/bionic/memcpy.S
index 0cd4d44..4a21709 100644
--- a/libc/arch-arm/krait/bionic/memcpy.S
+++ b/libc/arch-arm/krait/bionic/memcpy.S
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2013 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -45,9 +45,8 @@
ENTRY(memcpy)
.save {r0, lr}
/* start preloading as early as possible */
- pld [r1, #(CACHE_LINE_SIZE*0)]
+ pld [r1, #(CACHE_LINE_SIZE*4)]
stmfd sp!, {r0, lr}
- pld [r1, #(CACHE_LINE_SIZE*2)]
/* do we have at least 16-bytes to copy (needed for alignment below) */
cmp r2, #16
@@ -56,7 +55,7 @@
/* align destination to cache-line for the write-buffer */
rsb r3, r0, #0
ands r3, r3, #0xF
- beq 0f
+ beq 2f
/* copy up to 15-bytes (count in r3) */
sub r2, r2, r3
@@ -76,47 +75,29 @@
// copies 8 bytes, destination 64-bits aligned
vld1.8 {d0}, [r1]!
vst1.8 {d0}, [r0, :64]!
-2:
-0: /* preload immediately the next cache line, which we may need */
- pld [r1, #(CACHE_LINE_SIZE*0)]
- pld [r1, #(CACHE_LINE_SIZE*2)]
-
- /* make sure we have at least 64 bytes to copy */
+2: /* make sure we have at least 64 bytes to copy */
subs r2, r2, #64
blo 2f
- /* Preload all the cache lines we need.
- * NOTE: The number of pld below depends on CACHE_LINE_SIZE,
- * ideally we would increase the distance in the main loop to
- * avoid the goofy code below. In practice this doesn't seem to make
- * a big difference.
- * NOTE: The value CACHE_LINE_SIZE * 8 was chosen through
- * experimentation.
- */
- pld [r1, #(CACHE_LINE_SIZE*4)]
- pld [r1, #(CACHE_LINE_SIZE*6)]
- pld [r1, #(CACHE_LINE_SIZE*8)]
-
1: /* The main loop copies 64 bytes at a time */
vld1.8 {d0 - d3}, [r1]!
vld1.8 {d4 - d7}, [r1]!
- pld [r1, #(CACHE_LINE_SIZE*8)]
+ pld [r1, #(CACHE_LINE_SIZE*2)]
subs r2, r2, #64
vst1.8 {d0 - d3}, [r0, :128]!
vst1.8 {d4 - d7}, [r0, :128]!
bhs 1b
2: /* fix-up the remaining count and make sure we have >= 32 bytes left */
- add r2, r2, #64
- subs r2, r2, #32
+ adds r2, r2, #32
blo 4f
-3: /* 32 bytes at a time. These cache lines were already preloaded */
+ /* Copy 32 bytes. These cache lines were already preloaded */
vld1.8 {d0 - d3}, [r1]!
- subs r2, r2, #32
+ sub r2, r2, #32
vst1.8 {d0 - d3}, [r0, :128]!
- bhs 3b
+
4: /* less than 32 left */
add r2, r2, #32
tst r2, #0x10
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c
index 829bf10..3576202 100644
--- a/libc/netbsd/resolv/res_cache.c
+++ b/libc/netbsd/resolv/res_cache.c
@@ -1833,7 +1833,7 @@
/* return 1 if the provided list of name servers differs from the list of name servers
* currently attached to the provided cache_info */
static int _resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
- char** servers, int numservers);
+ const char** servers, int numservers);
/* remove a resolv_pidiface_info structure from _res_pidiface_list */
static void _remove_pidiface_info_locked(int pid);
/* get a resolv_pidiface_info structure from _res_pidiface_list with a certain pid */
@@ -2076,7 +2076,7 @@
}
void
-_resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers,
+_resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
const char *domains)
{
int i, rt, index;
@@ -2149,7 +2149,7 @@
static int
_resolv_is_nameservers_equal_locked(struct resolv_cache_info* cache_info,
- char** servers, int numservers)
+ const char** servers, int numservers)
{
int i;
char** ns;
@@ -2271,8 +2271,8 @@
memcpy(&cache_info->ifaddr, addr, sizeof(*addr));
if (DEBUG) {
- char* addr_s = inet_ntoa(cache_info->ifaddr);
- XLOG("address of interface %s is %s\n", ifname, addr_s);
+ XLOG("address of interface %s is %s\n",
+ ifname, inet_ntoa(cache_info->ifaddr));
}
}
pthread_mutex_unlock(&_res_cache_list_lock);
@@ -2411,26 +2411,24 @@
return len;
}
-int
-_resolv_get_default_iface(char* buff, int buffLen)
+size_t
+_resolv_get_default_iface(char* buff, size_t buffLen)
{
- char* ifname;
- int len = 0;
-
if (!buff || buffLen == 0) {
- return -1;
+ return 0;
}
pthread_once(&_res_cache_once, _res_cache_init);
pthread_mutex_lock(&_res_cache_list_lock);
- ifname = _get_default_iface_locked(); // never null, but may be empty
+ char* ifname = _get_default_iface_locked(); // never null, but may be empty
// if default interface not set. Get first cache with an interface
if (ifname[0] == '\0') {
ifname = _find_any_iface_name_locked(); // may be null
}
+ size_t len = 0;
// if we got the default iface or if (no-default) the find_any call gave an answer
if (ifname) {
len = strlen(ifname);
@@ -2447,28 +2445,32 @@
return len;
}
-int
+void
_resolv_populate_res_for_iface(res_state statp)
{
- int nserv;
- struct resolv_cache_info* info = NULL;
+ if (statp == NULL) {
+ return;
+ }
- if (statp) {
+ if (statp->iface[0] == '\0') { // no interface set assign default
+ size_t if_len = _resolv_get_default_iface(statp->iface, sizeof(statp->iface));
+ if (if_len + 1 > sizeof(statp->iface)) {
+ XLOG("%s: INTERNAL_ERROR: can't fit interface name into statp->iface.\n", __FUNCTION__);
+ return;
+ }
+ if (if_len == 0) {
+ XLOG("%s: INTERNAL_ERROR: can't find any suitable interfaces.\n", __FUNCTION__);
+ return;
+ }
+ }
+
+ pthread_once(&_res_cache_once, _res_cache_init);
+ pthread_mutex_lock(&_res_cache_list_lock);
+
+ struct resolv_cache_info* info = _find_cache_info_locked(statp->iface);
+ if (info != NULL) {
+ int nserv;
struct addrinfo* ai;
-
- if (statp->iface[0] == '\0') { // no interface set assign default
- _resolv_get_default_iface(statp->iface, sizeof(statp->iface));
- }
-
- pthread_once(&_res_cache_once, _res_cache_init);
- pthread_mutex_lock(&_res_cache_list_lock);
- info = _find_cache_info_locked(statp->iface);
-
- if (info == NULL) {
- pthread_mutex_unlock(&_res_cache_list_lock);
- return 0;
- }
-
XLOG("_resolv_populate_res_for_iface: %s\n", statp->iface);
for (nserv = 0; nserv < MAXNS; nserv++) {
ai = info->nsaddrinfo[nserv];
@@ -2502,8 +2504,6 @@
while (pp < statp->dnsrch + MAXDNSRCH && *p != -1) {
*pp++ = &statp->defdname + *p++;
}
-
- pthread_mutex_unlock(&_res_cache_list_lock);
}
- return nserv;
+ pthread_mutex_unlock(&_res_cache_list_lock);
}
diff --git a/libc/private/resolv_cache.h b/libc/private/resolv_cache.h
index d70857d..68a1180 100644
--- a/libc/private/resolv_cache.h
+++ b/libc/private/resolv_cache.h
@@ -28,6 +28,7 @@
#ifndef _RESOLV_CACHE_H_
#define _RESOLV_CACHE_H_
+#include <stddef.h>
#include <sys/cdefs.h>
struct __res_state;
@@ -77,16 +78,17 @@
__LIBC_HIDDEN__
extern struct in_addr* _resolv_get_addr_of_iface(const char* ifname);
-/* Copy the name of the default interface to provided buffer.
- * Return length of buffer on success on failure -1 is returned */
+/* Copy the name of the default interface to the provided buffer.
+ * Returns the string length of the default interface,
+ * be that less or more than the buffLen, or 0 if nothing had been written */
__LIBC_HIDDEN__
-extern int _resolv_get_default_iface(char* buff, int buffLen);
+ extern size_t _resolv_get_default_iface(char* buff, size_t buffLen);
/* sets the name server addresses to the provided res_state structure. The
* name servers are retrieved from the cache which is associated
* with the interface to which the res_state structure is associated */
__LIBC_HIDDEN__
-extern int _resolv_populate_res_for_iface(struct __res_state* statp);
+extern void _resolv_populate_res_for_iface(struct __res_state* statp);
typedef enum {
RESOLV_CACHE_UNSUPPORTED, /* the cache can't handle that kind of queries */
diff --git a/libc/private/resolv_iface.h b/libc/private/resolv_iface.h
index bf5abad..789d997 100644
--- a/libc/private/resolv_iface.h
+++ b/libc/private/resolv_iface.h
@@ -48,7 +48,7 @@
extern void _resolv_set_default_iface(const char* ifname);
/* set name servers for an interface */
-extern void _resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers,
+extern void _resolv_set_nameservers_for_iface(const char* ifname, const char** servers, int numservers,
const char *domains);
/* tell resolver of the address of an interface */