summaryrefslogtreecommitdiffstats
path: root/toolchain/musl
diff options
context:
space:
mode:
authorSteven Barth <cyrus@openwrt.org>2015-06-20 18:36:50 +0000
committerSteven Barth <cyrus@openwrt.org>2015-06-20 18:36:50 +0000
commiteb73f4aed798280e9012f535b6b7c227d4496b8f (patch)
tree6e435679b2efec455012c6d6f132aa91e47246e0 /toolchain/musl
parent34aeffef08596ab5330e4c60f8d1028f7021013c (diff)
downloadmaster-31e0f0ae-eb73f4aed798280e9012f535b6b7c227d4496b8f.tar.gz
master-31e0f0ae-eb73f4aed798280e9012f535b6b7c227d4496b8f.tar.bz2
master-31e0f0ae-eb73f4aed798280e9012f535b6b7c227d4496b8f.zip
musl: update musl to 2015-06-20
Fixes a mips-regression and a missing SSP function Signed-off-by: Steven Barth <steven@midlink.org> SVN-Revision: 46075
Diffstat (limited to 'toolchain/musl')
-rw-r--r--toolchain/musl/patches/001-git-2015-06-20.patch (renamed from toolchain/musl/patches/001-git-2015-06-16.patch)836
1 files changed, 763 insertions, 73 deletions
diff --git a/toolchain/musl/patches/001-git-2015-06-16.patch b/toolchain/musl/patches/001-git-2015-06-20.patch
index 5941adc320..33768a59d8 100644
--- a/toolchain/musl/patches/001-git-2015-06-16.patch
+++ b/toolchain/musl/patches/001-git-2015-06-20.patch
@@ -1,17 +1,125 @@
+From bafa38541e911806b74a1ab094a404bbdd692ade Mon Sep 17 00:00:00 2001
+From: Steven Barth <steven@midlink.org>
+Date: Sat, 20 Jun 2015 16:59:48 +0200
+Subject: [PATCH] commit 55d061f031085f24d138664c897791aebe9a2fab Author: Rich
+ Felker <dalias@aerifal.cx> Date: Sat Jun 20 03:01:07 2015 +0000
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+ provide __stack_chk_fail_local in libc.a
+
+ this symbol is needed only on archs where the PLT call ABI is klunky,
+ and only for position-independent code compiled with stack protector.
+ thus references usually only appear in shared libraries or PIE
+ executables, but they can also appear when linking statically if some
+ of the object files being linked were built as PIC/PIE.
+
+ normally libssp_nonshared.a from the compiler toolchain should provide
+ __stack_chk_fail_local, but reportedly it appears prior to -lc in the
+ link order, thus failing to satisfy references from libc itself (which
+ arise only if libc.a was built as PIC/PIE with stack protector
+ enabled).
+
+commit ce3688eca920aa77549323f84e21f33522397115
+Author: Rich Felker <dalias@aerifal.cx>
+Date: Sat Jun 20 02:54:30 2015 +0000
+
+ work around mips detached thread exit breakage due to kernel regression
+
+ linux kernel commit 46e12c07b3b9603c60fc1d421ff18618241cb081 caused
+ the mips syscall mechanism to fail with EFAULT when the userspace
+ stack pointer is invalid, breaking __unmapself used for detached
+ thread exit. the workaround is to set $sp to a known-valid, readable
+ address, and the simplest one to obtain is the address of the current
+ function, which is available (per o32 calling convention) in $25.
+
+commit 75eceb3ae824d54e865686c0c538551aeebf3372
+Author: Rich Felker <dalias@aerifal.cx>
+Date: Wed Jun 17 17:21:46 2015 +0000
+
+ ignore ENOSYS error from mprotect in pthread_create and dynamic linker
+
+ this error simply indicated a system without memory protection (NOMMU)
+ and should not cause failure in the caller.
+
+commit 10d0268ccfab9152250eeeed3952ce3fed44131a
+Author: Rich Felker <dalias@aerifal.cx>
+Date: Tue Jun 16 15:25:02 2015 +0000
+
+ switch to using trap number 31 for syscalls on sh
+
+ nominally the low bits of the trap number on sh are the number of
+ syscall arguments, but they have never been used by the kernel, and
+ some code making syscalls does not even know the number of arguments
+ and needs to pass an arbitrary high number anyway.
+
+ sh3/sh4 traditionally used the trap range 16-31 for syscalls, but part
+ of this range overlapped with hardware exceptions/interrupts on sh2
+ hardware, so an incompatible range 32-47 was chosen for sh2.
+
+ using trap number 31 everywhere, since it's in the existing sh3/sh4
+ range and does not conflict with sh2 hardware, is a proposed
+ unification of the kernel syscall convention that will allow binaries
+ to be shared between sh2 and sh3/sh4. if this is not accepted into the
+ kernel, we can refit the sh2 target with runtime selection mechanisms
+ for the trap number, but doing so would be invasive and would entail
+ non-trivial overhead.
+
+commit 3366a99b17847b58f2d8cc52cbb5d65deb824f8a
+Author: Rich Felker <dalias@aerifal.cx>
+Date: Tue Jun 16 14:55:06 2015 +0000
+
+ switch sh port's __unmapself to generic version when running on sh2/nommu
+
+ due to the way the interrupt and syscall trap mechanism works,
+ userspace on sh2 must never set the stack pointer to an invalid value.
+ thus, the approach used on most archs, where __unmapself executes with
+ no stack for the interval between SYS_munmap and SYS_exit, is not
+ viable on sh2.
+
+ in order not to pessimize sh3/sh4, the sh asm version of __unmapself
+ is not removed. instead it's renamed and redirected through code that
+ calls either the generic (safe) __unmapself or the sh3/sh4 asm,
+ depending on compile-time and run-time conditions.
+
+commit f9d84554bae0fa17c9a1d724549c4408022228a5
+Author: Rich Felker <dalias@aerifal.cx>
+Date: Tue Jun 16 14:28:30 2015 +0000
+
+ add support for sh2 interrupt-masking-based atomics to sh port
+
+ the sh2 target is being considered an ISA subset of sh3/sh4, in the
+ sense that binaries built for sh2 are intended to be usable on later
+ cpu models/kernels with mmu support. so rather than hard-coding
+ sh2-specific atomics, the runtime atomic selection mechanisms that was
+ already in place has been extended to add sh2 atomics.
+
+ at this time, the sh2 atomics are not SMP-compatible; since the ISA
+ lacks actual atomic operations, the new code instead masks interrupts
+ for the duration of the atomic operation, producing an atomic result
+ on single-core. this is only possible because the kernel/hardware does
+ not impose protections against userspace doing so. additional changes
+ will be needed to support future SMP systems.
+
+ care has been taken to avoid producing significant additional code
+ size in the case where it's known at compile-time that the target is
+ not sh2 and does not need sh2-specific code.
+
commit 1b0cdc8700d29ef018bf226d74b2b58b23bce91c
Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 16 07:11:19 2015 +0000
refactor stdio open file list handling, move it out of global libc struct
-
+
functions which open in-memory FILE stream variants all shared a tail
with __fdopen, adding the FILE structure to stdio's open file list.
replacing this common tail with a function call reduces code size and
duplication of logic. the list is also partially encapsulated now.
-
+
function signatures were chosen to facilitate tail call optimization
and reduce the need for additional accessor functions.
-
+
with these changes, static linked programs that do not use stdio no
longer have an open file list at all.
@@ -20,7 +128,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 16 06:18:00 2015 +0000
byte-based C locale, phase 3: make MB_CUR_MAX variable to activate code
-
+
this patch activates the new byte-based C locale (high bytes treated
as abstract code unit "characters" rather than decoded as multibyte
characters) by making the value of MB_CUR_MAX depend on the active
@@ -32,25 +140,25 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 16 05:35:31 2015 +0000
byte-based C locale, phase 2: stdio and iconv (multibyte callers)
-
+
this patch adjusts libc components which use the multibyte functions
internally, and which depend on them operating in a particular
encoding, to make the appropriate locale changes before calling them
and restore the calling thread's locale afterwards. activating the
byte-based C locale without these changes would cause regressions in
stdio and iconv.
-
+
in the case of iconv, the current implementation was simply using the
multibyte functions as UTF-8 conversions. setting a multibyte UTF-8
locale for the duration of the iconv operation allows the code to
continue working.
-
+
in the case of stdio, POSIX requires that FILE streams have an
encoding rule bound at the time of setting wide orientation. as long
as all locales, including the C locale, used the same encoding,
treating high bytes as UTF-8, there was no need to store an encoding
rule as part of the stream's state.
-
+
a new locale field in the FILE structure points to the locale that
should be made active during fgetwc/fputwc/ungetwc on the stream. it
cannot point to the locale active at the time the stream becomes
@@ -66,14 +174,14 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 16 04:44:17 2015 +0000
byte-based C locale, phase 1: multibyte character handling functions
-
+
this patch makes the functions which work directly on multibyte
characters treat the high bytes as individual abstract code units
rather than as multibyte sequences when MB_CUR_MAX is 1. since
MB_CUR_MAX is presently defined as a constant 4, all of the new code
added is dead code, and optimizing compilers' code generation should
not be affected at all. a future commit will activate the new code.
-
+
as abstract code units, bytes 0x80 to 0xff are represented by wchar_t
values 0xdf80 to 0xdfff, at the end of the surrogates range. this
ensures that they will never be misinterpreted as Unicode characters,
@@ -88,7 +196,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 16 04:21:38 2015 +0000
fix btowc corner case
-
+
btowc is required to interpret its argument by conversion to unsigned
char, unless the argument is equal to EOF. since the conversion to
produces a non-character value anyway, we can just unconditionally
@@ -99,7 +207,7 @@ Author: Szabolcs Nagy <nsz@port70.net>
Date: Wed Jun 3 10:32:14 2015 +0100
arm: add vdso support
-
+
vdso will be available on arm in linux v4.2, the user-space code
for it is in kernel commit 8512287a8165592466cb9cb347ba94892e9c56a5
@@ -108,16 +216,16 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sun Jun 14 01:59:02 2015 +0000
refactor malloc's expand_heap to share with __simple_malloc
-
+
this extends the brk/stack collision protection added to full malloc
in commit 276904c2f6bde3a31a24ebfa201482601d18b4f9 to also protect the
__simple_malloc function used in static-linked programs that don't
reference the free function.
-
+
it also extends support for using mmap when brk fails, which full
malloc got in commit 5446303328adf4b4e36d9fba21848e6feb55fab4, to
__simple_malloc.
-
+
since __simple_malloc may expand the heap by arbitrarily large
increments, the stack collision detection is enhanced to detect
interval overlap rather than just proximity of a single address to the
@@ -131,7 +239,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sat Jun 13 20:53:02 2015 +0000
remove cancellation points in stdio
-
+
commit 58165923890865a6ac042fafce13f440ee986fd9 added these optional
cancellation points on the basis that cancellable stdio could be
useful, to unblock threads stuck on stdio operations that will never
@@ -140,7 +248,7 @@ Date: Sat Jun 13 20:53:02 2015 +0000
cancellation is acted upon, discarding knowledge of any partial data
transfer already completed. our implementation exhibited this behavior
and was thus non-conforming.
-
+
in addition to improving correctness, removing these cancellation
points moderately reduces code size, and should significantly improve
performance on i386, where sysenter/syscall instructions can be used
@@ -151,7 +259,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sat Jun 13 05:17:16 2015 +0000
fix idiom for setting stdio stream orientation to wide
-
+
the old idiom, f->mode |= f->mode+1, was adapted from the idiom for
setting byte orientation, f->mode |= f->mode-1, but the adaptation was
incorrect. unless the stream was alreasdy set byte-oriented, this code
@@ -167,7 +275,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sat Jun 13 04:42:38 2015 +0000
add printing of null %s arguments as "(null)" in wide printf
-
+
this is undefined, but supported in our implementation of the normal
printf, so for consistency the wide variant should support it too.
@@ -188,11 +296,11 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Wed Jun 10 02:27:40 2015 +0000
implement arch-generic version of __unmapself
-
+
this can be used to put off writing an asm version of __unmapself for
new archs, or as a permanent solution on archs where it's not
practical or even possible to run momentarily with no stack.
-
+
the concept here is simple: the caller takes a lock on a global shared
stack and uses it to make the munmap and exit syscalls. the only trick
is unlocking, which must be done after the thread exits, and this is
@@ -204,14 +312,14 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 9 20:30:35 2015 +0000
in malloc, refuse to use brk if it grows into stack
-
+
the linux/nommu fdpic ELF loader sets up the brk range to overlap
entirely with the main thread's stack (but growing from opposite
ends), so that the resulting failure mode for malloc is not to return
a null pointer but to start returning pointers to memory that overlaps
with the caller's stack. needless to say this extremely dangerous and
makes brk unusable.
-
+
since it's non-trivial to detect execution environments that might be
affected by this kernel bug, and since the severity of the bug makes
any sort of detection that might yield false-negatives unsafe, we
@@ -221,7 +329,7 @@ Date: Tue Jun 9 20:30:35 2015 +0000
arbitrary gap distance of 8 MB is imposed, chosen to be larger than
linux default main-thread stack reservation sizes and larger than any
reasonable stack configuration on nommu.
-
+
the effeciveness of this patch relies on an assumption that the amount
by which the brk is being grown is smaller than the gap limit, which
is always true for malloc's use of brk. reliance on this assumption is
@@ -232,14 +340,14 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jun 9 20:09:27 2015 +0000
fix spurious errors from pwd/grp functions when nscd backend is absent
-
+
for several pwd/grp functions, the only way the caller can distinguish
between a successful negative result ("no such user/group") and an
internal error is by clearing errno before the call and checking errno
afterwards. the nscd backend support code correctly simulated a
not-found response on systems where such a backend is not running, but
failed to restore errno.
-
+
this commit also fixed an outdated/incorrect comment.
commit 75ce4503950621b11fcc7f1fd1187dbcf3cde312
@@ -247,7 +355,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sun Jun 7 20:55:23 2015 +0000
fix regression in pre-v7 arm on kernels with kuser helper removed
-
+
the arm atomics/TLS runtime selection code is called from
__set_thread_area and depends on having libc.auxv and __hwcap
available. commit 71f099cb7db821c51d8f39dfac622c61e54d794c moved the
@@ -255,9 +363,9 @@ Date: Sun Jun 7 20:55:23 2015 +0000
before this data is made available, causing the runtime detection code
to always see __hwcap as zero and thereby select the atomics/TLS
implementations based on kuser helper.
-
+
upcoming work on superh will use similar runtime detection.
-
+
ideally this early-init code should be cleanly refactored and shared
between the dynamic linker and static-linked startup.
@@ -272,7 +380,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sun Jun 7 02:59:49 2015 +0000
remove redefinition of MB_CUR_MAX in locale_impl.h
-
+
unless/until the byte-based C locale is implemented, defining
MB_CUR_MAX to 1 in the C locale is wrong. no internal code currently
uses the MB_CUR_MAX macro, but having it defined inconsistently is
@@ -296,7 +404,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sat Jun 6 18:16:22 2015 +0000
add macro version of ctype.h isascii function
-
+
presumably internal code (ungetwc and fputwc) was written assuming a
macro implementation existed; otherwise use of isascii is just a
pessimization.
@@ -306,7 +414,7 @@ Author: Rich Felker <dalias@aerifal.cx>
Date: Sat Jun 6 18:11:17 2015 +0000
remove invalid skip of locking in ungetwc
-
+
aside from being invalid, the early check only optimized the error
case, and likely pessimized the common case by separating the
two branches on isascii(c) at opposite ends of the function.
@@ -316,13 +424,88 @@ Author: Timo Teräs <timo.teras@iki.fi>
Date: Fri Jun 5 10:39:42 2015 +0300
fix uselocale((locale_t)0) not to modify locale
-
+
commit 68630b55c0c7219fe9df70dc28ffbf9efc8021d8 made the new locale to
be assigned unconditonally resulting in crashes later on.
+---
+ arch/arm/syscall_arch.h | 4 ++
+ arch/sh/src/__set_thread_area.c | 34 ++++++++++++++++
+ arch/sh/src/__unmapself.c | 19 +++++++++
+ arch/sh/src/atomic.c | 72 ++++++++++++++++++++++++++++++----
+ arch/sh/src/sh_atomic.h | 15 +++++++
+ arch/sh/syscall_arch.h | 2 +-
+ include/ctype.h | 1 +
+ include/stdlib.h | 3 +-
+ src/ctype/__ctype_get_mb_cur_max.c | 5 ++-
+ src/ctype/isascii.c | 1 +
+ src/env/__stack_chk_fail.c | 4 ++
+ src/internal/libc.h | 2 -
+ src/internal/locale_impl.h | 12 ++++++
+ src/internal/sh/syscall.s | 2 +-
+ src/internal/stdio_impl.h | 6 ++-
+ src/ldso/dynlink.c | 37 +++++++++---------
+ src/locale/c_locale.c | 15 +++++++
+ src/locale/iconv.c | 6 +++
+ src/locale/langinfo.c | 3 +-
+ src/locale/locale_map.c | 12 +-----
+ src/locale/newlocale.c | 15 ++-----
+ src/locale/uselocale.c | 4 +-
+ src/malloc/expand_heap.c | 72 ++++++++++++++++++++++++++++++++++
+ src/malloc/lite_malloc.c | 49 ++++++++++++-----------
+ src/malloc/malloc.c | 80 ++++++++++++++------------------------
+ src/multibyte/btowc.c | 5 ++-
+ src/multibyte/internal.h | 7 ++++
+ src/multibyte/mbrtowc.c | 2 +
+ src/multibyte/mbsrtowcs.c | 19 +++++++++
+ src/multibyte/mbtowc.c | 2 +
+ src/multibyte/wcrtomb.c | 9 +++++
+ src/multibyte/wctob.c | 4 +-
+ src/passwd/nscd_query.c | 12 ++++--
+ src/process/sh/vfork.s | 23 +++++++++++
+ src/regex/fnmatch.c | 3 +-
+ src/signal/sh/restore.s | 4 +-
+ src/stdio/__fdopen.c | 8 +---
+ src/stdio/__stdio_exit.c | 3 +-
+ src/stdio/__stdio_read.c | 11 +-----
+ src/stdio/__stdio_write.c | 14 +------
+ src/stdio/fclose.c | 6 +--
+ src/stdio/fflush.c | 5 +--
+ src/stdio/fgetwc.c | 15 +++++--
+ src/stdio/fmemopen.c | 8 +---
+ src/stdio/fopen.c | 2 +-
+ src/stdio/fputwc.c | 7 +++-
+ src/stdio/fputws.c | 7 +++-
+ src/stdio/fwide.c | 11 +++---
+ src/stdio/ofl.c | 16 ++++++++
+ src/stdio/ofl_add.c | 11 ++++++
+ src/stdio/open_memstream.c | 8 +---
+ src/stdio/open_wmemstream.c | 8 +---
+ src/stdio/ungetwc.c | 18 ++++-----
+ src/stdio/vfwprintf.c | 5 ++-
+ src/stdio/vfwscanf.c | 2 +-
+ src/thread/__unmapself.c | 29 ++++++++++++++
+ src/thread/mips/__unmapself.s | 1 +
+ src/thread/pthread_create.c | 6 ++-
+ src/thread/sh/__set_thread_area.s | 6 ---
+ src/thread/sh/__unmapself.s | 10 ++---
+ src/thread/sh/clone.s | 4 +-
+ src/thread/sh/syscall_cp.s | 2 +-
+ src/unistd/sh/pipe.s | 2 +-
+ 63 files changed, 548 insertions(+), 242 deletions(-)
+ create mode 100644 arch/sh/src/__set_thread_area.c
+ create mode 100644 arch/sh/src/__unmapself.c
+ create mode 100644 arch/sh/src/sh_atomic.h
+ create mode 100644 src/locale/c_locale.c
+ create mode 100644 src/malloc/expand_heap.c
+ create mode 100644 src/process/sh/vfork.s
+ create mode 100644 src/stdio/ofl.c
+ create mode 100644 src/stdio/ofl_add.c
+diff --git a/arch/arm/syscall_arch.h b/arch/arm/syscall_arch.h
+index 199ad2a..64461ec 100644
--- a/arch/arm/syscall_arch.h
+++ b/arch/arm/syscall_arch.h
-@@ -72,3 +72,7 @@ static inline long __syscall6(long n, lo
+@@ -72,3 +72,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
register long r5 __asm__("r5") = f;
__asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5));
}
@@ -330,6 +513,236 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+#define VDSO_USEFUL
+#define VDSO_CGT_SYM "__vdso_clock_gettime"
+#define VDSO_CGT_VER "LINUX_2.6"
+diff --git a/arch/sh/src/__set_thread_area.c b/arch/sh/src/__set_thread_area.c
+new file mode 100644
+index 0000000..1d3e022
+--- /dev/null
++++ b/arch/sh/src/__set_thread_area.c
+@@ -0,0 +1,34 @@
++#include "pthread_impl.h"
++#include "libc.h"
++#include "sh_atomic.h"
++#include <elf.h>
++
++/* Also perform sh-specific init */
++
++#define CPU_HAS_LLSC 0x0040
++
++__attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model, __sh_nommu;
++
++int __set_thread_area(void *p)
++{
++ size_t *aux;
++ __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
++#ifndef __SH4A__
++ if (__hwcap & CPU_HAS_LLSC) {
++ __sh_atomic_model = SH_A_LLSC;
++ return 0;
++ }
++#if !defined(__SH3__) && !defined(__SH4__)
++ for (aux=libc.auxv; *aux; aux+=2) {
++ if (*aux != AT_PLATFORM) continue;
++ const char *s = (void *)aux[1];
++ if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
++ __sh_atomic_model = SH_A_IMASK;
++ __sh_nommu = 1;
++ return 0;
++ }
++#endif
++ /* __sh_atomic_model = SH_A_GUSA; */ /* 0, default */
++#endif
++ return 0;
++}
+diff --git a/arch/sh/src/__unmapself.c b/arch/sh/src/__unmapself.c
+new file mode 100644
+index 0000000..4df9e7b
+--- /dev/null
++++ b/arch/sh/src/__unmapself.c
+@@ -0,0 +1,19 @@
++#include "pthread_impl.h"
++
++void __unmapself_sh_mmu(void *, size_t);
++void __unmapself_sh_nommu(void *, size_t);
++
++#if !defined(__SH3__) && !defined(__SH4__)
++#define __unmapself __unmapself_sh_nommu
++#include "../../../src/thread/__unmapself.c"
++#undef __unmapself
++extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
++#else
++#define __sh_nommu 0
++#endif
++
++void __unmapself(void *base, size_t size)
++{
++ if (__sh_nommu) __unmapself_sh_nommu(base, size);
++ else __unmapself_sh_mmu(base, size);
++}
+diff --git a/arch/sh/src/atomic.c b/arch/sh/src/atomic.c
+index f8c615f..7fd7307 100644
+--- a/arch/sh/src/atomic.c
++++ b/arch/sh/src/atomic.c
+@@ -1,8 +1,26 @@
+ #ifndef __SH4A__
+
++#include "sh_atomic.h"
+ #include "atomic.h"
+ #include "libc.h"
+
++static inline unsigned mask()
++{
++ unsigned sr;
++ __asm__ __volatile__ ( "\n"
++ " stc sr,r0 \n"
++ " mov r0,%0 \n"
++ " or #0xf0,r0 \n"
++ " ldc r0,sr \n"
++ : "=&r"(sr) : : "memory", "r0" );
++ return sr;
++}
++
++static inline void unmask(unsigned sr)
++{
++ __asm__ __volatile__ ( "ldc %0,sr" : : "r"(sr) : "memory" );
++}
++
+ /* gusa is a hack in the kernel which lets you create a sequence of instructions
+ * which will be restarted if the process is preempted in the middle of the
+ * sequence. It will do for implementing atomics on non-smp systems. ABI is:
+@@ -25,11 +43,17 @@
+ " mov.l " new ", @" mem "\n" \
+ "1: mov r1, r15\n"
+
+-#define CPU_HAS_LLSC 0x0040
+-
+ int __sh_cas(volatile int *p, int t, int s)
+ {
+- if (__hwcap & CPU_HAS_LLSC) return __sh_cas_llsc(p, t, s);
++ if (__sh_atomic_model == SH_A_LLSC) return __sh_cas_llsc(p, t, s);
++
++ if (__sh_atomic_model == SH_A_IMASK) {
++ unsigned sr = mask();
++ int old = *p;
++ if (old==t) *p = s;
++ unmask(sr);
++ return old;
++ }
+
+ int old;
+ __asm__ __volatile__(
+@@ -43,7 +67,15 @@ int __sh_cas(volatile int *p, int t, int s)
+
+ int __sh_swap(volatile int *x, int v)
+ {
+- if (__hwcap & CPU_HAS_LLSC) return __sh_swap_llsc(x, v);
++ if (__sh_atomic_model == SH_A_LLSC) return __sh_swap_llsc(x, v);
++
++ if (__sh_atomic_model == SH_A_IMASK) {
++ unsigned sr = mask();
++ int old = *x;
++ *x = v;
++ unmask(sr);
++ return old;
++ }
+
+ int old;
+ __asm__ __volatile__(
+@@ -55,7 +87,15 @@ int __sh_swap(volatile int *x, int v)
+
+ int __sh_fetch_add(volatile int *x, int v)
+ {
+- if (__hwcap & CPU_HAS_LLSC) return __sh_fetch_add_llsc(x, v);
++ if (__sh_atomic_model == SH_A_LLSC) return __sh_fetch_add_llsc(x, v);
++
++ if (__sh_atomic_model == SH_A_IMASK) {
++ unsigned sr = mask();
++ int old = *x;
++ *x = old + v;
++ unmask(sr);
++ return old;
++ }
+
+ int old, dummy;
+ __asm__ __volatile__(
+@@ -69,7 +109,7 @@ int __sh_fetch_add(volatile int *x, int v)
+
+ void __sh_store(volatile int *p, int x)
+ {
+- if (__hwcap & CPU_HAS_LLSC) return __sh_store_llsc(p, x);
++ if (__sh_atomic_model == SH_A_LLSC) return __sh_store_llsc(p, x);
+ __asm__ __volatile__(
+ " mov.l %1, @%0\n"
+ : : "r"(p), "r"(x) : "memory");
+@@ -77,7 +117,15 @@ void __sh_store(volatile int *p, int x)
+
+ void __sh_and(volatile int *x, int v)
+ {
+- if (__hwcap & CPU_HAS_LLSC) return __sh_and_llsc(x, v);
++ if (__sh_atomic_model == SH_A_LLSC) return __sh_and_llsc(x, v);
++
++ if (__sh_atomic_model == SH_A_IMASK) {
++ unsigned sr = mask();
++ int old = *x;
++ *x = old & v;
++ unmask(sr);
++ return;
++ }
+
+ int dummy;
+ __asm__ __volatile__(
+@@ -89,7 +137,15 @@ void __sh_and(volatile int *x, int v)
+
+ void __sh_or(volatile int *x, int v)
+ {
+- if (__hwcap & CPU_HAS_LLSC) return __sh_or_llsc(x, v);
++ if (__sh_atomic_model == SH_A_LLSC) return __sh_or_llsc(x, v);
++
++ if (__sh_atomic_model == SH_A_IMASK) {
++ unsigned sr = mask();
++ int old = *x;
++ *x = old | v;
++ unmask(sr);
++ return;
++ }
+
+ int dummy;
+ __asm__ __volatile__(
+diff --git a/arch/sh/src/sh_atomic.h b/arch/sh/src/sh_atomic.h
+new file mode 100644
+index 0000000..054c2a3
+--- /dev/null
++++ b/arch/sh/src/sh_atomic.h
+@@ -0,0 +1,15 @@
++#ifndef _SH_ATOMIC_H
++#define _SH_ATOMIC_H
++
++#define SH_A_GUSA 0
++#define SH_A_LLSC 1
++#define SH_A_CAS 2
++#if !defined(__SH3__) && !defined(__SH4__)
++#define SH_A_IMASK 3
++#else
++#define SH_A_IMASK -1LL /* unmatchable by unsigned int */
++#endif
++
++extern __attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model;
++
++#endif
+diff --git a/arch/sh/syscall_arch.h b/arch/sh/syscall_arch.h
+index 7ee21a5..f63675a 100644
+--- a/arch/sh/syscall_arch.h
++++ b/arch/sh/syscall_arch.h
+@@ -8,7 +8,7 @@
+ */
+ #define __asm_syscall(trapno, ...) do { \
+ __asm__ __volatile__ ( \
+- "trapa #" #trapno "\n" \
++ "trapa #31\n" \
+ "or r0, r0\n" \
+ "or r0, r0\n" \
+ "or r0, r0\n" \
+diff --git a/include/ctype.h b/include/ctype.h
+index cd2e016..7936536 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -64,6 +64,7 @@ int isascii(int);
@@ -340,9 +753,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#endif
+diff --git a/include/stdlib.h b/include/stdlib.h
+index 97ce5a7..d2c911f 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
-@@ -76,7 +76,8 @@ size_t wcstombs (char *__restrict, const
+@@ -76,7 +76,8 @@ size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
@@ -352,6 +767,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#define RAND_MAX (0x7fffffff)
+diff --git a/src/ctype/__ctype_get_mb_cur_max.c b/src/ctype/__ctype_get_mb_cur_max.c
+index d235f4d..8e946fc 100644
--- a/src/ctype/__ctype_get_mb_cur_max.c
+++ b/src/ctype/__ctype_get_mb_cur_max.c
@@ -1,6 +1,7 @@
@@ -364,6 +781,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
- return 4;
+ return MB_CUR_MAX;
}
+diff --git a/src/ctype/isascii.c b/src/ctype/isascii.c
+index 3af0a10..54ad3bf 100644
--- a/src/ctype/isascii.c
+++ b/src/ctype/isascii.c
@@ -1,4 +1,5 @@
@@ -372,6 +791,21 @@ Date: Fri Jun 5 10:39:42 2015 +0300
int isascii(int c)
{
+diff --git a/src/env/__stack_chk_fail.c b/src/env/__stack_chk_fail.c
+index 47784c6..be0c184 100644
+--- a/src/env/__stack_chk_fail.c
++++ b/src/env/__stack_chk_fail.c
+@@ -25,4 +25,8 @@ void __stack_chk_fail_local(void)
+ a_crash();
+ }
+
++#else
++
++weak_alias(__stack_chk_fail, __stack_chk_fail_local);
++
+ #endif
+diff --git a/src/internal/libc.h b/src/internal/libc.h
+index 6810cd8..98c7535 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -17,8 +17,6 @@ struct __libc {
@@ -383,6 +817,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
size_t tls_size;
size_t page_size;
struct __locale_struct global_locale;
+diff --git a/src/internal/locale_impl.h b/src/internal/locale_impl.h
+index 9b8385e..f5e4d9b 100644
--- a/src/internal/locale_impl.h
+++ b/src/internal/locale_impl.h
@@ -1,3 +1,6 @@
@@ -418,6 +854,21 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1)
+
+#endif
+diff --git a/src/internal/sh/syscall.s b/src/internal/sh/syscall.s
+index d00712a..331918a 100644
+--- a/src/internal/sh/syscall.s
++++ b/src/internal/sh/syscall.s
+@@ -13,7 +13,7 @@ __syscall:
+ mov.l @r15, r7
+ mov.l @(4,r15), r0
+ mov.l @(8,r15), r1
+- trapa #22
++ trapa #31
+ or r0, r0
+ or r0, r0
+ or r0, r0
+diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h
+index e1325fe..0dd7fb5 100644
--- a/src/internal/stdio_impl.h
+++ b/src/internal/stdio_impl.h
@@ -47,6 +47,7 @@ struct _IO_FILE {
@@ -440,9 +891,31 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#define feof(f) ((f)->flags & F_EOF)
#define ferror(f) ((f)->flags & F_ERR)
+diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
+index 42b056d..7e56693 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
-@@ -1192,6 +1192,17 @@ _Noreturn void __dls3(size_t *sp)
+@@ -536,7 +536,8 @@ static void *map_library(int fd, struct dso *dso)
+ }
+ for (i=0; ((size_t *)(base+dyn))[i]; i+=2)
+ if (((size_t *)(base+dyn))[i]==DT_TEXTREL) {
+- if (mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC) < 0)
++ if (mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC)
++ && errno != ENOSYS)
+ goto error;
+ break;
+ }
+@@ -927,7 +928,8 @@ static void reloc_all(struct dso *p)
+ do_relocs(p, (void *)(p->base+dyn[DT_RELA]), dyn[DT_RELASZ], 3);
+
+ if (head != &ldso && p->relro_start != p->relro_end &&
+- mprotect(p->base+p->relro_start, p->relro_end-p->relro_start, PROT_READ) < 0) {
++ mprotect(p->base+p->relro_start, p->relro_end-p->relro_start, PROT_READ)
++ && errno != ENOSYS) {
+ error("Error relocating %s: RELRO protection failed: %m",
+ p->name);
+ if (runtime) longjmp(*rtld_fail, 1);
+@@ -1192,6 +1194,17 @@ _Noreturn void __dls3(size_t *sp)
char **argv_orig = argv;
char **envp = argv+argc+1;
@@ -460,7 +933,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
/* Setup early thread pointer in builtin_tls for ldso/libc itself to
* use during dynamic linking. If possible it will also serve as the
* thread pointer at runtime. */
-@@ -1200,25 +1211,11 @@ _Noreturn void __dls3(size_t *sp)
+@@ -1200,25 +1213,11 @@ _Noreturn void __dls3(size_t *sp)
a_crash();
}
@@ -489,6 +962,9 @@ Date: Fri Jun 5 10:39:42 2015 +0300
/* If the main program was already loaded by the kernel,
* AT_PHDR will point to some location other than the dynamic
+diff --git a/src/locale/c_locale.c b/src/locale/c_locale.c
+new file mode 100644
+index 0000000..77ccf58
--- /dev/null
+++ b/src/locale/c_locale.c
@@ -0,0 +1,15 @@
@@ -507,6 +983,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+const struct __locale_struct __c_dot_utf8_locale = {
+ .cat[LC_CTYPE] = &__c_dot_utf8
+};
+diff --git a/src/locale/iconv.c b/src/locale/iconv.c
+index e6121ae..1eeea94 100644
--- a/src/locale/iconv.c
+++ b/src/locale/iconv.c
@@ -5,6 +5,7 @@
@@ -517,7 +995,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#define UTF_32BE 0300
#define UTF_16LE 0301
-@@ -165,9 +166,12 @@ size_t iconv(iconv_t cd0, char **restric
+@@ -165,9 +166,12 @@ size_t iconv(iconv_t cd0, char **restrict in, size_t *restrict inb, char **restr
int err;
unsigned char type = map[-1];
unsigned char totype = tomap[-1];
@@ -530,7 +1008,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
for (; *inb; *in+=l, *inb-=l) {
c = *(unsigned char *)*in;
l = 1;
-@@ -431,6 +435,7 @@ size_t iconv(iconv_t cd0, char **restric
+@@ -431,6 +435,7 @@ size_t iconv(iconv_t cd0, char **restrict in, size_t *restrict inb, char **restr
break;
}
}
@@ -545,9 +1023,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ *ploc = loc;
return x;
}
+diff --git a/src/locale/langinfo.c b/src/locale/langinfo.c
+index a1ada24..776b447 100644
--- a/src/locale/langinfo.c
+++ b/src/locale/langinfo.c
-@@ -33,7 +33,8 @@ char *__nl_langinfo_l(nl_item item, loca
+@@ -33,7 +33,8 @@ char *__nl_langinfo_l(nl_item item, locale_t loc)
int idx = item & 65535;
const char *str;
@@ -557,6 +1037,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
switch (cat) {
case LC_NUMERIC:
+diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c
+index 4346bb0..c3e5917 100644
--- a/src/locale/locale_map.c
+++ b/src/locale/locale_map.c
@@ -24,14 +24,6 @@ static const char envvars[][12] = {
@@ -574,7 +1056,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
const struct __locale_map *__get_locale(int cat, const char *val)
{
static int lock[2];
-@@ -107,8 +99,8 @@ const struct __locale_map *__get_locale(
+@@ -107,8 +99,8 @@ const struct __locale_map *__get_locale(int cat, const char *val)
* sake of being able to do message translations at the
* application level. */
if (!new && (new = malloc(sizeof *new))) {
@@ -585,6 +1067,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
memcpy(new->name, val, n);
new->name[n] = 0;
new->next = loc_head;
+diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c
+index 89d36b1..f50bbe9 100644
--- a/src/locale/newlocale.c
+++ b/src/locale/newlocale.c
@@ -3,16 +3,9 @@
@@ -605,7 +1089,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
}
locale_t __newlocale(int mask, const char *name, locale_t loc)
-@@ -44,9 +37,9 @@ locale_t __newlocale(int mask, const cha
+@@ -44,9 +37,9 @@ locale_t __newlocale(int mask, const char *name, locale_t loc)
}
if (!j)
@@ -618,6 +1102,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if ((loc = malloc(sizeof *loc))) *loc = tmp;
+diff --git a/src/locale/uselocale.c b/src/locale/uselocale.c
+index b70a0c1..0fc5ecb 100644
--- a/src/locale/uselocale.c
+++ b/src/locale/uselocale.c
@@ -8,9 +8,7 @@ locale_t __uselocale(locale_t new)
@@ -631,6 +1117,9 @@ Date: Fri Jun 5 10:39:42 2015 +0300
return old == global ? LC_GLOBAL_LOCALE : old;
}
+diff --git a/src/malloc/expand_heap.c b/src/malloc/expand_heap.c
+new file mode 100644
+index 0000000..d8c0be7
--- /dev/null
+++ b/src/malloc/expand_heap.c
@@ -0,0 +1,72 @@
@@ -706,6 +1195,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ mmap_step++;
+ return area;
+}
+diff --git a/src/malloc/lite_malloc.c b/src/malloc/lite_malloc.c
+index 7643fc2..008549d 100644
--- a/src/malloc/lite_malloc.c
+++ b/src/malloc/lite_malloc.c
@@ -4,43 +4,46 @@
@@ -778,6 +1269,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
}
weak_alias(__simple_malloc, malloc);
+diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
+index d4de2dc..290fda1 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -13,7 +13,6 @@
@@ -827,23 +1320,17 @@ Date: Fri Jun 5 10:39:42 2015 +0300
- mal.brk = mal.brk + 2*SIZE_ALIGN-1 & -SIZE_ALIGN;
- mal.heap = (void *)mal.brk;
- init = 1;
+- }
+ /* The argument n already accounts for the caller's chunk
+ * overhead needs, but if the heap can't be extended in-place,
+ * we need room for an extra zero-sized sentinel chunk. */
+ n += SIZE_ALIGN;
-+
-+ lock(heap_lock);
-+
-+ p = __expand_heap(&n);
-+ if (!p) {
-+ unlock(heap_lock);
-+ return 0;
- }
- if (n > SIZE_MAX - mal.brk - 2*PAGE_SIZE) goto fail;
- new = mal.brk + n + SIZE_ALIGN + PAGE_SIZE - 1 & -PAGE_SIZE;
- n = new - mal.brk;
--
++ lock(heap_lock);
+
- if (__brk(new) != new) {
- size_t min = (size_t)PAGE_SIZE << mal.mmap_step/2;
- n += -n & PAGE_SIZE-1;
@@ -851,7 +1338,12 @@ Date: Fri Jun 5 10:39:42 2015 +0300
- void *area = __mmap(0, n, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (area == MAP_FAILED) goto fail;
--
++ p = __expand_heap(&n);
++ if (!p) {
++ unlock(heap_lock);
++ return 0;
++ }
+
- mal.mmap_step++;
- area = (char *)area + SIZE_ALIGN - OVERHEAD;
- w = area;
@@ -902,6 +1394,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
}
static int adjust_size(size_t *n)
+diff --git a/src/multibyte/btowc.c b/src/multibyte/btowc.c
+index 9d2c3b1..8acd0a2 100644
--- a/src/multibyte/btowc.c
+++ b/src/multibyte/btowc.c
@@ -1,7 +1,10 @@
@@ -916,6 +1410,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ int b = (unsigned char)c;
+ return b<128U ? b : (MB_CUR_MAX==1 && c!=EOF) ? CODEUNIT(c) : WEOF;
}
+diff --git a/src/multibyte/internal.h b/src/multibyte/internal.h
+index cc017fa..53d62ed 100644
--- a/src/multibyte/internal.h
+++ b/src/multibyte/internal.h
@@ -23,3 +23,10 @@ extern const uint32_t bittab[];
@@ -929,6 +1425,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+
+/* Get inline definition of MB_CUR_MAX. */
+#include "locale_impl.h"
+diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c
+index e7b3654..ca7da70 100644
--- a/src/multibyte/mbrtowc.c
+++ b/src/multibyte/mbrtowc.c
@@ -4,6 +4,7 @@
@@ -939,7 +1437,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#include <wchar.h>
#include <errno.h>
#include "internal.h"
-@@ -27,6 +28,7 @@ size_t mbrtowc(wchar_t *restrict wc, con
+@@ -27,6 +28,7 @@ size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate
if (!n) return -2;
if (!c) {
if (*s < 0x80) return !!(*wc = *s);
@@ -947,6 +1445,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (*s-SA > SB-SA) goto ilseq;
c = bittab[*s++-SA]; n--;
}
+diff --git a/src/multibyte/mbsrtowcs.c b/src/multibyte/mbsrtowcs.c
+index 3c1343a..e23083d 100644
--- a/src/multibyte/mbsrtowcs.c
+++ b/src/multibyte/mbsrtowcs.c
@@ -7,6 +7,8 @@
@@ -958,7 +1458,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#include "internal.h"
size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st)
-@@ -24,6 +26,23 @@ size_t mbsrtowcs(wchar_t *restrict ws, c
+@@ -24,6 +26,23 @@ size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbs
}
}
@@ -982,6 +1482,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (!ws) for (;;) {
if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) {
while (!(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) {
+diff --git a/src/multibyte/mbtowc.c b/src/multibyte/mbtowc.c
+index 803d221..71a9506 100644
--- a/src/multibyte/mbtowc.c
+++ b/src/multibyte/mbtowc.c
@@ -4,6 +4,7 @@
@@ -992,7 +1494,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#include <wchar.h>
#include <errno.h>
#include "internal.h"
-@@ -19,6 +20,7 @@ int mbtowc(wchar_t *restrict wc, const c
+@@ -19,6 +20,7 @@ int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n)
if (!wc) wc = &dummy;
if (*s < 0x80) return !!(*wc = *s);
@@ -1000,6 +1502,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (*s-SA > SB-SA) goto ilseq;
c = bittab[*s++-SA];
+diff --git a/src/multibyte/wcrtomb.c b/src/multibyte/wcrtomb.c
+index 59f733d..ddc37a5 100644
--- a/src/multibyte/wcrtomb.c
+++ b/src/multibyte/wcrtomb.c
@@ -4,8 +4,10 @@
@@ -1013,7 +1517,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st)
{
-@@ -13,6 +15,13 @@ size_t wcrtomb(char *restrict s, wchar_t
+@@ -13,6 +15,13 @@ size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st)
if ((unsigned)wc < 0x80) {
*s = wc;
return 1;
@@ -1027,6 +1531,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
} else if ((unsigned)wc < 0x800) {
*s++ = 0xc0 | (wc>>6);
*s = 0x80 | (wc&0x3f);
+diff --git a/src/multibyte/wctob.c b/src/multibyte/wctob.c
+index d6353ee..4aeda6a 100644
--- a/src/multibyte/wctob.c
+++ b/src/multibyte/wctob.c
@@ -1,8 +1,10 @@
@@ -1041,9 +1547,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ if (MB_CUR_MAX==1 && IS_CODEUNIT(c)) return (unsigned char)c;
return EOF;
}
+diff --git a/src/passwd/nscd_query.c b/src/passwd/nscd_query.c
+index 69a7815..d38e371 100644
--- a/src/passwd/nscd_query.c
+++ b/src/passwd/nscd_query.c
-@@ -32,6 +32,7 @@ FILE *__nscd_query(int32_t req, const ch
+@@ -32,6 +32,7 @@ FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *
},
.msg_iovlen = 2
};
@@ -1070,6 +1578,9 @@ Date: Fri Jun 5 10:39:42 2015 +0300
goto error;
}
+diff --git a/src/process/sh/vfork.s b/src/process/sh/vfork.s
+new file mode 100644
+index 0000000..48cc939
--- /dev/null
+++ b/src/process/sh/vfork.s
@@ -0,0 +1,23 @@
@@ -1082,7 +1593,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ mov #95, r3
+ add r3, r3
+
-+ trapa #16
++ trapa #31
+ or r0, r0
+ or r0, r0
+ or r0, r0
@@ -1096,6 +1607,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ .align 2
+ .hidden __syscall_ret
+1: .long __syscall_ret@PLT-(2b+4-.)
+diff --git a/src/regex/fnmatch.c b/src/regex/fnmatch.c
+index 7f6b65f..978fff8 100644
--- a/src/regex/fnmatch.c
+++ b/src/regex/fnmatch.c
@@ -18,6 +18,7 @@
@@ -1106,7 +1619,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#define END 0
#define UNMATCHABLE -2
-@@ -229,7 +230,7 @@ static int fnmatch_internal(const char *
+@@ -229,7 +230,7 @@ static int fnmatch_internal(const char *pat, size_t m, const char *str, size_t n
* On illegal sequences we may get it wrong, but in that case
* we necessarily have a matching failure anyway. */
for (s=endstr; s>str && tailcnt; tailcnt--) {
@@ -1115,6 +1628,30 @@ Date: Fri Jun 5 10:39:42 2015 +0300
else while ((unsigned char)*--s-0x80U<0x40 && s>str);
}
if (tailcnt) return FNM_NOMATCH;
+diff --git a/src/signal/sh/restore.s b/src/signal/sh/restore.s
+index ab26034..eaedcdf 100644
+--- a/src/signal/sh/restore.s
++++ b/src/signal/sh/restore.s
+@@ -2,7 +2,7 @@
+ .type __restore, @function
+ __restore:
+ mov #119, r3 !__NR_sigreturn
+- trapa #16
++ trapa #31
+
+ or r0, r0
+ or r0, r0
+@@ -15,7 +15,7 @@ __restore:
+ __restore_rt:
+ mov #100, r3 !__NR_rt_sigreturn
+ add #73, r3
+- trapa #16
++ trapa #31
+
+ or r0, r0
+ or r0, r0
+diff --git a/src/stdio/__fdopen.c b/src/stdio/__fdopen.c
+index ef8f47d..8d6ce81 100644
--- a/src/stdio/__fdopen.c
+++ b/src/stdio/__fdopen.c
@@ -54,13 +54,7 @@ FILE *__fdopen(int fd, const char *mode)
@@ -1132,6 +1669,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
}
weak_alias(__fdopen, fdopen);
+diff --git a/src/stdio/__stdio_exit.c b/src/stdio/__stdio_exit.c
+index 716e5f7..191b445 100644
--- a/src/stdio/__stdio_exit.c
+++ b/src/stdio/__stdio_exit.c
@@ -16,8 +16,7 @@ static void close_file(FILE *f)
@@ -1144,6 +1683,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
close_file(__stdin_used);
close_file(__stdout_used);
}
+diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c
+index 5947344..f8fa6d3 100644
--- a/src/stdio/__stdio_read.c
+++ b/src/stdio/__stdio_read.c
@@ -1,12 +1,5 @@
@@ -1159,7 +1700,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
{
-@@ -16,9 +9,7 @@ size_t __stdio_read(FILE *f, unsigned ch
+@@ -16,9 +9,7 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
};
ssize_t cnt;
@@ -1170,6 +1711,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (cnt <= 0) {
f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt);
return cnt;
+diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
+index 8c89389..d2d8947 100644
--- a/src/stdio/__stdio_write.c
+++ b/src/stdio/__stdio_write.c
@@ -1,12 +1,5 @@
@@ -1185,7 +1728,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
{
-@@ -19,9 +12,7 @@ size_t __stdio_write(FILE *f, const unsi
+@@ -19,9 +12,7 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
int iovcnt = 2;
ssize_t cnt;
for (;;) {
@@ -1196,7 +1739,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (cnt == rem) {
f->wend = f->buf + f->buf_size;
f->wpos = f->wbase = f->buf;
-@@ -34,11 +25,8 @@ size_t __stdio_write(FILE *f, const unsi
+@@ -34,11 +25,8 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
}
rem -= cnt;
if (cnt > iov[0].iov_len) {
@@ -1208,6 +1751,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
}
iov[0].iov_base = (char *)iov[0].iov_base + cnt;
iov[0].iov_len -= cnt;
+diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c
+index 317b3c9..839d88a 100644
--- a/src/stdio/fclose.c
+++ b/src/stdio/fclose.c
@@ -14,11 +14,11 @@ int fclose(FILE *f)
@@ -1225,6 +1770,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
}
r = fflush(f);
+diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
+index 7bf862a..3f462c8 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -35,13 +35,12 @@ int fflush(FILE *f)
@@ -1243,6 +1790,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
return r;
}
+diff --git a/src/stdio/fgetwc.c b/src/stdio/fgetwc.c
+index 8626d54..e455cfe 100644
--- a/src/stdio/fgetwc.c
+++ b/src/stdio/fgetwc.c
@@ -1,8 +1,9 @@
@@ -1282,9 +1831,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
wint_t fgetwc(FILE *f)
{
wint_t c;
+diff --git a/src/stdio/fmemopen.c b/src/stdio/fmemopen.c
+index d784960..7c193a5 100644
--- a/src/stdio/fmemopen.c
+++ b/src/stdio/fmemopen.c
-@@ -110,11 +110,5 @@ FILE *fmemopen(void *restrict buf, size_
+@@ -110,11 +110,5 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode)
if (!libc.threaded) f->lock = -1;
@@ -1297,9 +1848,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
- return f;
+ return __ofl_add(f);
}
+diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c
+index 07bdb6e..252f082 100644
--- a/src/stdio/fopen.c
+++ b/src/stdio/fopen.c
-@@ -18,7 +18,7 @@ FILE *fopen(const char *restrict filenam
+@@ -18,7 +18,7 @@ FILE *fopen(const char *restrict filename, const char *restrict mode)
/* Compute the flags to pass to open() */
flags = __fmodeflags(mode);
@@ -1308,6 +1861,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (fd < 0) return 0;
if (flags & O_CLOEXEC)
__syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC);
+diff --git a/src/stdio/fputwc.c b/src/stdio/fputwc.c
+index 7b621dd..789fe9c 100644
--- a/src/stdio/fputwc.c
+++ b/src/stdio/fputwc.c
@@ -1,4 +1,5 @@
@@ -1316,7 +1871,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
#include <wchar.h>
#include <limits.h>
#include <ctype.h>
-@@ -7,8 +8,10 @@ wint_t __fputwc_unlocked(wchar_t c, FILE
+@@ -7,8 +8,10 @@ wint_t __fputwc_unlocked(wchar_t c, FILE *f)
{
char mbc[MB_LEN_MAX];
int l;
@@ -1328,7 +1883,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
if (isascii(c)) {
c = putc_unlocked(c, f);
-@@ -20,6 +23,8 @@ wint_t __fputwc_unlocked(wchar_t c, FILE
+@@ -20,6 +23,8 @@ wint_t __fputwc_unlocked(wchar_t c, FILE *f)
l = wctomb(mbc, c);
if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF;
}
@@ -1337,6 +1892,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
return c;
}
+diff --git a/src/stdio/fputws.c b/src/stdio/fputws.c
+index 5723cbc..0ed02f1 100644
--- a/src/stdio/fputws.c
+++ b/src/stdio/fputws.c
@@ -1,23 +1,28 @@
@@ -1369,6 +1926,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
return l; /* 0 or -1 */
}
+diff --git a/src/stdio/fwide.c b/src/stdio/fwide.c
+index 8088e7a..8410b15 100644
--- a/src/stdio/fwide.c
+++ b/src/stdio/fwide.c
@@ -1,13 +1,14 @@
@@ -1391,6 +1950,9 @@ Date: Fri Jun 5 10:39:42 2015 +0300
mode = f->mode;
FUNLOCK(f);
return mode;
+diff --git a/src/stdio/ofl.c b/src/stdio/ofl.c
+new file mode 100644
+index 0000000..b143999
--- /dev/null
+++ b/src/stdio/ofl.c
@@ -0,0 +1,16 @@
@@ -1410,6 +1972,9 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+{
+ UNLOCK(ofl_lock);
+}
+diff --git a/src/stdio/ofl_add.c b/src/stdio/ofl_add.c
+new file mode 100644
+index 0000000..d7de9f1
--- /dev/null
+++ b/src/stdio/ofl_add.c
@@ -0,0 +1,11 @@
@@ -1424,9 +1989,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ __ofl_unlock();
+ return f;
+}
+diff --git a/src/stdio/open_memstream.c b/src/stdio/open_memstream.c
+index 9eafdfb..58504c9 100644
--- a/src/stdio/open_memstream.c
+++ b/src/stdio/open_memstream.c
-@@ -79,11 +79,5 @@ FILE *open_memstream(char **bufp, size_t
+@@ -79,11 +79,5 @@ FILE *open_memstream(char **bufp, size_t *sizep)
if (!libc.threaded) f->lock = -1;
@@ -1439,9 +2006,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
- return f;
+ return __ofl_add(f);
}
+diff --git a/src/stdio/open_wmemstream.c b/src/stdio/open_wmemstream.c
+index 3537030..7ab2c64 100644
--- a/src/stdio/open_wmemstream.c
+++ b/src/stdio/open_wmemstream.c
-@@ -81,11 +81,5 @@ FILE *open_wmemstream(wchar_t **bufp, si
+@@ -81,11 +81,5 @@ FILE *open_wmemstream(wchar_t **bufp, size_t *sizep)
if (!libc.threaded) f->lock = -1;
@@ -1454,6 +2023,8 @@ Date: Fri Jun 5 10:39:42 2015 +0300
- return f;
+ return __ofl_add(f);
}
+diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c
+index 913f716..80d6e20 100644
--- a/src/stdio/ungetwc.c
+++ b/src/stdio/ungetwc.c
@@ -1,4 +1,5 @@
@@ -1498,9 +2069,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ *ploc = loc;
return c;
}
+diff --git a/src/stdio/vfwprintf.c b/src/stdio/vfwprintf.c
+index ebdff00..f06d5ae 100644
--- a/src/stdio/vfwprintf.c
+++ b/src/stdio/vfwprintf.c
-@@ -293,7 +293,10 @@ static int wprintf_core(FILE *f, const w
+@@ -293,7 +293,10 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_
if ((fl&LEFT_ADJ)) fprintf(f, "%.*s", w-p, "");
l=w;
continue;
@@ -1511,7 +2084,7 @@ Date: Fri Jun 5 10:39:42 2015 +0300
bs = arg.p;
if (p<0) p = INT_MAX;
for (i=l=0; l<p && (i=mbtowc(&wc, bs, MB_LEN_MAX))>0; bs+=i, l++);
-@@ -356,7 +359,7 @@ int vfwprintf(FILE *restrict f, const wc
+@@ -356,7 +359,7 @@ int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
}
FLOCK(f);
@@ -1520,9 +2093,11 @@ Date: Fri Jun 5 10:39:42 2015 +0300
olderr = f->flags & F_ERR;
f->flags &= ~F_ERR;
ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type);
+diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c
+index ac5c2c2..223aad4 100644
--- a/src/stdio/vfwscanf.c
+++ b/src/stdio/vfwscanf.c
-@@ -104,7 +104,7 @@ int vfwscanf(FILE *restrict f, const wch
+@@ -104,7 +104,7 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
FLOCK(f);
@@ -1531,7 +2106,9 @@ Date: Fri Jun 5 10:39:42 2015 +0300
for (p=fmt; *p; p++) {
---- /dev/null
+diff --git a/src/thread/__unmapself.c b/src/thread/__unmapself.c
+index e69de29..1d3bee1 100644
+--- a/src/thread/__unmapself.c
+++ b/src/thread/__unmapself.c
@@ -0,0 +1,29 @@
+#include "pthread_impl.h"
@@ -1563,9 +2140,23 @@ Date: Fri Jun 5 10:39:42 2015 +0300
+ unmap_size = size;
+ CRTJMP(do_unmap, stack);
+}
+diff --git a/src/thread/mips/__unmapself.s b/src/thread/mips/__unmapself.s
+index 9aa0371..ba139dc 100644
+--- a/src/thread/mips/__unmapself.s
++++ b/src/thread/mips/__unmapself.s
+@@ -2,6 +2,7 @@
+ .global __unmapself
+ .type __unmapself,@function
+ __unmapself:
++ move $sp, $25
+ li $2, 4091
+ syscall
+ li $4, 0
+diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
+index de72818..e7df34a 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
-@@ -191,8 +191,9 @@ int __pthread_create(pthread_t *restrict
+@@ -191,8 +191,9 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
if (!libc.can_do_threads) return ENOSYS;
self = __pthread_self();
if (!libc.threaded) {
@@ -1576,3 +2167,102 @@ Date: Fri Jun 5 10:39:42 2015 +0300
init_file_lock(__stdin_used);
init_file_lock(__stdout_used);
init_file_lock(__stderr_used);
+@@ -231,7 +232,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
+ if (guard) {
+ map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
+ if (map == MAP_FAILED) goto fail;
+- if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)) {
++ if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)
++ && errno != ENOSYS) {
+ __munmap(map, size);
+ goto fail;
+ }
+diff --git a/src/thread/sh/__set_thread_area.s b/src/thread/sh/__set_thread_area.s
+index d9f1181..e69de29 100644
+--- a/src/thread/sh/__set_thread_area.s
++++ b/src/thread/sh/__set_thread_area.s
+@@ -1,6 +0,0 @@
+-.global __set_thread_area
+-.type __set_thread_area, @function
+-__set_thread_area:
+- ldc r4, gbr
+- rts
+- mov #0, r0
+diff --git a/src/thread/sh/__unmapself.s b/src/thread/sh/__unmapself.s
+index b34c3c8..0161d53 100644
+--- a/src/thread/sh/__unmapself.s
++++ b/src/thread/sh/__unmapself.s
+@@ -1,9 +1,9 @@
+ .text
+-.global __unmapself
+-.type __unmapself, @function
+-__unmapself:
++.global __unmapself_sh_mmu
++.type __unmapself_sh_mmu, @function
++__unmapself_sh_mmu:
+ mov #91, r3 ! SYS_munmap
+- trapa #18
++ trapa #31
+
+ or r0, r0
+ or r0, r0
+@@ -13,7 +13,7 @@ __unmapself:
+
+ mov #1, r3 ! SYS_exit
+ mov #0, r4
+- trapa #17
++ trapa #31
+
+ or r0, r0
+ or r0, r0
+diff --git a/src/thread/sh/clone.s b/src/thread/sh/clone.s
+index d6c9184..f8ad845 100644
+--- a/src/thread/sh/clone.s
++++ b/src/thread/sh/clone.s
+@@ -17,7 +17,7 @@ __clone:
+ mov.l @r15, r6 ! r6 = ptid
+ mov.l @(8,r15), r7 ! r7 = ctid
+ mov.l @(4,r15), r0 ! r0 = tls
+- trapa #21
++ trapa #31
+
+ or r0, r0
+ or r0, r0
+@@ -38,7 +38,7 @@ __clone:
+
+ mov #1, r3 ! __NR_exit
+ mov r0, r4
+- trapa #17
++ trapa #31
+
+ or r0, r0
+ or r0, r0
+diff --git a/src/thread/sh/syscall_cp.s b/src/thread/sh/syscall_cp.s
+index 6b28ddf..c3cafac 100644
+--- a/src/thread/sh/syscall_cp.s
++++ b/src/thread/sh/syscall_cp.s
+@@ -31,7 +31,7 @@ L1: .long __cancel@PLT-(1b-.)
+ mov.l @(4,r15), r7
+ mov.l @(8,r15), r0
+ mov.l @(12,r15), r1
+- trapa #22
++ trapa #31
+
+ __cp_end:
+ ! work around hardware bug
+diff --git a/src/unistd/sh/pipe.s b/src/unistd/sh/pipe.s
+index d865ae3..46c4908 100644
+--- a/src/unistd/sh/pipe.s
++++ b/src/unistd/sh/pipe.s
+@@ -2,7 +2,7 @@
+ .type pipe, @function
+ pipe:
+ mov #42, r3
+- trapa #17
++ trapa #31
+
+ ! work around hardware bug
+ or r0, r0
+--
+2.1.4
+