Merge "libc: remove private declarations from <time.h> and <resolv.h>"
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 800726a..82f542c 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -253,6 +253,7 @@
 int     delete_module(const char*, unsigned int)   129
 int     klogctl:syslog(int, char *, int)   103
 int     sysinfo(struct sysinfo *)  116
+int     personality(unsigned long)  136
 
 # futex
 int	futex(void *, int, int, void *, void *, int) 240
diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk
index 1f2a1cd..b7a4532 100644
--- a/libc/arch-arm/syscalls.mk
+++ b/libc/arch-arm/syscalls.mk
@@ -170,6 +170,7 @@
 syscall_src += arch-arm/syscalls/delete_module.S
 syscall_src += arch-arm/syscalls/klogctl.S
 syscall_src += arch-arm/syscalls/sysinfo.S
+syscall_src += arch-arm/syscalls/personality.S
 syscall_src += arch-arm/syscalls/futex.S
 syscall_src += arch-arm/syscalls/epoll_create.S
 syscall_src += arch-arm/syscalls/epoll_ctl.S
diff --git a/libc/arch-arm/syscalls/personality.S b/libc/arch-arm/syscalls/personality.S
new file mode 100644
index 0000000..17ac686
--- /dev/null
+++ b/libc/arch-arm/syscalls/personality.S
@@ -0,0 +1,14 @@
+/* autogenerated by gensyscalls.py */
+#include <machine/asm.h>
+#include <sys/linux-syscalls.h>
+
+ENTRY(personality)
+    .save   {r4, r7}
+    stmfd   sp!, {r4, r7}
+    ldr     r7, =__NR_personality
+    swi     #0
+    ldmfd   sp!, {r4, r7}
+    movs    r0, r0
+    bxpl    lr
+    b       __set_syscall_errno
+END(personality)
diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk
index e6fba58..36cc594 100644
--- a/libc/arch-sh/syscalls.mk
+++ b/libc/arch-sh/syscalls.mk
@@ -160,6 +160,7 @@
 syscall_src += arch-sh/syscalls/delete_module.S
 syscall_src += arch-sh/syscalls/klogctl.S
 syscall_src += arch-sh/syscalls/sysinfo.S
+syscall_src += arch-sh/syscalls/personality.S
 syscall_src += arch-sh/syscalls/futex.S
 syscall_src += arch-sh/syscalls/epoll_create.S
 syscall_src += arch-sh/syscalls/epoll_ctl.S
diff --git a/libc/arch-sh/syscalls/personality.S b/libc/arch-sh/syscalls/personality.S
new file mode 100644
index 0000000..efc2ea3
--- /dev/null
+++ b/libc/arch-sh/syscalls/personality.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type personality, @function
+    .globl personality
+    .align 4
+
+personality:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_personality_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_personality_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_personality
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk
index f263470..03b4cbd 100644
--- a/libc/arch-x86/syscalls.mk
+++ b/libc/arch-x86/syscalls.mk
@@ -174,6 +174,7 @@
 syscall_src += arch-x86/syscalls/delete_module.S
 syscall_src += arch-x86/syscalls/klogctl.S
 syscall_src += arch-x86/syscalls/sysinfo.S
+syscall_src += arch-x86/syscalls/personality.S
 syscall_src += arch-x86/syscalls/futex.S
 syscall_src += arch-x86/syscalls/epoll_create.S
 syscall_src += arch-x86/syscalls/epoll_ctl.S
diff --git a/libc/arch-x86/syscalls/personality.S b/libc/arch-x86/syscalls/personality.S
new file mode 100644
index 0000000..af4f912
--- /dev/null
+++ b/libc/arch-x86/syscalls/personality.S
@@ -0,0 +1,23 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type personality, @function
+    .globl personality
+    .align 4
+
+personality:
+    pushl   %ebx
+    mov     8(%esp), %ebx
+    movl    $__NR_personality, %eax
+    int     $0x80
+    cmpl    $-129, %eax
+    jb      1f
+    negl    %eax
+    pushl   %eax
+    call    __set_errno
+    addl    $4, %esp
+    orl     $-1, %eax
+1:
+    popl    %ebx
+    ret
diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h
index 5361ace..e6d7dfb 100644
--- a/libc/include/sys/linux-syscalls.h
+++ b/libc/include/sys/linux-syscalls.h
@@ -133,6 +133,7 @@
 #define __NR_delete_module                (__NR_SYSCALL_BASE + 129)
 #define __NR_syslog                       (__NR_SYSCALL_BASE + 103)
 #define __NR_sysinfo                      (__NR_SYSCALL_BASE + 116)
