am 6519756b: Merge "DO NOT MERGE Cherry-pick of 0ee092fb2 from master" into honeycomb
* commit '6519756b23a8b18d06dae53cc3ece32c87146972':
DO NOT MERGE Cherry-pick of 0ee092fb2 from master
diff --git a/libc/arch-x86/bionic/atomics_x86.S b/libc/arch-x86/bionic/atomics_x86.S
index 666e182..e98a391 100644
--- a/libc/arch-x86/bionic/atomics_x86.S
+++ b/libc/arch-x86/bionic/atomics_x86.S
@@ -73,100 +73,3 @@
popl %esi
popl %ebx
ret
-
-/* int __atomic_cmpxchg(int old, int new, volatile int* addr) */
-
-.text
-.globl __atomic_cmpxchg
-.type __atomic_cmpxchg, @function
-.align 4
-__atomic_cmpxchg:
- mov 4(%esp), %eax /* old */
- mov 8(%esp), %ecx /* new */
- mov 12(%esp), %edx /* addr */
- lock cmpxchg %ecx, (%edx)
- jnz 1f
- xor %eax, %eax
- jmp 2f
-1:
- movl $1, %eax
-2:
- ret /* 0 == success, 1 == failure */
-
-
-/* int __atomic_swap(int new, volatile int* addr) */
-
-.text
-.globl __atomic_swap
-.type __atomic_swap, @function
-.align 4
-__atomic_swap:
- mov 4(%esp), %ecx /* new */
- mov 8(%esp), %edx /* addr */
- lock xchg %ecx, (%edx)
- mov %ecx, %eax
- ret
-
-
-/*
- * int __atomic_dec(volatile int* addr)
- *
- * My x86 asm is really rusty.. this is probably suboptimal
- */
-
-.text
-.globl __atomic_dec
-.type __atomic_dec, @function
-.align 4
-__atomic_dec:
- pushl %ebx
- pushl %esi
- movl 12(%esp), %ebx /* addr */
-
-1:
- movl (%ebx), %esi /* old = *addr */
- movl %esi, %edx
- subl $1, %edx /* new = old - 1 */
-
- pushl %ebx
- pushl %edx
- pushl %esi
- call __atomic_cmpxchg
- addl $12, %esp
- test %eax, %eax
- jnz 1b
-
- movl %esi, %eax /* return old */
- popl %esi
- popl %ebx
- ret
-
-
-.text
-/* int __atomic_inc(volatile int* addr) */
-.globl __atomic_inc
-.type __atomic_inc, @function
-.align 4
-__atomic_inc:
- pushl %ebx
- pushl %esi
- movl 12(%esp), %ebx /* addr */
-
-1:
- movl (%ebx), %esi /* old = *addr */
- movl %esi, %edx
- addl $1, %edx /* new = old + 1 */
-
- pushl %ebx
- pushl %edx
- pushl %esi
- call __atomic_cmpxchg
- addl $12, %esp
- test %eax, %eax
- jnz 1b
-
- movl %esi, %eax /* return old */
- popl %esi
- popl %ebx
- ret
-
diff --git a/libc/arch-x86/bionic/clone.S b/libc/arch-x86/bionic/clone.S
index 44fce1e..b9b0957 100644
--- a/libc/arch-x86/bionic/clone.S
+++ b/libc/arch-x86/bionic/clone.S
@@ -20,8 +20,7 @@
movl %eax, -12(%ecx)
movl 24(%esp), %eax
movl %eax, -8(%ecx)
- lea (%ecx), %eax
- movl %eax, -4(%ecx)
+ movl %ecx, -4(%ecx)
movl $__NR_clone, %eax
int $0x80
diff --git a/libc/arch-x86/include/sys/atomics.h b/libc/arch-x86/include/sys/atomics.h
new file mode 100644
index 0000000..7aed3ae
--- /dev/null
+++ b/libc/arch-x86/include/sys/atomics.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 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 _SYS_ATOMICS_H
+#define _SYS_ATOMICS_H
+
+#include <sys/cdefs.h>
+#include <sys/time.h>
+
+__BEGIN_DECLS
+
+static inline __attribute__((always_inline)) int
+__atomic_cmpxchg(int old, int _new, volatile int *ptr)
+{
+ return !__sync_bool_compare_and_swap (ptr, old, _new);
+}
+
+static inline __attribute__((always_inline)) int
+__atomic_swap(int _new, volatile int *ptr)
+{
+ return __sync_lock_test_and_set(ptr, _new);
+}
+
+static inline __attribute__((always_inline)) int
+__atomic_dec(volatile int *ptr)
+{
+ return __sync_fetch_and_sub (ptr, 1);
+}
+
+static inline __attribute__((always_inline)) int
+__atomic_inc(volatile int *ptr)
+{
+ return __sync_fetch_and_add (ptr, 1);
+}
+
+int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout);
+int __futex_wake(volatile void *ftx, int count);
+
+__END_DECLS
+
+#endif /* _SYS_ATOMICS_H */
diff --git a/libc/kernel/common/linux/if_arp.h b/libc/kernel/common/linux/if_arp.h
index a3df6c8..d8a4001 100644
--- a/libc/kernel/common/linux/if_arp.h
+++ b/libc/kernel/common/linux/if_arp.h
@@ -77,6 +77,7 @@
#define ARPHRD_PHONET 820
#define ARPHRD_PHONET_PIPE 821
+#define ARPHRD_CAIF 822
#define ARPHRD_VOID 0xFFFF
#define ARPHRD_NONE 0xFFFE
@@ -111,8 +112,7 @@
#define ATF_NETMASK 0x20
#define ATF_DONTPUB 0x40
-struct arphdr
-{
+struct arphdr {
__be16 ar_hrd;
__be16 ar_pro;
unsigned char ar_hln;
@@ -122,3 +122,4 @@
};
#endif
+
diff --git a/libc/kernel/common/linux/if_link.h b/libc/kernel/common/linux/if_link.h
index e9d77d4..4b83760 100644
--- a/libc/kernel/common/linux/if_link.h
+++ b/libc/kernel/common/linux/if_link.h
@@ -15,8 +15,7 @@
#include <linux/types.h>
#include <linux/netlink.h>
-struct rtnl_link_stats
-{
+struct rtnl_link_stats {
__u32 rx_packets;
__u32 tx_packets;
__u32 rx_bytes;
@@ -45,8 +44,36 @@
__u32 tx_compressed;
};
-struct rtnl_link_ifmap
-{
+struct rtnl_link_stats64 {
+ __u64 rx_packets;
+ __u64 tx_packets;
+ __u64 rx_bytes;
+ __u64 tx_bytes;
+ __u64 rx_errors;
+ __u64 tx_errors;
+ __u64 rx_dropped;
+ __u64 tx_dropped;
+ __u64 multicast;
+ __u64 collisions;
+
+ __u64 rx_length_errors;
+ __u64 rx_over_errors;
+ __u64 rx_crc_errors;
+ __u64 rx_frame_errors;
+ __u64 rx_fifo_errors;
+ __u64 rx_missed_errors;
+
+ __u64 tx_aborted_errors;
+ __u64 tx_carrier_errors;
+ __u64 tx_fifo_errors;
+ __u64 tx_heartbeat_errors;
+ __u64 tx_window_errors;
+
+ __u64 rx_compressed;
+ __u64 tx_compressed;
+};
+
+struct rtnl_link_ifmap {
__u64 mem_start;
__u64 mem_end;
__u64 base_addr;
@@ -55,8 +82,7 @@
__u8 port;
};
-enum
-{
+enum {
IFLA_UNSPEC,
IFLA_ADDRESS,
IFLA_BROADCAST,
@@ -87,6 +113,11 @@
#define IFLA_LINKINFO IFLA_LINKINFO
IFLA_NET_NS_PID,
IFLA_IFALIAS,
+ IFLA_NUM_VF,
+ IFLA_VFINFO_LIST,
+ IFLA_STATS64,
+ IFLA_VF_PORTS,
+ IFLA_PORT_SELF,
__IFLA_MAX
};
@@ -95,8 +126,7 @@
#define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
-enum
-{
+enum {
IFLA_INET6_UNSPEC,
IFLA_INET6_FLAGS,
IFLA_INET6_CONF,
@@ -109,16 +139,14 @@
#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
-struct ifla_cacheinfo
-{
+struct ifla_cacheinfo {
__u32 max_reasm_len;
__u32 tstamp;
__u32 reachable_time;
__u32 retrans_time;
};
-enum
-{
+enum {
IFLA_INFO_UNSPEC,
IFLA_INFO_KIND,
IFLA_INFO_DATA,
@@ -128,8 +156,7 @@
#define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1)
-enum
-{
+enum {
IFLA_VLAN_UNSPEC,
IFLA_VLAN_ID,
IFLA_VLAN_FLAGS,
@@ -145,8 +172,7 @@
__u32 mask;
};
-enum
-{
+enum {
IFLA_VLAN_QOS_UNSPEC,
IFLA_VLAN_QOS_MAPPING,
__IFLA_VLAN_QOS_MAX
@@ -154,10 +180,123 @@
#define IFLA_VLAN_QOS_MAX (__IFLA_VLAN_QOS_MAX - 1)
-struct ifla_vlan_qos_mapping
-{
+struct ifla_vlan_qos_mapping {
__u32 from;
__u32 to;
};
+enum {
+ IFLA_MACVLAN_UNSPEC,
+ IFLA_MACVLAN_MODE,
+ __IFLA_MACVLAN_MAX,
+};
+
+#define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
+
+enum macvlan_mode {
+ MACVLAN_MODE_PRIVATE = 1,
+ MACVLAN_MODE_VEPA = 2,
+ MACVLAN_MODE_BRIDGE = 4,
+};
+
+enum {
+ IFLA_VF_INFO_UNSPEC,
+ IFLA_VF_INFO,
+ __IFLA_VF_INFO_MAX,
+};
+
+#define IFLA_VF_INFO_MAX (__IFLA_VF_INFO_MAX - 1)
+
+enum {
+ IFLA_VF_UNSPEC,
+ IFLA_VF_MAC,
+ IFLA_VF_VLAN,
+ IFLA_VF_TX_RATE,
+ __IFLA_VF_MAX,
+};
+
+#define IFLA_VF_MAX (__IFLA_VF_MAX - 1)
+
+struct ifla_vf_mac {
+ __u32 vf;
+ __u8 mac[32];
+};
+
+struct ifla_vf_vlan {
+ __u32 vf;
+ __u32 vlan;
+ __u32 qos;
+};
+
+struct ifla_vf_tx_rate {
+ __u32 vf;
+ __u32 rate;
+};
+
+struct ifla_vf_info {
+ __u32 vf;
+ __u8 mac[32];
+ __u32 vlan;
+ __u32 qos;
+ __u32 tx_rate;
+};
+
+enum {
+ IFLA_VF_PORT_UNSPEC,
+ IFLA_VF_PORT,
+ __IFLA_VF_PORT_MAX,
+};
+
+#define IFLA_VF_PORT_MAX (__IFLA_VF_PORT_MAX - 1)
+
+enum {
+ IFLA_PORT_UNSPEC,
+ IFLA_PORT_VF,
+ IFLA_PORT_PROFILE,
+ IFLA_PORT_VSI_TYPE,
+ IFLA_PORT_INSTANCE_UUID,
+ IFLA_PORT_HOST_UUID,
+ IFLA_PORT_REQUEST,
+ IFLA_PORT_RESPONSE,
+ __IFLA_PORT_MAX,
+};
+
+#define IFLA_PORT_MAX (__IFLA_PORT_MAX - 1)
+
+#define PORT_PROFILE_MAX 40
+#define PORT_UUID_MAX 16
+#define PORT_SELF_VF -1
+
+enum {
+ PORT_REQUEST_PREASSOCIATE = 0,
+ PORT_REQUEST_PREASSOCIATE_RR,
+ PORT_REQUEST_ASSOCIATE,
+ PORT_REQUEST_DISASSOCIATE,
+};
+
+enum {
+ PORT_VDP_RESPONSE_SUCCESS = 0,
+ PORT_VDP_RESPONSE_INVALID_FORMAT,
+ PORT_VDP_RESPONSE_INSUFFICIENT_RESOURCES,
+ PORT_VDP_RESPONSE_UNUSED_VTID,
+ PORT_VDP_RESPONSE_VTID_VIOLATION,
+ PORT_VDP_RESPONSE_VTID_VERSION_VIOALTION,
+ PORT_VDP_RESPONSE_OUT_OF_SYNC,
+
+ PORT_PROFILE_RESPONSE_SUCCESS = 0x100,
+ PORT_PROFILE_RESPONSE_INPROGRESS,
+ PORT_PROFILE_RESPONSE_INVALID,
+ PORT_PROFILE_RESPONSE_BADSTATE,
+ PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES,
+ PORT_PROFILE_RESPONSE_ERROR,
+};
+
+struct ifla_port_vsi {
+ __u8 vsi_mgr_id;
+ __u8 vsi_type_id[3];
+ __u8 vsi_type_version;
+ __u8 pad[3];
+};
+
#endif
+
diff --git a/libc/kernel/common/linux/if_tun.h b/libc/kernel/common/linux/if_tun.h
index c5db4e0..9ed49f1 100644
--- a/libc/kernel/common/linux/if_tun.h
+++ b/libc/kernel/common/linux/if_tun.h
@@ -12,6 +12,10 @@
#ifndef __IF_TUN_H
#define __IF_TUN_H
+#include <linux/types.h>
+#include <linux/if_ether.h>
+#include <linux/filter.h>
+
#define TUN_READQ_SIZE 500
#define TUN_TUN_DEV 0x0001
@@ -23,6 +27,7 @@
#define TUN_NO_PI 0x0040
#define TUN_ONE_QUEUE 0x0080
#define TUN_PERSIST 0x0100
+#define TUN_VNET_HDR 0x0200
#define TUNSETNOCSUM _IOW('T', 200, int)
#define TUNSETDEBUG _IOW('T', 201, int)
@@ -30,16 +35,43 @@
#define TUNSETPERSIST _IOW('T', 203, int)
#define TUNSETOWNER _IOW('T', 204, int)
#define TUNSETLINK _IOW('T', 205, int)
+#define TUNSETGROUP _IOW('T', 206, int)
+#define TUNGETFEATURES _IOR('T', 207, unsigned int)
+#define TUNSETOFFLOAD _IOW('T', 208, unsigned int)
+#define TUNSETTXFILTER _IOW('T', 209, unsigned int)
+#define TUNGETIFF _IOR('T', 210, unsigned int)
+#define TUNGETSNDBUF _IOR('T', 211, int)
+#define TUNSETSNDBUF _IOW('T', 212, int)
+#define TUNATTACHFILTER _IOW('T', 213, struct sock_fprog)
+#define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
+#define TUNGETVNETHDRSZ _IOR('T', 215, int)
+#define TUNSETVNETHDRSZ _IOW('T', 216, int)
#define IFF_TUN 0x0001
#define IFF_TAP 0x0002
#define IFF_NO_PI 0x1000
#define IFF_ONE_QUEUE 0x2000
+#define IFF_VNET_HDR 0x4000
+#define IFF_TUN_EXCL 0x8000
-struct tun_pi {
- unsigned short flags;
- unsigned short proto;
-};
+#define TUN_F_CSUM 0x01
+#define TUN_F_TSO4 0x02
+#define TUN_F_TSO6 0x04
+#define TUN_F_TSO_ECN 0x08
+#define TUN_F_UFO 0x10
+
#define TUN_PKT_STRIP 0x0001
+struct tun_pi {
+ __u16 flags;
+ __be16 proto;
+};
+
+#define TUN_FLT_ALLMULTI 0x0001
+struct tun_filter {
+ __u16 flags;
+ __u16 count;
+ __u8 addr[0][ETH_ALEN];
+};
#endif
+
diff --git a/libc/kernel/common/linux/rtnetlink.h b/libc/kernel/common/linux/rtnetlink.h
index e305505..bbd991a 100644
--- a/libc/kernel/common/linux/rtnetlink.h
+++ b/libc/kernel/common/linux/rtnetlink.h
@@ -18,6 +18,10 @@
#include <linux/if_addr.h>
#include <linux/neighbour.h>
+#define RTNL_FAMILY_IPMR 128
+#define RTNL_FAMILY_IP6MR 129
+#define RTNL_FAMILY_MAX 129
+
enum {
RTM_BASE = 16,
#define RTM_BASE RTM_BASE
@@ -126,8 +130,7 @@
#define RTM_NR_FAMILIES (RTM_NR_MSGTYPES >> 2)
#define RTM_FAM(cmd) (((cmd) - RTM_BASE) >> 2)
-struct rtattr
-{
+struct rtattr {
unsigned short rta_len;
unsigned short rta_type;
};
@@ -141,8 +144,7 @@
#define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
#define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
-struct rtmsg
-{
+struct rtmsg {
unsigned char rtm_family;
unsigned char rtm_dst_len;
unsigned char rtm_src_len;
@@ -156,8 +158,7 @@
unsigned rtm_flags;
};
-enum
-{
+enum {
RTN_UNSPEC,
RTN_UNICAST,
RTN_LOCAL,
@@ -191,8 +192,7 @@
#define RTPROT_NTK 15
#define RTPROT_DHCP 16
-enum rt_scope_t
-{
+enum rt_scope_t {
RT_SCOPE_UNIVERSE=0,
RT_SCOPE_SITE=200,
@@ -206,8 +206,7 @@
#define RTM_F_EQUALIZE 0x400
#define RTM_F_PREFIX 0x800
-enum rt_class_t
-{
+enum rt_class_t {
RT_TABLE_UNSPEC=0,
RT_TABLE_COMPAT=252,
@@ -217,8 +216,7 @@
RT_TABLE_MAX=0xFFFFFFFF
};
-enum rtattr_type_t
-{
+enum rtattr_type_t {
RTA_UNSPEC,
RTA_DST,
RTA_SRC,
@@ -235,6 +233,7 @@
RTA_SESSION,
RTA_MP_ALGO,
RTA_TABLE,
+ RTA_MARK,
__RTA_MAX
};
@@ -243,8 +242,7 @@
#define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
#define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
-struct rtnexthop
-{
+struct rtnexthop {
unsigned short rtnh_len;
unsigned char rtnh_flags;
unsigned char rtnh_hops;
@@ -263,8 +261,7 @@
#define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
#define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
-struct rta_cacheinfo
-{
+struct rta_cacheinfo {
__u32 rta_clntref;
__u32 rta_lastuse;
__s32 rta_expires;
@@ -277,8 +274,7 @@
__u32 rta_tsage;
};
-enum
-{
+enum {
RTAX_UNSPEC,
#define RTAX_UNSPEC RTAX_UNSPEC
RTAX_LOCK,
@@ -307,6 +303,8 @@
#define RTAX_FEATURES RTAX_FEATURES
RTAX_RTO_MIN,
#define RTAX_RTO_MIN RTAX_RTO_MIN
+ RTAX_INITRWND,
+#define RTAX_INITRWND RTAX_INITRWND
__RTAX_MAX
};
@@ -317,8 +315,7 @@
#define RTAX_FEATURE_TIMESTAMP 0x00000004
#define RTAX_FEATURE_ALLFRAG 0x00000008
-struct rta_session
-{
+struct rta_session {
__u8 proto;
__u8 pad1;
__u16 pad2;
@@ -339,13 +336,11 @@
} u;
};
-struct rtgenmsg
-{
+struct rtgenmsg {
unsigned char rtgen_family;
};
-struct ifinfomsg
-{
+struct ifinfomsg {
unsigned char ifi_family;
unsigned char __ifi_pad;
unsigned short ifi_type;
@@ -354,8 +349,7 @@
unsigned ifi_change;
};
-struct prefixmsg
-{
+struct prefixmsg {
unsigned char prefix_family;
unsigned char prefix_pad1;
unsigned short prefix_pad2;
@@ -376,14 +370,12 @@
#define PREFIX_MAX (__PREFIX_MAX - 1)
-struct prefix_cacheinfo
-{
+struct prefix_cacheinfo {
__u32 preferred_time;
__u32 valid_time;
};
-struct tcmsg
-{
+struct tcmsg {
unsigned char tcm_family;
unsigned char tcm__pad1;
unsigned short tcm__pad2;
@@ -393,8 +385,7 @@
__u32 tcm_info;
};
-enum
-{
+enum {
TCA_UNSPEC,
TCA_KIND,
TCA_OPTIONS,
@@ -412,8 +403,7 @@
#define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
#define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
-struct nduseroptmsg
-{
+struct nduseroptmsg {
unsigned char nduseropt_family;
unsigned char nduseropt_pad1;
unsigned short nduseropt_opts_len;
@@ -425,8 +415,7 @@
};
-enum
-{
+enum {
NDUSEROPT_UNSPEC,
NDUSEROPT_SRCADDR,
__NDUSEROPT_MAX
@@ -503,8 +492,7 @@
};
#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
-struct tcamsg
-{
+struct tcamsg {
unsigned char tca_family;
unsigned char tca__pad1;
unsigned short tca__pad2;
@@ -515,3 +503,4 @@
#define TCAA_MAX 1
#endif
+
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c
index 84194c2..f0c51ab 100644
--- a/libc/netbsd/resolv/res_cache.c
+++ b/libc/netbsd/resolv/res_cache.c
@@ -32,12 +32,15 @@
#include <time.h>
#include "pthread.h"
+#include <errno.h>
+#include "arpa_nameser.h"
+
/* This code implements a small and *simple* DNS resolver cache.
*
- * It is only used to cache DNS answers for a maximum of CONFIG_SECONDS seconds
- * in order to reduce DNS traffic. It is not supposed to be a full DNS cache,
- * since we plan to implement that in the future in a dedicated process running
- * on the system.
+ * It is only used to cache DNS answers for a time defined by the smallest TTL
+ * among the answer records in order to reduce DNS traffic. It is not supposed
+ * to be a full DNS cache, since we plan to implement that in the future in a
+ * dedicated process running on the system.
*
* Note that its design is kept simple very intentionally, i.e.:
*
@@ -47,9 +50,8 @@
* (this means that two similar queries that encode the DNS name
* differently will be treated distinctly).
*
- * - the TTLs of answer RRs are ignored. our DNS resolver library does not use
- * them anyway, but it means that records with a TTL smaller than
- * CONFIG_SECONDS will be kept in the cache anyway.
+ * the smallest TTL value among the answer records are used as the time
+ * to keep an answer in the cache.
*
* this is bad, but we absolutely want to avoid parsing the answer packets
* (and should be solved by the later full DNS cache process).
@@ -141,6 +143,7 @@
/* set to 1 to debug query data */
#define DEBUG_DATA 0
+#undef XLOG
#if DEBUG
# include <logd.h>
# define XLOG(...) \
@@ -149,6 +152,9 @@
#include <stdio.h>
#include <stdarg.h>
+#include <arpa/inet.h>
+#include "resolv_private.h"
+
/** BOUNDED BUFFER FORMATTING
**/
@@ -987,10 +993,50 @@
int querylen;
const uint8_t* answer;
int answerlen;
- time_t when; /* time_t when entry was added to table */
- int id; /* for debugging purpose */
+ time_t expires; /* time_t when the entry isn't valid any more */
+ int id; /* for debugging purpose */
} Entry;
+/**
+ * Parse the answer records and find the smallest
+ * TTL among the answer records.
+ *
+ * The returned TTL is the number of seconds to
+ * keep the answer in the cache.
+ *
+ * In case of parse error zero (0) is returned which
+ * indicates that the answer shall not be cached.
+ */
+static u_long
+answer_getTTL(const void* answer, int answerlen)
+{
+ ns_msg handle;
+ int ancount, n;
+ u_long result, ttl;
+ ns_rr rr;
+
+ result = 0;
+ if (ns_initparse(answer, answerlen, &handle) >= 0) {
+ // get number of answer records
+ ancount = ns_msg_count(handle, ns_s_an);
+ for (n = 0; n < ancount; n++) {
+ if (ns_parserr(&handle, ns_s_an, n, &rr) == 0) {
+ ttl = ns_rr_ttl(rr);
+ if (n == 0 || ttl < result) {
+ result = ttl;
+ }
+ } else {
+ XLOG("ns_parserr failed ancount no = %d. errno = %s\n", n, strerror(errno));
+ }
+ }
+ } else {
+ XLOG("ns_parserr failed. %s\n", strerror(errno));
+ }
+
+ XLOG("TTL = %d\n", result);
+
+ return result;
+}
static void
entry_free( Entry* e )
@@ -1072,8 +1118,6 @@
memcpy( (char*)e->answer, answer, e->answerlen );
- e->when = _time_now();
-
return e;
}
@@ -1183,12 +1227,47 @@
XLOG("%s", temp);
}
+
+static void
+_dump_answer(const void* answer, int answerlen)
+{
+ res_state statep;
+ FILE* fp;
+ char* buf;
+ int fileLen;
+
+ fp = fopen("/data/reslog.txt", "w+");
+ if (fp != NULL) {
+ statep = __res_get_state();
+
+ res_pquery(statep, answer, answerlen, fp);
+
+ //Get file length
+ fseek(fp, 0, SEEK_END);
+ fileLen=ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+ buf = (char *)malloc(fileLen+1);
+ if (buf != NULL) {
+ //Read file contents into buffer
+ fread(buf, fileLen, 1, fp);
+ XLOG("%s\n", buf);
+ free(buf);
+ }
+ fclose(fp);
+ remove("/data/reslog.txt");
+ }
+ else {
+ XLOG("_dump_answer: can't open file\n");
+ }
+}
#endif
#if DEBUG
# define XLOG_QUERY(q,len) _dump_query((q), (len))
+# define XLOG_ANSWER(a, len) _dump_answer((a), (len))
#else
# define XLOG_QUERY(q,len) ((void)0)
+# define XLOG_ANSWER(a,len) ((void)0)
#endif
/* This function tries to find a key within the hash table
@@ -1322,7 +1401,7 @@
now = _time_now();
/* remove stale entries here */
- if ( (unsigned)(now - e->when) >= CONFIG_SECONDS ) {
+ if (now >= e->expires) {
XLOG( " NOT IN CACHE (STALE ENTRY %p DISCARDED)", *lookup );
_cache_remove_p(cache, lookup);
goto Exit;
@@ -1363,6 +1442,7 @@
Entry key[1];
Entry* e;
Entry** lookup;
+ u_long ttl;
/* don't assume that the query has already been cached
*/
@@ -1375,6 +1455,7 @@
XLOG( "%s: query:", __FUNCTION__ );
XLOG_QUERY(query,querylen);
+ XLOG_ANSWER(answer, answerlen);
#if DEBUG_DATA
XLOG( "answer:");
XLOG_BYTES(answer,answerlen);
@@ -1401,9 +1482,13 @@
}
}
- e = entry_alloc( key, answer, answerlen );
- if (e != NULL) {
- _cache_add_p(cache, lookup, e);
+ ttl = answer_getTTL(answer, answerlen);
+ if (ttl > 0) {
+ e = entry_alloc(key, answer, answerlen);
+ if (e != NULL) {
+ e->expires = ttl + _time_now();
+ _cache_add_p(cache, lookup, e);
+ }
}
#if DEBUG
_cache_dump_mru(cache);
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index 98ecfc9..072104b 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -26,6 +26,7 @@
* SUCH DAMAGE.
*/
#include <string.h>
+#include <strings.h>
void *memmove(void *dst, const void *src, size_t n)
{
@@ -37,39 +38,7 @@
if (__builtin_expect((q < p) || ((size_t)(q - p) >= n), 1)) {
return memcpy(dst, src, n);
} else {
-#define PRELOAD_DISTANCE 64
- /* a semi-optimized memmove(). we're preloading the src and dst buffers
- * as we go */
- size_t c0, c1, i;
- p += n;
- q += n;
- /* note: we preload the destination as well, because the 1-byte at a time
- * copy below doesn't take advantage of the write-buffer, we need
- * to use the cache instead as a poor man's write-combiner */
- __builtin_prefetch(p-1);
- __builtin_prefetch(q-1);
- if (PRELOAD_DISTANCE > 32) {
- __builtin_prefetch(p-(32+1));
- __builtin_prefetch(q-(32+1));
- }
- /* do the prefetech as soon as possible, prevent the compiler to
- * reorder the instructions above the prefetch */
- asm volatile("":::"memory");
- c0 = n & 0x1F; /* cache-line is 32 bytes */
- c1 = n >> 5;
- while ( c1-- ) {
- /* ARMv6 can have up to 3 memory access outstanding */
- __builtin_prefetch(p - (PRELOAD_DISTANCE+1));
- __builtin_prefetch(q - (PRELOAD_DISTANCE+1));
- asm volatile("":::"memory");
- for (i=0 ; i<32 ; i++) {
- *--q = *--p;
- }
- }
- while ( c0-- ) {
- *--q = *--p;
- }
+ bcopy(src, dst, n);
+ return dst;
}
-
- return dst;
}
diff --git a/libthread_db/include/sys/procfs.h b/libthread_db/include/sys/procfs.h
new file mode 100644
index 0000000..0ae7a0b
--- /dev/null
+++ b/libthread_db/include/sys/procfs.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2006 The Android Open Source Project
+ */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H
+
+#include <sys/types.h>
+
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+typedef pid_t lwpid_t;
+typedef void *psaddr_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libthread_db/include/thread_db.h b/libthread_db/include/thread_db.h
index 1b36cb2..6ff968f 100644
--- a/libthread_db/include/thread_db.h
+++ b/libthread_db/include/thread_db.h
@@ -9,9 +9,7 @@
#include <signal.h>
#include <stdint.h>
#include <sys/types.h>
-
-typedef void *psaddr_t;
-typedef pid_t lwpid_t;
+#include <sys/procfs.h>
#define TD_THR_ANY_USER_FLAGS 0xffffffff
#define TD_THR_LOWEST_PRIORITY -20