Merge change I37d0317d

* changes:
  modified SYSCALLS.TXT to support SuperH architecture
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0db5b03
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+libc/kernel/original
diff --git a/MAINTAINERS b/MAINTAINERS
new file mode 100644
index 0000000..a76dc24
--- /dev/null
+++ b/MAINTAINERS
@@ -0,0 +1,6 @@
+
+Bionic support for SuperH
+-------------------------
+Bionic support for SuperH architecture is written by
+Shin-ichiro KAWASAKI <shinichiro.kawasaki.mg@hitachi.com>
+and Contributed to Android by Hitachi, Ltd. and Renesas Solutions Corp.
diff --git a/libc/Android.mk b/libc/Android.mk
index 330802a..506dac5 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -1,6 +1,9 @@
 LOCAL_PATH:= $(call my-dir)
 
 include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk
+
+# Define the common source files for all the libc instances
+# =========================================================
 libc_common_src_files := \
 	$(syscall_src) \
 	unistd/abort.c \
@@ -49,6 +52,7 @@
 	unistd/siginterrupt.c \
 	unistd/siglist.c \
 	unistd/signal.c \
+	unistd/signame.c \
 	unistd/sigsetmask.c \
 	unistd/sigsuspend.c \
 	unistd/sigwait.c \
@@ -172,7 +176,6 @@
 	string/memccpy.c \
 	string/memchr.c \
 	string/memmem.c \
-	string/memmove.c.arm \
 	string/memrchr.c \
 	string/memswap.c \
 	string/strcasecmp.c \
@@ -256,7 +259,7 @@
 	netbsd/resolv/res_mkquery.c \
 	netbsd/resolv/res_query.c \
 	netbsd/resolv/res_send.c \
-	netbsd/resolv/res_state.c.arm \
+	netbsd/resolv/res_state.c \
 	netbsd/resolv/res_cache.c \
 	netbsd/net/nsdispatch.c \
 	netbsd/net/getaddrinfo.c \
@@ -272,6 +275,8 @@
 	netbsd/nameser/ns_print.c \
 	netbsd/nameser/ns_samedomain.c
 
+# Architecture specific source files go here
+# =========================================================
 ifeq ($(TARGET_ARCH),arm)
 libc_common_src_files += \
 	bionic/eabi.c \
@@ -292,6 +297,7 @@
 	arch-arm/bionic/sigsetjmp.S \
 	arch-arm/bionic/strlen.c.arm \
 	arch-arm/bionic/syscall.S \
+	string/memmove.c.arm \
 	unistd/socketcalls.c
 
 # These files need to be arm so that gdbserver
@@ -301,6 +307,14 @@
 	bionic/pthread.c.arm \
 	bionic/pthread-timers.c.arm \
 	bionic/ptrace.c.arm
+
+# these are used by the static and dynamic versions of the libc
+# respectively
+libc_arch_static_src_files := \
+	arch-arm/bionic/exidx_static.c
+
+libc_arch_dynamic_src_files := \
+	arch-arm/bionic/exidx_dynamic.c
 else # !arm
 
 ifeq ($(TARGET_ARCH),x86)
@@ -319,13 +333,52 @@
 	arch-x86/string/memcmp.S \
 	arch-x86/string/memcpy.S \
 	arch-x86/string/strlen.S \
+	string/memmove.c \
 	bionic/pthread.c \
 	bionic/pthread-timers.c \
 	bionic/ptrace.c
-endif # x86
 
+# this is needed for static versions of libc
+libc_arch_static_src_files := \
+	arch-x86/bionic/dl_iterate_phdr_static.c
+
+libc_arch_dynamic_src_files :=
+else # !x86
+
+ifeq ($(TARGET_ARCH),sh)
+libc_common_src_files += \
+	arch-sh/bionic/__get_pc.S \
+	arch-sh/bionic/__get_sp.S \
+	arch-sh/bionic/_exit_with_stack_teardown.S \
+	arch-sh/bionic/_setjmp.S \
+	arch-sh/bionic/atomics_sh.c \
+	arch-sh/bionic/atomic_cmpxchg.S \
+	arch-sh/bionic/clone.S \
+	arch-sh/bionic/pipe.S \
+	arch-sh/bionic/memcpy.S \
+	arch-sh/bionic/memset.S \
+	arch-sh/bionic/bzero.S \
+	arch-sh/bionic/setjmp.S \
+	arch-sh/bionic/sigsetjmp.S \
+	arch-sh/bionic/syscall.S \
+	arch-sh/bionic/memmove.S \
+	arch-sh/bionic/__set_tls.c \
+	arch-sh/bionic/__get_tls.c \
+	arch-sh/bionic/ffs.S \
+	string/memcmp.c \
+	string/strlen.c \
+	bionic/eabi.c \
+	bionic/pthread.c \
+	bionic/pthread-timers.c \
+	bionic/ptrace.c \
+	unistd/socketcalls.c
+endif # sh
+
+endif # !x86
 endif # !arm
 
+# Define some common cflags
+# ========================================================
 libc_common_cflags := \
 		-DWITH_ERRLIST			\
 		-DANDROID_CHANGES		\
@@ -337,162 +390,158 @@
 		-DNEED_PSELECT=1		\
 		-DINET6 \
 		-I$(LOCAL_PATH)/private \
+		-DUSE_DL_PREFIX
 
-ifeq ($(TARGET_BUILD_TYPE),debug)
+ifeq ($(strip $(DEBUG_BIONIC_LIBC)),true)
   libc_common_cflags += -DDEBUG
 endif
 
 ifeq ($(TARGET_ARCH),arm)
   libc_common_cflags += -fstrict-aliasing
-endif
+  libc_crt_target_cflags := -mthumb-interwork
+else # !arm
+  ifeq ($(TARGET_ARCH),x86)
+    libc_crt_target_cflags := -m32
+  endif # x86
+endif # !arm
 
+# Define some common includes
+# ========================================================
 libc_common_c_includes := \
 		$(LOCAL_PATH)/stdlib  \
 		$(LOCAL_PATH)/string  \
 		$(LOCAL_PATH)/stdio
 