+#define __NR_personality                  (__NR_SYSCALL_BASE + 136)
 #define __NR_futex                        (__NR_SYSCALL_BASE + 240)
 #define __NR_poll                         (__NR_SYSCALL_BASE + 168)
 
diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h
deleted file mode 100644
index 867cfe6..0000000
--- a/libc/include/sys/linux-unistd.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/* auto-generated by gensyscalls.py, do not touch */
-#ifndef _BIONIC_LINUX_UNISTD_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void             _exit (int);
-void             _exit_thread (int);
-pid_t            __fork (void);
-pid_t            _waitpid (pid_t, int*, int, struct rusage*);
-int              __waitid (int, pid_t, struct siginfo_t*, int,void*);
-pid_t            __sys_clone (int, void*, int*, void*, int*);
-int              execve (const char*, char* const*, char* const*);
-int              __setuid (uid_t);
-uid_t            getuid (void);
-gid_t            getgid (void);
-uid_t            geteuid (void);
-gid_t            getegid (void);
-uid_t            getresuid (void);
-gid_t            getresgid (void);
-pid_t            gettid (void);
-ssize_t          readahead (int, off64_t, size_t);
-int              getgroups (int, gid_t *);
-pid_t            getpgid (pid_t);
-pid_t            getppid (void);
-pid_t            setsid (void);
-int              setgid (gid_t);
-int              seteuid (uid_t);
-int              __setreuid (uid_t, uid_t);
-int              __setresuid (uid_t, uid_t, uid_t);
-int              setresgid (gid_t, gid_t, gid_t);
-void*            __brk (void*);
-int              kill (pid_t, int);
-int              tkill (pid_t tid, int sig);
-int              tgkill (pid_t tgid, pid_t tid, int sig);
-int              __ptrace (int request, int pid, void* addr, void* data);
-int              __set_thread_area (void*  user_desc);
-int              __getpriority (int, int);
-int              setpriority (int, int, int);
-int              setrlimit (int resource, const struct rlimit *rlp);
-int              getrlimit (int resource, struct rlimit *rlp);
-int              getrusage (int who, struct rusage*  r_usage);
-int              setgroups (int, const gid_t *);
-pid_t            getpgrp (void);
-int              setpgid (pid_t, pid_t);
-pid_t            vfork (void);
-int              setregid (gid_t, gid_t);
-int              chroot (const char *);
-int              prctl (int option, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
-int              capget (cap_user_header_t header, cap_user_data_t data);
-int              capset (cap_user_header_t header, const cap_user_data_t data);
-int              sigaltstack (const stack_t*, stack_t*);
-int              acct (const char*  filepath);
-ssize_t          read (int, void*, size_t);
-ssize_t          write (int, const void*, size_t);
-ssize_t          pread64 (int, void *, size_t, off64_t);
-ssize_t          pwrite64 (int, void *, size_t, off64_t);
-int              __open (const char*, int, mode_t);
-int              __openat (int, const char*, int, mode_t);
-int              close (int);
-int              creat (const char*, mode_t);
-off_t            lseek (int, off_t, int);
-int              __llseek (int, unsigned long, unsigned long, loff_t*, int);
-pid_t            getpid (void);
-void *           mmap (void *, size_t, int, int, int, long);
-void *           __mmap2 (void*, size_t, int, int, int, long);
-int              munmap (void *, size_t);
-void *           mremap (void *, size_t, size_t, unsigned long);
-int              msync (const void *, size_t, int);
-int              mprotect (const void *, size_t, int);
-int              madvise (const void *, size_t, int);
-int              mlock (const void *addr, size_t len);
-int              munlock (const void *addr, size_t len);
-int              mincore (void*  start, size_t  length, unsigned char*  vec);
-int              __ioctl (int, int, void *);
-int              readv (int, const struct iovec *, int);
-int              writev (int, const struct iovec *, int);
-int              __fcntl (int, int, void*);
-int              flock (int, int);
-int              fchmod (int, mode_t);
-int              dup (int);
-int              pipe (int *);
-int              pipe2 (int *, int);
-int              dup2 (int, int);
-int              select (int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *);
-int              ftruncate (int, off_t);
-int              ftruncate64 (int, off64_t);
-int              getdents (unsigned int, struct dirent *, unsigned int);
-int              fsync (int);
-int              fdatasync (int);
-int              fchown (int, uid_t, gid_t);
-void             sync (void);
-int              __fcntl64 (int, int, void *);
-int              __fstatfs64 (int, size_t, struct statfs *);
-ssize_t          sendfile (int out_fd, int in_fd, off_t *offset, size_t count);
-int              fstatat (int dirfd, const char *path, struct stat *buf, int flags);
-int              mkdirat (int dirfd, const char *pathname, mode_t mode);
-int              fchownat (int dirfd, const char *path, uid_t owner, gid_t group, int flags);
-int              fchmodat (int dirfd, const char *path, mode_t mode, int flags);
-int              renameat (int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
-int              link (const char*, const char*);
-int              unlink (const char*);
-int              unlinkat (int, const char *, int);
-int              chdir (const char*);
-int              mknod (const char*, mode_t, dev_t);
-int              chmod (const char*,mode_t);
-int              chown (const char *, uid_t, gid_t);
-int              lchown (const char*, uid_t, gid_t);
-int              mount (const char*, const char*, const char*, unsigned long, const void*);
-int              umount (const char*);
-int              umount2 (const char*, int);
-int              fstat (int, struct stat*);
-int              stat (const char *, struct stat *);
-int              lstat (const char *, struct stat *);
-int              mkdir (const char *, mode_t);
-int              readlink (const char *, char *, size_t);
-int              rmdir (const char *);
-int              rename (const char *, const char *);
-int              __getcwd (char * buf, size_t size);
-int              access (const char *, int);
-int              symlink (const char *, const char *);
-int              fchdir (int);
-int              truncate (const char*, off_t);
-int              __statfs64 (const char *, size_t, struct statfs *);
-int              pause (void);
-int              gettimeofday (struct timeval*, struct timezone*);
-int              settimeofday (const struct timeval*, const struct timezone*);
-clock_t          times (struct tms *);
-int              nanosleep (const struct timespec *, struct timespec *);
-int              clock_gettime (clockid_t clk_id, struct timespec *tp);
-int              clock_settime (clockid_t clk_id, const struct timespec *tp);
-int              clock_getres (clockid_t clk_id, struct timespec *res);
-int              clock_nanosleep (const struct timespec *req, struct timespec *rem);
-int              getitimer (int, const struct itimerval *);
-int              setitimer (int, const struct itimerval *, struct itimerval *);
-int              __timer_create (clockid_t clockid, struct sigevent *evp, timer_t *timerid);
-int              __timer_settime (timer_t, int, const struct itimerspec*, struct itimerspec*);
-int              __timer_gettime (timer_t, struct itimerspec*);
-int              __timer_getoverrun (timer_t);
-int              __timer_delete (timer_t);
-int              utimes (const char*, const struct timeval tvp[2]);
-int              utimensat (int, const char *, const struct timespec times[2], int);
-int              sigaction (int, const struct sigaction *, struct sigaction *);
-int              sigprocmask (int, const sigset_t *, sigset_t *);
-int              __sigsuspend (int unused1, int unused2, unsigned mask);
-int              __rt_sigaction (int sig, const struct sigaction *act, struct sigaction *oact, size_t sigsetsize);
-int              __rt_sigprocmask (int  how, const sigset_t *set, sigset_t *oset, size_t sigsetsize);
-int              __rt_sigtimedwait (const sigset_t *set, struct siginfo_t  *info, struct timespec_t  *timeout, size_t  sigset_size);
-int              sigpending (sigset_t *);
-int              socket (int, int, int);
-int              socketpair (int, int, int, int*);
-int              bind (int, struct sockaddr *, int);
-int              connect (int, struct sockaddr *, socklen_t);
-int              listen (int, int);
-int              accept (int, struct sockaddr *, socklen_t *);
-int              getsockname (int, struct sockaddr *, socklen_t *);
-int              getpeername (int, struct sockaddr *, socklen_t *);
-int              sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
-int              recvfrom (int, void *, size_t, unsigned int, struct sockaddr *, socklen_t *);
-int              shutdown (int, int);
-int              setsockopt (int, int, int, const void *, socklen_t);
-int              getsockopt (int, int, int, void *, socklen_t *);
-int              sendmsg (int, const struct msghdr *, unsigned int);
-int              recvmsg (int, struct msghdr *, unsigned int);
-int              socket (int, int, int);
-int              bind (int, struct sockaddr *, int);
-int              connect (int, struct sockaddr *, socklen_t);
-int              listen (int, int);
-int              accept (int, struct sockaddr *, socklen_t *);
-int              getsockname (int, struct sockaddr *, socklen_t *);
-int              getpeername (int, struct sockaddr *, socklen_t *);
-int              socketpair (int, int, int, int*);
-int              sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
-int              recvfrom (int, void *, size_t, unsigned int, struct sockaddr *, socklen_t *);
-int              shutdown (int, int);
-int              setsockopt (int, int, int, const void *, socklen_t);
-int              getsockopt (int, int, int, void *, socklen_t *);
-int              sendmsg (int, const struct msghdr *, unsigned int);
-int              recvmsg (int, struct msghdr *, unsigned int);
-int              __socketcall (int, unsigned long*);
-int              sched_setscheduler (pid_t pid, int policy, const struct sched_param *param);
-int              sched_getscheduler (pid_t pid);
-int              sched_yield (void);
-int              sched_setparam (pid_t pid, const struct sched_param *param);
-int              sched_getparam (pid_t pid, struct sched_param *param);
-int              sched_get_priority_max (int policy);
-int              sched_get_priority_min (int policy);
-int              sched_rr_get_interval (pid_t pid, struct timespec *interval);
-int              sched_setaffinity (pid_t pid, size_t setsize, const cpu_set_t* set);
-int              __sched_getaffinity (pid_t pid, size_t setsize, cpu_set_t* set);
-int              __getcpu (unsigned *cpu, unsigned *node, void *unused);
-int              ioprio_set (int which, int who, int ioprio);
-int              ioprio_get (int which, int who);
-int              uname (struct utsname *);
-pid_t            __wait4 (pid_t pid, int *status, int options, struct rusage *rusage);
-mode_t           umask (mode_t);
-int              __reboot (int, int, int, void *);
-int              __syslog (int, char *, int);
-int              init_module (void *, unsigned long, const char *);
-int              delete_module (const char*, unsigned int);
-int              klogctl (int, char *, int);
-int              sysinfo (struct sysinfo *);
-int              futex (void *, int, int, void *, void *, int);
-int              epoll_create (int size);
-int              epoll_ctl (int epfd, int op, int fd, struct epoll_event *event);
-int              epoll_wait (int epfd, struct epoll_event *events, int max, int timeout);
-int              inotify_init (void);
-int              inotify_add_watch (int, const char *, unsigned int);
-int              inotify_rm_watch (int, unsigned int);
-int              poll (struct pollfd *, unsigned int, long);
-int              eventfd (unsigned int, int);
-int              __set_tls (void*);
-int              cacheflush (long start, long end, long flags);
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _BIONIC_LINUX_UNISTD_H_ */
diff --git a/libc/include/sys/personality.h b/libc/include/sys/personality.h
new file mode 100644
index 0000000..7772550
--- /dev/null
+++ b/libc/include/sys/personality.h
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+#ifndef _SYS_PERSONALITY_H_
+#define _SYS_PERSONALITY_H_
+
+#include <linux/personality.h>
+
+__BEGIN_DECLS
+
+extern int personality (unsigned long persona);
+
+__END_DECLS
+
+#endif /* _SYS_PERSONALITY_H_ */
diff --git a/libc/kernel/README.TXT b/libc/kernel/README.TXT
index 76dfa4d..9ff97d6 100644
--- a/libc/kernel/README.TXT
+++ b/libc/kernel/README.TXT
@@ -56,7 +56,7 @@
 
   * tools/update_all.py
     automatically update all clean headers from the content of 
-    'bionic/kernel/original'. this is the script you're likely going to 
+    'external/kernel-headers/original'. this is the script you're likely going to
     run whenever you update the original headers.
 
 NOTE:
diff --git a/libc/kernel/common/linux/personality.h b/libc/kernel/common/linux/personality.h
index 1f84b4e..bb55b75 100644
--- a/libc/kernel/common/linux/personality.h
+++ b/libc/kernel/common/linux/personality.h
@@ -7,77 +7,65 @@
  ***   structures, and macros generated from the original header, and thus,
  ***   contains no copyrightable information.
  ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
  ****************************************************************************
  ****************************************************************************/
 #ifndef _LINUX_PERSONALITY_H
 #define _LINUX_PERSONALITY_H
-
-struct exec_domain;
-struct pt_regs;
-
 enum {
+ UNAME26 = 0x0020000,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  ADDR_NO_RANDOMIZE = 0x0040000,
  FDPIC_FUNCPTRS = 0x0080000,
  MMAP_PAGE_ZERO = 0x0100000,
  ADDR_COMPAT_LAYOUT = 0x0200000,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  READ_IMPLIES_EXEC = 0x0400000,
  ADDR_LIMIT_32BIT = 0x0800000,
  SHORT_INODE = 0x1000000,
  WHOLE_SECONDS = 0x2000000,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  STICKY_TIMEOUTS = 0x4000000,
  ADDR_LIMIT_3GB = 0x8000000,
 };
-
-#define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC|ADDR_NO_RANDOMIZE)
-
+#define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC |   ADDR_NO_RANDOMIZE |   ADDR_COMPAT_LAYOUT |   MMAP_PAGE_ZERO)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 enum {
  PER_LINUX = 0x0000,
  PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT,
  PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
  PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE,
  PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS |
  WHOLE_SECONDS | SHORT_INODE,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS,
  PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE,
  PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS,
  PER_BSD = 0x0006,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PER_SUNOS = 0x0006 | STICKY_TIMEOUTS,
  PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE,
  PER_LINUX32 = 0x0008,
  PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,
  PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,
  PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,
  PER_RISCOS = 0x000c,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PER_SOLARIS = 0x000d | STICKY_TIMEOUTS,
  PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
  PER_OSF4 = 0x000f,
  PER_HPUX = 0x0010,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
  PER_MASK = 0x00ff,
 };
-
-typedef void (*handler_t)(int, struct pt_regs *);
-
-struct exec_domain {
- const char *name;
- handler_t handler;
- unsigned char pers_low;
- unsigned char pers_high;
- unsigned long *signal_map;
- unsigned long *signal_invmap;
- struct map_segment *err_map;
- struct map_segment *socktype_map;
- struct map_segment *sockopt_map;
- struct map_segment *af_map;
- struct module *module;
- struct exec_domain *next;
-};
-
-#define personality(pers) (pers & PER_MASK)
-
-#define get_personality (current->personality)
-
-#define set_personality(pers)   ((current->personality == pers) ? 0 : __set_personality(pers))
-
 #endif
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index 0549fc2..22e62aa 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -37,7 +37,7 @@
         src_path = src_path[1:]
 
     if len(src_path) == 0:
-        panic( "oops, internal error, can't extract correct relative path" )
+        panic( "oops, internal error, can't extract correct relative path\n" )
 
     # convert into destination path, extracting architecture if needed
     # and the corresponding list of known static functions
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 6a730a5..badef92 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -37,13 +37,13 @@
 progdir = find_program_dir()
 
 if len(args) == 1:
-    original_dir = arg[0]
+    original_dir = args[0]
     if not os.path.isdir(original_dir):
-        panic( "Not a directory: %s" % original_dir )
+        panic( "Not a directory: %s\n" % original_dir )
 else:
     original_dir = kernel_original_path
     if not os.path.isdir(original_dir):
-        panic( "Missing directory, please specify one through command-line: %s" % original_dir )
+        panic( "Missing directory, please specify one through command-line: %s\n" % original_dir )
 
 # find all source files in 'original'
 #
diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c
index b118956..dbad6dd 100644
--- a/libc/netbsd/resolv/res_send.c
+++ b/libc/netbsd/resolv/res_send.c
@@ -99,6 +99,7 @@
 #include <arpa/inet.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <netdb.h>
 #ifdef ANDROID_CHANGES
 #include "resolv_private.h"
@@ -109,6 +110,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 
 #include <isc/eventlib.h>
@@ -117,6 +119,8 @@
 #  include <resolv_cache.h>
 #endif
 
+#include "logd.h"
+
 #ifndef DE_CONST
 #define DE_CONST(c,v)   v = ((c) ? \
     strchr((const void *)(c), *(const char *)(const void *)(c)) : NULL)
