Start mass upgrade
[dragora.git] / patches / musl / branch-updates.diff
blob07724d34b3ceedf2af89be7400e645c26f9553a7
1 diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h
2 index 7ab73f99..424cc4d4 100644
3 --- a/arch/aarch64/bits/hwcap.h
4 +++ b/arch/aarch64/bits/hwcap.h
5 @@ -48,3 +48,5 @@
6 #define HWCAP2_BF16 (1 << 14)
7 #define HWCAP2_DGH (1 << 15)
8 #define HWCAP2_RNG (1 << 16)
9 +#define HWCAP2_BTI (1 << 17)
10 +#define HWCAP2_MTE (1 << 18)
11 diff --git a/arch/aarch64/bits/mman.h b/arch/aarch64/bits/mman.h
12 new file mode 100644
13 index 00000000..8fad5ceb
14 --- /dev/null
15 +++ b/arch/aarch64/bits/mman.h
16 @@ -0,0 +1,2 @@
17 +#define PROT_BTI 0x10
18 +#define PROT_MTE 0x20
19 diff --git a/arch/aarch64/bits/syscall.h.in b/arch/aarch64/bits/syscall.h.in
20 index f9457c18..1ad467c0 100644
21 --- a/arch/aarch64/bits/syscall.h.in
22 +++ b/arch/aarch64/bits/syscall.h.in
23 @@ -293,4 +293,5 @@
24 #define __NR_openat2 437
25 #define __NR_pidfd_getfd 438
26 #define __NR_faccessat2 439
27 +#define __NR_process_madvise 440
29 diff --git a/arch/arm/bits/syscall.h.in b/arch/arm/bits/syscall.h.in
30 index 7e2fc266..cf9e3411 100644
31 --- a/arch/arm/bits/syscall.h.in
32 +++ b/arch/arm/bits/syscall.h.in
33 @@ -393,6 +393,7 @@
34 #define __NR_openat2 437
35 #define __NR_pidfd_getfd 438
36 #define __NR_faccessat2 439
37 +#define __NR_process_madvise 440
39 #define __ARM_NR_breakpoint 0x0f0001
40 #define __ARM_NR_cacheflush 0x0f0002
41 diff --git a/arch/i386/bits/syscall.h.in b/arch/i386/bits/syscall.h.in
42 index abdb210d..5d1c4d7a 100644
43 --- a/arch/i386/bits/syscall.h.in
44 +++ b/arch/i386/bits/syscall.h.in
45 @@ -430,4 +430,5 @@
46 #define __NR_openat2 437
47 #define __NR_pidfd_getfd 438
48 #define __NR_faccessat2 439
49 +#define __NR_process_madvise 440
51 diff --git a/arch/m68k/bits/syscall.h.in b/arch/m68k/bits/syscall.h.in
52 index e10969a2..6794b1a0 100644
53 --- a/arch/m68k/bits/syscall.h.in
54 +++ b/arch/m68k/bits/syscall.h.in
55 @@ -410,3 +410,4 @@
56 #define __NR_openat2 437
57 #define __NR_pidfd_getfd 438
58 #define __NR_faccessat2 439
59 +#define __NR_process_madvise 440
60 diff --git a/arch/microblaze/bits/syscall.h.in b/arch/microblaze/bits/syscall.h.in
61 index 9d469047..7f71df3b 100644
62 --- a/arch/microblaze/bits/syscall.h.in
63 +++ b/arch/microblaze/bits/syscall.h.in
64 @@ -431,4 +431,5 @@
65 #define __NR_openat2 437
66 #define __NR_pidfd_getfd 438
67 #define __NR_faccessat2 439
68 +#define __NR_process_madvise 440
70 diff --git a/arch/mips/bits/syscall.h.in b/arch/mips/bits/syscall.h.in
71 index 2bb03f06..d54845b2 100644
72 --- a/arch/mips/bits/syscall.h.in
73 +++ b/arch/mips/bits/syscall.h.in
74 @@ -412,4 +412,5 @@
75 #define __NR_openat2 4437
76 #define __NR_pidfd_getfd 4438
77 #define __NR_faccessat2 4439
78 +#define __NR_process_madvise 4440
80 diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h
81 index c45347ab..376b7741 100644
82 --- a/arch/mips/pthread_arch.h
83 +++ b/arch/mips/pthread_arch.h
84 @@ -1,10 +1,9 @@
85 static inline uintptr_t __get_tp()
87 -#if __mips_isa_rev < 2
88 register uintptr_t tp __asm__("$3");
89 +#if __mips_isa_rev < 2
90 __asm__ (".word 0x7c03e83b" : "=r" (tp) );
91 #else
92 - uintptr_t tp;
93 __asm__ ("rdhwr %0, $29" : "=r" (tp) );
94 #endif
95 return tp;
96 diff --git a/arch/mips64/bits/syscall.h.in b/arch/mips64/bits/syscall.h.in
97 index 045e8238..920b4358 100644
98 --- a/arch/mips64/bits/syscall.h.in
99 +++ b/arch/mips64/bits/syscall.h.in
100 @@ -342,4 +342,5 @@
101 #define __NR_openat2 5437
102 #define __NR_pidfd_getfd 5438
103 #define __NR_faccessat2 5439
104 +#define __NR_process_madvise 5440
106 diff --git a/arch/mipsn32/bits/syscall.h.in b/arch/mipsn32/bits/syscall.h.in
107 index 5b322558..e6dad688 100644
108 --- a/arch/mipsn32/bits/syscall.h.in
109 +++ b/arch/mipsn32/bits/syscall.h.in
110 @@ -366,4 +366,5 @@
111 #define __NR_openat2 6437
112 #define __NR_pidfd_getfd 6438
113 #define __NR_faccessat2 6439
114 +#define __NR_process_madvise 6440
116 diff --git a/arch/or1k/bits/syscall.h.in b/arch/or1k/bits/syscall.h.in
117 index b3603891..463ee901 100644
118 --- a/arch/or1k/bits/syscall.h.in
119 +++ b/arch/or1k/bits/syscall.h.in
120 @@ -315,4 +315,5 @@
121 #define __NR_openat2 437
122 #define __NR_pidfd_getfd 438
123 #define __NR_faccessat2 439
124 +#define __NR_process_madvise 440
126 diff --git a/arch/powerpc/bits/fenv.h b/arch/powerpc/bits/fenv.h
127 index c5a3e5c5..5b15c69a 100644
128 --- a/arch/powerpc/bits/fenv.h
129 +++ b/arch/powerpc/bits/fenv.h
130 @@ -1,4 +1,4 @@
131 -#ifdef _SOFT_FLOAT
132 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
133 #define FE_ALL_EXCEPT 0
134 #define FE_TONEAREST 0
135 #else
136 diff --git a/arch/powerpc/bits/shm.h b/arch/powerpc/bits/shm.h
137 index fb1d4020..7f1ca17e 100644
138 --- a/arch/powerpc/bits/shm.h
139 +++ b/arch/powerpc/bits/shm.h
140 @@ -8,11 +8,11 @@ struct shmid_ds {
141 unsigned long __shm_dtime_lo;
142 unsigned long __shm_ctime_hi;
143 unsigned long __shm_ctime_lo;
144 + unsigned long __pad1;
145 size_t shm_segsz;
146 pid_t shm_cpid;
147 pid_t shm_lpid;
148 unsigned long shm_nattch;
149 - unsigned long __pad1;
150 unsigned long __pad2;
151 time_t shm_atime;
152 time_t shm_dtime;
153 diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in
154 index 5c6fae3e..db4d0ca4 100644
155 --- a/arch/powerpc/bits/syscall.h.in
156 +++ b/arch/powerpc/bits/syscall.h.in
157 @@ -419,4 +419,5 @@
158 #define __NR_openat2 437
159 #define __NR_pidfd_getfd 438
160 #define __NR_faccessat2 439
161 +#define __NR_process_madvise 440
163 diff --git a/arch/powerpc/reloc.h b/arch/powerpc/reloc.h
164 index 527b6b7c..fdfbf827 100644
165 --- a/arch/powerpc/reloc.h
166 +++ b/arch/powerpc/reloc.h
167 @@ -1,4 +1,4 @@
168 -#ifdef _SOFT_FLOAT
169 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
170 #define FP_SUFFIX "-sf"
171 #else
172 #define FP_SUFFIX ""
173 diff --git a/arch/powerpc64/bits/syscall.h.in b/arch/powerpc64/bits/syscall.h.in
174 index edf73d3d..a128890b 100644
175 --- a/arch/powerpc64/bits/syscall.h.in
176 +++ b/arch/powerpc64/bits/syscall.h.in
177 @@ -391,4 +391,5 @@
178 #define __NR_openat2 437
179 #define __NR_pidfd_getfd 438
180 #define __NR_faccessat2 439
181 +#define __NR_process_madvise 440
183 diff --git a/arch/riscv64/bits/syscall.h.in b/arch/riscv64/bits/syscall.h.in
184 index 5def016b..39c0d650 100644
185 --- a/arch/riscv64/bits/syscall.h.in
186 +++ b/arch/riscv64/bits/syscall.h.in
187 @@ -76,7 +76,7 @@
188 #define __NR_splice 76
189 #define __NR_tee 77
190 #define __NR_readlinkat 78
191 -#define __NR_fstatat 79
192 +#define __NR_newfstatat 79
193 #define __NR_fstat 80
194 #define __NR_sync 81
195 #define __NR_fsync 82
196 @@ -293,6 +293,7 @@
197 #define __NR_openat2 437
198 #define __NR_pidfd_getfd 438
199 #define __NR_faccessat2 439
200 +#define __NR_process_madvise 440
202 #define __NR_sysriscv __NR_arch_specific_syscall
203 #define __NR_riscv_flush_icache (__NR_sysriscv + 15)
204 diff --git a/arch/riscv64/bits/user.h b/arch/riscv64/bits/user.h
205 index 2da743ea..0d37de0b 100644
206 --- a/arch/riscv64/bits/user.h
207 +++ b/arch/riscv64/bits/user.h
208 @@ -1,5 +1,6 @@
209 #include <signal.h>
211 #define ELF_NGREG 32
212 +#define ELF_NFPREG 33
213 typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];
214 typedef union __riscv_mc_fp_state elf_fpregset_t;
215 diff --git a/arch/s390x/bits/syscall.h.in b/arch/s390x/bits/syscall.h.in
216 index fb2e60e3..9c8d984e 100644
217 --- a/arch/s390x/bits/syscall.h.in
218 +++ b/arch/s390x/bits/syscall.h.in
219 @@ -356,4 +356,5 @@
220 #define __NR_openat2 437
221 #define __NR_pidfd_getfd 438
222 #define __NR_faccessat2 439
223 +#define __NR_process_madvise 440
225 diff --git a/arch/sh/bits/syscall.h.in b/arch/sh/bits/syscall.h.in
226 index 158afc09..17dd7e07 100644
227 --- a/arch/sh/bits/syscall.h.in
228 +++ b/arch/sh/bits/syscall.h.in
229 @@ -403,4 +403,5 @@
230 #define __NR_openat2 437
231 #define __NR_pidfd_getfd 438
232 #define __NR_faccessat2 439
233 +#define __NR_process_madvise 440
235 diff --git a/arch/x32/bits/syscall.h.in b/arch/x32/bits/syscall.h.in
236 index cfd9856f..5361442e 100644
237 --- a/arch/x32/bits/syscall.h.in
238 +++ b/arch/x32/bits/syscall.h.in
239 @@ -302,6 +302,7 @@
240 #define __NR_openat2 (0x40000000 + 437)
241 #define __NR_pidfd_getfd (0x40000000 + 438)
242 #define __NR_faccessat2 (0x40000000 + 439)
243 +#define __NR_process_madvise (0x40000000 + 440)
246 #define __NR_rt_sigaction (0x40000000 + 512)
247 diff --git a/arch/x86_64/bits/syscall.h.in b/arch/x86_64/bits/syscall.h.in
248 index a6117951..e943883d 100644
249 --- a/arch/x86_64/bits/syscall.h.in
250 +++ b/arch/x86_64/bits/syscall.h.in
251 @@ -349,4 +349,5 @@
252 #define __NR_openat2 437
253 #define __NR_pidfd_getfd 438
254 #define __NR_faccessat2 439
255 +#define __NR_process_madvise 440
257 diff --git a/configure b/configure
258 index a5231a0e..ca5cbc0b 100755
259 --- a/configure
260 +++ b/configure
261 @@ -409,7 +409,7 @@ test "$debug" = yes && CFLAGS_AUTO=-g
263 printf "checking whether we should preprocess assembly to add debugging information... "
264 if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" &&
265 - test -f "tools/add-cfi.$ARCH.awk" &&
266 + test -f "$srcdir/tools/add-cfi.$ARCH.awk" &&
267 printf ".file 1 \"srcfile.s\"\n.line 1\n.cfi_startproc\n.cfi_endproc" | $CC -g -x assembler -c -o /dev/null 2>/dev/null -
268 then
269 ADD_CFI=yes
270 @@ -671,9 +671,7 @@ trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
273 if test "$ARCH" = "powerpc" ; then
274 -trycppif "__NO_FPRS__ && !_SOFT_FLOAT" "$t" && fail \
275 - "$0: error: compiler's floating point configuration is unsupported"
276 -trycppif _SOFT_FLOAT "$t" && SUBARCH=${SUBARCH}-sf
277 +trycppif "_SOFT_FLOAT || __NO_FPRS__" "$t" && SUBARCH=${SUBARCH}-sf
278 printf "checking whether compiler can use 'd' constraint in asm... "
279 echo 'double f(double x) { __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); return x; }' > "$tmpc"
280 if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
281 diff --git a/include/ctype.h b/include/ctype.h
282 index 7936536f..32bcef4d 100644
283 --- a/include/ctype.h
284 +++ b/include/ctype.h
285 @@ -64,7 +64,9 @@ int isascii(int);
286 int toascii(int);
287 #define _tolower(a) ((a)|0x20)
288 #define _toupper(a) ((a)&0x5f)
289 +#ifndef __cplusplus
290 #define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128)
291 +#endif
293 #endif
295 diff --git a/include/elf.h b/include/elf.h
296 index b5e7befb..5170f3e2 100644
297 --- a/include/elf.h
298 +++ b/include/elf.h
299 @@ -686,6 +686,7 @@ typedef struct {
300 #define NT_ARM_PAC_MASK 0x406
301 #define NT_ARM_PACA_KEYS 0x407
302 #define NT_ARM_PACG_KEYS 0x408
303 +#define NT_ARM_TAGGED_ADDR_CTRL 0x409
304 #define NT_METAG_CBUF 0x500
305 #define NT_METAG_RPIPE 0x501
306 #define NT_METAG_TLS 0x502
307 diff --git a/include/locale.h b/include/locale.h
308 index ce384381..11106fea 100644
309 --- a/include/locale.h
310 +++ b/include/locale.h
311 @@ -7,7 +7,9 @@ extern "C" {
313 #include <features.h>
315 -#ifdef __cplusplus
316 +#if __cplusplus >= 201103L
317 +#define NULL nullptr
318 +#elif defined(__cplusplus)
319 #define NULL 0L
320 #else
321 #define NULL ((void*)0)
322 diff --git a/include/pthread.h b/include/pthread.h
323 index 0492f26a..89fd9ff7 100644
324 --- a/include/pthread.h
325 +++ b/include/pthread.h
326 @@ -221,6 +221,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
327 int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
328 int pthread_getattr_np(pthread_t, pthread_attr_t *);
329 int pthread_setname_np(pthread_t, const char *);
330 +int pthread_getname_np(pthread_t, char *, size_t);
331 int pthread_getattr_default_np(pthread_attr_t *);
332 int pthread_setattr_default_np(const pthread_attr_t *);
333 int pthread_tryjoin_np(pthread_t, void **);
334 diff --git a/include/setjmp.h b/include/setjmp.h
335 index 2d43abf8..1976af23 100644
336 --- a/include/setjmp.h
337 +++ b/include/setjmp.h
338 @@ -15,25 +15,33 @@ typedef struct __jmp_buf_tag {
339 unsigned long __ss[128/sizeof(long)];
340 } jmp_buf[1];
342 +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
343 +#define __setjmp_attr __attribute__((__returns_twice__))
344 +#else
345 +#define __setjmp_attr
346 +#endif
348 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
349 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
350 || defined(_BSD_SOURCE)
351 typedef jmp_buf sigjmp_buf;
352 -int sigsetjmp (sigjmp_buf, int);
353 +int sigsetjmp (sigjmp_buf, int) __setjmp_attr;
354 _Noreturn void siglongjmp (sigjmp_buf, int);
355 #endif
357 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
358 || defined(_BSD_SOURCE)
359 -int _setjmp (jmp_buf);
360 +int _setjmp (jmp_buf) __setjmp_attr;
361 _Noreturn void _longjmp (jmp_buf, int);
362 #endif
364 -int setjmp (jmp_buf);
365 +int setjmp (jmp_buf) __setjmp_attr;
366 _Noreturn void longjmp (jmp_buf, int);
368 #define setjmp setjmp
370 +#undef __setjmp_attr
372 #ifdef __cplusplus
374 #endif
375 diff --git a/include/signal.h b/include/signal.h
376 index 9ed929e4..f270a594 100644
377 --- a/include/signal.h
378 +++ b/include/signal.h
379 @@ -75,6 +75,8 @@ typedef struct sigaltstack stack_t;
380 #define SEGV_ACCERR 2
381 #define SEGV_BNDERR 3
382 #define SEGV_PKUERR 4
383 +#define SEGV_MTEAERR 8
384 +#define SEGV_MTESERR 9
386 #define BUS_ADRALN 1
387 #define BUS_ADRERR 2
388 diff --git a/include/stdc-predef.h b/include/stdc-predef.h
389 index f8cd4b89..af1a2799 100644
390 --- a/include/stdc-predef.h
391 +++ b/include/stdc-predef.h
392 @@ -7,4 +7,7 @@
393 #define __STDC_IEC_559__ 1
394 #endif
396 +#define __STDC_UTF_16__ 1
397 +#define __STDC_UTF_32__ 1
399 #endif
400 diff --git a/include/stddef.h b/include/stddef.h
401 index bd753853..f25b8639 100644
402 --- a/include/stddef.h
403 +++ b/include/stddef.h
404 @@ -1,7 +1,9 @@
405 #ifndef _STDDEF_H
406 #define _STDDEF_H
408 -#ifdef __cplusplus
409 +#if __cplusplus >= 201103L
410 +#define NULL nullptr
411 +#elif defined(__cplusplus)
412 #define NULL 0L
413 #else
414 #define NULL ((void*)0)
415 diff --git a/include/stdio.h b/include/stdio.h
416 index 3604198c..d1ed01f0 100644
417 --- a/include/stdio.h
418 +++ b/include/stdio.h
419 @@ -25,7 +25,9 @@ extern "C" {
421 #include <bits/alltypes.h>
423 -#ifdef __cplusplus
424 +#if __cplusplus >= 201103L
425 +#define NULL nullptr
426 +#elif defined(__cplusplus)
427 #define NULL 0L
428 #else
429 #define NULL ((void*)0)
430 diff --git a/include/stdlib.h b/include/stdlib.h
431 index b54a051f..b507ca33 100644
432 --- a/include/stdlib.h
433 +++ b/include/stdlib.h
434 @@ -7,7 +7,9 @@ extern "C" {
436 #include <features.h>
438 -#ifdef __cplusplus
439 +#if __cplusplus >= 201103L
440 +#define NULL nullptr
441 +#elif defined(__cplusplus)
442 #define NULL 0L
443 #else
444 #define NULL ((void*)0)
445 @@ -146,6 +148,7 @@ int clearenv(void);
446 #define WCOREDUMP(s) ((s) & 0x80)
447 #define WIFCONTINUED(s) ((s) == 0xffff)
448 void *reallocarray (void *, size_t, size_t);
449 +void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
450 #endif
452 #ifdef _GNU_SOURCE
453 diff --git a/include/string.h b/include/string.h
454 index 795a2abc..43ad0942 100644
455 --- a/include/string.h
456 +++ b/include/string.h
457 @@ -7,7 +7,9 @@ extern "C" {
459 #include <features.h>
461 -#ifdef __cplusplus
462 +#if __cplusplus >= 201103L
463 +#define NULL nullptr
464 +#elif defined(__cplusplus)
465 #define NULL 0L
466 #else
467 #define NULL ((void*)0)
468 diff --git a/include/sys/membarrier.h b/include/sys/membarrier.h
469 index 10cb3108..11193eda 100644
470 --- a/include/sys/membarrier.h
471 +++ b/include/sys/membarrier.h
472 @@ -9,9 +9,13 @@
473 #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED 16
474 #define MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 32
475 #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE 64
476 +#define MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ 128
477 +#define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ 256
479 #define MEMBARRIER_CMD_SHARED MEMBARRIER_CMD_GLOBAL
481 +#define MEMBARRIER_CMD_FLAG_CPU 1
483 int membarrier(int, int);
485 #endif
486 diff --git a/include/sys/mman.h b/include/sys/mman.h
487 index 4d603e91..80a3baae 100644
488 --- a/include/sys/mman.h
489 +++ b/include/sys/mman.h
490 @@ -40,6 +40,7 @@ extern "C" {
492 #define MAP_HUGE_SHIFT 26
493 #define MAP_HUGE_MASK 0x3f
494 +#define MAP_HUGE_16KB (14 << 26)
495 #define MAP_HUGE_64KB (16 << 26)
496 #define MAP_HUGE_512KB (19 << 26)
497 #define MAP_HUGE_1MB (20 << 26)
498 diff --git a/include/sys/mount.h b/include/sys/mount.h
499 index 57a89c09..09bd6e9d 100644
500 --- a/include/sys/mount.h
501 +++ b/include/sys/mount.h
502 @@ -31,6 +31,7 @@ extern "C" {
503 #define MS_REMOUNT 32
504 #define MS_MANDLOCK 64
505 #define MS_DIRSYNC 128
506 +#define MS_NOSYMFOLLOW 256
507 #define MS_NOATIME 1024
508 #define MS_NODIRATIME 2048
509 #define MS_BIND 4096
510 diff --git a/include/sys/prctl.h b/include/sys/prctl.h
511 index 4b9fcc05..4ba73f42 100644
512 --- a/include/sys/prctl.h
513 +++ b/include/sys/prctl.h
514 @@ -157,6 +157,13 @@ struct prctl_mm_map {
515 #define PR_SET_TAGGED_ADDR_CTRL 55
516 #define PR_GET_TAGGED_ADDR_CTRL 56
517 #define PR_TAGGED_ADDR_ENABLE (1UL << 0)
518 +#define PR_MTE_TCF_SHIFT 1
519 +#define PR_MTE_TCF_NONE (0UL << 1)
520 +#define PR_MTE_TCF_SYNC (1UL << 1)
521 +#define PR_MTE_TCF_ASYNC (2UL << 1)
522 +#define PR_MTE_TCF_MASK (3UL << 1)
523 +#define PR_MTE_TAG_SHIFT 3
524 +#define PR_MTE_TAG_MASK (0xffffUL << 3)
526 #define PR_SET_IO_FLUSHER 57
527 #define PR_GET_IO_FLUSHER 58
528 diff --git a/include/time.h b/include/time.h
529 index 5494df18..3d948372 100644
530 --- a/include/time.h
531 +++ b/include/time.h
532 @@ -7,7 +7,9 @@ extern "C" {
534 #include <features.h>
536 -#ifdef __cplusplus
537 +#if __cplusplus >= 201103L
538 +#define NULL nullptr
539 +#elif defined(__cplusplus)
540 #define NULL 0L
541 #else
542 #define NULL ((void*)0)
543 diff --git a/include/unistd.h b/include/unistd.h
544 index 13064026..ee2dbe8a 100644
545 --- a/include/unistd.h
546 +++ b/include/unistd.h
547 @@ -15,7 +15,9 @@ extern "C" {
548 #define SEEK_CUR 1
549 #define SEEK_END 2
551 -#ifdef __cplusplus
552 +#if __cplusplus >= 201103L
553 +#define NULL nullptr
554 +#elif defined(__cplusplus)
555 #define NULL 0L
556 #else
557 #define NULL ((void*)0)
558 diff --git a/include/wchar.h b/include/wchar.h
559 index 88eb55b1..ed5d774d 100644
560 --- a/include/wchar.h
561 +++ b/include/wchar.h
562 @@ -38,7 +38,9 @@ extern "C" {
563 #define WCHAR_MIN (-1-0x7fffffff+L'\0')
564 #endif
566 -#ifdef __cplusplus
567 +#if __cplusplus >= 201103L
568 +#define NULL nullptr
569 +#elif defined(__cplusplus)
570 #define NULL 0L
571 #else
572 #define NULL ((void*)0)
573 diff --git a/ldso/dynlink.c b/ldso/dynlink.c
574 index 6b868c84..5b9c8be4 100644
575 --- a/ldso/dynlink.c
576 +++ b/ldso/dynlink.c
577 @@ -579,6 +579,7 @@ static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t of
579 static int no_map_fixed;
580 char *q;
581 + if (!n) return p;
582 if (!no_map_fixed) {
583 q = mmap(p, n, prot, flags|MAP_FIXED, fd, off);
584 if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL)
585 @@ -1830,7 +1831,7 @@ void __dls3(size_t *sp, size_t *auxv)
586 dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
587 _exit(1);
589 - Ehdr *ehdr = (void *)map_library(fd, &app);
590 + Ehdr *ehdr = map_library(fd, &app);
591 if (!ehdr) {
592 dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
593 _exit(1);
594 @@ -2330,7 +2331,8 @@ int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void
595 info.dlpi_adds = gencnt;
596 info.dlpi_subs = 0;
597 info.dlpi_tls_modid = current->tls_id;
598 - info.dlpi_tls_data = current->tls.image;
599 + info.dlpi_tls_data = !current->tls_id ? 0 :
600 + __tls_get_addr((tls_mod_off_t[]){current->tls_id,0});
602 ret = (callback)(&info, sizeof (info), data);
604 diff --git a/src/ctype/nonspacing.h b/src/ctype/nonspacing.h
605 index 5d05a3d1..7746f3b6 100644
606 --- a/src/ctype/nonspacing.h
607 +++ b/src/ctype/nonspacing.h
608 @@ -1,23 +1,23 @@
609 -16,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,16,16,32,16,16,16,33,34,35,
610 -36,37,38,39,16,16,40,16,16,16,16,16,16,16,16,16,16,16,41,42,16,16,43,16,16,16,
611 +16,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,16,33,16,16,16,34,35,36,
612 +37,38,39,40,16,16,41,16,16,16,16,16,16,16,16,16,16,16,42,43,16,16,44,16,16,16,
613 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
614 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
615 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
616 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
617 -16,16,16,16,16,16,16,16,16,16,44,16,45,46,47,48,16,16,16,16,16,16,16,16,16,16,
618 +16,16,16,16,16,16,16,16,16,16,45,16,46,47,48,49,16,16,16,16,16,16,16,16,16,16,
619 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
620 +16,16,16,16,16,16,16,50,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
621 +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,51,16,16,52,
622 +53,16,54,55,56,16,16,16,16,16,16,57,16,16,58,16,59,60,61,62,63,64,65,66,67,68,
623 +69,70,16,71,72,73,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
624 +16,74,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
625 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
626 -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50,
627 -51,16,52,53,54,16,16,16,16,16,16,55,16,16,56,16,57,58,59,60,61,62,63,64,65,66,
628 -67,68,16,69,70,71,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
629 -16,72,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
630 +16,16,16,75,76,16,16,16,77,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
631 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
632 -16,16,16,73,74,16,16,16,75,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
633 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
634 -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
635 -16,16,16,16,16,16,16,76,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
636 -16,16,77,78,16,16,16,16,16,16,16,79,16,16,16,16,16,80,81,82,16,16,16,16,16,83,
637 -84,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
638 +16,16,16,16,16,16,16,78,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
639 +16,16,79,80,16,16,16,16,16,16,16,81,16,16,16,16,16,82,83,84,16,16,16,16,16,85,
640 +86,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
641 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,
642 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
643 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
644 @@ -35,55 +35,57 @@
645 242,7,128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,31,0,63,0,0,0,0,0,0,0,0,0,3,0,0,160,
646 2,0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,0,0,0,0,
647 0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0,0,0,0,
648 -0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,
649 -0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,120,0,0,
650 -0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,
651 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,0,0,64,127,
652 -229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0,
653 -0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,
654 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
655 -0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,
656 +0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,
657 +255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,
658 +0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,
659 +15,32,0,0,0,0,0,120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,0,0,0,0,0,0,
660 +0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
661 +128,9,0,0,0,0,0,0,64,127,229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,
662 +15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,
663 +0,0,0,0,240,207,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,
664 +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,
665 251,0,248,0,0,0,124,0,0,0,0,0,0,223,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,
666 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0,
667 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,
668 0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
669 0,0,0,128,247,63,0,0,0,192,0,0,0,0,0,0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0,
670 0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,128,255,3,0,
671 -0,0,0,0,7,0,0,0,0,0,200,51,0,0,0,0,32,0,0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,
672 -0,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64,
673 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,
674 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,255,255,0,
675 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,
676 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
677 -0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
678 -0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
679 -0,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,
680 -0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
681 -0,0,0,192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,
682 -127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,
683 -0,0,0,0,0,0,8,0,3,0,0,0,0,0,192,127,0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0,
684 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,1,0,0,0,192,
685 -31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0,
686 -0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
687 -0,60,176,1,0,0,48,0,0,0,
688 -0,0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,
689 -0,224,188,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
690 -128,255,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
691 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,
692 -126,14,0,0,0,0,0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0,
693 -0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,180,191,0,
694 -0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
695 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,
696 -0,0,0,0,0,0,0,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
697 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,0,0,
698 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,
699 -0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,
700 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,
701 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
702 -0,0,0,255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,
703 -254,255,0,0,0,0,0,0,0,0,0,
704 -0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
705 -0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
706 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
707 -0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,240,7,0,0,0,0,0,0,0,0,
708 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,
709 +0,0,0,0,7,0,0,0,0,0,200,51,0,0,0,0,32,0,0,
710 +0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64,0,
711 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,0,0,0,
712 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,0,0,0,
713 +64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,255,
714 +255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,
715 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
716 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
717 +0,0,0,0,0,0,1,0,0,
718 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,
719 +0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,240,0,0,
720 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,1,0,
721 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,
722 +3,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,3,0,
723 +0,0,0,0,192,127,0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0,0,0,0,0,0,0,0,0,0,0,
724 +0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,
725 +0,0,0,0,0,0,0,0,0,
726 +0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,
727 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,0,0,0,0,0,0,
728 +248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,
729 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,0,0,0,0,
730 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
731 +0,0,0,0,0,0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,0,252,
732 +127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0,0,0,0,0,0,0,0,252,255,
733 +255,252,109,0,0,0,0,0,0,0,0,
734 +0,0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
735 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,
736 +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
737 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,
738 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,128,7,0,0,0,0,0,
739 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,0,0,0,0,0,0,
740 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,
741 +0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,
742 +255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,0,
743 +0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
744 +0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
745 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,
746 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,240,7,0,0,
747 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
748 diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
749 index 8fbe5262..c5b277bd 100644
750 --- a/src/env/__libc_start_main.c
751 +++ b/src/env/__libc_start_main.c
752 @@ -69,7 +69,8 @@ weak_alias(libc_start_init, __libc_start_init);
753 typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
754 static lsm2_fn libc_start_main_stage2;
756 -int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
757 +int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
758 + void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
760 char **envp = argv+argc+1;
762 diff --git a/src/fenv/powerpc/fenv-sf.c b/src/fenv/powerpc/fenv-sf.c
763 index 85bef40f..d4248f26 100644
764 --- a/src/fenv/powerpc/fenv-sf.c
765 +++ b/src/fenv/powerpc/fenv-sf.c
766 @@ -1,3 +1,3 @@
767 -#ifdef _SOFT_FLOAT
768 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
769 #include "../fenv.c"
770 #endif
771 diff --git a/src/fenv/powerpc/fenv.S b/src/fenv/powerpc/fenv.S
772 index 22cea216..55055d0b 100644
773 --- a/src/fenv/powerpc/fenv.S
774 +++ b/src/fenv/powerpc/fenv.S
775 @@ -1,4 +1,4 @@
776 -#ifndef _SOFT_FLOAT
777 +#if !defined(_SOFT_FLOAT) && !defined(__NO_FPRS__)
778 .global feclearexcept
779 .type feclearexcept,@function
780 feclearexcept:
781 diff --git a/src/include/stdlib.h b/src/include/stdlib.h
782 index e9da2015..812b04de 100644
783 --- a/src/include/stdlib.h
784 +++ b/src/include/stdlib.h
785 @@ -8,6 +8,7 @@ hidden void __env_rm_add(char *, char *);
786 hidden int __mkostemps(char *, int, int);
787 hidden int __ptsname_r(int, char *, size_t);
788 hidden char *__randname(char *);
789 +hidden void __qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
791 hidden void *__libc_malloc(size_t);
792 hidden void *__libc_malloc_impl(size_t);
793 diff --git a/src/ldso/dl_iterate_phdr.c b/src/ldso/dl_iterate_phdr.c
794 index 86c87ef8..9546dd36 100644
795 --- a/src/ldso/dl_iterate_phdr.c
796 +++ b/src/ldso/dl_iterate_phdr.c
797 @@ -1,5 +1,6 @@
798 #include <elf.h>
799 #include <link.h>
800 +#include "pthread_impl.h"
801 #include "libc.h"
803 #define AUX_CNT 38
804 @@ -35,7 +36,7 @@ static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size
805 info.dlpi_subs = 0;
806 if (tls_phdr) {
807 info.dlpi_tls_modid = 1;
808 - info.dlpi_tls_data = (void *)(base + tls_phdr->p_vaddr);
809 + info.dlpi_tls_data = __tls_get_addr((tls_mod_off_t[]){1,0});
810 } else {
811 info.dlpi_tls_modid = 0;
812 info.dlpi_tls_data = 0;
813 diff --git a/src/legacy/cuserid.c b/src/legacy/cuserid.c
814 index 4e78798d..dcaf73d4 100644
815 --- a/src/legacy/cuserid.c
816 +++ b/src/legacy/cuserid.c
817 @@ -2,13 +2,21 @@
818 #include <pwd.h>
819 #include <stdio.h>
820 #include <unistd.h>
821 +#include <string.h>
823 char *cuserid(char *buf)
825 + static char usridbuf[L_cuserid];
826 struct passwd pw, *ppw;
827 long pwb[256];
828 - if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw))
829 - return 0;
830 - snprintf(buf, L_cuserid, "%s", pw.pw_name);
831 + if (buf) *buf = 0;
832 + getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
833 + if (!ppw)
834 + return buf;
835 + size_t len = strnlen(pw.pw_name, L_cuserid);
836 + if (len == L_cuserid)
837 + return buf;
838 + if (!buf) buf = usridbuf;
839 + memcpy(buf, pw.pw_name, len+1);
840 return buf;
842 diff --git a/src/linux/epoll.c b/src/linux/epoll.c
843 index deff5b10..93baa814 100644
844 --- a/src/linux/epoll.c
845 +++ b/src/linux/epoll.c
846 @@ -24,9 +24,9 @@ int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev)
848 int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
850 - int r = __syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
851 + int r = __syscall_cp(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
852 #ifdef SYS_epoll_wait
853 - if (r==-ENOSYS && !sigs) r = __syscall(SYS_epoll_wait, fd, ev, cnt, to);
854 + if (r==-ENOSYS && !sigs) r = __syscall_cp(SYS_epoll_wait, fd, ev, cnt, to);
855 #endif
856 return __syscall_ret(r);
858 diff --git a/src/locale/strtod_l.c b/src/locale/strtod_l.c
859 new file mode 100644
860 index 00000000..574ba148
861 --- /dev/null
862 +++ b/src/locale/strtod_l.c
863 @@ -0,0 +1,22 @@
864 +#define _GNU_SOURCE
865 +#include <stdlib.h>
866 +#include <locale.h>
868 +float strtof_l(const char *restrict s, char **restrict p, locale_t l)
870 + return strtof(s, p);
873 +double strtod_l(const char *restrict s, char **restrict p, locale_t l)
875 + return strtod(s, p);
878 +long double strtold_l(const char *restrict s, char **restrict p, locale_t l)
880 + return strtold(s, p);
883 +weak_alias(strtof_l, __strtof_l);
884 +weak_alias(strtod_l, __strtod_l);
885 +weak_alias(strtold_l, __strtold_l);
886 diff --git a/src/malloc/free.c b/src/malloc/free.c
887 index f17a952c..3944f7b2 100644
888 --- a/src/malloc/free.c
889 +++ b/src/malloc/free.c
890 @@ -2,5 +2,5 @@
892 void free(void *p)
894 - return __libc_free(p);
895 + __libc_free(p);
897 diff --git a/src/malloc/mallocng/aligned_alloc.c b/src/malloc/mallocng/aligned_alloc.c
898 index 34116896..e0862a83 100644
899 --- a/src/malloc/mallocng/aligned_alloc.c
900 +++ b/src/malloc/mallocng/aligned_alloc.c
901 @@ -22,6 +22,9 @@ void *aligned_alloc(size_t align, size_t len)
902 if (align <= UNIT) align = UNIT;
904 unsigned char *p = malloc(len + align - UNIT);
905 + if (!p)
906 + return 0;
908 struct meta *g = get_meta(p);
909 int idx = get_slot_index(p);
910 size_t stride = get_stride(g);
911 diff --git a/src/malloc/mallocng/free.c b/src/malloc/mallocng/free.c
912 index 40745f97..418a085c 100644
913 --- a/src/malloc/mallocng/free.c
914 +++ b/src/malloc/mallocng/free.c
915 @@ -119,7 +119,11 @@ void free(void *p)
916 if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
917 unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
918 size_t len = (end-base) & -PGSZ;
919 - if (len) madvise(base, len, MADV_FREE);
920 + if (len) {
921 + int e = errno;
922 + madvise(base, len, MADV_FREE);
923 + errno = e;
927 // atomic free without locking if this is neither first or last slot
928 @@ -139,5 +143,9 @@ void free(void *p)
929 wrlock();
930 struct mapinfo mi = nontrivial_free(g, idx);
931 unlock();
932 - if (mi.len) munmap(mi.base, mi.len);
933 + if (mi.len) {
934 + int e = errno;
935 + munmap(mi.base, mi.len);
936 + errno = e;
939 diff --git a/src/malloc/oldmalloc/malloc.c b/src/malloc/oldmalloc/malloc.c
940 index 53f5f959..25d00d44 100644
941 --- a/src/malloc/oldmalloc/malloc.c
942 +++ b/src/malloc/oldmalloc/malloc.c
943 @@ -11,7 +11,7 @@
944 #include "malloc_impl.h"
945 #include "fork_impl.h"
947 -#define malloc __libc_malloc
948 +#define malloc __libc_malloc_impl
949 #define realloc __libc_realloc
950 #define free __libc_free
952 @@ -481,12 +481,14 @@ void __bin_chunk(struct chunk *self)
953 if (size > RECLAIM && (size^(size-osize)) > size-osize) {
954 uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE;
955 uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE;
956 + int e = errno;
957 #if 1
958 __madvise((void *)a, b-a, MADV_DONTNEED);
959 #else
960 __mmap((void *)a, b-a, PROT_READ|PROT_WRITE,
961 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
962 #endif
963 + errno = e;
966 unlock_bin(i);
967 @@ -499,7 +501,9 @@ static void unmap_chunk(struct chunk *self)
968 size_t len = CHUNK_SIZE(self) + extra;
969 /* Crash on double free */
970 if (extra & 1) a_crash();
971 + int e = errno;
972 __munmap(base, len);
973 + errno = e;
976 void free(void *p)
977 diff --git a/src/math/acoshf.c b/src/math/acoshf.c
978 index 8a4ec4d5..b773d48e 100644
979 --- a/src/math/acoshf.c
980 +++ b/src/math/acoshf.c
981 @@ -15,12 +15,12 @@ float acoshf(float x)
982 uint32_t a = u.i & 0x7fffffff;
984 if (a < 0x3f800000+(1<<23))
985 - /* |x| < 2, invalid if x < 1 or nan */
986 + /* |x| < 2, invalid if x < 1 */
987 /* up to 2ulp error in [1,1.125] */
988 return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
989 - if (a < 0x3f800000+(12<<23))
990 - /* |x| < 0x1p12 */
991 + if (u.i < 0x3f800000+(12<<23))
992 + /* 2 <= x < 0x1p12 */
993 return logf(2*x - 1/(x+sqrtf(x*x-1)));
994 - /* x >= 0x1p12 */
995 + /* x >= 0x1p12 or x <= -2 or nan */
996 return logf(x) + 0.693147180559945309417232121458176568f;
998 diff --git a/src/math/expm1f.c b/src/math/expm1f.c
999 index 297e0b44..09a41afe 100644
1000 --- a/src/math/expm1f.c
1001 +++ b/src/math/expm1f.c
1002 @@ -16,7 +16,6 @@
1003 #include "libm.h"
1005 static const float
1006 -o_threshold = 8.8721679688e+01, /* 0x42b17180 */
1007 ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
1008 ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
1009 invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
1010 @@ -41,7 +40,7 @@ float expm1f(float x)
1011 return x;
1012 if (sign)
1013 return -1;
1014 - if (x > o_threshold) {
1015 + if (hx > 0x42b17217) { /* x > log(FLT_MAX) */
1016 x *= 0x1p127f;
1017 return x;
1019 diff --git a/src/math/fmaf.c b/src/math/fmaf.c
1020 index 80f5cd8a..7c65acf1 100644
1021 --- a/src/math/fmaf.c
1022 +++ b/src/math/fmaf.c
1023 @@ -77,17 +77,16 @@ float fmaf(float x, float y, float z)
1024 * If result is inexact, and exactly halfway between two float values,
1025 * we need to adjust the low-order bit in the direction of the error.
1027 -#ifdef FE_TOWARDZERO
1028 - fesetround(FE_TOWARDZERO);
1029 -#endif
1030 - volatile double vxy = xy; /* XXX work around gcc CSE bug */
1031 - double adjusted_result = vxy + z;
1032 - fesetround(FE_TONEAREST);
1033 - if (result == adjusted_result) {
1034 - u.f = adjusted_result;
1035 + double err;
1036 + int neg = u.i >> 63;
1037 + if (neg == (z > xy))
1038 + err = xy - result + z;
1039 + else
1040 + err = z - result + xy;
1041 + if (neg == (err < 0))
1042 u.i++;
1043 - adjusted_result = u.f;
1045 - z = adjusted_result;
1046 + else
1047 + u.i--;
1048 + z = u.f;
1049 return z;
1051 diff --git a/src/math/powerpc/fabs.c b/src/math/powerpc/fabs.c
1052 index 0efc21ef..9453a3aa 100644
1053 --- a/src/math/powerpc/fabs.c
1054 +++ b/src/math/powerpc/fabs.c
1055 @@ -1,6 +1,6 @@
1056 #include <math.h>
1058 -#if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM)
1059 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
1061 #include "../fabs.c"
1063 diff --git a/src/math/powerpc/fabsf.c b/src/math/powerpc/fabsf.c
1064 index d88b5911..2e9da588 100644
1065 --- a/src/math/powerpc/fabsf.c
1066 +++ b/src/math/powerpc/fabsf.c
1067 @@ -1,6 +1,6 @@
1068 #include <math.h>
1070 -#ifdef _SOFT_FLOAT
1071 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
1073 #include "../fabsf.c"
1075 diff --git a/src/math/powerpc/fma.c b/src/math/powerpc/fma.c
1076 index 135c9903..0eb2ba1e 100644
1077 --- a/src/math/powerpc/fma.c
1078 +++ b/src/math/powerpc/fma.c
1079 @@ -1,6 +1,6 @@
1080 #include <math.h>
1082 -#if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM)
1083 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
1085 #include "../fma.c"
1087 diff --git a/src/math/powerpc/fmaf.c b/src/math/powerpc/fmaf.c
1088 index a99a2a3b..dc1a749d 100644
1089 --- a/src/math/powerpc/fmaf.c
1090 +++ b/src/math/powerpc/fmaf.c
1091 @@ -1,6 +1,6 @@
1092 #include <math.h>
1094 -#ifdef _SOFT_FLOAT
1095 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
1097 #include "../fmaf.c"
1099 diff --git a/src/misc/ioctl.c b/src/misc/ioctl.c
1100 index 49282811..35804f02 100644
1101 --- a/src/misc/ioctl.c
1102 +++ b/src/misc/ioctl.c
1103 @@ -6,6 +6,7 @@
1104 #include <stddef.h>
1105 #include <stdint.h>
1106 #include <string.h>
1107 +#include <endian.h>
1108 #include "syscall.h"
1110 #define alignof(t) offsetof(struct { char c; t x; }, x)
1111 @@ -53,7 +54,7 @@ static const struct ioctl_compat_map compat_map[] = {
1112 { _IOWR('A', 0x23, char[136]), _IOWR('A', 0x23, char[132]), 0, WR, 1, 0 },
1113 { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_sync_ptr (flags only) */
1114 { 0, 0, 32, WR, 1, OFFS(8,12,16,24,28) }, /* snd_pcm_mmap_status */
1115 - { 0, 0, 8, WR, 1, OFFS(0,4) }, /* snd_pcm_mmap_control */
1116 + { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_mmap_control (each member) */
1118 /* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */
1119 { _IOWR('V', 9, new_misaligned(68)), _IOWR('V', 9, char[68]), 68, WR, 1, OFFS(20, 24) },
1120 @@ -90,7 +91,11 @@ static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old,
1121 * if another exception appears this needs changing. */
1122 convert_ioctl_struct(map+1, old, new, dir);
1123 convert_ioctl_struct(map+2, old+4, new+8, dir);
1124 - convert_ioctl_struct(map+3, old+68, new+72, dir);
1125 + /* snd_pcm_mmap_control, special-cased due to kernel
1126 + * type definition having been botched. */
1127 + int adj = BYTE_ORDER==BIG_ENDIAN ? 4 : 0;
1128 + convert_ioctl_struct(map+3, old+68, new+72+adj, dir);
1129 + convert_ioctl_struct(map+3, old+72, new+76+3*adj, dir);
1130 return;
1132 for (int i=0; i < map->noffs; i++) {
1133 diff --git a/src/passwd/nscd_query.c b/src/passwd/nscd_query.c
1134 index d38e371b..dc3406b8 100644
1135 --- a/src/passwd/nscd_query.c
1136 +++ b/src/passwd/nscd_query.c
1137 @@ -40,7 +40,15 @@ retry:
1138 buf[0] = NSCDVERSION;
1140 fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
1141 - if (fd < 0) return NULL;
1142 + if (fd < 0) {
1143 + if (errno == EAFNOSUPPORT) {
1144 + f = fopen("/dev/null", "re");
1145 + if (f)
1146 + errno = errno_save;
1147 + return f;
1149 + return 0;
1152 if(!(f = fdopen(fd, "r"))) {
1153 close(fd);
1154 diff --git a/src/process/fdop.h b/src/process/fdop.h
1155 index 5adf1443..7cf733b2 100644
1156 --- a/src/process/fdop.h
1157 +++ b/src/process/fdop.h
1158 @@ -10,3 +10,8 @@ struct fdop {
1159 mode_t mode;
1160 char path[];
1163 +#define malloc __libc_malloc
1164 +#define calloc __libc_calloc
1165 +#define realloc undef
1166 +#define free __libc_free
1167 diff --git a/src/process/posix_spawn_file_actions_addclose.c b/src/process/posix_spawn_file_actions_addclose.c
1168 index cdda5979..0c2ef8fa 100644
1169 --- a/src/process/posix_spawn_file_actions_addclose.c
1170 +++ b/src/process/posix_spawn_file_actions_addclose.c
1171 @@ -5,6 +5,7 @@
1173 int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd)
1175 + if (fd < 0) return EBADF;
1176 struct fdop *op = malloc(sizeof *op);
1177 if (!op) return ENOMEM;
1178 op->cmd = FDOP_CLOSE;
1179 diff --git a/src/process/posix_spawn_file_actions_adddup2.c b/src/process/posix_spawn_file_actions_adddup2.c
1180 index 0367498f..addca4d4 100644
1181 --- a/src/process/posix_spawn_file_actions_adddup2.c
1182 +++ b/src/process/posix_spawn_file_actions_adddup2.c
1183 @@ -5,6 +5,7 @@
1185 int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd)
1187 + if (srcfd < 0 || fd < 0) return EBADF;
1188 struct fdop *op = malloc(sizeof *op);
1189 if (!op) return ENOMEM;
1190 op->cmd = FDOP_DUP2;
1191 diff --git a/src/process/posix_spawn_file_actions_addfchdir.c b/src/process/posix_spawn_file_actions_addfchdir.c
1192 index 436c683d..e89ede8c 100644
1193 --- a/src/process/posix_spawn_file_actions_addfchdir.c
1194 +++ b/src/process/posix_spawn_file_actions_addfchdir.c
1195 @@ -6,6 +6,7 @@
1197 int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd)
1199 + if (fd < 0) return EBADF;
1200 struct fdop *op = malloc(sizeof *op);
1201 if (!op) return ENOMEM;
1202 op->cmd = FDOP_FCHDIR;
1203 diff --git a/src/process/posix_spawn_file_actions_addopen.c b/src/process/posix_spawn_file_actions_addopen.c
1204 index 368922c7..82bbcec9 100644
1205 --- a/src/process/posix_spawn_file_actions_addopen.c
1206 +++ b/src/process/posix_spawn_file_actions_addopen.c
1207 @@ -6,6 +6,7 @@
1209 int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
1211 + if (fd < 0) return EBADF;
1212 struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
1213 if (!op) return ENOMEM;
1214 op->cmd = FDOP_OPEN;
1215 diff --git a/src/setjmp/powerpc/longjmp.S b/src/setjmp/powerpc/longjmp.S
1216 index e598bd05..611389fe 100644
1217 --- a/src/setjmp/powerpc/longjmp.S
1218 +++ b/src/setjmp/powerpc/longjmp.S
1219 @@ -37,7 +37,37 @@ longjmp:
1220 lwz 29, 72(3)
1221 lwz 30, 76(3)
1222 lwz 31, 80(3)
1223 -#ifndef _SOFT_FLOAT
1224 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
1225 + mflr 0
1226 + bl 1f
1227 + .hidden __hwcap
1228 + .long __hwcap-.
1229 +1: mflr 4
1230 + lwz 5, 0(4)
1231 + lwzx 4, 4, 5
1232 + andis. 4, 4, 0x80
1233 + beq 1f
1234 + .long 0x11c35b01 /* evldd 14,88(3) */
1235 + .long 0x11e36301 /* ... */
1236 + .long 0x12036b01
1237 + .long 0x12237301
1238 + .long 0x12437b01
1239 + .long 0x12638301
1240 + .long 0x12838b01
1241 + .long 0x12a39301
1242 + .long 0x12c39b01
1243 + .long 0x12e3a301
1244 + .long 0x1303ab01
1245 + .long 0x1323b301
1246 + .long 0x1343bb01
1247 + .long 0x1363c301
1248 + .long 0x1383cb01
1249 + .long 0x13a3d301
1250 + .long 0x13c3db01
1251 + .long 0x13e3e301 /* evldd 31,224(3) */
1252 + .long 0x11a3eb01 /* evldd 13,232(3) */
1253 +1: mtlr 0
1254 +#else
1255 lfd 14,88(3)
1256 lfd 15,96(3)
1257 lfd 16,104(3)
1258 diff --git a/src/setjmp/powerpc/setjmp.S b/src/setjmp/powerpc/setjmp.S
1259 index cd91a207..f1fcce33 100644
1260 --- a/src/setjmp/powerpc/setjmp.S
1261 +++ b/src/setjmp/powerpc/setjmp.S
1262 @@ -37,7 +37,37 @@ setjmp:
1263 stw 29, 72(3)
1264 stw 30, 76(3)
1265 stw 31, 80(3)
1266 -#ifndef _SOFT_FLOAT
1267 +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
1268 + mflr 0
1269 + bl 1f
1270 + .hidden __hwcap
1271 + .long __hwcap-.
1272 +1: mflr 4
1273 + lwz 5, 0(4)
1274 + lwzx 4, 4, 5
1275 + andis. 4, 4, 0x80
1276 + beq 1f
1277 + .long 0x11c35b21 /* evstdd 14,88(3) */
1278 + .long 0x11e36321 /* ... */
1279 + .long 0x12036b21
1280 + .long 0x12237321
1281 + .long 0x12437b21
1282 + .long 0x12638321
1283 + .long 0x12838b21
1284 + .long 0x12a39321
1285 + .long 0x12c39b21
1286 + .long 0x12e3a321
1287 + .long 0x1303ab21
1288 + .long 0x1323b321
1289 + .long 0x1343bb21
1290 + .long 0x1363c321
1291 + .long 0x1383cb21
1292 + .long 0x13a3d321
1293 + .long 0x13c3db21
1294 + .long 0x13e3e321 /* evstdd 31,224(3) */
1295 + .long 0x11a3eb21 /* evstdd 13,232(3) */
1296 +1: mtlr 0
1297 +#else
1298 stfd 14,88(3)
1299 stfd 15,96(3)
1300 stfd 16,104(3)
1301 diff --git a/src/signal/block.c b/src/signal/block.c
1302 index d7f61001..cc8698f0 100644
1303 --- a/src/signal/block.c
1304 +++ b/src/signal/block.c
1305 @@ -3,9 +3,9 @@
1306 #include <signal.h>
1308 static const unsigned long all_mask[] = {
1309 -#if ULONG_MAX == 0xffffffff && _NSIG == 129
1310 +#if ULONG_MAX == 0xffffffff && _NSIG > 65
1311 -1UL, -1UL, -1UL, -1UL
1312 -#elif ULONG_MAX == 0xffffffff
1313 +#elif ULONG_MAX == 0xffffffff || _NSIG > 65
1314 -1UL, -1UL
1315 #else
1316 -1UL
1317 diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c
1318 index d2f5b15a..df114441 100644
1319 --- a/src/stdio/getdelim.c
1320 +++ b/src/stdio/getdelim.c
1321 @@ -55,9 +55,11 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
1322 *s = tmp;
1323 *n = m;
1325 - memcpy(*s+i, f->rpos, k);
1326 - f->rpos += k;
1327 - i += k;
1328 + if (k) {
1329 + memcpy(*s+i, f->rpos, k);
1330 + f->rpos += k;
1331 + i += k;
1333 if (z) break;
1334 if ((c = getc_unlocked(f)) == EOF) {
1335 if (!i || !feof(f)) {
1336 diff --git a/src/stdio/popen.c b/src/stdio/popen.c
1337 index 92cb57ee..3ec83394 100644
1338 --- a/src/stdio/popen.c
1339 +++ b/src/stdio/popen.c
1340 @@ -31,25 +31,12 @@ FILE *popen(const char *cmd, const char *mode)
1341 __syscall(SYS_close, p[1]);
1342 return NULL;
1344 - FLOCK(f);
1346 - /* If the child's end of the pipe happens to already be on the final
1347 - * fd number to which it will be assigned (either 0 or 1), it must
1348 - * be moved to a different fd. Otherwise, there is no safe way to
1349 - * remove the close-on-exec flag in the child without also creating
1350 - * a file descriptor leak race condition in the parent. */
1351 - if (p[1-op] == 1-op) {
1352 - int tmp = fcntl(1-op, F_DUPFD_CLOEXEC, 0);
1353 - if (tmp < 0) {
1354 - e = errno;
1355 - goto fail;
1357 - __syscall(SYS_close, p[1-op]);
1358 - p[1-op] = tmp;
1361 e = ENOMEM;
1362 if (!posix_spawn_file_actions_init(&fa)) {
1363 + for (FILE *l = *__ofl_lock(); l; l=l->next)
1364 + if (l->pipe_pid && posix_spawn_file_actions_addclose(&fa, l->fd))
1365 + goto fail;
1366 if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) {
1367 if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0,
1368 (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) {
1369 @@ -58,13 +45,14 @@ FILE *popen(const char *cmd, const char *mode)
1370 if (!strchr(mode, 'e'))
1371 fcntl(p[op], F_SETFD, 0);
1372 __syscall(SYS_close, p[1-op]);
1373 - FUNLOCK(f);
1374 + __ofl_unlock();
1375 return f;
1378 +fail:
1379 + __ofl_unlock();
1380 posix_spawn_file_actions_destroy(&fa);
1382 -fail:
1383 fclose(f);
1384 __syscall(SYS_close, p[1-op]);
1386 diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c
1387 index da58fd31..314ddc29 100644
1388 --- a/src/stdlib/qsort.c
1389 +++ b/src/stdlib/qsort.c
1390 @@ -24,6 +24,7 @@
1391 /* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1).
1392 Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */
1394 +#define _BSD_SOURCE
1395 #include <stdint.h>
1396 #include <stdlib.h>
1397 #include <string.h>
1398 @@ -31,7 +32,7 @@
1399 #include "atomic.h"
1400 #define ntz(x) a_ctz_l((x))
1402 -typedef int (*cmpfun)(const void *, const void *);
1403 +typedef int (*cmpfun)(const void *, const void *, void *);
1405 static inline int pntz(size_t p[2]) {
1406 int r = ntz(p[0] - 1);
1407 @@ -88,7 +89,7 @@ static inline void shr(size_t p[2], int n)
1408 p[1] >>= n;
1411 -static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[])
1412 +static void sift(unsigned char *head, size_t width, cmpfun cmp, void *arg, int pshift, size_t lp[])
1414 unsigned char *rt, *lf;
1415 unsigned char *ar[14 * sizeof(size_t) + 1];
1416 @@ -99,10 +100,10 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size
1417 rt = head - width;
1418 lf = head - width - lp[pshift - 2];
1420 - if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) {
1421 + if(cmp(ar[0], lf, arg) >= 0 && cmp(ar[0], rt, arg) >= 0) {
1422 break;
1424 - if((*cmp)(lf, rt) >= 0) {
1425 + if(cmp(lf, rt, arg) >= 0) {
1426 ar[i++] = lf;
1427 head = lf;
1428 pshift -= 1;
1429 @@ -115,7 +116,7 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size
1430 cycle(width, ar, i);
1433 -static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[])
1434 +static void trinkle(unsigned char *head, size_t width, cmpfun cmp, void *arg, size_t pp[2], int pshift, int trusty, size_t lp[])
1436 unsigned char *stepson,
1437 *rt, *lf;
1438 @@ -130,13 +131,13 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2],
1439 ar[0] = head;
1440 while(p[0] != 1 || p[1] != 0) {
1441 stepson = head - lp[pshift];
1442 - if((*cmp)(stepson, ar[0]) <= 0) {
1443 + if(cmp(stepson, ar[0], arg) <= 0) {
1444 break;
1446 if(!trusty && pshift > 1) {
1447 rt = head - width;
1448 lf = head - width - lp[pshift - 2];
1449 - if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) {
1450 + if(cmp(rt, stepson, arg) >= 0 || cmp(lf, stepson, arg) >= 0) {
1451 break;
1454 @@ -150,11 +151,11 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2],
1456 if(!trusty) {
1457 cycle(width, ar, i);
1458 - sift(head, width, cmp, pshift, lp);
1459 + sift(head, width, cmp, arg, pshift, lp);
1463 -void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
1464 +void __qsort_r(void *base, size_t nel, size_t width, cmpfun cmp, void *arg)
1466 size_t lp[12*sizeof(size_t)];
1467 size_t i, size = width * nel;
1468 @@ -173,16 +174,16 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
1470 while(head < high) {
1471 if((p[0] & 3) == 3) {
1472 - sift(head, width, cmp, pshift, lp);
1473 + sift(head, width, cmp, arg, pshift, lp);
1474 shr(p, 2);
1475 pshift += 2;
1476 } else {
1477 if(lp[pshift - 1] >= high - head) {
1478 - trinkle(head, width, cmp, p, pshift, 0, lp);
1479 + trinkle(head, width, cmp, arg, p, pshift, 0, lp);
1480 } else {
1481 - sift(head, width, cmp, pshift, lp);
1482 + sift(head, width, cmp, arg, pshift, lp);
1486 if(pshift == 1) {
1487 shl(p, 1);
1488 pshift = 0;
1489 @@ -191,12 +192,12 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
1490 pshift = 1;
1495 p[0] |= 1;
1496 head += width;
1499 - trinkle(head, width, cmp, p, pshift, 0, lp);
1500 + trinkle(head, width, cmp, arg, p, pshift, 0, lp);
1502 while(pshift != 1 || p[0] != 1 || p[1] != 0) {
1503 if(pshift <= 1) {
1504 @@ -208,11 +209,13 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
1505 pshift -= 2;
1506 p[0] ^= 7;
1507 shr(p, 1);
1508 - trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp);
1509 + trinkle(head - lp[pshift] - width, width, cmp, arg, p, pshift + 1, 1, lp);
1510 shl(p, 1);
1511 p[0] |= 1;
1512 - trinkle(head - width, width, cmp, p, pshift, 1, lp);
1513 + trinkle(head - width, width, cmp, arg, p, pshift, 1, lp);
1515 head -= width;
1519 +weak_alias(__qsort_r, qsort_r);
1520 diff --git a/src/stdlib/qsort_nr.c b/src/stdlib/qsort_nr.c
1521 new file mode 100644
1522 index 00000000..efe7ccec
1523 --- /dev/null
1524 +++ b/src/stdlib/qsort_nr.c
1525 @@ -0,0 +1,14 @@
1526 +#define _BSD_SOURCE
1527 +#include <stdlib.h>
1529 +typedef int (*cmpfun)(const void *, const void *);
1531 +static int wrapper_cmp(const void *v1, const void *v2, void *cmp)
1533 + return ((cmpfun)cmp)(v1, v2);
1536 +void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
1538 + __qsort_r(base, nel, width, wrapper_cmp, cmp);
1540 diff --git a/src/stdlib/strtod.c b/src/stdlib/strtod.c
1541 index a5d0118a..39b9daad 100644
1542 --- a/src/stdlib/strtod.c
1543 +++ b/src/stdlib/strtod.c
1544 @@ -28,10 +28,3 @@ long double strtold(const char *restrict s, char **restrict p)
1546 return strtox(s, p, 2);
1549 -weak_alias(strtof, strtof_l);
1550 -weak_alias(strtod, strtod_l);
1551 -weak_alias(strtold, strtold_l);
1552 -weak_alias(strtof, __strtof_l);
1553 -weak_alias(strtod, __strtod_l);
1554 -weak_alias(strtold, __strtold_l);
1555 diff --git a/src/thread/pthread_getname_np.c b/src/thread/pthread_getname_np.c
1556 new file mode 100644
1557 index 00000000..85504e45
1558 --- /dev/null
1559 +++ b/src/thread/pthread_getname_np.c
1560 @@ -0,0 +1,25 @@
1561 +#define _GNU_SOURCE
1562 +#include <fcntl.h>
1563 +#include <unistd.h>
1564 +#include <sys/prctl.h>
1566 +#include "pthread_impl.h"
1568 +int pthread_getname_np(pthread_t thread, char *name, size_t len)
1570 + int fd, cs, status = 0;
1571 + char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
1573 + if (len < 16) return ERANGE;
1575 + if (thread == pthread_self())
1576 + return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
1578 + snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
1579 + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
1580 + if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
1581 + else name[len-1] = 0; /* remove trailing new line only if successful */
1582 + if (fd >= 0) close(fd);
1583 + pthread_setcancelstate(cs, 0);
1584 + return status;
1586 diff --git a/src/thread/pthread_setname_np.c b/src/thread/pthread_setname_np.c
1587 index 82d35e17..fc2d2306 100644
1588 --- a/src/thread/pthread_setname_np.c
1589 +++ b/src/thread/pthread_setname_np.c
1590 @@ -19,7 +19,7 @@ int pthread_setname_np(pthread_t thread, const char *name)
1592 snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
1593 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
1594 - if ((fd = open(f, O_WRONLY)) < 0 || write(fd, name, len) < 0) status = errno;
1595 + if ((fd = open(f, O_WRONLY|O_CLOEXEC)) < 0 || write(fd, name, len) < 0) status = errno;
1596 if (fd >= 0) close(fd);
1597 pthread_setcancelstate(cs, 0);
1598 return status;
1599 diff --git a/src/time/__tz.c b/src/time/__tz.c
1600 index 09a6317e..3e2fcdcb 100644
1601 --- a/src/time/__tz.c
1602 +++ b/src/time/__tz.c
1603 @@ -4,6 +4,7 @@
1604 #include <stdlib.h>
1605 #include <string.h>
1606 #include <sys/mman.h>
1607 +#include <ctype.h>
1608 #include "libc.h"
1609 #include "lock.h"
1610 #include "fork_impl.h"
1611 @@ -154,10 +155,21 @@ static void do_tzset()
1613 if (old_tz) memcpy(old_tz, s, i+1);
1615 + int posix_form = 0;
1616 + if (*s != ':') {
1617 + p = s;
1618 + char dummy_name[TZNAME_MAX+1];
1619 + getname(dummy_name, &p);
1620 + if (p!=s && (*p == '+' || *p == '-' || isdigit(*p)
1621 + || !strcmp(dummy_name, "UTC")
1622 + || !strcmp(dummy_name, "GMT")))
1623 + posix_form = 1;
1624 + }
1626 /* Non-suid can use an absolute tzfile pathname or a relative
1627 * pathame beginning with "."; in secure mode, only the
1628 * standard path will be searched. */
1629 - if (*s == ':' || ((p=strchr(s, '/')) && !memchr(s, ',', p-s))) {
1630 + if (!posix_form) {
1631 if (*s == ':') s++;
1632 if (*s == '/' || *s == '.') {
1633 if (!libc.secure || !strcmp(s, "/etc/localtime"))