-# libc_common.a
-# ========================================================
 
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(libc_common_src_files)
-LOCAL_CFLAGS := $(libc_common_cflags) -DUSE_DL_PREFIX
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-
-ifneq ($(TARGET_SIMULATOR),true)
-  ifeq ($(TARGET_ARCH),arm)
-    crtend_target_cflags := -mthumb-interwork
-  else
-    ifeq ($(TARGET_ARCH),x86)
-      crtend_target_cflags := -m32
-    endif
-  endif
-# We rename crtend.o to crtend_android.o to avoid a
-# name clash between gcc and bionic.
-GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
-$(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtend.S
-	@mkdir -p $(dir $@)
-	$(TARGET_CC) $(crtend_target_cflags) -o $@ -c $<
-ALL_GENERATED_SOURCES += $(GEN)
-endif
-
-
-# crtbegin_so.o/crtend_so.o
-# These are needed for building the shared libs.
-ifneq ($(TARGET_SIMULATOR),true)
+# Define the libc run-time (crt) support object files that must be built,
+# which are needed to build all other objects (shared/static libs and
+# executables)
+# ==========================================================================
 
 ifeq ($(TARGET_ARCH),x86)
-
-crt_begin_end_so_target_cflags := -m32
-
+# we only need begin_so/end_so for x86, since it needs an appropriate .init
+# section in the shared library with a function to call all the entries in
+# .ctors section. ARM uses init_array, and does not need the function.
 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o
 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_so.S
 	@mkdir -p $(dir $@)
-	$(TARGET_CC) $(crt_begin_end_so_target_cflags) -o $@ -c $<
+	$(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
 ALL_GENERATED_SOURCES += $(GEN)
 
 GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_so.o
 $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtend_so.S
 	@mkdir -p $(dir $@)
-	$(TARGET_CC) $(crt_begin_end_so_target_cflags) -o $@ -c $<
+	$(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
 ALL_GENERATED_SOURCES += $(GEN)
-
 endif # TARGET_ARCH == x86
 
-endif # !TARGET_SIMULATOR
+
+GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
+$(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_static.S
+	@mkdir -p $(dir $@)
+	$(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
+ALL_GENERATED_SOURCES += $(GEN)
+
+GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
+$(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_dynamic.S
+	@mkdir -p $(dir $@)
+	$(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
+ALL_GENERATED_SOURCES += $(GEN)
 
 
+# We rename crtend.o to crtend_android.o to avoid a
+# name clash between gcc and bionic.
+GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
+$(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtend.S
+	@mkdir -p $(dir $@)
+	$(TARGET_CC) $(libc_crt_target_cflags) -o $@ -c $<
+ALL_GENERATED_SOURCES += $(GEN)
+
+
+# To enable malloc leak check for statically linked programs, add
+# "WITH_MALLOC_CHECK_LIBC_A := true" to buildspec.mk
+WITH_MALLOC_CHECK_LIBC_A := $(strip $(WITH_MALLOC_CHECK_LIBC_A))
+
+# ========================================================
+# libc_common.a
+# ========================================================
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(libc_common_src_files)
+LOCAL_CFLAGS := $(libc_common_cflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_MODULE := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
 include $(BUILD_STATIC_LIBRARY)
 
 
-# libc.a
 # ========================================================
+# libc_nomalloc.a
+# ========================================================
+#
+# This is a version of the static C library that does not
+# include malloc. It's useful in situations when calling
+# the user wants to provide their own malloc implementation,
+# or wants to explicitly disallow the use of the use of malloc,
+# like the dynamic loader.
 
 include $(CLEAR_VARS)
 
-include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk
-
-# To enable malloc leak check for statically linked programs, add
-# "WITH_MALLOC_CHECK_LIBC_A := true" to device/buildspec.mk
-WITH_MALLOC_CHECK_LIBC_A := $(strip $(WITH_MALLOC_CHECK_LIBC_A))
-
 LOCAL_SRC_FILES := \
-	$(libc_common_src_files) \
-	bionic/dlmalloc.c \
+	$(libc_arch_static_src_files) \
 	bionic/libc_init_static.c
 
-ifeq ($(WITH_MALLOC_CHECK_LIBC_A),true)
-  LOCAL_SRC_FILES += bionic/malloc_leak.c.arm
-endif
-
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_SRC_FILES += \
-	arch-arm/bionic/exidx_static.c
-
-else # TARGET_ARCH != arm
-
-ifeq ($(TARGET_ARCH),x86)
-LOCAL_SRC_FILES += \
-	arch-x86/bionic/dl_iterate_phdr_static.c
-endif
-
-endif
-
-ifneq ($(TARGET_SIMULATOR),true)
-  ifeq ($(TARGET_ARCH),arm)
-    crtbegin_static_target_cflags := -mthumb-interwork
-  else
-    ifeq ($(TARGET_ARCH),x86)
-      crtbegin_static_target_cflags := -m32
-    endif
-  endif
-GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
-$(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_static.S
-	@mkdir -p $(dir $@)
-	$(TARGET_CC) $(crtbegin_static_target_cflags) -o $@ -c $<
-ALL_GENERATED_SOURCES += $(GEN)
-endif
-
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
 LOCAL_CFLAGS := $(libc_common_cflags)
 
-LOCAL_C_INCLUDES := $(libc_common_c_includes)
-
-ifeq ($(WITH_MALLOC_CHECK_LIBC_A),true)
-  LOCAL_CFLAGS += -DUSE_DL_PREFIX -DMALLOC_LEAK_CHECK
-endif
-
+LOCAL_MODULE := libc_nomalloc
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
-LOCAL_MODULE:= libc
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
 include $(BUILD_STATIC_LIBRARY)
 
 
-# libc.so
 # ========================================================
-
+# libc.a
+# ========================================================
 include $(CLEAR_VARS)
 
+LOCAL_SRC_FILES := \
+	$(libc_arch_static_src_files) \
+	bionic/dlmalloc.c \
+	bionic/libc_init_static.c
+
 LOCAL_CFLAGS := $(libc_common_cflags)
 
-LOCAL_CFLAGS += -DUSE_DL_PREFIX
+ifeq ($(WITH_MALLOC_CHECK_LIBC_A),true)
+  LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
+  LOCAL_SRC_FILES += bionic/malloc_leak.c.arm
+endif
 
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 
+LOCAL_MODULE := libc
+LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
+# libc.so
+# ========================================================
+include $(CLEAR_VARS)
+
+LOCAL_CFLAGS := $(libc_common_cflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+
 LOCAL_SRC_FILES := \
+	$(libc_arch_dynamic_src_files) \
 	bionic/dlmalloc.c \
 	bionic/malloc_leak.c.arm \
 	bionic/libc_init_dynamic.c
 
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_SRC_FILES += \
-	arch-arm/bionic/exidx_dynamic.c
-endif
-
 LOCAL_MODULE:= libc
 
 # WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
@@ -507,45 +556,26 @@
 LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
 LOCAL_SYSTEM_SHARED_LIBRARIES :=
 
-ifneq ($(TARGET_SIMULATOR),true)
-  ifeq ($(TARGET_ARCH),arm)
-    crtbegin_dynamic_target_cflags := -mthumb-interwork
-  else
-    ifeq ($(TARGET_ARCH),x86)
-      crtbegin_dynamic_target_cflags := -m32
-    endif
-  endif
-GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
-$(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_dynamic.S
-	@mkdir -p $(dir $@)
-	$(TARGET_CC) $(crtbegin_dynamic_target_cflags) -o $@ -c $<
-ALL_GENERATED_SOURCES += $(GEN)
-endif
-
 include $(BUILD_SHARED_LIBRARY)
 
 
+# ========================================================
 # libc_debug.so
 # ========================================================
-
 include $(CLEAR_VARS)
 
-LOCAL_CFLAGS := $(libc_common_cflags)
-
-LOCAL_CFLAGS += -DUSE_DL_PREFIX -DMALLOC_LEAK_CHECK
+LOCAL_CFLAGS := \
+	$(libc_common_cflags) \
+	-DMALLOC_LEAK_CHECK
 
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
 
 LOCAL_SRC_FILES := \
+	$(libc_arch_dynamic_src_files) \
 	bionic/dlmalloc.c \
 	bionic/malloc_leak.c.arm \
 	bionic/libc_init_dynamic.c
 
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_SRC_FILES += \
-	arch-arm/bionic/exidx_dynamic.c
-endif
-
 LOCAL_MODULE:= libc_debug
 
 # WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
@@ -564,9 +594,6 @@
 # Don't install on release build
 LOCAL_MODULE_TAGS := eng
 
-GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
-ALL_GENERATED_SOURCES += $(GEN)
-
 include $(BUILD_SHARED_LIBRARY)
 
 # ========================================================
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 b2da09f..57c4239 100644
--- a/libc/arch-arm/bionic/atomics_arm.S
+++ b/libc/arch-arm/bionic/atomics_arm.S
@@ -129,8 +129,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/arch-sh/bionic/__get_pc.S b/libc/arch-sh/bionic/__get_pc.S
new file mode 100644
index 0000000..155b387
--- /dev/null
+++ b/libc/arch-sh/bionic/__get_pc.S
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+.text
+.type   __get_pc, @function
+.globl  __get_pc
+.align  4
+
+__get_pc:
+    mova    1f, r0
+    rts
+1:  nop
+
diff --git a/libc/arch-sh/bionic/__get_sp.S b/libc/arch-sh/bionic/__get_sp.S
new file mode 100644
index 0000000..0e34a01
--- /dev/null
+++ b/libc/arch-sh/bionic/__get_sp.S
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+.text
+.type   __get_sp, @function
+.globl  __get_sp
+.align  4
+
+__get_sp:
+    rts
+    mov     r15, r0
+
diff --git a/libc/arch-sh/bionic/__get_tls.c b/libc/arch-sh/bionic/__get_tls.c
new file mode 100644
index 0000000..8a5e4ff
--- /dev/null
+++ b/libc/arch-sh/bionic/__get_tls.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+/* see the implementation of __set_tls and pthread.c to understand this
+ * code. Basically, the content of fs:[0] always is a pointer to the base
+ * address of the tls region
+ */
+void *__get_tls(void)
+{
+    void *tls;
+    asm volatile("stc gbr, %0" : "=r"(tls));
+    return tls;
+}
diff --git a/libc/arch-sh/bionic/__set_tls.c b/libc/arch-sh/bionic/__set_tls.c
new file mode 100644
index 0000000..7f863de
--- /dev/null
+++ b/libc/arch-sh/bionic/__set_tls.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 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 <pthread.h>
+
+/*
+ * Simply set tls address into GBR.
+ */
+int __set_tls(void *ptr)
+{
+    asm volatile("ldc %0, gbr" : /* no output */ : "r" (ptr));
+    return 0;
+}
diff --git a/libc/arch-sh/bionic/_exit_with_stack_teardown.S b/libc/arch-sh/bionic/_exit_with_stack_teardown.S
new file mode 100644
index 0000000..6356eb6
--- /dev/null
+++ b/libc/arch-sh/bionic/_exit_with_stack_teardown.S
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 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 <asm/unistd.h>
+
+.text
+.type   _exit_with_stack_teardown, @function
+.globl  _exit_with_stack_teardown
+.align  4
+
+# void _exit_with_stack_teardown(void * stackBase, int stackSize, int retCode)
+
+_exit_with_stack_teardown:
+    mov     r6, r8      /* save retCode : breaks r8 value */
+    mov.l   0f, r3      /* system call number */
+    trapa   #(2 + 0x10) /* invoke system call with num of args */
+
+    mov     r8, r4      /* restore retCode */
+    mov.l   1f, r3      /* system call number */
+    trapa   #(1 + 0x10) /* invoke system call with num of args */
+
+    /* exit() should never return, cause a crash if it does */
+    mov     #0, r0
+    mov.l   @r0, r0
+
+    .align  2
+0:  .long   __NR_munmap
+1:  .long   __NR_exit
diff --git a/libc/arch-sh/bionic/_setjmp.S b/libc/arch-sh/bionic/_setjmp.S
new file mode 100644
index 0000000..a04fcb6
--- /dev/null
+++ b/libc/arch-sh/bionic/_setjmp.S
@@ -0,0 +1,125 @@
+/*	$OpenBSD: _setjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
+/*	$NetBSD: _setjmp.S,v 1.7 2006/01/05 02:04:41 uwe Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	from: @(#)_setjmp.s	5.1 (Berkeley) 4/23/90
+ */
+
+#include <machine/asm.h>
+#include <machine/setjmp.h>
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ *	_longjmp(a,v)
+ * will generate a "return(v)" from the last call to
+ *	_setjmp(a)
+ * by restoring registers from the stack.
+ * The previous signal state is NOT restored.
+ */
+
+ENTRY(_setjmp)
+	xor	r0,	r0
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+	add	#(_JBLEN * 4), r4
+	sts	fpscr,	r1
+	mov.l	r1,	@-r4
+	lds	r0,	fpscr
+	sts.l	fpul,	@-r4
+	fmov.s	fr15,	@-r4
+	fmov.s	fr14,	@-r4
+	fmov.s	fr13,	@-r4
+	fmov.s	fr12,	@-r4
+	frchg
+	fmov.s	fr15,	@-r4
+	fmov.s	fr14,	@-r4
+	fmov.s	fr13,	@-r4
+	fmov.s	fr12,	@-r4
+	lds	r1,	fpscr
+#else
+	add	#((_JBLEN - 10) * 4), r4
+#endif
+	sts.l	mach,	@-r4
+	sts.l	macl,	@-r4
+	mov.l	r15,	@-r4
+	mov.l	r14,	@-r4
+	mov.l	r13,	@-r4
+	mov.l	r12,	@-r4
+	mov.l	r11,	@-r4
+	mov.l	r10,	@-r4
+	mov.l	r9,	@-r4
+	mov.l	r8,	@-r4
+	sts.l	pr,	@-r4
+	mov.l	r0,	@-r4		/* dummy signal mask */
+	rts
+	 mov.l	r0,	@-r4		/* no saved signal mask */
+	SET_ENTRY_SIZE(_setjmp)
+
+ENTRY(_longjmp)
+	add	#8,	r4
+	lds.l	@r4+,	pr
+	mov.l	@r4+,	r8
+	mov.l	@r4+,	r9
+	mov.l	@r4+,	r10
+	mov.l	@r4+,	r11
+	mov.l	@r4+,	r12
+	mov.l	@r4+,	r13
+	mov.l	@r4+,	r14
+	mov.l	@r4+,	r15
+	lds.l	@r4+,	macl
+	lds.l	@r4+,	mach
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+	xor	r0, 	r0
+	lds	r0,	fpscr
+	frchg
+	fmov.s	@r4+,	fr12
+	fmov.s	@r4+,	fr13
+	fmov.s	@r4+,	fr14
+	fmov.s	@r4+,	fr15
+	frchg
+	fmov.s	@r4+,	fr12
+	fmov.s	@r4+,	fr13
+	fmov.s	@r4+,	fr14
+	fmov.s	@r4+,	fr15
+	lds.l	@r4+,	fpul
+	lds.l	@r4+,	fpscr
+#endif
+
+	mov	r5,	r0
+	tst	r0,	r0
+	bf	.L0
+	add	#1,	r0
+.L0:
+	rts
+	 nop
+	SET_ENTRY_SIZE(_longjmp)
diff --git a/libc/arch-sh/bionic/atomic_cmpxchg.S b/libc/arch-sh/bionic/atomic_cmpxchg.S
new file mode 100644
index 0000000..4ccd6cf
--- /dev/null
+++ b/libc/arch-sh/bionic/atomic_cmpxchg.S
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+.text
+.type   __atomic_cmpxchg, @function
+.globl  __atomic_cmpxchg
+.align 4
+
+__atomic_cmpxchg:
+    mova    1f, r0
+    nop
+    mov     r15, r1
+    mov     #-8, r15    /* critical region start */
+0:  mov.l   @r6, r2
+    cmp/eq  r2, r4
+    bt      not_yet_modified
+    mov     #1, r0
+    bra     done
+    nop
+not_yet_modified:
+    mov     #0, r0
+    mov.l   r5, @r6
+done:
+1:  mov     r1, r15     /* critical region end */
+    rts
+    nop
diff --git a/libc/arch-sh/bionic/atomics_sh.c b/libc/arch-sh/bionic/atomics_sh.c
new file mode 100644
index 0000000..16966f7
--- /dev/null
+++ b/libc/arch-sh/bionic/atomics_sh.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2009 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 <pthread.h>
+#include <linux/futex.h>
+
+#define  SWAP_LOCK_COUNT  32U
+static pthread_mutex_t  _swap_locks[SWAP_LOCK_COUNT];
+
+#define  SWAP_LOCK(addr)   \
+   &_swap_locks[((unsigned)(void *)(addr) >> 3U) % SWAP_LOCK_COUNT]
+
+#if 0
+/*
+ * Only this function is moved to atomic_cmpxchg.S, and
+ * implemented with gUSA framework.
+ */
+int __atomic_cmpxchg(int old, int _new, volatile int *ptr)
+{
+    int result;
+    pthread_mutex_t *lock = SWAP_LOCK(ptr);
+
+    pthread_mutex_lock(lock);
+
+    if (*ptr == old) {
+        *ptr  = _new;
+        result = 0;
+    } else {
+        result = 1;
+    }
+    pthread_mutex_unlock(lock);
+    return result;
+}
+#else
+extern int __atomic_cmpxchg(int old, int _new, volatile int *ptr);
+#endif
+
+int __atomic_swap(int _new, volatile int *ptr)
+{
+    int oldValue;
+    do {
+        oldValue = *ptr;
+    } while (__atomic_cmpxchg(oldValue, _new, ptr));
+    return oldValue;
+}
+
+int __atomic_dec(volatile int *ptr)
+{
+    int oldValue;
+    do {
+        oldValue = *ptr;
+    } while (__atomic_cmpxchg(oldValue, oldValue-1, ptr));
+    return oldValue;
+}
+
+int __atomic_inc(volatile int *ptr)
+{
+    int32_t oldValue;
+    do {
+        oldValue = *ptr;
+    } while (__atomic_cmpxchg(oldValue, oldValue+1, ptr));
+    return oldValue;
+}
+
+extern int futex(volatile void *, int, int, void *, void *, int);
+
+int __futex_wait(volatile void *ftx, int val, const struct timespec *timeout)
+{
+    return futex(ftx, FUTEX_WAIT, val, (void *)timeout, NULL, 0);
+}
+
+int __futex_wake(volatile void *ftx, int count)
+{
+    return futex(ftx, FUTEX_WAKE, count, NULL, NULL, 0);
+}
diff --git a/libc/arch-sh/bionic/bzero.S b/libc/arch-sh/bionic/bzero.S
new file mode 100644
index 0000000..ca8bed4
--- /dev/null
+++ b/libc/arch-sh/bionic/bzero.S
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+#define BZERO
+#include "memset.S"
diff --git a/libc/arch-sh/bionic/clone.S b/libc/arch-sh/bionic/clone.S
new file mode 100644
index 0000000..0bbaecb
--- /dev/null
+++ b/libc/arch-sh/bionic/clone.S
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2009 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/linux-syscalls.h>
+
+.text
+.type   __pthread_clone, @function
+.globl  __pthread_clone
+.align  4
+
+__pthread_clone:
+    /* insert the args onto the new stack */
+    mov     r5, r0
+    mov.l   r4, @-r0    /* func */
+    mov.l   r7, @-r0    /* arg */
+
+    /* do the system call */
+    mov     r6, r4      /* Set clone_flags. new sp is ready in r5. */
+    mov.l   0f, r3
+    trapa   #(4 + 0x10)
+
+    /* check error */
+    cmp/pz  r0
+    bf      __error
+
+    /* check if parent or child */
+    cmp/pl  r0
+    bt      __return
+
+    /* prepare args for __thread_entry */
+    mov     #8, r1
+    sub     r1, r15     /* -8 */
+    mov.l   @r15+, r5   /* +4 */ /* arg */
+    mov.l   @r15+, r4   /* +4 */ /* func */
+    mov     r15, r6              /* tls */
+
+    /* jump to __thread_entry */
+    mov.l   1f, r0
+    jmp @r0
+    nop
+
+__error:
+    mov     #-1, r0
+__return:
+    rts
+    nop
+
+    .align 2
+0:  .long   __NR_clone
+1:  .long   __thread_entry
diff --git a/libc/arch-sh/bionic/crtbegin_dynamic.S b/libc/arch-sh/bionic/crtbegin_dynamic.S
new file mode 100644
index 0000000..dc485dd
--- /dev/null
+++ b/libc/arch-sh/bionic/crtbegin_dynamic.S
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+.text
+.align  4
+.type   _start,#function
+.globl  _start
+
+# this is the small startup code that is first run when
+# any executable that is statically-linked with Bionic
+# runs.
+#
+# it's purpose is to call __libc_init with appropriate
+# arguments, which are:
+#
+#    - the address of the raw data block setup by the Linux
+#      kernel ELF loader
+#
+#    - address of an "onexit" function, not used on any
+#      platform supported by Bionic
+#
+#    - address of the "main" function of the program. We
+#      can't hard-code it in the adr pseudo instruction
+#      so we use a tiny trampoline that will get relocated
+#      by the dynamic linker before this code runs
+#
+#    - address of the constructor list
+#
+_start:
+    mov     r15, r4
+    mov     #0, r5
+    mov.l   0f, r6
+    mova    2f, r0
+    mov     r0, r7
+    mov.l   1f, r0
+    jmp     @r0
+    nop
+
+    .balign 4
+0:  .long   main
+1:  .long   __libc_init
+2:  .long   __PREINIT_ARRAY__
+    .long   __INIT_ARRAY__
+    .long   __FINI_ARRAY__
+    .long   __CTOR_LIST__
+
+# the .ctors section contains a list of pointers to "constructor"
+# functions that need to be called in order during C library initialization,
+# just before the program is being run. This is a C++ requirement
+#
+# the last entry shall be 0, and is defined in crtend.S
+#
+    .section .preinit_array, "aw"
+    .globl __PREINIT_ARRAY__
+__PREINIT_ARRAY__:
+    .long -1
+
+    .section .init_array, "aw"
+    .globl __INIT_ARRAY__
+__INIT_ARRAY__:
+    .long -1
+
+    .section .fini_array, "aw"
+    .globl __FINI_ARRAY__
+__FINI_ARRAY__:
+    .long -1
+
+    .section .ctors, "aw"
+    .globl __CTOR_LIST__
+__CTOR_LIST__:
+    .long -1
diff --git a/libc/arch-sh/bionic/crtbegin_static.S b/libc/arch-sh/bionic/crtbegin_static.S
new file mode 100644
index 0000000..97db1e4
--- /dev/null
+++ b/libc/arch-sh/bionic/crtbegin_static.S
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+.text
+.align  4
+.type   _start,#function
+.globl  _start
+
+# this is the small startup code that is first run when
+# any executable that is statically-linked with Bionic
+# runs.
+#
+# it's purpose is to call __libc_init with appropriate
+# arguments, which are:
+#
+#    - the address of the raw data block setup by the Linux
+#      kernel ELF loader
+#
+#    - address of an "onexit" function, not used on any
+#      platform supported by Bionic
+#
+#    - address of the "main" function of the program. We
+#      can't hard-code it in the adr pseudo instruction
+#      so we use a tiny trampoline that will get relocated
+#      by the dynamic linker before this code runs
+#
+#    - address of the constructor list
+#
+_start:
+    mov     r15, r4
+    mov     #0, r5
+    mov.l   0f, r6
+    mova    2f, r0
+    mov     r0, r7
+    mov.l   1f, r0
+    jmp     @r0
+    nop
+
+    .balign 4
+0:  .long   main
+1:  .long   __libc_init
+2:  .long   __PREINIT_ARRAY__
+    .long   __INIT_ARRAY__
+    .long   __FINI_ARRAY__
+    .long   __CTOR_LIST__
+
+# the .ctors section contains a list of pointers to "constructor"
+# functions that need to be called in order during C library initialization,
+# just before the program is being run. This is a C++ requirement
+#
+# the last entry shall be 0, and is defined in crtend.S
+#
+    .section .preinit_array, "aw"
+    .globl __PREINIT_ARRAY__
+__PREINIT_ARRAY__:
+    .long -1
+
+    .section .init_array, "aw"
+    .globl __INIT_ARRAY__
+__INIT_ARRAY__:
+    .long -1
+
+    .section .fini_array, "aw"
+    .globl __FINI_ARRAY__
+__FINI_ARRAY__:
+    .long -1
+
+    .section .ctors, "aw"
+    .globl __CTOR_LIST__
+__CTOR_LIST__:
+    .long -1
+
diff --git a/libc/arch-sh/bionic/crtend.S b/libc/arch-sh/bionic/crtend.S
new file mode 100644
index 0000000..4ced3aa
--- /dev/null
+++ b/libc/arch-sh/bionic/crtend.S
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+    .section .preinit_array, "aw"
+    .long 0
+
+    .section .init_array, "aw"
+    .long 0
+
+    .section .fini_array, "aw"
+    .long 0
+
+    .section .ctors, "aw"
+    .long 0
diff --git a/libc/arch-sh/bionic/ffs.S b/libc/arch-sh/bionic/ffs.S
new file mode 100644
index 0000000..733694b
--- /dev/null
+++ b/libc/arch-sh/bionic/ffs.S
@@ -0,0 +1,103 @@
+/*	$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:50 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by ITOH Yasufumi.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the NetBSD
+ *	Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+	RCSID("$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:50 christos Exp $")
+#endif
+
+/*
+ * ffs - find first bit set
+ *
+ * This code makes use of ``test 8bit'' and ``shift 8bit'' instructions.
+ * The remaining 8bit is tested in every 2bit.
+ */
+
+ENTRY(ffs)
+	mov	r4,r0		! using r0 specific instructions
+	tst	#0xff,r0
+	bf/s	L8bit
+	mov	#0+1,r1		! ret = 1..8
+
+	tst	r0,r0		! ffs(0) is 0
+	bt	Lzero		! testing here to accelerate ret=1..8 cases
+
+	shlr8	r0
+	tst	#0xff,r0
+	bf/s	L8bit
+	mov	#8+1,r1		! ret = 9..16
+
+	shlr8	r0
+	tst	#0xff,r0
+	bf/s	L8bit
+	mov	#16+1,r1	! ret = 17..24
+
+	shlr8	r0
+	mov	#24+1,r1	! ret = 25..32
+
+L8bit:
+	tst	#0x0f,r0
+	bt	4f
+
+	tst	#0x03,r0
+	bt	2f
+	tst	#0x01,r0	! not bit 0 -> T
+	mov	#0,r0
+	rts
+	 addc	r1,r0		! 0 + r1 + T -> r0
+
+2:	tst	#0x04,r0
+	mov	#2,r0
+	rts
+	 addc	r1,r0
+
+4:	tst	#0x30,r0
+	bt	6f
+	tst	#0x10,r0
+	mov	#4,r0
+	rts
+	 addc	r1,r0
+
+6:	tst	#0x40,r0
+	mov	#6,r0
+	rts
+	 addc	r1,r0
+
+Lzero:	rts
+	 nop
diff --git a/libc/arch-sh/bionic/memcpy.S b/libc/arch-sh/bionic/memcpy.S
new file mode 100644
index 0000000..9d1b897
--- /dev/null
+++ b/libc/arch-sh/bionic/memcpy.S
@@ -0,0 +1,268 @@
+/*	$OpenBSD: memcpy.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $	*/
+/*	$NetBSD: memcpy.S,v 1.2 2006/04/22 23:53:47 uwe Exp $	*/
+
+/*
+ * Copyright (c) 2000 SHIMIZU Ryo <ryo@misakimix.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <machine/asm.h>
+
+#if !defined(MEMCOPY) && !defined(MEMMOVE) && !defined(BCOPY)
+#define MEMCOPY
+#endif
+
+#if defined(MEMCOPY) || defined(MEMMOVE)
+#define	REG_DST0	r3
+#define	REG_SRC		r5
+#define	REG_DST		r4
+#else
+#define	REG_SRC		r4
+#define	REG_DST		r5
+#endif
+
+#define	REG_LEN		r6
+
+#if defined(MEMCOPY)
+ENTRY(memcpy)
+#elif defined(MEMMOVE)
+ENTRY(memmove)
+#elif defined(BCOPY)
+ENTRY(bcopy)
+#endif
+#ifdef REG_DST0
+	mov	REG_DST,REG_DST0
+#endif
+	cmp/eq	REG_DST,REG_SRC	/* if ( src == dst ) return; */
+	bt/s	bcopy_return
+	cmp/hi	REG_DST,REG_SRC
+	bf/s	bcopy_overlap
+
+	mov	REG_SRC,r0
+	xor	REG_DST,r0
+	and	#3,r0
+	mov	r0,r1
+	tst	r0,r0		/* (src ^ dst) & 3         */
+	bf/s	word_align
+
+longword_align:
+	tst	REG_LEN,REG_LEN	/* if ( len==0 ) return;   */
+	bt/s	bcopy_return
+
+
+	mov	REG_SRC,r0
+	tst	#1,r0		/* if ( src & 1 )          */
+	bt	1f
+	mov.b	@REG_SRC+,r0	/*    *dst++ = *src++;     */
+	add	#-1,REG_LEN
+	mov.b	r0,@REG_DST
+	add	#1,REG_DST
+1:
+
+
+	mov	#1,r0
+	cmp/hi	r0,REG_LEN	/* if ( (len > 1) &&       */
+	bf/s	1f
+	mov	REG_SRC,r0
+	tst	#2,r0		/*      (src & 2) {        */
+	bt	1f
+	mov.w	@REG_SRC+,r0	/*        *((unsigned short*)dst)++ = *((unsigned short*)src)++; */
+	add	#-2,REG_LEN	/*        len -= 2;                                              */
+	mov.w	r0,@REG_DST
+	add	#2,REG_DST	/* }                       */
+1:
+
+
+	mov	#3,r1
+	cmp/hi	r1,REG_LEN	/* while ( len > 3 ) {     */
+	bf/s	no_align_delay
+	tst	REG_LEN,REG_LEN
+2:
+	mov.l	@REG_SRC+,r0	/*   *((unsigned long*)dst)++ = *((unsigned long*)src)++;        */
+	add	#-4,REG_LEN	/*   len -= 4;                                                   */
+	mov.l	r0,@REG_DST
+	cmp/hi	r1,REG_LEN
+	bt/s	2b
+	add	#4,REG_DST	/* }                       */
+
+	bra	no_align_delay
+	tst	REG_LEN,REG_LEN
+
+
+word_align:
+	mov	r1,r0
+	tst	#1,r0
+	bf/s	no_align_delay
+	tst	REG_LEN,REG_LEN	/* if ( len == 0 ) return; */
+	bt	bcopy_return
+
+
+	mov	REG_SRC,r0	/* if ( src & 1 )          */
+	tst	#1,r0
+	bt	1f
+	mov.b	@REG_SRC+,r0	/*    *dst++ = *src++;     */
+	add	#-1,REG_LEN
+	mov.b	r0,@REG_DST
+	add	#1,REG_DST
+1:
+
+
+	mov	#1,r1
+	cmp/hi	r1,REG_LEN	/* while ( len > 1 ) {     */
+	bf/s	no_align_delay
+	tst	REG_LEN,REG_LEN
+2:
+	mov.w	@REG_SRC+,r0	/*   *((unsigned short*)dst)++ = *((unsigned short*)src)++;      */
+	add	#-2,REG_LEN	/*   len -= 2;                                                   */
+	mov.w	r0,@REG_DST
+	cmp/hi	r1,REG_LEN
+	bt/s	2b
+	add	#2,REG_DST	/* }                       */
+
+
+no_align:
+	tst	REG_LEN,REG_LEN	/* while ( len!= ) {       */
+no_align_delay:
+	bt	bcopy_return
+1:
+	mov.b	@REG_SRC+,r0	/*    *dst++ = *src++;     */
+	add	#-1,REG_LEN	/*    len--;               */
+	mov.b	r0,@REG_DST
+	tst	REG_LEN,REG_LEN
+	bf/s	1b
+	add	#1,REG_DST	/* }                       */
+bcopy_return:
+	rts
+#ifdef REG_DST0
+	mov	REG_DST0,r0
+#else
+	nop
+#endif
+
+
+bcopy_overlap:
+	add	REG_LEN,REG_SRC
+	add	REG_LEN,REG_DST
+
+	mov	REG_SRC,r0
+	xor	REG_DST,r0
+	and	#3,r0
+	mov	r0,r1
+	tst	r0,r0		/* (src ^ dst) & 3         */
+	bf/s	ov_word_align
+
+ov_longword_align:
+	tst	REG_LEN,REG_LEN	/* if ( len==0 ) return;   */
+	bt/s	bcopy_return
+
+
+	mov	REG_SRC,r0
+	tst	#1,r0		/* if ( src & 1 )          */
+	bt	1f
+	add	#-1,REG_SRC	/*    *--dst = *--src;     */
+	mov.b	@REG_SRC,r0
+	mov.b	r0,@-REG_DST
+	add	#-1,REG_LEN
+1:
+
+
+	mov	#1,r0
+	cmp/hi	r0,REG_LEN	/* if ( (len > 1) &&       */
+	bf/s	1f
+	mov	REG_SRC,r0
+	tst	#2,r0		/*      (src & 2) {        */
+	bt	1f
+	add	#-2,REG_SRC	/*        *--((unsigned short*)dst) = *--((unsigned short*)src); */
+	mov.w	@REG_SRC,r0
+	add	#-2,REG_LEN	/*        len -= 2;                                              */
+	mov.w	r0,@-REG_DST	/* }                       */
+1:
+
+
+	mov	#3,r1
+	cmp/hi	r1,REG_LEN	/* while ( len > 3 ) {     */
+	bf/s	ov_no_align_delay
+	tst	REG_LEN,REG_LEN
+2:
+	add	#-4,REG_SRC
+	mov.l	@REG_SRC,r0	/*   *((unsigned long*)dst)++ = *((unsigned long*)src)++;        */
+	add	#-4,REG_LEN	/*   len -= 4;                                                   */
+	cmp/hi	r1,REG_LEN
+	bt/s	2b
+	mov.l	r0,@-REG_DST	/* }                       */
+
+	bra	ov_no_align_delay
+	tst	REG_LEN,REG_LEN
+
+
+ov_word_align:
+	mov	r1,r0
+	tst	#1,r0
+	bf/s	ov_no_align_delay
+	tst	REG_LEN,REG_LEN	/* if ( len == 0 ) return; */
+	bt	bcopy_return
+
+
+	mov	REG_SRC,r0	/* if ( src & 1 )          */
+	tst	#1,r0
+	bt	1f
+	add	#-1,REG_SRC
+	mov.b	@REG_SRC,r0	/*    *--dst = *--src;     */
+	add	#-1,REG_LEN
+	mov.b	r0,@-REG_DST
+1:
+
+
+	mov	#1,r1
+	cmp/hi	r1,REG_LEN	/* while ( len > 1 ) {     */
+	bf/s	ov_no_align_delay
+	tst	REG_LEN,REG_LEN
+2:
+	add	#-2,REG_SRC
+	mov.w	@REG_SRC,r0	/*   *--((unsigned short*)dst) = *--((unsigned short*)src);      */
+	add	#-2,REG_LEN	/*   len -= 2;                                                   */
+	cmp/hi	r1,REG_LEN
+	bt/s	2b
+	mov.w	r0,@-REG_DST	/* }                       */
+
+
+ov_no_align:
+	tst	REG_LEN,REG_LEN	/* while ( len!= ) {       */
+ov_no_align_delay:
+	bt	9f
+1:
+	add	#-1,REG_SRC
+	mov.b	@REG_SRC,r0	/*    *--dst = *--src;     */
+	add	#-1,REG_LEN	/*    len--;               */
+	tst	REG_LEN,REG_LEN
+	bf/s	1b
+	mov.b	r0,@-REG_DST	/* }                       */
+9:
+	rts
+#ifdef REG_DST0
+	mov	REG_DST0,r0
+#else
+	nop
+#endif
diff --git a/libc/arch-sh/bionic/memmove.S b/libc/arch-sh/bionic/memmove.S
new file mode 100644
index 0000000..023fc10
--- /dev/null
+++ b/libc/arch-sh/bionic/memmove.S
@@ -0,0 +1,5 @@
+/*	$OpenBSD: memmove.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $	*/
+/*	$NetBSD: memmove.S,v 1.2 2006/04/22 23:53:47 uwe Exp $	*/
+
+#define MEMMOVE
+#include "memcpy.S"
diff --git a/libc/arch-sh/bionic/memset.S b/libc/arch-sh/bionic/memset.S
new file mode 100644
index 0000000..73b0d06
--- /dev/null
+++ b/libc/arch-sh/bionic/memset.S
@@ -0,0 +1,295 @@
+/*	$OpenBSD: memset.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $	*/
+/*	$NetBSD: memset.S,v 1.1 2005/12/20 19:28:50 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2002 SHIMIZU Ryo.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <machine/asm.h>
+
+#define	REG_PTR				r0
+#define	REG_TMP1			r1
+
+#ifdef BZERO
+# define	REG_C			r2
+# define	REG_DST			r4
+# define	REG_LEN			r5
+#else
+# define	REG_DST0		r3
+# define	REG_DST			r4
+# define	REG_C			r5
+# define	REG_LEN			r6
+#endif
+
+#ifdef BZERO
+ENTRY(bzero)
+#else
+ENTRY(memset)
+	mov	REG_DST,REG_DST0	/* for return value */
+#endif
+	/* small amount to fill ? */
+	mov	#28,REG_TMP1
+	cmp/hs	REG_TMP1,REG_LEN	/* if (len >= 28) goto large; */
+	bt/s	large
+	mov	#12,REG_TMP1		/* if (len >= 12) goto small; */
+	cmp/hs	REG_TMP1,REG_LEN
+	bt/s	small
+#ifdef BZERO
+	mov	#0,REG_C
+#endif
+	/* very little fill (0 ~ 11 bytes) */
+	tst	REG_LEN,REG_LEN
+	add	REG_DST,REG_LEN
+	bt/s	done
+	add	#1,REG_DST
+
+	/* unroll 4 loops */
+	cmp/eq	REG_DST,REG_LEN
+1:	mov.b	REG_C,@-REG_LEN
+	bt/s	done
+	cmp/eq	REG_DST,REG_LEN
+	mov.b	REG_C,@-REG_LEN
+	bt/s	done
+	cmp/eq	REG_DST,REG_LEN
+	mov.b	REG_C,@-REG_LEN
+	bt/s	done
+	cmp/eq	REG_DST,REG_LEN
+	mov.b	REG_C,@-REG_LEN
+	bf/s	1b
+	cmp/eq	REG_DST,REG_LEN
+done:
+#ifdef BZERO
+	rts
+	nop
+#else
+	rts
+	mov	REG_DST0,r0
+#endif
+
+
+small:
+	mov	REG_DST,r0
+	tst	#1,r0
+	bt/s	small_aligned
+	mov	REG_DST,REG_TMP1
+	shll	REG_LEN
+	mova	1f,r0			/* 1f must be 4bytes aligned! */
+	add	#16,REG_TMP1		/* REG_TMP1 = dst+16; */
+	sub	REG_LEN,r0
+	jmp	@r0
+	mov	REG_C,r0
+
+	.align	2
+	mov.b	r0,@(15,REG_TMP1)
+	mov.b	r0,@(14,REG_TMP1)
+	mov.b	r0,@(13,REG_TMP1)
+	mov.b	r0,@(12,REG_TMP1)
+	mov.b	r0,@(11,REG_TMP1)
+	mov.b	r0,@(10,REG_TMP1)
+	mov.b	r0,@(9,REG_TMP1)
+	mov.b	r0,@(8,REG_TMP1)
+	mov.b	r0,@(7,REG_TMP1)
+	mov.b	r0,@(6,REG_TMP1)
+	mov.b	r0,@(5,REG_TMP1)
+	mov.b	r0,@(4,REG_TMP1)
+	mov.b	r0,@(3,REG_TMP1)
+	mov.b	r0,@(2,REG_TMP1)
+	mov.b	r0,@(1,REG_TMP1)
+	mov.b	r0,@REG_TMP1
+	mov.b	r0,@(15,REG_DST)
+	mov.b	r0,@(14,REG_DST)
+	mov.b	r0,@(13,REG_DST)
+	mov.b	r0,@(12,REG_DST)
+	mov.b	r0,@(11,REG_DST)
+	mov.b	r0,@(10,REG_DST)
+	mov.b	r0,@(9,REG_DST)
+	mov.b	r0,@(8,REG_DST)
+	mov.b	r0,@(7,REG_DST)
+	mov.b	r0,@(6,REG_DST)
+	mov.b	r0,@(5,REG_DST)
+	mov.b	r0,@(4,REG_DST)
+	mov.b	r0,@(3,REG_DST)
+	mov.b	r0,@(2,REG_DST)
+	mov.b	r0,@(1,REG_DST)
+#ifdef BZERO
+	rts
+1:	mov.b	r0,@REG_DST
+#else
+	mov.b	r0,@REG_DST
+1:	rts
+	mov	REG_DST0,r0
+#endif
+
+
+/* 2 bytes aligned small fill */
+small_aligned:
+#ifndef BZERO
+	extu.b	REG_C,REG_TMP1		/* REG_C = ??????xx, REG_TMP1 = ????00xx */
+	shll8	REG_C			/* REG_C = ????xx00, REG_TMP1 = ????00xx */
+	or	REG_TMP1,REG_C		/* REG_C = ????xxxx */
+#endif
+
+	mov	REG_LEN,r0
+	tst	#1,r0			/* len is aligned? */
+	bt/s	1f
+	add	#-1,r0
+	mov.b	REG_C,@(r0,REG_DST)	/* fill last a byte */
+	mov	r0,REG_LEN
+1:
+
+	mova	1f,r0			/* 1f must be 4bytes aligned! */
+	sub	REG_LEN,r0
+	jmp	@r0
+	mov	REG_C,r0
+
+	.align	2
+	mov.w	r0,@(30,REG_DST)
+	mov.w	r0,@(28,REG_DST)
+	mov.w	r0,@(26,REG_DST)
+	mov.w	r0,@(24,REG_DST)
+	mov.w	r0,@(22,REG_DST)
+	mov.w	r0,@(20,REG_DST)
+	mov.w	r0,@(18,REG_DST)
+	mov.w	r0,@(16,REG_DST)
+	mov.w	r0,@(14,REG_DST)
+	mov.w	r0,@(12,REG_DST)
+	mov.w	r0,@(10,REG_DST)
+	mov.w	r0,@(8,REG_DST)
+	mov.w	r0,@(6,REG_DST)
+	mov.w	r0,@(4,REG_DST)
+	mov.w	r0,@(2,REG_DST)
+#ifdef BZERO
+	rts
+1:	mov.w	r0,@REG_DST
+#else
+	mov.w	r0,@REG_DST
+1:	rts
+	mov	REG_DST0,r0
+#endif
+
+
+
+	.align	2
+large:
+#ifdef BZERO
+	mov	#0,REG_C
+#else
+	extu.b	REG_C,REG_TMP1		/* REG_C = ??????xx, REG_TMP1 = ????00xx */
+	shll8	REG_C			/* REG_C = ????xx00, REG_TMP1 = ????00xx */
+	or	REG_C,REG_TMP1		/* REG_C = ????xx00, REG_TMP1 = ????xxxx */
+	swap.w	REG_TMP1,REG_C		/* REG_C = xxxx????, REG_TMP1 = ????xxxx */
+	xtrct	REG_TMP1,REG_C		/* REG_C = xxxxxxxx */
+#endif
+
+	mov	#3,REG_TMP1
+	tst	REG_TMP1,REG_DST
+	mov	REG_DST,REG_PTR
+	bf/s	unaligned_dst
+	add	REG_LEN,REG_PTR		/* REG_PTR = dst + len; */
+	tst	REG_TMP1,REG_LEN
+	bf/s	unaligned_len
+
+aligned:
+	/* fill 32*n bytes */
+	mov	#32,REG_TMP1
+	cmp/hi	REG_LEN,REG_TMP1
+	bt	9f
+	.align	2
+1:	sub	REG_TMP1,REG_PTR
+	mov.l	REG_C,@REG_PTR
+	sub	REG_TMP1,REG_LEN
+	mov.l	REG_C,@(4,REG_PTR)
+	cmp/hi	REG_LEN,REG_TMP1
+	mov.l	REG_C,@(8,REG_PTR)
+	mov.l	REG_C,@(12,REG_PTR)
+	mov.l	REG_C,@(16,REG_PTR)
+	mov.l	REG_C,@(20,REG_PTR)
+	mov.l	REG_C,@(24,REG_PTR)
+	bf/s	1b
+	mov.l	REG_C,@(28,REG_PTR)
+9:
+
+	/* fill left 4*n bytes */
+	cmp/eq	REG_DST,REG_PTR
+	bt	9f
+	add	#4,REG_DST
+	cmp/eq	REG_DST,REG_PTR
+1:	mov.l	REG_C,@-REG_PTR
+	bt/s	9f
+	cmp/eq	REG_DST,REG_PTR
+	mov.l	REG_C,@-REG_PTR
+	bt/s	9f
+	cmp/eq	REG_DST,REG_PTR
+	mov.l	REG_C,@-REG_PTR
+	bt/s	9f
+	cmp/eq	REG_DST,REG_PTR
+	mov.l	REG_C,@-REG_PTR
+	bf/s	1b
+	cmp/eq	REG_DST,REG_PTR
+9:
+#ifdef BZERO
+	rts
+	nop
+#else
+	rts
+	mov	REG_DST0,r0
+#endif
+
+
+unaligned_dst:
+	mov	#1,REG_TMP1
+	tst	REG_TMP1,REG_DST	/* if (dst & 1) {               */
+	add	#1,REG_TMP1
+	bt/s	2f
+	tst	REG_TMP1,REG_DST
+	mov.b	REG_C,@REG_DST		/*   *dst++ = c;                */
+	add	#1,REG_DST
+	tst	REG_TMP1,REG_DST
+2:					/* }                            */
+					/* if (dst & 2) {               */
+	bt	4f
+	mov.w	REG_C,@REG_DST		/*   *(u_int16_t*)dst++ = c;    */
+	add	#2,REG_DST
+4:					/* }                            */
+
+
+	tst	#3,REG_PTR		/* if (ptr & 3) {               */
+	bt/s	4f			/*                              */
+unaligned_len:
+	tst	#1,REG_PTR		/*   if (ptr & 1) {             */
+	bt/s	2f
+	tst	#2,REG_PTR
+	mov.b	REG_C,@-REG_PTR		/*     --ptr = c;               */
+2:					/*   }                          */
+					/*   if (ptr & 2) {             */
+	bt	4f
+	mov.w	REG_C,@-REG_PTR		/*     *--(u_int16_t*)ptr = c;  */
+4:					/*   }                          */
+					/* }                            */
+
+	mov	REG_PTR,REG_LEN
+	bra	aligned
+	sub	REG_DST,REG_LEN
+
diff --git a/libc/arch-sh/bionic/pipe.S b/libc/arch-sh/bionic/pipe.S
new file mode 100644
index 0000000..936da2d
--- /dev/null
+++ b/libc/arch-sh/bionic/pipe.S
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 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/linux-syscalls.h>
+
+.text
+.type   pipe, @function
+.globl  pipe
+.align  4
+
+pipe:
+    /* invoke trap */
+    mov.l   0f, r3          /* trap num */
+    trapa   #(0 + 0x10)
+
+
+    /* check return value */
+    cmp/pz  r0
+    bt      setfds
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+    bra     end
+    nop
+setfds:
+    mov.l   r0, @r4
+    add     #4, r4
+    mov.l   r1, @r4
+end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_pipe
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/bionic/setjmp.S b/libc/arch-sh/bionic/setjmp.S
new file mode 100644
index 0000000..67f3397
--- /dev/null
+++ b/libc/arch-sh/bionic/setjmp.S
@@ -0,0 +1,167 @@
+/*	$OpenBSD: setjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
+/*	$NetBSD: setjmp.S,v 1.10 2006/01/05 19:21:37 uwe Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	from: @(#)setjmp.s	5.1 (Berkeley) 4/23/90
+ */
+
+#include <machine/asm.h>
+#include <machine/setjmp.h>
+
+/*
+ * C library -- setjmp, longjmp
+ *
+ *	longjmp(a,v)
+ * will generate a "return(v)" from the last call to
+ *	setjmp(a)
+ * by restoring registers from the stack.
+ * The previous signal state is restored.
+ */
+
+ENTRY(setjmp)
+	PIC_PROLOGUE(.L_got_1)
+	sts.l	pr,	@-sp
+	mov.l	r4,	@-sp
+
+	mov.l	.L_sigprocmask_1, r0
+	mov	r4,	r6
+	mov	#1,	r4		/* how = SIG_BLOCK */
+	mov	#0,	r5		/* new = NULL */
+1:	CALL	r0
+	 add	#4,	r6		/* old = &sigmask */
+
+	mov.l	@sp+,	r4
+	lds.l	@sp+,	pr
+	PIC_EPILOGUE
+
+	/* identical to _setjmp except that the first word is non-zero */
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+	add	#(_JBLEN * 4), r4
+	sts	fpscr,	r1
+	xor	r0,	r0
+	mov.l	r1,	@-r4
+	lds	r0,	fpscr
+	sts.l	fpul,	@-r4
+	fmov.s	fr15,	@-r4
+	fmov.s	fr14,	@-r4
+	fmov.s	fr13,	@-r4
+	fmov.s	fr12,	@-r4
+	frchg
+	fmov.s	fr15,	@-r4
+	fmov.s	fr14,	@-r4
+	fmov.s	fr13,	@-r4
+	fmov.s	fr12,	@-r4
+	lds	r1,	fpscr
+#else
+	add	#((_JBLEN - 10) * 4), r4
+#endif
+	sts.l	mach,	@-r4
+	sts.l	macl,	@-r4
+	mov.l	r15,	@-r4
+	mov.l	r14,	@-r4
+	mov.l	r13,	@-r4
+	mov.l	r12,	@-r4
+	mov.l	r11,	@-r4
+	mov.l	r10,	@-r4
+	mov.l	r9,	@-r4
+	mov.l	r8,	@-r4
+	sts.l	pr,	@-r4
+	add	#-4,	r4		/* skip signal mask */
+	mov	#1,	r0
+	mov.l	r0,	@-r4		/* has signal mask */
+	rts
+	 xor	r0,	r0
+
+	.align	2
+.L_got_1:		PIC_GOT_DATUM
+.L_sigprocmask_1:	CALL_DATUM(_C_LABEL(sigprocmask), 1b)
+	SET_ENTRY_SIZE(setjmp)
+
+ENTRY(longjmp)
+	/* we won't return here, so we don't need to save pr and r12 */
+	PIC_PROLOGUE_NOSAVE(.L_got_2)
+	mov.l	r5,	@-sp
+	mov.l	r4,	@-sp
+
+	mov.l	.L_sigprocmask_2, r0
+	mov	r4,	r5
+	mov	#3,	r4		/* how = SIG_SETMASK */
+	add	#4,	r5		/* new = &sigmask */
+1:	CALL	r0
+	 mov	#0,	r6		/* old = NULL */
+
+	mov.l	@sp+,	r4
+	mov.l	@sp+,	r5
+
+	/* identical to _longjmp */
+	add	#8,	r4
+	lds.l	@r4+,	pr
+	mov.l	@r4+,	r8
+	mov.l	@r4+,	r9
+	mov.l	@r4+,	r10
+	mov.l	@r4+,	r11
+	mov.l	@r4+,	r12
+	mov.l	@r4+,	r13
+	mov.l	@r4+,	r14
+	mov.l	@r4+,	r15
+	lds.l	@r4+,	macl
+	lds.l	@r4+,	mach
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+	xor	r0, 	r0
+	lds	r0,	fpscr
+	frchg
+	fmov.s	@r4+,	fr12
+	fmov.s	@r4+,	fr13
+	fmov.s	@r4+,	fr14
+	fmov.s	@r4+,	fr15
+	frchg
+	fmov.s	@r4+,	fr12
+	fmov.s	@r4+,	fr13
+	fmov.s	@r4+,	fr14
+	fmov.s	@r4+,	fr15
+	lds.l	@r4+,	fpul
+	lds.l	@r4+,	fpscr
+#endif
+
+	mov	r5,	r0
+	tst	r0,	r0	/* make sure return value is non-zero */
+	bf	.L0
+	add	#1,	r0
+.L0:
+	rts
+	 nop
+
+	.align	2
+.L_got_2:		PIC_GOT_DATUM
+.L_sigprocmask_2:	CALL_DATUM(_C_LABEL(sigprocmask), 1b)
+	SET_ENTRY_SIZE(longjmp)
diff --git a/libc/arch-sh/bionic/sigsetjmp.S b/libc/arch-sh/bionic/sigsetjmp.S
new file mode 100644
index 0000000..f88913a
--- /dev/null
+++ b/libc/arch-sh/bionic/sigsetjmp.S
@@ -0,0 +1,166 @@
+/*	$OpenBSD: sigsetjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
+/*	$NetBSD: sigsetjmp.S,v 1.9 2006/01/05 19:21:37 uwe Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	from: @(#)setjmp.s	5.1 (Berkeley) 4/23/90
+ */
+
+#include <machine/asm.h>
+#include <machine/setjmp.h>
+
+ENTRY(sigsetjmp)
+	tst	r5,	r5		/* if (savemask == 0) */
+	bt	2f
+
+	/* identical to setjmp */
+	PIC_PROLOGUE(.L_got_1)
+	sts.l	pr,	@-sp
+	mov.l	r4,	@-sp
+	mov.l	r5,	@-sp
+
+	mov.l	.L_sigprocmask_1, r0
+	mov	r4,	r6
+	mov	#1,	r4		/* how = SIG_BLOCK */
+	mov	#0,	r5		/* new = NULL */
+1:	CALL	r0
+	 add	#4,	r6		/* old = &sigmask */
+
+	mov.l	@sp+,	r5
+	mov.l	@sp+,	r4
+	lds.l	@sp+,	pr
+	PIC_EPILOGUE
+
+2:	/* identical to _setjmp except that first word is in r5 */
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+	add	#(_JBLEN * 4), r4
+	sts	fpscr,	r1
+	xor	r0,	r0
+	mov.l	r1,	@-r4
+	lds	r0,	fpscr
+	sts.l	fpul,	@-r4
+	fmov.s	fr15,	@-r4
+	fmov.s	fr14,	@-r4
+	fmov.s	fr13,	@-r4
+	fmov.s	fr12,	@-r4
+	frchg
+	fmov.s	fr15,	@-r4
+	fmov.s	fr14,	@-r4
+	fmov.s	fr13,	@-r4
+	fmov.s	fr12,	@-r4
+	lds	r1,	fpscr
+#else
+	add	#((_JBLEN - 10) * 4), r4
+#endif
+	sts.l	mach,	@-r4
+	sts.l	macl,	@-r4
+	mov.l	r15,	@-r4
+	mov.l	r14,	@-r4
+	mov.l	r13,	@-r4
+	mov.l	r12,	@-r4
+	mov.l	r11,	@-r4
+	mov.l	r10,	@-r4
+	mov.l	r9,	@-r4
+	mov.l	r8,	@-r4
+	sts.l	pr,	@-r4
+	add	#-4,	r4		/* skip signal mask */
+	mov.l	r5,	@-r4		/* has signal mask? */
+	rts
+	 xor	r0,	r0
+
+	.align	2
+.L_got_1:		PIC_GOT_DATUM
+.L_sigprocmask_1:	CALL_DATUM(_C_LABEL(sigprocmask), 1b)
+	SET_ENTRY_SIZE(sigsetjmp)
+
+ENTRY(siglongjmp)
+	mov.l	@r4+,	r0
+	tst	r0,	r0
+	bt	2f			/* if no mask */
+
+	/* identical to longjmp */
+	/* we won't return here, so we don't need to save pr and r12 */
+	PIC_PROLOGUE_NOSAVE(.L_got_2)
+	mov.l	r5,	@-sp
+	mov.l	r4,	@-sp
+
+	mov.l	.L_sigprocmask_2, r0
+	mov	r4,	r5		/* new = &sigmask */
+	mov	#3,	r4		/* how = SIG_SETMASK */
+1:	CALL	r0
+	 mov	#0,	r6		/* old = NULL */
+
+	mov.l	@sp+,	r4
+	mov.l	@sp+,	r5
+
+2:	/* identical to _longjmp */
+	add	#4,	r4
+	lds.l	@r4+,	pr
+	mov.l	@r4+,	r8
+	mov.l	@r4+,	r9
+	mov.l	@r4+,	r10
+	mov.l	@r4+,	r11
+	mov.l	@r4+,	r12
+	mov.l	@r4+,	r13
+	mov.l	@r4+,	r14
+	mov.l	@r4+,	r15
+	lds.l	@r4+,	macl
+	lds.l	@r4+,	mach
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+	xor	r0, 	r0
+	lds	r0,	fpscr
+	frchg
+	fmov.s	@r4+,	fr12
+	fmov.s	@r4+,	fr13
+	fmov.s	@r4+,	fr14
+	fmov.s	@r4+,	fr15
+	frchg
+	fmov.s	@r4+,	fr12
+	fmov.s	@r4+,	fr13
+	fmov.s	@r4+,	fr14
+	fmov.s	@r4+,	fr15
+	lds.l	@r4+,	fpul
+	lds.l	@r4+,	fpscr
+#endif
+
+	mov	r5,	r0
+	tst	r0,	r0	/* make sure return value is non-zero */
+	bf	.L0
+	add	#1,	r0
+.L0:
+	rts
+	 nop
+
+	.align	2
+.L_got_2:		PIC_GOT_DATUM
+.L_sigprocmask_2:	CALL_DATUM(_C_LABEL(sigprocmask), 1b)
+	SET_ENTRY_SIZE(siglongjmp)
diff --git a/libc/arch-sh/bionic/syscall.S b/libc/arch-sh/bionic/syscall.S
new file mode 100644
index 0000000..7e9f307
--- /dev/null
+++ b/libc/arch-sh/bionic/syscall.S
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2009 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/linux-syscalls.h>
+
+.text
+.type syscall, @function
+.globl syscall
+.align 4
+
+/*
+ * Current implementation assumes that the all syscall
+ * has maximum 7 arguments.
+ */
+syscall:
+    /* get args */
+    mov     r4, r3      /* system call number */
+    mov     r5, r4
+    mov     r6, r5
+    mov     r7, r6
+    mov.l   @r15, r7
+    mov.l   @(4, r15), r0
+    mov.l   @(8, r15), r1
+    mov.l   @(12, r15), r2
+
+    /* invoke trap */
+    trapa   #(7 + 0x10) /* assuming 7 arguments */
+
+    /* check return value */
+    cmp/pz  r0
+    bt      end
+
+    /* keep error number */
+    mov.l   r0, @-r15
+    mov.l   0f, r1
+    jsr     @r1
+    mov     r0, r4
+    mov.l   @r15+, r0
+
+end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __set_errno
diff --git a/libc/arch-sh/bionic/unwind.c b/libc/arch-sh/bionic/unwind.c
new file mode 100644
index 0000000..33ec58c
--- /dev/null
+++ b/libc/arch-sh/bionic/unwind.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+typedef long unsigned int *_Unwind_Ptr;
+
diff --git a/libc/arch-sh/include/endian.h b/libc/arch-sh/include/endian.h
new file mode 100644
index 0000000..ad10164
--- /dev/null
+++ b/libc/arch-sh/include/endian.h
@@ -0,0 +1,39 @@
+/*	$OpenBSD: endian.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
+/*	$NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $	*/
+
+/* Written by Manuel Bouyer. Public domain */
+
+#ifndef _SH_ENDIAN_H_
+#define	_SH_ENDIAN_H_
+
+#ifdef  __GNUC__
+
+#define	__swap64md	__swap64gen
+
+#define __swap16md(x) ({						\
+	uint16_t rval;							\
+									\
+	__asm volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));		\
+									\
+	rval;								\
+})
+
+#define __swap32md(x) ({						\
+	uint32_t rval;							\
+									\
+	__asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"	\
+			  : "=r"(rval) : "r"(x));			\
+									\
+	rval;								\
+})
+
+#define MD_SWAP
+
+#endif /* __GNUC_ */
+
+#define	_BYTE_ORDER _LITTLE_ENDIAN
+#include <sys/endian.h>
+
+#define	__STRICT_ALIGNMENT
+
+#endif /* !_SH_ENDIAN_H_ */
diff --git a/libc/arch-sh/include/machine/_types.h b/libc/arch-sh/include/machine/_types.h
new file mode 100644
index 0000000..6f59e21
--- /dev/null
+++ b/libc/arch-sh/include/machine/_types.h
@@ -0,0 +1,126 @@
+/*	$OpenBSD: _types.h,v 1.6 2008/07/21 20:50:55 martynas Exp $	*/
+
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	@(#)types.h	8.3 (Berkeley) 1/5/94
+ *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SH__TYPES_H_
+#define _SH__TYPES_H_
+
+#if defined(_KERNEL)
+typedef struct label_t {
+	int val[9];
+} label_t;
+#endif
+
+/* 7.18.1.1 Exact-width integer types */
+typedef	__signed char		__int8_t;
+typedef	unsigned char		__uint8_t;
+typedef	short			__int16_t;
+typedef	unsigned short		__uint16_t;
+typedef	int			__int32_t;
+typedef	unsigned int		__uint32_t;
+/* LONGLONG */
+typedef	long long		__int64_t;
+/* LONGLONG */
+typedef	unsigned long long	__uint64_t;
+
+/* 7.18.1.2 Minimum-width integer types */
+typedef	__int8_t		__int_least8_t;
+typedef	__uint8_t		__uint_least8_t;
+typedef	__int16_t		__int_least16_t;
+typedef	__uint16_t		__uint_least16_t;
+typedef	__int32_t		__int_least32_t;
+typedef	__uint32_t		__uint_least32_t;
+typedef	__int64_t		__int_least64_t;
+typedef	__uint64_t		__uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef	__int32_t		__int_fast8_t;
+typedef	__uint32_t		__uint_fast8_t;
+typedef	__int32_t		__int_fast16_t;
+typedef	__uint32_t		__uint_fast16_t;
+typedef	__int32_t		__int_fast32_t;
+typedef	__uint32_t		__uint_fast32_t;
+typedef	__int64_t		__int_fast64_t;
+typedef	__uint64_t		__uint_fast64_t;
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+typedef	long			__intptr_t;
+typedef	unsigned long		__uintptr_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+typedef	__int64_t		__intmax_t;
+typedef	__uint64_t		__uintmax_t;
+
+/* Register size */
+typedef __uint32_t		__register_t;
+
+/* VM system types */
+typedef unsigned long		__vaddr_t;
+typedef unsigned long		__paddr_t;
+typedef unsigned long		__vsize_t;
+typedef unsigned long		__psize_t;
+
+/* Standard system types */
+typedef int			__clock_t;
+typedef int			__clockid_t;
+typedef double			__double_t;
+typedef float			__float_t;
+typedef long long		__off_t;
+typedef long			__ptrdiff_t;
+#if 0
+/* cut it off for Android-SH */
+typedef	unsigned long		__size_t;
+#endif
+typedef	long			__ssize_t;
+typedef	int			__time_t;
+typedef int			__timer_t;
+#if defined(__GNUC__) && __GNUC__ >= 3
+typedef	__builtin_va_list	__va_list;
+#else
+struct __va_list_tag;
+typedef	struct __va_list_tag *	__va_list;
+#endif
+
+/* Wide character support types */
+#ifndef __cplusplus
+typedef	int			__wchar_t;
+#endif
+typedef int			__wint_t;
+typedef	int			__rune_t;
+typedef	void *			__wctrans_t;
+typedef	void *			__wctype_t;
+
+/* Feature test macros */
+#define	__HAVE_GENERIC_SOFT_INTERRUPTS
+
+#endif	/* _SH__TYPES_H_ */
diff --git a/libc/arch-sh/include/machine/asm.h b/libc/arch-sh/include/machine/asm.h
new file mode 100644
index 0000000..c659a9d
--- /dev/null
+++ b/libc/arch-sh/include/machine/asm.h
@@ -0,0 +1,217 @@
+/*	$OpenBSD: asm.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
+/*	$NetBSD: asm.h,v 1.25 2006/01/20 22:02:40 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	@(#)asm.h	5.5 (Berkeley) 5/7/91
+ */
+
+#ifndef _SH_ASM_H_
+#define	_SH_ASM_H_
+
+#ifdef __ELF__
+# define _C_LABEL(x)	x
+#else
+#ifdef __STDC__
+# define _C_LABEL(x)	_ ## x
+#else
+# define _C_LABEL(x)	_/**/x
+#endif
+#endif
+#define	_ASM_LABEL(x)	x
+
+#ifdef __STDC__
+# define __CONCAT(x,y)	x ## y
+# define __STRING(x)	#x
+#else
+# define __CONCAT(x,y)	x/**/y
+# define __STRING(x)	"x"
+#endif
+
+/* let kernels and others override entrypoint alignment */
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 2
+#endif
+
+#ifdef __ELF__
+#define	_ENTRY(x)							\
+	.text								;\
+	_ALIGN_TEXT							;\
+	.globl x							;\
+	.type x,@function						;\
+	x:
+#else /* !__ELF__ */
+#define	_ENTRY(x)							\
+	.text								;\
+	_ALIGN_TEXT							;\
+	.globl x							;\
+	x:
+#endif /* !__ELF__ */
+
+#ifdef GPROF
+#define	_PROF_PROLOGUE				  \
+	mov.l	1f,r1				; \
+	mova	2f,r0				; \
+	jmp	@r1				; \
+	 nop					; \
+	.align	2				; \
+1:	.long	__mcount			; \
+2:
+#else  /* !GPROF */
+#define	_PROF_PROLOGUE
+#endif /* !GPROF */
+
+#define	ENTRY(y)	_ENTRY(_C_LABEL(y)) _PROF_PROLOGUE
+#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
+#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)) _PROF_PROLOGUE
+
+#define SET_ENTRY_SIZE(y) \
+	.size	_C_LABEL(y), . - _C_LABEL(y)
+
+#define SET_ASENTRY_SIZE(y) \
+	.size	_ASM_LABEL(y), . - _ASM_LABEL(y)
+
+#ifdef __ELF__
+#define	ALTENTRY(name)				 \
+	.globl _C_LABEL(name)			;\
+	.type _C_LABEL(name),@function		;\
+	_C_LABEL(name):
+#else
+#define	ALTENTRY(name)				 \
+	.globl _C_LABEL(name)			;\
+	_C_LABEL(name):
+#endif
+
+
+/*
+ * Hide the gory details of PIC calls vs. normal calls.  Use as in the
+ * following example:
+ *
+ *	sts.l	pr, @-sp
+ *	PIC_PROLOGUE(.L_got, r0)	! saves old r12 on stack
+ *	...
+ *	mov.l	.L_function_1, r0
+ * 1:	CALL	r0			! each call site needs a label
+ *	 nop
+ *      ...
+ *	mov.l	.L_function_2, r0
+ * 2:	CALL	r0
+ *	 nop
+ *	...
+ *	PIC_EPILOGUE			! restores r12 from stack
+ *	lds.l	@sp+, pr		!  so call in right order 
+ *	rts
+ *	 nop
+ *
+ *	.align 2
+ * .L_got:
+ *	PIC_GOT_DATUM
+ * .L_function_1:			! if you call the same function twice
+ *	CALL_DATUM(function, 1b)	!  provide call datum for each call
+ * .L_function_2:
+ * 	CALL_DATUM(function, 2b)
+ */
+
+#ifdef PIC
+
+#define	PIC_PLT(x)	x@PLT
+#define	PIC_GOT(x)	x@GOT
+#define	PIC_GOTOFF(x)	x@GOTOFF
+
+#define	PIC_PROLOGUE(got)			\
+        	mov.l	r12, @-sp;		\
+		PIC_PROLOGUE_NOSAVE(got)
+
+/*
+ * Functions that do non local jumps don't need to preserve r12,
+ * so we can shave off two instructions to save/restore it.
+ */
+#define	PIC_PROLOGUE_NOSAVE(got)		\
+        	mov.l	got, r12;		\
+        	mova	got, r0;		\
+        	add	r0, r12
+
+#define	PIC_EPILOGUE				\
+		mov.l	@sp+, r12
+
+#define PIC_EPILOGUE_SLOT 			\
+		PIC_EPILOGUE
+
+#define PIC_GOT_DATUM \
+		.long	_GLOBAL_OFFSET_TABLE_
+
+#define CALL	bsrf
+#define JUMP	braf
+
+#define CALL_DATUM(function, lpcs) \
+		.long	PIC_PLT(function) - ((lpcs) + 4 - (.))
+
+/*
+ * This will result in text relocations in the shared library,
+ * unless the function is local or has hidden or protected visibility.
+ * Does not require PIC prologue.
+ */
+#define CALL_DATUM_LOCAL(function, lpcs) \
+		.long	function - ((lpcs) + 4)
+
+#else  /* !PIC */
+
+#define	PIC_PROLOGUE(label)
+#define	PIC_PROLOGUE_NOSAVE(label)
+#define	PIC_EPILOGUE
+#define	PIC_EPILOGUE_SLOT	nop
+#define PIC_GOT_DATUM
+
+#define CALL	jsr @
+#define JUMP	jmp @
+
+#define CALL_DATUM(function, lpcs) \
+		.long	function
+
+#define CALL_DATUM_LOCAL(function, lpcs) \
+		.long	function
+
+#endif /* !PIC */
+
+
+#define	ASMSTR		.asciz
+
+#ifdef __ELF__
+#define	WEAK_ALIAS(alias,sym)						\
+	.weak _C_LABEL(alias);						\
+	_C_LABEL(alias) = _C_LABEL(sym)
+#endif
+
+#define	WARN_REFERENCES(_sym,_msg)				\
+	.section .gnu.warning._sym; .ascii _msg; .previous
+
+#endif /* !_SH_ASM_H_ */
diff --git a/libc/arch-sh/include/machine/exec.h b/libc/arch-sh/include/machine/exec.h
new file mode 100644
index 0000000..48a9680
--- /dev/null
+++ b/libc/arch-sh/include/machine/exec.h
@@ -0,0 +1,35 @@
+/*	$OpenBSD: exec.h,v 1.2 2006/11/10 20:34:06 drahn Exp $	*/
+/*	$NetBSD: elf_machdep.h,v 1.8 2002/04/28 17:10:34 uch Exp $	*/
+
+#define __LDPGSZ	4096
+
+#define	NATIVE_EXEC_ELF
+
+#define	ARCH_ELFSIZE		32	/* MD native binary size */
+#define	ELF_TARG_CLASS		ELFCLASS32
+#ifdef __LITTLE_ENDIAN__
+#define	ELF_TARG_DATA		ELFDATA2LSB
+#else
+#define	ELF_TARG_DATA		ELFDATA2MSB
+#endif
+#define	ELF_TARG_MACH		EM_SH
+
+#define	_KERN_DO_ELF
+#define	_NLIST_DO_ELF
+
+/*
+ * SuperH ELF header flags.
+ */
+#define	EF_SH_MACH_MASK		0x1f
+
+#define	EF_SH_UNKNOWN		0x00
+#define	EF_SH_SH1		0x01
+#define	EF_SH_SH2		0x02
+#define	EF_SH_SH3		0x03
+#define	EF_SH_DSP		0x04
+#define	EF_SH_SH3_DSP		0x05
+#define	EF_SH_SH3E		0x08
+#define	EF_SH_SH4		0x09
+
+#define	EF_SH_HAS_DSP(x)	((x) & EF_SH_DSP)
+#define	EF_SH_HAS_FP(x)		((x) & EF_SH_SH3E)
diff --git a/libc/arch-sh/include/machine/ieee.h b/libc/arch-sh/include/machine/ieee.h
new file mode 100644
index 0000000..7646f85
--- /dev/null
+++ b/libc/arch-sh/include/machine/ieee.h
@@ -0,0 +1,132 @@
+/*	$OpenBSD: ieee.h,v 1.2 2006/11/10 20:29:36 otto Exp $	*/
+
+/*
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Lawrence Berkeley Laboratory.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *	@(#)ieee.h	8.1 (Berkeley) 6/11/93
+ */
+
+/*
+ * ieee.h defines the machine-dependent layout of the machine's IEEE
+ * floating point.  It does *not* define (yet?) any of the rounding
+ * mode bits, exceptions, and so forth.
+ */
+
+/*
+ * Define the number of bits in each fraction and exponent.
+ *
+ *		     k	         k+1
+ * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
+ *
+ *					  (-exp_bias+1)
+ * as fractions that look like 0.fffff x 2             .  This means that
+ *
+ *			 -126
+ * the number 0.10000 x 2    , for instance, is the same as the normalized
+ *
+ *		-127			   -128
+ * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
+ *
+ *				  -129
+ * in the fraction; to represent 2    , we need two, and so on.  This
+ *
+ *						     (-exp_bias-fracbits+1)
+ * implies that the smallest denormalized number is 2
+ *
+ * for whichever format we are talking about: for single precision, for
+ *
+ *						-126		-149
+ * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
+ *
+ * -149 == -127 - 23 + 1.
+ */
+#define	SNG_EXPBITS	8
+#define	SNG_FRACBITS	23
+
+#define	DBL_EXPBITS	11
+#define	DBL_FRACBITS	52
+
+#define	EXT_EXPBITS	15
+#define	EXT_FRACBITS	112
+
+struct ieee_single {
+	u_int	sng_frac:23;
+	u_int	sng_exp:8;
+	u_int	sng_sign:1;
+};
+
+struct ieee_double {
+	u_int	dbl_fracl;
+	u_int	dbl_frach:20;
+	u_int	dbl_exp:11;
+	u_int	dbl_sign:1;
+};
+
+struct ieee_ext {
+	u_int	ext_sign:1;
+	u_int	ext_exp:15;
+	u_int	ext_frach:16;
+	u_int	ext_frachm;
+	u_int	ext_fraclm;
+	u_int	ext_fracl;
+};
+
+/*
+ * Floats whose exponent is in [1..INFNAN) (of whatever type) are
+ * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
+ * Floats whose exponent is zero are either zero (iff all fraction
+ * bits are zero) or subnormal values.
+ *
+ * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
+ * high fraction; if the bit is set, it is a `quiet NaN'.
+ */
+#define	SNG_EXP_INFNAN	255
+#define	DBL_EXP_INFNAN	2047
+#define	EXT_EXP_INFNAN	32767
+
+#if 0
+#define	SNG_QUIETNAN	(1 << 22)
+#define	DBL_QUIETNAN	(1 << 19)
+#define	EXT_QUIETNAN	(1 << 15)
+#endif
+
+/*
+ * Exponent biases.
+ */
+#define	SNG_EXP_BIAS	127
+#define	DBL_EXP_BIAS	1023
+#define	EXT_EXP_BIAS	16383
diff --git a/libc/arch-sh/include/machine/internal_types.h b/libc/arch-sh/include/machine/internal_types.h
new file mode 100644
index 0000000..ea9b7c4
--- /dev/null
+++ b/libc/arch-sh/include/machine/internal_types.h
@@ -0,0 +1,6 @@
+/* $OpenBSD: internal_types.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $ */
+/* Public domain */
+#ifndef _SH_INTERNAL_TYPES_H_
+#define _SH_INTERNAL_TYPES_H_
+
+#endif
diff --git a/libc/arch-sh/include/machine/kernel.h b/libc/arch-sh/include/machine/kernel.h
new file mode 100644
index 0000000..948021a
--- /dev/null
+++ b/libc/arch-sh/include/machine/kernel.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 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 _ARCH_SH_KERNEL_H
+#define _ARCH_SH_KERNEL_H
+
+/* this file contains kernel-specific definitions that were optimized out of
+   our processed kernel headers, but still useful nonetheless... */
+
+typedef unsigned long   __kernel_blkcnt_t;
+typedef unsigned long   __kernel_blksize_t;
+
+/* these aren't really defined by the kernel headers though... */
+typedef unsigned long   __kernel_fsblkcnt_t;
+typedef unsigned long   __kernel_fsfilcnt_t;
+typedef unsigned int    __kernel_id_t;
+
+#endif /* _ARCH_SH_KERNEL_H */
diff --git a/libc/arch-sh/include/machine/limits.h b/libc/arch-sh/include/machine/limits.h
new file mode 100644
index 0000000..d602138
--- /dev/null
+++ b/libc/arch-sh/include/machine/limits.h
@@ -0,0 +1,60 @@
+/*	$OpenBSD: limits.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
+/*	$NetBSD: limits.h,v 1.1 1996/09/30 16:34:28 ws Exp $	*/
+
+/*-
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 _SH_LIMITS_H_
+#define _SH_LIMITS_H_
+
+#include <sys/cdefs.h>
+
+#define	MB_LEN_MAX	1		/* no multibyte characters	*/
+
+#ifndef	SIZE_MAX
+#define	SIZE_MAX	UINT_MAX	/* max value for a size_t */
+#endif
+#define SSIZE_MAX	INT_MAX		/* max value for a ssize_t */  
+
+#if __BSD_VISIBLE
+#define	SIZE_T_MAX	UINT_MAX	/* max value for a size_t (historic) */
+
+#define	UQUAD_MAX	0xffffffffffffffffULL		/* max unsigned quad */
+#define	QUAD_MAX	0x7fffffffffffffffLL		/* max signed quad */
+#define	QUAD_MIN	(-0x7fffffffffffffffLL-1)	/* min signed quad */
+#endif	/* __BSD_VISIBLE */
+
+#define LONGLONG_BIT    64
+#define LONGLONG_MIN    (-9223372036854775807LL-1)
+#define LONGLONG_MAX    9223372036854775807LL
+#define ULONGLONG_MAX   18446744073709551615ULL
+
+#endif /* _SH_LIMITS_H_ */
diff --git a/libc/arch-sh/include/machine/setjmp.h b/libc/arch-sh/include/machine/setjmp.h
new file mode 100644
index 0000000..014ad3e
--- /dev/null
+++ b/libc/arch-sh/include/machine/setjmp.h
@@ -0,0 +1,7 @@
+/*	$OpenBSD: setjmp.h,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
+/*	$NetBSD: setjmp.h,v 1.3 2006/01/05 00:50:23 uwe Exp $	*/
+
+/*
+ * machine/setjmp.h: machine dependent setjmp-related information.
+ */
+
diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk
new file mode 100644
index 0000000..cefb2ec
--- /dev/null
+++ b/libc/arch-sh/syscalls.mk
@@ -0,0 +1,157 @@
+# auto-generated by gensyscalls.py, do not touch
+syscall_src := 
+syscall_src += arch-sh/syscalls/_exit.S
+syscall_src += arch-sh/syscalls/_exit_thread.S
+syscall_src += arch-sh/syscalls/__fork.S
+syscall_src += arch-sh/syscalls/_waitpid.S
+syscall_src += arch-sh/syscalls/waitid.S
+syscall_src += arch-sh/syscalls/__clone.S
+syscall_src += arch-sh/syscalls/execve.S
+syscall_src += arch-sh/syscalls/setuid.S
+syscall_src += arch-sh/syscalls/getuid.S
+syscall_src += arch-sh/syscalls/getgid.S
+syscall_src += arch-sh/syscalls/geteuid.S
+syscall_src += arch-sh/syscalls/getegid.S
+syscall_src += arch-sh/syscalls/getresuid.S
+syscall_src += arch-sh/syscalls/getresgid.S
+syscall_src += arch-sh/syscalls/gettid.S
+syscall_src += arch-sh/syscalls/getgroups.S
+syscall_src += arch-sh/syscalls/getpgid.S
+syscall_src += arch-sh/syscalls/getppid.S
+syscall_src += arch-sh/syscalls/setsid.S
+syscall_src += arch-sh/syscalls/setgid.S
+syscall_src += arch-sh/syscalls/setreuid.S
+syscall_src += arch-sh/syscalls/setresuid.S
+syscall_src += arch-sh/syscalls/setresgid.S
+syscall_src += arch-sh/syscalls/__brk.S
+syscall_src += arch-sh/syscalls/kill.S
+syscall_src += arch-sh/syscalls/tkill.S
+syscall_src += arch-sh/syscalls/__ptrace.S
+syscall_src += arch-sh/syscalls/__set_thread_area.S
+syscall_src += arch-sh/syscalls/__getpriority.S
+syscall_src += arch-sh/syscalls/setpriority.S
+syscall_src += arch-sh/syscalls/setrlimit.S
+syscall_src += arch-sh/syscalls/getrlimit.S
+syscall_src += arch-sh/syscalls/getrusage.S
+syscall_src += arch-sh/syscalls/setgroups.S
+syscall_src += arch-sh/syscalls/setpgid.S
+syscall_src += arch-sh/syscalls/vfork.S
+syscall_src += arch-sh/syscalls/setregid.S
+syscall_src += arch-sh/syscalls/chroot.S
+syscall_src += arch-sh/syscalls/prctl.S
+syscall_src += arch-sh/syscalls/capget.S
+syscall_src += arch-sh/syscalls/capset.S
+syscall_src += arch-sh/syscalls/acct.S
+syscall_src += arch-sh/syscalls/read.S
+syscall_src += arch-sh/syscalls/write.S
+syscall_src += arch-sh/syscalls/__pread64.S
+syscall_src += arch-sh/syscalls/__pwrite64.S
+syscall_src += arch-sh/syscalls/__open.S
+syscall_src += arch-sh/syscalls/__openat.S
+syscall_src += arch-sh/syscalls/close.S
+syscall_src += arch-sh/syscalls/lseek.S
+syscall_src += arch-sh/syscalls/__llseek.S
+syscall_src += arch-sh/syscalls/getpid.S
+syscall_src += arch-sh/syscalls/__mmap2.S
+syscall_src += arch-sh/syscalls/munmap.S
+syscall_src += arch-sh/syscalls/mremap.S
+syscall_src += arch-sh/syscalls/msync.S
+syscall_src += arch-sh/syscalls/mprotect.S
+syscall_src += arch-sh/syscalls/madvise.S
+syscall_src += arch-sh/syscalls/mlock.S
+syscall_src += arch-sh/syscalls/munlock.S
+syscall_src += arch-sh/syscalls/mincore.S
+syscall_src += arch-sh/syscalls/__ioctl.S
+syscall_src += arch-sh/syscalls/readv.S
+syscall_src += arch-sh/syscalls/writev.S
+syscall_src += arch-sh/syscalls/__fcntl.S
+syscall_src += arch-sh/syscalls/flock.S
+syscall_src += arch-sh/syscalls/fchmod.S
+syscall_src += arch-sh/syscalls/dup.S
+syscall_src += arch-sh/syscalls/dup2.S
+syscall_src += arch-sh/syscalls/select.S
+syscall_src += arch-sh/syscalls/ftruncate.S
+syscall_src += arch-sh/syscalls/getdents.S
+syscall_src += arch-sh/syscalls/fsync.S
+syscall_src += arch-sh/syscalls/fchown.S
+syscall_src += arch-sh/syscalls/sync.S
+syscall_src += arch-sh/syscalls/__fcntl64.S
+syscall_src += arch-sh/syscalls/fstatfs.S
+syscall_src += arch-sh/syscalls/sendfile.S
+syscall_src += arch-sh/syscalls/fstatat.S
+syscall_src += arch-sh/syscalls/mkdirat.S
+syscall_src += arch-sh/syscalls/fchownat.S
+syscall_src += arch-sh/syscalls/fchmodat.S
+syscall_src += arch-sh/syscalls/renameat.S
+syscall_src += arch-sh/syscalls/link.S
+syscall_src += arch-sh/syscalls/unlink.S
+syscall_src += arch-sh/syscalls/unlinkat.S
+syscall_src += arch-sh/syscalls/chdir.S
+syscall_src += arch-sh/syscalls/mknod.S
+syscall_src += arch-sh/syscalls/chmod.S
+syscall_src += arch-sh/syscalls/chown.S
+syscall_src += arch-sh/syscalls/lchown.S
+syscall_src += arch-sh/syscalls/mount.S
+syscall_src += arch-sh/syscalls/umount2.S
+syscall_src += arch-sh/syscalls/fstat.S
+syscall_src += arch-sh/syscalls/stat.S
+syscall_src += arch-sh/syscalls/lstat.S
+syscall_src += arch-sh/syscalls/mkdir.S
+syscall_src += arch-sh/syscalls/readlink.S
+syscall_src += arch-sh/syscalls/rmdir.S
+syscall_src += arch-sh/syscalls/rename.S
+syscall_src += arch-sh/syscalls/__getcwd.S
+syscall_src += arch-sh/syscalls/access.S
+syscall_src += arch-sh/syscalls/symlink.S
+syscall_src += arch-sh/syscalls/fchdir.S
+syscall_src += arch-sh/syscalls/truncate.S
+syscall_src += arch-sh/syscalls/__statfs64.S
+syscall_src += arch-sh/syscalls/pause.S
+syscall_src += arch-sh/syscalls/gettimeofday.S
+syscall_src += arch-sh/syscalls/settimeofday.S
+syscall_src += arch-sh/syscalls/times.S
+syscall_src += arch-sh/syscalls/nanosleep.S
+syscall_src += arch-sh/syscalls/clock_gettime.S
+syscall_src += arch-sh/syscalls/clock_settime.S
+syscall_src += arch-sh/syscalls/clock_getres.S
+syscall_src += arch-sh/syscalls/clock_nanosleep.S
+syscall_src += arch-sh/syscalls/getitimer.S
+syscall_src += arch-sh/syscalls/setitimer.S
+syscall_src += arch-sh/syscalls/__timer_create.S
+syscall_src += arch-sh/syscalls/__timer_settime.S
+syscall_src += arch-sh/syscalls/__timer_gettime.S
+syscall_src += arch-sh/syscalls/__timer_getoverrun.S
+syscall_src += arch-sh/syscalls/__timer_delete.S
+syscall_src += arch-sh/syscalls/utimes.S
+syscall_src += arch-sh/syscalls/sigaction.S
+syscall_src += arch-sh/syscalls/sigprocmask.S
+syscall_src += arch-sh/syscalls/__sigsuspend.S
+syscall_src += arch-sh/syscalls/__rt_sigaction.S
+syscall_src += arch-sh/syscalls/__rt_sigprocmask.S
+syscall_src += arch-sh/syscalls/__rt_sigtimedwait.S
+syscall_src += arch-sh/syscalls/sigpending.S
+syscall_src += arch-sh/syscalls/__socketcall.S
+syscall_src += arch-sh/syscalls/sched_setscheduler.S
+syscall_src += arch-sh/syscalls/sched_getscheduler.S
+syscall_src += arch-sh/syscalls/sched_yield.S
+syscall_src += arch-sh/syscalls/sched_setparam.S
+syscall_src += arch-sh/syscalls/sched_getparam.S
+syscall_src += arch-sh/syscalls/sched_get_priority_max.S
+syscall_src += arch-sh/syscalls/sched_get_priority_min.S
+syscall_src += arch-sh/syscalls/sched_rr_get_interval.S
+syscall_src += arch-sh/syscalls/uname.S
+syscall_src += arch-sh/syscalls/__wait4.S
+syscall_src += arch-sh/syscalls/umask.S
+syscall_src += arch-sh/syscalls/__reboot.S
+syscall_src += arch-sh/syscalls/__syslog.S
+syscall_src += arch-sh/syscalls/init_module.S
+syscall_src += arch-sh/syscalls/delete_module.S
+syscall_src += arch-sh/syscalls/klogctl.S
+syscall_src += arch-sh/syscalls/futex.S
+syscall_src += arch-sh/syscalls/epoll_create.S
+syscall_src += arch-sh/syscalls/epoll_ctl.S
+syscall_src += arch-sh/syscalls/epoll_wait.S
+syscall_src += arch-sh/syscalls/inotify_init.S
+syscall_src += arch-sh/syscalls/inotify_add_watch.S
+syscall_src += arch-sh/syscalls/inotify_rm_watch.S
+syscall_src += arch-sh/syscalls/poll.S
diff --git a/libc/arch-sh/syscalls/__brk.S b/libc/arch-sh/syscalls/__brk.S
new file mode 100644
index 0000000..465389d
--- /dev/null
+++ b/libc/arch-sh/syscalls/__brk.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __brk, @function
+    .globl __brk
+    .align 4
+
+__brk:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_brk_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_brk_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_brk
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__clone.S b/libc/arch-sh/syscalls/__clone.S
new file mode 100644
index 0000000..1df6ca2
--- /dev/null
+++ b/libc/arch-sh/syscalls/__clone.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __clone, @function
+    .globl __clone
+    .align 4
+
+__clone:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_clone_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_clone_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_clone
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__fcntl.S b/libc/arch-sh/syscalls/__fcntl.S
new file mode 100644
index 0000000..654ee84
--- /dev/null
+++ b/libc/arch-sh/syscalls/__fcntl.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __fcntl, @function
+    .globl __fcntl
+    .align 4
+
+__fcntl:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fcntl_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fcntl_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fcntl
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__fcntl64.S b/libc/arch-sh/syscalls/__fcntl64.S
new file mode 100644
index 0000000..8a2f73f
--- /dev/null
+++ b/libc/arch-sh/syscalls/__fcntl64.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __fcntl64, @function
+    .globl __fcntl64
+    .align 4
+
+__fcntl64:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fcntl64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fcntl64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fcntl64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__fork.S b/libc/arch-sh/syscalls/__fork.S
new file mode 100644
index 0000000..5a00daf
--- /dev/null
+++ b/libc/arch-sh/syscalls/__fork.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __fork, @function
+    .globl __fork
+    .align 4
+
+__fork:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fork_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fork_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fork
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__getcwd.S b/libc/arch-sh/syscalls/__getcwd.S
new file mode 100644
index 0000000..9ce1f14
--- /dev/null
+++ b/libc/arch-sh/syscalls/__getcwd.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __getcwd, @function
+    .globl __getcwd
+    .align 4
+
+__getcwd:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getcwd_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getcwd_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getcwd
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__getpriority.S b/libc/arch-sh/syscalls/__getpriority.S
new file mode 100644
index 0000000..aa9f4f3
--- /dev/null
+++ b/libc/arch-sh/syscalls/__getpriority.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __getpriority, @function
+    .globl __getpriority
+    .align 4
+
+__getpriority:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getpriority_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getpriority_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getpriority
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__ioctl.S b/libc/arch-sh/syscalls/__ioctl.S
new file mode 100644
index 0000000..ec447cf
--- /dev/null
+++ b/libc/arch-sh/syscalls/__ioctl.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __ioctl, @function
+    .globl __ioctl
+    .align 4
+
+__ioctl:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_ioctl_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_ioctl_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_ioctl
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__llseek.S b/libc/arch-sh/syscalls/__llseek.S
new file mode 100644
index 0000000..e43b3ed
--- /dev/null
+++ b/libc/arch-sh/syscalls/__llseek.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __llseek, @function
+    .globl __llseek
+    .align 4
+
+__llseek:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR__llseek_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR__llseek_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR__llseek
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__mmap2.S b/libc/arch-sh/syscalls/__mmap2.S
new file mode 100644
index 0000000..6f70d46
--- /dev/null
+++ b/libc/arch-sh/syscalls/__mmap2.S
@@ -0,0 +1,36 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __mmap2, @function
+    .globl __mmap2
+    .align 4
+
+__mmap2:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+    mov.l   @(4, r15), r1
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(6 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mmap2_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mmap2_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mmap2
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__open.S b/libc/arch-sh/syscalls/__open.S
new file mode 100644
index 0000000..f57b5b9
--- /dev/null
+++ b/libc/arch-sh/syscalls/__open.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __open, @function
+    .globl __open
+    .align 4
+
+__open:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_open_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_open_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_open
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__openat.S b/libc/arch-sh/syscalls/__openat.S
new file mode 100644
index 0000000..08cf096
--- /dev/null
+++ b/libc/arch-sh/syscalls/__openat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __openat, @function
+    .globl __openat
+    .align 4
+
+__openat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_openat_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_openat_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_openat
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__pread64.S b/libc/arch-sh/syscalls/__pread64.S
new file mode 100644
index 0000000..474add3
--- /dev/null
+++ b/libc/arch-sh/syscalls/__pread64.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __pread64, @function
+    .globl __pread64
+    .align 4
+
+__pread64:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_pread64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_pread64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_pread64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__ptrace.S b/libc/arch-sh/syscalls/__ptrace.S
new file mode 100644
index 0000000..89bbc98
--- /dev/null
+++ b/libc/arch-sh/syscalls/__ptrace.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __ptrace, @function
+    .globl __ptrace
+    .align 4
+
+__ptrace:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_ptrace_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_ptrace_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_ptrace
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__pwrite64.S b/libc/arch-sh/syscalls/__pwrite64.S
new file mode 100644
index 0000000..a722242
--- /dev/null
+++ b/libc/arch-sh/syscalls/__pwrite64.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __pwrite64, @function
+    .globl __pwrite64
+    .align 4
+
+__pwrite64:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_pwrite64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_pwrite64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_pwrite64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__reboot.S b/libc/arch-sh/syscalls/__reboot.S
new file mode 100644
index 0000000..07cff36
--- /dev/null
+++ b/libc/arch-sh/syscalls/__reboot.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __reboot, @function
+    .globl __reboot
+    .align 4
+
+__reboot:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_reboot_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_reboot_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_reboot
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__rt_sigaction.S b/libc/arch-sh/syscalls/__rt_sigaction.S
new file mode 100644
index 0000000..693cb76
--- /dev/null
+++ b/libc/arch-sh/syscalls/__rt_sigaction.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __rt_sigaction, @function
+    .globl __rt_sigaction
+    .align 4
+
+__rt_sigaction:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_rt_sigaction_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_rt_sigaction_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_rt_sigaction
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__rt_sigprocmask.S b/libc/arch-sh/syscalls/__rt_sigprocmask.S
new file mode 100644
index 0000000..7822d4f
--- /dev/null
+++ b/libc/arch-sh/syscalls/__rt_sigprocmask.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __rt_sigprocmask, @function
+    .globl __rt_sigprocmask
+    .align 4
+
+__rt_sigprocmask:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_rt_sigprocmask_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_rt_sigprocmask_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_rt_sigprocmask
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__rt_sigtimedwait.S b/libc/arch-sh/syscalls/__rt_sigtimedwait.S
new file mode 100644
index 0000000..2804169
--- /dev/null
+++ b/libc/arch-sh/syscalls/__rt_sigtimedwait.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __rt_sigtimedwait, @function
+    .globl __rt_sigtimedwait
+    .align 4
+
+__rt_sigtimedwait:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_rt_sigtimedwait_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_rt_sigtimedwait_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_rt_sigtimedwait
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__set_thread_area.S b/libc/arch-sh/syscalls/__set_thread_area.S
new file mode 100644
index 0000000..7d5aea6
--- /dev/null
+++ b/libc/arch-sh/syscalls/__set_thread_area.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __set_thread_area, @function
+    .globl __set_thread_area
+    .align 4
+
+__set_thread_area:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_set_thread_area_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_set_thread_area_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_set_thread_area
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__sigsuspend.S b/libc/arch-sh/syscalls/__sigsuspend.S
new file mode 100644
index 0000000..9643940
--- /dev/null
+++ b/libc/arch-sh/syscalls/__sigsuspend.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __sigsuspend, @function
+    .globl __sigsuspend
+    .align 4
+
+__sigsuspend:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sigsuspend_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sigsuspend_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sigsuspend
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__socketcall.S b/libc/arch-sh/syscalls/__socketcall.S
new file mode 100644
index 0000000..864e9aa
--- /dev/null
+++ b/libc/arch-sh/syscalls/__socketcall.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __socketcall, @function
+    .globl __socketcall
+    .align 4
+
+__socketcall:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR___socketcall_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR___socketcall_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR___socketcall
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__statfs64.S b/libc/arch-sh/syscalls/__statfs64.S
new file mode 100644
index 0000000..ccd137b
--- /dev/null
+++ b/libc/arch-sh/syscalls/__statfs64.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __statfs64, @function
+    .globl __statfs64
+    .align 4
+
+__statfs64:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_statfs64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_statfs64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_statfs64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__syslog.S b/libc/arch-sh/syscalls/__syslog.S
new file mode 100644
index 0000000..ea1ac38
--- /dev/null
+++ b/libc/arch-sh/syscalls/__syslog.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __syslog, @function
+    .globl __syslog
+    .align 4
+
+__syslog:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_syslog_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_syslog_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_syslog
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__timer_create.S b/libc/arch-sh/syscalls/__timer_create.S
new file mode 100644
index 0000000..f2e2e5c
--- /dev/null
+++ b/libc/arch-sh/syscalls/__timer_create.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __timer_create, @function
+    .globl __timer_create
+    .align 4
+
+__timer_create:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_timer_create_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_timer_create_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_timer_create
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__timer_delete.S b/libc/arch-sh/syscalls/__timer_delete.S
new file mode 100644
index 0000000..d655d3d
--- /dev/null
+++ b/libc/arch-sh/syscalls/__timer_delete.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __timer_delete, @function
+    .globl __timer_delete
+    .align 4
+
+__timer_delete:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_timer_delete_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_timer_delete_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_timer_delete
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__timer_getoverrun.S b/libc/arch-sh/syscalls/__timer_getoverrun.S
new file mode 100644
index 0000000..64fa92f
--- /dev/null
+++ b/libc/arch-sh/syscalls/__timer_getoverrun.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __timer_getoverrun, @function
+    .globl __timer_getoverrun
+    .align 4
+
+__timer_getoverrun:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_timer_getoverrun_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_timer_getoverrun_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_timer_getoverrun
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__timer_gettime.S b/libc/arch-sh/syscalls/__timer_gettime.S
new file mode 100644
index 0000000..f1c63ed
--- /dev/null
+++ b/libc/arch-sh/syscalls/__timer_gettime.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __timer_gettime, @function
+    .globl __timer_gettime
+    .align 4
+
+__timer_gettime:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_timer_gettime_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_timer_gettime_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_timer_gettime
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__timer_settime.S b/libc/arch-sh/syscalls/__timer_settime.S
new file mode 100644
index 0000000..ea438a6
--- /dev/null
+++ b/libc/arch-sh/syscalls/__timer_settime.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __timer_settime, @function
+    .globl __timer_settime
+    .align 4
+
+__timer_settime:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_timer_settime_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_timer_settime_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_timer_settime
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/__wait4.S b/libc/arch-sh/syscalls/__wait4.S
new file mode 100644
index 0000000..a145e34
--- /dev/null
+++ b/libc/arch-sh/syscalls/__wait4.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type __wait4, @function
+    .globl __wait4
+    .align 4
+
+__wait4:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_wait4_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_wait4_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_wait4
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/_exit.S b/libc/arch-sh/syscalls/_exit.S
new file mode 100644
index 0000000..377a98a
--- /dev/null
+++ b/libc/arch-sh/syscalls/_exit.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type _exit, @function
+    .globl _exit
+    .align 4
+
+_exit:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_exit_group_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_exit_group_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_exit_group
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/_exit_thread.S b/libc/arch-sh/syscalls/_exit_thread.S
new file mode 100644
index 0000000..536d000
--- /dev/null
+++ b/libc/arch-sh/syscalls/_exit_thread.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type _exit_thread, @function
+    .globl _exit_thread
+    .align 4
+
+_exit_thread:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_exit_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_exit_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_exit
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/_waitpid.S b/libc/arch-sh/syscalls/_waitpid.S
new file mode 100644
index 0000000..db2cf61
--- /dev/null
+++ b/libc/arch-sh/syscalls/_waitpid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type _waitpid, @function
+    .globl _waitpid
+    .align 4
+
+_waitpid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_waitpid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_waitpid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_waitpid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/access.S b/libc/arch-sh/syscalls/access.S
new file mode 100644
index 0000000..dea8dfb
--- /dev/null
+++ b/libc/arch-sh/syscalls/access.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type access, @function
+    .globl access
+    .align 4
+
+access:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_access_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_access_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_access
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/acct.S b/libc/arch-sh/syscalls/acct.S
new file mode 100644
index 0000000..22d939e
--- /dev/null
+++ b/libc/arch-sh/syscalls/acct.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type acct, @function
+    .globl acct
+    .align 4
+
+acct:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_acct_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_acct_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_acct
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/capget.S b/libc/arch-sh/syscalls/capget.S
new file mode 100644
index 0000000..77f6c54
--- /dev/null
+++ b/libc/arch-sh/syscalls/capget.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type capget, @function
+    .globl capget
+    .align 4
+
+capget:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_capget_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_capget_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_capget
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/capset.S b/libc/arch-sh/syscalls/capset.S
new file mode 100644
index 0000000..c35b48e
--- /dev/null
+++ b/libc/arch-sh/syscalls/capset.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type capset, @function
+    .globl capset
+    .align 4
+
+capset:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_capset_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_capset_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_capset
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/chdir.S b/libc/arch-sh/syscalls/chdir.S
new file mode 100644
index 0000000..32b4a92
--- /dev/null
+++ b/libc/arch-sh/syscalls/chdir.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type chdir, @function
+    .globl chdir
+    .align 4
+
+chdir:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_chdir_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_chdir_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_chdir
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/chmod.S b/libc/arch-sh/syscalls/chmod.S
new file mode 100644
index 0000000..f145e4b
--- /dev/null
+++ b/libc/arch-sh/syscalls/chmod.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type chmod, @function
+    .globl chmod
+    .align 4
+
+chmod:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_chmod_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_chmod_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_chmod
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/chown.S b/libc/arch-sh/syscalls/chown.S
new file mode 100644
index 0000000..4938a2a
--- /dev/null
+++ b/libc/arch-sh/syscalls/chown.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type chown, @function
+    .globl chown
+    .align 4
+
+chown:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_chown32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_chown32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_chown32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/chroot.S b/libc/arch-sh/syscalls/chroot.S
new file mode 100644
index 0000000..a60b59d
--- /dev/null
+++ b/libc/arch-sh/syscalls/chroot.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type chroot, @function
+    .globl chroot
+    .align 4
+
+chroot:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_chroot_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_chroot_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_chroot
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/clock_getres.S b/libc/arch-sh/syscalls/clock_getres.S
new file mode 100644
index 0000000..0b38f22
--- /dev/null
+++ b/libc/arch-sh/syscalls/clock_getres.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type clock_getres, @function
+    .globl clock_getres
+    .align 4
+
+clock_getres:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_clock_getres_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_clock_getres_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_clock_getres
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/clock_gettime.S b/libc/arch-sh/syscalls/clock_gettime.S
new file mode 100644
index 0000000..67952a6
--- /dev/null
+++ b/libc/arch-sh/syscalls/clock_gettime.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type clock_gettime, @function
+    .globl clock_gettime
+    .align 4
+
+clock_gettime:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_clock_gettime_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_clock_gettime_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_clock_gettime
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/clock_nanosleep.S b/libc/arch-sh/syscalls/clock_nanosleep.S
new file mode 100644
index 0000000..7ef8d5e
--- /dev/null
+++ b/libc/arch-sh/syscalls/clock_nanosleep.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type clock_nanosleep, @function
+    .globl clock_nanosleep
+    .align 4
+
+clock_nanosleep:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_clock_nanosleep_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_clock_nanosleep_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_clock_nanosleep
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/clock_settime.S b/libc/arch-sh/syscalls/clock_settime.S
new file mode 100644
index 0000000..fd48ac6
--- /dev/null
+++ b/libc/arch-sh/syscalls/clock_settime.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type clock_settime, @function
+    .globl clock_settime
+    .align 4
+
+clock_settime:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_clock_settime_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_clock_settime_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_clock_settime
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/close.S b/libc/arch-sh/syscalls/close.S
new file mode 100644
index 0000000..b59002d
--- /dev/null
+++ b/libc/arch-sh/syscalls/close.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type close, @function
+    .globl close
+    .align 4
+
+close:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_close_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_close_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_close
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/delete_module.S b/libc/arch-sh/syscalls/delete_module.S
new file mode 100644
index 0000000..73410a9
--- /dev/null
+++ b/libc/arch-sh/syscalls/delete_module.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type delete_module, @function
+    .globl delete_module
+    .align 4
+
+delete_module:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_delete_module_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_delete_module_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_delete_module
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/dup.S b/libc/arch-sh/syscalls/dup.S
new file mode 100644
index 0000000..1c87dd7
--- /dev/null
+++ b/libc/arch-sh/syscalls/dup.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type dup, @function
+    .globl dup
+    .align 4
+
+dup:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_dup_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_dup_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_dup
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/dup2.S b/libc/arch-sh/syscalls/dup2.S
new file mode 100644
index 0000000..da2b7bd
--- /dev/null
+++ b/libc/arch-sh/syscalls/dup2.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type dup2, @function
+    .globl dup2
+    .align 4
+
+dup2:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_dup2_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_dup2_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_dup2
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/epoll_create.S b/libc/arch-sh/syscalls/epoll_create.S
new file mode 100644
index 0000000..64ca8a0
--- /dev/null
+++ b/libc/arch-sh/syscalls/epoll_create.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type epoll_create, @function
+    .globl epoll_create
+    .align 4
+
+epoll_create:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_epoll_create_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_epoll_create_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_epoll_create
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/epoll_ctl.S b/libc/arch-sh/syscalls/epoll_ctl.S
new file mode 100644
index 0000000..0293e73
--- /dev/null
+++ b/libc/arch-sh/syscalls/epoll_ctl.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type epoll_ctl, @function
+    .globl epoll_ctl
+    .align 4
+
+epoll_ctl:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_epoll_ctl_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_epoll_ctl_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_epoll_ctl
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/epoll_wait.S b/libc/arch-sh/syscalls/epoll_wait.S
new file mode 100644
index 0000000..acea8b5
--- /dev/null
+++ b/libc/arch-sh/syscalls/epoll_wait.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type epoll_wait, @function
+    .globl epoll_wait
+    .align 4
+
+epoll_wait:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_epoll_wait_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_epoll_wait_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_epoll_wait
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/execve.S b/libc/arch-sh/syscalls/execve.S
new file mode 100644
index 0000000..e4c451a
--- /dev/null
+++ b/libc/arch-sh/syscalls/execve.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type execve, @function
+    .globl execve
+    .align 4
+
+execve:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_execve_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_execve_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_execve
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fchdir.S b/libc/arch-sh/syscalls/fchdir.S
new file mode 100644
index 0000000..9743935
--- /dev/null
+++ b/libc/arch-sh/syscalls/fchdir.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fchdir, @function
+    .globl fchdir
+    .align 4
+
+fchdir:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fchdir_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fchdir_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fchdir
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fchmod.S b/libc/arch-sh/syscalls/fchmod.S
new file mode 100644
index 0000000..07b8156
--- /dev/null
+++ b/libc/arch-sh/syscalls/fchmod.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fchmod, @function
+    .globl fchmod
+    .align 4
+
+fchmod:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fchmod_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fchmod_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fchmod
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fchmodat.S b/libc/arch-sh/syscalls/fchmodat.S
new file mode 100644
index 0000000..2532d12
--- /dev/null
+++ b/libc/arch-sh/syscalls/fchmodat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fchmodat, @function
+    .globl fchmodat
+    .align 4
+
+fchmodat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fchmodat_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fchmodat_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fchmodat
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fchown.S b/libc/arch-sh/syscalls/fchown.S
new file mode 100644
index 0000000..a49f7d7
--- /dev/null
+++ b/libc/arch-sh/syscalls/fchown.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fchown, @function
+    .globl fchown
+    .align 4
+
+fchown:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fchown32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fchown32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fchown32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fchownat.S b/libc/arch-sh/syscalls/fchownat.S
new file mode 100644
index 0000000..3e82637
--- /dev/null
+++ b/libc/arch-sh/syscalls/fchownat.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fchownat, @function
+    .globl fchownat
+    .align 4
+
+fchownat:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fchownat_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fchownat_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fchownat
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/flock.S b/libc/arch-sh/syscalls/flock.S
new file mode 100644
index 0000000..d4274ea
--- /dev/null
+++ b/libc/arch-sh/syscalls/flock.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type flock, @function
+    .globl flock
+    .align 4
+
+flock:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_flock_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_flock_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_flock
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fstat.S b/libc/arch-sh/syscalls/fstat.S
new file mode 100644
index 0000000..bdb4952
--- /dev/null
+++ b/libc/arch-sh/syscalls/fstat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fstat, @function
+    .globl fstat
+    .align 4
+
+fstat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fstat64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fstat64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fstat64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fstatat.S b/libc/arch-sh/syscalls/fstatat.S
new file mode 100644
index 0000000..a5b18d1
--- /dev/null
+++ b/libc/arch-sh/syscalls/fstatat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fstatat, @function
+    .globl fstatat
+    .align 4
+
+fstatat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fstatat64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fstatat64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fstatat64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fstatfs.S b/libc/arch-sh/syscalls/fstatfs.S
new file mode 100644
index 0000000..6adb2cb
--- /dev/null
+++ b/libc/arch-sh/syscalls/fstatfs.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fstatfs, @function
+    .globl fstatfs
+    .align 4
+
+fstatfs:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fstatfs64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fstatfs64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fstatfs64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/fsync.S b/libc/arch-sh/syscalls/fsync.S
new file mode 100644
index 0000000..7904f53
--- /dev/null
+++ b/libc/arch-sh/syscalls/fsync.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type fsync, @function
+    .globl fsync
+    .align 4
+
+fsync:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_fsync_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_fsync_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_fsync
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/ftruncate.S b/libc/arch-sh/syscalls/ftruncate.S
new file mode 100644
index 0000000..8c34333
--- /dev/null
+++ b/libc/arch-sh/syscalls/ftruncate.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type ftruncate, @function
+    .globl ftruncate
+    .align 4
+
+ftruncate:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_ftruncate_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_ftruncate_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_ftruncate
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/futex.S b/libc/arch-sh/syscalls/futex.S
new file mode 100644
index 0000000..2aabd92
--- /dev/null
+++ b/libc/arch-sh/syscalls/futex.S
@@ -0,0 +1,36 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type futex, @function
+    .globl futex
+    .align 4
+
+futex:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+    mov.l   @(4, r15), r1
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(6 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_futex_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_futex_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_futex
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getdents.S b/libc/arch-sh/syscalls/getdents.S
new file mode 100644
index 0000000..66aedf3
--- /dev/null
+++ b/libc/arch-sh/syscalls/getdents.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getdents, @function
+    .globl getdents
+    .align 4
+
+getdents:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getdents64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getdents64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getdents64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getegid.S b/libc/arch-sh/syscalls/getegid.S
new file mode 100644
index 0000000..b3b91ca
--- /dev/null
+++ b/libc/arch-sh/syscalls/getegid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getegid, @function
+    .globl getegid
+    .align 4
+
+getegid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getegid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getegid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getegid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/geteuid.S b/libc/arch-sh/syscalls/geteuid.S
new file mode 100644
index 0000000..50f3549
--- /dev/null
+++ b/libc/arch-sh/syscalls/geteuid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type geteuid, @function
+    .globl geteuid
+    .align 4
+
+geteuid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_geteuid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_geteuid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_geteuid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getgid.S b/libc/arch-sh/syscalls/getgid.S
new file mode 100644
index 0000000..54480b7
--- /dev/null
+++ b/libc/arch-sh/syscalls/getgid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getgid, @function
+    .globl getgid
+    .align 4
+
+getgid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getgid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getgid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getgid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getgroups.S b/libc/arch-sh/syscalls/getgroups.S
new file mode 100644
index 0000000..854477e
--- /dev/null
+++ b/libc/arch-sh/syscalls/getgroups.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getgroups, @function
+    .globl getgroups
+    .align 4
+
+getgroups:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getgroups32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getgroups32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getgroups32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getitimer.S b/libc/arch-sh/syscalls/getitimer.S
new file mode 100644
index 0000000..aa444a6
--- /dev/null
+++ b/libc/arch-sh/syscalls/getitimer.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getitimer, @function
+    .globl getitimer
+    .align 4
+
+getitimer:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getitimer_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getitimer_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getitimer
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getpgid.S b/libc/arch-sh/syscalls/getpgid.S
new file mode 100644
index 0000000..0ff101d
--- /dev/null
+++ b/libc/arch-sh/syscalls/getpgid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getpgid, @function
+    .globl getpgid
+    .align 4
+
+getpgid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getpgid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getpgid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getpgid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getpid.S b/libc/arch-sh/syscalls/getpid.S
new file mode 100644
index 0000000..5606694
--- /dev/null
+++ b/libc/arch-sh/syscalls/getpid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getpid, @function
+    .globl getpid
+    .align 4
+
+getpid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getpid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getpid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getpid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getppid.S b/libc/arch-sh/syscalls/getppid.S
new file mode 100644
index 0000000..bf12372
--- /dev/null
+++ b/libc/arch-sh/syscalls/getppid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getppid, @function
+    .globl getppid
+    .align 4
+
+getppid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getppid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getppid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getppid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getresgid.S b/libc/arch-sh/syscalls/getresgid.S
new file mode 100644
index 0000000..3677211
--- /dev/null
+++ b/libc/arch-sh/syscalls/getresgid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getresgid, @function
+    .globl getresgid
+    .align 4
+
+getresgid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getresgid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getresgid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getresgid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getresuid.S b/libc/arch-sh/syscalls/getresuid.S
new file mode 100644
index 0000000..857495e
--- /dev/null
+++ b/libc/arch-sh/syscalls/getresuid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getresuid, @function
+    .globl getresuid
+    .align 4
+
+getresuid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getresuid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getresuid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getresuid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getrlimit.S b/libc/arch-sh/syscalls/getrlimit.S
new file mode 100644
index 0000000..78135d4
--- /dev/null
+++ b/libc/arch-sh/syscalls/getrlimit.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getrlimit, @function
+    .globl getrlimit
+    .align 4
+
+getrlimit:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_ugetrlimit_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_ugetrlimit_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_ugetrlimit
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getrusage.S b/libc/arch-sh/syscalls/getrusage.S
new file mode 100644
index 0000000..ccd9094
--- /dev/null
+++ b/libc/arch-sh/syscalls/getrusage.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getrusage, @function
+    .globl getrusage
+    .align 4
+
+getrusage:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getrusage_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getrusage_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getrusage
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/gettid.S b/libc/arch-sh/syscalls/gettid.S
new file mode 100644
index 0000000..bc25405
--- /dev/null
+++ b/libc/arch-sh/syscalls/gettid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type gettid, @function
+    .globl gettid
+    .align 4
+
+gettid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_gettid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_gettid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_gettid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/gettimeofday.S b/libc/arch-sh/syscalls/gettimeofday.S
new file mode 100644
index 0000000..50aba80
--- /dev/null
+++ b/libc/arch-sh/syscalls/gettimeofday.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type gettimeofday, @function
+    .globl gettimeofday
+    .align 4
+
+gettimeofday:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_gettimeofday_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_gettimeofday_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_gettimeofday
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/getuid.S b/libc/arch-sh/syscalls/getuid.S
new file mode 100644
index 0000000..9f9740d
--- /dev/null
+++ b/libc/arch-sh/syscalls/getuid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type getuid, @function
+    .globl getuid
+    .align 4
+
+getuid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_getuid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_getuid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_getuid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/init_module.S b/libc/arch-sh/syscalls/init_module.S
new file mode 100644
index 0000000..bd3be14
--- /dev/null
+++ b/libc/arch-sh/syscalls/init_module.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type init_module, @function
+    .globl init_module
+    .align 4
+
+init_module:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_init_module_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_init_module_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_init_module
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/inotify_add_watch.S b/libc/arch-sh/syscalls/inotify_add_watch.S
new file mode 100644
index 0000000..84d373e
--- /dev/null
+++ b/libc/arch-sh/syscalls/inotify_add_watch.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type inotify_add_watch, @function
+    .globl inotify_add_watch
+    .align 4
+
+inotify_add_watch:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_inotify_add_watch_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_inotify_add_watch_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_inotify_add_watch
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/inotify_init.S b/libc/arch-sh/syscalls/inotify_init.S
new file mode 100644
index 0000000..4030f69
--- /dev/null
+++ b/libc/arch-sh/syscalls/inotify_init.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type inotify_init, @function
+    .globl inotify_init
+    .align 4
+
+inotify_init:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_inotify_init_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_inotify_init_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_inotify_init
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/inotify_rm_watch.S b/libc/arch-sh/syscalls/inotify_rm_watch.S
new file mode 100644
index 0000000..7a03447
--- /dev/null
+++ b/libc/arch-sh/syscalls/inotify_rm_watch.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type inotify_rm_watch, @function
+    .globl inotify_rm_watch
+    .align 4
+
+inotify_rm_watch:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_inotify_rm_watch_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_inotify_rm_watch_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_inotify_rm_watch
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/kill.S b/libc/arch-sh/syscalls/kill.S
new file mode 100644
index 0000000..d331cde
--- /dev/null
+++ b/libc/arch-sh/syscalls/kill.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type kill, @function
+    .globl kill
+    .align 4
+
+kill:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_kill_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_kill_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_kill
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/klogctl.S b/libc/arch-sh/syscalls/klogctl.S
new file mode 100644
index 0000000..925875f
--- /dev/null
+++ b/libc/arch-sh/syscalls/klogctl.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type klogctl, @function
+    .globl klogctl
+    .align 4
+
+klogctl:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_syslog_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_syslog_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_syslog
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/lchown.S b/libc/arch-sh/syscalls/lchown.S
new file mode 100644
index 0000000..0d94631
--- /dev/null
+++ b/libc/arch-sh/syscalls/lchown.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type lchown, @function
+    .globl lchown
+    .align 4
+
+lchown:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_lchown32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_lchown32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_lchown32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/link.S b/libc/arch-sh/syscalls/link.S
new file mode 100644
index 0000000..f1716a7
--- /dev/null
+++ b/libc/arch-sh/syscalls/link.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type link, @function
+    .globl link
+    .align 4
+
+link:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_link_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_link_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_link
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/lseek.S b/libc/arch-sh/syscalls/lseek.S
new file mode 100644
index 0000000..df476ff
--- /dev/null
+++ b/libc/arch-sh/syscalls/lseek.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type lseek, @function
+    .globl lseek
+    .align 4
+
+lseek:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_lseek_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_lseek_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_lseek
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/lstat.S b/libc/arch-sh/syscalls/lstat.S
new file mode 100644
index 0000000..249c92e
--- /dev/null
+++ b/libc/arch-sh/syscalls/lstat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type lstat, @function
+    .globl lstat
+    .align 4
+
+lstat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_lstat64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_lstat64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_lstat64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/madvise.S b/libc/arch-sh/syscalls/madvise.S
new file mode 100644
index 0000000..e47eb3d
--- /dev/null
+++ b/libc/arch-sh/syscalls/madvise.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type madvise, @function
+    .globl madvise
+    .align 4
+
+madvise:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_madvise_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_madvise_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_madvise
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mincore.S b/libc/arch-sh/syscalls/mincore.S
new file mode 100644
index 0000000..3803358
--- /dev/null
+++ b/libc/arch-sh/syscalls/mincore.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mincore, @function
+    .globl mincore
+    .align 4
+
+mincore:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mincore_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mincore_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mincore
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mkdir.S b/libc/arch-sh/syscalls/mkdir.S
new file mode 100644
index 0000000..f40068a
--- /dev/null
+++ b/libc/arch-sh/syscalls/mkdir.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mkdir, @function
+    .globl mkdir
+    .align 4
+
+mkdir:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mkdir_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mkdir_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mkdir
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mkdirat.S b/libc/arch-sh/syscalls/mkdirat.S
new file mode 100644
index 0000000..e3506f8
--- /dev/null
+++ b/libc/arch-sh/syscalls/mkdirat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mkdirat, @function
+    .globl mkdirat
+    .align 4
+
+mkdirat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mkdirat_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mkdirat_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mkdirat
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mknod.S b/libc/arch-sh/syscalls/mknod.S
new file mode 100644
index 0000000..a2ab1ed
--- /dev/null
+++ b/libc/arch-sh/syscalls/mknod.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mknod, @function
+    .globl mknod
+    .align 4
+
+mknod:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mknod_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mknod_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mknod
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mlock.S b/libc/arch-sh/syscalls/mlock.S
new file mode 100644
index 0000000..2965d75
--- /dev/null
+++ b/libc/arch-sh/syscalls/mlock.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mlock, @function
+    .globl mlock
+    .align 4
+
+mlock:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mlock_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mlock_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mlock
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mount.S b/libc/arch-sh/syscalls/mount.S
new file mode 100644
index 0000000..d8c7c4b
--- /dev/null
+++ b/libc/arch-sh/syscalls/mount.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mount, @function
+    .globl mount
+    .align 4
+
+mount:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mount_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mount_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mount
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mprotect.S b/libc/arch-sh/syscalls/mprotect.S
new file mode 100644
index 0000000..d8fc96d
--- /dev/null
+++ b/libc/arch-sh/syscalls/mprotect.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mprotect, @function
+    .globl mprotect
+    .align 4
+
+mprotect:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mprotect_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mprotect_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mprotect
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/mremap.S b/libc/arch-sh/syscalls/mremap.S
new file mode 100644
index 0000000..d68fffb
--- /dev/null
+++ b/libc/arch-sh/syscalls/mremap.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type mremap, @function
+    .globl mremap
+    .align 4
+
+mremap:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_mremap_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_mremap_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_mremap
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/msync.S b/libc/arch-sh/syscalls/msync.S
new file mode 100644
index 0000000..2b84bdb
--- /dev/null
+++ b/libc/arch-sh/syscalls/msync.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type msync, @function
+    .globl msync
+    .align 4
+
+msync:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_msync_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_msync_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_msync
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/munlock.S b/libc/arch-sh/syscalls/munlock.S
new file mode 100644
index 0000000..c84c130
--- /dev/null
+++ b/libc/arch-sh/syscalls/munlock.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type munlock, @function
+    .globl munlock
+    .align 4
+
+munlock:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_munlock_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_munlock_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_munlock
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/munmap.S b/libc/arch-sh/syscalls/munmap.S
new file mode 100644
index 0000000..e338540
--- /dev/null
+++ b/libc/arch-sh/syscalls/munmap.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type munmap, @function
+    .globl munmap
+    .align 4
+
+munmap:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_munmap_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_munmap_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_munmap
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/nanosleep.S b/libc/arch-sh/syscalls/nanosleep.S
new file mode 100644
index 0000000..5aec582
--- /dev/null
+++ b/libc/arch-sh/syscalls/nanosleep.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type nanosleep, @function
+    .globl nanosleep
+    .align 4
+
+nanosleep:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_nanosleep_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_nanosleep_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_nanosleep
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/pause.S b/libc/arch-sh/syscalls/pause.S
new file mode 100644
index 0000000..23952d5
--- /dev/null
+++ b/libc/arch-sh/syscalls/pause.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type pause, @function
+    .globl pause
+    .align 4
+
+pause:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_pause_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_pause_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_pause
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/poll.S b/libc/arch-sh/syscalls/poll.S
new file mode 100644
index 0000000..7080298
--- /dev/null
+++ b/libc/arch-sh/syscalls/poll.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type poll, @function
+    .globl poll
+    .align 4
+
+poll:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_poll_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_poll_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_poll
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/prctl.S b/libc/arch-sh/syscalls/prctl.S
new file mode 100644
index 0000000..8c244d4
--- /dev/null
+++ b/libc/arch-sh/syscalls/prctl.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type prctl, @function
+    .globl prctl
+    .align 4
+
+prctl:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_prctl_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_prctl_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_prctl
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/read.S b/libc/arch-sh/syscalls/read.S
new file mode 100644
index 0000000..ac9faa1
--- /dev/null
+++ b/libc/arch-sh/syscalls/read.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type read, @function
+    .globl read
+    .align 4
+
+read:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_read_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_read_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_read
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/readlink.S b/libc/arch-sh/syscalls/readlink.S
new file mode 100644
index 0000000..e27cec7
--- /dev/null
+++ b/libc/arch-sh/syscalls/readlink.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type readlink, @function
+    .globl readlink
+    .align 4
+
+readlink:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_readlink_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_readlink_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_readlink
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/readv.S b/libc/arch-sh/syscalls/readv.S
new file mode 100644
index 0000000..2a95ea1
--- /dev/null
+++ b/libc/arch-sh/syscalls/readv.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type readv, @function
+    .globl readv
+    .align 4
+
+readv:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_readv_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_readv_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_readv
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/rename.S b/libc/arch-sh/syscalls/rename.S
new file mode 100644
index 0000000..692f40e
--- /dev/null
+++ b/libc/arch-sh/syscalls/rename.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type rename, @function
+    .globl rename
+    .align 4
+
+rename:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_rename_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_rename_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_rename
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/renameat.S b/libc/arch-sh/syscalls/renameat.S
new file mode 100644
index 0000000..0c9360f
--- /dev/null
+++ b/libc/arch-sh/syscalls/renameat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type renameat, @function
+    .globl renameat
+    .align 4
+
+renameat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_renameat_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_renameat_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_renameat
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/rmdir.S b/libc/arch-sh/syscalls/rmdir.S
new file mode 100644
index 0000000..124892e
--- /dev/null
+++ b/libc/arch-sh/syscalls/rmdir.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type rmdir, @function
+    .globl rmdir
+    .align 4
+
+rmdir:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_rmdir_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_rmdir_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_rmdir
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_get_priority_max.S b/libc/arch-sh/syscalls/sched_get_priority_max.S
new file mode 100644
index 0000000..dd642bf
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_get_priority_max.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_get_priority_max, @function
+    .globl sched_get_priority_max
+    .align 4
+
+sched_get_priority_max:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_get_priority_max_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_get_priority_max_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_get_priority_max
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_get_priority_min.S b/libc/arch-sh/syscalls/sched_get_priority_min.S
new file mode 100644
index 0000000..069b116
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_get_priority_min.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_get_priority_min, @function
+    .globl sched_get_priority_min
+    .align 4
+
+sched_get_priority_min:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_get_priority_min_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_get_priority_min_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_get_priority_min
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_getparam.S b/libc/arch-sh/syscalls/sched_getparam.S
new file mode 100644
index 0000000..c8417b2
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_getparam.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_getparam, @function
+    .globl sched_getparam
+    .align 4
+
+sched_getparam:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_getparam_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_getparam_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_getparam
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_getscheduler.S b/libc/arch-sh/syscalls/sched_getscheduler.S
new file mode 100644
index 0000000..ecd9a6a
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_getscheduler.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_getscheduler, @function
+    .globl sched_getscheduler
+    .align 4
+
+sched_getscheduler:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_getscheduler_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_getscheduler_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_getscheduler
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_rr_get_interval.S b/libc/arch-sh/syscalls/sched_rr_get_interval.S
new file mode 100644
index 0000000..64d5f69
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_rr_get_interval.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_rr_get_interval, @function
+    .globl sched_rr_get_interval
+    .align 4
+
+sched_rr_get_interval:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_rr_get_interval_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_rr_get_interval_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_rr_get_interval
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_setparam.S b/libc/arch-sh/syscalls/sched_setparam.S
new file mode 100644
index 0000000..f1687ee
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_setparam.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_setparam, @function
+    .globl sched_setparam
+    .align 4
+
+sched_setparam:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_setparam_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_setparam_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_setparam
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_setscheduler.S b/libc/arch-sh/syscalls/sched_setscheduler.S
new file mode 100644
index 0000000..7a6becf
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_setscheduler.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_setscheduler, @function
+    .globl sched_setscheduler
+    .align 4
+
+sched_setscheduler:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_setscheduler_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_setscheduler_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_setscheduler
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sched_yield.S b/libc/arch-sh/syscalls/sched_yield.S
new file mode 100644
index 0000000..538f487
--- /dev/null
+++ b/libc/arch-sh/syscalls/sched_yield.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sched_yield, @function
+    .globl sched_yield
+    .align 4
+
+sched_yield:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sched_yield_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sched_yield_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sched_yield
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/select.S b/libc/arch-sh/syscalls/select.S
new file mode 100644
index 0000000..b68f46a
--- /dev/null
+++ b/libc/arch-sh/syscalls/select.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type select, @function
+    .globl select
+    .align 4
+
+select:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR__newselect_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR__newselect_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR__newselect
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sendfile.S b/libc/arch-sh/syscalls/sendfile.S
new file mode 100644
index 0000000..015e433
--- /dev/null
+++ b/libc/arch-sh/syscalls/sendfile.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sendfile, @function
+    .globl sendfile
+    .align 4
+
+sendfile:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(4 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sendfile_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sendfile_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sendfile
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setgid.S b/libc/arch-sh/syscalls/setgid.S
new file mode 100644
index 0000000..2941fc1
--- /dev/null
+++ b/libc/arch-sh/syscalls/setgid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setgid, @function
+    .globl setgid
+    .align 4
+
+setgid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setgid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setgid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setgid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setgroups.S b/libc/arch-sh/syscalls/setgroups.S
new file mode 100644
index 0000000..723535d
--- /dev/null
+++ b/libc/arch-sh/syscalls/setgroups.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setgroups, @function
+    .globl setgroups
+    .align 4
+
+setgroups:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setgroups32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setgroups32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setgroups32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setitimer.S b/libc/arch-sh/syscalls/setitimer.S
new file mode 100644
index 0000000..84f0590
--- /dev/null
+++ b/libc/arch-sh/syscalls/setitimer.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setitimer, @function
+    .globl setitimer
+    .align 4
+
+setitimer:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setitimer_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setitimer_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setitimer
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setpgid.S b/libc/arch-sh/syscalls/setpgid.S
new file mode 100644
index 0000000..1dd8b33
--- /dev/null
+++ b/libc/arch-sh/syscalls/setpgid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setpgid, @function
+    .globl setpgid
+    .align 4
+
+setpgid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setpgid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setpgid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setpgid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setpriority.S b/libc/arch-sh/syscalls/setpriority.S
new file mode 100644
index 0000000..4f5091f
--- /dev/null
+++ b/libc/arch-sh/syscalls/setpriority.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setpriority, @function
+    .globl setpriority
+    .align 4
+
+setpriority:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setpriority_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setpriority_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setpriority
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setregid.S b/libc/arch-sh/syscalls/setregid.S
new file mode 100644
index 0000000..695f231
--- /dev/null
+++ b/libc/arch-sh/syscalls/setregid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setregid, @function
+    .globl setregid
+    .align 4
+
+setregid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setregid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setregid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setregid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setresgid.S b/libc/arch-sh/syscalls/setresgid.S
new file mode 100644
index 0000000..867cbc1
--- /dev/null
+++ b/libc/arch-sh/syscalls/setresgid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setresgid, @function
+    .globl setresgid
+    .align 4
+
+setresgid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setresgid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setresgid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setresgid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setresuid.S b/libc/arch-sh/syscalls/setresuid.S
new file mode 100644
index 0000000..41fe349
--- /dev/null
+++ b/libc/arch-sh/syscalls/setresuid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setresuid, @function
+    .globl setresuid
+    .align 4
+
+setresuid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setresuid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setresuid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setresuid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setreuid.S b/libc/arch-sh/syscalls/setreuid.S
new file mode 100644
index 0000000..025df27
--- /dev/null
+++ b/libc/arch-sh/syscalls/setreuid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setreuid, @function
+    .globl setreuid
+    .align 4
+
+setreuid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setreuid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setreuid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setreuid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setrlimit.S b/libc/arch-sh/syscalls/setrlimit.S
new file mode 100644
index 0000000..73fe89f
--- /dev/null
+++ b/libc/arch-sh/syscalls/setrlimit.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setrlimit, @function
+    .globl setrlimit
+    .align 4
+
+setrlimit:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setrlimit_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setrlimit_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setrlimit
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setsid.S b/libc/arch-sh/syscalls/setsid.S
new file mode 100644
index 0000000..fa7fc66
--- /dev/null
+++ b/libc/arch-sh/syscalls/setsid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setsid, @function
+    .globl setsid
+    .align 4
+
+setsid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(0 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setsid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setsid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setsid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/settimeofday.S b/libc/arch-sh/syscalls/settimeofday.S
new file mode 100644
index 0000000..0a38b60
--- /dev/null
+++ b/libc/arch-sh/syscalls/settimeofday.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type settimeofday, @function
+    .globl settimeofday
+    .align 4
+
+settimeofday:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_settimeofday_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_settimeofday_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_settimeofday
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/setuid.S b/libc/arch-sh/syscalls/setuid.S
new file mode 100644
index 0000000..1fb3148
--- /dev/null
+++ b/libc/arch-sh/syscalls/setuid.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type setuid, @function
+    .globl setuid
+    .align 4
+
+setuid:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_setuid32_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_setuid32_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_setuid32
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sigaction.S b/libc/arch-sh/syscalls/sigaction.S
new file mode 100644
index 0000000..f1dd824
--- /dev/null
+++ b/libc/arch-sh/syscalls/sigaction.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sigaction, @function
+    .globl sigaction
+    .align 4
+
+sigaction:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sigaction_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sigaction_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sigaction
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sigpending.S b/libc/arch-sh/syscalls/sigpending.S
new file mode 100644
index 0000000..75e479c
--- /dev/null
+++ b/libc/arch-sh/syscalls/sigpending.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sigpending, @function
+    .globl sigpending
+    .align 4
+
+sigpending:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sigpending_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sigpending_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sigpending
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sigprocmask.S b/libc/arch-sh/syscalls/sigprocmask.S
new file mode 100644
index 0000000..efa40ea
--- /dev/null
+++ b/libc/arch-sh/syscalls/sigprocmask.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sigprocmask, @function
+    .globl sigprocmask
+    .align 4
+
+sigprocmask:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sigprocmask_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sigprocmask_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sigprocmask
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/stat.S b/libc/arch-sh/syscalls/stat.S
new file mode 100644
index 0000000..aedd57d
--- /dev/null
+++ b/libc/arch-sh/syscalls/stat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type stat, @function
+    .globl stat
+    .align 4
+
+stat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_stat64_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_stat64_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_stat64
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/symlink.S b/libc/arch-sh/syscalls/symlink.S
new file mode 100644
index 0000000..d5ccc46
--- /dev/null
+++ b/libc/arch-sh/syscalls/symlink.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type symlink, @function
+    .globl symlink
+    .align 4
+
+symlink:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_symlink_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_symlink_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_symlink
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/sync.S b/libc/arch-sh/syscalls/sync.S
new file mode 100644
index 0000000..a8c0646
--- /dev/null
+++ b/libc/arch-sh/syscalls/sync.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type sync, @function
+    .globl sync
+    .align 4
+
+sync:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_sync_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_sync_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_sync
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/times.S b/libc/arch-sh/syscalls/times.S
new file mode 100644
index 0000000..079e098
--- /dev/null
+++ b/libc/arch-sh/syscalls/times.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type times, @function
+    .globl times
+    .align 4
+
+times:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_times_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_times_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_times
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/tkill.S b/libc/arch-sh/syscalls/tkill.S
new file mode 100644
index 0000000..b6fe2a3
--- /dev/null
+++ b/libc/arch-sh/syscalls/tkill.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type tkill, @function
+    .globl tkill
+    .align 4
+
+tkill:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_tkill_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_tkill_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_tkill
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/truncate.S b/libc/arch-sh/syscalls/truncate.S
new file mode 100644
index 0000000..dc08fcc
--- /dev/null
+++ b/libc/arch-sh/syscalls/truncate.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type truncate, @function
+    .globl truncate
+    .align 4
+
+truncate:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_truncate_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_truncate_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_truncate
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/umask.S b/libc/arch-sh/syscalls/umask.S
new file mode 100644
index 0000000..7575a1c
--- /dev/null
+++ b/libc/arch-sh/syscalls/umask.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type umask, @function
+    .globl umask
+    .align 4
+
+umask:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_umask_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_umask_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_umask
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/umount2.S b/libc/arch-sh/syscalls/umount2.S
new file mode 100644
index 0000000..06a11da
--- /dev/null
+++ b/libc/arch-sh/syscalls/umount2.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type umount2, @function
+    .globl umount2
+    .align 4
+
+umount2:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_umount2_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_umount2_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_umount2
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/uname.S b/libc/arch-sh/syscalls/uname.S
new file mode 100644
index 0000000..755c9de
--- /dev/null
+++ b/libc/arch-sh/syscalls/uname.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type uname, @function
+    .globl uname
+    .align 4
+
+uname:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_uname_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_uname_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_uname
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/unlink.S b/libc/arch-sh/syscalls/unlink.S
new file mode 100644
index 0000000..453d58a
--- /dev/null
+++ b/libc/arch-sh/syscalls/unlink.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type unlink, @function
+    .globl unlink
+    .align 4
+
+unlink:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_unlink_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_unlink_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_unlink
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/unlinkat.S b/libc/arch-sh/syscalls/unlinkat.S
new file mode 100644
index 0000000..7a448a3
--- /dev/null
+++ b/libc/arch-sh/syscalls/unlinkat.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type unlinkat, @function
+    .globl unlinkat
+    .align 4
+
+unlinkat:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_unlinkat_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_unlinkat_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_unlinkat
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/utimes.S b/libc/arch-sh/syscalls/utimes.S
new file mode 100644
index 0000000..fecaa66
--- /dev/null
+++ b/libc/arch-sh/syscalls/utimes.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type utimes, @function
+    .globl utimes
+    .align 4
+
+utimes:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(2 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_utimes_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_utimes_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_utimes
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/vfork.S b/libc/arch-sh/syscalls/vfork.S
new file mode 100644
index 0000000..2a2c78b
--- /dev/null
+++ b/libc/arch-sh/syscalls/vfork.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type vfork, @function
+    .globl vfork
+    .align 4
+
+vfork:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(1 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_vfork_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_vfork_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_vfork
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/waitid.S b/libc/arch-sh/syscalls/waitid.S
new file mode 100644
index 0000000..1f0432d
--- /dev/null
+++ b/libc/arch-sh/syscalls/waitid.S
@@ -0,0 +1,35 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type waitid, @function
+    .globl waitid
+    .align 4
+
+waitid:
+
+    /* get ready for additonal arg */
+    mov.l   @r15, r0
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(5 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_waitid_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_waitid_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_waitid
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/write.S b/libc/arch-sh/syscalls/write.S
new file mode 100644
index 0000000..71c6ea8
--- /dev/null
+++ b/libc/arch-sh/syscalls/write.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type write, @function
+    .globl write
+    .align 4
+
+write:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_write_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_write_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_write
+1:  .long   __set_syscall_errno
diff --git a/libc/arch-sh/syscalls/writev.S b/libc/arch-sh/syscalls/writev.S
new file mode 100644
index 0000000..518ae28
--- /dev/null
+++ b/libc/arch-sh/syscalls/writev.S
@@ -0,0 +1,32 @@
+/* autogenerated by gensyscalls.py */
+#include <sys/linux-syscalls.h>
+
+    .text
+    .type writev, @function
+    .globl writev
+    .align 4
+
+writev:
+
+    /* invoke trap */
+    mov.l   0f, r3  /* trap num */
+    trapa   #(3 + 0x10)
+
+    /* check return value */
+    cmp/pz  r0
+    bt      __NR_writev_end
+
+    /* keep error number */
+    sts.l   pr, @-r15
+    mov.l   1f, r1
+    jsr     @r1
+    mov     r0, r4
+    lds.l   @r15+, pr
+
+__NR_writev_end:
+    rts
+    nop
+
+    .align  2
+0:  .long   __NR_writev
+1:  .long   __set_syscall_errno
diff --git a/libc/bionic/dlmalloc.c b/libc/bionic/dlmalloc.c
index 78f20c0..f6f878e 100644
--- a/libc/bionic/dlmalloc.c
+++ b/libc/bionic/dlmalloc.c
@@ -1154,6 +1154,23 @@
 */
 void* mspace_realloc(mspace msp, void* mem, size_t newsize);
 
+#if ANDROID /* Added for Android, not part of dlmalloc as released */
+/*
+  mspace_merge_objects will merge allocated memory mema and memb
+  together, provided memb immediately follows mema.  It is roughly as
+  if memb has been freed and mema has been realloced to a larger size.
+  On successfully merging, mema will be returned. If either argument
+  is null or memb does not immediately follow mema, null will be
+  returned.
+
+  Both mema and memb should have been previously allocated using
+  malloc or a related routine such as realloc. If either mema or memb
+  was not malloced or was previously freed, the result is undefined,
+  but like mspace_free, the default is to abort the program.
+*/
+void* mspace_merge_objects(mspace msp, void* mema, void* memb);
+#endif
+
 /*
   mspace_calloc behaves as calloc, but operates within
   the given space.
@@ -4872,6 +4889,62 @@
   }
 }
 
+#if ANDROID
+void* mspace_merge_objects(mspace msp, void* mema, void* memb)
+{
+  /* PREACTION/POSTACTION aren't necessary because we are only
+     modifying fields of inuse chunks owned by the current thread, in
+     which case no other malloc operations can touch them.
+   */
+  if (mema == NULL || memb == NULL) {
+    return NULL;
+  }
+  mchunkptr pa = mem2chunk(mema);
+  mchunkptr pb = mem2chunk(memb);
+
+#if FOOTERS
+  mstate fm = get_mstate_for(pa);
+#else /* FOOTERS */
+  mstate fm = (mstate)msp;
+#endif /* FOOTERS */
+  if (!ok_magic(fm)) {
+    USAGE_ERROR_ACTION(fm, pa);
+    return NULL;
+  }
+  check_inuse_chunk(fm, pa);
+  if (RTCHECK(ok_address(fm, pa) && ok_cinuse(pa))) {
+    if (next_chunk(pa) != pb) {
+      /* Since pb may not be in fm, we can't check ok_address(fm, pb);
+         since ok_cinuse(pb) would be unsafe before an address check,
+         return NULL rather than invoke USAGE_ERROR_ACTION if pb is not
+         in use or is a bogus address.
+       */
+      return NULL;
+    }
+    /* Since b follows a, they share the mspace. */
+#if FOOTERS
+    assert(fm == get_mstate_for(pb));
+#endif /* FOOTERS */
+    check_inuse_chunk(fm, pb);
+    if (RTCHECK(ok_address(fm, pb) && ok_cinuse(pb))) {
+      size_t sz = chunksize(pb);
+      pa->head += sz;
+      /* Make sure pa still passes. */
+      check_inuse_chunk(fm, pa);
+      return mema;
+    }
+    else {
+      USAGE_ERROR_ACTION(fm, pb);
+      return NULL;
+    }
+  }
+  else {
+    USAGE_ERROR_ACTION(fm, pa);
+    return NULL;
+  }
+}
+#endif /* ANDROID */
+
 void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) {
   mstate ms = (mstate)msp;
   if (!ok_magic(ms)) {
diff --git a/libc/bionic/dlmalloc.h b/libc/bionic/dlmalloc.h
index 75b5e1f..e5f7d4a 100644
--- a/libc/bionic/dlmalloc.h
+++ b/libc/bionic/dlmalloc.h
@@ -547,6 +547,21 @@
 void* mspace_realloc(mspace msp, void* mem, size_t newsize);
 
 /*
+  mspace_merge_objects will merge allocated memory mema and memb
+  together, provided memb immediately follows mema.  It is roughly as
+  if memb has been freed and mema has been realloced to a larger size.
+  On successfully merging, mema will be returned. If either argument
+  is null or memb does not immediately follow mema, null will be
+  returned.
+
+  Both mema and memb should have been previously allocated using
+  malloc or a related routine such as realloc. If either mema or memb
+  was not malloced or was previously freed, the result is undefined,
+  but like mspace_free, the default is to abort the program.
+*/
+void* mspace_merge_objects(mspace msp, void* mema, void* memb);
+
+/*
   mspace_calloc behaves as calloc, but operates within
   the given space.
 */
diff --git a/libc/bionic/eabi.c b/libc/bionic/eabi.c
index f212d05..a5f6627 100644
--- a/libc/bionic/eabi.c
+++ b/libc/bionic/eabi.c
@@ -28,15 +28,24 @@
 #include <stddef.h>
 #include <string.h>
 
+extern int  __cxa_atexit(void (*)(void*), void*, void* );
+
 void* __dso_handle = 0;
 
+/* The "C++ ABI for ARM" document states that static C++ constructors,
+ * which are called from the .init_array, should manually call
+ * __aeabi_atexit() to register static destructors explicitely.
+ *
+ * Note that 'dso_handle' is the address of a magic linker-generate
+ * variable from the shared object that contains the constructor/destructor
+ */
+
 /* Make this a weak symbol to avoid a multiple definition error when linking
  * with libstdc++-v3.  */
 int __attribute__((weak))
 __aeabi_atexit (void *object, void (*destructor) (void *), void *dso_handle)
 {
-    //return __cxa_atexit(destructor, object, dso_handle);
-    return 0;
+    return __cxa_atexit(destructor, object, dso_handle);
 }
 
 
diff --git a/libc/bionic/libc_init_common.c b/libc/bionic/libc_init_common.c
index de4919d..d78d673 100644
--- a/libc/bionic/libc_init_common.c
+++ b/libc/bionic/libc_init_common.c
@@ -39,23 +39,6 @@
 #include <bionic_tls.h>
 #include <errno.h>
 
-extern void _init(void);
-extern void _fini(void);
-
-static void call_array(void(**list)())
-{
-    // First element is -1, list is null-terminated
-    while (*++list) {
-        (*list)();
-    }
-}
-
-static void __bionic_do_global_dtors(structors_array_t const * const p)
-{
-    call_array(p->fini_array);
-    //_fini();
-}
-
 extern unsigned __get_sp(void);
 extern pid_t    gettid(void);
 
@@ -69,23 +52,19 @@
 
 int __system_properties_init(void);
 
-void __libc_init_common(uintptr_t *elfdata,
-                       void (*onexit)(void),
-                       int (*slingshot)(int, char**, char**),
-                       structors_array_t const * const structors,
-                       void (*pre_ctor_hook)())
+void __libc_init_common(uintptr_t *elfdata)
 {
-    pthread_internal_t thread;
-    pthread_attr_t thread_attr;
-    void *tls_area[BIONIC_TLS_SLOTS];
-    int argc;
-    char **argv, **envp, **envend;
-    struct auxentry *auxentry;
-    unsigned int page_size = 0, page_shift = 0;
+    int     argc = *elfdata;
+    char**  argv = (char**)(elfdata + 1);
+    char**  envp = argv + argc + 1;
 
-    /* The main thread's stack has empirically shown to be 84k */
+    pthread_attr_t             thread_attr;
+    static pthread_internal_t  thread;
+    static void*               tls_area[BIONIC_TLS_SLOTS];
+
+    /* setup pthread runtime and maint thread descriptor */
     unsigned stacktop = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
-    unsigned stacksize = 128 * 1024; //84 * 1024;
+    unsigned stacksize = 128 * 1024;
     unsigned stackbottom = stacktop - stacksize;
 
     pthread_attr_init(&thread_attr);
@@ -93,30 +72,15 @@
     _init_thread(&thread, gettid(), &thread_attr, (void*)stackbottom);
     __init_tls(tls_area, &thread);
 
-    argc = (int) *elfdata++;
-    argv = (char**) elfdata;
-    envp = argv+(argc+1);
-    environ = envp;
-
-    __progname = argv[0] ? argv[0] : "<unknown>";
-
+    /* clear errno - requires TLS area */
     errno = 0;
 
+    /* set program name */
+    __progname = argv[0] ? argv[0] : "<unknown>";
+
+    /* setup environment pointer */
+    environ = envp;
+
+    /* setup system properties - requires environment */
     __system_properties_init();
-
-    if (pre_ctor_hook) pre_ctor_hook();
-
-    // XXX: we should execute the .fini_array upon exit
-
-    // pre-init array.
-    // XXX: I'm not sure what's the different with the init array.
-    call_array(structors->preinit_array);
-
-    // for compatibility with non-eabi binary, call the .ctors section
-    call_array(structors->ctors_array);
-
-    // call static constructors
-    call_array(structors->init_array);
-
-    exit(slingshot(argc, argv, envp));
 }
diff --git a/libc/bionic/libc_init_common.h b/libc/bionic/libc_init_common.h
index bbc82e4..8663c61 100644
--- a/libc/bionic/libc_init_common.h
+++ b/libc/bionic/libc_init_common.h
@@ -38,10 +38,6 @@
     void (**ctors_array)(void);
 } structors_array_t;
 
-extern __noreturn void __libc_init_common(uintptr_t *elfdata,
-                       void (*onexit)(void),
-                       int (*slingshot)(int, char**, char**),
-                       structors_array_t const * const structors,
-                       void (*pre_ctor_hook)());
+extern void __libc_init_common(uintptr_t *elfdata);
 
 #endif
diff --git a/libc/bionic/libc_init_dynamic.c b/libc/bionic/libc_init_dynamic.c
index 8cf24b4..b479b27 100644
--- a/libc/bionic/libc_init_dynamic.c
+++ b/libc/bionic/libc_init_dynamic.c
@@ -26,41 +26,81 @@
  * SUCH DAMAGE.
  */
 /*
- * libc_init_static.c
+ * libc_init_dynamic.c
  *
- * This function takes the raw data block set up by the ELF loader
- * in the kernel and parses it.  It is invoked by crt0.S which makes
- * any necessary adjustments and passes calls this function using
- * the standard C calling convention.
+ * This source files provides two important functions for dynamic
+ * executables:
  *
- * The arguments are:
- *  uintptr_t *elfdata	 -- The ELF loader data block; usually from the stack.
- *                          Basically a pointer to argc.
- *  void (*onexit)(void) -- Function to install into onexit
+ * - a C runtime initializer (__libc_preinit), which is called by
+ *   the dynamic linker when libc.so is loaded. This happens before
+ *   any other initializer (e.g. static C++ constructors in other
+ *   shared libraries the program depends on).
+ *
+ * - a program launch function (__libc_init), which is called after
+ *   all dynamic linking has been performed. Technically, it is called
+ *   from arch-$ARCH/bionic/crtbegin_dynamic.S which is itself called
+ *   by the dynamic linker after all libraries have been loaded and
+ *   initialized.
  */
 
-/*
- * Several Linux ABIs don't pass the onexit pointer, and the ones that
- * do never use it.  Therefore, unless USE_ONEXIT is defined, we just
- * ignore the onexit pointer.
- */
-/* #define USE_ONEXIT */
-
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <elf.h>
-#include "pthread_internal.h"
 #include "atexit.h"
 #include "libc_init_common.h"
+#include <bionic_tls.h>
 
 extern void malloc_debug_init();
 
+/* We flag the __libc_preinit function as a constructor to ensure
+ * that its address is listed in libc.so's .init_array section.
+ * This ensures that the function is called by the dynamic linker
+ * as soon as the shared library is loaded.
+ */
+void __attribute__((constructor)) __libc_prenit(void);
+
+void __libc_prenit(void)
+{
+    /* Read the ELF data pointer form a special slot of the
+     * TLS area, then call __libc_init_common with it.
+     *
+     * Note that:
+     * - we clear the slot so no other initializer sees its value.
+     * - __libc_init_common() will change the TLS area so the old one
+     *   won't be accessible anyway.
+     */
+    void**      tls_area = (void**)__get_tls();
+    unsigned*   elfdata   = tls_area[TLS_SLOT_BIONIC_PREINIT];
+
+    tls_area[TLS_SLOT_BIONIC_PREINIT] = NULL;
+
+    __libc_init_common(elfdata);
+
+#ifdef MALLOC_LEAK_CHECK
+    /* setup malloc leak checker, requires system properties */
+    extern void malloc_debug_init(void);
+    malloc_debug_init();
+#endif
+
+}
+
 __noreturn void __libc_init(uintptr_t *elfdata,
                        void (*onexit)(void),
                        int (*slingshot)(int, char**, char**),
                        structors_array_t const * const structors)
 {
-    __libc_init_common(elfdata, onexit, slingshot, structors, malloc_debug_init);
+    /* When we reach this point, all initializers have been already
+     * run by the dynamic linker, so ignore 'structors'.
+     */
+    int     argc = (int)*elfdata;
+    char**  argv = (char**)(elfdata + 1);
+    char**  envp = argv + argc + 1;
+
+    /* Several Linux ABIs don't pass the onexit pointer, and the ones that
+     * do never use it.  Therefore, we ignore it.
+     */
+
+    exit(slingshot(argc, argv, envp));
 }
diff --git a/libc/bionic/libc_init_static.c b/libc/bionic/libc_init_static.c
index ec463f7..e6264bb 100644
--- a/libc/bionic/libc_init_static.c
+++ b/libc/bionic/libc_init_static.c
@@ -28,24 +28,15 @@
 /*
  * libc_init_static.c
  *
- * This function takes the raw data block set up by the ELF loader
- * in the kernel and parses it.  It is invoked by crt0.S which makes
- * any necessary adjustments and passes calls this function using
- * the standard C calling convention.
+ * The program startup function __libc_init() defined here is
+ * used for static executables only (i.e. those that don't depend
+ * on shared libraries). It is called from arch-$ARCH/bionic/crtbegin_static.S
+ * which is directly invoked by the kernel when the program is launched.
  *
- * The arguments are:
- *  uintptr_t *elfdata	 -- The ELF loader data block; usually from the stack.
- *                          Basically a pointer to argc.
- *  void (*onexit)(void) -- Function to install into onexit
+ * The 'structors' parameter contains pointers to various initializer
+ * arrays that must be run before the program's 'main' routine is launched.
  */
 
-/*
- * Several Linux ABIs don't pass the onexit pointer, and the ones that
- * do never use it.  Therefore, unless USE_ONEXIT is defined, we just
- * ignore the onexit pointer.
- */
-/* #define USE_ONEXIT */
-
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -58,19 +49,47 @@
 #include <bionic_tls.h>
 #include <errno.h>
 
+static void call_array(void(**list)())
+{
+    // First element is -1, list is null-terminated
+    while (*++list) {
+        (*list)();
+    }
+}
+
 __noreturn void __libc_init(uintptr_t *elfdata,
                        void (*onexit)(void),
                        int (*slingshot)(int, char**, char**),
                        structors_array_t const * const structors)
 {
-/* 
- * To enable malloc checks for statically linked programs, add
- * "WITH_MALLOC_CHECK_LIBC_A := true" in device/buildspec.mk
- */
+    int  argc;
+    char **argv, **envp;
+
+    /* Initialize the C runtime environment */
+    __libc_init_common(elfdata);
+
 #ifdef MALLOC_LEAK_CHECK
-    extern void malloc_debug_init();
-    __libc_init_common(elfdata, onexit, slingshot, structors, malloc_debug_init);
-#else
-    __libc_init_common(elfdata, onexit, slingshot, structors, NULL);
+    /* setup malloc leak checker, requires system properties */
+    extern void malloc_debug_init(void);
+    malloc_debug_init();
 #endif
+
+    /* Several Linux ABIs don't pass the onexit pointer, and the ones that
+     * do never use it.  Therefore, we ignore it.
+     */
+
+    /* pre-init array. */
+    call_array(structors->preinit_array);
+
+    /* .ctors section initializers, for non-arm-eabi ABIs */
+    call_array(structors->ctors_array);
+
+    // call static constructors
+    call_array(structors->init_array);
+
+    argc = (int) *elfdata;
+    argv = (char**)(elfdata + 1);
+    envp = argv + argc + 1;
+
+    exit(slingshot(argc, argv, envp));
 }
diff --git a/libc/bionic/logd_write.c b/libc/bionic/logd_write.c
index 7c3608b..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,14 +140,14 @@
     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);
 }
 
 
-static int __android_log_vprint(int prio, const char *tag, const char *fmt,
-				va_list ap)
+int __libc_android_log_vprint(int prio, const char *tag, const char *fmt,
+                              va_list ap)
 {
-    char buf[LOG_BUF_SIZE];    
+    char buf[LOG_BUF_SIZE];
 
     vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
 
@@ -139,7 +157,7 @@
 int __libc_android_log_print(int prio, const char *tag, const char *fmt, ...)
 {
     va_list ap;
-    char buf[LOG_BUF_SIZE];    
+    char buf[LOG_BUF_SIZE];
 
     va_start(ap, fmt);
     vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
diff --git a/libc/bionic/malloc_leak.c b/libc/bionic/malloc_leak.c
index a0aa2ae..305f954 100644
--- a/libc/bionic/malloc_leak.c
+++ b/libc/bionic/malloc_leak.c
@@ -91,7 +91,14 @@
 static HashTable gHashTable;
 
 // =============================================================================
-// output fucntions
+// log functions
+// =============================================================================
+
+#define debug_log(format, ...)  \
+    __libc_android_log_print(ANDROID_LOG_DEBUG, "malloc_leak", (format), ##__VA_ARGS__ )
+
+// =============================================================================
+// output functions
 // =============================================================================
 
 static int hash_entry_compare(const void* arg1, const void* arg2)
@@ -257,12 +264,6 @@
     uint32_t guard;
 };
 
-// =============================================================================
-// log funtions
-// =============================================================================
-
-#define debug_log(format, ...)  \
-    __libc_android_log_print(ANDROID_LOG_DEBUG, "malloc_leak", (format), ##__VA_ARGS__ )
 
 // =============================================================================
 // Hash Table functions
@@ -515,8 +516,8 @@
 
     tmp[0] = 0; // Need to initialize tmp[0] for the first strcat
     for (i=0 ; i<c; i++) {
-        sprintf(buf, "%2d: %08x\n", i, addrs[i]);
-        strcat(tmp, buf);
+        snprintf(buf, sizeof buf, "%2d: %08x\n", i, addrs[i]);
+        strlcat(tmp, buf, sizeof tmp);
     }
     __libc_android_log_print(ANDROID_LOG_ERROR, "libc", "call stack:\n%s", tmp);
 }
@@ -526,69 +527,90 @@
     return 1;
 }
 
+static void assert_log_message(const char* format, ...)
+{
+    va_list  args;
+
+    pthread_mutex_lock(&gAllocationsMutex);
+        gMallocDispatch = &gMallocEngineTable[INDEX_NORMAL];
+        va_start(args, format);
+        __libc_android_log_vprint(ANDROID_LOG_ERROR, "libc",
+                                format, args);
+        va_end(args);
+        dump_stack_trace();
+        if (gTrapOnError) {
+            __builtin_trap();
+        }
+        gMallocDispatch = &gMallocEngineTable[INDEX_MALLOC_CHECK];
+    pthread_mutex_unlock(&gAllocationsMutex);
+}
+
 static void assert_valid_malloc_pointer(void* mem)
 {
     if (mem && !is_valid_malloc_pointer(mem)) {
-        pthread_mutex_lock(&gAllocationsMutex);
-        gMallocDispatch = &gMallocEngineTable[INDEX_NORMAL];
-            __libc_android_log_print(ANDROID_LOG_ERROR, "libc",
-                    "*** MALLOC CHECK: buffer %p, is not a valid "
-                    "malloc pointer (are you mixing up new/delete "
-                    "and malloc/free?)", mem);
-            dump_stack_trace();
-                if (gTrapOnError) {
-                    __builtin_trap();
-                }
-        gMallocDispatch = &gMallocEngineTable[INDEX_MALLOC_CHECK];
-        pthread_mutex_unlock(&gAllocationsMutex);
+        assert_log_message(
+            "*** MALLOC CHECK: buffer %p, is not a valid "
+            "malloc pointer (are you mixing up new/delete "
+            "and malloc/free?)", mem);
     }
 }
 
-static void chk_out_of_bounds_check__locked(void* buffer, size_t size)
+/* Check that a given address corresponds to a guarded block,
+ * and returns its original allocation size in '*allocated'.
+ * 'func' is the capitalized name of the caller function.
+ * Returns 0 on success, or -1 on failure.
+ * NOTE: Does not return if gTrapOnError is set.
+ */
+static int chk_mem_check(void*       mem,
+                         size_t*     allocated,
+                         const char* func)
 {
-    int i;
-    char* buf = (char*)buffer - CHK_SENTINEL_HEAD_SIZE;
+    char*  buffer;
+    size_t offset, bytes;
+    int    i;
+    char*  buf;
+
+    /* first check the bytes in the sentinel header */
+    buf = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
     for (i=0 ; i<CHK_SENTINEL_HEAD_SIZE ; i++) {
         if (buf[i] != CHK_SENTINEL_VALUE) {
-            gMallocDispatch = &gMallocEngineTable[INDEX_NORMAL];
-            __libc_android_log_print(ANDROID_LOG_ERROR, "libc",
-                    "*** MALLOC CHECK: buffer %p, size=%lu, "
-                    "corrupted %d bytes before allocation",
-                    buffer, size, CHK_SENTINEL_HEAD_SIZE-i);
-            dump_stack_trace();
-            if (gTrapOnError) {
-                __builtin_trap();
-            }
-            gMallocDispatch = &gMallocEngineTable[INDEX_MALLOC_CHECK];
+            assert_log_message( 
+                "*** %s CHECK: buffer %p "
+                "corrupted %d bytes before allocation",
+                func, mem, CHK_SENTINEL_HEAD_SIZE-i);
+            return -1;
         }
     }
-    buf = (char*)buffer + size;
+
+    /* then the ones in the sentinel trailer */
+    buffer = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
+    offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
+    bytes  = *(size_t *)(buffer + offset);
+
+    buf = (char*)mem + bytes;
     for (i=CHK_SENTINEL_TAIL_SIZE-1 ; i>=0 ; i--) {
         if (buf[i] != CHK_SENTINEL_VALUE) {
-            gMallocDispatch = &gMallocEngineTable[INDEX_NORMAL];
-            __libc_android_log_print(ANDROID_LOG_ERROR, "libc",
-                    "*** MALLOC CHECK: buffer %p, size=%lu, "
-                    "corrupted %d bytes after allocation",
-                    buffer, size, i+1);
-            dump_stack_trace();
-            if (gTrapOnError) {
-                __builtin_trap();
-            }
-            gMallocDispatch = &gMallocEngineTable[INDEX_MALLOC_CHECK];
+            assert_log_message( 
+                "*** %s CHECK: buffer %p, size=%lu, "
+                "corrupted %d bytes after allocation",
+                func, buffer, bytes, i+1);
+            return -1;
         }
     }
+
+    *allocated = bytes;
+    return 0;
 }
 
+
 void* chk_malloc(size_t bytes)
 {
     char* buffer = (char*)dlmalloc(bytes + CHK_OVERHEAD_SIZE);
     if (buffer) {
-        pthread_mutex_lock(&gAllocationsMutex);
-            memset(buffer, CHK_SENTINEL_VALUE, bytes + CHK_OVERHEAD_SIZE);
-            size_t offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
-            *(size_t *)(buffer + offset) = bytes;
-            buffer += CHK_SENTINEL_HEAD_SIZE;
-        pthread_mutex_unlock(&gAllocationsMutex);
+        memset(buffer, CHK_SENTINEL_VALUE, bytes + CHK_OVERHEAD_SIZE);
+        size_t offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
+        *(size_t *)(buffer + offset) = bytes;
+        buffer += CHK_SENTINEL_HEAD_SIZE;
     }
     return buffer;
 }
@@ -597,14 +619,14 @@
 {
     assert_valid_malloc_pointer(mem);
     if (mem) {
-        pthread_mutex_lock(&gAllocationsMutex);
-            char* buffer = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
-            size_t offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
-            size_t bytes = *(size_t *)(buffer + offset);
-            chk_out_of_bounds_check__locked(mem, bytes);
-        pthread_mutex_unlock(&gAllocationsMutex);
-        memset(buffer, CHK_FILL_FREE, bytes);
-        dlfree(buffer);
+        size_t  size;
+        char*   buffer;
+
+        if (chk_mem_check(mem, &size, "FREE") == 0) {
+            buffer = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
+            memset(buffer, CHK_FILL_FREE, size + CHK_OVERHEAD_SIZE);
+            dlfree(buffer);
+        }
     }
 }
 
@@ -628,19 +650,20 @@
 
 void* chk_realloc(void* mem, size_t bytes)
 {
+    char*   buffer;
+    int     ret;
+    size_t  old_bytes = 0;
+
     assert_valid_malloc_pointer(mem);
+
+    if (mem != NULL && chk_mem_check(mem, &old_bytes, "REALLOC") < 0)
+        return NULL;
+
     char* new_buffer = chk_malloc(bytes);
     if (mem == NULL) {
         return new_buffer;
     }
 
-    pthread_mutex_lock(&gAllocationsMutex);
-        char* buffer = (char*)mem - CHK_SENTINEL_HEAD_SIZE;
-        size_t offset = dlmalloc_usable_size(buffer) - sizeof(size_t);
-        size_t old_bytes = *(size_t *)(buffer + offset);
-        chk_out_of_bounds_check__locked(mem, old_bytes);
-    pthread_mutex_unlock(&gAllocationsMutex);
-
     if (new_buffer) {
         size_t size = (bytes < old_bytes)?(bytes):(old_bytes);
         memcpy(new_buffer, mem, size);
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index ec3c459..d2c81a3 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -1215,22 +1215,12 @@
                             pthread_mutex_t * mutex,
                             unsigned msecs)
 {
-    int oldvalue;
     struct timespec ts;
-    int status;
 
     ts.tv_sec = msecs / 1000;
     ts.tv_nsec = (msecs % 1000) * 1000000;
 
-    oldvalue = cond->value;
-
-    pthread_mutex_unlock(mutex);
-    status = __futex_wait(&cond->value, oldvalue, &ts);
-    pthread_mutex_lock(mutex);
-
-    if(status == (-ETIMEDOUT)) return ETIMEDOUT;
-
-    return 0;
+    return __pthread_cond_timedwait_relative(cond, mutex, &ts);
 }
 
 
diff --git a/libc/docs/ISSUES.TXT b/libc/docs/ISSUES.TXT
new file mode 100644
index 0000000..b53eb16
--- /dev/null
+++ b/libc/docs/ISSUES.TXT
@@ -0,0 +1,20 @@
+Bionic C Library Issues:
+========================
+
+This document lists important known issues of various releases
+of the Bionic C library. Note that these differ from specific
+implementation choices that are documented in the OVERVIEW.TXT
+document.
+
+Currently known issues:
+-----------------------
+
+- The C library initialization will improperly run static C++
+  constructors located in shared libraries twice.
+
+Android-1.5 issues:
+-------------------
+
+- getservbyname() returned the port number in the s_port field of
+  the 'struct servent' structure in host-byte-order, instead of
+  network-byte-order.
diff --git a/libc/include/stdint.h b/libc/include/stdint.h
index 39a8ab8..237baa2 100644
--- a/libc/include/stdint.h
+++ b/libc/include/stdint.h
@@ -46,13 +46,17 @@
 #  define  __STDINT_MACROS
 #endif
 
+#if !defined __STRICT_ANSI__ || __STDC_VERSION__ >= 199901L
+#  define __STDC_INT64__
+#endif
+
 typedef __int8_t      int8_t;
 typedef __uint8_t     uint8_t;
 typedef __int16_t     int16_t;
 typedef __uint16_t    uint16_t;
 typedef __int32_t     int32_t;
 typedef __uint32_t    uint32_t;
-#if !defined(__STRICT_ANSI__)
+#if defined(__STDC_INT64__)
 typedef __int64_t     int64_t;
 typedef __uint64_t    uint64_t;
 #endif
@@ -157,7 +161,7 @@
 #  define UINT_FAST32_C(c) UINT32_C(c)
 #endif
 
-#if !defined(__STRICT_ANSI__)
+#if defined(__STDC_INT64__)
 /*
  *  int64_t
  */
@@ -198,7 +202,7 @@
 #  define __PRIFAST_RANK ""
 #  define __PRIPTR_RANK  ""
 
-#endif /* !__STRICT_ANSI__ */
+#endif /* __STDC_INT64__ */
 
 /*
  * intptr_t & uintptr_t
@@ -221,7 +225,7 @@
  *  intmax_t & uintmax_t
  */
 
-#if !defined(__STRICT_ANSI__)
+#if defined(__STDC_INT64__)
 
 typedef uint64_t uintmax_t;
 typedef int64_t  intmax_t;
@@ -233,7 +237,7 @@
 #define INTMAX_C(c)	INT64_C(c)
 #define UINTMAX_C(c)	UINT64_C(c)
 
-#else /* __STRICT_ANSI__ */
+#else /* !__STDC_INT64__ */
 
 typedef uint32_t  uintmax_t;
 typedef int32_t   intmax_t;
@@ -245,7 +249,7 @@
 #define INTMAX_C(c)	INT32_C(c)
 #define UINTMAX_C(c)	UINT32_C(c)
 
-#endif /* __STRICT_ANSI__ */
+#endif /* !__STDC_INT64__ */
 
 
 /* size_t is defined by the GCC-specific <stddef.h> */
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/include/sys/_sigdefs.h b/libc/include/sys/_sigdefs.h
index a3cb7a3..6822c25 100644
--- a/libc/include/sys/_sigdefs.h
+++ b/libc/include/sys/_sigdefs.h
@@ -25,41 +25,46 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-/* this header is used to define signal constants and names; it might be included several times */
+
+/*
+ * this header is used to define signal constants and names;
+ * it might be included several times
+ */
+
 #ifndef __BIONIC_SIGDEF
 #error __BIONIC_SIGDEF not defined
 #endif
 
-__BIONIC_SIGDEF(SIGHUP,1,"Hangup")
-__BIONIC_SIGDEF(SIGINT,2,"Interrupt")
-__BIONIC_SIGDEF(SIGQUIT,3,"Quit")
-__BIONIC_SIGDEF(SIGILL,4,"Illegal instruction")
-__BIONIC_SIGDEF(SIGTRAP,5,"Trap")
-__BIONIC_SIGDEF(SIGABRT,6,"Aborted")
-__BIONIC_SIGDEF(SIGBUS,7,"Bus error")
-__BIONIC_SIGDEF(SIGFPE,8,"Floating point exception")
-__BIONIC_SIGDEF(SIGKILL,9,"Killed")
-__BIONIC_SIGDEF(SIGUSR1,10,"User signal 1")
-__BIONIC_SIGDEF(SIGSEGV,11,"Segmentation fault")
-__BIONIC_SIGDEF(SIGUSR2,12,"User signal 2")
-__BIONIC_SIGDEF(SIGPIPE,13,"Broken pipe")
-__BIONIC_SIGDEF(SIGALRM,14,"Alarm clock")
-__BIONIC_SIGDEF(SIGTERM,15,"Terminated")
-__BIONIC_SIGDEF(SIGSTKFLT,16,"Stack fault")
-__BIONIC_SIGDEF(SIGCHLD,17,"Child exited")
-__BIONIC_SIGDEF(SIGCONT,18,"Continue")
-__BIONIC_SIGDEF(SIGSTOP,19,"Stopped (signal)")
-__BIONIC_SIGDEF(SIGTSTP,20,"Stopped")
-__BIONIC_SIGDEF(SIGTTIN,21,"Stopped (tty input)")
-__BIONIC_SIGDEF(SIGTTOU,22,"Stopper (tty output)")
-__BIONIC_SIGDEF(SIGURG,23,"Urgent I/O condition")
-__BIONIC_SIGDEF(SIGXCPU,24,"CPU time limit exceeded")
-__BIONIC_SIGDEF(SIGXFSZ,25,"File size limit exceeded")
-__BIONIC_SIGDEF(SIGVTALRM,26,"Virtual timer expired")
-__BIONIC_SIGDEF(SIGPROF,27,"Profiling timer expired")
-__BIONIC_SIGDEF(SIGWINCH,28,"Window size changed")
-__BIONIC_SIGDEF(SIGIO,29,"I/O possible")
-__BIONIC_SIGDEF(SIGPWR,30,"Power failure")
-__BIONIC_SIGDEF(SIGSYS,31,"Bad system call")
+__BIONIC_SIGDEF(HUP,1,"Hangup")
+__BIONIC_SIGDEF(INT,2,"Interrupt")
+__BIONIC_SIGDEF(QUIT,3,"Quit")
+__BIONIC_SIGDEF(ILL,4,"Illegal instruction")
+__BIONIC_SIGDEF(TRAP,5,"Trap")
+__BIONIC_SIGDEF(ABRT,6,"Aborted")
+__BIONIC_SIGDEF(BUS,7,"Bus error")
+__BIONIC_SIGDEF(FPE,8,"Floating point exception")
+__BIONIC_SIGDEF(KILL,9,"Killed")
+__BIONIC_SIGDEF(USR1,10,"User signal 1")
+__BIONIC_SIGDEF(SEGV,11,"Segmentation fault")
+__BIONIC_SIGDEF(USR2,12,"User signal 2")
+__BIONIC_SIGDEF(PIPE,13,"Broken pipe")
+__BIONIC_SIGDEF(ALRM,14,"Alarm clock")
+__BIONIC_SIGDEF(TERM,15,"Terminated")
+__BIONIC_SIGDEF(STKFLT,16,"Stack fault")
+__BIONIC_SIGDEF(CHLD,17,"Child exited")
+__BIONIC_SIGDEF(CONT,18,"Continue")
+__BIONIC_SIGDEF(STOP,19,"Stopped (signal)")
+__BIONIC_SIGDEF(TSTP,20,"Stopped")
+__BIONIC_SIGDEF(TTIN,21,"Stopped (tty input)")
+__BIONIC_SIGDEF(TTOU,22,"Stopper (tty output)")
+__BIONIC_SIGDEF(URG,23,"Urgent I/O condition")
+__BIONIC_SIGDEF(XCPU,24,"CPU time limit exceeded")
+__BIONIC_SIGDEF(XFSZ,25,"File size limit exceeded")
+__BIONIC_SIGDEF(VTALRM,26,"Virtual timer expired")
+__BIONIC_SIGDEF(PROF,27,"Profiling timer expired")
+__BIONIC_SIGDEF(WINCH,28,"Window size changed")
+__BIONIC_SIGDEF(IO,29,"I/O possible")
+__BIONIC_SIGDEF(PWR,30,"Power failure")
+__BIONIC_SIGDEF(SYS,31,"Bad system call")
 
 #undef __BIONIC_SIGDEF
diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h
index 7772f1e..5d2b55e 100644
--- a/libc/include/sys/linux-syscalls.h
+++ b/libc/include/sys/linux-syscalls.h
@@ -218,6 +218,60 @@
 #define __NR_inotify_rm_watch             (__NR_SYSCALL_BASE + 293)
 #endif
 
+#if defined(__SH3__) || defined(__SH4__) 
+#define __NR_exit_group                   (__NR_SYSCALL_BASE + 252)
+#define __NR_waitpid                      (__NR_SYSCALL_BASE + 7)
+#define __NR_waitid                       (__NR_SYSCALL_BASE + 284)
+#define __NR_kill                         (__NR_SYSCALL_BASE + 37)
+#define __NR_tkill                        (__NR_SYSCALL_BASE + 238)
+#define __NR_set_thread_area              (__NR_SYSCALL_BASE + 243)
+#define __NR_vfork                        (__NR_SYSCALL_BASE + 190)
+#define __NR_openat                       (__NR_SYSCALL_BASE + 295)
+#define __NR_madvise                      (__NR_SYSCALL_BASE + 219)
+#define __NR_mincore                      (__NR_SYSCALL_BASE + 218)
+#define __NR_getdents64                   (__NR_SYSCALL_BASE + 220)
+#define __NR_fstatfs64                    (__NR_SYSCALL_BASE + 269)
+#define __NR_fstatat64                    (__NR_SYSCALL_BASE + 300)
+#define __NR_mkdirat                      (__NR_SYSCALL_BASE + 296)
+#define __NR_fchownat                     (__NR_SYSCALL_BASE + 298)
+#define __NR_fchmodat                     (__NR_SYSCALL_BASE + 306)
+#define __NR_renameat                     (__NR_SYSCALL_BASE + 302)
+#define __NR_unlinkat                     (__NR_SYSCALL_BASE + 301)
+#define __NR_statfs64                     (__NR_SYSCALL_BASE + 268)
+#define __NR_clock_gettime                (__NR_SYSCALL_BASE + 265)
+#define __NR_clock_settime                (__NR_SYSCALL_BASE + 264)
+#define __NR_clock_getres                 (__NR_SYSCALL_BASE + 266)
+#define __NR_clock_nanosleep              (__NR_SYSCALL_BASE + 267)
+#define __NR_timer_create                 (__NR_SYSCALL_BASE + 259)
+#define __NR_timer_settime                (__NR_SYSCALL_BASE + 260)
+#define __NR_timer_gettime                (__NR_SYSCALL_BASE + 261)
+#define __NR_timer_getoverrun             (__NR_SYSCALL_BASE + 262)
+#define __NR_timer_delete                 (__NR_SYSCALL_BASE + 263)
+#define __NR_utimes                       (__NR_SYSCALL_BASE + 271)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR_socketcall                   (__NR_SYSCALL_BASE + 102)
+#define __NR___socketcall                 (__NR_SYSCALL_BASE + 102)
+#define __NR_epoll_create                 (__NR_SYSCALL_BASE + 254)
+#define __NR_epoll_ctl                    (__NR_SYSCALL_BASE + 255)
+#define __NR_epoll_wait                   (__NR_SYSCALL_BASE + 256)
+#define __NR_inotify_init                 (__NR_SYSCALL_BASE + 290)
+#define __NR_inotify_add_watch            (__NR_SYSCALL_BASE + 291)
+#define __NR_inotify_rm_watch             (__NR_SYSCALL_BASE + 292)
+#endif
+
 #endif
 
 #endif /* _BIONIC_LINUX_SYSCALLS_H_ */
diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h
index 789271e..12f7704 100644
--- a/libc/include/sys/linux-unistd.h
+++ b/libc/include/sys/linux-unistd.h
@@ -171,6 +171,7 @@
 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);
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 23ab5ae..091ee6d 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -71,6 +71,13 @@
     unsigned long long  st_ino;
 };
 
+/* For compatibility with GLibc, we provide macro aliases
+ * for the non-Posix nano-seconds accessors.
+ */
+#define  st_atimensec  st_atime_nsec
+#define  st_mtimensec  st_mtime_nsec
+#define  st_ctimensec  st_ctime_nsec
+
 extern int    chmod(const char *, mode_t);
 extern int    fchmod(int, mode_t);
 extern int    mkdir(const char *, mode_t);
diff --git a/libc/kernel/common/linux/if_pppolac.h b/libc/kernel/common/linux/if_pppolac.h
new file mode 100644
index 0000000..bf6eba0
--- /dev/null
+++ b/libc/kernel/common/linux/if_pppolac.h
@@ -0,0 +1,29 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __LINUX_IF_PPPOLAC_H
+#define __LINUX_IF_PPPOLAC_H
+
+#include <linux/socket.h>
+#include <linux/types.h>
+
+#define PX_PROTO_OLAC 2
+
+struct sockaddr_pppolac {
+ sa_family_t sa_family;
+ unsigned int sa_protocol;
+ int udp_socket;
+ struct __attribute__((packed)) {
+ __u16 tunnel, session;
+ } local, remote;
+} __attribute__((packed));
+
+#endif
diff --git a/libc/kernel/common/linux/if_pppopns.h b/libc/kernel/common/linux/if_pppopns.h
new file mode 100644
index 0000000..ac75210
--- /dev/null
+++ b/libc/kernel/common/linux/if_pppopns.h
@@ -0,0 +1,28 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __LINUX_IF_PPPOPNS_H
+#define __LINUX_IF_PPPOPNS_H
+
+#include <linux/socket.h>
+#include <linux/types.h>
+
+#define PX_PROTO_OPNS 3
+
+struct sockaddr_pppopns {
+ sa_family_t sa_family;
+ unsigned int sa_protocol;
+ int tcp_socket;
+ __u16 local;
+ __u16 remote;
+} __attribute__((packed));
+
+#endif
diff --git a/libc/kernel/common/linux/ipsec.h b/libc/kernel/common/linux/ipsec.h
new file mode 100644
index 0000000..56acafa
--- /dev/null
+++ b/libc/kernel/common/linux/ipsec.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _LINUX_IPSEC_H
+#define _LINUX_IPSEC_H
+
+#include <linux/pfkeyv2.h>
+
+#define IPSEC_PORT_ANY 0
+#define IPSEC_ULPROTO_ANY 255
+#define IPSEC_PROTO_ANY 255
+
+enum {
+ IPSEC_MODE_ANY = 0,
+ IPSEC_MODE_TRANSPORT = 1,
+ IPSEC_MODE_TUNNEL = 2,
+ IPSEC_MODE_BEET = 3
+};
+
+enum {
+ IPSEC_DIR_ANY = 0,
+ IPSEC_DIR_INBOUND = 1,
+ IPSEC_DIR_OUTBOUND = 2,
+ IPSEC_DIR_FWD = 3,
+ IPSEC_DIR_MAX = 4,
+ IPSEC_DIR_INVALID = 5
+};
+
+enum {
+ IPSEC_POLICY_DISCARD = 0,
+ IPSEC_POLICY_NONE = 1,
+ IPSEC_POLICY_IPSEC = 2,
+ IPSEC_POLICY_ENTRUST = 3,
+ IPSEC_POLICY_BYPASS = 4
+};
+
+enum {
+ IPSEC_LEVEL_DEFAULT = 0,
+ IPSEC_LEVEL_USE = 1,
+ IPSEC_LEVEL_REQUIRE = 2,
+ IPSEC_LEVEL_UNIQUE = 3
+};
+
+#define IPSEC_MANUAL_REQID_MAX 0x3fff
+
+#define IPSEC_REPLAYWSIZE 32
+
+#endif
diff --git a/libc/kernel/common/linux/msm_adsp.h b/libc/kernel/common/linux/msm_adsp.h
index 6f12707..b138a5d 100644
--- a/libc/kernel/common/linux/msm_adsp.h
+++ b/libc/kernel/common/linux/msm_adsp.h
@@ -14,7 +14,6 @@
 
 #include <linux/types.h>
 #include <linux/ioctl.h>
-#include <asm/sizes.h>
 
 #define ADSP_IOCTL_MAGIC 'q'
 
@@ -33,25 +32,32 @@
  uint8_t *data;
 };
 
-struct adsp_pmem_info_t {
+#define ADSP_IOCTL_ENABLE _IOR(ADSP_IOCTL_MAGIC, 1, unsigned)
+
+#define ADSP_IOCTL_DISABLE _IOR(ADSP_IOCTL_MAGIC, 2, unsigned)
+
+#define ADSP_IOCTL_DISABLE_ACK _IOR(ADSP_IOCTL_MAGIC, 3, unsigned)
+
+#define ADSP_IOCTL_WRITE_COMMAND _IOR(ADSP_IOCTL_MAGIC, 4, struct adsp_command_t *)
+
+#define ADSP_IOCTL_GET_EVENT _IOWR(ADSP_IOCTL_MAGIC, 5, struct adsp_event_data_t *)
+
+#define ADSP_IOCTL_SET_CLKRATE _IOR(ADSP_IOCTL_MAGIC, 6, unsigned)
+
+#define ADSP_IOCTL_DISABLE_EVENT_RSP _IOR(ADSP_IOCTL_MAGIC, 10, unsigned)
+
+struct adsp_pmem_info {
  int fd;
  void *vaddr;
 };
 
-#define ADSP_IOCTL_ENABLE   _IOR(ADSP_IOCTL_MAGIC, 1, unsigned)
+#define ADSP_IOCTL_REGISTER_PMEM _IOW(ADSP_IOCTL_MAGIC, 13, unsigned)
 
-#define ADSP_IOCTL_DISABLE   _IOR(ADSP_IOCTL_MAGIC, 2, unsigned)
+#define ADSP_IOCTL_UNREGISTER_PMEM _IOW(ADSP_IOCTL_MAGIC, 14, unsigned)
 
-#define ADSP_IOCTL_DISABLE_ACK   _IOR(ADSP_IOCTL_MAGIC, 3, unsigned)
+#define ADSP_IOCTL_ABORT_EVENT_READ _IOW(ADSP_IOCTL_MAGIC, 15, unsigned)
 
-#define ADSP_IOCTL_WRITE_COMMAND   _IOR(ADSP_IOCTL_MAGIC, 4, struct adsp_command_t *)
-
-#define ADSP_IOCTL_GET_EVENT   _IOWR(ADSP_IOCTL_MAGIC, 5, struct adsp_event_data_t *)
-
-#define ADSP_IOCTL_DISABLE_EVENT_RSP   _IOR(ADSP_IOCTL_MAGIC, 10, unsigned)
-
-#define ADSP_IOCTL_REGISTER_PMEM   _IOW(ADSP_IOCTL_MAGIC, 13, struct adsp_pmem_info *)
-
-#define ADSP_IOCTL_ABORT_EVENT_READ   _IOW(ADSP_IOCTL_MAGIC, 15, unsigned)
+#define ADSP_IOCTL_LINK_TASK _IOW(ADSP_IOCTL_MAGIC, 16, unsigned)
 
 #endif
+
diff --git a/libc/kernel/common/linux/msm_audio.h b/libc/kernel/common/linux/msm_audio.h
index 9ac58aa..eed5901 100644
--- a/libc/kernel/common/linux/msm_audio.h
+++ b/libc/kernel/common/linux/msm_audio.h
@@ -82,4 +82,3 @@
 #define SND_GET_ENDPOINT _IOWR(SND_IOCTL_MAGIC, 5, struct msm_snd_endpoint *)
 
 #endif
-
diff --git a/libc/kernel/common/linux/uinput.h b/libc/kernel/common/linux/uinput.h
new file mode 100644
index 0000000..b7a6add
--- /dev/null
+++ b/libc/kernel/common/linux/uinput.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __UINPUT_H_
+#define __UINPUT_H_
+
+#include <linux/input.h>
+
+#define UINPUT_VERSION 3
+
+struct uinput_ff_upload {
+ int request_id;
+ int retval;
+ struct ff_effect effect;
+ struct ff_effect old;
+};
+
+struct uinput_ff_erase {
+ int request_id;
+ int retval;
+ int effect_id;
+};
+
+#define UINPUT_IOCTL_BASE 'U'
+#define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
+#define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
+
+#define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
+#define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
+#define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
+#define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
+#define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
+#define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
+#define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
+#define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
+#define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
+#define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int)
+
+#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
+#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
+#define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
+#define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
+
+#define EV_UINPUT 0x0101
+#define UI_FF_UPLOAD 1
+#define UI_FF_ERASE 2
+
+#define UINPUT_MAX_NAME_SIZE 80
+struct uinput_user_dev {
+ char name[UINPUT_MAX_NAME_SIZE];
+ struct input_id id;
+ int ff_effects_max;
+ int absmax[ABS_MAX + 1];
+ int absmin[ABS_MAX + 1];
+ int absfuzz[ABS_MAX + 1];
+ int absflat[ABS_MAX + 1];
+};
+#endif
+
diff --git a/libc/kernel/common/media/msm_camera.h b/libc/kernel/common/media/msm_camera.h
new file mode 100644
index 0000000..6596d6b
--- /dev/null
+++ b/libc/kernel/common/media/msm_camera.h
@@ -0,0 +1,356 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __LINUX_MSM_CAMERA_H
+#define __LINUX_MSM_CAMERA_H
+
+#include <linux/types.h>
+#include <asm/sizes.h>
+#include <linux/ioctl.h>
+
+#define MSM_CAM_IOCTL_MAGIC 'm'
+
+#define MSM_CAM_IOCTL_GET_SENSOR_INFO   _IOR(MSM_CAM_IOCTL_MAGIC, 1, struct msm_camsensor_info *)
+
+#define MSM_CAM_IOCTL_REGISTER_PMEM   _IOW(MSM_CAM_IOCTL_MAGIC, 2, struct msm_pmem_info *)
+
+#define MSM_CAM_IOCTL_UNREGISTER_PMEM   _IOW(MSM_CAM_IOCTL_MAGIC, 3, unsigned)
+
+#define MSM_CAM_IOCTL_CTRL_COMMAND   _IOW(MSM_CAM_IOCTL_MAGIC, 4, struct msm_ctrl_cmd *)
+
+#define MSM_CAM_IOCTL_CONFIG_VFE   _IOW(MSM_CAM_IOCTL_MAGIC, 5, struct msm_camera_vfe_cfg_cmd *)
+
+#define MSM_CAM_IOCTL_GET_STATS   _IOR(MSM_CAM_IOCTL_MAGIC, 6, struct msm_camera_stats_event_ctrl *)
+
+#define MSM_CAM_IOCTL_GETFRAME   _IOR(MSM_CAM_IOCTL_MAGIC, 7, struct msm_camera_get_frame *)
+
+#define MSM_CAM_IOCTL_ENABLE_VFE   _IOW(MSM_CAM_IOCTL_MAGIC, 8, struct camera_enable_cmd *)
+
+#define MSM_CAM_IOCTL_CTRL_CMD_DONE   _IOW(MSM_CAM_IOCTL_MAGIC, 9, struct camera_cmd *)
+
+#define MSM_CAM_IOCTL_CONFIG_CMD   _IOW(MSM_CAM_IOCTL_MAGIC, 10, struct camera_cmd *)
+
+#define MSM_CAM_IOCTL_DISABLE_VFE   _IOW(MSM_CAM_IOCTL_MAGIC, 11, struct camera_enable_cmd *)
+
+#define MSM_CAM_IOCTL_PAD_REG_RESET2   _IOW(MSM_CAM_IOCTL_MAGIC, 12, struct camera_enable_cmd *)
+
+#define MSM_CAM_IOCTL_VFE_APPS_RESET   _IOW(MSM_CAM_IOCTL_MAGIC, 13, struct camera_enable_cmd *)
+
+#define MSM_CAM_IOCTL_RELEASE_FRAME_BUFFER   _IOW(MSM_CAM_IOCTL_MAGIC, 14, struct camera_enable_cmd *)
+
+#define MSM_CAM_IOCTL_RELEASE_STATS_BUFFER   _IOW(MSM_CAM_IOCTL_MAGIC, 15, struct msm_stats_buf *)
+
+#define MSM_CAM_IOCTL_AXI_CONFIG   _IOW(MSM_CAM_IOCTL_MAGIC, 16, struct msm_camera_vfe_cfg_cmd *)
+
+#define MSM_CAM_IOCTL_GET_PICTURE   _IOW(MSM_CAM_IOCTL_MAGIC, 17, struct msm_camera_ctrl_cmd *)
+
+#define MSM_CAM_IOCTL_SET_CROP   _IOW(MSM_CAM_IOCTL_MAGIC, 18, struct crop_info *)
+
+#define MSM_CAM_IOCTL_PICT_PP   _IOW(MSM_CAM_IOCTL_MAGIC, 19, uint8_t *)
+
+#define MSM_CAM_IOCTL_PICT_PP_DONE   _IOW(MSM_CAM_IOCTL_MAGIC, 20, struct msm_snapshot_pp_status *)
+
+#define MSM_CAM_IOCTL_SENSOR_IO_CFG   _IOW(MSM_CAM_IOCTL_MAGIC, 21, struct sensor_cfg_data *)
+
+#define MSM_CAMERA_LED_OFF 0
+#define MSM_CAMERA_LED_LOW 1
+#define MSM_CAMERA_LED_HIGH 2
+
+#define MSM_CAM_IOCTL_FLASH_LED_CFG   _IOW(MSM_CAM_IOCTL_MAGIC, 22, unsigned *)
+
+#define MSM_CAM_IOCTL_UNBLOCK_POLL_FRAME   _IO(MSM_CAM_IOCTL_MAGIC, 23)
+
+#define MSM_CAM_IOCTL_CTRL_COMMAND_2   _IOW(MSM_CAM_IOCTL_MAGIC, 24, struct msm_ctrl_cmd *)
+
+#define MAX_SENSOR_NUM 3
+#define MAX_SENSOR_NAME 32
+
+#define MSM_CAM_CTRL_CMD_DONE 0
+#define MSM_CAM_SENSOR_VFE_CMD 1
+
+struct msm_ctrl_cmd {
+ uint16_t type;
+ uint16_t length;
+ void *value;
+ uint16_t status;
+ uint32_t timeout_ms;
+ int resp_fd;
+};
+
+struct msm_vfe_evt_msg {
+ unsigned short type;
+ unsigned short msg_id;
+ unsigned int len;
+ void *data;
+};
+
+#define MSM_CAM_RESP_CTRL 0
+#define MSM_CAM_RESP_STAT_EVT_MSG 1
+#define MSM_CAM_RESP_V4L2 2
+#define MSM_CAM_RESP_MAX 3
+
+struct msm_stats_event_ctrl {
+
+ int resptype;
+ int timeout_ms;
+ struct msm_ctrl_cmd ctrl_cmd;
+
+ struct msm_vfe_evt_msg stats_event;
+};
+
+struct msm_camera_cfg_cmd {
+
+ uint16_t cfg_type;
+
+ uint16_t cmd_type;
+ uint16_t queue;
+ uint16_t length;
+ void *value;
+};
+
+#define CMD_GENERAL 0
+#define CMD_AXI_CFG_OUT1 1
+#define CMD_AXI_CFG_SNAP_O1_AND_O2 2
+#define CMD_AXI_CFG_OUT2 3
+#define CMD_PICT_T_AXI_CFG 4
+#define CMD_PICT_M_AXI_CFG 5
+#define CMD_RAW_PICT_AXI_CFG 6
+#define CMD_STATS_AXI_CFG 7
+#define CMD_STATS_AF_AXI_CFG 8
+#define CMD_FRAME_BUF_RELEASE 9
+#define CMD_PREV_BUF_CFG 10
+#define CMD_SNAP_BUF_RELEASE 11
+#define CMD_SNAP_BUF_CFG 12
+#define CMD_STATS_DISABLE 13
+#define CMD_STATS_ENABLE 14
+#define CMD_STATS_AF_ENABLE 15
+#define CMD_STATS_BUF_RELEASE 16
+#define CMD_STATS_AF_BUF_RELEASE 17
+#define UPDATE_STATS_INVALID 18
+
+struct msm_vfe_cfg_cmd {
+ int cmd_type;
+ uint16_t length;
+ void *value;
+};
+
+#define MAX_CAMERA_ENABLE_NAME_LEN 32
+struct camera_enable_cmd {
+ char name[MAX_CAMERA_ENABLE_NAME_LEN];
+};
+
+#define MSM_PMEM_OUTPUT1 0
+#define MSM_PMEM_OUTPUT2 1
+#define MSM_PMEM_OUTPUT1_OUTPUT2 2
+#define MSM_PMEM_THUMBAIL 3
+#define MSM_PMEM_MAINIMG 4
+#define MSM_PMEM_RAW_MAINIMG 5
+#define MSM_PMEM_AEC_AWB 6
+#define MSM_PMEM_AF 7
+#define MSM_PMEM_MAX 8
+
+#define FRAME_PREVIEW_OUTPUT1 0
+#define FRAME_PREVIEW_OUTPUT2 1
+#define FRAME_SNAPSHOT 2
+#define FRAME_THUMBAIL 3
+#define FRAME_RAW_SNAPSHOT 4
+#define FRAME_MAX 5
+
+struct msm_pmem_info {
+ int type;
+ int fd;
+ void *vaddr;
+ uint32_t offset;
+ uint32_t len;
+ uint32_t y_off;
+ uint32_t cbcr_off;
+ uint8_t active;
+};
+
+struct outputCfg {
+ uint32_t height;
+ uint32_t width;
+
+ uint32_t window_height_firstline;
+ uint32_t window_height_lastline;
+};
+
+#define OUTPUT_1 0
+#define OUTPUT_2 1
+#define OUTPUT_1_AND_2 2
+#define CAMIF_TO_AXI_VIA_OUTPUT_2 3
+#define OUTPUT_1_AND_CAMIF_TO_AXI_VIA_OUTPUT_2 4
+#define OUTPUT_2_AND_CAMIF_TO_AXI_VIA_OUTPUT_1 5
+#define LAST_AXI_OUTPUT_MODE_ENUM = OUTPUT_2_AND_CAMIF_TO_AXI_VIA_OUTPUT_1 6
+
+#define MSM_FRAME_PREV_1 0
+#define MSM_FRAME_PREV_2 1
+#define MSM_FRAME_ENC 2
+
+struct msm_frame {
+ int path;
+ unsigned long buffer;
+ uint32_t y_off;
+ uint32_t cbcr_off;
+ int fd;
+
+ void *cropinfo;
+ int croplen;
+};
+
+#define STAT_AEAW 0
+#define STAT_AF 1
+#define STAT_MAX 2
+
+struct msm_stats_buf {
+ int type;
+ unsigned long buffer;
+ int fd;
+};
+
+#define MSM_V4L2_VID_CAP_TYPE 0
+#define MSM_V4L2_STREAM_ON 1
+#define MSM_V4L2_STREAM_OFF 2
+#define MSM_V4L2_SNAPSHOT 3
+#define MSM_V4L2_QUERY_CTRL 4
+#define MSM_V4L2_GET_CTRL 5
+#define MSM_V4L2_SET_CTRL 6
+#define MSM_V4L2_QUERY 7
+#define MSM_V4L2_MAX 8
+
+struct crop_info {
+ void *info;
+ int len;
+};
+
+struct msm_postproc {
+ int ftnum;
+ struct msm_frame fthumnail;
+ int fmnum;
+ struct msm_frame fmain;
+};
+
+struct msm_snapshot_pp_status {
+ void *status;
+};
+
+#define CFG_SET_MODE 0
+#define CFG_SET_EFFECT 1
+#define CFG_START 2
+#define CFG_PWR_UP 3
+#define CFG_PWR_DOWN 4
+#define CFG_WRITE_EXPOSURE_GAIN 5
+#define CFG_SET_DEFAULT_FOCUS 6
+#define CFG_MOVE_FOCUS 7
+#define CFG_REGISTER_TO_REAL_GAIN 8
+#define CFG_REAL_TO_REGISTER_GAIN 9
+#define CFG_SET_FPS 10
+#define CFG_SET_PICT_FPS 11
+#define CFG_SET_BRIGHTNESS 12
+#define CFG_SET_CONTRAST 13
+#define CFG_SET_ZOOM 14
+#define CFG_SET_EXPOSURE_MODE 15
+#define CFG_SET_WB 16
+#define CFG_SET_ANTIBANDING 17
+#define CFG_SET_EXP_GAIN 18
+#define CFG_SET_PICT_EXP_GAIN 19
+#define CFG_SET_LENS_SHADING 20
+#define CFG_GET_PICT_FPS 21
+#define CFG_GET_PREV_L_PF 22
+#define CFG_GET_PREV_P_PL 23
+#define CFG_GET_PICT_L_PF 24
+#define CFG_GET_PICT_P_PL 25
+#define CFG_GET_AF_MAX_STEPS 26
+#define CFG_GET_PICT_MAX_EXP_LC 27
+#define CFG_MAX 28
+
+#define MOVE_NEAR 0
+#define MOVE_FAR 1
+
+#define SENSOR_PREVIEW_MODE 0
+#define SENSOR_SNAPSHOT_MODE 1
+#define SENSOR_RAW_SNAPSHOT_MODE 2
+
+#define SENSOR_QTR_SIZE 0
+#define SENSOR_FULL_SIZE 1
+#define SENSOR_INVALID_SIZE 2
+
+#define CAMERA_EFFECT_OFF 0
+#define CAMERA_EFFECT_MONO 1
+#define CAMERA_EFFECT_NEGATIVE 2
+#define CAMERA_EFFECT_SOLARIZE 3
+#define CAMERA_EFFECT_PASTEL 4
+#define CAMERA_EFFECT_MOSAIC 5
+#define CAMERA_EFFECT_RESIZE 6
+#define CAMERA_EFFECT_SEPIA 7
+#define CAMERA_EFFECT_POSTERIZE 8
+#define CAMERA_EFFECT_WHITEBOARD 9
+#define CAMERA_EFFECT_BLACKBOARD 10
+#define CAMERA_EFFECT_AQUA 11
+#define CAMERA_EFFECT_MAX 12
+
+struct sensor_pict_fps {
+ uint16_t prevfps;
+ uint16_t pictfps;
+};
+
+struct exp_gain_cfg {
+ uint16_t gain;
+ uint32_t line;
+};
+
+struct focus_cfg {
+ int32_t steps;
+ int dir;
+};
+
+struct fps_cfg {
+ uint16_t f_mult;
+ uint16_t fps_div;
+ uint32_t pict_fps_div;
+};
+
+struct sensor_cfg_data {
+ int cfgtype;
+ int mode;
+ int rs;
+ uint8_t max_steps;
+
+ union {
+ int8_t effect;
+ uint8_t lens_shading;
+ uint16_t prevl_pf;
+ uint16_t prevp_pl;
+ uint16_t pictl_pf;
+ uint16_t pictp_pl;
+ uint32_t pict_max_exp_lc;
+ uint16_t p_fps;
+ struct sensor_pict_fps gfps;
+ struct exp_gain_cfg exp_gain;
+ struct focus_cfg focus;
+ struct fps_cfg fps;
+ } cfg;
+};
+
+#define GET_NAME 0
+#define GET_PREVIEW_LINE_PER_FRAME 1
+#define GET_PREVIEW_PIXELS_PER_LINE 2
+#define GET_SNAPSHOT_LINE_PER_FRAME 3
+#define GET_SNAPSHOT_PIXELS_PER_LINE 4
+#define GET_SNAPSHOT_FPS 5
+#define GET_SNAPSHOT_MAX_EP_LINE_CNT 6
+
+struct msm_camsensor_info {
+ char name[MAX_SENSOR_NAME];
+ uint8_t flash_enabled;
+};
+#endif
+
diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py
index aad0092..4227de7 100644
--- a/libc/kernel/tools/defaults.py
+++ b/libc/kernel/tools/defaults.py
@@ -7,7 +7,7 @@
 
 # the list of supported architectures
 #
-kernel_archs = [ 'arm', 'x86' ]
+kernel_archs = [ 'arm', 'x86', 'sh' ]
 
 # the list of include directories that belong to the kernel
 # tree. used when looking for sources...
@@ -57,6 +57,15 @@
         ]
     )
 
+kernel_known_sh_statics = set(
+       [ "___arch__swab16",    # asm-sh/byteorder.h
+         "___arch__swab32",    # asm-sh/byteorder.h
+         "___arch__swab64",    # asm-sh/byteorder.h
+         "__FD_ZERO",          # asm-sh/posix_types_32/64.h
+         "__FD_SET",           # asm-sh/posix_types_32/64.h
+       ]
+    )
+
 kernel_known_generic_statics = set(
         [ "__invalid_size_argument_for_IOC",  # asm-generic/ioctl.h
           "__cmsg_nxthdr",                    # linux/socket.h
@@ -70,7 +79,8 @@
 #
 kernel_known_statics = {
         "arm" : kernel_known_arm_statics,
-        "x86" : kernel_known_x86_statics
+        "x86" : kernel_known_x86_statics,
+        "sh" : kernel_known_sh_statics
     }
 
 # this is a list of macros which we want to specifically exclude from
diff --git a/libc/kernel/tools/update_all.py b/libc/kernel/tools/update_all.py
index 6272fcf..d25dc0e 100755
--- a/libc/kernel/tools/update_all.py
+++ b/libc/kernel/tools/update_all.py
@@ -73,7 +73,9 @@
 
     print "cleaning: %-*s -> %-*s (%s)" % ( 35, path, 35, dst_path, r )
 
-usePerforce = os.environ.has_key("ANDROID_PRODUCT_OUT")
+# We don't use Perforce anymore, but just in case, define ANDROID_USE_P4
+# in your environment if you think you need it.
+usePerforce = os.environ.has_key("ANDROID_USE_P4")
 
 if usePerforce:
     b.updateP4Files()
diff --git a/libc/netbsd/net/getaddrinfo.c b/libc/netbsd/net/getaddrinfo.c
index 2dd3d97..f2189fb 100644
--- a/libc/netbsd/net/getaddrinfo.c
+++ b/libc/netbsd/net/getaddrinfo.c
@@ -912,7 +912,11 @@
 		allownumeric = 1;
 		break;
 	case ANY:
+#if 1  /* ANDROID-SPECIFIC CHANGE TO MATCH GLIBC */	
+		allownumeric = 1;
+#else
 		allownumeric = 0;
+#endif
 		break;
 	default:
 		return EAI_SOCKTYPE;
@@ -1271,7 +1275,7 @@
 	name = va_arg(ap, char *);
 	pai = va_arg(ap, const struct addrinfo *);
 
-	fprintf(stderr, "_dns_getaddrinfo() name = '%s'\n", name);
+	//fprintf(stderr, "_dns_getaddrinfo() name = '%s'\n", name);
 
 	memset(&q, 0, sizeof(q));
 	memset(&q2, 0, sizeof(q2));
@@ -1630,7 +1634,7 @@
 		trailing_dot++;
 
 
-fprintf(stderr, "res_searchN() name = '%s'\n", name);
+        //fprintf(stderr, "res_searchN() name = '%s'\n", name);
 
 	/*
 	 * if there aren't any dots, it could be a user-level alias
diff --git a/libc/netbsd/net/getservent.c b/libc/netbsd/net/getservent.c
index 45207df..9f6ec32 100644
--- a/libc/netbsd/net/getservent.c
+++ b/libc/netbsd/net/getservent.c
@@ -27,6 +27,7 @@
  */
 #include <sys/cdefs.h>
 #include <sys/types.h>
+#include <endian.h>
 #include <netdb.h>
 #include "servent.h"
 #include "services.h"
@@ -54,6 +55,7 @@
     int          namelen;
     int          nn,count;
     int          total = 0;
+    int          port;
     char*        p2;
 
     p = rs->servent_ptr;
@@ -92,9 +94,12 @@
     memcpy( rs->servent.s_name, p+1, namelen );
     rs->servent.s_name[namelen] = 0;
     p += 1 + namelen;
-    rs->servent.s_port = ((((unsigned char*)p)[0] << 8) |
-                           ((unsigned char*)p)[1]);
 
+    /* s_port must be in network byte order */
+    port = ((((unsigned char*)p)[0] << 8) |
+             ((unsigned char*)p)[1]);
+
+    rs->servent.s_port  = htons(port);
     rs->servent.s_proto = p[2] == 't' ? "tcp" : "udp";
     p += 4;  /* skip port(2) + proto(1) + aliascount(1) */
 
diff --git a/libc/netbsd/resolv/res_comp.c b/libc/netbsd/resolv/res_comp.c
index 6991e8b..77b81b4 100644
--- a/libc/netbsd/resolv/res_comp.c
+++ b/libc/netbsd/resolv/res_comp.c
@@ -147,6 +147,12 @@
  * tell us anything about network-format data.  The rest of the BIND system
  * is not careful about this, but for some reason, we're doing it right here.
  */
+
+/* BIONIC: We also accept underscores in the middle of labels.
+ *         This extension is needed to make resolution on some VPN networks
+ *         work properly.
+ */
+
 #define PERIOD 0x2e
 #define	hyphenchar(c) ((c) == 0x2d)
 #define bslashchar(c) ((c) == 0x5c)
@@ -155,9 +161,10 @@
 #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
 		   || ((c) >= 0x61 && (c) <= 0x7a))
 #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+#define underscorechar(c)  ((c) == 0x5f)
 
 #define borderchar(c) (alphachar(c) || digitchar(c))
-#define middlechar(c) (borderchar(c) || hyphenchar(c))
+#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
 #define	domainchar(c) ((c) > 0x20 && (c) < 0x7f)
 
 int
diff --git a/libc/netbsd/resolv/res_init.c b/libc/netbsd/resolv/res_init.c
index fc0272c..751603d 100644
--- a/libc/netbsd/resolv/res_init.c
+++ b/libc/netbsd/resolv/res_init.c
@@ -112,6 +112,7 @@
 #define MAX_DNS_PROPERTIES 8
 #define DNS_PROP_NAME_PREFIX "net.dns"
 #define DNS_CHANGE_PROP_NAME "net.dnschange"
+#define DNS_SEARCH_PROP_NAME "net.dns.search"
 const prop_info *dns_change_prop;
 int dns_last_change_counter;
 static int _get_dns_change_count();
@@ -168,6 +169,39 @@
 	return (__res_vinit(statp, 0));
 }
 
+#ifdef ANDROID_CHANGES
+int load_domain_search_list(res_state statp) {
+	char propvalue[PROP_VALUE_MAX];
+	register char *cp, **pp;
+
+	if(__system_property_get(DNS_SEARCH_PROP_NAME, propvalue) >= 1) {
+		strlcpy(statp->defdname, propvalue, sizeof(statp->defdname));
+		if ((cp = strchr(statp->defdname, '\n')) != NULL)
+			*cp = '\0';
+		cp = statp->defdname;
+		pp = statp->dnsrch;
+		while ( pp < statp->dnsrch + MAXDNSRCH ) {
+			while (*cp == ' ' || *cp == '\t') /* skip leading white space */
+				cp++;
+			if (*cp == '\0')  /* stop if nothing more */
+				break;
+			*pp++ = cp;  /* record this search domain */
+			while (*cp) { /* zero-terminate it */
+				if (*cp == ' ' || *cp == '\t') {
+					*cp++ = '\0';
+					break;
+				}
+				cp++;
+			}
+		}
+		*pp = NULL; /* statp->dnsrch has MAXDNSRCH+1 items */
+		if (pp > statp->dnsrch)
+			return 1;
+	}
+	return 0;
+}
+#endif
+
 /* This function has to be reachable by res_data.c but not publicly. */
 int
 __res_vinit(res_state statp, int preinit) {
@@ -344,6 +378,9 @@
 			}
 		}
 	}
+
+	/* Add the domain search list */
+	havesearch = load_domain_search_list(statp);
 #else /* IGNORE resolv.conf */
 #define	MATCH(line, name) \
 	(!strncmp(line, name, sizeof(name) - 1) && \
diff --git a/libc/private/bionic_tls.h b/libc/private/bionic_tls.h
index da34344..742ef8c 100644
--- a/libc/private/bionic_tls.h
+++ b/libc/private/bionic_tls.h
@@ -60,6 +60,13 @@
 #define TLS_SLOT_OPENGL_API         3
 #define TLS_SLOT_OPENGL             4
 
+/* this slot is only used to pass information from the dynamic linker to
+ * libc.so when the C library is loaded in to memory. The C runtime init
+ * function will then clear it. Since its use is extremely temporary,
+ * we reuse an existing location.
+ */
+#define  TLS_SLOT_BIONIC_PREINIT    (TLS_SLOT_ERRNO+1)
+
 /* small technical note: it is not possible to call pthread_setspecific
  * on keys that are <= TLS_SLOT_MAX_WELL_KNOWN, which is why it is set to
  * TLS_SLOT_ERRNO.
@@ -80,8 +87,10 @@
 extern int __set_tls(void *ptr);
 
 /* get the TLS */
+/* Linux kernel helpers for its TLS implementation */
 #ifdef __arm__
-#  define __get_tls() ( *((volatile void **) 0xffff0ff0) )
+typedef void* (__kernel_get_tls_t)(void);
+#define __get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
 #else
 extern void*  __get_tls( void );
 #endif
diff --git a/libc/private/logd.h b/libc/private/logd.h
index 671cb48..43fa742 100644
--- a/libc/private/logd.h
+++ b/libc/private/logd.h
@@ -28,6 +28,8 @@
 #ifndef _ANDROID_BIONIC_LOGD_H
 #define _ANDROID_BIONIC_LOGD_H
 
+#include <stdarg.h>
+
 enum  {
     ANDROID_LOG_UNKNOWN = 0,
     ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */
@@ -43,5 +45,6 @@
 };
 
 int __libc_android_log_print(int prio, const char *tag, const char *fmt, ...);
+int __libc_android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap);
 
 #endif /* _ANDROID_BIONIC_LOGD_H */
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index 5bf82ba..4ba2177 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -147,10 +147,19 @@
 				p->fns[n].fn_ptr.cxa_func = NULL;
 				mprotect(p, pgsize, PROT_READ);
 			}
+#if ANDROID
+                        /* it looks like we should always call the function
+                         * with an argument, even if dso is not NULL. Otherwise
+                         * static destructors will not be called properly on
+                         * the ARM.
+                         */
+                        (*fn.fn_ptr.cxa_func)(fn.fn_arg);
+#else /* !ANDROID */
 			if (dso != NULL)
 				(*fn.fn_ptr.cxa_func)(fn.fn_arg);
 			else
 				(*fn.fn_ptr.std_func)();
+#endif /* !ANDROID */
 		}
 	}
 
diff --git a/libc/unistd/siglist.c b/libc/unistd/siglist.c
index a2ac9fe..f1c3377 100644
--- a/libc/unistd/siglist.c
+++ b/libc/unistd/siglist.c
@@ -28,6 +28,6 @@
 #include <signal.h>
 
 const char * const sys_siglist[NSIG] = {
-#define  __BIONIC_SIGDEF(x,y,z)   [ x ] = z,
+#define  __BIONIC_SIGDEF(x,y,z)   [ SIG##x ] = z,
 #include <sys/_sigdefs.h>
 };
diff --git a/libc/unistd/signame.c b/libc/unistd/signame.c
new file mode 100644
index 0000000..4611e44
--- /dev/null
+++ b/libc/unistd/signame.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2009 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 <signal.h>
+
+const char * const sys_signame[NSIG] = {
+#define  __BIONIC_SIGDEF(x,y,z)   [ SIG##x ] = #x,
+#include <sys/_sigdefs.h>
+};
diff --git a/libc/unistd/socketcalls.c b/libc/unistd/socketcalls.c
index d97abc2..51bdf57 100644
--- a/libc/unistd/socketcalls.c
+++ b/libc/unistd/socketcalls.c
@@ -232,7 +232,7 @@
 #endif /* !__NR_getsockopt */
 
 #ifndef __NR_sendmsg
-ssize_t sendmsg (int socket, const struct msghdr *message, unsigned int flags)
+int sendmsg (int socket, const struct msghdr *message, unsigned int flags)
 {
     unsigned long  t[3];
 
@@ -245,7 +245,7 @@
 #endif /* __NR_sendmsg */
 
 #ifndef __NR_recvmsg
-ssize_t recvmsg(int socket, struct msghdr *message, unsigned int flags)
+int recvmsg(int socket, struct msghdr *message, unsigned int flags)
 {
     unsigned long  t[3];
 
diff --git a/libdl/Android.mk b/libdl/Android.mk
index 150f704..8d56f9a 100644
--- a/libdl/Android.mk
+++ b/libdl/Android.mk
@@ -36,6 +36,21 @@
 LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
 LOCAL_SYSTEM_SHARED_LIBRARIES := 
 
+ifeq ($(TARGET_ARCH),sh)
+# for SuperH, additional code is necessary to handle .ctors section.
+GEN_SOBEGIN := $(TARGET_OUT_STATIC_LIBRARIES)/sobegin.o
+$(GEN_SOBEGIN): $(LOCAL_PATH)/arch-sh/sobegin.S
+	@mkdir -p $(dir $@)
+	$(TARGET_CC) -o $@ -c $<
+
+GEN_SOEND := $(TARGET_OUT_STATIC_LIBRARIES)/soend.o
+$(GEN_SOEND): $(LOCAL_PATH)/arch-sh/soend.S
+	@mkdir -p $(dir $@)
+	$(TARGET_CC) -o $@ -c $<
+
+LOCAL_ADDITIONAL_DEPENDENCIES := $(GEN_SOBEGIN) $(GEN_SOEND)
+endif
+
 include $(BUILD_SHARED_LIBRARY)
 
 BUILD_DLTEST:=0
diff --git a/libdl/arch-sh/sobegin.S b/libdl/arch-sh/sobegin.S
new file mode 100644
index 0000000..976b1a6
--- /dev/null
+++ b/libdl/arch-sh/sobegin.S
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2009 The Android Open 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.
+ */
+    .text
+    .align 4
+    .type  _init,#function
+    .globl _init
+
+# The toolchain for SH-Linux does not produce INIT_ARRAY information which
+# bionic linker relies on.  Instead of it, The toolchain for SH-Linux produces
+# INIT information when it find the function whose name is '_init'.
+#
+_init:
+    sts.l   pr, @-r15
+    mov.l   r8, @-r15
+    mov.l   0f, r8      /* first entry is invalid */
+.L_loop:
+    add     #4, r8
+    mov.l   @r8, r0
+    cmp/eq  #0, r0      /* Zero terimnated. See 'soend.so'. */
+    bt      .L_end
+    jsr     @r0         /* invoke a constructor */
+    nop
+    bra     .L_loop
+    nop
+.L_end:
+    mov.l   @r15+, r8
+    lds.l   @r15+, pr
+
+    rts
+    nop
+
+    .balign 4
+0:  .long   __CTOR_LIST__
+
+# the .ctors section contains a list of pointers to "constructor"
+# functions that need to be called in order during C library initialization,
+# just before the program is being run. This is a C++ requirement
+#
+# the last entry shall be 0, and is defined in crtend.S
+#
+    .section .ctors, "aw"
+    .globl __CTOR_LIST__
+__CTOR_LIST__:
+    .long   -1
+
diff --git a/libdl/arch-sh/soend.S b/libdl/arch-sh/soend.S
new file mode 100644
index 0000000..7fa98a4
--- /dev/null
+++ b/libdl/arch-sh/soend.S
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2009 The Android Open 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.
+ */
+
+    .section .ctors, "aw"
+    .long 0
+
diff --git a/libdl/libdl.c b/libdl/libdl.c
index 52707f1..7971942 100644
--- a/libdl/libdl.c
+++ b/libdl/libdl.c
@@ -24,7 +24,7 @@
 
 #ifdef __arm__
 void *dl_unwind_find_exidx(void *pc, int *pcount) { return 0; }
-#elif defined(__i386__)
+#elif defined(__i386__) || defined(__sh__)
 /* we munge the cb definition so we don't have to include any headers here.
  * It won't affect anything since these are just symbols anyway */
 int dl_iterate_phdr(int (*cb)(void *info, void *size, void *data),
diff --git a/libm/Android.mk b/libm/Android.mk
index 8f0c3b1..fa73aff 100644
--- a/libm/Android.mk
+++ b/libm/Android.mk
@@ -170,7 +170,17 @@
 
     libm_common_includes = $(LOCAL_PATH)/i386 $(LOCAL_PATH)/i387
   else
-    $(error "Unknown architecture")
+    ifeq ($(TARGET_OS)-$(TARGET_ARCH),linux-sh)
+      libm_common_src_files += \
+		sh/fenv.c \
+		src/s_scalbln.c \
+		src/s_scalbn.c \
+		src/s_scalbnf.c
+
+      libm_common_includes = $(LOCAL_PATH)/sh
+    else
+      $(error "Unknown architecture")
+    endif
   endif
 endif
 
diff --git a/libm/sh/_fpmath.h b/libm/sh/_fpmath.h
new file mode 100644
index 0000000..f75ec7b
--- /dev/null
+++ b/libm/sh/_fpmath.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 Android Open Source Project, All rights reserved.
+ *   Derived from "bionic/libm/arm/_fpmath.h"
+ *   Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
+ *
+ * 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.
+ */
+
+/*
+ * Assumes that 'long double' on SH-linux is just an alias for 'double'.
+ */
+union IEEEl2bits {
+	long double	e;
+	struct {
+#if  __BYTE_ORDER == __LITTLE_ENDIAN
+		unsigned int	manl	:32;
+		unsigned int	manh	:20;
+		unsigned int	exp	:11;
+		unsigned int	sign	:1;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+		unsigned int	sign	:1;
+		unsigned int	exp	:11;
+		unsigned int	manh	:20;
+		unsigned int	manl	:32;
+#endif
+	} bits;
+};
+
+/*
+ * LDBL_NBIT is a mask indicating the position of the integer
+ * bit in a long double.  But SH4 does not support it.
+ */
+#define	LDBL_NBIT	0
+#define	mask_nbit_l(u)	((void)0)
+
+#define	LDBL_MANH_SIZE	20
+#define	LDBL_MANL_SIZE	32
diff --git a/libm/sh/fenv.c b/libm/sh/fenv.c
new file mode 100644
index 0000000..ca8f476
--- /dev/null
+++ b/libm/sh/fenv.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2009 Android Open Source Project, All rights reserved.
+ *   Derived from "bionic/libm/arm/fenv.c"
+ *   Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ *
+ * 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.
+ */
+
+long __fpscr_values[2] = { 0L, 0x80000L };
diff --git a/libm/sh/fenv.h b/libm/sh/fenv.h
new file mode 100644
index 0000000..e872f47
--- /dev/null
+++ b/libm/sh/fenv.h
@@ -0,0 +1,240 @@
+/*
+ * Copyright (C) 2009 Android Open Source Project, All rights reserved.
+ *   Derived from "bionic/libm/arm/fenv.h"
+ *   Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
+ *
+ * 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 _FENV_H_
+#define _FENV_H_
+
+#include <stdio.h>
+#include <sys/types.h>
+
+typedef	uint32_t	fenv_t;
+typedef	uint32_t	fexcept_t;
+
+/* Exception flags */
+#define	FE_INVALID		0x0010
+#define	FE_DIVBYZERO	0x0008
+#define	FE_OVERFLOW		0x0004
+#define	FE_UNDERFLOW	0x0002
+#define	FE_INEXACT		0x0001
+#define	FE_ALL_EXCEPT	(FE_DIVBYZERO | FE_INEXACT | \
+				 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
+
+/* Rounding modes */
+#define	FE_TONEAREST	0x0000
+#define	FE_TOWARDZERO	0x0001
+#define	FE_UPWARD	0x0002 /* not supporetd */
+#define	FE_DOWNWARD	0x0003 /* not supporetd */
+#define	_ROUND_MASK	(FE_TONEAREST | FE_DOWNWARD | \
+				 FE_UPWARD | FE_TOWARDZERO)
+
+/* bit shift for FPSCR mapping */
+#define	_FPUE_CAUSE_SHIFT	12
+#define	_FPUE_ENABLE_SHIFT	17
+#define	_FPUE_FLAG_SHIFT	 2
+
+/* bit shifters */
+#define	_FPUE_CAUSE(_EXCS)	((_EXCS) << _FPUE_CAUSE_SHIFT)
+#define	_FPUE_ENABLE(_EXCS)	((_EXCS) << _FPUE_ENABLE_SHIFT)
+#define	_FPUE_FLAG(_EXCS)	((_EXCS) << _FPUE_FLAG_SHIFT)
+
+#define	_GET_FPUE_CAUSE(_FPUE)		(((_FPUE) >> _FPUE_CAUSE_SHIFT) & FE_ALL_EXCEPT)
+#define	_GET_FPUE_ENABLE(_FPUE)	(((_FPUE) >> _FPUE_ENABLE_SHIFT)& FE_ALL_EXCEPT)
+#define	_GET_FPUE_FLAG(_FPUE)		(((_FPUE) >> _FPUE_FLAG_SHIFT) & FE_ALL_EXCEPT)
+
+
+/* FPSCR register accessors */
+#ifdef	__SH4_NOFPU__
+#define	__read_fpscr(_ptr)
+#define	__write_fpscr(_val)
+#else
+#define	__read_fpscr(_ptr)	__asm __volatile("sts fpscr, %0" : "=r" (*(_ptr)))
+#define	__write_fpscr(_val)	__asm __volatile("lds %0, fpscr" : : "r" (_val))
+#endif
+
+
+/* functions for libm */
+static __inline int
+feclearexcept(int __excepts)
+{
+	uint32_t __fpscr;
+
+	__read_fpscr(&__fpscr);
+	__fpscr &= ~_FPUE_FLAG(__excepts);
+	__write_fpscr(__fpscr);
+	return (0);
+}
+
+static __inline int
+fegetexceptflag(fexcept_t *__flagp, int __excepts)
+{
+	uint32_t __fpscr;
+
+	__read_fpscr(&__fpscr);
+	*__flagp = _GET_FPUE_FLAG(__fpscr) & __excepts;
+	return (0);
+}
+
+
+static __inline int
+fesetexceptflag(const fexcept_t *__flagp, int __excepts)
+{
+	uint32_t __fpscr;
+
+	__read_fpscr(&__fpscr);
+	__fpscr &= ~_FPUE_FLAG(__excepts);
+	__fpscr |= ~_FPUE_FLAG(*__flagp & __excepts);
+	__write_fpscr(__fpscr);
+	return (0);
+}
+
+
+static __inline int
+feraiseexcept(int __excepts)
+{
+	fexcept_t __ex = __excepts;
+
+	fesetexceptflag(&__ex, __excepts);	/* XXX */
+	return (0);
+}
+
+
+static __inline int
+fetestexcept(int __excepts)
+{
+	fexcept_t __ex;
+
+	fegetexceptflag(&__ex,  __excepts);
+	return (__ex);
+}
+
+
+static __inline int
+fegetround(void)
+{
+	uint32_t __fpscr = 0;
+
+	__read_fpscr(&__fpscr);
+	return (__fpscr & _ROUND_MASK);	
+}
+
+static __inline int
+fesetround(int __round)
+{
+	uint32_t __fpscr = 0;
+
+	if (__round == FE_UPWARD || __round == FE_DOWNWARD) {
+		fprintf(stderr, "libm superh : "
+			"upward/downward rounding not supporetd.\n");
+		return -1;
+	}
+
+	__read_fpscr(&__fpscr);
+	__fpscr &= ~_ROUND_MASK;
+	__fpscr |= (__round & _ROUND_MASK);
+	__write_fpscr(__fpscr);
+	return (0);
+}
+
+static __inline int
+fegetenv(fenv_t *__envp)
+{
+	__read_fpscr(__envp);
+	return (0);
+}
+
+static __inline int
+feholdexcept(fenv_t *__envp)
+{
+	uint32_t __fpscr;
+
+	__read_fpscr(&__fpscr);
+	*__envp = __fpscr;
+	__fpscr &= ~_FPUE_FLAG(FE_ALL_EXCEPT);
+	__write_fpscr(__fpscr);
+	return (0);
+}
+
+
+static __inline int
+fesetenv(const fenv_t *__envp)
+{
+	__write_fpscr(*__envp);
+	return (0);
+}
+
+
+static __inline int
+feupdateenv(const fenv_t *__envp)
+{
+	uint32_t __fpscr;
+
+	__read_fpscr(&__fpscr);
+	__write_fpscr(*__envp);
+	feraiseexcept(_GET_FPUE_FLAG(__fpscr));
+	return (0);
+}
+
+#if __BSD_VISIBLE
+
+static __inline int
+feenableexcept(int __mask)
+{
+	uint32_t __old_fpscr, __new_fpscr;
+
+	__read_fpscr(&__old_fpscr);
+	__new_fpscr = __old_fpscr | _FPUE_ENABLE(__mask & FE_ALL_EXCEPT);
+	__write_fpscr(__new_fpscr);
+	return (_GET_FPUE_ENABLE(__old_fpscr));
+}
+
+static __inline int
+fedisableexcept(int __mask)
+{
+	uint32_t __old_fpscr, __new_fpscr;
+
+	__read_fpscr(&__old_fpscr);
+	__new_fpscr = __old_fpscr & ~(_FPUE_ENABLE(__mask & FE_ALL_EXCEPT));
+	__write_fpscr(__new_fpscr);
+	return (_GET_FPUE_ENABLE(__old_fpscr));
+}
+
+static __inline int
+fegetexcept(void)
+{
+	uint32_t __fpscr;
+
+	__read_fpscr(&__fpscr);
+	return (_GET_FPUE_ENABLE(__fpscr));
+}
+
+#endif /* __BSD_VISIBLE */
+
+
+#endif /* _FENV_H_ */
+
diff --git a/libstdc++/include/cassert b/libstdc++/include/cassert
new file mode 100644
index 0000000..5753e34
--- /dev/null
+++ b/libstdc++/include/cassert
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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.
+ */
+
+/*
+ * Standard C++ Library wrapper around the C assert.h header file.  This file
+ * can be included multiple times with different definition of NDEBUG, hence the
+ * absence of include guards.
+ */
+
+#ifndef BIONIC_LIBSTDCPP_INCLUDE_CASSERT__
+#define BIONIC_LIBSTDCPP_INCLUDE_CASSERT__
+#endif
+#include <assert.h>
diff --git a/libstdc++/include/cctype b/libstdc++/include/cctype
new file mode 100644
index 0000000..e236561
--- /dev/null
+++ b/libstdc++/include/cctype
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__
+#define BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__
+
+/*
+ * Standard C++ Library wrapper around the C ctype.h header file.
+ */
+
+#include <ctype.h>
+
+namespace std 
+{
+using ::isalnum;
+using ::isalpha;
+using ::iscntrl;
+using ::isdigit;
+using ::isgraph;
+using ::islower;
+using ::isprint;
+using ::ispunct;
+using ::isspace;
+using ::isupper;
+using ::isxdigit;
+using ::tolower;
+using ::toupper;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CCTYPE__
diff --git a/libstdc++/include/cerrno b/libstdc++/include/cerrno
new file mode 100644
index 0000000..e53ca25
--- /dev/null
+++ b/libstdc++/include/cerrno
@@ -0,0 +1,40 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CERRNO__
+#define BIONIC_LIBSTDCPP_INCLUDE_CERRNO__
+
+/*
+ * Standard C++ Library wrapper around the C errno.h header file.
+ */
+#include <errno.h>
+
+// errno is a macro, so we can't define std::errno
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CERRNO__
diff --git a/libstdc++/include/cfloat b/libstdc++/include/cfloat
new file mode 100644
index 0000000..21c01d9
--- /dev/null
+++ b/libstdc++/include/cfloat
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CFLOAT__
+#define BIONIC_LIBSTDCPP_INCLUDE_CFLOAT__
+
+/*
+ * Standard C++ Library wrapper around the C float.h header file.
+ */
+#include <sys/limits.h>
+#include <float.h>
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CFLOAT__
diff --git a/libstdc++/include/climits b/libstdc++/include/climits
new file mode 100644
index 0000000..df85cb9
--- /dev/null
+++ b/libstdc++/include/climits
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
+#define BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
+
+/*
+ * Standard C++ Library wrapper around the C limits.h header file.
+ */
+
+#include <limits.h>
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CLIMITS__
diff --git a/libstdc++/include/cmath b/libstdc++/include/cmath
new file mode 100644
index 0000000..bf697ff
--- /dev/null
+++ b/libstdc++/include/cmath
@@ -0,0 +1,71 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CMATH__
+#define BIONIC_LIBSTDCPP_INCLUDE_CMATH__
+
+/*
+ * Standard C++ Library wrapper around the C time.h header file.
+ */
+
+#include <cstddef>
+#include <math.h>
+
+namespace std
+{
+// Functions.
+using ::cos;
+using ::sin;
+using ::tan;
+using ::acos;
+using ::asin;
+using ::atan;
+using ::atan2;
+
+using ::cosh;
+using ::sinh;
+using ::tanh;
+
+using ::exp;
+using ::frexp;
+using ::ldexp;
+using ::log;
+using ::log10;
+using ::modf;
+
+using ::pow;
+using ::sqrt;
+
+using ::ceil;
+using ::fabs;
+using ::floor;
+using ::fmod;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CMATH__
diff --git a/libstdc++/include/csetjmp b/libstdc++/include/csetjmp
new file mode 100644
index 0000000..a68d127
--- /dev/null
+++ b/libstdc++/include/csetjmp
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__
+
+/*
+ * Standard C++ Library wrapper around the C setjmp.h header file.
+ */
+
+#include <setjmp.h>
+
+#ifndef setjmp
+#define setjmp(env) setjmp (env)
+#endif
+
+namespace std
+{
+using ::jmp_buf;
+using ::longjmp;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSETJMP__
diff --git a/libstdc++/include/csignal b/libstdc++/include/csignal
new file mode 100644
index 0000000..2600a75
--- /dev/null
+++ b/libstdc++/include/csignal
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__
+
+/*
+ * Standard C++ Library wrapper around the C signal.h header file.
+ */
+
+#include <signal.h>
+
+namespace std
+{
+using ::sig_atomic_t;
+using ::signal;
+using ::raise;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSIGNAL__
diff --git a/libstdc++/include/cstddef b/libstdc++/include/cstddef
index e69de29..fc1ca9d 100644
--- a/libstdc++/include/cstddef
+++ b/libstdc++/include/cstddef
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__
+
+/*
+ * Standard C++ Library wrapper around the C stddef.h header file.
+ * The following 2 types are also declared in the 'std' namespace:
+ *   . ptrdiff_t
+ *   . size_t
+ */
+#include <stddef.h>
+
+namespace std {
+using ::ptrdiff_t;
+using ::size_t;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDDEF__
diff --git a/libstdc++/include/cstdint b/libstdc++/include/cstdint
new file mode 100644
index 0000000..3df56df
--- /dev/null
+++ b/libstdc++/include/cstdint
@@ -0,0 +1,40 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__
+
+/*
+ * Standard C++ Library wrapper around the C stdint.h header file.
+ */
+
+#include <stdint.h>
+
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDINT__
diff --git a/libstdc++/include/cstdio b/libstdc++/include/cstdio
new file mode 100644
index 0000000..d46a18b
--- /dev/null
+++ b/libstdc++/include/cstdio
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__
+
+/*
+ * Standard C++ Library wrapper around the C stdio.h header file.
+ */
+#include <cstddef>
+#include <stdio.h>
+
+namespace std {
+using ::FILE;
+using ::fpos_t;
+
+using ::clearerr;
+using ::fclose;
+using ::feof;
+using ::ferror;
+using ::fflush;
+using ::fgetc;
+using ::fgetpos;
+using ::fgets;
+using ::fopen;
+using ::fprintf;
+using ::fputc;
+using ::fputs;
+using ::fread;
+using ::freopen;
+using ::fscanf;
+using ::fseek;
+using ::fsetpos;
+using ::ftell;
+using ::fwrite;
+using ::getc;
+using ::getchar;
+using ::gets;
+using ::perror;
+using ::printf;
+using ::putc;
+using ::putchar;
+using ::puts;
+using ::remove;
+using ::rename;
+using ::rewind;
+using ::scanf;
+using ::setbuf;
+using ::setvbuf;
+using ::sprintf;
+using ::sscanf;
+using ::tmpfile;
+using ::tmpnam;
+using ::ungetc;
+using ::vfprintf;
+using ::vprintf;
+using ::vsprintf;
+
+using ::snprintf;
+using ::vfscanf;
+using ::vscanf;
+using ::vsnprintf;
+using ::vsscanf;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDIO__
diff --git a/libstdc++/include/cstdlib b/libstdc++/include/cstdlib
new file mode 100644
index 0000000..5e6a0b3
--- /dev/null
+++ b/libstdc++/include/cstdlib
@@ -0,0 +1,113 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__
+
+/*
+ * Standard C++ Library wrapper around the C stdlib.h header file.
+ */
+#include <stdlib.h>
+
+namespace std {
+
+using ::exit;
+using ::abort;
+using ::atexit;
+using ::on_exit;
+
+using ::getenv;
+using ::putenv;
+using ::setenv;
+using ::unsetenv;
+using ::clearenv;
+
+using ::mktemp;
+using ::mkstemp;
+
+using ::strtol;
+using ::strtoll;
+using ::strtoul;
+using ::strtoull;
+using ::strtod;
+using ::strtof;
+
+using ::atoi;
+using ::atol;
+using ::atoll;
+using ::atof;
+
+using ::abs;
+using ::labs;
+using ::llabs;
+
+using ::realpath;
+using ::system;
+
+using ::bsearch;
+using ::qsort;
+
+using ::jrand48;
+using ::mrand48;
+using ::nrand48;
+using ::lrand48;
+using ::seed48;
+using ::srand48;
+
+using ::rand;
+using ::srand;
+using ::random;
+using ::srandom;
+
+using ::malloc;
+using ::free;
+using ::calloc;
+using ::realloc;
+
+using ::unlockpt;
+using ::ptsname;
+using ::ptsname_r;
+using ::getpt;
+using ::grantpt;
+
+using ::div_t;
+using ::div;
+using ::ldiv_t;
+using ::ldiv;
+using ::lldiv_t;
+using ::lldiv;
+
+using ::mblen;
+using ::mbstowcs;
+using ::mbtowc;
+using ::wctomb;
+using ::wcstombs;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTDLIB__
diff --git a/libstdc++/include/cstring b/libstdc++/include/cstring
new file mode 100644
index 0000000..4ff7a6f
--- /dev/null
+++ b/libstdc++/include/cstring
@@ -0,0 +1,97 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CSTRING__
+#define BIONIC_LIBSTDCPP_INCLUDE_CSTRING__
+
+/*
+ * Standard C++ Library wrapper around the C string.h header file.
+ */
+
+#include <cstddef>
+#include <string.h>
+
+namespace std
+{
+using ::memccpy;
+using ::memchr;
+using ::memrchr;
+using ::memcmp;
+using ::memcpy;
+using ::memmove;
+using ::memset;
+using ::memmem;
+// In string.h but not part of the std
+// using ::memswap;
+
+using ::index;
+using ::rindex;
+using ::strchr;
+using ::strrchr;
+
+using ::strlen;
+using ::strcmp;
+using ::strcpy;
+using ::strcat;
+
+using ::strcasecmp;
+using ::strncasecmp;
+using ::strdup;
+
+using ::strstr;
+using ::strcasestr;
+using ::strtok;
+using ::strtok_r;
+
+using ::strerror;
+using ::strerror_r;
+
+using ::strnlen;
+using ::strncat;
+using ::strndup;
+using ::strncmp;
+using ::strncpy;
+
+// In string.h but not part of the std
+// using ::strlcat;
+// using ::strlcpy;
+
+using ::strcspn;
+using ::strpbrk;
+using ::strsep;
+using ::strspn;
+
+using ::strsignal;
+
+using ::strcoll;
+using ::strxfrm;
+
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CSTRING__
diff --git a/libstdc++/include/ctime b/libstdc++/include/ctime
new file mode 100644
index 0000000..36fe7d5
--- /dev/null
+++ b/libstdc++/include/ctime
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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 BIONIC_LIBSTDCPP_INCLUDE_CTIME__
+#define BIONIC_LIBSTDCPP_INCLUDE_CTIME__
+
+/*
+ * Standard C++ Library wrapper around the C time.h header file.
+ */
+
+#include <cstddef>
+#include <time.h>
+
+namespace std 
+{
+// Types.
+using ::clock_t;
+using ::time_t;
+using ::tm;
+
+// Functions.
+using ::clock;
+using ::difftime;
+using ::mktime;
+using ::time;
+using ::asctime;
+using ::ctime;
+using ::gmtime;
+using ::localtime;
+using ::strftime;
+}  // namespace std
+
+#endif  // BIONIC_LIBSTDCPP_INCLUDE_CTIME__
diff --git a/libstdc++/include/cwchar b/libstdc++/include/cwchar
new file mode 100644
index 0000000..a4f9f42
--- /dev/null
+++ b/libstdc++/include/cwchar
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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.
+ */
+
+/* IMPORTANT: cwchar and cwctype are not supported. See comment in
+ * bionic/libc/include/wchar.h */
diff --git a/libstdc++/include/cwctype_is_not_supported b/libstdc++/include/cwctype_is_not_supported
new file mode 100644
index 0000000..a4f9f42
--- /dev/null
+++ b/libstdc++/include/cwctype_is_not_supported
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright (C) 2009 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.
+ */
+
+/* IMPORTANT: cwchar and cwctype are not supported. See comment in
+ * bionic/libc/include/wchar.h */
diff --git a/libstdc++/include/new b/libstdc++/include/new
index 559308b..19d8185 100644
--- a/libstdc++/include/new
+++ b/libstdc++/include/new
@@ -1,11 +1,10 @@
+/* -*- c++ -*- */
 #ifndef __NEW__
 #define __NEW__
 
-#include <stddef.h>
+#include <cstddef>
 
 namespace std {
-    using ::size_t;
-
     struct nothrow_t {};
     extern const nothrow_t nothrow;
 }
diff --git a/linker/Android.mk b/linker/Android.mk
index 48141be..6c26eb3 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -9,7 +9,12 @@
 	debugger.c \
 	ba.c
 
+ifeq ($(TARGET_ARCH),sh)
+# SH-4A series virtual address range from 0x00000000 to 0x7FFFFFFF.
+LINKER_TEXT_BASE := 0x70000100
+else
 LINKER_TEXT_BASE := 0xB0000100
+endif
 
 # The maximum size set aside for the linker, from
 # LINKER_TEXT_BASE rounded down to a megabyte.
@@ -31,13 +36,17 @@
   ifeq ($(TARGET_ARCH),x86)
     LOCAL_CFLAGS += -DANDROID_X86_LINKER
   else
-    $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
+    ifeq ($(TARGET_ARCH),sh)
+      LOCAL_CFLAGS += -DANDROID_SH_LINKER
+    else
+      $(error Unsupported TARGET_ARCH $(TARGET_ARCH))
+    endif
   endif
 endif
 
 LOCAL_MODULE:= linker
 
-LOCAL_STATIC_LIBRARIES := libcutils libc
+LOCAL_STATIC_LIBRARIES := libcutils libc_nomalloc
 
 #LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
 
diff --git a/linker/README.TXT b/linker/README.TXT
new file mode 100644
index 0000000..4fff14e
--- /dev/null
+++ b/linker/README.TXT
@@ -0,0 +1,114 @@
+Android Dynamic Linker Design Notes
+===================================
+
+Introduction:
+-------------
+
+This document provides several notes related to the design of the Android
+dynamic linker.
+
+
+Prelinking:
+-----------
+
+System libraries in Android are internally prelinked, which means that
+any internal relocations within them are stripped from the corresponding
+shared object, in order to reduce size and speed up loading.
+
+Such libraries can only be loaded at the very specific virtual memory address
+they have been prelinked to (during the build process). The list of prelinked
+system libraries and their corresponding virtual memory address is found in
+the file:
+
+   build/core/prelink-linux-<arch>.map
+
+It should be updated each time a new system library is added to the
+system.
+
+The prelink step happens at build time, and uses the 'soslim' and 'apriori'
+tools:
+
+  - 'apriori' is the real prelink tool which removes relocations from the
+    shared object, however, it must be given a list of symbols to remove
+    from the file.
+
+  - 'soslim' is used to find symbols in an executable ELF file
+    and generate a list that can be passed to 'apriori'.
+
+By default, these tools are only used to remove internal symbols from
+libraries, though they have been designed to allow more aggressive
+optimizations (e.g. 'global' prelinking and symbol stripping, which
+prevent replacing individual system libraries though).
+
+You can disable prelinking at build time by modifying your Android.mk with
+a line like:
+
+    LOCAL_PRELINK_MODULE := false
+
+
+Initialization and Termination functions:
+-----------------------------------------
+
+The Unix Sys V Binary Interface standard states that an
+executable can have the following entries in its .dynamic
+section:
+
+  DT_INIT
+      Points to the address of an initialization function
+      that must be called when the file is loaded.
+
+  DT_INIT_ARRAY
+      Points to an array of function addresses that must be
+      called, in-order, to perform initialization. Some of
+      the entries in the array can be 0 or -1, and should
+      be ignored.
+
+      Note: this is generally stored in a .init_array section
+
+  DT_INIT_ARRAYSZ
+      The size of the DT_INITARRAY, if any
+
+  DT_FINI
+      Points to the address of a finalization function which
+      must be called when the file is unloaded or the process
+      terminated.
+
+  DT_FINI_ARRAY
+      Same as DT_INITARRAY but for finalizers. Note that the
+      functions must be called in reverse-order though
+
+      Note: this is generally stroed in a .fini_array section
+
+  DT_FINI_ARRAYSZ
+      Size of FT_FINIARRAY
+
+  DT_PREINIT_ARRAY
+      An array similar to DT_INIT_ARRAY which must *only* be
+      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)
+
+      Note: this is generally stroed in a .preinit_array section
+
+  DT_PREINIT_ARRAYSZ
+      The size of DT_PREINIT_ARRAY
+
+If both a DT_INIT and DT_INITARRAY entry are present, the DT_INIT
+function must be called before the DT_INITARRAY functions.
+
+Consequently, the DT_FINIARRAY must be parsed in reverse order before
+the DT_FINI function, if both are available.
+
+Note that the implementation of static C++ constructors is very
+much processor dependent, and may use different ELF sections.
+
+On the ARM (see "C++ ABI for ARM" document), the static constructors
+must be called explicitely from the DT_INIT_ARRAY, and each one of them
+shall register a destructor by calling the special __eabi_atexit()
+function (provided by the C library). The DT_FINI_ARRAY is not used
+by static C++ destructors.
+
+On x86, the lists of constructors and destructors are placed in special
+sections named ".ctors" and ".dtors", and the DT_INIT / DT_FINI functions
+are in charge of calling them explicitely.
+
diff --git a/linker/arch/sh/begin.S b/linker/arch/sh/begin.S
new file mode 100644
index 0000000..6f49557
--- /dev/null
+++ b/linker/arch/sh/begin.S
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+.text
+.align  4
+.type   _start,#function
+.globl  _start
+
+_start:
+    mov     r15, r4
+
+    mov.l   0f, r0
+    jsr     @r0
+    nop
+
+    /* linker init returns the _entry address in the main image */
+    jmp     @r0
+    nop
+
+    .balign 4
+0:  .long   __linker_init
+
+    .section .ctors, "wa"
+    .globl  __CTOR_LIST__
+__CTOR_LIST__:
+    .long   -1
diff --git a/linker/dlfcn.c b/linker/dlfcn.c
index cd73d11..611bfd3 100644
--- a/linker/dlfcn.c
+++ b/linker/dlfcn.c
@@ -15,41 +15,49 @@
  */
 #include <dlfcn.h>
 #include <pthread.h>
+#include <stdio.h>
 #include "linker.h"
 
 /* This file hijacks the symbols stubbed out in libdl.so. */
 
 #define DL_SUCCESS                    0
-#define DL_ERR_CANNOT_FIND_LIBRARY    1
+#define DL_ERR_CANNOT_LOAD_LIBRARY    1
 #define DL_ERR_INVALID_LIBRARY_HANDLE 2
 #define DL_ERR_BAD_SYMBOL_NAME        3
 #define DL_ERR_SYMBOL_NOT_FOUND       4
 #define DL_ERR_SYMBOL_NOT_GLOBAL      5
 
+static char dl_err_buf[1024];
+static const char *dl_err_str;
+
 static const char *dl_errors[] = {
-    [DL_SUCCESS] = NULL,
-    [DL_ERR_CANNOT_FIND_LIBRARY] = "Cannot find library",
+    [DL_ERR_CANNOT_LOAD_LIBRARY] = "Cannot load library",
     [DL_ERR_INVALID_LIBRARY_HANDLE] = "Invalid library handle",
     [DL_ERR_BAD_SYMBOL_NAME] = "Invalid symbol name",
     [DL_ERR_SYMBOL_NOT_FOUND] = "Symbol not found",
     [DL_ERR_SYMBOL_NOT_GLOBAL] = "Symbol is not global",
 };
 
-static int dl_last_err = DL_SUCCESS;
-
 #define likely(expr)   __builtin_expect (expr, 1)
 #define unlikely(expr) __builtin_expect (expr, 0)
 
 static pthread_mutex_t dl_lock = PTHREAD_MUTEX_INITIALIZER;
 
-void *dlopen(const char *filename, int flag) 
+static void set_dlerror(int err)
+{
+    snprintf(dl_err_buf, sizeof(dl_err_buf), "%s: %s", dl_errors[err],
+             linker_get_error());
+    dl_err_str = (const char *)&dl_err_buf[0];
+};
+
+void *dlopen(const char *filename, int flag)
 {
     soinfo *ret;
 
     pthread_mutex_lock(&dl_lock);
     ret = find_library(filename);
     if (unlikely(ret == NULL)) {
-        dl_last_err = DL_ERR_CANNOT_FIND_LIBRARY;
+        set_dlerror(DL_ERR_CANNOT_LOAD_LIBRARY);
     } else {
         ret->refcount++;
     }
@@ -59,9 +67,9 @@
 
 const char *dlerror(void)
 {
-    const char *err = dl_errors[dl_last_err];
-    dl_last_err = DL_SUCCESS;
-    return err;
+    const char *tmp = dl_err_str;
+    dl_err_str = NULL;
+    return (const char *)tmp;
 }
 
 void *dlsym(void *handle, const char *symbol)
@@ -71,16 +79,16 @@
     unsigned bind;
 
     pthread_mutex_lock(&dl_lock);
-    
+
     if(unlikely(handle == 0)) { 
-        dl_last_err = DL_ERR_INVALID_LIBRARY_HANDLE;
+        set_dlerror(DL_ERR_INVALID_LIBRARY_HANDLE);
         goto err;
     }
     if(unlikely(symbol == 0)) {
-        dl_last_err = DL_ERR_BAD_SYMBOL_NAME;
+        set_dlerror(DL_ERR_BAD_SYMBOL_NAME);
         goto err;
     }
-    
+
     if(handle == RTLD_DEFAULT) {
         sym = lookup(symbol, &base);
     } else if(handle == RTLD_NEXT) {
@@ -92,16 +100,17 @@
 
     if(likely(sym != 0)) {
         bind = ELF32_ST_BIND(sym->st_info);
-    
+
         if(likely((bind == STB_GLOBAL) && (sym->st_shndx != 0))) {
             unsigned ret = sym->st_value + base;
             pthread_mutex_unlock(&dl_lock);
             return (void*)ret;
         }
 
-        dl_last_err = DL_ERR_SYMBOL_NOT_GLOBAL;
+        set_dlerror(DL_ERR_SYMBOL_NOT_GLOBAL);
     }
-    else dl_last_err = DL_ERR_SYMBOL_NOT_FOUND;
+    else
+        set_dlerror(DL_ERR_SYMBOL_NOT_FOUND);
 
 err:
     pthread_mutex_unlock(&dl_lock);
@@ -128,6 +137,12 @@
 #define ANDROID_LIBDL_STRTAB \
                       "dlopen\0dlclose\0dlsym\0dlerror\0dl_iterate_phdr\0"
 
+#elif defined(ANDROID_SH_LINKER)
+//                     0000000 00011111 111112 22222222 2333333333344444
+//                     0123456 78901234 567890 12345678 9012345678901234
+#define ANDROID_LIBDL_STRTAB \
+                      "dlopen\0dlclose\0dlsym\0dlerror\0dl_iterate_phdr\0"
+
 #else /* !defined(ANDROID_ARM_LINKER) && !defined(ANDROID_X86_LINKER) */
 #error Unsupported architecture. Only ARM and x86 are presently supported.
 #endif
@@ -172,6 +187,12 @@
       st_info: STB_GLOBAL << 4,
       st_shndx: 1,
     },
+#elif defined(ANDROID_SH_LINKER)
+    { st_name: 29,
+      st_value: (Elf32_Addr) &dl_iterate_phdr,
+      st_info: STB_GLOBAL << 4,
+      st_shndx: 1,
+    },
 #endif
 };
 
diff --git a/linker/linker.c b/linker/linker.c
index 300a95c..50eb415 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -51,7 +51,11 @@
 
 #include "ba.h"
 
-#define SO_MAX 64
+#define SO_MAX 96
+
+/* Assume average path length of 64 and max 8 paths */
+#define LDPATH_BUFSIZE 512
+#define LDPATH_MAX 8
 
 /* >>> IMPORTANT NOTE - READ ME BEFORE MODIFYING <<<
  *
@@ -66,18 +70,12 @@
  * - should we do anything special for STB_WEAK symbols?
  * - are we doing everything we should for ARM_COPY relocations?
  * - cleaner error reporting
- * - configuration for paths (LD_LIBRARY_PATH?)
  * - after linking, set as much stuff as possible to READONLY
  *   and NOEXEC
  * - linker hardcodes PAGE_SIZE and PAGE_MASK because the kernel
  *   headers provide versions that are negative...
  * - allocate space for soinfo structs dynamically instead of
  *   having a hard limit (64)
- *
- * features to add someday:
- *
- * - dlopen() and friends
- *
 */
 
 
@@ -89,6 +87,9 @@
 static soinfo *solist = &libdl_info;
 static soinfo *sonext = &libdl_info;
 
+static char ldpaths_buf[LDPATH_BUFSIZE];
+static const char *ldpaths[LDPATH_MAX + 1];
+
 int debug_verbosity;
 static int pid;
 
@@ -104,6 +105,32 @@
 #define PT_ARM_EXIDX    0x70000001      /* .ARM.exidx segment */
 #endif
 
+#define HOODLUM(name, ret, ...)                                               \
+    ret name __VA_ARGS__                                                      \
+    {                                                                         \
+        char errstr[] = "ERROR: " #name " called from the dynamic linker!\n"; \
+        write(2, errstr, sizeof(errstr));                                     \
+        abort();                                                              \
+    }
+HOODLUM(malloc, void *, (size_t size));
+HOODLUM(free, void, (void *ptr));
+HOODLUM(realloc, void *, (void *ptr, size_t size));
+HOODLUM(calloc, void *, (size_t cnt, size_t size));
+
+static char tmp_err_buf[768];
+static char __linker_dl_err_buf[768];
+#define DL_ERR(fmt, x...)                                                     \
+    do {                                                                      \
+        snprintf(__linker_dl_err_buf, sizeof(__linker_dl_err_buf),            \
+                 "%s[%d]: " fmt, __func__, __LINE__, ##x);                    \
+        ERROR(fmt "\n", ##x);                                                      \
+    } while(0)
+
+const char *linker_get_error(void)
+{
+    return (const char *)&__linker_dl_err_buf[0];
+}
+
 /*
  * This function is an empty stub where GDB locates a breakpoint to get notified
  * about linker activity.
@@ -125,6 +152,7 @@
     map = &(info->linkmap);
     map->l_addr = info->base;
     map->l_name = (char*) info->name;
+    map->l_ld = (uintptr_t)info->dynamic;
 
     /* Stick the new library at the end of the list.
      * gdb tends to care more about libc than it does
@@ -207,7 +235,7 @@
     soinfo *si;
 
     if(strlen(name) >= SOINFO_NAME_LEN) {
-        ERROR("%5d library name %s too long\n", pid, name);
+        DL_ERR("%5d library name %s too long", pid, name);
         return 0;
     }
 
@@ -216,7 +244,7 @@
     */
     if (!freelist) {
         if(socount == SO_MAX) {
-            ERROR("%5d too many libraries when loading %s\n", pid, name);
+            DL_ERR("%5d too many libraries when loading %s", pid, name);
             return NULL;
         }
         freelist = sopool + socount++;
@@ -252,7 +280,7 @@
     }
     if (trav == NULL) {
         /* si was not ni solist */
-        ERROR("%5d name %s is not in solist!\n", pid, si->name);
+        DL_ERR("%5d name %s is not in solist!", pid, si->name);
         return;
     }
 
@@ -317,7 +345,7 @@
    *pcount = 0;
     return NULL;
 }
-#elif defined(ANDROID_X86_LINKER)
+#elif defined(ANDROID_X86_LINKER) || defined(ANDROID_SH_LINKER)
 /* Here, we only have to provide a callback to iterate across all the
  * loaded libraries. gcc_eh does the rest. */
 int
@@ -477,13 +505,12 @@
     return -1;
 }
 
-/* TODO: Need to add support for initializing the so search path with
- * LD_LIBRARY_PATH env variable for non-setuid programs. */
 static int open_library(const char *name)
 {
     int fd;
     char buf[512];
     const char **path;
+    int n;
 
     TRACE("[ %5d opening %s ]\n", pid, name);
 
@@ -493,8 +520,21 @@
     if ((name[0] == '/') && ((fd = _open_lib(name)) >= 0))
         return fd;
 
+    for (path = ldpaths; *path; path++) {
+        n = snprintf(buf, sizeof(buf), "%s/%s", *path, name);
+        if (n < 0 || n >= (int)sizeof(buf)) {
+            WARN("Ignoring very long library path: %s/%s\n", *path, name);
+            continue;
+        }
+        if ((fd = _open_lib(buf)) >= 0)
+            return fd;
+    }
     for (path = sopaths; *path; path++) {
-        snprintf(buf, sizeof(buf), "%s/%s", *path, name);
+        n = snprintf(buf, sizeof(buf), "%s/%s", *path, name);
+        if (n < 0 || n >= (int)sizeof(buf)) {
+            WARN("Ignoring very long library path: %s/%s\n", *path, name);
+            continue;
+        }
         if ((fd = _open_lib(buf)) >= 0)
             return fd;
     }
@@ -521,7 +561,7 @@
 
     sz = lseek(fd, -sizeof(prelink_info_t), SEEK_END);
     if (sz < 0) {
-        ERROR("lseek() failed!\n");
+        DL_ERR("lseek() failed!");
         return 0;
     }
 
@@ -597,7 +637,7 @@
 
     TRACE("[ %5d Computing extents for '%s'. ]\n", pid, name);
     if (verify_elf_object(_hdr, name) < 0) {
-        ERROR("%5d - %s is not a valid ELF object\n", pid, name);
+        DL_ERR("%5d - %s is not a valid ELF object", pid, name);
         return (unsigned)-1;
     }
 
@@ -625,7 +665,7 @@
     }
 
     if ((min_vaddr == 0xffffffff) && (max_vaddr == 0)) {
-        ERROR("%5d - No loadable segments found in %s.\n", pid, name);
+        DL_ERR("%5d - No loadable segments found in %s.", pid, name);
         return (unsigned)-1;
     }
 
@@ -661,14 +701,14 @@
     void *base = mmap((void *)si->base, si->size, PROT_READ | PROT_EXEC,
                       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
     if (base == MAP_FAILED) {
-        ERROR("%5d can NOT map (%sprelinked) library '%s' at 0x%08x "
-              "as requested, will try general pool: %d (%s)\n",
+        DL_ERR("%5d can NOT map (%sprelinked) library '%s' at 0x%08x "
+              "as requested, will try general pool: %d (%s)",
               pid, (si->base ? "" : "non-"), si->name, si->base,
               errno, strerror(errno));
         return -1;
     } else if (base != (void *)si->base) {
-        ERROR("OOPS: %5d %sprelinked library '%s' mapped at 0x%08x, "
-              "not at 0x%08x\n", pid, (si->base ? "" : "non-"),
+        DL_ERR("OOPS: %5d %sprelinked library '%s' mapped at 0x%08x, "
+              "not at 0x%08x", pid, (si->base ? "" : "non-"),
               si->name, (unsigned)base, si->base);
         munmap(base, si->size);
         return -1;
@@ -705,7 +745,7 @@
     }
 
 err:
-    ERROR("OOPS: %5d cannot map library '%s'. no vspace available.\n",
+    DL_ERR("OOPS: %5d cannot map library '%s'. no vspace available.",
           pid, si->name);
     return -1;
 }
@@ -764,8 +804,8 @@
                          MAP_PRIVATE | MAP_FIXED, fd,
                          phdr->p_offset & (~PAGE_MASK));
             if (pbase == MAP_FAILED) {
-                ERROR("%d failed to map segment from '%s' @ 0x%08x (0x%08x). "
-                      "p_vaddr=0x%08x p_offset=0x%08x\n", pid, si->name,
+                DL_ERR("%d failed to map segment from '%s' @ 0x%08x (0x%08x). "
+                      "p_vaddr=0x%08x p_offset=0x%08x", pid, si->name,
                       (unsigned)tmp, len, phdr->p_vaddr, phdr->p_offset);
                 goto fail;
             }
@@ -820,8 +860,8 @@
                                   MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS,
                                   -1, 0);
                 if (extra_base == MAP_FAILED) {
-                    ERROR("[ %5d - failed to extend segment from '%s' @ 0x%08x "
-                          "(0x%08x) ]\n", pid, si->name, (unsigned)tmp,
+                    DL_ERR("[ %5d - failed to extend segment from '%s' @ 0x%08x"
+                           " (0x%08x) ]", pid, si->name, (unsigned)tmp,
                           extra_len);
                     goto fail;
                 }
@@ -873,8 +913,8 @@
 
     /* Sanity check */
     if (total_sz > si->size) {
-        ERROR("%5d - Total length (0x%08x) of mapped segments from '%s' is "
-              "greater than what was allocated (0x%08x). THIS IS BAD!\n",
+        DL_ERR("%5d - Total length (0x%08x) of mapped segments from '%s' is "
+              "greater than what was allocated (0x%08x). THIS IS BAD!",
               pid, total_sz, si->name, si->size);
         goto fail;
     }
@@ -937,21 +977,24 @@
     int cnt;
     unsigned ext_sz;
     unsigned req_base;
+    const char *bname;
     soinfo *si = NULL;
     Elf32_Ehdr *hdr;
 
-    if(fd == -1)
+    if(fd == -1) {
+        DL_ERR("Library '%s' not found", name);
         return NULL;
+    }
 
     /* We have to read the ELF header to figure out what to do with this image
      */
     if (lseek(fd, 0, SEEK_SET) < 0) {
-        ERROR("lseek() failed!\n");
+        DL_ERR("lseek() failed!");
         goto fail;
     }
 
     if ((cnt = read(fd, &__header[0], PAGE_SIZE)) < 0) {
-        ERROR("read() failed!\n");
+        DL_ERR("read() failed!");
         goto fail;
     }
 
@@ -968,7 +1011,8 @@
      * same thing would happen if we failed during linking. Configuring the
      * soinfo struct here is a lot more convenient.
      */
-    si = alloc_info(name);
+    bname = strrchr(name, '/');
+    si = alloc_info(bname ? bname + 1 : name);
     if (si == NULL)
         goto fail;
 
@@ -1037,13 +1081,15 @@
 soinfo *find_library(const char *name)
 {
     soinfo *si;
+    const char *bname = strrchr(name, '/');
+    bname = bname ? bname + 1 : name;
 
     for(si = solist; si != 0; si = si->next){
-        if(!strcmp(name, si->name)) {
+        if(!strcmp(bname, si->name)) {
             if(si->flags & FLAG_ERROR) return 0;
             if(si->flags & FLAG_LINKED) return si;
-            ERROR("OOPS: %5d recursive link to '%s'\n", pid, si->name);
-            return 0;
+            DL_ERR("OOPS: %5d recursive link to '%s'", pid, si->name);
+            return NULL;
         }
     }
 
@@ -1074,7 +1120,7 @@
                 if(lsi)
                     unload_library(lsi);
                 else
-                    ERROR("%5d could not unload '%s'\n",
+                    DL_ERR("%5d could not unload '%s'",
                           pid, si->strtab + d[1]);
             }
         }
@@ -1121,27 +1167,27 @@
         DEBUG("%5d Processing '%s' relocation at index %d\n", pid,
               si->name, idx);
         if(sym != 0) {
-            s = _do_lookup(si, strtab + symtab[sym].st_name, &base);
+            sym_name = (char *)(strtab + symtab[sym].st_name);
+            s = _do_lookup(si, sym_name, &base);
             if(s == 0) {
-                ERROR("%5d cannot locate '%s'...\n", pid, sym_name);
+                DL_ERR("%5d cannot locate '%s'...", pid, sym_name);
                 return -1;
             }
 #if 0
             if((base == 0) && (si->base != 0)){
                     /* linking from libraries to main image is bad */
-                ERROR("%5d cannot locate '%s'...\n", 
+                DL_ERR("%5d cannot locate '%s'...",
                        pid, strtab + symtab[sym].st_name);
                 return -1;
             }
 #endif
             if ((s->st_shndx == SHN_UNDEF) && (s->st_value != 0)) {
-                ERROR("%5d In '%s', shndx=%d && value=0x%08x. We do not "
-                      "handle this yet\n", pid, si->name, s->st_shndx,
+                DL_ERR("%5d In '%s', shndx=%d && value=0x%08x. We do not "
+                      "handle this yet", pid, si->name, s->st_shndx,
                       s->st_value);
                 return -1;
             }
             sym_addr = (unsigned)(s->st_value + base);
-            sym_name = (char *)(strtab + symtab[sym].st_name);
             COUNT_RELOC(RELOC_SYMBOL);
         } else {
             s = 0;
@@ -1198,7 +1244,7 @@
             COUNT_RELOC(RELOC_RELATIVE);
             MARK(rel->r_offset);
             if(sym){
-                ERROR("%5d odd RELATIVE form...\n", pid);
+                DL_ERR("%5d odd RELATIVE form...", pid);
                 return -1;
             }
             TRACE_TYPE(RELO, "%5d RELO RELATIVE %08x <- +%08x\n", pid,
@@ -1239,7 +1285,7 @@
 #endif /* ANDROID_ARM_LINKER */
 
         default:
-            ERROR("%5d unknown reloc type %d @ %p (%d)\n",
+            DL_ERR("%5d unknown reloc type %d @ %p (%d)",
                   pid, type, rel, (int) (rel - start));
             return -1;
         }
@@ -1248,13 +1294,132 @@
     return 0;
 }
 
-static void call_array(unsigned *ctor, int count)
+#if defined(ANDROID_SH_LINKER)
+static int reloc_library_a(soinfo *si, Elf32_Rela *rela, unsigned count)
 {
-    int n;
-    for(n = count; n > 0; n--){
-        TRACE("[ %5d Looking at ctor *0x%08x == 0x%08x ]\n", pid,
+    Elf32_Sym *symtab = si->symtab;
+    const char *strtab = si->strtab;
+    Elf32_Sym *s;
+    unsigned base;
+    Elf32_Rela *start = rela;
+    unsigned idx;
+
+    for (idx = 0; idx < count; ++idx) {
+        unsigned type = ELF32_R_TYPE(rela->r_info);
+        unsigned sym = ELF32_R_SYM(rela->r_info);
+        unsigned reloc = (unsigned)(rela->r_offset + si->base);
+        unsigned sym_addr = 0;
+        char *sym_name = NULL;
+
+        DEBUG("%5d Processing '%s' relocation at index %d\n", pid,
+              si->name, idx);
+        if(sym != 0) {
+            sym_name = (char *)(strtab + symtab[sym].st_name);
+            s = _do_lookup(si, sym_name, &base);
+            if(s == 0) {
+                DL_ERR("%5d cannot locate '%s'...", pid, sym_name);
+                return -1;
+            }
+#if 0
+            if((base == 0) && (si->base != 0)){
+                    /* linking from libraries to main image is bad */
+                DL_ERR("%5d cannot locate '%s'...",
+                       pid, strtab + symtab[sym].st_name);
+                return -1;
+            }
+#endif
+            if ((s->st_shndx == SHN_UNDEF) && (s->st_value != 0)) {
+                DL_ERR("%5d In '%s', shndx=%d && value=0x%08x. We do not "
+                      "handle this yet", pid, si->name, s->st_shndx,
+                      s->st_value);
+                return -1;
+            }
+            sym_addr = (unsigned)(s->st_value + base);
+            COUNT_RELOC(RELOC_SYMBOL);
+        } else {
+            s = 0;
+        }
+
+/* TODO: This is ugly. Split up the relocations by arch into
+ * different files.
+ */
+        switch(type){
+        case R_SH_JUMP_SLOT:
+            COUNT_RELOC(RELOC_ABSOLUTE);
+            MARK(rela->r_offset);
+            TRACE_TYPE(RELO, "%5d RELO JMP_SLOT %08x <- %08x %s\n", pid,
+                       reloc, sym_addr, sym_name);
+            *((unsigned*)reloc) = sym_addr;
+            break;
+        case R_SH_GLOB_DAT:
+            COUNT_RELOC(RELOC_ABSOLUTE);
+            MARK(rela->r_offset);
+            TRACE_TYPE(RELO, "%5d RELO GLOB_DAT %08x <- %08x %s\n", pid,
+                       reloc, sym_addr, sym_name);
+            *((unsigned*)reloc) = sym_addr;
+            break;
+        case R_SH_DIR32:
+            COUNT_RELOC(RELOC_ABSOLUTE);
+            MARK(rela->r_offset);
+            TRACE_TYPE(RELO, "%5d RELO DIR32 %08x <- %08x %s\n", pid,
+                       reloc, sym_addr, sym_name);
+            *((unsigned*)reloc) += sym_addr;
+            break;
+        case R_SH_RELATIVE:
+            COUNT_RELOC(RELOC_RELATIVE);
+            MARK(rela->r_offset);
+            if(sym){
+                DL_ERR("%5d odd RELATIVE form...", pid);
+                return -1;
+            }
+            TRACE_TYPE(RELO, "%5d RELO RELATIVE %08x <- +%08x\n", pid,
+                       reloc, si->base);
+            *((unsigned*)reloc) += si->base;
+            break;
+
+        default:
+            DL_ERR("%5d unknown reloc type %d @ %p (%d)",
+                  pid, type, rela, (int) (rela - start));
+            return -1;
+        }
+        rela++;
+    }
+    return 0;
+}
+#endif /* ANDROID_SH_LINKER */
+
+
+/* Please read the "Initialization and Termination functions" functions.
+ * of the linker design note in bionic/linker/README.TXT to understand
+ * what the following code is doing.
+ *
+ * The important things to remember are:
+ *
+ *   DT_PREINIT_ARRAY must be called first for executables, and should
+ *   not appear in shared libraries.
+ *
+ *   DT_INIT should be called before DT_INIT_ARRAY if both are present
+ *
+ *   DT_FINI should be called after DT_FINI_ARRAY if both are present
+ *
+ *   DT_FINI_ARRAY must be parsed in reverse order.
+ */
+
+static void call_array(unsigned *ctor, int count, int reverse)
+{
+    int n, inc = 1;
+
+    if (reverse) {
+        ctor += (count-1);
+        inc   = -1;
+    }
+
+    for(n = count; n > 0; n--) {
+        TRACE("[ %5d Looking at %s *0x%08x == 0x%08x ]\n", pid,
+              reverse ? "dtor" : "ctor",
               (unsigned)ctor, (unsigned)*ctor);
-        void (*func)() = (void (*)()) *ctor++;
+        void (*func)() = (void (*)()) *ctor;
+        ctor += inc;
         if(((int) func == 0) || ((int) func == -1)) continue;
         TRACE("[ %5d Calling func @ 0x%08x ]\n", pid, (unsigned)func);
         func();
@@ -1263,31 +1428,20 @@
 
 static void call_constructors(soinfo *si)
 {
-    /* TODO: THE ORIGINAL CODE SEEMED TO CALL THE INIT FUNCS IN THE WRONG ORDER.
-     *       Old order: init, init_array, preinit_array..
-     *       Correct order: preinit_array, init, init_array.
-     *       Verify WHY.
-     */
-
     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,
               si->name);
-        call_array(si->preinit_array, si->preinit_array_count);
+        call_array(si->preinit_array, si->preinit_array_count, 0);
         TRACE("[ %5d Done calling preinit_array for '%s' ]\n", pid, si->name);
     } else {
         if (si->preinit_array) {
-            ERROR("%5d Shared library '%s' has a preinit_array table @ 0x%08x."
-                  " This is INVALID.\n", pid, si->name,
-                  (unsigned)si->preinit_array);
+            DL_ERR("%5d Shared library '%s' has a preinit_array table @ 0x%08x."
+                   " This is INVALID.", pid, si->name,
+                   (unsigned)si->preinit_array);
         }
     }
 
-    // If we have an init section, then we should call it now, to make sure
-    // that all the funcs in the .ctors section get run.
-    // Note: For ARM, we shouldn't have a .ctor section (should be empty)
-    // when we have an (pre)init_array section, but let's be compatible with
-    // old (non-eabi) binaries and try the _init (DT_INIT) anyway.
     if (si->init_func) {
         TRACE("[ %5d Calling init_func @ 0x%08x for '%s' ]\n", pid,
               (unsigned)si->init_func, si->name);
@@ -1298,25 +1452,21 @@
     if (si->init_array) {
         TRACE("[ %5d Calling init_array @ 0x%08x [%d] for '%s' ]\n", pid,
               (unsigned)si->init_array, si->init_array_count, si->name);
-        call_array(si->init_array, si->init_array_count);
+        call_array(si->init_array, si->init_array_count, 0);
         TRACE("[ %5d Done calling init_array for '%s' ]\n", pid, si->name);
     }
 }
 
+
 static void call_destructors(soinfo *si)
 {
     if (si->fini_array) {
         TRACE("[ %5d Calling fini_array @ 0x%08x [%d] for '%s' ]\n", pid,
               (unsigned)si->fini_array, si->fini_array_count, si->name);
-        call_array(si->fini_array, si->fini_array_count);
+        call_array(si->fini_array, si->fini_array_count, 1);
         TRACE("[ %5d Done calling fini_array for '%s' ]\n", pid, si->name);
     }
 
-    // If we have an fini section, then we should call it now, to make sure
-    // that all the funcs in the .dtors section get run.
-    // Note: For ARM, we shouldn't have a .dtor section (should be empty)
-    // when we have an fini_array section, but let's be compatible with
-    // old (non-eabi) binaries and try the _fini (DT_FINI) anyway.
     if (si->fini_func) {
         TRACE("[ %5d Calling fini_func @ 0x%08x for '%s' ]\n", pid,
               (unsigned)si->fini_func, si->name);
@@ -1334,7 +1484,7 @@
 
     dev_null = open("/dev/null", O_RDWR);
     if (dev_null < 0) {
-        ERROR("Cannot open /dev/null.\n");
+        DL_ERR("Cannot open /dev/null.");
         return -1;
     }
     TRACE("[ %5d Opened /dev/null file-descriptor=%d]\n", pid, dev_null);
@@ -1360,7 +1510,7 @@
         /* The only error we allow is that the file descriptor does not
            exist, in which case we dup /dev/null to it. */
         if (errno != EBADF) {
-            ERROR("nullify_stdio: unhandled error %s\n", strerror(errno));
+            DL_ERR("nullify_stdio: unhandled error %s", strerror(errno));
             return_value = -1;
             continue;
         }
@@ -1371,9 +1521,9 @@
         do {
             status = dup2(dev_null, i);
         } while (status < 0 && errno == EINTR);
-        
+
         if (status < 0) {
-            ERROR("nullify_stdio: dup2 error %s\n", strerror(errno));
+            DL_ERR("nullify_stdio: dup2 error %s", strerror(errno));
             return_value = -1;
             continue;
         }
@@ -1382,12 +1532,12 @@
     /* If /dev/null is not one of the stdio file descriptors, close it. */
     if (dev_null > 2) {
         TRACE("[ %5d Closing /dev/null file-descriptor=%d]\n", pid, dev_null);
-	do {
+        do {
             status = close(dev_null);
         } while (status < 0 && errno == EINTR);
 
         if (status < 0) {
-            ERROR("nullify_stdio: close error %s\n", strerror(errno));
+            DL_ERR("nullify_stdio: close error %s", strerror(errno));
             return_value = -1;
         }
     }
@@ -1455,8 +1605,8 @@
                 }
             } else if (phdr->p_type == PT_DYNAMIC) {
                 if (si->dynamic != (unsigned *)-1) {
-                    ERROR("%5d multiple PT_DYNAMIC segments found in '%s'. "
-                          "Segment at 0x%08x, previously one found at 0x%08x\n",
+                    DL_ERR("%5d multiple PT_DYNAMIC segments found in '%s'. "
+                          "Segment at 0x%08x, previously one found at 0x%08x",
                           pid, si->name, si->base + phdr->p_vaddr,
                           (unsigned)si->dynamic);
                     goto fail;
@@ -1468,7 +1618,7 @@
     }
 
     if (si->dynamic == (unsigned *)-1) {
-        ERROR("%5d missing PT_DYNAMIC?!\n", pid);
+        DL_ERR("%5d missing PT_DYNAMIC?!", pid);
         goto fail;
     }
 
@@ -1490,24 +1640,40 @@
         case DT_SYMTAB:
             si->symtab = (Elf32_Sym *) (si->base + *d);
             break;
+#if !defined(ANDROID_SH_LINKER)
         case DT_PLTREL:
             if(*d != DT_REL) {
-                ERROR("DT_RELA not supported\n");
+                DL_ERR("DT_RELA not supported");
                 goto fail;
             }
             break;
+#endif
+#ifdef ANDROID_SH_LINKER
+        case DT_JMPREL:
+            si->plt_rela = (Elf32_Rela*) (si->base + *d);
+            break;
+        case DT_PLTRELSZ:
+            si->plt_rela_count = *d / sizeof(Elf32_Rela);
+            break;
+#else
         case DT_JMPREL:
             si->plt_rel = (Elf32_Rel*) (si->base + *d);
             break;
         case DT_PLTRELSZ:
             si->plt_rel_count = *d / 8;
             break;
+#endif
         case DT_REL:
             si->rel = (Elf32_Rel*) (si->base + *d);
             break;
         case DT_RELSZ:
             si->rel_count = *d / 8;
             break;
+#ifdef ANDROID_SH_LINKER
+        case DT_RELASZ:
+            si->rela_count = *d / sizeof(Elf32_Rela);
+             break;
+#endif
         case DT_PLTGOT:
             /* Save this in case we decide to do lazy binding. We don't yet. */
             si->plt_got = (unsigned *)(si->base + *d);
@@ -1516,9 +1682,15 @@
             // Set the DT_DEBUG entry to the addres of _r_debug for GDB
             *d = (int) &_r_debug;
             break;
+#ifdef ANDROID_SH_LINKER
         case DT_RELA:
-            ERROR("%5d DT_RELA not supported\n", pid);
+            si->rela = (Elf32_Rela *) (si->base + *d);
+            break;
+#else
+         case DT_RELA:
+            DL_ERR("%5d DT_RELA not supported", pid);
             goto fail;
+#endif
         case DT_INIT:
             si->init_func = (void (*)(void))(si->base + *d);
             DEBUG("%5d %s constructors (init func) found at %p\n",
@@ -1569,16 +1741,18 @@
            pid, si->base, si->strtab, si->symtab);
 
     if((si->strtab == 0) || (si->symtab == 0)) {
-        ERROR("%5d missing essential tables\n", pid);
+        DL_ERR("%5d missing essential tables", pid);
         goto fail;
     }
 
     for(d = si->dynamic; *d; d += 2) {
         if(d[0] == DT_NEEDED){
             DEBUG("%5d %s needs %s\n", pid, si->name, si->strtab + d[1]);
-            soinfo *lsi = find_library(si->strtab + d[1]);            
+            soinfo *lsi = find_library(si->strtab + d[1]);
             if(lsi == 0) {
-                ERROR("%5d could not load '%s'\n", pid, si->strtab + d[1]);
+                strlcpy(tmp_err_buf, linker_get_error(), sizeof(tmp_err_buf));
+                DL_ERR("%5d could not load needed library '%s' for '%s' (%s)",
+                       pid, si->strtab + d[1], si->name, tmp_err_buf);
                 goto fail;
             }
             lsi->refcount++;
@@ -1596,6 +1770,19 @@
             goto fail;
     }
 
+#ifdef ANDROID_SH_LINKER
+    if(si->plt_rela) {
+        DEBUG("[ %5d relocating %s plt ]\n", pid, si->name );
+        if(reloc_library_a(si, si->plt_rela, si->plt_rela_count))
+            goto fail;
+    }
+    if(si->rela) {
+        DEBUG("[ %5d relocating %s ]\n", pid, si->name );
+        if(reloc_library_a(si, si->rela, si->rela_count))
+            goto fail;
+    }
+#endif /* ANDROID_SH_LINKER */
+
     si->flags |= FLAG_LINKED;
     DEBUG("[ %5d finished linking %s ]\n", pid, si->name);
 
@@ -1643,6 +1830,29 @@
     return -1;
 }
 
+static void parse_library_path(char *path, char *delim)
+{
+    size_t len;
+    char *ldpaths_bufp = ldpaths_buf;
+    int i = 0;
+
+    len = strlcpy(ldpaths_buf, path, sizeof(ldpaths_buf));
+
+    while (i < LDPATH_MAX && (ldpaths[i] = strsep(&ldpaths_bufp, delim))) {
+        if (*ldpaths[i] != '\0')
+            ++i;
+    }
+
+    /* Forget the last path if we had to truncate; this occurs if the 2nd to
+     * last char isn't '\0' (i.e. not originally a delim). */
+    if (i > 0 && len >= sizeof(ldpaths_buf) &&
+            ldpaths_buf[sizeof(ldpaths_buf) - 2] != '\0') {
+        ldpaths[i - 1] = NULL;
+    } else {
+        ldpaths[i] = NULL;
+    }
+}
+
 int main(int argc, char **argv)
 {
     return 0;
@@ -1661,6 +1871,12 @@
     unsigned *vecs = (unsigned*) (argv + argc + 1);
     soinfo *si;
     struct link_map * map;
+    char *ldpath_env = NULL;
+
+    /* Setup a temporary TLS area that is used to get a working
+     * errno for system calls.
+     */
+    __set_tls(__tls_area);
 
     pid = getpid();
 
@@ -1669,8 +1885,15 @@
     gettimeofday(&t0, 0);
 #endif
 
-    __set_tls(__tls_area);
-    ((unsigned *)__get_tls())[TLS_SLOT_THREAD_ID] = gettid();
+    /* NOTE: we store the elfdata pointer on a special location
+     *       of the temporary TLS area in order to pass it to
+     *       the C Library's runtime initializer.
+     *
+     *       The initializer must clear the slot and reset the TLS
+     *       to point to a different location to ensure that no other
+     *       shared library constructor can access it.
+     */
+    __tls_area[TLS_SLOT_BIONIC_PREINIT] = elfdata;
 
     debugger_init();
 
@@ -1678,6 +1901,8 @@
     while(vecs[0] != 0) {
         if(!strncmp((char*) vecs[0], "DEBUG=", 6)) {
             debug_verbosity = atoi(((char*) vecs[0]) + 6);
+        } else if(!strncmp((char*) vecs[0], "LD_LIBRARY_PATH=", 16)) {
+            ldpath_env = (char*) vecs[0] + 16;
         }
         vecs++;
     }
@@ -1737,8 +1962,14 @@
     si->wrprotect_start = 0xffffffff;
     si->wrprotect_end = 0;
 
-    if(link_image(si, 0)){
-        ERROR("CANNOT LINK EXECUTABLE '%s'\n", argv[0]);
+        /* Use LD_LIBRARY_PATH if we aren't setuid/setgid */
+    if (ldpath_env && getuid() == geteuid() && getgid() == getegid())
+        parse_library_path(ldpath_env, ":");
+
+    if(link_image(si, 0)) {
+        char errmsg[] = "CANNOT LINK EXECUTABLE\n";
+        write(2, __linker_dl_err_buf, strlen(__linker_dl_err_buf));
+        write(2, errmsg, sizeof(errmsg));
         exit(-1);
     }
 
diff --git a/linker/linker.h b/linker/linker.h
index d80c761..2fe61b1 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -122,6 +122,14 @@
     Elf32_Rel *rel;
     unsigned rel_count;
 
+#ifdef ANDROID_SH_LINKER
+    Elf32_Rela *plt_rela;
+    unsigned plt_rela_count;
+
+    Elf32_Rela *rela;
+    unsigned rela_count;
+#endif /* ANDROID_SH_LINKER */
+
     unsigned *preinit_array;
     unsigned preinit_array_count;
 
@@ -147,10 +155,15 @@
 extern soinfo libdl_info;
 
 /* these must all be powers of two */
+#ifdef ARCH_SH
+#define LIBBASE 0x60000000
+#define LIBLAST 0x70000000
+#define LIBINC  0x00100000
+#else
 #define LIBBASE 0x80000000
 #define LIBLAST 0x90000000
 #define LIBINC  0x00100000
-
+#endif
 
 #ifdef ANDROID_ARM_LINKER
 
@@ -167,6 +180,13 @@
 #define R_386_JUMP_SLOT  7
 #define R_386_RELATIVE   8
 
+#elif defined(ANDROID_SH_LINKER)
+
+#define R_SH_DIR32      1
+#define R_SH_GLOB_DAT   163
+#define R_SH_JUMP_SLOT  164
+#define R_SH_RELATIVE   165
+
 #endif /* ANDROID_*_LINKER */
 
 
@@ -204,11 +224,12 @@
 unsigned unload_library(soinfo *si);
 Elf32_Sym *lookup_in_library(soinfo *si, const char *name);
 Elf32_Sym *lookup(const char *name, unsigned *base);
+const char *linker_get_error(void);
 
 #ifdef ANDROID_ARM_LINKER 
 typedef long unsigned int *_Unwind_Ptr;
 _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount);
-#elif defined(ANDROID_X86_LINKER)
+#elif defined(ANDROID_X86_LINKER) || defined(ANDROID_SH_LINKER)
 int dl_iterate_phdr(int (*cb)(struct dl_phdr_info *, size_t, void *), void *);
 #endif
 
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index 3cc1343..3f4fc4c 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -55,17 +55,16 @@
 #define TRUE                 1
 #define FALSE                0
 
-
-#define __PRINTVF(v,f,x...)   do {                                        \
-        (debug_verbosity > (v)) && (printf(x), ((f) && fflush(stdout))); \
-    } while (0)
 /* Only use printf() during debugging.  We have seen occasional memory
  * corruption when the linker uses printf().
  */
 #if LINKER_DEBUG
 extern int debug_verbosity;
 #warning "*** LINKER IS USING printf(); DO NOT CHECK THIS IN ***"
-#define _PRINTVF(v,f,x...)    __PRINTVF(v,f,x)
+#define _PRINTVF(v,f,x...)                                                \
+    do {                                                                  \
+        (debug_verbosity > (v)) && (printf(x), ((f) && fflush(stdout)));  \
+    } while (0)
 #else /* !LINKER_DEBUG */
 #define _PRINTVF(v,f,x...)   do {} while(0)
 #endif /* LINKER_DEBUG */
@@ -75,8 +74,9 @@
 #define TRACE(x...)          _PRINTVF(1, TRUE, x)
 #define WARN(fmt,args...)    \
         _PRINTVF(-1, TRUE, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args)
-#define ERROR(fmt,args...)   \
-        __PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args)
+#define ERROR(fmt,args...)    \
+        _PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args)
+
 
 #if TRACE_DEBUG
 #define DEBUG(x...)          _PRINTVF(2, TRUE, "DEBUG: " x)