@@ -130,6 +134,7 @@
 #include "res_private.h"
 
 #define EXT(res) ((res)->_u._ext)
+#define DBG 0
 
 static const int highestFD = FD_SETSIZE - 1;
 
@@ -152,7 +157,10 @@
 				const sigset_t *);
 #endif
 void res_pquery(const res_state, const u_char *, int, FILE *);
-
+static int connect_with_timeout(int sock, const struct sockaddr *nsap,
+			socklen_t salen, int sec);
+static int retrying_select(const int sock, fd_set *readset, fd_set *writeset,
+			const struct timespec *finish);
 
 /* BIONIC-BEGIN: implement source port randomization */
 typedef union {
@@ -413,7 +421,7 @@
 				if (EXT(statp).nssocks[ns] == -1)
 					continue;
 				peerlen = sizeof(peer);
-				if (getsockname(EXT(statp).nssocks[ns],
+				if (getpeername(EXT(statp).nssocks[ns],
 				    (struct sockaddr *)(void *)&peer, &peerlen) < 0) {
 					needclose++;
 					break;
@@ -521,16 +529,23 @@
 
 		Dprint(((statp->options & RES_DEBUG) &&
 			getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf),
-				    NULL, 0, niflags) == 0),
-		       (stdout, ";; Querying server (# %d) address = %s\n",
-			ns + 1, abuf));
+				NULL, 0, niflags) == 0),
+				(stdout, ";; Querying server (# %d) address = %s\n",
+				ns + 1, abuf));
 
 
 		if (v_circuit) {
 			/* Use VC; at most one attempt per server. */
 			try = statp->retry;
+
 			n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
 				    ns);
