am bd192b47: Add stack unwinding directives to assembly leaf functions.

Merge commit 'bd192b470b69e00e9313680b70c5572a609e535d' into eclair-plus-aosp

* commit 'bd192b470b69e00e9313680b70c5572a609e535d':
  Add stack unwinding directives to assembly leaf functions.
diff --git a/libc/README b/libc/README
index 4e29f12..d92d85d 100644
--- a/libc/README
+++ b/libc/README
@@ -1,4 +1,5 @@
-Welcome to Bionic, Android small and custom C library for the Android platform
+Welcome to Bionic, Android's small and custom C library for the Android
+platform.
 
 Bionic is mainly a port of the BSD C library to our Linux kernel with the
 following additions/changes:
diff --git a/libc/arch-arm/bionic/atomics_arm.S b/libc/arch-arm/bionic/atomics_arm.S
index f8b23e6..0cd0b92 100644
--- a/libc/arch-arm/bionic/atomics_arm.S
+++ b/libc/arch-arm/bionic/atomics_arm.S
@@ -138,8 +138,18 @@
 #endif
 
 /* r0(new) r1(addr) -> r0(old) */
+/* replaced swp instruction with ldrex/strex for ARMv6 & ARMv7 */
 __atomic_swap:
+#if defined (_ARM_HAVE_LDREX_STREX)
+1:  ldrex   r2, [r1]
+    strex   r3, r0, [r1]
+    teq     r3, #0
+    bne     1b
+    mov     r0, r2
+    mcr     p15, 0, r0, c7, c10, 5 /* or, use dmb */
+#else
     swp     r0, r0, [r1]
+#endif
     bx      lr
 
 /* __futex_wait(*ftx, val, *timespec) */
diff --git a/libc/arch-arm/include/machine/cpu-features.h b/libc/arch-arm/include/machine/cpu-features.h
index f836006..ecf6ff6 100644
--- a/libc/arch-arm/include/machine/cpu-features.h
+++ b/libc/arch-arm/include/machine/cpu-features.h
@@ -149,6 +149,13 @@
 #  define __ARM_HAVE_PC_INTERWORK
 #endif
 
+/* define _ARM_HAVE_LDREX_STREX for ARMv6 and ARMv7 architecure to be
+ * used in replacement of depricated swp instruction
+ */
+#if __ARM_ARCH__ >= 6
+#  define _ARM_HAVE_LDREX_STREX
+#endif
+
 
 /* Assembly-only macros */
 
diff --git a/libc/bionic/logd_write.c b/libc/bionic/logd_write.c
index 211b527..3336428 100644
--- a/libc/bionic/logd_write.c
+++ b/libc/bionic/logd_write.c
@@ -46,62 +46,80 @@
 #define LOG_BUF_SIZE	1024
 
 typedef enum {
-    LOG_ID_MAIN = 0,
+    LOG_ID_NONE = 0,
+    LOG_ID_MAIN,
     LOG_ID_RADIO,
     LOG_ID_MAX
 } log_id_t;
 
-static int __write_to_log_init(log_id_t, struct iovec *vec);
-static int (*write_to_log)(log_id_t, struct iovec *vec) = __write_to_log_init;
+/* logger handles writing to object, pointed by log channel id */
+typedef int (*logger_function_t)(log_id_t log_id, struct iovec *vec);
+
+typedef struct {
+    logger_function_t logger;
+    int               fd;
+    const char        *path;
+} log_channel_t;
+
+static int __write_to_log_init(log_id_t log_id, struct iovec *vec);
+static int __write_to_log_null(log_id_t log_id, struct iovec *vec);
+
 static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
 
-static int log_fds[(int)LOG_ID_MAX] = { -1, -1 };
+log_channel_t log_channels[LOG_ID_MAX] = {
+    { __write_to_log_null, -1, NULL },
+    { __write_to_log_init, -1, "/dev/"LOGGER_LOG_MAIN },
+    { __write_to_log_init, -1, "/dev/"LOGGER_LOG_RADIO }
+};
 
