1 --- a/arch/arm/atomic.h
2 +++ b/arch/arm/atomic.h
3 @@ -22,37 +22,150 @@ static inline int a_ctz_64(uint64_t x)
7 -#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
8 - || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
10 #if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
11 -#define MEM_BARRIER "dmb ish"
13 -#define MEM_BARRIER "mcr p15,0,r0,c7,c10,5"
16 -static inline int __k_cas(int t, int s, volatile int *p)
17 +static inline void a_barrier()
21 - " " MEM_BARRIER "\n"
22 + __asm__ __volatile__("dmb ish");
25 +static inline int a_cas(volatile int *p, int t, int s)
28 + __asm__ __volatile__(
35 - " strexeq %0,%2,%3\n"
38 - " " MEM_BARRIER "\n"
48 : "r"(t), "r"(s), "Q"(*p)
54 +static inline int a_swap(volatile int *x, int v)
57 + __asm__ __volatile__(
64 + : "=&r"(old), "=&r"(tmp)
70 +static inline int a_fetch_add(volatile int *x, int v)
73 + __asm__ __volatile__(
81 + : "=&r"(old), "=&r"(tmp)
87 +static inline void a_inc(volatile int *x)
90 + __asm__ __volatile__(
98 + : "=&r"(tmp), "=&r"(tmp2)
100 + : "memory", "cc" );
103 +static inline void a_dec(volatile int *x)
106 + __asm__ __volatile__(
110 + " strex %1,%0,%2\n"
114 + : "=&r"(tmp), "=&r"(tmp2)
116 + : "memory", "cc" );
119 +static inline void a_and(volatile int *x, int v)
122 + __asm__ __volatile__(
126 + " strex %1,%0,%3\n"
130 + : "=&r"(tmp), "=&r"(tmp2)
132 + : "memory", "cc" );
135 +static inline void a_or(volatile int *x, int v)
138 + __asm__ __volatile__(
142 + " strex %1,%0,%3\n"
146 + : "=&r"(tmp), "=&r"(tmp2)
148 + : "memory", "cc" );
151 +static inline void a_store(volatile int *p, int x)
153 + __asm__ __volatile__(
159 + : "memory", "cc" );
163 -#define __k_cas ((int (*)(int, int, volatile int *))0xffff0fc0)
166 +int __a_cas(int, int, volatile int *) __attribute__((__visibility__("hidden")));
167 +#define __k_cas __a_cas
169 +static inline void a_barrier()
171 + __asm__ __volatile__("bl __a_barrier"
172 + : : : "memory", "cc", "ip", "lr" );
175 static inline int a_cas(volatile int *p, int t, int s)
177 @@ -65,11 +178,6 @@ static inline int a_cas(volatile int *p,
181 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
183 - return (void *)a_cas(p, (int)t, (int)s);
186 static inline int a_swap(volatile int *x, int v)
189 @@ -98,19 +206,9 @@ static inline void a_dec(volatile int *x
191 static inline void a_store(volatile int *p, int x)
193 - while (__k_cas(*p, x, p));
196 -#define a_spin a_barrier
198 -static inline void a_barrier()
200 - __k_cas(0, 0, &(int){0});
203 -static inline void a_crash()
205 - *(volatile char *)0=0;
211 static inline void a_and(volatile int *p, int v)
212 @@ -127,6 +225,20 @@ static inline void a_or(volatile int *p,
213 while (__k_cas(old, old|v, p));
218 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
220 + return (void *)a_cas(p, (int)t, (int)s);
223 +#define a_spin a_barrier
225 +static inline void a_crash()
227 + *(volatile char *)0=0;
230 static inline void a_or_l(volatile void *p, long v)
233 --- a/arch/arm/bits/alltypes.h.in
234 +++ b/arch/arm/bits/alltypes.h.in
235 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
237 TYPEDEF unsigned wchar_t;
239 -TYPEDEF unsigned wint_t;
241 TYPEDEF float float_t;
242 TYPEDEF double double_t;
243 --- a/arch/arm/bits/syscall.h
244 +++ b/arch/arm/bits/syscall.h
246 #define __NR_seccomp 383
247 #define __NR_getrandom 384
248 #define __NR_memfd_create 385
249 +#define __NR_bpf 386
251 +#define __ARM_NR_breakpoint 0x0f0001
252 +#define __ARM_NR_cacheflush 0x0f0002
253 +#define __ARM_NR_usr26 0x0f0003
254 +#define __ARM_NR_usr32 0x0f0004
255 +#define __ARM_NR_set_tls 0x0f0005
257 /* Repeated with SYS_ prefix */
260 #define SYS_seccomp 383
261 #define SYS_getrandom 384
262 #define SYS_memfd_create 385
264 --- a/arch/arm/pthread_arch.h
265 +++ b/arch/arm/pthread_arch.h
266 @@ -10,9 +10,17 @@ static inline __attribute__((const)) pth
270 -typedef char *(*__ptr_func_t)(void) __attribute__((const));
271 -#define __pthread_self() \
272 - ((pthread_t)(((__ptr_func_t)0xffff0fe0)()+8-sizeof(struct pthread)))
273 +static inline __attribute__((const)) pthread_t __pthread_self()
277 + __asm__( "bl __a_gettp\n\tmov %0,r0" : "=r"(p) : : "cc", "r0", "lr" );
279 + register char *p __asm__("r0");
280 + __asm__( "bl __a_gettp" : "=r"(p) : : "cc", "lr" );
282 + return (void *)(p+8-sizeof(struct pthread));
288 +++ b/arch/arm/src/__set_thread_area.c
292 +#include "pthread_impl.h"
295 +#define HWCAP_TLS (1 << 15)
297 +extern const unsigned char __attribute__((__visibility__("hidden")))
298 + __a_barrier_dummy[], __a_barrier_oldkuser[],
299 + __a_barrier_v6[], __a_barrier_v7[],
300 + __a_cas_dummy[], __a_cas_v6[], __a_cas_v7[],
303 +#define __a_barrier_kuser 0xffff0fa0
304 +#define __a_cas_kuser 0xffff0fc0
305 +#define __a_gettp_kuser 0xffff0fe0
307 +extern uintptr_t __attribute__((__visibility__("hidden")))
308 + __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
310 +#define SET(op,ver) (__a_##op##_ptr = \
311 + (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
313 +int __set_thread_area(void *p)
315 +#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
316 + if (__hwcap & HWCAP_TLS) {
320 + for (aux=libc.auxv; *aux; aux+=2) {
321 + if (*aux != AT_PLATFORM) continue;
322 + const char *s = (void *)aux[1];
323 + if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
329 + int ver = *(int *)0xffff0ffc;
332 + SET(barrier, kuser);
333 + if (ver < 2) a_crash();
334 + if (ver < 3) SET(barrier, oldkuser);
337 + return __syscall(0xf0005, p);
340 +++ b/arch/arm/src/arm/atomics.s
346 +.type __a_barrier,%function
351 +1: .word __a_barrier_ptr-1b
352 +.global __a_barrier_dummy
353 +.hidden __a_barrier_dummy
358 +.global __a_barrier_oldkuser
359 +.hidden __a_barrier_oldkuser
360 +__a_barrier_oldkuser:
361 + push {r0,r1,r2,r3,ip,lr}
367 + pop {r0,r1,r2,r3,ip,lr}
371 +.global __a_barrier_v6
372 +.hidden __a_barrier_v6
374 + mcr p15,0,r0,c7,c10,5
376 +.global __a_barrier_v7
377 +.hidden __a_barrier_v7
379 + .word 0xf57ff05b /* dmb ish */
384 +.type __a_cas,%function
389 +1: .word __a_cas_ptr-1b
390 +.global __a_cas_dummy
391 +.hidden __a_cas_dummy
404 + mcr p15,0,r0,c7,c10,5
405 +1: .word 0xe1920f9f /* ldrex r0,[r2] */
407 + .word 0x01820f91 /* strexeq r0,r1,[r2] */
410 + mcr p15,0,r0,c7,c10,5
416 + .word 0xf57ff05b /* dmb ish */
417 +1: .word 0xe1920f9f /* ldrex r0,[r2] */
419 + .word 0x01820f91 /* strexeq r0,r1,[r2] */
422 + .word 0xf57ff05b /* dmb ish */
425 +.global __aeabi_read_tp
426 +.type __aeabi_read_tp,%function
431 +.type __a_gettp,%function
436 +1: .word __a_gettp_ptr-1b
437 +.global __a_gettp_dummy
438 +.hidden __a_gettp_dummy
440 + mrc p15,0,r0,c13,c0,3
444 +.global __a_barrier_ptr
445 +.hidden __a_barrier_ptr
454 +.global __a_gettp_ptr
455 +.hidden __a_gettp_ptr
458 --- a/arch/arm/syscall_arch.h
459 +++ b/arch/arm/syscall_arch.h
462 long (__syscall)(long, ...);
466 #define __asm_syscall(...) do { \
467 __asm__ __volatile__ ( "svc 0" \
468 : "=r"(r0) : __VA_ARGS__ : "memory"); \
469 @@ -54,41 +52,25 @@ static inline long __syscall4(long n, lo
470 __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3));
475 -static inline long __syscall0(long n)
477 - return (__syscall)(n);
480 -static inline long __syscall1(long n, long a)
482 - return (__syscall)(n, a);
485 -static inline long __syscall2(long n, long a, long b)
487 - return (__syscall)(n, a, b);
490 -static inline long __syscall3(long n, long a, long b, long c)
492 - return (__syscall)(n, a, b, c);
495 -static inline long __syscall4(long n, long a, long b, long c, long d)
497 - return (__syscall)(n, a, b, c, d);
502 static inline long __syscall5(long n, long a, long b, long c, long d, long e)
504 - return (__syscall)(n, a, b, c, d, e);
505 + register long r7 __asm__("r7") = n;
506 + register long r0 __asm__("r0") = a;
507 + register long r1 __asm__("r1") = b;
508 + register long r2 __asm__("r2") = c;
509 + register long r3 __asm__("r3") = d;
510 + register long r4 __asm__("r4") = e;
511 + __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4));
514 static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
516 - return (__syscall)(n, a, b, c, d, e, f);
517 + register long r7 __asm__("r7") = n;
518 + register long r0 __asm__("r0") = a;
519 + register long r1 __asm__("r1") = b;
520 + register long r2 __asm__("r2") = c;
521 + register long r3 __asm__("r3") = d;
522 + register long r4 __asm__("r4") = e;
523 + register long r5 __asm__("r5") = f;
524 + __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5));
526 --- a/arch/i386/bits/alltypes.h.in
527 +++ b/arch/i386/bits/alltypes.h.in
528 @@ -17,7 +17,6 @@ TYPEDEF __WCHAR_TYPE__ wchar_t;
529 TYPEDEF long wchar_t;
532 -TYPEDEF unsigned wint_t;
534 #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 0
535 TYPEDEF float float_t;
536 --- a/arch/i386/bits/syscall.h
537 +++ b/arch/i386/bits/syscall.h
539 #define __NR_seccomp 354
540 #define __NR_getrandom 355
541 #define __NR_memfd_create 356
542 +#define __NR_bpf 357
545 /* Repeated with SYS_ prefix */
547 #define SYS_seccomp 354
548 #define SYS_getrandom 355
549 #define SYS_memfd_create 356
551 --- a/arch/microblaze/bits/alltypes.h.in
552 +++ b/arch/microblaze/bits/alltypes.h.in
553 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
557 -TYPEDEF unsigned wint_t;
559 TYPEDEF float float_t;
560 TYPEDEF double double_t;
561 --- a/arch/microblaze/bits/syscall.h
562 +++ b/arch/microblaze/bits/syscall.h
564 #define __NR_seccomp 384
565 #define __NR_getrandom 385
566 #define __NR_memfd_create 386
567 +#define __NR_bpf 387
569 /* Repeated with SYS_ prefix */
572 #define SYS_seccomp 384
573 #define SYS_getrandom 385
574 #define SYS_memfd_create 386
576 --- a/arch/microblaze/syscall_arch.h
577 +++ b/arch/microblaze/syscall_arch.h
578 @@ -100,39 +100,7 @@ static inline long __syscall6(long n, lo
582 -static inline long __syscall0(long n)
584 - return (__syscall)(n);
587 -static inline long __syscall1(long n, long a)
589 - return (__syscall)(n, a);
592 -static inline long __syscall2(long n, long a, long b)
594 - return (__syscall)(n, a, b);
597 -static inline long __syscall3(long n, long a, long b, long c)
599 - return (__syscall)(n, a, b, c);
602 -static inline long __syscall4(long n, long a, long b, long c, long d)
604 - return (__syscall)(n, a, b, c, d);
607 -static inline long __syscall5(long n, long a, long b, long c, long d, long e)
609 - return (__syscall)(n, a, b, c, d, e);
612 -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
614 - return (__syscall)(n, a, b, c, d, e, f);
616 +#undef SYSCALL_NO_INLINE
617 +#define SYSCALL_NO_INLINE
620 --- a/arch/mips/bits/alltypes.h.in
621 +++ b/arch/mips/bits/alltypes.h.in
622 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
626 -TYPEDEF unsigned wint_t;
628 TYPEDEF float float_t;
629 TYPEDEF double double_t;
630 --- a/arch/mips/bits/syscall.h
631 +++ b/arch/mips/bits/syscall.h
633 #define __NR_seccomp 4352
634 #define __NR_getrandom 4353
635 #define __NR_memfd_create 4354
636 +#define __NR_bpf 4355
639 /* Repeated with SYS_ prefix */
641 #define SYS_seccomp 4352
642 #define SYS_getrandom 4353
643 #define SYS_memfd_create 4354
644 +#define SYS_bpf 4355
645 --- a/arch/or1k/bits/alltypes.h.in
646 +++ b/arch/or1k/bits/alltypes.h.in
647 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
649 TYPEDEF unsigned wchar_t;
651 -TYPEDEF unsigned wint_t;
653 TYPEDEF float float_t;
654 TYPEDEF double double_t;
655 --- a/arch/or1k/bits/syscall.h
656 +++ b/arch/or1k/bits/syscall.h
658 #define __NR_seccomp 277
659 #define __NR_getrandom 278
660 #define __NR_memfd_create 279
661 +#define __NR_bpf 280
663 #define SYS_io_setup __NR_io_setup
664 #define SYS_io_destroy __NR_io_destroy
666 #define SYS_seccomp __NR_seccomp
667 #define SYS_getrandom __NR_getrandom
668 #define SYS_memfd_create __NR_memfd_create
669 +#define SYS_bpf __NR_bpf
670 --- a/arch/or1k/syscall_arch.h
671 +++ b/arch/or1k/syscall_arch.h
673 #define __SYSCALL_LL_E(x) \
674 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
675 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
676 -#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
677 +#define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x))
679 #define SYSCALL_MMAP2_UNIT 8192ULL
681 @@ -118,39 +118,7 @@ static inline long __syscall6(long n, lo
685 -static inline long __syscall0(long n)
687 - return (__syscall)(n);
690 -static inline long __syscall1(long n, long a)
692 - return (__syscall)(n, a);
695 -static inline long __syscall2(long n, long a, long b)
697 - return (__syscall)(n, a, b);
700 -static inline long __syscall3(long n, long a, long b, long c)
702 - return (__syscall)(n, a, b, c);
705 -static inline long __syscall4(long n, long a, long b, long c, long d)
707 - return (__syscall)(n, a, b, c, d);
710 -static inline long __syscall5(long n, long a, long b, long c, long d, long e)
712 - return (__syscall)(n, a, b, c, d, e);
715 -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
717 - return (__syscall)(n, a, b, c, d, e, f);
719 +#undef SYSCALL_NO_INLINE
720 +#define SYSCALL_NO_INLINE
723 --- a/arch/powerpc/bits/alltypes.h.in
724 +++ b/arch/powerpc/bits/alltypes.h.in
725 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
727 TYPEDEF long wchar_t;
729 -TYPEDEF unsigned wint_t;
731 TYPEDEF float float_t;
732 TYPEDEF double double_t;
733 --- a/arch/powerpc/bits/syscall.h
734 +++ b/arch/powerpc/bits/syscall.h
736 #define __NR_seccomp 358
737 #define __NR_getrandom 359
738 #define __NR_memfd_create 360
739 +#define __NR_bpf 361
742 * repeated with SYS prefix
744 #define SYS_seccomp 358
745 #define SYS_getrandom 359
746 #define SYS_memfd_create 360
748 --- a/arch/powerpc/syscall_arch.h
749 +++ b/arch/powerpc/syscall_arch.h
751 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
752 #define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
754 -long (__syscall)(long, ...);
756 -static inline long __syscall0(long n)
758 - return (__syscall)(n, 0, 0, 0, 0, 0, 0);
761 -static inline long __syscall1(long n, long a)
763 - return (__syscall)(n, a, 0, 0, 0, 0, 0);
766 -static inline long __syscall2(long n, long a, long b)
768 - return (__syscall)(n, a, b, 0, 0, 0, 0);
771 -static inline long __syscall3(long n, long a, long b, long c)
773 - return (__syscall)(n, a, b, c, 0, 0, 0);
776 -static inline long __syscall4(long n, long a, long b, long c, long d)
778 - return (__syscall)(n, a, b, c, d, 0, 0);
781 -static inline long __syscall5(long n, long a, long b, long c, long d, long e)
783 - return (__syscall)(n, a, b, c, d, e, 0);
786 -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
788 - return (__syscall)(n, a, b, c, d, e, f);
790 +#undef SYSCALL_NO_INLINE
791 +#define SYSCALL_NO_INLINE
792 --- a/arch/sh/bits/alltypes.h.in
793 +++ b/arch/sh/bits/alltypes.h.in
794 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
796 TYPEDEF long wchar_t;
798 -TYPEDEF unsigned wint_t;
800 TYPEDEF float float_t;
801 TYPEDEF double double_t;
802 --- a/arch/x32/bits/alltypes.h.in
803 +++ b/arch/x32/bits/alltypes.h.in
804 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
806 TYPEDEF long wchar_t;
808 -TYPEDEF unsigned wint_t;
810 #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 2
811 TYPEDEF long double float_t;
812 --- a/arch/x32/bits/syscall.h
813 +++ b/arch/x32/bits/syscall.h
815 #define __NR_seccomp (__X32_SYSCALL_BIT + 317)
816 #define __NR_getrandom (__X32_SYSCALL_BIT + 318)
817 #define __NR_memfd_create (__X32_SYSCALL_BIT + 319)
818 +#define __NR_kexec_file_load (__X32_SYSCALL_BIT + 320)
819 +#define __NR_bpf (__X32_SYSCALL_BIT + 321)
821 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
822 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
824 #define SYS_seccomp __NR_seccomp
825 #define SYS_getrandom __NR_getrandom
826 #define SYS_memfd_create __NR_memfd_create
827 +#define SYS_kexec_file_load __NR_kexec_file_load
828 +#define SYS_bpf __NR_bpf
830 #define SYS_rt_sigaction __NR_rt_sigaction
831 #define SYS_rt_sigreturn __NR_rt_sigreturn
832 --- a/arch/x86_64/bits/alltypes.h.in
833 +++ b/arch/x86_64/bits/alltypes.h.in
834 @@ -8,7 +8,6 @@ TYPEDEF __builtin_va_list __isoc_va_list
838 -TYPEDEF unsigned wint_t;
840 #if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 2
841 TYPEDEF long double float_t;
842 --- a/arch/x86_64/bits/syscall.h
843 +++ b/arch/x86_64/bits/syscall.h
845 #define __NR_seccomp 317
846 #define __NR_getrandom 318
847 #define __NR_memfd_create 319
848 +#define __NR_kexec_file_load 320
849 +#define __NR_bpf 321
854 #define SYS_seccomp 317
855 #define SYS_getrandom 318
856 #define SYS_memfd_create 319
857 +#define SYS_kexec_file_load 320
862 --- a/include/alltypes.h.in
863 +++ b/include/alltypes.h.in
864 @@ -28,6 +28,7 @@ TYPEDEF _Int64 blkcnt_t;
865 TYPEDEF unsigned _Int64 fsblkcnt_t;
866 TYPEDEF unsigned _Int64 fsfilcnt_t;
868 +TYPEDEF unsigned wint_t;
869 TYPEDEF unsigned long wctype_t;
871 TYPEDEF void * timer_t;
872 --- a/include/arpa/nameser.h
873 +++ b/include/arpa/nameser.h
875 #ifndef _ARPA_NAMESER_H
876 #define _ARPA_NAMESER_H
885 #define __NAMESER 19991006
886 @@ -48,6 +53,8 @@ extern const struct _ns_flagdata _ns_fla
887 #define ns_msg_end(handle) ((handle)._eom + 0)
888 #define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
889 #define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
890 +#define ns_msg_getflag(handle, flag) \
891 + (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)
893 typedef struct __ns_rr {
894 char name[NS_MAXDNAME];
895 @@ -296,43 +303,20 @@ typedef enum __ns_cert_types {
896 #define NS_OPT_DNSSEC_OK 0x8000U
897 #define NS_OPT_NSID 3
899 -#define NS_GET16(s, cp) do { \
900 - register const unsigned char *t_cp = (const unsigned char *)(cp); \
901 - (s) = ((uint16_t)t_cp[0] << 8) \
902 - | ((uint16_t)t_cp[1]) \
904 - (cp) += NS_INT16SZ; \
907 -#define NS_GET32(l, cp) do { \
908 - register const unsigned char *t_cp = (const unsigned char *)(cp); \
909 - (l) = ((uint32_t)t_cp[0] << 24) \
910 - | ((uint32_t)t_cp[1] << 16) \
911 - | ((uint32_t)t_cp[2] << 8) \
912 - | ((uint32_t)t_cp[3]) \
914 - (cp) += NS_INT32SZ; \
917 -#define NS_PUT16(s, cp) do { \
918 - register uint16_t t_s = (uint16_t)(s); \
919 - register unsigned char *t_cp = (unsigned char *)(cp); \
920 - *t_cp++ = t_s >> 8; \
922 - (cp) += NS_INT16SZ; \
925 -#define NS_PUT32(l, cp) do { \
926 - register uint32_t t_l = (uint32_t)(l); \
927 - register unsigned char *t_cp = (unsigned char *)(cp); \
928 - *t_cp++ = t_l >> 24; \
929 - *t_cp++ = t_l >> 16; \
930 - *t_cp++ = t_l >> 8; \
932 - (cp) += NS_INT32SZ; \
936 +#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
937 +#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
938 +#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
939 +#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)
941 +unsigned ns_get16(const unsigned char *);
942 +unsigned long ns_get32(const unsigned char *);
943 +void ns_put16(unsigned, unsigned char *);
944 +void ns_put32(unsigned long, unsigned char *);
946 +int ns_initparse(const unsigned char *, int, ns_msg *);
947 +int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
948 +int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
949 +int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);
952 #define __BIND 19950621
953 @@ -464,4 +448,8 @@ typedef struct {
954 #define PUTSHORT NS_PUT16
955 #define PUTLONG NS_PUT32
962 --- a/include/complex.h
963 +++ b/include/complex.h
964 @@ -7,9 +7,9 @@ extern "C" {
966 #define complex _Complex
968 -#define _Complex_I (__extension__ 1.0fi)
969 +#define _Complex_I (__extension__ (0.0f+1.0fi))
971 -#define _Complex_I 1.0fi
972 +#define _Complex_I (0.0f+1.0fi)
976 @@ -101,8 +101,9 @@ double creal(double complex);
977 float crealf(float complex);
978 long double creall(long double complex);
981 #define __CIMAG(x, t) \
982 - ((union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1])
983 + (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1])
985 #define creal(x) ((double)(x))
986 #define crealf(x) ((float)(x))
987 @@ -111,13 +112,20 @@ long double creall(long double complex);
988 #define cimag(x) __CIMAG(x, double)
989 #define cimagf(x) __CIMAG(x, float)
990 #define cimagl(x) __CIMAG(x, long double)
993 -#define __CMPLX(x, y, t) \
994 - ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z)
996 +#if __STDC_VERSION__ >= 201112L
997 +#if defined(_Imaginary_I)
998 +#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)))
999 +#elif defined(__clang__)
1000 +#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) })
1002 +#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
1004 #define CMPLX(x, y) __CMPLX(x, y, double)
1005 #define CMPLXF(x, y) __CMPLX(x, y, float)
1006 #define CMPLXL(x, y) __CMPLX(x, y, long double)
1011 --- a/include/pthread.h
1012 +++ b/include/pthread.h
1013 @@ -84,7 +84,9 @@ __attribute__((const))
1014 pthread_t pthread_self(void);
1016 int pthread_equal(pthread_t, pthread_t);
1017 +#ifndef __cplusplus
1018 #define pthread_equal(x,y) ((x)==(y))
1021 int pthread_setcancelstate(int, int *);
1022 int pthread_setcanceltype(int, int *);
1023 --- a/include/stdint.h
1024 +++ b/include/stdint.h
1025 @@ -47,8 +47,8 @@ typedef uint64_t uint_least64_t;
1027 #define UINT8_MAX (0xff)
1028 #define UINT16_MAX (0xffff)
1029 -#define UINT32_MAX (0xffffffff)
1030 -#define UINT64_MAX (0xffffffffffffffff)
1031 +#define UINT32_MAX (0xffffffffu)
1032 +#define UINT64_MAX (0xffffffffffffffffu)
1034 #define INT_FAST8_MIN INT8_MIN
1035 #define INT_FAST64_MIN INT64_MIN
1036 @@ -78,7 +78,7 @@ typedef uint64_t uint_least64_t;
1037 #define INTMAX_MAX INT64_MAX
1038 #define UINTMAX_MAX UINT64_MAX
1041 +#define WINT_MIN 0U
1042 #define WINT_MAX UINT32_MAX
1045 --- a/include/sys/prctl.h
1046 +++ b/include/sys/prctl.h
1051 +#include <stdint.h>
1053 #define PR_SET_PDEATHSIG 1
1054 #define PR_GET_PDEATHSIG 2
1055 #define PR_GET_DUMPABLE 3
1056 @@ -80,6 +82,25 @@ extern "C" {
1057 #define PR_SET_MM_ENV_END 11
1058 #define PR_SET_MM_AUXV 12
1059 #define PR_SET_MM_EXE_FILE 13
1060 +#define PR_SET_MM_MAP 14
1061 +#define PR_SET_MM_MAP_SIZE 15
1063 +struct prctl_mm_map {
1064 + uint64_t start_code;
1065 + uint64_t end_code;
1066 + uint64_t start_data;
1067 + uint64_t end_data;
1068 + uint64_t start_brk;
1070 + uint64_t start_stack;
1071 + uint64_t arg_start;
1073 + uint64_t env_start;
1076 + uint32_t auxv_size;
1080 #define PR_SET_PTRACER 0x59616d61
1081 #define PR_SET_PTRACER_ANY (-1UL)
1082 --- a/include/threads.h
1083 +++ b/include/threads.h
1084 @@ -51,7 +51,9 @@ void thrd_yield(void);
1086 thrd_t thrd_current(void);
1087 int thrd_equal(thrd_t, thrd_t);
1088 +#ifndef __cplusplus
1089 #define thrd_equal(A, B) ((A) == (B))
1092 void call_once(once_flag *, void (*)(void));
1094 --- a/include/utmp.h
1095 +++ b/include/utmp.h
1096 @@ -35,6 +35,8 @@ void setutent(void);
1098 void updwtmp(const char *, const struct utmp *);
1100 +int login_tty(int);
1102 #define _PATH_UTMP "/dev/null/utmp"
1103 #define _PATH_WTMP "/dev/null/wtmp"
1105 --- a/src/fcntl/open.c
1106 +++ b/src/fcntl/open.c
1107 @@ -7,7 +7,7 @@ int open(const char *filename, int flags
1111 - if (flags & O_CREAT) {
1112 + if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
1114 va_start(ap, flags);
1115 mode = va_arg(ap, mode_t);
1116 --- a/src/fcntl/openat.c
1117 +++ b/src/fcntl/openat.c
1120 int openat(int fd, const char *filename, int flags, ...)
1124 - va_start(ap, flags);
1125 - mode = va_arg(ap, mode_t);
1129 + if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
1131 + va_start(ap, flags);
1132 + mode = va_arg(ap, mode_t);
1136 return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
1139 --- a/src/internal/libm.h
1140 +++ b/src/internal/libm.h
1141 @@ -128,6 +128,18 @@ do {
1150 +#define __CMPLX(x, y, t) \
1151 + ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z)
1153 +#define CMPLX(x, y) __CMPLX(x, y, double)
1154 +#define CMPLXF(x, y) __CMPLX(x, y, float)
1155 +#define CMPLXL(x, y) __CMPLX(x, y, long double)
1157 /* fdlibm kernel functions */
1159 int __rem_pio2_large(double*,double*,int,int,int);
1160 --- a/src/internal/syscall.h
1161 +++ b/src/internal/syscall.h
1162 @@ -24,12 +24,22 @@ long __syscall_ret(unsigned long), __sys
1163 __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
1164 syscall_arg_t, syscall_arg_t, syscall_arg_t);
1166 +#ifdef SYSCALL_NO_INLINE
1167 +#define __syscall0(n) (__syscall)(n)
1168 +#define __syscall1(n,a) (__syscall)(n,__scc(a))
1169 +#define __syscall2(n,a,b) (__syscall)(n,__scc(a),__scc(b))
1170 +#define __syscall3(n,a,b,c) (__syscall)(n,__scc(a),__scc(b),__scc(c))
1171 +#define __syscall4(n,a,b,c,d) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d))
1172 +#define __syscall5(n,a,b,c,d,e) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
1173 +#define __syscall6(n,a,b,c,d,e,f) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
1175 #define __syscall1(n,a) __syscall1(n,__scc(a))
1176 #define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b))
1177 #define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c))
1178 #define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d))
1179 #define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
1180 #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
1182 #define __syscall7(n,a,b,c,d,e,f,g) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f),__scc(g))
1184 #define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
1185 --- a/src/ldso/dynlink.c
1186 +++ b/src/ldso/dynlink.c
1187 @@ -645,6 +645,8 @@ static void decode_dyn(struct dso *p)
1188 p->hashtab = (void *)(p->base + dyn[DT_HASH]);
1189 if (dyn[0]&(1<<DT_RPATH))
1190 p->rpath_orig = (void *)(p->strings + dyn[DT_RPATH]);
1191 + if (dyn[0]&(1<<DT_RUNPATH))
1192 + p->rpath_orig = (void *)(p->strings + dyn[DT_RUNPATH]);
1193 if (search_vec(p->dynv, dyn, DT_GNU_HASH))
1194 p->ghashtab = (void *)(p->base + *dyn);
1195 if (search_vec(p->dynv, dyn, DT_VERSYM))
1196 @@ -1126,6 +1128,7 @@ void *__dynlink(int argc, char **argv)
1199 libc.page_size = aux[AT_PAGESZ];
1202 /* If the dynamic linker was invoked as a program itself, AT_BASE
1203 * will not be set. In that case, we assume the base address is
1204 --- a/src/math/__rem_pio2.c
1205 +++ b/src/math/__rem_pio2.c
1210 +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
1211 +#define EPS DBL_EPSILON
1212 +#elif FLT_EVAL_METHOD==2
1213 +#define EPS LDBL_EPSILON
1217 * invpio2: 53 bits of 2/pi
1218 * pio2_1: first 33 bit of pi/2
1220 * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
1224 invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
1225 pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
1226 pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
1227 @@ -41,8 +48,8 @@ pio2_3t = 8.47842766036889956997e-32; /*
1228 int __rem_pio2(double x, double *y)
1230 union {double f; uint64_t i;} u = {x};
1232 - double tx[3],ty[2],fn;
1233 + double_t z,w,t,r,fn;
1234 + double tx[3],ty[2];
1236 int sign, n, ex, ey, i;
1238 @@ -111,8 +118,7 @@ int __rem_pio2(double x, double *y)
1239 if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
1241 /* rint(x/(pi/2)), Assume round-to-nearest. */
1242 - fn = x*invpio2 + 0x1.8p52;
1243 - fn = fn - 0x1.8p52;
1244 + fn = x*invpio2 + toint - toint;
1247 w = fn*pio2_1t; /* 1st round, good to 85 bits */
1248 --- a/src/math/__rem_pio2f.c
1249 +++ b/src/math/__rem_pio2f.c
1254 +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
1255 +#define EPS DBL_EPSILON
1256 +#elif FLT_EVAL_METHOD==2
1257 +#define EPS LDBL_EPSILON
1261 * invpio2: 53 bits of 2/pi
1262 * pio2_1: first 25 bits of pi/2
1263 * pio2_1t: pi/2 - pio2_1
1267 invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
1268 pio2_1 = 1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */
1269 pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */
1270 @@ -35,7 +42,8 @@ pio2_1t = 1.58932547735281966916e-08; /*
1271 int __rem_pio2f(float x, double *y)
1273 union {float f; uint32_t i;} u = {x};
1274 - double tx[1],ty[1],fn;
1275 + double tx[1],ty[1];
1280 @@ -43,8 +51,7 @@ int __rem_pio2f(float x, double *y)
1281 /* 25+53 bit pi is good enough for medium size */
1282 if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */
1283 /* Use a specialized rint() to get fn. Assume round-to-nearest. */
1284 - fn = x*invpio2 + 0x1.8p52;
1285 - fn = fn - 0x1.8p52;
1286 + fn = x*invpio2 + toint - toint;
1288 *y = x - fn*pio2_1 - fn*pio2_1t;
1290 --- a/src/math/__rem_pio2l.c
1291 +++ b/src/math/__rem_pio2l.c
1293 * use __rem_pio2_large() for large x
1296 +static const long double toint = 1.5/LDBL_EPSILON;
1298 #if LDBL_MANT_DIG == 64
1299 /* u ~< 0x1p25*pi/2 */
1300 #define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000))
1301 -#define TOINT 0x1.8p63
1302 #define QUOBITS(x) ((uint32_t)(int32_t)x & 0x7fffffff)
1305 @@ -50,7 +51,6 @@ pio2_3t = -2.75299651904407171810e-37L;
1306 #elif LDBL_MANT_DIG == 113
1307 /* u ~< 0x1p45*pi/2 */
1308 #define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f))
1309 -#define TOINT 0x1.8p112
1310 #define QUOBITS(x) ((uint32_t)(int64_t)x & 0x7fffffff)
1313 @@ -77,7 +77,7 @@ int __rem_pio2l(long double x, long doub
1314 ex = u.i.se & 0x7fff;
1316 /* rint(x/(pi/2)), Assume round-to-nearest. */
1317 - fn = x*invpio2 + TOINT - TOINT;
1318 + fn = x*invpio2 + toint - toint;
1321 w = fn*pio2_1t; /* 1st round good to 102/180 bits (ld80/ld128) */
1322 --- a/src/math/ceil.c
1323 +++ b/src/math/ceil.c
1327 +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
1328 +#define EPS DBL_EPSILON
1329 +#elif FLT_EVAL_METHOD==2
1330 +#define EPS LDBL_EPSILON
1332 +static const double_t toint = 1/EPS;
1334 double ceil(double x)
1336 union {double f; uint64_t i;} u = {x};
1337 @@ -10,9 +17,9 @@ double ceil(double x)
1339 /* y = int(x) - x, where int(x) is an integer neighbor of x */
1341 - y = (double)(x - 0x1p52) + 0x1p52 - x;
1342 + y = x - toint + toint - x;
1344 - y = (double)(x + 0x1p52) - 0x1p52 - x;
1345 + y = x + toint - toint - x;
1346 /* special case because of non-nearest rounding modes */
1349 --- a/src/math/ceill.c
1350 +++ b/src/math/ceill.c
1351 @@ -6,11 +6,9 @@ long double ceill(long double x)
1354 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
1355 -#if LDBL_MANT_DIG == 64
1356 -#define TOINT 0x1p63
1357 -#elif LDBL_MANT_DIG == 113
1358 -#define TOINT 0x1p112
1361 +static const long double toint = 1/LDBL_EPSILON;
1363 long double ceill(long double x)
1365 union ldshape u = {x};
1366 @@ -21,9 +19,9 @@ long double ceill(long double x)
1368 /* y = int(x) - x, where int(x) is an integer neighbor of x */
1370 - y = x - TOINT + TOINT - x;
1371 + y = x - toint + toint - x;
1373 - y = x + TOINT - TOINT - x;
1374 + y = x + toint - toint - x;
1375 /* special case because of non-nearest rounding modes */
1376 if (e <= 0x3fff-1) {
1378 --- a/src/math/floor.c
1379 +++ b/src/math/floor.c
1383 +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
1384 +#define EPS DBL_EPSILON
1385 +#elif FLT_EVAL_METHOD==2
1386 +#define EPS LDBL_EPSILON
1388 +static const double_t toint = 1/EPS;
1390 double floor(double x)
1392 union {double f; uint64_t i;} u = {x};
1393 @@ -10,9 +17,9 @@ double floor(double x)
1395 /* y = int(x) - x, where int(x) is an integer neighbor of x */
1397 - y = (double)(x - 0x1p52) + 0x1p52 - x;
1398 + y = x - toint + toint - x;
1400 - y = (double)(x + 0x1p52) - 0x1p52 - x;
1401 + y = x + toint - toint - x;
1402 /* special case because of non-nearest rounding modes */
1405 --- a/src/math/floorl.c
1406 +++ b/src/math/floorl.c
1407 @@ -6,11 +6,9 @@ long double floorl(long double x)
1410 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
1411 -#if LDBL_MANT_DIG == 64
1412 -#define TOINT 0x1p63
1413 -#elif LDBL_MANT_DIG == 113
1414 -#define TOINT 0x1p112
1417 +static const long double toint = 1/LDBL_EPSILON;
1419 long double floorl(long double x)
1421 union ldshape u = {x};
1422 @@ -21,9 +19,9 @@ long double floorl(long double x)
1424 /* y = int(x) - x, where int(x) is an integer neighbor of x */
1426 - y = x - TOINT + TOINT - x;
1427 + y = x - toint + toint - x;
1429 - y = x + TOINT - TOINT - x;
1430 + y = x + toint - toint - x;
1431 /* special case because of non-nearest rounding modes */
1432 if (e <= 0x3fff-1) {
1434 --- a/src/math/i386/fmod.s
1435 +++ b/src/math/i386/fmod.s
1436 @@ -4,7 +4,7 @@ fmod:
1445 --- a/src/math/i386/fmodf.s
1446 +++ b/src/math/i386/fmodf.s
1447 @@ -4,7 +4,7 @@ fmodf:
1456 --- a/src/math/i386/fmodl.s
1457 +++ b/src/math/i386/fmodl.s
1458 @@ -4,7 +4,7 @@ fmodl:
1467 --- a/src/math/i386/remainder.s
1468 +++ b/src/math/i386/remainder.s
1469 @@ -7,7 +7,7 @@ drem:
1478 --- a/src/math/i386/remainderf.s
1479 +++ b/src/math/i386/remainderf.s
1480 @@ -7,7 +7,7 @@ dremf:
1489 --- a/src/math/i386/remainderl.s
1490 +++ b/src/math/i386/remainderl.s
1491 @@ -4,7 +4,7 @@ remainderl:
1500 --- a/src/math/i386/sqrt.s
1501 +++ b/src/math/i386/sqrt.s
1503 .type sqrt,@function
1511 --- a/src/math/modfl.c
1512 +++ b/src/math/modfl.c
1513 @@ -11,11 +11,9 @@ long double modfl(long double x, long do
1516 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
1517 -#if LDBL_MANT_DIG == 64
1518 -#define TOINT 0x1p63
1519 -#elif LDBL_MANT_DIG == 113
1520 -#define TOINT 0x1p112
1523 +static const long double toint = 1/LDBL_EPSILON;
1525 long double modfl(long double x, long double *iptr)
1527 union ldshape u = {x};
1528 @@ -40,7 +38,7 @@ long double modfl(long double x, long do
1530 /* raises spurious inexact */
1532 - y = absx + TOINT - TOINT - absx;
1533 + y = absx + toint - toint - absx;
1536 return s ? -0.0 : 0.0;
1537 --- a/src/math/rint.c
1538 +++ b/src/math/rint.c
1544 +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
1545 +#define EPS DBL_EPSILON
1546 +#elif FLT_EVAL_METHOD==2
1547 +#define EPS LDBL_EPSILON
1549 +static const double_t toint = 1/EPS;
1551 double rint(double x)
1553 union {double f; uint64_t i;} u = {x};
1554 @@ -11,9 +19,9 @@ double rint(double x)
1558 - y = (double)(x - 0x1p52) + 0x1p52;
1559 + y = x - toint + toint;
1561 - y = (double)(x + 0x1p52) - 0x1p52;
1562 + y = x + toint - toint;
1564 return s ? -0.0 : 0;
1566 --- a/src/math/rintf.c
1567 +++ b/src/math/rintf.c
1573 +#if FLT_EVAL_METHOD==0
1574 +#define EPS FLT_EPSILON
1575 +#elif FLT_EVAL_METHOD==1
1576 +#define EPS DBL_EPSILON
1577 +#elif FLT_EVAL_METHOD==2
1578 +#define EPS LDBL_EPSILON
1580 +static const float_t toint = 1/EPS;
1582 float rintf(float x)
1584 union {float f; uint32_t i;} u = {x};
1585 @@ -11,9 +21,9 @@ float rintf(float x)
1589 - y = (float)(x - 0x1p23f) + 0x1p23f;
1590 + y = x - toint + toint;
1592 - y = (float)(x + 0x1p23f) - 0x1p23f;
1593 + y = x + toint - toint;
1595 return s ? -0.0f : 0.0f;
1597 --- a/src/math/rintl.c
1598 +++ b/src/math/rintl.c
1599 @@ -6,11 +6,9 @@ long double rintl(long double x)
1602 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
1603 -#if LDBL_MANT_DIG == 64
1604 -#define TOINT 0x1p63
1605 -#elif LDBL_MANT_DIG == 113
1606 -#define TOINT 0x1p112
1609 +static const long double toint = 1/LDBL_EPSILON;
1611 long double rintl(long double x)
1613 union ldshape u = {x};
1614 @@ -21,9 +19,9 @@ long double rintl(long double x)
1615 if (e >= 0x3fff+LDBL_MANT_DIG-1)
1618 - y = x - TOINT + TOINT;
1619 + y = x - toint + toint;
1621 - y = x + TOINT - TOINT;
1622 + y = x + toint - toint;
1626 --- a/src/math/round.c
1627 +++ b/src/math/round.c
1631 +#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
1632 +#define EPS DBL_EPSILON
1633 +#elif FLT_EVAL_METHOD==2
1634 +#define EPS LDBL_EPSILON
1636 +static const double_t toint = 1/EPS;
1638 double round(double x)
1640 union {double f; uint64_t i;} u = {x};
1641 @@ -12,10 +19,10 @@ double round(double x)
1644 /* raise inexact if x!=0 */
1645 - FORCE_EVAL(x + 0x1p52);
1646 + FORCE_EVAL(x + toint);
1649 - y = (double)(x + 0x1p52) - 0x1p52 - x;
1650 + y = x + toint - toint - x;
1654 --- a/src/math/roundf.c
1655 +++ b/src/math/roundf.c
1659 +#if FLT_EVAL_METHOD==0
1660 +#define EPS FLT_EPSILON
1661 +#elif FLT_EVAL_METHOD==1
1662 +#define EPS DBL_EPSILON
1663 +#elif FLT_EVAL_METHOD==2
1664 +#define EPS LDBL_EPSILON
1666 +static const float_t toint = 1/EPS;
1668 float roundf(float x)
1670 union {float f; uint32_t i;} u = {x};
1671 @@ -11,10 +20,10 @@ float roundf(float x)
1675 - FORCE_EVAL(x + 0x1p23f);
1676 + FORCE_EVAL(x + toint);
1679 - y = (float)(x + 0x1p23f) - 0x1p23f - x;
1680 + y = x + toint - toint - x;
1683 else if (y <= -0.5f)
1684 --- a/src/math/roundl.c
1685 +++ b/src/math/roundl.c
1686 @@ -6,11 +6,9 @@ long double roundl(long double x)
1689 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
1690 -#if LDBL_MANT_DIG == 64
1691 -#define TOINT 0x1p63
1692 -#elif LDBL_MANT_DIG == 113
1693 -#define TOINT 0x1p112
1696 +static const long double toint = 1/LDBL_EPSILON;
1698 long double roundl(long double x)
1700 union ldshape u = {x};
1701 @@ -22,10 +20,10 @@ long double roundl(long double x)
1705 - FORCE_EVAL(x + TOINT);
1706 + FORCE_EVAL(x + toint);
1709 - y = x + TOINT - TOINT - x;
1710 + y = x + toint - toint - x;
1714 --- a/src/math/truncl.c
1715 +++ b/src/math/truncl.c
1716 @@ -6,11 +6,9 @@ long double truncl(long double x)
1719 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
1720 -#if LDBL_MANT_DIG == 64
1721 -#define TOINT 0x1p63
1722 -#elif LDBL_MANT_DIG == 113
1723 -#define TOINT 0x1p112
1726 +static const long double toint = 1/LDBL_EPSILON;
1728 long double truncl(long double x)
1730 union ldshape u = {x};
1731 @@ -27,7 +25,7 @@ long double truncl(long double x)
1732 /* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */
1735 - y = x + TOINT - TOINT - x;
1736 + y = x + toint - toint - x;
1740 --- a/src/math/x32/exp2l.s
1741 +++ b/src/math/x32/exp2l.s
1742 @@ -6,9 +6,7 @@ expm1l:
1744 movl $0xc2820000,-4(%esp)
1752 # x*log2e <= -65, return -1 without underflow
1753 @@ -17,11 +15,8 @@ expm1l:
1766 @@ -53,9 +48,7 @@ exp2l:
1774 je 2f # x - 0x1p63 + 0x1p63 == x
1776 flds (%esp) # 0x1p-149
1777 --- a/src/math/x32/fmodl.s
1778 +++ b/src/math/x32/fmodl.s
1779 @@ -4,8 +4,8 @@ fmodl:
1791 --- a/src/math/x32/remainderl.s
1792 +++ b/src/math/x32/remainderl.s
1793 @@ -4,8 +4,8 @@ remainderl:
1805 --- a/src/math/x86_64/exp2l.s
1806 +++ b/src/math/x86_64/exp2l.s
1807 @@ -6,9 +6,7 @@ expm1l:
1809 movl $0xc2820000,-4(%rsp)
1817 # x*log2e <= -65, return -1 without underflow
1818 @@ -17,11 +15,8 @@ expm1l:
1831 @@ -53,9 +48,7 @@ exp2l:
1839 je 2f # x - 0x1p63 + 0x1p63 == x
1841 flds (%rsp) # 0x1p-149
1842 --- a/src/math/x86_64/fmodl.s
1843 +++ b/src/math/x86_64/fmodl.s
1844 @@ -4,8 +4,8 @@ fmodl:
1856 --- a/src/math/x86_64/remainderl.s
1857 +++ b/src/math/x86_64/remainderl.s
1858 @@ -4,8 +4,8 @@ remainderl:
1870 --- a/src/misc/forkpty.c
1871 +++ b/src/misc/forkpty.c
1876 -#include <sys/ioctl.h>
1879 +#include <sys/wait.h>
1880 +#include <pthread.h>
1882 -int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws)
1883 +int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
1885 - int s, t, i, istmp[3]={0};
1887 + int m, s, ec=0, p[2], cs;
1889 + sigset_t set, oldset;
1891 - if (openpty(m, &s, name, tio, ws) < 0) return -1;
1892 + if (openpty(&m, &s, name, tio, ws) < 0) return -1;
1894 - /* Ensure before forking that we don't exceed fd limit */
1895 - for (i=0; i<3; i++) {
1896 - if (fcntl(i, F_GETFL) < 0) {
1897 - t = fcntl(s, F_DUPFD, i);
1899 - else if (t!=i) close(t);
1900 - else istmp[i] = 1;
1903 + pthread_sigmask(SIG_BLOCK, &set, &oldset);
1904 + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
1906 + if (pipe2(p, O_CLOEXEC)) {
1910 - pid = i==3 ? fork() : -1;
1916 - ioctl(s, TIOCSCTTY, (char *)0);
1920 - if (s>2) close(s);
1923 + if (login_tty(s)) {
1924 + write(p[1], &errno, sizeof errno);
1928 + pthread_setcancelstate(cs, 0);
1929 + pthread_sigmask(SIG_SETMASK, &oldset, 0);
1932 - for (i=0; i<3; i++)
1933 - if (istmp[i]) close(i);
1935 - if (pid < 0) close(*m);
1937 + if (read(p[0], &ec, sizeof ec) > 0) {
1939 + waitpid(pid, &status, 0);
1946 + if (pid > 0) *pm = m;
1949 + pthread_setcancelstate(cs, 0);
1950 + pthread_sigmask(SIG_SETMASK, &oldset, 0);
1954 --- a/src/misc/getopt.c
1955 +++ b/src/misc/getopt.c
1960 +#include "locale_impl.h"
1963 int optind=1, opterr=1, optopt, __optpos, __optreset=0;
1964 @@ -11,6 +12,18 @@ int optind=1, opterr=1, optopt, __optpos
1965 #define optpos __optpos
1966 weak_alias(__optreset, optreset);
1968 +void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
1971 + b = __lctrans_cur(b);
1973 + fwrite(a, strlen(a), 1, f)
1974 + && fwrite(b, strlen(b), 1, f)
1975 + && fwrite(c, l, 1, f)
1980 int getopt(int argc, char * const argv[], const char *optstring)
1983 @@ -24,8 +37,20 @@ int getopt(int argc, char * const argv[]
1987 - if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1])
1988 + if (optind >= argc || !argv[optind])
1991 + if (argv[optind][0] != '-') {
1992 + if (optstring[0] == '-') {
1993 + optarg = argv[optind++];
1999 + if (!argv[optind][1])
2002 if (argv[optind][1] == '-' && !argv[optind][2])
2003 return optind++, -1;
2005 @@ -43,30 +68,31 @@ int getopt(int argc, char * const argv[]
2009 - for (i=0; (l = mbtowc(&d, optstring+i, MB_LEN_MAX)) && d!=c; i+=l>0?l:1);
2010 + if (optstring[0] == '-' || optstring[0] == '+')
2016 + l = mbtowc(&d, optstring+i, MB_LEN_MAX);
2017 + if (l>0) i+=l; else i++;
2018 + } while (l && d != c);
2021 - if (optstring[0] != ':' && opterr) {
2022 - write(2, argv[0], strlen(argv[0]));
2023 - write(2, ": illegal option: ", 18);
2024 - write(2, optchar, k);
2025 - write(2, "\n", 1);
2027 + if (optstring[0] != ':' && opterr)
2028 + __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
2031 - if (optstring[i+1] == ':') {
2032 - if (optind >= argc) {
2033 + if (optstring[i] == ':') {
2034 + if (optstring[i+1] == ':') optarg = 0;
2035 + else if (optind >= argc) {
2036 if (optstring[0] == ':') return ':';
2038 - write(2, argv[0], strlen(argv[0]));
2039 - write(2, ": option requires an argument: ", 31);
2040 - write(2, optchar, k);
2041 - write(2, "\n", 1);
2043 + if (opterr) __getopt_msg(argv[0],
2044 + ": option requires an argument: ",
2048 - if (optstring[i+2] == ':') optarg = 0;
2049 - if (optstring[i+2] != ':' || optpos) {
2050 + if (optstring[i+1] != ':' || optpos) {
2051 optarg = argv[optind++] + optpos;
2054 --- a/src/misc/getopt_long.c
2055 +++ b/src/misc/getopt_long.c
2060 +#include <string.h>
2062 extern int __optpos, __optreset;
2064 +static void permute(char *const *argv, int dest, int src)
2066 + char **av = (char **)argv;
2067 + char *tmp = av[src];
2069 + for (i=src; i>dest; i--)
2074 +void __getopt_msg(const char *, const char *, const char *, size_t);
2076 +static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly);
2078 static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
2080 + int ret, skipped, resumed;
2081 + const char *optstring2 = optstring + 1;
2082 if (!optind || __optreset) {
2087 - if (optind >= argc || !argv[optind] || argv[optind][0] != '-') return -1;
2088 - if ((longonly && argv[optind][1]) ||
2089 - (argv[optind][1] == '-' && argv[optind][2]))
2091 + if (optind >= argc || !argv[optind]) return -1;
2093 + if (optstring[0] != '+' && optstring[0] != '-') {
2095 - for (i=0; longopts[i].name; i++) {
2096 + for (i=optind; ; i++) {
2097 + if (i >= argc || !argv[i]) return -1;
2098 + if (argv[i][0] == '-' && argv[i][1]) break;
2101 + optstring2 = optstring;
2104 + ret = __getopt_long_core(argc, argv, optstring2, longopts, idx, longonly);
2105 + if (resumed > skipped) {
2106 + int i, cnt = optind-resumed;
2107 + for (i=0; i<cnt; i++)
2108 + permute(argv, skipped, optind-1);
2109 + optind = skipped + cnt;
2114 +static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
2117 + if (longopts && argv[optind][0] == '-' &&
2118 + ((longonly && argv[optind][1]) ||
2119 + (argv[optind][1] == '-' && argv[optind][2])))
2121 + int i, cnt, match;
2123 + for (cnt=i=0; longopts[i].name; i++) {
2124 const char *name = longopts[i].name;
2125 - char *opt = argv[optind]+1;
2126 + opt = argv[optind]+1;
2127 if (*opt == '-') opt++;
2128 for (; *name && *name == *opt; name++, opt++);
2129 - if (*name || (*opt && *opt != '=')) continue;
2130 + if (*opt && *opt != '=') continue;
2141 + optopt = longopts[i].val;
2143 - if (!longopts[i].has_arg) continue;
2144 + if (!longopts[i].has_arg) {
2145 + if (optstring[0] == ':' || !opterr)
2147 + __getopt_msg(argv[0],
2148 + ": option does not take an argument: ",
2150 + strlen(longopts[i].name));
2155 if (longopts[i].has_arg == required_argument) {
2156 - if (!(optarg = argv[++optind]))
2158 + if (!(optarg = argv[optind])) {
2159 + if (optstring[0] == ':' || !opterr)
2161 + __getopt_msg(argv[0],
2162 + ": option requires an argument: ",
2164 + strlen(longopts[i].name));
2168 } else optarg = NULL;
2172 if (longopts[i].flag) {
2173 *longopts[i].flag = longopts[i].val;
2174 @@ -41,6 +110,12 @@ static int __getopt_long(int argc, char
2175 return longopts[i].val;
2177 if (argv[optind][1] == '-') {
2178 + if (optstring[0] != ':' && opterr)
2179 + __getopt_msg(argv[0], cnt ?
2180 + ": option is ambiguous: " :
2181 + ": unrecognized option: ",
2183 + strlen(argv[optind]+2));
2188 +++ b/src/misc/login_tty.c
2191 +#include <sys/ioctl.h>
2192 +#include <unistd.h>
2194 +int login_tty(int fd)
2197 + if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1;
2201 + if (fd>2) close(fd);
2204 --- a/src/misc/openpty.c
2205 +++ b/src/misc/openpty.c
2210 +#include <pthread.h>
2212 /* Nonstandard, but vastly superior to the standard functions */
2214 -int openpty(int *m, int *s, char *name, const struct termios *tio, const struct winsize *ws)
2215 +int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struct winsize *ws)
2218 + int m, s, n=0, cs;
2221 - *m = open("/dev/ptmx", O_RDWR|O_NOCTTY);
2222 - if (*m < 0) return -1;
2223 + m = open("/dev/ptmx", O_RDWR|O_NOCTTY);
2224 + if (m < 0) return -1;
2226 - if (ioctl(*m, TIOCSPTLCK, &n) || ioctl (*m, TIOCGPTN, &n)) {
2230 + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
2232 + if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n))
2235 if (!name) name = buf;
2236 snprintf(name, sizeof buf, "/dev/pts/%d", n);
2237 - if ((*s = open(name, O_RDWR|O_NOCTTY)) < 0) {
2241 + if ((s = open(name, O_RDWR|O_NOCTTY)) < 0)
2244 + if (tio) tcsetattr(s, TCSANOW, tio);
2245 + if (ws) ioctl(s, TIOCSWINSZ, ws);
2247 - if (tio) tcsetattr(*s, TCSANOW, tio);
2248 - if (ws) ioctl(*s, TIOCSWINSZ, ws);
2252 + pthread_setcancelstate(cs, 0);
2256 + pthread_setcancelstate(cs, 0);
2259 --- a/src/misc/syslog.c
2260 +++ b/src/misc/syslog.c
2261 @@ -46,8 +46,12 @@ void closelog(void)
2263 static void __openlog()
2265 - log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
2266 - if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr);
2267 + int fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
2268 + if (fd < 0) return;
2269 + if (connect(fd, (void *)&log_addr, sizeof log_addr) < 0)
2275 void openlog(const char *ident, int opt, int facility)
2276 --- a/src/multibyte/c16rtomb.c
2277 +++ b/src/multibyte/c16rtomb.c
2280 size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps)
2282 + static unsigned internal_state;
2283 + if (!ps) ps = (void *)&internal_state;
2284 unsigned *x = (unsigned *)ps;
2287 --- a/src/multibyte/mbrtoc16.c
2288 +++ b/src/multibyte/mbrtoc16.c
2291 size_t mbrtoc16(char16_t *restrict pc16, const char *restrict s, size_t n, mbstate_t *restrict ps)
2293 + static unsigned internal_state;
2294 + if (!ps) ps = (void *)&internal_state;
2295 unsigned *pending = (unsigned *)ps;
2297 if (!s) return mbrtoc16(0, "", 1, ps);
2298 --- a/src/multibyte/mbrtoc32.c
2299 +++ b/src/multibyte/mbrtoc32.c
2302 size_t mbrtoc32(char32_t *restrict pc32, const char *restrict s, size_t n, mbstate_t *restrict ps)
2304 + static unsigned internal_state;
2305 + if (!ps) ps = (void *)&internal_state;
2306 if (!s) return mbrtoc32(0, "", 1, ps);
2308 size_t ret = mbrtowc(&wc, s, n, ps);
2309 --- a/src/multibyte/wcsnrtombs.c
2310 +++ b/src/multibyte/wcsnrtombs.c
2311 @@ -40,7 +40,7 @@ size_t wcsnrtombs(char *restrict dst, co
2313 /* safe - this loop runs fewer than sizeof(buf) times */
2321 +++ b/src/network/ns_parse.c
2323 +#define _BSD_SOURCE
2325 +#include <stddef.h>
2326 +#include <resolv.h>
2327 +#include <arpa/nameser.h>
2329 +const struct _ns_flagdata _ns_flagdata[16] = {
2348 +unsigned ns_get16(const unsigned char *cp)
2350 + return cp[0]<<8 | cp[1];
2353 +unsigned long ns_get32(const unsigned char *cp)
2355 + return (unsigned)cp[0]<<24 | cp[1]<<16 | cp[2]<<8 | cp[3];
2358 +void ns_put16(unsigned s, unsigned char *cp)
2364 +void ns_put32(unsigned long l, unsigned char *cp)
2372 +int ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle)
2376 + handle->_msg = msg;
2377 + handle->_eom = msg + msglen;
2378 + if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad;
2379 + NS_GET16(handle->_id, msg);
2380 + NS_GET16(handle->_flags, msg);
2381 + for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg);
2382 + for (i = 0; i < ns_s_max; i++) {
2383 + if (handle->_counts[i]) {
2384 + handle->_sections[i] = msg;
2385 + r = ns_skiprr(msg, handle->_eom, i, handle->_counts[i]);
2386 + if (r < 0) return -1;
2389 + handle->_sections[i] = NULL;
2392 + if (msg != handle->_eom) goto bad;
2393 + handle->_sect = ns_s_max;
2394 + handle->_rrnum = -1;
2395 + handle->_msg_ptr = NULL;
2402 +int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect section, int count)
2404 + const unsigned char *p = ptr;
2408 + r = dn_skipname(p, eom);
2409 + if (r < 0) goto bad;
2410 + if (r + 2 * NS_INT16SZ > eom - p) goto bad;
2411 + p += r + 2 * NS_INT16SZ;
2412 + if (section != ns_s_qd) {
2413 + if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad;
2416 + if (r > eom - p) goto bad;
2426 +int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr)
2430 + if (section < 0 || section >= ns_s_max) goto bad;
2431 + if (section != handle->_sect) {
2432 + handle->_sect = section;
2433 + handle->_rrnum = 0;
2434 + handle->_msg_ptr = handle->_sections[section];
2436 + if (rrnum == -1) rrnum = handle->_rrnum;
2437 + if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad;
2438 + if (rrnum < handle->_rrnum) {
2439 + handle->_rrnum = 0;
2440 + handle->_msg_ptr = handle->_sections[section];
2442 + if (rrnum > handle->_rrnum) {
2443 + r = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum);
2444 + if (r < 0) return -1;
2445 + handle->_msg_ptr += r;
2446 + handle->_rrnum = rrnum;
2448 + r = ns_name_uncompress(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME);
2449 + if (r < 0) return -1;
2450 + handle->_msg_ptr += r;
2451 + if (2 * NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size;
2452 + NS_GET16(rr->type, handle->_msg_ptr);
2453 + NS_GET16(rr->rr_class, handle->_msg_ptr);
2454 + if (section != ns_s_qd) {
2455 + if (NS_INT32SZ + NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size;
2456 + NS_GET32(rr->ttl, handle->_msg_ptr);
2457 + NS_GET16(rr->rdlength, handle->_msg_ptr);
2458 + if (rr->rdlength > handle->_eom - handle->_msg_ptr) goto size;
2459 + rr->rdata = handle->_msg_ptr;
2460 + handle->_msg_ptr += rr->rdlength;
2467 + if (handle->_rrnum > handle->_counts[section]) {
2468 + handle->_sect = section + 1;
2469 + if (handle->_sect == ns_s_max) {
2470 + handle->_rrnum = -1;
2471 + handle->_msg_ptr = NULL;
2473 + handle->_rrnum = 0;
2485 +int ns_name_uncompress(const unsigned char *msg, const unsigned char *eom,
2486 + const unsigned char *src, char *dst, size_t dstsiz)
2489 + r = dn_expand(msg, eom, src, dst, dstsiz);
2490 + if (r < 0) errno = EMSGSIZE;
2494 --- a/src/process/posix_spawn.c
2495 +++ b/src/process/posix_spawn.c
2496 @@ -102,8 +102,7 @@ static int child(void *args_vp)
2500 - if ((ret=__syscall(SYS_close, op->fd)))
2502 + __syscall(SYS_close, op->fd);
2505 if ((ret=__sys_dup2(op->srcfd, op->fd))<0)
2506 @@ -137,7 +136,7 @@ static int child(void *args_vp)
2508 /* Since sizeof errno < PIPE_BUF, the write is atomic. */
2510 - if (ret) while (write(p, &ret, sizeof ret) < 0);
2511 + if (ret) while (__syscall(SYS_write, p, &ret, sizeof ret) < 0);
2515 --- a/src/regex/fnmatch.c
2516 +++ b/src/regex/fnmatch.c
2517 @@ -97,7 +97,13 @@ escaped:
2521 -static int match_bracket(const char *p, int k)
2522 +static int casefold(int k)
2524 + int c = towupper(k);
2525 + return c == k ? towlower(k) : c;
2528 +static int match_bracket(const char *p, int k, int kfold)
2532 @@ -119,7 +125,10 @@ static int match_bracket(const char *p,
2534 int l = mbtowc(&wc2, p+1, 4);
2535 if (l < 0) return 0;
2536 - if (wc<=wc2 && (unsigned)k-wc <= wc2-wc) return !inv;
2538 + if ((unsigned)k-wc <= wc2-wc ||
2539 + (unsigned)kfold-wc <= wc2-wc)
2544 @@ -132,7 +141,9 @@ static int match_bracket(const char *p,
2546 memcpy(buf, p0, p-1-p0);
2548 - if (iswctype(k, wctype(buf))) return !inv;
2549 + if (iswctype(k, wctype(buf)) ||
2550 + iswctype(kfold, wctype(buf)))
2555 @@ -143,7 +154,7 @@ static int match_bracket(const char *p,
2556 if (l < 0) return 0;
2559 - if (wc==k) return !inv;
2560 + if (wc==k || wc==kfold) return !inv;
2564 @@ -153,7 +164,7 @@ static int fnmatch_internal(const char *
2565 const char *p, *ptail, *endpat;
2566 const char *s, *stail, *endstr;
2567 size_t pinc, sinc, tailcnt=0;
2571 if (flags & FNM_PERIOD) {
2572 if (*str == '.' && *pat != '.')
2573 @@ -173,10 +184,11 @@ static int fnmatch_internal(const char *
2574 return (c==END) ? 0 : FNM_NOMATCH;
2577 + kfold = flags & FNM_CASEFOLD ? casefold(k) : k;
2579 - if (!match_bracket(pat, k))
2580 + if (!match_bracket(pat, k, kfold))
2582 - } else if (c != QUESTION && k != c) {
2583 + } else if (c != QUESTION && k != c && kfold != c) {
2587 @@ -233,10 +245,11 @@ static int fnmatch_internal(const char *
2591 + kfold = flags & FNM_CASEFOLD ? casefold(k) : k;
2593 - if (!match_bracket(p-pinc, k))
2594 + if (!match_bracket(p-pinc, k, kfold))
2596 - } else if (c != QUESTION && k != c) {
2597 + } else if (c != QUESTION && k != c && kfold != c) {
2601 @@ -261,10 +274,11 @@ static int fnmatch_internal(const char *
2602 k = str_next(s, endstr-s, &sinc);
2605 + kfold = flags & FNM_CASEFOLD ? casefold(k) : k;
2607 - if (!match_bracket(p-pinc, k))
2608 + if (!match_bracket(p-pinc, k, kfold))
2610 - } else if (c != QUESTION && k != c) {
2611 + } else if (c != QUESTION && k != c && kfold != c) {
2615 --- a/src/sched/affinity.c
2616 +++ b/src/sched/affinity.c
2620 +#include <string.h>
2621 #include "pthread_impl.h"
2622 #include "syscall.h"
2624 @@ -10,17 +11,23 @@ int sched_setaffinity(pid_t tid, size_t
2626 int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
2628 - return syscall(SYS_sched_setaffinity, td->tid, size, set);
2629 + return -__syscall(SYS_sched_setaffinity, td->tid, size, set);
2632 -int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
2633 +static int do_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
2635 long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
2636 - if (ret > 0) ret = 0;
2637 - return __syscall_ret(ret);
2638 + if (ret < 0) return ret;
2639 + if (ret < size) memset((char *)set+ret, 0, size-ret);
2643 +int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
2645 + return __syscall_ret(do_getaffinity(tid, size, set));
2648 int pthread_getaffinity_np(pthread_t td, size_t size, cpu_set_t *set)
2650 - return sched_getaffinity(td->tid, size, set);
2651 + return -do_getaffinity(td->tid, size, set);
2653 --- a/src/setjmp/arm/longjmp.s
2654 +++ b/src/setjmp/arm/longjmp.s
2655 @@ -20,7 +20,7 @@ longjmp:
2656 ldc p2, cr4, [ip], #48
2659 - ldc p11, cr8, [ip], #64
2660 + .word 0xecbc8b10 /* vldmia ip!, {d8-d15} */
2663 ldcl p1, cr10, [ip], #8
2664 --- a/src/setjmp/arm/setjmp.s
2665 +++ b/src/setjmp/arm/setjmp.s
2666 @@ -22,7 +22,7 @@ setjmp:
2667 stc p2, cr4, [ip], #48
2670 - stc p11, cr8, [ip], #64
2671 + .word 0xecac8b10 /* vstmia ip!, {d8-d15} */
2674 stcl p1, cr10, [ip], #8
2675 --- a/src/signal/raise.c
2676 +++ b/src/signal/raise.c
2681 - int pid, tid, ret;
2684 __block_app_sigs(&set);
2685 tid = __syscall(SYS_gettid);
2686 - pid = __syscall(SYS_getpid);
2687 - ret = syscall(SYS_tgkill, pid, tid, sig);
2688 + ret = syscall(SYS_tkill, tid, sig);
2689 __restore_sigs(&set);
2692 --- a/src/stdio/vfprintf.c
2693 +++ b/src/stdio/vfprintf.c
2694 @@ -158,7 +158,7 @@ static void pop_arg(union arg *arg, int
2696 static void out(FILE *f, const char *s, size_t l)
2698 - __fwritex((void *)s, l, f);
2699 + if (!(f->flags & F_ERR)) __fwritex((void *)s, l, f);
2702 static void pad(FILE *f, char c, int w, int l, int fl)
2703 @@ -225,7 +225,7 @@ static int fmt_fp(FILE *f, long double y
2706 char *s = (t&32)?"inf":"INF";
2707 - if (y!=y) s=(t&32)?"nan":"NAN", pl=0;
2708 + if (y!=y) s=(t&32)?"nan":"NAN";
2709 pad(f, ' ', w, 3+pl, fl&~ZERO_PAD);
2712 @@ -570,7 +570,7 @@ static int printf_core(FILE *f, const ch
2715 a = fmt_o(arg.i, z);
2716 - if ((fl&ALT_FORM) && arg.i) prefix+=5, pl=1;
2717 + if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1;
2721 @@ -656,6 +656,7 @@ int vfprintf(FILE *restrict f, const cha
2722 int nl_type[NL_ARGMAX+1] = {0};
2723 union arg nl_arg[NL_ARGMAX+1];
2724 unsigned char internal_buf[80], *saved_buf = 0;
2728 /* the copy allows passing va_list* even if va_list is an array */
2729 @@ -666,6 +667,8 @@ int vfprintf(FILE *restrict f, const cha
2733 + olderr = f->flags & F_ERR;
2734 + if (f->mode < 1) f->flags &= ~F_ERR;
2737 f->wpos = f->wbase = f->buf = internal_buf;
2738 @@ -680,6 +683,8 @@ int vfprintf(FILE *restrict f, const cha
2740 f->wpos = f->wbase = f->wend = 0;
2742 + if (f->flags & F_ERR) ret = -1;
2743 + f->flags |= olderr;
2747 --- a/src/stdio/vfwprintf.c
2748 +++ b/src/stdio/vfwprintf.c
2749 @@ -149,7 +149,7 @@ static void pop_arg(union arg *arg, int
2751 static void out(FILE *f, const wchar_t *s, size_t l)
2753 - while (l--) fputwc(*s++, f);
2754 + while (l-- && !(f->flags & F_ERR)) fputwc(*s++, f);
2757 static int getint(wchar_t **s) {
2758 @@ -345,6 +345,7 @@ int vfwprintf(FILE *restrict f, const wc
2760 int nl_type[NL_ARGMAX] = {0};
2761 union arg nl_arg[NL_ARGMAX];
2765 /* the copy allows passing va_list* even if va_list is an array */
2766 @@ -356,7 +357,11 @@ int vfwprintf(FILE *restrict f, const wc
2769 f->mode |= f->mode+1;
2770 + olderr = f->flags & F_ERR;
2771 + f->flags &= ~F_ERR;
2772 ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type);
2773 + if (f->flags & F_ERR) ret = -1;
2774 + f->flags |= olderr;
2778 --- a/src/string/armel/memcpy.s
2779 +++ b/src/string/armel/memcpy.s
2780 @@ -49,113 +49,113 @@ memcpy:
2781 * ARM ABI. Since we have to save R0, we might as well save R4
2782 * which we can use for better pipelining of the reads below
2785 - .save {r0, r4, lr}
2786 - stmfd sp!, {r0, r4, lr}
2787 - /* Making room for r5-r11 which will be spilled later */
2791 - /* it simplifies things to take care of len<4 early */
2793 - blo copy_last_3_and_return
2795 - /* compute the offset to align the source
2796 - * offset = (4-(src&3))&3 = -src & 3
2802 - /* align source to 32 bits. We need to insert 2 instructions between
2803 - * a ldr[b|h] and str[b|h] because byte and half-word instructions
2806 - movs r12, r3, lsl #31
2807 - sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
2808 - ldrmib r3, [r1], #1
2809 - ldrcsb r4, [r1], #1
2810 - ldrcsb r12,[r1], #1
2811 - strmib r3, [r0], #1
2812 - strcsb r4, [r0], #1
2813 - strcsb r12,[r0], #1
2815 + .save {r0, r4, lr}
2816 + stmfd sp!, {r0, r4, lr}
2817 + /* Making room for r5-r11 which will be spilled later */
2821 + /* it simplifies things to take care of len<4 early */
2823 + blo copy_last_3_and_return
2825 + /* compute the offset to align the source
2826 + * offset = (4-(src&3))&3 = -src & 3
2832 + /* align source to 32 bits. We need to insert 2 instructions between
2833 + * a ldr[b|h] and str[b|h] because byte and half-word instructions
2836 + movs r12, r3, lsl #31
2837 + sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
2838 + .word 0x44d13001 /* ldrbmi r3, [r1], #1 */
2839 + .word 0x24d14001 /* ldrbcs r4, [r1], #1 */
2840 + .word 0x24d1c001 /* ldrbcs r12,[r1], #1 */
2841 + .word 0x44c03001 /* strbmi r3, [r0], #1 */
2842 + .word 0x24c04001 /* strbcs r4, [r0], #1 */
2843 + .word 0x24c0c001 /* strbcs r12,[r0], #1 */
2847 /* see if src and dst are aligned together (congruent) */
2852 - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
2853 - * frame. Don't update sp.
2855 - stmea sp, {r5-r11}
2857 - /* align the destination to a cache-line */
2859 - ands r3, r3, #0x1C
2860 - beq congruent_aligned32
2862 - andhi r3, r2, #0x1C
2864 - /* conditionnaly copies 0 to 7 words (length in r3) */
2865 - movs r12, r3, lsl #28
2866 - ldmcsia r1!, {r4, r5, r6, r7} /* 16 bytes */
2867 - ldmmiia r1!, {r8, r9} /* 8 bytes */
2868 - stmcsia r0!, {r4, r5, r6, r7}
2869 - stmmiia r0!, {r8, r9}
2871 - ldrne r10,[r1], #4 /* 4 bytes */
2872 - strne r10,[r0], #4
2878 + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
2879 + * frame. Don't update sp.
2881 + stmea sp, {r5-r11}
2883 + /* align the destination to a cache-line */
2885 + ands r3, r3, #0x1C
2886 + beq congruent_aligned32
2888 + andhi r3, r2, #0x1C
2890 + /* conditionnaly copies 0 to 7 words (length in r3) */
2891 + movs r12, r3, lsl #28
2892 + ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
2893 + ldmmi r1!, {r8, r9} /* 8 bytes */
2894 + stmcs r0!, {r4, r5, r6, r7}
2895 + stmmi r0!, {r8, r9}
2897 + ldrne r10,[r1], #4 /* 4 bytes */
2898 + strne r10,[r0], #4
2901 congruent_aligned32:
2903 - * here source is aligned to 32 bytes.
2905 + * here source is aligned to 32 bytes.
2910 - blo less_than_32_left
2912 + blo less_than_32_left
2915 - * We preload a cache-line up to 64 bytes ahead. On the 926, this will
2916 - * stall only until the requested world is fetched, but the linefill
2917 - * continues in the the background.
2918 - * While the linefill is going, we write our previous cache-line
2919 - * into the write-buffer (which should have some free space).
2920 - * When the linefill is done, the writebuffer will
2921 - * start dumping its content into memory
2923 - * While all this is going, we then load a full cache line into
2924 - * 8 registers, this cache line should be in the cache by now
2925 - * (or partly in the cache).
2927 - * This code should work well regardless of the source/dest alignment.
2931 - /* Align the preload register to a cache-line because the cpu does
2932 - * "critical word first" (the first word requested is loaded first).
2934 - @ bic r12, r1, #0x1F
2935 - @ add r12, r12, #64
2937 -1: ldmia r1!, { r4-r11 }
2941 - * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi
2942 - * for ARM9 preload will not be safely guarded by the preceding subs.
2943 - * When it is safely guarded the only possibility to have SIGSEGV here
2944 - * is because the caller overstates the length.
2946 - @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
2947 - stmia r0!, { r4-r11 }
2950 + * We preload a cache-line up to 64 bytes ahead. On the 926, this will
2951 + * stall only until the requested world is fetched, but the linefill
2952 + * continues in the the background.
2953 + * While the linefill is going, we write our previous cache-line
2954 + * into the write-buffer (which should have some free space).
2955 + * When the linefill is done, the writebuffer will
2956 + * start dumping its content into memory
2958 + * While all this is going, we then load a full cache line into
2959 + * 8 registers, this cache line should be in the cache by now
2960 + * (or partly in the cache).
2962 + * This code should work well regardless of the source/dest alignment.
2967 + /* Align the preload register to a cache-line because the cpu does
2968 + * "critical word first" (the first word requested is loaded first).
2970 + @ bic r12, r1, #0x1F
2971 + @ add r12, r12, #64
2973 +1: ldmia r1!, { r4-r11 }
2977 + * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi
2978 + * for ARM9 preload will not be safely guarded by the preceding subs.
2979 + * When it is safely guarded the only possibility to have SIGSEGV here
2980 + * is because the caller overstates the length.
2982 + @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
2983 + stmia r0!, { r4-r11 }
2990 @@ -166,30 +166,30 @@ less_than_32_left:
2991 * be a common case (if not executed the code below takes
2999 - /* conditionnaly copies 0 to 31 bytes */
3000 - movs r12, r2, lsl #28
3001 - ldmcsia r1!, {r4, r5, r6, r7} /* 16 bytes */
3002 - ldmmiia r1!, {r8, r9} /* 8 bytes */
3003 - stmcsia r0!, {r4, r5, r6, r7}
3004 - stmmiia r0!, {r8, r9}
3005 - movs r12, r2, lsl #30
3006 - ldrcs r3, [r1], #4 /* 4 bytes */
3007 - ldrmih r4, [r1], #2 /* 2 bytes */
3008 - strcs r3, [r0], #4
3009 - strmih r4, [r0], #2
3011 - ldrneb r3, [r1] /* last byte */
3014 - /* we're done! restore everything and return */
3015 -1: ldmfd sp!, {r5-r11}
3016 - ldmfd sp!, {r0, r4, lr}
3020 + /* conditionnaly copies 0 to 31 bytes */
3021 + movs r12, r2, lsl #28
3022 + ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
3023 + ldmmi r1!, {r8, r9} /* 8 bytes */
3024 + stmcs r0!, {r4, r5, r6, r7}
3025 + stmmi r0!, {r8, r9}
3026 + movs r12, r2, lsl #30
3027 + ldrcs r3, [r1], #4 /* 4 bytes */
3028 + .word 0x40d140b2 /* ldrhmi r4, [r1], #2 */ /* 2 bytes */
3029 + strcs r3, [r0], #4
3030 + .word 0x40c040b2 /* strhmi r4, [r0], #2 */
3032 + .word 0x15d13000 /* ldrbne r3, [r1] */ /* last byte */
3033 + .word 0x15c03000 /* strbne r3, [r0] */
3035 + /* we're done! restore everything and return */
3036 +1: ldmfd sp!, {r5-r11}
3037 + ldmfd sp!, {r0, r4, lr}
3042 /********************************************************************/
3044 @@ -202,180 +202,180 @@ non_congruent:
3045 * (the number of bytes written is always smaller, because we have
3046 * partial words in the shift queue)
3049 - blo copy_last_3_and_return
3051 + blo copy_last_3_and_return
3053 - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
3054 - * frame. Don't update sp.
3056 - stmea sp, {r5-r11}
3058 - /* compute shifts needed to align src to dest */
3060 - and r5, r5, #3 /* r5 = # bytes in partial words */
3061 - mov r12, r5, lsl #3 /* r12 = right */
3062 - rsb lr, r12, #32 /* lr = left */
3064 - /* read the first word */
3068 - /* write a partial word (0 to 3 bytes), such that destination
3069 - * becomes aligned to 32 bits (r5 = nb of words to copy for alignment)
3071 - movs r5, r5, lsl #31
3072 - strmib r3, [r0], #1
3073 - movmi r3, r3, lsr #8
3074 - strcsb r3, [r0], #1
3075 - movcs r3, r3, lsr #8
3076 - strcsb r3, [r0], #1
3077 - movcs r3, r3, lsr #8
3080 - blo partial_word_tail
3082 - /* Align destination to 32 bytes (cache line boundary) */
3087 - orr r4, r3, r5, lsl lr
3088 - mov r3, r5, lsr r12
3092 - blo partial_word_tail
3093 + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
3094 + * frame. Don't update sp.
3096 + stmea sp, {r5-r11}
3098 + /* compute shifts needed to align src to dest */
3100 + and r5, r5, #3 /* r5 = # bytes in partial words */
3101 + mov r12, r5, lsl #3 /* r12 = right */
3102 + rsb lr, r12, #32 /* lr = left */
3104 + /* read the first word */
3108 + /* write a partial word (0 to 3 bytes), such that destination
3109 + * becomes aligned to 32 bits (r5 = nb of words to copy for alignment)
3111 + movs r5, r5, lsl #31
3112 + .word 0x44c03001 /* strbmi r3, [r0], #1 */
3113 + movmi r3, r3, lsr #8
3114 + .word 0x24c03001 /* strbcs r3, [r0], #1 */
3115 + movcs r3, r3, lsr #8
3116 + .word 0x24c03001 /* strbcs r3, [r0], #1 */
3117 + movcs r3, r3, lsr #8
3120 + blo partial_word_tail
3122 + /* Align destination to 32 bytes (cache line boundary) */
3127 + orr r4, r3, r5, lsl lr
3128 + mov r3, r5, lsr r12
3132 + blo partial_word_tail
3134 /* copy 32 bytes at a time */
3135 -2: subs r2, r2, #32
3136 - blo less_than_thirtytwo
3137 +2: subs r2, r2, #32
3138 + blo less_than_thirtytwo
3140 + /* Use immediate mode for the shifts, because there is an extra cycle
3141 + * for register shifts, which could account for up to 50% of
3142 + * performance hit.
3145 - /* Use immediate mode for the shifts, because there is an extra cycle
3146 - * for register shifts, which could account for up to 50% of
3147 - * performance hit.
3162 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
3164 - ldrhs r12, [r1], #4
3165 - orr r3, r3, r4, lsl #16
3166 - mov r4, r4, lsr #16
3167 - orr r4, r4, r5, lsl #16
3168 - mov r5, r5, lsr #16
3169 - orr r5, r5, r6, lsl #16
3170 - mov r6, r6, lsr #16
3171 - orr r6, r6, r7, lsl #16
3172 - mov r7, r7, lsr #16
3173 - orr r7, r7, r8, lsl #16
3174 - mov r8, r8, lsr #16
3175 - orr r8, r8, r9, lsl #16
3176 - mov r9, r9, lsr #16
3177 - orr r9, r9, r10, lsl #16
3178 - mov r10, r10, lsr #16
3179 - orr r10, r10, r11, lsl #16
3180 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
3181 - mov r3, r11, lsr #16
3183 - b less_than_thirtytwo
3186 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
3188 + ldrhs r12, [r1], #4
3189 + orr r3, r3, r4, lsl #16
3190 + mov r4, r4, lsr #16
3191 + orr r4, r4, r5, lsl #16
3192 + mov r5, r5, lsr #16
3193 + orr r5, r5, r6, lsl #16
3194 + mov r6, r6, lsr #16
3195 + orr r6, r6, r7, lsl #16
3196 + mov r7, r7, lsr #16
3197 + orr r7, r7, r8, lsl #16
3198 + mov r8, r8, lsr #16
3199 + orr r8, r8, r9, lsl #16
3200 + mov r9, r9, lsr #16
3201 + orr r9, r9, r10, lsl #16
3202 + mov r10, r10, lsr #16
3203 + orr r10, r10, r11, lsl #16
3204 + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
3205 + mov r3, r11, lsr #16
3207 + b less_than_thirtytwo
3212 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
3214 - ldrhs r12, [r1], #4
3215 - orr r3, r3, r4, lsl #24
3216 - mov r4, r4, lsr #8
3217 - orr r4, r4, r5, lsl #24
3218 - mov r5, r5, lsr #8
3219 - orr r5, r5, r6, lsl #24
3220 - mov r6, r6, lsr #8
3221 - orr r6, r6, r7, lsl #24
3222 - mov r7, r7, lsr #8
3223 - orr r7, r7, r8, lsl #24
3224 - mov r8, r8, lsr #8
3225 - orr r8, r8, r9, lsl #24
3226 - mov r9, r9, lsr #8
3227 - orr r9, r9, r10, lsl #24
3228 - mov r10, r10, lsr #8
3229 - orr r10, r10, r11, lsl #24
3230 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
3231 - mov r3, r11, lsr #8
3233 - b less_than_thirtytwo
3236 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
3238 + ldrhs r12, [r1], #4
3239 + orr r3, r3, r4, lsl #24
3240 + mov r4, r4, lsr #8
3241 + orr r4, r4, r5, lsl #24
3242 + mov r5, r5, lsr #8
3243 + orr r5, r5, r6, lsl #24
3244 + mov r6, r6, lsr #8
3245 + orr r6, r6, r7, lsl #24
3246 + mov r7, r7, lsr #8
3247 + orr r7, r7, r8, lsl #24
3248 + mov r8, r8, lsr #8
3249 + orr r8, r8, r9, lsl #24
3250 + mov r9, r9, lsr #8
3251 + orr r9, r9, r10, lsl #24
3252 + mov r10, r10, lsr #8
3253 + orr r10, r10, r11, lsl #24
3254 + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
3255 + mov r3, r11, lsr #8
3257 + b less_than_thirtytwo
3262 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
3264 - ldrhs r12, [r1], #4
3265 - orr r3, r3, r4, lsl #8
3266 - mov r4, r4, lsr #24
3267 - orr r4, r4, r5, lsl #8
3268 - mov r5, r5, lsr #24
3269 - orr r5, r5, r6, lsl #8
3270 - mov r6, r6, lsr #24
3271 - orr r6, r6, r7, lsl #8
3272 - mov r7, r7, lsr #24
3273 - orr r7, r7, r8, lsl #8
3274 - mov r8, r8, lsr #24
3275 - orr r8, r8, r9, lsl #8
3276 - mov r9, r9, lsr #24
3277 - orr r9, r9, r10, lsl #8
3278 - mov r10, r10, lsr #24
3279 - orr r10, r10, r11, lsl #8
3280 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
3281 - mov r3, r11, lsr #24
3285 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
3287 + ldrhs r12, [r1], #4
3288 + orr r3, r3, r4, lsl #8
3289 + mov r4, r4, lsr #24
3290 + orr r4, r4, r5, lsl #8
3291 + mov r5, r5, lsr #24
3292 + orr r5, r5, r6, lsl #8
3293 + mov r6, r6, lsr #24
3294 + orr r6, r6, r7, lsl #8
3295 + mov r7, r7, lsr #24
3296 + orr r7, r7, r8, lsl #8
3297 + mov r8, r8, lsr #24
3298 + orr r8, r8, r9, lsl #8
3299 + mov r9, r9, lsr #24
3300 + orr r9, r9, r10, lsl #8
3301 + mov r10, r10, lsr #24
3302 + orr r10, r10, r11, lsl #8
3303 + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
3304 + mov r3, r11, lsr #24
3307 less_than_thirtytwo:
3308 /* copy the last 0 to 31 bytes of the source */
3309 - rsb r12, lr, #32 /* we corrupted r12, recompute it */
3312 - blo partial_word_tail
3314 -1: ldr r5, [r1], #4
3316 - orr r4, r3, r5, lsl lr
3317 - mov r3, r5, lsr r12
3321 + rsb r12, lr, #32 /* we corrupted r12, recompute it */
3324 + blo partial_word_tail
3326 +1: ldr r5, [r1], #4
3328 + orr r4, r3, r5, lsl lr
3329 + mov r3, r5, lsr r12
3335 /* we have a partial word in the input buffer */
3336 - movs r5, lr, lsl #(31-3)
3337 - strmib r3, [r0], #1
3338 - movmi r3, r3, lsr #8
3339 - strcsb r3, [r0], #1
3340 - movcs r3, r3, lsr #8
3341 - strcsb r3, [r0], #1
3342 + movs r5, lr, lsl #(31-3)
3343 + .word 0x44c03001 /* strbmi r3, [r0], #1 */
3344 + movmi r3, r3, lsr #8
3345 + .word 0x24c03001 /* strbcs r3, [r0], #1 */
3346 + movcs r3, r3, lsr #8
3347 + .word 0x24c03001 /* strbcs r3, [r0], #1 */
3349 - /* Refill spilled registers from the stack. Don't update sp. */
3350 - ldmfd sp, {r5-r11}
3351 + /* Refill spilled registers from the stack. Don't update sp. */
3352 + ldmfd sp, {r5-r11}
3354 copy_last_3_and_return:
3355 - movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */
3356 - ldrmib r2, [r1], #1
3357 - ldrcsb r3, [r1], #1
3359 - strmib r2, [r0], #1
3360 - strcsb r3, [r0], #1
3363 - /* we're done! restore sp and spilled registers and return */
3365 - ldmfd sp!, {r0, r4, lr}
3369 + movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */
3370 + .word 0x44d12001 /* ldrbmi r2, [r1], #1 */
3371 + .word 0x24d13001 /* ldrbcs r3, [r1], #1 */
3372 + .word 0x25d1c000 /* ldrbcs r12,[r1] */
3373 + .word 0x44c02001 /* strbmi r2, [r0], #1 */
3374 + .word 0x24c03001 /* strbcs r3, [r0], #1 */
3375 + .word 0x25c0c000 /* strbcs r12,[r0] */
3377 + /* we're done! restore sp and spilled registers and return */
3379 + ldmfd sp!, {r0, r4, lr}
3383 --- a/src/thread/arm/__set_thread_area.s
3384 +++ b/src/thread/arm/__set_thread_area.s
3387 -.global __set_thread_area
3388 -.type __set_thread_area,%function
3398 +/* Replaced by C code in arch/arm/src */
3399 --- a/src/thread/arm/tls.s
3402 -.global __aeabi_read_tp
3403 -.type __aeabi_read_tp,%function
3405 - ldr pc,=0xffff0fe0
3406 --- a/src/thread/pthread_once.c
3407 +++ b/src/thread/pthread_once.c
3408 @@ -8,15 +8,8 @@ static void undo(void *control)
3409 __wake(control, -1, 1);
3412 -int __pthread_once(pthread_once_t *control, void (*init)(void))
3413 +int __pthread_once_full(pthread_once_t *control, void (*init)(void))
3415 - /* Return immediately if init finished before, but ensure that
3416 - * effects of the init routine are visible to the caller. */
3417 - if (*control == 2) {
3422 /* Try to enter initializing state. Four possibilities:
3423 * 0 - we're the first or the other cancelled; run init
3424 * 1 - another thread is running init; wait
3425 @@ -43,4 +36,15 @@ int __pthread_once(pthread_once_t *contr
3429 +int __pthread_once(pthread_once_t *control, void (*init)(void))
3431 + /* Return immediately if init finished before, but ensure that
3432 + * effects of the init routine are visible to the caller. */
3433 + if (*control == 2) {
3437 + return __pthread_once_full(control, init);
3440 weak_alias(__pthread_once, pthread_once);