+
+			if (DBG) {
+				__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+					"used send_vc %d\n", n);
+			}
+
 			if (n < 0)
 				goto fail;
 			if (n == 0)
@@ -538,12 +553,26 @@
 			resplen = n;
 		} else {
 			/* Use datagrams. */
+			if (DBG) {
+				__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+					"using send_dg\n");
+			}
+
 			n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
 				    ns, &v_circuit, &gotsomewhere);
+			if (DBG) {
+				__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+					"used send_dg %d\n",n);
+			}
+
 			if (n < 0)
 				goto fail;
 			if (n == 0)
 				goto next_ns;
+			if (DBG) {
+				__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+					"time=%d, %d\n",time(NULL), time(NULL)%2);
+			}
 			if (v_circuit)
 				goto same_ns;
 			resplen = n;
@@ -668,6 +697,23 @@
 	}
 }
 
+static int get_timeout(const res_state statp, const int ns)
+{
+	int timeout = (statp->retrans << ns);
+	if (ns > 0) {
+		timeout /= statp->nscount;
+	}
+	if (timeout <= 0) {
+		timeout = 1;
+	}
+	if (DBG) {
+		__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+			"using timeout of %d sec\n", timeout);
+	}
+
+	return timeout;
+}
+
 static int
 send_vc(res_state statp,
 	const u_char *buf, int buflen, u_char *ans, int anssiz,
@@ -683,6 +729,10 @@
 	u_char *cp;
 	void *tmp;
 
+	if (DBG) {
+		__libc_android_log_print(ANDROID_LOG_DEBUG, "libc", "using send_vc\n");
+	}
+
 	nsap = get_nsaddr(statp, (size_t)ns);
 	nsaplen = get_salen(nsap);
 
@@ -735,7 +785,8 @@
 			res_nclose(statp);
 			return (0);
 		}