-static int __write_to_log_null(log_id_t log_fd, struct iovec *vec)
+static int __write_to_log_null(log_id_t log_id, struct iovec *vec)
 {
-    return -1;
+    /* 
+     * ALTERED behaviour from previous version
+     * always returns successful result
+     */
+    int    i = 0;
+    size_t res = 0;
+
+    for ( ; i < 3; ++i) {
+        res += vec[i].iov_len;
+    }
+
+    return (int)res;
 }
 
+/*
+ *  it's supposed, that log_id contains valid id always.
+ *  this check must be performed in higher level functions
+ */
 static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec)
 {
     ssize_t ret;
-    int log_fd;
-
-    if ((int)log_id >= 0 && (int)log_id < (int)LOG_ID_MAX) {
-        log_fd = log_fds[(int)log_id];
-    } else {
-        return EBADF;
-    }
 
     do {
-        ret = writev(log_fd, vec, 3);
-    } while (ret < 0 && errno == EINTR);
+        ret = writev(log_channels[log_id].fd, vec, 3);
+    } while ((ret < 0) && (errno == EINTR));
 
     return ret;
 }
 
 static int __write_to_log_init(log_id_t log_id, struct iovec *vec)
 {
-    pthread_mutex_lock(&log_init_lock);
+    if ((LOG_ID_NONE < log_id) && (log_id < LOG_ID_MAX)) {
+        pthread_mutex_lock(&log_init_lock);
 
-    if (write_to_log == __write_to_log_init) {
-        log_fds[LOG_ID_MAIN] = open("/dev/"LOGGER_LOG_MAIN, O_WRONLY);
-        log_fds[LOG_ID_RADIO] = open("/dev/"LOGGER_LOG_RADIO, O_WRONLY);
+        int fd = open(log_channels[log_id].path, O_WRONLY);
 
-        write_to_log = __write_to_log_kernel;
+        log_channels[log_id].logger =
+            (fd < 0) ? __write_to_log_null : __write_to_log_kernel;
 
-        if (log_fds[LOG_ID_MAIN] < 0 || log_fds[LOG_ID_RADIO] < 0) {
-            close(log_fds[LOG_ID_MAIN]);
-            close(log_fds[LOG_ID_RADIO]);
-            log_fds[LOG_ID_MAIN] = -1;
-            log_fds[LOG_ID_RADIO] = -1;
-            write_to_log = __write_to_log_null;
-        }
+        pthread_mutex_unlock(&log_init_lock);
+
+        return log_channels[log_id].logger(log_id, vec);
     }
 
-    pthread_mutex_unlock(&log_init_lock);
-
-    return write_to_log(log_id, vec);
+    /* log_id is invalid */
+    return -1;
 }
 
 static int __android_log_write(int prio, const char *tag, const char *msg)
@@ -109,7 +127,7 @@
     struct iovec vec[3];
     log_id_t log_id = LOG_ID_MAIN;
 
-    if (!tag)
+    if (tag == NULL)
         tag = "";
 
     if (!strcmp(tag, "HTC_RIL"))
@@ -122,7 +140,7 @@
     vec[2].iov_base   = (void *) msg;
     vec[2].iov_len    = strlen(msg) + 1;
 
-    return write_to_log(log_id, vec);
+    return log_channels[log_id].logger(log_id, vec);
 }
 
 
diff --git a/libc/include/strings.h b/libc/include/strings.h
index 1f73e21..fee7dc4 100644
--- a/libc/include/strings.h
+++ b/libc/include/strings.h
@@ -39,6 +39,7 @@
 #ifndef _STRINGS_H_
 #define _STRINGS_H_
 
+#include <sys/types.h>
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
diff --git a/libc/netbsd/net/getservent.c b/libc/netbsd/net/getservent.c
index 65fbd7e..9f6ec32 100644
--- a/libc/netbsd/net/getservent.c
+++ b/libc/netbsd/net/getservent.c
@@ -27,7 +27,7 @@
  */
 #include <sys/cdefs.h>
 #include <sys/types.h>
-#include <sys/endian.h>
+#include <endian.h>
 #include <netdb.h>
 #include "servent.h"
 #include "services.h"