]> git.pld-linux.org Git - packages/dietlibc.git/blob - git.patch
always pass MYARCH explicitly
[packages/dietlibc.git] / git.patch
1 diff -urN -x .git dietlibc-0.33/alpha/Makefile.add dietlibc/alpha/Makefile.add
2 --- dietlibc-0.33/alpha/Makefile.add    2012-01-24 18:24:24.000000000 +0000
3 +++ dietlibc/alpha/Makefile.add 2015-01-01 12:14:43.454938895 +0000
4 @@ -3,3 +3,5 @@
5  VPATH:=alpha:syscalls.s:$(VPATH)
6  
7  LIBOBJ+=$(patsubst %,$(OBJDIR)/%,divq.o divl.o remq.o reml.o __time.o __alarm.o __CAS.o)
8 +
9 +$(OBJDIR)/__pause.o: include/signal.h
10 diff -urN -x .git dietlibc-0.33/alpha/start.S dietlibc/alpha/start.S
11 --- dietlibc-0.33/alpha/start.S 2006-05-29 16:30:53.000000000 +0000
12 +++ dietlibc/alpha/start.S      2015-01-01 12:14:43.454938895 +0000
13 @@ -24,6 +24,15 @@
14  
15         stq     $18, environ
16  
17 +#ifdef WANT_ELFINFO
18 +#  warning "MAKE ME alpha ASSEMBLER!"
19 +1:     ldq     $19, $18        ; load *envp into $19
20 +       addq    $18,  1,  $18   ; increment *envp
21 +       orr     $19, $19, $19
22 +       jne     1b
23 +       stq     $18, __elfinfo
24 +#endif
25 +
26  #ifdef WANT_DYNAMIC
27  /* in v0 ($0) is the ld.so _fini pointer */
28         mov      $0, $19        /* mov v0(dynload) to a3 */
29 diff -urN -x .git dietlibc-0.33/alpha/syscalls.h dietlibc/alpha/syscalls.h
30 --- dietlibc-0.33/alpha/syscalls.h      2008-05-06 17:18:34.000000000 +0000
31 +++ dietlibc/alpha/syscalls.h   2015-01-01 12:14:43.454938895 +0000
32 @@ -412,7 +412,38 @@
33  #define __NR_signalfd                  476
34  #define __NR_timerfd                   477
35  #define __NR_eventfd                   478
36 -
37 +#define __NR_recvmmsg                  479
38 +#define __NR_fallocate                 480
39 +#define __NR_timerfd_create            481
40 +#define __NR_timerfd_settime           482
41 +#define __NR_timerfd_gettime           483
42 +#define __NR_signalfd4                 484
43 +#define __NR_eventfd2                  485
44 +#define __NR_epoll_create1             486
45 +#define __NR_dup3                      487
46 +#define __NR_pipe2                     488
47 +#define __NR_inotify_init1             489
48 +#define __NR_preadv                    490
49 +#define __NR_pwritev                   491
50 +#define __NR_rt_tgsigqueueinfo         492
51 +#define __NR_perf_event_open           493
52 +#define __NR_fanotify_init             494
53 +#define __NR_fanotify_mark             495
54 +#define __NR_prlimit64                 496
55 +#define __NR_name_to_handle_at         497
56 +#define __NR_open_by_handle_at         498
57 +#define __NR_clock_adjtime             499
58 +#define __NR_syncfs                    500
59 +#define __NR_setns                     501
60 +#define __NR_accept4                   502
61 +#define __NR_sendmmsg                  503
62 +#define __NR_process_vm_readv          504
63 +#define __NR_process_vm_writev         505
64 +#define __NR_kcmp                      506
65 +#define __NR_finit_module              507
66 +#define __NR_sched_setattr             508
67 +#define __NR_sched_getattr             509
68 +#define __NR_renameat2                 510
69  
70  #define syscall_weak(name,wsym,sym) \
71  .text ; \
72 diff -urN -x .git dietlibc-0.33/arm/__aeabi_read_tp.S dietlibc/arm/__aeabi_read_tp.S
73 --- dietlibc-0.33/arm/__aeabi_read_tp.S 1970-01-01 00:00:00.000000000 +0000
74 +++ dietlibc/arm/__aeabi_read_tp.S      2015-01-01 12:14:43.454938895 +0000
75 @@ -0,0 +1,13 @@
76 +#include "arm-features.h"
77 +
78 +FUNC_START __aeabi_read_tp
79 +
80 +#if __ARM_ARCH__ < 6
81 +       mvn     r0, #0xf000
82 +       sub     pc, r0, #31
83 +#else
84 +       mrc     15, 0, r0, cr13, cr0, 3
85 +       bx      lr
86 +#endif
87 +
88 +FUNC_END __aeabi_read_tp
89 diff -urN -x .git dietlibc-0.33/arm/__aeabi_unwind_cpp.S dietlibc/arm/__aeabi_unwind_cpp.S
90 --- dietlibc-0.33/arm/__aeabi_unwind_cpp.S      2008-04-11 22:51:11.000000000 +0000
91 +++ dietlibc/arm/__aeabi_unwind_cpp.S   2015-01-01 12:14:43.454938895 +0000
92 @@ -1,21 +1,14 @@
93 -.text
94 -.global __aeabi_unwind_cpp_pr0
95 -.hidden __aeabi_unwind_cpp_pr0
96 -.type __aeabi_unwind_cpp_pr0, %function
97 +#include "arm-features.h"
98  
99 -.global __aeabi_unwind_cpp_pr1
100 +FUNC_START __aeabi_unwind_cpp_pr0
101 +FUNC_START __aeabi_unwind_cpp_pr1
102 +FUNC_START __aeabi_unwind_cpp_pr2
103 +.hidden __aeabi_unwind_cpp_pr0
104  .hidden __aeabi_unwind_cpp_pr1
105 -.type __aeabi_unwind_cpp_pr1, %function
106 -
107 -.global __aeabi_unwind_cpp_pr2
108  .hidden __aeabi_unwind_cpp_pr2
109 -.type __aeabi_unwind_cpp_pr2, %function
110  
111 -__aeabi_unwind_cpp_pr0:
112 -__aeabi_unwind_cpp_pr1:
113 -__aeabi_unwind_cpp_pr2:
114 -       mov     pc, lr  @ return from subroutine
115 +       RET
116  
117 -.size __aeabi_unwind_cpp_pr0,.-__aeabi_unwind_cpp_pr0
118 -.size __aeabi_unwind_cpp_pr1,.-__aeabi_unwind_cpp_pr1
119 -.size __aeabi_unwind_cpp_pr2,.-__aeabi_unwind_cpp_pr2
120 +FUNC_END  __aeabi_unwind_cpp_pr2
121 +FUNC_END  __aeabi_unwind_cpp_pr1
122 +FUNC_END  __aeabi_unwind_cpp_pr0
123 diff -urN -x .git dietlibc-0.33/arm/arm-features.h dietlibc/arm/arm-features.h
124 --- dietlibc-0.33/arm/arm-features.h    1970-01-01 00:00:00.000000000 +0000
125 +++ dietlibc/arm/arm-features.h 2015-01-01 12:14:43.454938895 +0000
126 @@ -0,0 +1,110 @@
127 +/* --*- asm -*-- */
128 +
129 +#ifndef H_DIETLIBC_ARM_FEATURES_H
130 +#define H_DIETLIBC_ARM_FEATURES_H
131 +
132 +/* Stolen from gcc (gcc/config/arm/lib1funcs.asm) */
133 +#if defined(__ARM_ARCH_2__)
134 +# define __ARM_ARCH__ 2
135 +#endif
136 +
137 +#if defined(__ARM_ARCH_3__)
138 +# define __ARM_ARCH__ 3
139 +#endif
140 +
141 +#if defined(__ARM_ARCH_3M__) || defined(__ARM_ARCH_4__) \
142 +        || defined(__ARM_ARCH_4T__)
143 +# define __ARM_ARCH__ 4
144 +#endif
145 +
146 +#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
147 +        || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
148 +        || defined(__ARM_ARCH_5TEJ__)
149 +# define __ARM_ARCH__ 5
150 +#endif
151 +
152 +#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
153 +        || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
154 +        || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
155 +        || defined(__ARM_ARCH_6M__)
156 +# define __ARM_ARCH__ 6
157 +#endif
158 +
159 +#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
160 +        || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__)
161 +# define __ARM_ARCH__ 7
162 +#endif
163 +
164 +#ifndef __ARM_ARCH__
165 +#error Unable to determine architecture.
166 +#endif
167 +
168 +#define DIET_JMPBUFSZ_REGS_REGULAR     10*32/8 /* r4-r11, sp, pc */
169 +#define DIET_JMPBUFSZ_REGS_FPv4                16*64/8 /* d0-d15 */
170 +
171 +#if !defined(__SOFTFP__) || defined(__IWMMXT__)
172 +#  define DIET_HAVE_COPROC_REGS        1
173 +#else
174 +#  undef  DIET_HAVE_COPROC_REGS
175 +#endif
176 +
177 +#ifdef __ASSEMBLER__
178 +
179 +.macro FUNC_START name
180 +       .text
181 +       .align  0
182 +       .global \name
183 +       .type   \name, %function
184 +\name:
185 +.endm
186 +
187 +.macro FUNC_START_WEAK name
188 +       .text
189 +       .align  0
190 +       .weak   \name
191 +       .type   \name, %function
192 +\name:
193 +.endm
194 +
195 +.macro FUNC_END name
196 +       .size   \name, . - \name
197 +.endm
198 +
199 +.macro RET
200 +#if (__ARM_ARCH__ > 4) || defined(__ARM_ARCH_4T__)
201 +       bx      lr
202 +#else
203 +       mov     pc, lr
204 +#endif
205 +.endm
206 +
207 +.macro SWI_UNIFIED     name
208 +#ifdef __ARM_EABI__
209 +       b       __unified_syscall_swi
210 +#else
211 +       swi     \name
212 +       b       __unified_syscall
213 +#endif
214 +.endm
215 +
216 +.macro SWI_UNIFIED4
217 +#ifdef __ARM_EABI__
218 +       b       __unified_syscall_swi
219 +#else
220 +       swi     \name
221 +       b       __unified_syscall4
222 +#endif
223 +.endm
224 +
225 +.macro LOAD_ARG4_5
226 +#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(__ARM_ARCH_5T__)
227 +       ldr     r4, [sp,#16]
228 +       ldr     r5, [sp,#20]
229 +#else
230 +       ldrd    r4, [sp,#16]
231 +#endif
232 +.endm
233 +
234 +#endif /* __ASSEMBLER__ */
235 +
236 +#endif /* H_DIETLIBC_ARM_FEATURES_H */
237 diff -urN -x .git dietlibc-0.33/arm/arm_set_tls.S dietlibc/arm/arm_set_tls.S
238 --- dietlibc-0.33/arm/arm_set_tls.S     1970-01-01 00:00:00.000000000 +0000
239 +++ dietlibc/arm/arm_set_tls.S  2015-01-01 12:14:43.454938895 +0000
240 @@ -0,0 +1,27 @@
241 +#include "syscalls.h"
242 +#include "arm-features.h"
243 +
244 +#ifdef __ARM_EABI__
245 +
246 +@ Calling convention:
247 +@   r0 ... thread data
248 +@ Returns:
249 +@   r0 ... low-level error code
250 +FUNC_START     __arm_set_tls
251 +       mov     ip, r7
252 +       ldr     r7, =__ARM_NR_set_tls
253 +       swi     0
254 +       mov     r7, ip
255 +
256 +       @ we do not have much options here to handle errors because
257 +       @ errno might not be available yet. Return error code as-is
258 +       @ and let it handle by the caller
259 +
260 +       RET
261 +FUNC_END       __arm_set_tls
262 +
263 +#else
264 +
265 +#warning "setup-tls only implemented for ARM_EABI!"
266 +
267 +#endif
268 diff -urN -x .git dietlibc-0.33/arm/clone.S dietlibc/arm/clone.S
269 --- dietlibc-0.33/arm/clone.S   2008-12-10 20:00:58.000000000 +0000
270 +++ dietlibc/arm/clone.S        2015-01-01 12:14:43.454938895 +0000
271 @@ -1,11 +1,7 @@
272 -
273  #include <errno.h>
274  #include "syscalls.h"
275 +#include "arm-features.h"
276  
277 -       .text
278 -       .weak   clone
279 -       .global __clone
280 -       
281  @
282  @ Some slightly tricky stuff here... edit with care :-)
283  @
284 @@ -15,13 +11,12 @@
285  
286  #define CLONE_VM      0x00000100
287  #define CLONE_THREAD  0x00010000
288 -       
289 +
290  @ ;  don't do this yet
291  @#define RESET_PID
292  
293 -               
294 -clone:
295 -__clone:
296 +FUNC_START_WEAK        clone
297 +FUNC_START     __clone
298         @ ; start with a sanity check
299         cmp     r0, #0
300         cmpne   r1, #0
301 @@ -31,13 +26,13 @@
302         @ ; insert args into stack
303         str     r3, [r1, #-4]!
304         str     r0, [r1, #-4]!
305 -       
306 +
307         @ ; do the system call
308         @ ; get the flags
309         mov     r0, r2
310 -#ifdef RESET_PID       
311 +#ifdef RESET_PID
312         mov     ip, r2
313 -#endif 
314 +#endif
315         @ ; child sp is already in r1
316         stmfd   sp!, {r4, r7}
317         @stmdb  sp!, {r4, r7}
318 @@ -46,14 +41,14 @@
319         ldr     r4, [sp, #16]
320          ldr     r7, =__NR_clone
321         swi     0
322 -       
323 +
324         cmp     r0, #0
325         beq     1f
326 -       ldmfd   sp!, {r4, r7}   
327 +       ldmfd   sp!, {r4, r7}
328         blt     __unified_syscall       @ (return code < 0): handle as an error
329 -       bx      lr
330 -1:     
331 -#ifdef RESET_PID               
332 +       RET
333 +1:
334 +#ifdef RESET_PID
335         tst     ip, #CLONE_THREAD
336         bne     3f
337  
338 @@ -67,21 +62,22 @@
339         swi     0
340         str     r0, [r1, #PID_OFFSET] @ ; not defined yet ??
341         str     r0, [r1, #TID_OFFSET] @ ; not defined yet ??
342 -3:     
343 +3:
344  #endif
345         @ ; pick the function arg and call address off the stack and execute
346         ldr     r0, [sp, #4]
347         mov     lr, pc
348         ldr     pc, [sp], #8
349 -       
350 +
351         @ ; and we're done, passing return value through r0
352         b       _exit                   @ branch to _exit (PIC safe)
353 +FUNC_END       __clone
354 +FUNC_END       clone
355  
356 -       
357  #else
358 -               
359 -clone:
360 -__clone:
361 +
362 +FUNC_START_WEAK        clone
363 +FUNC_START     __clone
364         movs    r12, r0                 @ check function pointer
365         cmpne   r1, #0                  @ if function check for stack pointer
366         moveq   r0, #-EINVAL            @ if one is not available set errno value
367 @@ -101,5 +97,7 @@
368         ldmia   sp!, { r0, pc }         @ load function param and jump to thread function
369  
370  1:     b       _exit                   @ branch to _exit (PIC safe)
371 +FUNC_END       __clone
372 +FUNC_END       clone
373  
374  #endif
375 diff -urN -x .git dietlibc-0.33/arm/dyn_syscalls.S dietlibc/arm/dyn_syscalls.S
376 --- dietlibc-0.33/arm/dyn_syscalls.S    2012-01-24 18:24:24.000000000 +0000
377 +++ dietlibc/arm/dyn_syscalls.S 2015-01-01 12:14:43.454938895 +0000
378 @@ -3,16 +3,21 @@
379   * Olaf Dreesen
380   */
381  
382 +#include "arm-features.h"
383 +
384  #include "../syscalls.s/environ.S"
385  #include "../syscalls.s/errno.S"
386  
387  #include <dietfeatures.h>
388  #include "syscalls.h"
389  
390 -.text
391 -__unified_syscall4:
392 +#ifdef __ARM_EABI__
393 +# error "dyn_syscall.S not ported for EABI yet"
394 +#endif
395 +
396 +FUNC_START     __unified_syscall4
397         ldmfd   sp!, {r4, r5, r6}
398 -__unified_syscall:
399 +FUNC_START     __unified_syscall
400         cmn     r0, #4096
401         movcc   pc, lr
402         rsb     r1, r0, #0
403 @@ -25,7 +30,9 @@
404  
405         mvn     r0, #0
406  #include "dietuglyweaks.h"
407 -       mov     pc, lr
408 +       RET
409 +FUNC_END       __unified_syscall
410 +FUNC_END       __unified_syscall4
411  
412  /* ok now include all syscalls.s (*.S) and sysdep *.S */
413  #include "mmap.S"
414 @@ -104,7 +111,6 @@
415  #include "../syscalls.s/n_sigprocmask.S"
416  #include "../syscalls.s/n_sigsuspend.S"
417  #include "../syscalls.s/nanosleep.S"
418 -#include "../syscalls.s/nice.S"
419  #include "../syscalls.s/open.S"
420  #include "../syscalls.s/pause.S"
421  #include "../syscalls.s/personality.S"
422 @@ -280,9 +286,11 @@
423  #include "../syscalls.s/fgetxattr.S"
424  
425  /* other asm-files w.o. changes ... */
426 -__exit:
427 +FUNC_START     __exit
428         swi     $__NR_exit
429         eor     pc,lr,lr
430 +FUNC_END       __exit
431 +
432  #define _exit __exit
433  #include "clone.S"
434  #undef _exit
435 diff -urN -x .git dietlibc-0.33/arm/__fadvise.c dietlibc/arm/__fadvise.c
436 --- dietlibc-0.33/arm/__fadvise.c       2011-03-03 18:40:05.000000000 +0000
437 +++ dietlibc/arm/__fadvise.c    2015-01-01 12:14:43.454938895 +0000
438 @@ -1,5 +1,7 @@
439 -#include <fcntl.h>
440  #include "syscalls.h"
441 +#define _LINUX_SOURCE
442 +#include <fcntl.h>
443 +#include <unistd.h>
444  
445  #ifndef __NR_fadvise64
446  long fadvise64_64(int fd, off64_t offset, off64_t len, int advice)
447 diff -urN -x .git dietlibc-0.33/arm/__guard.S dietlibc/arm/__guard.S
448 --- dietlibc-0.33/arm/__guard.S 2006-06-21 19:55:25.000000000 +0000
449 +++ dietlibc/arm/__guard.S      2015-01-01 12:14:43.454938895 +0000
450 @@ -1,4 +1,5 @@
451  .data
452 +.align 2
453  .type __guard,#object
454  .global __guard
455  .type __stack_chk_guard,#object
456 @@ -7,3 +8,5 @@
457  __stack_chk_guard:
458  .long 0xaff00
459  
460 +.size __guard, . - __guard
461 +.size __stack_chk_guard, . - __stack_chk_guard
462 diff -urN -x .git dietlibc-0.33/arm/__longjmp.S dietlibc/arm/__longjmp.S
463 --- dietlibc-0.33/arm/__longjmp.S       2001-07-02 16:06:48.000000000 +0000
464 +++ dietlibc/arm/__longjmp.S    2015-01-01 12:14:43.454938895 +0000
465 @@ -1,11 +1,23 @@
466 -.text
467 -.global __longjmp
468 -.type __longjmp,function
469 -__longjmp:
470 +#include "arm-features.h"
471 +
472 +FUNC_START     __longjmp
473         mov     ip, r0
474         movs    r0, r1
475         moveq   r0, #1
476 -#ifndef        __SOFTFP__
477 -       lfm     f4, 4, [ip], #48
478 +#ifndef __SOFTFP__
479 +# if __ARM_ARCH__ == 7
480 +       vldm    ip!, {d0-d15}
481 +#   ifdef __ARM_NEON__
482 +       vldm    ip!, {d16-d31}
483 +#   endif
484 +# else
485 +       lfm     f4, 4, [ip]!
486 +# endif
487  #endif
488 -       ldmia   ip, {r4-r11, sp, pc}
489 +
490 +#ifdef __IWMMXT__
491 +#  warning "sigjmp will not restore iwmmxt coprocessor registers"
492 +#endif
493 +
494 +       ldmia   ip!, {r4-r11, sp, pc}
495 +FUNC_END       __longjmp
496 diff -urN -x .git dietlibc-0.33/arm/Makefile.add dietlibc/arm/Makefile.add
497 --- dietlibc-0.33/arm/Makefile.add      2012-01-24 18:24:24.000000000 +0000
498 +++ dietlibc/arm/Makefile.add   2015-01-01 12:14:43.454938895 +0000
499 @@ -1,6 +1,7 @@
500  
501  LIBOBJ+=$(OBJDIR)/md5asm.o $(OBJDIR)/__aeabi_unwind_cpp.o
502  LIBOBJ+=$(OBJDIR)/__fadvise.o $(OBJDIR)/arm_fadvise.o
503 +LIBOBJ+=$(OBJDIR)/__aeabi_read_tp.o $(OBJDIR)/arm_set_tls.o
504  CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing
505  #ifdef __ARM_EABI__
506  #CFLAGS+=-mabi=aapcs-linux -mno-thumb-interwork
507 diff -urN -x .git dietlibc-0.33/arm/mcount.S dietlibc/arm/mcount.S
508 --- dietlibc-0.33/arm/mcount.S  2002-05-09 03:50:17.000000000 +0000
509 +++ dietlibc/arm/mcount.S       2015-01-01 12:14:43.454938895 +0000
510 @@ -1,4 +1,4 @@
511 -
512 +#include "arm-features.h"
513  @
514  @ mcount.S: ARM assembler implementation of mcount
515  @
516 @@ -27,11 +27,7 @@
517  @
518  @
519  
520 -.text
521 -
522 -.global mcount
523 -
524 -mcount:
525 +FUNC_START     mcount
526      mov     ip,  sp
527      stmdb   sp!, { r0 - r3, fp, ip, lr, pc }    @ build stack frame
528      sub     fp,  ip, #4                         @ setup new fp
529 @@ -43,4 +39,4 @@
530      bl      __mcount                            @ call __mcount
531  
532      ldmdb   fp,  { r0 - r3, fp, sp, pc }        @ restore context from stack frame and return.
533 -
534 +FUNC_END       mcount
535 diff -urN -x .git dietlibc-0.33/arm/md5asm.S dietlibc/arm/md5asm.S
536 --- dietlibc-0.33/arm/md5asm.S  2008-12-10 20:00:58.000000000 +0000
537 +++ dietlibc/arm/md5asm.S       2015-01-01 12:14:43.454938895 +0000
538 @@ -1,400 +1,394 @@
539 -/*****************************************************************************
540 -* Copyright (C) 2002 Andre McCurdy  <armccurdy@yahoo.co.uk>
541 -*
542 -* "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm"
543 -*
544 -* This program is free software. you can redistribute it and/or modify
545 -* it under the terms of the GNU General Public License as published by
546 -* the Free Software Foundation; either version 2 of the License, or
547 -* (at your option) any later version.
548 -*
549 -* This program is distributed in the hope that it will be useful,
550 -* but WITHOUT ANY WARRANTY, without even the implied warranty of
551 -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
552 -* GNU General Public License for more details.
553 -*
554 -* You should have received a copy of the GNU General Public License
555 -* along with this program; if not, write to the Free Software
556 -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
557 -*
558 -******************************************************************************
559 -*
560 -* History:
561 -*
562 -* 2002/02/12:  Andre McCurdy <armccurdy@yahoo.co.uk>
563 -*   - Original created.
564 -*
565 -* 2002/02/13:  Andre McCurdy <armccurdy@yahoo.co.uk>
566 -*   - Rewrote MD5Update in assembler (saves 52 bytes).
567 -*   - Added guard so we don't compile anything for Big-Endian targets.
568 -*
569 -* 2002/02/22:  Andre McCurdy <armccurdy@yahoo.co.uk>
570 -*   - Added new function MD5Update (a wrapper for the original version) which
571 -*     checks for correct 32bit alignment of the input data pointer.
572 -*   - Original MD5Update function renamed __MD5Update.
573 -*   - __MD5Transform symbol no longer exported.
574 -*
575 -* 2002/02/25:  Andre McCurdy <armccurdy@yahoo.co.uk>
576 -*   - MD5Update re-written in assembler (saves 12 bytes + lots of cycles :-)
577 -*
578 -* 2002/03/07:  Andre McCurdy <armccurdy@yahoo.co.uk>
579 -*   - _Finally_ fixed hashing from an unaligned buffer in all cases :-)
580 -*
581 -******************************************************************************
582 -*
583 -* Notes:
584 -*
585 -* This code is believed to be Position Independent (ie can be safely used
586 -* as part of a shared library).
587 -*
588 -*****************************************************************************/
589 -
590 -#include <endian.h>
591 -
592 -#if (__BYTE_ORDER == __LITTLE_ENDIAN)
593 -
594 -   .global MD5Init
595 -   .global MD5Update
596 -
597 -   .text
598 -#ifdef __ARM_EABI__
599 -   .align  4
600 -#else          
601 -   .align  2
602 -#endif
603 -       
604 -    @ --
605 -    @ void MD5Init (MD5_CTX* context);
606 -    @ --
607 -
608 -MD5Init:
609 -
610 -    adr     r1, 1f                          @ r1 = base address of MD5InitData array
611 -    ldmia   r1, { r1 - r3, r12 }            @ load 4 elements from MD5InitData array
612 -    stmia   r0, { r1 - r3, r12 }            @ store into MD5 context->state[0..3]
613 -    mov     r1, #0
614 -    str     r1, [r0, #0x10]                 @ initial count[0] = 0
615 -    str     r1, [r0, #0x14]                 @ initial count[1] = 0
616 -    mov     pc, lr                          @ return
617 -
618 -1: .word    0x67452301                      @ initial MD5 context->state[0]
619 -   .word    0xefcdab89                      @ initial MD5 context->state[1]
620 -   .word    0x98badcfe                      @ initial MD5 context->state[2]
621 -   .word    0x10325476                      @ initial MD5 context->state[3]
622 -
623 -
624 -    @ --
625 -    @ void MD5Update (MD5_CTX* context, const uint8_t* buf, signed int len);
626 -    @ --
627 -
628 -MD5Update:
629 -
630 -    stmdb   sp!, { r4 - r8, lr }
631 -    add     r4, r0, #(6 * 4)                @ r4 = &context->buffer[0]
632 -    ldmdb   r4, { r0, r3 }                  @ r0 = count[0], r3 = count[1]
633 -    mov     r5, r1                          @ r5 = input
634 -    mov     r6, r0, lsr #3                  @ r6 = (context->count[0] >> 3)
635 -    and     r6, r6, #0x3f                   @ r6 = byteIndex = ((context->count[0] >> 3) & 0x3f)
636 -    adds    r0, r0, r2, lsl #3
637 -    adc     r3, r3, r2, lsr #29
638 -    stmdb   r4, { r0, r3 }                  @ context->count += (inputBytes * 8)
639 -    rsb     r7, r6, #64                     @ r7 = (64 - byteIndex) == partLen
640 -    subs    r8, r2, r7                      @ r8 = (inputBytes - partLen)
641 -    add     r0, r4, r6
642 -    bcc     2f
643 -    mov     r2, r7
644 -    bl      memcpy                          @ memcpy (&context->buffer[byteIndex], input, partLen);
645 -    sub     r0, r4, #(6 * 4)
646 -    mov     r1, r4
647 -    mov     r2, #1
648 -    bl      __MD5Transform                  @ __MD5Transform (context->state, context->buffer, 1);
649 -    sub     r0, r4, #(6 * 4)
650 -    add     r1, r5, r7
651 -    mov     r2, r8, lsr #6                  @ r2 = len = ((inputBytes - partLen) / 64)
652 -    tst     r1, #3                          @ if (input & 0x03)
653 -    adr     lr, 1f
654 -    beq     __MD5Transform                  @ __MD5Transform (context->state, &input[partLen], len);
655 -    bne     __UnalignedMD5Transform         @ else __UnalignedMD5Transform (context->state, &input[partLen], len);
656 -1:  mov     r0, r4
657 -    bic     r2, r8, #0x3f
658 -    add     r1, r2, r7
659 -    add     r1, r1, r5
660 -    sub     r2, r8, r2
661 -2:  ldmia   sp!, { r4 - r8, lr }
662 -    b       memcpy                          @ classic tail-call optimisation...
663 -
664 -
665 -    @ --
666 -    @ static void __MD5Transform (uint32_t *buf, const uint32_t *in, int repeat);
667 -    @ --
668 -
669 -MD5MagicData:
670 -
671 -1: .word     0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee
672 -   .word     0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, ( 3f- 4f-4)
673 -   .word     0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, ( 3f- 4f-4)
674 -   .word     0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, ( 3f- 4f-4)
675 -   .word     0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, ( 4f- 4f-4)
676 -   .word     0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, ( 5f- 9f-4)
677 -   .word     0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, ( 6f- 9f-4)
678 -   .word     0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, ( 7f- 9f-4)
679 -   .word     0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, ( 9f- 9f-4)
680 -   .word     0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, (10f-14f-4)
681 -   .word     0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, (11f-14f-4)
682 -   .word     0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, (12f-14f-4)
683 -   .word     0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, (14f-14f-4)
684 -   .word     0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, (15f-19f-4)
685 -   .word     0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, (16f-19f-4)
686 -   .word     0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, (17f-19f-4)
687 -   .word     0x6e4120A9, 0x20657264, 0x7543634d, 0x00796472, (19f-19f-4)
688 -
689 -__MD5Transform:
690 -
691 -    cmp     r2, #0
692 -    moveq   pc, lr                          @ return if (repeat == 0)
693 -    stmdb   sp!, { r0, r2, r4 - r11, lr }   @ stack 'buf', 'repeat' and all callee saved registers
694 -    ldmia   r0,  { r2 - r5 }                @ r2 = a, r3 = b, r4 = c, r5 = d
695 -2:  adr     r0, 1b                          @ r0 = base address of MD5MagicData
696 -    ldmia   r0!, { r6 - r9 }                @ load first 4 elements from MD5MagicData
697 -3:  ldmia   r1!, { r10 - r12, lr }          @ r10 = in[i], r11 = in[i+1], r12 = in[i+2], lr = in[i+3]
698 -
699 -    add     r10, r10, r6                    @ r10 = in[i] + MD5MagicData[i]
700 -    eor     r6, r4, r5                      @ r6  =   (c ^ d)
701 -    and     r6, r6, r3                      @ r6  =  ((c ^ d) & b)
702 -    eor     r6, r6, r5                      @ r6  = (((c ^ d) & b) ^ d)
703 -    add     r2, r2, r6                      @ a   = (((c ^ d) & b) ^ d) + a
704 -    add     r2, r2, r10                     @ a   = (((c ^ d) & b) ^ d) + a + (in[i] + MD5MagicData[i])
705 -    add     r2, r3, r2, ROR #(32 -  7)      @ a   = b + (a rotated left by  7 places)
706 -
707 -    add     r11, r11, r7                    @ r11 = in[i+1] + MD5MagicData[i+1]
708 -    eor     r7, r3, r4                      @ r7  =   (b ^ c)
709 -    and     r7, r7, r2                      @ r7  =  ((b ^ c) & a)
710 -    eor     r7, r7, r4                      @ r7  = (((b ^ c) & a) ^ c)
711 -    add     r5, r5, r7                      @ d   = (((b ^ c) & a) ^ c) + d
712 -    add     r5, r5, r11                     @ d   = (((b ^ c) & a) ^ c) + d + (in[i+1] + MD5MagicData[i+1])
713 -    add     r5, r2, r5, ROR #(32 - 12)      @ d   = a + (d rotated left by 12 places)
714 -
715 -    add     r12, r12, r8                    @ r12 = in[i+2] + MD5MagicData[i+2]
716 -    eor     r8, r2, r3                      @ r8  =   (a ^ b)
717 -    and     r8, r8, r5                      @ r8  =  ((a ^ b) & d)
718 -    eor     r8, r8, r3                      @ r8  = (((a ^ b) & d) ^ b)
719 -    add     r4, r4, r8                      @ c   = (((a ^ b) & d) ^ b) + c
720 -    add     r4, r4, r12                     @ c   = (((a ^ b) & d) ^ b) + c + (in[i+2] + MD5MagicData[i+2])
721 -    add     r4, r5, r4, ROR #(32 - 17)      @ c   = d + (c rotated left by 17 places)
722 -
723 -    add     lr, lr, r9                      @ lr  = in[i+3] + MD5MagicData[i+3]
724 -    eor     r9, r5, r2                      @ r9  =   (d ^ a)
725 -    and     r9, r9, r4                      @ r9  =  ((d ^ a) & c)
726 -    eor     r9, r9, r2                      @ r9  = (((d ^ a) & c) ^ a)
727 -    add     r3, r3, r9                      @ b   = (((d ^ a) & c) ^ a) + b
728 -    add     r3, r3, lr                      @ b   = (((d ^ a) & c) ^ a) + b + (in[i+3] + MD5MagicData[i+3])
729 -    add     r3, r4, r3, ROR #(32 - 22)      @ b   = c + (b rotated left by 22 places)
730 -
731 -    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
732 -    add     pc, pc, r10                     @ and branch to next state
733 -
734 -4:  ldr     r10, [r1, #-(15*4)]             @ r10 = in[ 1]
735 -    ldr     r11, [r1, #-(10*4)]             @ r11 = in[ 6]
736 -    ldr     r12, [r1, #-( 5*4)]             @ r12 = in[11]
737 -    ldr     lr,  [r1, #-(16*4)]             @ lr  = in[ 0]
738 -    b       8f
739 -5:  ldr     r10, [r1, #-(11*4)]             @ r10 = in[ 5]
740 -    ldr     r11, [r1, #-( 6*4)]             @ r11 = in[10]
741 -    ldr     r12, [r1, #-( 1*4)]             @ r12 = in[15]
742 -    ldr     lr,  [r1, #-(12*4)]             @ lr  = in[ 4]
743 -    b       8f
744 -6:  ldr     r10, [r1, #-( 7*4)]             @ r10 = in[ 9]
745 -    ldr     r11, [r1, #-( 2*4)]             @ r11 = in[14]
746 -    ldr     r12, [r1, #-(13*4)]             @ r12 = in[ 3]
747 -    ldr     lr,  [r1, #-( 8*4)]             @ lr  = in[ 8]
748 -    b       8f
749 -7:  ldr     r10, [r1, #-( 3*4)]             @ r10 = in[13]
750 -    ldr     r11, [r1, #-(14*4)]             @ r11 = in[ 2]
751 -    ldr     r12, [r1, #-( 9*4)]             @ r12 = in[ 7]
752 -    ldr     lr,  [r1, #-( 4*4)]             @ lr  = in[12]
753 -
754 -8:  add     r10, r10, r6                    @ r10 = in[x] + MD5MagicData[i]
755 -    eor     r6, r3, r4                      @ r6  =   (b ^ c)
756 -    and     r6, r6, r5                      @ r6  =  ((b ^ c) & d)
757 -    eor     r6, r6, r4                      @ r6  = (((b ^ c) & d) ^ c)
758 -    add     r2, r2, r6                      @ a   = (((b ^ c) & d) ^ c) + a
759 -    add     r2, r2, r10                     @ a   = (((b ^ c) & d) ^ c) + a + (in[x] + MD5MagicData[i])
760 -    add     r2, r3, r2, ROR #(32 -  5)      @ a   = b + (a rotated left by  5 places)
761 -
762 -    add     r11, r11, r7                    @ r11 = in[x] + MD5MagicData[i+1]
763 -    eor     r7, r2, r3                      @ r7  =   (a ^ b)
764 -    and     r7, r7, r4                      @ r7  =  ((a ^ b) & c)
765 -    eor     r7, r7, r3                      @ r7  = (((a ^ b) & c) ^ b)
766 -    add     r5, r5, r7                      @ d   = (((a ^ b) & c) ^ b) + d
767 -    add     r5, r5, r11                     @ d   = (((a ^ b) & c) ^ b) + d + (in[x] + MD5MagicData[i+1])
768 -    add     r5, r2, r5, ROR #(32 -  9)      @ d   = a + (d rotated left by  9 places)
769 -
770 -    add     r12, r12, r8                    @ r12 = in[x] + MD5MagicData[i+2]
771 -    eor     r8, r5, r2                      @ r8  =   (d ^ a)
772 -    and     r8, r8, r3                      @ r8  =  ((d ^ a) & b)
773 -    eor     r8, r8, r2                      @ r8  = (((d ^ a) & b) ^ a)
774 -    add     r4, r4, r8                      @ c   = (((d ^ a) & b) ^ a) + c
775 -    add     r4, r4, r12                     @ c   = (((d ^ a) & b) ^ a) + c + (in[x] + MD5MagicData[i+2])
776 -    add     r4, r5, r4, ROR #(32 - 14)      @ c   = d + (c rotated left by 14 places)
777 -
778 -    add     lr, lr, r9                      @ lr  = in[x] + MD5MagicData[i+3]
779 -    eor     r9, r4, r5                      @ r9  =   (c ^ d)
780 -    and     r9, r9, r2                      @ r9  =  ((c ^ d) & a)
781 -    eor     r9, r9, r5                      @ r9  = (((c ^ d) & a) ^ d)
782 -    add     r3, r3, r9                      @ b   = (((c ^ d) & a) ^ d) + b
783 -    add     r3, r3, lr                      @ b   = (((c ^ d) & a) ^ d) + b + (in[x] + MD5MagicData[i+3])
784 -    add     r3, r4, r3, ROR #(32 - 20)      @ b   = c + (b rotated left by 20 places)
785 -
786 -    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
787 -    add     pc, pc, r10                     @ and branch to next state
788 -
789 -9:  ldr     r10, [r1, #-(11*4)]             @ r10 = in[ 5]
790 -    ldr     r11, [r1, #-( 8*4)]             @ r11 = in[ 8]
791 -    ldr     r12, [r1, #-( 5*4)]             @ r12 = in[11]
792 -    ldr     lr,  [r1, #-( 2*4)]             @ lr  = in[14]
793 -    b       13f
794 -10: ldr     r10, [r1, #-(15*4)]             @ r10 = in[ 1]
795 -    ldr     r11, [r1, #-(12*4)]             @ r11 = in[ 4]
796 -    ldr     r12, [r1, #-( 9*4)]             @ r12 = in[ 7]
797 -    ldr     lr,  [r1, #-( 6*4)]             @ lr  = in[10]
798 -    b       13f
799 -11: ldr     r10, [r1, #-( 3*4)]             @ r10 = in[13]
800 -    ldr     r11, [r1, #-(16*4)]             @ r11 = in[ 0]
801 -    ldr     r12, [r1, #-(13*4)]             @ r12 = in[ 3]
802 -    ldr     lr,  [r1, #-(10*4)]             @ lr  = in[ 6]
803 -    b       13f
804 -12: ldr     r10, [r1, #-( 7*4)]             @ r10 = in[ 9]
805 -    ldr     r11, [r1, #-( 4*4)]             @ r11 = in[12]
806 -    ldr     r12, [r1, #-( 1*4)]             @ r12 = in[15]
807 -    ldr     lr,  [r1, #-(14*4)]             @ lr  = in[ 2]
808 -
809 -13: add     r10, r10, r6                    @ r10 = in[x] + MD5MagicData[i]
810 -    add     r2, r2, r10                     @ a  += in[x] + MD5MagicData[i]
811 -    eor     r6, r3, r4                      @ r6  = (b ^ c)
812 -    eor     r10, r6, r5                     @ r10 = (b ^ c ^ d)
813 -    add     r2, r2, r10                     @ a  += (b ^ c ^ d)
814 -    add     r2, r3, r2, ROR #(32 -  4)      @ a   = b + (a rotated left by  4 places)
815 -
816 -    add     r11, r11, r7                    @ r11 = in[x] + MD5MagicData[i+1]
817 -    eor     r7, r2, r6                      @ r7  = (a ^ b ^ c)
818 -    add     r5, r5, r7                      @ d   = (a ^ b ^ c) + d
819 -    add     r5, r5, r11                     @ d   = (a ^ b ^ c) + d + (in[x] + MD5MagicData[i+1])
820 -    add     r5, r2, r5, ROR #(32 - 11)      @ d   = a + (d rotated left by 11 places)
821 -
822 -    add     r12, r12, r8                    @ r12 = in[x] + MD5MagicData[i+2]
823 -    add     r4, r4, r12                     @ c  += in[x] + MD5MagicData[i+2]
824 -    eor     r8, r5, r2                      @ r8  = (d ^ a)
825 -    eor     r12, r8, r3                     @ r12 = (d ^ a ^ b)
826 -    add     r4, r4, r12                     @ c  += (d ^ a ^ b)
827 -    add     r4, r5, r4, ROR #(32 - 16)      @ c   = d + (c rotated left by 16 places)
828 -
829 -    add     lr, lr, r9                      @ lr  = in[x] + MD5MagicData[i+3]
830 -    eor     r9, r4, r8                      @ r9  = (c ^ d ^ a)
831 -    add     r3, r3, r9                      @ b   = (c ^ d ^ a) + b
832 -    add     r3, r3, lr                      @ b   = (c ^ d ^ a) + b + (in[x] + MD5MagicData[i+3])
833 -    add     r3, r4, r3, ROR #(32 - 23)      @ b   = c + (b rotated left by 23 places)
834 -
835 -    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
836 -    add     pc, pc, r10                     @ and branch to next state
837 -
838 -14: ldr     r10, [r1, #-(16*4)]             @ r10 = in[ 0]
839 -    ldr     r11, [r1, #-( 9*4)]             @ r11 = in[ 7]
840 -    ldr     r12, [r1, #-( 2*4)]             @ r12 = in[14]
841 -    ldr     lr,  [r1, #-(11*4)]             @ lr  = in[ 5]
842 -    b       18f
843 -15: ldr     r10, [r1, #-( 4*4)]             @ r10 = in[12]
844 -    ldr     r11, [r1, #-(13*4)]             @ r11 = in[ 3]
845 -    ldr     r12, [r1, #-( 6*4)]             @ r12 = in[10]
846 -    ldr     lr,  [r1, #-(15*4)]             @ lr  = in[ 1]
847 -    b       18f
848 -16: ldr     r10, [r1, #-( 8*4)]             @ r10 = in[ 8]
849 -    ldr     r11, [r1, #-( 1*4)]             @ r11 = in[15]
850 -    ldr     r12, [r1, #-(10*4)]             @ r12 = in[ 6]
851 -    ldr     lr,  [r1, #-( 3*4)]             @ lr  = in[13]
852 -    b       18f
853 -17: ldr     r10, [r1, #-(12*4)]             @ r10 = in[ 4]
854 -    ldr     r11, [r1, #-( 5*4)]             @ r11 = in[11]
855 -    ldr     r12, [r1, #-(14*4)]             @ r12 = in[ 2]
856 -    ldr     lr,  [r1, #-( 7*4)]             @ lr  = in[ 9]
857 -
858 -18: add     r10, r10, r6                    @ r10 = in[x] + MD5MagicData[i]
859 -    add     r2, r2, r10                     @ a  += in[x] + MD5MagicData[i]
860 -    mvn     r6, r5                          @ r6  =      (    ~d)
861 -    orr     r6, r6, r3                      @ r6  =      (b | ~d)
862 -    eor     r6, r6, r4                      @ r6  = (c ^ (b | ~d))
863 -    add     r2, r2, r6                      @ a  += (c ^ (b | ~d))
864 -    add     r2, r3, r2, ROR #(32 -  6)      @ a   = b + (a rotated left by  6 places)
865 -
866 -    add     r11, r11, r7                    @ r11 = in[x] + MD5MagicData[i]
867 -    add     r5, r5, r11                     @ d  += in[x] + MD5MagicData[i]
868 -    mvn     r7, r4                          @ r7  =      (    ~c)
869 -    orr     r7, r7, r2                      @ r7  =      (a | ~c)
870 -    eor     r7, r7, r3                      @ r7  = (b ^ (a | ~c))
871 -    add     r5, r5, r7                      @ d  += (b ^ (a | ~c))
872 -    add     r5, r2, r5, ROR #(32 - 10)      @ d   = a + (d rotated left by 10 places)
873 -
874 -    add     r12, r12, r8                    @ r12 = in[x] + MD5MagicData[i]
875 -    add     r4, r4, r12                     @ c  += in[x] + MD5MagicData[i]
876 -    mvn     r8, r3                          @ r8  =      (    ~b)
877 -    orr     r8, r8, r5                      @ r8  =      (d | ~b)
878 -    eor     r8, r8, r2                      @ r8  = (a ^ (d | ~b))
879 -    add     r4, r4, r8                      @ c  += (a ^ (d | ~b))
880 -    add     r4, r5, r4, ROR #(32 - 15)      @ c   = d + (c rotated left by 15 places)
881 -
882 -    add     lr, lr, r9                      @ lr  = in[x] + MD5MagicData[i]
883 -    add     r3, r3, lr                      @ b  += in[x] + MD5MagicData[i]
884 -    mvn     r9, r2                          @ r9  =      (    ~a)
885 -    orr     r9, r9, r4                      @ r9  =      (c | ~a)
886 -    eor     r9, r9, r5                      @ r9  = (d ^ (c | ~a))
887 -    add     r3, r3, r9                      @ b  += (d ^ (c | ~a))
888 -    add     r3, r4, r3, ROR #(32 - 21)      @ b   = c + (b rotated left by 21 places)
889 -
890 -    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
891 -    add     pc, pc, r10                     @ and branch to next state
892 -
893 -19: ldmia   sp, { r0, r10 }                 @ fetch 'buf' and 'repeat' from the stack
894 -    ldmia   r0, { r6 - r9 }                 @ r6 = buf[0], r7 = buf[1], r8 = buf[2], r9 = buf[3] (original values..)
895 -    subs    r10, r10, #1
896 -    strne   r10, [sp, #4]
897 -    add     r2, r6, r2
898 -    add     r3, r7, r3
899 -    add     r4, r8, r4
900 -    add     r5, r9, r5
901 -    stmia   r0, { r2 - r5 }
902 -    bne     2b
903 -    ldmia   sp!, { r0, r2, r4 - r11, pc }   @ restore all callee saved registers and return
904 -
905 -
906 -    @ --
907 -    @ static void __UnalignedMD5Transform (uint32_t *buf, const uint8_t *in, int repeat);
908 -    @ --
909 -
910 -__UnalignedMD5Transform:
911 -
912 -    stmdb   sp!, { r4 - r7, lr }
913 -    movs    r4, r2, lsl #6                  @ r4 = (repeat * 64)
914 -    ldmeqia sp!, { r4 - r7, pc }            @ if  ((repeat * 64) == 0) return;
915 -    mov     r5, r0                          @ r5 = state
916 -    mov     r6, r1                          @ r6 = in
917 -    sub     sp, sp, #256                    @ create 256 byte temp buffer
918 -1:  cmp     r4, #256
919 -    mov     r0, sp
920 -    movcc   r7, r4
921 -    movcs   r7, #256                        @ r7 = (blockCount * 64) = min((repeat * 64), (4 * 64))
922 -    mov     r1, r6
923 -    mov     r2, r7
924 -    bl      memcpy                          @ memcpy (blockBuffer, in, (blockCount * 64));
925 -    mov     r0, r5
926 -    mov     r1, sp
927 -    mov     r2, r7, lsr #6
928 -    bl      __MD5Transform                  @ __MD5Transform (state, blockBuffer, blockCount);
929 -    subs    r4, r4, #256                    @ (repeat * 64) -= (4 * 64);
930 -    add     r6, r6, #256                    @ in += (4 * 64);
931 -    bgt     1b                              @ loop while (repeat > 0)
932 -    add     sp, sp, #256                    @ return temp buffer to stack
933 -    ldmia   sp!, { r4 - r7, pc }            @ return
934 -
935 -
936 -#endif   /* __BYTE_ORDER == __LITTLE_ENDIAN */
937 -
938 -
939 +#include "arm-features.h"
940 +
941 +/*****************************************************************************
942 +* Copyright (C) 2002 Andre McCurdy  <armccurdy@yahoo.co.uk>
943 +*
944 +* "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm"
945 +*
946 +* This program is free software. you can redistribute it and/or modify
947 +* it under the terms of the GNU General Public License as published by
948 +* the Free Software Foundation; either version 2 of the License, or
949 +* (at your option) any later version.
950 +*
951 +* This program is distributed in the hope that it will be useful,
952 +* but WITHOUT ANY WARRANTY, without even the implied warranty of
953 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
954 +* GNU General Public License for more details.
955 +*
956 +* You should have received a copy of the GNU General Public License
957 +* along with this program; if not, write to the Free Software
958 +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
959 +*
960 +******************************************************************************
961 +*
962 +* History:
963 +*
964 +* 2002/02/12:  Andre McCurdy <armccurdy@yahoo.co.uk>
965 +*   - Original created.
966 +*
967 +* 2002/02/13:  Andre McCurdy <armccurdy@yahoo.co.uk>
968 +*   - Rewrote MD5Update in assembler (saves 52 bytes).
969 +*   - Added guard so we don't compile anything for Big-Endian targets.
970 +*
971 +* 2002/02/22:  Andre McCurdy <armccurdy@yahoo.co.uk>
972 +*   - Added new function MD5Update (a wrapper for the original version) which
973 +*     checks for correct 32bit alignment of the input data pointer.
974 +*   - Original MD5Update function renamed __MD5Update.
975 +*   - __MD5Transform symbol no longer exported.
976 +*
977 +* 2002/02/25:  Andre McCurdy <armccurdy@yahoo.co.uk>
978 +*   - MD5Update re-written in assembler (saves 12 bytes + lots of cycles :-)
979 +*
980 +* 2002/03/07:  Andre McCurdy <armccurdy@yahoo.co.uk>
981 +*   - _Finally_ fixed hashing from an unaligned buffer in all cases :-)
982 +*
983 +******************************************************************************
984 +*
985 +* Notes:
986 +*
987 +* This code is believed to be Position Independent (ie can be safely used
988 +* as part of a shared library).
989 +*
990 +*****************************************************************************/
991 +
992 +#include <endian.h>
993 +#include "arm-features.h"
994 +
995 +#if (__BYTE_ORDER == __LITTLE_ENDIAN)
996 +
997 +    @ --
998 +    @ void MD5Init (MD5_CTX* context);
999 +    @ --
1000 +
1001 +FUNC_START     MD5Init
1002 +    adr     r1, 1f                          @ r1 = base address of MD5InitData array
1003 +    ldmia   r1, { r1 - r3, r12 }            @ load 4 elements from MD5InitData array
1004 +    stmia   r0, { r1 - r3, r12 }            @ store into MD5 context->state[0..3]
1005 +    mov     r1, #0
1006 +    str     r1, [r0, #0x10]                 @ initial count[0] = 0
1007 +    str     r1, [r0, #0x14]                 @ initial count[1] = 0
1008 +    RET
1009 +
1010 +   .align 3
1011 +1: .word    0x67452301                      @ initial MD5 context->state[0]
1012 +   .word    0xefcdab89                      @ initial MD5 context->state[1]
1013 +   .word    0x98badcfe                      @ initial MD5 context->state[2]
1014 +   .word    0x10325476                      @ initial MD5 context->state[3]
1015 +FUNC_END       MD5Init
1016 +
1017 +    @ --
1018 +    @ void MD5Update (MD5_CTX* context, const uint8_t* buf, signed int len);
1019 +    @ --
1020 +
1021 +FUNC_START     MD5Update
1022 +    stmdb   sp!, { r4 - r8, lr }
1023 +    add     r4, r0, #(6 * 4)                @ r4 = &context->buffer[0]
1024 +    ldmdb   r4, { r0, r3 }                  @ r0 = count[0], r3 = count[1]
1025 +    mov     r5, r1                          @ r5 = input
1026 +    mov     r6, r0, lsr #3                  @ r6 = (context->count[0] >> 3)
1027 +    and     r6, r6, #0x3f                   @ r6 = byteIndex = ((context->count[0] >> 3) & 0x3f)
1028 +    adds    r0, r0, r2, lsl #3
1029 +    adc     r3, r3, r2, lsr #29
1030 +    stmdb   r4, { r0, r3 }                  @ context->count += (inputBytes * 8)
1031 +    rsb     r7, r6, #64                     @ r7 = (64 - byteIndex) == partLen
1032 +    subs    r8, r2, r7                      @ r8 = (inputBytes - partLen)
1033 +    add     r0, r4, r6
1034 +    bcc     2f
1035 +    mov     r2, r7
1036 +    bl      memcpy                          @ memcpy (&context->buffer[byteIndex], input, partLen);
1037 +    sub     r0, r4, #(6 * 4)
1038 +    mov     r1, r4
1039 +    mov     r2, #1
1040 +    bl      __MD5Transform                  @ __MD5Transform (context->state, context->buffer, 1);
1041 +    sub     r0, r4, #(6 * 4)
1042 +    add     r1, r5, r7
1043 +    mov     r2, r8, lsr #6                  @ r2 = len = ((inputBytes - partLen) / 64)
1044 +    tst     r1, #3                          @ if (input & 0x03)
1045 +    adr     lr, 1f
1046 +    beq     __MD5Transform                  @ __MD5Transform (context->state, &input[partLen], len);
1047 +    bne     __UnalignedMD5Transform         @ else __UnalignedMD5Transform (context->state, &input[partLen], len);
1048 +1:  mov     r0, r4
1049 +    bic     r2, r8, #0x3f
1050 +    add     r1, r2, r7
1051 +    add     r1, r1, r5
1052 +    sub     r2, r8, r2
1053 +2:  ldmia   sp!, { r4 - r8, lr }
1054 +    b       memcpy                          @ classic tail-call optimisation...
1055 +FUNC_END       MD5Update
1056 +
1057 +    @ --
1058 +    @ static void __MD5Transform (uint32_t *buf, const uint32_t *in, int repeat);
1059 +    @ --
1060 +
1061 +.align 3
1062 +MD5MagicData:
1063 +
1064 +1: .word     0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee
1065 +   .word     0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, ( 3f- 4f-4)
1066 +   .word     0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, ( 3f- 4f-4)
1067 +   .word     0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, ( 3f- 4f-4)
1068 +   .word     0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, ( 4f- 4f-4)
1069 +   .word     0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, ( 5f- 9f-4)
1070 +   .word     0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, ( 6f- 9f-4)
1071 +   .word     0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, ( 7f- 9f-4)
1072 +   .word     0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, ( 9f- 9f-4)
1073 +   .word     0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, (10f-14f-4)
1074 +   .word     0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, (11f-14f-4)
1075 +   .word     0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, (12f-14f-4)
1076 +   .word     0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, (14f-14f-4)
1077 +   .word     0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, (15f-19f-4)
1078 +   .word     0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, (16f-19f-4)
1079 +   .word     0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, (17f-19f-4)
1080 +   .word     0x6e4120A9, 0x20657264, 0x7543634d, 0x00796472, (19f-19f-4)
1081 +
1082 +.align 2
1083 +__MD5Transform:
1084 +
1085 +    cmp     r2, #0
1086 +    moveq   pc, lr                          @ return if (repeat == 0)
1087 +    stmdb   sp!, { r0, r2, r4 - r11, lr }   @ stack 'buf', 'repeat' and all callee saved registers
1088 +    ldmia   r0,  { r2 - r5 }                @ r2 = a, r3 = b, r4 = c, r5 = d
1089 +2:  adr     r0, 1b                          @ r0 = base address of MD5MagicData
1090 +    ldmia   r0!, { r6 - r9 }                @ load first 4 elements from MD5MagicData
1091 +3:  ldmia   r1!, { r10 - r12, lr }          @ r10 = in[i], r11 = in[i+1], r12 = in[i+2], lr = in[i+3]
1092 +
1093 +    add     r10, r10, r6                    @ r10 = in[i] + MD5MagicData[i]
1094 +    eor     r6, r4, r5                      @ r6  =   (c ^ d)
1095 +    and     r6, r6, r3                      @ r6  =  ((c ^ d) & b)
1096 +    eor     r6, r6, r5                      @ r6  = (((c ^ d) & b) ^ d)
1097 +    add     r2, r2, r6                      @ a   = (((c ^ d) & b) ^ d) + a
1098 +    add     r2, r2, r10                     @ a   = (((c ^ d) & b) ^ d) + a + (in[i] + MD5MagicData[i])
1099 +    add     r2, r3, r2, ROR #(32 -  7)      @ a   = b + (a rotated left by  7 places)
1100 +
1101 +    add     r11, r11, r7                    @ r11 = in[i+1] + MD5MagicData[i+1]
1102 +    eor     r7, r3, r4                      @ r7  =   (b ^ c)
1103 +    and     r7, r7, r2                      @ r7  =  ((b ^ c) & a)
1104 +    eor     r7, r7, r4                      @ r7  = (((b ^ c) & a) ^ c)
1105 +    add     r5, r5, r7                      @ d   = (((b ^ c) & a) ^ c) + d
1106 +    add     r5, r5, r11                     @ d   = (((b ^ c) & a) ^ c) + d + (in[i+1] + MD5MagicData[i+1])
1107 +    add     r5, r2, r5, ROR #(32 - 12)      @ d   = a + (d rotated left by 12 places)
1108 +
1109 +    add     r12, r12, r8                    @ r12 = in[i+2] + MD5MagicData[i+2]
1110 +    eor     r8, r2, r3                      @ r8  =   (a ^ b)
1111 +    and     r8, r8, r5                      @ r8  =  ((a ^ b) & d)
1112 +    eor     r8, r8, r3                      @ r8  = (((a ^ b) & d) ^ b)
1113 +    add     r4, r4, r8                      @ c   = (((a ^ b) & d) ^ b) + c
1114 +    add     r4, r4, r12                     @ c   = (((a ^ b) & d) ^ b) + c + (in[i+2] + MD5MagicData[i+2])
1115 +    add     r4, r5, r4, ROR #(32 - 17)      @ c   = d + (c rotated left by 17 places)
1116 +
1117 +    add     lr, lr, r9                      @ lr  = in[i+3] + MD5MagicData[i+3]
1118 +    eor     r9, r5, r2                      @ r9  =   (d ^ a)
1119 +    and     r9, r9, r4                      @ r9  =  ((d ^ a) & c)
1120 +    eor     r9, r9, r2                      @ r9  = (((d ^ a) & c) ^ a)
1121 +    add     r3, r3, r9                      @ b   = (((d ^ a) & c) ^ a) + b
1122 +    add     r3, r3, lr                      @ b   = (((d ^ a) & c) ^ a) + b + (in[i+3] + MD5MagicData[i+3])
1123 +    add     r3, r4, r3, ROR #(32 - 22)      @ b   = c + (b rotated left by 22 places)
1124 +
1125 +    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
1126 +    add     pc, pc, r10                     @ and branch to next state
1127 +
1128 +4:  ldr     r10, [r1, #-(15*4)]             @ r10 = in[ 1]
1129 +    ldr     r11, [r1, #-(10*4)]             @ r11 = in[ 6]
1130 +    ldr     r12, [r1, #-( 5*4)]             @ r12 = in[11]
1131 +    ldr     lr,  [r1, #-(16*4)]             @ lr  = in[ 0]
1132 +    b       8f
1133 +5:  ldr     r10, [r1, #-(11*4)]             @ r10 = in[ 5]
1134 +    ldr     r11, [r1, #-( 6*4)]             @ r11 = in[10]
1135 +    ldr     r12, [r1, #-( 1*4)]             @ r12 = in[15]
1136 +    ldr     lr,  [r1, #-(12*4)]             @ lr  = in[ 4]
1137 +    b       8f
1138 +6:  ldr     r10, [r1, #-( 7*4)]             @ r10 = in[ 9]
1139 +    ldr     r11, [r1, #-( 2*4)]             @ r11 = in[14]
1140 +    ldr     r12, [r1, #-(13*4)]             @ r12 = in[ 3]
1141 +    ldr     lr,  [r1, #-( 8*4)]             @ lr  = in[ 8]
1142 +    b       8f
1143 +7:  ldr     r10, [r1, #-( 3*4)]             @ r10 = in[13]
1144 +    ldr     r11, [r1, #-(14*4)]             @ r11 = in[ 2]
1145 +    ldr     r12, [r1, #-( 9*4)]             @ r12 = in[ 7]
1146 +    ldr     lr,  [r1, #-( 4*4)]             @ lr  = in[12]
1147 +
1148 +8:  add     r10, r10, r6                    @ r10 = in[x] + MD5MagicData[i]
1149 +    eor     r6, r3, r4                      @ r6  =   (b ^ c)
1150 +    and     r6, r6, r5                      @ r6  =  ((b ^ c) & d)
1151 +    eor     r6, r6, r4                      @ r6  = (((b ^ c) & d) ^ c)
1152 +    add     r2, r2, r6                      @ a   = (((b ^ c) & d) ^ c) + a
1153 +    add     r2, r2, r10                     @ a   = (((b ^ c) & d) ^ c) + a + (in[x] + MD5MagicData[i])
1154 +    add     r2, r3, r2, ROR #(32 -  5)      @ a   = b + (a rotated left by  5 places)
1155 +
1156 +    add     r11, r11, r7                    @ r11 = in[x] + MD5MagicData[i+1]
1157 +    eor     r7, r2, r3                      @ r7  =   (a ^ b)
1158 +    and     r7, r7, r4                      @ r7  =  ((a ^ b) & c)
1159 +    eor     r7, r7, r3                      @ r7  = (((a ^ b) & c) ^ b)
1160 +    add     r5, r5, r7                      @ d   = (((a ^ b) & c) ^ b) + d
1161 +    add     r5, r5, r11                     @ d   = (((a ^ b) & c) ^ b) + d + (in[x] + MD5MagicData[i+1])
1162 +    add     r5, r2, r5, ROR #(32 -  9)      @ d   = a + (d rotated left by  9 places)
1163 +
1164 +    add     r12, r12, r8                    @ r12 = in[x] + MD5MagicData[i+2]
1165 +    eor     r8, r5, r2                      @ r8  =   (d ^ a)
1166 +    and     r8, r8, r3                      @ r8  =  ((d ^ a) & b)
1167 +    eor     r8, r8, r2                      @ r8  = (((d ^ a) & b) ^ a)
1168 +    add     r4, r4, r8                      @ c   = (((d ^ a) & b) ^ a) + c
1169 +    add     r4, r4, r12                     @ c   = (((d ^ a) & b) ^ a) + c + (in[x] + MD5MagicData[i+2])
1170 +    add     r4, r5, r4, ROR #(32 - 14)      @ c   = d + (c rotated left by 14 places)
1171 +
1172 +    add     lr, lr, r9                      @ lr  = in[x] + MD5MagicData[i+3]
1173 +    eor     r9, r4, r5                      @ r9  =   (c ^ d)
1174 +    and     r9, r9, r2                      @ r9  =  ((c ^ d) & a)
1175 +    eor     r9, r9, r5                      @ r9  = (((c ^ d) & a) ^ d)
1176 +    add     r3, r3, r9                      @ b   = (((c ^ d) & a) ^ d) + b
1177 +    add     r3, r3, lr                      @ b   = (((c ^ d) & a) ^ d) + b + (in[x] + MD5MagicData[i+3])
1178 +    add     r3, r4, r3, ROR #(32 - 20)      @ b   = c + (b rotated left by 20 places)
1179 +
1180 +    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
1181 +    add     pc, pc, r10                     @ and branch to next state
1182 +
1183 +9:  ldr     r10, [r1, #-(11*4)]             @ r10 = in[ 5]
1184 +    ldr     r11, [r1, #-( 8*4)]             @ r11 = in[ 8]
1185 +    ldr     r12, [r1, #-( 5*4)]             @ r12 = in[11]
1186 +    ldr     lr,  [r1, #-( 2*4)]             @ lr  = in[14]
1187 +    b       13f
1188 +10: ldr     r10, [r1, #-(15*4)]             @ r10 = in[ 1]
1189 +    ldr     r11, [r1, #-(12*4)]             @ r11 = in[ 4]
1190 +    ldr     r12, [r1, #-( 9*4)]             @ r12 = in[ 7]
1191 +    ldr     lr,  [r1, #-( 6*4)]             @ lr  = in[10]
1192 +    b       13f
1193 +11: ldr     r10, [r1, #-( 3*4)]             @ r10 = in[13]
1194 +    ldr     r11, [r1, #-(16*4)]             @ r11 = in[ 0]
1195 +    ldr     r12, [r1, #-(13*4)]             @ r12 = in[ 3]
1196 +    ldr     lr,  [r1, #-(10*4)]             @ lr  = in[ 6]
1197 +    b       13f
1198 +12: ldr     r10, [r1, #-( 7*4)]             @ r10 = in[ 9]
1199 +    ldr     r11, [r1, #-( 4*4)]             @ r11 = in[12]
1200 +    ldr     r12, [r1, #-( 1*4)]             @ r12 = in[15]
1201 +    ldr     lr,  [r1, #-(14*4)]             @ lr  = in[ 2]
1202 +
1203 +13: add     r10, r10, r6                    @ r10 = in[x] + MD5MagicData[i]
1204 +    add     r2, r2, r10                     @ a  += in[x] + MD5MagicData[i]
1205 +    eor     r6, r3, r4                      @ r6  = (b ^ c)
1206 +    eor     r10, r6, r5                     @ r10 = (b ^ c ^ d)
1207 +    add     r2, r2, r10                     @ a  += (b ^ c ^ d)
1208 +    add     r2, r3, r2, ROR #(32 -  4)      @ a   = b + (a rotated left by  4 places)
1209 +
1210 +    add     r11, r11, r7                    @ r11 = in[x] + MD5MagicData[i+1]
1211 +    eor     r7, r2, r6                      @ r7  = (a ^ b ^ c)
1212 +    add     r5, r5, r7                      @ d   = (a ^ b ^ c) + d
1213 +    add     r5, r5, r11                     @ d   = (a ^ b ^ c) + d + (in[x] + MD5MagicData[i+1])
1214 +    add     r5, r2, r5, ROR #(32 - 11)      @ d   = a + (d rotated left by 11 places)
1215 +
1216 +    add     r12, r12, r8                    @ r12 = in[x] + MD5MagicData[i+2]
1217 +    add     r4, r4, r12                     @ c  += in[x] + MD5MagicData[i+2]
1218 +    eor     r8, r5, r2                      @ r8  = (d ^ a)
1219 +    eor     r12, r8, r3                     @ r12 = (d ^ a ^ b)
1220 +    add     r4, r4, r12                     @ c  += (d ^ a ^ b)
1221 +    add     r4, r5, r4, ROR #(32 - 16)      @ c   = d + (c rotated left by 16 places)
1222 +
1223 +    add     lr, lr, r9                      @ lr  = in[x] + MD5MagicData[i+3]
1224 +    eor     r9, r4, r8                      @ r9  = (c ^ d ^ a)
1225 +    add     r3, r3, r9                      @ b   = (c ^ d ^ a) + b
1226 +    add     r3, r3, lr                      @ b   = (c ^ d ^ a) + b + (in[x] + MD5MagicData[i+3])
1227 +    add     r3, r4, r3, ROR #(32 - 23)      @ b   = c + (b rotated left by 23 places)
1228 +
1229 +    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
1230 +    add     pc, pc, r10                     @ and branch to next state
1231 +
1232 +14: ldr     r10, [r1, #-(16*4)]             @ r10 = in[ 0]
1233 +    ldr     r11, [r1, #-( 9*4)]             @ r11 = in[ 7]
1234 +    ldr     r12, [r1, #-( 2*4)]             @ r12 = in[14]
1235 +    ldr     lr,  [r1, #-(11*4)]             @ lr  = in[ 5]
1236 +    b       18f
1237 +15: ldr     r10, [r1, #-( 4*4)]             @ r10 = in[12]
1238 +    ldr     r11, [r1, #-(13*4)]             @ r11 = in[ 3]
1239 +    ldr     r12, [r1, #-( 6*4)]             @ r12 = in[10]
1240 +    ldr     lr,  [r1, #-(15*4)]             @ lr  = in[ 1]
1241 +    b       18f
1242 +16: ldr     r10, [r1, #-( 8*4)]             @ r10 = in[ 8]
1243 +    ldr     r11, [r1, #-( 1*4)]             @ r11 = in[15]
1244 +    ldr     r12, [r1, #-(10*4)]             @ r12 = in[ 6]
1245 +    ldr     lr,  [r1, #-( 3*4)]             @ lr  = in[13]
1246 +    b       18f
1247 +17: ldr     r10, [r1, #-(12*4)]             @ r10 = in[ 4]
1248 +    ldr     r11, [r1, #-( 5*4)]             @ r11 = in[11]
1249 +    ldr     r12, [r1, #-(14*4)]             @ r12 = in[ 2]
1250 +    ldr     lr,  [r1, #-( 7*4)]             @ lr  = in[ 9]
1251 +
1252 +18: add     r10, r10, r6                    @ r10 = in[x] + MD5MagicData[i]
1253 +    add     r2, r2, r10                     @ a  += in[x] + MD5MagicData[i]
1254 +    mvn     r6, r5                          @ r6  =      (    ~d)
1255 +    orr     r6, r6, r3                      @ r6  =      (b | ~d)
1256 +    eor     r6, r6, r4                      @ r6  = (c ^ (b | ~d))
1257 +    add     r2, r2, r6                      @ a  += (c ^ (b | ~d))
1258 +    add     r2, r3, r2, ROR #(32 -  6)      @ a   = b + (a rotated left by  6 places)
1259 +
1260 +    add     r11, r11, r7                    @ r11 = in[x] + MD5MagicData[i]
1261 +    add     r5, r5, r11                     @ d  += in[x] + MD5MagicData[i]
1262 +    mvn     r7, r4                          @ r7  =      (    ~c)
1263 +    orr     r7, r7, r2                      @ r7  =      (a | ~c)
1264 +    eor     r7, r7, r3                      @ r7  = (b ^ (a | ~c))
1265 +    add     r5, r5, r7                      @ d  += (b ^ (a | ~c))
1266 +    add     r5, r2, r5, ROR #(32 - 10)      @ d   = a + (d rotated left by 10 places)
1267 +
1268 +    add     r12, r12, r8                    @ r12 = in[x] + MD5MagicData[i]
1269 +    add     r4, r4, r12                     @ c  += in[x] + MD5MagicData[i]
1270 +    mvn     r8, r3                          @ r8  =      (    ~b)
1271 +    orr     r8, r8, r5                      @ r8  =      (d | ~b)
1272 +    eor     r8, r8, r2                      @ r8  = (a ^ (d | ~b))
1273 +    add     r4, r4, r8                      @ c  += (a ^ (d | ~b))
1274 +    add     r4, r5, r4, ROR #(32 - 15)      @ c   = d + (c rotated left by 15 places)
1275 +
1276 +    add     lr, lr, r9                      @ lr  = in[x] + MD5MagicData[i]
1277 +    add     r3, r3, lr                      @ b  += in[x] + MD5MagicData[i]
1278 +    mvn     r9, r2                          @ r9  =      (    ~a)
1279 +    orr     r9, r9, r4                      @ r9  =      (c | ~a)
1280 +    eor     r9, r9, r5                      @ r9  = (d ^ (c | ~a))
1281 +    add     r3, r3, r9                      @ b  += (d ^ (c | ~a))
1282 +    add     r3, r4, r3, ROR #(32 - 21)      @ b   = c + (b rotated left by 21 places)
1283 +
1284 +    ldmia   r0!, { r6 - r10 }               @ load next 4 elements from MD5MagicData
1285 +    add     pc, pc, r10                     @ and branch to next state
1286 +
1287 +19: ldmia   sp, { r0, r10 }                 @ fetch 'buf' and 'repeat' from the stack
1288 +    ldmia   r0, { r6 - r9 }                 @ r6 = buf[0], r7 = buf[1], r8 = buf[2], r9 = buf[3] (original values..)
1289 +    subs    r10, r10, #1
1290 +    strne   r10, [sp, #4]
1291 +    add     r2, r6, r2
1292 +    add     r3, r7, r3
1293 +    add     r4, r8, r4
1294 +    add     r5, r9, r5
1295 +    stmia   r0, { r2 - r5 }
1296 +    bne     2b
1297 +    ldmia   sp!, { r0, r2, r4 - r11, pc }   @ restore all callee saved registers and return
1298 +
1299 +
1300 +    @ --
1301 +    @ static void __UnalignedMD5Transform (uint32_t *buf, const uint8_t *in, int repeat);
1302 +    @ --
1303 +
1304 +__UnalignedMD5Transform:
1305 +
1306 +    stmdb   sp!, { r4 - r7, lr }
1307 +    movs    r4, r2, lsl #6                  @ r4 = (repeat * 64)
1308 +    ldmeqia sp!, { r4 - r7, pc }            @ if  ((repeat * 64) == 0) return;
1309 +    mov     r5, r0                          @ r5 = state
1310 +    mov     r6, r1                          @ r6 = in
1311 +    sub     sp, sp, #256                    @ create 256 byte temp buffer
1312 +1:  cmp     r4, #256
1313 +    mov     r0, sp
1314 +    movcc   r7, r4
1315 +    movcs   r7, #256                        @ r7 = (blockCount * 64) = min((repeat * 64), (4 * 64))
1316 +    mov     r1, r6
1317 +    mov     r2, r7
1318 +    bl      memcpy                          @ memcpy (blockBuffer, in, (blockCount * 64));
1319 +    mov     r0, r5
1320 +    mov     r1, sp
1321 +    mov     r2, r7, lsr #6
1322 +    bl      __MD5Transform                  @ __MD5Transform (state, blockBuffer, blockCount);
1323 +    subs    r4, r4, #256                    @ (repeat * 64) -= (4 * 64);
1324 +    add     r6, r6, #256                    @ in += (4 * 64);
1325 +    bgt     1b                              @ loop while (repeat > 0)
1326 +    add     sp, sp, #256                    @ return temp buffer to stack
1327 +    ldmia   sp!, { r4 - r7, pc }            @ return
1328 +
1329 +
1330 +#endif   /* __BYTE_ORDER == __LITTLE_ENDIAN */
1331 +
1332 +
1333 diff -urN -x .git dietlibc-0.33/arm/mmap.S dietlibc/arm/mmap.S
1334 --- dietlibc-0.33/arm/mmap.S    2008-12-10 20:00:58.000000000 +0000
1335 +++ dietlibc/arm/mmap.S 2015-01-01 12:14:43.454938895 +0000
1336 @@ -1,3 +1,5 @@
1337 +#include "arm-features.h"
1338 +
1339  #include <errno.h>
1340  #include "syscalls.h"
1341  
1342 @@ -28,7 +30,7 @@
1343         ldr     r4, [sp], #4
1344         ldr     r5, [sp], #4
1345         cmn     r0, #4096
1346 -       mov     pc, lr                  @ return
1347 +       RET
1348  
1349  #else  
1350                 
1351 diff -urN -x .git dietlibc-0.33/arm/setjmp.S dietlibc/arm/setjmp.S
1352 --- dietlibc-0.33/arm/setjmp.S  2008-12-10 20:00:58.000000000 +0000
1353 +++ dietlibc/arm/setjmp.S       2015-01-01 12:14:43.454938895 +0000
1354 @@ -1,17 +1,41 @@
1355 -.text
1356 -.weak setjmp
1357 -setjmp:
1358 -.global __setjmp
1359 -__setjmp:
1360 +#include "arm-features.h"
1361 +
1362 +FUNC_START_WEAK        setjmp
1363 +FUNC_START     __setjmp
1364         mov     r1, #0
1365 -.global __sigsetjmp
1366 -__sigsetjmp:
1367 -.weak sigsetjmp
1368 -sigsetjmp:
1369 -#ifndef        __SOFTFP__
1370 -       sfm     f4, 4, [r0], #48
1371 +FUNC_END       __setjmp
1372 +FUNC_END       setjmp
1373 +
1374 +FUNC_START_WEAK        sigsetjmp
1375 +FUNC_START     __sigsetjmp
1376 +
1377 +#ifdef DIET_HAVE_COPROC_REGS
1378 +       /* we have to work on a copy of 'r0' (jmpbuf *) */
1379 +       mov     ip, r0
1380 +#endif
1381 +
1382 +#ifndef __SOFTFP__
1383 +# if __ARM_ARCH__ >= 7
1384 +       vstmia  ip!, {d0-d15}
1385 +#   ifdef __ARM_NEON__
1386 +       vstmia  ip!, {d16-d31}
1387 +#   endif
1388 +# else
1389 +       sfm     f4, 4, [ip]!
1390 +# endif
1391 +#endif
1392 +
1393 +#ifdef __IWMMXT__
1394 +#  warning "setjmp will not save iwmmxt coprocessor registers"
1395  #endif
1396 +
1397 +#ifndef DIET_HAVE_COPROC_REGS
1398         stmia   r0, {r4-r11, sp, lr}
1399 -       sub     r0, r0, #48
1400 -       b       __sigjmp_save
1401  
1402 +#else
1403 +       stmia   ip!, {r4-r11, sp, lr}
1404 +#endif
1405 +
1406 +       b       __sigjmp_save
1407 +FUNC_END       __sigsetjmp
1408 +FUNC_END       sigsetjmp
1409 diff -urN -x .git dietlibc-0.33/arm/start.S dietlibc/arm/start.S
1410 --- dietlibc-0.33/arm/start.S   2012-01-24 18:24:24.000000000 +0000
1411 +++ dietlibc/arm/start.S        2015-01-01 12:14:43.454938895 +0000
1412 @@ -1,23 +1,10 @@
1413 -
1414  #include "dietfeatures.h"
1415  #include "syscalls.h"
1416 -
1417 -       .text
1418 -#ifdef __ARM_EABI__
1419 -       .align 4
1420 -#else
1421 -       .align 2
1422 -#endif
1423 -       
1424 -       .global _start
1425 -       .weak   exit
1426 -       .global _exit
1427 -
1428 +#include "arm-features.h"
1429  
1430  #ifdef __ARM_EABI__
1431  
1432 -_start:
1433 -
1434 +FUNC_START     _start
1435         mov     fp, #0                  @ clear the frame pointer
1436         ldr     a1, [sp]                @ argc
1437         add     a2, sp, #4              @ argv
1438 @@ -25,27 +12,40 @@
1439         add     a3, a2, a1, lsl #2      @ &argv[argc]
1440         add     a3, a3, #4              @ envp  
1441         str     a3, [ip, #0]            @ environ = envp
1442 -       bl      main
1443 -               
1444 +
1445 +#ifdef WANT_ELFINFO
1446 +       mov     r6, a3                  @ work on a copy of a3 so that common
1447 +                                       @ 'main(argc, argv, envp)' function
1448 +                                       @ stays valid
1449 +1:     ldr     r5, [r6], #4            @ load *envp and increment it
1450 +       cmp     r5, #0                  @ read value==0?
1451 +       bne     1b
1452 +       str     r6, [ip, #4]            @ __elfinfo = envp
1453 +#endif
1454 +
1455 +       bl      CALL_IN_STARTCODE
1456 +
1457  @
1458  @ The exit status from main() is already in r0.
1459  @ We need to branch to 'exit' in case we have linked with 'atexit'.
1460  @
1461         bl      exit
1462 +FUNC_END       _start
1463  
1464 -exit:
1465 -_exit:
1466 -
1467 +FUNC_START     _exit
1468 +FUNC_START_WEAK        exit
1469         mov     r7, #__NR_exit          
1470         swi     0                       @ never returns.
1471  
1472 +       .align  2
1473  .L3:   .word   environ
1474  
1475 -       
1476 -#else  
1477 +FUNC_END       exit
1478 +FUNC_END       _exit
1479 +
1480 +#else
1481  
1482 -       
1483 -_start:
1484 +FUNC_START     _start
1485  
1486  #ifdef WANT_DYNAMIC
1487         mov     a4, a1                  @ save dynamic ld.so _fini
1488 @@ -59,11 +59,25 @@
1489  #ifdef __DYN_LIB
1490         ldr     sl, .L4
1491  1:     add     sl, pc, sl
1492 -       str     a3, [sl, ip]            @ environ = envp
1493 +       str     a3, [ip, sl]!           @ environ = envp; ip = GOT(environ)
1494  #else
1495         str     a3, [ip, #0]            @ environ = envp
1496  #endif
1497  
1498 +#ifdef WANT_ELFINFO
1499 +       mov     r6, a3                  @ work on a copy of a3 so that common
1500 +                                       @ 'main(argc, argv, envp)' function
1501 +                                       @ stays valid
1502 +1:     ldr     r5, [r6], #4            @ load *envp and increment it
1503 +       cmp     r5, #0                  @ read value==0?
1504 +       bne     1b
1505 +#ifdef __DYN_LIB
1506 +       str     r6, [ip, sl]            @ __elfinfo = envp
1507 +#else
1508 +       str     r6, [ip, #4]            @ __elfinfo = envp
1509 +#endif
1510 +#endif
1511 +
1512  #ifdef PROFILING
1513         stmdb   sp!, { r0 - r3 }
1514         ldr     r0, .L5
1515 @@ -83,18 +97,20 @@
1516  @ We need to branch to 'exit' in case we have linked with 'atexit'.
1517  @
1518         bl      exit
1519 +FUNC_END       _start
1520  
1521 -exit:
1522 -_exit:
1523 -
1524 +FUNC_START     _exit
1525 +FUNC_START_WEAK        exit
1526  #ifdef PROFILING
1527         mov     r4, r0                  @ save a copy of exit status
1528         bl      _stop_monitor
1529         mov     r0, r4
1530  #endif
1531         swi     $__NR_exit              @ never returns.
1532 +FUNC_END       exit
1533 +FUNC_END       _exit
1534  
1535 -
1536 +       .align  2
1537  #ifdef __DYN_LIB
1538  .L3:   .word   environ(GOT)
1539  .L4:   .word   _GLOBAL_OFFSET_TABLE_-(1b+8)
1540 diff -urN -x .git dietlibc-0.33/arm/strcpy.S dietlibc/arm/strcpy.S
1541 --- dietlibc-0.33/arm/strcpy.S  2005-08-05 00:29:18.000000000 +0000
1542 +++ dietlibc/arm/strcpy.S       2015-01-01 12:14:43.454938895 +0000
1543 @@ -1,10 +1,7 @@
1544  #include "dietfeatures.h"
1545 +#include "arm-features.h"
1546  
1547 -.text
1548 -       .align  2
1549 -       .global strcpy
1550 -
1551 -strcpy:
1552 +FUNC_START     strcpy
1553  #ifndef WANT_SMALL_STRING_ROUTINES
1554         mov     ip, r0
1555         ands    r2, r1, #3
1556 @@ -61,6 +58,5 @@
1557         ldrneb  r2, [r1], #1
1558  #endif
1559         bne     .Lloop
1560 -       mov     pc, lr
1561 -.Lfe1:
1562 -       .size    strcpy,.Lfe1-strcpy
1563 +       RET
1564 +FUNC_END       strcpy
1565 diff -urN -x .git dietlibc-0.33/arm/strlen.S dietlibc/arm/strlen.S
1566 --- dietlibc-0.33/arm/strlen.S  2005-08-05 00:29:18.000000000 +0000
1567 +++ dietlibc/arm/strlen.S       2015-01-01 12:14:43.454938895 +0000
1568 @@ -1,12 +1,7 @@
1569  #include "dietfeatures.h"
1570 +#include "arm-features.h"
1571  
1572 -       .text
1573 -       .align  2
1574 -
1575 -       .global strlen
1576 -
1577 -strlen:
1578 -
1579 +FUNC_START     strlen
1580  #if 0
1581         teq     a1, #0                  @ is string pointer NULL ??
1582         moveq   pc, lr                  @ if so, return 0
1583 @@ -61,12 +56,10 @@
1584         sub     a1, a1, a2
1585  #endif
1586  
1587 -       mov     pc, lr
1588 +       RET
1589  
1590  #ifndef WANT_SMALL_STRING_ROUTINES
1591  .Lmagic:
1592         .word   0x01010101
1593  #endif
1594 -
1595 -.Lstrlen:
1596 -       .size   strlen,.Lstrlen-strlen
1597 +FUNC_END       strlen
1598 diff -urN -x .git dietlibc-0.33/arm/syscalls.h dietlibc/arm/syscalls.h
1599 --- dietlibc-0.33/arm/syscalls.h        2012-01-24 18:24:24.000000000 +0000
1600 +++ dietlibc/arm/syscalls.h     2015-01-01 12:14:43.454938895 +0000
1601 @@ -365,6 +365,38 @@
1602  #define __NR_fallocate                 (__NR_SYSCALL_BASE+352)
1603  #define __NR_timerfd_settime           (__NR_SYSCALL_BASE+353)
1604  #define __NR_timerfd_gettime           (__NR_SYSCALL_BASE+354)
1605 +#define __NR_signalfd4                 (__NR_SYSCALL_BASE+355)
1606 +#define __NR_eventfd2                  (__NR_SYSCALL_BASE+356)
1607 +#define __NR_epoll_create1             (__NR_SYSCALL_BASE+357)
1608 +#define __NR_dup3                      (__NR_SYSCALL_BASE+358)
1609 +#define __NR_pipe2                     (__NR_SYSCALL_BASE+359)
1610 +#define __NR_inotify_init1             (__NR_SYSCALL_BASE+360)
1611 +#define __NR_preadv                    (__NR_SYSCALL_BASE+361)
1612 +#define __NR_pwritev                   (__NR_SYSCALL_BASE+362)
1613 +#define __NR_rt_tgsigqueueinfo         (__NR_SYSCALL_BASE+363)
1614 +#define __NR_perf_event_open           (__NR_SYSCALL_BASE+364)
1615 +#define __NR_recvmmsg                  (__NR_SYSCALL_BASE+365)
1616 +#define __NR_accept4                   (__NR_SYSCALL_BASE+366)
1617 +#define __NR_fanotify_init             (__NR_SYSCALL_BASE+367)
1618 +#define __NR_fanotify_mark             (__NR_SYSCALL_BASE+368)
1619 +#define __NR_prlimit64                 (__NR_SYSCALL_BASE+369)
1620 +#define __NR_name_to_handle_at         (__NR_SYSCALL_BASE+370)
1621 +#define __NR_open_by_handle_at         (__NR_SYSCALL_BASE+371)
1622 +#define __NR_clock_adjtime             (__NR_SYSCALL_BASE+372)
1623 +#define __NR_syncfs                    (__NR_SYSCALL_BASE+373)
1624 +#define __NR_sendmmsg                  (__NR_SYSCALL_BASE+374)
1625 +#define __NR_setns                     (__NR_SYSCALL_BASE+375)
1626 +#define __NR_process_vm_readv          (__NR_SYSCALL_BASE+376)
1627 +#define __NR_process_vm_writev         (__NR_SYSCALL_BASE+377)
1628 +#define __NR_kcmp                      (__NR_SYSCALL_BASE+378)
1629 +#define __NR_finit_module              (__NR_SYSCALL_BASE+379)
1630 +#define __NR_sched_setattr             (__NR_SYSCALL_BASE+380)
1631 +#define __NR_sched_getattr             (__NR_SYSCALL_BASE+381)
1632 +#define __NR_renameat2                 (__NR_SYSCALL_BASE+382)
1633 +#define __NR_seccomp                   (__NR_SYSCALL_BASE+383)
1634 +#define __NR_getrandom                 (__NR_SYSCALL_BASE+384)
1635 +#define __NR_memfd_create              (__NR_SYSCALL_BASE+385)
1636 +
1637  
1638  /*
1639   * The following SWIs are ARM private.
1640 @@ -700,9 +732,9 @@
1641  #define __ARGS_getpeername             0
1642  #define __ARGS_socketpair              0
1643  #define __ARGS_send                    0
1644 -#define __ARGS_sendto                  0
1645 +#define __ARGS_sendto                  6
1646  #define __ARGS_recv                    0
1647 -#define __ARGS_recvfrom                        0
1648 +#define __ARGS_recvfrom                        6
1649  #define __ARGS_shutdown                        0
1650  #define __ARGS_setsockopt              0
1651  #define __ARGS_getsockopt              0
1652 @@ -768,73 +800,59 @@
1653  #define __ARGS_timerfd_settime         0
1654  #define __ARGS_timerfd_gettime         0
1655  
1656 +#define __ARGS_signalfd4               0
1657 +#define __ARGS_eventfd2                        0
1658 +#define __ARGS_epoll_create1           0
1659 +#define __ARGS_dup3                    0
1660 +#define __ARGS_pipe2                   0
1661 +#define __ARGS_inotify_init1           0
1662 +#define __ARGS_preadv                  0
1663 +#define __ARGS_pwritev                 0
1664 +#define __ARGS_rt_tgsigqueueinfo       0
1665 +#define __ARGS_perf_event_open         1
1666 +#define __ARGS_recvmmsg                        1
1667 +#define __ARGS_accept4                 0
1668 +#define __ARGS_fanotify_init           0
1669 +#define __ARGS_fanotify_mark           1
1670 +#define __ARGS_prlimit64               0
1671 +#define __ARGS_name_to_handle_at       1
1672 +#define __ARGS_open_by_handle_at       0
1673 +#define __ARGS_clock_adjtime           0
1674 +#define __ARGS_syncfs                  0
1675 +#define __ARGS_sendmmsg                        0
1676 +#define __ARGS_setns                   0
1677 +#define __ARGS_process_vm_readv                1
1678 +#define __ARGS_process_vm_writev       1
1679 +#define __ARGS_kcmp                    1
1680 +#define __ARGS_finit_module            0
1681 +
1682  
1683  #ifdef __ASSEMBLER__
1684  
1685 -#ifdef __ARM_EABI__
1686 +#include "arm-features.h"
1687  
1688  #define syscall_weak(name,wsym,sym) __syscall_weak __NR_##name, wsym, sym, __ARGS_##name
1689  .macro __syscall_weak name wsym sym typ
1690 -.text
1691 -.type \wsym,function
1692 -.weak \wsym
1693 -\wsym:
1694 -.type \sym,function
1695 -.global \sym
1696 -\sym:
1697 -        stmfd  sp!,{r4,r5,r7,lr}
1698 -       ldr     r4, [sp,#16]
1699 -       ldr     r5, [sp,#20]
1700 -        ldr     r7, =\name
1701 -       swi     0
1702 -       b       __unified_syscall
1703 +FUNC_START_WEAK        \wsym
1704 +__syscall      \name, \sym, \typ
1705 +FUNC_END       \wsym
1706  .endm
1707  
1708 +#ifdef __ARM_EABI__
1709  
1710  #define syscall(name,sym) __syscall __NR_##name, sym, __ARGS_##name
1711  .macro __syscall name sym typ
1712 -.text
1713 -.type \sym,function
1714 -.global \sym
1715 -\sym:
1716 -        stmfd  sp!,{r4,r5,r7,lr}
1717 -       ldr     r4, [sp,#16]
1718 -       ldr     r5, [sp,#20]
1719 -        ldr     r7, =\name
1720 -       swi     0
1721 -       b       __unified_syscall
1722 +FUNC_START     \sym
1723 +        ldr     ip, =\name
1724 +       b       __unified_syscall_swi
1725 +FUNC_END       \sym
1726  .endm
1727  
1728  #else
1729  
1730 -#define syscall_weak(name,wsym,sym) __syscall_weak $__NR_##name, wsym, sym, __ARGS_##name
1731 -.macro __syscall_weak name wsym sym typ
1732 -.text
1733 -.type \wsym,function
1734 -.weak \wsym
1735 -\wsym:
1736 -.type \sym,function
1737 -.global \sym
1738 -\sym:
1739 -.ifgt \typ
1740 -       mov     ip, sp
1741 -       stmfd   sp!,{r4, r5, r6}
1742 -       ldmia   ip, {r4, r5, r6}
1743 -.endif
1744 -       swi     \name
1745 -.ifgt \typ
1746 -       b       __unified_syscall4
1747 -.else
1748 -       b       __unified_syscall
1749 -.endif
1750 -.endm
1751 -
1752  #define syscall(name,sym) __syscall $__NR_##name, sym, __ARGS_##name
1753  .macro __syscall name sym typ
1754 -.text
1755 -.type \sym,function
1756 -.global \sym
1757 -\sym:
1758 +FUNC_START     \sym
1759  .ifgt \typ
1760         mov     ip, sp
1761         stmfd   sp!,{r4, r5, r6}
1762 @@ -846,6 +864,7 @@
1763  .else
1764         b       __unified_syscall
1765  .endif
1766 +FUNC_END       \sym
1767  .endm
1768  
1769  #endif
1770 diff -urN -x .git dietlibc-0.33/arm/__testandset.S dietlibc/arm/__testandset.S
1771 --- dietlibc-0.33/arm/__testandset.S    2001-03-09 19:30:52.000000000 +0000
1772 +++ dietlibc/arm/__testandset.S 2015-01-01 12:14:43.454938895 +0000
1773 @@ -1,7 +1,15 @@
1774 -.text
1775 -.global __testandset
1776 -__testandset:
1777 +#include "arm-features.h"
1778 +
1779 +FUNC_START     __testandset
1780         mov     r2, r0
1781         mov     r1, #1
1782 +# if __ARM_ARCH__ < 6
1783         swp     r0, r1, [r2]
1784 -       mov     pc, lr
1785 +# else
1786 +1:     ldrex   r0, [r2]
1787 +       strex   r3, r1, [r2]
1788 +       cmp     r3, #0
1789 +       bne     1b
1790 +# endif
1791 +       RET
1792 +FUNC_END       __testandset
1793 diff -urN -x .git dietlibc-0.33/arm/unified.S dietlibc/arm/unified.S
1794 --- dietlibc-0.33/arm/unified.S 2012-01-24 18:24:24.000000000 +0000
1795 +++ dietlibc/arm/unified.S      2015-01-01 12:14:43.454938895 +0000
1796 @@ -1,22 +1,29 @@
1797 -
1798  #include <dietfeatures.h>
1799 -
1800 -       .text
1801 -#ifdef __ARM_EABI__
1802 -       .align 4
1803 -#else
1804 -       .align 2
1805 -#endif         
1806 -       .global __unified_syscall
1807 -       .global __unified_syscall4
1808 -
1809 +#include "arm-features.h"
1810  
1811  #ifdef __ARM_EABI__
1812  
1813 -__unified_syscall4:
1814 -__unified_syscall:
1815 -       
1816 +/* expects:
1817 + * r0-r3 ... syscall arguments 0-3
1818 + * ip    ... syscall number
1819 + */
1820 +FUNC_START     __unified_syscall_swi
1821 +       .hidden __unified_syscall_swi
1822 +        stmfd  sp!,{r4,r5,r7,lr}
1823 +       mov     r7, ip
1824 +       LOAD_ARG4_5
1825 +       swi     0
1826 +       /* fallthrough to __unified4_syscall */
1827 +FUNC_END       __unified_syscall_swi
1828 +
1829 +/* expects:
1830 + * r0    ... syscall return value
1831 + * original r4-r7 + lr on stack
1832 + */
1833 +FUNC_START     __unified_syscall
1834 +       .hidden __unified_syscall
1835          cmn     r0, #4096
1836 +#ifndef WANT_THREAD_SAFE
1837          rsbcs   r2, r0, #0
1838          ldrcs   r3, 1f
1839          mvncs   r0, #0
1840 @@ -25,17 +32,28 @@
1841         .balign 4
1842  1:
1843          .word   errno
1844 -       
1845 +#else
1846 +       bcc     1f
1847 +       rsb     r4, r0, #0
1848 +       bl      __errno_location
1849 +       str     r4, [r0]
1850 +       mvn     r0, #0
1851 +1:
1852 +        ldmfd   sp!,{r4,r5,r7,pc}
1853 +#endif
1854 +FUNC_END       __unified_syscall
1855 +
1856  /* here we go and "reuse" the return for weak-void functions */
1857  #include "dietuglyweaks.h"
1858  
1859 -       mov     pc, lr                  @ return
1860 +       RET
1861  
1862 -#else  
1863 -       
1864 -__unified_syscall4:
1865 +#else
1866 +
1867 +FUNC_START     __unified_syscall4
1868         ldmia   sp!, {r4, r5, r6}
1869 -__unified_syscall:
1870 +
1871 +FUNC_START     __unified_syscall
1872         cmn     r0, #4096
1873         movcc   pc, lr                  @ return value comes direct from kernel.
1874  
1875 @@ -53,10 +71,13 @@
1876  /* here we go and "reuse" the return for weak-void functions */
1877  #include "dietuglyweaks.h"
1878  
1879 -       mov     pc, lr                  @ return
1880 +       RET
1881  
1882  #ifndef WANT_THREAD_SAFE
1883 +.align 2
1884  .L0:   .long   errno
1885  #endif
1886 +FUNC_END       __unified_syscall
1887 +FUNC_END       __unified_syscall4
1888  
1889  #endif
1890 diff -urN -x .git dietlibc-0.33/arm/waitpid.S dietlibc/arm/waitpid.S
1891 --- dietlibc-0.33/arm/waitpid.S 2008-12-10 20:00:58.000000000 +0000
1892 +++ dietlibc/arm/waitpid.S      2015-01-01 12:14:43.454938895 +0000
1893 @@ -1,15 +1,8 @@
1894 -.text
1895 -#ifdef __ARM_EABI__
1896 -.align 4
1897 -#else  
1898 -.align 2
1899 -#endif
1900 -.weak  waitpid
1901 -.type  waitpid, %function
1902 -waitpid:
1903 -.global        __libc_waitpid
1904 -.type  __libc_waitpid, %function
1905 -__libc_waitpid:
1906 -       mov     r3, #0
1907 -       b       wait4
1908 -       .size   waitpid, .-waitpid
1909 +#include "arm-features.h"
1910 +
1911 +FUNC_START_WEAK        waitpid
1912 +FUNC_START     __libc_waitpid
1913 +       mov     r3, #0
1914 +       b       wait4
1915 +FUNC_END       __libc_waitpid
1916 +FUNC_END       waitpid
1917 diff -urN -x .git dietlibc-0.33/CHANGES dietlibc/CHANGES
1918 --- dietlibc-0.33/CHANGES       2012-11-02 11:17:28.000000000 +0000
1919 +++ dietlibc/CHANGES    2015-01-01 12:14:43.451605563 +0000
1920 @@ -1,3 +1,19 @@
1921 +0.34:
1922 +  move stpcpy from libcompat to lib as it is now part of POSIX (Enrico Scholz)
1923 +  add linux/seccomp.h linux/prctl.h linux/audit.h linux/elf-em.h linux/filter.h
1924 +  SECURITY: make sure all assembler files mark the stack non-executable so
1925 +    the kernel can map the stack of the whole program as non-executable
1926 +  support compiling with clang (no cross compiling yet, and the resulting
1927 +    binary code is significantly larger than with gcc)
1928 +  implement experimental C11 threads
1929 +  fix fgets (Andreas Förster)
1930 +  add eventfd, inotify_init1, epoll_init1, accept4, recvmmsg, sendmmsg
1931 +  add dup3, fanotify_init, fanotify_mark, signalfd4, timerfd_settime
1932 +  add timerfd_gettime, setns, memfd_create, getrandom, syncfs
1933 +  add preadv, pwritev
1934 +  add getcontext, setcontext, makecontext, swapcontext (i386 and x86_64 only for now)
1935 +  add implementation of hsearch and friends
1936 +
1937  0.33:
1938    first stab at getting TLS to work in actual threads
1939    use fs: to find current thread on x86_64
1940 diff -urN -x .git dietlibc-0.33/contrib/dnsd.c dietlibc/contrib/dnsd.c
1941 --- dietlibc-0.33/contrib/dnsd.c        2010-09-25 17:03:25.000000000 +0000
1942 +++ dietlibc/contrib/dnsd.c     2015-01-01 12:14:43.458272230 +0000
1943 @@ -281,55 +281,54 @@
1944  }
1945  
1946  static void init_sockets(int* sock6,int* sock4,int port,char* v6ip,char* v4ip) {
1947 -  int s4,s6;
1948 +  int _s4,_s6;
1949    int one=1;
1950    *sock6=-1; *sock4=-1;
1951 -  s6=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP);
1952 -  s4=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
1953 -  if (s4==-1 && s6==-1) {
1954 +  _s6=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP);
1955 +  _s4=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
1956 +  if (_s4==-1 && _s6==-1) {
1957      perror("socket");
1958      return;
1959    }
1960 -  if (s6!=-1) {
1961 -    setsockopt(s6,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
1962 +  if (_s6!=-1) {
1963 +    setsockopt(_s6,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
1964      memset(&sa6,0,sizeof(sa6));
1965      sa6.sin6_family=PF_INET6;
1966      sa6.sin6_port=htons(port);
1967 -    if (bind(s6,(struct sockaddr*)&sa6,sizeof(struct sockaddr_in6))==-1) {
1968 +    if (bind(_s6,(struct sockaddr*)&sa6,sizeof(struct sockaddr_in6))==-1) {
1969        perror("bind IPv6");
1970 -      close(s6);
1971 -      s6=-1;
1972 +      close(_s6);
1973 +      _s6=-1;
1974      }
1975    }
1976 -  if (s4!=-1) {
1977 -    setsockopt(s4,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
1978 +  if (_s4!=-1) {
1979 +    setsockopt(_s4,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one));
1980      memset(&sa4,0,sizeof(sa4));
1981      sa4.sin_family=PF_INET;
1982      sa4.sin_port=htons(port);
1983 -    if (bind(s4,(struct sockaddr*)&sa4,sizeof(struct sockaddr_in))==-1) {
1984 -      if (errno!=EADDRINUSE || s6==-1)
1985 +    if (bind(_s4,(struct sockaddr*)&sa4,sizeof(struct sockaddr_in))==-1) {
1986 +      if (errno!=EADDRINUSE || _s6==-1)
1987         perror("bind IPv4");
1988 -      close(s4);
1989 -      s4=-1;
1990 +      close(_s4);
1991 +      _s4=-1;
1992      }
1993    }
1994 -  if (s4==-1 && s6==-1) return;
1995 +  if (_s4==-1 && _s6==-1) return;
1996  
1997    {
1998      int val=255;
1999 -    int one=1;
2000 -    if (s6!=-1) {
2001 +    if (_s6!=-1) {
2002        struct ipv6_mreq opt;
2003 -      setsockopt(s6,IPPROTO_IPV6,IPV6_UNICAST_HOPS,&val,sizeof(val));
2004 -      setsockopt(s6,IPPROTO_IPV6,IPV6_MULTICAST_LOOP,&one,sizeof(one));
2005 +      setsockopt(_s6,IPPROTO_IPV6,IPV6_UNICAST_HOPS,&val,sizeof(val));
2006 +      setsockopt(_s6,IPPROTO_IPV6,IPV6_MULTICAST_LOOP,&one,sizeof(one));
2007        memcpy(&opt.ipv6mr_multiaddr,v6ip,16);
2008        opt.ipv6mr_interface=0;
2009 -      setsockopt(s6,IPPROTO_IPV6,IPV6_ADD_MEMBERSHIP,&opt,sizeof opt);
2010 -      setsockopt(s6,IPPROTO_IPV6,IPV6_PKTINFO,&one,sizeof one);
2011 +      setsockopt(_s6,IPPROTO_IPV6,IPV6_ADD_MEMBERSHIP,&opt,sizeof opt);
2012 +      setsockopt(_s6,IPPROTO_IPV6,IPV6_PKTINFO,&one,sizeof one);
2013      }
2014      {
2015        struct ip_mreq opt;
2016 -      int s=(s4==-1?s6:s4);
2017 +      int s=(_s4==-1?_s6:_s4);
2018        setsockopt(s,SOL_IP,IP_TTL,&val,sizeof(val));
2019        memcpy(&opt.imr_multiaddr.s_addr,v4ip,4);
2020        opt.imr_interface.s_addr=0;
2021 @@ -338,8 +337,8 @@
2022      }
2023    }
2024  
2025 -  *sock4=s4;
2026 -  *sock6=s6;
2027 +  *sock4=_s4;
2028 +  *sock6=_s6;
2029  }
2030  
2031  int main() {
2032 diff -urN -x .git dietlibc-0.33/.cvsignore dietlibc/.cvsignore
2033 --- dietlibc-0.33/.cvsignore    2007-03-09 13:42:12.000000000 +0000
2034 +++ dietlibc/.cvsignore 2015-01-01 12:14:43.451605563 +0000
2035 @@ -28,3 +28,5 @@
2036  bin-x86_64
2037  pic-x86_64
2038  cycles
2039 +include/errno_definition.h
2040 +bin-x32
2041 diff -urN -x .git dietlibc-0.33/diet.c dietlibc/diet.c
2042 --- dietlibc-0.33/diet.c        2012-11-02 11:17:28.000000000 +0000
2043 +++ dietlibc/diet.c     2015-01-01 12:14:43.461605562 +0000
2044 @@ -25,10 +25,11 @@
2045  }
2046  
2047  static const char* Os[] = {
2048 -  "i386","-Os","-mpreferred-stack-boundary=2",
2049 +  "i386","-Os","-mpreferred-stack-boundary=4",
2050          "-falign-functions=1","-falign-jumps=1",
2051          "-falign-loops=1","-fomit-frame-pointer",0,
2052    "x86_64","-Os",0,
2053 +  "x32","-Os",0,
2054    "sparc","-Os","-mcpu=supersparc",0,
2055    "sparc64","-Os","-m64","-mhard-quad-float",0,
2056    "alpha","-Os","-fomit-frame-pointer",0,
2057 @@ -41,7 +42,6 @@
2058    "s390x","-Os","-fomit-frame-pointer",0,
2059    "sh","-Os","-fomit-frame-pointer",0,
2060    "ia64","-Os","-fno-omit-frame-pointer",0,
2061 -  "x86_64","-Os","-fstrict-aliasing","-momit-leaf-frame-pointer","-mfancy-math-387",0,
2062    0};
2063  
2064  static void usage(void) {
2065 @@ -120,7 +120,6 @@
2066      } else break;
2067    } while (1);
2068    {
2069 -    int i;
2070      m=0;
2071      for (i=1; i<argc; ++i) {
2072        if (!strcmp(argv[i],"-m32")) m=32; else
2073 @@ -144,6 +143,10 @@
2074        memmove(shortplatform,argv[1],(size_t)(tmp2-cc));
2075        platform[tmp2-cc+len]=0;
2076        if (shortplatform[0]=='i' && shortplatform[2]=='8' && shortplatform[3]=='6') shortplatform[1]='3';
2077 +      else if (strcmp(shortplatform, "powerpc") == 0)
2078 +        strcpy(shortplatform, "ppc");
2079 +      else if (strcmp(shortplatform, "powerpc64") == 0)
2080 +        strcpy(shortplatform, "ppc64");
2081      } else {
2082  #ifdef __sparc__
2083  #ifdef __arch64__
2084 @@ -193,15 +196,14 @@
2085        shortplatform="ia64";
2086  #endif
2087        {
2088 -       char *tmp=platform+strlen(platform);
2089 -       strcpy(tmp,shortplatform);
2090 -       shortplatform=tmp;
2091 +       char *tmp4=platform+strlen(platform);
2092 +       strcpy(tmp4,shortplatform);
2093 +       shortplatform=tmp4;
2094        }
2095      }
2096      /* MIPS needs special handling.  If argv contains -EL, change
2097       * platform name to mipsel */
2098      if (!strcmp(shortplatform,"mips")) {
2099 -      int i;
2100        for (i=1; i<argc; ++i)
2101         if (!strcmp(argv[i],"-EL"))
2102           strcpy(shortplatform,"mipsel");
2103 @@ -328,7 +330,7 @@
2104         }
2105         if (mangleopts)
2106           if (argv[i][0]=='-' && (argv[i][1]=='O' || argv[i][1]=='f' ||
2107 -                                 (argv[i][1]=='m' && argv[i][2]!='3' && argv[i][2]!='6'))) {
2108 +                                 (argv[i][1]=='m' && argv[i][2]!='3' && argv[i][2]!='6' && argv[i][2]!='x'))) {
2109             if (strcmp(argv[i],"-fpic") && strcmp(argv[i],"-fno-pic"))
2110               continue;
2111           }
2112 @@ -351,7 +353,7 @@
2113  
2114         {
2115           int fd;
2116 -         char* tmp=getenv("HOME");
2117 +         tmp=getenv("HOME");
2118           if (tmp) {
2119             if (strlen(tmp)+strlen(cc)<900) {
2120               strcpy(manglebuf,tmp);
2121 @@ -362,7 +364,6 @@
2122               if ((fd=open(manglebuf,O_RDONLY))>=0) {
2123                 int len=read(fd,manglebuf,1023);
2124                 if (len>0) {
2125 -                 int i;
2126                   manglebuf[len]=0;
2127                   *dest++=manglebuf;
2128                   for (i=1; i<len; ++i) {
2129 @@ -416,7 +417,6 @@
2130  #endif
2131        *dest=0;
2132        if (verbose) {
2133 -       int i;
2134         for (i=0; newargv[i]; i++) {
2135           __write2(newargv[i]);
2136           __write2(" ");
2137 diff -urN -x .git dietlibc-0.33/dietdirent.h dietlibc/dietdirent.h
2138 --- dietlibc-0.33/dietdirent.h  2002-07-03 20:33:37.000000000 +0000
2139 +++ dietlibc/dietdirent.h       2015-01-01 12:14:43.461605562 +0000
2140 @@ -1,8 +1,28 @@
2141  #include <sys/shm.h>
2142  
2143 +#include "dietpagesize.h"
2144 +
2145  struct __dirstream {
2146    int fd;
2147 -  char buf[PAGE_SIZE-(sizeof (int)*3)];
2148    unsigned int num;
2149    unsigned int cur;
2150 +  unsigned char is_64;
2151 +  char buf[] __attribute__((__aligned__(8)));
2152  };                             /* stream data from opendir() */
2153 +
2154 +struct linux_dirent {
2155 +  unsigned long   d_ino;
2156 +  unsigned long   d_off;
2157 +  unsigned short  d_reclen;
2158 +  char            d_name[1];
2159 +};
2160 +
2161 +struct linux_dirent64 {
2162 +  uint64_t        d_ino;
2163 +  int64_t         d_off;
2164 +  unsigned short  d_reclen;
2165 +  unsigned char   d_type;
2166 +  char            d_name[0];
2167 +};
2168 +
2169 +#define __DIRSTREAM_BUF_SIZE   (__DIET_PAGE_SIZE - offsetof(struct __dirstream, buf))
2170 diff -urN -x .git dietlibc-0.33/dietelfinfo.h dietlibc/dietelfinfo.h
2171 --- dietlibc-0.33/dietelfinfo.h 1970-01-01 00:00:00.000000000 +0000
2172 +++ dietlibc/dietelfinfo.h      2015-01-01 12:14:43.461605562 +0000
2173 @@ -0,0 +1,20 @@
2174 +#include "dietfeatures.h"
2175 +
2176 +#ifdef WANT_ELFINFO
2177 +#include <elf.h>
2178 +#include <endian.h>
2179 +#include <stdint.h>
2180 +
2181 +/* TODO: exported interface from <linux/elf.h> has been changed in 2.6.25 so
2182 + * the 'elf_addr_t' type is not available anymore. Hence, derive it from
2183 + * __WORDSIZE__. */
2184 +
2185 +#if __WORDSIZE == 64
2186 +typedef uint64_t       __diet_elf_addr_t;
2187 +#elif __WORDSIZE == 32
2188 +typedef uint32_t       __diet_elf_addr_t;
2189 +#endif
2190 +
2191 +__diet_elf_addr_t const *      __get_elf_aux_value(unsigned int tag)
2192 +       __attribute__((__visibility__("hidden"),__const__)) __pure;
2193 +#endif
2194 diff -urN -x .git dietlibc-0.33/dietfeatures.h dietlibc/dietfeatures.h
2195 --- dietlibc-0.33/dietfeatures.h        2012-11-02 11:17:28.000000000 +0000
2196 +++ dietlibc/dietfeatures.h     2015-01-01 12:14:43.461605562 +0000
2197 @@ -29,7 +29,7 @@
2198  #define WANT_TLS
2199  
2200  /* make the startcode, etc. dynamic aware ({con,de}structors) */
2201 -/* #define WANT_DYNAMIC */
2202 +// #define WANT_DYNAMIC
2203  
2204  /* GDB support in the dynamic linker */
2205  #define WANT_LD_SO_GDB_SUPPORT
2206 @@ -142,6 +142,16 @@
2207  #define WANT_SSP
2208  #endif
2209  
2210 +/* Some platforms like x86_64, ppc* or mips do not have a fixed PAGE_SIZE.
2211 + * Select WANT_DYN_PAGESIZE to detect the current PAGE_SIZE at runtime. Else,
2212 + * define WANT_STATIC_PAGESIZE to a proper value (must be a power of 2)
2213 + * matching the configured pagesize of the kernel where your binaries are
2214 + * running on.
2215 + *
2216 + * Selecting WANT_DYN_PAGESIZE enlarges the startup code by around 1-3
2217 + * instructions and might add an additional __elfinfo symbol */
2218 +#define WANT_DYN_PAGESIZE
2219 +/* #define WANT_STATIC_PAGESIZE 0x10000UL */
2220  
2221  
2222  /* stop uncommenting here ;-) */
2223 @@ -161,13 +171,6 @@
2224  #define WANT_SMALL_STRING_ROUTINES
2225  #endif
2226  
2227 -#ifdef WANT_THREAD_SAFE
2228 -#ifndef __ASSEMBLER__
2229 -#define errno (*__errno_location())
2230 -#define _REENTRANT
2231 -#endif
2232 -#endif
2233 -
2234  #ifdef __DYN_LIB
2235  /* with shared libraries you MUST have a dynamic aware startcode */
2236  #ifndef WANT_DYNAMIC
2237 @@ -179,4 +182,12 @@
2238  #endif
2239  #endif
2240  
2241 +#if defined(__x86_64__) && defined(__ILP32__)
2242 +#undef WANT_LARGEFILE_BACKCOMPAT
2243 +#endif
2244 +
2245 +#ifdef WANT_DYN_PAGESIZE
2246 +#define WANT_ELFINFO
2247 +#endif
2248 +
2249  #endif
2250 diff -urN -x .git dietlibc-0.33/dietpagesize.h dietlibc/dietpagesize.h
2251 --- dietlibc-0.33/dietpagesize.h        1970-01-01 00:00:00.000000000 +0000
2252 +++ dietlibc/dietpagesize.h     2015-01-01 12:14:43.461605562 +0000
2253 @@ -0,0 +1,31 @@
2254 +#ifndef H_DIETLIBC_DIETPAGESIZE_H
2255 +#define H_DIETLIBC_DIETPAGESIZE_H
2256 +
2257 +#include <strings.h>
2258 +#include "dietfeatures.h"
2259 +
2260 +extern size_t __libc_getpagesize(void) __attribute__((__const__)) __pure;
2261 +
2262 +#if defined(WANT_STATIC_PAGESIZE)
2263 +#  define __DIET_PAGE_SIZE_PREDEF      (WANT_STATIC_PAGESIZE)
2264 +#  define __DIET_PAGE_SHIFT_PREDEF     (ffs(__DIET_PAGE_SIZE_PREDEF)-1)
2265 +#elif defined(__alpha__) || defined(__sparc__)
2266 +#  define __DIET_PAGE_SIZE_PREDEF      (8192UL)
2267 +#  define __DIET_PAGE_SHIFT_PREDEF     (13)
2268 +#elif defined(__powerpc64__)
2269 +#  define __DIET_PAGE_SIZE_PREDEF      (65536UL)
2270 +#  define __DIET_PAGE_SHIFT_PREDEF     (16)
2271 +#else
2272 +#  define __DIET_PAGE_SIZE_PREDEF      (4096UL)
2273 +#  define __DIET_PAGE_SHIFT_PREDEF     (12)
2274 +#endif
2275 +
2276 +#ifdef WANT_DYN_PAGESIZE
2277 +#  define __DIET_PAGE_SIZE     (__libc_getpagesize())
2278 +#  define __DIET_PAGE_SHIFT    (ffs(__DIET_PAGE_SIZE)-1)
2279 +#else
2280 +#  define __DIET_PAGE_SIZE     __DIET_PAGE_SIZE_PREDEF
2281 +#  define __DIET_PAGE_SHIFT    __DIET_PAGE_SHIFT_PREDEF
2282 +#endif
2283 +
2284 +#endif /* H_DIETLIBC_DIETPAGESIZE_H */
2285 diff -urN -x .git dietlibc-0.33/dietuglyweaks.h dietlibc/dietuglyweaks.h
2286 --- dietlibc-0.33/dietuglyweaks.h       2004-06-30 05:52:30.000000000 +0000
2287 +++ dietlibc/dietuglyweaks.h    2015-01-01 12:14:43.461605562 +0000
2288 @@ -4,6 +4,18 @@
2289  /* if you change something here ... KNOW what you're doing !
2290   * it'll effect ALL platforms ! */
2291  
2292 +#ifdef __clang__
2293 +.macro DEF_G name
2294 +.global \name
2295 +.type \name,@function
2296 +\name:
2297 +.endm
2298 +.macro DEF_W name
2299 +.weak \name
2300 +.type \name,@function
2301 +\name:
2302 +.endm
2303 +#else
2304  .macro DEF_G name
2305  .global \name
2306  .type \name,function
2307 @@ -14,6 +26,7 @@
2308  .type \name,function
2309  \name:
2310  .endm
2311 +#endif
2312  
2313  DEF_W __fflush_stderr
2314  DEF_W __fflush_stdin
2315 diff -urN -x .git dietlibc-0.33/dietunaligned.h dietlibc/dietunaligned.h
2316 --- dietlibc-0.33/dietunaligned.h       1970-01-01 00:00:00.000000000 +0000
2317 +++ dietlibc/dietunaligned.h    2015-01-01 12:14:43.461605562 +0000
2318 @@ -0,0 +1,35 @@
2319 +#ifndef H_DIETLIBC_UNALIGNED_H
2320 +#define H_DIETLIBC_UNALIGNED_H
2321 +
2322 +#include <string.h>
2323 +#include <inttypes.h>
2324 +
2325 +#define read_unaligned(_src)                                           \
2326 +       ({                                                              \
2327 +               struct {                                                \
2328 +                       __typeof__(*(_src))     a;                      \
2329 +               } __attribute__((__packed__)) *_tmp = (void *)(_src);   \
2330 +               _tmp->a;                                                \
2331 +       })
2332 +
2333 +#define read_unaligned_s(_src, _type, _attr)                           \
2334 +       read_unaligned((__typeof__(&((_type *)(0))->_attr))(            \
2335 +                              (uintptr_t)(_src) +                      \
2336 +                              __builtin_offsetof(_type, _attr)))       \
2337 +
2338 +
2339 +#define write_unaligned(_v, _dst)              \
2340 +       ({                                                              \
2341 +               struct {                                                \
2342 +                       __typeof__(*(_dst))     a;                      \
2343 +               } __attribute__((__packed__)) *_tmp = (void *)(_dst);   \
2344 +               _tmp->a = (_v);                                         \
2345 +       })
2346 +
2347 +#define write_unaligned_s(_v, _dst, _type, _attr)                      \
2348 +       write_unaligned(_v,                                             \
2349 +                       (__typeof__(&((_type *)(0))->_attr))(           \
2350 +                               (uintptr_t)(_dst) +                     \
2351 +                               __builtin_offsetof(_type, _attr)))      \
2352 +
2353 +#endif /* H_DIETLIBC_UNALIGNED_H */
2354 diff -urN -x .git dietlibc-0.33/dynlinker/ldso_start.S dietlibc/dynlinker/ldso_start.S
2355 --- dietlibc-0.33/dynlinker/ldso_start.S        2007-03-09 13:42:12.000000000 +0000
2356 +++ dietlibc/dynlinker/ldso_start.S     2015-01-01 12:14:43.464938896 +0000
2357 @@ -86,6 +86,15 @@
2358         .long 0
2359  #endif
2360  
2361 +/* __elfinfo must follow __environ immediately */
2362 +.global __elfinfo
2363 +__elfinfo:
2364 +#if __WORDSIZE == 64
2365 +       .quad 0
2366 +#else
2367 +       .long 0
2368 +#endif
2369 +
2370  .global fini_entry
2371  fini_entry:
2372         .long 0
2373 diff -urN -x .git dietlibc-0.33/dyn_start.c dietlibc/dyn_start.c
2374 --- dietlibc-0.33/dyn_start.c   2008-05-06 17:18:34.000000000 +0000
2375 +++ dietlibc/dyn_start.c        2015-01-01 12:14:43.464938896 +0000
2376 @@ -54,10 +54,6 @@
2377      __deregister_frame_info(__EH_FRAME_BEGIN__);
2378  }
2379  
2380 -#ifdef WANT_STACKGAP
2381 -int stackgap(int argc,char* argv[],char* envp[]);
2382 -#endif
2383 -
2384  #ifndef __DYN_LIB_SHARED
2385  /* pre main, post _start */
2386  extern __attribute__((section(".init"))) void _init(void);
2387 @@ -65,7 +61,7 @@
2388  int _dyn_start(int argc, char **argv, char **envp, structor dl_init);
2389  int _dyn_start(int argc, char **argv, char **envp, structor dl_init)
2390  {
2391 -  int main(int argc, char **argv, char **envp);
2392 +  int CALL_IN_STARTCODE(int argc, char **argv, char **envp);
2393  
2394  #ifndef __arm__
2395    /* GT: segfaults on arm, don't know why (for now) */
2396 @@ -82,11 +78,7 @@
2397      __register_frame_info(__EH_FRAME_BEGIN__, &ob);
2398    }
2399  
2400 -#ifdef WANT_STACKGAP
2401 -  return stackgap(argc, argv, envp);
2402 -#else
2403 -  return main(argc, argv, envp);
2404 -#endif
2405 +  return CALL_IN_STARTCODE(argc, argv, envp);
2406  }
2407  #endif
2408  #endif
2409 diff -urN -x .git dietlibc-0.33/FAQ dietlibc/FAQ
2410 --- dietlibc-0.33/FAQ   2010-11-09 18:38:34.000000000 +0000
2411 +++ dietlibc/FAQ        2015-01-01 12:14:43.451605563 +0000
2412 @@ -246,7 +246,7 @@
2413     code.  Unfortunately, these options have been renamed on gcc 3.  You
2414     can fix this by creating a file ~/.diet/gcc containing this line:
2415  
2416 -     -Os -fomit-frame-pointer -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2
2417 +     -Os -fomit-frame-pointer -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4
2418  
2419     If you get this options not for diet -Os gcc but for diet -Os
2420     i386-linux-gcc, put this in ~/.diet/i386-linux-gcc instead.
2421 diff -urN -x .git dietlibc-0.33/findcflags.sh dietlibc/findcflags.sh
2422 --- dietlibc-0.33/findcflags.sh 2005-05-08 15:33:38.000000000 +0000
2423 +++ dietlibc/findcflags.sh      2015-01-01 12:14:43.464938896 +0000
2424 @@ -3,6 +3,6 @@
2425  case $version in
2426    2.9*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=1 -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 ;;
2427    3.0*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=1 -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 ;;
2428 -  [34]*) echo -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2;;
2429 +  [34]*) echo -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4;;
2430    *) echo -O2 -pipe -fomit-frame-pointer ;;
2431  esac
2432 diff -urN -x .git dietlibc-0.33/.gitignore dietlibc/.gitignore
2433 --- dietlibc-0.33/.gitignore    1970-01-01 00:00:00.000000000 +0000
2434 +++ dietlibc/.gitignore 2015-01-01 12:14:43.451605563 +0000
2435 @@ -0,0 +1,2 @@
2436 +/.cvsps
2437 +/include/errno_definition.h
2438 diff -urN -x .git dietlibc-0.33/i386/accept4.S dietlibc/i386/accept4.S
2439 --- dietlibc-0.33/i386/accept4.S        1970-01-01 00:00:00.000000000 +0000
2440 +++ dietlibc/i386/accept4.S     2015-01-01 12:14:43.464938896 +0000
2441 @@ -0,0 +1,4 @@
2442 +#include <linuxnet.h>
2443 +#include <syscalls.h>
2444 +
2445 +__socketcall(accept4,ACCEPT4)
2446 diff -urN -x .git dietlibc-0.33/i386/dyn_syscalls.S dietlibc/i386/dyn_syscalls.S
2447 --- dietlibc-0.33/i386/dyn_syscalls.S   2012-01-24 18:24:24.000000000 +0000
2448 +++ dietlibc/i386/dyn_syscalls.S        2015-01-01 12:14:43.464938896 +0000
2449 @@ -191,7 +191,6 @@
2450  #include "../syscalls.s/n_sigpending.S"
2451  #include "../syscalls.s/n_sigprocmask.S"
2452  #include "../syscalls.s/n_sigsuspend.S"
2453 -#include "../syscalls.s/nice.S"
2454  #include "../syscalls.s/pause.S"
2455  #include "../syscalls.s/personality.S"
2456  #include "../syscalls.s/query_module.S"
2457 diff -urN -x .git dietlibc-0.33/i386/getcontext.S dietlibc/i386/getcontext.S
2458 --- dietlibc-0.33/i386/getcontext.S     1970-01-01 00:00:00.000000000 +0000
2459 +++ dietlibc/i386/getcontext.S  2015-01-01 12:14:43.464938896 +0000
2460 @@ -0,0 +1,45 @@
2461 +#include "syscalls.h"
2462 +
2463 +.text
2464 +.global getcontext
2465 +.type getcontext,@function
2466 +/* store current CPU context into struct ucontext* */
2467 +getcontext:
2468 +  movl 4(%esp),%eax    /* load ucontext* */
2469 +  /* the registers are in uc_mcontext, which starts at offset 20 */
2470 +  movw %gs,20(%eax)
2471 +  movw %fs,24(%eax)
2472 +  movw %es,28(%eax)
2473 +  movw %ds,32(%eax)
2474 +  movl %edi,36(%eax)
2475 +  movl %esi,40(%eax)
2476 +  movl %ebp,44(%eax)
2477 +  /* skip esp until we stored ecx */
2478 +  movl %ebx,52(%eax)
2479 +  movl %edx,56(%eax)
2480 +  movl %ecx,60(%eax)
2481 +  lea 4(%esp),%ecx     /* store esp+4 to esp */
2482 +  mov %ecx,48(%eax)
2483 +  movl $0,64(%eax)     /* eax */
2484 +  /* not touching trapno and err, no idea what do store there */
2485 +  movl (%esp),%ecx
2486 +  movl %ecx,76(%eax)   /* store return value from stack into eip of struct */
2487 +  movw %cs,80(%eax)
2488 +  /* 84: eflags */
2489 +  /* 88: esp_at_signal */
2490 +  movw %ss,92(%eax)
2491 +
2492 +  lea 236(%eax),%ecx
2493 +  movl %ecx,96(%eax)
2494 +  fnstenv (%ecx)
2495 +  fldenv (%ecx)
2496 +  mov %ebx,%edi
2497 +  xor %ebx,%ebx
2498 +  xor %ecx,%ecx
2499 +  lea 108(%eax),%edx
2500 +  mov $__NR_sigprocmask,%eax
2501 +  int $0x80
2502 +  mov %edi,%ebx
2503 +  xor %eax,%eax
2504 +  ret
2505 +.size getcontext, .-getcontext
2506 diff -urN -x .git dietlibc-0.33/i386/Makefile.add dietlibc/i386/Makefile.add
2507 --- dietlibc-0.33/i386/Makefile.add     2012-01-24 18:24:24.000000000 +0000
2508 +++ dietlibc/i386/Makefile.add  2015-01-01 12:14:43.464938896 +0000
2509 @@ -1,7 +1,7 @@
2510  
2511  M:=$(shell ./findcflags.sh $(CC))
2512  LIBOBJ+=$(OBJDIR)/__ten.o $(OBJDIR)/md5asm.o $(OBJDIR)/__restore_rt.o \
2513 -$(OBJDIR)/__CAS.o
2514 +$(OBJDIR)/__CAS.o $(OBJDIR)/getcontext.o $(OBJDIR)/setcontext.o
2515  LIBMATH+=acos.o asin.o atan.o ceil.o cos.o exp.o exp10.o exp2.o expm1.o fabs.o floor.o hypot.o log.o log2.o log10.o sin.o sqrt.o copysign.o sincos.o __half.o ldexp.o ilogb.o cbrt.o log1p.o fmod.o libm2.o atan2.o tan.o
2516  LIBMATH:=$(filter-out acosh.o asinh.o atanh.o cbrt.o copysign.o exp10.o exp2.o expm1.o ilogb.o log2.o,$(LIBMATH))
2517  #CFLAGS+=-march=i386 -Os -fomit-frame-pointer -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mpreferred-stack-boundary=2
2518 diff -urN -x .git dietlibc-0.33/i386/recvmmsg.S dietlibc/i386/recvmmsg.S
2519 --- dietlibc-0.33/i386/recvmmsg.S       1970-01-01 00:00:00.000000000 +0000
2520 +++ dietlibc/i386/recvmmsg.S    2015-01-01 12:14:43.468272228 +0000
2521 @@ -0,0 +1,4 @@
2522 +#include <linuxnet.h>
2523 +#include <syscalls.h>
2524 +
2525 +__socketcall(recvmmsg,RECVMMSG)
2526 diff -urN -x .git dietlibc-0.33/i386/sendmmsg.S dietlibc/i386/sendmmsg.S
2527 --- dietlibc-0.33/i386/sendmmsg.S       1970-01-01 00:00:00.000000000 +0000
2528 +++ dietlibc/i386/sendmmsg.S    2015-01-01 12:14:43.468272228 +0000
2529 @@ -0,0 +1,4 @@
2530 +#include <linuxnet.h>
2531 +#include <syscalls.h>
2532 +
2533 +__socketcall(sendmmsg,SENDMMSG)
2534 diff -urN -x .git dietlibc-0.33/i386/setcontext.S dietlibc/i386/setcontext.S
2535 --- dietlibc-0.33/i386/setcontext.S     1970-01-01 00:00:00.000000000 +0000
2536 +++ dietlibc/i386/setcontext.S  2015-01-01 12:14:43.468272228 +0000
2537 @@ -0,0 +1,48 @@
2538 +#include "syscalls.h"
2539 +
2540 +.text
2541 +.global __setcontext_trampoline
2542 +.type __setcontext_trampoline,@function
2543 +__setcontext_trampoline:
2544 +  mov %ebx,4(%esp)
2545 +  /* fall through */
2546 +.size __setcontext_trampoline,.-__setcontext_trampoline
2547 +
2548 +.global setcontext
2549 +.type setcontext,@function
2550 +/* switch to stored CPU context from struct ucontext* */
2551 +setcontext:
2552 +  movl 4(%esp),%eax    /* load ucontext* */
2553 +  /* first, load the signal mask */
2554 +  movl %ebx,%edi
2555 +  xorl %edx,%edx
2556 +  movl $2,%ebx /* SIG_SETMASK */
2557 +  lea 108(%eax),%ecx
2558 +  movl $__NR_sigprocmask,%eax
2559 +  int $0x80
2560 +  cmp $-4095,%eax
2561 +  jb .Lnoerror
2562 +  jmp __error_unified_syscall
2563 +.Lnoerror:
2564 +  movl 4(%esp),%eax    /* load ucontext* */
2565 +  mov %edi,%ebx
2566 +  lea 236(%eax),%ecx
2567 +  fldenv (%ecx)
2568 +
2569 +  /* the registers are in uc_mcontext, which starts at offset 20 */
2570 +  /* do not restore gs because it's thread-specific */
2571 +  movw 24(%eax),%fs
2572 +  movw 28(%eax),%es
2573 +  movw 32(%eax),%ds
2574 +  movl 36(%eax),%edi
2575 +  movl 40(%eax),%esi
2576 +  movl 44(%eax),%ebp
2577 +  movl 48(%eax),%esp
2578 +  movw 92(%eax),%ss
2579 +  movl 52(%eax),%ebx
2580 +  movl 56(%eax),%edx
2581 +  movl 60(%eax),%ecx
2582 +
2583 +  movl 76(%eax),%eax
2584 +  jmp *%eax
2585 +.size setcontext, .-setcontext
2586 diff -urN -x .git dietlibc-0.33/i386/start.S dietlibc/i386/start.S
2587 --- dietlibc-0.33/i386/start.S  2012-01-24 18:24:24.000000000 +0000
2588 +++ dietlibc/i386/start.S       2015-01-01 12:14:43.468272228 +0000
2589 @@ -20,12 +20,18 @@
2590         PIC_INIT                        /* non-PIC: this is an empty line */
2591         PUT_VAR %esi, environ, %ecx     /* non-PIC: movl %esi,environ */
2592  
2593 -#ifdef WANT_SYSENTER
2594 +#if defined(WANT_ELFINFO) || defined(WANT_SYSENTER)
2595  /* skip environment, scan for NULL */
2596  1:
2597         lodsl
2598         testl   %eax,%eax
2599         jnz     1b
2600 +#  ifdef WANT_ELFINFO
2601 +       PUT_VAR %esi, __elfinfo, %ecx
2602 +#  endif
2603 +#endif
2604 +
2605 +#ifdef WANT_SYSENTER
2606  /* The ELF auxvec follows the environment, consists of key/value pairs.
2607     We are looking for key 32, which stands for the vsyscall page */
2608  1:
2609 diff -urN -x .git dietlibc-0.33/i386/syscalls.h dietlibc/i386/syscalls.h
2610 --- dietlibc-0.33/i386/syscalls.h       2012-01-24 18:24:24.000000000 +0000
2611 +++ dietlibc/i386/syscalls.h    2015-01-01 12:14:43.468272228 +0000
2612 @@ -339,6 +339,23 @@
2613  #define __NR_fanotify_init     338
2614  #define __NR_fanotify_mark     339
2615  #define __NR_prlimit64         340
2616 +#define __NR_name_to_handle_at 341
2617 +#define __NR_open_by_handle_at 342
2618 +#define __NR_clock_adjtime 343
2619 +#define __NR_syncfs 344
2620 +#define __NR_sendmmsg 345
2621 +#define __NR_setns 346
2622 +#define __NR_process_vm_readv 347
2623 +#define __NR_process_vm_writev 348
2624 +#define __NR_kcmp 349
2625 +#define __NR_finit_module 350
2626 +#define __NR_sched_setattr 351
2627 +#define __NR_sched_getattr 352
2628 +#define __NR_renameat2 353
2629 +#define __NR_seccomp 354
2630 +#define __NR_getrandom 355
2631 +#define __NR_memfd_create 356
2632 +
2633  
2634  #define syscall_weak(name,wsym,sym) \
2635  .text; \
2636 @@ -368,7 +385,6 @@
2637  .Lend##sym: ; \
2638  .size sym,.Lend##sym-sym
2639  
2640 -#ifndef __PIC__
2641  #define __socketcall(name,NAME) \
2642  .text; \
2643  .type name,@function; \
2644 @@ -381,6 +397,3 @@
2645         jmp socketcall; \
2646  .Lend##name:; \
2647  .size name,.Lend##name-name
2648 -#else
2649 -#define __socketcall(name,NAME)
2650 -#endif
2651 diff -urN -x .git dietlibc-0.33/ia64/clone.S dietlibc/ia64/clone.S
2652 --- dietlibc-0.33/ia64/clone.S  2006-06-23 17:29:33.000000000 +0000
2653 +++ dietlibc/ia64/clone.S       2015-01-01 12:14:43.468272228 +0000
2654 @@ -1,4 +1,4 @@
2655 -/* This is untested code which probably won´t work out of the box! */
2656 +/* This is untested code which probably won't work out of the box! */
2657  
2658  #include "syscalls.h"
2659  #include <errno.h>
2660 @@ -43,4 +43,5 @@
2661         br.call.dptk.few b0=__error_unified_syscall
2662         br.ret.sptk.few b0
2663  .endp __clone
2664 +.endp __clone2
2665  .size __clone, . - __clone
2666 diff -urN -x .git dietlibc-0.33/ia64/Makefile.add dietlibc/ia64/Makefile.add
2667 --- dietlibc-0.33/ia64/Makefile.add     2012-01-24 18:24:24.000000000 +0000
2668 +++ dietlibc/ia64/Makefile.add  2015-01-01 12:14:43.468272228 +0000
2669 @@ -1,2 +1,2 @@
2670  VPATH:=ia64:syscalls.s:$(VPATH)
2671 -LIBOBJ+=$(OBJDIR)/__time.o $(OBJDIR)/__waitpid.o $(OBJDIR)/__nice.o $(OBJDIR)/__alarm.o $(OBJDIR)/__CAS.o
2672 +LIBOBJ+=$(OBJDIR)/__time.o $(OBJDIR)/__waitpid.o $(OBJDIR)/__alarm.o $(OBJDIR)/__CAS.o $(OBJDIR)/__pause.o
2673 diff -urN -x .git dietlibc-0.33/ia64/__pause.c dietlibc/ia64/__pause.c
2674 --- dietlibc-0.33/ia64/__pause.c        1970-01-01 00:00:00.000000000 +0000
2675 +++ dietlibc/ia64/__pause.c     2015-01-01 12:14:43.468272228 +0000
2676 @@ -0,0 +1,10 @@
2677 +#include <unistd.h>
2678 +#include <signal.h>
2679 +
2680 +int pause(void)
2681 +{
2682 +  sigset_t set;
2683 +  sigemptyset(&set);
2684 +  sigprocmask(SIG_BLOCK, NULL, &set);
2685 +  return sigsuspend(&set);
2686 +}
2687 diff -urN -x .git dietlibc-0.33/ia64/start.S dietlibc/ia64/start.S
2688 --- dietlibc-0.33/ia64/start.S  2006-05-29 16:30:53.000000000 +0000
2689 +++ dietlibc/ia64/start.S       2015-01-01 12:14:43.468272228 +0000
2690 @@ -40,6 +40,16 @@
2691         ;;
2692         st8  [r14] = out2           /* store envp in environ */
2693  
2694 +#ifdef WANT_ELFINFO
2695 +#  warning "MAKE ME IE64 CODE!"
2696 +1:     ld8     r9 = [out2], 8      /* load *envp and increment it */
2697 +       orr     r9 = r9, r9         /* test for NULL */
2698 +       bne     1b
2699 +
2700 +       adds r14 = 8, r14           /* __elfinfo = environ + 8 */
2701 +       st8  [r14] = out2           /* store envp in __elfinfo */
2702 +#endif
2703 +
2704  #ifdef WANT_DYNAMIC
2705  /* FIXME: dl_init parameter ??? */
2706         br.call.sptk.few rp = _dyn_start
2707 diff -urN -x .git dietlibc-0.33/ia64/syscalls.h dietlibc/ia64/syscalls.h
2708 --- dietlibc-0.33/ia64/syscalls.h       2008-12-10 20:00:58.000000000 +0000
2709 +++ dietlibc/ia64/syscalls.h    2015-01-01 12:14:43.468272228 +0000
2710 @@ -289,6 +289,34 @@
2711  #define __NR_timerfd_create            1310
2712  #define __NR_timerfd_settime           1311
2713  #define __NR_timerfd_gettime           1312
2714 +#define __NR_signalfd4                 1313
2715 +#define __NR_eventfd2                  1314
2716 +#define __NR_epoll_create1             1315
2717 +#define __NR_dup3                      1316
2718 +#define __NR_pipe2                     1317
2719 +#define __NR_inotify_init1             1318
2720 +#define __NR_preadv                    1319
2721 +#define __NR_pwritev                   1320
2722 +#define __NR_rt_tgsigqueueinfo         1321
2723 +#define __NR_recvmmsg                  1322
2724 +#define __NR_fanotify_init             1323
2725 +#define __NR_fanotify_mark             1324
2726 +#define __NR_prlimit64                 1325
2727 +#define __NR_name_to_handle_at         1326
2728 +#define __NR_open_by_handle_at         1327
2729 +#define __NR_clock_adjtime             1328
2730 +#define __NR_syncfs                    1329
2731 +#define __NR_setns                     1330
2732 +#define __NR_sendmmsg                  1331
2733 +#define __NR_process_vm_readv          1332
2734 +#define __NR_process_vm_writev         1333
2735 +#define __NR_accept4                   1334
2736 +#define __NR_finit_module              1335
2737 +#define __NR_sched_setattr             1336
2738 +#define __NR_sched_getattr             1337
2739 +#define __NR_renameat2                 1338
2740 +#define __NR_getrandom                 1339
2741 +#define __NR_memfd_create              1340
2742  
2743  #define syscall(name, sym) \
2744  .text; \
2745 diff -urN -x .git dietlibc-0.33/ia64/unified.S dietlibc/ia64/unified.S
2746 --- dietlibc-0.33/ia64/unified.S        2006-06-23 17:29:33.000000000 +0000
2747 +++ dietlibc/ia64/unified.S     2015-01-01 12:14:43.468272228 +0000
2748 @@ -16,9 +16,7 @@
2749  .text
2750  
2751  .globl __unified_syscall
2752 -.proc  __unified_syscall
2753  .globl __error_unified_syscall
2754 -.proc  __error_unified_syscall
2755  .globl _exit
2756  .proc  _exit
2757  
2758 @@ -27,11 +25,16 @@
2759  .endp _exit
2760  .size _exit, . - _exit
2761  
2762 +.proc  __unified_syscall
2763  __unified_syscall:
2764         break.i 0x100000
2765         movl r2=errno
2766         cmp.eq p6,p0=-1,r10
2767         ;;
2768 +.endp __unified_syscall
2769 +.size __unified_syscall, . - __unified_syscall
2770 +
2771 +.proc  __error_unified_syscall
2772  __error_unified_syscall:
2773  (p6)    st4 [r2]=r8
2774  (p6)    mov r8=-1
2775 @@ -39,6 +42,6 @@
2776  #include "dietuglyweaks.h"
2777  
2778         br.ret.sptk.few rp
2779 +.endp __error_unified_syscall
2780  
2781 -.size __unified_syscall, __error_unified_syscall - __unified_syscall
2782  .size __error_unified_syscall, . - __error_unified_syscall
2783 diff -urN -x .git dietlibc-0.33/include/asm/posix_types.h dietlibc/include/asm/posix_types.h
2784 --- dietlibc-0.33/include/asm/posix_types.h     1970-01-01 00:00:00.000000000 +0000
2785 +++ dietlibc/include/asm/posix_types.h  2015-01-01 12:14:43.471605562 +0000
2786 @@ -0,0 +1,7 @@
2787 +#ifndef _ASM_POSIX_TYPES_H
2788 +#define _ASM_POSIX_TYPES_H
2789 +
2790 +typedef long __kernel_long_t;
2791 +typedef unsigned long __kernel_ulong_t;
2792 +
2793 +#endif
2794 diff -urN -x .git dietlibc-0.33/include/asm/prctl.h dietlibc/include/asm/prctl.h
2795 --- dietlibc-0.33/include/asm/prctl.h   1970-01-01 00:00:00.000000000 +0000
2796 +++ dietlibc/include/asm/prctl.h        2015-01-01 12:14:43.471605562 +0000
2797 @@ -0,0 +1,18 @@
2798 +#ifndef _ASM_PRCTL_H
2799 +#define _ASM_PRCTL_H
2800 +
2801 +#if defined(__x86_64__)
2802 +
2803 +#define ARCH_SET_GS 0x1001
2804 +#define ARCH_SET_FS 0x1002
2805 +#define ARCH_GET_FS 0x1003
2806 +#define ARCH_GET_GS 0x1004
2807 +
2808 +#elif defined(__i386__)
2809 +
2810 +#else
2811 +
2812 +#warning "need asm/prctl.h for this platform"
2813 +#endif
2814 +
2815 +#endif
2816 diff -urN -x .git dietlibc-0.33/include/dirent.h dietlibc/include/dirent.h
2817 --- dietlibc-0.33/include/dirent.h      2012-11-02 11:17:28.000000000 +0000
2818 +++ dietlibc/include/dirent.h   2015-01-01 12:14:43.471605562 +0000
2819 @@ -42,8 +42,8 @@
2820  #endif
2821  struct dirent64 *readdir64 (DIR *__dirp) __THROW;
2822  void rewinddir (DIR *__dirp) __THROW;
2823 -void seekdir (DIR *__dirp, long int __pos) __THROW;
2824 -long int telldir (DIR *__dirp) __THROW;
2825 +void seekdir (DIR *__dirp, long __pos) __THROW;
2826 +long telldir (DIR *__dirp) __THROW;
2827  
2828  int scandir(const char *dir, struct dirent ***namelist,
2829        int (*selection)(const struct dirent *),
2830 diff -urN -x .git dietlibc-0.33/include/dlfcn.h dietlibc/include/dlfcn.h
2831 --- dietlibc-0.33/include/dlfcn.h       2005-01-31 12:53:33.000000000 +0000
2832 +++ dietlibc/include/dlfcn.h    2015-01-01 12:14:43.471605562 +0000
2833 @@ -14,10 +14,10 @@
2834  
2835  __BEGIN_DECLS
2836  
2837 -void *dlopen (const char *filename, int flag);
2838 -const char *dlerror(void);
2839 -void *dlsym(void *handle, const char *symbol);
2840 -int dlclose (void *handle);
2841 +void *dlopen (const char *filename, int flag) __THROWNL;
2842 +const char *dlerror(void) __THROW;
2843 +void *dlsym(void *handle, const char *symbol) __THROW;
2844 +int dlclose (void *handle) __THROWNL;
2845  
2846  #ifdef _GNU_SOURCE
2847  typedef struct
2848 diff -urN -x .git dietlibc-0.33/include/elf.h dietlibc/include/elf.h
2849 --- dietlibc-0.33/include/elf.h 2010-09-25 17:03:25.000000000 +0000
2850 +++ dietlibc/include/elf.h      2015-01-01 12:14:43.471605562 +0000
2851 @@ -954,6 +954,15 @@
2852  
2853  #define        AT_SECURE       23              /* Boolean, was exec setuid-like?  */
2854  
2855 +#define AT_BASE_PLATFORM 24            /* String identifying real platforms.*/
2856 +
2857 +#define AT_RANDOM      25              /* Address of 16 random bytes.  */
2858 +
2859 +#define AT_HWCAP2      26              /* More machine-dependent hints about
2860 +                                          processor capabilities.  */
2861 +
2862 +#define AT_EXECFN      31              /* Filename of executable.  */
2863 +
2864  /* Pointer to the global system page used for system calls and other
2865     nice things.  */
2866  #define AT_SYSINFO     32
2867 diff -urN -x .git dietlibc-0.33/include/endian.h dietlibc/include/endian.h
2868 --- dietlibc-0.33/include/endian.h      2006-05-29 16:30:53.000000000 +0000
2869 +++ dietlibc/include/endian.h   2015-01-01 12:14:43.471605562 +0000
2870 @@ -39,10 +39,18 @@
2871  # define __LONG_LONG_PAIR(HI, LO) HI, LO
2872  #endif
2873  
2874 -#if defined(__alpha__) || defined(__mips64__) || defined(__sparc_v9__) || defined(__x86_64__) || defined(__ia64__) || defined(__powerpc64__) || defined(__s390x__)
2875 +#if defined(__alpha__) || defined(__mips64__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__powerpc64__) || defined(__s390x__)
2876  #define __WORDSIZE 64
2877  #endif
2878  
2879 +#if defined(__x86_64__)
2880 +#if defined(__ILP32__)
2881 +#define __OFF_T_MATCHES_OFF64_T
2882 +#else
2883 +#define __WORDSIZE 64
2884 +#endif
2885 +#endif
2886 +
2887  #if defined(__x86_64__) || defined(__powerpc64__) || defined(__sparc_v9__)
2888  #define __WORDSIZE_COMPAT32 1
2889  #endif
2890 @@ -51,7 +59,9 @@
2891  #define __WORDSIZE 64
2892  #endif
2893  
2894 -#ifndef __WORDSIZE
2895 +#ifdef __WORDSIZE
2896 +#define __OFF_T_MATCHES_OFF64_T
2897 +#else
2898  #define __WORDSIZE 32
2899  #endif
2900  
2901 diff -urN -x .git dietlibc-0.33/include/errno.h dietlibc/include/errno.h
2902 --- dietlibc-0.33/include/errno.h       2010-09-25 17:03:26.000000000 +0000
2903 +++ dietlibc/include/errno.h    2015-01-01 12:14:43.471605562 +0000
2904 @@ -704,11 +704,7 @@
2905  
2906  __BEGIN_DECLS
2907  
2908 -#ifndef _REENTRANT
2909 -extern int errno;
2910 -#else
2911 -#define errno (*__errno_location())
2912 -#endif
2913 +#include <errno_definition.h>
2914  
2915  extern int *__errno_location(void);
2916  
2917 diff -urN -x .git dietlibc-0.33/include/fcntl.h dietlibc/include/fcntl.h
2918 --- dietlibc-0.33/include/fcntl.h       2012-11-02 11:17:28.000000000 +0000
2919 +++ dietlibc/include/fcntl.h    2015-01-01 12:14:43.471605562 +0000
2920 @@ -14,8 +14,6 @@
2921  
2922  #if defined(__i386__) || defined(__s390__) || defined(__x86_64__) || defined(__ia64__)
2923  
2924 -/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
2925 -   located on an ext2 file system */
2926  #define O_ACCMODE         0003
2927  #define O_RDONLY            00
2928  #define O_WRONLY            01
2929 @@ -27,13 +25,17 @@
2930  #define O_APPEND         02000
2931  #define O_NONBLOCK       04000
2932  #define O_NDELAY       O_NONBLOCK
2933 -#define O_SYNC          010000
2934 +#define O_DSYNC                 010000
2935  #define FASYNC          020000 /* fcntl, for BSD compatibility */
2936  #define O_DIRECT        040000 /* direct disk access hint - currently ignored */
2937  #define O_LARGEFILE    0100000
2938  #define O_DIRECTORY    0200000 /* must be a directory */
2939  #define O_NOFOLLOW     0400000 /* don't follow links */
2940  #define O_NOATIME      01000000
2941 +#define O_CLOEXEC      02000000
2942 +#define O_SYNC         (O_DSYNC|04000000)
2943 +#define O_PATH         010000000
2944 +#define O_TMPFILE      020000000
2945  
2946  #define F_DUPFD                0       /* dup */
2947  #define F_GETFD                1       /* get close_on_exec */
2948 @@ -96,8 +98,6 @@
2949  
2950  #elif defined(__alpha__)
2951  
2952 -/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
2953 -   located on an ext2 file system */
2954  #define O_ACCMODE        0003
2955  #define O_RDONLY           00
2956  #define O_WRONLY           01
2957 @@ -110,13 +110,17 @@
2958  #define O_NONBLOCK      00004
2959  #define O_APPEND        00010
2960  #define O_NDELAY       O_NONBLOCK
2961 -#define O_SYNC         040000
2962 +#define O_DSYNC                040000
2963  #define FASYNC         020000  /* fcntl, for BSD compatibility */
2964  #define O_DIRECTORY    0100000 /* must be a directory */
2965  #define O_NOFOLLOW     0200000 /* don't follow links */
2966  #define O_LARGEFILE    0400000 /* will be set by the kernel on every open */
2967  #define O_DIRECT       02000000        /* direct disk access - should check with OSF/1 */
2968  #define O_NOATIME      04000000
2969 +#define O_CLOEXEC      010000000
2970 +#define O_SYNC         (020000000|O_DSYNC)
2971 +#define O_PATH         040000000
2972 +#define O_TMPFILE      0100000000
2973  
2974  #define F_DUPFD                0       /* dup */
2975  #define F_GETFD                1       /* get close_on_exec */
2976 @@ -167,14 +171,12 @@
2977  
2978  #elif defined(__mips__)
2979  
2980 -/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
2981 -   located on an ext2 file system */
2982  #define O_ACCMODE      0x0003
2983  #define O_RDONLY       0x0000
2984  #define O_WRONLY       0x0001
2985  #define O_RDWR         0x0002
2986  #define O_APPEND       0x0008
2987 -#define O_SYNC         0x0010
2988 +#define O_DSYNC                0x0010
2989  #define O_NONBLOCK     0x0080
2990  #define O_CREAT         0x0100 /* not fcntl */
2991  #define O_TRUNC                0x0200  /* not fcntl */
2992 @@ -182,10 +184,14 @@
2993  #define O_NOCTTY       0x0800  /* not fcntl */
2994  #define FASYNC         0x1000  /* fcntl, for BSD compatibility */
2995  #define O_LARGEFILE    0x2000  /* allow large file opens - currently ignored */
2996 +#define O_SYNC         (0x4000|O_DSYNC)
2997  #define O_DIRECT       0x8000  /* direct disk access hint - currently ignored */
2998  #define O_DIRECTORY    0x10000 /* must be a directory */
2999  #define O_NOFOLLOW     0x20000 /* don't follow links */
3000  #define O_NOATIME      0x40000
3001 +#define O_CLOEXEC      0x80000
3002 +#define O_PATH         040000000
3003 +#define O_TMPFILE      0100000000
3004  
3005  #define O_NDELAY       O_NONBLOCK
3006  
3007 @@ -266,8 +272,6 @@
3008  
3009  #elif defined(__sparc__)
3010  
3011 -/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
3012 -   located on an ext2 file system */
3013  #define O_RDONLY       0x0000
3014  #define O_WRONLY       0x0001
3015  #define O_RDWR         0x0002
3016 @@ -277,7 +281,7 @@
3017  #define O_CREAT                0x0200  /* not fcntl */
3018  #define O_TRUNC                0x0400  /* not fcntl */
3019  #define O_EXCL         0x0800  /* not fcntl */
3020 -#define O_SYNC         0x2000
3021 +#define O_DSYNC                0x2000
3022  #define O_NONBLOCK     0x4000
3023  #define O_NDELAY       (0x0004 | O_NONBLOCK)
3024  #define O_NOCTTY       0x8000  /* not fcntl */
3025 @@ -286,6 +290,10 @@
3026  #define O_LARGEFILE    0x40000
3027  #define O_DIRECT        0x100000 /* direct disk access hint */
3028  #define O_NOATIME      0x200000
3029 +#define O_CLOEXEC      0x400000
3030 +#define O_SYNC         (0x800000|O_DSYNC)
3031 +#define O_PATH         0x1000000
3032 +#define O_TMPFILE      0x2000000
3033  
3034  #define F_DUPFD                0       /* dup */
3035  #define F_GETFD                1       /* get close_on_exec */
3036 @@ -355,8 +363,6 @@
3037  
3038  #elif defined(__powerpc__) || defined(__powerpc64__)
3039  
3040 -/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
3041 -   located on an ext2 file system */
3042  #define O_ACCMODE         0003
3043  #define O_RDONLY            00
3044  #define O_WRONLY            01
3045 @@ -368,13 +374,17 @@
3046  #define O_APPEND         02000
3047  #define O_NONBLOCK       04000
3048  #define O_NDELAY       O_NONBLOCK
3049 -#define O_SYNC          010000
3050 +#define O_DSYNC                 010000
3051  #define FASYNC          020000 /* fcntl, for BSD compatibility */
3052  #define O_DIRECTORY      040000        /* must be a directory */
3053  #define O_NOFOLLOW      0100000        /* don't follow links */
3054  #define O_LARGEFILE     0200000
3055  #define O_DIRECT       0400000 /* direct disk access hint - currently ignored */
3056  #define O_NOATIME      01000000
3057 +#define O_CLOEXEC      02000000
3058 +#define O_SYNC         (O_DSYNC|04000000)
3059 +#define O_PATH         010000000
3060 +#define O_TMPFILE      020000000
3061  
3062  #define F_DUPFD                0       /* dup */
3063  #define F_GETFD                1       /* get close_on_exec */
3064 @@ -439,8 +449,6 @@
3065  
3066  #elif defined (__arm__)
3067  
3068 -/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
3069 -   located on an ext2 file system */
3070  #define O_ACCMODE         0003
3071  #define O_RDONLY            00
3072  #define O_WRONLY            01
3073 @@ -452,13 +460,17 @@
3074  #define O_APPEND         02000
3075  #define O_NONBLOCK       04000
3076  #define O_NDELAY       O_NONBLOCK
3077 -#define O_SYNC          010000
3078 +#define O_DSYNC                 010000
3079  #define FASYNC          020000 /* fcntl, for BSD compatibility */
3080  #define O_DIRECTORY     040000 /* must be a directory */
3081  #define O_NOFOLLOW     0100000 /* don't follow links */
3082  #define O_DIRECT       0200000 /* direct disk access hint - currently ignored */
3083  #define O_LARGEFILE    0400000
3084  #define O_NOATIME      01000000
3085 +#define O_CLOEXEC      02000000
3086 +#define O_SYNC         (O_DSYNC|04000000)
3087 +#define O_PATH         010000000
3088 +#define O_TMPFILE      020000000
3089  
3090  #define F_DUPFD                0       /* dup */
3091  #define F_GETFD                1       /* get close_on_exec */
3092 @@ -536,19 +548,24 @@
3093  #define O_EXCL      00002000 /* not fcntl */
3094  #define O_LARGEFILE 00004000
3095  #define O_ASYNC     00020000
3096 -#define O_SYNC      00100000
3097 +#define __O_SYNC      00100000
3098  #define O_NONBLOCK  00200004 /* HPUX has separate NDELAY & NONBLOCK */
3099  #define O_NDELAY    O_NONBLOCK
3100  #define O_NOCTTY    00400000 /* not fcntl */
3101  #define O_DSYNC     01000000 /* HPUX only */
3102  #define O_RSYNC     02000000 /* HPUX only */
3103  #define O_NOATIME   04000000
3104 +#define O_CLOEXEC   010000000
3105  #define O_DIRECTORY  00010000
3106  
3107  #define O_DIRECT    00040000 /* direct disk access hint - currently ignored */
3108  #define O_NOFOLLOW  00000200 /* don't follow links */
3109  #define O_INVISIBLE 04000000 /* invisible I/O, for DMAPI/XDSM */
3110  
3111 +#define O_PATH         020000000
3112 +#define O_TMPFILE      040000000
3113 +#define O_SYNC         (__O_SYNC|O_DSYNC)
3114 +
3115  #define F_DUPFD     0   /* Duplicate file descriptor.  */
3116  #define F_GETFD     1   /* Get file descriptor flags.  */
3117  #define F_SETFD     2   /* Set file descriptor flags.  */
3118 @@ -611,11 +628,55 @@
3119  
3120  #endif
3121  
3122 +#ifdef _GNU_SOURCE
3123 +
3124 +#define F_SETLEASE     (F_LINUX_SPECIFIC_BASE + 0)
3125 +#define F_GETLEASE     (F_LINUX_SPECIFIC_BASE + 1)
3126 +
3127 +/*
3128 + * Cancel a blocking posix lock; internal use only until we expose an
3129 + * asynchronous lock api to userspace:
3130 + */
3131 +#define F_CANCELLK     (F_LINUX_SPECIFIC_BASE + 5)
3132 +
3133 +/* Create a file descriptor with FD_CLOEXEC set. */
3134 +#define F_DUPFD_CLOEXEC        (F_LINUX_SPECIFIC_BASE + 6)
3135 +
3136 +/*
3137 + * Request nofications on a directory.
3138 + * See below for events that may be notified.
3139 + */
3140 +#define F_NOTIFY       (F_LINUX_SPECIFIC_BASE+2)
3141 +
3142 +/*
3143 + * Set and get of pipe page size array
3144 + */
3145 +#define F_SETPIPE_SZ   (F_LINUX_SPECIFIC_BASE + 7)
3146 +#define F_GETPIPE_SZ   (F_LINUX_SPECIFIC_BASE + 8)
3147 +
3148 +/*
3149 + * Set/Get seals
3150 + */
3151 +#define F_ADD_SEALS    (F_LINUX_SPECIFIC_BASE + 9)
3152 +#define F_GET_SEALS    (F_LINUX_SPECIFIC_BASE + 10)
3153 +
3154 +/*
3155 + * Types of seals
3156 + */
3157 +#define F_SEAL_SEAL    0x0001  /* prevent further seals from being set */
3158 +#define F_SEAL_SHRINK  0x0002  /* prevent file from shrinking */
3159 +#define F_SEAL_GROW    0x0004  /* prevent file from growing */
3160 +#define F_SEAL_WRITE   0x0008  /* prevent writes */
3161 +/* (1U << 31) is reserved for signed error codes */
3162 +#endif
3163 +
3164  extern int fcntl (int __fd, int __cmd, ...) __THROW;
3165  #ifndef __NO_STAT64
3166  extern int fcntl64 (int __fd, int __cmd, ...) __THROW;
3167 +extern int fstatat64(int dirfd, const char *pathname, struct stat *buf, int flags) __THROW;
3168  #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
3169  #define fcntl fcntl64
3170 +#define fstatat fstatat64
3171  #endif
3172  #endif
3173  
3174 @@ -628,37 +689,73 @@
3175  #endif
3176  
3177  #ifdef _GNU_SOURCE
3178 -#define SPLICE_F_MOVE  (0x01)  /* move pages instead of copying */
3179 -#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
3180 -                                /* we may still block on the fd we splice */
3181 -                                /* from/to, of course */
3182 -#define SPLICE_F_MORE  (0x04)  /* expect more data */
3183 -#define SPLICE_F_GIFT  (0x08)  /* pages passed in are a gift */
3184 +enum {
3185 +  SPLICE_F_MOVE=1,     /* move pages instead of copying */
3186 +#define SPLICE_F_MOVE SPLICE_F_MOVE
3187 +  SPLICE_F_NONBLOCK=2, /* don't block on splicing (may still block on fd we splice */
3188 +#define SPLICE_F_NONBLOCK SPLICE_F_NONBLOCK
3189 +  SPLICE_F_MORE=4,     /* expect more data */
3190 +#define SPLICE_F_MORE SPLICE_F_MORE
3191 +  SPLICE_F_GIFT=8      /* pages passed in are a gift */
3192 +#define SPLICE_F_GIFT SPLICE_F_GIFT
3193 +};
3194  
3195 -long tee(int fd_in, int fd_out, size_t len, unsigned int flags) __THROW;
3196 +ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags) __THROW;
3197  
3198  #include <sys/uio.h>
3199  
3200 -long vmsplice(int fd, const struct iovec *iov, unsigned long nr_segs, unsigned int flags) __THROW;
3201 -long splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) __THROW;
3202 +ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) __THROW;
3203 +ssize_t vmsplice(int fd, const struct iovec *iov, unsigned long nr_segs, unsigned int flags) __THROW;
3204  
3205  int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags) __THROW;
3206  
3207  #define FALLOC_FL_KEEP_SIZE 1
3208  
3209  int fallocate(int fd, int mode, loff_t offset, loff_t len) __THROW;
3210 +
3211 +/*
3212 + * Types of directory notifications that may be requested.
3213 + */
3214 +#define DN_ACCESS      0x00000001      /* File accessed */
3215 +#define DN_MODIFY      0x00000002      /* File modified */
3216 +#define DN_CREATE      0x00000004      /* File created */
3217 +#define DN_DELETE      0x00000008      /* File removed */
3218 +#define DN_RENAME      0x00000010      /* File renamed */
3219 +#define DN_ATTRIB      0x00000020      /* File changed attibutes */
3220 +#define DN_MULTISHOT   0x80000000      /* Don't remove notifier */
3221 +
3222  #endif
3223  
3224 -#if defined(_ATFILE_SOURCE) || ((_XOPEN_SOURCE + 0) >= 700) || ((_POSIX_C_SOURCE + 0) >= 200809L)
3225 +#define F_SETOWN_EX    15
3226 +#define F_GETOWN_EX    16
3227 +#define F_GETOWNER_UIDS        17
3228 +
3229 +#define F_OFD_GETLK    36
3230 +#define F_OFD_SETLK    37
3231 +#define F_OFD_SETLKW   38
3232 +
3233 +#define F_OWNER_TID    0
3234 +#define F_OWNER_PID    1
3235 +#define F_OWNER_PGRP   2
3236 +
3237 +struct f_owner_ex {
3238 +       int     type;
3239 +       int     pid;
3240 +};
3241 +
3242  #define AT_FDCWD               -100    /* Special value used to indicate openat should use the current working directory. */
3243  #define AT_SYMLINK_NOFOLLOW    0x100   /* Do not follow symbolic links.  */
3244  #define AT_REMOVEDIR           0x200   /* Remove directory instead of unlinking file.  */
3245  #define AT_SYMLINK_FOLLOW      0x400   /* Follow symbolic links.  */
3246 +#define AT_NO_AUTOMOUNT                0x800   /* Suppress terminal automount traversal */
3247 +#define AT_EMPTY_PATH          0x1000  /* Allow empty relative pathname */
3248 +
3249 +/* for faccessat */
3250 +#define AT_EACCESS             0x200   /* using euid, not uid for accessat */
3251  
3252  int openat(int dirfd, const char *pathname, int flags, ...) __THROW;
3253  int futimesat(int dirfd, const char *pathname, const struct timeval times[2]) __THROW;
3254  int unlinkat(int dirfd, const char *pathname, int flags) __THROW;
3255 -#endif
3256  
3257  #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0) >= 600
3258  #include "linux/fadvise.h"
3259 diff -urN -x .git dietlibc-0.33/include/inttypes.h dietlibc/include/inttypes.h
3260 --- dietlibc-0.33/include/inttypes.h    2012-01-24 18:24:25.000000000 +0000
3261 +++ dietlibc/include/inttypes.h 2015-01-01 12:14:43.471605562 +0000
3262 @@ -258,8 +258,8 @@
3263  #if __WORDSIZE == 64
3264  typedef signed long int64_t;
3265  typedef unsigned long uint64_t;
3266 -typedef signed long int intmax_t;
3267 -typedef unsigned long int uintmax_t;
3268 +typedef signed long intmax_t;
3269 +typedef unsigned long uintmax_t;
3270  #else
3271  __extension__ typedef signed long long int64_t;
3272  __extension__ typedef unsigned long long uint64_t;
3273 diff -urN -x .git dietlibc-0.33/include/linux/audit.h dietlibc/include/linux/audit.h
3274 --- dietlibc-0.33/include/linux/audit.h 1970-01-01 00:00:00.000000000 +0000
3275 +++ dietlibc/include/linux/audit.h      2015-01-01 12:14:43.471605562 +0000
3276 @@ -0,0 +1,432 @@
3277 +/* audit.h -- Auditing support
3278 + *
3279 + * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
3280 + * All Rights Reserved.
3281 + *
3282 + * This program is free software; you can redistribute it and/or modify
3283 + * it under the terms of the GNU General Public License as published by
3284 + * the Free Software Foundation; either version 2 of the License, or
3285 + * (at your option) any later version.
3286 + *
3287 + * This program is distributed in the hope that it will be useful,
3288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3290 + * GNU General Public License for more details.
3291 + *
3292 + * You should have received a copy of the GNU General Public License
3293 + * along with this program; if not, write to the Free Software
3294 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3295 + *
3296 + * Written by Rickard E. (Rik) Faith <faith@redhat.com>
3297 + *
3298 + */
3299 +
3300 +#ifndef _UAPI_LINUX_AUDIT_H_
3301 +#define _UAPI_LINUX_AUDIT_H_
3302 +
3303 +#include <inttypes.h>
3304 +
3305 +#include <linux/elf-em.h>
3306 +
3307 +/* The netlink messages for the audit system is divided into blocks:
3308 + * 1000 - 1099 are for commanding the audit system
3309 + * 1100 - 1199 user space trusted application messages
3310 + * 1200 - 1299 messages internal to the audit daemon
3311 + * 1300 - 1399 audit event messages
3312 + * 1400 - 1499 SE Linux use
3313 + * 1500 - 1599 kernel LSPP events
3314 + * 1600 - 1699 kernel crypto events
3315 + * 1700 - 1799 kernel anomaly records
3316 + * 1800 - 1899 kernel integrity events
3317 + * 1900 - 1999 future kernel use
3318 + * 2000 is for otherwise unclassified kernel audit messages (legacy)
3319 + * 2001 - 2099 unused (kernel)
3320 + * 2100 - 2199 user space anomaly records
3321 + * 2200 - 2299 user space actions taken in response to anomalies
3322 + * 2300 - 2399 user space generated LSPP events
3323 + * 2400 - 2499 user space crypto events
3324 + * 2500 - 2999 future user space (maybe integrity labels and related events)
3325 + *
3326 + * Messages from 1000-1199 are bi-directional. 1200-1299 & 2100 - 2999 are
3327 + * exclusively user space. 1300-2099 is kernel --> user space 
3328 + * communication.
3329 + */
3330 +#define AUDIT_GET              1000    /* Get status */
3331 +#define AUDIT_SET              1001    /* Set status (enable/disable/auditd) */
3332 +#define AUDIT_LIST             1002    /* List syscall rules -- deprecated */
3333 +#define AUDIT_ADD              1003    /* Add syscall rule -- deprecated */
3334 +#define AUDIT_DEL              1004    /* Delete syscall rule -- deprecated */
3335 +#define AUDIT_USER             1005    /* Message from userspace -- deprecated */
3336 +#define AUDIT_LOGIN            1006    /* Define the login id and information */
3337 +#define AUDIT_WATCH_INS                1007    /* Insert file/dir watch entry */
3338 +#define AUDIT_WATCH_REM                1008    /* Remove file/dir watch entry */
3339 +#define AUDIT_WATCH_LIST       1009    /* List all file/dir watches */
3340 +#define AUDIT_SIGNAL_INFO      1010    /* Get info about sender of signal to auditd */
3341 +#define AUDIT_ADD_RULE         1011    /* Add syscall filtering rule */
3342 +#define AUDIT_DEL_RULE         1012    /* Delete syscall filtering rule */
3343 +#define AUDIT_LIST_RULES       1013    /* List syscall filtering rules */
3344 +#define AUDIT_TRIM             1014    /* Trim junk from watched tree */
3345 +#define AUDIT_MAKE_EQUIV       1015    /* Append to watched tree */
3346 +#define AUDIT_TTY_GET          1016    /* Get TTY auditing status */
3347 +#define AUDIT_TTY_SET          1017    /* Set TTY auditing status */
3348 +#define AUDIT_SET_FEATURE      1018    /* Turn an audit feature on or off */
3349 +#define AUDIT_GET_FEATURE      1019    /* Get which features are enabled */
3350 +#define AUDIT_FEATURE_CHANGE   1020    /* audit log listing feature changes */
3351 +
3352 +#define AUDIT_FIRST_USER_MSG   1100    /* Userspace messages mostly uninteresting to kernel */
3353 +#define AUDIT_USER_AVC         1107    /* We filter this differently */
3354 +#define AUDIT_USER_TTY         1124    /* Non-ICANON TTY input meaning */
3355 +#define AUDIT_LAST_USER_MSG    1199
3356 +#define AUDIT_FIRST_USER_MSG2  2100    /* More user space messages */
3357 +#define AUDIT_LAST_USER_MSG2   2999
3358
3359 +#define AUDIT_DAEMON_START      1200    /* Daemon startup record */
3360 +#define AUDIT_DAEMON_END        1201    /* Daemon normal stop record */
3361 +#define AUDIT_DAEMON_ABORT      1202    /* Daemon error stop record */
3362 +#define AUDIT_DAEMON_CONFIG     1203    /* Daemon config change */
3363 +
3364 +#define AUDIT_SYSCALL          1300    /* Syscall event */
3365 +/* #define AUDIT_FS_WATCH      1301     * Deprecated */
3366 +#define AUDIT_PATH             1302    /* Filename path information */
3367 +#define AUDIT_IPC              1303    /* IPC record */
3368 +#define AUDIT_SOCKETCALL       1304    /* sys_socketcall arguments */
3369 +#define AUDIT_CONFIG_CHANGE    1305    /* Audit system configuration change */
3370 +#define AUDIT_SOCKADDR         1306    /* sockaddr copied as syscall arg */
3371 +#define AUDIT_CWD              1307    /* Current working directory */
3372 +#define AUDIT_EXECVE           1309    /* execve arguments */
3373 +#define AUDIT_IPC_SET_PERM     1311    /* IPC new permissions record type */
3374 +#define AUDIT_MQ_OPEN          1312    /* POSIX MQ open record type */
3375 +#define AUDIT_MQ_SENDRECV      1313    /* POSIX MQ send/receive record type */
3376 +#define AUDIT_MQ_NOTIFY                1314    /* POSIX MQ notify record type */
3377 +#define AUDIT_MQ_GETSETATTR    1315    /* POSIX MQ get/set attribute record type */
3378 +#define AUDIT_KERNEL_OTHER     1316    /* For use by 3rd party modules */
3379 +#define AUDIT_FD_PAIR          1317    /* audit record for pipe/socketpair */
3380 +#define AUDIT_OBJ_PID          1318    /* ptrace target */
3381 +#define AUDIT_TTY              1319    /* Input on an administrative TTY */
3382 +#define AUDIT_EOE              1320    /* End of multi-record event */
3383 +#define AUDIT_BPRM_FCAPS       1321    /* Information about fcaps increasing perms */
3384 +#define AUDIT_CAPSET           1322    /* Record showing argument to sys_capset */
3385 +#define AUDIT_MMAP             1323    /* Record showing descriptor and flags in mmap */
3386 +#define AUDIT_NETFILTER_PKT    1324    /* Packets traversing netfilter chains */
3387 +#define AUDIT_NETFILTER_CFG    1325    /* Netfilter chain modifications */
3388 +#define AUDIT_SECCOMP          1326    /* Secure Computing event */
3389 +
3390 +#define AUDIT_AVC              1400    /* SE Linux avc denial or grant */
3391 +#define AUDIT_SELINUX_ERR      1401    /* Internal SE Linux Errors */
3392 +#define AUDIT_AVC_PATH         1402    /* dentry, vfsmount pair from avc */
3393 +#define AUDIT_MAC_POLICY_LOAD  1403    /* Policy file load */
3394 +#define AUDIT_MAC_STATUS       1404    /* Changed enforcing,permissive,off */
3395 +#define AUDIT_MAC_CONFIG_CHANGE        1405    /* Changes to booleans */
3396 +#define AUDIT_MAC_UNLBL_ALLOW  1406    /* NetLabel: allow unlabeled traffic */
3397 +#define AUDIT_MAC_CIPSOV4_ADD  1407    /* NetLabel: add CIPSOv4 DOI entry */
3398 +#define AUDIT_MAC_CIPSOV4_DEL  1408    /* NetLabel: del CIPSOv4 DOI entry */
3399 +#define AUDIT_MAC_MAP_ADD      1409    /* NetLabel: add LSM domain mapping */
3400 +#define AUDIT_MAC_MAP_DEL      1410    /* NetLabel: del LSM domain mapping */
3401 +#define AUDIT_MAC_IPSEC_ADDSA  1411    /* Not used */
3402 +#define AUDIT_MAC_IPSEC_DELSA  1412    /* Not used  */
3403 +#define AUDIT_MAC_IPSEC_ADDSPD 1413    /* Not used */
3404 +#define AUDIT_MAC_IPSEC_DELSPD 1414    /* Not used */
3405 +#define AUDIT_MAC_IPSEC_EVENT  1415    /* Audit an IPSec event */
3406 +#define AUDIT_MAC_UNLBL_STCADD 1416    /* NetLabel: add a static label */
3407 +#define AUDIT_MAC_UNLBL_STCDEL 1417    /* NetLabel: del a static label */
3408 +
3409 +#define AUDIT_FIRST_KERN_ANOM_MSG   1700
3410 +#define AUDIT_LAST_KERN_ANOM_MSG    1799
3411 +#define AUDIT_ANOM_PROMISCUOUS      1700 /* Device changed promiscuous mode */
3412 +#define AUDIT_ANOM_ABEND            1701 /* Process ended abnormally */
3413 +#define AUDIT_ANOM_LINK                    1702 /* Suspicious use of file links */
3414 +#define AUDIT_INTEGRITY_DATA       1800 /* Data integrity verification */
3415 +#define AUDIT_INTEGRITY_METADATA    1801 /* Metadata integrity verification */
3416 +#define AUDIT_INTEGRITY_STATUS     1802 /* Integrity enable status */
3417 +#define AUDIT_INTEGRITY_HASH       1803 /* Integrity HASH type */
3418 +#define AUDIT_INTEGRITY_PCR        1804 /* PCR invalidation msgs */
3419 +#define AUDIT_INTEGRITY_RULE       1805 /* policy rule */
3420 +
3421 +#define AUDIT_KERNEL           2000    /* Asynchronous audit record. NOT A REQUEST. */
3422 +
3423 +/* Rule flags */
3424 +#define AUDIT_FILTER_USER      0x00    /* Apply rule to user-generated messages */
3425 +#define AUDIT_FILTER_TASK      0x01    /* Apply rule at task creation (not syscall) */
3426 +#define AUDIT_FILTER_ENTRY     0x02    /* Apply rule at syscall entry */
3427 +#define AUDIT_FILTER_WATCH     0x03    /* Apply rule to file system watches */
3428 +#define AUDIT_FILTER_EXIT      0x04    /* Apply rule at syscall exit */
3429 +#define AUDIT_FILTER_TYPE      0x05    /* Apply rule at audit_log_start */
3430 +
3431 +#define AUDIT_NR_FILTERS       6
3432 +
3433 +#define AUDIT_FILTER_PREPEND   0x10    /* Prepend to front of list */
3434 +
3435 +/* Rule actions */
3436 +#define AUDIT_NEVER    0       /* Do not build context if rule matches */
3437 +#define AUDIT_POSSIBLE 1       /* Build context if rule matches  */
3438 +#define AUDIT_ALWAYS   2       /* Generate audit record if rule matches */
3439 +
3440 +/* Rule structure sizes -- if these change, different AUDIT_ADD and
3441 + * AUDIT_LIST commands must be implemented. */
3442 +#define AUDIT_MAX_FIELDS   64
3443 +#define AUDIT_MAX_KEY_LEN  256
3444 +#define AUDIT_BITMASK_SIZE 64
3445 +#define AUDIT_WORD(nr) ((uint32_t)((nr)/32))
3446 +#define AUDIT_BIT(nr)  (1 << ((nr) - AUDIT_WORD(nr)*32))
3447 +
3448 +#define AUDIT_SYSCALL_CLASSES 16
3449 +#define AUDIT_CLASS_DIR_WRITE 0
3450 +#define AUDIT_CLASS_DIR_WRITE_32 1
3451 +#define AUDIT_CLASS_CHATTR 2
3452 +#define AUDIT_CLASS_CHATTR_32 3
3453 +#define AUDIT_CLASS_READ 4
3454 +#define AUDIT_CLASS_READ_32 5
3455 +#define AUDIT_CLASS_WRITE 6
3456 +#define AUDIT_CLASS_WRITE_32 7
3457 +#define AUDIT_CLASS_SIGNAL 8
3458 +#define AUDIT_CLASS_SIGNAL_32 9
3459 +
3460 +/* This bitmask is used to validate user input.  It represents all bits that
3461 + * are currently used in an audit field constant understood by the kernel.
3462 + * If you are adding a new #define AUDIT_<whatever>, please ensure that
3463 + * AUDIT_UNUSED_BITS is updated if need be. */
3464 +#define AUDIT_UNUSED_BITS      0x07FFFC00
3465 +
3466 +/* AUDIT_FIELD_COMPARE rule list */
3467 +#define AUDIT_COMPARE_UID_TO_OBJ_UID   1
3468 +#define AUDIT_COMPARE_GID_TO_OBJ_GID   2
3469 +#define AUDIT_COMPARE_EUID_TO_OBJ_UID  3
3470 +#define AUDIT_COMPARE_EGID_TO_OBJ_GID  4
3471 +#define AUDIT_COMPARE_AUID_TO_OBJ_UID  5
3472 +#define AUDIT_COMPARE_SUID_TO_OBJ_UID  6
3473 +#define AUDIT_COMPARE_SGID_TO_OBJ_GID  7
3474 +#define AUDIT_COMPARE_FSUID_TO_OBJ_UID 8
3475 +#define AUDIT_COMPARE_FSGID_TO_OBJ_GID 9
3476 +
3477 +#define AUDIT_COMPARE_UID_TO_AUID      10
3478 +#define AUDIT_COMPARE_UID_TO_EUID      11
3479 +#define AUDIT_COMPARE_UID_TO_FSUID     12
3480 +#define AUDIT_COMPARE_UID_TO_SUID      13
3481 +
3482 +#define AUDIT_COMPARE_AUID_TO_FSUID    14
3483 +#define AUDIT_COMPARE_AUID_TO_SUID     15
3484 +#define AUDIT_COMPARE_AUID_TO_EUID     16
3485 +
3486 +#define AUDIT_COMPARE_EUID_TO_SUID     17
3487 +#define AUDIT_COMPARE_EUID_TO_FSUID    18
3488 +
3489 +#define AUDIT_COMPARE_SUID_TO_FSUID    19
3490 +
3491 +#define AUDIT_COMPARE_GID_TO_EGID      20
3492 +#define AUDIT_COMPARE_GID_TO_FSGID     21
3493 +#define AUDIT_COMPARE_GID_TO_SGID      22
3494 +
3495 +#define AUDIT_COMPARE_EGID_TO_FSGID    23
3496 +#define AUDIT_COMPARE_EGID_TO_SGID     24
3497 +#define AUDIT_COMPARE_SGID_TO_FSGID    25
3498 +
3499 +#define AUDIT_MAX_FIELD_COMPARE                AUDIT_COMPARE_SGID_TO_FSGID
3500 +
3501 +/* Rule fields */
3502 +                               /* These are useful when checking the
3503 +                                * task structure at task creation time
3504 +                                * (AUDIT_PER_TASK).  */
3505 +#define AUDIT_PID      0
3506 +#define AUDIT_UID      1
3507 +#define AUDIT_EUID     2
3508 +#define AUDIT_SUID     3
3509 +#define AUDIT_FSUID    4
3510 +#define AUDIT_GID      5
3511 +#define AUDIT_EGID     6
3512 +#define AUDIT_SGID     7
3513 +#define AUDIT_FSGID    8
3514 +#define AUDIT_LOGINUID 9
3515 +#define AUDIT_PERS     10
3516 +#define AUDIT_ARCH     11
3517 +#define AUDIT_MSGTYPE  12
3518 +#define AUDIT_SUBJ_USER        13      /* security label user */
3519 +#define AUDIT_SUBJ_ROLE        14      /* security label role */
3520 +#define AUDIT_SUBJ_TYPE        15      /* security label type */
3521 +#define AUDIT_SUBJ_SEN 16      /* security label sensitivity label */
3522 +#define AUDIT_SUBJ_CLR 17      /* security label clearance label */
3523 +#define AUDIT_PPID     18
3524 +#define AUDIT_OBJ_USER 19
3525 +#define AUDIT_OBJ_ROLE 20
3526 +#define AUDIT_OBJ_TYPE 21
3527 +#define AUDIT_OBJ_LEV_LOW      22
3528 +#define AUDIT_OBJ_LEV_HIGH     23
3529 +#define AUDIT_LOGINUID_SET     24
3530 +
3531 +                               /* These are ONLY useful when checking
3532 +                                * at syscall exit time (AUDIT_AT_EXIT). */
3533 +#define AUDIT_DEVMAJOR 100
3534 +#define AUDIT_DEVMINOR 101
3535 +#define AUDIT_INODE    102
3536 +#define AUDIT_EXIT     103
3537 +#define AUDIT_SUCCESS   104    /* exit >= 0; value ignored */
3538 +#define AUDIT_WATCH    105
3539 +#define AUDIT_PERM     106
3540 +#define AUDIT_DIR      107
3541 +#define AUDIT_FILETYPE 108
3542 +#define AUDIT_OBJ_UID  109
3543 +#define AUDIT_OBJ_GID  110
3544 +#define AUDIT_FIELD_COMPARE    111
3545 +
3546 +#define AUDIT_ARG0      200
3547 +#define AUDIT_ARG1      (AUDIT_ARG0+1)
3548 +#define AUDIT_ARG2      (AUDIT_ARG0+2)
3549 +#define AUDIT_ARG3      (AUDIT_ARG0+3)
3550 +
3551 +#define AUDIT_FILTERKEY        210
3552 +
3553 +#define AUDIT_NEGATE                   0x80000000
3554 +
3555 +/* These are the supported operators.
3556 + *     4  2  1  8
3557 + *     =  >  <  ?
3558 + *     ----------
3559 + *     0  0  0  0      00      nonsense
3560 + *     0  0  0  1      08      &  bit mask
3561 + *     0  0  1  0      10      <
3562 + *     0  1  0  0      20      >
3563 + *     0  1  1  0      30      !=
3564 + *     1  0  0  0      40      =
3565 + *     1  0  0  1      48      &=  bit test
3566 + *     1  0  1  0      50      <=
3567 + *     1  1  0  0      60      >=
3568 + *     1  1  1  1      78      all operators
3569 + */
3570 +#define AUDIT_BIT_MASK                 0x08000000
3571 +#define AUDIT_LESS_THAN                        0x10000000
3572 +#define AUDIT_GREATER_THAN             0x20000000
3573 +#define AUDIT_NOT_EQUAL                        0x30000000
3574 +#define AUDIT_EQUAL                    0x40000000
3575 +#define AUDIT_BIT_TEST                 (AUDIT_BIT_MASK|AUDIT_EQUAL)
3576 +#define AUDIT_LESS_THAN_OR_EQUAL       (AUDIT_LESS_THAN|AUDIT_EQUAL)
3577 +#define AUDIT_GREATER_THAN_OR_EQUAL    (AUDIT_GREATER_THAN|AUDIT_EQUAL)
3578 +#define AUDIT_OPERATORS                        (AUDIT_EQUAL|AUDIT_NOT_EQUAL|AUDIT_BIT_MASK)
3579 +
3580 +enum {
3581 +       Audit_equal,
3582 +       Audit_not_equal,
3583 +       Audit_bitmask,
3584 +       Audit_bittest,
3585 +       Audit_lt,
3586 +       Audit_gt,
3587 +       Audit_le,
3588 +       Audit_ge,
3589 +       Audit_bad
3590 +};
3591 +
3592 +/* Status symbols */
3593 +                               /* Mask values */
3594 +#define AUDIT_STATUS_ENABLED           0x0001
3595 +#define AUDIT_STATUS_FAILURE           0x0002
3596 +#define AUDIT_STATUS_PID               0x0004
3597 +#define AUDIT_STATUS_RATE_LIMIT                0x0008
3598 +#define AUDIT_STATUS_BACKLOG_LIMIT     0x0010
3599 +                               /* Failure-to-log actions */
3600 +#define AUDIT_FAIL_SILENT      0
3601 +#define AUDIT_FAIL_PRINTK      1
3602 +#define AUDIT_FAIL_PANIC       2
3603 +
3604 +/* distinguish syscall tables */
3605 +#define __AUDIT_ARCH_64BIT 0x80000000
3606 +#define __AUDIT_ARCH_LE           0x40000000
3607 +#define AUDIT_ARCH_ALPHA       (EM_ALPHA|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
3608 +#define AUDIT_ARCH_ARM         (EM_ARM|__AUDIT_ARCH_LE)
3609 +#define AUDIT_ARCH_ARMEB       (EM_ARM)
3610 +#define AUDIT_ARCH_CRIS                (EM_CRIS|__AUDIT_ARCH_LE)
3611 +#define AUDIT_ARCH_FRV         (EM_FRV)
3612 +#define AUDIT_ARCH_I386                (EM_386|__AUDIT_ARCH_LE)
3613 +#define AUDIT_ARCH_IA64                (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
3614 +#define AUDIT_ARCH_M32R                (EM_M32R)
3615 +#define AUDIT_ARCH_M68K                (EM_68K)
3616 +#define AUDIT_ARCH_MIPS                (EM_MIPS)
3617 +#define AUDIT_ARCH_MIPSEL      (EM_MIPS|__AUDIT_ARCH_LE)
3618 +#define AUDIT_ARCH_MIPS64      (EM_MIPS|__AUDIT_ARCH_64BIT)
3619 +#define AUDIT_ARCH_MIPSEL64    (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
3620 +#define AUDIT_ARCH_OPENRISC    (EM_OPENRISC)
3621 +#define AUDIT_ARCH_PARISC      (EM_PARISC)
3622 +#define AUDIT_ARCH_PARISC64    (EM_PARISC|__AUDIT_ARCH_64BIT)
3623 +#define AUDIT_ARCH_PPC         (EM_PPC)
3624 +#define AUDIT_ARCH_PPC64       (EM_PPC64|__AUDIT_ARCH_64BIT)
3625 +#define AUDIT_ARCH_S390                (EM_S390)
3626 +#define AUDIT_ARCH_S390X       (EM_S390|__AUDIT_ARCH_64BIT)
3627 +#define AUDIT_ARCH_SH          (EM_SH)
3628 +#define AUDIT_ARCH_SHEL                (EM_SH|__AUDIT_ARCH_LE)
3629 +#define AUDIT_ARCH_SH64                (EM_SH|__AUDIT_ARCH_64BIT)
3630 +#define AUDIT_ARCH_SHEL64      (EM_SH|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
3631 +#define AUDIT_ARCH_SPARC       (EM_SPARC)
3632 +#define AUDIT_ARCH_SPARC64     (EM_SPARCV9|__AUDIT_ARCH_64BIT)
3633 +#define AUDIT_ARCH_X86_64      (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
3634 +
3635 +#define AUDIT_PERM_EXEC                1
3636 +#define AUDIT_PERM_WRITE       2
3637 +#define AUDIT_PERM_READ                4
3638 +#define AUDIT_PERM_ATTR                8
3639 +
3640 +/* MAX_AUDIT_MESSAGE_LENGTH is set in audit:lib/libaudit.h as:
3641 + * 8970 // PATH_MAX*2+CONTEXT_SIZE*2+11+256+1
3642 + * max header+body+tailer: 44 + 29 + 32 + 262 + 7 + pad
3643 + */
3644 +#define AUDIT_MESSAGE_TEXT_MAX 8560
3645 +
3646 +struct audit_status {
3647 +       uint32_t                mask;           /* Bit mask for valid entries */
3648 +       uint32_t                enabled;        /* 1 = enabled, 0 = disabled */
3649 +       uint32_t                failure;        /* Failure-to-log action */
3650 +       uint32_t                pid;            /* pid of auditd process */
3651 +       uint32_t                rate_limit;     /* messages rate limit (per second) */
3652 +       uint32_t                backlog_limit;  /* waiting messages limit */
3653 +       uint32_t                lost;           /* messages lost */
3654 +       uint32_t                backlog;        /* messages waiting in queue */
3655 +};
3656 +
3657 +struct audit_features {
3658 +#define AUDIT_FEATURE_VERSION  1
3659 +       uint32_t        vers;
3660 +       uint32_t        mask;           /* which bits we are dealing with */
3661 +       uint32_t        features;       /* which feature to enable/disable */
3662 +       uint32_t        lock;           /* which features to lock */
3663 +};
3664 +
3665 +#define AUDIT_FEATURE_ONLY_UNSET_LOGINUID      0
3666 +#define AUDIT_FEATURE_LOGINUID_IMMUTABLE       1
3667 +#define AUDIT_LAST_FEATURE                     AUDIT_FEATURE_LOGINUID_IMMUTABLE
3668 +
3669 +#define audit_feature_valid(x)         ((x) >= 0 && (x) <= AUDIT_LAST_FEATURE)
3670 +#define AUDIT_FEATURE_TO_MASK(x)       (1 << ((x) & 31)) /* mask for uint32_t */
3671 +
3672 +struct audit_tty_status {
3673 +       uint32_t                enabled;        /* 1 = enabled, 0 = disabled */
3674 +       uint32_t                log_passwd;     /* 1 = enabled, 0 = disabled */
3675 +};
3676 +
3677 +#define AUDIT_UID_UNSET (unsigned int)-1
3678 +
3679 +/* audit_rule_data supports filter rules with both integer and string
3680 + * fields.  It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and
3681 + * AUDIT_LIST_RULES requests.
3682 + */
3683 +struct audit_rule_data {
3684 +       uint32_t                flags;  /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
3685 +       uint32_t                action; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
3686 +       uint32_t                field_count;
3687 +       uint32_t                mask[AUDIT_BITMASK_SIZE]; /* syscall(s) affected */
3688 +       uint32_t                fields[AUDIT_MAX_FIELDS];
3689 +       uint32_t                values[AUDIT_MAX_FIELDS];
3690 +       uint32_t                fieldflags[AUDIT_MAX_FIELDS];
3691 +       uint32_t                buflen; /* total length of string fields */
3692 +       char            buf[0]; /* string fields buffer */
3693 +};
3694 +
3695 +/* audit_rule is supported to maintain backward compatibility with
3696 + * userspace.  It supports integer fields only and corresponds to
3697 + * AUDIT_ADD, AUDIT_DEL and AUDIT_LIST requests.
3698 + */
3699 +struct audit_rule {            /* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */
3700 +       uint32_t                flags;  /* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
3701 +       uint32_t                action; /* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
3702 +       uint32_t                field_count;
3703 +       uint32_t                mask[AUDIT_BITMASK_SIZE];
3704 +       uint32_t                fields[AUDIT_MAX_FIELDS];
3705 +       uint32_t                values[AUDIT_MAX_FIELDS];
3706 +};
3707 +
3708 +#endif /* _UAPI_LINUX_AUDIT_H_ */
3709 diff -urN -x .git dietlibc-0.33/include/linux/elf-em.h dietlibc/include/linux/elf-em.h
3710 --- dietlibc-0.33/include/linux/elf-em.h        1970-01-01 00:00:00.000000000 +0000
3711 +++ dietlibc/include/linux/elf-em.h     2015-01-01 12:14:43.471605562 +0000
3712 @@ -0,0 +1,57 @@
3713 +#ifndef _LINUX_ELF_EM_H
3714 +#define _LINUX_ELF_EM_H
3715 +
3716 +/* These constants define the various ELF target machines */
3717 +#define EM_NONE                0
3718 +#define EM_M32         1
3719 +#define EM_SPARC       2
3720 +#define EM_386         3
3721 +#define EM_68K         4
3722 +#define EM_88K         5
3723 +#define EM_486         6       /* Perhaps disused */
3724 +#define EM_860         7
3725 +#define EM_MIPS                8       /* MIPS R3000 (officially, big-endian only) */
3726 +                               /* Next two are historical and binaries and
3727 +                                  modules of these types will be rejected by
3728 +                                  Linux.  */
3729 +#define EM_MIPS_RS3_LE 10      /* MIPS R3000 little-endian */
3730 +#define EM_MIPS_RS4_BE 10      /* MIPS R4000 big-endian */
3731 +
3732 +#define EM_PARISC      15      /* HPPA */
3733 +#define EM_SPARC32PLUS 18      /* Sun's "v8plus" */
3734 +#define EM_PPC         20      /* PowerPC */
3735 +#define EM_PPC64       21       /* PowerPC64 */
3736 +#define EM_SPU         23      /* Cell BE SPU */
3737 +#define EM_ARM         40      /* ARM 32 bit */
3738 +#define EM_SH          42      /* SuperH */
3739 +#define EM_SPARCV9     43      /* SPARC v9 64-bit */
3740 +#define EM_IA_64       50      /* HP/Intel IA-64 */
3741 +#define EM_X86_64      62      /* AMD x86-64 */
3742 +#define EM_S390                22      /* IBM S/390 */
3743 +#define EM_CRIS                76      /* Axis Communications 32-bit embedded processor */
3744 +#define EM_V850                87      /* NEC v850 */
3745 +#define EM_M32R                88      /* Renesas M32R */
3746 +#define EM_MN10300     89      /* Panasonic/MEI MN10300, AM33 */
3747 +#define EM_BLACKFIN     106     /* ADI Blackfin Processor */
3748 +#define EM_TI_C6000    140     /* TI C6X DSPs */
3749 +#define EM_AARCH64     183     /* ARM 64 bit */
3750 +#define EM_FRV         0x5441  /* Fujitsu FR-V */
3751 +#define EM_AVR32       0x18ad  /* Atmel AVR32 */
3752 +
3753 +/*
3754 + * This is an interim value that we will use until the committee comes
3755 + * up with a final number.
3756 + */
3757 +#define EM_ALPHA       0x9026
3758 +
3759 +/* Bogus old v850 magic number, used by old tools. */
3760 +#define EM_CYGNUS_V850 0x9080
3761 +/* Bogus old m32r magic number, used by old tools. */
3762 +#define EM_CYGNUS_M32R 0x9041
3763 +/* This is the old interim value for S/390 architecture */
3764 +#define EM_S390_OLD    0xA390
3765 +/* Also Panasonic/MEI MN10300, AM33 */
3766 +#define EM_CYGNUS_MN10300 0xbeef
3767 +
3768 +
3769 +#endif /* _LINUX_ELF_EM_H */
3770 diff -urN -x .git dietlibc-0.33/include/linux/filter.h dietlibc/include/linux/filter.h
3771 --- dietlibc-0.33/include/linux/filter.h        1970-01-01 00:00:00.000000000 +0000
3772 +++ dietlibc/include/linux/filter.h     2015-01-01 12:14:43.471605562 +0000
3773 @@ -0,0 +1,137 @@
3774 +/*
3775 + * Linux Socket Filter Data Structures
3776 + */
3777 +
3778 +#ifndef _UAPI__LINUX_FILTER_H__
3779 +#define _UAPI__LINUX_FILTER_H__
3780 +
3781 +#include <inttypes.h>
3782 +
3783 +
3784 +/*
3785 + * Current version of the filter code architecture.
3786 + */
3787 +#define BPF_MAJOR_VERSION 1
3788 +#define BPF_MINOR_VERSION 1
3789 +
3790 +/*
3791 + *     Try and keep these values and structures similar to BSD, especially
3792 + *     the BPF code definitions which need to match so you can share filters
3793 + */
3794
3795 +struct sock_filter {   /* Filter block */
3796 +       uint16_t        code;   /* Actual filter code */
3797 +       uint8_t jt;     /* Jump true */
3798 +       uint8_t jf;     /* Jump false */
3799 +       uint32_t        k;      /* Generic multiuse field */
3800 +};
3801 +
3802 +struct sock_fprog {    /* Required for SO_ATTACH_FILTER. */
3803 +       unsigned short          len;    /* Number of filter blocks */
3804 +       struct sock_filter      *filter;
3805 +};
3806 +
3807 +/*
3808 + * Instruction classes
3809 + */
3810 +
3811 +#define BPF_CLASS(code) ((code) & 0x07)
3812 +#define         BPF_LD          0x00
3813 +#define         BPF_LDX         0x01
3814 +#define         BPF_ST          0x02
3815 +#define         BPF_STX         0x03
3816 +#define         BPF_ALU         0x04
3817 +#define         BPF_JMP         0x05
3818 +#define         BPF_RET         0x06
3819 +#define         BPF_MISC        0x07
3820 +
3821 +/* ld/ldx fields */
3822 +#define BPF_SIZE(code)  ((code) & 0x18)
3823 +#define         BPF_W           0x00
3824 +#define         BPF_H           0x08
3825 +#define         BPF_B           0x10
3826 +#define BPF_MODE(code)  ((code) & 0xe0)
3827 +#define         BPF_IMM         0x00
3828 +#define         BPF_ABS         0x20
3829 +#define         BPF_IND         0x40
3830 +#define         BPF_MEM         0x60
3831 +#define         BPF_LEN         0x80
3832 +#define         BPF_MSH         0xa0
3833 +
3834 +/* alu/jmp fields */
3835 +#define BPF_OP(code)    ((code) & 0xf0)
3836 +#define         BPF_ADD         0x00
3837 +#define         BPF_SUB         0x10
3838 +#define         BPF_MUL         0x20
3839 +#define         BPF_DIV         0x30
3840 +#define         BPF_OR          0x40
3841 +#define         BPF_AND         0x50
3842 +#define         BPF_LSH         0x60
3843 +#define         BPF_RSH         0x70
3844 +#define         BPF_NEG         0x80
3845 +#define                BPF_MOD         0x90
3846 +#define                BPF_XOR         0xa0
3847 +
3848 +#define         BPF_JA          0x00
3849 +#define         BPF_JEQ         0x10
3850 +#define         BPF_JGT         0x20
3851 +#define         BPF_JGE         0x30
3852 +#define         BPF_JSET        0x40
3853 +#define BPF_SRC(code)   ((code) & 0x08)
3854 +#define         BPF_K           0x00
3855 +#define         BPF_X           0x08
3856 +
3857 +/* ret - BPF_K and BPF_X also apply */
3858 +#define BPF_RVAL(code)  ((code) & 0x18)
3859 +#define         BPF_A           0x10
3860 +
3861 +/* misc */
3862 +#define BPF_MISCOP(code) ((code) & 0xf8)
3863 +#define         BPF_TAX         0x00
3864 +#define         BPF_TXA         0x80
3865 +
3866 +#ifndef BPF_MAXINSNS
3867 +#define BPF_MAXINSNS 4096
3868 +#endif
3869 +
3870 +/*
3871 + * Macros for filter block array initializers.
3872 + */
3873 +#ifndef BPF_STMT
3874 +#define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
3875 +#endif
3876 +#ifndef BPF_JUMP
3877 +#define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
3878 +#endif
3879 +
3880 +/*
3881 + * Number of scratch memory words for: BPF_ST and BPF_STX
3882 + */
3883 +#define BPF_MEMWORDS 16
3884 +
3885 +/* RATIONALE. Negative offsets are invalid in BPF.
3886 +   We use them to reference ancillary data.
3887 +   Unlike introduction new instructions, it does not break
3888 +   existing compilers/optimizers.
3889 + */
3890 +#define SKF_AD_OFF    (-0x1000)
3891 +#define SKF_AD_PROTOCOL 0
3892 +#define SKF_AD_PKTTYPE         4
3893 +#define SKF_AD_IFINDEX         8
3894 +#define SKF_AD_NLATTR  12
3895 +#define SKF_AD_NLATTR_NEST     16
3896 +#define SKF_AD_MARK    20
3897 +#define SKF_AD_QUEUE   24
3898 +#define SKF_AD_HATYPE  28
3899 +#define SKF_AD_RXHASH  32
3900 +#define SKF_AD_CPU     36
3901 +#define SKF_AD_ALU_XOR_X       40
3902 +#define SKF_AD_VLAN_TAG        44
3903 +#define SKF_AD_VLAN_TAG_PRESENT 48
3904 +#define SKF_AD_PAY_OFFSET      52
3905 +#define SKF_AD_MAX     56
3906 +#define SKF_NET_OFF   (-0x100000)
3907 +#define SKF_LL_OFF    (-0x200000)
3908 +
3909 +
3910 +#endif /* _UAPI__LINUX_FILTER_H__ */
3911 diff -urN -x .git dietlibc-0.33/include/linux/prctl.h dietlibc/include/linux/prctl.h
3912 --- dietlibc-0.33/include/linux/prctl.h 1970-01-01 00:00:00.000000000 +0000
3913 +++ dietlibc/include/linux/prctl.h      2015-01-01 12:14:43.474938895 +0000
3914 @@ -0,0 +1,152 @@
3915 +#ifndef _LINUX_PRCTL_H
3916 +#define _LINUX_PRCTL_H
3917 +
3918 +/* Values to pass as first argument to prctl() */
3919 +
3920 +#define PR_SET_PDEATHSIG  1  /* Second arg is a signal */
3921 +#define PR_GET_PDEATHSIG  2  /* Second arg is a ptr to return the signal */
3922 +
3923 +/* Get/set current->mm->dumpable */
3924 +#define PR_GET_DUMPABLE   3
3925 +#define PR_SET_DUMPABLE   4
3926 +
3927 +/* Get/set unaligned access control bits (if meaningful) */
3928 +#define PR_GET_UNALIGN   5
3929 +#define PR_SET_UNALIGN   6
3930 +# define PR_UNALIGN_NOPRINT    1       /* silently fix up unaligned user accesses */
3931 +# define PR_UNALIGN_SIGBUS     2       /* generate SIGBUS on unaligned user access */
3932 +
3933 +/* Get/set whether or not to drop capabilities on setuid() away from
3934 + * uid 0 (as per security/commoncap.c) */
3935 +#define PR_GET_KEEPCAPS   7
3936 +#define PR_SET_KEEPCAPS   8
3937 +
3938 +/* Get/set floating-point emulation control bits (if meaningful) */
3939 +#define PR_GET_FPEMU  9
3940 +#define PR_SET_FPEMU 10
3941 +# define PR_FPEMU_NOPRINT      1       /* silently emulate fp operations accesses */
3942 +# define PR_FPEMU_SIGFPE       2       /* don't emulate fp operations, send SIGFPE instead */
3943 +
3944 +/* Get/set floating-point exception mode (if meaningful) */
3945 +#define PR_GET_FPEXC   11
3946 +#define PR_SET_FPEXC   12
3947 +# define PR_FP_EXC_SW_ENABLE   0x80    /* Use FPEXC for FP exception enables */
3948 +# define PR_FP_EXC_DIV         0x010000        /* floating point divide by zero */
3949 +# define PR_FP_EXC_OVF         0x020000        /* floating point overflow */
3950 +# define PR_FP_EXC_UND         0x040000        /* floating point underflow */
3951 +# define PR_FP_EXC_RES         0x080000        /* floating point inexact result */
3952 +# define PR_FP_EXC_INV         0x100000        /* floating point invalid operation */
3953 +# define PR_FP_EXC_DISABLED    0       /* FP exceptions disabled */
3954 +# define PR_FP_EXC_NONRECOV    1       /* async non-recoverable exc. mode */
3955 +# define PR_FP_EXC_ASYNC       2       /* async recoverable exception mode */
3956 +# define PR_FP_EXC_PRECISE     3       /* precise exception mode */
3957 +
3958 +/* Get/set whether we use statistical process timing or accurate timestamp
3959 + * based process timing */
3960 +#define PR_GET_TIMING   13
3961 +#define PR_SET_TIMING   14
3962 +# define PR_TIMING_STATISTICAL  0       /* Normal, traditional,
3963 +                                                   statistical process timing */
3964 +# define PR_TIMING_TIMESTAMP    1       /* Accurate timestamp based
3965 +                                                   process timing */
3966 +
3967 +#define PR_SET_NAME    15              /* Set process name */
3968 +#define PR_GET_NAME    16              /* Get process name */
3969 +
3970 +/* Get/set process endian */
3971 +#define PR_GET_ENDIAN  19
3972 +#define PR_SET_ENDIAN  20
3973 +# define PR_ENDIAN_BIG         0
3974 +# define PR_ENDIAN_LITTLE      1       /* True little endian mode */
3975 +# define PR_ENDIAN_PPC_LITTLE  2       /* "PowerPC" pseudo little endian */
3976 +
3977 +/* Get/set process seccomp mode */
3978 +#define PR_GET_SECCOMP 21
3979 +#define PR_SET_SECCOMP 22
3980 +
3981 +/* Get/set the capability bounding set (as per security/commoncap.c) */
3982 +#define PR_CAPBSET_READ 23
3983 +#define PR_CAPBSET_DROP 24
3984 +
3985 +/* Get/set the process' ability to use the timestamp counter instruction */
3986 +#define PR_GET_TSC 25
3987 +#define PR_SET_TSC 26
3988 +# define PR_TSC_ENABLE         1       /* allow the use of the timestamp counter */
3989 +# define PR_TSC_SIGSEGV                2       /* throw a SIGSEGV instead of reading the TSC */
3990 +
3991 +/* Get/set securebits (as per security/commoncap.c) */
3992 +#define PR_GET_SECUREBITS 27
3993 +#define PR_SET_SECUREBITS 28
3994 +
3995 +/*
3996 + * Get/set the timerslack as used by poll/select/nanosleep
3997 + * A value of 0 means "use default"
3998 + */
3999 +#define PR_SET_TIMERSLACK 29
4000 +#define PR_GET_TIMERSLACK 30
4001 +
4002 +#define PR_TASK_PERF_EVENTS_DISABLE            31
4003 +#define PR_TASK_PERF_EVENTS_ENABLE             32
4004 +
4005 +/*
4006 + * Set early/late kill mode for hwpoison memory corruption.
4007 + * This influences when the process gets killed on a memory corruption.
4008 + */
4009 +#define PR_MCE_KILL    33
4010 +# define PR_MCE_KILL_CLEAR   0
4011 +# define PR_MCE_KILL_SET     1
4012 +
4013 +# define PR_MCE_KILL_LATE    0
4014 +# define PR_MCE_KILL_EARLY   1
4015 +# define PR_MCE_KILL_DEFAULT 2
4016 +
4017 +#define PR_MCE_KILL_GET 34
4018 +
4019 +/*
4020 + * Tune up process memory map specifics.
4021 + */
4022 +#define PR_SET_MM              35
4023 +# define PR_SET_MM_START_CODE          1
4024 +# define PR_SET_MM_END_CODE            2
4025 +# define PR_SET_MM_START_DATA          3
4026 +# define PR_SET_MM_END_DATA            4
4027 +# define PR_SET_MM_START_STACK         5
4028 +# define PR_SET_MM_START_BRK           6
4029 +# define PR_SET_MM_BRK                 7
4030 +# define PR_SET_MM_ARG_START           8
4031 +# define PR_SET_MM_ARG_END             9
4032 +# define PR_SET_MM_ENV_START           10
4033 +# define PR_SET_MM_ENV_END             11
4034 +# define PR_SET_MM_AUXV                        12
4035 +# define PR_SET_MM_EXE_FILE            13
4036 +
4037 +/*
4038 + * Set specific pid that is allowed to ptrace the current task.
4039 + * A value of 0 mean "no process".
4040 + */
4041 +#define PR_SET_PTRACER 0x59616d61
4042 +# define PR_SET_PTRACER_ANY ((unsigned long)-1)
4043 +
4044 +#define PR_SET_CHILD_SUBREAPER 36
4045 +#define PR_GET_CHILD_SUBREAPER 37
4046 +
4047 +/*
4048 + * If no_new_privs is set, then operations that grant new privileges (i.e.
4049 + * execve) will either fail or not grant them.  This affects suid/sgid,
4050 + * file capabilities, and LSMs.
4051 + *
4052 + * Operations that merely manipulate or drop existing privileges (setresuid,
4053 + * capset, etc.) will still work.  Drop those privileges if you want them gone.
4054 + *
4055 + * Changing LSM security domain is considered a new privilege.  So, for example,
4056 + * asking selinux for a specific new context (e.g. with runcon) will result
4057 + * in execve returning -EPERM.
4058 + *
4059 + * See Documentation/prctl/no_new_privs.txt for more details.
4060 + */
4061 +#define PR_SET_NO_NEW_PRIVS    38
4062 +#define PR_GET_NO_NEW_PRIVS    39
4063 +
4064 +#define PR_GET_TID_ADDRESS     40
4065 +
4066 +#endif /* _LINUX_PRCTL_H */
4067 diff -urN -x .git dietlibc-0.33/include/linux/random.h dietlibc/include/linux/random.h
4068 --- dietlibc-0.33/include/linux/random.h        1970-01-01 00:00:00.000000000 +0000
4069 +++ dietlibc/include/linux/random.h     2015-01-01 12:14:43.474938895 +0000
4070 @@ -0,0 +1,27 @@
4071 +/*
4072 + * include/linux/random.h
4073 + *
4074 + * Include file for the random number generator.
4075 + */
4076 +
4077 +#ifndef _LINUX_RANDOM_H
4078 +#define _LINUX_RANDOM_H
4079 +
4080 +#include <sys/cdefs.h>
4081 +
4082 +__BEGIN_DECLS
4083 +
4084 +#ifndef GRND_NONBLOCK
4085 +enum {
4086 +  GRND_NONBLOCK=1,
4087 +#define GRND_NONBLOCK GRND_NONBLOCK
4088 +  GRND_RANDOM=2
4089 +#define GRND_RANDOM GRND_RANDOM
4090 +};
4091 +
4092 +int getrandom(void* buf, size_t buflen, unsigned int flags) __THROW;
4093 +#endif
4094 +
4095 +__END_DECLS
4096 +
4097 +#endif /* _LINUX_RANDOM_H */
4098 diff -urN -x .git dietlibc-0.33/include/linux/seccomp.h dietlibc/include/linux/seccomp.h
4099 --- dietlibc-0.33/include/linux/seccomp.h       1970-01-01 00:00:00.000000000 +0000
4100 +++ dietlibc/include/linux/seccomp.h    2015-01-01 12:14:43.474938895 +0000
4101 @@ -0,0 +1,45 @@
4102 +#ifndef _UAPI_LINUX_SECCOMP_H
4103 +#define _UAPI_LINUX_SECCOMP_H
4104 +
4105 +#include <inttypes.h>
4106 +
4107 +/* Valid values for seccomp.mode and prctl(PR_SET_SECCOMP, <mode>) */
4108 +#define SECCOMP_MODE_DISABLED  0 /* seccomp is not in use. */
4109 +#define SECCOMP_MODE_STRICT    1 /* uses hard-coded filter. */
4110 +#define SECCOMP_MODE_FILTER    2 /* uses user-supplied filter. */
4111 +
4112 +/*
4113 + * All BPF programs must return a 32-bit value.
4114 + * The bottom 16-bits are for optional return data.
4115 + * The upper 16-bits are ordered from least permissive values to most.
4116 + *
4117 + * The ordering ensures that a min_t() over composed return values always
4118 + * selects the least permissive choice.
4119 + */
4120 +#define SECCOMP_RET_KILL       0x00000000U /* kill the task immediately */
4121 +#define SECCOMP_RET_TRAP       0x00030000U /* disallow and force a SIGSYS */
4122 +#define SECCOMP_RET_ERRNO      0x00050000U /* returns an errno */
4123 +#define SECCOMP_RET_TRACE      0x7ff00000U /* pass to a tracer or disallow */
4124 +#define SECCOMP_RET_ALLOW      0x7fff0000U /* allow */
4125 +
4126 +/* Masks for the return value sections. */
4127 +#define SECCOMP_RET_ACTION     0x7fff0000U
4128 +#define SECCOMP_RET_DATA       0x0000ffffU
4129 +
4130 +/**
4131 + * struct seccomp_data - the format the BPF program executes over.
4132 + * @nr: the system call number
4133 + * @arch: indicates system call convention as an AUDIT_ARCH_* value
4134 + *        as defined in <linux/audit.h>.
4135 + * @instruction_pointer: at the time of the system call.
4136 + * @args: up to 6 system call arguments always stored as 64-bit values
4137 + *        regardless of the architecture.
4138 + */
4139 +struct seccomp_data {
4140 +       int nr;
4141 +       uint32_t arch;
4142 +       uint64_t instruction_pointer;
4143 +       uint64_t args[6];
4144 +};
4145 +
4146 +#endif /* _UAPI_LINUX_SECCOMP_H */
4147 diff -urN -x .git dietlibc-0.33/include/linux/sysinfo.h dietlibc/include/linux/sysinfo.h
4148 --- dietlibc-0.33/include/linux/sysinfo.h       1970-01-01 00:00:00.000000000 +0000
4149 +++ dietlibc/include/linux/sysinfo.h    2015-01-01 12:14:43.474938895 +0000
4150 @@ -0,0 +1,24 @@
4151 +#ifndef _LINUX_SYSINFO_H
4152 +#define _LINUX_SYSINFO_H
4153 +
4154 +#include <linux/types.h>
4155 +
4156 +#define SI_LOAD_SHIFT  16
4157 +struct sysinfo {
4158 +       __kernel_long_t uptime;         /* Seconds since boot */
4159 +       __kernel_ulong_t loads[3];      /* 1, 5, and 15 minute load averages */
4160 +       __kernel_ulong_t totalram;      /* Total usable main memory size */
4161 +       __kernel_ulong_t freeram;       /* Available memory size */
4162 +       __kernel_ulong_t sharedram;     /* Amount of shared memory */
4163 +       __kernel_ulong_t bufferram;     /* Memory used by buffers */
4164 +       __kernel_ulong_t totalswap;     /* Total swap space size */
4165 +       __kernel_ulong_t freeswap;      /* swap space still available */
4166 +       __u16 procs;                    /* Number of current processes */
4167 +       __u16 pad;                      /* Explicit padding for m68k */
4168 +       __kernel_ulong_t totalhigh;     /* Total high memory size */
4169 +       __kernel_ulong_t freehigh;      /* Available high memory size */
4170 +       __u32 mem_unit;                 /* Memory unit size in bytes */
4171 +       char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)];   /* Padding: libc5 uses this.. */
4172 +};
4173 +
4174 +#endif /* _LINUX_SYSINFO_H */
4175 diff -urN -x .git dietlibc-0.33/include/linux/types.h dietlibc/include/linux/types.h
4176 --- dietlibc-0.33/include/linux/types.h 2001-07-30 13:34:41.000000000 +0000
4177 +++ dietlibc/include/linux/types.h      2015-01-01 12:14:43.474938895 +0000
4178 @@ -2,5 +2,6 @@
4179  #define _LINUX_TYPES_H
4180  
4181  #include <asm/types.h>
4182 +#include <asm/posix_types.h>
4183  
4184  #endif
4185 diff -urN -x .git dietlibc-0.33/include/netinet/tcp.h dietlibc/include/netinet/tcp.h
4186 --- dietlibc-0.33/include/netinet/tcp.h 2003-08-19 16:58:18.000000000 +0000
4187 +++ dietlibc/include/netinet/tcp.h      2015-01-01 12:14:43.474938895 +0000
4188 @@ -3,6 +3,7 @@
4189  
4190  #include <inttypes.h>
4191  #include <endian.h>
4192 +#include <sys/socket.h> /* for sockaddr_storage */
4193  
4194  __BEGIN_DECLS
4195  
4196 @@ -94,6 +95,12 @@
4197  #endif
4198  };
4199  
4200 +/*
4201 + * TCP general constants
4202 + */
4203 +#define TCP_MSS_DEFAULT                 536U   /* IPv4 (RFC1122, RFC2581) */
4204 +#define TCP_MSS_DESIRED                1220U   /* IPv6 (tunneled), EDNS0 (RFC3226) */
4205 +
4206  /* TCP socket options */
4207  #define TCP_NODELAY            1       /* Turn off Nagle's algorithm. */
4208  #define TCP_MAXSEG             2       /* Limit MSS */
4209 @@ -107,11 +114,25 @@
4210  #define TCP_WINDOW_CLAMP       10      /* Bound advertised window */
4211  #define TCP_INFO               11      /* Information about this connection. */
4212  #define TCP_QUICKACK           12      /* Block/reenable quick acks */
4213 +#define TCP_CONGESTION         13      /* Congestion control algorithm */
4214 +#define TCP_MD5SIG             14      /* TCP MD5 Signature (RFC2385) */
4215 +#define TCP_THIN_LINEAR_TIMEOUTS 16      /* Use linear timeouts for thin streams*/
4216 +#define TCP_THIN_DUPACK         17      /* Fast retrans. after 1 dupack */
4217 +#define TCP_USER_TIMEOUT       18      /* How long for loss retry before timeout */
4218 +#define TCP_REPAIR             19      /* TCP sock is under repair right now */
4219 +#define TCP_REPAIR_QUEUE       20
4220 +#define TCP_QUEUE_SEQ          21
4221 +#define TCP_REPAIR_OPTIONS     22
4222 +#define TCP_FASTOPEN           23      /* Enable FastOpen on listeners */
4223 +#define TCP_TIMESTAMP          24
4224 +#define TCP_NOTSENT_LOWAT      25      /* limit number of unsent bytes in write queue */
4225  
4226  #define TCPI_OPT_TIMESTAMPS    1
4227  #define TCPI_OPT_SACK          2
4228  #define TCPI_OPT_WSCALE                4
4229  #define TCPI_OPT_ECN           8
4230 +#define TCPI_OPT_ECN_SEEN      16 /* we received at least one packet with ECT */
4231 +#define TCPI_OPT_SYN_DATA      32 /* SYN-ACK acked data in SYN sent or rcvd */
4232  
4233  enum tcp_ca_state {
4234    TCP_CA_Open = 0,
4235 @@ -161,6 +182,24 @@
4236    uint32_t tcpi_snd_cwnd;
4237    uint32_t tcpi_advmss;
4238    uint32_t tcpi_reordering;
4239 +  uint32_t tcpi_rcv_rtt;
4240 +  uint32_t tcpi_rcv_space;
4241 +
4242 +  uint32_t tcpi_total_retrans;
4243 +
4244 +  uint64_t tcpi_pacing_rate;
4245 +  uint64_t tcpi_max_pacing_rate;
4246 +};
4247 +
4248 +/* for TCP_MD5SIG socket option */
4249 +#define TCP_MD5SIG_MAXKEYLEN   80
4250 +
4251 +struct tcp_md5sig {
4252 +  struct sockaddr_storage tcpm_addr;   /* address associated */
4253 +  uint16_t __tcpm_pad1;                                /* zero */
4254 +  uint16_t tcpm_keylen;                                /* key length */
4255 +  uint32_t __tcpm_pad2;                                /* zero */
4256 +  uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];      /* key (binary) */
4257  };
4258  
4259  __END_DECLS
4260 diff -urN -x .git dietlibc-0.33/include/netpacket/packet.h dietlibc/include/netpacket/packet.h
4261 --- dietlibc-0.33/include/netpacket/packet.h    2003-08-19 16:58:18.000000000 +0000
4262 +++ dietlibc/include/netpacket/packet.h 2015-01-01 12:14:43.474938895 +0000
4263 @@ -5,6 +5,13 @@
4264  
4265  __BEGIN_DECLS
4266  
4267 +struct sockaddr_pkt {
4268 +  unsigned short int spkt_family;
4269 +  unsigned char spkt_device[14];
4270 +  unsigned short int spkt_protocol;
4271 +};
4272 +
4273 +
4274  struct sockaddr_ll {
4275    unsigned short int sll_family;
4276    unsigned short int sll_protocol;
4277 @@ -21,6 +28,9 @@
4278  #define PACKET_OTHERHOST       3               /* To someone else.  */
4279  #define PACKET_OUTGOING                4               /* Originated by us. */
4280  #define PACKET_LOOPBACK                5
4281 +#define PACKET_USER            6               /* To user space        */
4282 +#define PACKET_KERNEL          7               /* To kernel space      */
4283 +/* Unused, PACKET_FASTROUTE and PACKET_LOOPBACK are invisible to user space */
4284  #define PACKET_FASTROUTE       6
4285  
4286  /* Packet socket options.  */
4287 @@ -30,6 +40,240 @@
4288  #define PACKET_RECV_OUTPUT             3
4289  #define PACKET_RX_RING                 5
4290  #define PACKET_STATISTICS              6
4291 +#define PACKET_COPY_THRESH             7
4292 +#define PACKET_AUXDATA                 8
4293 +#define PACKET_ORIGDEV                 9
4294 +#define PACKET_VERSION                 10
4295 +#define PACKET_HDRLEN                  11
4296 +#define PACKET_RESERVE                 12
4297 +#define PACKET_TX_RING                 13
4298 +#define PACKET_LOSS                    14
4299 +#define PACKET_VNET_HDR                        15
4300 +#define PACKET_TX_TIMESTAMP            16
4301 +#define PACKET_TIMESTAMP               17
4302 +#define PACKET_FANOUT                  18
4303 +#define PACKET_TX_HAS_OFF              19
4304 +#define PACKET_QDISC_BYPASS            20
4305 +
4306 +#define PACKET_FANOUT_HASH             0
4307 +#define PACKET_FANOUT_LB               1
4308 +#define PACKET_FANOUT_CPU              2
4309 +#define PACKET_FANOUT_ROLLOVER         3
4310 +#define PACKET_FANOUT_RND              4
4311 +#define PACKET_FANOUT_QM               5
4312 +#define PACKET_FANOUT_FLAG_ROLLOVER    0x1000
4313 +#define PACKET_FANOUT_FLAG_DEFRAG      0x8000
4314 +
4315 +struct tpacket_stats {
4316 +  unsigned int tp_packets;
4317 +  unsigned int tp_drops;
4318 +};
4319 +
4320 +struct tpacket_stats_v3 {
4321 +  unsigned int tp_packets;
4322 +  unsigned int tp_drops;
4323 +  unsigned int tp_freeze_q_cnt;
4324 +};
4325 +
4326 +union tpacket_stats_u {
4327 +  struct tpacket_stats stats1;
4328 +  struct tpacket_stats_v3 stats3;
4329 +};
4330 +
4331 +struct tpacket_auxdata {
4332 +  uint32_t tp_status;
4333 +  uint32_t tp_len;
4334 +  uint32_t tp_snaplen;
4335 +  uint16_t tp_mac;
4336 +  uint16_t tp_net;
4337 +  uint16_t tp_vlan_tci;
4338 +  uint16_t tp_vlan_tpid;
4339 +};
4340 +
4341 +/* Rx ring - header status */
4342 +#define TP_STATUS_KERNEL                     0
4343 +#define TP_STATUS_USER                 (1 << 0)
4344 +#define TP_STATUS_COPY                 (1 << 1)
4345 +#define TP_STATUS_LOSING               (1 << 2)
4346 +#define TP_STATUS_CSUMNOTREADY         (1 << 3)
4347 +#define TP_STATUS_VLAN_VALID           (1 << 4) /* auxdata has valid tp_vlan_tci */
4348 +#define TP_STATUS_BLK_TMO              (1 << 5)
4349 +#define TP_STATUS_VLAN_TPID_VALID      (1 << 6) /* auxdata has valid tp_vlan_tpid */
4350 +
4351 +/* Tx ring - header status */
4352 +#define TP_STATUS_AVAILABLE          0
4353 +#define TP_STATUS_SEND_REQUEST (1 << 0)
4354 +#define TP_STATUS_SENDING      (1 << 1)
4355 +#define TP_STATUS_WRONG_FORMAT (1 << 2)
4356 +
4357 +/* Rx and Tx ring - header status */
4358 +#define TP_STATUS_TS_SOFTWARE          (1 << 29)
4359 +#define TP_STATUS_TS_SYS_HARDWARE      (1 << 30)
4360 +#define TP_STATUS_TS_RAW_HARDWARE      (1 << 31)
4361 +
4362 +/* Rx ring - feature request bits */
4363 +#define TP_FT_REQ_FILL_RXHASH  0x1
4364 +
4365 +struct tpacket_hdr {
4366 +  unsigned long tp_status;
4367 +  unsigned int tp_len;
4368 +  unsigned int tp_snaplen;
4369 +  unsigned short tp_mac;
4370 +  unsigned short tp_net;
4371 +  unsigned int tp_sec;
4372 +  unsigned int tp_usec;
4373 +};
4374 +
4375 +#define TPACKET_ALIGNMENT      16
4376 +#define TPACKET_ALIGN(x)       (((x)+TPACKET_ALIGNMENT-1)&~(TPACKET_ALIGNMENT-1))
4377 +#define TPACKET_HDRLEN         (TPACKET_ALIGN(sizeof(struct tpacket_hdr)) + sizeof(struct sockaddr_ll))
4378 +
4379 +struct tpacket2_hdr {
4380 +  uint32_t tp_status;
4381 +  uint32_t tp_len;
4382 +  uint32_t tp_snaplen;
4383 +  uint16_t tp_mac;
4384 +  uint16_t tp_net;
4385 +  uint32_t tp_sec;
4386 +  uint32_t tp_nsec;
4387 +  uint16_t tp_vlan_tci;
4388 +  uint16_t tp_vlan_tpid;
4389 +  uint8_t tp_padding[4];
4390 +};
4391 +
4392 +struct tpacket_hdr_variant1 {
4393 +  uint32_t tp_rxhash;
4394 +  uint32_t tp_vlan_tci;
4395 +  uint16_t tp_vlan_tpid;
4396 +  uint16_t tp_padding;
4397 +};
4398 +
4399 +struct tpacket3_hdr {
4400 +  uint32_t tp_next_offset;
4401 +  uint32_t tp_sec;
4402 +  uint32_t tp_nsec;
4403 +  uint32_t tp_snaplen;
4404 +  uint32_t tp_len;
4405 +  uint32_t tp_status;
4406 +  uint16_t tp_mac;
4407 +  uint16_t tp_net;
4408 +  /* pkt_hdr variants */
4409 +  union {
4410 +    struct tpacket_hdr_variant1 hv1;
4411 +  };
4412 +  uint8_t tp_padding[8];
4413 +};
4414 +
4415 +struct tpacket_bd_ts {
4416 +  unsigned int ts_sec;
4417 +  union {
4418 +    unsigned int ts_usec;
4419 +    unsigned int ts_nsec;
4420 +  };
4421 +};
4422 +
4423 +struct tpacket_hdr_v1 {
4424 +  uint32_t block_status;
4425 +  uint32_t num_pkts;
4426 +  uint32_t offset_to_first_pkt;
4427 +
4428 +  /* Number of valid bytes (including padding)
4429 +    * blk_len <= tp_block_size
4430 +    */
4431 +  uint32_t blk_len;
4432 +
4433 +  /*
4434 +    * Quite a few uses of sequence number:
4435 +    * 1. Make sure cache flush etc worked.
4436 +    *    Well, one can argue - why not use the increasing ts below?
4437 +    *    But look at 2. below first.
4438 +    * 2. When you pass around blocks to other user space decoders,
4439 +    *    you can see which blk[s] is[are] outstanding etc.
4440 +    * 3. Validate kernel code.
4441 +    */
4442 +  uint64_t seq_num;
4443 +
4444 +  /*
4445 +    * ts_last_pkt:
4446 +    *
4447 +    * Case 1.  Block has 'N'(N >=1) packets and TMO'd(timed out)
4448 +    *          ts_last_pkt == 'time-stamp of last packet' and NOT the
4449 +    *          time when the timer fired and the block was closed.
4450 +    *          By providing the ts of the last packet we can absolutely
4451 +    *          guarantee that time-stamp wise, the first packet in the
4452 +    *          next block will never precede the last packet of the
4453 +    *          previous block.
4454 +    * Case 2.  Block has zero packets and TMO'd
4455 +    *          ts_last_pkt = time when the timer fired and the block
4456 +    *          was closed.
4457 +    * Case 3.  Block has 'N' packets and NO TMO.
4458 +    *          ts_last_pkt = time-stamp of the last pkt in the block.
4459 +    *
4460 +    * ts_first_pkt:
4461 +    *          Is always the time-stamp when the block was opened.
4462 +    *          Case a) ZERO packets
4463 +    *                  No packets to deal with but atleast you know the
4464 +    *                  time-interval of this block.
4465 +    *          Case b) Non-zero packets
4466 +    *                  Use the ts of the first packet in the block.
4467 +    *
4468 +    */
4469 +  struct tpacket_bd_ts ts_first_pkt, ts_last_pkt;
4470 +};
4471 +
4472 +union tpacket_bd_header_u {
4473 +  struct tpacket_hdr_v1 bh1;
4474 +};
4475 +
4476 +struct tpacket_block_desc {
4477 +  uint32_t version;
4478 +  uint32_t offset_to_priv;
4479 +  union tpacket_bd_header_u hdr;
4480 +};
4481 +
4482 +#define TPACKET2_HDRLEN                (TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll))
4483 +#define TPACKET3_HDRLEN                (TPACKET_ALIGN(sizeof(struct tpacket3_hdr)) + sizeof(struct sockaddr_ll))
4484 +
4485 +enum tpacket_versions {
4486 +  TPACKET_V1,
4487 +  TPACKET_V2,
4488 +  TPACKET_V3
4489 +};
4490 +
4491 +/*
4492 +   Frame structure:
4493 +
4494 +   - Start. Frame must be aligned to TPACKET_ALIGNMENT=16
4495 +   - struct tpacket_hdr
4496 +   - pad to TPACKET_ALIGNMENT=16
4497 +   - struct sockaddr_ll
4498 +   - Gap, chosen so that packet data (Start+tp_net) alignes to TPACKET_ALIGNMENT=16
4499 +   - Start+tp_mac: [ Optional MAC header ]
4500 +   - Start+tp_net: Packet data, aligned to TPACKET_ALIGNMENT=16.
4501 +   - Pad to align to TPACKET_ALIGNMENT=16
4502 + */
4503 +
4504 +struct tpacket_req {
4505 +  unsigned int tp_block_size;  /* Minimal size of contiguous block */
4506 +  unsigned int tp_block_nr;    /* Number of blocks */
4507 +  unsigned int tp_frame_size;  /* Size of frame */
4508 +  unsigned int tp_frame_nr;    /* Total number of frames */
4509 +};
4510 +
4511 +struct tpacket_req3 {
4512 +  unsigned int tp_block_size;  /* Minimal size of contiguous block */
4513 +  unsigned int tp_block_nr;    /* Number of blocks */
4514 +  unsigned int tp_frame_size;  /* Size of frame */
4515 +  unsigned int tp_frame_nr;    /* Total number of frames */
4516 +  unsigned int tp_retire_blk_tov; /* timeout in msecs */
4517 +  unsigned int tp_sizeof_priv; /* offset to private data area */
4518 +  unsigned int tp_feature_req_word;
4519 +};
4520 +
4521 +union tpacket_req_u {
4522 +  struct tpacket_req req;
4523 +  struct tpacket_req3 req3;
4524 +};
4525  
4526  struct packet_mreq {
4527    int mr_ifindex;
4528 @@ -41,6 +285,7 @@
4529  #define PACKET_MR_MULTICAST    0
4530  #define PACKET_MR_PROMISC      1
4531  #define PACKET_MR_ALLMULTI     2
4532 +#define PACKET_MR_UNICAST      3
4533  
4534  __END_DECLS
4535  
4536 diff -urN -x .git dietlibc-0.33/include/paths.h dietlibc/include/paths.h
4537 --- dietlibc-0.33/include/paths.h       2008-05-06 17:18:34.000000000 +0000
4538 +++ dietlibc/include/paths.h    2015-01-01 12:14:43.474938895 +0000
4539 @@ -2,7 +2,7 @@
4540  #define _PATHS_H
4541  
4542  #define _PATH_BSHELL "/bin/sh"
4543 -#define _PATH_DEFPATH "/bin:/usr/bin:"
4544 +#define _PATH_DEFPATH "/bin:/usr/bin"
4545  
4546  #define _PATH_DEVNULL "/dev/null"
4547  
4548 diff -urN -x .git dietlibc-0.33/include/sched.h dietlibc/include/sched.h
4549 --- dietlibc-0.33/include/sched.h       2012-01-24 18:24:25.000000000 +0000
4550 +++ dietlibc/include/sched.h    2015-01-01 12:14:43.478272229 +0000
4551 @@ -25,29 +25,29 @@
4552  
4553  /* END OF COPY form kernel-header */
4554  
4555 -int __sched_setparam(pid_t pid, const struct sched_param* p);
4556 -int sched_setparam(pid_t pid, const struct sched_param* p);
4557 +int __sched_setparam(pid_t pid, const struct sched_param* p) __THROW;
4558 +int sched_setparam(pid_t pid, const struct sched_param* p) __THROW;
4559  
4560 -int __sched_getparam(pid_t pid, struct sched_param* p);
4561 -int sched_getparam(pid_t pid, struct sched_param* p);
4562 +int __sched_getparam(pid_t pid, struct sched_param* p) __THROW;
4563 +int sched_getparam(pid_t pid, struct sched_param* p) __THROW;
4564  
4565 -int __sched_getscheduler(pid_t pid);
4566 -int sched_getscheduler(pid_t pid);
4567 +int __sched_getscheduler(pid_t pid) __THROW;
4568 +int sched_getscheduler(pid_t pid) __THROW;
4569  
4570 -int __sched_setscheduler(pid_t pid, int policy, const struct sched_param* p);
4571 -int sched_setscheduler(pid_t pid, int policy, const struct sched_param* p);
4572 +int __sched_setscheduler(pid_t pid, int policy, const struct sched_param* p) __THROW;
4573 +int sched_setscheduler(pid_t pid, int policy, const struct sched_param* p) __THROW;
4574  
4575 -int __sched_yield(void);
4576 -int sched_yield(void);
4577 +int __sched_yield(void) __THROW;
4578 +int sched_yield(void) __THROW;
4579  
4580 -int __sched_get_priority_max(int policy);
4581 -int sched_get_priority_max(int policy);
4582 +int __sched_get_priority_max(int policy) __THROW;
4583 +int sched_get_priority_max(int policy) __THROW;
4584  
4585 -int __sched_get_priority_min(int policy);
4586 -int sched_get_priority_min(int policy);
4587 +int __sched_get_priority_min(int policy) __THROW;
4588 +int sched_get_priority_min(int policy) __THROW;
4589  
4590 -int __sched_rr_get_interval(pid_t pid, struct timespec* tp);
4591 -int sched_rr_get_interval(pid_t pid, struct timespec* tp);
4592 +int __sched_rr_get_interval(pid_t pid, struct timespec* tp) __THROW;
4593 +int sched_rr_get_interval(pid_t pid, struct timespec* tp) __THROW;
4594  
4595  #ifdef _GNU_SOURCE
4596  /*
4597 @@ -63,12 +63,28 @@
4598  #define CLONE_VFORK     0x00004000      /* set if the parent wants the child to wake it up on mm_release */
4599  #define CLONE_PARENT    0x00008000      /* set if we want to have the same parent as the cloner */
4600  #define CLONE_THREAD    0x00010000      /* Same thread group? */
4601 +#define CLONE_NEWNS     0x00020000
4602 +#define CLONE_SYSVSEM   0x00040000
4603 +#define CLONE_SETTLS    0x00080000
4604 +#define CLONE_PARENT_SETTID 0x00100000
4605 +#define CLONE_CHILD_CLEARTID 0x00200000
4606 +#define CLONE_DETACHED  0x00400000
4607 +#define CLONE_UNTRACED  0x00800000
4608 +#define CLONE_CHILD_SETTID 0x01000000
4609 +#define CLONE_NEWUTS    0x04000000
4610 +#define CLONE_NEWIPC    0x08000000
4611 +#define CLONE_NEWUSER   0x10000000
4612 +#define CLONE_NEWPID    0x20000000
4613 +#define CLONE_NEWNET    0x40000000
4614 +#define CLONE_IO        0x80000000
4615  
4616  #define CLONE_SIGNAL    (CLONE_SIGHAND | CLONE_THREAD)
4617  
4618 -int clone(int *(*fn)(void*),void* stack,int flags,void* arg, ...);
4619 +int clone(int (*fn)(void*),void* stack,int flags,void* arg, ...) __THROW;
4620  
4621 -int unshare(int flags);
4622 +int unshare(int flags) __THROW;
4623 +
4624 +long set_tid_address(int* tid) __THROW;
4625  
4626  /*
4627   * Linux CPU affinity.
4628 @@ -112,11 +128,13 @@
4629         return *s1 == *s2;
4630  }
4631  
4632 -int sched_setaffinity(pid_t pid, size_t size, cpu_set_t *mask);
4633 -int sched_getaffinity(pid_t pid, size_t size, cpu_set_t *mask);
4634 +int sched_setaffinity(pid_t pid, size_t size, cpu_set_t *mask) __THROW;
4635 +int sched_getaffinity(pid_t pid, size_t size, cpu_set_t *mask) __THROW;
4636  #define pthread_setaffinity_np sched_setaffinity
4637  #define pthread_getaffinity_np sched_getaffinity
4638  
4639 +int setns(int fd,int nstype) __THROW;
4640 +
4641  #endif
4642  
4643  __END_DECLS
4644 diff -urN -x .git dietlibc-0.33/include/search.h dietlibc/include/search.h
4645 --- dietlibc-0.33/include/search.h      1970-01-01 00:00:00.000000000 +0000
4646 +++ dietlibc/include/search.h   2015-01-01 12:14:43.478272229 +0000
4647 @@ -0,0 +1,40 @@
4648 +#ifndef SEARCH_H
4649 +#define SEARCH_H
4650 +
4651 +#include <sys/cdefs.h>
4652 +#include <stddef.h>
4653 +#include <stdint.h>
4654 +
4655 +typedef enum { FIND, ENTER } ACTION;
4656 +typedef struct entry { char* key; void* data; } ENTRY;
4657 +
4658 +extern ENTRY* hsearch(ENTRY item, ACTION action) __THROW;
4659 +extern int hcreate(size_t count) __THROW;
4660 +extern void hdestroy(void) __THROW;
4661 +
4662 +#ifdef _GNU_SOURCE
4663 +/* This is the internal structure of the hash table buckets.
4664 + * Do not use it or your program will be dietlibc-only!
4665 + * It's here so it's possible to write traversal code. */
4666 +struct bucket {
4667 +  struct bucket* next;
4668 +  struct entry e;
4669 +  size_t hv;
4670 +};
4671 +#else
4672 +struct bucket;
4673 +#endif
4674 +
4675 +struct hsearch_data {
4676 +  struct bucket** table;
4677 +  size_t size, filled;
4678 +  unsigned char key[16];
4679 +};
4680 +
4681 +extern int hsearch_r(ENTRY item, ACTION action, ENTRY** retval, struct hsearch_data* htab) __THROW;
4682 +extern int hcreate_r(size_t count, struct hsearch_data* htab) __THROW;
4683 +extern void hdestroy_r(struct hsearch_data* htab) __THROW;
4684 +
4685 +extern uint64_t siphash24(const unsigned char key[16], const unsigned char *in, size_t len) __THROW;
4686 +
4687 +#endif
4688 diff -urN -x .git dietlibc-0.33/include/setjmp.h dietlibc/include/setjmp.h
4689 --- dietlibc-0.33/include/setjmp.h      2005-09-28 06:18:43.000000000 +0000
4690 +++ dietlibc/include/setjmp.h   2015-01-01 12:14:43.478272229 +0000
4691 @@ -166,7 +166,7 @@
4692  #ifdef __arm__
4693  #define __JMP_BUF_SP            8
4694  #ifndef __ASSEMBLER__
4695 -typedef int __jmp_buf[24];
4696 +typedef int __jmp_buf[10 + 16*2 + 16*2];
4697  #endif
4698  #endif
4699  
4700 @@ -222,12 +222,12 @@
4701  extern int __sigsetjmp(jmp_buf __env,int __savemask) __THROW;
4702  
4703  extern void longjmp(jmp_buf __env,int __val)
4704 -     __THROW __attribute__((__noreturn__));
4705 +     __THROWNL __attribute__((__noreturn__));
4706  
4707  typedef jmp_buf sigjmp_buf;
4708  
4709  extern void siglongjmp(sigjmp_buf __env,int __val)
4710 -     __THROW __attribute__((__noreturn__));
4711 +     __THROWNL __attribute__((__noreturn__));
4712  
4713  #ifdef _BSD_SOURCE
4714  #define setjmp(env) __sigsetjmp(env,1)
4715 diff -urN -x .git dietlibc-0.33/include/signal.h dietlibc/include/signal.h
4716 --- dietlibc-0.33/include/signal.h      2005-09-28 06:18:43.000000000 +0000
4717 +++ dietlibc/include/signal.h   2015-01-01 12:14:43.478272229 +0000
4718 @@ -431,10 +431,10 @@
4719  # define POLL_HUP      POLL_HUP
4720  };
4721  
4722 -#define _NSIG_WORDS    ((_NSIG/sizeof(long))>>3)
4723 +#define _SIGSET_WORDS  (1024 / (8 * sizeof (unsigned long int)))
4724  
4725  typedef struct {
4726 -  unsigned long sig[_NSIG_WORDS];
4727 +  unsigned long sig[_SIGSET_WORDS];
4728  } sigset_t;
4729  
4730  struct sigaction {
4731 diff -urN -x .git dietlibc-0.33/include/stdlib.h dietlibc/include/stdlib.h
4732 --- dietlibc-0.33/include/stdlib.h      2012-01-24 18:24:25.000000000 +0000
4733 +++ dietlibc/include/stdlib.h   2015-01-01 12:14:43.478272229 +0000
4734 @@ -14,6 +14,9 @@
4735  void free(void *ptr) __THROW;
4736  void *realloc(void *ptr, size_t size) __THROW __attribute_malloc__;
4737  
4738 +/* useful OpenBSD extension: */
4739 +void* reallocarray(void* ptr, size_t nmemb, size_t size) __THROW __attribute_malloc__;
4740 +
4741  char *getenv(const char *name) __THROW __pure;
4742  int putenv(const char *string) __THROW;
4743  int setenv(const char *name, const char *value, int overwrite) __THROW;
4744 @@ -28,8 +31,12 @@
4745  long int strtol(const char *nptr, char **endptr, int base) __THROW;
4746  unsigned long int strtoul(const char *nptr, char **endptr, int base) __THROW;
4747  
4748 +/* HACK: used flags in __dtostr
4749 +     0x01 ... 'g'
4750 +     0x02 ... uppercase
4751 +   Define some constants somewhere... */
4752  extern int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase) __THROW;
4753 -extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int g) __THROW;
4754 +extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int flags) __THROW;
4755  
4756  #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L
4757  __extension__ long long int strtoll(const char *nptr, char **endptr, int base) __THROW;
4758 @@ -43,7 +50,7 @@
4759  __extension__ long long int atoll(const char *nptr);
4760  
4761  void exit(int status) __THROW __attribute__((__noreturn__));
4762 -void abort(void) __THROW;
4763 +void abort(void) __THROW __attribute__((__noreturn__));
4764  
4765  extern int rand(void) __THROW;
4766  extern int rand_r(unsigned int *seed) __THROW;
4767 diff -urN -x .git dietlibc-0.33/include/sys/atomic.h dietlibc/include/sys/atomic.h
4768 --- dietlibc-0.33/include/sys/atomic.h  2012-04-19 16:50:20.000000000 +0000
4769 +++ dietlibc/include/sys/atomic.h       2015-01-01 12:14:43.478272229 +0000
4770 @@ -15,11 +15,9 @@
4771  
4772  #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
4773  
4774 -#define CAS(ptr,oldval,newval) __kernel_cmpxchg(oldval,newval,ptr)
4775 +#define __CAS(ptr,oldval,newval) __kernel_cmpxchg(oldval,newval,ptr)
4776  
4777 -#else
4778 -
4779 -#if defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1))
4780 +#elif defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1))
4781  
4782  /* recent gcc versions and the intel compiler have built-ins for this */
4783  #define __CAS(ptr,oldval,newval) __sync_val_compare_and_swap(ptr,oldval,newval)
4784 @@ -45,8 +43,6 @@
4785  #endif
4786  
4787  #endif
4788 -
4789 -#endif
4790  
4791  #if defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1))
4792  
4793 diff -urN -x .git dietlibc-0.33/include/sys/auxv.h dietlibc/include/sys/auxv.h
4794 --- dietlibc-0.33/include/sys/auxv.h    1970-01-01 00:00:00.000000000 +0000
4795 +++ dietlibc/include/sys/auxv.h 2015-01-01 12:14:43.478272229 +0000
4796 @@ -0,0 +1,40 @@
4797 +#ifndef SYS_AUXV
4798 +#define SYS_AUXV
4799 +
4800 +#include <sys/cdefs.h>
4801 +
4802 +unsigned long getauxval(unsigned long type);
4803 +
4804 +#ifndef AT_BASE
4805 +/* don't fail if they already included elf.h */
4806 +enum {
4807 +  AT_BASE=7,
4808 +  AT_BASE_PLATFORM=24,
4809 +  AT_CLKTCK=17,
4810 +  AT_DCACHEBSIZE=19,
4811 +  AT_EGID=14,
4812 +  AT_ENTRY=9,
4813 +  AT_EUID=12,
4814 +  AT_EXECFD=2,
4815 +  AT_EXECFN=31,
4816 +  AT_FLAGS=8,
4817 +  AT_FPUCW=18,
4818 +  AT_GID=13,
4819 +  AT_HWCAP=16,
4820 +  AT_HWCAP2=26,
4821 +  AT_ICACHEBSIZE=20,
4822 +  AT_PAGESZ=6,
4823 +  AT_PHDR=3,
4824 +  AT_PHENT=4,
4825 +  AT_PHNUM=5,
4826 +  AT_PLATFORM=15,
4827 +  AT_RANDOM=25,
4828 +  AT_SECURE=23,
4829 +  AT_SYSINFO=32,
4830 +  AT_SYSINFO_EHDR=33,
4831 +  AT_UCACHEBSIZE=21,
4832 +  AT_UID=11
4833 +};
4834 +#endif
4835 +
4836 +#endif
4837 diff -urN -x .git dietlibc-0.33/include/sys/cdefs.h dietlibc/include/sys/cdefs.h
4838 --- dietlibc-0.33/include/sys/cdefs.h   2009-07-01 00:27:26.000000000 +0000
4839 +++ dietlibc/include/sys/cdefs.h        2015-01-01 12:14:43.478272229 +0000
4840 @@ -16,6 +16,22 @@
4841  #define __extension__
4842  #endif
4843  
4844 +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
4845 +#define __leaf , __leaf__
4846 +#else
4847 +#define __leaf
4848 +#endif
4849 +
4850 +#if !defined(__cplusplus) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
4851 +#undef __THROW
4852 +#define __THROW __attribute__((__nothrow__ __leaf))
4853 +#define __THROWNL __attribute__((__nothrow__))
4854 +#endif
4855 +
4856 +#ifndef __THROWNL
4857 +#define __THROWNL __THROW
4858 +#endif
4859 +
4860  #if (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96))
4861  #define __pure __attribute__ ((__pure__))
4862  #else
4863 diff -urN -x .git dietlibc-0.33/include/sys/epoll.h dietlibc/include/sys/epoll.h
4864 --- dietlibc-0.33/include/sys/epoll.h   2012-11-02 11:17:28.000000000 +0000
4865 +++ dietlibc/include/sys/epoll.h        2015-01-01 12:14:43.478272229 +0000
4866 @@ -5,12 +5,10 @@
4867  #include <sys/types.h>
4868  #include <poll.h>
4869  #include <signal.h>
4870 +#include <fcntl.h>
4871  
4872  __BEGIN_DECLS
4873  
4874 -/* Flags for epoll_create1.  */
4875 -#define EPOLL_CLOEXEC O_CLOEXEC
4876 -
4877  /* Valid opcodes ( "op" parameter ) to issue to epoll_ctl() */
4878  #define EPOLL_CTL_ADD 1        /* Add a file decriptor to the interface */
4879  #define EPOLL_CTL_DEL 2        /* Remove a file decriptor from the interface */
4880 @@ -52,6 +50,13 @@
4881  #define EPOLLET EPOLLET
4882  };
4883  
4884 +/* flags for epoll_create1 */
4885 +enum {
4886 +  EPOLL_CLOEXEC = O_CLOEXEC
4887 +#define EPOLL_CLOEXEC EPOLL_CLOEXEC
4888 +};
4889 +
4890 +
4891  typedef union epoll_data {
4892    void *ptr;
4893    int fd;
4894 @@ -69,6 +74,7 @@
4895  ;
4896  
4897  int epoll_create(int size) __THROW;
4898 +int epoll_create1(int flags) __THROW;
4899  int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) __THROW;
4900  int epoll_wait(int epfd, struct epoll_event *events, int maxevents,
4901                int timeout) __THROW;
4902 diff -urN -x .git dietlibc-0.33/include/sys/eventfd.h dietlibc/include/sys/eventfd.h
4903 --- dietlibc-0.33/include/sys/eventfd.h 1970-01-01 00:00:00.000000000 +0000
4904 +++ dietlibc/include/sys/eventfd.h      2015-01-01 12:14:43.478272229 +0000
4905 @@ -0,0 +1,25 @@
4906 +#ifndef _SYS_EVENTFD_H
4907 +#define _SYS_EVENTFD_H
4908 +
4909 +#include <sys/cdefs.h>
4910 +#include <sys/types.h>
4911 +#include <fcntl.h>
4912 +
4913 +__BEGIN_DECLS
4914 +
4915 +enum {
4916 +  EFD_CLOEXEC = O_CLOEXEC,
4917 +#define EFD_CLOEXEC EFD_CLOEXEC
4918 +  EFD_NONBLOCK = O_NONBLOCK,
4919 +#define EFD_NONBLOCK EFD_NONBLOCK
4920 +  EFD_SEMAPHORE = 1
4921 +#define EFD_SEMAPHORE EFD_SEMAPHORE
4922 +};
4923 +
4924 +typedef uint64_t eventfd_t;
4925 +
4926 +int eventfd(unsigned int initval, int flags) __THROW;
4927 +
4928 +__END_DECLS
4929 +
4930 +#endif
4931 diff -urN -x .git dietlibc-0.33/include/sys/fanotify.h dietlibc/include/sys/fanotify.h
4932 --- dietlibc-0.33/include/sys/fanotify.h        1970-01-01 00:00:00.000000000 +0000
4933 +++ dietlibc/include/sys/fanotify.h     2015-01-01 12:14:43.478272229 +0000
4934 @@ -0,0 +1,24 @@
4935 +#ifndef SYS_FANOITFY_H
4936 +#define SYS_FANOITFY_H
4937 +
4938 +#include <sys/cdefs.h>
4939 +#include <stdint.h>
4940 +#include <sys/types.h>
4941 +
4942 +struct fanotify_event_metadata {
4943 +  uint32_t event_len;
4944 +  uint8_t vers, reserved;
4945 +  uint16_t metadata_len;
4946 +  uint64_t mask;
4947 +  int32_t fd, pid;
4948 +}
4949 +
4950 +__BEGIN_DECLS
4951 +
4952 +int fanotify_init(unsigned int flags, unsigned int event_f_flags);
4953 +int fanotify_mark(int fanotify_fd, unsigned int flags,
4954 +                 uint64_t mask, int dirfd, const char *pathname);
4955 +
4956 +__END_DECLS
4957 +
4958 +#endif
4959 diff -urN -x .git dietlibc-0.33/include/sys/futex.h dietlibc/include/sys/futex.h
4960 --- dietlibc-0.33/include/sys/futex.h   2005-10-04 17:47:03.000000000 +0000
4961 +++ dietlibc/include/sys/futex.h        2015-01-01 12:14:43.478272229 +0000
4962 @@ -1,8 +1,11 @@
4963  #ifndef _SYS_FUTEX_H
4964  #define _SYS_FUTEX_H
4965  
4966 +#include <sys/types.h>
4967  #include <sys/time.h>
4968  
4969 +__BEGIN_DECLS
4970 +
4971  enum {
4972    FUTEX_WAIT=0,
4973    FUTEX_WAKE=1,
4974 @@ -13,4 +16,6 @@
4975  
4976  long futex(int* uaddr,int op,int val,const struct timespec* timeout,int* uaddr2,int val3);
4977  
4978 +__END_DECLS
4979 +
4980  #endif
4981 diff -urN -x .git dietlibc-0.33/include/sys/inotify.h dietlibc/include/sys/inotify.h
4982 --- dietlibc-0.33/include/sys/inotify.h 2008-05-06 17:18:34.000000000 +0000
4983 +++ dietlibc/include/sys/inotify.h      2015-01-01 12:14:43.478272229 +0000
4984 @@ -52,12 +52,16 @@
4985                          IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \
4986                          IN_MOVE_SELF)
4987  
4988 +/* Flags for sys_inotify_init1.  */
4989 +#define IN_CLOEXEC O_CLOEXEC
4990 +#define IN_NONBLOCK O_NONBLOCK
4991  
4992  __BEGIN_DECLS
4993  
4994  int inotify_init(void) __THROW;
4995 -int inotify_add_watch(int fd,const char* path,unsigned long mask);
4996 -int inotify_rm_watch(int fd,int wd);
4997 +int inotify_init1(int flags) __THROW;
4998 +int inotify_add_watch(int fd,const char* path,unsigned long mask) __THROW;
4999 +int inotify_rm_watch(int fd,int wd) __THROW;
5000  
5001  __END_DECLS
5002  
5003 diff -urN -x .git dietlibc-0.33/include/sys/mman.h dietlibc/include/sys/mman.h
5004 --- dietlibc-0.33/include/sys/mman.h    2007-10-17 11:47:57.000000000 +0000
5005 +++ dietlibc/include/sys/mman.h 2015-01-01 12:14:43.478272229 +0000
5006 @@ -13,10 +13,27 @@
5007  #define PROT_READ      0x1             /* page can be read */
5008  #define PROT_WRITE     0x2             /* page can be written */
5009  #define PROT_EXEC      0x4             /* page can be executed */
5010 +#define PROT_SEM       0x8             /* page may be used for atomic ops */
5011  #define PROT_NONE      0x0             /* page can not be accessed */
5012  
5013 +#define PROT_GROWSDOWN 0x01000000      /* mprotect flag: extend change to start of growsdown vma */
5014 +#define PROT_GROWSUP   0x02000000      /* mprotect flag: extend change to end of growsdown vma */
5015 +
5016  #define MAP_SHARED     0x01            /* Share changes */
5017  #define MAP_PRIVATE    0x02            /* Changes are private */
5018 +#define MAP_TYPE       0xf             /* Mask for type of mapping */
5019 +
5020 +#define MADV_REMOVE            9
5021 +#define MADV_DONTFORK          10
5022 +#define MADV_DOFORK            11
5023 +#define MADV_MERGEABLE         12
5024 +#define MADV_UNMERGEABLE       13
5025 +#define MADV_HUGEPAGE          14
5026 +#define MADV_NOHUGEPAGE                15
5027 +#define MADV_DONTDUMP          16
5028 +#define MADV_DODUMP            17
5029 +#define MADV_HWPOISON          100
5030 +#define MADV_SOFT_OFFLINE      101
5031  
5032  #if defined(__mips__)
5033  #define MAP_FIXED      0x010           /* Interpret addr exactly */
5034 @@ -27,6 +44,9 @@
5035  #define MAP_EXECUTABLE 0x4000          /* mark it as an executable */
5036  #define MAP_LOCKED     0x8000          /* pages are locked */
5037  #define MAP_POPULATE   0x10000
5038 +#define MAP_NONBLOCK   0x20000
5039 +#define MAP_STACK      0x40000
5040 +#define MAP_HUGETLB    0x80000
5041  #define MS_ASYNC       0x0001          /* sync memory asynchronously */
5042  #define MS_INVALIDATE  0x0002          /* invalidate mappings & caches */
5043  #define MS_SYNC                0x0004          /* synchronous memory sync */
5044 @@ -46,6 +66,9 @@
5045  #define MAP_LOCKED     0x8000          /* lock the mapping */
5046  #define MAP_NORESERVE  0x10000         /* don't check for reservations */
5047  #define MAP_POPULATE   0x20000
5048 +#define MAP_NONBLOCK   0x40000
5049 +#define MAP_STACK      0x80000
5050 +#define MAP_HUGETLB    0x100000
5051  #define MS_ASYNC       1               /* sync memory asynchronously */
5052  #define MS_SYNC                2               /* synchronous memory sync */
5053  #define MS_INVALIDATE  4               /* invalidate the caches */
5054 @@ -57,7 +80,8 @@
5055  #define MADV_WILLNEED  3               /* will need these pages */
5056  #define MADV_SPACEAVAIL        5               /* ensure resources are available */
5057  #define MADV_DONTNEED  6               /* dont need these pages */
5058 -#elif defined(__i386__) || defined(__s390__) || defined(__x86_64__)
5059 +
5060 +#elif defined(__i386__) || defined(__s390__) || defined(__x86_64__) || defined(__arm__)
5061  #define MAP_FIXED      0x10            /* Interpret addr exactly */
5062  #define MAP_ANONYMOUS  0x20            /* don't use a file */
5063  #define MAP_GROWSDOWN  0x0100          /* stack-like segment */
5064 @@ -66,6 +90,9 @@
5065  #define MAP_LOCKED     0x2000          /* pages are locked */
5066  #define MAP_NORESERVE  0x4000          /* don't check for reservations */
5067  #define MAP_POPULATE   0x8000
5068 +#define MAP_NONBLOCK   0x10000
5069 +#define MAP_STACK      0x20000
5070 +#define MAP_HUGETLB    0x40000
5071  #define MS_ASYNC       1               /* sync memory asynchronously */
5072  #define MS_INVALIDATE  2               /* invalidate the caches */
5073  #define MS_SYNC                4               /* synchronous memory sync */
5074 @@ -76,6 +103,7 @@
5075  #define MADV_SEQUENTIAL        0x2             /* read-ahead aggressively */
5076  #define MADV_WILLNEED  0x3             /* pre-fault pages */
5077  #define MADV_DONTNEED  0x4             /* discard these pages */
5078 +
5079  #elif defined(__sparc__) || defined (__powerpc__) || defined (__powerpc64__)
5080  #define MAP_FIXED      0x10            /* Interpret addr exactly */
5081  #define MAP_ANONYMOUS  0x20            /* don't use a file */
5082 @@ -88,6 +116,9 @@
5083  #define MAP_DENYWRITE  0x0800          /* ETXTBSY */
5084  #define MAP_EXECUTABLE 0x1000          /* mark it as an executable */
5085  #define MAP_POPULATE   0x8000
5086 +#define MAP_NONBLOCK   0x10000
5087 +#define MAP_STACK      0x20000
5088 +#define MAP_HUGETLB    0x40000
5089  #define MS_ASYNC       1               /* sync memory asynchronously */
5090  #define MS_INVALIDATE  2               /* invalidate the caches */
5091  #define MS_SYNC                4               /* synchronous memory sync */
5092 @@ -99,27 +130,9 @@
5093  #define MADV_WILLNEED  0x3             /* pre-fault pages */
5094  #define MADV_DONTNEED  0x4             /* discard these pages */
5095  #define MADV_FREE      0x5             /* (Solaris) contents can be freed */
5096 -#elif defined (__arm__)
5097 -#define MAP_FIXED      0x10            /* Interpret addr exactly */
5098 -#define MAP_ANONYMOUS  0x20            /* don't use a file */
5099 -#define MAP_GROWSDOWN  0x0100          /* stack-like segment */
5100 -#define MAP_DENYWRITE  0x0800          /* ETXTBSY */
5101 -#define MAP_EXECUTABLE 0x1000          /* mark it as an executable */
5102 -#define MAP_LOCKED     0x2000          /* pages are locked */
5103 -#define MAP_NORESERVE  0x4000          /* don't check for reservations */
5104 -#define MAP_POPULATE   0x8000
5105 -#define MS_ASYNC       1               /* sync memory asynchronously */
5106 -#define MS_INVALIDATE  2               /* invalidate the caches */
5107 -#define MS_SYNC                4               /* synchronous memory sync */
5108 -#define MCL_CURRENT    1               /* lock all current mappings */
5109 -#define MCL_FUTURE     2               /* lock all future mappings */
5110 -#define MADV_NORMAL    0x0             /* default page-in behavior */
5111 -#define MADV_RANDOM    0x1             /* page-in minimum required */
5112 -#define MADV_SEQUENTIAL        0x2             /* read-ahead aggressively */
5113 -#define MADV_WILLNEED  0x3             /* pre-fault pages */
5114 -#define MADV_DONTNEED  0x4             /* discard these pages */
5115  
5116  #elif defined(__hppa__)
5117 +#undef MAP_TYPE
5118  #define MAP_TYPE       0x03    /* Mask for type of mapping */
5119  #define MAP_FIXED      0x04    /* Interpret addr exactly */
5120  #define MAP_ANONYMOUS  0x10    /* don't use a file */
5121 @@ -130,6 +143,9 @@
5122  #define MAP_NORESERVE  0x4000  /* don't check for reservations */
5123  #define MAP_GROWSDOWN  0x8000  /* stack-like segment */
5124  #define MAP_POPULATE   0x10000
5125 +#define MAP_NONBLOCK   0x20000
5126 +#define MAP_STACK      0x40000
5127 +#define MAP_HUGETLB    0x80000
5128  
5129  #define MS_SYNC        1       /* synchronous memory sync */
5130  #define MS_ASYNC       2       /* sync memory asynchronously */
5131 @@ -154,9 +170,23 @@
5132  #define MADV_4M_PAGES  22      /* Use 4 Megabyte pages */
5133  #define MADV_16M_PAGES 24      /* Use 16 Megabyte pages */
5134  #define MADV_64M_PAGES 26      /* Use 64 Megabyte pages */
5135 +
5136 +#undef MADV_MERGEABLE
5137 +#undef MADV_UNMERGEABLE
5138 +#undef MADV_HUGEPAGE
5139 +#undef MADV_NOHUGEPAGE
5140 +#undef MADV_DONTDUMP
5141 +#undef MADV_DODUMP
5142 +
5143 +#define MADV_MERGEABLE 65
5144 +#define MADV_UNMERGEABLE 66
5145 +#define MADV_HUGEPAGE 67
5146 +#define MADV_NOHUGEPAGE 68
5147 +#define MADV_DONTDUMP 69
5148 +#define MADV_DODUMP 70
5149 +
5150  #elif defined(__ia64__)
5151  
5152 -#define MAP_TYPE       0x0f    /* Mask for type of mapping */
5153  #define MAP_FIXED      0x10    /* Interpret addr exactly */
5154  #define MAP_ANONYMOUS  0x20    /* don't use a file */
5155  
5156 @@ -167,8 +197,9 @@
5157  #define MAP_LOCKED     0x2000  /* pages are locked */
5158  #define MAP_NORESERVE  0x4000  /* don't check for reservations */
5159  #define MAP_POPULATE   0x8000
5160 -#define MAP_WRITECOMBINED 0x10000      /* write-combine the area */
5161 -#define MAP_NONCACHED  0x20000 /* don't cache the memory */
5162 +#define MAP_NONBLOCK   0x10000
5163 +#define MAP_STACK      0x20000
5164 +#define MAP_HUGETLB    0x40000
5165  
5166  #define MS_ASYNC       1       /* sync memory asynchronously */
5167  #define MS_INVALIDATE  2       /* invalidate the caches */
5168 diff -urN -x .git dietlibc-0.33/include/sys/prctl.h dietlibc/include/sys/prctl.h
5169 --- dietlibc-0.33/include/sys/prctl.h   2007-03-09 13:42:12.000000000 +0000
5170 +++ dietlibc/include/sys/prctl.h        2015-01-01 12:14:43.478272229 +0000
5171 @@ -2,65 +2,7 @@
5172  #define _SYS_PRCTL_H
5173  
5174  #include <sys/cdefs.h>
5175 -
5176 -/* Values to pass as first argument to prctl() */
5177 -
5178 -#define PR_SET_PDEATHSIG  1  /* Second arg is a signal */
5179 -#define PR_GET_PDEATHSIG  2  /* Second arg is a ptr to return the signal */
5180 -
5181 -/* Get/set current->mm->dumpable */
5182 -#define PR_GET_DUMPABLE   3
5183 -#define PR_SET_DUMPABLE   4
5184 -
5185 -/* Get/set unaligned access control bits (if meaningful) */
5186 -#define PR_GET_UNALIGN   5
5187 -#define PR_SET_UNALIGN   6
5188 -# define PR_UNALIGN_NOPRINT    1       /* silently fix up unaligned user accesses */
5189 -# define PR_UNALIGN_SIGBUS     2       /* generate SIGBUS on unaligned user access */
5190 -
5191 -/* Get/set whether or not to drop capabilities on setuid() away from uid 0 */
5192 -#define PR_GET_KEEPCAPS   7
5193 -#define PR_SET_KEEPCAPS   8
5194 -
5195 -/* Get/set floating-point emulation control bits (if meaningful) */
5196 -#define PR_GET_FPEMU  9
5197 -#define PR_SET_FPEMU 10
5198 -# define PR_FPEMU_NOPRINT      1       /* silently emulate fp operations accesses */
5199 -# define PR_FPEMU_SIGFPE       2       /* don't emulate fp operations, send SIGFPE instead */
5200 -
5201 -/* Get/set floating-point exception mode (if meaningful) */
5202 -#define PR_GET_FPEXC   11
5203 -#define PR_SET_FPEXC   12
5204 -# define PR_FP_EXC_SW_ENABLE   0x80    /* Use FPEXC for FP exception enables */
5205 -# define PR_FP_EXC_DIV         0x010000        /* floating point divide by zero */
5206 -# define PR_FP_EXC_OVF         0x020000        /* floating point overflow */
5207 -# define PR_FP_EXC_UND         0x040000        /* floating point underflow */
5208 -# define PR_FP_EXC_RES         0x080000        /* floating point inexact result */
5209 -# define PR_FP_EXC_INV         0x100000        /* floating point invalid operation */
5210 -# define PR_FP_EXC_DISABLED    0       /* FP exceptions disabled */
5211 -# define PR_FP_EXC_NONRECOV    1       /* async non-recoverable exc. mode */
5212 -# define PR_FP_EXC_ASYNC       2       /* async recoverable exception mode */
5213 -# define PR_FP_EXC_PRECISE     3       /* precise exception mode */
5214 -
5215 -/* Get/set whether we use statistical process timing or accurate timestamp
5216 - * based process timing */
5217 -#define PR_GET_TIMING   13
5218 -#define PR_SET_TIMING   14
5219 -# define PR_TIMING_STATISTICAL  0       /* Normal, traditional,
5220 -                                                   statistical process timing */
5221 -# define PR_TIMING_TIMESTAMP    1       /* Accurate timestamp based
5222 -                                                   process timing */
5223 -
5224 -#define PR_SET_NAME    15              /* Set process name */
5225 -#define PR_GET_NAME    16              /* Get process name */
5226 -
5227 -/* Get/set process endian */
5228 -#define PR_GET_ENDIAN  19
5229 -#define PR_SET_ENDIAN  20
5230 -# define PR_ENDIAN_BIG         0
5231 -# define PR_ENDIAN_LITTLE      1       /* True little endian mode */
5232 -# define PR_ENDIAN_PPC_LITTLE  2       /* "PowerPC" pseudo little endian */
5233 -
5234 +#include <linux/prctl.h>
5235  
5236  __BEGIN_DECLS
5237  
5238 diff -urN -x .git dietlibc-0.33/include/sys/shm.h dietlibc/include/sys/shm.h
5239 --- dietlibc-0.33/include/sys/shm.h     2005-09-28 06:18:43.000000000 +0000
5240 +++ dietlibc/include/sys/shm.h  2015-01-01 12:14:43.478272229 +0000
5241 @@ -60,15 +60,6 @@
5242    unsigned long swap_successes;
5243  };
5244  
5245 -#if defined(__i386__) || defined(__mips__) || defined(__arm__) || defined(__powerpc__) || defined (__powerpc64__) || defined(__s390__) || defined(__hppa__) || defined(__x86_64__) || defined(__ia64__)
5246 -#define PAGE_SIZE 4096UL
5247 -#define PAGE_SHIFT 12
5248 -#elif defined(__alpha__) || defined(__sparc__)
5249 -/* sun4* has 4k except sun4 architecture, sparc64 has 8k */
5250 -#define PAGE_SIZE 8192UL
5251 -#define PAGE_SHIFT 13
5252 -#endif
5253 -
5254  extern int shmget(key_t key, int size, int shmflg) __THROW;
5255  extern void *shmat(int shmid, const void *shmaddr, int shmflg) __THROW;
5256  extern int shmdt (const void *shmaddr) __THROW;
5257 diff -urN -x .git dietlibc-0.33/include/sys/signalfd.h dietlibc/include/sys/signalfd.h
5258 --- dietlibc-0.33/include/sys/signalfd.h        2008-02-19 00:28:13.000000000 +0000
5259 +++ dietlibc/include/sys/signalfd.h     2015-01-01 12:14:43.478272229 +0000
5260 @@ -26,7 +26,7 @@
5261  __BEGIN_DECLS
5262  
5263  extern int signalfd (int __fd, const sigset_t *__mask, int __flags)
5264 -  __nonnull ((2)) __THROW;
5265 +  __THROW __nonnull ((2)) ;
5266  
5267  __END_DECLS
5268  
5269 diff -urN -x .git dietlibc-0.33/include/sys/socket.h dietlibc/include/sys/socket.h
5270 --- dietlibc-0.33/include/sys/socket.h  2012-11-02 11:17:28.000000000 +0000
5271 +++ dietlibc/include/sys/socket.h       2015-01-01 12:14:43.478272229 +0000
5272 @@ -3,44 +3,98 @@
5273  
5274  #include <sys/cdefs.h>
5275  #include <sys/types.h>
5276 +#include <fcntl.h>
5277  
5278  __BEGIN_DECLS
5279  
5280  /* For setsockopt(2) */
5281 +
5282  #if defined(__alpha__) || defined(__mips__)
5283  #define SOL_SOCKET     0xffff
5284  
5285  #define SO_DEBUG       0x0001
5286  #define SO_REUSEADDR   0x0004
5287 -#define SO_TYPE                0x1008
5288 -#define SO_ERROR       0x1007
5289 +#define SO_KEEPALIVE   0x0008
5290  #define SO_DONTROUTE   0x0010
5291  #define SO_BROADCAST   0x0020
5292 +#define SO_LINGER      0x0080
5293 +#define SO_OOBINLINE   0x0100
5294 +#define SO_REUSEPORT   0x0200
5295 +#define SO_TYPE                0x1008
5296 +#define SO_ERROR       0x1007
5297  #define SO_SNDBUF      0x1001
5298  #define SO_RCVBUF      0x1002
5299 -#define SO_KEEPALIVE   0x0008
5300 -#define SO_OOBINLINE   0x0100
5301 +
5302  #define SO_NO_CHECK    11
5303  #define SO_PRIORITY    12
5304 -#define SO_LINGER      0x0080
5305  #define SO_BSDCOMPAT   14
5306 -/* To add :#define SO_REUSEPORT 15 */
5307  #define SO_PASSCRED    17
5308  #define SO_PEERCRED    18
5309 -#define SO_RCVLOWAT    0x1004
5310 -#define SO_SNDLOWAT    0x1003
5311 -#define SO_RCVTIMEO    0x1006
5312 -#define SO_SNDTIMEO    0x1005
5313 -#define SO_ACCEPTCONN  0x1009
5314 +
5315 +/* Security levels - as per NRL IPv6 - don't actually do anything */
5316 +#define SO_SECURITY_AUTHENTICATION             19
5317 +#define SO_SECURITY_ENCRYPTION_TRANSPORT       20
5318 +#define SO_SECURITY_ENCRYPTION_NETWORK         21
5319 +
5320 +#define SO_BINDTODEVICE        25
5321 +#define SO_ATTACH_FILTER       26
5322 +#define SO_DETACH_FILTER       27
5323 +#define SO_GET_FILTER  SO_ATTACH_FILTER
5324 +#define SO_PEERNAME    28
5325 +#define SO_TIMESTAMP   29
5326 +#define SCM_TIMESTAMP  SO_TIMESTAMP
5327 +#define SO_PEERSEC     30
5328 +#define SO_PASSSEC     34
5329 +#define SO_TIMESTAMPNS 35
5330 +#define SCM_TIMESTAMPNS        SO_TIMESTAMPNS
5331 +#define SO_MARK                        36
5332 +#define SO_TIMESTAMPING                37
5333 +#define SCM_TIMESTAMPING       SO_TIMESTAMPING
5334 +#define SO_RXQ_OVFL             40
5335 +#define SO_WIFI_STATUS         41
5336 +#define SCM_WIFI_STATUS                SO_WIFI_STATUS
5337 +#define SO_PEEK_OFF            42
5338 +
5339 +/* Instruct lower device to use last 4-bytes of skb data as FCS */
5340 +#define SO_NOFCS               43
5341 +
5342 +#define SO_LOCK_FILTER         44
5343 +
5344 +#define SO_SELECT_ERR_QUEUE    45
5345 +
5346 +#define SO_BUSY_POLL           46
5347 +
5348 +#define SO_MAX_PACING_RATE     47
5349 +
5350 +#define SO_BPF_EXTENSIONS      48
5351 +
5352  
5353  #ifdef __alpha__
5354  #define SO_SNDBUFFORCE 0x100a
5355  #define SO_RCVBUFFORCE 0x100b
5356 +
5357 +#define        SO_RCVLOWAT     0x1010
5358 +#define        SO_SNDLOWAT     0x1011
5359 +#define        SO_RCVTIMEO     0x1012
5360 +#define        SO_SNDTIMEO     0x1013
5361 +#define SO_ACCEPTCONN  0x1014
5362 +
5363  #else
5364 +/* mips */
5365  #define SO_SNDBUFFORCE 31
5366  #define SO_RCVBUFFORCE 33
5367 +
5368 +#define SO_RCVLOWAT    0x1004
5369 +#define SO_SNDLOWAT    0x1003
5370 +#define SO_RCVTIMEO    0x1006
5371 +#define SO_SNDTIMEO    0x1005
5372 +#define SO_ACCEPTCONN  0x1009
5373 +
5374  #endif
5375  
5376 +#define SO_PROTOCOL    0x1028
5377 +#define SO_DOMAIN      0x1029
5378 +
5379  #define SO_STYLE       SO_TYPE /* Synonym */
5380  
5381  #elif defined(__hppa__)
5382 @@ -74,6 +128,8 @@
5383  #define SO_PEERCRED    0x4011
5384  #define SO_TIMESTAMP   0x4012
5385  #define SCM_TIMESTAMP   SO_TIMESTAMP
5386 +#define SO_TIMESTAMPNS 0x4013
5387 +#define SCM_TIMESTAMPNS        SO_TIMESTAMPNS
5388  
5389  /* Security levels - as per NRL IPv6 - don't actually do anything */
5390  #define SO_SECURITY_AUTHENTICATION     0x4016
5391 @@ -85,9 +141,37 @@
5392  /* Socket filtering */
5393  #define SO_ATTACH_FILTER       0x401a
5394  #define SO_DETACH_FILTER       0x401b
5395 +#define SO_GET_FILTER          SO_ATTACH_FILTER
5396  
5397  #define SO_ACCEPTCONN  0x401c
5398  
5399 +#define SO_PEERSEC             0x401d
5400 +#define SO_PASSSEC             0x401e
5401 +
5402 +#define SO_MARK                        0x401f
5403 +
5404 +#define SO_TIMESTAMPING                0x4020
5405 +#define SCM_TIMESTAMPING       SO_TIMESTAMPING
5406 +
5407 +#define SO_RXQ_OVFL             0x4021
5408 +
5409 +#define SO_WIFI_STATUS         0x4022
5410 +#define SCM_WIFI_STATUS                SO_WIFI_STATUS
5411 +#define SO_PEEK_OFF            0x4023
5412 +
5413 +/* Instruct lower device to use last 4-bytes of skb data as FCS */
5414 +#define SO_NOFCS               0x4024
5415 +
5416 +#define SO_LOCK_FILTER         0x4025
5417 +
5418 +#define SO_SELECT_ERR_QUEUE    0x4026
5419 +
5420 +#define SO_BUSY_POLL           0x4027
5421 +
5422 +#define SO_MAX_PACING_RATE     0x4028
5423 +
5424 +#define SO_BPF_EXTENSIONS      0x4029
5425 +
5426  #elif defined(__sparc__)
5427  #define SOL_SOCKET     0xffff
5428  
5429 @@ -120,11 +204,41 @@
5430  
5431  #define SO_ATTACH_FILTER       0x001a
5432  #define SO_DETACH_FILTER       0x001b
5433 +#define SO_GET_FILTER          SO_ATTACH_FILTER
5434  
5435  #define SO_PEERNAME    0x001c
5436  #define SO_TIMESTAMP   0x001d
5437  #define SCM_TIMESTAMP  SO_TIMESTAMP
5438  
5439 +#define SO_PEERSEC             0x001e
5440 +#define SO_PASSSEC             0x001f
5441 +#define SO_TIMESTAMPNS         0x0021
5442 +#define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
5443 +
5444 +#define SO_MARK                        0x0022
5445 +
5446 +#define SO_TIMESTAMPING                0x0023
5447 +#define SCM_TIMESTAMPING       SO_TIMESTAMPING
5448 +
5449 +#define SO_RXQ_OVFL             0x0024
5450 +
5451 +#define SO_WIFI_STATUS         0x0025
5452 +#define SCM_WIFI_STATUS                SO_WIFI_STATUS
5453 +#define SO_PEEK_OFF            0x0026
5454 +
5455 +/* Instruct lower device to use last 4-bytes of skb data as FCS */
5456 +#define SO_NOFCS               0x0027
5457 +
5458 +#define SO_LOCK_FILTER         0x0028
5459 +
5460 +#define SO_SELECT_ERR_QUEUE    0x0029
5461 +
5462 +#define SO_BUSY_POLL           0x0030
5463 +
5464 +#define SO_MAX_PACING_RATE     0x0031
5465 +
5466 +#define SO_BPF_EXTENSIONS      0x0032
5467 +
5468  /* Security levels - as per NRL IPv6 - don't actually do anything */
5469  #define SO_SECURITY_AUTHENTICATION              0x5001
5470  #define SO_SECURITY_ENCRYPTION_TRANSPORT        0x5002
5471 @@ -155,28 +269,63 @@
5472  #define SO_SNDLOWAT    19
5473  #define SO_RCVTIMEO    20
5474  #define SO_SNDTIMEO    21
5475 -#define SO_ACCEPTCONN  30
5476 -#define SO_SNDBUFFORCE 32
5477 -#define SO_RCVBUFFORCE 33
5478  
5479 -#endif
5480 -
5481 -#if !defined(__hppa__) && !defined(__sparc__)
5482  /* Security levels - as per NRL IPv6 - don't actually do anything */
5483  #define SO_SECURITY_AUTHENTICATION             22
5484  #define SO_SECURITY_ENCRYPTION_TRANSPORT       23
5485  #define SO_SECURITY_ENCRYPTION_NETWORK         24
5486  
5487  #define SO_BINDTODEVICE        25
5488 -
5489 -/* Socket filtering */
5490 -#define SO_ATTACH_FILTER        26
5491 -#define SO_DETACH_FILTER        27
5492 -
5493 +#define SO_ATTACH_FILTER       26
5494 +#define SO_DETACH_FILTER       27
5495 +#define SO_GET_FILTER          SO_ATTACH_FILTER
5496  #define SO_PEERNAME            28
5497  #define SO_TIMESTAMP           29
5498  #define SCM_TIMESTAMP          SO_TIMESTAMP
5499 +
5500 +#define SO_ACCEPTCONN  30
5501 +#define SO_PEERSEC             31
5502 +#define SO_SNDBUFFORCE 32
5503 +#define SO_RCVBUFFORCE 33
5504 +#define SO_PASSSEC             34
5505 +#define SO_TIMESTAMPNS         35
5506 +#define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
5507 +
5508 +#define SO_MARK                        36
5509 +
5510 +#define SO_TIMESTAMPING                37
5511 +#define SCM_TIMESTAMPING       SO_TIMESTAMPING
5512 +
5513 +#define SO_PROTOCOL            38
5514 +#define SO_DOMAIN              39
5515 +
5516 +#define SO_RXQ_OVFL             40
5517 +
5518 +#define SO_WIFI_STATUS         41
5519 +#define SCM_WIFI_STATUS        SO_WIFI_STATUS
5520 +#define SO_PEEK_OFF            42
5521 +
5522 +/* Instruct lower device to use last 4-bytes of skb data as FCS */
5523 +#define SO_NOFCS               43
5524 +
5525 +#define SO_LOCK_FILTER         44
5526 +
5527 +#define SO_SELECT_ERR_QUEUE    45
5528 +
5529 +#define SO_BUSY_POLL           46
5530 +
5531 +#define SO_MAX_PACING_RATE     47
5532 +
5533 +#define SO_BPF_EXTENSIONS      48
5534 +
5535 +#endif
5536 +
5537 +#if defined(__hppa__) || defined(__alpha__)
5538 +#define SOCK_NONBLOCK 0x40000000
5539 +#else
5540 +#define SOCK_NONBLOCK O_NONBLOCK
5541  #endif
5542 +#define SOCK_CLOEXEC O_CLOEXEC
5543  
5544  /* Socket types. */
5545  #ifdef __mips__
5546 @@ -189,6 +338,7 @@
5547  #define SOCK_RAW       3               /* raw socket                   */
5548  #define SOCK_RDM       4               /* reliably-delivered message   */
5549  #define SOCK_SEQPACKET 5               /* sequential packet socket     */
5550 +#define SOCK_DCCP      6               /* Datagram Congestion Control Protocol socket */
5551  #define SOCK_PACKET    10              /* linux specific way of        */
5552                                         /* getting packets at the dev   */
5553                                         /* level.  For writing rarp and */
5554 @@ -324,6 +474,14 @@
5555  #define MSG_ERRQUEUE   0x2000  /* Fetch message from error queue */
5556  #define MSG_NOSIGNAL   0x4000  /* Do not generate SIGPIPE */
5557  #define MSG_MORE       0x8000  /* Sender will send more */
5558 +#define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */
5559 +#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */
5560 +#define MSG_EOF         MSG_FIN
5561 +
5562 +#define MSG_FASTOPEN   0x20000000      /* Send data in TCP SYN */
5563 +#define MSG_CMSG_CLOEXEC 0x40000000    /* Set close_on_exit for file
5564 +                                          descriptor received through
5565 +                                          SCM_RIGHTS */
5566  
5567  /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
5568  #define SOL_IP         0
5569 @@ -381,16 +539,6 @@
5570    char __ss_padding[(128  - (2 * sizeof (uint32_t ))) ];
5571  };
5572  
5573 -#ifndef SOCK_DGRAM
5574 -/* the Linux kernel headers suck really badly on non-x86 */
5575 -#define SOCK_STREAM    1               /* stream (connection) socket   */
5576 -#define SOCK_DGRAM     2               /* datagram (conn.less) socket  */
5577 -#define SOCK_RAW       3               /* raw socket                   */
5578 -#define SOCK_RDM       4               /* reliably-delivered message   */
5579 -#define SOCK_SEQPACKET 5               /* sequential packet socket     */
5580 -#define SOCK_PACKET    10              /* linux specific way of        */
5581 -#endif
5582 -
5583  int socket(int domain, int type, int protocol) __THROW;
5584  int accept(int s, struct sockaddr *addr, socklen_t *addrlen) __THROW;
5585  int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) __THROW;
5586 @@ -415,7 +563,19 @@
5587  #define SHUT_RDWR 2
5588  int shutdown(int s, int how) __THROW;
5589  
5590 -int socketpair(int d, int type, int protocol, int sv[2]);
5591 +int socketpair(int d, int type, int protocol, int sv[2]) __THROW;
5592 +
5593 +#ifdef _GNU_SOURCE
5594 +struct mmsghdr {
5595 +   struct msghdr msg_hdr;  /* Message header */
5596 +   unsigned int  msg_len;  /* Number of bytes transmitted */
5597 +};
5598 +
5599 +int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
5600 +            unsigned int flags, struct timespec *timeout) __THROW;
5601 +int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
5602 +            unsigned int flags);
5603 +#endif
5604  
5605  /* currently not supported: */
5606  #define NI_NOFQDN 1
5607 diff -urN -x .git dietlibc-0.33/include/sys/stat.h dietlibc/include/sys/stat.h
5608 --- dietlibc-0.33/include/sys/stat.h    2012-11-02 11:17:28.000000000 +0000
5609 +++ dietlibc/include/sys/stat.h 2015-01-01 12:14:43.478272229 +0000
5610 @@ -8,6 +8,7 @@
5611  __BEGIN_DECLS
5612  
5613  #if defined(__i386__)
5614 +
5615  struct stat {
5616         uint32_t        st_dev;
5617         unsigned long   st_ino;
5618 @@ -489,7 +490,7 @@
5619         unsigned long long st_ino;
5620  };
5621  
5622 -#elif defined(__x86_64__)
5623 +#elif defined(__x86_64__) && !defined(__ILP32__)
5624  
5625  struct stat {
5626         unsigned long   st_dev;
5627 @@ -512,6 +513,24 @@
5628         long            __unused[3];
5629  };
5630  
5631 +#elif defined(__x86_64__)
5632 +
5633 +/* for X32 */
5634 +
5635 +struct stat {
5636 +       uint64_t        st_dev, st_ino, st_nlink;
5637 +       uint32_t        st_mode, st_uid, st_gid, __pad0;
5638 +       uint64_t        st_rdev;
5639 +       int64_t         st_size, st_blksize, st_blocks;
5640 +       time_t          st_atime;
5641 +       uint64_t        st_atime_nsec;
5642 +       time_t          st_mtime;
5643 +       uint64_t        st_mtime_nsec;
5644 +       time_t          st_ctime;
5645 +       uint64_t        st_ctime_nsec;
5646 +       unsigned int    __unused[3]
5647 +};
5648 +
5649  #elif defined(__ia64__)
5650  
5651  struct stat {
5652 @@ -576,7 +595,7 @@
5653  extern int fstat(int __fd, struct stat *__buf) __THROW;
5654  extern int lstat(const char *__file, struct stat *__buf) __THROW;
5655  
5656 -#if __WORDSIZE == 64
5657 +#if (__WORDSIZE == 64) || defined(__OFF_T_MATCHES_OFF64_T)
5658  #define __NO_STAT64
5659  #else
5660  extern int stat64(const char *__file, struct stat64 *__buf) __THROW;
5661 diff -urN -x .git dietlibc-0.33/include/sys/time.h dietlibc/include/sys/time.h
5662 --- dietlibc-0.33/include/sys/time.h    2008-12-10 20:00:59.000000000 +0000
5663 +++ dietlibc/include/sys/time.h 2015-01-01 12:14:43.481605561 +0000
5664 @@ -73,10 +73,10 @@
5665  #define timeradd(a,b,x) do { (x)->tv_sec=(a)->tv_sec+(b)->tv_sec; if (((x)->tv_usec=(a)->tv_usec+(b)->tv_usec)>=1000000) { ++(x)->tv_sec; (x)->tv_usec-=1000000; } } while (0)
5666  #define timersub(a,b,x) do { (x)->tv_sec=(a)->tv_sec-(b)->tv_sec; if (((x)->tv_usec=(a)->tv_usec-(b)->tv_usec)<0) { --(x)->tv_sec; (x)->tv_usec+=1000000; } } while (0)
5667  #define timerisset(x) ((x)->tv_sec || (x)->tv_usec)
5668 -
5669 -int utimes(const char * filename, struct timeval * tvp);
5670  #endif
5671  
5672 +int utimes(const char * filename, struct timeval * tvp) __THROW;
5673 +
5674  __END_DECLS
5675  
5676  #endif
5677 diff -urN -x .git dietlibc-0.33/include/sys/tls.h dietlibc/include/sys/tls.h
5678 --- dietlibc-0.33/include/sys/tls.h     2010-09-25 17:03:26.000000000 +0000
5679 +++ dietlibc/include/sys/tls.h  2015-01-01 12:14:43.481605561 +0000
5680 @@ -9,8 +9,7 @@
5681  typedef union dtv
5682  {
5683    size_t counter;
5684 -  struct
5685 -  {
5686 +  struct {
5687      void *val;
5688      bool is_static;
5689    } pointer;
5690 @@ -18,19 +17,18 @@
5691  
5692  typedef struct
5693  {
5694 -  void *tcb;            /* Pointer to the TCB.  Not necessary the
5695 -                           thread descriptor used by libpthread.  */
5696 -  dtv_t *dtv;
5697 +  void *tcb;            /* Pointer to the TCB.  Accessed as GS:[0], points to itself. */
5698 +  dtv_t *dtv;          /* Data structure used to find thread-local storage */
5699    void *self;           /* Pointer to the thread descriptor.  */
5700 -  int multiple_threads;
5701 +  int multiple_threads;        /* Set to 0 by _start/stackgap(), set to 1 by thrd_create */
5702  #ifdef __x86_64__
5703 -  int gscope_flag;
5704 +  int gscope_flag;     /* no idea what this is for */
5705  #endif
5706 -  uintptr_t sysinfo;
5707 -  uintptr_t stack_guard;
5708 -  uintptr_t pointer_guard;
5709 +  uintptr_t sysinfo;           /* not sure why this is here; passed via ELF auxvec, copied here by thrd_create */
5710 +  uintptr_t stack_guard;       /* random value used as canary value by gcc -fstack-protector, initialized by _start/stackgap()/thrd_create */
5711 +  uintptr_t pointer_guard;     /* random value used by glibc to xor internal pointers as exploit mitigation; not used in dietlibc */
5712  #ifdef __i386__
5713 -  int gscope_flag;
5714 +  int gscope_flag;     /* no idea what this is for */
5715  #endif
5716  } tcbhead_t;
5717  
5718 @@ -61,6 +59,22 @@
5719  
5720  int arch_prctl(unsigned int what, void* where);
5721  
5722 +#elif defined(__ia64__) || defined(__powerpc64__)
5723 +
5724 +#define __ABI_TLS_REGISTER     "r13"
5725 +
5726 +#elif defined(__powerpc__)
5727 +
5728 +#define __ABI_TLS_REGISTER     "r2"
5729 +
5730 +#elif defined(__sparc__)
5731 +
5732 +#define __ABI_TLS_REGISTER     "%g7"
5733 +
5734 +#elif defined(__arm__)
5735 +
5736 +void __arm_set_tls(void *);
5737 +
5738  #else
5739  
5740  #warning "need proper sys/tls.h for this platform"
5741 diff -urN -x .git dietlibc-0.33/include/sys/types.h dietlibc/include/sys/types.h
5742 --- dietlibc-0.33/include/sys/types.h   2010-09-25 17:03:26.000000000 +0000
5743 +++ dietlibc/include/sys/types.h        2015-01-01 12:14:43.481605561 +0000
5744 @@ -84,7 +84,11 @@
5745  typedef int32_t pid_t;                 /* Used for process IDs and process group IDs. */
5746  typedef signed long ssize_t;           /* Used for a count of bytes or an error indication. */
5747  typedef signed long suseconds_t;       /* Used for time in microseconds. */
5748 +#if defined(__x86_64__) && defined(__ILP32__)
5749 +typedef signed long long time_t;
5750 +#else
5751  typedef signed long time_t;            /* Used for time in seconds. */
5752 +#endif
5753  typedef signed long useconds_t;                /* Used for time in microseconds. */
5754  
5755  /* non-susv2 types: */
5756 @@ -94,8 +98,13 @@
5757  #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
5758  typedef off64_t off_t;
5759  #else
5760 +
5761 +#if defined(__x86_64__) && defined(__ILP32__)
5762 +typedef off64_t off_t;
5763 +#else
5764  typedef signed long off_t;             /* Used for file sizes. */
5765  #endif
5766 +#endif
5767  
5768  __extension__ typedef unsigned long long ino64_t;
5769  __extension__ typedef signed long long blkcnt64_t;
5770 diff -urN -x .git dietlibc-0.33/include/sys/ucontext.h dietlibc/include/sys/ucontext.h
5771 --- dietlibc-0.33/include/sys/ucontext.h        2005-03-11 17:18:15.000000000 +0000
5772 +++ dietlibc/include/sys/ucontext.h     2015-01-01 12:14:43.481605561 +0000
5773 @@ -10,13 +10,16 @@
5774  typedef struct sigcontext mcontext_t;
5775  #endif
5776  
5777 -#if defined(__i386__) || defined(__arm__) || defined(__mips__) || defined(__mips64__) || defined(__powerpc__) || defined(__powerpc64__) || defined(__hppa__)
5778 +#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__mips__) || defined(__mips64__) || defined(__powerpc__) || defined(__powerpc64__) || defined(__hppa__)
5779  struct ucontext {
5780    unsigned long                uc_flags;
5781    struct ucontext      *uc_link;
5782    stack_t              uc_stack;
5783    struct sigcontext    uc_mcontext;
5784    sigset_t             uc_sigmask;     /* mask last for extensibility */
5785 +#if defined(__i386__) || defined(__x86_64__)
5786 +  struct _fpstate      __fpregs_mem;
5787 +#endif
5788  };
5789  #elif defined(__alpha__)
5790  struct ucontext {
5791 @@ -105,15 +108,6 @@
5792  #define uc_link                uc_mcontext.sc_gr[0]    /* wrong type; nobody cares */
5793  #define uc_sigmask     uc_mcontext.sc_sigmask
5794  #define uc_stack       uc_mcontext.sc_stack
5795 -#elif defined(__x86_64__)
5796 -
5797 -struct ucontext {
5798 -       unsigned long     uc_flags;
5799 -       struct ucontext  *uc_link;
5800 -       stack_t           uc_stack;
5801 -       struct sigcontext uc_mcontext;
5802 -       sigset_t          uc_sigmask;   /* mask last for extensibility */
5803 -};
5804  
5805  #else
5806  #error NEED TO PORT <sys/sigcontext.h>!
5807 diff -urN -x .git dietlibc-0.33/include/sys/uio.h dietlibc/include/sys/uio.h
5808 --- dietlibc-0.33/include/sys/uio.h     2003-08-19 16:58:18.000000000 +0000
5809 +++ dietlibc/include/sys/uio.h  2015-01-01 12:14:43.481605561 +0000
5810 @@ -6,8 +6,11 @@
5811  __BEGIN_DECLS
5812  
5813  /* I have no idea why susv3 specifies count as int instead of size_t */
5814 -ssize_t readv(int filedes, const struct iovec *vector, int count);
5815 -ssize_t writev(int filedes, const struct iovec *vector, int count);
5816 +ssize_t readv(int filedes, const struct iovec *vector, int count) __THROW;
5817 +ssize_t writev(int filedes, const struct iovec *vector, int count) __THROW;
5818 +
5819 +ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) __THROW;
5820 +ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) __THROW;
5821  
5822  __END_DECLS
5823  
5824 diff -urN -x .git dietlibc-0.33/include/sys/wait.h dietlibc/include/sys/wait.h
5825 --- dietlibc-0.33/include/sys/wait.h    2006-05-29 16:30:53.000000000 +0000
5826 +++ dietlibc/include/sys/wait.h 2015-01-01 12:14:43.481605561 +0000
5827 @@ -41,12 +41,12 @@
5828  #define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
5829  #endif
5830  
5831 -pid_t wait(int *status) __THROW;
5832 -pid_t waitpid(pid_t pid, int *status, int options) __THROW;
5833 +pid_t wait(int *status);
5834 +pid_t waitpid(pid_t pid, int *status, int options);
5835  
5836 -pid_t wait3(int *status, int options, struct rusage *rusage) __THROW;
5837 +pid_t wait3(int *status, int options, struct rusage *rusage) __THROWNL;
5838  
5839 -pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) __THROW;
5840 +pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) __THROWNL;
5841  
5842  typedef enum {
5843    P_ALL,               /* Wait for any child.  */
5844 diff -urN -x .git dietlibc-0.33/include/threads.h dietlibc/include/threads.h
5845 --- dietlibc-0.33/include/threads.h     1970-01-01 00:00:00.000000000 +0000
5846 +++ dietlibc/include/threads.h  2015-01-01 12:14:43.481605561 +0000
5847 @@ -0,0 +1,95 @@
5848 +#ifndef THREAD_H
5849 +#define THREAD_H
5850 +
5851 +#include <sys/types.h>
5852 +#include <sys/time.h>
5853 +
5854 +typedef struct __thrd_t {
5855 +  char* memstart;      // points to beginning of guard page
5856 +  size_t memsize;      // this includes the guard page, the stack, the thread local storage but not tcb and thrd_t data
5857 +  pid_t tid;
5858 +  /* the thread function and the argument it was called with */
5859 +  int (*func)(void*);
5860 +  void* arg;
5861 +  /* the return value of the function, so it can be read with pthread_join */
5862 +  int res;
5863 +  /* 1: the thread was detached
5864 +   * 2: the thread already exited, stack and thread local data freed
5865 +   * 4: being torn down (calls to thrd_detach and thrd_join fail) */
5866 +  int flags;
5867 +  int join_futex,join_wait_futex;
5868 +}* thrd_t;
5869 +
5870 +enum {
5871 +  thrd_success = 0,
5872 +  thrd_timedout,
5873 +  thrd_busy,
5874 +  thrd_nomem,
5875 +  thrd_error
5876 +};
5877 +
5878 +typedef int (*thrd_start_t)(void* arg);
5879 +
5880 +int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
5881 +thrd_t thrd_current(void);
5882 +int thrd_detach(thrd_t thr);
5883 +int thrd_equal(thrd_t thr0, thrd_t thr1);
5884 +void thrd_exit(int res);
5885 +int thrd_join(thrd_t thr, int* res);
5886 +int thrd_sleep(const struct timespec* time_point, struct timespec* remaining);
5887 +void thrd_yield(void);
5888 +
5889 +typedef struct __mtx_t {
5890 +  int lock, type;
5891 +  thrd_t owner;
5892 +} mtx_t;
5893 +
5894 +enum {
5895 +  mtx_plain = 0,
5896 +  mtx_timed = 1,
5897 +  mtx_recursive = 2
5898 +};
5899 +
5900 +int mtx_init(mtx_t* mutex, int type);
5901 +int mtx_lock(mtx_t* mutex);
5902 +int mtx_timedlock(mtx_t *restrict mutex, const struct timespec *restrict time_point);
5903 +int mtx_trylock(mtx_t* mutex);
5904 +int mtx_unlock(mtx_t* mutex);
5905 +void mtx_destroy(mtx_t* mutex);
5906 +
5907 +#ifdef _DIETLIBC_SOURCE
5908 +int __mtx_trylock(mtx_t* mutex,int* lockval);
5909 +#endif
5910 +
5911 +typedef int once_flag;
5912 +#define ONCE_FLAG_INIT 0
5913 +
5914 +void call_once(once_flag* flag, void (*func)(void));
5915 +
5916 +typedef struct __cnd_t {
5917 +  int sem;
5918 +} cnd_t;
5919 +
5920 +int cnd_init(cnd_t* cond);
5921 +int cnd_signal(cnd_t *cond);
5922 +int cnd_broadcast(cnd_t *cond);
5923 +int cnd_wait(cnd_t* cond, mtx_t* mutex);
5924 +int cnd_timedwait(cnd_t* restrict cond, mtx_t* restrict mutex, const struct timespec* restrict time_point);
5925 +void cnd_destroy(cnd_t* cond);
5926 +
5927 +#define thread_local __thread
5928 +
5929 +typedef void (*tss_dtor_t)(void*);
5930 +typedef struct __tss_t {
5931 +  void* data;
5932 +  tss_dtor_t dtor;
5933 +  struct __tss_t* next;
5934 +}* tss_t;
5935 +
5936 +#define TSS_DTOR_ITERATIONS 1
5937 +int tss_create(tss_t* tss_id, tss_dtor_t destructor);
5938 +void *tss_get(tss_t tss_id);
5939 +int tss_set(tss_t tss_id, void *val);
5940 +void tss_delete(tss_t tss_id);
5941 +
5942 +#endif
5943 diff -urN -x .git dietlibc-0.33/include/ucontext.h dietlibc/include/ucontext.h
5944 --- dietlibc-0.33/include/ucontext.h    1970-01-01 00:00:00.000000000 +0000
5945 +++ dietlibc/include/ucontext.h 2015-01-01 12:14:43.481605561 +0000
5946 @@ -0,0 +1,17 @@
5947 +#ifndef _UCONTEXT_H
5948 +#define _UCONTEXT_H
5949 +
5950 +#include <sys/ucontext.h>
5951 +
5952 +__BEGIN_DECLS
5953 +
5954 +extern int getcontext (ucontext_t *c) __THROW;
5955 +extern int setcontext (const ucontext_t *c) __THROW;
5956 +extern int swapcontext (ucontext_t *__restrict o,
5957 +                       const ucontext_t *__restrict n) __THROWNL;
5958 +extern void makecontext (ucontext_t *c, void (*__func) (void),
5959 +                        int argc, ...) __THROW;
5960 +
5961 +__END_DECLS
5962 +
5963 +#endif
5964 diff -urN -x .git dietlibc-0.33/include/unistd.h dietlibc/include/unistd.h
5965 --- dietlibc-0.33/include/unistd.h      2012-11-02 11:17:28.000000000 +0000
5966 +++ dietlibc/include/unistd.h   2015-01-01 12:14:43.481605561 +0000
5967 @@ -34,11 +34,13 @@
5968  #define STDERR_FILENO  2
5969  
5970  off_t lseek(int fildes, off_t offset, int whence) __THROW;
5971 -#if __WORDSIZE == 32
5972 +#if !defined(__OFF_T_MATCHES_OFF64_T)
5973  loff_t lseek64(int fildes, loff_t offset, int whence) __THROW;
5974  #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
5975  #define lseek(fildes,offset,whence) lseek64(fildes,offset,whence)
5976  #endif
5977 +#else
5978 +#define lseek64(fildes,offset,whence) lseek(fildes,offset,whence)
5979  #endif
5980  
5981  int chdir(const char *path) __THROW;
5982 @@ -48,6 +50,8 @@
5983  
5984  #ifdef _GNU_SOURCE
5985  char *get_current_dir_name (void) __THROW __attribute_dontuse__;
5986 +
5987 +int pipe2(int pipefd[2], int flags) __THROW;
5988  #endif
5989  
5990  int open(const char* pathname,int flags, ...) __THROW;
5991 @@ -84,11 +88,22 @@
5992  pid_t setsid (void) __THROW;
5993  int dup (int oldfd) __THROW;
5994  int dup2 (int oldfd,int newfd) __THROW;
5995 +#ifdef _GNU_SOURCE
5996 +int dup3(int oldfd, int newfd, int flags) __THROW;
5997 +
5998 +/* flags for memfd_create(2) (unsigned int) */
5999 +#define MFD_CLOEXEC            0x0001U
6000 +#define MFD_ALLOW_SEALING      0x0002U
6001 +
6002 +int memfd_create(const char* name, unsigned int flags) __THROW;
6003  
6004 -struct dirent;
6005 -struct dirent64;
6006 -int getdents(int fd, struct dirent *dirp, unsigned int count) __THROW;
6007 -int getdents64(int fd, struct dirent64 *dirp, unsigned int count) __THROW;
6008 +int syncfs(int fd) __THROW;
6009 +#endif
6010 +
6011 +struct linux_dirent;
6012 +struct linux_dirent64;
6013 +int getdents(int fd, struct linux_dirent *dirp, unsigned int count) __THROW;
6014 +int getdents64(int fd, struct linux_dirent64 *dirp, unsigned int count) __THROW;
6015  
6016  pid_t fork(void) __THROW;
6017  pid_t vfork(void) __THROW;
6018 @@ -187,6 +202,8 @@
6019  #define _SC_NPROCESSORS_ONLN 6
6020  #define _SC_NPROCESSORS_CONF _SC_NPROCESSORS_ONLN
6021  #define _SC_PHYS_PAGES 7
6022 +#define _SC_GETPW_R_SIZE_MAX 8
6023 +#define _SC_GETGR_R_SIZE_MAX 9
6024  long sysconf(int name) __THROW;
6025  #define _PC_PATH_MAX 1
6026  #define _PC_VDISABLE 2
6027 @@ -258,7 +275,7 @@
6028  #endif
6029  #endif
6030  
6031 -#ifdef _LINUX_SOURCE
6032 +#if defined(_LINUX_SOURCE) || defined(_GNU_SOURCE)
6033  int pivot_root(const char *new_root, const char *put_old) __THROW;
6034  /* Linux 2.6 module loading infrastructure:
6035   * init_module takes a buffer where you read the module file into */
6036 @@ -270,8 +287,19 @@
6037  int tkill(pid_t tid, int sig) __THROW;
6038  int tgkill(pid_t tgid, pid_t tid, int sig) __THROW;
6039  /* see linux/fadvise.h */
6040 -long fadvise64(int fd,off64_t offset,size_t len,int advice);
6041 -long fadvise64_64(int fd,off64_t offset,off64_t len,int advice);
6042 +long fadvise64(int fd,off64_t offset,size_t len,int advice) __THROW;
6043 +long fadvise64_64(int fd,off64_t offset,off64_t len,int advice) __THROW;
6044 +
6045 +#ifndef GRND_NONBLOCK
6046 +enum {
6047 +  GRND_NONBLOCK=1,
6048 +#define GRND_NONBLOCK GRND_NONBLOCK
6049 +  GRND_RANDOM=2
6050 +#define GRND_RANDOM GRND_RANDOM
6051 +};
6052 +
6053 +int getrandom(void* buf, size_t buflen, unsigned int flags) __THROW;
6054 +#endif
6055  #endif
6056  
6057  #if defined(_ATFILE_SOURCE) || ((_XOPEN_SOURCE + 0) >= 700) || ((_POSIX_C_SOURCE + 0) >= 200809L)
6058 diff -urN -x .git dietlibc-0.33/include/wchar.h dietlibc/include/wchar.h
6059 --- dietlibc-0.33/include/wchar.h       2010-09-25 17:03:26.000000000 +0000
6060 +++ dietlibc/include/wchar.h    2015-01-01 12:14:43.481605561 +0000
6061 @@ -13,7 +13,7 @@
6062  #else
6063  typedef unsigned int wint_t;
6064  #endif
6065 -typedef int (*wctype_t)(wint_t) __THROW __attribute__((__const__));
6066 +typedef int (*wctype_t)(wint_t) __attribute__((__const__)) __THROW;
6067  
6068  #ifndef WCHAR_MIN
6069  #define WCHAR_MIN (-2147483647 - 1)
6070 diff -urN -x .git dietlibc-0.33/ldso.c dietlibc/ldso.c
6071 --- dietlibc-0.33/ldso.c        1970-01-01 00:00:00.000000000 +0000
6072 +++ dietlibc/ldso.c     2015-01-01 12:14:43.481605561 +0000
6073 @@ -0,0 +1,803 @@
6074 +#define errno fnord
6075 +#include <unistd.h>
6076 +#include <fcntl.h>
6077 +#include <sys/mman.h>
6078 +#include <elf.h>
6079 +#include <stdlib.h>
6080 +#include <stdint.h>
6081 +#undef errno
6082 +
6083 +#if (__WORDSIZE == 64)
6084 +
6085 +#define phdr Elf64_Phdr
6086 +#define ehdr Elf64_Ehdr
6087 +#define shdr Elf64_Shdr
6088 +#define sym Elf64_Sym
6089 +#define dyn Elf64_Dyn
6090 +#define rela Elf64_Rela
6091 +#define R_SYM ELF64_R_SYM
6092 +#define R_TYPE ELF64_R_TYPE
6093 +
6094 +#else
6095 +
6096 +#define phdr Elf32_Phdr
6097 +#define ehdr Elf32_Ehdr
6098 +#define shdr Elf32_Shdr
6099 +#define sym Elf32_Sym
6100 +#define dyn Elf32_Dyn
6101 +#define rela Elf32_Rela
6102 +#define R_SYM ELF32_R_SYM
6103 +#define R_TYPE ELF32_R_TYPE
6104 +
6105 +#endif
6106 +
6107 +static int errno;
6108 +__attribute__((visibility("hidden"))) int* __errno_location(void) { return &errno; }
6109 +
6110 +static size_t _strlen(const char* s) {
6111 +  size_t i;
6112 +  for (i=0; s[i]; ++i);
6113 +  return i;
6114 +}
6115 +static char* _stpcpy(char* dest,const char* src) {
6116 +  size_t i;
6117 +  for (i=0; src[i]; ++i)
6118 +    dest[i]=src[i];
6119 +  dest[i]=0;
6120 +  return dest+i;
6121 +}
6122 +static char* _strchr(char* s,char c) {
6123 +  size_t i;
6124 +  for (i=0; s[i] && s[i]!=c; ++i) ;
6125 +  if (s[i]==c) return s+i; else return NULL;
6126 +}
6127 +static int _strcmp(const void* str1,const void* str2) {
6128 +  const unsigned char* a=str1;
6129 +  const unsigned char* b=str2;
6130 +  size_t i;
6131 +  int r;
6132 +  for (i=0; (r=(a[i]-b[i]))==0 && a[i]; ++i) ;
6133 +  return r;
6134 +}
6135 +static int _memcmp(const void* dst,const void* src,size_t count) {
6136 +  const unsigned char* a=dst;
6137 +  const unsigned char* b=src;
6138 +  size_t i;
6139 +  int r;
6140 +  for (i=0; i<count && (r=(a[i]-b[i]))==0; ++i) ;
6141 +  return r;
6142 +}
6143 +static void* _memcpy(void* dst,const void* src,size_t len) {
6144 +  char* a=dst;
6145 +  const char* b=src;
6146 +  size_t i;
6147 +  for (i=0; i<len; ++i)
6148 +    a[i]=b[i];
6149 +  return dst;
6150 +}
6151 +static void _memset(void* dst,unsigned char c,size_t len) {
6152 +  unsigned char* a=dst;
6153 +  size_t i;
6154 +  for (i=0; i<len; ++i) a[i]=c;
6155 +}
6156 +static ssize_t __write1(const char* s) {
6157 +  write(1,s,_strlen(s));
6158 +}
6159 +static ssize_t __write2(const char* s) {
6160 +  write(2,s,_strlen(s));
6161 +}
6162 +
6163 +ssize_t write(int fd,const void* buf,size_t len) __attribute__((visibility("hidden")));
6164 +int open(const char* pathname,int flags, ...) __attribute__((visibility("hidden")));
6165 +ssize_t read(int fd,void* buf,size_t len) __attribute__((visibility("hidden")));
6166 +int close(int fd) __attribute__((visibility("hidden")));
6167 +ssize_t pread64(int fd, void *buf, size_t count, off64_t offset) __attribute__((visibility("hidden")));;
6168 +void *mmap(void *__addr, size_t __len, int __prot, int __flags, int __fd, off_t __offset) __attribute__((visibility("hidden")));
6169 +int munmap(void *__addr, size_t __len) __attribute__((visibility("hidden")));
6170 +int mprotect (void *__addr, size_t __len, int __prot) __attribute__((visibility("hidden")));
6171 +void exit(int res) __attribute__((visibility("hidden")));
6172 +
6173 +static struct page {
6174 +  struct page* next;
6175 +  size_t a;
6176 +  char data[4096-sizeof(size_t)-sizeof(struct page*)];
6177 +}* heap;
6178 +
6179 +static void* _malloc(size_t l) {
6180 +  struct page** p;
6181 +  if (l>sizeof(heap->data)) return 0;
6182 +  if (l%(sizeof(void*)*2)) {
6183 +    l += sizeof(void*)*2;
6184 +    l -= l%(sizeof(void*)*2);
6185 +  }
6186 +  for (p=&heap; *p && (*p)->a<l; p=&((*p)->next)) ;
6187 +  if (!*p) {
6188 +    void* tmp=mmap(0,4096,PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
6189 +    if (tmp==MAP_FAILED) return 0;
6190 +    *p=tmp;
6191 +    (*p)->a=sizeof(heap->data);
6192 +  }
6193 +  if (l <= (*p)->a) {
6194 +    char* tmp=(*p)->data+sizeof((*p)->data)-(*p)->a;
6195 +    (*p)->a-=l;
6196 +    return tmp;
6197 +  } else
6198 +    return 0;  // can't happen
6199 +}
6200 +
6201 +static char path[100];
6202 +static char* ldlp;
6203 +
6204 +static struct dll {
6205 +  struct dll* next;
6206 +  ehdr* e;
6207 +  void* code,* data;
6208 +  size_t codelen,datalen,codeplus;
6209 +  char name[1];                // asciiz of library name
6210 +} *dlls, dllroot;
6211 +
6212 +static int map_sections(int fd,const ehdr* e,const phdr* p,struct dll* D) {
6213 +  size_t i;
6214 +  uintptr_t codeplus=0;
6215 +
6216 +  for (i=0; i<e->e_phnum; ++i) {
6217 +    if (p[i].p_type==PT_LOAD) {
6218 +      size_t delta=p[i].p_offset%4096;
6219 +      size_t maplen=p[i].p_filesz+delta;
6220 +      size_t bssdiff=(p[i].p_filesz+delta)%4096;
6221 +      char* c;
6222 +      if ((p[i].p_flags&PF_W) && (p[i].p_flags&PF_X)) {
6223 +       __write2("section is both executable and writable, aborting!\n");
6224 +       return 1;
6225 +      }
6226 +      if (!(p[i].p_flags&PF_W)) {
6227 +       /* code segment */
6228 +       size_t ofs,len,rolen=0,nolen=0,rolen2=0,vaddr=p[i].p_vaddr,baseofs=0;
6229 +       /* the first segment will be the code segment, and it will have
6230 +        * either a fixed address or 0 if it's a shared library. We
6231 +        * insist that the mapping start at file offset 0, and we extend
6232 +        * the mapping so it includes the section table */
6233 +       ofs=p[i].p_offset;
6234 +       len=p[i].p_filesz;
6235 +       if (ofs) {
6236 +         __write2("can't happen error: ofs!=0\n");
6237 +         exit(1);
6238 +         if (vaddr)
6239 +           vaddr-=ofs;
6240 +         else
6241 +           baseofs=ofs;
6242 +         rolen=ofs;
6243 +         len+=ofs;
6244 +         ofs=0;
6245 +       }
6246 +       if (ofs+len < e->e_shoff+e->e_shnum*e->e_shentsize) {
6247 +         size_t needed=e->e_shoff+e->e_shnum*e->e_shentsize;
6248 +         /* if this mapping does not include the section table is not
6249 +          * included, extend the mapping to include it */
6250 +         rolen2=e->e_shnum*e->e_shentsize;
6251 +         if (rolen2>needed-len)
6252 +           /* we were almost there, part of the section table was
6253 +            * already mapped */
6254 +           rolen2=needed-len;
6255 +         else
6256 +           nolen=needed-len-rolen2;
6257 +         /*
6258 +          * +------------------------+
6259 +          * | rolen       e->        | if the mapping did not start at beginning of file, this is the beginning of file, PROT_READ
6260 +          * +------------------------+
6261 +          * | len         base->     | this is the actual mapping, base points here, PROT_READ|PROT_EXEC
6262 +          * +------------------------+
6263 +          * | nolen                  | stuff we don't really need and will mprotect PROT_NONE
6264 +          * +------------------------+
6265 +          * | rolen2      e+e->shoff | the section header table, PROT_READ
6266 +          * +------------------------+
6267 +          */
6268 +       }
6269 +       c=mmap((char*)vaddr,rolen+len+nolen+rolen2,
6270 +                 ((p[i].p_flags&PF_R)?PROT_READ:0) |
6271 +                 ((p[i].p_flags&PF_X)?PROT_EXEC:0),
6272 +                 MAP_SHARED|(vaddr?MAP_FIXED:0),
6273 +                 fd,0);
6274 +       /* in case the can't happen branch ever happens */
6275 +       D->e=(ehdr*)c;
6276 +       D->code=c+rolen; D->codelen=len;
6277 +//     D->s=(shdr*)(c+e->e_shoff);
6278 +       if (rolen>=4096)        /* if we extended the mapping in the front, remove exec permissions */
6279 +         mprotect(c,rolen&~4095,PROT_READ);
6280 +       if (!vaddr && !codeplus) codeplus=(uintptr_t)(c+rolen);
6281 +       if (nolen) {
6282 +         /* We mapped junk in the middle.
6283 +          * If there are full pages in there, map them PROT_NONE */
6284 +         char* start=c+rolen+len;
6285 +         size_t len=nolen;
6286 +         size_t diff=(-(uintptr_t)start & 4095);
6287 +         if (diff < nolen) {
6288 +           /* diff is the part at the beginning we need to skip because
6289 +            * it's on a page we actually need to be executable.
6290 +            * Now find out if we overshoot onto a page we want */
6291 +           size_t removeatend=((uintptr_t)c+rolen+len)&4095;
6292 +           mprotect(start+diff,len-diff-removeatend,PROT_NONE);
6293 +         }
6294 +       }
6295 +       if (rolen2) {
6296 +         /* Now we want to mprotect PROT_READ the section table.
6297 +          * What makes this complex is that mprotect granularity is one
6298 +          * page.  First figure out the region we are interested in. */
6299 +         char* start=c+rolen+len+nolen;
6300 +         size_t len=rolen2;
6301 +         /* we want to mprotect from start to start+len */
6302 +         int diff=((uintptr_t)start)&4095;
6303 +         /* This is the offset of start from the page start.  We need
6304 +          * to mprotect the whole page -- unless it also has code on
6305 +          * it, in which case we need to leave it alone */
6306 +         if (diff > nolen) {
6307 +           size_t roundup=(-(uintptr_t)start)&4095;
6308 +           /* we need to skip the first page. Let's see if there is
6309 +            * anything left in that case */
6310 +           start+=roundup;
6311 +           if (rolen2>roundup)
6312 +             len-=roundup;
6313 +           else
6314 +             len=0;
6315 +         } else {
6316 +           start-=diff;
6317 +           len+=diff;
6318 +         }
6319 +         if (len) mprotect(start,len,PROT_READ);
6320 +       }
6321 +      } else if (p[i].p_flags&PF_W) {  /* data segment */
6322 +       /* We have already mapped the code segment to base.
6323 +        * For programs, the base mapping of the code and data segment
6324 +        * is absolute and we just map there with MAP_FIXED.  For shared
6325 +        * libraries however, the base mapping of the code segment is 0,
6326 +        * and the vaddr of the data segment is not absolute but
6327 +        * relative to the code segment */
6328 +
6329 +       /* The data segment may not start on a page boundary.  Round
6330 +        * start address if necessary. */
6331 +       size_t addr,ofs,len,memsetstart=0,memsetend=0,additional=0;
6332 +       addr=p[i].p_vaddr+codeplus;
6333 +       ofs=p[i].p_offset;
6334 +       len=p[i].p_filesz;
6335 +       if ((memsetstart=(ofs%4096))) {
6336 +         len+=memsetstart;
6337 +         ofs-=memsetstart;
6338 +         addr-=memsetstart;
6339 +       }
6340 +
6341 +       /* The data segment consists of actual data, but a part of it is
6342 +        * data initialized to 0, the .bss section.  This section is not
6343 +        * actually put in the file to save space, but the ELF loader
6344 +        * (that's us) is expected to allocate that data at program
6345 +        * start. */
6346 +       memsetend=p[i].p_memsz-p[i].p_filesz;
6347 +       if (memsetend) {
6348 +         /* We have a .bss.  We need to handle two cases.  First: if
6349 +          * the number of bytes is small enough to fit on the last page
6350 +          * we already mapped for the data, all we need to do is memset
6351 +          * it.  Otherwise we needto memset the rest of that page and
6352 +          * map some additional pages after it. */
6353 +         size_t bytes_on_last_page=(-len)&4095;
6354 +         if (memsetend<bytes_on_last_page)
6355 +           len+=memsetend;
6356 +         else {
6357 +           len+=bytes_on_last_page;
6358 +           additional=memsetend-bytes_on_last_page;
6359 +           memsetend=bytes_on_last_page;
6360 +         }
6361 +       }
6362 +
6363 +       c=mmap((char*)addr,len,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,fd,ofs);
6364 +       if (c==MAP_FAILED) {
6365 +         __write2("mmap failed!\n");
6366 +         return 1;
6367 +       }
6368 +
6369 +       if (memsetstart) _memset(c,0,memsetstart);
6370 +       if (memsetend) _memset(c+len-memsetend,0,memsetend);
6371 +       if (additional) {
6372 +         char* tmp=mmap(c+len,additional,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);
6373 +         if (tmp==MAP_FAILED) {
6374 +           __write2("mmap failed!\n");
6375 +           return 1;
6376 +         }
6377 +       }
6378 +       D->data=c+memsetstart; D->datalen=len-memsetstart;
6379 +       D->codeplus=codeplus;
6380 +      } else {
6381 +       __write2("can't happen error: LOAD segment that is neither code nor data.\n");
6382 +       return 1;
6383 +      }
6384 +    }
6385 +  }
6386 +  return 0;
6387 +}
6388 +
6389 +
6390 +static int __loadlibrary(const char* fn) {
6391 +  struct dll* D;
6392 +  int fd;
6393 +  char buf[1000];
6394 +  ehdr* e;
6395 +  phdr* p;
6396 +  shdr* s;
6397 +  size_t i;
6398 +  char* code=0,* data=0;
6399 +  char* base=0;
6400 +  size_t codelen,datalen;
6401 +#if 0
6402 +  __write1("trying ");
6403 +  __write1(fn);
6404 +  __write1("\n");
6405 +#endif
6406 +  fd=open(fn,O_RDONLY);
6407 +  if (fd==-1) return -1;
6408 +  if (read(fd,buf,1000)<1000) {
6409 +kaputt:
6410 +    close(fd);
6411 +    return -1;
6412 +  }
6413 +  if (_memcmp(buf,"\177ELF",4)) goto kaputt;
6414 +  e=(ehdr*)buf;
6415 +
6416 +  if (e->e_ident[4] != (sizeof(size_t)/4) ||   // wrong word size
6417 +      e->e_type != ET_DYN ||                   // not shared object
6418 +      e->e_machine !=                          // for different architecture
6419 +#if defined(__x86_64__)
6420 +       EM_X86_64
6421 +#elif defined(__i386__)
6422 +       EM_386
6423 +#else
6424 +#error architecture not recognized, please add
6425 +#endif
6426 +                                ||
6427 +      e->e_phentsize != sizeof(phdr) ||                // wrong program header entry size
6428 +      e->e_phnum > 20 ||                       // too many program header entries
6429 +      e->e_shentsize !=sizeof(shdr) ||         // wrong section header entry size
6430 +      e->e_shnum > 100)                                // too many sections
6431 +    goto kaputt;
6432 +
6433 +
6434 +  if (e->e_phoff>=1000 || e->e_phentsize*e->e_phnum>1000-e->e_phoff) {
6435 +    size_t wanted=e->e_phentsize*e->e_phnum;
6436 +    p=alloca(wanted);
6437 +    if (pread64(fd,p,wanted,e->e_phoff)!=wanted)
6438 +      goto kaputt;
6439 +  } else
6440 +    p=(phdr*)(buf+e->e_phoff);
6441 +
6442 +  struct dll dll;
6443 +  if (map_sections(fd,e,p,&dll)) {
6444 +    __write2("map_sections failed\n");
6445 +    goto kaputt;
6446 +  }
6447 +
6448 +  close(fd);
6449 +
6450 +  {
6451 +    const char* tmp;
6452 +    for (i=0; fn[i]; ++i)
6453 +      if (fn[i]=='/') tmp=fn+i;
6454 +    ++tmp;
6455 +    D=_malloc(sizeof(struct dll)+_strlen(tmp));
6456 +    _stpcpy(D->name,tmp);
6457 +  }
6458 +  D->next=0;
6459 +  D->code=dll.code; D->codelen=dll.codelen;
6460 +  D->data=dll.data; D->datalen=dll.datalen;
6461 +//  D->s=dll.s;
6462 +  D->e=dll.e;
6463 +  D->codeplus=dll.codeplus;
6464 +  {
6465 +    struct dll** x;
6466 +    for (x=&dlls; *x; x=&(*x)->next) ;
6467 +    *x=D;
6468 +  }
6469 +  return 0;
6470 +}
6471 +
6472 +static int loadlibrary(const char* fn) {
6473 +  char lp[200];
6474 +  int r;
6475 +  char* c;
6476 +  const char* shortname=fn;
6477 +  struct dll* d;
6478 +
6479 +  {
6480 +    size_t i;
6481 +    for (i=0; fn[i]; ++i)
6482 +      if (fn[i]=='/') shortname=fn+i+1;
6483 +  }
6484 +
6485 +  if (_strlen(fn)>50) return -1;
6486 +  for (d=dlls; d; d=d->next)
6487 +    if (!_strcmp(d->name,shortname))
6488 +      return 0;
6489 +
6490 +  __write1("loadlibrary(\"");
6491 +  __write1(fn);
6492 +  __write1("\")\n");
6493 +  if (fn[0]=='/') {
6494 +    return __loadlibrary(fn);
6495 +  }
6496 +
6497 +  c=_stpcpy(lp,path);
6498 +  *c++='/';
6499 +  _stpcpy(c,fn);
6500 +  r=__loadlibrary(lp);
6501 +  if (r==0) return r;
6502 +  if (ldlp) {
6503 +    size_t i;
6504 +    char* d;
6505 +    c=ldlp;
6506 +    for (i=0; ; ++i) {
6507 +again:
6508 +      if (c[i]==':' || c[i]==0) {
6509 +       if (i<100) {
6510 +         lp[i]='/';
6511 +         _stpcpy(lp+i+1,fn);
6512 +         r=__loadlibrary(lp);
6513 +         if (r==0) return;
6514 +       }
6515 +       if (c[i]==0) break;
6516 +       c+=i+1; i=0; goto again;
6517 +      } else
6518 +       if (i<100) lp[i]=c[i];
6519 +    }
6520 +  }
6521 +  return r;
6522 +}
6523 +
6524 +static int loadlibs(struct dll* D) {
6525 +  size_t i;
6526 +  phdr* p=(phdr*)((char*)D->e+D->e->e_phoff);
6527 +  dyn* d;
6528 +  size_t dnum,dynstrlen;
6529 +  char* dynstr;
6530 +
6531 +  /* we know we have exactly one code and exactly one data segment,
6532 +   * otherwise we wouldn't have gotten this far */
6533 +  for (i=0; i<D->e->e_phnum; ++i)
6534 +    if (p[i].p_type==PT_DYNAMIC) {
6535 +      d=(dyn*)((char*)p[i].p_vaddr+D->codeplus);
6536 +      dnum=p[i].p_memsz/sizeof(dyn);
6537 +      break;
6538 +    }
6539 +  for (i=0; i<dnum; ++i)
6540 +    if (d[i].d_tag==DT_STRTAB) {
6541 +      dynstr=(char*)d[i].d_un.d_ptr+D->codeplus;
6542 +      break;
6543 +    } else if (d[i].d_tag==DT_NULL)
6544 +      break;
6545 +
6546 +  /* we now have a dynamic section we can traverse */
6547 +  for (i=0; i<dnum; ++i) {
6548 +    if (d[i].d_tag==DT_NEEDED) {
6549 +      if (loadlibrary(dynstr+d[i].d_un.d_val)) {
6550 +       __write2("library ");
6551 +       __write2(dynstr+d[i].d_un.d_val);
6552 +       __write2(" not found!\n");
6553 +       exit(2);
6554 +      }
6555 +    } else if (d[i].d_tag==DT_NULL)
6556 +      break;
6557 +  }
6558 +
6559 +  return 0;
6560 +}
6561 +
6562 +static unsigned int elf_hash(const unsigned char *name) {
6563 +  unsigned int h=0, g;
6564 +
6565 +  while (*name) {
6566 +    h = (h<<4) + *(name++);
6567 +    if ((g = h&0xf0000000)) h ^= g>>24;
6568 +    h ^= g;
6569 +  }
6570 +  return h;
6571 +}
6572 +
6573 +static uint_fast32_t gnu_hash(const unsigned char *s) {
6574 +  unsigned char c;
6575 +  uint_fast32_t h=5381;
6576 +  for(c=*s;(c!='\0');c=*++s) {
6577 +//    h=h*33+c;
6578 +    h=((h<<5)+h)+c;
6579 +  }
6580 +  return (h&0xffffffff);
6581 +}
6582 +
6583 +static char* dlsym_int(const char* symbol,struct dll* x) {
6584 +  for (; x; x=x->next) {
6585 +    size_t i;
6586 +    dyn* d;
6587 +    sym* sy;
6588 +    phdr* p=(phdr*)(x->e->e_phoff+(char*)x->e);
6589 +    const char* strtab;
6590 +    size_t dnum;
6591 +    int* hash=0;
6592 +    for (i=0; i<x->e->e_phnum; ++i)
6593 +      if (p[i].p_type==PT_DYNAMIC) {
6594 +       d=(dyn*)(x->codeplus + p[i].p_vaddr);
6595 +       dnum=p[i].p_memsz/sizeof(dyn);
6596 +       break;
6597 +      }
6598 +
6599 +    for (i=0; i<dnum; ++i) {
6600 +      if (d[i].d_tag == DT_HASH)
6601 +       hash=(int*)((char*)x->codeplus + d[i].d_un.d_ptr);
6602 +      else if (d[i].d_tag == DT_SYMTAB)
6603 +       sy=(sym*)((char*)(x->codeplus+d[i].d_un.d_ptr));
6604 +      else if (d[i].d_tag == DT_STRTAB)
6605 +       strtab=(char*)(x->codeplus+d[i].d_un.d_ptr);
6606 +    }
6607 +
6608 +    /* hash[0] is the number of buckets. */
6609 +    /* hash[1] is the hash chain length, not used here */
6610 +    size_t bhash=elf_hash(symbol)%hash[0];
6611 +    unsigned int* chain=hash+2+hash[0];
6612 +    unsigned int index;
6613 +    for (index=(hash+2)[bhash]; index; index=chain[index]) {
6614 +#if 0
6615 +      __write1(strtab+sy[index].st_name); __write1("\n");
6616 +#endif
6617 +      if (sy[index].st_value && sy[index].st_shndx!=SHN_UNDEF && !_strcmp(strtab+sy[index].st_name,symbol)) {
6618 +       return (char*)x->codeplus+sy[index].st_value;
6619 +      }
6620 +    }
6621 +#if 0
6622 +    if (x->next) {
6623 +      __write1(" ... next: ");
6624 +      __write1(x->next->name);
6625 +      __write1("\n");
6626 +    }
6627 +#endif
6628 +  }
6629 +  return 0;
6630 +}
6631 +
6632 +static void* dlsym(const char* s) {
6633 +  return dlsym_int(s,&dllroot);
6634 +}
6635 +
6636 +static void* _dlsym(const char* s) {
6637 +  void* x=dlsym(s);
6638 +  if (!x) {
6639 +    __write2("ld.so: lookup of symbol \"");
6640 +    __write2(s);
6641 +    __write2("\" failed.\n");
6642 +//    exit(1);
6643 +  }
6644 +  return x;
6645 +}
6646 +
6647 +static void resolve(struct dll* D) {
6648 +  size_t i;
6649 +  phdr* p=(phdr*)((char*)D->e+D->e->e_phoff);
6650 +  dyn* d=0;
6651 +  size_t dnum,dynstrlen,rnum=0;
6652 +  char* dynstr=0, *pltgot=0, *pltrel=0;
6653 +  rela* r=0;
6654 +  sym* symtab=0;
6655 +
6656 +  /* we know we have exactly one code and exactly one data segment,
6657 +   * otherwise we wouldn't have gotten this far */
6658 +  for (i=0; i<D->e->e_phnum; ++i)
6659 +    if (p[i].p_type==PT_DYNAMIC) {
6660 +      d=(dyn*)((char*)p[i].p_vaddr+D->codeplus);
6661 +      dnum=p[i].p_memsz/sizeof(dyn);
6662 +      break;
6663 +    }
6664 +  for (i=0; i<dnum; ++i)
6665 +    if (d[i].d_tag==DT_STRTAB)
6666 +      dynstr=(char*)d[i].d_un.d_ptr+D->codeplus;
6667 +    else if (d[i].d_tag==DT_RELA)
6668 +      r=(rela*)((char*)d[i].d_un.d_ptr+D->codeplus);
6669 +    else if (d[i].d_tag==DT_RELASZ)
6670 +      rnum=d[i].d_un.d_val/sizeof(rela);
6671 +    else if (d[i].d_tag==DT_SYMTAB)
6672 +      symtab=(sym*)((char*)d[i].d_un.d_ptr+D->codeplus);
6673 +    else if (d[i].d_tag==0)
6674 +      break;
6675 +
6676 +  for (i=0; i<rnum; ++i) {
6677 +    size_t* x=(size_t*)((char*)(r[i].r_offset+D->codeplus));
6678 +    char* y;
6679 +    size_t sym=R_SYM(r[i].r_info);
6680 +    switch (R_TYPE(r[i].r_info)) {
6681 +#if defined(__x86_64__)
6682 +    case R_X86_64_64:
6683 +      *x=D->codeplus+symtab[sym].st_value;
6684 +      break;
6685 +    case R_X86_64_COPY:
6686 +      y=dlsym_int(symtab[sym].st_name+dynstr,D->next);
6687 +      if (!y && ELF32_ST_BIND(symtab[sym].st_info) != STB_WEAK) {
6688 +       __write2("symbol lookup failed: ");
6689 +       __write2(dynstr+symtab[sym].st_name);
6690 +       __write2("\n");
6691 +       exit(1);
6692 +      }
6693 +      _memcpy(x,y,symtab[sym].st_size);
6694 +      break;
6695 +    case R_X86_64_GLOB_DAT:
6696 +    case R_X86_64_JUMP_SLOT:
6697 +      y=dlsym(symtab[sym].st_name+dynstr);
6698 +      if (!y && ELF32_ST_BIND(symtab[sym].st_info) != STB_WEAK) {
6699 +       __write2("symbol lookup failed: ");
6700 +       __write2(dynstr+symtab[sym].st_name);
6701 +       __write2("\n");
6702 +       exit(1);
6703 +      }
6704 +      *x=(uintptr_t)y;
6705 +      break;
6706 +    case R_X86_64_RELATIVE:
6707 +      *x=r[i].r_addend+D->codeplus;
6708 +      break;
6709 +    case R_X86_64_32:
6710 +      *(uint32_t*)x=*(uint32_t*)_dlsym(symtab[sym].st_name+dynstr)+r[i].r_addend;
6711 +      break;
6712 +    default:
6713 +      __write2("unknown relocation type!\n");
6714 +      exit(1);
6715 +      break;
6716 +#else
6717 +#error fixme: add relocation types for your platform
6718 +#endif
6719 +    }
6720 +  }
6721 +
6722 +  return;
6723 +}
6724 +
6725 +int main(int argc,char* argv[],char* envp[]) {
6726 +  int fd;
6727 +  size_t l;
6728 +  char* m;
6729 +  char buf[1000];
6730 +  ehdr* e;
6731 +  phdr* p;
6732 +  phdr* code=0,* data=0;
6733 +  shdr* s;
6734 +  dyn* d;
6735 +  size_t dnum;
6736 +  char* dynstr;
6737 +  size_t dynstrlen;
6738 +  size_t i;
6739 +
6740 +#if 0
6741 +  {
6742 +    fd=open("/proc/self/maps",O_RDONLY);
6743 +    if (fd!=-1) {
6744 +      size_t l;
6745 +      do {
6746 +       l=read(fd,buf,sizeof(buf));
6747 +       write(1,buf,l);
6748 +      } while (l==sizeof(buf));
6749 +      close(fd);
6750 +    }
6751 +  }
6752 +#endif
6753 +  if (argc<2) {
6754 +    __write2("usage: ld.so /path/to/binary\n");
6755 +    return 0;
6756 +  }
6757 +  fd=open("/etc/diet.ld.conf",O_RDONLY);
6758 +  if (fd!=-1) {
6759 +    int r=read(fd,path,99);
6760 +    if (r>0) path[r]=0;
6761 +    while (r>0 && path[r-1]=='\n') path[--r]=0;
6762 +    close(fd);
6763 +  }
6764 +  for (i=0; envp[i]; ++i) {
6765 +    if (_memcmp(envp[i],"LD_LIBRARY_PATH=",16)==0)
6766 +      ldlp=envp[i]+16;
6767 +  }
6768 +  fd=open(argv[1],O_RDONLY);
6769 +  if (fd==-1) {
6770 +    __write2("could not open \"");
6771 +    __write2(argv[1]);
6772 +    __write2("\".\n");
6773 +    return 1;
6774 +  }
6775 +  l=read(fd,buf,1000);
6776 +  if (l<sizeof(ehdr) || _memcmp(buf,"\177ELF",4)) {
6777 +kaputt:
6778 +    __write2("invalid ELF file \"");
6779 +    close(fd);
6780 +    return 1;
6781 +  }
6782 +  e=(ehdr*)buf;
6783 +
6784 +  if (e->e_ident[4] != (sizeof(size_t)/4)) {
6785 +    __write2("wrong word size!\n");
6786 +    return 1;
6787 +  }
6788 +#if 0
6789 +  if (e->e_ident[7] != ELFOSABI_LINUX) {
6790 +    __write2("ABI not Linux!\n");
6791 +    return 1;
6792 +  }
6793 +#endif
6794 +  if (e->e_type != ET_EXEC) {
6795 +    __write2("not an executable!\n");
6796 +    return 1;
6797 +  }
6798 +  if (e->e_machine !=
6799 +#if defined(__x86_64__)
6800 +      EM_X86_64
6801 +#elif defined(__i386__)
6802 +      EM_386
6803 +#else
6804 +#error architecture not recognized, please add
6805 +#endif
6806 +     ) {
6807 +    __write2("invalid architecture!\n");
6808 +    return 1;
6809 +  }
6810 +
6811 +  if (e->e_phentsize != sizeof(phdr)) {
6812 +    __write2("invalid phentsize!\n");
6813 +    return 1;
6814 +  }
6815 +  if (e->e_phnum > 20) {
6816 +    __write2("phnum too large!\n");
6817 +    return 1;
6818 +  }
6819 +  if (e->e_shentsize != sizeof(shdr)) {
6820 +    __write2("invalid shentsize!\n");
6821 +    return 1;
6822 +  }
6823 +  if (e->e_shnum > 100) {
6824 +    __write2("shnum too large!\n");
6825 +    return 1;
6826 +  }
6827 +
6828 +  if (e->e_phoff>=l || e->e_phentsize*e->e_phnum>l-e->e_phoff) {
6829 +    size_t wanted=e->e_phentsize*e->e_phnum;
6830 +    p=alloca(wanted);
6831 +    if (pread64(fd,p,wanted,e->e_phoff)!=wanted)
6832 +      goto kaputt;
6833 +  } else
6834 +    p=(phdr*)(buf+e->e_phoff);
6835 +
6836 +  dlls=&dllroot;
6837 +  if (map_sections(fd,e,p,&dllroot)) {
6838 +    __write2("map_sections failed!\n");
6839 +    return 1;
6840 +  }
6841 +  close(fd);
6842 +
6843 +  loadlibs(&dllroot);
6844 +
6845 +  /* now load the prerequisites of the libraries we loaded */
6846 +  {
6847 +    struct dll* x;
6848 +    for (x=dlls; x; x=x->next) {
6849 +      loadlibs(x);
6850 +    }
6851 +  }
6852 +
6853 +  resolve(&dllroot);
6854 +
6855 +  __write2("jumping...\n");
6856 +
6857 +  {
6858 +    int (*_init)(int argc,char* argv[],char* envp[])=(void*)(e->e_entry+dllroot.codeplus);
6859 +    return _init(argc,argv,envp);
6860 +  }
6861 +#if 0
6862 +  {
6863 +    char* x=dlsym("theint");
6864 +    __write1("done\n");
6865 +  }
6866 +#endif
6867 +
6868 +#if 0
6869 +  printf("jump to %p\n",e->e_entry);
6870 +  for (i=0; i<16; ++i) {
6871 +    printf("%02x ",((unsigned char*)e->e_entry)[i]);
6872 +  }
6873 +#endif
6874 +
6875 +  return 0;
6876 +}
6877 diff -urN -x .git dietlibc-0.33/lib/alloc.c dietlibc/lib/alloc.c
6878 --- dietlibc-0.33/lib/alloc.c   2007-10-17 11:47:57.000000000 +0000
6879 +++ dietlibc/lib/alloc.c        2015-01-01 12:14:43.481605561 +0000
6880 @@ -18,8 +18,7 @@
6881  #include <stdlib.h>
6882  #include <string.h>
6883  
6884 -#include <sys/shm.h>   /* for PAGE_SIZE */
6885 -
6886 +#include "../dietpagesize.h"
6887  
6888  /* -- HELPER CODE --------------------------------------------------------- */
6889  
6890 @@ -39,7 +38,7 @@
6891  #define BLOCK_START(b) (((void*)(b))-sizeof(__alloc_t))
6892  #define BLOCK_RET(b)   (((void*)(b))+sizeof(__alloc_t))
6893  
6894 -#define MEM_BLOCK_SIZE PAGE_SIZE
6895 +#define MEM_BLOCK_SIZE __DIET_PAGE_SIZE
6896  #define PAGE_ALIGN(s)  (((s)+MEM_BLOCK_SIZE-1)&(unsigned long)(~(MEM_BLOCK_SIZE-1)))
6897  
6898  /* a simple mmap :) */
6899 @@ -66,7 +65,9 @@
6900  
6901  #define FIRST_SMALL(p)         (((unsigned long)(p))&(~(MEM_BLOCK_SIZE-1)))
6902  
6903 -static inline int __ind_shift() { return (MEM_BLOCK_SIZE==4096)?4:5; }
6904 +static inline int __ind_shift() {
6905 +       return __DIET_PAGE_SHIFT - sizeof(__small_mem)/sizeof(__small_mem[0]);
6906 +}
6907  
6908  static size_t REGPARM(1) get_index(size_t _size) {
6909    register size_t idx=0;
6910 @@ -143,7 +144,6 @@
6911  }
6912  void __libc_free(void *ptr) __attribute__((alias("_alloc_libc_free")));
6913  void free(void *ptr) __attribute__((weak,alias("_alloc_libc_free")));
6914 -void if_freenameindex(void* ptr) __attribute__((alias("free")));
6915  
6916  #ifdef WANT_MALLOC_ZERO
6917  static __alloc_t zeromem[2];
6918 diff -urN -x .git dietlibc-0.33/lib/call_once.c dietlibc/lib/call_once.c
6919 --- dietlibc-0.33/lib/call_once.c       1970-01-01 00:00:00.000000000 +0000
6920 +++ dietlibc/lib/call_once.c    2015-01-01 12:14:43.481605561 +0000
6921 @@ -0,0 +1,6 @@
6922 +#include <threads.h>
6923 +
6924 +void call_once(once_flag* flag, void (*func)(void)) {
6925 +  if (__sync_bool_compare_and_swap(flag,0,1))
6926 +    func();
6927 +}
6928 diff -urN -x .git dietlibc-0.33/lib/closedir.c dietlibc/lib/closedir.c
6929 --- dietlibc-0.33/lib/closedir.c        2002-07-03 20:33:37.000000000 +0000
6930 +++ dietlibc/lib/closedir.c     2015-01-01 12:14:43.484938895 +0000
6931 @@ -4,8 +4,10 @@
6932  #include <dirent.h>
6933  #include <stdlib.h>
6934  
6935 +#include "../dietpagesize.h"
6936 +
6937  int closedir (DIR* d) {
6938    int res=close(d->fd);
6939 -  munmap (d, PAGE_SIZE);
6940 +  munmap (d, __DIET_PAGE_SIZE);
6941    return res;
6942  }
6943 diff -urN -x .git dietlibc-0.33/lib/cnd_broadcast.c dietlibc/lib/cnd_broadcast.c
6944 --- dietlibc-0.33/lib/cnd_broadcast.c   1970-01-01 00:00:00.000000000 +0000
6945 +++ dietlibc/lib/cnd_broadcast.c        2015-01-01 12:14:43.484938895 +0000
6946 @@ -0,0 +1,8 @@
6947 +#include <threads.h>
6948 +#include <sys/futex.h>
6949 +
6950 +int cnd_broadcast(cnd_t* cond) {
6951 +  cond->sem=1;
6952 +  futex(&cond->sem,FUTEX_WAKE,0x7fffffff,0,0,0);
6953 +  return thrd_success;
6954 +}
6955 diff -urN -x .git dietlibc-0.33/lib/cnd_destroy.c dietlibc/lib/cnd_destroy.c
6956 --- dietlibc-0.33/lib/cnd_destroy.c     1970-01-01 00:00:00.000000000 +0000
6957 +++ dietlibc/lib/cnd_destroy.c  2015-01-01 12:14:43.484938895 +0000
6958 @@ -0,0 +1,6 @@
6959 +#include <threads.h>
6960 +
6961 +void cnd_destroy(cnd_t* cond) {
6962 +  // no need to do anything
6963 +  (void)cond;
6964 +}
6965 diff -urN -x .git dietlibc-0.33/lib/cnd_init.c dietlibc/lib/cnd_init.c
6966 --- dietlibc-0.33/lib/cnd_init.c        1970-01-01 00:00:00.000000000 +0000
6967 +++ dietlibc/lib/cnd_init.c     2015-01-01 12:14:43.484938895 +0000
6968 @@ -0,0 +1,6 @@
6969 +#include <threads.h>
6970 +
6971 +int cnd_init(cnd_t* cond) {
6972 +  cond->sem=0;
6973 +  return thrd_success;
6974 +}
6975 diff -urN -x .git dietlibc-0.33/lib/cnd_signal.c dietlibc/lib/cnd_signal.c
6976 --- dietlibc-0.33/lib/cnd_signal.c      1970-01-01 00:00:00.000000000 +0000
6977 +++ dietlibc/lib/cnd_signal.c   2015-01-01 12:14:43.484938895 +0000
6978 @@ -0,0 +1,8 @@
6979 +#include <threads.h>
6980 +#include <sys/futex.h>
6981 +
6982 +int cnd_signal(cnd_t* cond) {
6983 +  cond->sem=1;
6984 +  futex(&cond->sem,FUTEX_WAKE,1,0,0,0);
6985 +  return thrd_success;
6986 +}
6987 diff -urN -x .git dietlibc-0.33/lib/cnd_timedwait.c dietlibc/lib/cnd_timedwait.c
6988 --- dietlibc-0.33/lib/cnd_timedwait.c   1970-01-01 00:00:00.000000000 +0000
6989 +++ dietlibc/lib/cnd_timedwait.c        2015-01-01 12:14:43.484938895 +0000
6990 @@ -0,0 +1,17 @@
6991 +#include <threads.h>
6992 +#include <sys/futex.h>
6993 +#include <errno.h>
6994 +
6995 +int cnd_timedwait(cnd_t* cond, mtx_t* mutex, const struct timespec* time_point) {
6996 +  int r;
6997 +  do {
6998 +    r=futex(&cond->sem,FUTEX_WAIT,0,time_point,0,0);
6999 +    if (r==-1) {
7000 +      if (errno==EWOULDBLOCK) { r=0; break; }
7001 +      else if (errno==EINTR) continue;
7002 +    } else
7003 +      break;
7004 +  } while (r==0);
7005 +  cond->sem=0;
7006 +  return mtx_timedlock(mutex,time_point);
7007 +}
7008 diff -urN -x .git dietlibc-0.33/lib/cnd_wait.c dietlibc/lib/cnd_wait.c
7009 --- dietlibc-0.33/lib/cnd_wait.c        1970-01-01 00:00:00.000000000 +0000
7010 +++ dietlibc/lib/cnd_wait.c     2015-01-01 12:14:43.484938895 +0000
7011 @@ -0,0 +1,7 @@
7012 +#include <threads.h>
7013 +#include <sys/futex.h>
7014 +#include <errno.h>
7015 +
7016 +int cnd_wait(cnd_t* cond, mtx_t* mutex) {
7017 +  return cnd_timedwait(cond,mutex,0);
7018 +}
7019 diff -urN -x .git dietlibc-0.33/lib/__dtostr.c dietlibc/lib/__dtostr.c
7020 --- dietlibc-0.33/lib/__dtostr.c        2006-09-14 16:29:22.000000000 +0000
7021 +++ dietlibc/lib/__dtostr.c     2015-01-01 12:14:43.481605561 +0000
7022 @@ -5,13 +5,15 @@
7023  
7024  static int copystring(char* buf,int maxlen, const char* s) {
7025    int i;
7026 -  for (i=0; i<3&&i<maxlen; ++i)
7027 +  for (i=0; i<maxlen; ++i) {
7028      buf[i]=s[i];
7029 -  if (i<maxlen) { buf[i]=0; ++i; }
7030 +    if (!s[i])
7031 +      break;
7032 +  }
7033    return i;
7034  }
7035  
7036 -int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int g) {
7037 +int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int flags) {
7038  #if 1
7039    union {
7040      unsigned long long l;
7041 @@ -35,8 +37,12 @@
7042    double tmp;
7043    char *oldbuf=buf;
7044  
7045 -  if ((i=isinf(d))) return copystring(buf,maxlen,i>0?"inf":"-inf");
7046 -  if (isnan(d)) return copystring(buf,maxlen,"nan");
7047 +  if (isinf(d))
7048 +    return copystring(buf,maxlen,
7049 +                     (d<0)?
7050 +                     (flags&0x02?"-INF":"-inf"):
7051 +                     (flags&0x02?"INF":"inf"));
7052 +  if (isnan(d)) return copystring(buf,maxlen,flags&0x02?"NAN":"nan");
7053    e10=1+(long)(e*0.30102999566398119802); /* log10(2) */
7054    /* Wir iterieren von Links bis wir bei 0 sind oder maxlen erreicht
7055     * ist.  Wenn maxlen erreicht ist, machen wir das nochmal in
7056 @@ -126,7 +132,7 @@
7057    if (prec2 || prec>(unsigned int)(buf-oldbuf)+1) {    /* more digits wanted */
7058      if (!maxlen) return 0; --maxlen;
7059      *buf='.'; ++buf;
7060 -    if (g) {
7061 +    if ((flags & 0x01)) {
7062        if (prec2) prec=prec2;
7063        prec-=buf-oldbuf-1;
7064      } else {
7065 diff -urN -x .git dietlibc-0.33/lib/errno.c dietlibc/lib/errno.c
7066 --- dietlibc-0.33/lib/errno.c   1970-01-01 00:00:00.000000000 +0000
7067 +++ dietlibc/lib/errno.c        2015-01-01 12:14:43.484938895 +0000
7068 @@ -0,0 +1,3 @@
7069 +#define extern
7070 +
7071 +#include "errno_definition.h"
7072 diff -urN -x .git dietlibc-0.33/lib/errno_location.c dietlibc/lib/errno_location.c
7073 --- dietlibc-0.33/lib/errno_location.c  2001-06-07 12:29:35.000000000 +0000
7074 +++ dietlibc/lib/errno_location.c       2015-01-01 12:14:43.484938895 +0000
7075 @@ -1,5 +1,7 @@
7076 -extern int errno;
7077 +#include <sys/tls.h>
7078 +#include <threads.h>
7079 +#include <errno.h>
7080  
7081 -int *__errno_location(void) __attribute__((weak));
7082 -int *__errno_location() { return &errno; }
7083 +// int *__errno_location(void) __attribute__((weak));
7084 +__attribute__((weak)) int *__errno_location(void) { return &errno; }
7085  
7086 diff -urN -x .git dietlibc-0.33/lib/eventfd.c dietlibc/lib/eventfd.c
7087 --- dietlibc-0.33/lib/eventfd.c 1970-01-01 00:00:00.000000000 +0000
7088 +++ dietlibc/lib/eventfd.c      2015-01-01 12:14:43.484938895 +0000
7089 @@ -0,0 +1,21 @@
7090 +#include <sys/types.h>
7091 +#include <fcntl.h>
7092 +#include <errno.h>
7093 +#include <sys/eventfd.h>
7094 +
7095 +extern int __eventfd(unsigned int count);
7096 +extern int __eventfd2(unsigned int count,int flags);
7097 +
7098 +int eventfd(unsigned int count,int flags) {
7099 +  int r=__eventfd2(count,flags);
7100 +  if (r==-1 && errno==ENOSYS) {
7101 +    r=__eventfd(count);
7102 +    if (r!=-1 && flags) {
7103 +      int x;
7104 +      x=fcntl(r,F_SETFD,flags);
7105 +      if (x==-1)
7106 +       close(r);
7107 +    }
7108 +  }
7109 +  return r;
7110 +}
7111 diff -urN -x .git dietlibc-0.33/lib/fdopendir.c dietlibc/lib/fdopendir.c
7112 --- dietlibc-0.33/lib/fdopendir.c       2012-01-15 19:20:56.000000000 +0000
7113 +++ dietlibc/lib/fdopendir.c    2015-01-01 12:14:43.484938895 +0000
7114 @@ -1,4 +1,5 @@
7115  #include "dietdirent.h"
7116 +#include "dietpagesize.h"
7117  #include <sys/mman.h>
7118  #include <unistd.h>
7119  #include <dirent.h>
7120 @@ -9,12 +10,9 @@
7121    DIR*  t  = NULL;
7122  
7123    if ( fd >= 0 ) {
7124 -    t = (DIR *) mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, 
7125 +    t = (DIR *) mmap (NULL, __DIET_PAGE_SIZE, PROT_READ | PROT_WRITE,
7126                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
7127 -    if (t == MAP_FAILED)
7128 -lose:
7129 -      close (fd);
7130 -    else
7131 +    if (t != MAP_FAILED)
7132        t->fd = fd;
7133    }
7134  
7135 diff -urN -x .git dietlibc-0.33/lib/__get_cur_tcb.c dietlibc/lib/__get_cur_tcb.c
7136 --- dietlibc-0.33/lib/__get_cur_tcb.c   1970-01-01 00:00:00.000000000 +0000
7137 +++ dietlibc/lib/__get_cur_tcb.c        2015-01-01 12:14:43.481605561 +0000
7138 @@ -0,0 +1,26 @@
7139 +#include <sys/tls.h>
7140 +
7141 +tcbhead_t* __get_cur_tcb(void) {
7142 +#if defined(__alpha__)
7143 +  register void* cur asm("$0");
7144 +  asm("call_pal 158" : "=r"(cur) );    /* PAL_rduniq = 158 */
7145 +#else  /* alpha */
7146 +  register void* cur=0;
7147 +#if defined(__sparc__)
7148 +  asm("mov %%g6,%0" : "=r"(cur) );     /* %g6 (res. system use) is used as thread pointer */
7149 +#elif defined(__s390__)
7150 +  asm("ear %0,%%a0" : "=d"(cur) );     /* a0 (access register 0) is used as thread pointer */
7151 +#elif defined(__ia64__)
7152 +  asm("mov %0 = r13" : "=r"(cur) );    /* r13 (tp) is used as thread pointer */
7153 +#elif defined(__x86_64__)
7154 +#ifdef __ILP32__
7155 +  asm("movl %%fs:(0),%0" : "=r"(cur));
7156 +#else
7157 +  asm("movq %%fs:(0),%0" : "=r"(cur));
7158 +#endif
7159 +#elif defined(__i386__)
7160 +  asm("movl %%gs:(0),%0" : "=r"(cur));
7161 +#endif
7162 +#endif /* __alpha__ */
7163 +  return cur;
7164 +}
7165 diff -urN -x .git dietlibc-0.33/lib/__get_elf_aux_value.c dietlibc/lib/__get_elf_aux_value.c
7166 --- dietlibc-0.33/lib/__get_elf_aux_value.c     1970-01-01 00:00:00.000000000 +0000
7167 +++ dietlibc/lib/__get_elf_aux_value.c  2015-01-01 12:14:43.481605561 +0000
7168 @@ -0,0 +1,19 @@
7169 +#include "dietfeatures.h"
7170 +
7171 +#ifdef WANT_ELFINFO
7172 +#include <stdlib.h>
7173 +#include "../dietelfinfo.h"
7174 +
7175 +__diet_elf_addr_t const *__get_elf_aux_value(unsigned int tag)
7176 +{
7177 +  extern __diet_elf_addr_t const * const       __elfinfo;
7178 +  __diet_elf_addr_t const                      *aux_ptr;
7179 +
7180 +  for (aux_ptr = __elfinfo; aux_ptr[0]!=AT_NULL; aux_ptr += 2)
7181 +    if (aux_ptr[0]==tag)
7182 +      return aux_ptr+1;
7183 +
7184 +  return NULL;
7185 +}
7186 +
7187 +#endif
7188 diff -urN -x .git dietlibc-0.33/lib/hcreate.c dietlibc/lib/hcreate.c
7189 --- dietlibc-0.33/lib/hcreate.c 1970-01-01 00:00:00.000000000 +0000
7190 +++ dietlibc/lib/hcreate.c      2015-01-01 12:14:43.484938895 +0000
7191 @@ -0,0 +1,18 @@
7192 +#include <search.h>
7193 +
7194 +static struct hsearch_data hd;
7195 +
7196 +int hcreate(size_t count) {
7197 +  return hcreate_r(count,&hd);
7198 +}
7199 +
7200 +void hdestroy(void) {
7201 +  hdestroy_r(&hd);
7202 +}
7203 +
7204 +ENTRY* hsearch(ENTRY item, ACTION action) {
7205 +  ENTRY* x;
7206 +  if (hsearch_r(item,action,&x,&hd))
7207 +    return x;
7208 +  return NULL;
7209 +}
7210 diff -urN -x .git dietlibc-0.33/lib/hcreate_r.c dietlibc/lib/hcreate_r.c
7211 --- dietlibc-0.33/lib/hcreate_r.c       1970-01-01 00:00:00.000000000 +0000
7212 +++ dietlibc/lib/hcreate_r.c    2015-01-01 12:14:43.484938895 +0000
7213 @@ -0,0 +1,28 @@
7214 +#define _GNU_SOURCE
7215 +#include <search.h>
7216 +#include <stdlib.h>
7217 +#include <unistd.h>
7218 +#include <time.h>
7219 +#include <sys/auxv.h>
7220 +
7221 +int hcreate_r(size_t count, struct hsearch_data* htab) {
7222 +  htab->size=count;
7223 +  htab->filled=0;
7224 +  htab->table=calloc(count,sizeof(htab->table[0]));
7225 +  if (htab->table) {
7226 +    char* rnd=(char*)getauxval(AT_RANDOM);
7227 +    if (rnd)
7228 +      memcpy(htab->key,rnd,16);
7229 +    else {
7230 +      struct timeval tv;
7231 +      struct timeval* x=(struct timeval*)htab->key;
7232 +      if (getrandom(&htab->key,sizeof(htab->key),0) != sizeof(htab->key)) {
7233 +       gettimeofday(&tv,NULL);
7234 +       x->tv_sec += tv.tv_sec;
7235 +       x->tv_usec += tv.tv_usec;
7236 +      }
7237 +    }
7238 +  }
7239 +  return htab->table ? 1 : 0;
7240 +}
7241 +
7242 diff -urN -x .git dietlibc-0.33/lib/hdestroy_r.c dietlibc/lib/hdestroy_r.c
7243 --- dietlibc-0.33/lib/hdestroy_r.c      1970-01-01 00:00:00.000000000 +0000
7244 +++ dietlibc/lib/hdestroy_r.c   2015-01-01 12:14:43.484938895 +0000
7245 @@ -0,0 +1,19 @@
7246 +#define _GNU_SOURCE
7247 +#include <search.h>
7248 +#include <stdlib.h>
7249 +
7250 +static void freelist(struct bucket* b) {
7251 +  while (b) {
7252 +    struct bucket* o=b;
7253 +    b=b->next;
7254 +    free(o);
7255 +  }
7256 +}
7257 +
7258 +void hdestroy_r(struct hsearch_data* htab) {
7259 +  size_t i;
7260 +  for (i=0; i<htab->size; ++i) {
7261 +    freelist(htab->table[i]);
7262 +    htab->table[i]=0;
7263 +  }
7264 +}
7265 diff -urN -x .git dietlibc-0.33/lib/hsearch_r.c dietlibc/lib/hsearch_r.c
7266 --- dietlibc-0.33/lib/hsearch_r.c       1970-01-01 00:00:00.000000000 +0000
7267 +++ dietlibc/lib/hsearch_r.c    2015-01-01 12:14:43.484938895 +0000
7268 @@ -0,0 +1,68 @@
7269 +#define _GNU_SOURCE
7270 +#include <search.h>
7271 +#include <string.h>
7272 +#include <errno.h>
7273 +#include <stdlib.h>
7274 +
7275 +static const size_t primes[] = {
7276 +  67, 127, 257, 521, 1031, 2053, 4099, 8191, 16381, 32771, 65537,
7277 +  131071, 262147, 524287, 1048583, 2097143 };
7278 +
7279 +static const unsigned int nprimes = sizeof(primes)/sizeof(primes[0]);
7280 +
7281 +int hsearch_r(ENTRY item, ACTION action, ENTRY** retval, struct hsearch_data* htab) {
7282 +  uint64_t hv=siphash24(htab->key,(const unsigned char*)item.key,strlen(item.key));
7283 +  struct bucket** b=&htab->table[hv%htab->size];
7284 +  while (*b) {
7285 +    if ((*b)->hv==hv && !strcmp((*b)->e.key,item.key)) {
7286 +      /* found */
7287 +      if (retval) *retval=&(*b)->e;
7288 +      return 1;
7289 +    }
7290 +    b=(&(*b)->next);
7291 +  }
7292 +  if (action==FIND) {
7293 +    errno=ESRCH;
7294 +    return 0;
7295 +  }
7296 +  /* if we get this far, we are supposed to add the key */
7297 +  if (htab -> size < primes[nprimes-1] && htab->filled+1 > htab->size) {
7298 +    /* attempt to resize */
7299 +    unsigned int i;
7300 +    struct bucket** n;
7301 +    for (i=0; i<nprimes; ++i)
7302 +      if (htab->size < primes[i]) break;
7303 +    i=primes[i];
7304 +    n=calloc(i,sizeof(struct bucket*));
7305 +    /* If the allocation failed, we can just limp on.
7306 +      * Performance will be reduced but we'll live. */
7307 +    if (n) {
7308 +      unsigned int j;
7309 +
7310 +      for (j=0; j<htab->size; ++j) {
7311 +       struct bucket* B=htab->table[j];
7312 +       while (B) {
7313 +         struct bucket* c=B;
7314 +         B=B->next;
7315 +         unsigned int m=c->hv % i;
7316 +         c->next=n[m];
7317 +         n[m]=c;
7318 +       }
7319 +      }
7320 +      free(htab->table);
7321 +      htab->table=n;
7322 +      htab->size=i;
7323 +      b=&htab->table[hv%htab->size];
7324 +      while (*b)
7325 +       b=(&(*b)->next);
7326 +    }
7327 +  }
7328 +  *b=malloc(sizeof(struct bucket));
7329 +  if (!*b) return 0;
7330 +  ++htab->filled;
7331 +  (*b)->next=0;
7332 +  (*b)->e=item;
7333 +  (*b)->hv=hv;
7334 +  if (retval) *retval=&(*b)->e;
7335 +  return 1;
7336 +}
7337 diff -urN -x .git dietlibc-0.33/lib/if_freenameindex.c dietlibc/lib/if_freenameindex.c
7338 --- dietlibc-0.33/lib/if_freenameindex.c        1970-01-01 00:00:00.000000000 +0000
7339 +++ dietlibc/lib/if_freenameindex.c     2015-01-01 12:14:43.484938895 +0000
7340 @@ -0,0 +1,6 @@
7341 +#include <net/if.h>
7342 +#include <stdlib.h>
7343 +
7344 +void if_freenameindex(struct if_nameindex* ptr) {
7345 +  free(ptr);
7346 +}
7347 diff -urN -x .git dietlibc-0.33/lib/makecontext.c dietlibc/lib/makecontext.c
7348 --- dietlibc-0.33/lib/makecontext.c     1970-01-01 00:00:00.000000000 +0000
7349 +++ dietlibc/lib/makecontext.c  2015-01-01 12:14:43.484938895 +0000
7350 @@ -0,0 +1,69 @@
7351 +#include <ucontext.h>
7352 +#include <stdarg.h>
7353 +
7354 +extern void __setcontext_trampoline();
7355 +
7356 +void makecontext(ucontext_t* c, void (*func)(void), int argc, ...) {
7357 +  size_t* sp;
7358 +  va_list v;
7359 +  int i;
7360 +#ifdef __hppa__
7361 +#define PUSH(val) *++sp=(val);
7362 +#else
7363 +#define PUSH(val) *--sp=(val);
7364 +#endif
7365 +  /* we are called like this:
7366 +
7367 +    if (getcontext(&uctx_func1) == -1)
7368 +        handle_error("getcontext");
7369 +    uctx_func1.uc_stack.ss_sp = func1_stack;
7370 +    uctx_func1.uc_stack.ss_size = sizeof(func1_stack);
7371 +    uctx_func1.uc_link = &uctx_main;
7372 +    makecontext(&uctx_func1, func1, 0);
7373 +  */
7374 +
7375 +  /* first order of business: set up the stack */
7376 +  /* the &-16 aligns it to 16 bytes */
7377 +  sp=(size_t*)((size_t)(c->uc_stack.ss_sp + c->uc_stack.ss_size)&-16);
7378 +  /* note that if the provided stack is to small, we will just crash in here */
7379 +  va_start(v,argc);
7380 +#ifdef __i386__
7381 +  /* if there are no args, we need to make sure there is space on the
7382 +   * stack for the trampoline to pretend uc_link was passed as stack
7383 +   * argument */
7384 +  if (!argc) PUSH(0);
7385 +  /* we set up the context so we jump to it directly, and we leave
7386 +   * __setcontext_trampoline as return address on the stack. */
7387 +  /* __setcontext_trampoline needs to know the c->uc_link, so we put
7388 +   * that into ebx, which is callee-saved */
7389 +  c->uc_mcontext.ebx=(size_t)c->uc_link;
7390 +  sp-=argc;
7391 +  for (i=0; i<argc; ++i)
7392 +    sp[i]=va_arg(v,size_t);
7393 +  PUSH((size_t)__setcontext_trampoline);
7394 +  c->uc_mcontext.esp=(size_t)sp;
7395 +  c->uc_mcontext.eip=(size_t)func;
7396 +#elif defined __x86_64__
7397 +  /* __setcontext_trampoline needs to know the c->uc_link, so we put
7398 +   * that into ebx, which is callee-saved */
7399 +  c->uc_mcontext.rbx=(size_t)c->uc_link;
7400 +  for (i=0; i<argc; ++i) {
7401 +    switch(i) {
7402 +    case 0: c->uc_mcontext.rdi=va_arg(v,size_t); break;
7403 +    case 1: c->uc_mcontext.rsi=va_arg(v,size_t); break;
7404 +    case 2: c->uc_mcontext.rdx=va_arg(v,size_t); break;
7405 +    case 3: c->uc_mcontext.rcx=va_arg(v,size_t); break;
7406 +    case 4: c->uc_mcontext.r8=va_arg(v,size_t); break;
7407 +    case 5: c->uc_mcontext.r9=va_arg(v,size_t); break;
7408 +    default: /* the rest goes on the stack */
7409 +      PUSH(va_arg(v,size_t));
7410 +    }
7411 +  }
7412 +  PUSH((size_t)__setcontext_trampoline);
7413 +  c->uc_mcontext.rsp=(size_t)sp;
7414 +  c->uc_mcontext.rip=(size_t)func;
7415 +#else
7416 +#warning platform not supported yet in makecontext
7417 +#endif
7418 +  va_end(v);
7419 +}
7420 diff -urN -x .git dietlibc-0.33/lib/mbrlen.c dietlibc/lib/mbrlen.c
7421 --- dietlibc-0.33/lib/mbrlen.c  2008-12-10 20:00:59.000000000 +0000
7422 +++ dietlibc/lib/mbrlen.c       2015-01-01 12:14:43.484938895 +0000
7423 @@ -1,8 +1,6 @@
7424  #include <wchar.h>
7425  #include <errno.h>
7426  
7427 -static mbstate_t internal;
7428 -
7429  size_t mbrlen(const char *s, size_t n, mbstate_t *ps) {
7430    static mbstate_t internal;
7431    return mbrtowc (NULL, s, n, ps ?: &internal);
7432 diff -urN -x .git dietlibc-0.33/lib/mmap64.c dietlibc/lib/mmap64.c
7433 --- dietlibc-0.33/lib/mmap64.c  2004-12-13 10:21:31.000000000 +0000
7434 +++ dietlibc/lib/mmap64.c       2015-01-01 12:14:43.484938895 +0000
7435 @@ -4,16 +4,18 @@
7436  #include <syscalls.h>
7437  #include <errno.h>
7438  
7439 +#include "../dietpagesize.h"
7440 +
7441  #ifdef __NR_mmap2
7442  void*__mmap2(void*start,size_t length,int prot,int flags,int fd,off_t pgoffset);
7443  
7444  void*__libc_mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset);
7445  void*__libc_mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset) {
7446 -  if (offset&(PAGE_SIZE-1)) {
7447 +  if (offset&(__DIET_PAGE_SIZE)) {
7448      errno=-EINVAL;
7449      return MAP_FAILED;
7450    }
7451 -  return __mmap2(addr,len,prot,flags,fd,offset>>PAGE_SHIFT);
7452 +  return __mmap2(addr,len,prot,flags,fd,offset>>__DIET_PAGE_SHIFT);
7453  }
7454  
7455  void*mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset)
7456 diff -urN -x .git dietlibc-0.33/lib/mtx_destroy.c dietlibc/lib/mtx_destroy.c
7457 --- dietlibc-0.33/lib/mtx_destroy.c     1970-01-01 00:00:00.000000000 +0000
7458 +++ dietlibc/lib/mtx_destroy.c  2015-01-01 12:14:43.484938895 +0000
7459 @@ -0,0 +1,6 @@
7460 +#include <threads.h>
7461 +
7462 +void mtx_destroy(mtx_t* mutex) {
7463 +  // no need to do anything
7464 +  (void)mutex;
7465 +}
7466 diff -urN -x .git dietlibc-0.33/lib/mtx_init.c dietlibc/lib/mtx_init.c
7467 --- dietlibc-0.33/lib/mtx_init.c        1970-01-01 00:00:00.000000000 +0000
7468 +++ dietlibc/lib/mtx_init.c     2015-01-01 12:14:43.484938895 +0000
7469 @@ -0,0 +1,7 @@
7470 +#include <threads.h>
7471 +
7472 +int mtx_init(mtx_t* mutex, int type) {
7473 +  mutex->lock=0;
7474 +  mutex->type=type;
7475 +  return thrd_success;
7476 +}
7477 diff -urN -x .git dietlibc-0.33/lib/mtx_lock.c dietlibc/lib/mtx_lock.c
7478 --- dietlibc-0.33/lib/mtx_lock.c        1970-01-01 00:00:00.000000000 +0000
7479 +++ dietlibc/lib/mtx_lock.c     2015-01-01 12:14:43.484938895 +0000
7480 @@ -0,0 +1,8 @@
7481 +#define _REENTRANT
7482 +#include <threads.h>
7483 +#include <sys/futex.h>
7484 +#include <errno.h>
7485 +
7486 +int mtx_lock(mtx_t* mutex) {
7487 +  return mtx_timedlock(mutex,0);
7488 +}
7489 diff -urN -x .git dietlibc-0.33/lib/mtx_timedlock.c dietlibc/lib/mtx_timedlock.c
7490 --- dietlibc-0.33/lib/mtx_timedlock.c   1970-01-01 00:00:00.000000000 +0000
7491 +++ dietlibc/lib/mtx_timedlock.c        2015-01-01 12:14:43.484938895 +0000
7492 @@ -0,0 +1,24 @@
7493 +#define _REENTRANT
7494 +#define _DIETLIBC_SOURCE
7495 +#include <threads.h>
7496 +#include <sys/futex.h>
7497 +#include <errno.h>
7498 +
7499 +int mtx_timedlock(mtx_t* mutex, const struct timespec* time_point) {
7500 +  int i,r;
7501 +  thrd_t me=thrd_current();
7502 +  do {
7503 +    r=__mtx_trylock(mutex,&i);
7504 +    if (r!=thrd_busy) return r;
7505 +    for (;;) {
7506 +      r=futex(&mutex->lock,FUTEX_WAIT,i,time_point,0,0);
7507 +      if (r==-1) {
7508 +       if (errno==EWOULDBLOCK) { r=0; break; } else
7509 +       if (errno==ETIMEDOUT) return thrd_timedout; else
7510 +       if (errno==EINTR) continue;
7511 +      } else
7512 +       break;
7513 +    }
7514 +  } while (r==0);
7515 +  return thrd_error;
7516 +}
7517 diff -urN -x .git dietlibc-0.33/lib/mtx_trylock.c dietlibc/lib/mtx_trylock.c
7518 --- dietlibc-0.33/lib/mtx_trylock.c     1970-01-01 00:00:00.000000000 +0000
7519 +++ dietlibc/lib/mtx_trylock.c  2015-01-01 12:14:43.484938895 +0000
7520 @@ -0,0 +1,28 @@
7521 +#define _REENTRANT
7522 +#define _DIETLIBC_SOURCE
7523 +#include <threads.h>
7524 +#include <sys/futex.h>
7525 +#include <errno.h>
7526 +
7527 +int __mtx_trylock(mtx_t* mutex,int* lockval) {
7528 +  int i;
7529 +  thrd_t me=thrd_current();
7530 +  /* attempt to lock the mutex with an atomic instruction */
7531 +  if ((i=__sync_val_compare_and_swap(&mutex->lock,0,1))==0) {
7532 +    mutex->owner=me;
7533 +    return thrd_success;
7534 +  }
7535 +  if ((mutex->type&mtx_recursive) && mutex->owner==me) {
7536 +    if (__sync_add_and_fetch(&mutex->lock,1)>1000) {
7537 +      __sync_add_and_fetch(&mutex->lock,-1);
7538 +      return thrd_error;
7539 +    }
7540 +    return thrd_success;
7541 +  }
7542 +  if (lockval) *lockval=i;
7543 +  return thrd_busy;
7544 +}
7545 +
7546 +int mtx_trylock(mtx_t* mutex) {
7547 +  return __mtx_trylock(mutex,NULL);
7548 +}
7549 diff -urN -x .git dietlibc-0.33/lib/mtx_unlock.c dietlibc/lib/mtx_unlock.c
7550 --- dietlibc-0.33/lib/mtx_unlock.c      1970-01-01 00:00:00.000000000 +0000
7551 +++ dietlibc/lib/mtx_unlock.c   2015-01-01 12:14:43.484938895 +0000
7552 @@ -0,0 +1,22 @@
7553 +#define _REENTRANT
7554 +#include <threads.h>
7555 +#include <sys/futex.h>
7556 +#include <errno.h>
7557 +
7558 +int mtx_unlock(mtx_t* mutex) {
7559 +  int i,r;
7560 +  thrd_t me=thrd_current();
7561 +  if (mutex->lock==0) return thrd_error;
7562 +  if ((mutex->type&mtx_recursive) && mutex->owner==me) {
7563 +    if (__sync_add_and_fetch(&mutex->lock,-1)==0) {
7564 +      // If we get here, the mutex was recursive, we unlocked it, and we
7565 +      // were the last guy holding the lock.  Wake waiters.
7566 +      mutex->owner=0;  // cosmetic; not really needed
7567 +      futex(&mutex->lock,FUTEX_WAKE,1,0,0,0);
7568 +    }
7569 +    return thrd_success;
7570 +  }
7571 +  if (__sync_val_compare_and_swap(&mutex->lock,1,0)==1)
7572 +    futex(&mutex->lock,FUTEX_WAKE,1,0,0,0);
7573 +  return thrd_success;
7574 +}
7575 diff -urN -x .git dietlibc-0.33/lib/__nice.c dietlibc/lib/__nice.c
7576 --- dietlibc-0.33/lib/__nice.c  2005-01-21 18:25:10.000000000 +0000
7577 +++ dietlibc/lib/__nice.c       1970-01-01 00:00:00.000000000 +0000
7578 @@ -1,9 +0,0 @@
7579 -#include "syscalls.h"
7580 -#include <sys/time.h>
7581 -#include <sys/resource.h>
7582 -
7583 -#ifndef __NR_nice
7584 -int nice(int i) {
7585 -  return setpriority(PRIO_PROCESS,0,getpriority(PRIO_PROCESS,0)+i);
7586 -}
7587 -#endif
7588 diff -urN -x .git dietlibc-0.33/lib/nice.c dietlibc/lib/nice.c
7589 --- dietlibc-0.33/lib/nice.c    2012-01-15 18:43:18.000000000 +0000
7590 +++ dietlibc/lib/nice.c 2015-01-01 12:14:43.484938895 +0000
7591 @@ -1,17 +1,56 @@
7592 -#define _REENTRANT
7593 +/*
7594 + * nice() for uClibc
7595 + *
7596 + * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
7597 + * Copyright (C) 2005 by Manuel Novoa III <mjn3@codepoet.org>
7598 + *
7599 + * GNU Library General Public License (LGPL) version 2 or later.
7600 + */
7601 +
7602  #include <errno.h>
7603 -#include <unistd.h>
7604 +#include <limits.h>
7605  #include <sys/resource.h>
7606  
7607 -int nice(int incr) {
7608 -  int prio;
7609 -  int res;
7610 -  errno=0;
7611 -  prio = getpriority(PRIO_PROCESS,0) + incr;
7612 -  if (prio < PRIO_MIN) prio=PRIO_MIN;
7613 -  if (prio >= PRIO_MAX) prio=PRIO_MAX-1;
7614 -  if (setpriority (PRIO_PROCESS, 0, prio)==-1)
7615 -    return -1;
7616 -  else
7617 -    return getpriority(PRIO_PROCESS, 0);
7618 +static inline int int_add_no_wrap(int a, int b)
7619 +{
7620 +       int     s;
7621 +
7622 +       if ((b > 0) && (a > (INT_MAX - b)))
7623 +               s = INT_MAX;
7624 +       else if ((b < 0) && (a < (INT_MIN - b)))
7625 +               s = INT_MIN;
7626 +       else
7627 +               s = a + b;
7628 +
7629 +       return s;
7630 +}
7631 +
7632 +static inline int __syscall_nice(int incr)
7633 +{
7634 +       int old_priority;
7635 +       int old_errno;
7636 +
7637 +       old_errno = errno;
7638 +       __set_errno(0);
7639 +       old_priority = getpriority(PRIO_PROCESS, 0);
7640 +       if ((old_priority == -1) && errno) {
7641 +               return -1;
7642 +       }
7643 +       __set_errno(old_errno);
7644 +
7645 +       if (setpriority(PRIO_PROCESS, 0, int_add_no_wrap(old_priority, incr))) {
7646 +               __set_errno(EPERM);     /* SUSv3 mandates EPERM for nice failure. */
7647 +               return -1;
7648 +       }
7649 +
7650 +       return 0;
7651 +}
7652 +
7653 +int nice(int incr)
7654 +{
7655 +       if (__syscall_nice(incr)) {
7656 +               return -1;
7657 +       }
7658 +
7659 +       return getpriority(PRIO_PROCESS, 0);
7660  }
7661 diff -urN -x .git dietlibc-0.33/lib/opendir.c dietlibc/lib/opendir.c
7662 --- dietlibc-0.33/lib/opendir.c 2002-07-03 20:33:38.000000000 +0000
7663 +++ dietlibc/lib/opendir.c      2015-01-01 12:14:43.484938895 +0000
7664 @@ -5,6 +5,8 @@
7665  #include <stdlib.h>
7666  #include <fcntl.h>
7667  
7668 +#include "../dietpagesize.h"
7669 +
7670  DIR*  opendir ( const char* name ) {
7671    int   fd = open (name, O_RDONLY | O_DIRECTORY);
7672    DIR*  t  = NULL;
7673 @@ -12,7 +14,7 @@
7674    if ( fd >= 0 ) {
7675      if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
7676        goto lose;
7677 -    t = (DIR *) mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, 
7678 +    t = (DIR *) mmap (NULL, __DIET_PAGE_SIZE, PROT_READ | PROT_WRITE,
7679                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
7680      if (t == MAP_FAILED)
7681  lose:
7682 diff -urN -x .git dietlibc-0.33/lib/readdir64.c dietlibc/lib/readdir64.c
7683 --- dietlibc-0.33/lib/readdir64.c       2004-03-02 21:27:19.000000000 +0000
7684 +++ dietlibc/lib/readdir64.c    2015-01-01 12:14:43.484938895 +0000
7685 @@ -13,11 +13,13 @@
7686  
7687  #ifndef WANT_LARGEFILE_BACKCOMPAT
7688  struct dirent64* readdir64(DIR *d) {
7689 -  if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) {
7690 -    int res=getdents64(d->fd,(struct dirent64*)d->buf, sizeof (d->buf)-1);
7691 +  struct linux_dirent64 *ld = d->num ? (struct linux_dirent64*)(d->buf+d->cur) : NULL;
7692 +  if (!d->num || (d->cur += ld->d_reclen)>=d->num) {
7693 +    int res=getdents64(d->fd,(struct linux_dirent64*)d->buf, __DIRSTREAM_BUF_SIZE-1);
7694      if (res<=0) return 0;
7695 -    d->num=res; d->cur=0;
7696 +    d->num=res; d->cur=0; d->is_64=1;
7697    }
7698 +  /* \todo: ensure that dirent64 and linux_dirent64 are compatible */
7699    return (struct dirent64*)(d->buf+d->cur);
7700  }
7701  #else
7702 @@ -25,28 +27,30 @@
7703  #ifdef __NR_getdents64
7704    static int trygetdents64=1;
7705  #endif
7706 -  struct dirent* o;
7707    static struct dirent64 d64;
7708  #ifdef __NR_getdents64
7709  again:
7710    if (!trygetdents64) {
7711  #endif
7712 -    if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) {
7713 -      int res=getdents(d->fd,(struct dirent*)d->buf, sizeof (d->buf)-1);
7714 +    struct linux_dirent *ld = d->num ? (struct linux_dirent*)(d->buf+d->cur) : NULL;
7715 +    if (!d->num || (d->cur += ld->d_reclen)>=d->num) {
7716 +      int res=getdents(d->fd,(struct linux_dirent*)d->buf, __DIRSTREAM_BUF_SIZE-1);
7717        if (res<=0) return 0;
7718 -      d->num=res; d->cur=0;
7719 +      d->num=res; d->cur=0;d->is_64=0;
7720 +      ld=(struct linux_dirent*)(d->buf+d->cur);
7721      }
7722 -    o=(struct dirent*)(d->buf+d->cur);
7723 -    d64.d_ino=o->d_ino;
7724 -    d64.d_off=o->d_off;
7725 -    d64.d_reclen=o->d_reclen;
7726 -    strcpy(d64.d_name,o->d_name);
7727 +    d64.d_ino=ld->d_ino;
7728 +    d64.d_off=ld->d_off;
7729 +    d64.d_reclen=ld->d_reclen;
7730 +    strcpy(d64.d_name,ld->d_name);
7731      d64.d_type=0;      /* is this correct? */
7732      return &d64;
7733  #ifdef __NR_getdents64
7734    }
7735 -  if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) {
7736 -    int res=getdents64(d->fd,(struct dirent64*)d->buf,sizeof (d->buf));
7737 +  {
7738 +  struct linux_dirent64 *ld = d->num ? (struct linux_dirent64*)(d->buf+d->cur) : NULL;
7739 +  if (!d->num || (d->cur += ld->d_reclen)>=d->num) {
7740 +    int res=getdents64(d->fd,(struct linux_dirent64*)d->buf,__DIRSTREAM_BUF_SIZE);
7741      if (res<=0) {
7742        if (errno==ENOSYS) {
7743         trygetdents64=0;
7744 @@ -54,8 +58,10 @@
7745        }
7746        return 0;
7747      }
7748 -    d->num=res; d->cur=0;
7749 +    d->num=res; d->cur=0; d->is_64=1;
7750    }
7751 +  }
7752 +  /* \todo: ensure that dirent64 and linux_dirent64 are compatible */
7753    return (struct dirent64*)(d->buf+d->cur);
7754  #endif
7755  }
7756 diff -urN -x .git dietlibc-0.33/lib/readdir.c dietlibc/lib/readdir.c
7757 --- dietlibc-0.33/lib/readdir.c 2012-11-02 11:17:28.000000000 +0000
7758 +++ dietlibc/lib/readdir.c      2015-01-01 12:14:43.484938895 +0000
7759 @@ -1,3 +1,4 @@
7760 +#define _POSIX_SOURCE
7761  #include "dietdirent.h"
7762  #include <unistd.h>
7763  #include <dirent.h>
7764 diff -urN -x .git dietlibc-0.33/lib/readdir_r.c dietlibc/lib/readdir_r.c
7765 --- dietlibc-0.33/lib/readdir_r.c       2012-10-30 19:54:17.000000000 +0000
7766 +++ dietlibc/lib/readdir_r.c    2015-01-01 12:14:43.484938895 +0000
7767 @@ -4,21 +4,14 @@
7768  #include <dirent.h>
7769  #include <stdlib.h>
7770  
7771 -struct linux_dirent {
7772 -  long         d_ino;
7773 -  off_t                d_off;
7774 -  uint16_t     d_reclen;
7775 -  char         d_name[1];
7776 -};
7777 -
7778  int readdir_r(DIR *d,struct dirent* entry, struct dirent** result) {
7779 -  struct linux_dirent* ld;
7780 +  struct linux_dirent* ld = d->num ? (struct linux_dirent*)(d->buf+d->cur) : NULL;
7781    *result=0;
7782 -  if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) {
7783 -    int res=getdents(d->fd,(struct dirent*)d->buf,sizeof (d->buf)-1);
7784 +  if (!d->num || d->cur >= d->num || (d->cur += ld->d_reclen)>=d->num) {
7785 +    int res=getdents(d->fd,(struct linux_dirent*)d->buf,__DIRSTREAM_BUF_SIZE-1);
7786      if (res<=0)
7787        return res<0;
7788 -    d->num=res; d->cur=0;
7789 +    d->num=res; d->cur=0; d->is_64=0;
7790    }
7791    ld=(struct linux_dirent*)(d->buf+d->cur);
7792    if (ld->d_reclen < sizeof(struct linux_dirent))
7793 diff -urN -x .git dietlibc-0.33/lib/reallocarray.c dietlibc/lib/reallocarray.c
7794 --- dietlibc-0.33/lib/reallocarray.c    1970-01-01 00:00:00.000000000 +0000
7795 +++ dietlibc/lib/reallocarray.c 2015-01-01 12:14:43.484938895 +0000
7796 @@ -0,0 +1,17 @@
7797 +#include <stdlib.h>
7798 +#include <endian.h>
7799 +
7800 +#if __WORDSIZE == 64
7801 +typedef __uint128_t ulll;
7802 +#else
7803 +typedef uint64_t ulll;
7804 +#endif
7805 +
7806 +void* reallocarray(void* ptr, size_t nmemb, size_t size) {
7807 +  /* produce a compile-time error if uintmax_t is not larger than size_t */
7808 +  typedef char compile_time_assertion[(sizeof(ulll)>=sizeof(size_t)*2)-1];
7809 +
7810 +  ulll l=(ulll)nmemb * size;
7811 +  if ((size_t)l != l) return 0;        // overflow
7812 +  return realloc(ptr,(size_t)l);
7813 +}
7814 diff -urN -x .git dietlibc-0.33/lib/seekdir.c dietlibc/lib/seekdir.c
7815 --- dietlibc-0.33/lib/seekdir.c 2006-05-29 16:30:53.000000000 +0000
7816 +++ dietlibc/lib/seekdir.c      2015-01-01 12:14:43.488272228 +0000
7817 @@ -2,9 +2,15 @@
7818  #include <unistd.h>
7819  #include <dirent.h>
7820  
7821 -void seekdir(DIR *d,off_t offset) {
7822 +void seekdir(DIR *d,long offset) {
7823    if (lseek(d->fd,offset,SEEK_SET) != (off_t)-1) {
7824      d->num=d->cur=0;
7825 -    ((struct dirent *)(d->buf))->d_off = offset;
7826 +    if (d->is_64) {
7827 +      struct linux_dirent64 *ld = (void *)(d->buf + d->cur);
7828 +      ld->d_off = offset;
7829 +    } else {
7830 +      struct linux_dirent *ld = (void *)(d->buf + d->cur);
7831 +      ld->d_off = offset;
7832 +    }
7833    }
7834  }
7835 diff -urN -x .git dietlibc-0.33/lib/sigandset.c dietlibc/lib/sigandset.c
7836 --- dietlibc-0.33/lib/sigandset.c       2004-12-17 19:14:49.000000000 +0000
7837 +++ dietlibc/lib/sigandset.c    2015-01-01 12:14:43.488272228 +0000
7838 @@ -4,8 +4,8 @@
7839  int sigandset(sigset_t*set,const sigset_t*left,const sigset_t*right)
7840  {
7841    set->sig[0]=left->sig[0]&right->sig[0];
7842 -  if (_NSIG_WORDS>1) set->sig[1]=left->sig[1]&right->sig[1];
7843 -  if (_NSIG_WORDS>2) {
7844 +  if (_SIGSET_WORDS>1) set->sig[1]=left->sig[1]&right->sig[1];
7845 +  if (_SIGSET_WORDS>2) {
7846      set->sig[2]=left->sig[2]&right->sig[2];
7847      set->sig[3]=left->sig[3]&right->sig[3];
7848    }
7849 diff -urN -x .git dietlibc-0.33/lib/sigemptyset.c dietlibc/lib/sigemptyset.c
7850 --- dietlibc-0.33/lib/sigemptyset.c     2001-07-26 13:14:34.000000000 +0000
7851 +++ dietlibc/lib/sigemptyset.c  2015-01-01 12:14:43.488272228 +0000
7852 @@ -2,8 +2,8 @@
7853  
7854  int sigemptyset(sigset_t *set) {
7855    set->sig[0]=0;
7856 -  if (_NSIG_WORDS>1) set->sig[1]=0;
7857 -  if (_NSIG_WORDS>2) {
7858 +  if (_SIGSET_WORDS>1) set->sig[1]=0;
7859 +  if (_SIGSET_WORDS>2) {
7860      set->sig[2]=0;
7861      set->sig[3]=0;
7862    }
7863 diff -urN -x .git dietlibc-0.33/lib/sigfillset.c dietlibc/lib/sigfillset.c
7864 --- dietlibc-0.33/lib/sigfillset.c      2001-07-26 13:14:34.000000000 +0000
7865 +++ dietlibc/lib/sigfillset.c   2015-01-01 12:14:43.488272228 +0000
7866 @@ -2,8 +2,8 @@
7867  
7868  int sigfillset(sigset_t *set) {
7869    set->sig[0]=(unsigned long)-1;
7870 -  if (_NSIG_WORDS>1) set->sig[1]=(unsigned long)-1;
7871 -  if (_NSIG_WORDS>2) {
7872 +  if (_SIGSET_WORDS>1) set->sig[1]=(unsigned long)-1;
7873 +  if (_SIGSET_WORDS>2) {
7874      set->sig[2]=(unsigned long)-1;
7875      set->sig[3]=(unsigned long)-1;
7876    }
7877 diff -urN -x .git dietlibc-0.33/lib/sigisemptyset.c dietlibc/lib/sigisemptyset.c
7878 --- dietlibc-0.33/lib/sigisemptyset.c   2005-09-28 06:18:43.000000000 +0000
7879 +++ dietlibc/lib/sigisemptyset.c        2015-01-01 12:14:43.488272228 +0000
7880 @@ -5,8 +5,8 @@
7881  {
7882    unsigned long ret;
7883    ret=set->sig[0];
7884 -  if (_NSIG_WORDS>1) ret|=set->sig[1];
7885 -  if (_NSIG_WORDS>2) {
7886 +  if (_SIGSET_WORDS>1) ret|=set->sig[1];
7887 +  if (_SIGSET_WORDS>2) {
7888      ret|=set->sig[2];
7889      ret|=set->sig[3];
7890    }
7891 diff -urN -x .git dietlibc-0.33/lib/signalfd.c dietlibc/lib/signalfd.c
7892 --- dietlibc-0.33/lib/signalfd.c        2008-08-30 13:59:28.000000000 +0000
7893 +++ dietlibc/lib/signalfd.c     2015-01-01 12:14:43.488272228 +0000
7894 @@ -1,13 +1,21 @@
7895  #include <signal.h>
7896  #include <errno.h>
7897  #include <sys/signalfd.h>
7898 +#include <fcntl.h>
7899  
7900  extern int __signalfd(int fd,const sigset_t* mask,size_t nsig);
7901 +extern int __signalfd4(int fd,const sigset_t* mask,size_t nsig, int flags);
7902  
7903  int signalfd(int fd,const sigset_t* mask,int flags) {
7904 -  if (flags) { /* bizarre glibc bullshit */
7905 -    errno=EINVAL;
7906 -    return -1;
7907 +  int r=__signalfd4(fd,mask,_NSIG/8,flags);
7908 +  if (r==-1 && errno==ENOSYS) {
7909 +    r=__signalfd(fd,mask,NSIG/8);
7910 +    if (r!=-1 && flags) {
7911 +      int x;
7912 +      x=fcntl(r,F_SETFD,flags);
7913 +      if (x==-1)
7914 +       close(r);
7915 +    }
7916    }
7917 -  return __signalfd(fd,mask,_NSIG/8);
7918 +  return r;
7919  }
7920 diff -urN -x .git dietlibc-0.33/lib/sigorset.c dietlibc/lib/sigorset.c
7921 --- dietlibc-0.33/lib/sigorset.c        2004-12-17 19:14:49.000000000 +0000
7922 +++ dietlibc/lib/sigorset.c     2015-01-01 12:14:43.488272228 +0000
7923 @@ -4,8 +4,8 @@
7924  int sigorset(sigset_t*set,const sigset_t*left,const sigset_t*right)
7925  {
7926    set->sig[0]=left->sig[0]|right->sig[0];
7927 -  if (_NSIG_WORDS>1) set->sig[1]=left->sig[1]|right->sig[1];
7928 -  if (_NSIG_WORDS>2) {
7929 +  if (_SIGSET_WORDS>1) set->sig[1]=left->sig[1]|right->sig[1];
7930 +  if (_SIGSET_WORDS>2) {
7931      set->sig[2]=left->sig[2]|right->sig[2];
7932      set->sig[3]=left->sig[3]|right->sig[3];
7933    }
7934 diff -urN -x .git dietlibc-0.33/lib/siphash24.c dietlibc/lib/siphash24.c
7935 --- dietlibc-0.33/lib/siphash24.c       1970-01-01 00:00:00.000000000 +0000
7936 +++ dietlibc/lib/siphash24.c    2015-01-01 12:14:43.488272228 +0000
7937 @@ -0,0 +1,67 @@
7938 +#include <search.h>
7939 +
7940 +/* taken from https://github.com/floodyberry/siphash */
7941 +
7942 +#define ROTL64(a,b) (((a)<<(b))|((a)>>(64-b)))
7943 +
7944 +static uint64_t
7945 +U8TO64_LE(const unsigned char *p) {
7946 +       return *(const uint64_t *)p;
7947 +}
7948 +
7949 +uint64_t
7950 +siphash24(const unsigned char key[16], const unsigned char *m, size_t len) {
7951 +       uint64_t v0, v1, v2, v3;
7952 +       uint64_t mi, k0, k1;
7953 +       uint64_t last7;
7954 +       size_t i, blocks;
7955 +
7956 +       k0 = U8TO64_LE(key + 0);
7957 +       k1 = U8TO64_LE(key + 8);
7958 +       v0 = k0 ^ 0x736f6d6570736575ull;
7959 +       v1 = k1 ^ 0x646f72616e646f6dull;
7960 +       v2 = k0 ^ 0x6c7967656e657261ull;
7961 +       v3 = k1 ^ 0x7465646279746573ull;
7962 +
7963 +       last7 = (uint64_t)(len & 0xff) << 56;
7964 +
7965 +#define sipcompress() \
7966 +       v0 += v1; v2 += v3; \
7967 +       v1 = ROTL64(v1,13);     v3 = ROTL64(v3,16); \
7968 +       v1 ^= v0; v3 ^= v2; \
7969 +       v0 = ROTL64(v0,32); \
7970 +       v2 += v1; v0 += v3; \
7971 +       v1 = ROTL64(v1,17); v3 = ROTL64(v3,21); \
7972 +       v1 ^= v2; v3 ^= v0; \
7973 +       v2 = ROTL64(v2,32);
7974 +
7975 +       for (i = 0, blocks = (len & ~7); i < blocks; i += 8) {
7976 +               mi = U8TO64_LE(m + i);
7977 +               v3 ^= mi;
7978 +               sipcompress()
7979 +               sipcompress()
7980 +               v0 ^= mi;
7981 +       }
7982 +
7983 +       switch (len - blocks) {
7984 +               case 7: last7 |= (uint64_t)m[i + 6] << 48;
7985 +               case 6: last7 |= (uint64_t)m[i + 5] << 40;
7986 +               case 5: last7 |= (uint64_t)m[i + 4] << 32;
7987 +               case 4: last7 |= (uint64_t)m[i + 3] << 24;
7988 +               case 3: last7 |= (uint64_t)m[i + 2] << 16;
7989 +               case 2: last7 |= (uint64_t)m[i + 1] <<  8;
7990 +               case 1: last7 |= (uint64_t)m[i + 0]      ;
7991 +               case 0:
7992 +               default:;
7993 +       };
7994 +       v3 ^= last7;
7995 +       sipcompress()
7996 +       sipcompress()
7997 +       v0 ^= last7;
7998 +       v2 ^= 0xff;
7999 +       sipcompress()
8000 +       sipcompress()
8001 +       sipcompress()
8002 +       sipcompress()
8003 +       return v0 ^ v1 ^ v2 ^ v3;
8004 +}
8005 diff -urN -x .git dietlibc-0.33/lib/stackgap.c dietlibc/lib/stackgap.c
8006 --- dietlibc-0.33/lib/stackgap.c        2012-01-24 18:24:26.000000000 +0000
8007 +++ dietlibc/lib/stackgap.c     2015-01-01 12:14:43.488272228 +0000
8008 @@ -16,13 +16,20 @@
8009  #include <elf.h>
8010  #include <stdlib.h>
8011  #include "dietfeatures.h"
8012 +#include <sys/auxv.h>
8013 +#include "dietelfinfo.h"
8014 +
8015 +#ifdef IN_LDSO
8016 +#undef WANT_TLS
8017 +#undef WANT_SSP
8018 +#endif
8019  
8020  #ifdef WANT_GNU_STARTUP_BLOAT
8021  char* program_invocation_name;
8022  char* program_invocation_short_name;
8023  #endif
8024  
8025 -void* __vdso;
8026 +void const * __vdso;
8027  
8028  extern int main(int argc,char* argv[],char* envp[]);
8029  
8030 @@ -50,11 +57,12 @@
8031  
8032  static void findtlsdata(long* auxvec) {
8033  #if (__WORDSIZE == 64)
8034 -  Elf64_Phdr* x=0;
8035 +  Elf64_Phdr const * x=0;
8036  #else
8037 -  Elf32_Phdr* x=0;
8038 +  Elf32_Phdr const * x=0;
8039  #endif
8040    size_t i,n=0;
8041 +#ifndef WANT_ELFINFO
8042    while (*auxvec) {
8043      if (auxvec[0]==3) {        /* AT_PHDR */
8044        x=(void*)auxvec[1];
8045 @@ -65,12 +73,26 @@
8046      }
8047      auxvec+=2;
8048    } /* if we don't find the entry, the kernel let us down */
8049 +#else
8050 +  {
8051 +    __diet_elf_addr_t const    *x_addr = __get_elf_aux_value(AT_PHDR);
8052 +    __diet_elf_addr_t const    *n_addr = __get_elf_aux_value(AT_PHNUM);
8053 +
8054 +    (void)auxvec;
8055 +    if (x_addr)
8056 +      x = (__typeof__(x)) *x_addr;
8057 +    if (n_addr)
8058 +      n = *n_addr;
8059 +  }
8060 +#endif
8061    if (!x || !n) return;        /* a kernel this old does not support thread local storage anyway */
8062    for (i=0; i<n; ++i)
8063      if (x[i].p_type==PT_TLS) {
8064        __tdataptr=(void*)x[i].p_vaddr;
8065        __tdatasize=x[i].p_filesz;
8066        __tmemsize=x[i].p_memsz;
8067 +      if (__tmemsize&15)
8068 +       __tmemsize=(__tmemsize+15)&~15;
8069        break;
8070      }
8071    /* if there is no PT_TLS section, there is no thread-local data, and
8072 @@ -113,42 +135,61 @@
8073  
8074  #elif defined(__alpha__) || defined(__s390__)
8075    __builtin_set_thread_pointer(mainthread);
8076 -#elif defined(__ia64__) || defined(__powerpc__)
8077 -  register tcbhead_t* __thread_self __asm__("r13");
8078 -  __thread_self=mainthread;
8079 -#elif defined(__sparc__)
8080 -  register tcbhead_t* __thread_self __asm("%g7");
8081 +#elif defined(__arm__)
8082 +  __arm_set_tls(mainthread);
8083 +#elif defined(__ABI_TLS_REGISTER)
8084 +  register tcbhead_t* __thread_self __asm__(__ABI_TLS_REGISTER);
8085    __thread_self=mainthread;
8086 +  __asm__ __volatile__("" : : "r"(__thread_self) : "memory");
8087  #else
8088 -#warning "no idea how to enable TLS on this platform, edit lib/stackgap.c"
8089 +#error "no idea how to enable TLS on this platform, edit lib/stackgap.c"
8090  #endif
8091  }
8092  #endif
8093  
8094 -static void* find_in_auxvec(long* x,long what) {
8095 +static void const * find_in_auxvec(long* x,long what) {
8096 +#ifndef WANT_ELFINFO
8097    while (*x) {
8098      if (*x==what)
8099        return (void*)x[1];
8100      x+=2;
8101    }
8102    return NULL;
8103 +#else
8104 +  __diet_elf_addr_t const      *a = __get_elf_aux_value(what);
8105 +  (void)x;
8106 +  return a ? (void *)*a : NULL;
8107 +#endif
8108 +}
8109 +
8110 +#ifndef WANT_ELFINFO
8111 +static long* _auxvec;
8112 +#else
8113 +#define _auxvec        NULL
8114 +#endif
8115 +
8116 +unsigned long getauxval(unsigned long type) {
8117 +  return (long)find_in_auxvec(_auxvec,type);
8118  }
8119  
8120  int stackgap(int argc,char* argv[],char* envp[]);
8121  int stackgap(int argc,char* argv[],char* envp[]) {
8122 -  long* auxvec=(long*)envp;
8123  #if defined(WANT_STACKGAP) || defined(WANT_SSP) || defined(WANT_TLS)
8124 -  char* rand;
8125 +  char const * rand;
8126    char* tlsdata;
8127 +  long* auxvec=(long*)envp;
8128 +#ifndef WANT_ELFINFO
8129    while (*auxvec) ++auxvec; ++auxvec;  /* skip envp to get to auxvec */
8130 +  _auxvec=auxvec;
8131 +#endif
8132  #ifdef WANT_STACKGAP
8133    unsigned short s;
8134 +  volatile char* gap;
8135  #endif
8136  #if defined(WANT_STACKGAP) || defined(WANT_SSP)
8137 -  volatile char* gap;
8138 +  char myrand[10];
8139    rand=find_in_auxvec(auxvec,25);
8140    if (!rand) {
8141 -    char myrand[10];
8142      int fd=open("/dev/urandom",O_RDONLY);
8143      read(fd,myrand,10);
8144      close(fd);
8145 @@ -181,6 +222,7 @@
8146    memcpy(tlsdata,__tdataptr,__tdatasize);
8147    memset(tlsdata+__tdatasize,0,__tmemsize-__tdatasize);
8148    __setup_tls(__tcb_mainthread=(tcbhead_t*)(tlsdata+__tmemsize));
8149 +  __tcb_mainthread->sysinfo=(uintptr_t)find_in_auxvec(auxvec,32);
8150  #elif defined(WANT_SSP)
8151    tlsdata=alloca(sizeof(tcbhead_t));
8152    __setup_tls(__tcb_mainthread=(tcbhead_t*)(tlsdata));
8153 diff -urN -x .git dietlibc-0.33/lib/stack_smash_handler2.c dietlibc/lib/stack_smash_handler2.c
8154 --- dietlibc-0.33/lib/stack_smash_handler2.c    2006-04-04 05:35:14.000000000 +0000
8155 +++ dietlibc/lib/stack_smash_handler2.c 2015-01-01 12:14:43.488272228 +0000
8156 @@ -8,5 +8,17 @@
8157   * diagnostics.  No more. :-( */
8158  void __stack_chk_fail(void) {
8159    __write2("smashed stack detected, program terminated.\n");
8160 -  _exit(127);
8161 +
8162 +  /* trigger a segfault which can be inspected within a debugger (inclusive
8163 +   * stack-trace). 'abort(3)' at this place would be too heavy weighted.
8164 +   *
8165 +   * TODO: limit this to systems which are known to have an MMU (resp. is
8166 +   * dietlibc with stack-protector used on systems without an MMU?)
8167 +   */
8168 +  *(char volatile *)0 = 0;
8169 +  while (1) {
8170 +#if defined(__GNUC__) && ((((__GNUC__) << 8) | (__GNUC_MINOR__)) >= 0x405)
8171 +    __builtin_unreachable();
8172 +#endif
8173 +  }
8174  }
8175 diff -urN -x .git dietlibc-0.33/lib/stpcpy.c dietlibc/lib/stpcpy.c
8176 --- dietlibc-0.33/lib/stpcpy.c  1970-01-01 00:00:00.000000000 +0000
8177 +++ dietlibc/lib/stpcpy.c       2015-01-01 12:14:43.488272228 +0000
8178 @@ -0,0 +1,6 @@
8179 +#include <string.h>
8180 +
8181 +char * stpcpy (char *dst, const char *src) {
8182 +  while ((*dst++ = *src++));
8183 +  return (dst-1);
8184 +}
8185 diff -urN -x .git dietlibc-0.33/lib/swapcontext.c dietlibc/lib/swapcontext.c
8186 --- dietlibc-0.33/lib/swapcontext.c     1970-01-01 00:00:00.000000000 +0000
8187 +++ dietlibc/lib/swapcontext.c  2015-01-01 12:14:43.488272228 +0000
8188 @@ -0,0 +1,12 @@
8189 +#include <ucontext.h>
8190 +#include <stdio.h>
8191 +
8192 +int swapcontext(ucontext_t* o,const ucontext_t* n) {
8193 +  volatile int once=0;
8194 +  if (getcontext(o)==-1) return -1;
8195 +  if (!once) {
8196 +    ++once;
8197 +    return setcontext(n);
8198 +  }
8199 +  return 0;
8200 +}
8201 diff -urN -x .git dietlibc-0.33/lib/tcsetattr.c dietlibc/lib/tcsetattr.c
8202 --- dietlibc-0.33/lib/tcsetattr.c       2002-01-11 18:06:53.000000000 +0000
8203 +++ dietlibc/lib/tcsetattr.c    2015-01-01 12:14:43.488272228 +0000
8204 @@ -3,24 +3,8 @@
8205  #include <errno.h>
8206  #include "dietfeatures.h"
8207  
8208 -#if !defined(__powerpc__) && !defined(__sparc__) && !defined(__alpha__) && !defined(__hppa__)
8209 -#if TCSANOW==0 && TCSADRAIN==1 && TCSAFLUSH==2 && TCSETSW-TCSETS==1 && TCSETSF-TCSETS==2
8210 -#define shortcut
8211 -#endif
8212 -#endif
8213 -
8214  int  tcsetattr ( int fildes, int optional_actions, struct termios* termios_p )
8215  {
8216 -#ifdef shortcut
8217 -
8218 -    if ( (unsigned int)optional_actions < 3u )
8219 -        return ioctl ( fildes, TCSETS+optional_actions, termios_p );
8220 -
8221 -    errno = EINVAL;
8222 -    return -1;
8223 -
8224 -#else
8225 -
8226      switch ( optional_actions ) {
8227      case TCSANOW:
8228          return ioctl ( fildes, TCSETS , termios_p );
8229 @@ -32,6 +16,4 @@
8230          errno = EINVAL;
8231          return -1;
8232      }
8233 -    
8234 -#endif    
8235  }
8236 diff -urN -x .git dietlibc-0.33/lib/telldir.c dietlibc/lib/telldir.c
8237 --- dietlibc-0.33/lib/telldir.c 2006-05-29 16:30:53.000000000 +0000
8238 +++ dietlibc/lib/telldir.c      2015-01-01 12:14:43.488272228 +0000
8239 @@ -2,9 +2,16 @@
8240  #include <unistd.h>
8241  #include <dirent.h>
8242  
8243 -off_t telldir(DIR *d) {
8244 -  off_t result = 0;
8245 -  if (lseek(d->fd,0,SEEK_CUR))
8246 -    result=((struct dirent*)(d->buf+d->cur))->d_off;
8247 +long telldir(DIR *d) {
8248 +  long result = 0;
8249 +  if (lseek(d->fd,0,SEEK_CUR)) {
8250 +    if (d->is_64) {
8251 +      struct linux_dirent64 *ld = (void *)(d->buf + d->cur);
8252 +      result=ld->d_off;
8253 +    } else {
8254 +      struct linux_dirent *ld = (void *)(d->buf + d->cur);
8255 +      result=ld->d_off;
8256 +    }
8257 +  }
8258    return result;
8259  }
8260 diff -urN -x .git dietlibc-0.33/lib/thrd_create.c dietlibc/lib/thrd_create.c
8261 --- dietlibc-0.33/lib/thrd_create.c     1970-01-01 00:00:00.000000000 +0000
8262 +++ dietlibc/lib/thrd_create.c  2015-01-01 12:14:43.488272228 +0000
8263 @@ -0,0 +1,73 @@
8264 +#define _LINUX_SOURCE
8265 +#include <unistd.h>
8266 +#include <threads.h>
8267 +#include <sys/mman.h>
8268 +#include <fcntl.h>
8269 +#define _GNU_SOURCE
8270 +#include <sched.h>
8271 +#include "dietfeatures.h"
8272 +#include <sys/tls.h>
8273 +#include <stdio.h>
8274 +
8275 +extern thrd_t _thrd_root;
8276 +extern size_t _thrd_stacksize;
8277 +
8278 +#ifdef WANT_TLS
8279 +extern size_t __tdatasize, __tmemsize;
8280 +extern void* __tdataptr;
8281 +extern tcbhead_t* __tcb_mainthread;
8282 +#else
8283 +static const size_t __tmemsize=0,__tdatasize=0;
8284 +#endif
8285 +
8286 +static int launch(void* p) {
8287 +  thrd_t self=p;
8288 +  thrd_exit(self->func(self->arg));
8289 +  return 0;
8290 +}
8291 +
8292 +int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) {
8293 +  size_t stacksize=_thrd_stacksize;    // capture value to prevent asynchronous changes to break us
8294 +  char* stack=mmap(0,stacksize+4096+__tmemsize+sizeof(tcbhead_t)+sizeof(**thr),PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK|MAP_GROWSDOWN,-1,0);
8295 +  thrd_t t;
8296 +  tcbhead_t* tcb;
8297 +  int r;
8298 +
8299 +  if (stack==MAP_FAILED) return thrd_nomem;
8300 +  r=thrd_success;
8301 +  if (mprotect(stack+4096,stacksize+__tmemsize+sizeof(tcbhead_t)+sizeof(**thr),PROT_READ|PROT_WRITE)) {
8302 +    munmap(stack,stacksize+4096+__tmemsize+sizeof(tcbhead_t)+sizeof(**thr));
8303 +    return thrd_error;
8304 +  }
8305 +  tcb=(tcbhead_t*)(stack+stacksize+4096+__tmemsize);
8306 +  tcb->tcb=tcb;
8307 +  tcb->dtv=0;
8308 +  t=(thrd_t)(tcb+1);
8309 +  tcb->self=t;
8310 +  tcb->multiple_threads=1;
8311 +#ifdef WANT_TLS
8312 +  tcb->sysinfo=__tcb_mainthread->sysinfo;
8313 +  tcb->stack_guard=__tcb_mainthread->stack_guard ^ gettid() ^ (uintptr_t)t;
8314 +  __tcb_mainthread->multiple_threads=1;
8315 +#endif
8316 +  t->memstart=stack;
8317 +  t->memsize=stacksize+4096+__tmemsize;
8318 +  t->res=0;
8319 +  t->func=func;
8320 +  t->arg=arg;
8321 +  t->flags=0;
8322 +  t->join_futex=0;
8323 +
8324 +#ifdef WANT_TLS
8325 +  memcpy(stack+stacksize+4096,__tdataptr,__tdatasize);
8326 +  memset(stack+stacksize+4096+__tdatasize,0,__tmemsize-__tdatasize);
8327 +#endif
8328 +
8329 +  t->tid=clone(launch,stack+4096+stacksize,CLONE_FILES|CLONE_FS|CLONE_IO|CLONE_PARENT|CLONE_SIGHAND|CLONE_SYSVSEM|CLONE_THREAD|CLONE_VM|CLONE_SETTLS|CLONE_PARENT_SETTID,t,&t->tid,stack+stacksize+4096+__tmemsize);
8330 +  if (t->tid==-1) {
8331 +    munmap(stack,stacksize+4096+__tmemsize+sizeof(tcbhead_t)+sizeof(**thr));
8332 +    return thrd_error;
8333 +  }
8334 +  *thr=t;
8335 +  return thrd_success;
8336 +}
8337 diff -urN -x .git dietlibc-0.33/lib/thrd_current.c dietlibc/lib/thrd_current.c
8338 --- dietlibc-0.33/lib/thrd_current.c    1970-01-01 00:00:00.000000000 +0000
8339 +++ dietlibc/lib/thrd_current.c 2015-01-01 12:14:43.488272228 +0000
8340 @@ -0,0 +1,8 @@
8341 +#include <sys/tls.h>
8342 +#include <threads.h>
8343 +
8344 +thrd_t thrd_current(void) {
8345 +  tcbhead_t* x=__get_cur_tcb();
8346 +  if (x->multiple_threads==0) return NULL;
8347 +  return (thrd_t)(x+1);
8348 +}
8349 diff -urN -x .git dietlibc-0.33/lib/thrd_detach.c dietlibc/lib/thrd_detach.c
8350 --- dietlibc-0.33/lib/thrd_detach.c     1970-01-01 00:00:00.000000000 +0000
8351 +++ dietlibc/lib/thrd_detach.c  2015-01-01 12:14:43.488272228 +0000
8352 @@ -0,0 +1,17 @@
8353 +#include <threads.h>
8354 +#include <sys/tls.h>
8355 +#include <sys/mman.h>
8356 +
8357 +int thrd_detach(thrd_t thr) {
8358 +  int flags=thr->flags;
8359 +  do {
8360 +    if (flags&4) return thrd_error;
8361 +    if (flags&2) {
8362 +      munmap(thr->memstart+thr->memsize,sizeof(tcbhead_t)+sizeof(*thr));
8363 +      return thrd_success;
8364 +    }
8365 +    if (flags&1) return thrd_success;
8366 +    flags=__sync_val_compare_and_swap(&thr->flags,flags,flags|1);
8367 +  } while (1);
8368 +}
8369 +
8370 diff -urN -x .git dietlibc-0.33/lib/thrd_exit.c dietlibc/lib/thrd_exit.c
8371 --- dietlibc-0.33/lib/thrd_exit.c       1970-01-01 00:00:00.000000000 +0000
8372 +++ dietlibc/lib/thrd_exit.c    2015-01-01 12:14:43.488272228 +0000
8373 @@ -0,0 +1,59 @@
8374 +#define _REENTRANT
8375 +#define _LINUX_SOURCE
8376 +#include <threads.h>
8377 +#include <unistd.h>
8378 +#include <sys/futex.h>
8379 +#include <sys/tls.h>
8380 +#include <stdlib.h>
8381 +#include <errno.h>
8382 +
8383 +extern void __munmap_and_exit(void* map,size_t len) __attribute__((noreturn));
8384 +
8385 +thread_local tss_t tss_dtor_list;
8386 +
8387 +void thrd_exit(int res) {
8388 +  thrd_t t=thrd_current();
8389 +  int flags;
8390 +
8391 +  size_t len;
8392 +
8393 +  while (tss_dtor_list) {
8394 +    tss_t cur=tss_dtor_list;
8395 +    tss_dtor_list=tss_dtor_list->next;
8396 +    if (cur->dtor) cur->dtor(cur);
8397 +  }
8398 +  if (!t) exit(res);   // moron user called us when no threads are running
8399 +  t->res=res;
8400 +  if ((flags=__sync_fetch_and_or(&t->flags,4))&4) return;      // shouldn't be possible, but the tear-down-bit was already set
8401 +  if (t->join_futex) { // somebody is waiting; send him a message
8402 +    t->join_wait_futex=0;
8403 +    if (futex(&t->join_futex,FUTEX_WAKE,1,0,0,0)==1) { // wake the guy waiting for us
8404 +      // We woke somebody up.
8405 +      // Give him time to read our exit code.
8406 +      int r;
8407 +      do {
8408 +       r=futex(&t->join_wait_futex,FUTEX_WAIT,0,0,0,0);
8409 +      } while (r==EINTR);
8410 +    }
8411 +    flags|=1;  // mark as detached
8412 +  }
8413 +
8414 +  len=t->memsize;
8415 +  if (flags&1) {
8416 +    // We are detached or somebody already thrd_join'ed us.
8417 +    // We can die in piece and free all our resources
8418 +    len += sizeof(tcbhead_t)+sizeof(*t);
8419 +  } else {
8420 +    // Tell thrd_join that we are dead and cleaned up our stack and it
8421 +    // should clean up the rest when it's done.
8422 +    __sync_fetch_and_or(&t->flags,2);
8423 +    len&=~4095;        // round down to nearest page
8424 +    t->arg=t->memstart+len;
8425 +    t->memsize=t->memsize+sizeof(tcbhead_t)+sizeof(*t)-len;
8426 +  }
8427 +  /* Problem: we need to unmap the stack and call exit, but we can't
8428 +   * touch the stack in between. Unfortunately, calling exit touches the
8429 +   * stack. Returning from the munmap syscall also touches the stack. So
8430 +   * this needs to be done in assembly language. */
8431 +  __munmap_and_exit(t->memstart,len);
8432 +}
8433 diff -urN -x .git dietlibc-0.33/lib/thrd_join.c dietlibc/lib/thrd_join.c
8434 --- dietlibc-0.33/lib/thrd_join.c       1970-01-01 00:00:00.000000000 +0000
8435 +++ dietlibc/lib/thrd_join.c    2015-01-01 12:14:43.488272228 +0000
8436 @@ -0,0 +1,30 @@
8437 +#define _REENTRANT
8438 +#include <threads.h>
8439 +#include <sys/futex.h>
8440 +#include <sys/mman.h>
8441 +#include <sys/tls.h>
8442 +#include <errno.h>
8443 +
8444 +int thrd_join(thrd_t thr, int* res) {
8445 +  int flags=thr->flags;
8446 +  int r;
8447 +  if ((flags&2)==0) {
8448 +    if (flags&5)
8449 +      // thread is detached or in the process of being cleaned up, refuse join
8450 +      return thrd_error;
8451 +    if (!__sync_bool_compare_and_swap(&thr->join_futex,0,1))
8452 +      // somebody is already calling thrd_join, refuse join
8453 +      return thrd_error;
8454 +    do {
8455 +      r=futex(&thr->join_futex,FUTEX_WAIT,1,0,0,0);
8456 +    } while (r==-1 && errno==EINTR);
8457 +    if (res) *res=thr->res;
8458 +    thr->join_wait_futex=1;
8459 +    futex(&thr->join_wait_futex,FUTEX_WAKE,1,0,0,0);
8460 +  } else {
8461 +    if (res) *res=thr->res;
8462 +    munmap(thr->arg,thr->memsize);
8463 +  }
8464 +  return thrd_success;
8465 +}
8466 +
8467 diff -urN -x .git dietlibc-0.33/lib/thrd_root.c dietlibc/lib/thrd_root.c
8468 --- dietlibc-0.33/lib/thrd_root.c       1970-01-01 00:00:00.000000000 +0000
8469 +++ dietlibc/lib/thrd_root.c    2015-01-01 12:14:43.488272228 +0000
8470 @@ -0,0 +1,4 @@
8471 +#include <threads.h>
8472 +
8473 +thrd_t _thrd_root;
8474 +size_t _thrd_stacksize=16*1024;
8475 diff -urN -x .git dietlibc-0.33/lib/tss_create.c dietlibc/lib/tss_create.c
8476 --- dietlibc-0.33/lib/tss_create.c      1970-01-01 00:00:00.000000000 +0000
8477 +++ dietlibc/lib/tss_create.c   2015-01-01 12:14:43.488272228 +0000
8478 @@ -0,0 +1,14 @@
8479 +#include <stdlib.h>
8480 +#include <threads.h>
8481 +
8482 +extern thread_local tss_t tss_dtor_list;
8483 +
8484 +int tss_create(tss_t* tss_id, tss_dtor_t destructor) {
8485 +  *tss_id=malloc(sizeof(**tss_id));
8486 +  if (!*tss_id) return thrd_nomem;
8487 +  (*tss_id)->dtor=destructor;
8488 +  (*tss_id)->next=tss_dtor_list;
8489 +  (*tss_id)->data=0;
8490 +  tss_dtor_list=*tss_id;
8491 +  return thrd_success;
8492 +}
8493 diff -urN -x .git dietlibc-0.33/lib/tss_delete.c dietlibc/lib/tss_delete.c
8494 --- dietlibc-0.33/lib/tss_delete.c      1970-01-01 00:00:00.000000000 +0000
8495 +++ dietlibc/lib/tss_delete.c   2015-01-01 12:14:43.488272228 +0000
8496 @@ -0,0 +1,14 @@
8497 +#include <threads.h>
8498 +
8499 +extern thread_local tss_t tss_dtor_list;
8500 +
8501 +void tss_delete(tss_t tss_id) {
8502 +  tss_t* cur;
8503 +  for (cur=&tss_dtor_list; *cur; cur=&((*cur)->next)) {
8504 +    if (*cur==tss_id)
8505 +      *cur=tss_id->next;
8506 +  }
8507 +  tss_id->dtor=0;
8508 +  tss_id->data=0;
8509 +  tss_id->next=0;
8510 +}
8511 diff -urN -x .git dietlibc-0.33/lib/tss_get.c dietlibc/lib/tss_get.c
8512 --- dietlibc-0.33/lib/tss_get.c 1970-01-01 00:00:00.000000000 +0000
8513 +++ dietlibc/lib/tss_get.c      2015-01-01 12:14:43.488272228 +0000
8514 @@ -0,0 +1,5 @@
8515 +#include <threads.h>
8516 +
8517 +void* tss_get(tss_t tss_id) {
8518 +  return tss_id->data;
8519 +}
8520 diff -urN -x .git dietlibc-0.33/lib/tss_set.c dietlibc/lib/tss_set.c
8521 --- dietlibc-0.33/lib/tss_set.c 1970-01-01 00:00:00.000000000 +0000
8522 +++ dietlibc/lib/tss_set.c      2015-01-01 12:14:43.488272228 +0000
8523 @@ -0,0 +1,6 @@
8524 +#include <threads.h>
8525 +
8526 +int tss_set(tss_t tss_id, void* val) {
8527 +  tss_id->data=val;
8528 +  return thrd_success;
8529 +}
8530 diff -urN -x .git dietlibc-0.33/lib/__utime.c dietlibc/lib/__utime.c
8531 --- dietlibc-0.33/lib/__utime.c 2011-03-03 18:40:05.000000000 +0000
8532 +++ dietlibc/lib/__utime.c      2015-01-01 12:14:43.481605561 +0000
8533 @@ -1,7 +1,13 @@
8534 -#include <utime.h>
8535  #include <syscalls.h>
8536 +#define _BSD_SOURCE
8537 +#include <utime.h>
8538 +#include <sys/time.h>
8539  
8540  #ifndef __NR_utime
8541 +#define _BSD_SOURCE
8542 +#include <utime.h>
8543 +#include <sys/time.h>
8544 +
8545  int utime(const char *filename, const struct utimbuf *times)
8546  {
8547    if (times == NULL)
8548 diff -urN -x .git dietlibc-0.33/lib/__v_printf.c dietlibc/lib/__v_printf.c
8549 --- dietlibc-0.33/lib/__v_printf.c      2008-05-06 17:18:34.000000000 +0000
8550 +++ dietlibc/lib/__v_printf.c   2015-01-01 12:14:43.481605561 +0000
8551 @@ -4,6 +4,7 @@
8552  #include <stdlib.h>
8553  #include <string.h>
8554  #include <errno.h>
8555 +#include <math.h>
8556  #include "dietstdio.h"
8557  #include "dietwarning.h"
8558  
8559 @@ -346,45 +347,49 @@
8560  #ifdef WANT_FLOATING_POINT_IN_PRINTF
8561        /* print a floating point value */
8562        case 'f':
8563 +      case 'F':
8564        case 'g':
8565 +      case 'G':
8566         {
8567 -         int g=(ch=='g');
8568 +         int flags=(((ch&0x5f)=='G') ? 0x01 : 0x00) | ((ch&0x20) ? 0x00 : 0x02);
8569           double d=va_arg(arg_ptr,double);
8570           s=buf+1;
8571           if (width==0) width=1;
8572           if (!flag_dot) preci=6;
8573           if (flag_sign || d < +0.0) flag_in_sign=1;
8574  
8575 -         sz=__dtostr(d,s,sizeof(buf)-1,width,preci,g);
8576 +         sz=__dtostr(d,s,sizeof(buf)-1,width,preci,flags);
8577  
8578 -         if (flag_dot) {
8579 -           char *tmp;
8580 -           if ((tmp=strchr(s,'.'))) {
8581 -             if (preci || flag_hash) ++tmp;
8582 -             while (preci>0 && *++tmp) --preci;
8583 -             *tmp=0;
8584 -           } else if (flag_hash) {
8585 -             s[sz]='.';
8586 -             s[++sz]='\0';
8587 +         if (!isnan(d) && !isinf(d)) {         /* skip NaN + INF values */
8588 +           if (flag_dot) {
8589 +             char *tmp;
8590 +             if ((tmp=strchr(s,'.'))) {
8591 +               if (preci || flag_hash) ++tmp;
8592 +               while (preci>0 && *++tmp) --preci;
8593 +               *tmp=0;
8594 +             } else if (flag_hash) {
8595 +               s[sz]='.';
8596 +               s[++sz]='\0';
8597 +             }
8598             }
8599 -         }
8600  
8601 -         if (g) {
8602 -           char *tmp,*tmp1;    /* boy, is _this_ ugly! */
8603 -           if ((tmp=strchr(s,'.'))) {
8604 -             tmp1=strchr(tmp,'e');
8605 -             while (*tmp) ++tmp;
8606 -             if (tmp1) tmp=tmp1;
8607 -             while (*--tmp=='0') ;
8608 -             if (*tmp!='.') ++tmp;
8609 -             *tmp=0;
8610 -             if (tmp1) strcpy(tmp,tmp1);
8611 +           if ((flags&0x01)) {
8612 +             char *tmp,*tmp1;  /* boy, is _this_ ugly! */
8613 +             if ((tmp=strchr(s,'.'))) {
8614 +               tmp1=strchr(tmp,'e');
8615 +               while (*tmp) ++tmp;
8616 +               if (tmp1) tmp=tmp1;
8617 +               while (*--tmp=='0') ;
8618 +               if (*tmp!='.') ++tmp;
8619 +               *tmp=0;
8620 +               if (tmp1) strcpy(tmp,tmp1);
8621 +             }
8622             }
8623 -         }
8624           
8625 -         if ((flag_sign || flag_space) && d>=0) {
8626 -           *(--s)=(flag_sign)?'+':' ';
8627 -           ++sz;
8628 +           if ((flag_sign || flag_space) && d>=0) {
8629 +             *(--s)=(flag_sign)?'+':' ';
8630 +             ++sz;
8631 +           }
8632           }
8633           
8634           sz=strlen(s);
8635 diff -urN -x .git dietlibc-0.33/libcompat/rcmd.c dietlibc/libcompat/rcmd.c
8636 --- dietlibc-0.33/libcompat/rcmd.c      2005-05-08 15:33:39.000000000 +0000
8637 +++ dietlibc/libcompat/rcmd.c   2015-01-01 12:14:43.491605562 +0000
8638 @@ -4,6 +4,12 @@
8639          const char *remuser, const char *cmd, int *fd2p);
8640  int rcmd(char **ahost, int inport, const char *locuser,
8641          const char *remuser, const char *cmd, int *fd2p) {
8642 +  (void)ahost;
8643 +  (void)inport;
8644 +  (void)locuser;
8645 +  (void)remuser;
8646 +  (void)cmd;
8647 +  (void)fd2p;
8648    __write2("for security reasons, rcmd is not supported by the diet libc.\n");
8649    return -1;
8650  }
8651 diff -urN -x .git dietlibc-0.33/libcompat/stpcpy.c dietlibc/libcompat/stpcpy.c
8652 --- dietlibc-0.33/libcompat/stpcpy.c    2002-05-03 21:22:06.000000000 +0000
8653 +++ dietlibc/libcompat/stpcpy.c 1970-01-01 00:00:00.000000000 +0000
8654 @@ -1,6 +0,0 @@
8655 -#include <string.h>
8656 -
8657 -char * stpcpy (char *dst, const char *src) {
8658 -  while ((*dst++ = *src++));
8659 -  return (dst-1);
8660 -}
8661 diff -urN -x .git dietlibc-0.33/libcompat/syscall.S dietlibc/libcompat/syscall.S
8662 --- dietlibc-0.33/libcompat/syscall.S   2006-05-29 16:30:53.000000000 +0000
8663 +++ dietlibc/libcompat/syscall.S        2015-01-01 12:14:43.491605562 +0000
8664 @@ -130,6 +130,13 @@
8665         b    __unified_syscall
8666  
8667  #else
8668 -               /* arch not implemented yet */
8669 +#include <endian.h>
8670 +       .section        .comment
8671 +#if (__WORDSIZE == 64)
8672 +       .quad           __syscall_2_not_implemented_for_this_arch
8673 +#else
8674 +       .long           __syscall_2_not_implemented_for_this_arch
8675 +#endif
8676 +       .section        .text
8677  #endif
8678  .size  syscall, . - syscall
8679 diff -urN -x .git dietlibc-0.33/libcruft/bindtextdomain.c dietlibc/libcruft/bindtextdomain.c
8680 --- dietlibc-0.33/libcruft/bindtextdomain.c     2003-11-14 15:16:51.000000000 +0000
8681 +++ dietlibc/libcruft/bindtextdomain.c  2015-01-01 12:14:43.491605562 +0000
8682 @@ -5,6 +5,7 @@
8683  static char* dir;
8684  
8685  char* bindtextdomain(const char* domainname,const char* dirname) {
8686 +  (void)domainname;
8687    if (dir) free(dir);
8688    if (!(dir=strdup(dirname))) return 0;
8689    return dir;
8690 diff -urN -x .git dietlibc-0.33/libcruft/dcgettext.c dietlibc/libcruft/dcgettext.c
8691 --- dietlibc-0.33/libcruft/dcgettext.c  2003-11-04 18:26:52.000000000 +0000
8692 +++ dietlibc/libcruft/dcgettext.c       2015-01-01 12:14:43.491605562 +0000
8693 @@ -1,5 +1,7 @@
8694  #include <libintl.h>
8695  
8696  char* dcgettext(const char *domainname, const char *msgid, int category) {
8697 +  (void)domainname;
8698 +  (void)category;
8699    return (char*)msgid;
8700  }
8701 diff -urN -x .git dietlibc-0.33/libcruft/dgettext.c dietlibc/libcruft/dgettext.c
8702 --- dietlibc-0.33/libcruft/dgettext.c   2003-11-04 18:26:52.000000000 +0000
8703 +++ dietlibc/libcruft/dgettext.c        2015-01-01 12:14:43.491605562 +0000
8704 @@ -1,4 +1,4 @@
8705  #include <libintl.h>
8706  
8707  #undef dgettext
8708 -char* dgettext(const char* domainname, const char* x) { return (char*)x; }
8709 +char* dgettext(const char* domainname, const char* x) { (void)domainname; return (char*)x; }
8710 diff -urN -x .git dietlibc-0.33/libcruft/getpagesize.c dietlibc/libcruft/getpagesize.c
8711 --- dietlibc-0.33/libcruft/getpagesize.c        2009-07-01 00:27:26.000000000 +0000
8712 +++ dietlibc/libcruft/getpagesize.c     2015-01-01 12:14:43.491605562 +0000
8713 @@ -1,25 +1,23 @@
8714  #include <sys/types.h>
8715  #include <sys/ipc.h>
8716  #include <sys/shm.h>
8717 -/* for environ: */
8718 -#include <stdlib.h>
8719  
8720 -#ifndef PAGE_SIZE
8721 -#define PAGE_SIZE 4096
8722 -#endif
8723 +#include "../dietelfinfo.h"
8724 +#include "../dietpagesize.h"
8725  
8726 -size_t __libc_getpagesize(void);
8727  size_t __libc_getpagesize(void) {
8728 -  long* x=(long*)environ;
8729 -  int fd;
8730 -  while (*x) ++x; ++x; /* skip envp to get to auxvec */
8731 -  while (*x) {
8732 -    if (*x==6)
8733 -      return x[1];
8734 -    x+=2;
8735 +#ifdef WANT_DYN_PAGESIZE
8736 +  static size_t        pgsz;
8737 +
8738 +  if (__unlikely(pgsz==0)) {
8739 +    __diet_elf_addr_t const    *v = __get_elf_aux_value(AT_PAGESZ);
8740 +    pgsz = *v; /* causes segfault when 'v==NULL' */
8741    }
8742 -  return PAGE_SIZE;
8743 +
8744 +  return pgsz;
8745 +#else
8746 +  return __DIET_PAGE_SIZE_PREDEF;
8747 +#endif
8748  }
8749  
8750  size_t getpagesize(void)       __attribute__((weak,alias("__libc_getpagesize")));
8751 -
8752 diff -urN -x .git dietlibc-0.33/libcruft/mkstemp.c dietlibc/libcruft/mkstemp.c
8753 --- dietlibc-0.33/libcruft/mkstemp.c    2001-08-16 18:44:17.000000000 +0000
8754 +++ dietlibc/libcruft/mkstemp.c 2015-01-01 12:14:43.494938894 +0000
8755 @@ -1,3 +1,4 @@
8756 +#define _FILE_OFFSET_BITS 64
8757  #include <unistd.h>
8758  #include <fcntl.h>
8759  #include <string.h>
8760 diff -urN -x .git dietlibc-0.33/libcruft/res_mkquery.c dietlibc/libcruft/res_mkquery.c
8761 --- dietlibc-0.33/libcruft/res_mkquery.c        2007-03-09 13:42:12.000000000 +0000
8762 +++ dietlibc/libcruft/res_mkquery.c     2015-01-01 12:14:43.494938894 +0000
8763 @@ -44,12 +44,17 @@
8764    unsigned char packet[512];
8765    unsigned long len;
8766  
8767 +  (void)newrr;
8768 +  (void)data;
8769 +  (void)datalen;
8770 +
8771    memcpy(packet,dnspacket,12);
8772    len=rand();
8773    packet[0]=len;
8774    packet[1]=len>>8;
8775    len=0;
8776    if ((_res.options&RES_RECURSE)==0) packet[2]=0;
8777 +  packet[2] |= (op&7)<<3;
8778    {
8779      unsigned char* x;
8780      const char* y,* tmp;
8781 diff -urN -x .git dietlibc-0.33/libcruft/sysconf.c dietlibc/libcruft/sysconf.c
8782 --- dietlibc-0.33/libcruft/sysconf.c    2012-01-24 18:24:27.000000000 +0000
8783 +++ dietlibc/libcruft/sysconf.c 2015-01-01 12:14:43.494938894 +0000
8784 @@ -6,6 +6,9 @@
8785  #define _GNU_SOURCE
8786  #include <sched.h>
8787  
8788 +#include "dietelfinfo.h"
8789 +#include "dietpagesize.h"
8790 +
8791  extern int __sc_nr_cpus();
8792  
8793  static long physpages() {
8794 @@ -42,6 +45,14 @@
8795        return limit.rlim_cur;
8796      }
8797    case _SC_CLK_TCK:
8798 +#ifdef WANT_ELFINFO
8799 +    {
8800 +      __diet_elf_addr_t const  *v = __get_elf_aux_value(AT_CLKTCK);
8801 +      if (v)
8802 +       return *v;
8803 +    }
8804 +#endif
8805 +
8806  #ifdef __alpha__
8807      return 1024;
8808  #else
8809 @@ -49,11 +60,7 @@
8810  #endif
8811  
8812    case _SC_PAGESIZE:
8813 -#if ( defined(__alpha__) || defined(__sparc__) )
8814 -    return 8192;
8815 -#else
8816 -    return 4096;
8817 -#endif
8818 +    return __libc_getpagesize();
8819  
8820    case _SC_PHYS_PAGES:
8821      return physpages();
8822 diff -urN -x .git dietlibc-0.33/libcruft/tmpnam.c dietlibc/libcruft/tmpnam.c
8823 --- dietlibc-0.33/libcruft/tmpnam.c     2002-02-23 22:18:42.000000000 +0000
8824 +++ dietlibc/libcruft/tmpnam.c  2015-01-01 12:14:43.494938894 +0000
8825 @@ -16,7 +16,7 @@
8826    if (s) tmp=s; else tmp=buf;
8827    strcpy(tmp,"/tmp/temp_");
8828    for (;;) {
8829 -    struct stat s;
8830 +    struct stat ss;
8831      int i,j;
8832      i=rand();
8833      for (j=0; j<8; ++j) {
8834 @@ -25,7 +25,7 @@
8835        i>>=4;
8836      }
8837      tmp[17]=0;
8838 -    if (lstat(tmp,&s)==-1 && errno==ENOENT) break;
8839 +    if (lstat(tmp,&ss)==-1 && errno==ENOENT) break;
8840    }
8841    return tmp;
8842  }
8843 diff -urN -x .git dietlibc-0.33/libm/ceil.c dietlibc/libm/ceil.c
8844 --- dietlibc-0.33/libm/ceil.c   1970-01-01 00:00:00.000000000 +0000
8845 +++ dietlibc/libm/ceil.c        2015-01-01 12:14:43.498272228 +0000
8846 @@ -0,0 +1,92 @@
8847 +/* @(#)s_ceil.c 5.1 93/09/24 */
8848 +/*
8849 + * ====================================================
8850 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8851 + *
8852 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8853 + * Permission to use, copy, modify, and distribute this
8854 + * software is freely granted, provided that this notice
8855 + * is preserved.
8856 + * ====================================================
8857 + */
8858 +
8859 +/*
8860 + * ceil(x)
8861 + * Return x rounded toward -inf to integral value
8862 + * Method:
8863 + *     Bit twiddling.
8864 + * Exception:
8865 + *     Inexact flag raised if x not equal to ceil(x).
8866 + */
8867 +
8868 +#include <math.h>
8869 +
8870 +typedef union {
8871 +  double value;
8872 +  struct {
8873 +    unsigned int lsw;
8874 +    unsigned int msw;
8875 +  } parts;
8876 +} ieee_double_shape_type;
8877 +
8878 +/* Get two 32 bit ints from a double.  */
8879 +
8880 +#define EXTRACT_WORDS(ix0,ix1,d)                                \
8881 +do {                                                            \
8882 +  ieee_double_shape_type ew_u;                                  \
8883 +  ew_u.value = (d);                                             \
8884 +  (ix0) = ew_u.parts.msw;                                       \
8885 +  (ix1) = ew_u.parts.lsw;                                       \
8886 +} while (0)
8887 +
8888 +#define INSERT_WORDS(d,ix0,ix1)                                 \
8889 +do {                                                            \
8890 +  ieee_double_shape_type iw_u;                                  \
8891 +  iw_u.parts.msw = (ix0);                                       \
8892 +  iw_u.parts.lsw = (ix1);                                       \
8893 +  (d) = iw_u.value;                                             \
8894 +} while (0)
8895 +
8896 +static const double huge = 1.0e300;
8897 +
8898 +double ceil(double x)
8899 +{
8900 +       int i0,i1,j0;
8901 +       unsigned int i,j;
8902 +       EXTRACT_WORDS(i0,i1,x);
8903 +       j0 = ((i0>>20)&0x7ff)-0x3ff;
8904 +       if(j0<20) {
8905 +           if(j0<0) {  /* raise inexact if x != 0 */
8906 +               if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
8907 +                   if(i0<0) {i0=0x80000000;i1=0;}
8908 +                   else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
8909 +               }
8910 +           } else {
8911 +               i = (0x000fffff)>>j0;
8912 +               if(((i0&i)|i1)==0) return x; /* x is integral */
8913 +               if(huge+x>0.0) {        /* raise inexact flag */
8914 +                   if(i0>0) i0 += (0x00100000)>>j0;
8915 +                   i0 &= (~i); i1=0;
8916 +               }
8917 +           }
8918 +       } else if (j0>51) {
8919 +           if(j0==0x400) return x+x;   /* inf or NaN */
8920 +           else return x;              /* x is integral */
8921 +       } else {
8922 +           i = ((unsigned int)(0xffffffff))>>(j0-20);
8923 +           if((i1&i)==0) return x;     /* x is integral */
8924 +           if(huge+x>0.0) {            /* raise inexact flag */
8925 +               if(i0>0) {
8926 +                   if(j0==20) i0+=1;
8927 +                   else {
8928 +                       j = i1 + (1<<(52-j0));
8929 +                       if(j<i1) i0+=1; /* got a carry */
8930 +                       i1 = j;
8931 +                   }
8932 +               }
8933 +               i1 &= (~i);
8934 +           }
8935 +       }
8936 +       INSERT_WORDS(x,i0,i1);
8937 +       return x;
8938 +}
8939 diff -urN -x .git dietlibc-0.33/libm/gamma.c dietlibc/libm/gamma.c
8940 --- dietlibc-0.33/libm/gamma.c  2005-05-08 15:33:39.000000000 +0000
8941 +++ dietlibc/libm/gamma.c       2015-01-01 12:14:43.498272228 +0000
8942 @@ -33,19 +33,19 @@
8943  #include <stdlib.h>
8944  #include <math.h>
8945  
8946 -#define B0      +            1.0l/   6/ 1/ 2
8947 -#define B1      -            1.0l/  30/ 3/ 4
8948 -#define B2      +            1.0l/  42/ 5/ 6
8949 -#define B3      -            1.0l/  30/ 7/ 8
8950 -#define B4      +            5.0l/  66/ 9/10
8951 -#define B5      -          691.0l/2730/11/12
8952 -#define B6      +            7.0l/   6/13/14
8953 -#define B7      -         3617.0l/ 510/15/16
8954 -#define B8      +        43867.0l/ 798/17/18
8955 -#define B9      -       174611.0l/ 330/19/20
8956 -#define B10     +       854513.0l/ 138/21/22
8957 -#define B11     -    236364091.0l/2730/23/24
8958 -#define B12     +      8553103.0l/   6/25/26
8959 +#define B0      +            1.0/   6/ 1/ 2
8960 +#define B1      -            1.0/  30/ 3/ 4
8961 +#define B2      +            1.0/  42/ 5/ 6
8962 +#define B3      -            1.0/  30/ 7/ 8
8963 +#define B4      +            5.0/  66/ 9/10
8964 +#define B5      -          691.0/2730/11/12
8965 +#define B6      +            7.0/   6/13/14
8966 +#define B7      -         3617.0/ 510/15/16
8967 +#define B8      +        43867.0/ 798/17/18
8968 +#define B9      -       174611.0/ 330/19/20
8969 +#define B10     +       854513.0/ 138/21/22
8970 +#define B11     -    236364091.0/2730/23/24
8971 +#define B12     +      8553103.0/   6/25/26
8972  
8973  static const double  coeff[] = { B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10 };
8974  int                  signgam;
8975 diff -urN -x .git dietlibc-0.33/libpthread/pthread_attr_getscope.c dietlibc/libpthread/pthread_attr_getscope.c
8976 --- dietlibc-0.33/libpthread/pthread_attr_getscope.c    2003-08-18 17:32:52.000000000 +0000
8977 +++ dietlibc/libpthread/pthread_attr_getscope.c 2015-01-01 12:14:43.498272228 +0000
8978 @@ -5,7 +5,7 @@
8979  #include "thread_internal.h"
8980  
8981  int pthread_attr_getscope(const pthread_attr_t*attr,int*scope) {
8982 -  if (0) { attr=0; }
8983 +  (void)attr;
8984    *scope=PTHREAD_SCOPE_SYSTEM;
8985    return 0;
8986  }
8987 diff -urN -x .git dietlibc-0.33/libpthread/pthread_attr_setscope.c dietlibc/libpthread/pthread_attr_setscope.c
8988 --- dietlibc-0.33/libpthread/pthread_attr_setscope.c    2003-08-18 17:32:52.000000000 +0000
8989 +++ dietlibc/libpthread/pthread_attr_setscope.c 2015-01-01 12:14:43.498272228 +0000
8990 @@ -5,7 +5,7 @@
8991  #include "thread_internal.h"
8992  
8993  int pthread_attr_setscope(pthread_attr_t*attr,int scope) {
8994 -  if (0) { attr=0; }
8995 +  (void)attr;
8996    if (scope==PTHREAD_SCOPE_SYSTEM) return 0;
8997    if (scope==PTHREAD_SCOPE_PROCESS) return ENOTSUP;
8998    return EINVAL;
8999 diff -urN -x .git dietlibc-0.33/libpthread/pthread_condattr_getshared.c dietlibc/libpthread/pthread_condattr_getshared.c
9000 --- dietlibc-0.33/libpthread/pthread_condattr_getshared.c       2003-08-18 17:32:53.000000000 +0000
9001 +++ dietlibc/libpthread/pthread_condattr_getshared.c    2015-01-01 12:14:43.498272228 +0000
9002 @@ -5,7 +5,7 @@
9003  #include "thread_internal.h"
9004  
9005  int pthread_condattr_getpshared(const pthread_condattr_t*attr,int*pshared) {
9006 -  if (0) { attr=0; }
9007 +  (void)attr;
9008    *pshared=PTHREAD_PROCESS_PRIVATE;
9009    return 0;
9010  }
9011 diff -urN -x .git dietlibc-0.33/libpthread/pthread_condattr_setshared.c dietlibc/libpthread/pthread_condattr_setshared.c
9012 --- dietlibc-0.33/libpthread/pthread_condattr_setshared.c       2003-08-18 17:32:53.000000000 +0000
9013 +++ dietlibc/libpthread/pthread_condattr_setshared.c    2015-01-01 12:14:43.498272228 +0000
9014 @@ -5,7 +5,7 @@
9015  #include "thread_internal.h"
9016  
9017  int pthread_condattr_setpshared(pthread_condattr_t*attr,int pshared) {
9018 -  if (0) { attr=0; }
9019 +  (void)attr;
9020    if ((pshared!=PTHREAD_PROCESS_PRIVATE) && (pshared!=PTHREAD_PROCESS_SHARED))
9021      return EINVAL;
9022    if (pshared!=PTHREAD_PROCESS_PRIVATE)
9023 diff -urN -x .git dietlibc-0.33/libpthread/pthread_cond_init.c dietlibc/libpthread/pthread_cond_init.c
9024 --- dietlibc-0.33/libpthread/pthread_cond_init.c        2003-08-18 17:32:52.000000000 +0000
9025 +++ dietlibc/libpthread/pthread_cond_init.c     2015-01-01 12:14:43.498272228 +0000
9026 @@ -6,7 +6,7 @@
9027  #include "thread_internal.h"
9028  
9029  int pthread_cond_init(pthread_cond_t*cond,pthread_condattr_t*cond_attr) {
9030 -  if (0) { cond_attr=0; }
9031 +  (void)cond_attr;
9032    memset(cond,0,sizeof(pthread_cond_t));
9033    cond->lock.__spinlock=PTHREAD_SPIN_UNLOCKED;
9034    return 0;
9035 diff -urN -x .git dietlibc-0.33/libpthread/pthread_errno.c dietlibc/libpthread/pthread_errno.c
9036 --- dietlibc-0.33/libpthread/pthread_errno.c    2001-06-09 17:45:50.000000000 +0000
9037 +++ dietlibc/libpthread/pthread_errno.c 1970-01-01 00:00:00.000000000 +0000
9038 @@ -1,5 +0,0 @@
9039 -int errno;
9040 -
9041 -#include "dietwarning.h"
9042 -
9043 -link_warning("errno","\e[1;33;41m>>> your multithreaded code uses errno! <<<\e[0m");
9044 diff -urN -x .git dietlibc-0.33/libpthread/pthread_internal.c dietlibc/libpthread/pthread_internal.c
9045 --- dietlibc-0.33/libpthread/pthread_internal.c 2010-09-25 17:03:27.000000000 +0000
9046 +++ dietlibc/libpthread/pthread_internal.c      2015-01-01 12:14:43.498272228 +0000
9047 @@ -283,7 +283,7 @@
9048  /* cancel signal */
9049  static void pthread_handle_sigcancel(int sig,siginfo_t*info,void*arg) {
9050    _pthread_descr this=__thread_self();
9051 -  if (0) { sig=0; arg=0; }
9052 +  (void)sig; (void)arg;
9053  #ifdef DEBUG
9054    printf("pthread_handle_sigcancel(%d): sigcancel %d\n",sig,this->pid);
9055  #endif
9056 @@ -519,7 +519,7 @@
9057    struct pollfd pfd;
9058    _pthread_descr td;
9059    int n,status;
9060 -  if (0) arg=0;
9061 +  (void)arg;
9062    pfd.fd=mgr_recv_fd;
9063    pfd.events=POLLIN;
9064  
9065 diff -urN -x .git dietlibc-0.33/libpthread/pthread_semaphore_misc.c dietlibc/libpthread/pthread_semaphore_misc.c
9066 --- dietlibc-0.33/libpthread/pthread_semaphore_misc.c   2003-09-17 15:06:10.000000000 +0000
9067 +++ dietlibc/libpthread/pthread_semaphore_misc.c        2015-01-01 12:14:43.498272228 +0000
9068 @@ -6,12 +6,12 @@
9069  #include "thread_internal.h"
9070  
9071  sem_t*sem_open(const char*name,int oflag,...) {
9072 -  if (0) { name=0; oflag=0; }
9073 +  (void)name; (void)oflag;
9074    _errno_=ENOSYS;
9075    return 0;
9076  }
9077  int sem_close(sem_t*sem) {
9078 -  if (0) sem=0;
9079 +  (void)sem;
9080    _errno_=ENOSYS;
9081    return -1;
9082  }
9083 diff -urN -x .git dietlibc-0.33/libpthread/pthread_spinlock.c dietlibc/libpthread/pthread_spinlock.c
9084 --- dietlibc-0.33/libpthread/pthread_spinlock.c 2003-08-18 17:32:53.000000000 +0000
9085 +++ dietlibc/libpthread/pthread_spinlock.c      2015-01-01 12:14:43.498272228 +0000
9086 @@ -1,11 +1,86 @@
9087 +#define _REENTRANT
9088 +
9089 +#include <errno.h>
9090 +
9091  #include <time.h>
9092  
9093  #include <pthread.h>
9094  #include "thread_internal.h"
9095  
9096 +#include <sys/atomic.h>
9097 +#include <sys/futex.h>
9098 +
9099 +#include <stdio.h>
9100 +#include <stdlib.h>
9101 +#include <write12.h>
9102 +
9103 +#define NO_CAS
9104 +
9105 +#ifndef NO_CAS
9106 +int __kernel_supports_futex;
9107 +#endif
9108 +
9109  void __pthread_lock(struct _pthread_fastlock*lock) {
9110    int cnt=0;
9111    struct timespec tm;
9112 +#ifndef NO_CAS
9113 +  if (__kernel_supports_futex==-1) goto old_and_busted;
9114 +  /* if we have CAS, use a futex */
9115 +try_again:
9116 +#if 0
9117 +  if (__atomic_add(&lock->__spinlock,1)==1)
9118 +    /* we now hold the lock, there was no contention */
9119 +    return;
9120 +  __atomic_add(&lock->__spinlock,-1);
9121 +#else
9122 +  {
9123 +    /* slight optimization: if we don't get the lock immediately, busy-loop for a few iterations. */
9124 +    size_t i;
9125 +    for (i=0; i<10; ++i) {
9126 +      if (__CAS(&lock->__spinlock,0,1)==0)
9127 +       /* we now hold the lock, there was no contention */
9128 +       return;
9129 +    }
9130 +  }
9131 +#endif
9132 +  if (__CAS(&lock->__spinlock,1,2)!=1) goto try_again;
9133 +  /* if we got here, we did not get the lock. */
9134 +#if 0
9135 +  {
9136 +    char buf[1024];
9137 +    sprintf(buf,"thread %u goes FUTEX_WAIT (lock now %u)\n",gettid(),lock->__spinlock);
9138 +    write(1,buf,strlen(buf));
9139 +  }
9140 +#endif
9141 +  if (futex(&lock->__spinlock,FUTEX_WAIT,2,NULL,NULL,0)!=0) {
9142 +    switch (*__errno_location()) {
9143 +    case ENOSYS: /* kernel too old */
9144 +      goto old_and_busted;
9145 +    case EWOULDBLOCK: /* when futex() looked, the value was no longer -1 */
9146 +    case EINTR: /* a signal interrupted us */
9147 +    case EDEADLK: /* not in the man page, treat same as EWOULDBLOCK? */
9148 +      break;
9149 +#if 0
9150 +    default:
9151 +      {
9152 +       char buf[100];
9153 +       sprintf(buf,"futex %d",*__errno_location());
9154 +       perror(buf);
9155 +      }
9156 +      exit(1);
9157 +#endif
9158 +    }
9159 +  }
9160 +#if 0
9161 +  else { /* we waited, the other guy left, we got woken up. */
9162 +    char buf[1024];
9163 +    sprintf(buf,"thread %u comes out of FUTEX_WAIT (lock now %u)\n",gettid(),lock->__spinlock);
9164 +    write(1,buf,strlen(buf));
9165 +  }
9166 +#endif
9167 +  goto try_again;
9168 +old_and_busted:
9169 +#endif
9170    while (__testandset(&lock->__spinlock)) {
9171      if (cnt<MAX_SPIN_COUNT) {
9172        sched_yield();
9173 @@ -20,10 +95,33 @@
9174  }
9175  
9176  int __pthread_trylock(struct _pthread_fastlock*lock) {
9177 +#ifndef NO_CAS
9178 +  if (__kernel_supports_futex==-1) goto old_and_busted;
9179 +  /* if we have CAS, use a futex */
9180 +  return __CAS(&lock->__spinlock,0,1)!=0;
9181 +old_and_busted:
9182 +#endif
9183    return __testandset(&lock->__spinlock);
9184  }
9185  
9186  int __pthread_unlock(struct _pthread_fastlock*lock) {
9187 +#ifndef NO_CAS
9188 +  if (__kernel_supports_futex==-1) goto old_and_busted;
9189 +  /* if we have CAS, use a futex */
9190 +  if (__CAS(&lock->__spinlock,1,0)!=1) {
9191 +    lock->__spinlock=0;
9192 +    futex(&lock->__spinlock,FUTEX_WAKE,1,NULL,NULL,0);
9193 +#if 0
9194 +    {
9195 +      char buf[1024];
9196 +      sprintf(buf,"thread %u calls FUTEX_WAKE (lock now %u)\n",gettid(),lock->__spinlock);
9197 +      write(1,buf,strlen(buf));
9198 +    }
9199 +#endif
9200 +  }
9201 +  return 0;
9202 +old_and_busted:
9203 +#endif
9204    lock->__spinlock=PTHREAD_SPIN_UNLOCKED;
9205    return 0;
9206  }
9207 diff -urN -x .git dietlibc-0.33/libpthread/pthread_sys_fcntl.c dietlibc/libpthread/pthread_sys_fcntl.c
9208 --- dietlibc-0.33/libpthread/pthread_sys_fcntl.c        2003-08-18 17:32:53.000000000 +0000
9209 +++ dietlibc/libpthread/pthread_sys_fcntl.c     2015-01-01 12:14:43.498272228 +0000
9210 @@ -1,7 +1,9 @@
9211 +#define fcntl lib_fcntl
9212  #include <unistd.h>
9213  
9214  #include <pthread.h>
9215  #include "thread_internal.h"
9216 +#undef fcntl
9217  
9218  int fcntl(int fd, int cmd, void *arg);
9219  int fcntl(int fd, int cmd, void *arg) {
9220 diff -urN -x .git dietlibc-0.33/libregex/rx.c dietlibc/libregex/rx.c
9221 --- dietlibc-0.33/libregex/rx.c 2010-09-25 17:03:27.000000000 +0000
9222 +++ dietlibc/libregex/rx.c      2015-01-01 12:14:43.501605560 +0000
9223 @@ -429,6 +429,12 @@
9224  }
9225  
9226  static int matchempty(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
9227 +  (void)x;
9228 +  (void)s;
9229 +  (void)ofs;
9230 +  (void)preg;
9231 +  (void)plus;
9232 +  (void)eflags;
9233    return 0;
9234  }
9235  
9236 @@ -450,10 +456,10 @@
9237      }
9238  //    printf("b->p from %p to ",b->p);
9239      {
9240 -      struct piece* tmp;
9241 -      if (!(tmp=realloc(b->p,++b->num*sizeof(p)))) return s;
9242 -//      printf("piece realloc: %p -> %p (%d*%d)\n",b->p,tmp,b->num,sizeof(p));
9243 -      b->p=tmp;
9244 +      struct piece* t;
9245 +      if (!(t=realloc(b->p,++b->num*sizeof(p)))) return s;
9246 +//      printf("piece realloc: %p -> %p (%d*%d)\n",b->p,t,b->num,sizeof(p));
9247 +      b->p=t;
9248      }
9249  //    printf("%p (size %d)\n",b->p,b->num*sizeof(p));
9250      b->p[b->num-1]=p;
9251 @@ -501,10 +507,10 @@
9252      if (tmp==s && !closebracket(s,p)) return s;
9253  //    printf("r->b from %p to ",r->b);
9254      {
9255 -      struct branch* tmp;
9256 -      if (!(tmp=realloc(r->b,++r->num*sizeof(b)))) return s;
9257 -//      printf("branch realloc: %p -> %p (%d*%d)\n",r->b,tmp,r->num,sizeof(b));
9258 -      r->b=tmp;
9259 +      struct branch* t;
9260 +      if (!(t=realloc(r->b,++r->num*sizeof(b)))) return s;
9261 +//      printf("branch realloc: %p -> %p (%d*%d)\n",r->b,t,r->num,sizeof(b));
9262 +      r->b=t;
9263      }
9264  //    printf("%p (size %d)\n",r->b,r->num*sizeof(b));
9265      r->b[r->num-1]=b;
9266 @@ -618,6 +624,8 @@
9267  }
9268  
9269  size_t regerror(int errcode, const regex_t*__restrict__ preg, char*__restrict__ errbuf, size_t errbuf_size) {
9270 +  (void)preg;
9271 +  (void)errcode;
9272    strncpy(errbuf,"invalid regular expression (sorry)",errbuf_size);
9273    return strlen(errbuf);
9274  }
9275 diff -urN -x .git dietlibc-0.33/librpc/auth_none.c dietlibc/librpc/auth_none.c
9276 --- dietlibc-0.33/librpc/auth_none.c    2003-08-19 19:34:18.000000000 +0000
9277 +++ dietlibc/librpc/auth_none.c 2015-01-01 12:14:43.504938894 +0000
9278 @@ -98,6 +98,8 @@
9279  {
9280         register struct authnone_private *ap = authnone_private;
9281  
9282 +       (void)client;
9283 +
9284         if (ap == 0)
9285                 return (0);
9286         return ((*xdrs->x_ops->x_putbytes) (xdrs,
9287 @@ -106,21 +108,24 @@
9288  
9289  static void authnone_verf(AUTH *x)
9290  {
9291 +  (void)x;
9292  }
9293  
9294  static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
9295  {
9296 -
9297 +  (void)x;
9298 +  (void)x1;
9299         return (TRUE);
9300  }
9301  
9302  static bool_t authnone_refresh(AUTH *x)
9303  {
9304 -
9305 +  (void)x;
9306         return (FALSE);
9307  }
9308  
9309  static void authnone_destroy(AUTH *x)
9310  {
9311 +  (void)x;
9312  }
9313  
9314 diff -urN -x .git dietlibc-0.33/librpc/auth_unix.c dietlibc/librpc/auth_unix.c
9315 --- dietlibc-0.33/librpc/auth_unix.c    2003-08-19 19:34:18.000000000 +0000
9316 +++ dietlibc/librpc/auth_unix.c 2015-01-01 12:14:43.504938894 +0000
9317 @@ -191,6 +191,7 @@
9318  static void authunix_nextverf(auth)
9319  AUTH *auth;
9320  {
9321 +  (void)auth;
9322         /* no action necessary */
9323  }
9324  
9325 diff -urN -x .git dietlibc-0.33/librpc/clnt_perror.c dietlibc/librpc/clnt_perror.c
9326 --- dietlibc-0.33/librpc/clnt_perror.c  2003-08-19 19:34:18.000000000 +0000
9327 +++ dietlibc/librpc/clnt_perror.c       2015-01-01 12:14:43.504938894 +0000
9328 @@ -67,6 +67,8 @@
9329   */
9330  char *clnt_sperror __P ((CLIENT *rpch, const char *s))
9331  {
9332 +  (void)rpch;
9333 +  (void)s;
9334  #if 0
9335         struct rpc_err e;
9336         void clnt_perrno();
9337 @@ -204,6 +206,7 @@
9338  char *clnt_sperrno(stat)
9339  enum clnt_stat stat;
9340  {
9341 +  (void)stat;
9342  #if 0
9343         int i;
9344  
9345 @@ -225,6 +228,7 @@
9346  
9347  char *clnt_spcreateerror __P ((__const char *s))
9348  {
9349 +  (void)s;
9350  #if 0
9351         extern int sys_nerr;
9352         extern char *sys_errlist[];
9353 diff -urN -x .git dietlibc-0.33/librpc/clnt_raw.c dietlibc/librpc/clnt_raw.c
9354 --- dietlibc-0.33/librpc/clnt_raw.c     2003-08-19 19:34:18.000000000 +0000
9355 +++ dietlibc/librpc/clnt_raw.c  2015-01-01 12:14:43.504938894 +0000
9356 @@ -53,7 +53,10 @@
9357         CLIENT client_object;
9358         XDR xdr_stream;
9359         char _raw_buf[UDPMSGSIZE];
9360 -       char mashl_callmsg[MCALL_MSG_SIZE];
9361 +       union {
9362 +               struct rpc_msg  msg;
9363 +               char buf[MCALL_MSG_SIZE];
9364 +       } mashl_call;
9365         unsigned int mcnt;
9366  } *clntraw_private;
9367  
9368 @@ -101,7 +104,7 @@
9369         call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
9370         call_msg.rm_call.cb_prog = prog;
9371         call_msg.rm_call.cb_vers = vers;
9372 -       xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
9373 +       xdrmem_create(xdrs, clp->mashl_call.buf, MCALL_MSG_SIZE, XDR_ENCODE);
9374         if (!xdr_callhdr(xdrs, &call_msg)) {
9375                 perror("clnt_raw.c - Fatal header serialization error.");
9376         }
9377 @@ -137,6 +140,8 @@
9378         enum clnt_stat status;
9379         struct rpc_err error;
9380  
9381 +       (void)timeout;
9382 +
9383         if (clp == 0)
9384                 return (RPC_FAILED);
9385    call_again:
9386 @@ -145,8 +150,8 @@
9387          */
9388         xdrs->x_op = XDR_ENCODE;
9389         XDR_SETPOS(xdrs, 0);
9390 -       ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
9391 -       if ((!XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
9392 +       clp->mashl_call.msg.rm_xid++;
9393 +       if ((!XDR_PUTBYTES(xdrs, clp->mashl_call.buf, clp->mcnt)) ||
9394                 (!XDR_PUTLONG(xdrs, (long *) &proc)) ||
9395                 (!AUTH_MARSHALL(h->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp))) {
9396                 return (RPC_CANTENCODEARGS);
9397 @@ -197,6 +202,8 @@
9398  
9399  static void clntraw_geterr(CLIENT *x, struct rpc_err *x1)
9400  {
9401 +  (void)x;
9402 +  (void)x1;
9403  }
9404  
9405  
9406 @@ -209,6 +216,8 @@
9407         register XDR *xdrs = &clp->xdr_stream;
9408         bool_t rval;
9409  
9410 +       (void)cl;
9411 +
9412         if (clp == 0) {
9413                 rval = (bool_t) RPC_FAILED;
9414                 return (rval);
9415 @@ -223,10 +232,14 @@
9416  
9417  static bool_t clntraw_control(CLIENT *x, int x1, char *x2)
9418  {
9419 +  (void)x;
9420 +  (void)x1;
9421 +  (void)x2;
9422         return (FALSE);
9423  }
9424  
9425  static void clntraw_destroy(CLIENT *x)
9426  {
9427 +  (void)x;
9428  }
9429  
9430 diff -urN -x .git dietlibc-0.33/librpc/clnt_udp.c dietlibc/librpc/clnt_udp.c
9431 --- dietlibc-0.33/librpc/clnt_udp.c     2005-05-08 15:33:39.000000000 +0000
9432 +++ dietlibc/librpc/clnt_udp.c  2015-01-01 12:14:43.504938894 +0000
9433 @@ -335,7 +335,7 @@
9434                 if (inlen < 4)
9435                         continue;
9436                 /* see if reply transaction id matches sent id */
9437 -               if (*((uint32_t *) (cu->cu_inbuf)) != *((uint32_t *) (cu->cu_outbuf)))
9438 +               if (memcmp(cu->cu_inbuf, cu->cu_outbuf, 4) != 0)
9439                         continue;
9440                 /* we now assume we have the proper reply */
9441                 break;
9442 diff -urN -x .git dietlibc-0.33/librpc/pmap_rmt.c dietlibc/librpc/pmap_rmt.c
9443 --- dietlibc-0.33/librpc/pmap_rmt.c     2005-05-08 15:33:39.000000000 +0000
9444 +++ dietlibc/librpc/pmap_rmt.c  2015-01-01 12:14:43.504938894 +0000
9445 @@ -158,6 +158,9 @@
9446  int sock;                                              /* any valid socket will do */
9447  char *buf;                                             /* why allocxate more when we can use existing... */
9448  {
9449 +  (void)addrs;
9450 +  (void)sock;
9451 +  (void)buf;
9452  #ifdef __linux__
9453         struct sockaddr_in addr;
9454  
9455 diff -urN -x .git dietlibc-0.33/librpc/svc_auth_unix.c dietlibc/librpc/svc_auth_unix.c
9456 --- dietlibc-0.33/librpc/svc_auth_unix.c        2007-03-09 13:42:12.000000000 +0000
9457 +++ dietlibc/librpc/svc_auth_unix.c     2015-01-01 12:14:43.504938894 +0000
9458 @@ -136,5 +136,7 @@
9459  struct svc_req *rqst;
9460  struct rpc_msg *msg;
9461  {
9462 +  (void)rqst;
9463 +  (void)msg;
9464         return (AUTH_REJECTEDCRED);
9465  }
9466 diff -urN -x .git dietlibc-0.33/librpc/svc_raw.c dietlibc/librpc/svc_raw.c
9467 --- dietlibc-0.33/librpc/svc_raw.c      2003-08-19 19:34:18.000000000 +0000
9468 +++ dietlibc/librpc/svc_raw.c   2015-01-01 12:14:43.504938894 +0000
9469 @@ -91,7 +91,7 @@
9470  
9471  static enum xprt_stat svcraw_stat(SVCXPRT *__xprt)
9472  {
9473 -
9474 +  (void)__xprt;
9475         return (XPRT_IDLE);
9476  }
9477  
9478 @@ -102,6 +102,8 @@
9479         register struct svcraw_private *srp = svcraw_private;
9480         register XDR *xdrs;
9481  
9482 +       (void)xprt;
9483 +
9484         if (srp == 0)
9485                 return (0);
9486         xdrs = &srp->xdr_stream;
9487 @@ -119,6 +121,8 @@
9488         register struct svcraw_private *srp = svcraw_private;
9489         register XDR *xdrs;
9490  
9491 +       (void)xprt;
9492 +
9493         if (srp == 0)
9494                 return (FALSE);
9495         xdrs = &srp->xdr_stream;
9496 @@ -137,6 +141,8 @@
9497  {
9498         register struct svcraw_private *srp = svcraw_private;
9499  
9500 +       (void)xprt;
9501 +
9502         if (srp == 0)
9503                 return (FALSE);
9504         return ((*xdr_args) (&srp->xdr_stream, args_ptr));
9505 @@ -150,6 +156,8 @@
9506         register struct svcraw_private *srp = svcraw_private;
9507         register XDR *xdrs;
9508  
9509 +       (void)xprt;
9510 +
9511         if (srp == 0)
9512                 return (FALSE);
9513         xdrs = &srp->xdr_stream;
9514 @@ -159,5 +167,6 @@
9515  
9516  static void svcraw_destroy(SVCXPRT *__xprt)
9517  {
9518 +  (void)__xprt;
9519  }
9520  
9521 diff -urN -x .git dietlibc-0.33/librpc/svc_tcp.c dietlibc/librpc/svc_tcp.c
9522 --- dietlibc-0.33/librpc/svc_tcp.c      2012-11-02 11:17:28.000000000 +0000
9523 +++ dietlibc/librpc/svc_tcp.c   2015-01-01 12:14:43.504938894 +0000
9524 @@ -232,6 +232,8 @@
9525         struct sockaddr_in addr;
9526         socklen_t len;
9527  
9528 +       (void)msg;
9529 +
9530         r = (struct tcp_rendezvous *) xprt->xp_p1;
9531    again:
9532         len = sizeof(struct sockaddr_in);
9533 @@ -253,7 +255,7 @@
9534  
9535  static enum xprt_stat rendezvous_stat(SVCXPRT *xprt)
9536  {
9537 -
9538 +  (void)xprt;
9539         return (XPRT_IDLE);
9540  }
9541  
9542 diff -urN -x .git dietlibc-0.33/librpc/svc_udp.c dietlibc/librpc/svc_udp.c
9543 --- dietlibc-0.33/librpc/svc_udp.c      2005-05-08 15:33:39.000000000 +0000
9544 +++ dietlibc/librpc/svc_udp.c   2015-01-01 12:14:43.504938894 +0000
9545 @@ -160,7 +160,7 @@
9546  static enum xprt_stat svcudp_stat(xprt)
9547  SVCXPRT *xprt;
9548  {
9549 -
9550 +  (void)xprt;
9551         return (XPRT_IDLE);
9552  }
9553  
9554 diff -urN -x .git dietlibc-0.33/librpc/xdr_array.c dietlibc/librpc/xdr_array.c
9555 --- dietlibc-0.33/librpc/xdr_array.c    2002-07-31 21:42:20.000000000 +0000
9556 +++ dietlibc/librpc/xdr_array.c 2015-01-01 12:14:43.504938894 +0000
9557 @@ -82,9 +82,9 @@
9558         }
9559         /* duh, look for integer overflow (fefe) */
9560         {
9561 -         unsigned int i;
9562 +         unsigned int j;
9563           nodesize = 0;
9564 -         for (i=c; i; --i) {
9565 +         for (j=c; j; --j) {
9566             unsigned int tmp=nodesize+elsize;
9567             if (tmp<nodesize)   /* overflow */
9568               return FALSE;
9569 diff -urN -x .git dietlibc-0.33/librpc/xdr_mem.c dietlibc/librpc/xdr_mem.c
9570 --- dietlibc-0.33/librpc/xdr_mem.c      2012-11-02 11:17:28.000000000 +0000
9571 +++ dietlibc/librpc/xdr_mem.c   2015-01-01 12:14:43.504938894 +0000
9572 @@ -91,6 +91,7 @@
9573  static void
9574  xdrmem_destroy (XDR *xdrs)
9575  {
9576 +  (void)xdrs;
9577  }
9578  
9579  static bool_t
9580 diff -urN -x .git dietlibc-0.33/librpc/xdr_stdio.c dietlibc/librpc/xdr_stdio.c
9581 --- dietlibc-0.33/librpc/xdr_stdio.c    2003-08-19 19:34:18.000000000 +0000
9582 +++ dietlibc/librpc/xdr_stdio.c 2015-01-01 12:14:43.504938894 +0000
9583 @@ -174,6 +174,8 @@
9584  
9585  static int32_t *xdrstdio_inline(XDR* xdrs, unsigned int len)
9586  {
9587 +  (void)xdrs;
9588 +  (void)len;
9589  
9590         /*
9591          * Must do some work to implement this: must insure
9592 diff -urN -x .git dietlibc-0.33/libstdio/fdglue.c dietlibc/libstdio/fdglue.c
9593 --- dietlibc-0.33/libstdio/fdglue.c     2004-03-02 21:27:19.000000000 +0000
9594 +++ dietlibc/libstdio/fdglue.c  2015-01-01 12:14:43.508272227 +0000
9595 @@ -13,9 +13,9 @@
9596      switch (*mode) {
9597      case 0: return f;
9598      case 'b': break;
9599 -    case 'r': f=O_RDONLY; break;
9600 -    case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
9601 -    case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
9602 +    case 'r': f|=O_RDONLY; break;
9603 +    case 'w': f|=O_WRONLY|O_CREAT|O_TRUNC; break;
9604 +    case 'a': f|=O_WRONLY|O_CREAT|O_APPEND; break;
9605      case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
9606      }
9607      ++mode;
9608 diff -urN -x .git dietlibc-0.33/libstdio/fflush.c dietlibc/libstdio/fflush.c
9609 --- dietlibc-0.33/libstdio/fflush.c     2012-11-02 11:17:28.000000000 +0000
9610 +++ dietlibc/libstdio/fflush.c  2015-01-01 12:14:43.508272227 +0000
9611 @@ -17,7 +17,6 @@
9612    if (stream==0) {
9613      int res;
9614      FILE *f;
9615 -    __fflush_stdin();
9616      __fflush_stdout();
9617      __fflush_stderr();
9618      for (res=0, f=__stdio_root; f; f=f->next)
9619 diff -urN -x .git dietlibc-0.33/libstdio/fgets.c dietlibc/libstdio/fgets.c
9620 --- dietlibc-0.33/libstdio/fgets.c      2012-11-02 11:17:28.000000000 +0000
9621 +++ dietlibc/libstdio/fgets.c   2015-01-01 12:14:43.508272227 +0000
9622 @@ -2,7 +2,8 @@
9623  
9624  char *fgets_unlocked(char *s, int size, FILE *stream) {
9625    int l;
9626 -  for (l=0; l<size; ) {
9627 +  if (size<=0) return 0;
9628 +  for (l=0; l+1<size; ) {
9629      register int c;
9630      if (l && __likely(stream->bm<stream->bs)) {
9631        /* try common case first */
9632 @@ -11,17 +12,14 @@
9633        c=fgetc_unlocked(stream);
9634        if (__unlikely(c==EOF)) {
9635         if (!l) return 0;
9636 -       goto fini;
9637 +       break;
9638        }
9639      }
9640      s[l]=c;
9641      ++l;
9642 -    if (c=='\n') {
9643 -fini:
9644 -      s[l]=0;
9645 -      break;
9646 -    }
9647 +    if (c=='\n') break;
9648    }
9649 +  s[l]=0;
9650    return s;
9651  }
9652  
9653 diff -urN -x .git dietlibc-0.33/libstdio/fread.c dietlibc/libstdio/fread.c
9654 --- dietlibc-0.33/libstdio/fread.c      2005-09-28 06:18:44.000000000 +0000
9655 +++ dietlibc/libstdio/fread.c   2015-01-01 12:14:43.508272227 +0000
9656 @@ -3,7 +3,6 @@
9657  #include <unistd.h>
9658  
9659  size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream) {
9660 -  int res;
9661    unsigned long i,j;
9662    j=size*nmemb;
9663    i=0;
9664 @@ -44,6 +43,7 @@
9665    }
9666  #endif
9667    for (; i<j; ++i) {
9668 +    int res;
9669      res=fgetc_unlocked(stream);
9670      if (res==EOF)
9671  exit:
9672 diff -urN -x .git dietlibc-0.33/libugly/asctime.c dietlibc/libugly/asctime.c
9673 --- dietlibc-0.33/libugly/asctime.c     2001-02-01 22:14:06.000000000 +0000
9674 +++ dietlibc/libugly/asctime.c  2015-01-01 12:14:43.508272227 +0000
9675 @@ -1,6 +1,6 @@
9676  #include <time.h>
9677  
9678 -static char buf[25];
9679 +static char buf[26];
9680  
9681  char *asctime(const struct tm *timeptr) {
9682    return asctime_r(timeptr,buf);
9683 diff -urN -x .git dietlibc-0.33/libugly/asctime_r.c dietlibc/libugly/asctime_r.c
9684 --- dietlibc-0.33/libugly/asctime_r.c   2001-07-20 13:10:07.000000000 +0000
9685 +++ dietlibc/libugly/asctime_r.c        2015-01-01 12:14:43.508272227 +0000
9686 @@ -9,7 +9,7 @@
9687  }
9688  
9689  char *asctime_r(const struct tm *t, char *buf) {
9690 -  /* "Wed Jun 30 21:49:08 1993\n" */
9691 +  /* "Wed Jun 30 21:49:08 1993\n\0" */
9692    *(int*)buf=*(int*)(days+(t->tm_wday<<2));
9693    *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
9694    num2str(buf+8,t->tm_mday);
9695 @@ -25,5 +25,6 @@
9696    num2str(buf+20,(t->tm_year+1900)/100);
9697    num2str(buf+22,(t->tm_year+1900)%100);
9698    buf[24]='\n';
9699 +  buf[25]='\0';
9700    return buf;
9701  }
9702 diff -urN -x .git dietlibc-0.33/libugly/gethostent.c dietlibc/libugly/gethostent.c
9703 --- dietlibc-0.33/libugly/gethostent.c  2003-06-23 10:48:13.000000000 +0000
9704 +++ dietlibc/libugly/gethostent.c       2015-01-01 12:14:43.511605561 +0000
9705 @@ -74,11 +74,11 @@
9706      while (cur<last && !isspace(*cur)) ++cur;
9707      {
9708        char *from=pe->h_aliases[aliasidx];
9709 -      int len=cur-from;
9710 -      if (max-dest<len+2) goto nospace;
9711 +      int l=cur-from;
9712 +      if (max-dest<l+2) goto nospace;
9713        pe->h_aliases[aliasidx]=dest;
9714        memmove(dest,from,(size_t)(cur-from));
9715 -      dest+=len;
9716 +      dest+=l;
9717        *dest=0; ++dest;
9718      }
9719      if (*cur=='\n') { ++cur; ++aliasidx; break; }
9720 diff -urN -x .git dietlibc-0.33/libugly/strftime.c dietlibc/libugly/strftime.c
9721 --- dietlibc-0.33/libugly/strftime.c    2012-04-19 16:50:23.000000000 +0000
9722 +++ dietlibc/libugly/strftime.c 2015-01-01 12:14:43.514938893 +0000
9723 @@ -45,46 +45,47 @@
9724             else
9725  again:
9726             switch (*format) {
9727 -//          case '%': *p++ = '%';                               break;                 // reduce size of jump table
9728 -           case 'n': *p++ = '\n';                               break;
9729 -           case 't': *p++ = '\t';                               break;
9730 +//          case '%': *p++ = '%';                              break;                  // reduce size of jump table
9731 +           case 'n': *p++ = '\n';                              break;
9732 +           case 't': *p++ = '\t';                              break;
9733             case 'O': case 'E': ++format; goto again;
9734 -           case 'c': src = "%b %a %d %k:%M:%S %Z %Y";           goto _strf;
9735 -           case 'r': src = "%I:%M:%S %p";                       goto _strf;
9736 -           case 'R': src = "%H:%M";                             goto _strf;
9737 -           case 'x': src = "%b %a %d";                          goto _strf;
9738 -           case 'X': src = "%k:%M:%S";                          goto _strf;
9739 -           case 'D': src = "%m/%d/%y";                          goto _strf;
9740 +           case 'c': src = "%b %a %d %k:%M:%S %Z %Y";          goto _strf;
9741 +           case 'r': src = "%I:%M:%S %p";                      goto _strf;
9742 +           case 'R': src = "%H:%M";                            goto _strf;
9743 +           case 'x': src = "%b %a %d";                         goto _strf;
9744 +           case 'X': src = "%k:%M:%S";                         goto _strf;
9745 +           case 'D': src = "%m/%d/%y";                         goto _strf;
9746 +           case 'F': src = "%Y-%m-%d";                         goto _strf;
9747             case 'T': src = "%H:%M:%S";
9748                _strf: p  += strftime (p, (size_t)(dst+max-p), src, tm);          break;
9749 -           case 'a': src = sweekdays [tm->tm_wday];             goto _str;
9750 -           case 'A': src = weekdays  [tm->tm_wday];             goto _str;
9751 +           case 'a': src = sweekdays [tm->tm_wday];            goto _str;
9752 +           case 'A': src = weekdays  [tm->tm_wday];            goto _str;
9753             case 'h':
9754 -           case 'b': src = smonths   [tm->tm_mon];              goto _str;
9755 -           case 'B': src = months    [tm->tm_mon];              goto _str;
9756 +           case 'b': src = smonths   [tm->tm_mon];             goto _str;
9757 +           case 'B': src = months    [tm->tm_mon];             goto _str;
9758             case 'p': src = ampm [tm->tm_hour > 12 ? 3 : 2]; goto _str;
9759             case 'P': src = ampm [tm->tm_hour > 12 ? 1 : 0]; goto _str;
9760 -           case 'C': no  = tm->tm_year/100 + 19;                goto _no;
9761 -           case 'd': no  = tm->tm_mday;                         goto _no;
9762 -           case 'e': no  = tm->tm_mday;                         goto _nos;
9763 -           case 'H': no  = tm->tm_hour;                         goto _no;
9764 -           case 'I': no  = tm->tm_hour % 12;                    goto _no;
9765 -           case 'j': no  = tm->tm_yday;                         goto _no;
9766 -           case 'k': no  = tm->tm_hour;                         goto _nos;
9767 -           case 'l': no  = tm->tm_hour % 12;                    goto _nos;
9768 -           case 'm': no  = tm->tm_mon + 1;                      goto _no;
9769 -           case 'M': no  = tm->tm_min;                          goto _no;
9770 -           case 'S': no  = tm->tm_sec;                          goto _no;
9771 -           case 'u': no  = tm->tm_wday ? tm->tm_wday : 7;       goto _no;
9772 -           case 'w': no  = tm->tm_wday;                         goto _no;
9773 +           case 'C': no  = tm->tm_year/100 + 19;               goto _no;
9774 +           case 'd': no  = tm->tm_mday;                        goto _no;
9775 +           case 'e': no  = tm->tm_mday;                        goto _nos;
9776 +           case 'H': no  = tm->tm_hour;                        goto _no;
9777 +           case 'I': no  = tm->tm_hour % 12;                   goto _no;
9778 +           case 'j': no  = tm->tm_yday;                        goto _no;
9779 +           case 'k': no  = tm->tm_hour;                        goto _nos;
9780 +           case 'l': no  = tm->tm_hour % 12;                   goto _nos;
9781 +           case 'm': no  = tm->tm_mon + 1;                     goto _no;
9782 +           case 'M': no  = tm->tm_min;                         goto _no;
9783 +           case 'S': no  = tm->tm_sec;                         goto _no;
9784 +           case 'u': no  = tm->tm_wday ? tm->tm_wday : 7;      goto _no;
9785 +           case 'w': no  = tm->tm_wday;                        goto _no;
9786             case 'U': no  = (tm->tm_yday - tm->tm_wday + 7) / 7; goto _no;
9787             case 'W': no  = (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7; goto _no;
9788             case 's': {
9789                         time_t t = mktime((struct tm*)tm);
9790 -                       char buf[101];
9791 +                       char sbuf[101];
9792                         char* c;
9793 -                       buf[100]=0;
9794 -                       for (c=buf+99; c>buf; --c) {
9795 +                       sbuf[100]=0;
9796 +                       for (c=sbuf+99; c>sbuf; --c) {
9797                           *c=(t%10)+'0';
9798                           t/=10;
9799                           if (!t) break;
9800 diff -urN -x .git dietlibc-0.33/libugly/strptime.c dietlibc/libugly/strptime.c
9801 --- dietlibc-0.33/libugly/strptime.c    2008-12-10 20:00:59.000000000 +0000
9802 +++ dietlibc/libugly/strptime.c 2015-01-01 12:14:43.514938893 +0000
9803 @@ -119,10 +119,10 @@
9804         ++s;
9805         break;
9806        case 'x':
9807 -       s=strptime(s,"%b %a %d",tm);
9808 +       s=strptime(s,"%m/%d/%y",tm);
9809         break;
9810        case 'X':
9811 -       s=strptime(s,"%k:%M:%S",tm);
9812 +       s=strptime(s,"%H:%M:%S",tm);
9813         break;
9814        case 'y':
9815         i=getint(&s,2);
9816 diff -urN -x .git dietlibc-0.33/libugly/timegm.c dietlibc/libugly/timegm.c
9817 --- dietlibc-0.33/libugly/timegm.c      2005-01-31 12:53:34.000000000 +0000
9818 +++ dietlibc/libugly/timegm.c   2015-01-01 12:14:43.514938893 +0000
9819 @@ -14,6 +14,7 @@
9820    if (t->tm_min>60) { t->tm_hour += t->tm_min/60; t->tm_min%=60; }
9821    if (t->tm_hour>60) { t->tm_mday += t->tm_hour/60; t->tm_hour%=60; }
9822    if (t->tm_mon>12) { t->tm_year += t->tm_mon/12; t->tm_mon%=12; }
9823 +  if (t->tm_mon<0) t->tm_mon=0;
9824    while (t->tm_mday>__spm[1+t->tm_mon]) {
9825      if (t->tm_mon==1 && __isleap(t->tm_year+1900)) {
9826        if (t->tm_mon==31+29) break;
9827 diff -urN -x .git dietlibc-0.33/linuxnet.h dietlibc/linuxnet.h
9828 --- dietlibc-0.33/linuxnet.h    2001-06-16 17:49:29.000000000 +0000
9829 +++ dietlibc/linuxnet.h 2015-01-01 12:14:43.514938893 +0000
9830 @@ -16,4 +16,7 @@
9831  #define SYS_GETSOCKOPT 15              /* sys_getsockopt(2)            */
9832  #define SYS_SENDMSG    16              /* sys_sendmsg(2)               */
9833  #define SYS_RECVMSG    17              /* sys_recvmsg(2)               */
9834 +#define SYS_ACCEPT4    18              /* sys_accept4(2)               */
9835 +#define SYS_RECVMMSG   19              /* sys_recvmmsg(2)              */
9836 +#define SYS_SENDMMSG   20              /* sys_sendmmsg(2)              */
9837  
9838 diff -urN -x .git dietlibc-0.33/Makefile dietlibc/Makefile
9839 --- dietlibc-0.33/Makefile      2012-11-02 11:17:28.000000000 +0000
9840 +++ dietlibc/Makefile   2015-01-01 12:14:43.451605563 +0000
9841 @@ -8,7 +8,9 @@
9842  BINDIR=${prefix}/bin
9843  MAN1DIR=${prefix}/man/man1
9844  
9845 -MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6]t\?e\?[lb]/arm/')
9846 +EXTRACFLAGS=
9847 +
9848 +MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-7]t\?[eh]\?j\?[lb]/arm/')
9849  
9850  # This extra-ugly cruft is here so make will not run uname and sed each
9851  # time it looks at $(OBJDIR).  This alone sped up running make when
9852 @@ -100,10 +102,13 @@
9853  
9854  profiling: $(OBJDIR)/libgmon.a $(OBJDIR)/pstart.o
9855  
9856 -CFLAGS=-pipe -nostdinc
9857 +DEFAULTCFLAGS=-pipe -nostdinc -D_REENTRANT $(EXTRACFLAGS)
9858 +CFLAGS=$(DEFAULTCFLAGS)
9859  CROSS=
9860  
9861  CC=gcc
9862 +CCC=$(CROSS)$(CC)
9863 +STRIP=$(COMMENT) $(CROSS)strip
9864  INC=-I. -isystem include
9865  
9866  VPATH=lib:libstdio:libugly:libcruft:libcrypt:libshell:liblatin1:libcompat:libdl:librpc:libregex:libm:profiling
9867 @@ -128,19 +133,26 @@
9868  
9869  LIBGMON_OBJS=$(OBJDIR)/__mcount.o $(OBJDIR)/monitor.o $(OBJDIR)/profil.o
9870  
9871 +NO_STACK_PROTECTOR=stackgap.o __get_elf_aux_value.o
9872 +
9873  include $(ARCH)/Makefile.add
9874  
9875  LIBMATHOBJ=$(patsubst %,$(OBJDIR)/%,$(LIBMATH))
9876  
9877 -ifeq ($(CFLAGS),-pipe -nostdinc)
9878 +ifeq ($(CFLAGS),$(DEFAULTCFLAGS))
9879  CFLAGS+=-O -fomit-frame-pointer
9880  endif
9881  
9882  ifneq ($(DEBUG),)
9883  CFLAGS = -g
9884 -COMMENT = :
9885 +STRIP = :
9886 +endif
9887 +CFLAGS += -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow
9888 +
9889 +ASM_CFLAGS = -Wa,--noexecstack
9890 +ifneq ($(subst clang,fnord,$(CC)),$(CC))
9891 +ASM_CFLAGS += -fno-integrated-as
9892  endif
9893 -CFLAGS += -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls
9894  
9895  PWD=$(shell pwd)
9896  
9897 @@ -155,31 +167,35 @@
9898  
9899  % :: %,v
9900  
9901 -$(OBJDIR)/%: $(OBJDIR)
9902 -
9903  ifeq ($(CC),tcc)
9904 -$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h
9905 -       $(CROSS)cpp $(INC) $< | $(CROSS)as -o $@
9906 +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h | $(OBJDIR)
9907 +       $(CROSS)cpp $(INC) $< | $(CROSS)as --noexecstack -o $@
9908  
9909 -$(OBJDIR)/%.o: %.c
9910 +$(OBJDIR)/%.o: %.c | $(OBJDIR)
9911         tcc -I. -Iinclude -c $< -o $@
9912 -       $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
9913 +       -$(STRIP) -x -R .comment -R .note $@
9914  else
9915 -$(OBJDIR)/pstart.o: start.S
9916 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -DPROFILING -c $< -o $@
9917 +$(OBJDIR)/pstart.o: start.S | $(OBJDIR)
9918 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -DPROFILING -c $< $(ASM_CFLAGS) -o $@
9919 +
9920 +$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h | $(OBJDIR)
9921 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -c $< $(ASM_CFLAGS) -o $@
9922  
9923 -$(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h
9924 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@
9925 +$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c | $(OBJDIR)
9926 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -c $< -o $@
9927 +       -$(STRIP) -x -R .comment -R .note $@
9928 +$(OBJDIR)/stack_smash_handler2.o:      EXTRACFLAGS:=-fno-omit-frame-pointer
9929  
9930 -$(OBJDIR)/pthread_%.o: libpthread/pthread_%.c
9931 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@
9932 -       $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
9933 +$(OBJDIR)/%.o: %.c | $(OBJDIR)
9934 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -c $< -o $@ -D__dietlibc__
9935 +       -$(STRIP) -x -R .comment -R .note $@
9936  
9937 -$(OBJDIR)/%.o: %.c
9938 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ -D__dietlibc__
9939 -       $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
9940 +$(addprefix $(OBJDIR)/,$(NO_STACK_PROTECTOR)) \
9941 +$(addprefix $(PICODIR)/,$(NO_STACKPROTECTOR)): EXTRACFLAGS+=-fno-stack-protector
9942  endif
9943  
9944 +
9945 +
9946  ifeq ($(shell $(CC) -v 2>&1 | grep "gcc version"),gcc version 4.0.0)
9947  SAFE_CFLAGS=$(shell echo $(CFLAGS)|sed 's/-Os/-O2/')
9948  SAFER_CFLAGS=$(shell echo $(CFLAGS)|sed 's/-Os/-O/')
9949 @@ -190,8 +206,8 @@
9950  
9951  CC+=-D__dietlibc__
9952  
9953 -$(OBJDIR)/crypt.o: libcrypt/crypt.c
9954 -       $(CROSS)$(CC) $(INC) $(SAFER_CFLAGS) -c $< -o $@
9955 +$(OBJDIR)/crypt.o: libcrypt/crypt.c | $(OBJDIR)
9956 +       $(CCC) $(INC) $(SAFER_CFLAGS) $(EXTRACFLAGS) -c $< -o $@
9957  
9958  DIETLIBC_OBJ = $(OBJDIR)/unified.o \
9959  $(SYSCALLOBJ) $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \
9960 @@ -205,9 +221,9 @@
9961  $(OBJDIR)/librpc.a: $(LIBRPCOBJ)
9962         $(CROSS)ar cru $@ $(LIBRPCOBJ)
9963  
9964 -$(OBJDIR)/libcrypt.a:
9965 +$(OBJDIR)/libcrypt.a: | $(OBJDIR)
9966         touch dummy.c
9967 -       $(CROSS)$(CC) -c dummy.c
9968 +       $(CCC) -c dummy.c
9969         $(CROSS)ar cru $@ dummy.o
9970         rm -f dummy.c dummy.o
9971  
9972 @@ -242,23 +258,23 @@
9973         $(PICODIR)/libpthread.so $(PICODIR)/libdl.so $(PICODIR)/libcompat.so \
9974         $(PICODIR)/libm.so $(PICODIR)/diet-dyn $(PICODIR)/diet-dyn-i
9975  
9976 -$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h
9977 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
9978 +$(PICODIR)/%.o: %.S $(ARCH)/syscalls.h | $(PICODIR)
9979 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB $(ASM_CFLAGS) -c $< -o $@
9980  
9981 -$(PICODIR)/pthread_%.o: libpthread/pthread_%.c
9982 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
9983 -       $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@
9984 -
9985 -$(PICODIR)/%.o: %.c
9986 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
9987 -       $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@
9988 -
9989 -$(PICODIR)/dstart.o: start.S
9990 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
9991 -
9992 -$(PICODIR)/dyn_so_start.o: dyn_start.c
9993 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@
9994 -       $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@
9995 +$(PICODIR)/pthread_%.o: libpthread/pthread_%.c | $(PICODIR)
9996 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
9997 +       $(STRIP) -x -R .comment -R .note $@
9998 +
9999 +$(PICODIR)/%.o: %.c | $(PICODIR)
10000 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB -c $< -o $@
10001 +       $(STRIP) -x -R .comment -R .note $@
10002 +
10003 +$(PICODIR)/dstart.o: start.S | $(PICODIR)
10004 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB $(ASM_CFLAGS) -c $< -o $@
10005 +
10006 +$(PICODIR)/dyn_so_start.o: dyn_start.c | $(PICODIR)
10007 +       $(CCC) $(INC) $(CFLAGS) $(EXTRACFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@
10008 +       $(STRIP) -x -R .comment -R .note $@
10009  
10010  DYN_LIBC_PIC = $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \
10011  $(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ)
10012 @@ -274,55 +290,55 @@
10013  
10014  DYN_LIBMATH_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBMATHOBJ))
10015  
10016 -$(PICODIR)/libc.so: $(PICODIR) $(DYN_LIBC_OBJ)
10017 -       $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so
10018 +$(PICODIR)/libc.so: $(DYN_LIBC_OBJ)
10019 +       $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so
10020  
10021 -$(PICODIR)/libpthread.so: $(DYN_PTHREAD_OBJS) dietfeatures.h
10022 -       $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so
10023 +$(PICODIR)/libpthread.so: $(DYN_PTHREAD_OBJS) dietfeatures.h $(PICODIR)/libc.so
10024 +       $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so
10025  
10026 -$(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h
10027 -       $(LD_UNSET) $(CROSS)$(CC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -Bsymbolic -Wl,-Bsymbolic \
10028 +$(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h $(PICODIR)/libc.so
10029 +       $(LD_UNSET) $(CCC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -Bsymbolic -Wl,-Bsymbolic \
10030                 -o $@ $(SAFE_CFLAGS) $(INC) libdl/_dl_main.c -Wl,-soname=libdl.so
10031  
10032  $(OBJDIR)/pthread_create.o $(PICODIR)/pthread_create.o: dietfeatures.h
10033  $(OBJDIR)/pthread_internal.o $(PICODIR)/pthread_internal.o: dietfeatures.h
10034  
10035  #$(PICODIR)/libdl.so: $(DYN_LIBDL_OBJS) dietfeatures.h
10036 -#      $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBDL_OBJS) -L$(PICODIR) -ldietc -Wl,-soname=libdl.so
10037 +#      $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBDL_OBJS) -L$(PICODIR) -ldietc -Wl,-soname=libdl.so
10038  
10039 -$(PICODIR)/libcompat.so: $(DYN_LIBCOMPAT_OBJS) dietfeatures.h
10040 -       $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBCOMPAT_OBJS) -L$(PICODIR) -lc -Wl,-soname=libcompat.so
10041 +$(PICODIR)/libcompat.so: $(DYN_LIBCOMPAT_OBJS) dietfeatures.h $(PICODIR)/libc.so
10042 +       $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBCOMPAT_OBJS) -L$(PICODIR) -lc -Wl,-soname=libcompat.so
10043  
10044 -$(PICODIR)/libm.so: $(DYN_LIBMATH_OBJS) dietfeatures.h
10045 -       $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBMATH_OBJS) -L$(PICODIR) -lc -Wl,-soname=libm.so
10046 +$(PICODIR)/libm.so: $(DYN_LIBMATH_OBJS) dietfeatures.h $(PICODIR)/libc.so
10047 +       $(LD_UNSET) $(CCC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBMATH_OBJS) -L$(PICODIR) -lc -Wl,-soname=libm.so
10048  
10049  
10050  $(SYSCALLOBJ): syscalls.h
10051  
10052  $(OBJDIR)/elftrunc: $(OBJDIR)/diet contrib/elftrunc.c
10053 -       bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/elftrunc.c
10054 +       bin-$(MYARCH)/diet $(CCC) $(CFLAGS) -o $@ contrib/elftrunc.c
10055  
10056  $(OBJDIR)/dnsd: $(OBJDIR)/diet contrib/dnsd.c
10057 -       bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/dnsd.c
10058 +       bin-$(MYARCH)/diet $(CCC) $(CFLAGS) -o $@ contrib/dnsd.c
10059  
10060  VERSION=dietlibc-$(shell head -n 1 CHANGES|sed 's/://')
10061  CURNAME=$(notdir $(shell pwd))
10062  
10063  $(OBJDIR)/diet: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o
10064 -       $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc
10065 -       $(CROSS)strip -R .comment -R .note $@
10066 +       $(CCC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc
10067 +       $(STRIP) -R .comment -R .note $@
10068  
10069  $(OBJDIR)/diet-i: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o
10070 -       $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc
10071 -       $(CROSS)strip -R .comment -R .note $@
10072 +       $(CCC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc
10073 +       $(STRIP) -R .comment -R .note $@
10074  
10075  $(PICODIR)/diet-dyn: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c
10076 -       $(LD_UNSET) $(CROSS)$(CC) -isystem include $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(HOME)/$(PICODIR)/libdl.so
10077 -       $(CROSS)strip -R .command -R .note $@
10078 +       $(LD_UNSET) $(CCC) -isystem include $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(HOME)/$(PICODIR)/libdl.so
10079 +       $(STRIP) -R .command -R .note $@
10080  
10081  $(PICODIR)/diet-dyn-i: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c
10082 -       $(LD_UNSET) $(CROSS)$(CC) -isystem include $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(ILIBDIR)/libdl.so -DINSTALLVERSION
10083 -       $(CROSS)strip -R .command -R .note $@
10084 +       $(LD_UNSET) $(CCC) -isystem include $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(ILIBDIR)/libdl.so -DINSTALLVERSION
10085 +       $(STRIP) -R .command -R .note $@
10086  
10087  $(OBJDIR)/djb: $(OBJDIR)/compile $(OBJDIR)/load
10088  
10089 @@ -335,7 +351,7 @@
10090         chmod 755 $@
10091  
10092  clean:
10093 -       rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so
10094 +       rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so include/errno_definition.h
10095         rm -rf bin-* pic-*
10096         $(MAKE) -C examples clean
10097         $(MAKE) -C dynlinker clean
10098 @@ -352,14 +368,14 @@
10099  
10100  .PHONY: t t1
10101  t:
10102 -       $(CROSS)$(CC) -g $(CFLAGS) -fno-builtin -nostdlib -isystem include -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dietlibc.a -lgcc $(OBJDIR)/dyn_stop.o -Wl,-Map,mapfile
10103 +       $(CCC) -g $(CFLAGS) -fno-builtin -nostdlib -isystem include -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dietlibc.a -lgcc $(OBJDIR)/dyn_stop.o -Wl,-Map,mapfile
10104  
10105  t1:
10106 -       $(CROSS)$(CC) -g -o t1 t.c
10107 +       $(CCC) -g -o t1 t.c
10108  
10109  install-bin: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/librpc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/elftrunc $(OBJDIR)/diet-i
10110         $(INSTALL) -d $(DESTDIR)$(ILIBDIR) $(DESTDIR)$(MAN1DIR) $(DESTDIR)$(BINDIR)
10111 -       $(INSTALL) $(OBJDIR)/start.o $(DESTDIR)$(ILIBDIR)/start.o
10112 +       $(INSTALL) -m 644 $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)/
10113         $(INSTALL) -m 644 $(OBJDIR)/libm.a $(OBJDIR)/libpthread.a $(OBJDIR)/librpc.a \
10114  $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/libcrypt.a $(DESTDIR)$(ILIBDIR)
10115         $(INSTALL) -m 644 $(OBJDIR)/dietlibc.a $(DESTDIR)$(ILIBDIR)/libc.a
10116 @@ -371,7 +387,7 @@
10117         $(INSTALL) -m 644 diet.1 $(DESTDIR)$(MAN1DIR)/diet.1
10118  
10119  install-profiling:
10120 -       -$(INSTALL) $(OBJDIR)/pstart.o $(OBJDIR)/libgmon.a $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)
10121 +       -$(INSTALL) $(OBJDIR)/pstart.o $(OBJDIR)/libgmon.a $(DESTDIR)$(ILIBDIR)
10122  
10123  install-pic:
10124         -$(INSTALL) $(PICODIR)/libc.so $(DESTDIR)$(ILIBDIR)/libc.so
10125 @@ -445,6 +461,10 @@
10126  cross:
10127         $(MAKE) $(subst $(ARCH),,$(CROSS_ARCH))
10128  
10129 +# DOES NOT WORK YET
10130 +mips64:
10131 +       ARCH=mips64 CROSS=mips64-linux- CC="gcc -mabi=64"
10132 +
10133  
10134  # these depend on dietfeatures.h for large file backward compatibility
10135  $(OBJDIR)/__fstat64.o $(OBJDIR)/__lstat64.o $(OBJDIR)/__stat64.o $(OBJDIR)/lseek64.o $(OBJDIR)/readdir64.o $(OBJDIR)/stat64.o $(OBJDIR)/lstat64.o $(OBJDIR)/fstat64.o $(OBJDIR)/truncate64.o $(OBJDIR)/__truncate64.o $(OBJDIR)/ftruncate64.o $(OBJDIR)/__ftruncate64.o $(OBJDIR)/sendfile64.o $(OBJDIR)/__sendfile64.o $(PICODIR)/dyn_syscalls.o $(PICODIR)/__truncate64.o $(PICODIR)/__ftruncate64.o $(PICODIR)/__stat64.o $(PICODIR)/__lstat64.o $(PICODIR)/__fstat64.o $(OBJDIR)/__sendfile64.o $(OBJDIR)/fstatfs64.o $(OBJDIR)/statfs64.o: dietfeatures.h
10136 @@ -519,6 +539,10 @@
10137  # these depend on dietfeatures.h for WANT_INET_ADDR_DNS
10138  $(OBJDIR)/gethostbyname_r.o: dietfeatures.h
10139  
10140 +# these depend on dietfeatures.h for WANT_VALGRIND_SUPPORT
10141 +bin-x86_64/strlen.o bin-x86_64/memchr.o bin-x86_64/gettimeofday.o: dietfeatures.h
10142 +bin-x32/strlen.o bin-x32/memchr.o bin-x32/gettimeofday.o: dietfeatures.h
10143 +
10144  # WANT_PLUGPLAY_DNS
10145  $(OBJDIR)/getaddrinfo.o: dietfeatures.h
10146  
10147 @@ -531,11 +555,84 @@
10148  # WANT_LARGEFILE_BACKCOMPAT
10149  $(OBJDIR)/fcntl64.o: dietfeatures.h
10150  
10151 -# WANT_SSP
10152 -# This facepalm brought to you by: Ubuntu!
10153 -$(OBJDIR)/stackgap.o: lib/stackgap.c dietfeatures.h
10154 -       $(CROSS)$(CC) $(INC) $(CFLAGS) -c lib/stackgap.c -o $@ -D__dietlibc__ -fno-stack-protector
10155 -       $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@
10156 -
10157  # WANT_MALLOC_ZERO
10158  $(OBJDIR)/strndup.o: dietfeatures.h
10159 +
10160 +# dietdirent.h dependencies
10161 +$(OBJDIR)/closedir.o $(OBJDIR)/fdopendir.o $(OBJDIR)/ftw.o $(OBJDIR)/ftw64.o $(OBJDIR)/opendir.o $(OBJDIR)/readdir.o $(OBJDIR)/readdir64.o $(OBJDIR)/readdir_r.o $(OBJDIR)/rewinddir.o $(OBJDIR)/seekdir.o $(OBJDIR)/telldir.o $(OBJDIR)/dirfd.o: dietdirent.h
10162 +
10163 +$(OBJDIR)/thrd_%.o: include/thread.h
10164 +
10165 +$(OBJDIR)/__fcntl64.o $(OBJDIR)/__fstat64.o $(OBJDIR)/__fstatfs64.o $(OBJDIR)/__ftruncate64.o \
10166 +$(OBJDIR)/__getcwd.o $(OBJDIR)/__lstat64.o $(OBJDIR)/__mmap.o $(OBJDIR)/__ptrace.o \
10167 +$(OBJDIR)/__sendfile64.o $(OBJDIR)/__stat64.o $(OBJDIR)/__statfs64.o $(OBJDIR)/__stime.o \
10168 +$(OBJDIR)/__truncate64.o $(OBJDIR)/__utmp_io.o $(OBJDIR)/__v_printf.o $(OBJDIR)/addmntent.o \
10169 +$(OBJDIR)/alloc.o $(OBJDIR)/bindresvport.o $(OBJDIR)/cfsetispeed.o $(OBJDIR)/cfsetospeed.o \
10170 +$(OBJDIR)/clnt_generic.o $(OBJDIR)/clnt_tcp.o $(OBJDIR)/clnt_udp.o $(OBJDIR)/cnd_timedwait.o \
10171 +$(OBJDIR)/cnd_wait.o $(OBJDIR)/confstr.o $(OBJDIR)/dnscruft2.o $(OBJDIR)/dnsd.o \
10172 +$(OBJDIR)/err.o $(OBJDIR)/errno_location.o $(OBJDIR)/errx.o $(OBJDIR)/execl.o \
10173 +$(OBJDIR)/execle.o $(OBJDIR)/execlp.o $(OBJDIR)/execv.o $(OBJDIR)/execvp.o \
10174 +$(OBJDIR)/fdglue.o $(OBJDIR)/fdglue2.o $(OBJDIR)/fdopen.o $(OBJDIR)/freopen.o \
10175 +$(OBJDIR)/ftell.o $(OBJDIR)/fwrite.o $(OBJDIR)/getdelim.o $(OBJDIR)/gethostbyaddr.o \
10176 +$(OBJDIR)/gethostbyaddr_r.o $(OBJDIR)/gethostbyname.o $(OBJDIR)/gethostbyname2.o \
10177 +$(OBJDIR)/gethostbyname2_r.o $(OBJDIR)/gethostbyname_r.o $(OBJDIR)/gethostent.o \
10178 +$(OBJDIR)/getpass.o $(OBJDIR)/glob.o $(OBJDIR)/herrno_location.o $(OBJDIR)/iconv.o \
10179 +$(OBJDIR)/iconv_open.o $(OBJDIR)/inet_pton.o $(OBJDIR)/isatty.o $(OBJDIR)/lockf.o \
10180 +$(OBJDIR)/logging.o $(OBJDIR)/lseek64.o $(OBJDIR)/mbrlen.o $(OBJDIR)/mbrtowc.o \
10181 +$(OBJDIR)/mkdtemp.o $(OBJDIR)/mkstemp.o $(OBJDIR)/mktemp.o $(OBJDIR)/mmap64.o \
10182 +$(OBJDIR)/mtx_lock.o $(OBJDIR)/mtx_timedlock.o $(OBJDIR)/mtx_trylock.o \
10183 +$(OBJDIR)/mtx_unlock.o $(OBJDIR)/netent.o $(OBJDIR)/nice.o $(OBJDIR)/openpty.o \
10184 +$(OBJDIR)/perror.o $(OBJDIR)/pmap_getmaps.o $(OBJDIR)/pmap_rmt.o \
10185 +$(OBJDIR)/pthread_atfork.o $(OBJDIR)/pthread_attr_getdetachstate.o \
10186 +$(OBJDIR)/pthread_attr_getinheritsched.o $(OBJDIR)/pthread_attr_getschedparam.o \
10187 +$(OBJDIR)/pthread_attr_getschedpolicy.o $(OBJDIR)/pthread_attr_getscope.o \
10188 +$(OBJDIR)/pthread_attr_getstackaddr.o $(OBJDIR)/pthread_attr_getstacksize.o \
10189 +$(OBJDIR)/pthread_attr_setdetachstate.o $(OBJDIR)/pthread_attr_setinheritsched.o \
10190 +$(OBJDIR)/pthread_attr_setschedparam.o $(OBJDIR)/pthread_attr_setschedpolicy.o \
10191 +$(OBJDIR)/pthread_attr_setscope.o $(OBJDIR)/pthread_attr_setstackaddr.o \
10192 +$(OBJDIR)/pthread_attr_setstacksize.o $(OBJDIR)/pthread_cleanup.o \
10193 +$(OBJDIR)/pthread_cond_broadcast.o $(OBJDIR)/pthread_cond_destroy.o \
10194 +$(OBJDIR)/pthread_cond_init.o $(OBJDIR)/pthread_cond_signal.o \
10195 +$(OBJDIR)/pthread_cond_timedwait.o $(OBJDIR)/pthread_cond_wait.o \
10196 +$(OBJDIR)/pthread_condattr_getshared.o $(OBJDIR)/pthread_condattr_setshared.o \
10197 +$(OBJDIR)/pthread_create.o $(OBJDIR)/pthread_detach.o $(OBJDIR)/pthread_fdglue2.o \
10198 +$(OBJDIR)/pthread_internal.o $(OBJDIR)/pthread_join.o $(OBJDIR)/pthread_key.o \
10199 +$(OBJDIR)/pthread_mutex_destroy.o $(OBJDIR)/pthread_mutex_init.o \
10200 +$(OBJDIR)/pthread_mutex_lock.o $(OBJDIR)/pthread_mutex_trylock.o \
10201 +$(OBJDIR)/pthread_mutex_unlock.o $(OBJDIR)/pthread_mutexattr_getkind_np.o \
10202 +$(OBJDIR)/pthread_mutexattr_init.o $(OBJDIR)/pthread_mutexattr_setkind_np.o \
10203 +$(OBJDIR)/pthread_semaphore_destroy.o $(OBJDIR)/pthread_semaphore_getvalue.o \
10204 +$(OBJDIR)/pthread_semaphore_init.o $(OBJDIR)/pthread_semaphore_misc.o \
10205 +$(OBJDIR)/pthread_semaphore_post.o $(OBJDIR)/pthread_semaphore_trywait.o \
10206 +$(OBJDIR)/pthread_semaphore_wait.o $(OBJDIR)/pthread_setcancelstate.o \
10207 +$(OBJDIR)/pthread_setschedparam.o $(OBJDIR)/pthread_spinlock.o \
10208 +$(OBJDIR)/putenv.o $(OBJDIR)/putpwent.o $(OBJDIR)/readdir64.o \
10209 +$(OBJDIR)/realpath.o $(OBJDIR)/remove.o $(OBJDIR)/res_mkquery.o \
10210 +$(OBJDIR)/res_query.o $(OBJDIR)/res_search.o $(OBJDIR)/sigaddset.o \
10211 +$(OBJDIR)/sigdelset.o $(OBJDIR)/sigismember.o $(OBJDIR)/signalfd.o \
10212 +$(OBJDIR)/strerror.o $(OBJDIR)/strtol.o $(OBJDIR)/strtoll.o \
10213 +$(OBJDIR)/strtoul.o $(OBJDIR)/strtoull.o $(OBJDIR)/svc.o \
10214 +$(OBJDIR)/svc_run.o $(OBJDIR)/svc_tcp.o $(OBJDIR)/svc_udp.o \
10215 +$(OBJDIR)/sysconf.o $(OBJDIR)/sysconf_cpus.o $(OBJDIR)/system.o \
10216 +$(OBJDIR)/tcflow.o $(OBJDIR)/tcsendbreak.o $(OBJDIR)/tcsetattr.o \
10217 +$(OBJDIR)/tempnam.o $(OBJDIR)/thrd_exit.o $(OBJDIR)/thrd_join.o \
10218 +$(OBJDIR)/tmpnam.o $(OBJDIR)/utxent.o $(OBJDIR)/verr.o \
10219 +$(OBJDIR)/verrx.o $(OBJDIR)/vwarn.o $(OBJDIR)/warn.o \
10220 +$(OBJDIR)/wcsrtombs.o $(OBJDIR)/wcstombs.o: include/errno_definition.h
10221 +
10222 +$(OBJDIR)/abort.o $(OBJDIR)/pselect.o $(OBJDIR)/__utmp_block_signals.o \
10223 +$(OBJDIR)/system.o $(OBJDIR)/utxent.o $(OBJDIR)/sigemptyset.o \
10224 +$(OBJDIR)/sigorset.o $(OBJDIR)/sigandset.o $(OBJDIR)/sigfillset.o \
10225 +$(OBJDIR)/sigisemptyset.o: include/signal.h
10226 +
10227 +include/errno_definition.h: dietfeatures.h
10228 +       if grep -q '^#define WANT_TLS' $<; then echo "extern __thread int errno;"; else echo "extern int errno;"; fi > $@
10229 +
10230 +ldso: ldso.c
10231 +       gcc -nostdlib -shared -g -DIN_LDSO -Iinclude.ldso -I. -isystem include x86_64/start.S -o ldso ldso.c -fPIC x86_64/dyn_syscalls.S lib/errno_location.c -D__thread=
10232 +
10233 +GIT_CVSIMPORT=git cvsimport
10234 +CVS_EXTRA_bigo.ensc.de=;proxy=www-cache;proxyport=3128
10235 +CVS_EXTRA=$(CVS_EXTRA_$(shell hostname -d))
10236 +cvsimport:
10237 +       $(GIT_CVSIMPORT) -k -p '--cvs-direct' -d ':pserver$(CVS_EXTRA):cvs@cvs.fefe.de:/cvs' dietlibc
10238 diff -urN -x .git dietlibc-0.33/mips/Makefile.add dietlibc/mips/Makefile.add
10239 --- dietlibc-0.33/mips/Makefile.add     2012-01-24 18:24:27.000000000 +0000
10240 +++ dietlibc/mips/Makefile.add  2015-01-01 12:14:43.514938893 +0000
10241 @@ -9,6 +9,10 @@
10242  ifeq ($(CROSS),mips-linux-)
10243  ENDIAN=-meb
10244  endif
10245 +ifeq ($(CC),gcc -mabi=64)
10246 +CFLAGS+=$(ENDIAN) -Os -march=mips64
10247 +else
10248  CFLAGS+=$(ENDIAN) -Os -march=mips2
10249 +endif
10250  VPATH:=mips:syscalls.s:$(VPATH)
10251  LIBOBJ+=$(OBJDIR)/pread64.o $(OBJDIR)/pwrite64.o $(OBJDIR)/divdi3.o $(OBJDIR)/__CAS.o
10252 diff -urN -x .git dietlibc-0.33/mips/start.S dietlibc/mips/start.S
10253 --- dietlibc-0.33/mips/start.S  2006-05-29 16:30:53.000000000 +0000
10254 +++ dietlibc/mips/start.S       2015-01-01 12:14:43.514938893 +0000
10255 @@ -47,6 +47,15 @@
10256  #endif
10257         add     $a2, $a2, $a1
10258         sw      $a2, environ
10259 +#ifdef WANT_ELFINFO
10260 +#  warning "MAKE ME MIPS CODE!"
10261 +1:     addu    $a2, $a2, 4     /* increment envp */
10262 +       lw      $4, -4($a2)     /* load envp[-1]; TODO: is $4 a proper
10263 +                                  temporary register? */
10264 +       bnz     1b              /* ... until envp[-1]==NULL
10265 +                                  TODO: use proper 'bnz' operation */
10266 +       sw      $a2, __elfinfo
10267 +#endif
10268         jalr    $25
10269         la      $25, exit
10270         move    $4,$2
10271 diff -urN -x .git dietlibc-0.33/mips/syscalls.h dietlibc/mips/syscalls.h
10272 --- dietlibc-0.33/mips/syscalls.h       2008-12-10 20:00:59.000000000 +0000
10273 +++ dietlibc/mips/syscalls.h    2015-01-01 12:14:43.514938893 +0000
10274 @@ -3,16 +3,16 @@
10275   * Linux o32 style syscalls are in the range from 4000 to 4999.
10276   */
10277  #define __NR_Linux                     4000
10278 -#define __NR_syscall                   (__NR_Linux +   0)
10279 -#define __NR_exit                      (__NR_Linux +   1)
10280 -#define __NR_fork                      (__NR_Linux +   2)
10281 -#define __NR_read                      (__NR_Linux +   3)
10282 -#define __NR_write                     (__NR_Linux +   4)
10283 -#define __NR_open                      (__NR_Linux +   5)
10284 -#define __NR_close                     (__NR_Linux +   6)
10285 -#define __NR_waitpid                   (__NR_Linux +   7)
10286 -#define __NR_creat                     (__NR_Linux +   8)
10287 -#define __NR_link                      (__NR_Linux +   9)
10288 +#define __NR_syscall                   (__NR_Linux +   0)
10289 +#define __NR_exit                      (__NR_Linux +   1)
10290 +#define __NR_fork                      (__NR_Linux +   2)
10291 +#define __NR_read                      (__NR_Linux +   3)
10292 +#define __NR_write                     (__NR_Linux +   4)
10293 +#define __NR_open                      (__NR_Linux +   5)
10294 +#define __NR_close                     (__NR_Linux +   6)
10295 +#define __NR_waitpid                   (__NR_Linux +   7)
10296 +#define __NR_creat                     (__NR_Linux +   8)
10297 +#define __NR_link                      (__NR_Linux +   9)
10298  #define __NR_unlink                    (__NR_Linux +  10)
10299  #define __NR_execve                    (__NR_Linux +  11)
10300  #define __NR_chdir                     (__NR_Linux +  12)
10301 @@ -203,8 +203,8 @@
10302  #define __NR_rt_sigtimedwait           (__NR_Linux + 197)
10303  #define __NR_rt_sigqueueinfo           (__NR_Linux + 198)
10304  #define __NR_rt_sigsuspend             (__NR_Linux + 199)
10305 -#define __NR_pread                     (__NR_Linux + 200)
10306 -#define __NR_pwrite                    (__NR_Linux + 201)
10307 +#define __NR_pread64                   (__NR_Linux + 200)
10308 +#define __NR_pwrite64                  (__NR_Linux + 201)
10309  #define __NR_chown                     (__NR_Linux + 202)
10310  #define __NR_getcwd                    (__NR_Linux + 203)
10311  #define __NR_capget                    (__NR_Linux + 204)
10312 @@ -296,7 +296,7 @@
10313  #define __NR_mknodat                   (__NR_Linux + 290)
10314  #define __NR_fchownat                  (__NR_Linux + 291)
10315  #define __NR_futimesat                 (__NR_Linux + 292)
10316 -#define __NR_fstatat                   (__NR_Linux + 293)
10317 +#define __NR_fstatat64                 (__NR_Linux + 293)
10318  #define __NR_unlinkat                  (__NR_Linux + 294)
10319  #define __NR_renameat                  (__NR_Linux + 295)
10320  #define __NR_linkat                    (__NR_Linux + 296)
10321 @@ -312,21 +312,53 @@
10322  #define __NR_tee                       (__NR_Linux + 306)
10323  #define __NR_vmsplice                  (__NR_Linux + 307)
10324  #define __NR_move_pages                        (__NR_Linux + 308)
10325 -#define __NR_set_robust_list           (__NR_Linux + 272)
10326 -#define __NR_get_robust_list           (__NR_Linux + 273)
10327 -#define __NR_kexec_load                        (__NR_Linux + 274)
10328 -#define __NR_getcpu                    (__NR_Linux + 275)
10329 -#define __NR_epoll_pwait               (__NR_Linux + 276)
10330 -#define __NR_ioprio_set                        (__NR_Linux + 277)
10331 -#define __NR_ioprio_get                        (__NR_Linux + 278)
10332 -#define __NR_utimensat                 (__NR_Linux + 279)
10333 -#define __NR_signalfd                  (__NR_Linux + 280)
10334 -#define __NR_timerfd                   (__NR_Linux + 281)
10335 -#define __NR_eventfd                   (__NR_Linux + 282)
10336 -#define __NR_fallocate                 (__NR_Linux + 283)
10337 -#define __NR_timerfd_create            (__NR_Linux + 284)
10338 -#define __NR_timerfd_gettime           (__NR_Linux + 285)
10339 -#define __NR_timerfd_settime           (__NR_Linux + 286)
10340 +#define __NR_set_robust_list           (__NR_Linux + 309)
10341 +#define __NR_get_robust_list           (__NR_Linux + 310)
10342 +#define __NR_kexec_load                        (__NR_Linux + 311)
10343 +#define __NR_getcpu                    (__NR_Linux + 312)
10344 +#define __NR_epoll_pwait               (__NR_Linux + 313)
10345 +#define __NR_ioprio_set                        (__NR_Linux + 314)
10346 +#define __NR_ioprio_get                        (__NR_Linux + 315)
10347 +#define __NR_utimensat                 (__NR_Linux + 316)
10348 +#define __NR_signalfd                  (__NR_Linux + 317)
10349 +#define __NR_timerfd                   (__NR_Linux + 318)
10350 +#define __NR_eventfd                   (__NR_Linux + 319)
10351 +#define __NR_fallocate                 (__NR_Linux + 320)
10352 +#define __NR_timerfd_create            (__NR_Linux + 321)
10353 +#define __NR_timerfd_gettime           (__NR_Linux + 322)
10354 +#define __NR_timerfd_settime           (__NR_Linux + 323)
10355 +#define __NR_signalfd4                 (__NR_Linux + 324)
10356 +#define __NR_eventfd2                  (__NR_Linux + 325)
10357 +#define __NR_epoll_create1             (__NR_Linux + 326)
10358 +#define __NR_dup3                      (__NR_Linux + 327)
10359 +#define __NR_pipe2                     (__NR_Linux + 328)
10360 +#define __NR_inotify_init1             (__NR_Linux + 329)
10361 +#define __NR_preadv                    (__NR_Linux + 330)
10362 +#define __NR_pwritev                   (__NR_Linux + 331)
10363 +#define __NR_rt_tgsigqueueinfo         (__NR_Linux + 332)
10364 +#define __NR_perf_event_open           (__NR_Linux + 333)
10365 +#define __NR_accept4                   (__NR_Linux + 334)
10366 +#define __NR_recvmmsg                  (__NR_Linux + 335)
10367 +#define __NR_fanotify_init             (__NR_Linux + 336)
10368 +#define __NR_fanotify_mark             (__NR_Linux + 337)
10369 +#define __NR_prlimit64                 (__NR_Linux + 338)
10370 +#define __NR_name_to_handle_at         (__NR_Linux + 339)
10371 +#define __NR_open_by_handle_at         (__NR_Linux + 340)
10372 +#define __NR_clock_adjtime             (__NR_Linux + 341)
10373 +#define __NR_syncfs                    (__NR_Linux + 342)
10374 +#define __NR_sendmmsg                  (__NR_Linux + 343)
10375 +#define __NR_setns                     (__NR_Linux + 344)
10376 +#define __NR_process_vm_readv          (__NR_Linux + 345)
10377 +#define __NR_process_vm_writev         (__NR_Linux + 346)
10378 +#define __NR_kcmp                      (__NR_Linux + 347)
10379 +#define __NR_finit_module              (__NR_Linux + 348)
10380 +#define __NR_sched_setattr             (__NR_Linux + 349)
10381 +#define __NR_sched_getattr             (__NR_Linux + 350)
10382 +#define __NR_renameat2                 (__NR_Linux + 351)
10383 +#define __NR_seccomp                   (__NR_Linux + 352)
10384 +#define __NR_getrandom                 (__NR_Linux + 353)
10385 +#define __NR_memfd_create              (__NR_Linux + 354)
10386 +
10387  
10388  #define syscall_weak(name,wsym,sym) \
10389  .text; \
10390 diff -urN -x .git dietlibc-0.33/parisc/semctl.S dietlibc/parisc/semctl.S
10391 --- dietlibc-0.33/parisc/semctl.S       1970-01-01 00:00:00.000000000 +0000
10392 +++ dietlibc/parisc/semctl.S    2015-01-01 12:14:43.518272227 +0000
10393 @@ -0,0 +1,3 @@
10394 +#include "syscalls.h"
10395 +
10396 +syscall(semctl,semctl)
10397 diff -urN -x .git dietlibc-0.33/parisc/semget.S dietlibc/parisc/semget.S
10398 --- dietlibc-0.33/parisc/semget.S       1970-01-01 00:00:00.000000000 +0000
10399 +++ dietlibc/parisc/semget.S    2015-01-01 12:14:43.518272227 +0000
10400 @@ -0,0 +1,3 @@
10401 +#include "syscalls.h"
10402 +
10403 +syscall(semget,semget)
10404 diff -urN -x .git dietlibc-0.33/parisc/semop.S dietlibc/parisc/semop.S
10405 --- dietlibc-0.33/parisc/semop.S        1970-01-01 00:00:00.000000000 +0000
10406 +++ dietlibc/parisc/semop.S     2015-01-01 12:14:43.518272227 +0000
10407 @@ -0,0 +1,3 @@
10408 +#include "syscalls.h"
10409 +
10410 +syscall(semop,semop)
10411 diff -urN -x .git dietlibc-0.33/parisc/start.S dietlibc/parisc/start.S
10412 --- dietlibc-0.33/parisc/start.S        2006-05-29 16:30:53.000000000 +0000
10413 +++ dietlibc/parisc/start.S     2015-01-01 12:14:43.518272227 +0000
10414 @@ -34,6 +34,16 @@
10415         ldil LP%environ, %r19
10416         ldo RP%environ(%r19), %r19
10417  
10418 +#ifdef WANT_ELFINFO
10419 +#  warning "MAKE ME PARISC CODE!"
10420 +1:     add %r20, %r19, %r19            ; envp += 4
10421 +       ldw -4(0,%r19), %r21            ; load envp[-4] into %r21
10422 +       comibf =,0, 0,%r21,1b           ; compare %r21 with 0 without nullification
10423 +
10424 +       ldil LP%__elfinfo, %r19
10425 +       ldo RP%__elfinfo(%r19), %r19
10426 +#endif
10427 +
10428         /* Expand the stack to store the 5th through 7th args */
10429         ldo 64(%sp), %sp
10430  
10431 diff -urN -x .git dietlibc-0.33/parisc/strcmp.S dietlibc/parisc/strcmp.S
10432 --- dietlibc-0.33/parisc/strcmp.S       2003-09-04 01:50:50.000000000 +0000
10433 +++ dietlibc/parisc/strcmp.S    2015-01-01 12:14:43.518272227 +0000
10434 @@ -1,6 +1,8 @@
10435  .text
10436  .globl strcmp
10437  
10438 +.weak strcoll
10439 +strcoll:
10440  strcmp:
10441         .PROC
10442         .CALLINFO
10443 diff -urN -x .git dietlibc-0.33/parisc/syscalls.h dietlibc/parisc/syscalls.h
10444 --- dietlibc-0.33/parisc/syscalls.h     2008-12-10 20:00:59.000000000 +0000
10445 +++ dietlibc/parisc/syscalls.h  2015-01-01 12:14:43.518272227 +0000
10446 @@ -323,8 +323,40 @@
10447  #define __NR_timerfd_create    (__NR_Linux + 306)
10448  #define __NR_timerfd_settime   (__NR_Linux + 307)
10449  #define __NR_timerfd_gettime   (__NR_Linux + 308)
10450 +#define __NR_signalfd4         (__NR_Linux + 309)
10451 +#define __NR_eventfd2          (__NR_Linux + 310)
10452 +#define __NR_epoll_create1     (__NR_Linux + 311)
10453 +#define __NR_dup3              (__NR_Linux + 312)
10454 +#define __NR_pipe2             (__NR_Linux + 313)
10455 +#define __NR_inotify_init1     (__NR_Linux + 314)
10456 +#define __NR_preadv            (__NR_Linux + 315)
10457 +#define __NR_pwritev           (__NR_Linux + 316)
10458 +#define __NR_rt_tgsigqueueinfo (__NR_Linux + 317)
10459 +#define __NR_perf_event_open   (__NR_Linux + 318)
10460 +#define __NR_recvmmsg          (__NR_Linux + 319)
10461 +#define __NR_accept4           (__NR_Linux + 320)
10462 +#define __NR_prlimit64         (__NR_Linux + 321)
10463 +#define __NR_fanotify_init     (__NR_Linux + 322)
10464 +#define __NR_fanotify_mark     (__NR_Linux + 323)
10465 +#define __NR_clock_adjtime     (__NR_Linux + 324)
10466 +#define __NR_name_to_handle_at (__NR_Linux + 325)
10467 +#define __NR_open_by_handle_at (__NR_Linux + 326)
10468 +#define __NR_syncfs            (__NR_Linux + 327)
10469 +#define __NR_setns             (__NR_Linux + 328)
10470 +#define __NR_sendmmsg          (__NR_Linux + 329)
10471 +#define __NR_process_vm_readv  (__NR_Linux + 330)
10472 +#define __NR_process_vm_writev (__NR_Linux + 331)
10473 +#define __NR_kcmp              (__NR_Linux + 332)
10474 +#define __NR_finit_module      (__NR_Linux + 333)
10475 +#define __NR_sched_setattr     (__NR_Linux + 334)
10476 +#define __NR_sched_getattr     (__NR_Linux + 335)
10477 +#define __NR_utimes            (__NR_Linux + 336)
10478 +#define __NR_renameat2         (__NR_Linux + 337)
10479 +#define __NR_seccomp           (__NR_Linux + 338)
10480 +#define __NR_getrandom         (__NR_Linux + 339)
10481 +#define __NR_memfd_create      (__NR_Linux + 340)
10482  
10483 -#define __NR_Linux_syscalls    (__NR_fallocate + 1)
10484 +#define __NR_Linux_syscalls    (__NR_memfd_create + 1)
10485  
10486  #define LINUX_GATEWAY_ADDR      0x100
10487  
10488 diff -urN -x .git dietlibc-0.33/PORTING dietlibc/PORTING
10489 --- dietlibc-0.33/PORTING       2010-09-25 17:03:25.000000000 +0000
10490 +++ dietlibc/PORTING    2015-01-01 12:14:43.451605563 +0000
10491 @@ -18,9 +18,11 @@
10492    - edit include/sys/mman.h
10493    - edit include/sys/shm.h
10494    - edit include/sys/stat.h
10495 +  - edit include/sys/tls.h
10496    - edit include/errno.h
10497    - edit syscalls.h
10498    - edit include/termios.h
10499 +  - edit lib/__get_cur_tcb.c
10500    - edit diet.c to make it recognize the architecture and add proper
10501      CFLAGS
10502    - edit libcompat/syscall.S
10503 diff -urN -x .git dietlibc-0.33/ppc/select.S dietlibc/ppc/select.S
10504 --- dietlibc-0.33/ppc/select.S  1970-01-01 00:00:00.000000000 +0000
10505 +++ dietlibc/ppc/select.S       2015-01-01 12:14:43.518272227 +0000
10506 @@ -0,0 +1,3 @@
10507 +#include "syscalls.h"
10508 +
10509 +syscall_weak(_newselect,select,__libc_select)
10510 diff -urN -x .git dietlibc-0.33/ppc/start.S dietlibc/ppc/start.S
10511 --- dietlibc-0.33/ppc/start.S   2006-05-29 16:30:53.000000000 +0000
10512 +++ dietlibc/ppc/start.S        2015-01-01 12:14:43.518272227 +0000
10513 @@ -31,6 +31,15 @@
10514         lis     14,environ@ha
10515         stw     5,environ@l(14)
10516  
10517 +#ifdef WANT_ELFINFO
10518 +1:     lwzu    15,0(5)
10519 +       addi    5, 5, 4
10520 +       cmpwi   15,0
10521 +       bne     1b
10522 +
10523 +       stw     5,__elfinfo@l(14)
10524 +#endif
10525 +
10526  #ifdef WANT_DYNAMIC
10527         mr      6,7
10528         bl      _dyn_start
10529 diff -urN -x .git dietlibc-0.33/ppc/syscalls.h dietlibc/ppc/syscalls.h
10530 --- dietlibc-0.33/ppc/syscalls.h        2008-12-10 20:00:59.000000000 +0000
10531 +++ dietlibc/ppc/syscalls.h     2015-01-01 12:14:43.518272227 +0000
10532 @@ -311,7 +311,54 @@
10533  #define __NR_subpage_prot      310
10534  #define __NR_timerfd_settime   311
10535  #define __NR_timerfd_gettime   312
10536 -
10537 +#define __NR_signalfd4         313
10538 +#define __NR_eventfd2          314
10539 +#define __NR_epoll_create1     315
10540 +#define __NR_dup3              316
10541 +#define __NR_pipe2             317
10542 +#define __NR_inotify_init1     318
10543 +#define __NR_perf_event_open   319
10544 +#define __NR_preadv            320
10545 +#define __NR_pwritev           321
10546 +#define __NR_rt_tgsigqueueinfo 322
10547 +#define __NR_fanotify_init     323
10548 +#define __NR_fanotify_mark     324
10549 +#define __NR_prlimit64         325
10550 +#define __NR_socket            326
10551 +#define __NR_bind              327
10552 +#define __NR_connect           328
10553 +#define __NR_listen            329
10554 +#define __NR_accept            330
10555 +#define __NR_getsockname       331
10556 +#define __NR_getpeername       332
10557 +#define __NR_socketpair                333
10558 +#define __NR_send              334
10559 +#define __NR_sendto            335
10560 +#define __NR_recv              336
10561 +#define __NR_recvfrom          337
10562 +#define __NR_shutdown          338
10563 +#define __NR_setsockopt                339
10564 +#define __NR_getsockopt                340
10565 +#define __NR_sendmsg           341
10566 +#define __NR_recvmsg           342
10567 +#define __NR_recvmmsg          343
10568 +#define __NR_accept4           344
10569 +#define __NR_name_to_handle_at 345
10570 +#define __NR_open_by_handle_at 346
10571 +#define __NR_clock_adjtime     347
10572 +#define __NR_syncfs            348
10573 +#define __NR_sendmmsg          349
10574 +#define __NR_setns             350
10575 +#define __NR_process_vm_readv  351
10576 +#define __NR_process_vm_writev 352
10577 +#define __NR_finit_module      353
10578 +#define __NR_kcmp              354
10579 +#define __NR_sched_setattr     355
10580 +#define __NR_sched_getattr     356
10581 +#define __NR_renameat2         357
10582 +#define __NR_seccomp           358
10583 +#define __NR_getrandom         359
10584 +#define __NR_memfd_create      360
10585  
10586  #define syscall_weak(name,wsym,sym) \
10587  .text; \
10588 diff -urN -x .git dietlibc-0.33/ppc64/select.S dietlibc/ppc64/select.S
10589 --- dietlibc-0.33/ppc64/select.S        1970-01-01 00:00:00.000000000 +0000
10590 +++ dietlibc/ppc64/select.S     2015-01-01 12:14:43.521605560 +0000
10591 @@ -0,0 +1,3 @@
10592 +#include "syscalls.h"
10593 +
10594 +syscall_weak(_newselect,select,__libc_select)
10595 diff -urN -x .git dietlibc-0.33/ppc64/start.S dietlibc/ppc64/start.S
10596 --- dietlibc-0.33/ppc64/start.S 2012-01-24 18:24:28.000000000 +0000
10597 +++ dietlibc/ppc64/start.S      2015-01-01 12:14:43.521605560 +0000
10598 @@ -58,6 +58,15 @@
10599         oris    14,14,environ@ha
10600         std     5,environ@l(14)
10601  
10602 +#ifdef WANT_ELFINFO
10603 +1:     ldu     15,0(5)
10604 +       addi    5, 5, 8
10605 +       cmpdi   15,0
10606 +       bne     1b
10607 +
10608 +       std     5,__elfinfo@l(14)
10609 +#endif
10610 +
10611  #ifdef WANT_DYNAMIC
10612  /* #warning dynamic */
10613         mr      6,7
10614 diff -urN -x .git dietlibc-0.33/ppc64/syscalls.h dietlibc/ppc64/syscalls.h
10615 --- dietlibc-0.33/ppc64/syscalls.h      2008-12-10 20:00:59.000000000 +0000
10616 +++ dietlibc/ppc64/syscalls.h   2015-01-01 12:14:43.521605560 +0000
10617 @@ -311,7 +311,54 @@
10618  #define __NR_subpage_prot      310
10619  #define __NR_timerfd_settime   311
10620  #define __NR_timerfd_gettime   312
10621 -
10622 +#define __NR_signalfd4         313
10623 +#define __NR_eventfd2          314
10624 +#define __NR_epoll_create1     315
10625 +#define __NR_dup3              316
10626 +#define __NR_pipe2             317
10627 +#define __NR_inotify_init1     318
10628 +#define __NR_perf_event_open   319
10629 +#define __NR_preadv            320
10630 +#define __NR_pwritev           321
10631 +#define __NR_rt_tgsigqueueinfo 322
10632 +#define __NR_fanotify_init     323
10633 +#define __NR_fanotify_mark     324
10634 +#define __NR_prlimit64         325
10635 +#define __NR_socket            326
10636 +#define __NR_bind              327
10637 +#define __NR_connect           328
10638 +#define __NR_listen            329
10639 +#define __NR_accept            330
10640 +#define __NR_getsockname       331
10641 +#define __NR_getpeername       332
10642 +#define __NR_socketpair                333
10643 +#define __NR_send              334
10644 +#define __NR_sendto            335
10645 +#define __NR_recv              336
10646 +#define __NR_recvfrom          337
10647 +#define __NR_shutdown          338
10648 +#define __NR_setsockopt                339
10649 +#define __NR_getsockopt                340
10650 +#define __NR_sendmsg           341
10651 +#define __NR_recvmsg           342
10652 +#define __NR_recvmmsg          343
10653 +#define __NR_accept4           344
10654 +#define __NR_name_to_handle_at 345
10655 +#define __NR_open_by_handle_at 346
10656 +#define __NR_clock_adjtime     347
10657 +#define __NR_syncfs            348
10658 +#define __NR_sendmmsg          349
10659 +#define __NR_setns             350
10660 +#define __NR_process_vm_readv  351
10661 +#define __NR_process_vm_writev 352
10662 +#define __NR_finit_module      353
10663 +#define __NR_kcmp              354
10664 +#define __NR_sched_setattr     355
10665 +#define __NR_sched_getattr     356
10666 +#define __NR_renameat2         357
10667 +#define __NR_seccomp           358
10668 +#define __NR_getrandom         359
10669 +#define __NR_memfd_create      360
10670  
10671  #define __diet_proto_common(sym) \
10672         .section ".opd","aw"; \
10673 diff -urN -x .git dietlibc-0.33/s390/fadvise64_64.S dietlibc/s390/fadvise64_64.S
10674 --- dietlibc-0.33/s390/fadvise64_64.S   1970-01-01 00:00:00.000000000 +0000
10675 +++ dietlibc/s390/fadvise64_64.S        2015-01-01 12:14:43.521605560 +0000
10676 @@ -0,0 +1,5 @@
10677 +#include "syscalls.h"
10678 +
10679 +#ifdef __NR_fadvise64_64
10680 +syscall(fadvise64_64, __s390_fadvise64_64);
10681 +#endif
10682 diff -urN -x .git dietlibc-0.33/s390/__fadvise.c dietlibc/s390/__fadvise.c
10683 --- dietlibc-0.33/s390/__fadvise.c      1970-01-01 00:00:00.000000000 +0000
10684 +++ dietlibc/s390/__fadvise.c   2015-01-01 12:14:43.521605560 +0000
10685 @@ -0,0 +1,29 @@
10686 +#include "syscalls.h"
10687 +
10688 +#define _LINUX_SOURCE
10689 +#include <fcntl.h>
10690 +#include <unistd.h>
10691 +
10692 +struct fadvise64_64_layout
10693 +{
10694 +  int fd;
10695 +  off64_t offset;
10696 +  off64_t len;
10697 +  int advise;
10698 +};
10699 +
10700 +long fadvise64_64(int fd, off64_t offset, off64_t len, int advise)
10701 +{
10702 +  struct fadvise64_64_layout parameters;
10703 +  extern long __s390_fadvise64_64(struct fadvise64_64_layout *args);
10704 +
10705 +  parameters.fd = fd;
10706 +  parameters.offset = offset;
10707 +  parameters.len = len;
10708 +  parameters.advise = advise;
10709 +
10710 +  return __s390_fadvise64_64(&parameters);
10711 +}
10712 +
10713 +int posix_fadvise(int fd, off64_t offset, off64_t len, int advise)
10714 +  __attribute__((__alias__("fadvise64_64")));
10715 diff -urN -x .git dietlibc-0.33/s390/Makefile.add dietlibc/s390/Makefile.add
10716 --- dietlibc-0.33/s390/Makefile.add     2002-11-09 18:10:23.000000000 +0000
10717 +++ dietlibc/s390/Makefile.add  2015-01-01 12:14:43.521605560 +0000
10718 @@ -1,4 +1,4 @@
10719  
10720  CFLAGS+=-Os # -fomit-frame-pointer -fstrict-aliasing
10721  VPATH:=s390:syscalls.s:$(VPATH)
10722 -LIBOBJ+=$(OBJDIR)/__waitpid.o
10723 +LIBOBJ+=$(OBJDIR)/__waitpid.o $(OBJDIR)/__fadvise.o
10724 diff -urN -x .git dietlibc-0.33/s390/setjmp.S dietlibc/s390/setjmp.S
10725 --- dietlibc-0.33/s390/setjmp.S 2001-11-26 14:50:08.000000000 +0000
10726 +++ dietlibc/s390/setjmp.S      2015-01-01 12:14:43.521605560 +0000
10727 @@ -14,6 +14,7 @@
10728  
10729  .global _setjmp
10730  .type  _setjmp,@function
10731 +_setjmp:
10732         lhi     %r3,0
10733  .size  _setjmp,.-_setjmp
10734  
10735 @@ -26,15 +27,18 @@
10736         std     %f6,48(%r2)
10737  
10738         /* Make a tail call to __sigjmp_save; it takes the same args.  */
10739 -       basr    %r1,%r0
10740 +       basr    %r1,0
10741  #ifdef PIC
10742 -.L0:   la      %r1,.L1-.L0(0,%r1)
10743 +.L0:   al      %r1,.L1-.L0(0,%r1)
10744         l       %r1,__sigjmp_save@GOT12(0,%r1)
10745 +#else
10746 +.L0:   l       %r1,.L1-.L0(0,%r1)
10747 +#endif
10748         br      %r1
10749 +       .p2align 3
10750 +#ifdef PIC
10751  .L1:   .long   _GLOBAL_OFFSET_TABLE_-.L0
10752  #else
10753 -       l       %r1,.L1(0,%r1)
10754 -       br      %r1
10755  .L1:   .long   __sigjmp_save
10756  #endif
10757  .size __sigsetjmp,.-__sigsetjmp;
10758 diff -urN -x .git dietlibc-0.33/s390/start.S dietlibc/s390/start.S
10759 --- dietlibc-0.33/s390/start.S  2006-05-29 16:30:53.000000000 +0000
10760 +++ dietlibc/s390/start.S       2015-01-01 12:14:43.521605560 +0000
10761 @@ -30,6 +30,17 @@
10762         l       %r1,8(%r13)
10763         st      %r4,0(%r1)
10764  
10765 +#ifdef WANT_ELFINFO
10766 +       lhi     %r6, -4
10767 +1:     ahi     %r4, 4          # increment envp
10768 +       l       %r12, 0(%r6,%r4)        # load envp[-1] into %r12
10769 +       or      %r12, %r12      # test %r12 for NULL
10770 +       jne     1b
10771 +
10772 +       ahi     %r1, 4
10773 +       st      %r4,0(%r1)
10774 +#endif
10775 +
10776  /* call main or _dyn_start */
10777         l       %r1,0(%r13)
10778         basr    %r14,%r1
10779 diff -urN -x .git dietlibc-0.33/s390/syscalls.h dietlibc/s390/syscalls.h
10780 --- dietlibc-0.33/s390/syscalls.h       2008-12-10 20:00:59.000000000 +0000
10781 +++ dietlibc/s390/syscalls.h    2015-01-01 12:14:43.521605560 +0000
10782 @@ -277,6 +277,7 @@
10783  #define __NR_mknodat           290
10784  #define __NR_fchownat          291
10785  #define __NR_futimesat         292
10786 +#define __NR_fstatat64         293
10787  #define __NR_unlinkat          294
10788  #define __NR_renameat          295
10789  #define __NR_linkat            296
10790 @@ -305,7 +306,35 @@
10791  #define __NR_timerfd_create    319
10792  #define __NR_timerfd_settime   320
10793  #define __NR_timerfd_gettime   321
10794 -
10795 +#define __NR_signalfd4         322
10796 +#define __NR_eventfd2          323
10797 +#define __NR_inotify_init1     324
10798 +#define __NR_pipe2             325
10799 +#define __NR_dup3              326
10800 +#define __NR_epoll_create1     327
10801 +#define        __NR_preadv             328
10802 +#define        __NR_pwritev            329
10803 +#define __NR_rt_tgsigqueueinfo 330
10804 +#define __NR_perf_event_open   331
10805 +#define __NR_fanotify_init     332
10806 +#define __NR_fanotify_mark     333
10807 +#define __NR_prlimit64         334
10808 +#define __NR_name_to_handle_at 335
10809 +#define __NR_open_by_handle_at 336
10810 +#define __NR_clock_adjtime     337
10811 +#define __NR_syncfs            338
10812 +#define __NR_setns             339
10813 +#define __NR_process_vm_readv  340
10814 +#define __NR_process_vm_writev 341
10815 +#define __NR_s390_runtime_instr 342
10816 +#define __NR_kcmp              343
10817 +#define __NR_finit_module      344
10818 +#define __NR_sched_setattr     345
10819 +#define __NR_sched_getattr     346
10820 +#define __NR_renameat2         347
10821 +#define __NR_seccomp           348
10822 +#define __NR_getrandom         349
10823 +#define __NR_memfd_create      350
10824  
10825  #define syscall_weak(name,wsym,sym) \
10826  .text; \
10827 diff -urN -x .git dietlibc-0.33/s390x/setjmp.S dietlibc/s390x/setjmp.S
10828 --- dietlibc-0.33/s390x/setjmp.S        2003-10-10 13:37:34.000000000 +0000
10829 +++ dietlibc/s390x/setjmp.S     2015-01-01 12:14:43.521605560 +0000
10830 @@ -14,6 +14,7 @@
10831  
10832  .global _setjmp
10833  .type  _setjmp,@function
10834 +_setjmp:
10835         lhi     %r3,0
10836  .size  _setjmp,.-_setjmp
10837  
10838 @@ -26,15 +27,18 @@
10839         std     %f6,48(%r2)
10840  
10841         /* Make a tail call to __sigjmp_save; it takes the same args.  */
10842 -       basr    %r1,%r0
10843 +       basr    %r1,0
10844  #ifdef PIC
10845 -.L0:   la      %r1,.L1-.L0(0,%r1)
10846 +.L0:   al      %r1,.L1-.L0(0,%r1)
10847         l       %r1,__sigjmp_save@GOT12(0,%r1)
10848 +#else
10849 +.L0:   l       %r1,.L1-.L0(0,%r1)
10850 +#endif
10851         br      %r1
10852 +       .p2align 3
10853 +#ifdef PIC
10854  .L1:   .long   _GLOBAL_OFFSET_TABLE_-.L0
10855  #else
10856 -       l       %r1,.L1(0,%r1)
10857 -       br      %r1
10858  .L1:   .long   __sigjmp_save
10859  #endif
10860  .size __sigsetjmp,.-__sigsetjmp;
10861 diff -urN -x .git dietlibc-0.33/s390x/start.S dietlibc/s390x/start.S
10862 --- dietlibc-0.33/s390x/start.S 2006-05-29 16:30:54.000000000 +0000
10863 +++ dietlibc/s390x/start.S      2015-01-01 12:14:43.521605560 +0000
10864 @@ -26,6 +26,16 @@
10865         larl    %r13,environ
10866         stg     %r4,0(%r13)
10867  
10868 +#ifdef WANT_ELFINFO
10869 +1:     aghi    %r4, 8          # increment envp
10870 +       lg      %r12, -8(0,%r4) # load envp[-1] into %r12
10871 +       ogr     %r12, %r12      # test %r12 for NULL
10872 +       jne     1b
10873 +
10874 +       aghi    %r13, 8
10875 +       stg     %r4,0(%r13)
10876 +#endif
10877 +
10878  /* call main or _dyn_start */
10879  #ifdef WANT_DYNAMIC
10880         brasl   %r14,_dyn_start
10881 diff -urN -x .git dietlibc-0.33/s390x/syscalls.h dietlibc/s390x/syscalls.h
10882 --- dietlibc-0.33/s390x/syscalls.h      2008-12-10 20:00:59.000000000 +0000
10883 +++ dietlibc/s390x/syscalls.h   2015-01-01 12:14:43.521605560 +0000
10884 @@ -305,7 +305,35 @@
10885  #define __NR_timerfd_create    319
10886  #define __NR_timerfd_settime   320
10887  #define __NR_timerfd_gettime   321
10888 -
10889 +#define __NR_signalfd4         322
10890 +#define __NR_eventfd2          323
10891 +#define __NR_inotify_init1     324
10892 +#define __NR_pipe2             325
10893 +#define __NR_dup3              326
10894 +#define __NR_epoll_create1     327
10895 +#define __NR_preadv            328
10896 +#define __NR_pwritev           329
10897 +#define __NR_rt_tgsigqueueinfo 330
10898 +#define __NR_perf_event_open   331
10899 +#define __NR_fanotify_init     332
10900 +#define __NR_fanotify_mark     333
10901 +#define __NR_prlimit64         334
10902 +#define __NR_name_to_handle_at 335
10903 +#define __NR_open_by_handle_at 336
10904 +#define __NR_clock_adjtime     337
10905 +#define __NR_syncfs            338
10906 +#define __NR_setns             339
10907 +#define __NR_process_vm_readv  340
10908 +#define __NR_process_vm_writev 341
10909 +#define __NR_s390_runtime_instr 342
10910 +#define __NR_kcmp              343
10911 +#define __NR_finit_module      344
10912 +#define __NR_sched_setattr     345
10913 +#define __NR_sched_getattr     346
10914 +#define __NR_renameat2         347
10915 +#define __NR_seccomp           348
10916 +#define __NR_getrandom         349
10917 +#define __NR_memfd_create      350
10918  
10919  /* 
10920   * There are some system calls that are not present on 64 bit, some
10921 @@ -313,6 +341,7 @@
10922   * is __NR_chown on 64 bit).
10923   */
10924  #ifdef __s390x__
10925 +
10926  #undef  __NR_time
10927  #undef  __NR_lchown
10928  #undef  __NR_setuid
10929 diff -urN -x .git dietlibc-0.33/sparc/shmat.c dietlibc/sparc/shmat.c
10930 --- dietlibc-0.33/sparc/shmat.c 2001-06-16 17:48:57.000000000 +0000
10931 +++ dietlibc/sparc/shmat.c      2015-01-01 12:14:43.521605560 +0000
10932 @@ -3,17 +3,15 @@
10933  #include <sys/shm.h>
10934  #include <unistd.h>
10935  
10936 -extern void* __ipc();
10937 +#include "../dietpagesize.h"
10938  
10939 -#ifndef PAGE_SIZE
10940 -#define PAGE_SIZE 4096
10941 -#endif
10942 +extern void* __ipc();
10943  
10944  void* shmat(int shmid,const void* shmaddr,int shmflg) {
10945    void* raddr;
10946    register void* result;
10947    result=__ipc(SHMAT,shmid,shmflg,&raddr,shmaddr);
10948 -  if ((unsigned long)result <= -(unsigned long)PAGE_SIZE)
10949 +  if ((unsigned long)result <= -(unsigned long)__DIET_PAGE_SIZE)
10950      result=raddr;
10951    return result;
10952  }
10953 diff -urN -x .git dietlibc-0.33/sparc/start.S dietlibc/sparc/start.S
10954 --- dietlibc-0.33/sparc/start.S 2006-05-29 16:30:54.000000000 +0000
10955 +++ dietlibc/sparc/start.S      2015-01-01 12:14:43.521605560 +0000
10956 @@ -25,6 +25,17 @@
10957         or      %o3, %lo(environ), %o3
10958         st      %o2, [%o3]
10959  
10960 +#ifdef WANT_ELFINFO
10961 +#  warning "VERIFY ME!"
10962 +1:     add     %o2, %o2, 4
10963 +       ld      [%o2-4], %o4
10964 +       orcc    %o4, %o4, %o4
10965 +       bne     1b
10966 +
10967 +       add     %o3, %o3, 4
10968 +       st      %o2, [%o3]
10969 +#endif
10970 +
10971  /* When starting a binary via the dynamic linker, %g1 contains the
10972     address of the shared library termination function, which will be
10973     registered with atexit(). If we are statically linked, this will
10974 diff -urN -x .git dietlibc-0.33/sparc/strchr.S dietlibc/sparc/strchr.S
10975 --- dietlibc-0.33/sparc/strchr.S        2003-09-04 01:50:50.000000000 +0000
10976 +++ dietlibc/sparc/strchr.S     2015-01-01 12:14:43.521605560 +0000
10977 @@ -11,6 +11,8 @@
10978  
10979  .text
10980  .globl strchr
10981 +.weak index
10982 +index:
10983  strchr:
10984         ldub [%o0], %o2
10985         cmp %o2, %o1
10986 diff -urN -x .git dietlibc-0.33/sparc/strcmp.S dietlibc/sparc/strcmp.S
10987 --- dietlibc-0.33/sparc/strcmp.S        2003-09-04 01:50:50.000000000 +0000
10988 +++ dietlibc/sparc/strcmp.S     2015-01-01 12:14:43.521605560 +0000
10989 @@ -11,6 +11,8 @@
10990  
10991  .text
10992  .globl strcmp
10993 +.weak strcoll
10994 +strcoll:
10995  strcmp:
10996         clr %o4
10997  .Lloop:
10998 diff -urN -x .git dietlibc-0.33/sparc/syscalls.h dietlibc/sparc/syscalls.h
10999 --- dietlibc-0.33/sparc/syscalls.h      2008-12-10 20:00:59.000000000 +0000
11000 +++ dietlibc/sparc/syscalls.h   2015-01-01 12:14:43.521605560 +0000
11001 @@ -315,6 +315,38 @@
11002  #define __NR_fallocate         314
11003  #define __NR_timerfd_settime   315
11004  #define __NR_timerfd_gettime   316
11005 +#define __NR_signalfd4         317
11006 +#define __NR_eventfd2          318
11007 +#define __NR_epoll_create1     319
11008 +#define __NR_dup3              320
11009 +#define __NR_pipe2             321
11010 +#define __NR_inotify_init1     322
11011 +#define __NR_accept4           323
11012 +#define __NR_preadv            324
11013 +#define __NR_pwritev           325
11014 +#define __NR_rt_tgsigqueueinfo 326
11015 +#define __NR_perf_event_open   327
11016 +#define __NR_recvmmsg          328
11017 +#define __NR_fanotify_init     329
11018 +#define __NR_fanotify_mark     330
11019 +#define __NR_prlimit64         331
11020 +#define __NR_name_to_handle_at 332
11021 +#define __NR_open_by_handle_at 333
11022 +#define __NR_clock_adjtime     334
11023 +#define __NR_syncfs            335
11024 +#define __NR_sendmmsg          336
11025 +#define __NR_setns             337
11026 +#define __NR_process_vm_readv  338
11027 +#define __NR_process_vm_writev 339
11028 +#define __NR_kern_features     340
11029 +#define __NR_kcmp              341
11030 +#define __NR_finit_module      342
11031 +#define __NR_sched_setattr     343
11032 +#define __NR_sched_getattr     344
11033 +#define __NR_renameat2         345
11034 +#define __NR_seccomp           346
11035 +#define __NR_getrandom         347
11036 +#define __NR_memfd_create      348
11037  
11038  #define syscall_weak(name,wsym,sym) \
11039  .text; \
11040 diff -urN -x .git dietlibc-0.33/sparc64/start.S dietlibc/sparc64/start.S
11041 --- dietlibc-0.33/sparc64/start.S       2006-05-29 16:30:54.000000000 +0000
11042 +++ dietlibc/sparc64/start.S    2015-01-01 12:14:43.524938894 +0000
11043 @@ -25,6 +25,17 @@
11044         or      %o3, %lo(environ), %o3
11045         stx     %o2, [%o3]
11046  
11047 +#ifdef WANT_ELFINFO
11048 +#  warning "VERIFY ME!"
11049 +1:     add     %o2, %o2, 8
11050 +       ldx     [%o2-8], %o4
11051 +       orcc    %o4, %o4, %o4
11052 +       bne     1b
11053 +
11054 +       add     %o3, %o3, 8
11055 +       stx     %o2, [%o3]
11056 +#endif
11057 +
11058  /* When starting a binary via the dynamic linker, %g1 contains the
11059     address of the shared library termination function, which will be
11060     registered with atexit(). If we are statically linked, this will
11061 diff -urN -x .git dietlibc-0.33/sparc64/syscalls.h dietlibc/sparc64/syscalls.h
11062 --- dietlibc-0.33/sparc64/syscalls.h    2008-12-10 20:00:59.000000000 +0000
11063 +++ dietlibc/sparc64/syscalls.h 2015-01-01 12:14:43.524938894 +0000
11064 @@ -314,6 +314,38 @@
11065  #define __NR_fallocate         314
11066  #define __NR_timerfd_settime   315
11067  #define __NR_timerfd_gettime   316
11068 +#define __NR_signalfd4         317
11069 +#define __NR_eventfd2          318
11070 +#define __NR_epoll_create1     319
11071 +#define __NR_dup3              320
11072 +#define __NR_pipe2             321
11073 +#define __NR_inotify_init1     322
11074 +#define __NR_accept4           323
11075 +#define __NR_preadv            324
11076 +#define __NR_pwritev           325
11077 +#define __NR_rt_tgsigqueueinfo 326
11078 +#define __NR_perf_event_open   327
11079 +#define __NR_recvmmsg          328
11080 +#define __NR_fanotify_init     329
11081 +#define __NR_fanotify_mark     330
11082 +#define __NR_prlimit64         331
11083 +#define __NR_name_to_handle_at 332
11084 +#define __NR_open_by_handle_at 333
11085 +#define __NR_clock_adjtime     334
11086 +#define __NR_syncfs            335
11087 +#define __NR_sendmmsg          336
11088 +#define __NR_setns             337
11089 +#define __NR_process_vm_readv  338
11090 +#define __NR_process_vm_writev 339
11091 +#define __NR_kern_features     340
11092 +#define __NR_kcmp              341
11093 +#define __NR_finit_module      342
11094 +#define __NR_sched_setattr     343
11095 +#define __NR_sched_getattr     344
11096 +#define __NR_renameat2         345
11097 +#define __NR_seccomp           346
11098 +#define __NR_getrandom         347
11099 +#define __NR_memfd_create      348
11100  
11101  #define syscall_weak(name,wsym,sym) \
11102  .text; \
11103 diff -urN -x .git dietlibc-0.33/syscalls.h dietlibc/syscalls.h
11104 --- dietlibc-0.33/syscalls.h    2005-05-08 15:33:38.000000000 +0000
11105 +++ dietlibc/syscalls.h 2015-01-01 12:14:43.524938894 +0000
11106 @@ -2,7 +2,11 @@
11107  #include "i386/syscalls.h"
11108  
11109  #elif defined(__x86_64__)
11110 +#if defined(__ILP32__)
11111 +#include "x32/syscalls.h"
11112 +#else
11113  #include "x86_64/syscalls.h"
11114 +#endif
11115  
11116  #elif defined(__sparc__)
11117  #if defined(__arch64__)
11118 diff -urN -x .git dietlibc-0.33/syscalls.s/accept4.S dietlibc/syscalls.s/accept4.S
11119 --- dietlibc-0.33/syscalls.s/accept4.S  1970-01-01 00:00:00.000000000 +0000
11120 +++ dietlibc/syscalls.s/accept4.S       2015-01-01 12:14:43.524938894 +0000
11121 @@ -0,0 +1,5 @@
11122 +#include "syscalls.h"
11123 +
11124 +#ifdef __NR_accept4
11125 +syscall(accept4,accept4)
11126 +#endif
11127 diff -urN -x .git dietlibc-0.33/syscalls.s/dup3.S dietlibc/syscalls.s/dup3.S
11128 --- dietlibc-0.33/syscalls.s/dup3.S     1970-01-01 00:00:00.000000000 +0000
11129 +++ dietlibc/syscalls.s/dup3.S  2015-01-01 12:14:43.524938894 +0000
11130 @@ -0,0 +1,3 @@
11131 +#include "syscalls.h"
11132 +
11133 +syscall(dup3,dup3)
11134 diff -urN -x .git dietlibc-0.33/syscalls.s/environ.S dietlibc/syscalls.s/environ.S
11135 --- dietlibc-0.33/syscalls.s/environ.S  2005-01-31 12:53:34.000000000 +0000
11136 +++ dietlibc/syscalls.s/environ.S       2015-01-01 12:14:43.524938894 +0000
11137 @@ -1,6 +1,7 @@
11138  .section ".bss"
11139  .align 8
11140  #include <endian.h>
11141 +#include <dietfeatures.h>
11142  
11143  .type environ,object
11144  .weak environ
11145 @@ -15,3 +16,18 @@
11146  #endif
11147  .size environ,.-environ
11148  .size __environ,.-__environ
11149 +
11150 +/* __elfinfo will be initialized in start.S to point to the
11151 +   terminating NULL of the environment. */
11152 +
11153 +#ifdef WANT_ELFINFO
11154 +.type __elfinfo,object
11155 +.weak __elfinfo
11156 +__elfinfo:
11157 +#if __WORDSIZE == 64
11158 +       .quad 0
11159 +#else
11160 +       .long 0
11161 +#endif
11162 +.size __elfinfo,.-__elfinfo
11163 +#endif
11164 diff -urN -x .git dietlibc-0.33/syscalls.s/epoll_create1.S dietlibc/syscalls.s/epoll_create1.S
11165 --- dietlibc-0.33/syscalls.s/epoll_create1.S    1970-01-01 00:00:00.000000000 +0000
11166 +++ dietlibc/syscalls.s/epoll_create1.S 2015-01-01 12:14:43.524938894 +0000
11167 @@ -0,0 +1,5 @@
11168 +#include "syscalls.h"
11169 +
11170 +#ifdef __NR_epoll_create1
11171 +syscall(epoll_create1,epoll_create1)
11172 +#endif
11173 diff -urN -x .git dietlibc-0.33/syscalls.s/errno.S dietlibc/syscalls.s/errno.S
11174 --- dietlibc-0.33/syscalls.s/errno.S    2002-11-15 15:39:17.000000000 +0000
11175 +++ dietlibc/syscalls.s/errno.S 1970-01-01 00:00:00.000000000 +0000
11176 @@ -1,8 +0,0 @@
11177 -.section ".bss"
11178 -.align 8
11179 -
11180 -.type errno,object
11181 -.weak errno
11182 -errno:
11183 -       .long 0
11184 -.size errno,.-errno
11185 diff -urN -x .git dietlibc-0.33/syscalls.s/__eventfd2.S dietlibc/syscalls.s/__eventfd2.S
11186 --- dietlibc-0.33/syscalls.s/__eventfd2.S       1970-01-01 00:00:00.000000000 +0000
11187 +++ dietlibc/syscalls.s/__eventfd2.S    2015-01-01 12:14:43.524938894 +0000
11188 @@ -0,0 +1,3 @@
11189 +#include "syscalls.h"
11190 +
11191 +syscall(eventfd2,__eventfd2)
11192 diff -urN -x .git dietlibc-0.33/syscalls.s/__eventfd.S dietlibc/syscalls.s/__eventfd.S
11193 --- dietlibc-0.33/syscalls.s/__eventfd.S        1970-01-01 00:00:00.000000000 +0000
11194 +++ dietlibc/syscalls.s/__eventfd.S     2015-01-01 12:14:43.524938894 +0000
11195 @@ -0,0 +1,3 @@
11196 +#include "syscalls.h"
11197 +
11198 +syscall(eventfd,__eventfd)
11199 diff -urN -x .git dietlibc-0.33/syscalls.s/fadvise64.S dietlibc/syscalls.s/fadvise64.S
11200 --- dietlibc-0.33/syscalls.s/fadvise64.S        2012-01-24 18:24:28.000000000 +0000
11201 +++ dietlibc/syscalls.s/fadvise64.S     2015-01-01 12:14:43.524938894 +0000
11202 @@ -3,15 +3,14 @@
11203  
11204  #include "syscalls.h"
11205  
11206 +#ifdef __NR_fadvise64
11207 +syscall(fadvise64,fadvise64)
11208 +
11209  #ifndef __NR_fadvise64_64
11210 +posix_fadvise = fadvise64
11211  .globl posix_fadvise
11212 -.type posix_fadvise,@function
11213 -posix_fadvise:
11214  #endif
11215  
11216 -#ifdef __NR_fadvise64
11217 -syscall(fadvise64,fadvise64)
11218 -
11219  #endif
11220  
11221  #endif
11222 diff -urN -x .git dietlibc-0.33/syscalls.s/fanotify_init.S dietlibc/syscalls.s/fanotify_init.S
11223 --- dietlibc-0.33/syscalls.s/fanotify_init.S    1970-01-01 00:00:00.000000000 +0000
11224 +++ dietlibc/syscalls.s/fanotify_init.S 2015-01-01 12:14:43.524938894 +0000
11225 @@ -0,0 +1,3 @@
11226 +#include "syscalls.h"
11227 +
11228 +syscall(fanotify_init,fanotify_init)
11229 diff -urN -x .git dietlibc-0.33/syscalls.s/fanotify_mark.S dietlibc/syscalls.s/fanotify_mark.S
11230 --- dietlibc-0.33/syscalls.s/fanotify_mark.S    1970-01-01 00:00:00.000000000 +0000
11231 +++ dietlibc/syscalls.s/fanotify_mark.S 2015-01-01 12:14:43.524938894 +0000
11232 @@ -0,0 +1,3 @@
11233 +#include "syscalls.h"
11234 +
11235 +syscall(fanotify_mark,fanotify_mark)
11236 diff -urN -x .git dietlibc-0.33/syscalls.s/fstatat64.S dietlibc/syscalls.s/fstatat64.S
11237 --- dietlibc-0.33/syscalls.s/fstatat64.S        1970-01-01 00:00:00.000000000 +0000
11238 +++ dietlibc/syscalls.s/fstatat64.S     2015-01-01 12:14:43.524938894 +0000
11239 @@ -0,0 +1,5 @@
11240 +#include "syscalls.h"
11241 +
11242 +#ifdef __NR_fstatat64
11243 +syscall(fstatat64,fstatat64)
11244 +#endif
11245 diff -urN -x .git dietlibc-0.33/syscalls.s/fstatat.S dietlibc/syscalls.s/fstatat.S
11246 --- dietlibc-0.33/syscalls.s/fstatat.S  1970-01-01 00:00:00.000000000 +0000
11247 +++ dietlibc/syscalls.s/fstatat.S       2015-01-01 12:14:43.524938894 +0000
11248 @@ -0,0 +1,5 @@
11249 +#include "syscalls.h"
11250 +
11251 +#ifdef __NR_fstatat
11252 +syscall(fstatat,fstatat)
11253 +#endif
11254 diff -urN -x .git dietlibc-0.33/syscalls.s/getrandom.S dietlibc/syscalls.s/getrandom.S
11255 --- dietlibc-0.33/syscalls.s/getrandom.S        1970-01-01 00:00:00.000000000 +0000
11256 +++ dietlibc/syscalls.s/getrandom.S     2015-01-01 12:14:43.528272226 +0000
11257 @@ -0,0 +1,3 @@
11258 +#include "syscalls.h"
11259 +
11260 +syscall(getrandom,getrandom)
11261 diff -urN -x .git dietlibc-0.33/syscalls.s/inotify_init1.S dietlibc/syscalls.s/inotify_init1.S
11262 --- dietlibc-0.33/syscalls.s/inotify_init1.S    1970-01-01 00:00:00.000000000 +0000
11263 +++ dietlibc/syscalls.s/inotify_init1.S 2015-01-01 12:14:43.528272226 +0000
11264 @@ -0,0 +1,5 @@
11265 +#include "syscalls.h"
11266 +
11267 +#ifdef __NR_inotify_init1
11268 +syscall(inotify_init1,inotify_init1)
11269 +#endif
11270 diff -urN -x .git dietlibc-0.33/syscalls.s/_llseek.S dietlibc/syscalls.s/_llseek.S
11271 --- dietlibc-0.33/syscalls.s/_llseek.S  2004-06-30 05:52:31.000000000 +0000
11272 +++ dietlibc/syscalls.s/_llseek.S       2015-01-01 12:14:43.524938894 +0000
11273 @@ -2,7 +2,7 @@
11274  
11275  #ifdef __NR__llseek
11276  .global llseek
11277 -.type  llseek,function
11278 +.type  llseek,STT_FUNC
11279  llseek:
11280  syscall(_llseek,_llseek)
11281  #endif
11282 diff -urN -x .git dietlibc-0.33/syscalls.s/memfd_create.S dietlibc/syscalls.s/memfd_create.S
11283 --- dietlibc-0.33/syscalls.s/memfd_create.S     1970-01-01 00:00:00.000000000 +0000
11284 +++ dietlibc/syscalls.s/memfd_create.S  2015-01-01 12:14:43.528272226 +0000
11285 @@ -0,0 +1,3 @@
11286 +#include "syscalls.h"
11287 +
11288 +syscall(memfd_create,memfd_create)
11289 diff -urN -x .git dietlibc-0.33/syscalls.s/newfstatat.S dietlibc/syscalls.s/newfstatat.S
11290 --- dietlibc-0.33/syscalls.s/newfstatat.S       2012-01-16 21:10:29.000000000 +0000
11291 +++ dietlibc/syscalls.s/newfstatat.S    2015-01-01 12:14:43.528272226 +0000
11292 @@ -2,4 +2,12 @@
11293  
11294  #ifdef __NR_newfstatat
11295  syscall(newfstatat,newfstatat)
11296 +
11297 +#ifdef __NR_fstatat64
11298 +#  error __NR_newfstatat and __NR_fstatat64 must not both be defined
11299 +#endif
11300 +
11301 +fstatat = newfstatat
11302 +.globl fstatat
11303 +
11304  #endif
11305 diff -urN -x .git dietlibc-0.33/syscalls.s/pipe2.S dietlibc/syscalls.s/pipe2.S
11306 --- dietlibc-0.33/syscalls.s/pipe2.S    1970-01-01 00:00:00.000000000 +0000
11307 +++ dietlibc/syscalls.s/pipe2.S 2015-01-01 12:14:43.528272226 +0000
11308 @@ -0,0 +1,3 @@
11309 +#include "syscalls.h"
11310 +
11311 +syscall(pipe2,pipe2)
11312 diff -urN -x .git dietlibc-0.33/syscalls.s/preadv.S dietlibc/syscalls.s/preadv.S
11313 --- dietlibc-0.33/syscalls.s/preadv.S   1970-01-01 00:00:00.000000000 +0000
11314 +++ dietlibc/syscalls.s/preadv.S        2015-01-01 12:14:43.528272226 +0000
11315 @@ -0,0 +1,3 @@
11316 +#include "syscalls.h"
11317 +
11318 +syscall(preadv,preadv)
11319 diff -urN -x .git dietlibc-0.33/syscalls.s/pwritev.S dietlibc/syscalls.s/pwritev.S
11320 --- dietlibc-0.33/syscalls.s/pwritev.S  1970-01-01 00:00:00.000000000 +0000
11321 +++ dietlibc/syscalls.s/pwritev.S       2015-01-01 12:14:43.528272226 +0000
11322 @@ -0,0 +1,3 @@
11323 +#include "syscalls.h"
11324 +
11325 +syscall(pwritev,pwritev)
11326 diff -urN -x .git dietlibc-0.33/syscalls.s/recvmmsg.S dietlibc/syscalls.s/recvmmsg.S
11327 --- dietlibc-0.33/syscalls.s/recvmmsg.S 1970-01-01 00:00:00.000000000 +0000
11328 +++ dietlibc/syscalls.s/recvmmsg.S      2015-01-01 12:14:43.528272226 +0000
11329 @@ -0,0 +1,5 @@
11330 +#include "syscalls.h"
11331 +
11332 +#ifdef __NR_recvmmsg
11333 +syscall(recvmmsg,recvmmsg)
11334 +#endif
11335 diff -urN -x .git dietlibc-0.33/syscalls.s/sendmmsg.S dietlibc/syscalls.s/sendmmsg.S
11336 --- dietlibc-0.33/syscalls.s/sendmmsg.S 1970-01-01 00:00:00.000000000 +0000
11337 +++ dietlibc/syscalls.s/sendmmsg.S      2015-01-01 12:14:43.528272226 +0000
11338 @@ -0,0 +1,5 @@
11339 +#include "syscalls.h"
11340 +
11341 +#ifdef __NR_sendmmsg
11342 +syscall(sendmmsg,sendmmsg)
11343 +#endif
11344 diff -urN -x .git dietlibc-0.33/syscalls.s/setns.S dietlibc/syscalls.s/setns.S
11345 --- dietlibc-0.33/syscalls.s/setns.S    1970-01-01 00:00:00.000000000 +0000
11346 +++ dietlibc/syscalls.s/setns.S 2015-01-01 12:14:43.528272226 +0000
11347 @@ -0,0 +1,3 @@
11348 +#include "syscalls.h"
11349 +
11350 +syscall(setns,setns)
11351 diff -urN -x .git dietlibc-0.33/syscalls.s/__signalfd4.S dietlibc/syscalls.s/__signalfd4.S
11352 --- dietlibc-0.33/syscalls.s/__signalfd4.S      1970-01-01 00:00:00.000000000 +0000
11353 +++ dietlibc/syscalls.s/__signalfd4.S   2015-01-01 12:14:43.524938894 +0000
11354 @@ -0,0 +1,5 @@
11355 +#include "syscalls.h"
11356 +
11357 +#ifdef __NR_signalfd
11358 +syscall(signalfd4,__signalfd4)
11359 +#endif
11360 diff -urN -x .git dietlibc-0.33/syscalls.s/syncfs.S dietlibc/syscalls.s/syncfs.S
11361 --- dietlibc-0.33/syscalls.s/syncfs.S   1970-01-01 00:00:00.000000000 +0000
11362 +++ dietlibc/syscalls.s/syncfs.S        2015-01-01 12:14:43.531605560 +0000
11363 @@ -0,0 +1,3 @@
11364 +#include "syscalls.h"
11365 +
11366 +syscall(syncfs,syncfs)
11367 diff -urN -x .git dietlibc-0.33/syscalls.s/timerfd_gettime.S dietlibc/syscalls.s/timerfd_gettime.S
11368 --- dietlibc-0.33/syscalls.s/timerfd_gettime.S  1970-01-01 00:00:00.000000000 +0000
11369 +++ dietlibc/syscalls.s/timerfd_gettime.S       2015-01-01 12:14:43.531605560 +0000
11370 @@ -0,0 +1,3 @@
11371 +#include "syscalls.h"
11372 +
11373 +syscall(timerfd_gettime,timerfd_gettime)
11374 diff -urN -x .git dietlibc-0.33/syscalls.s/timerfd_settime.S dietlibc/syscalls.s/timerfd_settime.S
11375 --- dietlibc-0.33/syscalls.s/timerfd_settime.S  1970-01-01 00:00:00.000000000 +0000
11376 +++ dietlibc/syscalls.s/timerfd_settime.S       2015-01-01 12:14:43.531605560 +0000
11377 @@ -0,0 +1,3 @@
11378 +#include "syscalls.h"
11379 +
11380 +syscall(timerfd_settime,timerfd_settime)
11381 diff -urN -x .git dietlibc-0.33/t.c dietlibc/t.c
11382 --- dietlibc-0.33/t.c   2010-09-25 17:03:25.000000000 +0000
11383 +++ dietlibc/t.c        2015-01-01 12:14:43.531605560 +0000
11384 @@ -47,6 +47,7 @@
11385  #include <pty.h>
11386  #include <sys/statfs.h>
11387  #include <mqueue.h>
11388 +#include <ucontext.h>
11389  #ifdef __dietlibc__
11390  #include <md5.h>
11391  #include <write12.h>
11392 @@ -108,12 +109,27 @@
11393  #define malloc(x) ({typeof(x) y=x; (y<0 || (size_t)(y)!=y ? 0 : malloc(y));})
11394  
11395  int main(int argc,char *argv[]) {
11396 +  int n;
11397 +  struct ucontext uc;
11398 +  n=0;
11399 +  getcontext(&uc);
11400 +  puts("getcontext returned");
11401 +  if (n==0) {
11402 +    ++n;
11403 +    setcontext(&uc);
11404 +    puts("should not get here");
11405 +    exit(1);
11406 +  }
11407 +  puts("all ok");
11408 +  return 0;
11409  #if 0
11410    char* a=malloc(-3);
11411    char* b=malloc(0xffffffffull+1);
11412    printf("%p %p\n",a,b);
11413  #endif
11414 +#if 0
11415    printf("%u\n",getpagesize());
11416 +#endif
11417  #if 0
11418    struct stat s;
11419    time_t t=time(0);
11420 @@ -172,7 +188,7 @@
11421    strcpy(buf+i,"/bin:/bin");
11422    putenv(buf);
11423    execvp("sh",argv);
11424 -  printf("%d\n",islower('ü'));
11425 +  printf("%d\n",islower(0xfc));
11426  #endif
11427  #if 0
11428    char buf[101];
11429 diff -urN -x .git dietlibc-0.33/test/adjtime.c dietlibc/test/adjtime.c
11430 --- dietlibc-0.33/test/adjtime.c        2002-08-05 18:08:24.000000000 +0000
11431 +++ dietlibc/test/adjtime.c     2015-01-01 12:14:43.531605560 +0000
11432 @@ -1,9 +1,25 @@
11433  #include <stdio.h>
11434 +#include <assert.h>
11435 +#include <errno.h>
11436  #include <sys/time.h>
11437  
11438  int main() {
11439    struct timeval a,b;
11440 +  int rc;
11441    a.tv_sec=0; a.tv_usec=0;
11442 -  printf("%d\n",adjtime(&a,&b));
11443 +  rc = adjtime(&a,&b);
11444 +  assert(!rc || errno == EPERM);
11445 +
11446 +  rc = adjtime(&a, NULL);
11447 +  assert(!rc || errno == EPERM);
11448 +
11449 +  rc = adjtime(NULL,&b);
11450 +  assert(!rc);
11451 +  assert(b.tv_sec  < 30);          /* 30 seconds delta is very unlikely... */
11452 +  assert(b.tv_sec  > -30);         /* 30 seconds delta is very unlikely... */
11453 +  assert(b.tv_usec > -1000000);
11454 +  assert(b.tv_usec < 1000000);
11455 +
11456 +  printf("%lu/%d\n", (unsigned long)b.tv_sec, (int)b.tv_usec);
11457    return 0;
11458  }
11459 diff -urN -x .git dietlibc-0.33/test/asctime.c dietlibc/test/asctime.c
11460 --- dietlibc-0.33/test/asctime.c        1970-01-01 00:00:00.000000000 +0000
11461 +++ dietlibc/test/asctime.c     2015-01-01 12:14:43.531605560 +0000
11462 @@ -0,0 +1,27 @@
11463 +#include <assert.h>
11464 +#include <stdlib.h>
11465 +#include <time.h>
11466 +
11467 +int main(void)
11468 +{
11469 +       char            *buf;
11470 +       struct tm const tm = {
11471 +               .tm_sec = 20,
11472 +               .tm_min = 21,
11473 +               .tm_hour = 22,
11474 +               .tm_mday = 10,
11475 +               .tm_mon = 11,
11476 +               .tm_year = 112,
11477 +       };
11478 +       char            *res;
11479 +
11480 +       buf = malloc(4096);
11481 +       assert(buf != NULL);
11482 +       memset(buf, 23, 4096);
11483 +
11484 +       res = asctime_r(&tm, buf);
11485 +       assert(strcmp(res, asctime(&tm)) == 0);
11486 +       assert(strcmp(res, "Sun Dec 10 22:21:20 2012\n") == 0);
11487 +
11488 +       return EXIT_SUCCESS;
11489 +}
11490 diff -urN -x .git dietlibc-0.33/test/asprintf.c dietlibc/test/asprintf.c
11491 --- dietlibc-0.33/test/asprintf.c       2003-12-15 13:07:42.000000000 +0000
11492 +++ dietlibc/test/asprintf.c    2015-01-01 12:14:43.531605560 +0000
11493 @@ -13,7 +13,7 @@
11494   assert(strlen(path) == asprintlen);
11495              
11496   printf("%s\n", path);
11497 - asprintlen=asprintf(&path, "/proc" "/%d/stat", strlen(argv[1]));
11498 + asprintlen=asprintf(&path, "/proc" "/%zu/stat", strlen(argv[1]));
11499   assert(strlen(path) == asprintlen);
11500   printf("%s\n", path);
11501  
11502 diff -urN -x .git dietlibc-0.33/test/atexit.c dietlibc/test/atexit.c
11503 --- dietlibc-0.33/test/atexit.c 2003-02-20 15:57:12.000000000 +0000
11504 +++ dietlibc/test/atexit.c      2015-01-01 12:14:43.531605560 +0000
11505 @@ -2,7 +2,7 @@
11506  #include <unistd.h>
11507  
11508  void blah(void) {
11509 -  write(2,"atexit\n",7);
11510 +  write(1,"atexit\n",7);
11511  }
11512  
11513  int main() {
11514 diff -urN -x .git dietlibc-0.33/test/atfile.c dietlibc/test/atfile.c
11515 --- dietlibc-0.33/test/atfile.c 1970-01-01 00:00:00.000000000 +0000
11516 +++ dietlibc/test/atfile.c      2015-01-01 12:14:43.531605560 +0000
11517 @@ -0,0 +1,111 @@
11518 +#define _GNU_SOURCE
11519 +#define _XOPEN_SOURCE 700
11520 +#define _FILE_OFFSET_BITS 64
11521 +
11522 +#include <stdlib.h>
11523 +#include <fcntl.h>
11524 +#include <errno.h>
11525 +#include <assert.h>
11526 +#include <stdio.h>
11527 +#include <sys/stat.h>
11528 +
11529 +#define TMPDIR "/tmp"
11530 +
11531 +#define TEST(_op)      do {                                            \
11532 +               int rc = (_op);                                         \
11533 +               if (rc < 0) {                                           \
11534 +                       printf("%s:%u: %s: %u/%s\n", __FILE__, __LINE__,        \
11535 +                              # _op, errno, strerror(errno));          \
11536 +                       abort();                                        \
11537 +               }                                                       \
11538 +       } while (0)
11539 +
11540 +#define memeq(_a, _b) \
11541 +       ((memcmp(_a, _b, sizeof *(_a)) == 0 ? 0 : -1))
11542 +
11543 +#define memne(_a, _b) \
11544 +       ((memcmp(_a, _b, sizeof *(_a)) == 0 ? -1 : 0))
11545 +
11546 +int main(void)
11547 +{
11548 +       char dname_buf[] = "/tmp/test-mmap.XXXXXX";
11549 +       char *dname;
11550 +       int dir_fd;
11551 +       int file_fd;
11552 +       struct stat st[5];
11553 +
11554 +       /* check whether *at(2) syscalls are available */
11555 +       dir_fd = openat(AT_FDCWD, "/", O_DIRECTORY|O_RDONLY);
11556 +       if (dir_fd == -1 && errno == ENOSYS)
11557 +               return EXIT_SUCCESS;    /* kernel too old */
11558 +
11559 +       assert(dir_fd != -1);
11560 +       close(dir_fd);
11561 +
11562 +       /* create a tree like
11563 +        * /
11564 +        * +- tmp/
11565 +        *    +- <tmpname>/
11566 +        *       |- test/
11567 +        *       |- some-file
11568 +        *       +- some-link -> some-file
11569 +        */
11570 +       dname = mkdtemp(dname_buf);
11571 +       assert(dname != NULL);
11572 +
11573 +       dir_fd = open(dname, O_DIRECTORY|O_RDONLY);
11574 +       assert(dir_fd != -1);
11575 +
11576 +       TEST(mkdirat(dir_fd, "test", 0700));
11577 +       TEST(chdir(dname));
11578 +       TEST(chdir("test"));
11579 +
11580 +       file_fd = openat(dir_fd, "some-file", O_WRONLY|O_CREAT, 0400);
11581 +       assert(file_fd != -1);
11582 +
11583 +       write(file_fd, "some text\n", 10);
11584 +       TEST(close(file_fd));
11585 +
11586 +       TEST(symlinkat("some-file", dir_fd, "some-link"));
11587 +       TEST(symlinkat("dangling", dir_fd, "dangling-link"));
11588 +
11589 +       /* now check, whether attributes of 'some-file' and 'some-link'
11590 +        * returned by stat(2), lstat(2) and fstatat(2) are consistent */
11591 +       TEST(stat("../some-file", &st[0]));
11592 +       TEST(lstat("../some-link", &st[1]));
11593 +
11594 +       TEST(fstatat(dir_fd, "some-file", &st[2], 0));
11595 +       TEST(fstatat(dir_fd, "some-link", &st[3], AT_SYMLINK_NOFOLLOW));
11596 +       TEST(fstatat(dir_fd, "some-link", &st[4], 0));
11597 +
11598 +       TEST(faccessat(dir_fd, "some-file", R_OK, 0));
11599 +       TEST((faccessat(dir_fd, "some-file", W_OK, 0) == -1 &&
11600 +             errno == EACCES) ? 0 : -1);;
11601 +
11602 +       if (1)
11603 +               fputs("skipping faccessat(..., AT_SYMLINK_NOFOLLOW) checks for now...\n",
11604 +                     stderr);
11605 +       else {
11606 +               /* this is broken for dietlibc; the 'flags' parameter is not checked
11607 +                * by the kernel but must be handled by the libc itself */
11608 +               TEST(faccessat(dir_fd, "some-link", W_OK, AT_SYMLINK_NOFOLLOW));
11609 +               TEST(faccessat(dir_fd, "dangling-link", R_OK, AT_SYMLINK_NOFOLLOW));
11610 +       }
11611 +
11612 +       assert(st[0].st_mode == (0400 | S_IFREG));
11613 +       assert(S_ISLNK(st[1].st_mode));
11614 +
11615 +       TEST(memne(&st[0], &st[1]));
11616 +       TEST(memeq(&st[0], &st[2]));
11617 +       TEST(memeq(&st[0], &st[4]));
11618 +       TEST(memeq(&st[1], &st[3]));
11619 +
11620 +       /* and cleanup the mess... */
11621 +       TEST(unlinkat(dir_fd, "some-link", 0));
11622 +       TEST(unlinkat(dir_fd, "some-file", 0));
11623 +       TEST(unlinkat(dir_fd, "dangling-link", 0));
11624 +       TEST(unlinkat(dir_fd, "test", AT_REMOVEDIR));
11625 +       TEST(rmdir(dname));
11626 +
11627 +       return EXIT_SUCCESS;
11628 +}
11629 diff -urN -x .git dietlibc-0.33/test/byteswap.c dietlibc/test/byteswap.c
11630 --- dietlibc-0.33/test/byteswap.c       2003-12-15 13:07:42.000000000 +0000
11631 +++ dietlibc/test/byteswap.c    2015-01-01 12:14:43.531605560 +0000
11632 @@ -9,12 +9,12 @@
11633    snprintf(buf,100,"%x %x", bswap_16(0x1234), bswap_16(0x5678));
11634    assert(strcmp(buf, "3412 7856") == 0);
11635    
11636 -  printf("%lx\n",bswap_32(0x12345678));
11637 -  snprintf(buf,100,"%lx", bswap_32(0x12345678));
11638 +  printf("%x\n",(unsigned int)bswap_32(0x12345678));
11639 +  snprintf(buf,100,"%x", (unsigned int)bswap_32(0x12345678));
11640    assert(strcmp(buf, "78563412") == 0);
11641  
11642 -  printf("%qx\n",bswap_64(0x123456789ABCDEFull));
11643 -  snprintf(buf,100,"%qx", bswap_64(0x123456789ABCDEFull));
11644 +  printf("%llx\n",(unsigned long long)bswap_64(0x123456789ABCDEFull));
11645 +  snprintf(buf,100,"%llx", (unsigned long long)bswap_64(0x123456789ABCDEFull));
11646    assert(strcmp(buf, "efcdab8967452301") == 0);
11647    return 0; 
11648  }
11649 diff -urN -x .git dietlibc-0.33/test/cycles.c dietlibc/test/cycles.c
11650 --- dietlibc-0.33/test/cycles.c 2004-08-27 15:09:14.000000000 +0000
11651 +++ dietlibc/test/cycles.c      2015-01-01 12:14:43.531605560 +0000
11652 @@ -12,8 +12,21 @@
11653    asm volatile ("rdtsc" : "=a" (l), "=d" (h)); \
11654    dst = (((uint64_t)h) << 32) | l;                             \
11655  } while (0)
11656 +#elif defined (__powerpc64__)
11657 +#define RDTSC(dst) asm volatile ("mftb %0" : "=r" (dst))
11658 +#elif defined (__powerpc__)
11659 +#define RDTSC(dst) do { \
11660 +  uint32_t chk, tbl, tbu; \
11661 +  /* The code below is as suggested in Motorola reference manual for 32 bits PPCs. */ \
11662 +  __asm__ __volatile__ ("1: mftbu %0; mftb %1; mftbu %2; cmpw %2,%0; bne 1b" \
11663 +    : "=r" (tbu), "=r" (tbl), "=r" (chk) ); \
11664 +  dst = ((uint64_t)tbu << 32) | tbl; \
11665 +} while (0)
11666 +#elif defined (__sparcv9__)
11667 +#define RDTSC(dst) asm volatile ("rd %%tick, %%0":"=r"(dst))
11668  #else
11669 -#error "Unimplemented rdtsc"
11670 +#warning "Unimplemented rdtsc"
11671 +#define RDTSC(dst) dst = 0
11672  #endif
11673  
11674  extern char **environ;
11675 @@ -24,7 +37,7 @@
11676    if (!fork()) { execve(argv[1],argv+1,environ); exit(1); }
11677    wait(0);
11678    RDTSC(b);
11679 -  printf("%llu cycles\n",b-a);
11680 +  printf("%llu cycles\n",(unsigned long long)(b-a));
11681  
11682    return 0;
11683  }
11684 diff -urN -x .git dietlibc-0.33/test/dirent/.gitignore dietlibc/test/dirent/.gitignore
11685 --- dietlibc-0.33/test/dirent/.gitignore        1970-01-01 00:00:00.000000000 +0000
11686 +++ dietlibc/test/dirent/.gitignore     2015-01-01 12:14:43.531605560 +0000
11687 @@ -0,0 +1,2 @@
11688 +/opendir-tst1
11689 +/tst-seekdir
11690 diff -urN -x .git dietlibc-0.33/test/ftruncate.c dietlibc/test/ftruncate.c
11691 --- dietlibc-0.33/test/ftruncate.c      1970-01-01 00:00:00.000000000 +0000
11692 +++ dietlibc/test/ftruncate.c   2015-01-01 12:14:43.531605560 +0000
11693 @@ -0,0 +1,54 @@
11694 +#define _GNU_SOURCE
11695 +#define _XOPEN_SOURCE 600
11696 +#define _FILE_OFFSET_BITS 64
11697 +
11698 +#include <stdlib.h>
11699 +#include <fcntl.h>
11700 +#include <assert.h>
11701 +#include <unistd.h>
11702 +#include <sys/stat.h>
11703 +
11704 +#define CHECK(_sz)                             \
11705 +  assert(ftruncate(fd, (_sz)) == 0);           \
11706 +  assert(fstat(fd, &st) == 0);                 \
11707 +  assert(st.st_size == (_sz));                 \
11708 +
11709 +#define CHECK64(_sz)                           \
11710 +  assert(ftruncate64(fd, (_sz)) == 0);         \
11711 +  assert(fstat64(fd, &st64) == 0);             \
11712 +  assert(st64.st_size == (_sz));               \
11713 +
11714 +int main(void)
11715 +{
11716 +  char file[] = "/tmp/dietlibc-fadvise-test.XXXXXX";
11717 +  int fd;
11718 +  struct stat st;
11719 +
11720 +  fd = mkstemp(file);
11721 +  unlink(file);
11722 +
11723 +  assert(ftruncate(fd, 500000) == 0);
11724 +  assert(fstat(fd, &st) == 0);
11725 +
11726 +  if (st.st_blocks > 1) {
11727 +    /* spare files not supported by filesystem :( */
11728 +    return EXIT_SUCCESS;
11729 +  }
11730 +
11731 +  CHECK(1);
11732 +  CHECK(0x7fffffff);
11733 +
11734 +#if __WORDSIZE == 32
11735 +  {
11736 +    struct stat64 st64;
11737 +    CHECK64(1);
11738 +    CHECK64(0x7fffffff);
11739 +    CHECK64(0x80000001ul);
11740 +    CHECK64(0x17fffffffull);
11741 +  }
11742 +#else
11743 +  CHECK(0x17fffffffull);
11744 +#endif
11745 +
11746 +  return EXIT_SUCCESS;
11747 +}
11748 diff -urN -x .git dietlibc-0.33/test/getmntent.c dietlibc/test/getmntent.c
11749 --- dietlibc-0.33/test/getmntent.c      2003-12-15 13:07:42.000000000 +0000
11750 +++ dietlibc/test/getmntent.c   2015-01-01 12:14:43.534938894 +0000
11751 @@ -33,10 +33,6 @@
11752  
11753   printf("closing /etc/fstab\n");
11754   assert ( 1 == endmntent(fstab));
11755 - printf("closing /etc/fstab again\n");
11756 - assert ( 1 == endmntent(fstab)); /* endmntent must always return 1 */
11757 - printf("entmntent(0)\n");
11758 - assert ( 1 == endmntent(0)); /* causes a segfault with diet libc */
11759 +
11760   return 0;
11761  }
11762 -
11763 diff -urN -x .git dietlibc-0.33/test/getservbyname.c dietlibc/test/getservbyname.c
11764 --- dietlibc-0.33/test/getservbyname.c  2003-12-15 13:07:42.000000000 +0000
11765 +++ dietlibc/test/getservbyname.c       2015-01-01 12:14:43.534938894 +0000
11766 @@ -1,5 +1,6 @@
11767  #include <stdio.h>
11768  #include <netdb.h>
11769 +#include <arpa/inet.h>
11770  
11771  int main(int argc,char *argv[]) {
11772    struct servent* se;
11773 diff -urN -x .git dietlibc-0.33/test/.gitignore dietlibc/test/.gitignore
11774 --- dietlibc-0.33/test/.gitignore       1970-01-01 00:00:00.000000000 +0000
11775 +++ dietlibc/test/.gitignore    2015-01-01 12:14:43.531605560 +0000
11776 @@ -0,0 +1,91 @@
11777 +.testenv.sh
11778 +/adjtime
11779 +/alarm
11780 +/argv
11781 +/asctime
11782 +/asprintf
11783 +/atexit
11784 +/atfile
11785 +/bsearch
11786 +/byteswap
11787 +/calloc
11788 +/confstr
11789 +/cycles
11790 +/empty
11791 +/fadvise
11792 +/ffs
11793 +/flush
11794 +/fnmatch
11795 +/fputc
11796 +/ftruncate
11797 +/ftw
11798 +/fwrite
11799 +/getaddrinfo
11800 +/getdelim
11801 +/getenv
11802 +/getgrnam
11803 +/gethostbyaddr
11804 +/gethostbyname
11805 +/gethostbyname_r
11806 +/getmntent
11807 +/getopt
11808 +/getpass
11809 +/getpwnam
11810 +/getservbyname
11811 +/getservbyport
11812 +/getusershell
11813 +/glob
11814 +/grent
11815 +/hasmntopt
11816 +/hello
11817 +/iconv
11818 +/if_nameindex
11819 +/ltostr
11820 +/malloc-debugger
11821 +/math
11822 +/md5_testharness
11823 +/memccpy
11824 +/memchr
11825 +/memcmp
11826 +/memrchr
11827 +/memusage
11828 +/mktime
11829 +/mmap_test
11830 +/pipe
11831 +/printf
11832 +/printftest
11833 +/protoent
11834 +/prototypes
11835 +/putenv
11836 +/pwent
11837 +/rand48
11838 +/read1
11839 +/readdir
11840 +/readdir64
11841 +/regex
11842 +/select
11843 +/sendfile
11844 +/servent
11845 +/setjmp
11846 +/siglist
11847 +/sigsetjmp
11848 +/speed
11849 +/spent
11850 +/sprintf
11851 +/sscanf
11852 +/stdarg
11853 +/strcasecmp
11854 +/strcmp
11855 +/strncat
11856 +/strncpy
11857 +/strptime
11858 +/strrchr
11859 +/strstr
11860 +/strtol
11861 +/sysconf
11862 +/sysenter
11863 +/test
11864 +/testing
11865 +/ungetc
11866 +/utime
11867 +/waitpid
11868 diff -urN -x .git dietlibc-0.33/test/if_nameindex.c dietlibc/test/if_nameindex.c
11869 --- dietlibc-0.33/test/if_nameindex.c   2003-02-20 15:57:12.000000000 +0000
11870 +++ dietlibc/test/if_nameindex.c        2015-01-01 12:14:43.534938894 +0000
11871 @@ -1,8 +1,12 @@
11872  #include <stdio.h>
11873 +#include <assert.h>
11874  #include <net/if.h>
11875  
11876  int main() {
11877    struct if_nameindex* t=if_nameindex();
11878 +
11879 +  assert(t != NULL);
11880 +
11881    if (t) {
11882      struct if_nameindex* t1=t;
11883      while (t->if_index) {
11884 diff -urN -x .git dietlibc-0.33/test/inet/.gitignore dietlibc/test/inet/.gitignore
11885 --- dietlibc-0.33/test/inet/.gitignore  1970-01-01 00:00:00.000000000 +0000
11886 +++ dietlibc/test/inet/.gitignore       2015-01-01 12:14:43.534938894 +0000
11887 @@ -0,0 +1,3 @@
11888 +/test_ifindex
11889 +/tst-gethnm
11890 +/tst-ntoa
11891 diff -urN -x .git dietlibc-0.33/test/Makefile dietlibc/test/Makefile
11892 --- dietlibc-0.33/test/Makefile 2012-01-24 18:24:29.000000000 +0000
11893 +++ dietlibc/test/Makefile      2015-01-01 12:14:43.531605560 +0000
11894 @@ -7,14 +7,14 @@
11895  
11896  LCOMPAT=-lcompat
11897  
11898 -TESTPROGRAMS=adjtime alarm argv asprintf atexit bsearch byteswap calloc confstr cycles empty fadvise flush fnmatch \
11899 -fputc ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \
11900 +TESTPROGRAMS=adjtime alarm argv asctime asprintf atexit atfile bsearch byteswap calloc confstr cycles empty fadvise flush fnmatch \
11901 +fputc ftruncate ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \
11902  gethostbyname_r getmntent getopt getpass getpwnam getservbyname getservbyport getusershell \
11903 -glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \
11904 +glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger math md5_testharness \
11905  memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest \
11906 -protoent prototypes putenv pwent rand48 read1 readdir regex select sendfile servent siglist \
11907 -speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \
11908 -strstr strtol sysenter ungetc utime waitpid
11909 +protoent prototypes putenv pwent rand48 read1 readdir readdir64 regex select sendfile servent setjmp siglist \
11910 +sigsetjmp speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \
11911 +strstr strtol sysconf sysenter unaligned ungetc utime waitpid
11912  
11913  test: $(TESTPROGRAMS)
11914  
11915 diff -urN -x .git dietlibc-0.33/test/malloc-debugger.c dietlibc/test/malloc-debugger.c
11916 --- dietlibc-0.33/test/malloc-debugger.c        2003-02-20 15:57:13.000000000 +0000
11917 +++ dietlibc/test/malloc-debugger.c     2015-01-01 12:14:43.534938894 +0000
11918 @@ -4,7 +4,7 @@
11919  int main() {
11920    char* c=malloc(13);
11921    char* tmp;
11922 -  fprintf(stderr,"got %p\n",c);
11923 +  fprintf(stdout,"got %p\n",c);
11924    c[0]=14;
11925  //  c[15]=0;
11926    tmp=realloc(c,12345);
11927 diff -urN -x .git dietlibc-0.33/test/math.c dietlibc/test/math.c
11928 --- dietlibc-0.33/test/math.c   1970-01-01 00:00:00.000000000 +0000
11929 +++ dietlibc/test/math.c        2015-01-01 12:14:43.534938894 +0000
11930 @@ -0,0 +1,29 @@
11931 +#include <math.h>
11932 +#include <float.h>
11933 +#include <assert.h>
11934 +
11935 +int main()
11936 +{
11937 +  extern int __isinf(double d);
11938 +  extern int __isnan(double d);
11939 +
11940 +#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
11941 +  assert(__isinf(__builtin_inff())  == +1);
11942 +  assert(__isinf(-__builtin_inff()) == -1);
11943 +
11944 +  assert(__isinf(__builtin_inf())   == +1);
11945 +  assert(__isinf(-__builtin_inf())  == -1);
11946 +
11947 +  assert(__isnan(__builtin_nan("")));
11948 +#endif
11949 +
11950 +  assert(__isinf((DBL_MAX * DBL_MAX))  == +1);
11951 +  assert(__isinf(-(DBL_MAX * DBL_MAX)) == -1);
11952 +
11953 +  assert(isinf((DBL_MAX * DBL_MAX)));
11954 +  assert(isinf(-(DBL_MAX * DBL_MAX)));
11955 +
11956 +  //assert(isnan(nan("")));
11957 +
11958 +  return 0;
11959 +}
11960 diff -urN -x .git dietlibc-0.33/test/mktime.c dietlibc/test/mktime.c
11961 --- dietlibc-0.33/test/mktime.c 2004-03-27 00:47:00.000000000 +0000
11962 +++ dietlibc/test/mktime.c      2015-01-01 12:14:43.534938894 +0000
11963 @@ -9,15 +9,15 @@
11964    t.tm_mday=29;
11965    t.tm_mon=2;
11966    t.tm_year=100;
11967 -  printf("%d\n",mktime(&t));
11968 +  printf("%ld\n",(long)mktime(&t));
11969    t.tm_mday=1;
11970    t.tm_mon=3;
11971    t.tm_year=102;
11972 -  printf("%d\n",mktime(&t));
11973 +  printf("%ld\n",(long)mktime(&t));
11974    t.tm_mday=1;
11975    t.tm_mon=6;
11976    t.tm_year=102;
11977 -  printf("%d\n",mktime(&t));
11978 +  printf("%ld\n",(long)mktime(&t));
11979    return 0;
11980  }
11981  
11982 diff -urN -x .git dietlibc-0.33/test/mmap_test.c dietlibc/test/mmap_test.c
11983 --- dietlibc-0.33/test/mmap_test.c      2002-02-18 00:37:31.000000000 +0000
11984 +++ dietlibc/test/mmap_test.c   2015-01-01 12:14:43.534938894 +0000
11985 @@ -1,12 +1,13 @@
11986 -
11987  #include <stdio.h>
11988  #include <fcntl.h>
11989  #include <unistd.h>
11990 +#include <stdlib.h>
11991 +#include <string.h>
11992  #include <sys/mman.h>
11993  #include <errno.h>
11994  
11995 -#define FILENAME   "/tmp/zz_temp_mmap_test"
11996 -#define TESTSTRING "This is a test string"
11997 +#define TESTSTRING0 "This is a test string"
11998 +#define TESTSTRING1 "Another string for testing"
11999  
12000  
12001  int main (int argc, char * argv[])
12002 @@ -14,16 +15,26 @@
12003     int fd;
12004     void *filememory_1;
12005     void *filememory_2;
12006 -   
12007 -   fd = open (FILENAME, O_RDWR | O_CREAT);
12008 -   
12009 +   void *filememory_3;
12010 +   unsigned int pg_sz = sysconf(_SC_PAGESIZE);
12011 +   char fname[] = "/tmp/test-mmap.XXXXXX";
12012 +
12013 +   fd = mkstemp(fname);
12014     if (fd < 0)
12015     {
12016 -      fprintf (stderr, "Couldn't open %s for writing\n", FILENAME);
12017 +      fprintf (stderr, "Couldn't open %s for writing\n", fname);
12018        return (1);
12019     }
12020  
12021 -   write (fd, TESTSTRING, sizeof(TESTSTRING));
12022 +   unlink(fname);
12023 +
12024 +   write (fd, TESTSTRING0, sizeof TESTSTRING0);
12025 +
12026 +   ftruncate(fd, pg_sz);
12027 +   lseek(fd, pg_sz, SEEK_SET);
12028 +   write(fd, TESTSTRING1, sizeof TESTSTRING1);
12029 +
12030 +   ftruncate(fd, 2*pg_sz);
12031  
12032     /*
12033        Try mmapping the newly created file...
12034 @@ -38,6 +49,18 @@
12035     }
12036  
12037     /*
12038 +      Test mapping at a given offset
12039 +    */
12040 +
12041 +   filememory_3 = mmap (NULL, 0x0100, PROT_READ, MAP_PRIVATE, fd, pg_sz);
12042 +
12043 +   if (filememory_3 == (void *) -1)
12044 +   {
12045 +      perror("mmap (pg_sz) returned error");
12046 +      return (1);
12047 +   }
12048 +
12049 +   /*
12050        Try mmapping with a bogus file descriptor... (should fail)
12051     */
12052  
12053 @@ -49,32 +72,33 @@
12054        return (1);
12055     }
12056     
12057 -   close (fd);
12058 -
12059     /*
12060        Check that we can read back from the file OK
12061     */
12062  
12063 -   if ((*(unsigned char *) filememory_1) != TESTSTRING[0])
12064 +   if (memcmp(filememory_1, TESTSTRING0, sizeof TESTSTRING0) != 0)
12065     {
12066        fprintf (stderr, "mmap doesn't give expected data...\n");
12067        return (1);
12068     }
12069 -   
12070 -   /*
12071 -      fixme: check unmapping as well.... ??
12072 -   */
12073  
12074 +   if (memcmp(filememory_3, TESTSTRING1, sizeof TESTSTRING1) != 0)
12075 +   {
12076 +      fprintf (stderr, "mmap (pg_sz) doesn't give expected data...\n");
12077 +      return (1);
12078 +   }
12079 +
12080 +   if (munmap(filememory_3, 0x0100) < 0 ||
12081 +       munmap(filememory_1, 0x0100) < 0)
12082 +   {
12083 +      perror("munmap()");
12084 +      return 1;
12085 +   }
12086  
12087     /*
12088        Clean up.
12089     */
12090 -
12091 -   if (unlink (FILENAME) != 0)
12092 -   {
12093 -      fprintf (stderr, "Unexpected problem deleting the tempfile... ?\n");
12094 -      return (1);
12095 -   }
12096 +   close (fd);
12097  
12098     return (0);
12099  }
12100 diff -urN -x .git dietlibc-0.33/test/pipe.c dietlibc/test/pipe.c
12101 --- dietlibc-0.33/test/pipe.c   2002-05-13 15:56:48.000000000 +0000
12102 +++ dietlibc/test/pipe.c        2015-01-01 12:14:43.534938894 +0000
12103 @@ -5,6 +5,9 @@
12104  main (void)
12105  {
12106         int fd[2];
12107 +       close(3);
12108 +       close(4);
12109 +
12110         assert (!pipe (fd));
12111         /* if for some reason the parent process has fd3 or fd4
12112            already open, then this will fail although there is
12113 diff -urN -x .git dietlibc-0.33/test/printf.c dietlibc/test/printf.c
12114 --- dietlibc-0.33/test/printf.c 2008-05-06 17:18:35.000000000 +0000
12115 +++ dietlibc/test/printf.c      2015-01-01 12:14:43.534938894 +0000
12116 @@ -2,11 +2,26 @@
12117  #include <string.h>
12118  #include <stdlib.h>
12119  #include <assert.h>
12120 +#include <math.h>
12121 +#include <float.h>
12122  #include <sys/param.h>
12123  #include <locale.h>
12124  
12125  #define ALGN           5
12126  
12127 +#ifndef INFINITY
12128 +#  if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
12129 +#    define INFINITY   (__builtin_inf())
12130 +#  endif
12131 +#endif
12132 +
12133 +#ifndef NAN
12134 +#  if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
12135 +#    define NAN                (__builtin_nan(""))
12136 +#  endif
12137 +#endif
12138 +
12139 +
12140  // https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=112986
12141  #if 0
12142  #undef  assert
12143 @@ -60,7 +75,7 @@
12144    TEST_SNPRINTF(EXP,  0,                __VA_ARGS__);          \
12145    TEST_SNPRINTF(EXP,  sizeof(EXP)+ALGN, __VA_ARGS__);          \
12146    TEST_SNPRINTF_NULL(EXP, __VA_ARGS__)
12147 -  
12148 +
12149  
12150  int main()
12151  {
12152 @@ -101,7 +116,7 @@
12153    TEST("42.23",   "%5.2f",  42.23);
12154    TEST("42.23",   "%5.4g",  42.23);
12155    TEST(" 42.2",   "%5.3g",  42.23);
12156 -  
12157 +
12158    TEST("   1",     "%*i",   4, 1);
12159    TEST("   1",     "%4i",   1);
12160    TEST("1   ",     "%-4i",  1);
12161 @@ -131,13 +146,32 @@
12162    TEST("-01234",   "%6.5i", -1234);
12163    TEST("  1234",   "%6.5s", "1234");
12164  
12165 +#ifdef INFINITY
12166 +  TEST("inf",  "%f", INFINITY);
12167 +  TEST("-inf", "%f", -INFINITY);
12168 +  TEST("INF",  "%F", INFINITY);
12169 +  TEST("-INF", "%F", -INFINITY);
12170 +
12171 +  TEST("inf",  "%g", INFINITY);
12172 +  TEST("-inf", "%g", -INFINITY);
12173 +  TEST("INF",  "%G", INFINITY);
12174 +  TEST("-INF", "%G", -INFINITY);
12175 +#endif
12176 +
12177 +#ifdef NAN
12178 +  TEST("nan",  "%f", NAN);
12179 +  TEST("NAN",  "%F", NAN);
12180 +  TEST("nan",  "%g", NAN);
12181 +  TEST("NAN",  "%G", NAN);
12182 +#endif
12183 +
12184  #ifdef XSI_TESTS
12185    setlocale(LC_ALL, "de_DE");
12186 -  
12187 +
12188    TEST("1.234",    "%'u", 1234);
12189    TEST("2 1",      "%2$u %1$u",  1, 2);
12190  #endif
12191 -  
12192 -  
12193 +
12194 +
12195    return EXIT_SUCCESS;
12196  }
12197 diff -urN -x .git dietlibc-0.33/test/printftest.c dietlibc/test/printftest.c
12198 --- dietlibc-0.33/test/printftest.c     2003-12-15 13:07:42.000000000 +0000
12199 +++ dietlibc/test/printftest.c  2015-01-01 12:14:43.534938894 +0000
12200 @@ -101,8 +101,8 @@
12201    printf("#%i#\n",18);
12202    printf("#%d#\n",18);
12203    printf("#%u#\n",18);
12204 -  printf("#%lu#\n",18);
12205 -  printf("#%li#\n",18);
12206 +  printf("#%lu#\n",18l);
12207 +  printf("#%li#\n",18l);
12208    printf("#%-+#06d#\n", -123);
12209    printf("#%-+#6d#\n", -123);
12210    printf("#%+#06d#\n", -123);
12211 @@ -142,7 +142,7 @@
12212             buf);
12213      memset(buf2,0,sizeof(buf));
12214      i=snprintf(buf2, 256, "%.9999u", 10);
12215 -    printf("%i %i\n",i,strlen(buf2));
12216 +    printf("%i %li\n",i,strlen(buf2));
12217      
12218      printf ("snprintf (\"%%.999999u\", 10) == %d\n",
12219             snprintf(buf2, sizeof(buf2), "%.999999u", 10));
12220 diff -urN -x .git dietlibc-0.33/test/rand48.c dietlibc/test/rand48.c
12221 --- dietlibc-0.33/test/rand48.c 2002-05-29 13:20:40.000000000 +0000
12222 +++ dietlibc/test/rand48.c      2015-01-01 12:14:43.534938894 +0000
12223 @@ -6,16 +6,16 @@
12224  {
12225    static unsigned short  data[7] = { 1, 2, 3, 4, 5, 6, 7 };
12226  
12227 -  printf ("one   %X\n", mrand48 ());
12228 -  printf ("two   %X\n", mrand48 ());
12229 -  printf ("three %X\n", mrand48 ());
12230 +  printf ("one   %lX\n", mrand48 ());
12231 +  printf ("two   %lX\n", mrand48 ());
12232 +  printf ("three %lX\n", mrand48 ());
12233  
12234    lcong48 (data);
12235    printf ("after lcong48:\n");
12236  
12237 -  printf ("one   %X\n", mrand48 ());
12238 -  printf ("two   %X\n", mrand48 ());
12239 -  printf ("three %X\n", mrand48 ());
12240 +  printf ("one   %lX\n", mrand48 ());
12241 +  printf ("two   %lX\n", mrand48 ());
12242 +  printf ("three %lX\n", mrand48 ());
12243  
12244    return 0;
12245  }
12246 diff -urN -x .git dietlibc-0.33/test/readdir64.c dietlibc/test/readdir64.c
12247 --- dietlibc-0.33/test/readdir64.c      1970-01-01 00:00:00.000000000 +0000
12248 +++ dietlibc/test/readdir64.c   2015-01-01 12:14:43.534938894 +0000
12249 @@ -0,0 +1,2 @@
12250 +#define _FILE_OFFSET_BITS 64
12251 +#include "readdir.c"
12252 diff -urN -x .git dietlibc-0.33/test/readdir.c dietlibc/test/readdir.c
12253 --- dietlibc-0.33/test/readdir.c        2003-02-20 15:57:13.000000000 +0000
12254 +++ dietlibc/test/readdir.c     2015-01-01 12:14:43.534938894 +0000
12255 @@ -1,17 +1,103 @@
12256 -#define _FILE_OFFSET_BITS 64
12257 +#define _BSD_SOURCE
12258  #include <dirent.h>
12259  #include <stdio.h>
12260 +#include <stdlib.h>
12261  #include <errno.h>
12262 +#include <fcntl.h>
12263 +
12264 +#include "../dietdirent.h"
12265 +
12266 +static int rc = 0;
12267 +
12268 +static void xputs(char const *str)
12269 +{
12270 +  fputs(str, stderr);
12271 +  rc = 1;
12272 +}
12273 +
12274 +static int create_file(char const *dir, char const *name)
12275 +{
12276 +  char buf[strlen(dir) + strlen(name) + sizeof("/")];
12277 +  strcpy(buf, dir);
12278 +  strcat(buf, "/");
12279 +  strcat(buf, name);
12280 +
12281 +  return close(open(buf, O_WRONLY|O_CREAT,0666));
12282 +}
12283 +
12284 +static int remove_file(char const *dir, char const *name)
12285 +{
12286 +  char buf[strlen(dir) + strlen(name) + sizeof("/")];
12287 +  strcpy(buf, dir);
12288 +  strcat(buf, "/");
12289 +  strcat(buf, name);
12290 +
12291 +  return unlink(buf);
12292 +}
12293  
12294  int main() {
12295 -  DIR* D=opendir(".");
12296 -  struct dirent* d;
12297 +  char tmpdir[] = "/tmp/readdir.XXXXXX";
12298 +  unsigned long res = 0;
12299 +  DIR* D;
12300 +  if (!mkdtemp(tmpdir)) {
12301 +    perror("mkdtemp");
12302 +    return 1;
12303 +  }
12304 +  D=opendir(tmpdir);
12305    if (!D) {
12306      perror("opendir");
12307 +    rmdir(tmpdir);
12308      return 1;
12309    }
12310 +
12311 +  if (chdir(tmpdir) < 0) {
12312 +    perror("chdir");
12313 +    rmdir(tmpdir);
12314 +    return 1;
12315 +  }
12316 +  close(open("bar",O_WRONLY|O_CREAT,0666));
12317 +  close(open("baz",O_WRONLY|O_CREAT,0666));
12318 +
12319 +  struct dirent* d;
12320 +
12321    while ((d=readdir(D))) {
12322 -    printf("found %s\n",d->d_name);
12323 +    struct stat                st;
12324 +
12325 +    if (strcmp(d->d_name,".") == 0)
12326 +      res |= 1<<0;
12327 +    else if (strcmp(d->d_name,"..") == 0)
12328 +      res |= 1<<1;
12329 +    else if (strcmp(d->d_name,"bar") == 0)
12330 +      res |= 1<<2;
12331 +    else if (strcmp(d->d_name,"baz") == 0)
12332 +      res |= 1<<3;
12333 +    else
12334 +      xputs("got additional file");
12335 +
12336 +    if (lstat(d->d_name, &st) < 0) {
12337 +      perror("lstat");
12338 +      rc = 1;
12339 +    } else if (st.st_ino != d->d_ino) {
12340 +      xputs("mismatch in ino");
12341 +    } else if (d->d_type == DT_UNKNOWN) {
12342 +      /* noop */
12343 +    } else if ((d->d_type == DT_REG && !S_ISREG(st.st_mode)) ||
12344 +              (d->d_type == DT_DIR && !S_ISDIR(st.st_mode))) {
12345 +      xputs("mismatch in d_type");
12346 +    } else if (d->d_type != DT_REG && d->d_type != DT_DIR) {
12347 +      xputs("unexpected d_type");
12348 +    }
12349 +
12350 +    if (telldir(D) != d->d_off) {
12351 +      xputs("mismatch with telldir");
12352 +    }
12353 +
12354 +    unlink(d->d_name);
12355    }
12356 -  return 0;
12357 +
12358 +  if (res != 0x0f)
12359 +    xputs("did not got all expected files");
12360 +
12361 +  rmdir(tmpdir);
12362 +  return rc;
12363  }
12364 diff -urN -x .git dietlibc-0.33/test/regex.c dietlibc/test/regex.c
12365 --- dietlibc-0.33/test/regex.c  2010-09-25 17:03:28.000000000 +0000
12366 +++ dietlibc/test/regex.c       2015-01-01 12:14:43.534938894 +0000
12367 @@ -117,6 +117,9 @@
12368    assert(regexec(&r,"foobarfoo",10,matches,0)==0);
12369    regfree(&r);
12370  
12371 +  assert(regcomp(&r,"^(postmaster|abuse|(felix|leitner|zoke|sanjiyan|dreesen|akuma|braun|kristine|gilda|oskar|moritz)(-[^@]*|))@qarx.de$",REG_NOSUB|REG_EXTENDED)==0);
12372 +  assert(regexec(&r,"apollo.bingo-ev.de@fefe.de",10,matches,0)!=0);
12373 +
12374  #if 0
12375    printf("regcomp %d\n",regcomp(&r,"\\.( ? ? ?\\.)*\\.",REG_EXTENDED|REG_NOSUB));
12376    printf("regexec %d\n",regexec(&r,buf,1,0,0));
12377 diff -urN -x .git dietlibc-0.33/test/runtests.sh dietlibc/test/runtests.sh
12378 --- dietlibc-0.33/test/runtests.sh      2012-01-24 18:24:29.000000000 +0000
12379 +++ dietlibc/test/runtests.sh   2015-01-01 12:14:43.534938894 +0000
12380 @@ -1,6 +1,6 @@
12381  SUBDIRS="dirent inet stdio string stdlib time"
12382  
12383 -TESTPROGRAMS="adjtime alarm argv atexit bsearch byteswap calloc confstr empty fadvise flush fputc ffs fnmatch ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent siglist speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysenter ungetc utime waitpid"
12384 +TESTPROGRAMS="adjtime alarm argv asctime atexit atfile bsearch byteswap calloc confstr empty fadvise flush fputc ffs fnmatch ftruncate ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger math md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent setjmp siglist sigsetjmp speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysconf sysenter ungetc utime waitpid"
12385  
12386  STDIN="read1"
12387  PASS="getpass" 
12388 diff -urN -x .git dietlibc-0.33/test/runtests-X.sh dietlibc/test/runtests-X.sh
12389 --- dietlibc-0.33/test/runtests-X.sh    1970-01-01 00:00:00.000000000 +0000
12390 +++ dietlibc/test/runtests-X.sh 2015-01-01 12:14:43.534938894 +0000
12391 @@ -0,0 +1,162 @@
12392 +#! /bin/bash
12393 +
12394 +SKIP=(
12395 +  ":asprintf"                  # requires special cmdline
12396 +  ":getpass"                   # expects input from TTY
12397 +  ":read1"                     # expects input
12398 +  ":stdio:tst-ferror"          # expects input
12399 +  ":stdio:tstscanf"            # expects input
12400 +  ":stdlib:testdiv"            # expects input
12401 +)
12402 +
12403 +FAILURES_BOGUS=(
12404 +  ":gethostbyname"             # network test; net might not be available in test environment
12405 +  ":gethostbyname_r"           # network test; net might not be available in test environment
12406 +
12407 +  ":stdlib:tst-environ"                # test uses environ function in unsupported ways (dup keys)
12408 +  ":stdlib:tst-rand48"         # platform dependent; does not give reliable results
12409 +  ":stdlib:tst-strtod"         # infinite recursion in __dtostr()
12410 +  ":time:tst-mktime"           # dietlibc does not support $TZ env
12411 +  ":time:tst-posixtz"          # dietlibc does not support $TZ env
12412 +  ":time:tst-strftime"         # dietlibc does not support glibc specific format specifications
12413 +)
12414 +
12415 +FAILURES_BOGUS_emulator=(
12416 +  ":adjtime"                   # ajdtimex() not implement in qemu
12417 +  ":if_nameindex"              # ioctls not implement in qemu
12418 +  ":mmap_test"                 # qemu does not pass back mmap(2) error codes
12419 +  ":fadvise"                   # bad translation of 64bit args in qemu
12420 +  ":stdio:tst-fseek"           # !! unclear; must be investigated
12421 +  ":dirent:tst-seekdir"                # 32/64 bit issue when calling lseek()
12422 +)
12423 +
12424 +FAILURES_KNOWN=(
12425 +  ":sendfile"                  # stdin/stdout not supported; test must be wrapped
12426 +  ":sigsetjmp"                 # fp test fails when registers are on stack
12427 +  ":stdio:tstdiomisc"          # scanf(3) fails on some constructs
12428 +  ":stdio:tst-fphex"           # printf(3) does not support %a specifiers
12429 +  ":stdio:tst-printf"          # printf(3) does not support some floating point ops
12430 +  ":stdio:tst-sscanf"          # scanf(3) fails on double input
12431 +  ":stdlib:test-canon"         # realpath(3) is broken...
12432 +)
12433 +
12434 +TESTENV=.testenv.sh
12435 +
12436 +function is_in() {
12437 +    local      val=$1
12438 +    local      i
12439 +    shift
12440 +
12441 +    for i; do
12442 +       test x"$i" != x"$val" || return 0
12443 +    done
12444 +    return 1
12445 +}
12446 +
12447 +function getenv() {
12448 +    local _e=testenv.sh
12449 +
12450 +    if ${1:-false} || \
12451 +       test ! -e $TESTENV -o \
12452 +               Makefile -nt $TESTENV -o \
12453 +               runtests.sh -nt $TESTENV; then
12454 +       eval $(grep '^\(SUBDIRS\)=' runtests.sh)
12455 +       eval $(make --no-print-directory \
12456 +           --eval 'print-tests:;@echo TESTPROGRAMS=\"$(sort $(TESTPROGRAMS))\"' \
12457 +           print-tests)
12458 +
12459 +       rm -f $TESTENV
12460 +
12461 +       {
12462 +         printf "SUBDIRS='%s'\n" "$SUBDIRS"
12463 +         printf "TESTPROGRAMS='%s'\n" "$TESTPROGRAMS"
12464 +       } > $TESTENV
12465 +    fi
12466 +
12467 +    source $TESTENV
12468 +}
12469 +
12470 +: ${TESTDIR:=.}
12471 +
12472 +case $1 in
12473 +  --generate-env)
12474 +       getenv true
12475 +       TESTPROGRAMS=           # skip tests; progress subdirs only
12476 +       ;;
12477 +  --install)
12478 +       getenv
12479 +       install -d -m 0755 $2/$TESTDIR
12480 +       install -p -m 0755 $TESTPROGRAMS $TESTENV $2/$TESTDIR/
12481 +       TESTPROGRAMS=
12482 +       ;;
12483 +  *)
12484 +       getenv
12485 +       ;;
12486 +esac
12487 +
12488 +rc=0
12489 +
12490 +: ${ME:=${BASH_SOURCE[0]}}
12491 +: ${EMULATOR:=}
12492 +: ${RUNTEST_INDENT=0}
12493 +
12494 +export ME
12495 +export RUNTEST_INDENT
12496 +export RUNTEST_NS
12497 +export TESTDIR
12498 +
12499 +case $ME in
12500 +  /*) ;;
12501 +  *) ME=`pwd`/$ME;;
12502 +esac
12503 +
12504 +test -z "$EMULATOR" || \
12505 +    FAILURES_BOGUS=( "${FAILURES_BOGUS[@]}" "${FAILURES_BOGUS_emulator[@]}" )
12506 +
12507 +for p in $TESTPROGRAMS; do
12508 +    ! tty -s || printf '%*s%-20s' $RUNTEST_INDENT '' "$p"
12509 +
12510 +    is_in "$RUNTEST_NS:$p" "${FAILURES_BOGUS[@]}" && fail_bogus=true || fail_bogus=false
12511 +    is_in "$RUNTEST_NS:$p" "${FAILURES_KNOWN[@]}" && fail_known=true || fail_known=false
12512 +
12513 +    if is_in "$RUNTEST_NS:$p" "${SKIP[@]}"; then
12514 +       res='SKIPPED'
12515 +    else
12516 +       $EMULATOR ./$p >/dev/null && failed=false || failed=true
12517 +
12518 +       case $failed:$fail_known:$fail_bogus in
12519 +         (false:false:*)       res='OK';;
12520 +         (false:true:true)     res='OK (bogus)';;
12521 +         (false:true:false)    res="OK (unexpected)"; let ++rc;;
12522 +         (true:*:true)         res='FAIL (bogus)';;
12523 +         (true:true:*)         res="FAIL (known)";;
12524 +         (true:false:*)        res='FAIL'; let ++rc;;
12525 +       esac
12526 +    fi
12527 +
12528 +    ! tty -s || printf '\r'
12529 +
12530 +    printf '%*s%-20s%s\n' $RUNTEST_INDENT '' "$p" "$res"
12531 +done
12532 +
12533 +test $rc -eq 0 || \
12534 +    printf "%*s--> %u tests failed\n" $RUNTEST_INDENT '' $rc
12535 +
12536 +orig_testdir=$TESTDIR
12537 +
12538 +for d in $SUBDIRS; do
12539 +    echo "--- entering directory $d ---"
12540 +    let RUNTEST_INDENT+=2
12541 +    old_ns=$RUNTEST_NS
12542 +    RUNTEST_NS=$RUNTEST_NS:$d
12543 +
12544 +    TESTDIR=$orig_testdir/$d
12545 +    cd $d && bash $ME "$@" || let ++rc
12546 +
12547 +    RUNTEST_NS=$old_ns
12548 +    let RUNTEST_INDENT-=2
12549 +
12550 +    cd $OLDPWD || exit 1
12551 +done
12552 +
12553 +test $rc -eq 0 && exit 0 || exit 1
12554 diff -urN -x .git dietlibc-0.33/test/sendfile.c dietlibc/test/sendfile.c
12555 --- dietlibc-0.33/test/sendfile.c       2003-12-15 13:07:42.000000000 +0000
12556 +++ dietlibc/test/sendfile.c    2015-01-01 12:14:43.534938894 +0000
12557 @@ -11,5 +11,5 @@
12558  
12559    printf("sendfile returned %d\n",ret);
12560  
12561 -return 0;    
12562 +  return ret<0 ? 1 : 0;
12563  }
12564 diff -urN -x .git dietlibc-0.33/test/setjmp.c dietlibc/test/setjmp.c
12565 --- dietlibc-0.33/test/setjmp.c 1970-01-01 00:00:00.000000000 +0000
12566 +++ dietlibc/test/setjmp.c      2015-01-01 12:14:43.534938894 +0000
12567 @@ -0,0 +1,106 @@
12568 +#include <assert.h>
12569 +#include <stdlib.h>
12570 +#include <string.h>
12571 +#include <setjmp.h>
12572 +
12573 +static int Xmemcmp(void const volatile *a, void const volatile *b, size_t l)
12574 +{
12575 +  return memcmp((void const *)a, (void const *)b, l);
12576 +}
12577 +
12578 +int main(void)
12579 +{
12580 +  char volatile a[8] = "testbufA";
12581 +  jmp_buf env;
12582 +  char volatile b[8] = "testbufB";
12583 +
12584 +  assert(Xmemcmp(a, "testbufA", 8) == 0);
12585 +  assert(Xmemcmp(b, "testbufB", 8) == 0);
12586 +
12587 +
12588 +  /* Test 1: not calling longjmp */
12589 +  if (setjmp(env) == 0) {
12590 +    char volatile somebuf[128];
12591 +
12592 +    memset((void *)somebuf, 0xde, sizeof somebuf);
12593 +
12594 +    assert(Xmemcmp(a, "testbufA", 8) == 0);
12595 +    assert(Xmemcmp(b, "testbufB", 8) == 0);
12596 +  } else
12597 +    assert(0);
12598 +
12599 +  assert(Xmemcmp(a, "testbufA", 8) == 0);
12600 +  assert(Xmemcmp(b, "testbufB", 8) == 0);
12601 +
12602 +
12603 +  /* Test 2: calling longjmp */
12604 +  switch (setjmp(env)) {
12605 +  case 0: {
12606 +    char volatile somebuf[128];
12607 +
12608 +    memset((void *)somebuf, 0xde, sizeof somebuf);
12609 +
12610 +    assert(Xmemcmp(a, "testbufA", 8) == 0);
12611 +    assert(Xmemcmp(b, "testbufB", 8) == 0);
12612 +
12613 +    longjmp(env, 23);
12614 +
12615 +    a[0] = 'X';
12616 +    b[0] = 'X';
12617 +  }
12618 +
12619 +  case 23:
12620 +    break;
12621 +
12622 +  default:
12623 +    assert(0);
12624 +  }
12625 +
12626 +  assert(Xmemcmp(a, "testbufA", 8) == 0);
12627 +  assert(Xmemcmp(b, "testbufB", 8) == 0);
12628 +
12629 +
12630 +  /* Test 3: calling longjmp again with dirty env */
12631 +  switch (setjmp(env)) {
12632 +  case 0: {
12633 +    char volatile somebuf[128];
12634 +
12635 +    memset((void *)somebuf, 0xde, sizeof somebuf);
12636 +
12637 +    assert(Xmemcmp(a, "testbufA", 8) == 0);
12638 +    assert(Xmemcmp(b, "testbufB", 8) == 0);
12639 +
12640 +    longjmp(env, 23);
12641 +
12642 +    a[0] = 'X';
12643 +    b[0] = 'X';
12644 +  }
12645 +
12646 +  case 23:
12647 +    break;
12648 +
12649 +  default:
12650 +    assert(0);
12651 +  }
12652 +
12653 +  assert(Xmemcmp(a, "testbufA", 8) == 0);
12654 +  assert(Xmemcmp(b, "testbufB", 8) == 0);
12655 +
12656 +
12657 + /* Test 4: not calling longjmp, but dirty env */
12658 +  if (setjmp(env) == 0) {
12659 +    char volatile somebuf[128];
12660 +
12661 +    memset((void *)somebuf, 0xde, sizeof somebuf);
12662 +
12663 +    assert(Xmemcmp(a, "testbufA", 8) == 0);
12664 +    assert(Xmemcmp(b, "testbufB", 8) == 0);
12665 +  } else
12666 +    assert(0);
12667 +
12668 +  assert(Xmemcmp(a, "testbufA", 8) == 0);
12669 +  assert(Xmemcmp(b, "testbufB", 8) == 0);
12670 +
12671 +
12672 +  return EXIT_SUCCESS;
12673 +}
12674 diff -urN -x .git dietlibc-0.33/test/sigsetjmp.c dietlibc/test/sigsetjmp.c
12675 --- dietlibc-0.33/test/sigsetjmp.c      1970-01-01 00:00:00.000000000 +0000
12676 +++ dietlibc/test/sigsetjmp.c   2015-01-01 12:14:43.534938894 +0000
12677 @@ -0,0 +1,206 @@
12678 +#include <assert.h>
12679 +#include <stdlib.h>
12680 +#include <stddef.h>
12681 +#include <stdio.h>
12682 +#include <string.h>
12683 +#include <signal.h>
12684 +#include <setjmp.h>
12685 +
12686 +#define TEST_PATTERN   \
12687 +       "0123456789abcdefghijklmnopqrstuv"      \
12688 +       "ZYXWVUTSRQPONMLKJIHGFEDCBA987654"      \
12689 +       "456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"      \
12690 +       "vutsrqponmlkjihgfedcba9876543210"      \
12691 +       "0123456789ABCDEFGHIJKLMNOPQRSTUV"      \
12692 +       "zyxwvutsrqponmlkjihgfedcba987654"      \
12693 +       "456789abcdefghijklmnopqrstuvwxyz"      \
12694 +       "VUTSRQPONMLKJIHGFEDCBA987654321"       \
12695 +
12696 +static struct {
12697 +       char volatile a[256];
12698 +       sigjmp_buf env;
12699 +       char volatile b[256];
12700 +} sigenv = {
12701 +       .a = TEST_PATTERN "<",
12702 +       .b = TEST_PATTERN ">",
12703 +};
12704 +
12705 +static double const volatile   FP_REF[] = {
12706 +  0.4, 0.8, 1.5, 1.6, 2.3, 4.2
12707 +};
12708 +
12709 +static int volatile sig_seen;
12710 +
12711 +#define VALIDATE_BUFFERS(_sig_exp) do {                \
12712 +    assert(Xmemcmp(sigenv.a, TEST_PATTERN "<", sizeof sigenv.a) == 0); \
12713 +    assert(Xmemcmp(sigenv.b, TEST_PATTERN ">", sizeof sigenv.b) == 0); \
12714 +    assert(sig_seen == (_sig_exp));            \
12715 +  } while (0)
12716 +
12717 +static int Xmemcmp(void const volatile *a, void const volatile *b, size_t l)
12718 +{
12719 +  return memcmp((void const *)a, (void const *)b, l);
12720 +}
12721 +
12722 +static void do_test(int sig_num, int do_save, int block_sig)
12723 +{
12724 +  int          rc;
12725 +  sigset_t     block_set;
12726 +  sigset_t     cur_set;
12727 +
12728 +  printf("%s(%d,%d,%d)... ", __func__, sig_num, do_save, block_sig);
12729 +  fflush(stdout);
12730 +
12731 +  VALIDATE_BUFFERS(0);
12732 +
12733 +  sigemptyset(&block_set);
12734 +  assert(sigprocmask(SIG_SETMASK, NULL, &cur_set) == 0);
12735 +
12736 +  /* verify that tested signal is not blocked */
12737 +  if (sig_num != 0)
12738 +    assert(!sigismember(&cur_set, sig_num));
12739 +
12740 +  /* verify that blocked signal is not already blocked and fill signal set */
12741 +  if (block_sig != 0) {
12742 +    assert(!sigismember(&cur_set, block_sig));
12743 +    sigaddset(&block_set, block_sig);
12744 +  }
12745 +
12746 +  sig_seen = 0;
12747 +  rc = sigsetjmp(sigenv.env, do_save);
12748 +  if (rc == 0) {
12749 +    char volatile somebuf[128];
12750 +
12751 +    memset((void *)somebuf, 0x42, sizeof somebuf);
12752 +    VALIDATE_BUFFERS(0);
12753 +
12754 +    /* modify signal mask */
12755 +    if (block_sig != 0)
12756 +      assert(sigprocmask(SIG_BLOCK, &block_set, NULL) == 0);
12757 +
12758 +    /* raise a signal which triggers a siglongjmp */
12759 +    if (sig_num != 0) {
12760 +      raise(sig_num);
12761 +      sigenv.a[0] = 'X';
12762 +      sigenv.b[0] = 'X';
12763 +      assert(0);
12764 +    }
12765 +  } else if (rc != sig_num)
12766 +    /* sigsetjmp() returned with an unexpected value */
12767 +    assert(0);
12768 +
12769 +  VALIDATE_BUFFERS(sig_num);
12770 +  sig_seen = 0;
12771 +
12772 +  /* check whether current signal mask contains the blocked signal; it should
12773 +     be there iff sigsetjmp() was triggered and sigmask was saved. */
12774 +  if (block_sig != 0) {
12775 +    sigset_t   cur_set;
12776 +    assert(sigprocmask(SIG_SETMASK, NULL, &cur_set) == 0);
12777 +
12778 +    if (do_save && rc != 0)
12779 +      assert(!sigismember(&cur_set, block_sig));
12780 +    else {
12781 +      assert( sigismember(&cur_set, block_sig));
12782 +      sigprocmask(SIG_UNBLOCK, &block_set, NULL);
12783 +    }
12784 +  }
12785 +
12786 +  printf(" ok\n");
12787 +};
12788 +
12789 +static void do_test_fp(int sig_num, int do_save)
12790 +{
12791 +  sigset_t     cur_set;
12792 +  int          rc;
12793 +  double       fp0, fp1, fp2, fp3;
12794 +
12795 +  printf("%s(%d,%d)... ", __func__, sig_num, do_save);
12796 +  fflush(stdout);
12797 +
12798 +  VALIDATE_BUFFERS(0);
12799 +
12800 +  assert(sigprocmask(SIG_SETMASK, NULL, &cur_set) == 0);
12801 +
12802 +  /* verify that tested signal is not blocked */
12803 +  if (sig_num != 0)
12804 +    assert(!sigismember(&cur_set, sig_num));
12805 +
12806 +  fp0 = FP_REF[0];
12807 +  fp1 = FP_REF[1];
12808 +  fp2 = FP_REF[2];
12809 +  fp3 = FP_REF[3];
12810 +
12811 +  sig_seen = 0;
12812 +  rc = sigsetjmp(sigenv.env, do_save);
12813 +
12814 +  if (rc == 0) {
12815 +    fp0 = FP_REF[4];
12816 +    fp3 = FP_REF[5];
12817 +
12818 +    if (sig_num != 0) {
12819 +      raise(sig_num);
12820 +      assert(0);
12821 +    }
12822 +  } else if (rc != sig_num)
12823 +    /* sigsetjmp() returned with an unexpected value */
12824 +    assert(0);
12825 +
12826 +  assert(fp1 == FP_REF[1]);
12827 +  assert(fp2 == FP_REF[2]);
12828 +
12829 +  if (sig_num == 0) {
12830 +    /* "exception" was not triggered; we should see the new values */
12831 +    assert(fp0 == FP_REF[4]);
12832 +    assert(fp3 == FP_REF[5]);
12833 +  } else {
12834 +    /* "exception" was triggered; we should see the old values */
12835 +    assert(fp0 == FP_REF[0]);
12836 +    assert(fp3 == FP_REF[3]);
12837 +  }
12838 +
12839 +  VALIDATE_BUFFERS(sig_num);
12840 +  sig_seen = 0;
12841 +
12842 +  printf(" ok\n");
12843 +}
12844 +
12845 +static void sig_handler(int num)
12846 +{
12847 +  assert(sig_seen == 0);
12848 +  sig_seen = num;
12849 +  siglongjmp(sigenv.env, num);
12850 +}
12851 +
12852 +int main(void)
12853 +{
12854 +  struct sigaction sigact = {
12855 +    .sa_handler        = sig_handler,
12856 +    .sa_flags  = SA_NODEFER, /* raised signal will be in blocked mask else */
12857 +  };
12858 +
12859 +  /* verify our assumptions about the memory layout */
12860 +  assert(sizeof sigenv.a == 256);
12861 +  assert(sizeof sigenv.b == 256);
12862 +  assert(offsetof(__typeof__(sigenv), env) == sizeof sigenv.a);
12863 +  assert(offsetof(__typeof__(sigenv), b)   == sizeof sigenv.a + sizeof sigenv.env);
12864 +
12865 +  sigaction(SIGBUS,  &sigact, NULL);
12866 +  sigaction(SIGUSR1, &sigact, NULL);
12867 +
12868 +  do_test(0, 0, 0);
12869 +  do_test(0, 0, SIGUSR1);
12870 +  do_test(0, 1, 0);
12871 +  do_test(0, 1, SIGUSR1);
12872 +  do_test(SIGBUS, 0, 0);
12873 +  do_test(SIGBUS, 0, SIGUSR1);
12874 +  do_test(SIGBUS, 1, 0);
12875 +  do_test(SIGBUS, 1, SIGUSR1);
12876 +
12877 +  do_test_fp(0, 0);
12878 +  do_test_fp(0, 1);
12879 +  do_test_fp(SIGBUS, 0);
12880 +  do_test_fp(SIGBUS, 1);
12881 +
12882 +  return EXIT_SUCCESS;
12883 +}
12884 diff -urN -x .git dietlibc-0.33/test/speed.c dietlibc/test/speed.c
12885 --- dietlibc-0.33/test/speed.c  2003-12-15 13:07:42.000000000 +0000
12886 +++ dietlibc/test/speed.c       2015-01-01 12:14:43.534938894 +0000
12887 @@ -7,10 +7,10 @@
12888    int i;
12889    time_t t;
12890    
12891 -  printf("%d\n", time(0));
12892 +  printf("%ld\n", (long)time(0));
12893    for (i=0; i<10000000; ++i)
12894      t=time(0);
12895  
12896 - printf("%d\n", time(0));
12897 +  printf("%ld\n", (long)time(0));
12898   return 0;   
12899  }
12900 diff -urN -x .git dietlibc-0.33/test/stat.c dietlibc/test/stat.c
12901 --- dietlibc-0.33/test/stat.c   1970-01-01 00:00:00.000000000 +0000
12902 +++ dietlibc/test/stat.c        2015-01-01 12:14:43.534938894 +0000
12903 @@ -0,0 +1,37 @@
12904 +#define _FILE_OFFSET_BITS 64
12905 +#include <sys/types.h>
12906 +#include <sys/stat.h>
12907 +#include <sys/time.h>
12908 +#include <stdio.h>
12909 +#include <stdlib.h>
12910 +#include <fcntl.h>
12911 +#include <unistd.h>
12912 +
12913 +int main() {
12914 +  int fd=open("/tmp/foo",O_CREAT|O_WRONLY|O_EXCL,0666);
12915 +  struct timeval tv[2];
12916 +  struct stat s;
12917 +  if (fd==-1) {
12918 +    perror("open");
12919 +    return -1;
12920 +  }
12921 +  lseek(fd,0x100000000,SEEK_SET);
12922 +  write(fd,"x",1);
12923 +  close(fd);
12924 +  tv[0].tv_sec=123456789;
12925 +  tv[0].tv_usec=0;
12926 +  tv[1].tv_sec=123456789;
12927 +  tv[1].tv_usec=0;
12928 +  if (utimes("/tmp/foo",tv)) {
12929 +    perror("utimes");
12930 +    unlink("/tmp/foo");
12931 +    return -1;
12932 +  }
12933 +  if (stat("/tmp/foo",&s)) {
12934 +    perror("stat");
12935 +    unlink("/tmp/foo");
12936 +    return -1;
12937 +  }
12938 +  printf("size %lld, atime %ld, mtime %ld, inode %ld\n",(long long)s.st_size,(long)s.st_atime,(long)s.st_mtime,(long)s.st_ino);
12939 +  unlink("/tmp/foo");
12940 +}
12941 diff -urN -x .git dietlibc-0.33/test/stdio/.gitignore dietlibc/test/stdio/.gitignore
12942 --- dietlibc-0.33/test/stdio/.gitignore 1970-01-01 00:00:00.000000000 +0000
12943 +++ dietlibc/test/stdio/.gitignore      2015-01-01 12:14:43.534938894 +0000
12944 @@ -0,0 +1,14 @@
12945 +/tst-fdopen
12946 +/tst-ferror
12947 +/tst-fileno
12948 +/tst-fphex
12949 +/tst-fseek
12950 +/tst-printf
12951 +/tst-sprintf
12952 +/tst-sscanf
12953 +/tst-tmpnam
12954 +/tst-unbputc
12955 +/tst-ungetc
12956 +/tstdiomisc
12957 +/tstgetln
12958 +/tstscanf
12959 diff -urN -x .git dietlibc-0.33/test/stdio/tstscanf.c dietlibc/test/stdio/tstscanf.c
12960 --- dietlibc-0.33/test/stdio/tstscanf.c 2003-12-15 13:07:42.000000000 +0000
12961 +++ dietlibc/test/stdio/tstscanf.c      2015-01-01 12:14:43.534938894 +0000
12962 @@ -338,14 +338,14 @@
12963      int res;
12964  
12965      res = sscanf ("-InF", "%f", &value);
12966 -    if (res != 1 || isinf (value) != -1)
12967 +    if (res != 1 || !isinf (value) || !(value<0))
12968        {
12969         fputs ("test failed!\n", stdout);
12970         result = 1;
12971        }
12972  
12973      res = sscanf ("+InfiNiTY", "%f", &value);
12974 -    if (res != 1 || isinf (value) != 1)
12975 +    if (res != 1 || !isinf (value) || !(value>0))
12976        {
12977         fputs ("test failed!\n", stdout);
12978         result = 1;
12979 diff -urN -x .git dietlibc-0.33/test/stdlib/.gitignore dietlibc/test/stdlib/.gitignore
12980 --- dietlibc-0.33/test/stdlib/.gitignore        1970-01-01 00:00:00.000000000 +0000
12981 +++ dietlibc/test/stdlib/.gitignore     2015-01-01 12:14:43.538272226 +0000
12982 @@ -0,0 +1,13 @@
12983 +/test-canon
12984 +/testdiv
12985 +/testrand
12986 +/testsort
12987 +/tst-calloc
12988 +/tst-environ
12989 +/tst-limits
12990 +/tst-malloc
12991 +/tst-rand48
12992 +/tst-strtod
12993 +/tst-strtol
12994 +/tst-strtoll
12995 +/tst-system
12996 diff -urN -x .git dietlibc-0.33/test/stdlib/testsort.c dietlibc/test/stdlib/testsort.c
12997 --- dietlibc-0.33/test/stdlib/testsort.c        2003-12-15 13:07:42.000000000 +0000
12998 +++ dietlibc/test/stdlib/testsort.c     2015-01-01 12:14:43.538272226 +0000
12999 @@ -1,3 +1,5 @@
13000 +#define _BSD_SOURCE
13001 +
13002  #include <stdlib.h>
13003  #include <string.h>
13004  #include <stdio.h>
13005 diff -urN -x .git dietlibc-0.33/test/stdlib/tst-calloc.c dietlibc/test/stdlib/tst-calloc.c
13006 --- dietlibc-0.33/test/stdlib/tst-calloc.c      2003-12-15 13:07:42.000000000 +0000
13007 +++ dietlibc/test/stdlib/tst-calloc.c   2015-01-01 12:14:43.538272226 +0000
13008 @@ -17,6 +17,8 @@
13009     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
13010     02111-1307 USA.  */
13011  
13012 +#define _BSD_SOURCE
13013 +
13014  #include <errno.h>
13015  #include <limits.h>
13016  #include <malloc.h>
13017 diff -urN -x .git dietlibc-0.33/test/stdlib/tst-malloc.c dietlibc/test/stdlib/tst-malloc.c
13018 --- dietlibc-0.33/test/stdlib/tst-malloc.c      2003-12-15 13:07:42.000000000 +0000
13019 +++ dietlibc/test/stdlib/tst-malloc.c   2015-01-01 12:14:43.538272226 +0000
13020 @@ -21,13 +21,15 @@
13021  #include <stdlib.h>
13022  #include <stdio.h>
13023  
13024 +#include "../../dietfeatures.h"
13025 +
13026  static int errors = 0;
13027  
13028  static void
13029  merror (const char *msg)
13030  {
13031    ++errors;
13032 -  printf ("Error: %s\n", msg);
13033 +  fprintf (stderr, "Error: %s\n", msg);
13034  }
13035  
13036  int
13037 @@ -56,9 +58,11 @@
13038    if (p != NULL)
13039      merror ("realloc (p, 0) failed.");
13040  
13041 +#ifdef WANT_MALLOC_ZERO
13042    p = malloc (0);
13043    if (p == NULL)
13044      merror ("malloc (0) failed.");
13045 +#endif
13046  
13047    p = realloc (p, 0);
13048    if (p != NULL)
13049 diff -urN -x .git dietlibc-0.33/test/stdlib/tst-strtod.c dietlibc/test/stdlib/tst-strtod.c
13050 --- dietlibc-0.33/test/stdlib/tst-strtod.c      2003-12-15 13:07:42.000000000 +0000
13051 +++ dietlibc/test/stdlib/tst-strtod.c   2015-01-01 12:14:43.538272226 +0000
13052 @@ -149,10 +149,10 @@
13053      }
13054  
13055    const char input2[] = "+1.000000000116415321826934814453125";
13056 -  if (strtold (input2, NULL) != +1.000000000116415321826934814453125)
13057 +  if (strtold (input2, NULL) != +1.000000000116415321826934814453125L)
13058      {
13059        printf ("input2: %La != %La\n", strtold (input2, NULL),
13060 -             +1.000000000116415321826934814453125);
13061 +             +1.000000000116415321826934814453125L);
13062        status = 1;
13063      }
13064  
13065 diff -urN -x .git dietlibc-0.33/test/string/.gitignore dietlibc/test/string/.gitignore
13066 --- dietlibc-0.33/test/string/.gitignore        1970-01-01 00:00:00.000000000 +0000
13067 +++ dietlibc/test/string/.gitignore     2015-01-01 12:14:43.538272226 +0000
13068 @@ -0,0 +1,16 @@
13069 +/memccpy
13070 +/memchr
13071 +/memcmp
13072 +/memcpy
13073 +/mempcpy
13074 +/memrchr
13075 +/strcasecmp
13076 +/strcmp
13077 +/strcspn
13078 +/strlen
13079 +/strncat
13080 +/strncpy
13081 +/strpbrk
13082 +/strrchr
13083 +/strspn
13084 +/strstr
13085 diff -urN -x .git dietlibc-0.33/test/sysconf.c dietlibc/test/sysconf.c
13086 --- dietlibc-0.33/test/sysconf.c        1970-01-01 00:00:00.000000000 +0000
13087 +++ dietlibc/test/sysconf.c     2015-01-01 12:14:43.538272226 +0000
13088 @@ -0,0 +1,80 @@
13089 +#include <unistd.h>
13090 +#include <stdio.h>
13091 +#include <stdlib.h>
13092 +#include <assert.h>
13093 +#include <sys/wait.h>
13094 +
13095 +#include "../dietpagesize.h"
13096 +
13097 +static long exec_getconf(char const *var)
13098 +{
13099 +  char buf[128];
13100 +  pid_t        pid;
13101 +  int  fd[2];
13102 +  int  status;
13103 +  ssize_t      l;
13104 +
13105 +  if (pipe(fd)<0 || (pid = fork())<0)
13106 +    abort();
13107 +
13108 +  if (pid==0) {
13109 +    close(fd[0]);
13110 +
13111 +    if (fd[1]!=1) {
13112 +      dup2(fd[1], 1);
13113 +      close(fd[1]);
13114 +    }
13115 +
13116 +    execlp("getconf", "getconf", var, NULL);
13117 +    _exit(1);
13118 +  }
13119 +
13120 +  close(fd[1]);
13121 +  l = read(fd[0], buf, sizeof(buf)-1);
13122 +  if (l<0) {
13123 +    perror("read()");
13124 +    goto err;
13125 +  } else if (l==sizeof(buf)-1)
13126 +    goto err;
13127 +  close(fd[0]);
13128 +
13129 +  buf[l] = '\0';
13130 +
13131 +  if (waitpid(pid, &status, 0)<0)
13132 +    goto err;
13133 +
13134 +  if (!WIFEXITED(status) || WEXITSTATUS(status)!=0)
13135 +    goto err;
13136 +
13137 +  return strtol(buf, NULL, 10);
13138 +
13139 + err:
13140 +  kill(pid, SIGKILL);
13141 +  abort();
13142 +}
13143 +
13144 +static unsigned int do_check(char const *var, long exp)
13145 +{
13146 +  long cur = exec_getconf(var);
13147 +
13148 +  if (cur!=exp) {
13149 +    fprintf(stderr, "%s mismatch: got %ld, expected %ld\n",
13150 +           var, cur, exp);
13151 +    return 1;
13152 +  }
13153 +
13154 +  return 0;
13155 +}
13156 +
13157 +int main(int argc, char *argv[])
13158 +{
13159 +  unsigned int err = 0;
13160 +
13161 +  assert(sysconf(_SC_PAGESIZE) == __DIET_PAGE_SIZE);
13162 +  assert(__DIET_PAGE_SIZE == (1<<__DIET_PAGE_SHIFT));
13163 +
13164 +  err += do_check("PAGE_SIZE", sysconf(_SC_PAGESIZE));
13165 +  err += do_check("CLK_TCK",   sysconf(_SC_CLK_TCK));
13166 +
13167 +  return err;
13168 +}
13169 diff -urN -x .git dietlibc-0.33/test/sysenter.c dietlibc/test/sysenter.c
13170 --- dietlibc-0.33/test/sysenter.c       2003-12-15 13:07:42.000000000 +0000
13171 +++ dietlibc/test/sysenter.c    2015-01-01 12:14:43.538272226 +0000
13172 @@ -11,11 +11,11 @@
13173    int i;
13174    for (i=0; environ[i]; ++i) ;
13175    for (x=(struct elf_aux*)(environ+i+1); x->type; ++x) {
13176 -    printf("%d %x\n",x->type,x->value);
13177 +    printf("%ld %lx\n",x->type,x->value);
13178      if (x->type==AT_PAGESZ)
13179 -      printf("pagesize %d\n",x->value);
13180 +      printf("pagesize %ld\n",x->value);
13181      else if (x->type==AT_SYSINFO)
13182 -      printf("vsyscall %p\n",x->value);
13183 +      printf("vsyscall %p\n",(void *)x->value);
13184    }
13185    return 0;
13186  }
13187 diff -urN -x .git dietlibc-0.33/test/thread.c dietlibc/test/thread.c
13188 --- dietlibc-0.33/test/thread.c 1970-01-01 00:00:00.000000000 +0000
13189 +++ dietlibc/test/thread.c      2015-01-01 12:14:43.538272226 +0000
13190 @@ -0,0 +1,162 @@
13191 +#define _REENTRANT
13192 +#include <threads.h>
13193 +#include <stdio.h>
13194 +#include <unistd.h>
13195 +#include <assert.h>
13196 +#include <write12.h>
13197 +#include <time.h>
13198 +#include <errno.h>
13199 +
13200 +mtx_t m;
13201 +
13202 +long l;
13203 +
13204 +int thread(void* arg) {
13205 +  size_t i;
13206 +  char buf[100];
13207 +  (void)arg;
13208 +  for (i=0; i<100; ++i) {
13209 +    mtx_lock(&m);
13210 +    ++l;
13211 +    mtx_unlock(&m);
13212 +  }
13213 +  return 23;
13214 +}
13215 +
13216 +int thread2(void* arg) {
13217 +  mtx_lock(&m);
13218 +  sleep(1);
13219 +  mtx_unlock(&m);
13220 +  return 23;
13221 +}
13222 +
13223 +int recursive_lock(int a) {
13224 +  mtx_lock(&m);
13225 +  if (a>0)
13226 +    return recursive_lock(a-1);
13227 +  else
13228 +    sleep(1);
13229 +  mtx_unlock(&m);
13230 +}
13231 +
13232 +int thread3(void* arg) {
13233 +  recursive_lock(5);
13234 +}
13235 +
13236 +once_flag f=ONCE_FLAG_INIT;
13237 +
13238 +void callme(void) {
13239 +  __write1("callme got called\n");
13240 +}
13241 +
13242 +int thread4(void* arg) {
13243 +  call_once(&f,callme);
13244 +  return 0;
13245 +}
13246 +
13247 +cnd_t cond;
13248 +int done;
13249 +
13250 +int thread5(void* arg) {
13251 +  cnd_wait(&cond,&m);
13252 +//  __write1("thread5\n");
13253 +  ++done;
13254 +  mtx_unlock(&m);
13255 +}
13256 +
13257 +int thread6(void* arg) {
13258 +  errno=0;
13259 +  assert(write(-1,"foo",3)==-1);
13260 +  assert(errno==EBADF);
13261 +  return 0;
13262 +}
13263 +
13264 +int main() {
13265 +  thrd_t threads[16];
13266 +  size_t i;
13267 +  mtx_init(&m,mtx_plain);
13268 +
13269 +  __write1("plain mutex test\n");
13270 +  for (i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) {
13271 +    assert(thrd_create(threads+i,thread,NULL)==thrd_success);
13272 +  }
13273 +  for (i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) {
13274 +    int r;
13275 +    assert(thrd_join(threads[i],&r)==thrd_success && r==23);
13276 +  }
13277 +  assert(l==100*sizeof(threads)/sizeof(threads[0]));
13278 +
13279 +  __write1("mtx_timedlock test\n");
13280 +  assert(thrd_create(threads,thread2,NULL)==thrd_success);
13281 +  {
13282 +    struct timespec ts;
13283 +    ts.tv_sec=0;
13284 +    ts.tv_nsec=10000;
13285 +    nanosleep(&ts,0);
13286 +    assert(mtx_timedlock(&m,&ts)==thrd_timedout);
13287 +  }
13288 +  {
13289 +    int r;
13290 +    assert(thrd_join(threads[0],&r)==thrd_success);
13291 +  }
13292 +  mtx_destroy(&m);
13293 +
13294 +  __write1("mtx_recursive test\n");
13295 +  mtx_init(&m,mtx_recursive);
13296 +  assert(thrd_create(threads,thread3,NULL)==thrd_success);
13297 +  {
13298 +    struct timespec ts;
13299 +    ts.tv_sec=0;
13300 +    ts.tv_nsec=10000;
13301 +    nanosleep(&ts,0);
13302 +    // at this point thread3 should be running, and it should have
13303 +    // locked the recursive lock, and be inside the sleep(1);
13304 +    assert(mtx_trylock(&m)==thrd_busy);
13305 +  }
13306 +  {
13307 +    int r;
13308 +    assert(thrd_join(threads[0],&r)==thrd_success);
13309 +  }
13310 +
13311 +  __write1("call_once test\n");
13312 +  for (i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) {
13313 +    assert(thrd_create(threads+i,thread4,NULL)==thrd_success);
13314 +  }
13315 +  for (i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) {
13316 +    int r;
13317 +    assert(thrd_join(threads[i],&r)==thrd_success && r==0);
13318 +  }
13319 +
13320 +  __write1("cnd_t test\n");
13321 +  cnd_init(&cond);
13322 +  mtx_init(&m,mtx_plain);
13323 +  for (i=0; i<sizeof(threads)/sizeof(threads[0]); ++i) {
13324 +    assert(thrd_create(threads+i,thread5,NULL)==thrd_success);
13325 +    assert(thrd_detach(threads[i])==thrd_success);
13326 +  }
13327 +  {
13328 +    struct timespec ts;
13329 +    ts.tv_sec=0;
13330 +    ts.tv_nsec=100000000;
13331 +    nanosleep(&ts,0);
13332 +    cnd_signal(&cond);
13333 +    nanosleep(&ts,0);
13334 +    mtx_lock(&m);
13335 +    assert(done==1);
13336 +    mtx_unlock(&m);
13337 +    cnd_broadcast(&cond);
13338 +    nanosleep(&ts,0);
13339 +    mtx_lock(&m);
13340 +    assert(done==sizeof(threads)/sizeof(threads[0]));
13341 +    mtx_unlock(&m);
13342 +  }
13343 +
13344 +  errno=0;
13345 +  assert(write(-1,"foo",3)==-1);
13346 +  assert(errno==EBADF);
13347 +
13348 +  assert(thrd_create(threads,thread6,NULL)==thrd_success);
13349 +  assert(thrd_join(threads[0],NULL)==thrd_success);
13350 +
13351 +  return 0;
13352 +}
13353 diff -urN -x .git dietlibc-0.33/test/time/.gitignore dietlibc/test/time/.gitignore
13354 --- dietlibc-0.33/test/time/.gitignore  1970-01-01 00:00:00.000000000 +0000
13355 +++ dietlibc/test/time/.gitignore       2015-01-01 12:14:43.538272226 +0000
13356 @@ -0,0 +1,4 @@
13357 +/tst-mktime
13358 +/tst-posixtz
13359 +/tst-strftime
13360 +/tst-strptime
13361 diff -urN -x .git dietlibc-0.33/test/time/tst-strftime.c dietlibc/test/time/tst-strftime.c
13362 --- dietlibc-0.33/test/time/tst-strftime.c      2003-12-15 13:07:42.000000000 +0000
13363 +++ dietlibc/test/time/tst-strftime.c   2015-01-01 12:14:43.538272226 +0000
13364 @@ -49,18 +49,18 @@
13365  
13366        if (res == 0)
13367         {
13368 -         printf ("%Zu: %s: res == 0 despite size == %Zu\n",
13369 +         printf ("%zu: %s: res == 0 despite size == %zu\n",
13370                   cnt, tests[cnt].fmt, size);
13371           result = 1;
13372         }
13373        else if (size < tests[cnt].min)
13374         {
13375 -         printf ("%Zu: %s: size == %Zu was enough\n",
13376 +         printf ("%zu: %s: size == %zu was enough\n",
13377                   cnt, tests[cnt].fmt, size);
13378           result = 1;
13379         }
13380        else
13381 -       printf ("%Zu: %s: size == %Zu: OK\n", cnt, tests[cnt].fmt, size);
13382 +       printf ("%zu: %s: size == %zu: OK\n", cnt, tests[cnt].fmt, size);
13383  
13384        free (buf);
13385      }
13386 diff -urN -x .git dietlibc-0.33/test/time/tst-strptime.c dietlibc/test/time/tst-strptime.c
13387 --- dietlibc-0.33/test/time/tst-strptime.c      2003-12-15 13:07:42.000000000 +0000
13388 +++ dietlibc/test/time/tst-strptime.c   2015-01-01 12:14:43.538272226 +0000
13389 @@ -41,10 +41,12 @@
13390    { "C", "03/03/00", "%D", 5, 62, 2, 3 },
13391    { "C", "9/9/99", "%x", 4, 251, 8, 9 },
13392    { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 },
13393 +#if 0          /* dietlibc does not support %U/%W/%j and non-POSIX locales */
13394    { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 },
13395    { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 },
13396    { "ja_JP.EUC-JP", "2001 20 \xb7\xee", "%Y %U %a", 1, 140, 4, 21 },
13397    { "ja_JP.EUC-JP", "2001 21 \xb7\xee", "%Y %W %a", 1, 140, 4, 21 },
13398 +#endif
13399  };
13400  
13401  
13402 @@ -72,9 +74,16 @@
13403  
13404    for (i = 0; i < sizeof (tm_tests) / sizeof (tm_tests[0]); ++i)
13405      {
13406 +      char *pres;
13407        memset (&tm, '\0', sizeof (tm));
13408 -      
13409 -      if (strptime (tm_tests[i].input, tm_tests[i].format, &tm) != '\0')
13410 +
13411 +      pres = strptime (tm_tests[i].input, tm_tests[i].format, &tm);
13412 +      if (!pres)
13413 +       {
13414 +         fprintf(stderr, "failed to parse '%s'\n", day_tests[i].input);
13415 +         result = 1;
13416 +       }
13417 +      else if (*pres != '\0')
13418         {
13419           printf ("not all of `%s' read\n", tm_tests[i].input);
13420           result = 1;
13421 @@ -118,6 +127,7 @@
13422  
13423    for (i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i)
13424      {
13425 +      char *pres;
13426        memset (&tm, '\0', sizeof (tm));
13427  
13428        if (setlocale (LC_ALL, day_tests[i].locale) == NULL)
13429 @@ -125,7 +135,14 @@
13430           printf ("cannot set locale %s: %m\n", day_tests[i].locale);
13431         }
13432  
13433 -      if (*strptime (day_tests[i].input, day_tests[i].format, &tm) != '\0')
13434 +      pres = strptime (day_tests[i].input, day_tests[i].format, &tm);
13435 +      if (!pres)
13436 +       {
13437 +         fprintf(stderr, "failed to parse '%s' for locale '%s'\n",
13438 +                 day_tests[i].input, day_tests[i].locale);
13439 +         result = 1;
13440 +       }
13441 +      else if (*pres != '\0')
13442         {
13443           printf ("not all of `%s' read\n", day_tests[i].input);
13444           result = 1;
13445 diff -urN -x .git dietlibc-0.33/test/unaligned.c dietlibc/test/unaligned.c
13446 --- dietlibc-0.33/test/unaligned.c      1970-01-01 00:00:00.000000000 +0000
13447 +++ dietlibc/test/unaligned.c   2015-01-01 12:14:43.538272226 +0000
13448 @@ -0,0 +1,53 @@
13449 +#include "../dietunaligned.h"
13450 +#include <assert.h>
13451 +#include <string.h>
13452 +#include <stdlib.h>
13453 +
13454 +struct unaligned0 {
13455 +       uint8_t         u8;
13456 +       uint16_t        u16;
13457 +       uint32_t        u32;
13458 +       uint64_t        u64;
13459 +};
13460 +
13461 +int main()
13462 +{
13463 +       struct unaligned0       data0 = {
13464 +               .u8 = 8,
13465 +               .u16 = 16,
13466 +               .u32 = 32,
13467 +               .u64 = 64
13468 +       };
13469 +       struct unaligned0       data1;
13470 +
13471 +       unsigned char           *buf0 = malloc(sizeof data0 + 1);
13472 +       unsigned char           *buf1 = malloc(sizeof data0 + 1);
13473 +
13474 +       assert(buf0 != NULL);
13475 +       assert(buf1 != NULL);
13476 +
13477 +       memcpy(buf0+1, &data0, sizeof data0);
13478 +
13479 +       assert(read_unaligned_s(buf0+1, struct unaligned0, u8)  == data0.u8);
13480 +       assert(read_unaligned_s(buf0+1, struct unaligned0, u16) == data0.u16);
13481 +       assert(read_unaligned_s(buf0+1, struct unaligned0, u32) == data0.u32);
13482 +       assert(read_unaligned_s(buf0+1, struct unaligned0, u64) == data0.u64);
13483 +
13484 +
13485 +       memset(buf1, 0, sizeof data0 + 1);
13486 +       write_unaligned_s(data0.u8,  buf1+1, struct unaligned0, u8);
13487 +       write_unaligned_s(data0.u16, buf1+1, struct unaligned0, u16);
13488 +       write_unaligned_s(data0.u32, buf1+1, struct unaligned0, u32);
13489 +       write_unaligned_s(data0.u64, buf1+1, struct unaligned0, u64);
13490 +
13491 +       memcpy(&data1, buf1+1, sizeof data1);
13492 +       assert(data0.u8  == data1.u8);
13493 +       assert(data0.u16 == data1.u16);
13494 +       assert(data0.u32 == data1.u32);
13495 +       assert(data0.u64 == data1.u64);
13496 +
13497 +       free(buf1);
13498 +       free(buf0);
13499 +
13500 +       return 0;
13501 +}
13502 diff -urN -x .git dietlibc-0.33/test/waitpid.c dietlibc/test/waitpid.c
13503 --- dietlibc-0.33/test/waitpid.c        2003-12-15 13:07:42.000000000 +0000
13504 +++ dietlibc/test/waitpid.c     2015-01-01 12:14:43.538272226 +0000
13505 @@ -11,7 +11,7 @@
13506      perror("fork");
13507      _exit(1);
13508    case 0:
13509 -    fprintf(stderr,"child, my pid is %u\n",getpid());
13510 +    fprintf(stdout,"child, my pid is %u\n",getpid());
13511      sleep(1);
13512      _exit(23);
13513    }
13514 diff -urN -x .git dietlibc-0.33/x32/Makefile.add dietlibc/x32/Makefile.add
13515 --- dietlibc-0.33/x32/Makefile.add      1970-01-01 00:00:00.000000000 +0000
13516 +++ dietlibc/x32/Makefile.add   2015-01-01 12:14:43.538272226 +0000
13517 @@ -0,0 +1,3 @@
13518 +CFLAGS := -Os -fstrict-aliasing -momit-leaf-frame-pointer -mfancy-math-387
13519 +VPATH  := x32:x86_64:syscalls.s:$(VPATH)
13520 +LIBOBJ += $(OBJDIR)/arch_prctl.o $(OBJDIR)/__CAS.o
13521 diff -urN -x .git dietlibc-0.33/x32/start.S dietlibc/x32/start.S
13522 --- dietlibc-0.33/x32/start.S   1970-01-01 00:00:00.000000000 +0000
13523 +++ dietlibc/x32/start.S        2015-01-01 12:14:43.538272226 +0000
13524 @@ -0,0 +1,71 @@
13525 +#include "dietfeatures.h"
13526 +
13527 +.text
13528 +.global _start
13529 +_start:
13530 +#ifdef WANT_DYNAMIC
13531 +       movq    %rdx, %rcx              /* %rcx = dynamic fini */
13532 +#endif
13533 +       movl    (%esp), %edi            /* %edi = argc */
13534 +       lea     4(%esp), %esi           /* %esi = argv */
13535 +       
13536 +       leaq    4(%rsi,%rdi,4),%rdx     /* %edx = envp = (4*edi)+%esi+4 */
13537 +
13538 +#ifdef WANT_ELFINFO
13539 +       /* untested !! */
13540 +
13541 +#ifdef __DYN_LIB
13542 +       movl    environ@GOTPCREL(%rip), %eax
13543 +#else
13544 +       leal    environ(%rip), %eax
13545 +#endif
13546 +       movl    %edx, (%eax)    /* environ */
13547 +
13548 +1:     add     $4, %edx        /* incorment envp */
13549 +       cmpl    $0, -4(%edx)    /* load envp[-1] */
13550 +       jne     1b              /* ... until envp[-1]==NULL */
13551 +
13552 +       movl    %edx, 4(%eax)   /* __elfinfo */
13553 +#else  /* WANT_ELFINFO */
13554 +#ifdef __DYN_LIB
13555 +       movl    environ@GOTPCREL(%rip), %eax
13556 +       movl    %edx, (%eax)
13557 +#else
13558 +       movl    %edx, environ(%rip)
13559 +#endif
13560 +#endif /* WANT_ELFINFO */
13561 +
13562 +#ifdef PROFILING
13563 +       pushl   %edi                    /* save reg args */
13564 +       pushl   %esi
13565 +       pushl   %edx
13566 +       pushl   %ecx
13567 +
13568 +       leal    _etext(%eip), %esi      /* highpc */
13569 +       leal     .text(%eip), %edi      /* lowpc */
13570 +       call    monitor
13571 +
13572 +       popl    %ecx                    /* restore reg args */
13573 +       popl    %edx
13574 +       popl    %esi
13575 +       popl    %edi
13576 +#endif
13577 +
13578 +#ifdef WANT_DYNAMIC
13579 +       call    _dyn_start
13580 +#else
13581 +       call    CALL_IN_STARTCODE
13582 +#endif
13583 +
13584 +#ifdef PROFILING
13585 +       pushl   %eax
13586 +       call    _stop_monitor
13587 +       popl    %edi
13588 +#else
13589 +       movl    %eax, %edi      /* return value */
13590 +#endif
13591 +       call    exit
13592 +       hlt
13593 +.Lstart:
13594 +       .size    _start,.Lstart-_start
13595 +
13596 diff -urN -x .git dietlibc-0.33/x32/syscalls.h dietlibc/x32/syscalls.h
13597 --- dietlibc-0.33/x32/syscalls.h        1970-01-01 00:00:00.000000000 +0000
13598 +++ dietlibc/x32/syscalls.h     2015-01-01 12:14:43.538272226 +0000
13599 @@ -0,0 +1,375 @@
13600 +/* the x32 syscall bit is 0x40000000 but we handle that inside our
13601 + * unified syscall, not here, so we can have a tiny optimization for
13602 + * small syscall numbers. We still leave the #define in so we can cut
13603 + * and paste from
13604 + * /usr/src/linux/arch/x86/include/generated/uapi/asm/unistd_x32.h */
13605 +#define __X32_SYSCALL_BIT 0
13606 +
13607 +#define __NR_read (__X32_SYSCALL_BIT + 0)
13608 +#define __NR_write (__X32_SYSCALL_BIT + 1)
13609 +#define __NR_open (__X32_SYSCALL_BIT + 2)
13610 +#define __NR_close (__X32_SYSCALL_BIT + 3)
13611 +#define __NR_stat (__X32_SYSCALL_BIT + 4)
13612 +#define __NR_fstat (__X32_SYSCALL_BIT + 5)
13613 +#define __NR_lstat (__X32_SYSCALL_BIT + 6)
13614 +#define __NR_poll (__X32_SYSCALL_BIT + 7)
13615 +#define __NR_lseek (__X32_SYSCALL_BIT + 8)
13616 +#define __NR_mmap (__X32_SYSCALL_BIT + 9)
13617 +#define __NR_mprotect (__X32_SYSCALL_BIT + 10)
13618 +#define __NR_munmap (__X32_SYSCALL_BIT + 11)
13619 +#define __NR_brk (__X32_SYSCALL_BIT + 12)
13620 +#define __NR_rt_sigprocmask (__X32_SYSCALL_BIT + 14)
13621 +#define __NR_pread64 (__X32_SYSCALL_BIT + 17)
13622 +#define __NR_pwrite64 (__X32_SYSCALL_BIT + 18)
13623 +#define __NR_access (__X32_SYSCALL_BIT + 21)
13624 +#define __NR_pipe (__X32_SYSCALL_BIT + 22)
13625 +#define __NR_select (__X32_SYSCALL_BIT + 23)
13626 +#define __NR_sched_yield (__X32_SYSCALL_BIT + 24)
13627 +#define __NR_mremap (__X32_SYSCALL_BIT + 25)
13628 +#define __NR_msync (__X32_SYSCALL_BIT + 26)
13629 +#define __NR_mincore (__X32_SYSCALL_BIT + 27)
13630 +#define __NR_madvise (__X32_SYSCALL_BIT + 28)
13631 +#define __NR_shmget (__X32_SYSCALL_BIT + 29)
13632 +#define __NR_shmat (__X32_SYSCALL_BIT + 30)
13633 +#define __NR_shmctl (__X32_SYSCALL_BIT + 31)
13634 +#define __NR_dup (__X32_SYSCALL_BIT + 32)
13635 +#define __NR_dup2 (__X32_SYSCALL_BIT + 33)
13636 +#define __NR_pause (__X32_SYSCALL_BIT + 34)
13637 +#define __NR_nanosleep (__X32_SYSCALL_BIT + 35)
13638 +#define __NR_getitimer (__X32_SYSCALL_BIT + 36)
13639 +#define __NR_alarm (__X32_SYSCALL_BIT + 37)
13640 +#define __NR_setitimer (__X32_SYSCALL_BIT + 38)
13641 +#define __NR_getpid (__X32_SYSCALL_BIT + 39)
13642 +#define __NR_sendfile (__X32_SYSCALL_BIT + 40)
13643 +#define __NR_socket (__X32_SYSCALL_BIT + 41)
13644 +#define __NR_connect (__X32_SYSCALL_BIT + 42)
13645 +#define __NR_accept (__X32_SYSCALL_BIT + 43)
13646 +#define __NR_sendto (__X32_SYSCALL_BIT + 44)
13647 +#define __NR_shutdown (__X32_SYSCALL_BIT + 48)
13648 +#define __NR_bind (__X32_SYSCALL_BIT + 49)
13649 +#define __NR_listen (__X32_SYSCALL_BIT + 50)
13650 +#define __NR_getsockname (__X32_SYSCALL_BIT + 51)
13651 +#define __NR_getpeername (__X32_SYSCALL_BIT + 52)
13652 +#define __NR_socketpair (__X32_SYSCALL_BIT + 53)
13653 +#define __NR_clone (__X32_SYSCALL_BIT + 56)
13654 +#define __NR_fork (__X32_SYSCALL_BIT + 57)
13655 +#define __NR_vfork (__X32_SYSCALL_BIT + 58)
13656 +#define __NR_exit (__X32_SYSCALL_BIT + 60)
13657 +#define __NR_wait4 (__X32_SYSCALL_BIT + 61)
13658 +#define __NR_kill (__X32_SYSCALL_BIT + 62)
13659 +#define __NR_uname (__X32_SYSCALL_BIT + 63)
13660 +#define __NR_semget (__X32_SYSCALL_BIT + 64)
13661 +#define __NR_semop (__X32_SYSCALL_BIT + 65)
13662 +#define __NR_semctl (__X32_SYSCALL_BIT + 66)
13663 +#define __NR_shmdt (__X32_SYSCALL_BIT + 67)
13664 +#define __NR_msgget (__X32_SYSCALL_BIT + 68)
13665 +#define __NR_msgsnd (__X32_SYSCALL_BIT + 69)
13666 +#define __NR_msgrcv (__X32_SYSCALL_BIT + 70)
13667 +#define __NR_msgctl (__X32_SYSCALL_BIT + 71)
13668 +#define __NR_fcntl (__X32_SYSCALL_BIT + 72)
13669 +#define __NR_flock (__X32_SYSCALL_BIT + 73)
13670 +#define __NR_fsync (__X32_SYSCALL_BIT + 74)
13671 +#define __NR_fdatasync (__X32_SYSCALL_BIT + 75)
13672 +#define __NR_truncate (__X32_SYSCALL_BIT + 76)
13673 +#define __NR_ftruncate (__X32_SYSCALL_BIT + 77)
13674 +#define __NR_getdents (__X32_SYSCALL_BIT + 78)
13675 +#define __NR_getcwd (__X32_SYSCALL_BIT + 79)
13676 +#define __NR_chdir (__X32_SYSCALL_BIT + 80)
13677 +#define __NR_fchdir (__X32_SYSCALL_BIT + 81)
13678 +#define __NR_rename (__X32_SYSCALL_BIT + 82)
13679 +#define __NR_mkdir (__X32_SYSCALL_BIT + 83)
13680 +#define __NR_rmdir (__X32_SYSCALL_BIT + 84)
13681 +#define __NR_creat (__X32_SYSCALL_BIT + 85)
13682 +#define __NR_link (__X32_SYSCALL_BIT + 86)
13683 +#define __NR_unlink (__X32_SYSCALL_BIT + 87)
13684 +#define __NR_symlink (__X32_SYSCALL_BIT + 88)
13685 +#define __NR_readlink (__X32_SYSCALL_BIT + 89)
13686 +#define __NR_chmod (__X32_SYSCALL_BIT + 90)
13687 +#define __NR_fchmod (__X32_SYSCALL_BIT + 91)
13688 +#define __NR_chown (__X32_SYSCALL_BIT + 92)
13689 +#define __NR_fchown (__X32_SYSCALL_BIT + 93)
13690 +#define __NR_lchown (__X32_SYSCALL_BIT + 94)
13691 +#define __NR_umask (__X32_SYSCALL_BIT + 95)
13692 +#define __NR_gettimeofday (__X32_SYSCALL_BIT + 96)
13693 +#define __NR_getrlimit (__X32_SYSCALL_BIT + 97)
13694 +#define __NR_getrusage (__X32_SYSCALL_BIT + 98)
13695 +#define __NR_sysinfo (__X32_SYSCALL_BIT + 99)
13696 +#define __NR_times (__X32_SYSCALL_BIT + 100)
13697 +#define __NR_getuid (__X32_SYSCALL_BIT + 102)
13698 +#define __NR_syslog (__X32_SYSCALL_BIT + 103)
13699 +#define __NR_getgid (__X32_SYSCALL_BIT + 104)
13700 +#define __NR_setuid (__X32_SYSCALL_BIT + 105)
13701 +#define __NR_setgid (__X32_SYSCALL_BIT + 106)
13702 +#define __NR_geteuid (__X32_SYSCALL_BIT + 107)
13703 +#define __NR_getegid (__X32_SYSCALL_BIT + 108)
13704 +#define __NR_setpgid (__X32_SYSCALL_BIT + 109)
13705 +#define __NR_getppid (__X32_SYSCALL_BIT + 110)
13706 +#define __NR_getpgrp (__X32_SYSCALL_BIT + 111)
13707 +#define __NR_setsid (__X32_SYSCALL_BIT + 112)
13708 +#define __NR_setreuid (__X32_SYSCALL_BIT + 113)
13709 +#define __NR_setregid (__X32_SYSCALL_BIT + 114)
13710 +#define __NR_getgroups (__X32_SYSCALL_BIT + 115)
13711 +#define __NR_setgroups (__X32_SYSCALL_BIT + 116)
13712 +#define __NR_setresuid (__X32_SYSCALL_BIT + 117)
13713 +#define __NR_getresuid (__X32_SYSCALL_BIT + 118)
13714 +#define __NR_setresgid (__X32_SYSCALL_BIT + 119)
13715 +#define __NR_getresgid (__X32_SYSCALL_BIT + 120)
13716 +#define __NR_getpgid (__X32_SYSCALL_BIT + 121)
13717 +#define __NR_setfsuid (__X32_SYSCALL_BIT + 122)
13718 +#define __NR_setfsgid (__X32_SYSCALL_BIT + 123)
13719 +#define __NR_getsid (__X32_SYSCALL_BIT + 124)
13720 +#define __NR_capget (__X32_SYSCALL_BIT + 125)
13721 +#define __NR_capset (__X32_SYSCALL_BIT + 126)
13722 +#define __NR_rt_sigsuspend (__X32_SYSCALL_BIT + 130)
13723 +#define __NR_utime (__X32_SYSCALL_BIT + 132)
13724 +#define __NR_mknod (__X32_SYSCALL_BIT + 133)
13725 +#define __NR_personality (__X32_SYSCALL_BIT + 135)
13726 +#define __NR_ustat (__X32_SYSCALL_BIT + 136)
13727 +#define __NR_statfs (__X32_SYSCALL_BIT + 137)
13728 +#define __NR_fstatfs (__X32_SYSCALL_BIT + 138)
13729 +#define __NR_sysfs (__X32_SYSCALL_BIT + 139)
13730 +#define __NR_getpriority (__X32_SYSCALL_BIT + 140)
13731 +#define __NR_setpriority (__X32_SYSCALL_BIT + 141)
13732 +#define __NR_sched_setparam (__X32_SYSCALL_BIT + 142)
13733 +#define __NR_sched_getparam (__X32_SYSCALL_BIT + 143)
13734 +#define __NR_sched_setscheduler (__X32_SYSCALL_BIT + 144)
13735 +#define __NR_sched_getscheduler (__X32_SYSCALL_BIT + 145)
13736 +#define __NR_sched_get_priority_max (__X32_SYSCALL_BIT + 146)
13737 +#define __NR_sched_get_priority_min (__X32_SYSCALL_BIT + 147)
13738 +#define __NR_sched_rr_get_interval (__X32_SYSCALL_BIT + 148)
13739 +#define __NR_mlock (__X32_SYSCALL_BIT + 149)
13740 +#define __NR_munlock (__X32_SYSCALL_BIT + 150)
13741 +#define __NR_mlockall (__X32_SYSCALL_BIT + 151)
13742 +#define __NR_munlockall (__X32_SYSCALL_BIT + 152)
13743 +#define __NR_vhangup (__X32_SYSCALL_BIT + 153)
13744 +#define __NR_modify_ldt (__X32_SYSCALL_BIT + 154)
13745 +#define __NR_pivot_root (__X32_SYSCALL_BIT + 155)
13746 +#define __NR_prctl (__X32_SYSCALL_BIT + 157)
13747 +#define __NR_arch_prctl (__X32_SYSCALL_BIT + 158)
13748 +#define __NR_adjtimex (__X32_SYSCALL_BIT + 159)
13749 +#define __NR_setrlimit (__X32_SYSCALL_BIT + 160)
13750 +#define __NR_chroot (__X32_SYSCALL_BIT + 161)
13751 +#define __NR_sync (__X32_SYSCALL_BIT + 162)
13752 +#define __NR_acct (__X32_SYSCALL_BIT + 163)
13753 +#define __NR_settimeofday (__X32_SYSCALL_BIT + 164)
13754 +#define __NR_mount (__X32_SYSCALL_BIT + 165)
13755 +#define __NR_umount2 (__X32_SYSCALL_BIT + 166)
13756 +#define __NR_swapon (__X32_SYSCALL_BIT + 167)
13757 +#define __NR_swapoff (__X32_SYSCALL_BIT + 168)
13758 +#define __NR_reboot (__X32_SYSCALL_BIT + 169)
13759 +#define __NR_sethostname (__X32_SYSCALL_BIT + 170)
13760 +#define __NR_setdomainname (__X32_SYSCALL_BIT + 171)
13761 +#define __NR_iopl (__X32_SYSCALL_BIT + 172)
13762 +#define __NR_ioperm (__X32_SYSCALL_BIT + 173)
13763 +#define __NR_init_module (__X32_SYSCALL_BIT + 175)
13764 +#define __NR_delete_module (__X32_SYSCALL_BIT + 176)
13765 +#define __NR_quotactl (__X32_SYSCALL_BIT + 179)
13766 +#define __NR_getpmsg (__X32_SYSCALL_BIT + 181)
13767 +#define __NR_putpmsg (__X32_SYSCALL_BIT + 182)
13768 +#define __NR_afs_syscall (__X32_SYSCALL_BIT + 183)
13769 +#define __NR_tuxcall (__X32_SYSCALL_BIT + 184)
13770 +#define __NR_security (__X32_SYSCALL_BIT + 185)
13771 +#define __NR_gettid (__X32_SYSCALL_BIT + 186)
13772 +#define __NR_readahead (__X32_SYSCALL_BIT + 187)
13773 +#define __NR_setxattr (__X32_SYSCALL_BIT + 188)
13774 +#define __NR_lsetxattr (__X32_SYSCALL_BIT + 189)
13775 +#define __NR_fsetxattr (__X32_SYSCALL_BIT + 190)
13776 +#define __NR_getxattr (__X32_SYSCALL_BIT + 191)
13777 +#define __NR_lgetxattr (__X32_SYSCALL_BIT + 192)
13778 +#define __NR_fgetxattr (__X32_SYSCALL_BIT + 193)
13779 +#define __NR_listxattr (__X32_SYSCALL_BIT + 194)
13780 +#define __NR_llistxattr (__X32_SYSCALL_BIT + 195)
13781 +#define __NR_flistxattr (__X32_SYSCALL_BIT + 196)
13782 +#define __NR_removexattr (__X32_SYSCALL_BIT + 197)
13783 +#define __NR_lremovexattr (__X32_SYSCALL_BIT + 198)
13784 +#define __NR_fremovexattr (__X32_SYSCALL_BIT + 199)
13785 +#define __NR_tkill (__X32_SYSCALL_BIT + 200)
13786 +#define __NR_time (__X32_SYSCALL_BIT + 201)
13787 +#define __NR_futex (__X32_SYSCALL_BIT + 202)
13788 +#define __NR_sched_setaffinity (__X32_SYSCALL_BIT + 203)
13789 +#define __NR_sched_getaffinity (__X32_SYSCALL_BIT + 204)
13790 +#define __NR_io_destroy (__X32_SYSCALL_BIT + 207)
13791 +#define __NR_io_getevents (__X32_SYSCALL_BIT + 208)
13792 +#define __NR_io_cancel (__X32_SYSCALL_BIT + 210)
13793 +#define __NR_lookup_dcookie (__X32_SYSCALL_BIT + 212)
13794 +#define __NR_epoll_create (__X32_SYSCALL_BIT + 213)
13795 +#define __NR_remap_file_pages (__X32_SYSCALL_BIT + 216)
13796 +#define __NR_getdents64 (__X32_SYSCALL_BIT + 217)
13797 +#define __NR_set_tid_address (__X32_SYSCALL_BIT + 218)
13798 +#define __NR_restart_syscall (__X32_SYSCALL_BIT + 219)
13799 +#define __NR_semtimedop (__X32_SYSCALL_BIT + 220)
13800 +#define __NR_fadvise64 (__X32_SYSCALL_BIT + 221)
13801 +#define __NR_timer_settime (__X32_SYSCALL_BIT + 223)
13802 +#define __NR_timer_gettime (__X32_SYSCALL_BIT + 224)
13803 +#define __NR_timer_getoverrun (__X32_SYSCALL_BIT + 225)
13804 +#define __NR_timer_delete (__X32_SYSCALL_BIT + 226)
13805 +#define __NR_clock_settime (__X32_SYSCALL_BIT + 227)
13806 +#define __NR_clock_gettime (__X32_SYSCALL_BIT + 228)
13807 +#define __NR_clock_getres (__X32_SYSCALL_BIT + 229)
13808 +#define __NR_clock_nanosleep (__X32_SYSCALL_BIT + 230)
13809 +#define __NR_exit_group (__X32_SYSCALL_BIT + 231)
13810 +#define __NR_epoll_wait (__X32_SYSCALL_BIT + 232)
13811 +#define __NR_epoll_ctl (__X32_SYSCALL_BIT + 233)
13812 +#define __NR_tgkill (__X32_SYSCALL_BIT + 234)
13813 +#define __NR_utimes (__X32_SYSCALL_BIT + 235)
13814 +#define __NR_mbind (__X32_SYSCALL_BIT + 237)
13815 +#define __NR_set_mempolicy (__X32_SYSCALL_BIT + 238)
13816 +#define __NR_get_mempolicy (__X32_SYSCALL_BIT + 239)
13817 +#define __NR_mq_open (__X32_SYSCALL_BIT + 240)
13818 +#define __NR_mq_unlink (__X32_SYSCALL_BIT + 241)
13819 +#define __NR_mq_timedsend (__X32_SYSCALL_BIT + 242)
13820 +#define __NR_mq_timedreceive (__X32_SYSCALL_BIT + 243)
13821 +#define __NR_mq_getsetattr (__X32_SYSCALL_BIT + 245)
13822 +#define __NR_add_key (__X32_SYSCALL_BIT + 248)
13823 +#define __NR_request_key (__X32_SYSCALL_BIT + 249)
13824 +#define __NR_keyctl (__X32_SYSCALL_BIT + 250)
13825 +#define __NR_ioprio_set (__X32_SYSCALL_BIT + 251)
13826 +#define __NR_ioprio_get (__X32_SYSCALL_BIT + 252)
13827 +#define __NR_inotify_init (__X32_SYSCALL_BIT + 253)
13828 +#define __NR_inotify_add_watch (__X32_SYSCALL_BIT + 254)
13829 +#define __NR_inotify_rm_watch (__X32_SYSCALL_BIT + 255)
13830 +#define __NR_migrate_pages (__X32_SYSCALL_BIT + 256)
13831 +#define __NR_openat (__X32_SYSCALL_BIT + 257)
13832 +#define __NR_mkdirat (__X32_SYSCALL_BIT + 258)
13833 +#define __NR_mknodat (__X32_SYSCALL_BIT + 259)
13834 +#define __NR_fchownat (__X32_SYSCALL_BIT + 260)
13835 +#define __NR_futimesat (__X32_SYSCALL_BIT + 261)
13836 +#define __NR_newfstatat (__X32_SYSCALL_BIT + 262)
13837 +#define __NR_unlinkat (__X32_SYSCALL_BIT + 263)
13838 +#define __NR_renameat (__X32_SYSCALL_BIT + 264)
13839 +#define __NR_linkat (__X32_SYSCALL_BIT + 265)
13840 +#define __NR_symlinkat (__X32_SYSCALL_BIT + 266)
13841 +#define __NR_readlinkat (__X32_SYSCALL_BIT + 267)
13842 +#define __NR_fchmodat (__X32_SYSCALL_BIT + 268)
13843 +#define __NR_faccessat (__X32_SYSCALL_BIT + 269)
13844 +#define __NR_pselect6 (__X32_SYSCALL_BIT + 270)
13845 +#define __NR_ppoll (__X32_SYSCALL_BIT + 271)
13846 +#define __NR_unshare (__X32_SYSCALL_BIT + 272)
13847 +#define __NR_splice (__X32_SYSCALL_BIT + 275)
13848 +#define __NR_tee (__X32_SYSCALL_BIT + 276)
13849 +#define __NR_sync_file_range (__X32_SYSCALL_BIT + 277)
13850 +#define __NR_utimensat (__X32_SYSCALL_BIT + 280)
13851 +#define __NR_epoll_pwait (__X32_SYSCALL_BIT + 281)
13852 +#define __NR_signalfd (__X32_SYSCALL_BIT + 282)
13853 +#define __NR_timerfd_create (__X32_SYSCALL_BIT + 283)
13854 +#define __NR_eventfd (__X32_SYSCALL_BIT + 284)
13855 +#define __NR_fallocate (__X32_SYSCALL_BIT + 285)
13856 +#define __NR_timerfd_settime (__X32_SYSCALL_BIT + 286)
13857 +#define __NR_timerfd_gettime (__X32_SYSCALL_BIT + 287)
13858 +#define __NR_accept4 (__X32_SYSCALL_BIT + 288)
13859 +#define __NR_signalfd4 (__X32_SYSCALL_BIT + 289)
13860 +#define __NR_eventfd2 (__X32_SYSCALL_BIT + 290)
13861 +#define __NR_epoll_create1 (__X32_SYSCALL_BIT + 291)
13862 +#define __NR_dup3 (__X32_SYSCALL_BIT + 292)
13863 +#define __NR_pipe2 (__X32_SYSCALL_BIT + 293)
13864 +#define __NR_inotify_init1 (__X32_SYSCALL_BIT + 294)
13865 +#define __NR_perf_event_open (__X32_SYSCALL_BIT + 298)
13866 +#define __NR_fanotify_init (__X32_SYSCALL_BIT + 300)
13867 +#define __NR_fanotify_mark (__X32_SYSCALL_BIT + 301)
13868 +#define __NR_prlimit64 (__X32_SYSCALL_BIT + 302)
13869 +#define __NR_name_to_handle_at (__X32_SYSCALL_BIT + 303)
13870 +#define __NR_open_by_handle_at (__X32_SYSCALL_BIT + 304)
13871 +#define __NR_clock_adjtime (__X32_SYSCALL_BIT + 305)
13872 +#define __NR_syncfs (__X32_SYSCALL_BIT + 306)
13873 +#define __NR_setns (__X32_SYSCALL_BIT + 308)
13874 +#define __NR_getcpu (__X32_SYSCALL_BIT + 309)
13875 +#define __NR_kcmp (__X32_SYSCALL_BIT + 312)
13876 +#define __NR_finit_module (__X32_SYSCALL_BIT + 313)
13877 +#define __NR_sched_setattr (__X32_SYSCALL_BIT + 314)
13878 +#define __NR_sched_getattr (__X32_SYSCALL_BIT + 315)
13879 +#define __NR_renameat2 (__X32_SYSCALL_BIT + 316)
13880 +#define __NR_seccomp (__X32_SYSCALL_BIT + 317)
13881 +#define __NR_getrandom (__X32_SYSCALL_BIT + 318)
13882 +#define __NR_memfd_create (__X32_SYSCALL_BIT + 319)
13883 +#define __NR_kexec_file_load (__X32_SYSCALL_BIT + 320)
13884 +
13885 +#define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
13886 +#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
13887 +#define __NR_ioctl (__X32_SYSCALL_BIT + 514)
13888 +#define __NR_readv (__X32_SYSCALL_BIT + 515)
13889 +#define __NR_writev (__X32_SYSCALL_BIT + 516)
13890 +#define __NR_recvfrom (__X32_SYSCALL_BIT + 517)
13891 +#define __NR_sendmsg (__X32_SYSCALL_BIT + 518)
13892 +#define __NR_recvmsg (__X32_SYSCALL_BIT + 519)
13893 +#define __NR_execve (__X32_SYSCALL_BIT + 520)
13894 +#define __NR_ptrace (__X32_SYSCALL_BIT + 521)
13895 +#define __NR_rt_sigpending (__X32_SYSCALL_BIT + 522)
13896 +#define __NR_rt_sigtimedwait (__X32_SYSCALL_BIT + 523)
13897 +#define __NR_rt_sigqueueinfo (__X32_SYSCALL_BIT + 524)
13898 +#define __NR_sigaltstack (__X32_SYSCALL_BIT + 525)
13899 +#define __NR_timer_create (__X32_SYSCALL_BIT + 526)
13900 +#define __NR_mq_notify (__X32_SYSCALL_BIT + 527)
13901 +#define __NR_kexec_load (__X32_SYSCALL_BIT + 528)
13902 +#define __NR_waitid (__X32_SYSCALL_BIT + 529)
13903 +#define __NR_set_robust_list (__X32_SYSCALL_BIT + 530)
13904 +#define __NR_get_robust_list (__X32_SYSCALL_BIT + 531)
13905 +#define __NR_vmsplice (__X32_SYSCALL_BIT + 532)
13906 +#define __NR_move_pages (__X32_SYSCALL_BIT + 533)
13907 +#define __NR_preadv (__X32_SYSCALL_BIT + 534)
13908 +#define __NR_pwritev (__X32_SYSCALL_BIT + 535)
13909 +#define __NR_rt_tgsigqueueinfo (__X32_SYSCALL_BIT + 536)
13910 +#define __NR_recvmmsg (__X32_SYSCALL_BIT + 537)
13911 +#define __NR_sendmmsg (__X32_SYSCALL_BIT + 538)
13912 +#define __NR_process_vm_readv (__X32_SYSCALL_BIT + 539)
13913 +#define __NR_process_vm_writev (__X32_SYSCALL_BIT + 540)
13914 +#define __NR_setsockopt (__X32_SYSCALL_BIT + 541)
13915 +#define __NR_getsockopt (__X32_SYSCALL_BIT + 542)
13916 +#define __NR_io_setup (__X32_SYSCALL_BIT + 543)
13917 +#define __NR_io_submit (__X32_SYSCALL_BIT + 544)
13918 +
13919 +#ifdef __PIC__
13920 +#define syscall_weak(name,wsym,sym) \
13921 +.text; \
13922 +.type wsym,@function; \
13923 +.weak wsym; \
13924 +wsym: ; \
13925 +.type sym,@function; \
13926 +.global sym; \
13927 +sym: \
13928 +       mov     $__NR_##name,%al; \
13929 +       jmp     __unified_syscall@PLT
13930 +
13931 +#define syscall(name,sym) \
13932 +.text; \
13933 +.type sym,@function; \
13934 +.global sym; \
13935 +sym: \
13936 +.ifge __NR_##name-256 ; \
13937 +       mov     $__NR_##name,%ax; \
13938 +       jmp     __unified_syscall_16bit@PLT;  \
13939 +.else ; \
13940 +       mov     $__NR_##name,%al; \
13941 +       jmp     __unified_syscall@PLT;  \
13942 +.endif
13943 +
13944 +#else
13945 +
13946 +#define syscall_weak(name,wsym,sym) \
13947 +.text; \
13948 +.type wsym,@function; \
13949 +.weak wsym; \
13950 +wsym: ; \
13951 +.type sym,@function; \
13952 +.global sym; \
13953 +sym: \
13954 +.ifge __NR_##name-256 ; \
13955 +       mov     $__NR_##name,%ax; \
13956 +       jmp     __unified_syscall_16bit;  \
13957 +.else ; \
13958 +       mov     $__NR_##name,%al; \
13959 +       jmp     __unified_syscall;  \
13960 +.endif
13961 +
13962 +#define syscall(name,sym) \
13963 +.text; \
13964 +.type sym,@function; \
13965 +.global sym; \
13966 +sym: \
13967 +.ifge __NR_##name-256 ; \
13968 +       mov     $__NR_##name,%ax; \
13969 +       jmp     __unified_syscall_16bit; \
13970 +.else ; \
13971 +       mov     $__NR_##name,%al; \
13972 +       jmp     __unified_syscall; \
13973 +.endif
13974 +#endif
13975 diff -urN -x .git dietlibc-0.33/x86_64/clone.S dietlibc/x86_64/clone.S
13976 --- dietlibc-0.33/x86_64/clone.S        2005-01-31 12:53:34.000000000 +0000
13977 +++ dietlibc/x86_64/clone.S     2015-01-01 12:14:43.541605560 +0000
13978 @@ -20,8 +20,52 @@
13979         movq    %rcx,8(%rsi)    /* thread parameter */
13980         movq    %rdi,0(%rsi)    /* thread function */
13981  
13982 -       /* syscall */
13983 +       /* args to this function:               args to syscall
13984 +          ----------------------------------------------------
13985 +          rdi = function to be called          rdi = flags
13986 +          rsi = child_stack                    rsi = child_stack
13987 +          rdx = flags                          rdx = ptid
13988 +          rcx = arg                            r10 = ctid
13989 +          r8 = ptid                            r8 = regs
13990 +          r9 = tls
13991 +          stack = ctid */
13992 +
13993         movq    %rdx,%rdi
13994 +       /* if CLONE_PARENT_SETTID is set, r8 goes into rdx */
13995 +       test $0x100000,%rdi
13996 +       jz .Lnocps
13997 +       movq    %r8,%rdx
13998 +       /* if CLONE_SETTLS is set, r9 goes into r8 */
13999 +       test $0x80000,%rdi
14000 +       jz .Lcps_notls
14001 +       movq    %r9,%r8
14002 +       /* if CLONE_CHILD_SETTID is set, stack goes into r10 */
14003 +       test $0x1000000,%rdi
14004 +       jz .Ldone
14005 +       movq    8(%rsp),%r10
14006 +       jmp .Ldone
14007 +
14008 +.Lnocps:
14009 +       /* if CLONE_SETTLS is set, r8 goes into r8 */
14010 +       test $0x80000,%rdi
14011 +       jz .Lnocps_notls
14012 +/*     movq    %r8,%r9 */
14013 +.Lcps_notls:
14014 +       /* if CLONE_CHILD_SETTID is set, r9 goes into r10 */
14015 +       test $0x1000000,%rdi
14016 +       jz .Ldone
14017 +       movq    %r9,%r10
14018 +       jmp .Ldone
14019 +
14020 +.Lnocps_notls:
14021 +       /* if CLONE_CHILD_SETTID is set, r8 goes into r10 */
14022 +       test $0x1000000,%rdi
14023 +       jz .Ldone
14024 +       movq    %r8,%r10
14025 +
14026 +.Ldone:
14027 +
14028 +       /* syscall */
14029         movl    $__NR_clone,%eax
14030         syscall
14031         cmpl    $0,%eax
14032 @@ -36,9 +80,9 @@
14033         /* exit a thread */
14034         movq    %rax,%rdi
14035  #ifdef __PIC__
14036 -       jmp     _exit@PLT
14037 +       jmp     thrd_exit@PLT
14038  #else
14039 -       jmp     _exit
14040 +       jmp     thrd_exit
14041  #endif
14042  
14043  .Lclone_error:
14044 diff -urN -x .git dietlibc-0.33/x86_64/dyn_syscalls.S dietlibc/x86_64/dyn_syscalls.S
14045 --- dietlibc-0.33/x86_64/dyn_syscalls.S 2012-01-24 18:24:30.000000000 +0000
14046 +++ dietlibc/x86_64/dyn_syscalls.S      2015-01-01 12:14:43.541605560 +0000
14047 @@ -19,7 +19,7 @@
14048  .global __unified_syscall_16bit
14049  __unified_syscall:
14050  _unified_syscall:
14051 -       mov     $0, %al
14052 +       mov     $0, %ah
14053  __unified_syscall_16bit:
14054         movzwl  %ax, %eax
14055         mov     %rcx, %r10
14056 @@ -29,7 +29,12 @@
14057         jbe     .Lnoerror
14058         negl    %eax
14059         pushq   %rax
14060 +#ifdef IN_LDSO
14061 +       call    __errno_location
14062 +       .hidden __errno_location
14063 +#else
14064         call    __errno_location@PLT
14065 +#endif
14066         popq    %rcx
14067         movl    %ecx,(%rax)
14068         orq     $-1, %rax
14069 @@ -70,7 +75,6 @@
14070  #include "../syscalls.s/epoll_create.S"
14071  #include "../syscalls.s/epoll_ctl.S"
14072  #include "../syscalls.s/epoll_wait.S"
14073 -#include "../syscalls.s/errno.S"
14074  #include "../syscalls.s/execve.S"
14075  #include "../syscalls.s/fchdir.S"
14076  #include "../syscalls.s/fchmod.S"
14077 @@ -141,7 +145,6 @@
14078  #include "../syscalls.s/n_sigprocmask.S"
14079  #include "../syscalls.s/n_sigsuspend.S"
14080  #include "../syscalls.s/nanosleep.S"
14081 -#include "../syscalls.s/nice.S"
14082  #include "../syscalls.s/open.S"
14083  #include "../syscalls.s/pause.S"
14084  #include "../syscalls.s/personality.S"
14085 @@ -331,3 +334,5 @@
14086  #include "x86_64/gettimeofday.S"
14087  
14088  #include "syscalls.s/__guard.S"
14089 +
14090 +       .section        .note.GNU-stack,"",@progbits
14091 diff -urN -x .git dietlibc-0.33/x86_64/getcontext.S dietlibc/x86_64/getcontext.S
14092 --- dietlibc-0.33/x86_64/getcontext.S   1970-01-01 00:00:00.000000000 +0000
14093 +++ dietlibc/x86_64/getcontext.S        2015-01-01 12:14:43.541605560 +0000
14094 @@ -0,0 +1,47 @@
14095 +#include "syscalls.h"
14096 +
14097 +.text
14098 +.global getcontext
14099 +.type getcontext,@function
14100 +/* store current CPU context into struct ucontext* */
14101 +getcontext:
14102 +  /* the registers are in uc_mcontext, which starts at offset 40 */
14103 +  movq %r8,40(%rdi)
14104 +  movq %r9,48(%rdi)
14105 +//  movq %r10,56(%rdi)
14106 +//  movq %r11,64(%rdi)
14107 +  movq %r12,72(%rdi)
14108 +  movq %r13,80(%rdi)
14109 +  movq %r14,88(%rdi)
14110 +  movq %r15,96(%rdi)
14111 +  movq %rdi,104(%rdi)  /* what a useless statement :-) */
14112 +  movq %rsi,112(%rdi)
14113 +  movq %rbp,120(%rdi)
14114 +  movq %rbx,128(%rdi)
14115 +  movq %rdx,136(%rdi)
14116 +  movq $0,144(%rdi)    /* store 0 as value of rax because that's the return value of the function */
14117 +  movq %rcx,152(%rdi)
14118 +  leaq 8(%rsp),%rax
14119 +  movq %rax,160(%rdi)
14120 +  movq (%rsp),%rax
14121 +  movq %rax,168(%rdi)  /* store function return address as rip */
14122 +  lahf
14123 +  movq %rax,176(%rdi)
14124 +  /* valgrind dies if we use these instructions */
14125 +//  movw %cs,184(%rdi)
14126 +//  movw %gs,186(%rdi)
14127 +//  movw %fs,188(%rdi)
14128 +  /* write nothing to err (192) and trapno (200) */
14129 +
14130 +  leaq 424(%rdi),%rax
14131 +  movq %rax,224(%rdi)
14132 +  fnstenv (%rax)
14133 +  fldenv (%rax)
14134 +  stmxcsr 448(%rdi)
14135 +
14136 +  /* now call sigprocmask(SIG_BLOCK, NULL, &uc->uc_sigmask) */
14137 +  leaq 296(%rdi),%rdx
14138 +  xorl %esi,%esi
14139 +  xorl %edi,%edi
14140 +  jmp sigprocmask
14141 +.size getcontext, .-getcontext
14142 diff -urN -x .git dietlibc-0.33/x86_64/gettimeofday.S dietlibc/x86_64/gettimeofday.S
14143 --- dietlibc-0.33/x86_64/gettimeofday.S 2012-01-24 18:24:30.000000000 +0000
14144 +++ dietlibc/x86_64/gettimeofday.S      2015-01-01 12:14:43.541605560 +0000
14145 @@ -1,7 +1,19 @@
14146 +#include "dietfeatures.h"
14147 +#include "syscalls.h"
14148 +
14149  .text
14150  .global gettimeofday
14151  .type gettimeofday,@function
14152  gettimeofday:
14153 +#ifdef WANT_VALGRIND_SUPPORT
14154 +#ifdef __PIC__
14155 +       mov __valgrind@GOTPCREL(%rip), %rax
14156 +       cmpb $1, (%rax)
14157 +#else
14158 +       cmpb $1, __valgrind(%rip)
14159 +#endif
14160 +       je .Lvalgrind
14161 +#endif
14162         movq gtod(%rip), %rax
14163         test %rax,%rax
14164         jz .L1
14165 @@ -11,13 +23,25 @@
14166  .L1:
14167         push %rsi
14168         push %rdi
14169 +#ifdef __PIC__
14170 +       movq __vdso@GOTPCREL(%rip), %rax
14171 +       movq (%rax),%rdi
14172 +       movq funcname@GOTPCREL(%rip), %rsi
14173 +       call vdso_dlsym@PLT
14174 +#else
14175         movq __vdso(%rip),%rdi
14176         movq $funcname, %rsi
14177         call vdso_dlsym
14178 +#endif
14179         pop %rdi
14180         pop %rsi
14181         jmp .L2
14182  
14183 +#ifdef WANT_VALGRIND_SUPPORT
14184 +.Lvalgrind:
14185 +       mov $__NR_gettimeofday, %al
14186 +       jmp __unified_syscall
14187 +#endif
14188  .Lhere:
14189         .size    gettimeofday,.Lhere-gettimeofday
14190  .local gtod
14191 diff -urN -x .git dietlibc-0.33/x86_64/Makefile.add dietlibc/x86_64/Makefile.add
14192 --- dietlibc-0.33/x86_64/Makefile.add   2012-01-24 18:24:30.000000000 +0000
14193 +++ dietlibc/x86_64/Makefile.add        2015-01-01 12:14:43.541605560 +0000
14194 @@ -1,3 +1,8 @@
14195 -CFLAGS := -Os -fstrict-aliasing -momit-leaf-frame-pointer -mfancy-math-387
14196 +ifeq ($(CC),clang)
14197 +CFLAGS := -Os -fstrict-aliasing -momit-leaf-frame-pointer $(EXTRACFLAGS)
14198 +else
14199 +CFLAGS := -Os -fstrict-aliasing -momit-leaf-frame-pointer -mfancy-math-387 -fPIC -fvisibility=hidden $(EXTRACFLAGS)
14200 +endif
14201  VPATH  := x86_64:syscalls.s:$(VPATH)
14202 -LIBOBJ += $(OBJDIR)/arch_prctl.o $(OBJDIR)/__CAS.o
14203 +LIBOBJ += $(OBJDIR)/arch_prctl.o $(OBJDIR)/__CAS.o $(OBJDIR)/__munmap_and_exit.o $(OBJDIR)/getcontext.o
14204 +LIBOBJ += $(OBJDIR)/setcontext.o
14205 diff -urN -x .git dietlibc-0.33/x86_64/__munmap_and_exit.S dietlibc/x86_64/__munmap_and_exit.S
14206 --- dietlibc-0.33/x86_64/__munmap_and_exit.S    1970-01-01 00:00:00.000000000 +0000
14207 +++ dietlibc/x86_64/__munmap_and_exit.S 2015-01-01 12:14:43.541605560 +0000
14208 @@ -0,0 +1,13 @@
14209 +#include "syscalls.h"
14210 +
14211 +.text
14212 +.global __munmap_and_exit
14213 +.type __munmap_and_exit,@function
14214 +__munmap_and_exit:
14215 +  mov $__NR_munmap,%eax
14216 +  syscall
14217 +  mov $__NR_exit,%eax
14218 +  xor %edi,%edi
14219 +  syscall
14220 +.Lhere:
14221 +.size __munmap_and_exit, .Lhere-__munmap_and_exit
14222 diff -urN -x .git dietlibc-0.33/x86_64/setcontext.S dietlibc/x86_64/setcontext.S
14223 --- dietlibc-0.33/x86_64/setcontext.S   1970-01-01 00:00:00.000000000 +0000
14224 +++ dietlibc/x86_64/setcontext.S        2015-01-01 12:14:43.541605560 +0000
14225 @@ -0,0 +1,56 @@
14226 +#include "syscalls.h"
14227 +
14228 +.text
14229 +
14230 +.global __setcontext_trampoline
14231 +.type __setcontext_trampoline,@function
14232 +__setcontext_trampoline:
14233 +  movq %rbx,%rdi
14234 +  /* fall through */
14235 +  .size __setcontext_trampoline, .-__setcontext_trampoline
14236 +
14237 +.global setcontext
14238 +.type setcontext,@function
14239 +/* load current CPU context from struct ucontext* */
14240 +setcontext:
14241 +  /* first restore the signal mask, call sigprocmask(SIG_SETMASK,&uc->uc_sigmask,NULL) */
14242 +  movq %rdi,%rbx
14243 +  leaq 296(%rdi),%rsi
14244 +  xorl %edx,%edx
14245 +  movl $2,%edi
14246 +  call sigprocmask
14247 +  mov %rbx,%rdi
14248 +  test %rax,%rax
14249 +  jc .Lexit
14250 +
14251 +  /* now the floating point context */
14252 +  movq 224(%rdi),%rax
14253 +  fldenv (%rax)
14254 +  ldmxcsr 448(%rdi)
14255 +
14256 +  /* the registers are in uc_mcontext, which starts at offset 40 */
14257 +  movq 40(%rdi),%r8
14258 +  movq 48(%rdi),%r9
14259 +  movq 72(%rdi),%r12
14260 +  movq 80(%rdi),%r13
14261 +  movq 88(%rdi),%r14
14262 +  movq 96(%rdi),%r15
14263 +
14264 +  movq 112(%rdi),%rsi
14265 +  movq 120(%rdi),%rbp
14266 +  movq 128(%rdi),%rbx
14267 +  movq 136(%rdi),%rdx
14268 +  movq 152(%rdi),%rcx
14269 +  movq 160(%rdi),%rsp
14270 +  pushq 168(%rdi)      /* push return value so ret goes to the right place */
14271 +
14272 +//  movw 186(%rdi),%gs
14273 +//  movw 188(%rdi),%fs
14274 +
14275 +  movq 104(%rdi),%rdi
14276 +
14277 +  xorl %eax,%eax
14278 +
14279 +.Lexit:
14280 +  ret
14281 +.size setcontext, .-setcontext
14282 diff -urN -x .git dietlibc-0.33/x86_64/start.S dietlibc/x86_64/start.S
14283 --- dietlibc-0.33/x86_64/start.S        2012-11-02 11:17:28.000000000 +0000
14284 +++ dietlibc/x86_64/start.S     2015-01-01 12:14:43.541605560 +0000
14285 @@ -12,11 +12,28 @@
14286         
14287         leaq    8(%rsi,%rdi,8),%rdx     /* %rdx = envp = (8*rdi)+%rsi+8 */
14288  
14289 +#ifndef IN_LDSO
14290 +#ifdef WANT_ELFINFO
14291 +#ifdef __DYN_LIB
14292 +       movq    environ@GOTPCREL(%rip), %rax
14293 +#else
14294 +       leaq    environ(%rip), %rax
14295 +#endif
14296 +       movq    %rdx, (%rax)    /* environ */
14297 +
14298 +1:     add     $8, %rdx        /* increment envp */
14299 +       cmpq    $0, -8(%rdx)    /* load envp[-1] */
14300 +       jne     1b              /* ... until envp[-1]==NULL */
14301 +
14302 +       movq    %rdx, 8(%rax)   /* __elfinfo */
14303 +#else
14304  #ifdef __DYN_LIB
14305         movq    environ@GOTPCREL(%rip), %rax
14306         movq    %rdx, (%rax)
14307  #else
14308         movq    %rdx, environ(%rip)
14309 +       .hidden environ
14310 +#endif
14311  #endif
14312  
14313  #ifdef PROFILING
14314 @@ -37,8 +54,10 @@
14315  
14316  #ifdef WANT_DYNAMIC
14317         call    _dyn_start
14318 +       .hidden _dyn_start
14319  #else
14320         call    CALL_IN_STARTCODE
14321 +       .hidden CALL_IN_STARTCODE
14322  #endif
14323  
14324  #ifdef PROFILING
14325 @@ -48,14 +67,22 @@
14326  #else
14327         movq    %rax, %rdi      /* return value */
14328  #endif
14329 +
14330 +#else
14331 +       call    main
14332 +       .hidden main
14333 +#endif
14334 +
14335  #if defined(__ILP32__)
14336 -       xor %rax,%rax           /* do exit inline with x64 syscall number so it also works if the kernel does not have x32 support */
14337 -       inc %rax
14338 +       mov     $SYS_exit,%eax
14339         syscall
14340  #else
14341         call    exit
14342 +#ifndef __DYN_LIB
14343 +       .hidden exit
14344 +#endif
14345  #endif
14346         hlt
14347  .Lstart:
14348         .size    _start,.Lstart-_start
14349 -
14350 +       .section        .note.GNU-stack,"",@progbits
14351 diff -urN -x .git dietlibc-0.33/x86_64/syscalls.h dietlibc/x86_64/syscalls.h
14352 --- dietlibc-0.33/x86_64/syscalls.h     2012-01-24 18:24:30.000000000 +0000
14353 +++ dietlibc/x86_64/syscalls.h  2015-01-01 12:14:43.541605560 +0000
14354 @@ -349,6 +349,24 @@
14355  #define __NR_fanotify_init     300
14356  #define __NR_fanotify_mark     301
14357  #define __NR_prlimit64         302
14358 +#define __NR_name_to_handle_at 303
14359 +#define __NR_open_by_handle_at 304
14360 +#define __NR_clock_adjtime 305
14361 +#define __NR_syncfs 306
14362 +#define __NR_sendmmsg 307
14363 +#define __NR_setns 308
14364 +#define __NR_getcpu 309
14365 +#define __NR_process_vm_readv 310
14366 +#define __NR_process_vm_writev 311
14367 +#define __NR_kcmp 312
14368 +#define __NR_finit_module 313
14369 +#define __NR_sched_setattr 314
14370 +#define __NR_sched_getattr 315
14371 +#define __NR_renameat2 316
14372 +#define __NR_seccomp 317
14373 +#define __NR_getrandom 318
14374 +#define __NR_memfd_create 319
14375 +#define __NR_kexec_file_load 320
14376  
14377  #ifdef __PIC__
14378  #define syscall_weak(name,wsym,sym) \
14379 @@ -359,8 +377,13 @@
14380  .type sym,@function; \
14381  .global sym; \
14382  sym: \
14383 +.ifge __NR_##name-256 ; \
14384 +       mov     $__NR_##name,%ax; \
14385 +       jmp     __unified_syscall_16bit@PLT;  \
14386 +.else ; \
14387         mov     $__NR_##name,%al; \
14388 -       jmp     __unified_syscall@PLT
14389 +       jmp     __unified_syscall@PLT; \
14390 +.endif
14391  
14392  #define syscall(name,sym) \
14393  .text; \
14394 @@ -369,10 +392,10 @@
14395  sym: \
14396  .ifge __NR_##name-256 ; \
14397         mov     $__NR_##name,%ax; \
14398 -       jmp     __unified_syscall_16bit@PLT;  \
14399 +       jmp     __unified_syscall_16bit@PLT; \
14400  .else ; \
14401         mov     $__NR_##name,%al; \
14402 -       jmp     __unified_syscall@PLT;  \
14403 +       jmp     __unified_syscall@PLT; \
14404  .endif
14405  
14406  #else
14407 @@ -387,10 +410,10 @@
14408  sym: \
14409  .ifge __NR_##name-256 ; \
14410         mov     $__NR_##name,%ax; \
14411 -       jmp     __unified_syscall_16bit;  \
14412 +       jmp     __unified_syscall_16bit; \
14413  .else ; \
14414         mov     $__NR_##name,%al; \
14415 -       jmp     __unified_syscall;  \
14416 +       jmp     __unified_syscall; \
14417  .endif
14418  
14419  #define syscall(name,sym) \
14420 diff -urN -x .git dietlibc-0.33/x86_64/__time.S dietlibc/x86_64/__time.S
14421 --- dietlibc-0.33/x86_64/__time.S       1970-01-01 00:00:00.000000000 +0000
14422 +++ dietlibc/x86_64/__time.S    2015-01-01 12:14:43.541605560 +0000
14423 @@ -0,0 +1,11 @@
14424 +/* implement time(2) via gettimeofday(2) on x86-64 because gettimeofday
14425 +   is a vsyscall (i.e. no actual switch to kernel mode) */
14426 +.text
14427 +.global time
14428 +.type time,@function
14429 +time:
14430 +       mov     $0xffffffffff600400,%rax
14431 +       call    *%rax
14432 +       ret
14433 +.Lhere:
14434 +       .size    time,.Lhere-time
14435 diff -urN -x .git dietlibc-0.33/x86_64/time.S dietlibc/x86_64/time.S
14436 --- dietlibc-0.33/x86_64/time.S 2012-01-24 18:24:30.000000000 +0000
14437 +++ dietlibc/x86_64/time.S      2015-01-01 12:14:43.541605560 +0000
14438 @@ -1,11 +1 @@
14439 -/* implement time(2) via gettimeofday(2) on x86-64 because gettimeofday
14440 -   is a vsyscall (i.e. no actual switch to kernel mode) */
14441 -.text
14442 -.global time
14443 -.type time,@function
14444 -time:
14445 -       mov     $0xffffffffff600400,%rax
14446 -       call    *%rax
14447 -       ret
14448 -.Lhere:
14449 -       .size    time,.Lhere-time
14450 +/* avoid empty source file */
14451 diff -urN -x .git dietlibc-0.33/x86_64/unified.S dietlibc/x86_64/unified.S
14452 --- dietlibc-0.33/x86_64/unified.S      2012-11-02 11:17:29.000000000 +0000
14453 +++ dietlibc/x86_64/unified.S   2015-01-01 12:14:43.541605560 +0000
14454 @@ -13,12 +13,14 @@
14455  .global __error_unified_syscall
14456  .global __unified_syscall
14457  .global __unified_syscall_16bit
14458 +.global __unified_syscall_lp64
14459  __unified_syscall:
14460         mov     $0, %ah
14461  __unified_syscall_16bit:
14462         movzwl  %ax, %eax
14463  #if defined(__ILP32__)
14464         or      $0x40000000, %eax
14465 +__unified_syscall_lp64:
14466  #endif
14467         mov     %rcx, %r10
14468         syscall
14469 @@ -28,6 +30,9 @@
14470         negl    %eax
14471         pushq   %rax
14472         call    __errno_location
14473 +#ifdef IN_LDSO
14474 +       .hidden __errno_location
14475 +#endif
14476         popq    %rcx
14477         movl    %ecx,(%rax)
14478         orq     $-1, %rax
This page took 1.591708 seconds and 3 git commands to generate.