-		if (connect(statp->_vcsock, nsap, (socklen_t)nsaplen) < 0) {
+		if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t)nsaplen,
+				get_timeout(statp, ns)) < 0) {
 			*terrno = errno;
 			Aerror(statp, stderr, "connect/vc", errno, nsap,
 			    nsaplen);
@@ -859,6 +910,111 @@
 	return (resplen);
 }
 
+/* return -1 on error (errno set), 0 on success */
+static int
+connect_with_timeout(int sock, const struct sockaddr *nsap, socklen_t salen, int sec)
+{
+	int res, origflags;
+	fd_set rset, wset;
+	struct timespec now, timeout, finish;
+
+	origflags = fcntl(sock, F_GETFL, 0);
+	fcntl(sock, F_SETFL, origflags | O_NONBLOCK);
+
+	res = connect(sock, nsap, salen);
+	if (res < 0 && errno != EINPROGRESS) {
+                res = -1;
+                goto done;
+	}
+	if (res != 0) {
+		now = evNowTime();
+		timeout = evConsTime((long)sec, 0L);
+		finish = evAddTime(now, timeout);
+		if (DBG) {
+			__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+				"  %d send_vc\n", sock);
+		}
+
+		res = retrying_select(sock, &rset, &wset, &finish);
+		if (res <= 0) {
+                        res = -1;
+		}
+	}
+done:
+	fcntl(sock, F_SETFL, origflags);
+	if (DBG) {
+		__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+			"  %d connect_with_timeout returning %s\n", sock, res);
+	}
+	return res;
+}
+
+static int
+retrying_select(const int sock, fd_set *readset, fd_set *writeset, const struct timespec *finish)
+{
+	struct timespec now, timeout;
+	int n, error;
+	socklen_t len;
+
+
+retry:
+	if (DBG) {
+		__libc_android_log_print(ANDROID_LOG_DEBUG, "libc", "  %d retying_select\n", sock);
+	}
+
+	now = evNowTime();
+	if (readset) {
+		FD_ZERO(readset);
+		FD_SET(sock, readset);
+	}
+	if (writeset) {
+		FD_ZERO(writeset);
+		FD_SET(sock, writeset);
+	}
+	if (evCmpTime(*finish, now) > 0)
+		timeout = evSubTime(*finish, now);
+	else
+		timeout = evConsTime(0L, 0L);
+
+	n = pselect(sock + 1, readset, writeset, NULL, &timeout, NULL);
+	if (n == 0) {
+		if (DBG) {
+			__libc_android_log_print(ANDROID_LOG_DEBUG, " libc",
+				"  %d retrying_select timeout\n", sock);
+		}
+		errno = ETIMEDOUT;
+		return 0;
+	}
+	if (n < 0) {
+		if (errno == EINTR)
+			goto retry;
+		if (DBG) {
+			__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+				"  %d retrying_select got error %d\n",sock, n);
+		}
+		return n;
+	}
+	if ((readset && FD_ISSET(sock, readset)) || (writeset && FD_ISSET(sock, writeset))) {
+		len = sizeof(error);
+		if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
+			errno = error;
+			if (DBG) {
+				__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+					"  %d retrying_select dot error2 %d\n", sock, errno);
+			}
+
+			return -1;
+		}
+	}
+	if (DBG) {
+		__libc_android_log_print(ANDROID_LOG_DEBUG, "libc",
+			"  %d retrying_select returning %d for %d\n",sock, n);
+	}
+
+	return n;
+}
+
+
 static int
 send_dg(res_state statp,
 	const u_char *buf, int buflen, u_char *ans, int anssiz,
@@ -944,33 +1100,19 @@
 	/*
 	 * Wait for reply.
 	 */
-	seconds = (statp->retrans << ns);
-	if (ns > 0)
-		seconds /= statp->nscount;
-	if (seconds <= 0)
-		seconds = 1;
+	seconds = get_timeout(statp, ns);
 	now = evNowTime();
 	timeout = evConsTime((long)seconds, 0L);
 	finish = evAddTime(now, timeout);
-	goto nonow;
- wait:
-	now = evNowTime();
- nonow:
-	FD_ZERO(&dsmask);
-	FD_SET(s, &dsmask);
-	if (evCmpTime(finish, now) > 0)
-		timeout = evSubTime(finish, now);
-	else
-		timeout = evConsTime(0L, 0L);
-	n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL);
+retry:
+	n = retrying_select(s, &dsmask, NULL, &finish);
+
 	if (n == 0) {
 		Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n"));
 		*gotsomewhere = 1;
 		return (0);
 	}
 	if (n < 0) {
-		if (errno == EINTR)
-			goto wait;
 		Perror(statp, stderr, "select", errno);
 		res_nclose(statp);
 		return (0);
@@ -1006,7 +1148,7 @@
 			(statp->pfcode & RES_PRF_REPLY),
 			(stdout, ";; old answer:\n"),
 			ans, (resplen > anssiz) ? anssiz : resplen);
-		goto wait;
+		goto retry;
 	}
 	if (!(statp->options & RES_INSECURE1) &&
 	    !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) {
@@ -1019,7 +1161,7 @@
 			(statp->pfcode & RES_PRF_REPLY),
 			(stdout, ";; not our server:\n"),
 			ans, (resplen > anssiz) ? anssiz : resplen);
-		goto wait;
+		goto retry;
 	}
 #ifdef RES_USE_EDNS0
 	if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) {
@@ -1049,7 +1191,7 @@
 			(statp->pfcode & RES_PRF_REPLY),
 			(stdout, ";; wrong query name:\n"),
 			ans, (resplen > anssiz) ? anssiz : resplen);
-		goto wait;
+		goto retry;;
 	}
 	if (anhp->rcode == SERVFAIL ||
 	    anhp->rcode == NOTIMP ||
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index c188e04..479109d 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -510,23 +510,6 @@
         self.other_files.append( path )
 
 
-    # now dump the content of linux/_syscalls.h
-    def gen_linux_unistd_h(self):
-        path = "include/sys/linux-unistd.h"
-        D( "generating "+path )
-        fp = create_file( path )
-        fp.write( "/* auto-generated by gensyscalls.py, do not touch */\n" )
-        fp.write( "#ifndef _BIONIC_LINUX_UNISTD_H_\n\n" );
-        fp.write( "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n" )
-
-        for sc in self.syscalls:
-            fp.write( sc["decl"]+"\n" )
-
-        fp.write( "#ifdef __cplusplus\n}\n#endif\n" )
-        fp.write( "\n#endif /* _BIONIC_LINUX_UNISTD_H_ */\n" );
-        fp.close()
-        self.other_files.append( path )
-
     # now dump the contents of syscalls.mk
     def gen_arch_syscalls_mk(self, arch):
         path = "arch-%s/syscalls.mk" % arch
@@ -612,7 +595,6 @@
         self.gen_linux_syscalls_h()
         for arch in all_archs:
             self.gen_arch_syscalls_mk(arch)
-        self.gen_linux_unistd_h()
         self.gen_syscall_stubs()
 
         D( "comparing files" )
diff --git a/linker/README.TXT b/linker/README.TXT
index a8efe35..f920b97 100644
--- a/linker/README.TXT
+++ b/linker/README.TXT
@@ -87,6 +87,7 @@
       present in executables, not shared libraries, which contains
       a list of functions that need to be called before any other
       initialization function (i.e. DT_INIT and/or DT_INIT_ARRAY)
+      in the executable or any of its libraries.
 
       Note: this is generally stored in a .preinit_array section
 
diff --git a/linker/dlfcn.c b/linker/dlfcn.c
index 7161455..62dde2f 100644
--- a/linker/dlfcn.c
+++ b/linker/dlfcn.c
@@ -60,6 +60,7 @@
     if (unlikely(ret == NULL)) {
         set_dlerror(DL_ERR_CANNOT_LOAD_LIBRARY);
     } else {
+        call_constructors_recursive(ret);
         ret->refcount++;
     }
     pthread_mutex_unlock(&dl_lock);
diff --git a/linker/linker.c b/linker/linker.c
index e4618e3..a692d62 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -1617,8 +1617,11 @@
     }
 }
 
-static void call_constructors(soinfo *si)
+void call_constructors_recursive(soinfo *si)
 {
+    if (si->constructors_called)
+        return;
+
     if (si->flags & FLAG_EXE) {
         TRACE("[ %5d Calling preinit_array @ 0x%08x [%d] for '%s' ]\n",
               pid, (unsigned)si->preinit_array, si->preinit_array_count,
@@ -1633,6 +1636,21 @@
         }
     }
 
+    if (si->dynamic) {
+        unsigned *d;
+        for(d = si->dynamic; *d; d += 2) {
+            if(d[0] == DT_NEEDED){
+                soinfo* lsi = (soinfo *)d[1];
+                if (!validate_soinfo(lsi)) {
+                    DL_ERR("%5d bad DT_NEEDED pointer in %s",
+                           pid, si->name);
+                } else {
+                    call_constructors_recursive(lsi);
+                }
+            }
+        }
+    }
+
     if (si->init_func) {
         TRACE("[ %5d Calling init_func @ 0x%08x for '%s' ]\n", pid,
               (unsigned)si->init_func, si->name);
@@ -1646,8 +1664,9 @@
         call_array(si->init_array, si->init_array_count, 0);
         TRACE("[ %5d Done calling init_array for '%s' ]\n", pid, si->name);
     }
-}
 
+    si->constructors_called = 1;
+}
 
 static void call_destructors(soinfo *si)
 {
@@ -2046,7 +2065,6 @@
     if (program_is_setuid)
         nullify_closed_stdio ();
     notify_gdb_of_load(si);
-    call_constructors(si);
     return 0;
 
 fail:
@@ -2251,6 +2269,8 @@
         exit(-1);
     }
 
+    call_constructors_recursive(si);
+
 #if ALLOW_SYMBOLS_FROM_MAIN
     /* Set somain after we've loaded all the libraries in order to prevent
      * linking of symbols back to the main image, which is not set up at that
diff --git a/linker/linker.h b/linker/linker.h
index aa1e5e7..c9e0309 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -149,6 +149,8 @@
 
     unsigned refcount;
     struct link_map linkmap;
+
+    int constructors_called;
 };
 
 
@@ -217,6 +219,7 @@
 soinfo *find_containing_library(const void *addr);
 Elf32_Sym *find_containing_symbol(const void *addr, soinfo *si);
 const char *linker_get_error(void);
+void call_constructors_recursive(soinfo *si);
 
 #ifdef ANDROID_ARM_LINKER 
 typedef long unsigned int *_Unwind_Ptr;