12 src/internal/version.h
17 # Do not make changes here.
21 exec_prefix = /usr/local
22 bindir = $(exec_prefix)/bin
24 @@ -16,31 +17,42 @@ includedir = $(prefix)/include
25 libdir = $(prefix)/lib
28 -SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
30 +BASE_SRCS = $(sort $(wildcard $(srcdir)/src/*/*.c))
31 +BASE_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(BASE_SRCS)))
32 +ARCH_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)/*.[csS])
33 +ARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS)))
34 +REPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS)))
35 +LDSO_SRCS = $(sort $(wildcard $(srcdir)/ldso/*.c))
36 +LDSO_OBJS = $(patsubst $(srcdir)/%,obj/%.lo,$(basename $(LDSO_SRCS)))
37 +OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS))))
39 LOBJS = $(OBJS:.o=.lo)
40 -GENH = include/bits/alltypes.h
41 -GENH_INT = src/internal/version.h
42 -IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
43 +GENH = obj/include/bits/alltypes.h
44 +GENH_INT = obj/src/internal/version.h
45 +IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h)
54 +CFLAGS_AUTO = -Os -pipe
55 CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
57 CFLAGS_ALL = $(CFLAGS_C99FSE)
58 -CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
59 -CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
60 -CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
61 -CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
62 +CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I$(srcdir)/arch/generic -Iobj/src/internal -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include
63 +CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
65 +LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
67 AR = $(CROSS_COMPILE)ar
68 RANLIB = $(CROSS_COMPILE)ranlib
69 -INSTALL = ./tools/install.sh
70 +INSTALL = $(srcdir)/tools/install.sh
72 -ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
73 -ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
74 +ARCH_INCLUDES = $(wildcard $(srcdir)/arch/$(ARCH)/bits/*.h)
75 +GENERIC_INCLUDES = $(wildcard $(srcdir)/arch/generic/bits/*.h)
76 +INCLUDES = $(wildcard $(srcdir)/include/*.h $(srcdir)/include/*/*.h)
77 +ALL_INCLUDES = $(sort $(INCLUDES:$(srcdir)/%=%) $(GENH:obj/%=%) $(ARCH_INCLUDES:$(srcdir)/arch/$(ARCH)/%=include/%) $(GENERIC_INCLUDES:$(srcdir)/arch/generic/%=include/%))
79 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
80 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
81 @@ -49,7 +61,7 @@ STATIC_LIBS = lib/libc.a
82 SHARED_LIBS = lib/libc.so
83 TOOL_LIBS = lib/musl-gcc.specs
84 ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
85 -ALL_TOOLS = tools/musl-gcc
86 +ALL_TOOLS = obj/musl-gcc
90 @@ -58,122 +70,128 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(A
95 +$(error Please set ARCH in config.mak before running make.)
98 all: $(ALL_LIBS) $(ALL_TOOLS)
100 +OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(LDSO_OBJS) $(GENH) $(GENH_INT))) $(addprefix obj/, crt crt/$(ARCH) include))
102 +$(ALL_LIBS) $(ALL_TOOLS) $(CRT_LIBS:lib/%=obj/crt/%) $(OBJS) $(LOBJS) $(GENH) $(GENH_INT): | $(OBJ_DIRS)
107 install: install-libs install-headers install-tools
113 - rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
115 - rm -f $(GENH) $(GENH_INT)
123 - @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
124 - ln -sf ../arch/$(ARCH)/bits $@
125 +obj/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed
126 + sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@
128 -include/bits/alltypes.h.in: include/bits
129 +obj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git)
130 + printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@
132 -include/bits/alltypes.h: include/bits/alltypes.h.in include/alltypes.h.in tools/mkalltypes.sed
133 - sed -f tools/mkalltypes.sed include/bits/alltypes.h.in include/alltypes.h.in > $@
134 +obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h
136 -src/internal/version.h: $(wildcard VERSION .git)
137 - printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
138 +obj/crt/rcrt1.o obj/ldso/dlstart.lo obj/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h
140 -src/internal/version.lo: src/internal/version.h
141 +obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
143 -crt/rcrt1.o src/ldso/dlstart.lo src/ldso/dynlink.lo: src/internal/dynlink.h arch/$(ARCH)/reloc.h
144 +obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c
146 -crt/crt1.o crt/Scrt1.o crt/rcrt1.o src/ldso/dlstart.lo: $(wildcard arch/$(ARCH)/crt_arch.h)
147 +obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC
149 -crt/rcrt1.o: src/ldso/dlstart.c
150 +obj/crt/$(ARCH)/crti.o: $(srcdir)/crt/$(ARCH)/crti.s
152 -crt/Scrt1.o crt/rcrt1.o: CFLAGS += -fPIC
153 +obj/crt/$(ARCH)/crtn.o: $(srcdir)/crt/$(ARCH)/crtn.s
155 -OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
156 -$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
157 +OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%))
158 +$(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3
160 MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c
161 -$(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
162 +$(MEMOPS_SRCS:%.c=obj/%.o) $(MEMOPS_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS)
164 NOSSP_SRCS = $(wildcard crt/*.c) \
165 src/env/__libc_start_main.c src/env/__init_tls.c \
166 - src/thread/__set_thread_area.c src/env/__stack_chk_fail.c \
167 - src/string/memset.c src/string/memcpy.c \
168 - src/ldso/dlstart.c src/ldso/dynlink.c
169 -$(NOSSP_SRCS:%.c=%.o) $(NOSSP_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_NOSSP)
170 + src/env/__stack_chk_fail.c \
171 + src/thread/__set_thread_area.c src/thread/$(ARCH)/__set_thread_area.c \
172 + src/string/memset.c src/string/$(ARCH)/memset.c \
173 + src/string/memcpy.c src/string/$(ARCH)/memcpy.c \
174 + ldso/dlstart.c ldso/dynlink.c
175 +$(NOSSP_SRCS:%.c=obj/%.o) $(NOSSP_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
177 -$(CRT_LIBS:lib/%=crt/%): CFLAGS += -DCRT
178 +$(CRT_LIBS:lib/%=obj/crt/%): CFLAGS_ALL += -DCRT
180 -# This incantation ensures that changes to any subarch asm files will
181 -# force the corresponding object file to be rebuilt, even if the implicit
182 -# rule below goes indirectly through a .sub file.
184 -$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
186 -$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
187 +$(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC
189 +CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $<
191 # Choose invocation of assembler to be used
192 -# $(1) is input file, $(2) is output file, $(3) is assembler flags
193 ifeq ($(ADD_CFI),yes)
194 - AS_CMD = LC_ALL=C awk -f tools/add-cfi.common.awk -f tools/add-cfi.$(ARCH).awk $< | $(CC) -x assembler -c -o $@ -
195 + AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ -
197 - AS_CMD = $(CC) -c -o $@ $<
201 -%.o: $(ARCH)$(ASMSUBARCH)/%.sub
202 - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
203 +obj/%.o: $(srcdir)/%.s
207 - $(AS_CMD) $(CFLAGS_ALL_STATIC)
208 +obj/%.o: $(srcdir)/%.S
211 -%.o: %.c $(GENH) $(IMPH)
212 - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
213 +obj/%.o: $(srcdir)/%.c $(GENH) $(IMPH)
216 -%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
217 - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
218 +obj/%.lo: $(srcdir)/%.s
222 - $(AS_CMD) $(CFLAGS_ALL_SHARED)
223 +obj/%.lo: $(srcdir)/%.S
226 -%.lo: %.c $(GENH) $(IMPH)
227 - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
228 +obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
231 -lib/libc.so: $(LOBJS)
232 - $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
233 +lib/libc.so: $(LOBJS) $(LDSO_OBJS)
234 + $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \
235 -Wl,-e,_dlstart -Wl,-Bsymbolic-functions \
236 - -o $@ $(LOBJS) $(LIBCC)
237 + -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC)
240 +lib/libc.a: $(AOBJS)
242 - $(AR) rc $@ $(OBJS)
243 + $(AR) rc $@ $(AOBJS)
251 +lib/%.o: obj/crt/%.o
254 -lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
255 +lib/crti.o: obj/crt/$(ARCH)/crti.o
258 +lib/crtn.o: obj/crt/$(ARCH)/crtn.o
261 +lib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak
262 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
264 -tools/musl-gcc: config.mak
265 +obj/musl-gcc: config.mak
266 printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
269 -tools/%-clang: tools/%-clang.in config.mak
270 +obj/%-clang: $(srcdir)/tools/%-clang.in config.mak
271 sed -e 's!@CC@!$(WRAPCC_CLANG)!g' -e 's!@PREFIX@!$(prefix)!g' -e 's!@INCDIR@!$(includedir)!g' -e 's!@LIBDIR@!$(libdir)!g' -e 's!@LDSO@!$(LDSO_PATHNAME)!g' $< > $@
274 -$(DESTDIR)$(bindir)/%: tools/%
275 +$(DESTDIR)$(bindir)/%: obj/%
278 $(DESTDIR)$(libdir)/%.so: lib/%.so
279 @@ -182,10 +200,16 @@ $(DESTDIR)$(libdir)/%.so: lib/%.so
280 $(DESTDIR)$(libdir)/%: lib/%
281 $(INSTALL) -D -m 644 $< $@
283 -$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
284 +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/%
285 $(INSTALL) -D -m 644 $< $@
287 -$(DESTDIR)$(includedir)/%: include/%
288 +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/generic/bits/%
289 + $(INSTALL) -D -m 644 $< $@
291 +$(DESTDIR)$(includedir)/bits/%: obj/include/bits/%
292 + $(INSTALL) -D -m 644 $< $@
294 +$(DESTDIR)$(includedir)/%: $(srcdir)/include/%
295 $(INSTALL) -D -m 644 $< $@
297 $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
298 @@ -195,12 +219,12 @@ install-libs: $(ALL_LIBS:lib/%=$(DESTDIR
300 install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
302 -install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
303 +install-tools: $(ALL_TOOLS:obj/%=$(DESTDIR)$(bindir)/%)
305 musl-git-%.tar.gz: .git
306 - git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@)
307 + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@)
310 - git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@)
311 + git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@)
313 .PHONY: all clean install install-libs install-headers install-tools
314 --- a/arch/aarch64/atomic.h
317 -#ifndef _INTERNAL_ATOMIC_H
318 -#define _INTERNAL_ATOMIC_H
322 -static inline int a_ctz_64(uint64_t x)
327 - : "=r"(x) : "r"(x));
331 -static inline int a_ctz_l(unsigned long x)
333 - return a_ctz_64(x);
336 -static inline void a_barrier()
338 - __asm__ __volatile__("dmb ish");
341 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
344 - __asm__ __volatile__(
349 - " stxr %w0,%2,%3\n"
354 - : "r"(t), "r"(s), "Q"(*(long*)p)
359 -static inline int a_cas(volatile int *p, int t, int s)
362 - __asm__ __volatile__(
367 - " stxr %w0,%w2,%3\n"
372 - : "r"(t), "r"(s), "Q"(*p)
377 -static inline int a_swap(volatile int *x, int v)
380 - __asm__ __volatile__(
383 - " stxr %w1,%w2,%3\n"
386 - : "=&r"(old), "=&r"(tmp)
388 - : "memory", "cc" );
392 -static inline int a_fetch_add(volatile int *x, int v)
395 - __asm__ __volatile__(
398 - " add %w0,%w0,%w2\n"
399 - " stxr %w1,%w0,%3\n"
402 - : "=&r"(old), "=&r"(tmp)
404 - : "memory", "cc" );
408 -static inline void a_inc(volatile int *x)
411 - __asm__ __volatile__(
414 - " add %w0,%w0,#1\n"
415 - " stxr %w1,%w0,%2\n"
418 - : "=&r"(tmp), "=&r"(tmp2)
420 - : "memory", "cc" );
423 -static inline void a_dec(volatile int *x)
426 - __asm__ __volatile__(
429 - " sub %w0,%w0,#1\n"
430 - " stxr %w1,%w0,%2\n"
433 - : "=&r"(tmp), "=&r"(tmp2)
435 - : "memory", "cc" );
438 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
441 - __asm__ __volatile__(
445 - " stxr %w1,%0,%3\n"
448 - : "=&r"(tmp), "=&r"(tmp2)
450 - : "memory", "cc" );
453 -static inline void a_and(volatile int *p, int v)
456 - __asm__ __volatile__(
459 - " and %w0,%w0,%w2\n"
460 - " stxr %w1,%w0,%3\n"
463 - : "=&r"(tmp), "=&r"(tmp2)
465 - : "memory", "cc" );
468 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
471 - __asm__ __volatile__(
475 - " stxr %w1,%0,%3\n"
478 - : "=&r"(tmp), "=&r"(tmp2)
480 - : "memory", "cc" );
483 -static inline void a_or_l(volatile void *p, long v)
485 - return a_or_64(p, v);
488 -static inline void a_or(volatile int *p, int v)
491 - __asm__ __volatile__(
494 - " orr %w0,%w0,%w2\n"
495 - " stxr %w1,%w0,%3\n"
498 - : "=&r"(tmp), "=&r"(tmp2)
500 - : "memory", "cc" );
503 -static inline void a_store(volatile int *p, int x)
505 - __asm__ __volatile__(
511 - : "memory", "cc" );
514 -#define a_spin a_barrier
516 -static inline void a_crash()
518 - *(volatile char *)0=0;
524 +++ b/arch/aarch64/atomic_arch.h
527 +static inline int a_ll(volatile int *p)
530 + __asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p));
535 +static inline int a_sc(volatile int *p, int v)
538 + __asm__ __volatile__ ("stlxr %w0,%w1,%2" : "=&r"(r) : "r"(v), "Q"(*p) : "memory");
542 +#define a_barrier a_barrier
543 +static inline void a_barrier()
545 + __asm__ __volatile__ ("dmb ish" : : : "memory");
549 +static inline int a_cas(volatile int *p, int t, int s)
558 + } while (!a_sc(p, s));
562 +static inline void *a_ll_p(volatile void *p)
565 + __asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *)p));
569 +static inline int a_sc_p(volatile int *p, void *v)
572 + __asm__ __volatile__ ("stlxr %w0,%1,%2" : "=&r"(r) : "r"(v), "Q"(*(void *volatile *)p) : "memory");
576 +#define a_cas_p a_cas_p
577 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
586 + } while (!a_sc_p(p, s));
590 +#define a_ctz_64 a_ctz_64
591 +static inline int a_ctz_64(uint64_t x)
596 + : "=r"(x) : "r"(x));
599 --- a/arch/aarch64/bits/errno.h
637 -#define ENAMETOOLONG 36
640 -#define ENOTEMPTY 39
642 -#define EWOULDBLOCK EAGAIN
659 -#define EDEADLOCK EDEADLK
673 -#define EMULTIHOP 72
676 -#define EOVERFLOW 75
690 -#define EDESTADDRREQ 89
692 -#define EPROTOTYPE 91
693 -#define ENOPROTOOPT 92
694 -#define EPROTONOSUPPORT 93
695 -#define ESOCKTNOSUPPORT 94
696 -#define EOPNOTSUPP 95
697 -#define ENOTSUP EOPNOTSUPP
698 -#define EPFNOSUPPORT 96
699 -#define EAFNOSUPPORT 97
700 -#define EADDRINUSE 98
701 -#define EADDRNOTAVAIL 99
702 -#define ENETDOWN 100
703 -#define ENETUNREACH 101
704 -#define ENETRESET 102
705 -#define ECONNABORTED 103
706 -#define ECONNRESET 104
709 -#define ENOTCONN 107
710 -#define ESHUTDOWN 108
711 -#define ETOOMANYREFS 109
712 -#define ETIMEDOUT 110
713 -#define ECONNREFUSED 111
714 -#define EHOSTDOWN 112
715 -#define EHOSTUNREACH 113
716 -#define EALREADY 114
717 -#define EINPROGRESS 115
723 -#define EREMOTEIO 121
725 -#define ENOMEDIUM 123
726 -#define EMEDIUMTYPE 124
727 -#define ECANCELED 125
729 -#define EKEYEXPIRED 127
730 -#define EKEYREVOKED 128
731 -#define EKEYREJECTED 129
732 -#define EOWNERDEAD 130
733 -#define ENOTRECOVERABLE 131
735 -#define EHWPOISON 133
736 --- a/arch/aarch64/bits/mman.h
737 +++ b/arch/aarch64/bits/mman.h
740 #define MCL_CURRENT 1
742 +#define MCL_ONFAULT 4
744 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
745 #define MADV_NORMAL 0
746 --- a/arch/aarch64/bits/statfs.h
750 - unsigned long f_type, f_bsize;
751 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
752 - fsfilcnt_t f_files, f_ffree;
754 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
756 --- a/arch/aarch64/bits/stdarg.h
759 -#define va_start(v,l) __builtin_va_start(v,l)
760 -#define va_end(v) __builtin_va_end(v)
761 -#define va_arg(v,l) __builtin_va_arg(v,l)
762 -#define va_copy(d,s) __builtin_va_copy(d,s)
763 --- a/arch/aarch64/bits/syscall.h
764 +++ b/arch/aarch64/bits/syscall.h
766 #define __NR_memfd_create 279
768 #define __NR_execveat 281
769 +#define __NR_userfaultfd 282
770 +#define __NR_membarrier 283
771 +#define __NR_mlock2 284
773 #define SYS_io_setup __NR_io_setup
774 #define SYS_io_destroy __NR_io_destroy
776 #define SYS_memfd_create __NR_memfd_create
777 #define SYS_bpf __NR_bpf
778 #define SYS_execveat __NR_execveat
779 +#define SYS_userfaultfd __NR_userfaultfd
780 +#define SYS_membarrier __NR_membarrier
781 +#define SYS_mlock2 __NR_mlock2
782 --- a/arch/aarch64/bits/termios.h
793 - speed_t __c_ispeed;
794 - speed_t __c_ospeed;
815 -#define IGNBRK 0000001
816 -#define BRKINT 0000002
817 -#define IGNPAR 0000004
818 -#define PARMRK 0000010
819 -#define INPCK 0000020
820 -#define ISTRIP 0000040
821 -#define INLCR 0000100
822 -#define IGNCR 0000200
823 -#define ICRNL 0000400
824 -#define IUCLC 0001000
825 -#define IXON 0002000
826 -#define IXANY 0004000
827 -#define IXOFF 0010000
828 -#define IMAXBEL 0020000
829 -#define IUTF8 0040000
831 -#define OPOST 0000001
832 -#define OLCUC 0000002
833 -#define ONLCR 0000004
834 -#define OCRNL 0000010
835 -#define ONOCR 0000020
836 -#define ONLRET 0000040
837 -#define OFILL 0000100
838 -#define OFDEL 0000200
839 -#define NLDLY 0000400
842 -#define CRDLY 0003000
847 -#define TABDLY 0014000
848 -#define TAB0 0000000
849 -#define TAB1 0004000
850 -#define TAB2 0010000
851 -#define TAB3 0014000
852 -#define BSDLY 0020000
855 -#define FFDLY 0100000
859 -#define VTDLY 0040000
866 -#define B110 0000003
867 -#define B134 0000004
868 -#define B150 0000005
869 -#define B200 0000006
870 -#define B300 0000007
871 -#define B600 0000010
872 -#define B1200 0000011
873 -#define B1800 0000012
874 -#define B2400 0000013
875 -#define B4800 0000014
876 -#define B9600 0000015
877 -#define B19200 0000016
878 -#define B38400 0000017
880 -#define B57600 0010001
881 -#define B115200 0010002
882 -#define B230400 0010003
883 -#define B460800 0010004
884 -#define B500000 0010005
885 -#define B576000 0010006
886 -#define B921600 0010007
887 -#define B1000000 0010010
888 -#define B1152000 0010011
889 -#define B1500000 0010012
890 -#define B2000000 0010013
891 -#define B2500000 0010014
892 -#define B3000000 0010015
893 -#define B3500000 0010016
894 -#define B4000000 0010017
896 -#define CBAUD 0010017
898 -#define CSIZE 0000060
903 -#define CSTOPB 0000100
904 -#define CREAD 0000200
905 -#define PARENB 0000400
906 -#define PARODD 0001000
907 -#define HUPCL 0002000
908 -#define CLOCAL 0004000
910 -#define ISIG 0000001
911 -#define ICANON 0000002
912 -#define ECHO 0000010
913 -#define ECHOE 0000020
914 -#define ECHOK 0000040
915 -#define ECHONL 0000100
916 -#define NOFLSH 0000200
917 -#define TOSTOP 0000400
918 -#define IEXTEN 0100000
920 -#define ECHOCTL 0001000
921 -#define ECHOPRT 0002000
922 -#define ECHOKE 0004000
923 -#define FLUSHO 0010000
924 -#define PENDIN 0040000
939 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
940 -#define CBAUDEX 0010000
941 -#define CRTSCTS 020000000000
942 -#define EXTPROC 0200000
943 -#define XTABS 0014000
945 --- a/arch/aarch64/pthread_arch.h
946 +++ b/arch/aarch64/pthread_arch.h
947 @@ -8,4 +8,4 @@ static inline struct pthread *__pthread_
949 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 16)
951 -#define CANCEL_REG_IP 33
953 --- a/arch/arm/atomic.h
956 -#ifndef _INTERNAL_ATOMIC_H
957 -#define _INTERNAL_ATOMIC_H
961 -static inline int a_ctz_l(unsigned long x)
963 - static const char debruijn32[32] = {
964 - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
965 - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
967 - return debruijn32[(x&-x)*0x076be629 >> 27];
970 -static inline int a_ctz_64(uint64_t x)
975 - return 32 + a_ctz_l(y);
980 -#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
982 -static inline void a_barrier()
984 - __asm__ __volatile__("dmb ish");
987 -static inline int a_cas(volatile int *p, int t, int s)
990 - __asm__ __volatile__(
995 - " strex %0,%2,%3\n"
1001 - : "r"(t), "r"(s), "Q"(*p)
1002 - : "memory", "cc" );
1006 -static inline int a_swap(volatile int *x, int v)
1009 - __asm__ __volatile__(
1011 - "1: ldrex %0,%3\n"
1012 - " strex %1,%2,%3\n"
1016 - : "=&r"(old), "=&r"(tmp)
1018 - : "memory", "cc" );
1022 -static inline int a_fetch_add(volatile int *x, int v)
1025 - __asm__ __volatile__(
1027 - "1: ldrex %0,%3\n"
1029 - " strex %1,%0,%3\n"
1033 - : "=&r"(old), "=&r"(tmp)
1035 - : "memory", "cc" );
1039 -static inline void a_inc(volatile int *x)
1042 - __asm__ __volatile__(
1044 - "1: ldrex %0,%2\n"
1046 - " strex %1,%0,%2\n"
1050 - : "=&r"(tmp), "=&r"(tmp2)
1052 - : "memory", "cc" );
1055 -static inline void a_dec(volatile int *x)
1058 - __asm__ __volatile__(
1060 - "1: ldrex %0,%2\n"
1062 - " strex %1,%0,%2\n"
1066 - : "=&r"(tmp), "=&r"(tmp2)
1068 - : "memory", "cc" );
1071 -static inline void a_and(volatile int *x, int v)
1074 - __asm__ __volatile__(
1076 - "1: ldrex %0,%3\n"
1078 - " strex %1,%0,%3\n"
1082 - : "=&r"(tmp), "=&r"(tmp2)
1084 - : "memory", "cc" );
1087 -static inline void a_or(volatile int *x, int v)
1090 - __asm__ __volatile__(
1092 - "1: ldrex %0,%3\n"
1094 - " strex %1,%0,%3\n"
1098 - : "=&r"(tmp), "=&r"(tmp2)
1100 - : "memory", "cc" );
1103 -static inline void a_store(volatile int *p, int x)
1105 - __asm__ __volatile__(
1111 - : "memory", "cc" );
1116 -int __a_cas(int, int, volatile int *) __attribute__((__visibility__("hidden")));
1117 -#define __k_cas __a_cas
1119 -static inline void a_barrier()
1121 - __asm__ __volatile__("bl __a_barrier"
1122 - : : : "memory", "cc", "ip", "lr" );
1125 -static inline int a_cas(volatile int *p, int t, int s)
1129 - if (!__k_cas(t, s, p))
1131 - if ((old=*p) != t)
1136 -static inline int a_swap(volatile int *x, int v)
1140 - while (__k_cas(old, v, x));
1144 -static inline int a_fetch_add(volatile int *x, int v)
1148 - while (__k_cas(old, old+v, x));
1152 -static inline void a_inc(volatile int *x)
1154 - a_fetch_add(x, 1);
1157 -static inline void a_dec(volatile int *x)
1159 - a_fetch_add(x, -1);
1162 -static inline void a_store(volatile int *p, int x)
1169 -static inline void a_and(volatile int *p, int v)
1173 - while (__k_cas(old, old&v, p));
1176 -static inline void a_or(volatile int *p, int v)
1180 - while (__k_cas(old, old|v, p));
1185 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
1187 - return (void *)a_cas(p, (int)t, (int)s);
1190 -#define a_spin a_barrier
1192 -static inline void a_crash()
1194 - *(volatile char *)0=0;
1197 -static inline void a_or_l(volatile void *p, long v)
1202 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
1204 - union { uint64_t v; uint32_t r[2]; } u = { v };
1205 - a_and((int *)p, u.r[0]);
1206 - a_and((int *)p+1, u.r[1]);
1209 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
1211 - union { uint64_t v; uint32_t r[2]; } u = { v };
1212 - a_or((int *)p, u.r[0]);
1213 - a_or((int *)p+1, u.r[1]);
1218 +++ b/arch/arm/atomic_arch.h
1220 +__attribute__((__visibility__("hidden")))
1221 +extern const void *__arm_atomics[3]; /* gettp, cas, barrier */
1223 +#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
1224 + || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
1227 +static inline int a_ll(volatile int *p)
1230 + __asm__ __volatile__ ("ldrex %0, %1" : "=r"(v) : "Q"(*p));
1235 +static inline int a_sc(volatile int *p, int v)
1238 + __asm__ __volatile__ ("strex %0,%1,%2" : "=&r"(r) : "r"(v), "Q"(*p) : "memory");
1242 +#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
1244 +#define a_barrier a_barrier
1245 +static inline void a_barrier()
1247 + __asm__ __volatile__ ("dmb ish" : : : "memory");
1252 +#define a_pre_llsc a_barrier
1253 +#define a_post_llsc a_barrier
1257 +#define a_cas a_cas
1258 +static inline int a_cas(volatile int *p, int t, int s)
1261 + register int r0 __asm__("r0") = t;
1262 + register int r1 __asm__("r1") = s;
1263 + register volatile int *r2 __asm__("r2") = p;
1265 + __asm__ __volatile__ (
1267 + : "+r"(r0) : "r"(r1), "r"(r2)
1268 + : "memory", "r3", "lr", "ip", "cc" );
1269 + if (!r0) return t;
1270 + if ((old=*p)!=t) return old;
1277 +#define a_barrier a_barrier
1278 +static inline void a_barrier()
1280 + __asm__ __volatile__("bl __a_barrier"
1281 + : : : "memory", "cc", "ip", "lr" );
1285 +#define a_crash a_crash
1286 +static inline void a_crash()
1288 + __asm__ __volatile__(
1290 + ".word 0xe7f000f0"
1296 --- a/arch/arm/bits/errno.h
1334 -#define ENAMETOOLONG 36
1337 -#define ENOTEMPTY 39
1339 -#define EWOULDBLOCK EAGAIN
1343 -#define EL2NSYNC 45
1356 -#define EDEADLOCK EDEADLK
1370 -#define EMULTIHOP 72
1373 -#define EOVERFLOW 75
1374 -#define ENOTUNIQ 76
1381 -#define ELIBEXEC 83
1383 -#define ERESTART 85
1384 -#define ESTRPIPE 86
1386 -#define ENOTSOCK 88
1387 -#define EDESTADDRREQ 89
1388 -#define EMSGSIZE 90
1389 -#define EPROTOTYPE 91
1390 -#define ENOPROTOOPT 92
1391 -#define EPROTONOSUPPORT 93
1392 -#define ESOCKTNOSUPPORT 94
1393 -#define EOPNOTSUPP 95
1394 -#define ENOTSUP EOPNOTSUPP
1395 -#define EPFNOSUPPORT 96
1396 -#define EAFNOSUPPORT 97
1397 -#define EADDRINUSE 98
1398 -#define EADDRNOTAVAIL 99
1399 -#define ENETDOWN 100
1400 -#define ENETUNREACH 101
1401 -#define ENETRESET 102
1402 -#define ECONNABORTED 103
1403 -#define ECONNRESET 104
1404 -#define ENOBUFS 105
1405 -#define EISCONN 106
1406 -#define ENOTCONN 107
1407 -#define ESHUTDOWN 108
1408 -#define ETOOMANYREFS 109
1409 -#define ETIMEDOUT 110
1410 -#define ECONNREFUSED 111
1411 -#define EHOSTDOWN 112
1412 -#define EHOSTUNREACH 113
1413 -#define EALREADY 114
1414 -#define EINPROGRESS 115
1416 -#define EUCLEAN 117
1417 -#define ENOTNAM 118
1418 -#define ENAVAIL 119
1420 -#define EREMOTEIO 121
1422 -#define ENOMEDIUM 123
1423 -#define EMEDIUMTYPE 124
1424 -#define ECANCELED 125
1426 -#define EKEYEXPIRED 127
1427 -#define EKEYREVOKED 128
1428 -#define EKEYREJECTED 129
1429 -#define EOWNERDEAD 130
1430 -#define ENOTRECOVERABLE 131
1431 -#define ERFKILL 132
1432 -#define EHWPOISON 133
1433 --- a/arch/arm/bits/ioctl.h
1436 -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
1437 -#define _IOC_NONE 0U
1438 -#define _IOC_WRITE 1U
1439 -#define _IOC_READ 2U
1441 -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
1442 -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
1443 -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
1444 -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
1446 -#define TCGETS 0x5401
1447 -#define TCSETS 0x5402
1448 -#define TCSETSW 0x5403
1449 -#define TCSETSF 0x5404
1450 -#define TCGETA 0x5405
1451 -#define TCSETA 0x5406
1452 -#define TCSETAW 0x5407
1453 -#define TCSETAF 0x5408
1454 -#define TCSBRK 0x5409
1455 -#define TCXONC 0x540A
1456 -#define TCFLSH 0x540B
1457 -#define TIOCEXCL 0x540C
1458 -#define TIOCNXCL 0x540D
1459 -#define TIOCSCTTY 0x540E
1460 -#define TIOCGPGRP 0x540F
1461 -#define TIOCSPGRP 0x5410
1462 -#define TIOCOUTQ 0x5411
1463 -#define TIOCSTI 0x5412
1464 -#define TIOCGWINSZ 0x5413
1465 -#define TIOCSWINSZ 0x5414
1466 -#define TIOCMGET 0x5415
1467 -#define TIOCMBIS 0x5416
1468 -#define TIOCMBIC 0x5417
1469 -#define TIOCMSET 0x5418
1470 -#define TIOCGSOFTCAR 0x5419
1471 -#define TIOCSSOFTCAR 0x541A
1472 -#define FIONREAD 0x541B
1473 -#define TIOCINQ FIONREAD
1474 -#define TIOCLINUX 0x541C
1475 -#define TIOCCONS 0x541D
1476 -#define TIOCGSERIAL 0x541E
1477 -#define TIOCSSERIAL 0x541F
1478 -#define TIOCPKT 0x5420
1479 -#define FIONBIO 0x5421
1480 -#define TIOCNOTTY 0x5422
1481 -#define TIOCSETD 0x5423
1482 -#define TIOCGETD 0x5424
1483 -#define TCSBRKP 0x5425
1484 -#define TIOCTTYGSTRUCT 0x5426
1485 -#define TIOCSBRK 0x5427
1486 -#define TIOCCBRK 0x5428
1487 -#define TIOCGSID 0x5429
1488 -#define TIOCGPTN 0x80045430
1489 -#define TIOCSPTLCK 0x40045431
1490 -#define TCGETX 0x5432
1491 -#define TCSETX 0x5433
1492 -#define TCSETXF 0x5434
1493 -#define TCSETXW 0x5435
1495 -#define FIONCLEX 0x5450
1496 -#define FIOCLEX 0x5451
1497 -#define FIOASYNC 0x5452
1498 -#define TIOCSERCONFIG 0x5453
1499 -#define TIOCSERGWILD 0x5454
1500 -#define TIOCSERSWILD 0x5455
1501 -#define TIOCGLCKTRMIOS 0x5456
1502 -#define TIOCSLCKTRMIOS 0x5457
1503 -#define TIOCSERGSTRUCT 0x5458
1504 -#define TIOCSERGETLSR 0x5459
1505 -#define TIOCSERGETMULTI 0x545A
1506 -#define TIOCSERSETMULTI 0x545B
1508 -#define TIOCMIWAIT 0x545C
1509 -#define TIOCGICOUNT 0x545D
1510 -#define TIOCGHAYESESP 0x545E
1511 -#define TIOCSHAYESESP 0x545F
1512 -#define FIOQSIZE 0x5460
1514 -#define TIOCPKT_DATA 0
1515 -#define TIOCPKT_FLUSHREAD 1
1516 -#define TIOCPKT_FLUSHWRITE 2
1517 -#define TIOCPKT_STOP 4
1518 -#define TIOCPKT_START 8
1519 -#define TIOCPKT_NOSTOP 16
1520 -#define TIOCPKT_DOSTOP 32
1521 -#define TIOCPKT_IOCTL 64
1523 -#define TIOCSER_TEMT 0x01
1526 - unsigned short ws_row;
1527 - unsigned short ws_col;
1528 - unsigned short ws_xpixel;
1529 - unsigned short ws_ypixel;
1532 -#define TIOCM_LE 0x001
1533 -#define TIOCM_DTR 0x002
1534 -#define TIOCM_RTS 0x004
1535 -#define TIOCM_ST 0x008
1536 -#define TIOCM_SR 0x010
1537 -#define TIOCM_CTS 0x020
1538 -#define TIOCM_CAR 0x040
1539 -#define TIOCM_RNG 0x080
1540 -#define TIOCM_DSR 0x100
1541 -#define TIOCM_CD TIOCM_CAR
1542 -#define TIOCM_RI TIOCM_RNG
1543 -#define TIOCM_OUT1 0x2000
1544 -#define TIOCM_OUT2 0x4000
1545 -#define TIOCM_LOOP 0x8000
1546 -#define TIOCM_MODEM_BITS TIOCM_OUT2
1558 -#define N_PROFIBUS_FDL 10
1560 -#define N_SMSBLOCK 12
1562 -#define N_SYNC_PPP 14
1565 -#define FIOSETOWN 0x8901
1566 -#define SIOCSPGRP 0x8902
1567 -#define FIOGETOWN 0x8903
1568 -#define SIOCGPGRP 0x8904
1569 -#define SIOCATMARK 0x8905
1570 -#define SIOCGSTAMP 0x8906
1572 -#define SIOCADDRT 0x890B
1573 -#define SIOCDELRT 0x890C
1574 -#define SIOCRTMSG 0x890D
1576 -#define SIOCGIFNAME 0x8910
1577 -#define SIOCSIFLINK 0x8911
1578 -#define SIOCGIFCONF 0x8912
1579 -#define SIOCGIFFLAGS 0x8913
1580 -#define SIOCSIFFLAGS 0x8914
1581 -#define SIOCGIFADDR 0x8915
1582 -#define SIOCSIFADDR 0x8916
1583 -#define SIOCGIFDSTADDR 0x8917
1584 -#define SIOCSIFDSTADDR 0x8918
1585 -#define SIOCGIFBRDADDR 0x8919
1586 -#define SIOCSIFBRDADDR 0x891a
1587 -#define SIOCGIFNETMASK 0x891b
1588 -#define SIOCSIFNETMASK 0x891c
1589 -#define SIOCGIFMETRIC 0x891d
1590 -#define SIOCSIFMETRIC 0x891e
1591 -#define SIOCGIFMEM 0x891f
1592 -#define SIOCSIFMEM 0x8920
1593 -#define SIOCGIFMTU 0x8921
1594 -#define SIOCSIFMTU 0x8922
1595 -#define SIOCSIFHWADDR 0x8924
1596 -#define SIOCGIFENCAP 0x8925
1597 -#define SIOCSIFENCAP 0x8926
1598 -#define SIOCGIFHWADDR 0x8927
1599 -#define SIOCGIFSLAVE 0x8929
1600 -#define SIOCSIFSLAVE 0x8930
1601 -#define SIOCADDMULTI 0x8931
1602 -#define SIOCDELMULTI 0x8932
1603 -#define SIOCGIFINDEX 0x8933
1604 -#define SIOGIFINDEX SIOCGIFINDEX
1605 -#define SIOCSIFPFLAGS 0x8934
1606 -#define SIOCGIFPFLAGS 0x8935
1607 -#define SIOCDIFADDR 0x8936
1608 -#define SIOCSIFHWBROADCAST 0x8937
1609 -#define SIOCGIFCOUNT 0x8938
1611 -#define SIOCGIFBR 0x8940
1612 -#define SIOCSIFBR 0x8941
1614 -#define SIOCGIFTXQLEN 0x8942
1615 -#define SIOCSIFTXQLEN 0x8943
1617 -#define SIOCDARP 0x8953
1618 -#define SIOCGARP 0x8954
1619 -#define SIOCSARP 0x8955
1621 -#define SIOCDRARP 0x8960
1622 -#define SIOCGRARP 0x8961
1623 -#define SIOCSRARP 0x8962
1625 -#define SIOCGIFMAP 0x8970
1626 -#define SIOCSIFMAP 0x8971
1628 -#define SIOCADDDLCI 0x8980
1629 -#define SIOCDELDLCI 0x8981
1631 -#define SIOCDEVPRIVATE 0x89F0
1632 -#define SIOCPROTOPRIVATE 0x89E0
1633 --- a/arch/arm/bits/ipc.h
1638 - key_t __ipc_perm_key;
1644 - int __ipc_perm_seq;
1649 -#define IPC_64 0x100
1650 --- a/arch/arm/bits/mman.h
1651 +++ b/arch/arm/bits/mman.h
1654 #define MCL_CURRENT 1
1655 #define MCL_FUTURE 2
1656 +#define MCL_ONFAULT 4
1658 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
1659 #define MADV_NORMAL 0
1660 --- a/arch/arm/bits/msg.h
1665 - struct ipc_perm msg_perm;
1672 - unsigned long msg_cbytes;
1673 - msgqnum_t msg_qnum;
1674 - msglen_t msg_qbytes;
1677 - unsigned long __unused[2];
1679 --- a/arch/arm/bits/sem.h
1683 - struct ipc_perm sem_perm;
1688 -#if __BYTE_ORDER == __LITTLE_ENDIAN
1689 - unsigned short sem_nsems;
1690 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
1692 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
1693 - unsigned short sem_nsems;
1698 --- a/arch/arm/bits/shm.h
1701 -#define SHMLBA 4096
1705 - struct ipc_perm shm_perm;
1715 - unsigned long shm_nattch;
1716 - unsigned long __pad1;
1717 - unsigned long __pad2;
1721 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
1726 - unsigned long shm_tot, shm_rss, shm_swp;
1727 - unsigned long __swap_attempts, __swap_successes;
1730 --- a/arch/arm/bits/socket.h
1736 - socklen_t msg_namelen;
1737 - struct iovec *msg_iov;
1739 - void *msg_control;
1740 - socklen_t msg_controllen;
1746 - socklen_t cmsg_len;
1750 --- a/arch/arm/bits/statfs.h
1754 - unsigned long f_type, f_bsize;
1755 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
1756 - fsfilcnt_t f_files, f_ffree;
1758 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
1760 --- a/arch/arm/bits/stdarg.h
1763 -#define va_start(v,l) __builtin_va_start(v,l)
1764 -#define va_end(v) __builtin_va_end(v)
1765 -#define va_arg(v,l) __builtin_va_arg(v,l)
1766 -#define va_copy(d,s) __builtin_va_copy(d,s)
1767 --- a/arch/arm/bits/syscall.h
1768 +++ b/arch/arm/bits/syscall.h
1770 #define __NR_memfd_create 385
1771 #define __NR_bpf 386
1772 #define __NR_execveat 387
1773 +#define __NR_userfaultfd 388
1774 +#define __NR_membarrier 389
1775 +#define __NR_mlock2 390
1777 #define __ARM_NR_breakpoint 0x0f0001
1778 #define __ARM_NR_cacheflush 0x0f0002
1780 #define SYS_memfd_create 385
1782 #define SYS_execveat 387
1783 +#define SYS_userfaultfd 388
1784 +#define SYS_membarrier 389
1785 +#define SYS_mlock2 390
1786 --- a/arch/arm/bits/termios.h
1797 - speed_t __c_ispeed;
1798 - speed_t __c_ospeed;
1813 -#define VREPRINT 12
1814 -#define VDISCARD 13
1819 -#define IGNBRK 0000001
1820 -#define BRKINT 0000002
1821 -#define IGNPAR 0000004
1822 -#define PARMRK 0000010
1823 -#define INPCK 0000020
1824 -#define ISTRIP 0000040
1825 -#define INLCR 0000100
1826 -#define IGNCR 0000200
1827 -#define ICRNL 0000400
1828 -#define IUCLC 0001000
1829 -#define IXON 0002000
1830 -#define IXANY 0004000
1831 -#define IXOFF 0010000
1832 -#define IMAXBEL 0020000
1833 -#define IUTF8 0040000
1835 -#define OPOST 0000001
1836 -#define OLCUC 0000002
1837 -#define ONLCR 0000004
1838 -#define OCRNL 0000010
1839 -#define ONOCR 0000020
1840 -#define ONLRET 0000040
1841 -#define OFILL 0000100
1842 -#define OFDEL 0000200
1843 -#define NLDLY 0000400
1844 -#define NL0 0000000
1845 -#define NL1 0000400
1846 -#define CRDLY 0003000
1847 -#define CR0 0000000
1848 -#define CR1 0001000
1849 -#define CR2 0002000
1850 -#define CR3 0003000
1851 -#define TABDLY 0014000
1852 -#define TAB0 0000000
1853 -#define TAB1 0004000
1854 -#define TAB2 0010000
1855 -#define TAB3 0014000
1856 -#define BSDLY 0020000
1857 -#define BS0 0000000
1858 -#define BS1 0020000
1859 -#define FFDLY 0100000
1860 -#define FF0 0000000
1861 -#define FF1 0100000
1863 -#define VTDLY 0040000
1864 -#define VT0 0000000
1865 -#define VT1 0040000
1868 -#define B50 0000001
1869 -#define B75 0000002
1870 -#define B110 0000003
1871 -#define B134 0000004
1872 -#define B150 0000005
1873 -#define B200 0000006
1874 -#define B300 0000007
1875 -#define B600 0000010
1876 -#define B1200 0000011
1877 -#define B1800 0000012
1878 -#define B2400 0000013
1879 -#define B4800 0000014
1880 -#define B9600 0000015
1881 -#define B19200 0000016
1882 -#define B38400 0000017
1884 -#define B57600 0010001
1885 -#define B115200 0010002
1886 -#define B230400 0010003
1887 -#define B460800 0010004
1888 -#define B500000 0010005
1889 -#define B576000 0010006
1890 -#define B921600 0010007
1891 -#define B1000000 0010010
1892 -#define B1152000 0010011
1893 -#define B1500000 0010012
1894 -#define B2000000 0010013
1895 -#define B2500000 0010014
1896 -#define B3000000 0010015
1897 -#define B3500000 0010016
1898 -#define B4000000 0010017
1900 -#define CBAUD 0010017
1902 -#define CSIZE 0000060
1903 -#define CS5 0000000
1904 -#define CS6 0000020
1905 -#define CS7 0000040
1906 -#define CS8 0000060
1907 -#define CSTOPB 0000100
1908 -#define CREAD 0000200
1909 -#define PARENB 0000400
1910 -#define PARODD 0001000
1911 -#define HUPCL 0002000
1912 -#define CLOCAL 0004000
1914 -#define ISIG 0000001
1915 -#define ICANON 0000002
1916 -#define ECHO 0000010
1917 -#define ECHOE 0000020
1918 -#define ECHOK 0000040
1919 -#define ECHONL 0000100
1920 -#define NOFLSH 0000200
1921 -#define TOSTOP 0000400
1922 -#define IEXTEN 0100000
1924 -#define ECHOCTL 0001000
1925 -#define ECHOPRT 0002000
1926 -#define ECHOKE 0004000
1927 -#define FLUSHO 0010000
1928 -#define PENDIN 0040000
1937 -#define TCIOFLUSH 2
1940 -#define TCSADRAIN 1
1941 -#define TCSAFLUSH 2
1943 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
1944 -#define CBAUDEX 0010000
1945 -#define CRTSCTS 020000000000
1946 -#define EXTPROC 0200000
1947 -#define XTABS 0014000
1949 --- a/arch/arm/pthread_arch.h
1950 +++ b/arch/arm/pthread_arch.h
1951 @@ -27,4 +27,4 @@ static inline pthread_t __pthread_self()
1952 #define TLS_ABOVE_TP
1953 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8)
1955 -#define CANCEL_REG_IP 18
1956 +#define MC_PC arm_pc
1957 --- a/arch/arm/reloc.h
1958 +++ b/arch/arm/reloc.h
1960 #define ENDIAN_SUFFIX ""
1964 -#define FP_SUFFIX ""
1967 #define FP_SUFFIX "hf"
1969 +#define FP_SUFFIX ""
1972 #define LDSO_ARCH "arm" ENDIAN_SUFFIX FP_SUFFIX
1974 #define REL_TPOFF R_ARM_TLS_TPOFF32
1975 //#define REL_TLSDESC R_ARM_TLS_DESC
1978 #define CRTJMP(pc,sp) __asm__ __volatile__( \
1979 "mov sp,%1 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
1981 -#define CRTJMP(pc,sp) __asm__ __volatile__( \
1982 - "mov sp,%1 ; tst %0,#1 ; moveq pc,%0 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
1984 --- a/arch/arm/src/__aeabi_atexit.c
1987 -int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
1989 -int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
1991 - return __cxa_atexit (func, obj, d);
1993 --- a/arch/arm/src/__aeabi_memclr.c
1996 -#include <string.h>
1999 -void __aeabi_memclr(void *dest, size_t n)
2001 - memset(dest, 0, n);
2003 -weak_alias(__aeabi_memclr, __aeabi_memclr4);
2004 -weak_alias(__aeabi_memclr, __aeabi_memclr8);
2005 --- a/arch/arm/src/__aeabi_memcpy.c
2008 -#include <string.h>
2011 -void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
2013 - memcpy(dest, src, n);
2015 -weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
2016 -weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
2017 --- a/arch/arm/src/__aeabi_memmove.c
2020 -#include <string.h>
2023 -void __aeabi_memmove(void *dest, const void *src, size_t n)
2025 - memmove(dest, src, n);
2027 -weak_alias(__aeabi_memmove, __aeabi_memmove4);
2028 -weak_alias(__aeabi_memmove, __aeabi_memmove8);
2029 --- a/arch/arm/src/__aeabi_memset.c
2032 -#include <string.h>
2035 -void __aeabi_memset(void *dest, size_t n, int c)
2037 - memset(dest, c, n);
2039 -weak_alias(__aeabi_memset, __aeabi_memset4);
2040 -weak_alias(__aeabi_memset, __aeabi_memset8);
2041 --- a/arch/arm/src/__set_thread_area.c
2044 -#include <stdint.h>
2046 -#include "pthread_impl.h"
2049 -#define HWCAP_TLS (1 << 15)
2051 -extern const unsigned char __attribute__((__visibility__("hidden")))
2052 - __a_barrier_dummy[], __a_barrier_oldkuser[],
2053 - __a_barrier_v6[], __a_barrier_v7[],
2054 - __a_cas_dummy[], __a_cas_v6[], __a_cas_v7[],
2055 - __a_gettp_dummy[];
2057 -#define __a_barrier_kuser 0xffff0fa0
2058 -#define __a_cas_kuser 0xffff0fc0
2059 -#define __a_gettp_kuser 0xffff0fe0
2061 -extern uintptr_t __attribute__((__visibility__("hidden")))
2062 - __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
2064 -#define SET(op,ver) (__a_##op##_ptr = \
2065 - (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
2067 -int __set_thread_area(void *p)
2069 -#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
2070 - if (__hwcap & HWCAP_TLS) {
2074 - for (aux=libc.auxv; *aux; aux+=2) {
2075 - if (*aux != AT_PLATFORM) continue;
2076 - const char *s = (void *)aux[1];
2077 - if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
2083 - int ver = *(int *)0xffff0ffc;
2084 - SET(gettp, kuser);
2086 - SET(barrier, kuser);
2087 - if (ver < 2) a_crash();
2088 - if (ver < 3) SET(barrier, oldkuser);
2091 - return __syscall(0xf0005, p);
2093 --- a/arch/arm/src/arm/atomics.s
2098 -.global __a_barrier
2099 -.hidden __a_barrier
2100 -.type __a_barrier,%function
2105 -1: .word __a_barrier_ptr-1b
2106 -.global __a_barrier_dummy
2107 -.hidden __a_barrier_dummy
2112 -.global __a_barrier_oldkuser
2113 -.hidden __a_barrier_oldkuser
2114 -__a_barrier_oldkuser:
2115 - push {r0,r1,r2,r3,ip,lr}
2118 - ldr ip,=0xffff0fc0
2121 - pop {r0,r1,r2,r3,ip,lr}
2125 -.global __a_barrier_v6
2126 -.hidden __a_barrier_v6
2128 - mcr p15,0,r0,c7,c10,5
2130 -.global __a_barrier_v7
2131 -.hidden __a_barrier_v7
2133 - .word 0xf57ff05b /* dmb ish */
2138 -.type __a_cas,%function
2143 -1: .word __a_cas_ptr-1b
2144 -.global __a_cas_dummy
2145 -.hidden __a_cas_dummy
2158 - mcr p15,0,r0,c7,c10,5
2159 -1: .word 0xe1920f9f /* ldrex r0,[r2] */
2161 - .word 0x01820f91 /* strexeq r0,r1,[r2] */
2164 - mcr p15,0,r0,c7,c10,5
2170 - .word 0xf57ff05b /* dmb ish */
2171 -1: .word 0xe1920f9f /* ldrex r0,[r2] */
2173 - .word 0x01820f91 /* strexeq r0,r1,[r2] */
2176 - .word 0xf57ff05b /* dmb ish */
2179 -.global __aeabi_read_tp
2180 -.type __aeabi_read_tp,%function
2185 -.type __a_gettp,%function
2190 -1: .word __a_gettp_ptr-1b
2191 -.global __a_gettp_dummy
2192 -.hidden __a_gettp_dummy
2194 - mrc p15,0,r0,c13,c0,3
2198 -.global __a_barrier_ptr
2199 -.hidden __a_barrier_ptr
2203 -.global __a_cas_ptr
2204 -.hidden __a_cas_ptr
2208 -.global __a_gettp_ptr
2209 -.hidden __a_gettp_ptr
2212 --- a/arch/arm/src/find_exidx.c
2215 -#define _GNU_SOURCE
2217 -#include <stdint.h>
2219 -struct find_exidx_data {
2220 - uintptr_t pc, exidx_start;
2224 -static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
2226 - struct find_exidx_data *data = ptr;
2227 - const ElfW(Phdr) *phdr = info->dlpi_phdr;
2228 - uintptr_t addr, exidx_start = 0;
2229 - int i, match = 0, exidx_len = 0;
2231 - for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
2232 - addr = info->dlpi_addr + phdr->p_vaddr;
2233 - switch (phdr->p_type) {
2235 - match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
2237 - case PT_ARM_EXIDX:
2238 - exidx_start = addr;
2239 - exidx_len = phdr->p_memsz;
2243 - data->exidx_start = exidx_start;
2244 - data->exidx_len = exidx_len;
2248 -uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
2250 - struct find_exidx_data data;
2252 - if (dl_iterate_phdr(find_exidx, &data) <= 0)
2254 - *pcount = data.exidx_len / 8;
2255 - return data.exidx_start;
2258 +++ b/arch/generic/bits/errno.h
2295 +#define ENAMETOOLONG 36
2298 +#define ENOTEMPTY 39
2300 +#define EWOULDBLOCK EAGAIN
2304 +#define EL2NSYNC 45
2317 +#define EDEADLOCK EDEADLK
2331 +#define EMULTIHOP 72
2334 +#define EOVERFLOW 75
2335 +#define ENOTUNIQ 76
2342 +#define ELIBEXEC 83
2344 +#define ERESTART 85
2345 +#define ESTRPIPE 86
2347 +#define ENOTSOCK 88
2348 +#define EDESTADDRREQ 89
2349 +#define EMSGSIZE 90
2350 +#define EPROTOTYPE 91
2351 +#define ENOPROTOOPT 92
2352 +#define EPROTONOSUPPORT 93
2353 +#define ESOCKTNOSUPPORT 94
2354 +#define EOPNOTSUPP 95
2355 +#define ENOTSUP EOPNOTSUPP
2356 +#define EPFNOSUPPORT 96
2357 +#define EAFNOSUPPORT 97
2358 +#define EADDRINUSE 98
2359 +#define EADDRNOTAVAIL 99
2360 +#define ENETDOWN 100
2361 +#define ENETUNREACH 101
2362 +#define ENETRESET 102
2363 +#define ECONNABORTED 103
2364 +#define ECONNRESET 104
2365 +#define ENOBUFS 105
2366 +#define EISCONN 106
2367 +#define ENOTCONN 107
2368 +#define ESHUTDOWN 108
2369 +#define ETOOMANYREFS 109
2370 +#define ETIMEDOUT 110
2371 +#define ECONNREFUSED 111
2372 +#define EHOSTDOWN 112
2373 +#define EHOSTUNREACH 113
2374 +#define EALREADY 114
2375 +#define EINPROGRESS 115
2377 +#define EUCLEAN 117
2378 +#define ENOTNAM 118
2379 +#define ENAVAIL 119
2381 +#define EREMOTEIO 121
2383 +#define ENOMEDIUM 123
2384 +#define EMEDIUMTYPE 124
2385 +#define ECANCELED 125
2387 +#define EKEYEXPIRED 127
2388 +#define EKEYREVOKED 128
2389 +#define EKEYREJECTED 129
2390 +#define EOWNERDEAD 130
2391 +#define ENOTRECOVERABLE 131
2392 +#define ERFKILL 132
2393 +#define EHWPOISON 133
2395 +++ b/arch/generic/bits/fcntl.h
2397 +#define O_CREAT 0100
2398 +#define O_EXCL 0200
2399 +#define O_NOCTTY 0400
2400 +#define O_TRUNC 01000
2401 +#define O_APPEND 02000
2402 +#define O_NONBLOCK 04000
2403 +#define O_DSYNC 010000
2404 +#define O_SYNC 04010000
2405 +#define O_RSYNC 04010000
2406 +#define O_DIRECTORY 0200000
2407 +#define O_NOFOLLOW 0400000
2408 +#define O_CLOEXEC 02000000
2410 +#define O_ASYNC 020000
2411 +#define O_DIRECT 040000
2412 +#define O_LARGEFILE 0100000
2413 +#define O_NOATIME 01000000
2414 +#define O_PATH 010000000
2415 +#define O_TMPFILE 020200000
2416 +#define O_NDELAY O_NONBLOCK
2426 +#define F_SETSIG 10
2427 +#define F_GETSIG 11
2431 +#define F_SETLKW 14
2433 +#define F_SETOWN_EX 15
2434 +#define F_GETOWN_EX 16
2436 +#define F_GETOWNER_UIDS 17
2438 +++ b/arch/generic/bits/fenv.h
2440 +#define FE_ALL_EXCEPT 0
2441 +#define FE_TONEAREST 0
2443 +typedef unsigned long fexcept_t;
2446 + unsigned long __cw;
2449 +#define FE_DFL_ENV ((const fenv_t *) -1)
2451 +++ b/arch/generic/bits/ioctl.h
2453 +#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
2454 +#define _IOC_NONE 0U
2455 +#define _IOC_WRITE 1U
2456 +#define _IOC_READ 2U
2458 +#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
2459 +#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
2460 +#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
2461 +#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
2463 +#define TCGETS 0x5401
2464 +#define TCSETS 0x5402
2465 +#define TCSETSW 0x5403
2466 +#define TCSETSF 0x5404
2467 +#define TCGETA 0x5405
2468 +#define TCSETA 0x5406
2469 +#define TCSETAW 0x5407
2470 +#define TCSETAF 0x5408
2471 +#define TCSBRK 0x5409
2472 +#define TCXONC 0x540A
2473 +#define TCFLSH 0x540B
2474 +#define TIOCEXCL 0x540C
2475 +#define TIOCNXCL 0x540D
2476 +#define TIOCSCTTY 0x540E
2477 +#define TIOCGPGRP 0x540F
2478 +#define TIOCSPGRP 0x5410
2479 +#define TIOCOUTQ 0x5411
2480 +#define TIOCSTI 0x5412
2481 +#define TIOCGWINSZ 0x5413
2482 +#define TIOCSWINSZ 0x5414
2483 +#define TIOCMGET 0x5415
2484 +#define TIOCMBIS 0x5416
2485 +#define TIOCMBIC 0x5417
2486 +#define TIOCMSET 0x5418
2487 +#define TIOCGSOFTCAR 0x5419
2488 +#define TIOCSSOFTCAR 0x541A
2489 +#define FIONREAD 0x541B
2490 +#define TIOCINQ FIONREAD
2491 +#define TIOCLINUX 0x541C
2492 +#define TIOCCONS 0x541D
2493 +#define TIOCGSERIAL 0x541E
2494 +#define TIOCSSERIAL 0x541F
2495 +#define TIOCPKT 0x5420
2496 +#define FIONBIO 0x5421
2497 +#define TIOCNOTTY 0x5422
2498 +#define TIOCSETD 0x5423
2499 +#define TIOCGETD 0x5424
2500 +#define TCSBRKP 0x5425
2501 +#define TIOCTTYGSTRUCT 0x5426
2502 +#define TIOCSBRK 0x5427
2503 +#define TIOCCBRK 0x5428
2504 +#define TIOCGSID 0x5429
2505 +#define TIOCGPTN 0x80045430
2506 +#define TIOCSPTLCK 0x40045431
2507 +#define TCGETX 0x5432
2508 +#define TCSETX 0x5433
2509 +#define TCSETXF 0x5434
2510 +#define TCSETXW 0x5435
2512 +#define FIONCLEX 0x5450
2513 +#define FIOCLEX 0x5451
2514 +#define FIOASYNC 0x5452
2515 +#define TIOCSERCONFIG 0x5453
2516 +#define TIOCSERGWILD 0x5454
2517 +#define TIOCSERSWILD 0x5455
2518 +#define TIOCGLCKTRMIOS 0x5456
2519 +#define TIOCSLCKTRMIOS 0x5457
2520 +#define TIOCSERGSTRUCT 0x5458
2521 +#define TIOCSERGETLSR 0x5459
2522 +#define TIOCSERGETMULTI 0x545A
2523 +#define TIOCSERSETMULTI 0x545B
2525 +#define TIOCMIWAIT 0x545C
2526 +#define TIOCGICOUNT 0x545D
2527 +#define TIOCGHAYESESP 0x545E
2528 +#define TIOCSHAYESESP 0x545F
2529 +#define FIOQSIZE 0x5460
2531 +#define TIOCPKT_DATA 0
2532 +#define TIOCPKT_FLUSHREAD 1
2533 +#define TIOCPKT_FLUSHWRITE 2
2534 +#define TIOCPKT_STOP 4
2535 +#define TIOCPKT_START 8
2536 +#define TIOCPKT_NOSTOP 16
2537 +#define TIOCPKT_DOSTOP 32
2538 +#define TIOCPKT_IOCTL 64
2540 +#define TIOCSER_TEMT 0x01
2543 + unsigned short ws_row;
2544 + unsigned short ws_col;
2545 + unsigned short ws_xpixel;
2546 + unsigned short ws_ypixel;
2549 +#define TIOCM_LE 0x001
2550 +#define TIOCM_DTR 0x002
2551 +#define TIOCM_RTS 0x004
2552 +#define TIOCM_ST 0x008
2553 +#define TIOCM_SR 0x010
2554 +#define TIOCM_CTS 0x020
2555 +#define TIOCM_CAR 0x040
2556 +#define TIOCM_RNG 0x080
2557 +#define TIOCM_DSR 0x100
2558 +#define TIOCM_CD TIOCM_CAR
2559 +#define TIOCM_RI TIOCM_RNG
2560 +#define TIOCM_OUT1 0x2000
2561 +#define TIOCM_OUT2 0x4000
2562 +#define TIOCM_LOOP 0x8000
2563 +#define TIOCM_MODEM_BITS TIOCM_OUT2
2575 +#define N_PROFIBUS_FDL 10
2577 +#define N_SMSBLOCK 12
2579 +#define N_SYNC_PPP 14
2582 +#define FIOSETOWN 0x8901
2583 +#define SIOCSPGRP 0x8902
2584 +#define FIOGETOWN 0x8903
2585 +#define SIOCGPGRP 0x8904
2586 +#define SIOCATMARK 0x8905
2587 +#define SIOCGSTAMP 0x8906
2589 +#define SIOCADDRT 0x890B
2590 +#define SIOCDELRT 0x890C
2591 +#define SIOCRTMSG 0x890D
2593 +#define SIOCGIFNAME 0x8910
2594 +#define SIOCSIFLINK 0x8911
2595 +#define SIOCGIFCONF 0x8912
2596 +#define SIOCGIFFLAGS 0x8913
2597 +#define SIOCSIFFLAGS 0x8914
2598 +#define SIOCGIFADDR 0x8915
2599 +#define SIOCSIFADDR 0x8916
2600 +#define SIOCGIFDSTADDR 0x8917
2601 +#define SIOCSIFDSTADDR 0x8918
2602 +#define SIOCGIFBRDADDR 0x8919
2603 +#define SIOCSIFBRDADDR 0x891a
2604 +#define SIOCGIFNETMASK 0x891b
2605 +#define SIOCSIFNETMASK 0x891c
2606 +#define SIOCGIFMETRIC 0x891d
2607 +#define SIOCSIFMETRIC 0x891e
2608 +#define SIOCGIFMEM 0x891f
2609 +#define SIOCSIFMEM 0x8920
2610 +#define SIOCGIFMTU 0x8921
2611 +#define SIOCSIFMTU 0x8922
2612 +#define SIOCSIFHWADDR 0x8924
2613 +#define SIOCGIFENCAP 0x8925
2614 +#define SIOCSIFENCAP 0x8926
2615 +#define SIOCGIFHWADDR 0x8927
2616 +#define SIOCGIFSLAVE 0x8929
2617 +#define SIOCSIFSLAVE 0x8930
2618 +#define SIOCADDMULTI 0x8931
2619 +#define SIOCDELMULTI 0x8932
2620 +#define SIOCGIFINDEX 0x8933
2621 +#define SIOGIFINDEX SIOCGIFINDEX
2622 +#define SIOCSIFPFLAGS 0x8934
2623 +#define SIOCGIFPFLAGS 0x8935
2624 +#define SIOCDIFADDR 0x8936
2625 +#define SIOCSIFHWBROADCAST 0x8937
2626 +#define SIOCGIFCOUNT 0x8938
2628 +#define SIOCGIFBR 0x8940
2629 +#define SIOCSIFBR 0x8941
2631 +#define SIOCGIFTXQLEN 0x8942
2632 +#define SIOCSIFTXQLEN 0x8943
2634 +#define SIOCDARP 0x8953
2635 +#define SIOCGARP 0x8954
2636 +#define SIOCSARP 0x8955
2638 +#define SIOCDRARP 0x8960
2639 +#define SIOCGRARP 0x8961
2640 +#define SIOCSRARP 0x8962
2642 +#define SIOCGIFMAP 0x8970
2643 +#define SIOCSIFMAP 0x8971
2645 +#define SIOCADDDLCI 0x8980
2646 +#define SIOCDELDLCI 0x8981
2648 +#define SIOCDEVPRIVATE 0x89F0
2649 +#define SIOCPROTOPRIVATE 0x89E0
2651 +++ b/arch/generic/bits/ipc.h
2655 + key_t __ipc_perm_key;
2661 + int __ipc_perm_seq;
2666 +#define IPC_64 0x100
2668 +++ b/arch/generic/bits/msg.h
2672 + struct ipc_perm msg_perm;
2679 + unsigned long msg_cbytes;
2680 + msgqnum_t msg_qnum;
2681 + msglen_t msg_qbytes;
2684 + unsigned long __unused[2];
2687 +++ b/arch/generic/bits/sem.h
2690 + struct ipc_perm sem_perm;
2695 +#if __BYTE_ORDER == __LITTLE_ENDIAN
2696 + unsigned short sem_nsems;
2697 + char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
2699 + char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
2700 + unsigned short sem_nsems;
2706 +++ b/arch/generic/bits/shm.h
2708 +#define SHMLBA 4096
2712 + struct ipc_perm shm_perm;
2722 + unsigned long shm_nattch;
2723 + unsigned long __pad1;
2724 + unsigned long __pad2;
2728 + unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
2733 + unsigned long shm_tot, shm_rss, shm_swp;
2734 + unsigned long __swap_attempts, __swap_successes;
2738 +++ b/arch/generic/bits/socket.h
2743 + socklen_t msg_namelen;
2744 + struct iovec *msg_iov;
2746 + void *msg_control;
2747 + socklen_t msg_controllen;
2753 + socklen_t cmsg_len;
2758 +++ b/arch/generic/bits/statfs.h
2761 + unsigned long f_type, f_bsize;
2762 + fsblkcnt_t f_blocks, f_bfree, f_bavail;
2763 + fsfilcnt_t f_files, f_ffree;
2765 + unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
2768 +++ b/arch/generic/bits/stdarg.h
2770 +#define va_start(v,l) __builtin_va_start(v,l)
2771 +#define va_end(v) __builtin_va_end(v)
2772 +#define va_arg(v,l) __builtin_va_arg(v,l)
2773 +#define va_copy(d,s) __builtin_va_copy(d,s)
2775 +++ b/arch/generic/bits/termios.h
2785 + speed_t __c_ispeed;
2786 + speed_t __c_ospeed;
2801 +#define VREPRINT 12
2802 +#define VDISCARD 13
2807 +#define IGNBRK 0000001
2808 +#define BRKINT 0000002
2809 +#define IGNPAR 0000004
2810 +#define PARMRK 0000010
2811 +#define INPCK 0000020
2812 +#define ISTRIP 0000040
2813 +#define INLCR 0000100
2814 +#define IGNCR 0000200
2815 +#define ICRNL 0000400
2816 +#define IUCLC 0001000
2817 +#define IXON 0002000
2818 +#define IXANY 0004000
2819 +#define IXOFF 0010000
2820 +#define IMAXBEL 0020000
2821 +#define IUTF8 0040000
2823 +#define OPOST 0000001
2824 +#define OLCUC 0000002
2825 +#define ONLCR 0000004
2826 +#define OCRNL 0000010
2827 +#define ONOCR 0000020
2828 +#define ONLRET 0000040
2829 +#define OFILL 0000100
2830 +#define OFDEL 0000200
2831 +#define NLDLY 0000400
2832 +#define NL0 0000000
2833 +#define NL1 0000400
2834 +#define CRDLY 0003000
2835 +#define CR0 0000000
2836 +#define CR1 0001000
2837 +#define CR2 0002000
2838 +#define CR3 0003000
2839 +#define TABDLY 0014000
2840 +#define TAB0 0000000
2841 +#define TAB1 0004000
2842 +#define TAB2 0010000
2843 +#define TAB3 0014000
2844 +#define BSDLY 0020000
2845 +#define BS0 0000000
2846 +#define BS1 0020000
2847 +#define FFDLY 0100000
2848 +#define FF0 0000000
2849 +#define FF1 0100000
2851 +#define VTDLY 0040000
2852 +#define VT0 0000000
2853 +#define VT1 0040000
2856 +#define B50 0000001
2857 +#define B75 0000002
2858 +#define B110 0000003
2859 +#define B134 0000004
2860 +#define B150 0000005
2861 +#define B200 0000006
2862 +#define B300 0000007
2863 +#define B600 0000010
2864 +#define B1200 0000011
2865 +#define B1800 0000012
2866 +#define B2400 0000013
2867 +#define B4800 0000014
2868 +#define B9600 0000015
2869 +#define B19200 0000016
2870 +#define B38400 0000017
2872 +#define B57600 0010001
2873 +#define B115200 0010002
2874 +#define B230400 0010003
2875 +#define B460800 0010004
2876 +#define B500000 0010005
2877 +#define B576000 0010006
2878 +#define B921600 0010007
2879 +#define B1000000 0010010
2880 +#define B1152000 0010011
2881 +#define B1500000 0010012
2882 +#define B2000000 0010013
2883 +#define B2500000 0010014
2884 +#define B3000000 0010015
2885 +#define B3500000 0010016
2886 +#define B4000000 0010017
2888 +#define CBAUD 0010017
2890 +#define CSIZE 0000060
2891 +#define CS5 0000000
2892 +#define CS6 0000020
2893 +#define CS7 0000040
2894 +#define CS8 0000060
2895 +#define CSTOPB 0000100
2896 +#define CREAD 0000200
2897 +#define PARENB 0000400
2898 +#define PARODD 0001000
2899 +#define HUPCL 0002000
2900 +#define CLOCAL 0004000
2902 +#define ISIG 0000001
2903 +#define ICANON 0000002
2904 +#define ECHO 0000010
2905 +#define ECHOE 0000020
2906 +#define ECHOK 0000040
2907 +#define ECHONL 0000100
2908 +#define NOFLSH 0000200
2909 +#define TOSTOP 0000400
2910 +#define IEXTEN 0100000
2912 +#define ECHOCTL 0001000
2913 +#define ECHOPRT 0002000
2914 +#define ECHOKE 0004000
2915 +#define FLUSHO 0010000
2916 +#define PENDIN 0040000
2925 +#define TCIOFLUSH 2
2928 +#define TCSADRAIN 1
2929 +#define TCSAFLUSH 2
2931 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
2932 +#define CBAUDEX 0010000
2933 +#define CRTSCTS 020000000000
2934 +#define EXTPROC 0200000
2935 +#define XTABS 0014000
2937 --- a/arch/i386/atomic.h
2940 -#ifndef _INTERNAL_ATOMIC_H
2941 -#define _INTERNAL_ATOMIC_H
2943 -#include <stdint.h>
2945 -static inline int a_ctz_64(uint64_t x)
2948 - __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; addl $32,%0\n1:"
2949 - : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
2953 -static inline int a_ctz_l(unsigned long x)
2956 - __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
2960 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
2962 - __asm__( "lock ; andl %1, (%0) ; lock ; andl %2, 4(%0)"
2963 - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
2966 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
2968 - __asm__( "lock ; orl %1, (%0) ; lock ; orl %2, 4(%0)"
2969 - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
2972 -static inline void a_or_l(volatile void *p, long v)
2974 - __asm__( "lock ; orl %1, %0"
2975 - : "=m"(*(long *)p) : "r"(v) : "memory" );
2978 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
2980 - __asm__( "lock ; cmpxchg %3, %1"
2981 - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
2985 -static inline int a_cas(volatile int *p, int t, int s)
2987 - __asm__( "lock ; cmpxchg %3, %1"
2988 - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
2992 -static inline void a_or(volatile int *p, int v)
2994 - __asm__( "lock ; orl %1, %0"
2995 - : "=m"(*p) : "r"(v) : "memory" );
2998 -static inline void a_and(volatile int *p, int v)
3000 - __asm__( "lock ; andl %1, %0"
3001 - : "=m"(*p) : "r"(v) : "memory" );
3004 -static inline int a_swap(volatile int *x, int v)
3006 - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
3010 -#define a_xchg a_swap
3012 -static inline int a_fetch_add(volatile int *x, int v)
3014 - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
3018 -static inline void a_inc(volatile int *x)
3020 - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
3023 -static inline void a_dec(volatile int *x)
3025 - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
3028 -static inline void a_store(volatile int *p, int x)
3030 - __asm__( "movl %1, %0 ; lock ; orl $0,(%%esp)" : "=m"(*p) : "r"(x) : "memory" );
3033 -static inline void a_spin()
3035 - __asm__ __volatile__( "pause" : : : "memory" );
3038 -static inline void a_barrier()
3040 - __asm__ __volatile__( "" : : : "memory" );
3043 -static inline void a_crash()
3045 - __asm__ __volatile__( "hlt" : : : "memory" );
3051 +++ b/arch/i386/atomic_arch.h
3053 +#define a_cas a_cas
3054 +static inline int a_cas(volatile int *p, int t, int s)
3056 + __asm__ __volatile__ (
3057 + "lock ; cmpxchg %3, %1"
3058 + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
3062 +#define a_swap a_swap
3063 +static inline int a_swap(volatile int *p, int v)
3065 + __asm__ __volatile__(
3067 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
3071 +#define a_fetch_add a_fetch_add
3072 +static inline int a_fetch_add(volatile int *p, int v)
3074 + __asm__ __volatile__(
3075 + "lock ; xadd %0, %1"
3076 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
3080 +#define a_and a_and
3081 +static inline void a_and(volatile int *p, int v)
3083 + __asm__ __volatile__(
3084 + "lock ; and %1, %0"
3085 + : "=m"(*p) : "r"(v) : "memory" );
3089 +static inline void a_or(volatile int *p, int v)
3091 + __asm__ __volatile__(
3092 + "lock ; or %1, %0"
3093 + : "=m"(*p) : "r"(v) : "memory" );
3096 +#define a_inc a_inc
3097 +static inline void a_inc(volatile int *p)
3099 + __asm__ __volatile__(
3101 + : "=m"(*p) : "m"(*p) : "memory" );
3104 +#define a_dec a_dec
3105 +static inline void a_dec(volatile int *p)
3107 + __asm__ __volatile__(
3109 + : "=m"(*p) : "m"(*p) : "memory" );
3112 +#define a_store a_store
3113 +static inline void a_store(volatile int *p, int x)
3115 + __asm__ __volatile__(
3116 + "mov %1, %0 ; lock ; orl $0,(%%esp)"
3117 + : "=m"(*p) : "r"(x) : "memory" );
3120 +#define a_barrier a_barrier
3121 +static inline void a_barrier()
3123 + __asm__ __volatile__( "" : : : "memory" );
3126 +#define a_pause a_pause
3127 +static inline void a_spin()
3129 + __asm__ __volatile__( "pause" : : : "memory" );
3132 +#define a_crash a_crash
3133 +static inline void a_crash()
3135 + __asm__ __volatile__( "hlt" : : : "memory" );
3138 +#define a_ctz_64 a_ctz_64
3139 +static inline int a_ctz_64(uint64_t x)
3142 + __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; add $32,%0\n1:"
3143 + : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
3147 +#define a_ctz_l a_ctz_l
3148 +static inline int a_ctz_l(unsigned long x)
3151 + __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
3154 --- a/arch/i386/bits/alltypes.h.in
3155 +++ b/arch/i386/bits/alltypes.h.in
3156 @@ -26,10 +26,12 @@ TYPEDEF long double float_t;
3157 TYPEDEF long double double_t;
3161 -TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t;
3163 +#if !defined(__cplusplus)
3164 TYPEDEF struct { _Alignas(8) long long __ll; long double __ld; } max_align_t;
3165 +#elif defined(__GNUC__)
3166 +TYPEDEF struct { __attribute__((__aligned__(8))) long long __ll; long double __ld; } max_align_t;
3168 +TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t;
3171 TYPEDEF long time_t;
3172 --- a/arch/i386/bits/errno.h
3210 -#define ENAMETOOLONG 36
3213 -#define ENOTEMPTY 39
3215 -#define EWOULDBLOCK EAGAIN
3219 -#define EL2NSYNC 45
3232 -#define EDEADLOCK EDEADLK
3246 -#define EMULTIHOP 72
3249 -#define EOVERFLOW 75
3250 -#define ENOTUNIQ 76
3257 -#define ELIBEXEC 83
3259 -#define ERESTART 85
3260 -#define ESTRPIPE 86
3262 -#define ENOTSOCK 88
3263 -#define EDESTADDRREQ 89
3264 -#define EMSGSIZE 90
3265 -#define EPROTOTYPE 91
3266 -#define ENOPROTOOPT 92
3267 -#define EPROTONOSUPPORT 93
3268 -#define ESOCKTNOSUPPORT 94
3269 -#define EOPNOTSUPP 95
3270 -#define ENOTSUP EOPNOTSUPP
3271 -#define EPFNOSUPPORT 96
3272 -#define EAFNOSUPPORT 97
3273 -#define EADDRINUSE 98
3274 -#define EADDRNOTAVAIL 99
3275 -#define ENETDOWN 100
3276 -#define ENETUNREACH 101
3277 -#define ENETRESET 102
3278 -#define ECONNABORTED 103
3279 -#define ECONNRESET 104
3280 -#define ENOBUFS 105
3281 -#define EISCONN 106
3282 -#define ENOTCONN 107
3283 -#define ESHUTDOWN 108
3284 -#define ETOOMANYREFS 109
3285 -#define ETIMEDOUT 110
3286 -#define ECONNREFUSED 111
3287 -#define EHOSTDOWN 112
3288 -#define EHOSTUNREACH 113
3289 -#define EALREADY 114
3290 -#define EINPROGRESS 115
3292 -#define EUCLEAN 117
3293 -#define ENOTNAM 118
3294 -#define ENAVAIL 119
3296 -#define EREMOTEIO 121
3298 -#define ENOMEDIUM 123
3299 -#define EMEDIUMTYPE 124
3300 -#define ECANCELED 125
3302 -#define EKEYEXPIRED 127
3303 -#define EKEYREVOKED 128
3304 -#define EKEYREJECTED 129
3305 -#define EOWNERDEAD 130
3306 -#define ENOTRECOVERABLE 131
3307 -#define ERFKILL 132
3308 -#define EHWPOISON 133
3309 --- a/arch/i386/bits/fcntl.h
3312 -#define O_CREAT 0100
3313 -#define O_EXCL 0200
3314 -#define O_NOCTTY 0400
3315 -#define O_TRUNC 01000
3316 -#define O_APPEND 02000
3317 -#define O_NONBLOCK 04000
3318 -#define O_DSYNC 010000
3319 -#define O_SYNC 04010000
3320 -#define O_RSYNC 04010000
3321 -#define O_DIRECTORY 0200000
3322 -#define O_NOFOLLOW 0400000
3323 -#define O_CLOEXEC 02000000
3325 -#define O_ASYNC 020000
3326 -#define O_DIRECT 040000
3327 -#define O_LARGEFILE 0100000
3328 -#define O_NOATIME 01000000
3329 -#define O_PATH 010000000
3330 -#define O_TMPFILE 020200000
3331 -#define O_NDELAY O_NONBLOCK
3341 -#define F_SETSIG 10
3342 -#define F_GETSIG 11
3346 -#define F_SETLKW 14
3348 -#define F_SETOWN_EX 15
3349 -#define F_GETOWN_EX 16
3351 -#define F_GETOWNER_UIDS 17
3352 --- a/arch/i386/bits/ioctl.h
3355 -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
3356 -#define _IOC_NONE 0U
3357 -#define _IOC_WRITE 1U
3358 -#define _IOC_READ 2U
3360 -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
3361 -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
3362 -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
3363 -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
3365 -#define TCGETS 0x5401
3366 -#define TCSETS 0x5402
3367 -#define TCSETSW 0x5403
3368 -#define TCSETSF 0x5404
3369 -#define TCGETA 0x5405
3370 -#define TCSETA 0x5406
3371 -#define TCSETAW 0x5407
3372 -#define TCSETAF 0x5408
3373 -#define TCSBRK 0x5409
3374 -#define TCXONC 0x540A
3375 -#define TCFLSH 0x540B
3376 -#define TIOCEXCL 0x540C
3377 -#define TIOCNXCL 0x540D
3378 -#define TIOCSCTTY 0x540E
3379 -#define TIOCGPGRP 0x540F
3380 -#define TIOCSPGRP 0x5410
3381 -#define TIOCOUTQ 0x5411
3382 -#define TIOCSTI 0x5412
3383 -#define TIOCGWINSZ 0x5413
3384 -#define TIOCSWINSZ 0x5414
3385 -#define TIOCMGET 0x5415
3386 -#define TIOCMBIS 0x5416
3387 -#define TIOCMBIC 0x5417
3388 -#define TIOCMSET 0x5418
3389 -#define TIOCGSOFTCAR 0x5419
3390 -#define TIOCSSOFTCAR 0x541A
3391 -#define FIONREAD 0x541B
3392 -#define TIOCINQ FIONREAD
3393 -#define TIOCLINUX 0x541C
3394 -#define TIOCCONS 0x541D
3395 -#define TIOCGSERIAL 0x541E
3396 -#define TIOCSSERIAL 0x541F
3397 -#define TIOCPKT 0x5420
3398 -#define FIONBIO 0x5421
3399 -#define TIOCNOTTY 0x5422
3400 -#define TIOCSETD 0x5423
3401 -#define TIOCGETD 0x5424
3402 -#define TCSBRKP 0x5425
3403 -#define TIOCTTYGSTRUCT 0x5426
3404 -#define TIOCSBRK 0x5427
3405 -#define TIOCCBRK 0x5428
3406 -#define TIOCGSID 0x5429
3407 -#define TIOCGPTN 0x80045430
3408 -#define TIOCSPTLCK 0x40045431
3409 -#define TCGETX 0x5432
3410 -#define TCSETX 0x5433
3411 -#define TCSETXF 0x5434
3412 -#define TCSETXW 0x5435
3414 -#define FIONCLEX 0x5450
3415 -#define FIOCLEX 0x5451
3416 -#define FIOASYNC 0x5452
3417 -#define TIOCSERCONFIG 0x5453
3418 -#define TIOCSERGWILD 0x5454
3419 -#define TIOCSERSWILD 0x5455
3420 -#define TIOCGLCKTRMIOS 0x5456
3421 -#define TIOCSLCKTRMIOS 0x5457
3422 -#define TIOCSERGSTRUCT 0x5458
3423 -#define TIOCSERGETLSR 0x5459
3424 -#define TIOCSERGETMULTI 0x545A
3425 -#define TIOCSERSETMULTI 0x545B
3427 -#define TIOCMIWAIT 0x545C
3428 -#define TIOCGICOUNT 0x545D
3429 -#define TIOCGHAYESESP 0x545E
3430 -#define TIOCSHAYESESP 0x545F
3431 -#define FIOQSIZE 0x5460
3433 -#define TIOCPKT_DATA 0
3434 -#define TIOCPKT_FLUSHREAD 1
3435 -#define TIOCPKT_FLUSHWRITE 2
3436 -#define TIOCPKT_STOP 4
3437 -#define TIOCPKT_START 8
3438 -#define TIOCPKT_NOSTOP 16
3439 -#define TIOCPKT_DOSTOP 32
3440 -#define TIOCPKT_IOCTL 64
3442 -#define TIOCSER_TEMT 0x01
3445 - unsigned short ws_row;
3446 - unsigned short ws_col;
3447 - unsigned short ws_xpixel;
3448 - unsigned short ws_ypixel;
3451 -#define TIOCM_LE 0x001
3452 -#define TIOCM_DTR 0x002
3453 -#define TIOCM_RTS 0x004
3454 -#define TIOCM_ST 0x008
3455 -#define TIOCM_SR 0x010
3456 -#define TIOCM_CTS 0x020
3457 -#define TIOCM_CAR 0x040
3458 -#define TIOCM_RNG 0x080
3459 -#define TIOCM_DSR 0x100
3460 -#define TIOCM_CD TIOCM_CAR
3461 -#define TIOCM_RI TIOCM_RNG
3462 -#define TIOCM_OUT1 0x2000
3463 -#define TIOCM_OUT2 0x4000
3464 -#define TIOCM_LOOP 0x8000
3465 -#define TIOCM_MODEM_BITS TIOCM_OUT2
3477 -#define N_PROFIBUS_FDL 10
3479 -#define N_SMSBLOCK 12
3481 -#define N_SYNC_PPP 14
3484 -#define FIOSETOWN 0x8901
3485 -#define SIOCSPGRP 0x8902
3486 -#define FIOGETOWN 0x8903
3487 -#define SIOCGPGRP 0x8904
3488 -#define SIOCATMARK 0x8905
3489 -#define SIOCGSTAMP 0x8906
3491 -#define SIOCADDRT 0x890B
3492 -#define SIOCDELRT 0x890C
3493 -#define SIOCRTMSG 0x890D
3495 -#define SIOCGIFNAME 0x8910
3496 -#define SIOCSIFLINK 0x8911
3497 -#define SIOCGIFCONF 0x8912
3498 -#define SIOCGIFFLAGS 0x8913
3499 -#define SIOCSIFFLAGS 0x8914
3500 -#define SIOCGIFADDR 0x8915
3501 -#define SIOCSIFADDR 0x8916
3502 -#define SIOCGIFDSTADDR 0x8917
3503 -#define SIOCSIFDSTADDR 0x8918
3504 -#define SIOCGIFBRDADDR 0x8919
3505 -#define SIOCSIFBRDADDR 0x891a
3506 -#define SIOCGIFNETMASK 0x891b
3507 -#define SIOCSIFNETMASK 0x891c
3508 -#define SIOCGIFMETRIC 0x891d
3509 -#define SIOCSIFMETRIC 0x891e
3510 -#define SIOCGIFMEM 0x891f
3511 -#define SIOCSIFMEM 0x8920
3512 -#define SIOCGIFMTU 0x8921
3513 -#define SIOCSIFMTU 0x8922
3514 -#define SIOCSIFHWADDR 0x8924
3515 -#define SIOCGIFENCAP 0x8925
3516 -#define SIOCSIFENCAP 0x8926
3517 -#define SIOCGIFHWADDR 0x8927
3518 -#define SIOCGIFSLAVE 0x8929
3519 -#define SIOCSIFSLAVE 0x8930
3520 -#define SIOCADDMULTI 0x8931
3521 -#define SIOCDELMULTI 0x8932
3522 -#define SIOCGIFINDEX 0x8933
3523 -#define SIOGIFINDEX SIOCGIFINDEX
3524 -#define SIOCSIFPFLAGS 0x8934
3525 -#define SIOCGIFPFLAGS 0x8935
3526 -#define SIOCDIFADDR 0x8936
3527 -#define SIOCSIFHWBROADCAST 0x8937
3528 -#define SIOCGIFCOUNT 0x8938
3530 -#define SIOCGIFBR 0x8940
3531 -#define SIOCSIFBR 0x8941
3533 -#define SIOCGIFTXQLEN 0x8942
3534 -#define SIOCSIFTXQLEN 0x8943
3536 -#define SIOCDARP 0x8953
3537 -#define SIOCGARP 0x8954
3538 -#define SIOCSARP 0x8955
3540 -#define SIOCDRARP 0x8960
3541 -#define SIOCGRARP 0x8961
3542 -#define SIOCSRARP 0x8962
3544 -#define SIOCGIFMAP 0x8970
3545 -#define SIOCSIFMAP 0x8971
3547 -#define SIOCADDDLCI 0x8980
3548 -#define SIOCDELDLCI 0x8981
3550 -#define SIOCDEVPRIVATE 0x89F0
3551 -#define SIOCPROTOPRIVATE 0x89E0
3552 --- a/arch/i386/bits/ipc.h
3557 - key_t __ipc_perm_key;
3563 - int __ipc_perm_seq;
3568 -#define IPC_64 0x100
3569 --- a/arch/i386/bits/mman.h
3570 +++ b/arch/i386/bits/mman.h
3573 #define MCL_CURRENT 1
3574 #define MCL_FUTURE 2
3575 +#define MCL_ONFAULT 4
3577 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
3578 #define MADV_NORMAL 0
3579 --- a/arch/i386/bits/msg.h
3584 - struct ipc_perm msg_perm;
3591 - unsigned long msg_cbytes;
3592 - msgqnum_t msg_qnum;
3593 - msglen_t msg_qbytes;
3596 - unsigned long __unused[2];
3598 --- a/arch/i386/bits/sem.h
3602 - struct ipc_perm sem_perm;
3607 -#if __BYTE_ORDER == __LITTLE_ENDIAN
3608 - unsigned short sem_nsems;
3609 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
3611 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
3612 - unsigned short sem_nsems;
3617 --- a/arch/i386/bits/shm.h
3620 -#define SHMLBA 4096
3624 - struct ipc_perm shm_perm;
3634 - unsigned long shm_nattch;
3635 - unsigned long __pad1;
3636 - unsigned long __pad2;
3640 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
3645 - unsigned long shm_tot, shm_rss, shm_swp;
3646 - unsigned long __swap_attempts, __swap_successes;
3649 --- a/arch/i386/bits/socket.h
3655 - socklen_t msg_namelen;
3656 - struct iovec *msg_iov;
3658 - void *msg_control;
3659 - socklen_t msg_controllen;
3665 - socklen_t cmsg_len;
3669 --- a/arch/i386/bits/statfs.h
3673 - unsigned long f_type, f_bsize;
3674 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
3675 - fsfilcnt_t f_files, f_ffree;
3677 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
3679 --- a/arch/i386/bits/syscall.h
3680 +++ b/arch/i386/bits/syscall.h
3681 @@ -357,6 +357,24 @@
3682 #define __NR_memfd_create 356
3683 #define __NR_bpf 357
3684 #define __NR_execveat 358
3685 +#define __NR_socket 359
3686 +#define __NR_socketpair 360
3687 +#define __NR_bind 361
3688 +#define __NR_connect 362
3689 +#define __NR_listen 363
3690 +#define __NR_accept4 364
3691 +#define __NR_getsockopt 365
3692 +#define __NR_setsockopt 366
3693 +#define __NR_getsockname 367
3694 +#define __NR_getpeername 368
3695 +#define __NR_sendto 369
3696 +#define __NR_sendmsg 370
3697 +#define __NR_recvfrom 371
3698 +#define __NR_recvmsg 372
3699 +#define __NR_shutdown 373
3700 +#define __NR_userfaultfd 374
3701 +#define __NR_membarrier 375
3702 +#define __NR_mlock2 376
3705 /* Repeated with SYS_ prefix */
3706 @@ -720,3 +738,21 @@
3707 #define SYS_memfd_create 356
3709 #define SYS_execveat 358
3710 +#define SYS_socket 359
3711 +#define SYS_socketpair 360
3712 +#define SYS_bind 361
3713 +#define SYS_connect 362
3714 +#define SYS_listen 363
3715 +#define SYS_accept4 364
3716 +#define SYS_getsockopt 365
3717 +#define SYS_setsockopt 366
3718 +#define SYS_getsockname 367
3719 +#define SYS_getpeername 368
3720 +#define SYS_sendto 369
3721 +#define SYS_sendmsg 370
3722 +#define SYS_recvfrom 371
3723 +#define SYS_recvmsg 372
3724 +#define SYS_shutdown 373
3725 +#define SYS_userfaultfd 374
3726 +#define SYS_membarrier 375
3727 +#define SYS_mlock2 376
3728 --- a/arch/i386/bits/termios.h
3739 - speed_t __c_ispeed;
3740 - speed_t __c_ospeed;
3755 -#define VREPRINT 12
3756 -#define VDISCARD 13
3761 -#define IGNBRK 0000001
3762 -#define BRKINT 0000002
3763 -#define IGNPAR 0000004
3764 -#define PARMRK 0000010
3765 -#define INPCK 0000020
3766 -#define ISTRIP 0000040
3767 -#define INLCR 0000100
3768 -#define IGNCR 0000200
3769 -#define ICRNL 0000400
3770 -#define IUCLC 0001000
3771 -#define IXON 0002000
3772 -#define IXANY 0004000
3773 -#define IXOFF 0010000
3774 -#define IMAXBEL 0020000
3775 -#define IUTF8 0040000
3777 -#define OPOST 0000001
3778 -#define OLCUC 0000002
3779 -#define ONLCR 0000004
3780 -#define OCRNL 0000010
3781 -#define ONOCR 0000020
3782 -#define ONLRET 0000040
3783 -#define OFILL 0000100
3784 -#define OFDEL 0000200
3785 -#define NLDLY 0000400
3786 -#define NL0 0000000
3787 -#define NL1 0000400
3788 -#define CRDLY 0003000
3789 -#define CR0 0000000
3790 -#define CR1 0001000
3791 -#define CR2 0002000
3792 -#define CR3 0003000
3793 -#define TABDLY 0014000
3794 -#define TAB0 0000000
3795 -#define TAB1 0004000
3796 -#define TAB2 0010000
3797 -#define TAB3 0014000
3798 -#define BSDLY 0020000
3799 -#define BS0 0000000
3800 -#define BS1 0020000
3801 -#define FFDLY 0100000
3802 -#define FF0 0000000
3803 -#define FF1 0100000
3805 -#define VTDLY 0040000
3806 -#define VT0 0000000
3807 -#define VT1 0040000
3810 -#define B50 0000001
3811 -#define B75 0000002
3812 -#define B110 0000003
3813 -#define B134 0000004
3814 -#define B150 0000005
3815 -#define B200 0000006
3816 -#define B300 0000007
3817 -#define B600 0000010
3818 -#define B1200 0000011
3819 -#define B1800 0000012
3820 -#define B2400 0000013
3821 -#define B4800 0000014
3822 -#define B9600 0000015
3823 -#define B19200 0000016
3824 -#define B38400 0000017
3826 -#define B57600 0010001
3827 -#define B115200 0010002
3828 -#define B230400 0010003
3829 -#define B460800 0010004
3830 -#define B500000 0010005
3831 -#define B576000 0010006
3832 -#define B921600 0010007
3833 -#define B1000000 0010010
3834 -#define B1152000 0010011
3835 -#define B1500000 0010012
3836 -#define B2000000 0010013
3837 -#define B2500000 0010014
3838 -#define B3000000 0010015
3839 -#define B3500000 0010016
3840 -#define B4000000 0010017
3842 -#define CBAUD 0010017
3844 -#define CSIZE 0000060
3845 -#define CS5 0000000
3846 -#define CS6 0000020
3847 -#define CS7 0000040
3848 -#define CS8 0000060
3849 -#define CSTOPB 0000100
3850 -#define CREAD 0000200
3851 -#define PARENB 0000400
3852 -#define PARODD 0001000
3853 -#define HUPCL 0002000
3854 -#define CLOCAL 0004000
3856 -#define ISIG 0000001
3857 -#define ICANON 0000002
3858 -#define ECHO 0000010
3859 -#define ECHOE 0000020
3860 -#define ECHOK 0000040
3861 -#define ECHONL 0000100
3862 -#define NOFLSH 0000200
3863 -#define TOSTOP 0000400
3864 -#define IEXTEN 0100000
3866 -#define ECHOCTL 0001000
3867 -#define ECHOPRT 0002000
3868 -#define ECHOKE 0004000
3869 -#define FLUSHO 0010000
3870 -#define PENDIN 0040000
3879 -#define TCIOFLUSH 2
3882 -#define TCSADRAIN 1
3883 -#define TCSAFLUSH 2
3885 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
3886 -#define CBAUDEX 0010000
3887 -#define CRTSCTS 020000000000
3888 -#define EXTPROC 0200000
3889 -#define XTABS 0014000
3891 --- a/arch/i386/pthread_arch.h
3892 +++ b/arch/i386/pthread_arch.h
3893 @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
3895 #define TP_ADJ(p) (p)
3897 -#define CANCEL_REG_IP 14
3898 +#define MC_PC gregs[REG_EIP]
3899 --- a/arch/i386/syscall_arch.h
3900 +++ b/arch/i386/syscall_arch.h
3901 @@ -55,3 +55,5 @@ static inline long __syscall6(long n, lo
3903 #define VDSO_CGT_SYM "__vdso_clock_gettime"
3904 #define VDSO_CGT_VER "LINUX_2.6"
3906 +#define SYSCALL_USE_SOCKETCALL
3907 --- a/arch/microblaze/atomic.h
3910 -#ifndef _INTERNAL_ATOMIC_H
3911 -#define _INTERNAL_ATOMIC_H
3913 -#include <stdint.h>
3915 -static inline int a_ctz_l(unsigned long x)
3917 - static const char debruijn32[32] = {
3918 - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
3919 - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
3921 - return debruijn32[(x&-x)*0x076be629 >> 27];
3924 -static inline int a_ctz_64(uint64_t x)
3929 - return 32 + a_ctz_l(y);
3931 - return a_ctz_l(y);
3934 -static inline int a_cas(volatile int *p, int t, int s)
3936 - register int old, tmp;
3937 - __asm__ __volatile__ (
3938 - " addi %0, r0, 0\n"
3939 - "1: lwx %0, %2, r0\n"
3940 - " rsubk %1, %0, %3\n"
3942 - " swx %4, %2, r0\n"
3943 - " addic %1, r0, 0\n"
3946 - : "=&r"(old), "=&r"(tmp)
3947 - : "r"(p), "r"(t), "r"(s)
3948 - : "cc", "memory" );
3952 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
3954 - return (void *)a_cas(p, (int)t, (int)s);
3957 -static inline int a_swap(volatile int *x, int v)
3959 - register int old, tmp;
3960 - __asm__ __volatile__ (
3961 - " addi %0, r0, 0\n"
3962 - "1: lwx %0, %2, r0\n"
3963 - " swx %3, %2, r0\n"
3964 - " addic %1, r0, 0\n"
3967 - : "=&r"(old), "=&r"(tmp)
3969 - : "cc", "memory" );
3973 -static inline int a_fetch_add(volatile int *x, int v)
3975 - register int new, tmp;
3976 - __asm__ __volatile__ (
3977 - " addi %0, r0, 0\n"
3978 - "1: lwx %0, %2, r0\n"
3979 - " addk %0, %0, %3\n"
3980 - " swx %0, %2, r0\n"
3981 - " addic %1, r0, 0\n"
3984 - : "=&r"(new), "=&r"(tmp)
3986 - : "cc", "memory" );
3990 -static inline void a_inc(volatile int *x)
3992 - a_fetch_add(x, 1);
3995 -static inline void a_dec(volatile int *x)
3997 - a_fetch_add(x, -1);
4000 -static inline void a_store(volatile int *p, int x)
4002 - __asm__ __volatile__ (
4004 - : "=m"(*p) : "r"(x) : "memory" );
4007 -#define a_spin a_barrier
4009 -static inline void a_barrier()
4011 - a_cas(&(int){0}, 0, 0);
4014 -static inline void a_crash()
4016 - *(volatile char *)0=0;
4019 -static inline void a_and(volatile int *p, int v)
4023 - while (a_cas(p, old, old&v) != old);
4026 -static inline void a_or(volatile int *p, int v)
4030 - while (a_cas(p, old, old|v) != old);
4033 -static inline void a_or_l(volatile void *p, long v)
4038 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
4040 - union { uint64_t v; uint32_t r[2]; } u = { v };
4041 - a_and((int *)p, u.r[0]);
4042 - a_and((int *)p+1, u.r[1]);
4045 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
4047 - union { uint64_t v; uint32_t r[2]; } u = { v };
4048 - a_or((int *)p, u.r[0]);
4049 - a_or((int *)p+1, u.r[1]);
4054 +++ b/arch/microblaze/atomic_arch.h
4056 +#define a_cas a_cas
4057 +static inline int a_cas(volatile int *p, int t, int s)
4059 + register int old, tmp;
4060 + __asm__ __volatile__ (
4061 + " addi %0, r0, 0\n"
4062 + "1: lwx %0, %2, r0\n"
4063 + " rsubk %1, %0, %3\n"
4065 + " swx %4, %2, r0\n"
4066 + " addic %1, r0, 0\n"
4069 + : "=&r"(old), "=&r"(tmp)
4070 + : "r"(p), "r"(t), "r"(s)
4071 + : "cc", "memory" );
4075 +#define a_swap a_swap
4076 +static inline int a_swap(volatile int *x, int v)
4078 + register int old, tmp;
4079 + __asm__ __volatile__ (
4080 + " addi %0, r0, 0\n"
4081 + "1: lwx %0, %2, r0\n"
4082 + " swx %3, %2, r0\n"
4083 + " addic %1, r0, 0\n"
4086 + : "=&r"(old), "=&r"(tmp)
4088 + : "cc", "memory" );
4092 +#define a_fetch_add a_fetch_add
4093 +static inline int a_fetch_add(volatile int *x, int v)
4095 + register int new, tmp;
4096 + __asm__ __volatile__ (
4097 + " addi %0, r0, 0\n"
4098 + "1: lwx %0, %2, r0\n"
4099 + " addk %0, %0, %3\n"
4100 + " swx %0, %2, r0\n"
4101 + " addic %1, r0, 0\n"
4104 + : "=&r"(new), "=&r"(tmp)
4106 + : "cc", "memory" );
4109 --- a/arch/microblaze/bits/errno.h
4147 -#define ENAMETOOLONG 36
4150 -#define ENOTEMPTY 39
4152 -#define EWOULDBLOCK EAGAIN
4156 -#define EL2NSYNC 45
4169 -#define EDEADLOCK EDEADLK
4183 -#define EMULTIHOP 72
4186 -#define EOVERFLOW 75
4187 -#define ENOTUNIQ 76
4194 -#define ELIBEXEC 83
4196 -#define ERESTART 85
4197 -#define ESTRPIPE 86
4199 -#define ENOTSOCK 88
4200 -#define EDESTADDRREQ 89
4201 -#define EMSGSIZE 90
4202 -#define EPROTOTYPE 91
4203 -#define ENOPROTOOPT 92
4204 -#define EPROTONOSUPPORT 93
4205 -#define ESOCKTNOSUPPORT 94
4206 -#define EOPNOTSUPP 95
4207 -#define ENOTSUP EOPNOTSUPP
4208 -#define EPFNOSUPPORT 96
4209 -#define EAFNOSUPPORT 97
4210 -#define EADDRINUSE 98
4211 -#define EADDRNOTAVAIL 99
4212 -#define ENETDOWN 100
4213 -#define ENETUNREACH 101
4214 -#define ENETRESET 102
4215 -#define ECONNABORTED 103
4216 -#define ECONNRESET 104
4217 -#define ENOBUFS 105
4218 -#define EISCONN 106
4219 -#define ENOTCONN 107
4220 -#define ESHUTDOWN 108
4221 -#define ETOOMANYREFS 109
4222 -#define ETIMEDOUT 110
4223 -#define ECONNREFUSED 111
4224 -#define EHOSTDOWN 112
4225 -#define EHOSTUNREACH 113
4226 -#define EALREADY 114
4227 -#define EINPROGRESS 115
4229 -#define EUCLEAN 117
4230 -#define ENOTNAM 118
4231 -#define ENAVAIL 119
4233 -#define EREMOTEIO 121
4235 -#define ENOMEDIUM 123
4236 -#define EMEDIUMTYPE 124
4237 -#define ECANCELED 125
4239 -#define EKEYEXPIRED 127
4240 -#define EKEYREVOKED 128
4241 -#define EKEYREJECTED 129
4242 -#define EOWNERDEAD 130
4243 -#define ENOTRECOVERABLE 131
4244 -#define ERFKILL 132
4245 -#define EHWPOISON 133
4246 --- a/arch/microblaze/bits/fcntl.h
4249 -#define O_CREAT 0100
4250 -#define O_EXCL 0200
4251 -#define O_NOCTTY 0400
4252 -#define O_TRUNC 01000
4253 -#define O_APPEND 02000
4254 -#define O_NONBLOCK 04000
4255 -#define O_DSYNC 010000
4256 -#define O_SYNC 04010000
4257 -#define O_RSYNC 04010000
4258 -#define O_DIRECTORY 0200000
4259 -#define O_NOFOLLOW 0400000
4260 -#define O_CLOEXEC 02000000
4262 -#define O_ASYNC 020000
4263 -#define O_DIRECT 040000
4264 -#define O_LARGEFILE 0100000
4265 -#define O_NOATIME 01000000
4266 -#define O_PATH 010000000
4267 -#define O_TMPFILE 020200000
4268 -#define O_NDELAY O_NONBLOCK
4278 -#define F_SETSIG 10
4279 -#define F_GETSIG 11
4283 -#define F_SETLKW 14
4285 -#define F_SETOWN_EX 15
4286 -#define F_GETOWN_EX 16
4288 -#define F_GETOWNER_UIDS 17
4289 --- a/arch/microblaze/bits/fenv.h
4292 -#define FE_ALL_EXCEPT 0
4293 -#define FE_TONEAREST 0
4295 -typedef unsigned long fexcept_t;
4298 - unsigned long __cw;
4301 -#define FE_DFL_ENV ((const fenv_t *) -1)
4302 --- a/arch/microblaze/bits/ioctl.h
4305 -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
4306 -#define _IOC_NONE 0U
4307 -#define _IOC_WRITE 1U
4308 -#define _IOC_READ 2U
4310 -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
4311 -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
4312 -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
4313 -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
4315 -#define TCGETS 0x5401
4316 -#define TCSETS 0x5402
4317 -#define TCSETSW 0x5403
4318 -#define TCSETSF 0x5404
4319 -#define TCGETA 0x5405
4320 -#define TCSETA 0x5406
4321 -#define TCSETAW 0x5407
4322 -#define TCSETAF 0x5408
4323 -#define TCSBRK 0x5409
4324 -#define TCXONC 0x540A
4325 -#define TCFLSH 0x540B
4326 -#define TIOCEXCL 0x540C
4327 -#define TIOCNXCL 0x540D
4328 -#define TIOCSCTTY 0x540E
4329 -#define TIOCGPGRP 0x540F
4330 -#define TIOCSPGRP 0x5410
4331 -#define TIOCOUTQ 0x5411
4332 -#define TIOCSTI 0x5412
4333 -#define TIOCGWINSZ 0x5413
4334 -#define TIOCSWINSZ 0x5414
4335 -#define TIOCMGET 0x5415
4336 -#define TIOCMBIS 0x5416
4337 -#define TIOCMBIC 0x5417
4338 -#define TIOCMSET 0x5418
4339 -#define TIOCGSOFTCAR 0x5419
4340 -#define TIOCSSOFTCAR 0x541A
4341 -#define FIONREAD 0x541B
4342 -#define TIOCINQ FIONREAD
4343 -#define TIOCLINUX 0x541C
4344 -#define TIOCCONS 0x541D
4345 -#define TIOCGSERIAL 0x541E
4346 -#define TIOCSSERIAL 0x541F
4347 -#define TIOCPKT 0x5420
4348 -#define FIONBIO 0x5421
4349 -#define TIOCNOTTY 0x5422
4350 -#define TIOCSETD 0x5423
4351 -#define TIOCGETD 0x5424
4352 -#define TCSBRKP 0x5425
4353 -#define TIOCTTYGSTRUCT 0x5426
4354 -#define TIOCSBRK 0x5427
4355 -#define TIOCCBRK 0x5428
4356 -#define TIOCGSID 0x5429
4357 -#define TIOCGPTN 0x80045430
4358 -#define TIOCSPTLCK 0x40045431
4359 -#define TCGETX 0x5432
4360 -#define TCSETX 0x5433
4361 -#define TCSETXF 0x5434
4362 -#define TCSETXW 0x5435
4364 -#define FIONCLEX 0x5450
4365 -#define FIOCLEX 0x5451
4366 -#define FIOASYNC 0x5452
4367 -#define TIOCSERCONFIG 0x5453
4368 -#define TIOCSERGWILD 0x5454
4369 -#define TIOCSERSWILD 0x5455
4370 -#define TIOCGLCKTRMIOS 0x5456
4371 -#define TIOCSLCKTRMIOS 0x5457
4372 -#define TIOCSERGSTRUCT 0x5458
4373 -#define TIOCSERGETLSR 0x5459
4374 -#define TIOCSERGETMULTI 0x545A
4375 -#define TIOCSERSETMULTI 0x545B
4377 -#define TIOCMIWAIT 0x545C
4378 -#define TIOCGICOUNT 0x545D
4379 -#define TIOCGHAYESESP 0x545E
4380 -#define TIOCSHAYESESP 0x545F
4381 -#define FIOQSIZE 0x5460
4383 -#define TIOCPKT_DATA 0
4384 -#define TIOCPKT_FLUSHREAD 1
4385 -#define TIOCPKT_FLUSHWRITE 2
4386 -#define TIOCPKT_STOP 4
4387 -#define TIOCPKT_START 8
4388 -#define TIOCPKT_NOSTOP 16
4389 -#define TIOCPKT_DOSTOP 32
4390 -#define TIOCPKT_IOCTL 64
4392 -#define TIOCSER_TEMT 0x01
4395 - unsigned short ws_row;
4396 - unsigned short ws_col;
4397 - unsigned short ws_xpixel;
4398 - unsigned short ws_ypixel;
4401 -#define TIOCM_LE 0x001
4402 -#define TIOCM_DTR 0x002
4403 -#define TIOCM_RTS 0x004
4404 -#define TIOCM_ST 0x008
4405 -#define TIOCM_SR 0x010
4406 -#define TIOCM_CTS 0x020
4407 -#define TIOCM_CAR 0x040
4408 -#define TIOCM_RNG 0x080
4409 -#define TIOCM_DSR 0x100
4410 -#define TIOCM_CD TIOCM_CAR
4411 -#define TIOCM_RI TIOCM_RNG
4412 -#define TIOCM_OUT1 0x2000
4413 -#define TIOCM_OUT2 0x4000
4414 -#define TIOCM_LOOP 0x8000
4415 -#define TIOCM_MODEM_BITS TIOCM_OUT2
4427 -#define N_PROFIBUS_FDL 10
4429 -#define N_SMSBLOCK 12
4431 -#define N_SYNC_PPP 14
4434 -#define FIOSETOWN 0x8901
4435 -#define SIOCSPGRP 0x8902
4436 -#define FIOGETOWN 0x8903
4437 -#define SIOCGPGRP 0x8904
4438 -#define SIOCATMARK 0x8905
4439 -#define SIOCGSTAMP 0x8906
4441 -#define SIOCADDRT 0x890B
4442 -#define SIOCDELRT 0x890C
4443 -#define SIOCRTMSG 0x890D
4445 -#define SIOCGIFNAME 0x8910
4446 -#define SIOCSIFLINK 0x8911
4447 -#define SIOCGIFCONF 0x8912
4448 -#define SIOCGIFFLAGS 0x8913
4449 -#define SIOCSIFFLAGS 0x8914
4450 -#define SIOCGIFADDR 0x8915
4451 -#define SIOCSIFADDR 0x8916
4452 -#define SIOCGIFDSTADDR 0x8917
4453 -#define SIOCSIFDSTADDR 0x8918
4454 -#define SIOCGIFBRDADDR 0x8919
4455 -#define SIOCSIFBRDADDR 0x891a
4456 -#define SIOCGIFNETMASK 0x891b
4457 -#define SIOCSIFNETMASK 0x891c
4458 -#define SIOCGIFMETRIC 0x891d
4459 -#define SIOCSIFMETRIC 0x891e
4460 -#define SIOCGIFMEM 0x891f
4461 -#define SIOCSIFMEM 0x8920
4462 -#define SIOCGIFMTU 0x8921
4463 -#define SIOCSIFMTU 0x8922
4464 -#define SIOCSIFHWADDR 0x8924
4465 -#define SIOCGIFENCAP 0x8925
4466 -#define SIOCSIFENCAP 0x8926
4467 -#define SIOCGIFHWADDR 0x8927
4468 -#define SIOCGIFSLAVE 0x8929
4469 -#define SIOCSIFSLAVE 0x8930
4470 -#define SIOCADDMULTI 0x8931
4471 -#define SIOCDELMULTI 0x8932
4472 -#define SIOCGIFINDEX 0x8933
4473 -#define SIOGIFINDEX SIOCGIFINDEX
4474 -#define SIOCSIFPFLAGS 0x8934
4475 -#define SIOCGIFPFLAGS 0x8935
4476 -#define SIOCDIFADDR 0x8936
4477 -#define SIOCSIFHWBROADCAST 0x8937
4478 -#define SIOCGIFCOUNT 0x8938
4480 -#define SIOCGIFBR 0x8940
4481 -#define SIOCSIFBR 0x8941
4483 -#define SIOCGIFTXQLEN 0x8942
4484 -#define SIOCSIFTXQLEN 0x8943
4486 -#define SIOCDARP 0x8953
4487 -#define SIOCGARP 0x8954
4488 -#define SIOCSARP 0x8955
4490 -#define SIOCDRARP 0x8960
4491 -#define SIOCGRARP 0x8961
4492 -#define SIOCSRARP 0x8962
4494 -#define SIOCGIFMAP 0x8970
4495 -#define SIOCSIFMAP 0x8971
4497 -#define SIOCADDDLCI 0x8980
4498 -#define SIOCDELDLCI 0x8981
4500 -#define SIOCDEVPRIVATE 0x89F0
4501 -#define SIOCPROTOPRIVATE 0x89E0
4502 --- a/arch/microblaze/bits/ipc.h
4507 - key_t __ipc_perm_key;
4513 - int __ipc_perm_seq;
4518 -#define IPC_64 0x100
4519 --- a/arch/microblaze/bits/mman.h
4520 +++ b/arch/microblaze/bits/mman.h
4523 #define MCL_CURRENT 1
4524 #define MCL_FUTURE 2
4525 +#define MCL_ONFAULT 4
4527 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
4528 #define MADV_NORMAL 0
4529 --- a/arch/microblaze/bits/msg.h
4534 - struct ipc_perm msg_perm;
4541 - unsigned long msg_cbytes;
4542 - msgqnum_t msg_qnum;
4543 - msglen_t msg_qbytes;
4546 - unsigned long __unused[2];
4548 --- a/arch/microblaze/bits/sem.h
4552 - struct ipc_perm sem_perm;
4557 -#if __BYTE_ORDER == __LITTLE_ENDIAN
4558 - unsigned short sem_nsems;
4559 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
4561 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
4562 - unsigned short sem_nsems;
4567 --- a/arch/microblaze/bits/shm.h
4570 -#define SHMLBA 4096
4574 - struct ipc_perm shm_perm;
4584 - unsigned long shm_nattch;
4585 - unsigned long __pad1;
4586 - unsigned long __pad2;
4590 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
4595 - unsigned long shm_tot, shm_rss, shm_swp;
4596 - unsigned long __swap_attempts, __swap_successes;
4599 --- a/arch/microblaze/bits/socket.h
4605 - socklen_t msg_namelen;
4606 - struct iovec *msg_iov;
4608 - void *msg_control;
4609 - socklen_t msg_controllen;
4615 - socklen_t cmsg_len;
4619 --- a/arch/microblaze/bits/statfs.h
4623 - unsigned long f_type, f_bsize;
4624 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
4625 - fsfilcnt_t f_files, f_ffree;
4627 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
4629 --- a/arch/microblaze/bits/stdarg.h
4632 -#define va_start(v,l) __builtin_va_start(v,l)
4633 -#define va_end(v) __builtin_va_end(v)
4634 -#define va_arg(v,l) __builtin_va_arg(v,l)
4635 -#define va_copy(d,s) __builtin_va_copy(d,s)
4636 --- a/arch/microblaze/bits/termios.h
4647 - speed_t __c_ispeed;
4648 - speed_t __c_ospeed;
4663 -#define VREPRINT 12
4664 -#define VDISCARD 13
4669 -#define IGNBRK 0000001
4670 -#define BRKINT 0000002
4671 -#define IGNPAR 0000004
4672 -#define PARMRK 0000010
4673 -#define INPCK 0000020
4674 -#define ISTRIP 0000040
4675 -#define INLCR 0000100
4676 -#define IGNCR 0000200
4677 -#define ICRNL 0000400
4678 -#define IUCLC 0001000
4679 -#define IXON 0002000
4680 -#define IXANY 0004000
4681 -#define IXOFF 0010000
4682 -#define IMAXBEL 0020000
4683 -#define IUTF8 0040000
4685 -#define OPOST 0000001
4686 -#define OLCUC 0000002
4687 -#define ONLCR 0000004
4688 -#define OCRNL 0000010
4689 -#define ONOCR 0000020
4690 -#define ONLRET 0000040
4691 -#define OFILL 0000100
4692 -#define OFDEL 0000200
4693 -#define NLDLY 0000400
4694 -#define NL0 0000000
4695 -#define NL1 0000400
4696 -#define CRDLY 0003000
4697 -#define CR0 0000000
4698 -#define CR1 0001000
4699 -#define CR2 0002000
4700 -#define CR3 0003000
4701 -#define TABDLY 0014000
4702 -#define TAB0 0000000
4703 -#define TAB1 0004000
4704 -#define TAB2 0010000
4705 -#define TAB3 0014000
4706 -#define BSDLY 0020000
4707 -#define BS0 0000000
4708 -#define BS1 0020000
4709 -#define FFDLY 0100000
4710 -#define FF0 0000000
4711 -#define FF1 0100000
4713 -#define VTDLY 0040000
4714 -#define VT0 0000000
4715 -#define VT1 0040000
4718 -#define B50 0000001
4719 -#define B75 0000002
4720 -#define B110 0000003
4721 -#define B134 0000004
4722 -#define B150 0000005
4723 -#define B200 0000006
4724 -#define B300 0000007
4725 -#define B600 0000010
4726 -#define B1200 0000011
4727 -#define B1800 0000012
4728 -#define B2400 0000013
4729 -#define B4800 0000014
4730 -#define B9600 0000015
4731 -#define B19200 0000016
4732 -#define B38400 0000017
4734 -#define B57600 0010001
4735 -#define B115200 0010002
4736 -#define B230400 0010003
4737 -#define B460800 0010004
4738 -#define B500000 0010005
4739 -#define B576000 0010006
4740 -#define B921600 0010007
4741 -#define B1000000 0010010
4742 -#define B1152000 0010011
4743 -#define B1500000 0010012
4744 -#define B2000000 0010013
4745 -#define B2500000 0010014
4746 -#define B3000000 0010015
4747 -#define B3500000 0010016
4748 -#define B4000000 0010017
4750 -#define CBAUD 0010017
4752 -#define CSIZE 0000060
4753 -#define CS5 0000000
4754 -#define CS6 0000020
4755 -#define CS7 0000040
4756 -#define CS8 0000060
4757 -#define CSTOPB 0000100
4758 -#define CREAD 0000200
4759 -#define PARENB 0000400
4760 -#define PARODD 0001000
4761 -#define HUPCL 0002000
4762 -#define CLOCAL 0004000
4764 -#define ISIG 0000001
4765 -#define ICANON 0000002
4766 -#define ECHO 0000010
4767 -#define ECHOE 0000020
4768 -#define ECHOK 0000040
4769 -#define ECHONL 0000100
4770 -#define NOFLSH 0000200
4771 -#define TOSTOP 0000400
4772 -#define IEXTEN 0100000
4774 -#define ECHOCTL 0001000
4775 -#define ECHOPRT 0002000
4776 -#define ECHOKE 0004000
4777 -#define FLUSHO 0010000
4778 -#define PENDIN 0040000
4787 -#define TCIOFLUSH 2
4790 -#define TCSADRAIN 1
4791 -#define TCSAFLUSH 2
4793 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
4794 -#define CBAUDEX 0010000
4795 -#define CRTSCTS 020000000000
4796 -#define EXTPROC 0200000
4797 -#define XTABS 0014000
4799 --- a/arch/microblaze/pthread_arch.h
4800 +++ b/arch/microblaze/pthread_arch.h
4801 @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
4803 #define TP_ADJ(p) (p)
4805 -#define CANCEL_REG_IP 32
4806 +#define MC_PC regs.pc
4807 --- a/arch/mips/atomic.h
4810 -#ifndef _INTERNAL_ATOMIC_H
4811 -#define _INTERNAL_ATOMIC_H
4813 -#include <stdint.h>
4815 -static inline int a_ctz_l(unsigned long x)
4817 - static const char debruijn32[32] = {
4818 - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
4819 - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
4821 - return debruijn32[(x&-x)*0x076be629 >> 27];
4824 -static inline int a_ctz_64(uint64_t x)
4829 - return 32 + a_ctz_l(y);
4831 - return a_ctz_l(y);
4834 -static inline int a_cas(volatile int *p, int t, int s)
4837 - __asm__ __volatile__(
4840 - ".set noreorder\n"
4843 - " bne %0, %3, 1f\n"
4844 - " addu %1, %4, $0\n"
4846 - " beq %1, $0, 1b\n"
4851 - : "=&r"(t), "=&r"(dummy), "+m"(*p) : "r"(t), "r"(s) : "memory" );
4855 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
4857 - return (void *)a_cas(p, (int)t, (int)s);
4860 -static inline int a_swap(volatile int *x, int v)
4863 - __asm__ __volatile__(
4866 - ".set noreorder\n"
4869 - " addu %1, %3, $0\n"
4871 - " beq %1, $0, 1b\n"
4875 - : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
4879 -static inline int a_fetch_add(volatile int *x, int v)
4882 - __asm__ __volatile__(
4885 - ".set noreorder\n"
4888 - " addu %1, %0, %3\n"
4890 - " beq %1, $0, 1b\n"
4894 - : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
4898 -static inline void a_inc(volatile int *x)
4901 - __asm__ __volatile__(
4904 - ".set noreorder\n"
4907 - " addu %0, %0, 1\n"
4909 - " beq %0, $0, 1b\n"
4913 - : "=&r"(dummy), "+m"(*x) : : "memory" );
4916 -static inline void a_dec(volatile int *x)
4919 - __asm__ __volatile__(
4922 - ".set noreorder\n"
4925 - " subu %0, %0, 1\n"
4927 - " beq %0, $0, 1b\n"
4931 - : "=&r"(dummy), "+m"(*x) : : "memory" );
4934 -static inline void a_store(volatile int *p, int x)
4936 - __asm__ __volatile__(
4939 - ".set noreorder\n"
4944 - : "+m"(*p) : "r"(x) : "memory" );
4947 -#define a_spin a_barrier
4949 -static inline void a_barrier()
4951 - a_cas(&(int){0}, 0, 0);
4954 -static inline void a_crash()
4956 - *(volatile char *)0=0;
4959 -static inline void a_and(volatile int *p, int v)
4962 - __asm__ __volatile__(
4965 - ".set noreorder\n"
4968 - " and %0, %0, %2\n"
4970 - " beq %0, $0, 1b\n"
4974 - : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
4977 -static inline void a_or(volatile int *p, int v)
4980 - __asm__ __volatile__(
4983 - ".set noreorder\n"
4986 - " or %0, %0, %2\n"
4988 - " beq %0, $0, 1b\n"
4992 - : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
4995 -static inline void a_or_l(volatile void *p, long v)
5000 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
5002 - union { uint64_t v; uint32_t r[2]; } u = { v };
5003 - a_and((int *)p, u.r[0]);
5004 - a_and((int *)p+1, u.r[1]);
5007 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
5009 - union { uint64_t v; uint32_t r[2]; } u = { v };
5010 - a_or((int *)p, u.r[0]);
5011 - a_or((int *)p+1, u.r[1]);
5016 +++ b/arch/mips/atomic_arch.h
5019 +static inline int a_ll(volatile int *p)
5022 + __asm__ __volatile__ (
5023 + ".set push ; .set mips2\n\t"
5026 + : "=r"(v) : "m"(*p));
5031 +static inline int a_sc(volatile int *p, int v)
5034 + __asm__ __volatile__ (
5035 + ".set push ; .set mips2\n\t"
5038 + : "=r"(r), "=m"(*p) : "0"(v) : "memory");
5042 +#define a_barrier a_barrier
5043 +static inline void a_barrier()
5045 + /* mips2 sync, but using too many directives causes
5046 + * gcc not to inline it, so encode with .long instead. */
5047 + __asm__ __volatile__ (".long 0xf" : : : "memory");
5049 + __asm__ __volatile__ (
5050 + ".set push ; .set mips2 ; sync ; .set pop"
5055 +#define a_pre_llsc a_barrier
5056 +#define a_post_llsc a_barrier
5057 --- a/arch/mips/bits/ipc.h
5062 - key_t __ipc_perm_key;
5068 - int __ipc_perm_seq;
5073 -#define IPC_64 0x100
5074 --- a/arch/mips/bits/mman.h
5075 +++ b/arch/mips/bits/mman.h
5078 #define MCL_CURRENT 1
5079 #define MCL_FUTURE 2
5080 +#define MCL_ONFAULT 4
5082 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
5083 #define MADV_NORMAL 0
5084 --- a/arch/mips/bits/signal.h
5085 +++ b/arch/mips/bits/signal.h
5086 @@ -73,6 +73,15 @@ typedef struct __ucontext {
5087 #define SIG_UNBLOCK 2
5088 #define SIG_SETMASK 3
5093 +#define SI_ASYNCIO (-2)
5094 +#define SI_MESGQ (-4)
5095 +#define SI_TIMER (-3)
5097 +#define __SI_SWAP_ERRNO_CODE
5102 --- a/arch/mips/bits/stdarg.h
5105 -#define va_start(v,l) __builtin_va_start(v,l)
5106 -#define va_end(v) __builtin_va_end(v)
5107 -#define va_arg(v,l) __builtin_va_arg(v,l)
5108 -#define va_copy(d,s) __builtin_va_copy(d,s)
5109 --- a/arch/mips/bits/syscall.h
5110 +++ b/arch/mips/bits/syscall.h
5112 #define __NR_memfd_create 4354
5113 #define __NR_bpf 4355
5114 #define __NR_execveat 4356
5115 +#define __NR_userfaultfd 4357
5116 +#define __NR_membarrier 4358
5117 +#define __NR_mlock2 4359
5120 /* Repeated with SYS_ prefix */
5122 #define SYS_memfd_create 4354
5123 #define SYS_bpf 4355
5124 #define SYS_execveat 4356
5125 +#define SYS_userfaultfd 4357
5126 +#define SYS_membarrier 4358
5127 +#define SYS_mlock2 4359
5128 --- a/arch/mips/crt_arch.h
5129 +++ b/arch/mips/crt_arch.h
5130 @@ -4,13 +4,16 @@ __asm__(
5132 ".global _" START "\n"
5133 ".global " START "\n"
5134 +".global " START "_data\n"
5135 ".type _" START ", @function\n"
5136 ".type " START ", @function\n"
5137 +".type " START "_data, @function\n"
5143 +"" START "_data: \n"
5144 +" .gpword " START "_data \n"
5145 " .gpword " START "_c \n"
5147 ".hidden _DYNAMIC \n"
5148 --- a/arch/mips/pthread_arch.h
5149 +++ b/arch/mips/pthread_arch.h
5150 @@ -16,4 +16,4 @@ static inline struct pthread *__pthread_
5152 #define DTP_OFFSET 0x8000
5154 -#define CANCEL_REG_IP (3-(union {int __i; char __b;}){1}.__b)
5156 --- a/arch/mips/syscall_arch.h
5157 +++ b/arch/mips/syscall_arch.h
5159 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
5160 #define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
5163 __attribute__((visibility("hidden")))
5165 long (__syscall)(long, ...);
5167 #define SYSCALL_RLIM_INFINITY (-1UL/2)
5168 @@ -163,3 +161,7 @@ static inline long __syscall6(long n, lo
5169 if (n == SYS_fstatat) __stat_fix(c);
5173 +#define VDSO_USEFUL
5174 +#define VDSO_CGT_SYM "__vdso_clock_gettime"
5175 +#define VDSO_CGT_VER "LINUX_2.6"
5176 --- a/arch/or1k/atomic.h
5179 -#ifndef _INTERNAL_ATOMIC_H
5180 -#define _INTERNAL_ATOMIC_H
5182 -#include <stdint.h>
5184 -static inline int a_ctz_l(unsigned long x)
5186 - static const char debruijn32[32] = {
5187 - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
5188 - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
5190 - return debruijn32[(x&-x)*0x076be629 >> 27];
5193 -static inline int a_ctz_64(uint64_t x)
5198 - return 32 + a_ctz_l(y);
5200 - return a_ctz_l(y);
5203 -static inline int a_cas(volatile int *p, int t, int s)
5205 - __asm__("1: l.lwa %0, %1\n"
5206 - " l.sfeq %0, %2\n"
5213 - : "=&r"(t), "+m"(*p) : "r"(t), "r"(s) : "cc", "memory" );
5217 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
5219 - return (void *)a_cas(p, (int)t, (int)s);
5222 -static inline int a_swap(volatile int *x, int v)
5226 - while (a_cas(x, old, v) != old);
5230 -static inline int a_fetch_add(volatile int *x, int v)
5234 - while (a_cas(x, old, old+v) != old);
5238 -static inline void a_inc(volatile int *x)
5240 - a_fetch_add(x, 1);
5243 -static inline void a_dec(volatile int *x)
5245 - a_fetch_add(x, -1);
5248 -static inline void a_store(volatile int *p, int x)
5253 -#define a_spin a_barrier
5255 -static inline void a_barrier()
5257 - a_cas(&(int){0}, 0, 0);
5260 -static inline void a_crash()
5262 - *(volatile char *)0=0;
5265 -static inline void a_and(volatile int *p, int v)
5269 - while (a_cas(p, old, old&v) != old);
5272 -static inline void a_or(volatile int *p, int v)
5276 - while (a_cas(p, old, old|v) != old);
5279 -static inline void a_or_l(volatile void *p, long v)
5284 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
5286 - union { uint64_t v; uint32_t r[2]; } u = { v };
5287 - a_and((int *)p, u.r[0]);
5288 - a_and((int *)p+1, u.r[1]);
5291 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
5293 - union { uint64_t v; uint32_t r[2]; } u = { v };
5294 - a_or((int *)p, u.r[0]);
5295 - a_or((int *)p+1, u.r[1]);
5300 +++ b/arch/or1k/atomic_arch.h
5302 +#define a_cas a_cas
5303 +static inline int a_cas(volatile int *p, int t, int s)
5305 + __asm__("1: l.lwa %0, %1\n"
5306 + " l.sfeq %0, %2\n"
5313 + : "=&r"(t), "+m"(*p) : "r"(t), "r"(s) : "cc", "memory" );
5316 --- a/arch/or1k/bits/errno.h
5354 -#define ENAMETOOLONG 36
5357 -#define ENOTEMPTY 39
5359 -#define EWOULDBLOCK EAGAIN
5363 -#define EL2NSYNC 45
5376 -#define EDEADLOCK EDEADLK
5390 -#define EMULTIHOP 72
5393 -#define EOVERFLOW 75
5394 -#define ENOTUNIQ 76
5401 -#define ELIBEXEC 83
5403 -#define ERESTART 85
5404 -#define ESTRPIPE 86
5406 -#define ENOTSOCK 88
5407 -#define EDESTADDRREQ 89
5408 -#define EMSGSIZE 90
5409 -#define EPROTOTYPE 91
5410 -#define ENOPROTOOPT 92
5411 -#define EPROTONOSUPPORT 93
5412 -#define ESOCKTNOSUPPORT 94
5413 -#define EOPNOTSUPP 95
5414 -#define ENOTSUP EOPNOTSUPP
5415 -#define EPFNOSUPPORT 96
5416 -#define EAFNOSUPPORT 97
5417 -#define EADDRINUSE 98
5418 -#define EADDRNOTAVAIL 99
5419 -#define ENETDOWN 100
5420 -#define ENETUNREACH 101
5421 -#define ENETRESET 102
5422 -#define ECONNABORTED 103
5423 -#define ECONNRESET 104
5424 -#define ENOBUFS 105
5425 -#define EISCONN 106
5426 -#define ENOTCONN 107
5427 -#define ESHUTDOWN 108
5428 -#define ETOOMANYREFS 109
5429 -#define ETIMEDOUT 110
5430 -#define ECONNREFUSED 111
5431 -#define EHOSTDOWN 112
5432 -#define EHOSTUNREACH 113
5433 -#define EALREADY 114
5434 -#define EINPROGRESS 115
5436 -#define EUCLEAN 117
5437 -#define ENOTNAM 118
5438 -#define ENAVAIL 119
5440 -#define EREMOTEIO 121
5442 -#define ENOMEDIUM 123
5443 -#define EMEDIUMTYPE 124
5444 -#define ECANCELED 125
5446 -#define EKEYEXPIRED 127
5447 -#define EKEYREVOKED 128
5448 -#define EKEYREJECTED 129
5449 -#define EOWNERDEAD 130
5450 -#define ENOTRECOVERABLE 131
5451 -#define ERFKILL 132
5452 -#define EHWPOISON 133
5453 --- a/arch/or1k/bits/fcntl.h
5456 -#define O_CREAT 0100
5457 -#define O_EXCL 0200
5458 -#define O_NOCTTY 0400
5459 -#define O_TRUNC 01000
5460 -#define O_APPEND 02000
5461 -#define O_NONBLOCK 04000
5462 -#define O_DSYNC 010000
5463 -#define O_SYNC 04010000
5464 -#define O_RSYNC 04010000
5465 -#define O_DIRECTORY 0200000
5466 -#define O_NOFOLLOW 0400000
5467 -#define O_CLOEXEC 02000000
5469 -#define O_ASYNC 020000
5470 -#define O_DIRECT 040000
5471 -#define O_LARGEFILE 0100000
5472 -#define O_NOATIME 01000000
5473 -#define O_PATH 010000000
5474 -#define O_TMPFILE 020200000
5475 -#define O_NDELAY O_NONBLOCK
5485 -#define F_SETSIG 10
5486 -#define F_GETSIG 11
5490 -#define F_SETLKW 14
5492 -#define F_SETOWN_EX 15
5493 -#define F_GETOWN_EX 16
5495 -#define F_GETOWNER_UIDS 17
5496 --- a/arch/or1k/bits/fenv.h
5499 -#define FE_ALL_EXCEPT 0
5500 -#define FE_TONEAREST 0
5502 -typedef unsigned long fexcept_t;
5505 - unsigned long __cw;
5508 -#define FE_DFL_ENV ((const fenv_t *) -1)
5509 --- a/arch/or1k/bits/ioctl.h
5512 -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) )
5513 -#define _IOC_NONE 0U
5514 -#define _IOC_WRITE 1U
5515 -#define _IOC_READ 2U
5517 -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0)
5518 -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c))
5519 -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c))
5520 -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c))
5522 -#define TCGETS 0x5401
5523 -#define TCSETS 0x5402
5524 -#define TCSETSW 0x5403
5525 -#define TCSETSF 0x5404
5526 -#define TCGETA 0x5405
5527 -#define TCSETA 0x5406
5528 -#define TCSETAW 0x5407
5529 -#define TCSETAF 0x5408
5530 -#define TCSBRK 0x5409
5531 -#define TCXONC 0x540A
5532 -#define TCFLSH 0x540B
5533 -#define TIOCEXCL 0x540C
5534 -#define TIOCNXCL 0x540D
5535 -#define TIOCSCTTY 0x540E
5536 -#define TIOCGPGRP 0x540F
5537 -#define TIOCSPGRP 0x5410
5538 -#define TIOCOUTQ 0x5411
5539 -#define TIOCSTI 0x5412
5540 -#define TIOCGWINSZ 0x5413
5541 -#define TIOCSWINSZ 0x5414
5542 -#define TIOCMGET 0x5415
5543 -#define TIOCMBIS 0x5416
5544 -#define TIOCMBIC 0x5417
5545 -#define TIOCMSET 0x5418
5546 -#define TIOCGSOFTCAR 0x5419
5547 -#define TIOCSSOFTCAR 0x541A
5548 -#define FIONREAD 0x541B
5549 -#define TIOCINQ FIONREAD
5550 -#define TIOCLINUX 0x541C
5551 -#define TIOCCONS 0x541D
5552 -#define TIOCGSERIAL 0x541E
5553 -#define TIOCSSERIAL 0x541F
5554 -#define TIOCPKT 0x5420
5555 -#define FIONBIO 0x5421
5556 -#define TIOCNOTTY 0x5422
5557 -#define TIOCSETD 0x5423
5558 -#define TIOCGETD 0x5424
5559 -#define TCSBRKP 0x5425
5560 -#define TIOCTTYGSTRUCT 0x5426
5561 -#define TIOCSBRK 0x5427
5562 -#define TIOCCBRK 0x5428
5563 -#define TIOCGSID 0x5429
5564 -#define TIOCGPTN 0x80045430
5565 -#define TIOCSPTLCK 0x40045431
5566 -#define TCGETX 0x5432
5567 -#define TCSETX 0x5433
5568 -#define TCSETXF 0x5434
5569 -#define TCSETXW 0x5435
5571 -#define FIONCLEX 0x5450
5572 -#define FIOCLEX 0x5451
5573 -#define FIOASYNC 0x5452
5574 -#define TIOCSERCONFIG 0x5453
5575 -#define TIOCSERGWILD 0x5454
5576 -#define TIOCSERSWILD 0x5455
5577 -#define TIOCGLCKTRMIOS 0x5456
5578 -#define TIOCSLCKTRMIOS 0x5457
5579 -#define TIOCSERGSTRUCT 0x5458
5580 -#define TIOCSERGETLSR 0x5459
5581 -#define TIOCSERGETMULTI 0x545A
5582 -#define TIOCSERSETMULTI 0x545B
5584 -#define TIOCMIWAIT 0x545C
5585 -#define TIOCGICOUNT 0x545D
5586 -#define TIOCGHAYESESP 0x545E
5587 -#define TIOCSHAYESESP 0x545F
5588 -#define FIOQSIZE 0x5460
5590 -#define TIOCPKT_DATA 0
5591 -#define TIOCPKT_FLUSHREAD 1
5592 -#define TIOCPKT_FLUSHWRITE 2
5593 -#define TIOCPKT_STOP 4
5594 -#define TIOCPKT_START 8
5595 -#define TIOCPKT_NOSTOP 16
5596 -#define TIOCPKT_DOSTOP 32
5597 -#define TIOCPKT_IOCTL 64
5599 -#define TIOCSER_TEMT 0x01
5602 - unsigned short ws_row;
5603 - unsigned short ws_col;
5604 - unsigned short ws_xpixel;
5605 - unsigned short ws_ypixel;
5608 -#define TIOCM_LE 0x001
5609 -#define TIOCM_DTR 0x002
5610 -#define TIOCM_RTS 0x004
5611 -#define TIOCM_ST 0x008
5612 -#define TIOCM_SR 0x010
5613 -#define TIOCM_CTS 0x020
5614 -#define TIOCM_CAR 0x040
5615 -#define TIOCM_RNG 0x080
5616 -#define TIOCM_DSR 0x100
5617 -#define TIOCM_CD TIOCM_CAR
5618 -#define TIOCM_RI TIOCM_RNG
5619 -#define TIOCM_OUT1 0x2000
5620 -#define TIOCM_OUT2 0x4000
5621 -#define TIOCM_LOOP 0x8000
5622 -#define TIOCM_MODEM_BITS TIOCM_OUT2
5634 -#define N_PROFIBUS_FDL 10
5636 -#define N_SMSBLOCK 12
5638 -#define N_SYNC_PPP 14
5641 -#define FIOSETOWN 0x8901
5642 -#define SIOCSPGRP 0x8902
5643 -#define FIOGETOWN 0x8903
5644 -#define SIOCGPGRP 0x8904
5645 -#define SIOCATMARK 0x8905
5646 -#define SIOCGSTAMP 0x8906
5648 -#define SIOCADDRT 0x890B
5649 -#define SIOCDELRT 0x890C
5650 -#define SIOCRTMSG 0x890D
5652 -#define SIOCGIFNAME 0x8910
5653 -#define SIOCSIFLINK 0x8911
5654 -#define SIOCGIFCONF 0x8912
5655 -#define SIOCGIFFLAGS 0x8913
5656 -#define SIOCSIFFLAGS 0x8914
5657 -#define SIOCGIFADDR 0x8915
5658 -#define SIOCSIFADDR 0x8916
5659 -#define SIOCGIFDSTADDR 0x8917
5660 -#define SIOCSIFDSTADDR 0x8918
5661 -#define SIOCGIFBRDADDR 0x8919
5662 -#define SIOCSIFBRDADDR 0x891a
5663 -#define SIOCGIFNETMASK 0x891b
5664 -#define SIOCSIFNETMASK 0x891c
5665 -#define SIOCGIFMETRIC 0x891d
5666 -#define SIOCSIFMETRIC 0x891e
5667 -#define SIOCGIFMEM 0x891f
5668 -#define SIOCSIFMEM 0x8920
5669 -#define SIOCGIFMTU 0x8921
5670 -#define SIOCSIFMTU 0x8922
5671 -#define SIOCSIFHWADDR 0x8924
5672 -#define SIOCGIFENCAP 0x8925
5673 -#define SIOCSIFENCAP 0x8926
5674 -#define SIOCGIFHWADDR 0x8927
5675 -#define SIOCGIFSLAVE 0x8929
5676 -#define SIOCSIFSLAVE 0x8930
5677 -#define SIOCADDMULTI 0x8931
5678 -#define SIOCDELMULTI 0x8932
5679 -#define SIOCGIFINDEX 0x8933
5680 -#define SIOGIFINDEX SIOCGIFINDEX
5681 -#define SIOCSIFPFLAGS 0x8934
5682 -#define SIOCGIFPFLAGS 0x8935
5683 -#define SIOCDIFADDR 0x8936
5684 -#define SIOCSIFHWBROADCAST 0x8937
5685 -#define SIOCGIFCOUNT 0x8938
5687 -#define SIOCGIFBR 0x8940
5688 -#define SIOCSIFBR 0x8941
5690 -#define SIOCGIFTXQLEN 0x8942
5691 -#define SIOCSIFTXQLEN 0x8943
5693 -#define SIOCDARP 0x8953
5694 -#define SIOCGARP 0x8954
5695 -#define SIOCSARP 0x8955
5697 -#define SIOCDRARP 0x8960
5698 -#define SIOCGRARP 0x8961
5699 -#define SIOCSRARP 0x8962
5701 -#define SIOCGIFMAP 0x8970
5702 -#define SIOCSIFMAP 0x8971
5704 -#define SIOCADDDLCI 0x8980
5705 -#define SIOCDELDLCI 0x8981
5707 -#define SIOCDEVPRIVATE 0x89F0
5708 -#define SIOCPROTOPRIVATE 0x89E0
5709 --- a/arch/or1k/bits/mman.h
5710 +++ b/arch/or1k/bits/mman.h
5713 #define MCL_CURRENT 1
5714 #define MCL_FUTURE 2
5715 +#define MCL_ONFAULT 4
5717 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
5718 #define MADV_NORMAL 0
5719 --- a/arch/or1k/bits/shm.h
5722 -#define SHMLBA 4096
5725 - struct ipc_perm shm_perm;
5735 - unsigned long shm_nattch;
5736 - unsigned long __pad1;
5737 - unsigned long __pad2;
5741 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
5746 - unsigned long shm_tot, shm_rss, shm_swp;
5747 - unsigned long __swap_attempts, __swap_successes;
5749 --- a/arch/or1k/bits/socket.h
5754 - socklen_t msg_namelen;
5755 - struct iovec *msg_iov;
5757 - void *msg_control;
5758 - socklen_t msg_controllen;
5763 - socklen_t cmsg_len;
5767 --- a/arch/or1k/bits/statfs.h
5771 - unsigned long f_type, f_bsize;
5772 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
5773 - fsfilcnt_t f_files, f_ffree;
5775 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
5777 --- a/arch/or1k/bits/stdarg.h
5780 -#define va_start(v,l) __builtin_va_start(v,l)
5781 -#define va_end(v) __builtin_va_end(v)
5782 -#define va_arg(v,l) __builtin_va_arg(v,l)
5783 -#define va_copy(d,s) __builtin_va_copy(d,s)
5784 --- a/arch/or1k/bits/syscall.h
5785 +++ b/arch/or1k/bits/syscall.h
5787 #define __NR_memfd_create 279
5788 #define __NR_bpf 280
5789 #define __NR_execveat 281
5790 +#define __NR_userfaultfd 282
5791 +#define __NR_membarrier 283
5792 +#define __NR_mlock2 284
5794 #define SYS_io_setup __NR_io_setup
5795 #define SYS_io_destroy __NR_io_destroy
5797 #define SYS_memfd_create __NR_memfd_create
5798 #define SYS_bpf __NR_bpf
5799 #define SYS_execveat __NR_execveat
5800 +#define SYS_userfaultfd __NR_userfaultfd
5801 +#define SYS_membarrier __NR_membarrier
5802 +#define SYS_mlock2 __NR_mlock2
5803 --- a/arch/or1k/bits/termios.h
5813 - speed_t __c_ispeed;
5814 - speed_t __c_ospeed;
5829 -#define VREPRINT 12
5830 -#define VDISCARD 13
5835 -#define IGNBRK 0000001
5836 -#define BRKINT 0000002
5837 -#define IGNPAR 0000004
5838 -#define PARMRK 0000010
5839 -#define INPCK 0000020
5840 -#define ISTRIP 0000040
5841 -#define INLCR 0000100
5842 -#define IGNCR 0000200
5843 -#define ICRNL 0000400
5844 -#define IUCLC 0001000
5845 -#define IXON 0002000
5846 -#define IXANY 0004000
5847 -#define IXOFF 0010000
5848 -#define IMAXBEL 0020000
5849 -#define IUTF8 0040000
5851 -#define OPOST 0000001
5852 -#define OLCUC 0000002
5853 -#define ONLCR 0000004
5854 -#define OCRNL 0000010
5855 -#define ONOCR 0000020
5856 -#define ONLRET 0000040
5857 -#define OFILL 0000100
5858 -#define OFDEL 0000200
5859 -#define NLDLY 0000400
5860 -#define NL0 0000000
5861 -#define NL1 0000400
5862 -#define CRDLY 0003000
5863 -#define CR0 0000000
5864 -#define CR1 0001000
5865 -#define CR2 0002000
5866 -#define CR3 0003000
5867 -#define TABDLY 0014000
5868 -#define TAB0 0000000
5869 -#define TAB1 0004000
5870 -#define TAB2 0010000
5871 -#define TAB3 0014000
5872 -#define BSDLY 0020000
5873 -#define BS0 0000000
5874 -#define BS1 0020000
5875 -#define FFDLY 0100000
5876 -#define FF0 0000000
5877 -#define FF1 0100000
5879 -#define VTDLY 0040000
5880 -#define VT0 0000000
5881 -#define VT1 0040000
5884 -#define B50 0000001
5885 -#define B75 0000002
5886 -#define B110 0000003
5887 -#define B134 0000004
5888 -#define B150 0000005
5889 -#define B200 0000006
5890 -#define B300 0000007
5891 -#define B600 0000010
5892 -#define B1200 0000011
5893 -#define B1800 0000012
5894 -#define B2400 0000013
5895 -#define B4800 0000014
5896 -#define B9600 0000015
5897 -#define B19200 0000016
5898 -#define B38400 0000017
5900 -#define B57600 0010001
5901 -#define B115200 0010002
5902 -#define B230400 0010003
5903 -#define B460800 0010004
5904 -#define B500000 0010005
5905 -#define B576000 0010006
5906 -#define B921600 0010007
5907 -#define B1000000 0010010
5908 -#define B1152000 0010011
5909 -#define B1500000 0010012
5910 -#define B2000000 0010013
5911 -#define B2500000 0010014
5912 -#define B3000000 0010015
5913 -#define B3500000 0010016
5914 -#define B4000000 0010017
5916 -#define CBAUD 0010017
5918 -#define CSIZE 0000060
5919 -#define CS5 0000000
5920 -#define CS6 0000020
5921 -#define CS7 0000040
5922 -#define CS8 0000060
5923 -#define CSTOPB 0000100
5924 -#define CREAD 0000200
5925 -#define PARENB 0000400
5926 -#define PARODD 0001000
5927 -#define HUPCL 0002000
5928 -#define CLOCAL 0004000
5930 -#define ISIG 0000001
5931 -#define ICANON 0000002
5932 -#define ECHO 0000010
5933 -#define ECHOE 0000020
5934 -#define ECHOK 0000040
5935 -#define ECHONL 0000100
5936 -#define NOFLSH 0000200
5937 -#define TOSTOP 0000400
5938 -#define IEXTEN 0100000
5940 -#define ECHOCTL 0001000
5941 -#define ECHOPRT 0002000
5942 -#define ECHOKE 0004000
5943 -#define FLUSHO 0010000
5944 -#define PENDIN 0040000
5953 -#define TCIOFLUSH 2
5956 -#define TCSADRAIN 1
5957 -#define TCSAFLUSH 2
5959 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
5960 -#define CBAUDEX 0010000
5961 -#define CRTSCTS 020000000000
5962 -#define EXTPROC 0200000
5963 -#define XTABS 0014000
5965 --- a/arch/or1k/pthread_arch.h
5966 +++ b/arch/or1k/pthread_arch.h
5967 @@ -14,5 +14,4 @@ static inline struct pthread *__pthread_
5968 #define TLS_ABOVE_TP
5969 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread))
5971 -/* word-offset to 'pc' in mcontext_t */
5972 -#define CANCEL_REG_IP 32
5973 +#define MC_PC regs.pc
5974 --- a/arch/powerpc/atomic.h
5977 -#ifndef _INTERNAL_ATOMIC_H
5978 -#define _INTERNAL_ATOMIC_H
5980 -#include <stdint.h>
5981 -#include <endian.h>
5983 -static inline int a_ctz_l(unsigned long x)
5985 - static const char debruijn32[32] = {
5986 - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
5987 - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
5989 - return debruijn32[(x&-x)*0x076be629 >> 27];
5992 -static inline int a_ctz_64(uint64_t x)
5997 - return 32 + a_ctz_l(y);
5999 - return a_ctz_l(y);
6002 -static inline int a_cas(volatile int *p, int t, int s)
6006 - "1: lwarx %0, 0, %4\n"
6009 - " stwcx. %3, 0, %4\n"
6013 - : "=&r"(t), "+m"(*p) : "r"(t), "r"(s), "r"(p) : "cc", "memory" );
6017 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
6019 - return (void *)a_cas(p, (int)t, (int)s);
6022 -static inline int a_swap(volatile int *x, int v)
6026 - while (a_cas(x, old, v) != old);
6030 -static inline int a_fetch_add(volatile int *x, int v)
6034 - while (a_cas(x, old, old+v) != old);
6038 -static inline void a_inc(volatile int *x)
6040 - a_fetch_add(x, 1);
6043 -static inline void a_dec(volatile int *x)
6045 - a_fetch_add(x, -1);
6048 -static inline void a_store(volatile int *p, int x)
6050 - __asm__ __volatile__ ("\n"
6054 - : "=m"(*p) : "r"(x) : "memory" );
6057 -#define a_spin a_barrier
6059 -static inline void a_barrier()
6061 - a_cas(&(int){0}, 0, 0);
6064 -static inline void a_crash()
6066 - *(volatile char *)0=0;
6069 -static inline void a_and(volatile int *p, int v)
6073 - while (a_cas(p, old, old&v) != old);
6076 -static inline void a_or(volatile int *p, int v)
6080 - while (a_cas(p, old, old|v) != old);
6083 -static inline void a_or_l(volatile void *p, long v)
6088 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
6090 - union { uint64_t v; uint32_t r[2]; } u = { v };
6091 - a_and((int *)p, u.r[0]);
6092 - a_and((int *)p+1, u.r[1]);
6095 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
6097 - union { uint64_t v; uint32_t r[2]; } u = { v };
6098 - a_or((int *)p, u.r[0]);
6099 - a_or((int *)p+1, u.r[1]);
6104 +++ b/arch/powerpc/atomic_arch.h
6107 +static inline int a_ll(volatile int *p)
6110 + __asm__ __volatile__ ("lwarx %0, 0, %2" : "=r"(v) : "m"(*p), "r"(p));
6115 +static inline int a_sc(volatile int *p, int v)
6118 + __asm__ __volatile__ (
6119 + "stwcx. %2, 0, %3 ; mfcr %0"
6120 + : "=r"(r), "=m"(*p) : "r"(v), "r"(p) : "memory", "cc");
6121 + return r & 0x20000000; /* "bit 2" of "cr0" (backwards bit order) */
6124 +#define a_barrier a_barrier
6125 +static inline void a_barrier()
6127 + __asm__ __volatile__ ("sync" : : : "memory");
6130 +#define a_pre_llsc a_barrier
6132 +#define a_post_llsc a_post_llsc
6133 +static inline void a_post_llsc()
6135 + __asm__ __volatile__ ("isync" : : : "memory");
6138 +#define a_store a_store
6139 +static inline void a_store(volatile int *p, int v)
6145 --- a/arch/powerpc/bits/mman.h
6146 +++ b/arch/powerpc/bits/mman.h
6149 #define PROT_WRITE 2
6151 +#define PROT_SAO 0x10
6152 #define PROT_GROWSDOWN 0x01000000
6153 #define PROT_GROWSUP 0x02000000
6156 #define MS_INVALIDATE 2
6159 -#define MCL_CURRENT 1
6160 -#define MCL_FUTURE 2
6161 +#define MCL_CURRENT 0x2000
6162 +#define MCL_FUTURE 0x4000
6163 +#define MCL_ONFAULT 0x8000
6165 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
6166 #define MADV_NORMAL 0
6167 --- a/arch/powerpc/bits/statfs.h
6171 - unsigned long f_type, f_bsize;
6172 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
6173 - fsfilcnt_t f_files, f_ffree;
6175 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
6177 --- a/arch/powerpc/bits/stdarg.h
6180 -#define va_start(v,l) __builtin_va_start(v,l)
6181 -#define va_end(v) __builtin_va_end(v)
6182 -#define va_arg(v,l) __builtin_va_arg(v,l)
6183 -#define va_copy(d,s) __builtin_va_copy(d,s)
6184 --- a/arch/powerpc/bits/syscall.h
6185 +++ b/arch/powerpc/bits/syscall.h
6186 @@ -194,23 +194,19 @@
6187 #define __NR_vfork 189
6188 #define __NR_ugetrlimit 190
6189 #define __NR_readahead 191
6190 -#if !defined(__PPC64) || defined(__ABI32)
6191 #define __NR_mmap2 192
6192 #define __NR_truncate64 193
6193 #define __NR_ftruncate64 194
6194 #define __NR_stat64 195
6195 #define __NR_lstat64 196
6196 #define __NR_fstat64 197
6198 #define __NR_pciconfig_read 198
6199 #define __NR_pciconfig_write 199
6200 #define __NR_pciconfig_iobase 200
6201 #define __NR_multiplexer 201
6202 #define __NR_getdents64 202
6203 #define __NR_pivot_root 203
6204 -#if !defined(__PPC64) || defined(__ABI32)
6205 #define __NR_fcntl64 204
6207 #define __NR_madvise 205
6208 #define __NR_mincore 206
6209 #define __NR_gettid 207
6211 #define __NR_sched_setaffinity 222
6212 #define __NR_sched_getaffinity 223
6213 #define __NR_tuxcall 225
6214 -#if !defined(__PPC64) || defined(__ABI32)
6215 #define __NR_sendfile64 226
6217 #define __NR_io_setup 227
6218 #define __NR_io_destroy 228
6219 #define __NR_io_getevents 229
6221 #define __NR_utimes 251
6222 #define __NR_statfs64 252
6223 #define __NR_fstatfs64 253
6224 -#if !defined(__PPC64) || defined(__ABI32)
6225 #define __NR_fadvise64_64 254
6227 #define __NR_rtas 255
6228 #define __NR_sys_debug_setcontext 256
6229 #define __NR_migrate_pages 258
6230 @@ -299,11 +291,7 @@
6231 #define __NR_mknodat 288
6232 #define __NR_fchownat 289
6233 #define __NR_futimesat 290
6234 -#if defined(__PPC64) && !defined(__ABI32)
6235 -#define __NR_newfstatat 291
6237 #define __NR_fstatat64 291
6239 #define __NR_unlinkat 292
6240 #define __NR_renameat 293
6241 #define __NR_linkat 294
6242 @@ -376,6 +364,10 @@
6243 #define __NR_memfd_create 360
6244 #define __NR_bpf 361
6245 #define __NR_execveat 362
6246 +#define __NR_switch_endian 363
6247 +#define __NR_userfaultfd 364
6248 +#define __NR_membarrier 365
6249 +#define __NR_mlock2 378
6252 * repeated with SYS prefix
6253 @@ -576,23 +568,19 @@
6254 #define SYS_vfork 189
6255 #define SYS_ugetrlimit 190
6256 #define SYS_readahead 191
6257 -#if !defined(__PPC64) || defined(__ABI32)
6258 #define SYS_mmap2 192
6259 #define SYS_truncate64 193
6260 #define SYS_ftruncate64 194
6261 #define SYS_stat64 195
6262 #define SYS_lstat64 196
6263 #define SYS_fstat64 197
6265 #define SYS_pciconfig_read 198
6266 #define SYS_pciconfig_write 199
6267 #define SYS_pciconfig_iobase 200
6268 #define SYS_multiplexer 201
6269 #define SYS_getdents64 202
6270 #define SYS_pivot_root 203
6271 -#if !defined(__PPC64) || defined(__ABI32)
6272 #define SYS_fcntl64 204
6274 #define SYS_madvise 205
6275 #define SYS_mincore 206
6276 #define SYS_gettid 207
6278 #define SYS_sched_setaffinity 222
6279 #define SYS_sched_getaffinity 223
6280 #define SYS_tuxcall 225
6281 -#if !defined(__PPC64) || defined(__ABI32)
6282 #define SYS_sendfile64 226
6284 #define SYS_io_setup 227
6285 #define SYS_io_destroy 228
6286 #define SYS_io_getevents 229
6288 #define SYS_utimes 251
6289 #define SYS_statfs64 252
6290 #define SYS_fstatfs64 253
6291 -#if !defined(__PPC64) || defined(__ABI32)
6292 #define SYS_fadvise64_64 254
6294 #define SYS_rtas 255
6295 #define SYS_sys_debug_setcontext 256
6296 #define SYS_migrate_pages 258
6297 @@ -681,11 +665,7 @@
6298 #define SYS_mknodat 288
6299 #define SYS_fchownat 289
6300 #define SYS_futimesat 290
6301 -#if defined(__PPC64) && !defined(__ABI32)
6302 -#define SYS_newfstatat 291
6304 #define SYS_fstatat64 291
6306 #define SYS_unlinkat 292
6307 #define SYS_renameat 293
6308 #define SYS_linkat 294
6310 #define SYS_memfd_create 360
6312 #define SYS_execveat 362
6313 +#define SYS_switch_endian 363
6314 +#define SYS_userfaultfd 364
6315 +#define SYS_membarrier 365
6316 +#define SYS_mlock2 378
6317 --- a/arch/powerpc/pthread_arch.h
6318 +++ b/arch/powerpc/pthread_arch.h
6319 @@ -15,9 +15,8 @@ static inline struct pthread *__pthread_
6321 #define DTP_OFFSET 0x8000
6323 -// offset of the PC register in mcontext_t, divided by the system wordsize
6324 // the kernel calls the ip "nip", it's the first saved value after the 32
6326 -#define CANCEL_REG_IP 32
6327 +#define MC_PC gregs[32]
6329 #define CANARY canary_at_end
6330 --- a/arch/sh/atomic.h
6333 -#ifndef _INTERNAL_ATOMIC_H
6334 -#define _INTERNAL_ATOMIC_H
6336 -#include <stdint.h>
6338 -static inline int a_ctz_l(unsigned long x)
6340 - static const char debruijn32[32] = {
6341 - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
6342 - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
6344 - return debruijn32[(x&-x)*0x076be629 >> 27];
6347 -static inline int a_ctz_64(uint64_t x)
6352 - return 32 + a_ctz_l(y);
6354 - return a_ctz_l(y);
6357 -#define LLSC_CLOBBERS "r0", "t", "memory"
6358 -#define LLSC_START(mem) "synco\n" \
6359 - "0: movli.l @" mem ", r0\n"
6360 -#define LLSC_END(mem) \
6361 - "1: movco.l r0, @" mem "\n" \
6365 -static inline int __sh_cas_llsc(volatile int *p, int t, int s)
6368 - __asm__ __volatile__(
6371 - " cmp/eq %0, %2\n"
6375 - : "=&r"(old) : "r"(p), "r"(t), "r"(s) : LLSC_CLOBBERS);
6379 -static inline int __sh_swap_llsc(volatile int *x, int v)
6382 - __asm__ __volatile__(
6387 - : "=&r"(old) : "r"(x), "r"(v) : LLSC_CLOBBERS);
6391 -static inline int __sh_fetch_add_llsc(volatile int *x, int v)
6394 - __asm__ __volatile__(
6399 - : "=&r"(old) : "r"(x), "r"(v) : LLSC_CLOBBERS);
6403 -static inline void __sh_store_llsc(volatile int *p, int x)
6405 - __asm__ __volatile__(
6407 - " mov.l %1, @%0\n"
6409 - : : "r"(p), "r"(x) : "memory");
6412 -static inline void __sh_and_llsc(volatile int *x, int v)
6414 - __asm__ __volatile__(
6418 - : : "r"(x), "r"(v) : LLSC_CLOBBERS);
6421 -static inline void __sh_or_llsc(volatile int *x, int v)
6423 - __asm__ __volatile__(
6427 - : : "r"(x), "r"(v) : LLSC_CLOBBERS);
6431 -#define a_cas(p,t,s) __sh_cas_llsc(p,t,s)
6432 -#define a_swap(x,v) __sh_swap_llsc(x,v)
6433 -#define a_fetch_add(x,v) __sh_fetch_add_llsc(x, v)
6434 -#define a_store(x,v) __sh_store_llsc(x, v)
6435 -#define a_and(x,v) __sh_and_llsc(x, v)
6436 -#define a_or(x,v) __sh_or_llsc(x, v)
6439 -int __sh_cas(volatile int *, int, int);
6440 -int __sh_swap(volatile int *, int);
6441 -int __sh_fetch_add(volatile int *, int);
6442 -void __sh_store(volatile int *, int);
6443 -void __sh_and(volatile int *, int);
6444 -void __sh_or(volatile int *, int);
6446 -#define a_cas(p,t,s) __sh_cas(p,t,s)
6447 -#define a_swap(x,v) __sh_swap(x,v)
6448 -#define a_fetch_add(x,v) __sh_fetch_add(x, v)
6449 -#define a_store(x,v) __sh_store(x, v)
6450 -#define a_and(x,v) __sh_and(x, v)
6451 -#define a_or(x,v) __sh_or(x, v)
6454 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
6456 - return (void *)a_cas(p, (int)t, (int)s);
6459 -static inline void a_inc(volatile int *x)
6461 - a_fetch_add(x, 1);
6464 -static inline void a_dec(volatile int *x)
6466 - a_fetch_add(x, -1);
6469 -#define a_spin a_barrier
6471 -static inline void a_barrier()
6473 - a_cas(&(int){0}, 0, 0);
6476 -static inline void a_crash()
6478 - *(volatile char *)0=0;
6481 -static inline void a_or_l(volatile void *p, long v)
6486 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
6488 - union { uint64_t v; uint32_t r[2]; } u = { v };
6489 - a_and((int *)p, u.r[0]);
6490 - a_and((int *)p+1, u.r[1]);
6493 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
6495 - union { uint64_t v; uint32_t r[2]; } u = { v };
6496 - a_or((int *)p, u.r[0]);
6497 - a_or((int *)p+1, u.r[1]);
6502 +++ b/arch/sh/atomic_arch.h
6504 +#if defined(__SH4A__)
6507 +static inline int a_ll(volatile int *p)
6510 + __asm__ __volatile__ ("movli.l @%1, %0" : "=z"(v) : "r"(p), "m"(*p));
6515 +static inline int a_sc(volatile int *p, int v)
6518 + __asm__ __volatile__ (
6519 + "movco.l %2, @%3 ; movt %0"
6520 + : "=r"(r), "=m"(*p) : "z"(v), "r"(p) : "memory", "cc");
6524 +#define a_barrier a_barrier
6525 +static inline void a_barrier()
6527 + __asm__ __volatile__ ("synco" : : "memory");
6530 +#define a_pre_llsc a_barrier
6531 +#define a_post_llsc a_barrier
6535 +#define a_cas a_cas
6536 +__attribute__((__visibility__("hidden"))) extern const void *__sh_cas_ptr;
6537 +static inline int a_cas(volatile int *p, int t, int s)
6539 + register int r1 __asm__("r1");
6540 + register int r2 __asm__("r2") = t;
6541 + register int r3 __asm__("r3") = s;
6542 + __asm__ __volatile__ (
6544 + : "=r"(r1), "+r"(r3) : "z"(p), "r"(r2), "r"(__sh_cas_ptr)
6545 + : "memory", "pr", "cc");
6550 --- a/arch/sh/bits/errno.h
6588 -#define ENAMETOOLONG 36
6591 -#define ENOTEMPTY 39
6593 -#define EWOULDBLOCK EAGAIN
6597 -#define EL2NSYNC 45
6610 -#define EDEADLOCK EDEADLK
6624 -#define EMULTIHOP 72
6627 -#define EOVERFLOW 75
6628 -#define ENOTUNIQ 76
6635 -#define ELIBEXEC 83
6637 -#define ERESTART 85
6638 -#define ESTRPIPE 86
6640 -#define ENOTSOCK 88
6641 -#define EDESTADDRREQ 89
6642 -#define EMSGSIZE 90
6643 -#define EPROTOTYPE 91
6644 -#define ENOPROTOOPT 92
6645 -#define EPROTONOSUPPORT 93
6646 -#define ESOCKTNOSUPPORT 94
6647 -#define EOPNOTSUPP 95
6648 -#define ENOTSUP EOPNOTSUPP
6649 -#define EPFNOSUPPORT 96
6650 -#define EAFNOSUPPORT 97
6651 -#define EADDRINUSE 98
6652 -#define EADDRNOTAVAIL 99
6653 -#define ENETDOWN 100
6654 -#define ENETUNREACH 101
6655 -#define ENETRESET 102
6656 -#define ECONNABORTED 103
6657 -#define ECONNRESET 104
6658 -#define ENOBUFS 105
6659 -#define EISCONN 106
6660 -#define ENOTCONN 107
6661 -#define ESHUTDOWN 108
6662 -#define ETOOMANYREFS 109
6663 -#define ETIMEDOUT 110
6664 -#define ECONNREFUSED 111
6665 -#define EHOSTDOWN 112
6666 -#define EHOSTUNREACH 113
6667 -#define EALREADY 114
6668 -#define EINPROGRESS 115
6670 -#define EUCLEAN 117
6671 -#define ENOTNAM 118
6672 -#define ENAVAIL 119
6674 -#define EREMOTEIO 121
6676 -#define ENOMEDIUM 123
6677 -#define EMEDIUMTYPE 124
6678 -#define ECANCELED 125
6680 -#define EKEYEXPIRED 127
6681 -#define EKEYREVOKED 128
6682 -#define EKEYREJECTED 129
6683 -#define EOWNERDEAD 130
6684 -#define ENOTRECOVERABLE 131
6685 -#define ERFKILL 132
6686 -#define EHWPOISON 133
6687 --- a/arch/sh/bits/fcntl.h
6690 -#define O_CREAT 0100
6691 -#define O_EXCL 0200
6692 -#define O_NOCTTY 0400
6693 -#define O_TRUNC 01000
6694 -#define O_APPEND 02000
6695 -#define O_NONBLOCK 04000
6696 -#define O_DSYNC 010000
6697 -#define O_SYNC 04010000
6698 -#define O_RSYNC 04010000
6699 -#define O_DIRECTORY 0200000
6700 -#define O_NOFOLLOW 0400000
6701 -#define O_CLOEXEC 02000000
6703 -#define O_ASYNC 020000
6704 -#define O_DIRECT 040000
6705 -#define O_LARGEFILE 0100000
6706 -#define O_NOATIME 01000000
6707 -#define O_PATH 010000000
6708 -#define O_TMPFILE 020200000
6709 -#define O_NDELAY O_NONBLOCK
6719 -#define F_SETSIG 10
6720 -#define F_GETSIG 11
6724 -#define F_SETLKW 14
6726 -#define F_SETOWN_EX 15
6727 -#define F_GETOWN_EX 16
6729 -#define F_GETOWNER_UIDS 17
6730 --- a/arch/sh/bits/ipc.h
6735 - key_t __ipc_perm_key;
6741 - int __ipc_perm_seq;
6746 -#define IPC_64 0x100
6747 --- a/arch/sh/bits/mman.h
6748 +++ b/arch/sh/bits/mman.h
6751 #define MCL_CURRENT 1
6752 #define MCL_FUTURE 2
6753 +#define MCL_ONFAULT 4
6755 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
6756 #define MADV_NORMAL 0
6757 --- a/arch/sh/bits/msg.h
6762 - struct ipc_perm msg_perm;
6769 - unsigned long msg_cbytes;
6770 - msgqnum_t msg_qnum;
6771 - msglen_t msg_qbytes;
6774 - unsigned long __unused[2];
6776 --- a/arch/sh/bits/sem.h
6780 - struct ipc_perm sem_perm;
6785 -#if __BYTE_ORDER == __LITTLE_ENDIAN
6786 - unsigned short sem_nsems;
6787 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
6789 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
6790 - unsigned short sem_nsems;
6795 --- a/arch/sh/bits/socket.h
6801 - socklen_t msg_namelen;
6802 - struct iovec *msg_iov;
6804 - void *msg_control;
6805 - socklen_t msg_controllen;
6811 - socklen_t cmsg_len;
6815 --- a/arch/sh/bits/statfs.h
6819 - unsigned long f_type, f_bsize;
6820 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
6821 - fsfilcnt_t f_files, f_ffree;
6823 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
6825 --- a/arch/sh/bits/stdarg.h
6828 -#define va_start(v,l) __builtin_va_start(v,l)
6829 -#define va_end(v) __builtin_va_end(v)
6830 -#define va_arg(v,l) __builtin_va_arg(v,l)
6831 -#define va_copy(d,s) __builtin_va_copy(d,s)
6832 --- a/arch/sh/bits/termios.h
6843 - speed_t __c_ispeed;
6844 - speed_t __c_ospeed;
6859 -#define VREPRINT 12
6860 -#define VDISCARD 13
6865 -#define IGNBRK 0000001
6866 -#define BRKINT 0000002
6867 -#define IGNPAR 0000004
6868 -#define PARMRK 0000010
6869 -#define INPCK 0000020
6870 -#define ISTRIP 0000040
6871 -#define INLCR 0000100
6872 -#define IGNCR 0000200
6873 -#define ICRNL 0000400
6874 -#define IUCLC 0001000
6875 -#define IXON 0002000
6876 -#define IXANY 0004000
6877 -#define IXOFF 0010000
6878 -#define IMAXBEL 0020000
6879 -#define IUTF8 0040000
6881 -#define OPOST 0000001
6882 -#define OLCUC 0000002
6883 -#define ONLCR 0000004
6884 -#define OCRNL 0000010
6885 -#define ONOCR 0000020
6886 -#define ONLRET 0000040
6887 -#define OFILL 0000100
6888 -#define OFDEL 0000200
6889 -#define NLDLY 0000400
6890 -#define NL0 0000000
6891 -#define NL1 0000400
6892 -#define CRDLY 0003000
6893 -#define CR0 0000000
6894 -#define CR1 0001000
6895 -#define CR2 0002000
6896 -#define CR3 0003000
6897 -#define TABDLY 0014000
6898 -#define TAB0 0000000
6899 -#define TAB1 0004000
6900 -#define TAB2 0010000
6901 -#define TAB3 0014000
6902 -#define BSDLY 0020000
6903 -#define BS0 0000000
6904 -#define BS1 0020000
6905 -#define FFDLY 0100000
6906 -#define FF0 0000000
6907 -#define FF1 0100000
6909 -#define VTDLY 0040000
6910 -#define VT0 0000000
6911 -#define VT1 0040000
6914 -#define B50 0000001
6915 -#define B75 0000002
6916 -#define B110 0000003
6917 -#define B134 0000004
6918 -#define B150 0000005
6919 -#define B200 0000006
6920 -#define B300 0000007
6921 -#define B600 0000010
6922 -#define B1200 0000011
6923 -#define B1800 0000012
6924 -#define B2400 0000013
6925 -#define B4800 0000014
6926 -#define B9600 0000015
6927 -#define B19200 0000016
6928 -#define B38400 0000017
6930 -#define B57600 0010001
6931 -#define B115200 0010002
6932 -#define B230400 0010003
6933 -#define B460800 0010004
6934 -#define B500000 0010005
6935 -#define B576000 0010006
6936 -#define B921600 0010007
6937 -#define B1000000 0010010
6938 -#define B1152000 0010011
6939 -#define B1500000 0010012
6940 -#define B2000000 0010013
6941 -#define B2500000 0010014
6942 -#define B3000000 0010015
6943 -#define B3500000 0010016
6944 -#define B4000000 0010017
6946 -#define CBAUD 0010017
6948 -#define CSIZE 0000060
6949 -#define CS5 0000000
6950 -#define CS6 0000020
6951 -#define CS7 0000040
6952 -#define CS8 0000060
6953 -#define CSTOPB 0000100
6954 -#define CREAD 0000200
6955 -#define PARENB 0000400
6956 -#define PARODD 0001000
6957 -#define HUPCL 0002000
6958 -#define CLOCAL 0004000
6960 -#define ISIG 0000001
6961 -#define ICANON 0000002
6962 -#define ECHO 0000010
6963 -#define ECHOE 0000020
6964 -#define ECHOK 0000040
6965 -#define ECHONL 0000100
6966 -#define NOFLSH 0000200
6967 -#define TOSTOP 0000400
6968 -#define IEXTEN 0100000
6970 -#define ECHOCTL 0001000
6971 -#define ECHOPRT 0002000
6972 -#define ECHOKE 0004000
6973 -#define FLUSHO 0010000
6974 -#define PENDIN 0040000
6983 -#define TCIOFLUSH 2
6986 -#define TCSADRAIN 1
6987 -#define TCSAFLUSH 2
6989 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
6990 -#define CBAUDEX 0010000
6991 -#define CRTSCTS 020000000000
6992 -#define EXTPROC 0200000
6993 -#define XTABS 0014000
6995 --- a/arch/sh/crt_arch.h
6996 +++ b/arch/sh/crt_arch.h
6997 @@ -22,7 +22,8 @@ START ": \n"
6999 " mov.l 1f+4, r6 \n"
7001 -" bsr __fdpic_fixup \n"
7007 @@ -31,11 +32,16 @@ START ": \n"
7008 " mov.l r9, @-r15 \n"
7009 " mov.l r8, @-r15 \n"
7011 -" bsr " START "_c \n"
7016 "1: .long __ROFIXUP_LIST__@PCREL \n"
7017 " .long __ROFIXUP_END__@PCREL + 4 \n"
7018 +"2: .long " START "_c@PCREL - (3b+4-.) \n"
7020 +"4: .long __fdpic_fixup@PCREL - (5b+4-.) \n"
7025 @@ -53,13 +59,14 @@ START ": \n"
7030 -" bsr " START "_c \n"
7037 ".hidden _DYNAMIC \n"
7038 "1: .long _DYNAMIC-. \n"
7039 +"2: .long " START "_c@PCREL - (3b+4-.) \n"
7043 --- a/arch/sh/pthread_arch.h
7044 +++ b/arch/sh/pthread_arch.h
7045 @@ -8,4 +8,4 @@ static inline struct pthread *__pthread_
7046 #define TLS_ABOVE_TP
7047 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8)
7049 -#define CANCEL_REG_IP 17
7050 +#define MC_PC sc_pc
7051 --- a/arch/sh/reloc.h
7052 +++ b/arch/sh/reloc.h
7054 #define REL_DTPOFF R_SH_TLS_DTPOFF32
7055 #define REL_TPOFF R_SH_TLS_TPOFF32
7057 +#define DL_NOMMU_SUPPORT 1
7060 #define REL_FUNCDESC R_SH_FUNCDESC
7061 #define REL_FUNCDESC_VAL R_SH_FUNCDESC_VALUE
7062 --- a/arch/sh/src/__fpscr_values.c
7067 -/* used by gcc for switching the FPU between single and double precision */
7068 -//const unsigned long __fpscr_values[2] ATTR_LIBC_VISIBILITY = { 0, 0x80000 };
7070 --- a/arch/sh/src/__set_thread_area.c
7073 -#include "pthread_impl.h"
7075 -#include "sh_atomic.h"
7078 -/* Also perform sh-specific init */
7080 -#define CPU_HAS_LLSC 0x0040
7082 -__attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model, __sh_nommu;
7084 -int __set_thread_area(void *p)
7087 - __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
7089 - if (__hwcap & CPU_HAS_LLSC) {
7090 - __sh_atomic_model = SH_A_LLSC;
7093 -#if !defined(__SH3__) && !defined(__SH4__)
7094 - for (aux=libc.auxv; *aux; aux+=2) {
7095 - if (*aux != AT_PLATFORM) continue;
7096 - const char *s = (void *)aux[1];
7097 - if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
7098 - __sh_atomic_model = SH_A_IMASK;
7103 - /* __sh_atomic_model = SH_A_GUSA; */ /* 0, default */
7107 --- a/arch/sh/src/__shcall.c
7110 -__attribute__((__visibility__("hidden")))
7111 -int __shcall(void *arg, int (*func)(void *))
7115 --- a/arch/sh/src/__unmapself.c
7118 -#include "pthread_impl.h"
7120 -void __unmapself_sh_mmu(void *, size_t);
7121 -void __unmapself_sh_nommu(void *, size_t);
7123 -#if !defined(__SH3__) && !defined(__SH4__)
7124 -#define __unmapself __unmapself_sh_nommu
7125 -#include "dynlink.h"
7127 -#define CRTJMP(pc,sp) __asm__ __volatile__( \
7128 - "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
7129 - : : "r"(pc), "r"(sp) : "r0", "memory" )
7130 -#include "../../../src/thread/__unmapself.c"
7132 -extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
7134 -#define __sh_nommu 0
7137 -void __unmapself(void *base, size_t size)
7139 - if (__sh_nommu) __unmapself_sh_nommu(base, size);
7140 - else __unmapself_sh_mmu(base, size);
7142 --- a/arch/sh/src/atomic.c
7147 -#include "sh_atomic.h"
7148 -#include "atomic.h"
7151 -static inline unsigned mask()
7154 - __asm__ __volatile__ ( "\n"
7159 - : "=&r"(sr) : : "memory", "r0" );
7163 -static inline void unmask(unsigned sr)
7165 - __asm__ __volatile__ ( "ldc %0,sr" : : "r"(sr) : "memory" );
7168 -/* gusa is a hack in the kernel which lets you create a sequence of instructions
7169 - * which will be restarted if the process is preempted in the middle of the
7170 - * sequence. It will do for implementing atomics on non-smp systems. ABI is:
7171 - * r0 = address of first instruction after the atomic sequence
7172 - * r1 = original stack pointer
7173 - * r15 = -1 * length of atomic sequence in bytes
7175 -#define GUSA_CLOBBERS "r0", "r1", "memory"
7176 -#define GUSA_START(mem,old,nop) \
7178 - " mova 1f, r0\n" \
7180 - " mov r15, r1\n" \
7181 - " mov #(0f-1f), r15\n" \
7182 - "0: mov.l @" mem ", " old "\n"
7183 -/* the target of mova must be 4 byte aligned, so we may need a nop */
7184 -#define GUSA_START_ODD(mem,old) GUSA_START(mem,old,"")
7185 -#define GUSA_START_EVEN(mem,old) GUSA_START(mem,old,"\tnop\n")
7186 -#define GUSA_END(mem,new) \
7187 - " mov.l " new ", @" mem "\n" \
7188 - "1: mov r1, r15\n"
7190 -int __sh_cas(volatile int *p, int t, int s)
7192 - if (__sh_atomic_model == SH_A_LLSC) return __sh_cas_llsc(p, t, s);
7194 - if (__sh_atomic_model == SH_A_IMASK) {
7195 - unsigned sr = mask();
7197 - if (old==t) *p = s;
7203 - __asm__ __volatile__(
7204 - GUSA_START_EVEN("%1", "%0")
7205 - " cmp/eq %0, %2\n"
7207 - GUSA_END("%1", "%3")
7208 - : "=&r"(old) : "r"(p), "r"(t), "r"(s) : GUSA_CLOBBERS, "t");
7212 -int __sh_swap(volatile int *x, int v)
7214 - if (__sh_atomic_model == SH_A_LLSC) return __sh_swap_llsc(x, v);
7216 - if (__sh_atomic_model == SH_A_IMASK) {
7217 - unsigned sr = mask();
7225 - __asm__ __volatile__(
7226 - GUSA_START_EVEN("%1", "%0")
7227 - GUSA_END("%1", "%2")
7228 - : "=&r"(old) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7232 -int __sh_fetch_add(volatile int *x, int v)
7234 - if (__sh_atomic_model == SH_A_LLSC) return __sh_fetch_add_llsc(x, v);
7236 - if (__sh_atomic_model == SH_A_IMASK) {
7237 - unsigned sr = mask();
7245 - __asm__ __volatile__(
7246 - GUSA_START_EVEN("%2", "%0")
7249 - GUSA_END("%2", "%1")
7250 - : "=&r"(old), "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7254 -void __sh_store(volatile int *p, int x)
7256 - if (__sh_atomic_model == SH_A_LLSC) return __sh_store_llsc(p, x);
7257 - __asm__ __volatile__(
7258 - " mov.l %1, @%0\n"
7259 - : : "r"(p), "r"(x) : "memory");
7262 -void __sh_and(volatile int *x, int v)
7264 - if (__sh_atomic_model == SH_A_LLSC) return __sh_and_llsc(x, v);
7266 - if (__sh_atomic_model == SH_A_IMASK) {
7267 - unsigned sr = mask();
7275 - __asm__ __volatile__(
7276 - GUSA_START_ODD("%1", "%0")
7278 - GUSA_END("%1", "%0")
7279 - : "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7282 -void __sh_or(volatile int *x, int v)
7284 - if (__sh_atomic_model == SH_A_LLSC) return __sh_or_llsc(x, v);
7286 - if (__sh_atomic_model == SH_A_IMASK) {
7287 - unsigned sr = mask();
7295 - __asm__ __volatile__(
7296 - GUSA_START_ODD("%1", "%0")
7298 - GUSA_END("%1", "%0")
7299 - : "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7303 --- a/arch/sh/src/sh_atomic.h
7306 -#ifndef _SH_ATOMIC_H
7307 -#define _SH_ATOMIC_H
7309 -#define SH_A_GUSA 0
7310 -#define SH_A_LLSC 1
7312 -#if !defined(__SH3__) && !defined(__SH4__)
7313 -#define SH_A_IMASK 3
7315 -#define SH_A_IMASK -1LL /* unmatchable by unsigned int */
7318 -extern __attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model;
7321 --- a/arch/x32/atomic.h
7324 -#ifndef _INTERNAL_ATOMIC_H
7325 -#define _INTERNAL_ATOMIC_H
7327 -#include <stdint.h>
7329 -static inline int a_ctz_64(uint64_t x)
7331 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7335 -static inline int a_ctz_l(unsigned long x)
7337 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7341 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
7343 - __asm__( "lock ; and %1, %0"
7344 - : "=m"(*p) : "r"(v) : "memory" );
7347 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
7349 - __asm__( "lock ; or %1, %0"
7350 - : "=m"(*p) : "r"(v) : "memory" );
7353 -static inline void a_or_l(volatile void *p, long v)
7355 - __asm__( "lock ; or %1, %0"
7356 - : "=m"(*(long *)p) : "r"(v) : "memory" );
7359 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
7361 - __asm__( "lock ; cmpxchg %3, %1"
7362 - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
7366 -static inline int a_cas(volatile int *p, int t, int s)
7368 - __asm__( "lock ; cmpxchg %3, %1"
7369 - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
7373 -static inline void a_or(volatile int *p, int v)
7375 - __asm__( "lock ; or %1, %0"
7376 - : "=m"(*p) : "r"(v) : "memory" );
7379 -static inline void a_and(volatile int *p, int v)
7381 - __asm__( "lock ; and %1, %0"
7382 - : "=m"(*p) : "r"(v) : "memory" );
7385 -static inline int a_swap(volatile int *x, int v)
7387 - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
7391 -static inline int a_fetch_add(volatile int *x, int v)
7393 - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
7397 -static inline void a_inc(volatile int *x)
7399 - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
7402 -static inline void a_dec(volatile int *x)
7404 - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
7407 -static inline void a_store(volatile int *p, int x)
7409 - __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
7412 -static inline void a_spin()
7414 - __asm__ __volatile__( "pause" : : : "memory" );
7417 -static inline void a_barrier()
7419 - __asm__ __volatile__( "" : : : "memory" );
7422 -static inline void a_crash()
7424 - __asm__ __volatile__( "hlt" : : : "memory" );
7430 +++ b/arch/x32/atomic_arch.h
7432 +#define a_cas a_cas
7433 +static inline int a_cas(volatile int *p, int t, int s)
7435 + __asm__ __volatile__ (
7436 + "lock ; cmpxchg %3, %1"
7437 + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
7441 +#define a_swap a_swap
7442 +static inline int a_swap(volatile int *p, int v)
7444 + __asm__ __volatile__(
7446 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
7450 +#define a_fetch_add a_fetch_add
7451 +static inline int a_fetch_add(volatile int *p, int v)
7453 + __asm__ __volatile__(
7454 + "lock ; xadd %0, %1"
7455 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
7459 +#define a_and a_and
7460 +static inline void a_and(volatile int *p, int v)
7462 + __asm__ __volatile__(
7463 + "lock ; and %1, %0"
7464 + : "=m"(*p) : "r"(v) : "memory" );
7468 +static inline void a_or(volatile int *p, int v)
7470 + __asm__ __volatile__(
7471 + "lock ; or %1, %0"
7472 + : "=m"(*p) : "r"(v) : "memory" );
7475 +#define a_and_64 a_and_64
7476 +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
7478 + __asm__ __volatile(
7479 + "lock ; and %1, %0"
7480 + : "=m"(*p) : "r"(v) : "memory" );
7483 +#define a_or_64 a_or_64
7484 +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
7486 + __asm__ __volatile__(
7487 + "lock ; or %1, %0"
7488 + : "=m"(*p) : "r"(v) : "memory" );
7491 +#define a_inc a_inc
7492 +static inline void a_inc(volatile int *p)
7494 + __asm__ __volatile__(
7496 + : "=m"(*p) : "m"(*p) : "memory" );
7499 +#define a_dec a_dec
7500 +static inline void a_dec(volatile int *p)
7502 + __asm__ __volatile__(
7504 + : "=m"(*p) : "m"(*p) : "memory" );
7507 +#define a_store a_store
7508 +static inline void a_store(volatile int *p, int x)
7510 + __asm__ __volatile__(
7511 + "mov %1, %0 ; lock ; orl $0,(%%rsp)"
7512 + : "=m"(*p) : "r"(x) : "memory" );
7515 +#define a_barrier a_barrier
7516 +static inline void a_barrier()
7518 + __asm__ __volatile__( "" : : : "memory" );
7521 +#define a_pause a_pause
7522 +static inline void a_spin()
7524 + __asm__ __volatile__( "pause" : : : "memory" );
7527 +#define a_crash a_crash
7528 +static inline void a_crash()
7530 + __asm__ __volatile__( "hlt" : : : "memory" );
7533 +#define a_ctz_64 a_ctz_64
7534 +static inline int a_ctz_64(uint64_t x)
7536 + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7540 +#define a_ctz_l a_ctz_l
7541 +static inline int a_ctz_l(unsigned long x)
7543 + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7546 --- a/arch/x32/bits/errno.h
7584 -#define ENAMETOOLONG 36
7587 -#define ENOTEMPTY 39
7589 -#define EWOULDBLOCK EAGAIN
7593 -#define EL2NSYNC 45
7606 -#define EDEADLOCK EDEADLK
7620 -#define EMULTIHOP 72
7623 -#define EOVERFLOW 75
7624 -#define ENOTUNIQ 76
7631 -#define ELIBEXEC 83
7633 -#define ERESTART 85
7634 -#define ESTRPIPE 86
7636 -#define ENOTSOCK 88
7637 -#define EDESTADDRREQ 89
7638 -#define EMSGSIZE 90
7639 -#define EPROTOTYPE 91
7640 -#define ENOPROTOOPT 92
7641 -#define EPROTONOSUPPORT 93
7642 -#define ESOCKTNOSUPPORT 94
7643 -#define EOPNOTSUPP 95
7644 -#define ENOTSUP EOPNOTSUPP
7645 -#define EPFNOSUPPORT 96
7646 -#define EAFNOSUPPORT 97
7647 -#define EADDRINUSE 98
7648 -#define EADDRNOTAVAIL 99
7649 -#define ENETDOWN 100
7650 -#define ENETUNREACH 101
7651 -#define ENETRESET 102
7652 -#define ECONNABORTED 103
7653 -#define ECONNRESET 104
7654 -#define ENOBUFS 105
7655 -#define EISCONN 106
7656 -#define ENOTCONN 107
7657 -#define ESHUTDOWN 108
7658 -#define ETOOMANYREFS 109
7659 -#define ETIMEDOUT 110
7660 -#define ECONNREFUSED 111
7661 -#define EHOSTDOWN 112
7662 -#define EHOSTUNREACH 113
7663 -#define EALREADY 114
7664 -#define EINPROGRESS 115
7666 -#define EUCLEAN 117
7667 -#define ENOTNAM 118
7668 -#define ENAVAIL 119
7670 -#define EREMOTEIO 121
7672 -#define ENOMEDIUM 123
7673 -#define EMEDIUMTYPE 124
7674 -#define ECANCELED 125
7676 -#define EKEYEXPIRED 127
7677 -#define EKEYREVOKED 128
7678 -#define EKEYREJECTED 129
7679 -#define EOWNERDEAD 130
7680 -#define ENOTRECOVERABLE 131
7681 -#define ERFKILL 132
7682 -#define EHWPOISON 133
7683 --- a/arch/x32/bits/mman.h
7684 +++ b/arch/x32/bits/mman.h
7687 #define MCL_CURRENT 1
7688 #define MCL_FUTURE 2
7689 +#define MCL_ONFAULT 4
7691 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
7692 #define MADV_NORMAL 0
7693 --- a/arch/x32/bits/sem.h
7697 - struct ipc_perm sem_perm;
7702 -#if __BYTE_ORDER == __LITTLE_ENDIAN
7703 - unsigned short sem_nsems;
7704 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
7706 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
7707 - unsigned short sem_nsems;
7712 --- a/arch/x32/bits/stdarg.h
7715 -#define va_start(v,l) __builtin_va_start(v,l)
7716 -#define va_end(v) __builtin_va_end(v)
7717 -#define va_arg(v,l) __builtin_va_arg(v,l)
7718 -#define va_copy(d,s) __builtin_va_copy(d,s)
7719 --- a/arch/x32/bits/syscall.h
7720 +++ b/arch/x32/bits/syscall.h
7722 #define __NR_memfd_create (__X32_SYSCALL_BIT + 319)
7723 #define __NR_kexec_file_load (__X32_SYSCALL_BIT + 320)
7724 #define __NR_bpf (__X32_SYSCALL_BIT + 321)
7725 +#define __NR_userfaultfd (__X32_SYSCALL_BIT + 323)
7726 +#define __NR_membarrier (__X32_SYSCALL_BIT + 324)
7727 +#define __NR_mlock2 (__X32_SYSCALL_BIT + 325)
7729 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
7730 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
7732 #define SYS_memfd_create __NR_memfd_create
7733 #define SYS_kexec_file_load __NR_kexec_file_load
7734 #define SYS_bpf __NR_bpf
7735 +#define SYS_userfaultfd __NR_userfaultfd
7736 +#define SYS_membarrier __NR_membarrier
7737 +#define SYS_mlock2 __NR_mlock2
7740 #define SYS_rt_sigaction __NR_rt_sigaction
7741 --- a/arch/x32/bits/termios.h
7752 - speed_t __c_ispeed;
7753 - speed_t __c_ospeed;
7768 -#define VREPRINT 12
7769 -#define VDISCARD 13
7774 -#define IGNBRK 0000001
7775 -#define BRKINT 0000002
7776 -#define IGNPAR 0000004
7777 -#define PARMRK 0000010
7778 -#define INPCK 0000020
7779 -#define ISTRIP 0000040
7780 -#define INLCR 0000100
7781 -#define IGNCR 0000200
7782 -#define ICRNL 0000400
7783 -#define IUCLC 0001000
7784 -#define IXON 0002000
7785 -#define IXANY 0004000
7786 -#define IXOFF 0010000
7787 -#define IMAXBEL 0020000
7788 -#define IUTF8 0040000
7790 -#define OPOST 0000001
7791 -#define OLCUC 0000002
7792 -#define ONLCR 0000004
7793 -#define OCRNL 0000010
7794 -#define ONOCR 0000020
7795 -#define ONLRET 0000040
7796 -#define OFILL 0000100
7797 -#define OFDEL 0000200
7798 -#define NLDLY 0000400
7799 -#define NL0 0000000
7800 -#define NL1 0000400
7801 -#define CRDLY 0003000
7802 -#define CR0 0000000
7803 -#define CR1 0001000
7804 -#define CR2 0002000
7805 -#define CR3 0003000
7806 -#define TABDLY 0014000
7807 -#define TAB0 0000000
7808 -#define TAB1 0004000
7809 -#define TAB2 0010000
7810 -#define TAB3 0014000
7811 -#define BSDLY 0020000
7812 -#define BS0 0000000
7813 -#define BS1 0020000
7814 -#define FFDLY 0100000
7815 -#define FF0 0000000
7816 -#define FF1 0100000
7818 -#define VTDLY 0040000
7819 -#define VT0 0000000
7820 -#define VT1 0040000
7823 -#define B50 0000001
7824 -#define B75 0000002
7825 -#define B110 0000003
7826 -#define B134 0000004
7827 -#define B150 0000005
7828 -#define B200 0000006
7829 -#define B300 0000007
7830 -#define B600 0000010
7831 -#define B1200 0000011
7832 -#define B1800 0000012
7833 -#define B2400 0000013
7834 -#define B4800 0000014
7835 -#define B9600 0000015
7836 -#define B19200 0000016
7837 -#define B38400 0000017
7839 -#define B57600 0010001
7840 -#define B115200 0010002
7841 -#define B230400 0010003
7842 -#define B460800 0010004
7843 -#define B500000 0010005
7844 -#define B576000 0010006
7845 -#define B921600 0010007
7846 -#define B1000000 0010010
7847 -#define B1152000 0010011
7848 -#define B1500000 0010012
7849 -#define B2000000 0010013
7850 -#define B2500000 0010014
7851 -#define B3000000 0010015
7852 -#define B3500000 0010016
7853 -#define B4000000 0010017
7855 -#define CBAUD 0010017
7857 -#define CSIZE 0000060
7858 -#define CS5 0000000
7859 -#define CS6 0000020
7860 -#define CS7 0000040
7861 -#define CS8 0000060
7862 -#define CSTOPB 0000100
7863 -#define CREAD 0000200
7864 -#define PARENB 0000400
7865 -#define PARODD 0001000
7866 -#define HUPCL 0002000
7867 -#define CLOCAL 0004000
7869 -#define ISIG 0000001
7870 -#define ICANON 0000002
7871 -#define ECHO 0000010
7872 -#define ECHOE 0000020
7873 -#define ECHOK 0000040
7874 -#define ECHONL 0000100
7875 -#define NOFLSH 0000200
7876 -#define TOSTOP 0000400
7877 -#define IEXTEN 0100000
7879 -#define ECHOCTL 0001000
7880 -#define ECHOPRT 0002000
7881 -#define ECHOKE 0004000
7882 -#define FLUSHO 0010000
7883 -#define PENDIN 0040000
7892 -#define TCIOFLUSH 2
7895 -#define TCSADRAIN 1
7896 -#define TCSAFLUSH 2
7898 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
7899 -#define CBAUDEX 0010000
7900 -#define CRTSCTS 020000000000
7901 -#define EXTPROC 0200000
7902 -#define XTABS 0014000
7904 --- a/arch/x32/pthread_arch.h
7905 +++ b/arch/x32/pthread_arch.h
7906 @@ -7,6 +7,6 @@ static inline struct pthread *__pthread_
7908 #define TP_ADJ(p) (p)
7910 -#define CANCEL_REG_IP 32
7911 +#define MC_PC gregs[REG_RIP]
7913 #define CANARY canary2
7914 --- a/arch/x32/src/syscall_cp_fixup.c
7917 -#include <sys/syscall.h>
7920 -__attribute__((__visibility__("hidden")))
7922 -long __syscall_cp_internal(volatile void*, long long, long long, long long, long long,
7923 - long long, long long, long long);
7925 -struct __timespec { long long tv_sec; long tv_nsec; };
7926 -struct __timespec_kernel { long long tv_sec; long long tv_nsec; };
7927 -#define __tsc(X) ((struct __timespec*)(unsigned long)(X))
7928 -#define __fixup(X) do { if(X) { \
7929 - ts->tv_sec = __tsc(X)->tv_sec; \
7930 - ts->tv_nsec = __tsc(X)->tv_nsec; \
7931 - (X) = (unsigned long)ts; } } while(0)
7934 -__attribute__((__visibility__("hidden")))
7936 -long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3,
7937 - long long a4, long long a5, long long a6)
7939 - struct __timespec_kernel ts[1];
7941 - case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6:
7945 - if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */)
7948 - case SYS_clock_nanosleep:
7949 - case SYS_rt_sigtimedwait: case SYS_ppoll:
7952 - case SYS_nanosleep:
7956 - return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6);
7959 --- a/arch/x32/src/sysinfo.c
7962 -#include <sys/sysinfo.h>
7963 -#include "syscall.h"
7966 -#define klong long long
7967 -#define kulong unsigned long long
7969 -struct kernel_sysinfo {
7982 - unsigned mem_unit;
7985 -int __lsysinfo(struct sysinfo *info)
7987 - struct kernel_sysinfo tmp;
7988 - int ret = syscall(SYS_sysinfo, &tmp);
7989 - if(ret == -1) return ret;
7990 - info->uptime = tmp.uptime;
7991 - info->loads[0] = tmp.loads[0];
7992 - info->loads[1] = tmp.loads[1];
7993 - info->loads[2] = tmp.loads[2];
7995 - kulong max = tmp.totalram | tmp.totalswap;
7996 - __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max));
7997 - shifts = shifts >= 32 ? shifts - 31 : 0;
7998 - info->totalram = tmp.totalram >> shifts;
7999 - info->freeram = tmp.freeram >> shifts;
8000 - info->sharedram = tmp.sharedram >> shifts;
8001 - info->bufferram = tmp.bufferram >> shifts;
8002 - info->totalswap = tmp.totalswap >> shifts;
8003 - info->freeswap = tmp.freeswap >> shifts;
8004 - info->procs = tmp.procs ;
8005 - info->totalhigh = tmp.totalhigh >> shifts;
8006 - info->freehigh = tmp.freehigh >> shifts;
8007 - info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts;
8011 -weak_alias(__lsysinfo, sysinfo);
8012 --- a/arch/x86_64/atomic.h
8015 -#ifndef _INTERNAL_ATOMIC_H
8016 -#define _INTERNAL_ATOMIC_H
8018 -#include <stdint.h>
8020 -static inline int a_ctz_64(uint64_t x)
8022 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
8026 -static inline int a_ctz_l(unsigned long x)
8028 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
8032 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
8034 - __asm__( "lock ; and %1, %0"
8035 - : "=m"(*p) : "r"(v) : "memory" );
8038 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
8040 - __asm__( "lock ; or %1, %0"
8041 - : "=m"(*p) : "r"(v) : "memory" );
8044 -static inline void a_or_l(volatile void *p, long v)
8046 - __asm__( "lock ; or %1, %0"
8047 - : "=m"(*(long *)p) : "r"(v) : "memory" );
8050 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
8052 - __asm__( "lock ; cmpxchg %3, %1"
8053 - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
8057 -static inline int a_cas(volatile int *p, int t, int s)
8059 - __asm__( "lock ; cmpxchg %3, %1"
8060 - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
8064 -static inline void a_or(volatile int *p, int v)
8066 - __asm__( "lock ; or %1, %0"
8067 - : "=m"(*p) : "r"(v) : "memory" );
8070 -static inline void a_and(volatile int *p, int v)
8072 - __asm__( "lock ; and %1, %0"
8073 - : "=m"(*p) : "r"(v) : "memory" );
8076 -static inline int a_swap(volatile int *x, int v)
8078 - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
8082 -static inline int a_fetch_add(volatile int *x, int v)
8084 - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
8088 -static inline void a_inc(volatile int *x)
8090 - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
8093 -static inline void a_dec(volatile int *x)
8095 - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
8098 -static inline void a_store(volatile int *p, int x)
8100 - __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
8103 -static inline void a_spin()
8105 - __asm__ __volatile__( "pause" : : : "memory" );
8108 -static inline void a_barrier()
8110 - __asm__ __volatile__( "" : : : "memory" );
8113 -static inline void a_crash()
8115 - __asm__ __volatile__( "hlt" : : : "memory" );
8121 +++ b/arch/x86_64/atomic_arch.h
8123 +#define a_cas a_cas
8124 +static inline int a_cas(volatile int *p, int t, int s)
8126 + __asm__ __volatile__ (
8127 + "lock ; cmpxchg %3, %1"
8128 + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
8132 +#define a_cas_p a_cas_p
8133 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
8135 + __asm__( "lock ; cmpxchg %3, %1"
8136 + : "=a"(t), "=m"(*(void *volatile *)p)
8137 + : "a"(t), "r"(s) : "memory" );
8141 +#define a_swap a_swap
8142 +static inline int a_swap(volatile int *p, int v)
8144 + __asm__ __volatile__(
8146 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
8150 +#define a_fetch_add a_fetch_add
8151 +static inline int a_fetch_add(volatile int *p, int v)
8153 + __asm__ __volatile__(
8154 + "lock ; xadd %0, %1"
8155 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
8159 +#define a_and a_and
8160 +static inline void a_and(volatile int *p, int v)
8162 + __asm__ __volatile__(
8163 + "lock ; and %1, %0"
8164 + : "=m"(*p) : "r"(v) : "memory" );
8168 +static inline void a_or(volatile int *p, int v)
8170 + __asm__ __volatile__(
8171 + "lock ; or %1, %0"
8172 + : "=m"(*p) : "r"(v) : "memory" );
8175 +#define a_and_64 a_and_64
8176 +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
8178 + __asm__ __volatile(
8179 + "lock ; and %1, %0"
8180 + : "=m"(*p) : "r"(v) : "memory" );
8183 +#define a_or_64 a_or_64
8184 +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
8186 + __asm__ __volatile__(
8187 + "lock ; or %1, %0"
8188 + : "=m"(*p) : "r"(v) : "memory" );
8191 +#define a_inc a_inc
8192 +static inline void a_inc(volatile int *p)
8194 + __asm__ __volatile__(
8196 + : "=m"(*p) : "m"(*p) : "memory" );
8199 +#define a_dec a_dec
8200 +static inline void a_dec(volatile int *p)
8202 + __asm__ __volatile__(
8204 + : "=m"(*p) : "m"(*p) : "memory" );
8207 +#define a_store a_store
8208 +static inline void a_store(volatile int *p, int x)
8210 + __asm__ __volatile__(
8211 + "mov %1, %0 ; lock ; orl $0,(%%rsp)"
8212 + : "=m"(*p) : "r"(x) : "memory" );
8215 +#define a_barrier a_barrier
8216 +static inline void a_barrier()
8218 + __asm__ __volatile__( "" : : : "memory" );
8221 +#define a_pause a_pause
8222 +static inline void a_spin()
8224 + __asm__ __volatile__( "pause" : : : "memory" );
8227 +#define a_crash a_crash
8228 +static inline void a_crash()
8230 + __asm__ __volatile__( "hlt" : : : "memory" );
8233 +#define a_ctz_64 a_ctz_64
8234 +static inline int a_ctz_64(uint64_t x)
8236 + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
8239 --- a/arch/x86_64/bits/errno.h
8277 -#define ENAMETOOLONG 36
8280 -#define ENOTEMPTY 39
8282 -#define EWOULDBLOCK EAGAIN
8286 -#define EL2NSYNC 45
8299 -#define EDEADLOCK EDEADLK
8313 -#define EMULTIHOP 72
8316 -#define EOVERFLOW 75
8317 -#define ENOTUNIQ 76
8324 -#define ELIBEXEC 83
8326 -#define ERESTART 85
8327 -#define ESTRPIPE 86
8329 -#define ENOTSOCK 88
8330 -#define EDESTADDRREQ 89
8331 -#define EMSGSIZE 90
8332 -#define EPROTOTYPE 91
8333 -#define ENOPROTOOPT 92
8334 -#define EPROTONOSUPPORT 93
8335 -#define ESOCKTNOSUPPORT 94
8336 -#define EOPNOTSUPP 95
8337 -#define ENOTSUP EOPNOTSUPP
8338 -#define EPFNOSUPPORT 96
8339 -#define EAFNOSUPPORT 97
8340 -#define EADDRINUSE 98
8341 -#define EADDRNOTAVAIL 99
8342 -#define ENETDOWN 100
8343 -#define ENETUNREACH 101
8344 -#define ENETRESET 102
8345 -#define ECONNABORTED 103
8346 -#define ECONNRESET 104
8347 -#define ENOBUFS 105
8348 -#define EISCONN 106
8349 -#define ENOTCONN 107
8350 -#define ESHUTDOWN 108
8351 -#define ETOOMANYREFS 109
8352 -#define ETIMEDOUT 110
8353 -#define ECONNREFUSED 111
8354 -#define EHOSTDOWN 112
8355 -#define EHOSTUNREACH 113
8356 -#define EALREADY 114
8357 -#define EINPROGRESS 115
8359 -#define EUCLEAN 117
8360 -#define ENOTNAM 118
8361 -#define ENAVAIL 119
8363 -#define EREMOTEIO 121
8365 -#define ENOMEDIUM 123
8366 -#define EMEDIUMTYPE 124
8367 -#define ECANCELED 125
8369 -#define EKEYEXPIRED 127
8370 -#define EKEYREVOKED 128
8371 -#define EKEYREJECTED 129
8372 -#define EOWNERDEAD 130
8373 -#define ENOTRECOVERABLE 131
8374 -#define ERFKILL 132
8375 -#define EHWPOISON 133
8376 --- a/arch/x86_64/bits/mman.h
8377 +++ b/arch/x86_64/bits/mman.h
8380 #define MCL_CURRENT 1
8381 #define MCL_FUTURE 2
8382 +#define MCL_ONFAULT 4
8384 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
8385 #define MADV_NORMAL 0
8386 --- a/arch/x86_64/bits/sem.h
8390 - struct ipc_perm sem_perm;
8395 -#if __BYTE_ORDER == __LITTLE_ENDIAN
8396 - unsigned short sem_nsems;
8397 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
8399 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
8400 - unsigned short sem_nsems;
8405 --- a/arch/x86_64/bits/statfs.h
8409 - unsigned long f_type, f_bsize;
8410 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
8411 - fsfilcnt_t f_files, f_ffree;
8413 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
8415 --- a/arch/x86_64/bits/stdarg.h
8418 -#define va_start(v,l) __builtin_va_start(v,l)
8419 -#define va_end(v) __builtin_va_end(v)
8420 -#define va_arg(v,l) __builtin_va_arg(v,l)
8421 -#define va_copy(d,s) __builtin_va_copy(d,s)
8422 --- a/arch/x86_64/bits/syscall.h
8423 +++ b/arch/x86_64/bits/syscall.h
8425 #define __NR_kexec_file_load 320
8426 #define __NR_bpf 321
8427 #define __NR_execveat 322
8428 +#define __NR_userfaultfd 323
8429 +#define __NR_membarrier 324
8430 +#define __NR_mlock2 325
8435 #define SYS_kexec_file_load 320
8437 #define SYS_execveat 322
8438 +#define SYS_userfaultfd 323
8439 +#define SYS_membarrier 324
8440 +#define SYS_mlock2 325
8441 --- a/arch/x86_64/bits/termios.h
8452 - speed_t __c_ispeed;
8453 - speed_t __c_ospeed;
8468 -#define VREPRINT 12
8469 -#define VDISCARD 13
8474 -#define IGNBRK 0000001
8475 -#define BRKINT 0000002
8476 -#define IGNPAR 0000004
8477 -#define PARMRK 0000010
8478 -#define INPCK 0000020
8479 -#define ISTRIP 0000040
8480 -#define INLCR 0000100
8481 -#define IGNCR 0000200
8482 -#define ICRNL 0000400
8483 -#define IUCLC 0001000
8484 -#define IXON 0002000
8485 -#define IXANY 0004000
8486 -#define IXOFF 0010000
8487 -#define IMAXBEL 0020000
8488 -#define IUTF8 0040000
8490 -#define OPOST 0000001
8491 -#define OLCUC 0000002
8492 -#define ONLCR 0000004
8493 -#define OCRNL 0000010
8494 -#define ONOCR 0000020
8495 -#define ONLRET 0000040
8496 -#define OFILL 0000100
8497 -#define OFDEL 0000200
8498 -#define NLDLY 0000400
8499 -#define NL0 0000000
8500 -#define NL1 0000400
8501 -#define CRDLY 0003000
8502 -#define CR0 0000000
8503 -#define CR1 0001000
8504 -#define CR2 0002000
8505 -#define CR3 0003000
8506 -#define TABDLY 0014000
8507 -#define TAB0 0000000
8508 -#define TAB1 0004000
8509 -#define TAB2 0010000
8510 -#define TAB3 0014000
8511 -#define BSDLY 0020000
8512 -#define BS0 0000000
8513 -#define BS1 0020000
8514 -#define FFDLY 0100000
8515 -#define FF0 0000000
8516 -#define FF1 0100000
8518 -#define VTDLY 0040000
8519 -#define VT0 0000000
8520 -#define VT1 0040000
8523 -#define B50 0000001
8524 -#define B75 0000002
8525 -#define B110 0000003
8526 -#define B134 0000004
8527 -#define B150 0000005
8528 -#define B200 0000006
8529 -#define B300 0000007
8530 -#define B600 0000010
8531 -#define B1200 0000011
8532 -#define B1800 0000012
8533 -#define B2400 0000013
8534 -#define B4800 0000014
8535 -#define B9600 0000015
8536 -#define B19200 0000016
8537 -#define B38400 0000017
8539 -#define B57600 0010001
8540 -#define B115200 0010002
8541 -#define B230400 0010003
8542 -#define B460800 0010004
8543 -#define B500000 0010005
8544 -#define B576000 0010006
8545 -#define B921600 0010007
8546 -#define B1000000 0010010
8547 -#define B1152000 0010011
8548 -#define B1500000 0010012
8549 -#define B2000000 0010013
8550 -#define B2500000 0010014
8551 -#define B3000000 0010015
8552 -#define B3500000 0010016
8553 -#define B4000000 0010017
8555 -#define CBAUD 0010017
8557 -#define CSIZE 0000060
8558 -#define CS5 0000000
8559 -#define CS6 0000020
8560 -#define CS7 0000040
8561 -#define CS8 0000060
8562 -#define CSTOPB 0000100
8563 -#define CREAD 0000200
8564 -#define PARENB 0000400
8565 -#define PARODD 0001000
8566 -#define HUPCL 0002000
8567 -#define CLOCAL 0004000
8569 -#define ISIG 0000001
8570 -#define ICANON 0000002
8571 -#define ECHO 0000010
8572 -#define ECHOE 0000020
8573 -#define ECHOK 0000040
8574 -#define ECHONL 0000100
8575 -#define NOFLSH 0000200
8576 -#define TOSTOP 0000400
8577 -#define IEXTEN 0100000
8579 -#define ECHOCTL 0001000
8580 -#define ECHOPRT 0002000
8581 -#define ECHOKE 0004000
8582 -#define FLUSHO 0010000
8583 -#define PENDIN 0040000
8592 -#define TCIOFLUSH 2
8595 -#define TCSADRAIN 1
8596 -#define TCSAFLUSH 2
8598 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
8599 -#define CBAUDEX 0010000
8600 -#define CRTSCTS 020000000000
8601 -#define EXTPROC 0200000
8602 -#define XTABS 0014000
8604 --- a/arch/x86_64/pthread_arch.h
8605 +++ b/arch/x86_64/pthread_arch.h
8606 @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
8608 #define TP_ADJ(p) (p)
8610 -#define CANCEL_REG_IP 16
8611 +#define MC_PC gregs[REG_RIP]
8614 @@ -9,6 +9,9 @@ VAR=VALUE. See below for descriptions o
8616 Defaults for the options are specified in brackets.
8619 + --srcdir=DIR source directory [detected]
8621 Installation directories:
8622 --prefix=PREFIX main installation prefix [/usr/local/musl]
8623 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
8624 @@ -117,6 +120,7 @@ CFLAGS_TRY=
8629 prefix=/usr/local/musl
8630 exec_prefix='$(prefix)'
8631 bindir='$(exec_prefix)/bin'
8632 @@ -139,6 +143,7 @@ clang_wrapper=no
8636 +--srcdir=*) srcdir=${arg#*=} ;;
8637 --prefix=*) prefix=${arg#*=} ;;
8638 --exec-prefix=*) exec_prefix=${arg#*=} ;;
8639 --bindir=*) bindir=${arg#*=} ;;
8640 @@ -179,11 +184,23 @@ LIBCC=*) LIBCC=${arg#*=} ;;
8644 -for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
8645 +for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do
8650 +# Get the source dir for out-of-tree builds
8652 +if test -z "$srcdir" ; then
8653 +srcdir="${0%/configure}"
8656 +abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
8657 +abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
8658 +test "$abs_srcdir" = "$abs_builddir" && srcdir=.
8659 +test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
8662 # Get a temp filename we can use
8665 @@ -263,11 +280,11 @@ fi
8668 if test "$gcc_wrapper" = yes ; then
8669 -tools="$tools tools/musl-gcc"
8670 +tools="$tools obj/musl-gcc"
8671 tool_libs="$tool_libs lib/musl-gcc.specs"
8673 if test "$clang_wrapper" = yes ; then
8674 -tools="$tools tools/musl-clang tools/ld.musl-clang"
8675 +tools="$tools obj/musl-clang obj/ld.musl-clang"
8679 @@ -321,7 +338,7 @@ __attribute__((__may_alias__))
8683 -if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
8684 +if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
8685 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
8688 @@ -330,6 +347,13 @@ CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_al
8692 +# The GNU toolchain defaults to assuming unmarked files need an
8693 +# executable stack, potentially exposing vulnerabilities in programs
8694 +# linked with such object files. Fix this.
8696 +tryflag CFLAGS_C99FSE -Wa,--noexecstack
8699 # Check for options to disable stack protector, which needs to be
8700 # disabled for a few early-bootstrap translation units. If not found,
8701 # this is not an error; we assume the toolchain does not do ssp.
8702 @@ -430,11 +454,15 @@ tryflag CFLAGS_AUTO -fno-unwind-tables
8703 tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
8706 -# The GNU toolchain defaults to assuming unmarked files need an
8707 -# executable stack, potentially exposing vulnerabilities in programs
8708 -# linked with such object files. Fix this.
8709 +# Attempt to put each function and each data object in its own
8710 +# section. This both allows additional size optimizations at link
8711 +# time and works around a dangerous class of compiler/assembler bugs
8712 +# whereby relative address expressions are constant-folded by the
8713 +# assembler even when one or more of the symbols involved is
8714 +# replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc.
8716 -tryflag CFLAGS_AUTO -Wa,--noexecstack
8717 +tryflag CFLAGS_AUTO -ffunction-sections
8718 +tryflag CFLAGS_AUTO -fdata-sections
8721 # On x86, make sure we don't have incompatible instruction set
8722 @@ -489,7 +517,7 @@ int foo(void) { }
8723 int bar(void) { fp = foo; return foo(); }
8725 if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \
8726 - -DSHARED -fPIC -I./src/internal -include vis.h \
8727 + -DSHARED -fPIC -I$srcdir/src/internal -include vis.h \
8728 -nostdlib -shared -Wl,-Bsymbolic-functions \
8729 -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
8731 @@ -504,6 +532,25 @@ CFLAGS_AUTO="$CFLAGS_AUTO -include vis.h
8732 CFLAGS_AUTO="${CFLAGS_AUTO# }"
8735 +# Determine if the compiler produces position-independent code (PIC)
8736 +# by default. If so, we don't need to compile separate object files
8737 +# for libc.a and libc.so.
8738 +if trycppif __PIC__ "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then
8744 +# Reduce space lost to padding for alignment purposes by sorting data
8745 +# objects according to their alignment reqirements. This approximates
8747 +tryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment
8748 +tryldflag LDFLAGS_AUTO -Wl,--sort-common
8750 +# When linking shared library, drop dummy weak definitions that were
8751 +# replaced by strong definitions from other translation units.
8752 +tryldflag LDFLAGS_AUTO -Wl,--gc-sections
8754 # Some patched GCC builds have these defaults messed up...
8755 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
8757 @@ -513,6 +560,11 @@ tryldflag LDFLAGS_AUTO -Wl,--hash-style=
8758 # runtime library; implementation error is also a possibility.
8759 tryldflag LDFLAGS_AUTO -Wl,--no-undefined
8761 +# Avoid exporting symbols from compiler runtime libraries. They
8762 +# should be hidden anyway, but some toolchains including old gcc
8763 +# versions built without shared library support and pcc are broken.
8764 +tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL
8766 test "$shared" = "no" || {
8767 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
8769 @@ -599,8 +651,9 @@ echo '#include <float.h>' > "$tmpc"
8770 echo '#if LDBL_MANT_DIG == 53' >> "$tmpc"
8771 echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc"
8772 echo '#endif' >> "$tmpc"
8773 -if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \
8774 - -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
8775 +if $CC $CFLAGS_C99FSE \
8776 + -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \
8777 + $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
8781 @@ -622,6 +675,7 @@ cat << EOF
8784 ASMSUBARCH = $ASMSUBARCH
8787 exec_prefix = $exec_prefix
8789 @@ -629,12 +683,14 @@ libdir = $libdir
8790 includedir = $includedir
8791 syslibdir = $syslibdir
8793 -CFLAGS = $CFLAGS_AUTO $CFLAGS
8795 +CFLAGS_AUTO = $CFLAGS_AUTO
8796 CFLAGS_C99FSE = $CFLAGS_C99FSE
8797 CFLAGS_MEMOPS = $CFLAGS_MEMOPS
8798 CFLAGS_NOSSP = $CFLAGS_NOSSP
8799 CPPFLAGS = $CPPFLAGS
8800 -LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
8802 +LDFLAGS_AUTO = $LDFLAGS_AUTO
8803 CROSS_COMPILE = $CROSS_COMPILE
8805 OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
8806 @@ -646,6 +702,9 @@ test "x$static" = xno && echo "STATIC_LI
8807 test "x$shared" = xno && echo "SHARED_LIBS ="
8808 test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
8809 test "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)'
8810 +test "x$pic_default" = xyes && echo 'AOBJS = $(LOBJS)'
8813 +test "$srcdir" = "." || ln -sf $srcdir/Makefile .
8816 --- a/crt/arm/crti.s
8817 +++ b/crt/arm/crti.s
8823 .type _init,%function
8824 --- a/crt/arm/crtn.s
8825 +++ b/crt/arm/crtn.s
8844 #define START "_start"
8845 #define _dlstart_c _start_c
8846 -#include "../src/ldso/dlstart.c"
8847 +#include "../ldso/dlstart.c"
8850 void _init() __attribute__((weak));
8851 --- a/include/complex.h
8852 +++ b/include/complex.h
8853 @@ -116,7 +116,7 @@ long double creall(long double complex);
8855 #if __STDC_VERSION__ >= 201112L
8856 #if defined(_Imaginary_I)
8857 -#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)))
8858 +#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y))
8859 #elif defined(__clang__)
8860 #define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) })
8862 --- a/include/netinet/in.h
8863 +++ b/include/netinet/in.h
8864 @@ -103,6 +103,7 @@ uint16_t ntohs(uint16_t);
8865 #define IPPROTO_SCTP 132
8866 #define IPPROTO_MH 135
8867 #define IPPROTO_UDPLITE 136
8868 +#define IPPROTO_MPLS 137
8869 #define IPPROTO_RAW 255
8870 #define IPPROTO_MAX 256
8872 @@ -200,6 +201,7 @@ uint16_t ntohs(uint16_t);
8873 #define IP_MINTTL 21
8874 #define IP_NODEFRAG 22
8875 #define IP_CHECKSUM 23
8876 +#define IP_BIND_ADDRESS_NO_PORT 24
8877 #define IP_MULTICAST_IF 32
8878 #define IP_MULTICAST_TTL 33
8879 #define IP_MULTICAST_LOOP 34
8880 --- a/include/netinet/tcp.h
8881 +++ b/include/netinet/tcp.h
8883 #define TCP_FASTOPEN 23
8884 #define TCP_TIMESTAMP 24
8885 #define TCP_NOTSENT_LOWAT 25
8886 +#define TCP_CC_INFO 26
8887 +#define TCP_SAVE_SYN 27
8888 +#define TCP_SAVED_SYN 28
8890 #define TCP_ESTABLISHED 1
8891 #define TCP_SYN_SENT 2
8893 #define TCP_CLOSING 11
8895 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
8896 +#define TCPOPT_EOL 0
8897 +#define TCPOPT_NOP 1
8898 +#define TCPOPT_MAXSEG 2
8899 +#define TCPOPT_WINDOW 3
8900 +#define TCPOPT_SACK_PERMITTED 4
8901 +#define TCPOPT_SACK 5
8902 +#define TCPOPT_TIMESTAMP 8
8903 +#define TCPOLEN_SACK_PERMITTED 2
8904 +#define TCPOLEN_WINDOW 3
8905 +#define TCPOLEN_MAXSEG 4
8906 +#define TCPOLEN_TIMESTAMP 10
8910 #include <sys/types.h>
8911 #include <sys/socket.h>
8913 @@ -164,6 +180,10 @@ struct tcp_info
8914 uint32_t tcpi_total_retrans;
8915 uint64_t tcpi_pacing_rate;
8916 uint64_t tcpi_max_pacing_rate;
8917 + uint64_t tcpi_bytes_acked;
8918 + uint64_t tcpi_bytes_received;
8919 + uint32_t tcpi_segs_out;
8920 + uint32_t tcpi_segs_in;
8923 #define TCP_MD5SIG_MAXKEYLEN 80
8924 --- a/include/netpacket/packet.h
8925 +++ b/include/netpacket/packet.h
8926 @@ -32,10 +32,27 @@ struct packet_mreq {
8927 #define PACKET_RECV_OUTPUT 3
8928 #define PACKET_RX_RING 5
8929 #define PACKET_STATISTICS 6
8930 +#define PACKET_COPY_THRESH 7
8931 +#define PACKET_AUXDATA 8
8932 +#define PACKET_ORIGDEV 9
8933 +#define PACKET_VERSION 10
8934 +#define PACKET_HDRLEN 11
8935 +#define PACKET_RESERVE 12
8936 +#define PACKET_TX_RING 13
8937 +#define PACKET_LOSS 14
8938 +#define PACKET_VNET_HDR 15
8939 +#define PACKET_TX_TIMESTAMP 16
8940 +#define PACKET_TIMESTAMP 17
8941 +#define PACKET_FANOUT 18
8942 +#define PACKET_TX_HAS_OFF 19
8943 +#define PACKET_QDISC_BYPASS 20
8944 +#define PACKET_ROLLOVER_STATS 21
8945 +#define PACKET_FANOUT_DATA 22
8947 #define PACKET_MR_MULTICAST 0
8948 #define PACKET_MR_PROMISC 1
8949 #define PACKET_MR_ALLMULTI 2
8950 +#define PACKET_MR_UNICAST 3
8954 --- a/include/signal.h
8955 +++ b/include/signal.h
8956 @@ -27,8 +27,6 @@ extern "C" {
8958 #include <bits/alltypes.h>
8960 -#define SIG_HOLD ((void (*)(int)) 2)
8963 #define SIG_UNBLOCK 1
8964 #define SIG_SETMASK 2
8965 @@ -43,6 +41,18 @@ extern "C" {
8967 #define SI_KERNEL 128
8969 +typedef struct sigaltstack stack_t;
8973 +#include <bits/signal.h>
8975 +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
8976 + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
8977 + || defined(_BSD_SOURCE)
8979 +#define SIG_HOLD ((void (*)(int)) 2)
8981 #define FPE_INTDIV 1
8982 #define FPE_INTOVF 2
8983 #define FPE_FLTDIV 3
8984 @@ -78,15 +88,17 @@ extern "C" {
8985 #define CLD_STOPPED 5
8986 #define CLD_CONTINUED 6
8988 -typedef struct sigaltstack stack_t;
8996 +#ifdef __SI_SWAP_ERRNO_CODE
8997 + int si_signo, si_code, si_errno;
8999 int si_signo, si_errno, si_code;
9002 char __pad[128 - 2*sizeof(int) - sizeof(long)];
9004 @@ -240,8 +252,6 @@ int sigandset(sigset_t *, const sigset_t
9005 #define SA_ONESHOT SA_RESETHAND
9008 -#include <bits/signal.h>
9010 #define SIG_ERR ((void (*)(int))-1)
9011 #define SIG_DFL ((void (*)(int)) 0)
9012 #define SIG_IGN ((void (*)(int)) 1)
9013 --- a/include/sys/mman.h
9014 +++ b/include/sys/mman.h
9015 @@ -39,6 +39,7 @@ int remap_file_pages (void *, size_t, in
9018 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
9019 +#define MLOCK_ONFAULT 0x01
9020 int madvise (void *, size_t, int);
9021 int mincore (void *, size_t, unsigned char *);
9023 --- a/include/sys/mount.h
9024 +++ b/include/sys/mount.h
9025 @@ -46,12 +46,13 @@ extern "C" {
9026 #define MS_KERNMOUNT (1<<22)
9027 #define MS_I_VERSION (1<<23)
9028 #define MS_STRICTATIME (1<<24)
9029 +#define MS_LAZYTIME (1<<25)
9030 #define MS_NOSEC (1<<28)
9031 #define MS_BORN (1<<29)
9032 #define MS_ACTIVE (1<<30)
9033 #define MS_NOUSER (1U<<31)
9035 -#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION)
9036 +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME)
9038 #define MS_MGC_VAL 0xc0ed0000
9039 #define MS_MGC_MSK 0xffff0000
9040 --- a/include/sys/prctl.h
9041 +++ b/include/sys/prctl.h
9042 @@ -124,6 +124,12 @@ struct prctl_mm_map {
9043 #define PR_FP_MODE_FR (1 << 0)
9044 #define PR_FP_MODE_FRE (1 << 1)
9046 +#define PR_CAP_AMBIENT 47
9047 +#define PR_CAP_AMBIENT_IS_SET 1
9048 +#define PR_CAP_AMBIENT_RAISE 2
9049 +#define PR_CAP_AMBIENT_LOWER 3
9050 +#define PR_CAP_AMBIENT_CLEAR_ALL 4
9052 int prctl (int, ...);
9055 --- a/include/sys/ptrace.h
9056 +++ b/include/sys/ptrace.h
9057 @@ -39,6 +39,7 @@ extern "C" {
9058 #define PTRACE_PEEKSIGINFO 0x4209
9059 #define PTRACE_GETSIGMASK 0x420a
9060 #define PTRACE_SETSIGMASK 0x420b
9061 +#define PTRACE_SECCOMP_GET_FILTER 0x420c
9063 #define PT_READ_I PTRACE_PEEKTEXT
9064 #define PT_READ_D PTRACE_PEEKDATA
9065 @@ -72,7 +73,8 @@ extern "C" {
9066 #define PTRACE_O_TRACEEXIT 0x00000040
9067 #define PTRACE_O_TRACESECCOMP 0x00000080
9068 #define PTRACE_O_EXITKILL 0x00100000
9069 -#define PTRACE_O_MASK 0x001000ff
9070 +#define PTRACE_O_SUSPEND_SECCOMP 0x00200000
9071 +#define PTRACE_O_MASK 0x003000ff
9073 #define PTRACE_EVENT_FORK 1
9074 #define PTRACE_EVENT_VFORK 2
9075 --- a/include/sys/socket.h
9076 +++ b/include/sys/socket.h
9077 @@ -96,6 +96,7 @@ struct linger
9078 #define PF_WANPIPE 25
9084 #define PF_BLUETOOTH 31
9085 @@ -141,6 +142,7 @@ struct linger
9086 #define AF_WANPIPE PF_WANPIPE
9087 #define AF_LLC PF_LLC
9089 +#define AF_MPLS PF_MPLS
9090 #define AF_CAN PF_CAN
9091 #define AF_TIPC PF_TIPC
9092 #define AF_BLUETOOTH PF_BLUETOOTH
9093 @@ -255,6 +257,7 @@ struct linger
9094 #define MSG_NOSIGNAL 0x4000
9095 #define MSG_MORE 0x8000
9096 #define MSG_WAITFORONE 0x10000
9097 +#define MSG_FASTOPEN 0x20000000
9098 #define MSG_CMSG_CLOEXEC 0x40000000
9100 #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
9102 +++ b/ldso/dlstart.c
9104 +#include <stddef.h>
9105 +#include "dynlink.h"
9108 +#define START "_dlstart"
9111 +#include "crt_arch.h"
9114 +#define GETFUNCSYM(fp, sym, got) do { \
9115 + __attribute__((__visibility__("hidden"))) void sym(); \
9116 + static void (*static_func_ptr)() = sym; \
9117 + __asm__ __volatile__ ( "" : "+m"(static_func_ptr) : : "memory"); \
9118 + *(fp) = static_func_ptr; } while(0)
9121 +__attribute__((__visibility__("hidden")))
9122 +void _dlstart_c(size_t *sp, size_t *dynv)
9124 + size_t i, aux[AUX_CNT], dyn[DYN_CNT];
9125 + size_t *rel, rel_size, base;
9128 + char **argv = (void *)(sp+1);
9130 + for (i=argc+1; argv[i]; i++);
9131 + size_t *auxv = (void *)(argv+i+1);
9133 + for (i=0; i<AUX_CNT; i++) aux[i] = 0;
9134 + for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT)
9135 + aux[auxv[i]] = auxv[i+1];
9138 + struct fdpic_loadseg *segs, fakeseg;
9141 + /* crt_arch.h entry point asm is responsible for reserving
9142 + * space and moving the extra fdpic arguments to the stack
9143 + * vector where they are easily accessible from C. */
9144 + segs = ((struct fdpic_loadmap *)(sp[-1] ? sp[-1] : sp[-2]))->segs;
9146 + /* If dynv is null, the entry point was started from loader
9147 + * that is not fdpic-aware. We can assume normal fixed-
9148 + * displacement ELF loading was performed, but when ldso was
9149 + * run as a command, finding the Ehdr is a heursitic: we
9150 + * have to assume Phdrs start in the first 4k of the file. */
9151 + base = aux[AT_BASE];
9152 + if (!base) base = aux[AT_PHDR] & -4096;
9154 + segs[0].addr = base;
9155 + segs[0].p_vaddr = 0;
9156 + segs[0].p_memsz = -1;
9157 + Ehdr *eh = (void *)base;
9158 + Phdr *ph = (void *)(base + eh->e_phoff);
9159 + size_t phnum = eh->e_phnum;
9160 + size_t phent = eh->e_phentsize;
9161 + while (phnum-- && ph->p_type != PT_DYNAMIC)
9162 + ph = (void *)((size_t)ph + phent);
9163 + dynv = (void *)(base + ph->p_vaddr);
9167 + for (i=0; i<DYN_CNT; i++) dyn[i] = 0;
9168 + for (i=0; dynv[i]; i+=2) if (dynv[i]<DYN_CNT)
9169 + dyn[dynv[i]] = dynv[i+1];
9172 + for (i=0; i<DYN_CNT; i++) {
9173 + if (i==DT_RELASZ || i==DT_RELSZ) continue;
9174 + if (!dyn[i]) continue;
9175 + for (j=0; dyn[i]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
9176 + dyn[i] += segs[j].addr - segs[j].p_vaddr;
9180 + const Sym *syms = (void *)dyn[DT_SYMTAB];
9182 + rel = (void *)dyn[DT_RELA];
9183 + rel_size = dyn[DT_RELASZ];
9184 + for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
9185 + if (!IS_RELATIVE(rel[1], syms)) continue;
9186 + for (j=0; rel[0]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
9187 + size_t *rel_addr = (void *)
9188 + (rel[0] + segs[j].addr - segs[j].p_vaddr);
9189 + if (R_TYPE(rel[1]) == REL_FUNCDESC_VAL) {
9190 + *rel_addr += segs[rel_addr[1]].addr
9191 + - segs[rel_addr[1]].p_vaddr
9192 + + syms[R_SYM(rel[1])].st_value;
9193 + rel_addr[1] = dyn[DT_PLTGOT];
9195 + size_t val = syms[R_SYM(rel[1])].st_value;
9196 + for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
9197 + *rel_addr = rel[2] + segs[j].addr - segs[j].p_vaddr + val;
9201 + /* If the dynamic linker is invoked as a command, its load
9202 + * address is not available in the aux vector. Instead, compute
9203 + * the load address as the difference between &_DYNAMIC and the
9204 + * virtual address in the PT_DYNAMIC program header. */
9205 + base = aux[AT_BASE];
9207 + size_t phnum = aux[AT_PHNUM];
9208 + size_t phentsize = aux[AT_PHENT];
9209 + Phdr *ph = (void *)aux[AT_PHDR];
9210 + for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
9211 + if (ph->p_type == PT_DYNAMIC) {
9212 + base = (size_t)dynv - ph->p_vaddr;
9218 + /* MIPS uses an ugly packed form for GOT relocations. Since we
9219 + * can't make function calls yet and the code is tiny anyway,
9220 + * it's simply inlined here. */
9221 + if (NEED_MIPS_GOT_RELOCS) {
9222 + size_t local_cnt = 0;
9223 + size_t *got = (void *)(base + dyn[DT_PLTGOT]);
9224 + for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
9225 + local_cnt = dynv[i+1];
9226 + for (i=0; i<local_cnt; i++) got[i] += base;
9229 + rel = (void *)(base+dyn[DT_REL]);
9230 + rel_size = dyn[DT_RELSZ];
9231 + for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
9232 + if (!IS_RELATIVE(rel[1], 0)) continue;
9233 + size_t *rel_addr = (void *)(base + rel[0]);
9234 + *rel_addr += base;
9237 + rel = (void *)(base+dyn[DT_RELA]);
9238 + rel_size = dyn[DT_RELASZ];
9239 + for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
9240 + if (!IS_RELATIVE(rel[1], 0)) continue;
9241 + size_t *rel_addr = (void *)(base + rel[0]);
9242 + *rel_addr = base + rel[2];
9247 + GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
9248 + dls2((void *)base, sp);
9251 +++ b/ldso/dynlink.c
9253 +#define _GNU_SOURCE
9255 +#include <stdlib.h>
9256 +#include <stdarg.h>
9257 +#include <stddef.h>
9258 +#include <string.h>
9259 +#include <unistd.h>
9260 +#include <stdint.h>
9262 +#include <sys/mman.h>
9263 +#include <limits.h>
9265 +#include <sys/stat.h>
9268 +#include <setjmp.h>
9269 +#include <pthread.h>
9272 +#include "pthread_impl.h"
9274 +#include "dynlink.h"
9276 +static void error(const char *, ...);
9278 +#define MAXP2(a,b) (-(-(a)&-(b)))
9279 +#define ALIGN(x,y) ((x)+(y)-1 & -(y))
9291 + struct td_index *next;
9296 + struct fdpic_loadmap *loadmap;
9298 + unsigned char *base;
9302 + struct dso *next, *prev;
9309 + uint32_t *hashtab;
9310 + uint32_t *ghashtab;
9313 + unsigned char *map;
9317 + signed char global;
9320 + char kernel_mapped;
9321 + struct dso **deps, *needed_by;
9322 + char *rpath_orig, *rpath;
9323 + struct tls_module tls;
9325 + size_t relro_start, relro_end;
9327 + unsigned char *new_tls;
9328 + volatile int new_dtv_idx, new_tls_idx;
9329 + struct td_index *td_index;
9330 + struct dso *fini_next;
9333 + unsigned char *base;
9335 + struct fdpic_loadmap *loadmap;
9350 +int __init_tp(void *);
9351 +void __init_libc(char **, char *);
9352 +void *__copy_tls(unsigned char *);
9354 +__attribute__((__visibility__("hidden")))
9355 +const char *__libc_get_version(void);
9357 +static struct builtin_tls {
9359 + struct pthread pt;
9362 +#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
9364 +#define ADDEND_LIMIT 4096
9365 +static size_t *saved_addends, *apply_addends_to;
9367 +static struct dso ldso;
9368 +static struct dso *head, *tail, *fini_head;
9369 +static char *env_path, *sys_path;
9370 +static unsigned long long gencnt;
9371 +static int runtime;
9372 +static int ldd_mode;
9373 +static int ldso_fail;
9375 +static jmp_buf *rtld_fail;
9376 +static pthread_rwlock_t lock;
9377 +static struct debug debug;
9378 +static struct tls_module *tls_tail;
9379 +static size_t tls_cnt, tls_offset, tls_align = MIN_TLS_ALIGN;
9380 +static size_t static_tls_cnt;
9381 +static pthread_mutex_t init_fini_lock = { ._m_type = PTHREAD_MUTEX_RECURSIVE };
9382 +static struct fdpic_loadmap *app_loadmap;
9383 +static struct fdpic_dummy_loadmap app_dummy_loadmap;
9385 +struct debug *_dl_debug_addr = &debug;
9387 +__attribute__((__visibility__("hidden")))
9388 +void (*const __init_array_start)(void)=0, (*const __fini_array_start)(void)=0;
9390 +__attribute__((__visibility__("hidden")))
9391 +extern void (*const __init_array_end)(void), (*const __fini_array_end)(void);
9393 +weak_alias(__init_array_start, __init_array_end);
9394 +weak_alias(__fini_array_start, __fini_array_end);
9396 +static int dl_strcmp(const char *l, const char *r)
9398 + for (; *l==*r && *l; l++, r++);
9399 + return *(unsigned char *)l - *(unsigned char *)r;
9401 +#define strcmp(l,r) dl_strcmp(l,r)
9403 +/* Compute load address for a virtual address in a given dso. */
9405 +static void *laddr(const struct dso *p, size_t v)
9408 + if (!p->loadmap) return p->base + v;
9409 + for (j=0; v-p->loadmap->segs[j].p_vaddr >= p->loadmap->segs[j].p_memsz; j++);
9410 + return (void *)(v - p->loadmap->segs[j].p_vaddr + p->loadmap->segs[j].addr);
9412 +#define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \
9413 + laddr(p, v), (p)->got })
9415 +#define laddr(p, v) (void *)((p)->base + (v))
9416 +#define fpaddr(p, v) ((void (*)())laddr(p, v))
9419 +static void decode_vec(size_t *v, size_t *a, size_t cnt)
9422 + for (i=0; i<cnt; i++) a[i] = 0;
9423 + for (; v[0]; v+=2) if (v[0]-1<cnt-1) {
9424 + a[0] |= 1UL<<v[0];
9429 +static int search_vec(size_t *v, size_t *r, size_t key)
9431 + for (; v[0]!=key; v+=2)
9432 + if (!v[0]) return 0;
9437 +static uint32_t sysv_hash(const char *s0)
9439 + const unsigned char *s = (void *)s0;
9440 + uint_fast32_t h = 0;
9443 + h ^= h>>24 & 0xf0;
9445 + return h & 0xfffffff;
9448 +static uint32_t gnu_hash(const char *s0)
9450 + const unsigned char *s = (void *)s0;
9451 + uint_fast32_t h = 5381;
9457 +static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
9460 + Sym *syms = dso->syms;
9461 + uint32_t *hashtab = dso->hashtab;
9462 + char *strings = dso->strings;
9463 + for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) {
9464 + if ((!dso->versym || dso->versym[i] >= 0)
9465 + && (!strcmp(s, strings+syms[i].st_name)))
9471 +static Sym *gnu_lookup(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s)
9473 + uint32_t nbuckets = hashtab[0];
9474 + uint32_t *buckets = hashtab + 4 + hashtab[2]*(sizeof(size_t)/4);
9475 + uint32_t i = buckets[h1 % nbuckets];
9479 + uint32_t *hashval = buckets + nbuckets + (i - hashtab[1]);
9481 + for (h1 |= 1; ; i++) {
9482 + uint32_t h2 = *hashval++;
9483 + if ((h1 == (h2|1)) && (!dso->versym || dso->versym[i] >= 0)
9484 + && !strcmp(s, dso->strings + dso->syms[i].st_name))
9485 + return dso->syms+i;
9486 + if (h2 & 1) break;
9492 +static Sym *gnu_lookup_filtered(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s, uint32_t fofs, size_t fmask)
9494 + const size_t *bloomwords = (const void *)(hashtab+4);
9495 + size_t f = bloomwords[fofs & (hashtab[2]-1)];
9496 + if (!(f & fmask)) return 0;
9498 + f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
9499 + if (!(f & 1)) return 0;
9501 + return gnu_lookup(h1, hashtab, dso, s);
9504 +#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON | 1<<STT_TLS)
9505 +#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
9507 +#ifndef ARCH_SYM_REJECT_UND
9508 +#define ARCH_SYM_REJECT_UND(s) 0
9511 +static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
9513 + uint32_t h = 0, gh, gho, *ght;
9515 + struct symdef def = {0};
9516 + for (; dso; dso=dso->next) {
9518 + if (!dso->global) continue;
9519 + if ((ght = dso->ghashtab)) {
9522 + int maskbits = 8 * sizeof ghm;
9523 + gho = gh / maskbits;
9524 + ghm = 1ul << gh % maskbits;
9526 + sym = gnu_lookup_filtered(gh, ght, dso, s, gho, ghm);
9528 + if (!h) h = sysv_hash(s);
9529 + sym = sysv_lookup(s, h, dso);
9531 + if (!sym) continue;
9532 + if (!sym->st_shndx)
9533 + if (need_def || (sym->st_info&0xf) == STT_TLS
9534 + || ARCH_SYM_REJECT_UND(sym))
9536 + if (!sym->st_value)
9537 + if ((sym->st_info&0xf) != STT_TLS)
9539 + if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
9540 + if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
9542 + if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
9545 + if (sym->st_info>>4 == STB_GLOBAL) break;
9550 +__attribute__((__visibility__("hidden")))
9551 +ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
9553 +static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
9555 + unsigned char *base = dso->base;
9556 + Sym *syms = dso->syms;
9557 + char *strings = dso->strings;
9563 + struct symdef def;
9564 + size_t *reloc_addr;
9568 + int skip_relative = 0, reuse_addends = 0, save_slot = 0;
9570 + if (dso == &ldso) {
9571 + /* Only ldso's REL table needs addend saving/reuse. */
9572 + if (rel == apply_addends_to)
9573 + reuse_addends = 1;
9574 + skip_relative = 1;
9577 + for (; rel_size; rel+=stride, rel_size-=stride*sizeof(size_t)) {
9578 + if (skip_relative && IS_RELATIVE(rel[1], dso->syms)) continue;
9579 + type = R_TYPE(rel[1]);
9580 + if (type == REL_NONE) continue;
9581 + sym_index = R_SYM(rel[1]);
9582 + reloc_addr = laddr(dso, rel[0]);
9584 + sym = syms + sym_index;
9585 + name = strings + sym->st_name;
9586 + ctx = type==REL_COPY ? head->next : head;
9587 + def = (sym->st_info&0xf) == STT_SECTION
9588 + ? (struct symdef){ .dso = dso, .sym = sym }
9589 + : find_sym(ctx, name, type==REL_PLT);
9590 + if (!def.sym && (sym->st_shndx != SHN_UNDEF
9591 + || sym->st_info>>4 != STB_WEAK)) {
9592 + error("Error relocating %s: %s: symbol not found",
9594 + if (runtime) longjmp(*rtld_fail, 1);
9605 + } else if (type==REL_GOT || type==REL_PLT|| type==REL_COPY) {
9607 + } else if (reuse_addends) {
9608 + /* Save original addend in stage 2 where the dso
9609 + * chain consists of just ldso; otherwise read back
9610 + * saved addend since the inline one was clobbered. */
9612 + saved_addends[save_slot] = *reloc_addr;
9613 + addend = saved_addends[save_slot++];
9615 + addend = *reloc_addr;
9618 + sym_val = def.sym ? (size_t)laddr(def.dso, def.sym->st_value) : 0;
9619 + tls_val = def.sym ? def.sym->st_value : 0;
9625 + addend -= (size_t)reloc_addr;
9626 + case REL_SYMBOLIC:
9629 + *reloc_addr = sym_val + addend;
9631 + case REL_RELATIVE:
9632 + *reloc_addr = (size_t)base + addend;
9634 + case REL_SYM_OR_REL:
9635 + if (sym) *reloc_addr = sym_val + addend;
9636 + else *reloc_addr = (size_t)base + addend;
9639 + memcpy(reloc_addr, (void *)sym_val, sym->st_size);
9641 + case REL_OFFSET32:
9642 + *(uint32_t *)reloc_addr = sym_val + addend
9643 + - (size_t)reloc_addr;
9645 + case REL_FUNCDESC:
9646 + *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs
9647 + + (def.sym - def.dso->syms)) : 0;
9649 + case REL_FUNCDESC_VAL:
9650 + if ((sym->st_info&0xf) == STT_SECTION) *reloc_addr += sym_val;
9651 + else *reloc_addr = sym_val;
9652 + reloc_addr[1] = def.sym ? (size_t)def.dso->got : 0;
9655 + *reloc_addr = def.dso->tls_id;
9658 + *reloc_addr = tls_val + addend - DTP_OFFSET;
9660 +#ifdef TLS_ABOVE_TP
9662 + *reloc_addr = tls_val + def.dso->tls.offset + TPOFF_K + addend;
9666 + *reloc_addr = tls_val - def.dso->tls.offset + addend;
9668 + case REL_TPOFF_NEG:
9669 + *reloc_addr = def.dso->tls.offset - tls_val + addend;
9673 + if (stride<3) addend = reloc_addr[1];
9674 + if (runtime && def.dso->tls_id >= static_tls_cnt) {
9675 + struct td_index *new = malloc(sizeof *new);
9678 + "Error relocating %s: cannot allocate TLSDESC for %s",
9679 + dso->name, sym ? name : "(local)" );
9680 + longjmp(*rtld_fail, 1);
9682 + new->next = dso->td_index;
9683 + dso->td_index = new;
9684 + new->args[0] = def.dso->tls_id;
9685 + new->args[1] = tls_val + addend;
9686 + reloc_addr[0] = (size_t)__tlsdesc_dynamic;
9687 + reloc_addr[1] = (size_t)new;
9689 + reloc_addr[0] = (size_t)__tlsdesc_static;
9690 +#ifdef TLS_ABOVE_TP
9691 + reloc_addr[1] = tls_val + def.dso->tls.offset
9692 + + TPOFF_K + addend;
9694 + reloc_addr[1] = tls_val - def.dso->tls.offset
9700 + error("Error relocating %s: unsupported relocation type %d",
9702 + if (runtime) longjmp(*rtld_fail, 1);
9708 +/* A huge hack: to make up for the wastefulness of shared libraries
9709 + * needing at least a page of dirty memory even if they have no global
9710 + * data, we reclaim the gaps at the beginning and end of writable maps
9711 + * and "donate" them to the heap by setting up minimal malloc
9712 + * structures and then freeing them. */
9714 +static void reclaim(struct dso *dso, size_t start, size_t end)
9717 + if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end;
9718 + if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start;
9719 + start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t);
9720 + end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t);
9721 + if (start>end || end-start < 4*sizeof(size_t)) return;
9722 + a = laddr(dso, start);
9723 + z = laddr(dso, end);
9725 + a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1;
9730 +static void reclaim_gaps(struct dso *dso)
9732 + Phdr *ph = dso->phdr;
9733 + size_t phcnt = dso->phnum;
9735 + if (DL_FDPIC) return; // FIXME
9736 + for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
9737 + if (ph->p_type!=PT_LOAD) continue;
9738 + if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
9739 + reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
9740 + reclaim(dso, ph->p_vaddr+ph->p_memsz,
9741 + ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
9745 +static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t off)
9747 + static int no_map_fixed;
9749 + if (!no_map_fixed) {
9750 + q = mmap(p, n, prot, flags|MAP_FIXED, fd, off);
9751 + if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL)
9755 + /* Fallbacks for MAP_FIXED failure on NOMMU kernels. */
9756 + if (flags & MAP_ANONYMOUS) {
9761 + if (lseek(fd, off, SEEK_SET) < 0) return MAP_FAILED;
9762 + for (q=p; n; q+=r, off+=r, n-=r) {
9763 + r = read(fd, q, n);
9764 + if (r < 0 && errno != EINTR) return MAP_FAILED;
9773 +static void unmap_library(struct dso *dso)
9775 + if (dso->loadmap) {
9777 + for (i=0; i<dso->loadmap->nsegs; i++) {
9778 + if (!dso->loadmap->segs[i].p_memsz)
9780 + munmap((void *)dso->loadmap->segs[i].addr,
9781 + dso->loadmap->segs[i].p_memsz);
9783 + free(dso->loadmap);
9784 + } else if (dso->map && dso->map_len) {
9785 + munmap(dso->map, dso->map_len);
9789 +static void *map_library(int fd, struct dso *dso)
9791 + Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
9792 + void *allocated_buf=0;
9794 + size_t addr_min=SIZE_MAX, addr_max=0, map_len;
9795 + size_t this_min, this_max;
9801 + unsigned char *map=MAP_FAILED, *base;
9803 + size_t tls_image=0;
9806 + ssize_t l = read(fd, buf, sizeof buf);
9808 + if (l<0) return 0;
9809 + if (l<sizeof *eh || (eh->e_type != ET_DYN && eh->e_type != ET_EXEC))
9811 + phsize = eh->e_phentsize * eh->e_phnum;
9812 + if (phsize > sizeof buf - sizeof *eh) {
9813 + allocated_buf = malloc(phsize);
9814 + if (!allocated_buf) return 0;
9815 + l = pread(fd, allocated_buf, phsize, eh->e_phoff);
9816 + if (l < 0) goto error;
9817 + if (l != phsize) goto noexec;
9818 + ph = ph0 = allocated_buf;
9819 + } else if (eh->e_phoff + phsize > l) {
9820 + l = pread(fd, buf+1, phsize, eh->e_phoff);
9821 + if (l < 0) goto error;
9822 + if (l != phsize) goto noexec;
9823 + ph = ph0 = (void *)(buf + 1);
9825 + ph = ph0 = (void *)((char *)buf + eh->e_phoff);
9827 + for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
9828 + if (ph->p_type == PT_DYNAMIC) {
9829 + dyn = ph->p_vaddr;
9830 + } else if (ph->p_type == PT_TLS) {
9831 + tls_image = ph->p_vaddr;
9832 + dso->tls.align = ph->p_align;
9833 + dso->tls.len = ph->p_filesz;
9834 + dso->tls.size = ph->p_memsz;
9835 + } else if (ph->p_type == PT_GNU_RELRO) {
9836 + dso->relro_start = ph->p_vaddr & -PAGE_SIZE;
9837 + dso->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
9839 + if (ph->p_type != PT_LOAD) continue;
9841 + if (ph->p_vaddr < addr_min) {
9842 + addr_min = ph->p_vaddr;
9843 + off_start = ph->p_offset;
9844 + prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
9845 + ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
9846 + ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
9848 + if (ph->p_vaddr+ph->p_memsz > addr_max) {
9849 + addr_max = ph->p_vaddr+ph->p_memsz;
9852 + if (!dyn) goto noexec;
9853 + if (DL_FDPIC && !(eh->e_flags & FDPIC_CONSTDISP_FLAG)) {
9854 + dso->loadmap = calloc(1, sizeof *dso->loadmap
9855 + + nsegs * sizeof *dso->loadmap->segs);
9856 + if (!dso->loadmap) goto error;
9857 + dso->loadmap->nsegs = nsegs;
9858 + for (ph=ph0, i=0; i<nsegs; ph=(void *)((char *)ph+eh->e_phentsize)) {
9859 + if (ph->p_type != PT_LOAD) continue;
9860 + prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
9861 + ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
9862 + ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
9863 + map = mmap(0, ph->p_memsz + (ph->p_vaddr & PAGE_SIZE-1),
9864 + prot, MAP_PRIVATE,
9865 + fd, ph->p_offset & -PAGE_SIZE);
9866 + if (map == MAP_FAILED) {
9867 + unmap_library(dso);
9870 + dso->loadmap->segs[i].addr = (size_t)map +
9871 + (ph->p_vaddr & PAGE_SIZE-1);
9872 + dso->loadmap->segs[i].p_vaddr = ph->p_vaddr;
9873 + dso->loadmap->segs[i].p_memsz = ph->p_memsz;
9875 + if (prot & PROT_WRITE) {
9876 + size_t brk = (ph->p_vaddr & PAGE_SIZE-1)
9878 + size_t pgbrk = brk + PAGE_SIZE-1 & -PAGE_SIZE;
9879 + size_t pgend = brk + ph->p_memsz - ph->p_filesz
9880 + + PAGE_SIZE-1 & -PAGE_SIZE;
9881 + if (pgend > pgbrk && mmap_fixed(map+pgbrk,
9882 + pgend-pgbrk, prot,
9883 + MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS,
9884 + -1, off_start) == MAP_FAILED)
9886 + memset(map + brk, 0, pgbrk-brk);
9889 + map = (void *)dso->loadmap->segs[0].addr;
9891 + goto done_mapping;
9893 + addr_max += PAGE_SIZE-1;
9894 + addr_max &= -PAGE_SIZE;
9895 + addr_min &= -PAGE_SIZE;
9896 + off_start &= -PAGE_SIZE;
9897 + map_len = addr_max - addr_min + off_start;
9898 + /* The first time, we map too much, possibly even more than
9899 + * the length of the file. This is okay because we will not
9900 + * use the invalid part; we just need to reserve the right
9901 + * amount of virtual address space to map over later. */
9902 + map = DL_NOMMU_SUPPORT
9903 + ? mmap((void *)addr_min, map_len, PROT_READ|PROT_WRITE|PROT_EXEC,
9904 + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
9905 + : mmap((void *)addr_min, map_len, prot,
9906 + MAP_PRIVATE, fd, off_start);
9907 + if (map==MAP_FAILED) goto error;
9909 + dso->map_len = map_len;
9910 + /* If the loaded file is not relocatable and the requested address is
9911 + * not available, then the load operation must fail. */
9912 + if (eh->e_type != ET_DYN && addr_min && map!=(void *)addr_min) {
9916 + base = map - addr_min;
9919 + for (ph=ph0, i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
9920 + if (ph->p_type != PT_LOAD) continue;
9921 + /* Check if the programs headers are in this load segment, and
9922 + * if so, record the address for use by dl_iterate_phdr. */
9923 + if (!dso->phdr && eh->e_phoff >= ph->p_offset
9924 + && eh->e_phoff+phsize <= ph->p_offset+ph->p_filesz) {
9925 + dso->phdr = (void *)(base + ph->p_vaddr
9926 + + (eh->e_phoff-ph->p_offset));
9927 + dso->phnum = eh->e_phnum;
9928 + dso->phentsize = eh->e_phentsize;
9930 + /* Reuse the existing mapping for the lowest-address LOAD */
9931 + if ((ph->p_vaddr & -PAGE_SIZE) == addr_min && !DL_NOMMU_SUPPORT)
9933 + this_min = ph->p_vaddr & -PAGE_SIZE;
9934 + this_max = ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE;
9935 + off_start = ph->p_offset & -PAGE_SIZE;
9936 + prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
9937 + ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
9938 + ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
9939 + if (mmap_fixed(base+this_min, this_max-this_min, prot, MAP_PRIVATE|MAP_FIXED, fd, off_start) == MAP_FAILED)
9941 + if (ph->p_memsz > ph->p_filesz) {
9942 + size_t brk = (size_t)base+ph->p_vaddr+ph->p_filesz;
9943 + size_t pgbrk = brk+PAGE_SIZE-1 & -PAGE_SIZE;
9944 + memset((void *)brk, 0, pgbrk-brk & PAGE_SIZE-1);
9945 + if (pgbrk-(size_t)base < this_max && mmap_fixed((void *)pgbrk, (size_t)base+this_max-pgbrk, prot, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED)
9949 + for (i=0; ((size_t *)(base+dyn))[i]; i+=2)
9950 + if (((size_t *)(base+dyn))[i]==DT_TEXTREL) {
9951 + if (mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC)
9952 + && errno != ENOSYS)
9958 + dso->dynv = laddr(dso, dyn);
9959 + if (dso->tls.size) dso->tls.image = laddr(dso, tls_image);
9960 + if (!runtime) reclaim_gaps(dso);
9961 + free(allocated_buf);
9966 + if (map!=MAP_FAILED) unmap_library(dso);
9967 + free(allocated_buf);
9971 +static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
9976 + s += strspn(s, ":\n");
9977 + l = strcspn(s, ":\n");
9978 + if (l-1 >= INT_MAX) return -1;
9979 + if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
9980 + if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd;
9985 + case ENAMETOOLONG:
9988 + /* Any negative value but -1 will inhibit
9989 + * futher path search. */
9997 +static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
10000 + const char *s, *t, *origin;
10002 + if (p->rpath || !p->rpath_orig) return 0;
10003 + if (!strchr(p->rpath_orig, '$')) {
10004 + p->rpath = p->rpath_orig;
10008 + s = p->rpath_orig;
10009 + while ((t=strchr(s, '$'))) {
10010 + if (strncmp(t, "$ORIGIN", 7) && strncmp(t, "${ORIGIN}", 9))
10015 + if (n > SSIZE_MAX/PATH_MAX) return 0;
10017 + if (p->kernel_mapped) {
10018 + /* $ORIGIN searches cannot be performed for the main program
10019 + * when it is suid/sgid/AT_SECURE. This is because the
10020 + * pathname is under the control of the caller of execve.
10021 + * For libraries, however, $ORIGIN can be processed safely
10022 + * since the library's pathname came from a trusted source
10023 + * (either system paths or a call to dlopen). */
10026 + l = readlink("/proc/self/exe", buf, buf_size);
10027 + if (l == -1) switch (errno) {
10035 + if (l >= buf_size)
10040 + origin = p->name;
10042 + t = strrchr(origin, '/');
10043 + l = t ? t-origin : 0;
10044 + p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1);
10045 + if (!p->rpath) return -1;
10048 + s = p->rpath_orig;
10049 + while ((t=strchr(s, '$'))) {
10050 + memcpy(d, s, t-s);
10052 + memcpy(d, origin, l);
10054 + /* It was determined previously that the '$' is followed
10055 + * either by "ORIGIN" or "{ORIGIN}". */
10056 + s = t + 7 + 2*(t[1]=='{');
10062 +static void decode_dyn(struct dso *p)
10064 + size_t dyn[DYN_CNT];
10065 + decode_vec(p->dynv, dyn, DYN_CNT);
10066 + p->syms = laddr(p, dyn[DT_SYMTAB]);
10067 + p->strings = laddr(p, dyn[DT_STRTAB]);
10068 + if (dyn[0]&(1<<DT_HASH))
10069 + p->hashtab = laddr(p, dyn[DT_HASH]);
10070 + if (dyn[0]&(1<<DT_RPATH))
10071 + p->rpath_orig = p->strings + dyn[DT_RPATH];
10072 + if (dyn[0]&(1<<DT_RUNPATH))
10073 + p->rpath_orig = p->strings + dyn[DT_RUNPATH];
10074 + if (dyn[0]&(1<<DT_PLTGOT))
10075 + p->got = laddr(p, dyn[DT_PLTGOT]);
10076 + if (search_vec(p->dynv, dyn, DT_GNU_HASH))
10077 + p->ghashtab = laddr(p, *dyn);
10078 + if (search_vec(p->dynv, dyn, DT_VERSYM))
10079 + p->versym = laddr(p, *dyn);
10082 +static size_t count_syms(struct dso *p)
10084 + if (p->hashtab) return p->hashtab[1];
10087 + uint32_t *buckets = p->ghashtab + 4 + (p->ghashtab[2]*sizeof(size_t)/4);
10088 + uint32_t *hashval;
10089 + for (i = nsym = 0; i < p->ghashtab[0]; i++) {
10090 + if (buckets[i] > nsym)
10091 + nsym = buckets[i];
10094 + hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
10096 + while (!(*hashval++ & 1));
10101 +static void *dl_mmap(size_t n)
10104 + int prot = PROT_READ|PROT_WRITE, flags = MAP_ANONYMOUS|MAP_PRIVATE;
10106 + p = (void *)__syscall(SYS_mmap2, 0, n, prot, flags, -1, 0);
10108 + p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
10110 + return p == MAP_FAILED ? 0 : p;
10113 +static void makefuncdescs(struct dso *p)
10115 + static int self_done;
10116 + size_t nsym = count_syms(p);
10117 + size_t i, size = nsym * sizeof(*p->funcdescs);
10119 + if (!self_done) {
10120 + p->funcdescs = dl_mmap(size);
10123 + p->funcdescs = malloc(size);
10125 + if (!p->funcdescs) {
10126 + if (!runtime) a_crash();
10127 + error("Error allocating function descriptors for %s", p->name);
10128 + longjmp(*rtld_fail, 1);
10130 + for (i=0; i<nsym; i++) {
10131 + if ((p->syms[i].st_info&0xf)==STT_FUNC && p->syms[i].st_shndx) {
10132 + p->funcdescs[i].addr = laddr(p, p->syms[i].st_value);
10133 + p->funcdescs[i].got = p->got;
10135 + p->funcdescs[i].addr = 0;
10136 + p->funcdescs[i].got = 0;
10141 +static struct dso *load_library(const char *name, struct dso *needed_by)
10143 + char buf[2*NAME_MAX+2];
10144 + const char *pathname;
10145 + unsigned char *map;
10146 + struct dso *p, temp_dso = {0};
10149 + size_t alloc_size;
10158 + /* Catch and block attempts to reload the implementation itself */
10159 + if (name[0]=='l' && name[1]=='i' && name[2]=='b') {
10160 + static const char *rp, reserved[] =
10161 + "c\0pthread\0rt\0m\0dl\0util\0xnet\0";
10162 + char *z = strchr(name, '.');
10164 + size_t l = z-name;
10165 + for (rp=reserved; *rp && strncmp(name+3, rp, l-3); rp+=strlen(rp)+1);
10168 + /* Track which names have been resolved
10169 + * and only report each one once. */
10170 + static unsigned reported;
10171 + unsigned mask = 1U<<(rp-reserved);
10172 + if (!(reported & mask)) {
10173 + reported |= mask;
10174 + dprintf(1, "\t%s => %s (%p)\n",
10183 + if (!strcmp(name, ldso.name)) is_self = 1;
10185 + if (!ldso.prev) {
10186 + tail->next = &ldso;
10187 + ldso.prev = tail;
10188 + tail = ldso.next ? ldso.next : &ldso;
10192 + if (strchr(name, '/')) {
10194 + fd = open(name, O_RDONLY|O_CLOEXEC);
10196 + /* Search for the name to see if it's already loaded */
10197 + for (p=head->next; p; p=p->next) {
10198 + if (p->shortname && !strcmp(p->shortname, name)) {
10203 + if (strlen(name) > NAME_MAX) return 0;
10205 + if (env_path) fd = path_open(name, env_path, buf, sizeof buf);
10206 + for (p=needed_by; fd == -1 && p; p=p->needed_by) {
10207 + if (fixup_rpath(p, buf, sizeof buf) < 0)
10208 + fd = -2; /* Inhibit further search. */
10210 + fd = path_open(name, p->rpath, buf, sizeof buf);
10214 + char *prefix = 0;
10215 + size_t prefix_len;
10216 + if (ldso.name[0]=='/') {
10218 + for (s=t=z=ldso.name; *s; s++)
10219 + if (*s=='/') z=t, t=s;
10220 + prefix_len = z-ldso.name;
10221 + if (prefix_len < PATH_MAX)
10222 + prefix = ldso.name;
10228 + char etc_ldso_path[prefix_len + 1
10229 + + sizeof "/etc/ld-musl-" LDSO_ARCH ".path"];
10230 + snprintf(etc_ldso_path, sizeof etc_ldso_path,
10231 + "%.*s/etc/ld-musl-" LDSO_ARCH ".path",
10232 + (int)prefix_len, prefix);
10233 + FILE *f = fopen(etc_ldso_path, "rbe");
10235 + if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
10240 + } else if (errno != ENOENT) {
10244 + if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
10245 + fd = path_open(name, sys_path, buf, sizeof buf);
10249 + if (fd < 0) return 0;
10250 + if (fstat(fd, &st) < 0) {
10254 + for (p=head->next; p; p=p->next) {
10255 + if (p->dev == st.st_dev && p->ino == st.st_ino) {
10256 + /* If this library was previously loaded with a
10257 + * pathname but a search found the same inode,
10258 + * setup its shortname so it can be found by name. */
10259 + if (!p->shortname && pathname != name)
10260 + p->shortname = strrchr(p->name, '/')+1;
10266 + map = noload ? 0 : map_library(fd, &temp_dso);
10268 + if (!map) return 0;
10270 + /* Allocate storage for the new DSO. When there is TLS, this
10271 + * storage must include a reservation for all pre-existing
10272 + * threads to obtain copies of both the new TLS, and an
10273 + * extended DTV capable of storing an additional slot for
10274 + * the newly-loaded DSO. */
10275 + alloc_size = sizeof *p + strlen(pathname) + 1;
10276 + if (runtime && temp_dso.tls.image) {
10277 + size_t per_th = temp_dso.tls.size + temp_dso.tls.align
10278 + + sizeof(void *) * (tls_cnt+3);
10279 + n_th = libc.threads_minus_1 + 1;
10280 + if (n_th > SSIZE_MAX / per_th) alloc_size = SIZE_MAX;
10281 + else alloc_size += n_th * per_th;
10283 + p = calloc(1, alloc_size);
10285 + unmap_library(&temp_dso);
10288 + memcpy(p, &temp_dso, sizeof temp_dso);
10290 + p->dev = st.st_dev;
10291 + p->ino = st.st_ino;
10293 + p->needed_by = needed_by;
10294 + p->name = p->buf;
10295 + strcpy(p->name, pathname);
10296 + /* Add a shortname only if name arg was not an explicit pathname. */
10297 + if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
10298 + if (p->tls.image) {
10299 + p->tls_id = ++tls_cnt;
10300 + tls_align = MAXP2(tls_align, p->tls.align);
10301 +#ifdef TLS_ABOVE_TP
10302 + p->tls.offset = tls_offset + ( (tls_align-1) &
10303 + -(tls_offset + (uintptr_t)p->tls.image) );
10304 + tls_offset += p->tls.size;
10306 + tls_offset += p->tls.size + p->tls.align - 1;
10307 + tls_offset -= (tls_offset + (uintptr_t)p->tls.image)
10308 + & (p->tls.align-1);
10309 + p->tls.offset = tls_offset;
10311 + p->new_dtv = (void *)(-sizeof(size_t) &
10312 + (uintptr_t)(p->name+strlen(p->name)+sizeof(size_t)));
10313 + p->new_tls = (void *)(p->new_dtv + n_th*(tls_cnt+1));
10314 + if (tls_tail) tls_tail->next = &p->tls;
10315 + else libc.tls_head = &p->tls;
10316 + tls_tail = &p->tls;
10323 + if (DL_FDPIC) makefuncdescs(p);
10325 + if (ldd_mode) dprintf(1, "\t%s => %s (%p)\n", name, pathname, p->base);
10330 +static void load_deps(struct dso *p)
10332 + size_t i, ndeps=0;
10333 + struct dso ***deps = &p->deps, **tmp, *dep;
10334 + for (; p; p=p->next) {
10335 + for (i=0; p->dynv[i]; i+=2) {
10336 + if (p->dynv[i] != DT_NEEDED) continue;
10337 + dep = load_library(p->strings + p->dynv[i+1], p);
10339 + error("Error loading shared library %s: %m (needed by %s)",
10340 + p->strings + p->dynv[i+1], p->name);
10341 + if (runtime) longjmp(*rtld_fail, 1);
10345 + tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2));
10346 + if (!tmp) longjmp(*rtld_fail, 1);
10347 + tmp[ndeps++] = dep;
10355 +static void load_preload(char *s)
10359 + for (z=s; *z; s=z) {
10360 + for ( ; *s && (isspace(*s) || *s==':'); s++);
10361 + for (z=s; *z && !isspace(*z) && *z!=':'; z++);
10364 + load_library(s, 0);
10369 +static void make_global(struct dso *p)
10371 + for (; p; p=p->next) p->global = 1;
10374 +static void do_mips_relocs(struct dso *p, size_t *got)
10376 + size_t i, j, rel[2];
10377 + unsigned char *base = p->base;
10378 + i=0; search_vec(p->dynv, &i, DT_MIPS_LOCAL_GOTNO);
10382 + while (i--) *got++ += (size_t)base;
10384 + j=0; search_vec(p->dynv, &j, DT_MIPS_GOTSYM);
10385 + i=0; search_vec(p->dynv, &i, DT_MIPS_SYMTABNO);
10386 + Sym *sym = p->syms + j;
10387 + rel[0] = (unsigned char *)got - base;
10388 + for (i-=j; i; i--, sym++, rel[0]+=sizeof(size_t)) {
10389 + rel[1] = sym-p->syms << 8 | R_MIPS_JUMP_SLOT;
10390 + do_relocs(p, rel, sizeof rel, 2);
10394 +static void reloc_all(struct dso *p)
10396 + size_t dyn[DYN_CNT];
10397 + for (; p; p=p->next) {
10398 + if (p->relocated) continue;
10399 + decode_vec(p->dynv, dyn, DYN_CNT);
10400 + if (NEED_MIPS_GOT_RELOCS)
10401 + do_mips_relocs(p, laddr(p, dyn[DT_PLTGOT]));
10402 + do_relocs(p, laddr(p, dyn[DT_JMPREL]), dyn[DT_PLTRELSZ],
10403 + 2+(dyn[DT_PLTREL]==DT_RELA));
10404 + do_relocs(p, laddr(p, dyn[DT_REL]), dyn[DT_RELSZ], 2);
10405 + do_relocs(p, laddr(p, dyn[DT_RELA]), dyn[DT_RELASZ], 3);
10407 + if (head != &ldso && p->relro_start != p->relro_end &&
10408 + mprotect(laddr(p, p->relro_start), p->relro_end-p->relro_start, PROT_READ)
10409 + && errno != ENOSYS) {
10410 + error("Error relocating %s: RELRO protection failed: %m",
10412 + if (runtime) longjmp(*rtld_fail, 1);
10415 + p->relocated = 1;
10419 +static void kernel_mapped_dso(struct dso *p)
10421 + size_t min_addr = -1, max_addr = 0, cnt;
10422 + Phdr *ph = p->phdr;
10423 + for (cnt = p->phnum; cnt--; ph = (void *)((char *)ph + p->phentsize)) {
10424 + if (ph->p_type == PT_DYNAMIC) {
10425 + p->dynv = laddr(p, ph->p_vaddr);
10426 + } else if (ph->p_type == PT_GNU_RELRO) {
10427 + p->relro_start = ph->p_vaddr & -PAGE_SIZE;
10428 + p->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
10430 + if (ph->p_type != PT_LOAD) continue;
10431 + if (ph->p_vaddr < min_addr)
10432 + min_addr = ph->p_vaddr;
10433 + if (ph->p_vaddr+ph->p_memsz > max_addr)
10434 + max_addr = ph->p_vaddr+ph->p_memsz;
10436 + min_addr &= -PAGE_SIZE;
10437 + max_addr = (max_addr + PAGE_SIZE-1) & -PAGE_SIZE;
10438 + p->map = p->base + min_addr;
10439 + p->map_len = max_addr - min_addr;
10440 + p->kernel_mapped = 1;
10443 +void __libc_exit_fini()
10446 + size_t dyn[DYN_CNT];
10447 + for (p=fini_head; p; p=p->fini_next) {
10448 + if (!p->constructed) continue;
10449 + decode_vec(p->dynv, dyn, DYN_CNT);
10450 + if (dyn[0] & (1<<DT_FINI_ARRAY)) {
10451 + size_t n = dyn[DT_FINI_ARRAYSZ]/sizeof(size_t);
10452 + size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY])+n;
10453 + while (n--) ((void (*)(void))*--fn)();
10455 +#ifndef NO_LEGACY_INITFINI
10456 + if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
10457 + fpaddr(p, dyn[DT_FINI])();
10462 +static void do_init_fini(struct dso *p)
10464 + size_t dyn[DYN_CNT];
10465 + int need_locking = libc.threads_minus_1;
10466 + /* Allow recursive calls that arise when a library calls
10467 + * dlopen from one of its constructors, but block any
10468 + * other threads until all ctors have finished. */
10469 + if (need_locking) pthread_mutex_lock(&init_fini_lock);
10470 + for (; p; p=p->prev) {
10471 + if (p->constructed) continue;
10472 + p->constructed = 1;
10473 + decode_vec(p->dynv, dyn, DYN_CNT);
10474 + if (dyn[0] & ((1<<DT_FINI) | (1<<DT_FINI_ARRAY))) {
10475 + p->fini_next = fini_head;
10478 +#ifndef NO_LEGACY_INITFINI
10479 + if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
10480 + fpaddr(p, dyn[DT_INIT])();
10482 + if (dyn[0] & (1<<DT_INIT_ARRAY)) {
10483 + size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t);
10484 + size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]);
10485 + while (n--) ((void (*)(void))*fn++)();
10487 + if (!need_locking && libc.threads_minus_1) {
10488 + need_locking = 1;
10489 + pthread_mutex_lock(&init_fini_lock);
10492 + if (need_locking) pthread_mutex_unlock(&init_fini_lock);
10495 +void __libc_start_init(void)
10497 + do_init_fini(tail);
10500 +static void dl_debug_state(void)
10504 +weak_alias(dl_debug_state, _dl_debug_state);
10506 +void __init_tls(size_t *auxv)
10510 +__attribute__((__visibility__("hidden")))
10511 +void *__tls_get_new(size_t *v)
10513 + pthread_t self = __pthread_self();
10515 + /* Block signals to make accessing new TLS async-signal-safe */
10517 + __block_all_sigs(&set);
10518 + if (v[0]<=(size_t)self->dtv[0]) {
10519 + __restore_sigs(&set);
10520 + return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET;
10523 + /* This is safe without any locks held because, if the caller
10524 + * is able to request the Nth entry of the DTV, the DSO list
10525 + * must be valid at least that far out and it was synchronized
10526 + * at program startup or by an already-completed call to dlopen. */
10528 + for (p=head; p->tls_id != v[0]; p=p->next);
10530 + /* Get new DTV space from new DSO if needed */
10531 + if (v[0] > (size_t)self->dtv[0]) {
10532 + void **newdtv = p->new_dtv +
10533 + (v[0]+1)*a_fetch_add(&p->new_dtv_idx,1);
10534 + memcpy(newdtv, self->dtv,
10535 + ((size_t)self->dtv[0]+1) * sizeof(void *));
10536 + newdtv[0] = (void *)v[0];
10537 + self->dtv = self->dtv_copy = newdtv;
10540 + /* Get new TLS memory from all new DSOs up to the requested one */
10541 + unsigned char *mem;
10542 + for (p=head; ; p=p->next) {
10543 + if (!p->tls_id || self->dtv[p->tls_id]) continue;
10544 + mem = p->new_tls + (p->tls.size + p->tls.align)
10545 + * a_fetch_add(&p->new_tls_idx,1);
10546 + mem += ((uintptr_t)p->tls.image - (uintptr_t)mem)
10547 + & (p->tls.align-1);
10548 + self->dtv[p->tls_id] = mem;
10549 + memcpy(mem, p->tls.image, p->tls.len);
10550 + if (p->tls_id == v[0]) break;
10552 + __restore_sigs(&set);
10553 + return mem + v[1] + DTP_OFFSET;
10556 +static void update_tls_size()
10558 + libc.tls_cnt = tls_cnt;
10559 + libc.tls_align = tls_align;
10560 + libc.tls_size = ALIGN(
10561 + (1+tls_cnt) * sizeof(void *) +
10563 + sizeof(struct pthread) +
10568 +/* Stage 1 of the dynamic linker is defined in dlstart.c. It calls the
10569 + * following stage 2 and stage 3 functions via primitive symbolic lookup
10570 + * since it does not have access to their addresses to begin with. */
10572 +/* Stage 2 of the dynamic linker is called after relative relocations
10573 + * have been processed. It can make function calls to static functions
10574 + * and access string literals and static data, but cannot use extern
10575 + * symbols. Its job is to perform symbolic relocations on the dynamic
10576 + * linker itself, but some of the relocations performed may need to be
10577 + * replaced later due to copy relocations in the main program. */
10579 +__attribute__((__visibility__("hidden")))
10580 +void __dls2(unsigned char *base, size_t *sp)
10583 + void *p1 = (void *)sp[-2];
10584 + void *p2 = (void *)sp[-1];
10586 + size_t *auxv, aux[AUX_CNT];
10587 + for (auxv=sp+1+*sp+1; *auxv; auxv++); auxv++;
10588 + decode_vec(auxv, aux, AUX_CNT);
10589 + if (aux[AT_BASE]) ldso.base = (void *)aux[AT_BASE];
10590 + else ldso.base = (void *)(aux[AT_PHDR] & -4096);
10592 + app_loadmap = p2 ? p1 : 0;
10593 + ldso.loadmap = p2 ? p2 : p1;
10594 + ldso.base = laddr(&ldso, 0);
10596 + ldso.base = base;
10598 + Ehdr *ehdr = (void *)ldso.base;
10599 + ldso.name = ldso.shortname = "libc.so";
10601 + ldso.phnum = ehdr->e_phnum;
10602 + ldso.phdr = laddr(&ldso, ehdr->e_phoff);
10603 + ldso.phentsize = ehdr->e_phentsize;
10604 + kernel_mapped_dso(&ldso);
10605 + decode_dyn(&ldso);
10607 + if (DL_FDPIC) makefuncdescs(&ldso);
10609 + /* Prepare storage for to save clobbered REL addends so they
10610 + * can be reused in stage 3. There should be very few. If
10611 + * something goes wrong and there are a huge number, abort
10612 + * instead of risking stack overflow. */
10613 + size_t dyn[DYN_CNT];
10614 + decode_vec(ldso.dynv, dyn, DYN_CNT);
10615 + size_t *rel = laddr(&ldso, dyn[DT_REL]);
10616 + size_t rel_size = dyn[DT_RELSZ];
10617 + size_t symbolic_rel_cnt = 0;
10618 + apply_addends_to = rel;
10619 + for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t))
10620 + if (!IS_RELATIVE(rel[1], ldso.syms)) symbolic_rel_cnt++;
10621 + if (symbolic_rel_cnt >= ADDEND_LIMIT) a_crash();
10622 + size_t addends[symbolic_rel_cnt+1];
10623 + saved_addends = addends;
10626 + reloc_all(&ldso);
10628 + ldso.relocated = 0;
10630 + /* Call dynamic linker stage-3, __dls3, looking it up
10631 + * symbolically as a barrier against moving the address
10632 + * load across the above relocation processing. */
10633 + struct symdef dls3_def = find_sym(&ldso, "__dls3", 0);
10634 + if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls3_def.sym-ldso.syms])(sp);
10635 + else ((stage3_func)laddr(&ldso, dls3_def.sym->st_value))(sp);
10638 +/* Stage 3 of the dynamic linker is called with the dynamic linker/libc
10639 + * fully functional. Its job is to load (if not already loaded) and
10640 + * process dependencies and relocations for the main application and
10641 + * transfer control to its entry point. */
10643 +_Noreturn void __dls3(size_t *sp)
10645 + static struct dso app, vdso;
10646 + size_t aux[AUX_CNT], *auxv;
10648 + char *env_preload=0;
10649 + size_t vdso_base;
10651 + char **argv = (void *)(sp+1);
10652 + char **argv_orig = argv;
10653 + char **envp = argv+argc+1;
10655 + /* Find aux vector just past environ[] and use it to initialize
10656 + * global data that may be needed before we can make syscalls. */
10657 + __environ = envp;
10658 + for (i=argc+1; argv[i]; i++);
10659 + libc.auxv = auxv = (void *)(argv+i+1);
10660 + decode_vec(auxv, aux, AUX_CNT);
10661 + __hwcap = aux[AT_HWCAP];
10662 + libc.page_size = aux[AT_PAGESZ];
10663 + libc.secure = ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID]
10664 + || aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]);
10666 + /* Setup early thread pointer in builtin_tls for ldso/libc itself to
10667 + * use during dynamic linking. If possible it will also serve as the
10668 + * thread pointer at runtime. */
10669 + libc.tls_size = sizeof builtin_tls;
10670 + libc.tls_align = tls_align;
10671 + if (__init_tp(__copy_tls((void *)builtin_tls)) < 0) {
10675 + /* Only trust user/env if kernel says we're not suid/sgid */
10676 + if (!libc.secure) {
10677 + env_path = getenv("LD_LIBRARY_PATH");
10678 + env_preload = getenv("LD_PRELOAD");
10681 + /* If the main program was already loaded by the kernel,
10682 + * AT_PHDR will point to some location other than the dynamic
10683 + * linker's program headers. */
10684 + if (aux[AT_PHDR] != (size_t)ldso.phdr) {
10685 + size_t interp_off = 0;
10686 + size_t tls_image = 0;
10687 + /* Find load address of the main program, via AT_PHDR vs PT_PHDR. */
10688 + Phdr *phdr = app.phdr = (void *)aux[AT_PHDR];
10689 + app.phnum = aux[AT_PHNUM];
10690 + app.phentsize = aux[AT_PHENT];
10691 + for (i=aux[AT_PHNUM]; i; i--, phdr=(void *)((char *)phdr + aux[AT_PHENT])) {
10692 + if (phdr->p_type == PT_PHDR)
10693 + app.base = (void *)(aux[AT_PHDR] - phdr->p_vaddr);
10694 + else if (phdr->p_type == PT_INTERP)
10695 + interp_off = (size_t)phdr->p_vaddr;
10696 + else if (phdr->p_type == PT_TLS) {
10697 + tls_image = phdr->p_vaddr;
10698 + app.tls.len = phdr->p_filesz;
10699 + app.tls.size = phdr->p_memsz;
10700 + app.tls.align = phdr->p_align;
10703 + if (DL_FDPIC) app.loadmap = app_loadmap;
10704 + if (app.tls.size) app.tls.image = laddr(&app, tls_image);
10705 + if (interp_off) ldso.name = laddr(&app, interp_off);
10706 + if ((aux[0] & (1UL<<AT_EXECFN))
10707 + && strncmp((char *)aux[AT_EXECFN], "/proc/", 6))
10708 + app.name = (char *)aux[AT_EXECFN];
10710 + app.name = argv[0];
10711 + kernel_mapped_dso(&app);
10714 + char *ldname = argv[0];
10715 + size_t l = strlen(ldname);
10716 + if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
10718 + while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
10719 + char *opt = argv[0]+2;
10720 + *argv++ = (void *)-1;
10723 + } else if (!memcmp(opt, "list", 5)) {
10725 + } else if (!memcmp(opt, "library-path", 12)) {
10726 + if (opt[12]=='=') env_path = opt+13;
10727 + else if (opt[12]) *argv = 0;
10728 + else if (*argv) env_path = *argv++;
10729 + } else if (!memcmp(opt, "preload", 7)) {
10730 + if (opt[7]=='=') env_preload = opt+8;
10731 + else if (opt[7]) *argv = 0;
10732 + else if (*argv) env_preload = *argv++;
10737 + argv[-1] = (void *)(argc - (argv-argv_orig));
10739 + dprintf(2, "musl libc (" LDSO_ARCH ")\n"
10741 + "Dynamic Program Loader\n"
10742 + "Usage: %s [options] [--] pathname%s\n",
10743 + __libc_get_version(), ldname,
10744 + ldd_mode ? "" : " [args]");
10747 + fd = open(argv[0], O_RDONLY);
10749 + dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
10753 + Ehdr *ehdr = (void *)map_library(fd, &app);
10755 + dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
10760 + ldso.name = ldname;
10761 + app.name = argv[0];
10762 + aux[AT_ENTRY] = (size_t)laddr(&app, ehdr->e_entry);
10763 + /* Find the name that would have been used for the dynamic
10764 + * linker had ldd not taken its place. */
10766 + for (i=0; i<app.phnum; i++) {
10767 + if (app.phdr[i].p_type == PT_INTERP)
10768 + ldso.name = laddr(&app, app.phdr[i].p_vaddr);
10770 + dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
10773 + if (app.tls.size) {
10774 + libc.tls_head = tls_tail = &app.tls;
10775 + app.tls_id = tls_cnt = 1;
10776 +#ifdef TLS_ABOVE_TP
10777 + app.tls.offset = 0;
10778 + tls_offset = app.tls.size
10779 + + ( -((uintptr_t)app.tls.image + app.tls.size)
10780 + & (app.tls.align-1) );
10782 + tls_offset = app.tls.offset = app.tls.size
10783 + + ( -((uintptr_t)app.tls.image + app.tls.size)
10784 + & (app.tls.align-1) );
10786 + tls_align = MAXP2(tls_align, app.tls.align);
10789 + decode_dyn(&app);
10791 + makefuncdescs(&app);
10792 + if (!app.loadmap) {
10793 + app.loadmap = (void *)&app_dummy_loadmap;
10794 + app.loadmap->nsegs = 1;
10795 + app.loadmap->segs[0].addr = (size_t)app.map;
10796 + app.loadmap->segs[0].p_vaddr = (size_t)app.map
10797 + - (size_t)app.base;
10798 + app.loadmap->segs[0].p_memsz = app.map_len;
10800 + argv[-3] = (void *)app.loadmap;
10803 + /* Attach to vdso, if provided by the kernel */
10804 + if (search_vec(auxv, &vdso_base, AT_SYSINFO_EHDR)) {
10805 + Ehdr *ehdr = (void *)vdso_base;
10806 + Phdr *phdr = vdso.phdr = (void *)(vdso_base + ehdr->e_phoff);
10807 + vdso.phnum = ehdr->e_phnum;
10808 + vdso.phentsize = ehdr->e_phentsize;
10809 + for (i=ehdr->e_phnum; i; i--, phdr=(void *)((char *)phdr + ehdr->e_phentsize)) {
10810 + if (phdr->p_type == PT_DYNAMIC)
10811 + vdso.dynv = (void *)(vdso_base + phdr->p_offset);
10812 + if (phdr->p_type == PT_LOAD)
10813 + vdso.base = (void *)(vdso_base - phdr->p_vaddr + phdr->p_offset);
10816 + vdso.shortname = "linux-gate.so.1";
10818 + vdso.relocated = 1;
10819 + decode_dyn(&vdso);
10820 + vdso.prev = &ldso;
10821 + ldso.next = &vdso;
10824 + /* Initial dso chain consists only of the app. */
10825 + head = tail = &app;
10827 + /* Donate unused parts of app and library mapping to malloc */
10828 + reclaim_gaps(&app);
10829 + reclaim_gaps(&ldso);
10831 + /* Load preload/needed libraries, add their symbols to the global
10832 + * namespace, and perform all remaining relocations. */
10833 + if (env_preload) load_preload(env_preload);
10835 + make_global(&app);
10837 +#ifndef DYNAMIC_IS_RO
10838 + for (i=0; app.dynv[i]; i+=2)
10839 + if (app.dynv[i]==DT_DEBUG)
10840 + app.dynv[i+1] = (size_t)&debug;
10843 + /* The main program must be relocated LAST since it may contin
10844 + * copy relocations which depend on libraries' relocations. */
10845 + reloc_all(app.next);
10848 + update_tls_size();
10849 + if (libc.tls_size > sizeof builtin_tls || tls_align > MIN_TLS_ALIGN) {
10850 + void *initial_tls = calloc(libc.tls_size, 1);
10851 + if (!initial_tls) {
10852 + dprintf(2, "%s: Error getting %zu bytes thread-local storage: %m\n",
10853 + argv[0], libc.tls_size);
10856 + if (__init_tp(__copy_tls(initial_tls)) < 0) {
10860 + size_t tmp_tls_size = libc.tls_size;
10861 + pthread_t self = __pthread_self();
10862 + /* Temporarily set the tls size to the full size of
10863 + * builtin_tls so that __copy_tls will use the same layout
10864 + * as it did for before. Then check, just to be safe. */
10865 + libc.tls_size = sizeof builtin_tls;
10866 + if (__copy_tls((void*)builtin_tls) != self) a_crash();
10867 + libc.tls_size = tmp_tls_size;
10869 + static_tls_cnt = tls_cnt;
10871 + if (ldso_fail) _exit(127);
10872 + if (ldd_mode) _exit(0);
10874 + /* Switch to runtime mode: any further failures in the dynamic
10875 + * linker are a reportable failure rather than a fatal startup
10880 + debug.bp = dl_debug_state;
10881 + debug.head = head;
10882 + debug.base = ldso.base;
10884 + _dl_debug_state();
10888 + CRTJMP((void *)aux[AT_ENTRY], argv-1);
10892 +void *dlopen(const char *file, int mode)
10894 + struct dso *volatile p, *orig_tail, *next;
10895 + struct tls_module *orig_tls_tail;
10896 + size_t orig_tls_cnt, orig_tls_offset, orig_tls_align;
10901 + if (!file) return head;
10903 + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
10904 + pthread_rwlock_wrlock(&lock);
10908 + orig_tls_tail = tls_tail;
10909 + orig_tls_cnt = tls_cnt;
10910 + orig_tls_offset = tls_offset;
10911 + orig_tls_align = tls_align;
10912 + orig_tail = tail;
10913 + noload = mode & RTLD_NOLOAD;
10916 + if (setjmp(*rtld_fail)) {
10917 + /* Clean up anything new that was (partially) loaded */
10918 + if (p && p->deps) for (i=0; p->deps[i]; i++)
10919 + if (p->deps[i]->global < 0)
10920 + p->deps[i]->global = 0;
10921 + for (p=orig_tail->next; p; p=next) {
10923 + while (p->td_index) {
10924 + void *tmp = p->td_index->next;
10925 + free(p->td_index);
10926 + p->td_index = tmp;
10928 + free(p->funcdescs);
10929 + if (p->rpath != p->rpath_orig)
10932 + unmap_library(p);
10935 + if (!orig_tls_tail) libc.tls_head = 0;
10936 + tls_tail = orig_tls_tail;
10937 + tls_cnt = orig_tls_cnt;
10938 + tls_offset = orig_tls_offset;
10939 + tls_align = orig_tls_align;
10940 + tail = orig_tail;
10944 + } else p = load_library(file, head);
10948 + "Library %s is not already loaded" :
10949 + "Error loading shared library %s: %m",
10954 + /* First load handling */
10957 + if (p->deps) for (i=0; p->deps[i]; i++)
10958 + if (!p->deps[i]->global)
10959 + p->deps[i]->global = -1;
10960 + if (!p->global) p->global = -1;
10962 + if (p->deps) for (i=0; p->deps[i]; i++)
10963 + if (p->deps[i]->global < 0)
10964 + p->deps[i]->global = 0;
10965 + if (p->global < 0) p->global = 0;
10968 + if (mode & RTLD_GLOBAL) {
10969 + if (p->deps) for (i=0; p->deps[i]; i++)
10970 + p->deps[i]->global = 1;
10974 + update_tls_size();
10975 + _dl_debug_state();
10976 + orig_tail = tail;
10980 + pthread_rwlock_unlock(&lock);
10981 + if (p) do_init_fini(orig_tail);
10982 + pthread_setcancelstate(cs, 0);
10986 +__attribute__((__visibility__("hidden")))
10987 +int __dl_invalid_handle(void *h)
10990 + for (p=head; p; p=p->next) if (h==p) return 0;
10991 + error("Invalid library handle %p", (void *)h);
10995 +static void *addr2dso(size_t a)
10999 + if (DL_FDPIC) for (p=head; p; p=p->next) {
11000 + i = count_syms(p);
11001 + if (a-(size_t)p->funcdescs < i*sizeof(*p->funcdescs))
11004 + for (p=head; p; p=p->next) {
11005 + if (DL_FDPIC && p->loadmap) {
11006 + for (i=0; i<p->loadmap->nsegs; i++) {
11007 + if (a-p->loadmap->segs[i].p_vaddr
11008 + < p->loadmap->segs[i].p_memsz)
11012 + if (a-(size_t)p->map < p->map_len)
11019 +void *__tls_get_addr(size_t *);
11021 +static void *do_dlsym(struct dso *p, const char *s, void *ra)
11024 + uint32_t h = 0, gh = 0, *ght;
11026 + if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) {
11027 + if (p == RTLD_DEFAULT) {
11029 + } else if (p == RTLD_NEXT) {
11030 + p = addr2dso((size_t)ra);
11034 + struct symdef def = find_sym(p, s, 0);
11035 + if (!def.sym) goto failed;
11036 + if ((def.sym->st_info&0xf) == STT_TLS)
11037 + return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});
11038 + if (DL_FDPIC && (def.sym->st_info&0xf) == STT_FUNC)
11039 + return def.dso->funcdescs + (def.sym - def.dso->syms);
11040 + return laddr(def.dso, def.sym->st_value);
11042 + if (__dl_invalid_handle(p))
11044 + if ((ght = p->ghashtab)) {
11045 + gh = gnu_hash(s);
11046 + sym = gnu_lookup(gh, ght, p, s);
11048 + h = sysv_hash(s);
11049 + sym = sysv_lookup(s, h, p);
11051 + if (sym && (sym->st_info&0xf) == STT_TLS)
11052 + return __tls_get_addr((size_t []){p->tls_id, sym->st_value});
11053 + if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
11054 + return p->funcdescs + (sym - p->syms);
11055 + if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
11056 + return laddr(p, sym->st_value);
11057 + if (p->deps) for (i=0; p->deps[i]; i++) {
11058 + if ((ght = p->deps[i]->ghashtab)) {
11059 + if (!gh) gh = gnu_hash(s);
11060 + sym = gnu_lookup(gh, ght, p->deps[i], s);
11062 + if (!h) h = sysv_hash(s);
11063 + sym = sysv_lookup(s, h, p->deps[i]);
11065 + if (sym && (sym->st_info&0xf) == STT_TLS)
11066 + return __tls_get_addr((size_t []){p->deps[i]->tls_id, sym->st_value});
11067 + if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
11068 + return p->deps[i]->funcdescs + (sym - p->deps[i]->syms);
11069 + if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
11070 + return laddr(p->deps[i], sym->st_value);
11073 + error("Symbol not found: %s", s);
11077 +int dladdr(const void *addr, Dl_info *info)
11080 + Sym *sym, *bestsym;
11085 + pthread_rwlock_rdlock(&lock);
11086 + p = addr2dso((size_t)addr);
11087 + pthread_rwlock_unlock(&lock);
11089 + if (!p) return 0;
11092 + strings = p->strings;
11093 + nsym = count_syms(p);
11096 + size_t idx = ((size_t)addr-(size_t)p->funcdescs)
11097 + / sizeof(*p->funcdescs);
11098 + if (idx < nsym && (sym[idx].st_info&0xf) == STT_FUNC) {
11099 + best = p->funcdescs + idx;
11100 + bestsym = sym + idx;
11104 + if (!best) for (; nsym; nsym--, sym++) {
11105 + if (sym->st_value
11106 + && (1<<(sym->st_info&0xf) & OK_TYPES)
11107 + && (1<<(sym->st_info>>4) & OK_BINDS)) {
11108 + void *symaddr = laddr(p, sym->st_value);
11109 + if (symaddr > addr || symaddr < best)
11113 + if (addr == symaddr)
11118 + if (!best) return 0;
11120 + if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
11121 + best = p->funcdescs + (bestsym - p->syms);
11123 + info->dli_fname = p->name;
11124 + info->dli_fbase = p->base;
11125 + info->dli_sname = strings + bestsym->st_name;
11126 + info->dli_saddr = best;
11131 +__attribute__((__visibility__("hidden")))
11132 +void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
11135 + pthread_rwlock_rdlock(&lock);
11136 + res = do_dlsym(p, s, ra);
11137 + pthread_rwlock_unlock(&lock);
11141 +int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
11143 + struct dso *current;
11144 + struct dl_phdr_info info;
11146 + for(current = head; current;) {
11147 + info.dlpi_addr = (uintptr_t)current->base;
11148 + info.dlpi_name = current->name;
11149 + info.dlpi_phdr = current->phdr;
11150 + info.dlpi_phnum = current->phnum;
11151 + info.dlpi_adds = gencnt;
11152 + info.dlpi_subs = 0;
11153 + info.dlpi_tls_modid = current->tls_id;
11154 + info.dlpi_tls_data = current->tls.image;
11156 + ret = (callback)(&info, sizeof (info), data);
11158 + if (ret != 0) break;
11160 + pthread_rwlock_rdlock(&lock);
11161 + current = current->next;
11162 + pthread_rwlock_unlock(&lock);
11167 +__attribute__((__visibility__("hidden")))
11168 +void __dl_vseterr(const char *, va_list);
11170 +static void error(const char *fmt, ...)
11173 + va_start(ap, fmt);
11175 + vdprintf(2, fmt, ap);
11176 + dprintf(2, "\n");
11181 + __dl_vseterr(fmt, ap);
11184 --- a/src/env/__init_tls.c
11185 +++ b/src/env/__init_tls.c
11187 #include "atomic.h"
11188 #include "syscall.h"
11193 int __init_tp(void *p)
11196 @@ -24,8 +21,6 @@ int __init_tp(void *p)
11202 static struct builtin_tls {
11205 @@ -33,33 +28,40 @@ static struct builtin_tls {
11207 #define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
11209 -struct tls_image {
11211 - size_t len, size, align;
11214 -#define T __static_tls
11215 +static struct tls_module main_tls;
11217 void *__copy_tls(unsigned char *mem)
11220 - if (!T.image) return mem;
11221 - void **dtv = (void *)mem;
11222 - dtv[0] = (void *)1;
11223 + struct tls_module *p;
11227 #ifdef TLS_ABOVE_TP
11228 - mem += sizeof(void *) * 2;
11229 - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (T.align-1);
11230 + dtv = (void **)(mem + libc.tls_size) - (libc.tls_cnt + 1);
11232 + mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1);
11233 td = (pthread_t)mem;
11234 mem += sizeof(struct pthread);
11236 + for (i=1, p=libc.tls_head; p; i++, p=p->next) {
11237 + dtv[i] = mem + p->offset;
11238 + memcpy(dtv[i], p->image, p->len);
11241 + dtv = (void **)mem;
11243 mem += libc.tls_size - sizeof(struct pthread);
11244 - mem -= (uintptr_t)mem & (T.align-1);
11245 + mem -= (uintptr_t)mem & (libc.tls_align-1);
11246 td = (pthread_t)mem;
11249 + for (i=1, p=libc.tls_head; p; i++, p=p->next) {
11250 + dtv[i] = mem - p->offset;
11251 + memcpy(dtv[i], p->image, p->len);
11254 + dtv[0] = (void *)libc.tls_cnt;
11255 td->dtv = td->dtv_copy = dtv;
11257 - memcpy(mem, T.image, T.len);
11261 @@ -69,7 +71,7 @@ typedef Elf32_Phdr Phdr;
11262 typedef Elf64_Phdr Phdr;
11265 -void __init_tls(size_t *aux)
11266 +static void static_init_tls(size_t *aux)
11270 @@ -86,16 +88,24 @@ void __init_tls(size_t *aux)
11274 - T.image = (void *)(base + tls_phdr->p_vaddr);
11275 - T.len = tls_phdr->p_filesz;
11276 - T.size = tls_phdr->p_memsz;
11277 - T.align = tls_phdr->p_align;
11278 + main_tls.image = (void *)(base + tls_phdr->p_vaddr);
11279 + main_tls.len = tls_phdr->p_filesz;
11280 + main_tls.size = tls_phdr->p_memsz;
11281 + main_tls.align = tls_phdr->p_align;
11282 + libc.tls_cnt = 1;
11283 + libc.tls_head = &main_tls;
11286 - T.size += (-T.size - (uintptr_t)T.image) & (T.align-1);
11287 - if (T.align < MIN_TLS_ALIGN) T.align = MIN_TLS_ALIGN;
11288 + main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image)
11289 + & (main_tls.align-1);
11290 + if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN;
11291 +#ifndef TLS_ABOVE_TP
11292 + main_tls.offset = main_tls.size;
11295 - libc.tls_size = 2*sizeof(void *)+T.size+T.align+sizeof(struct pthread)
11296 + libc.tls_align = main_tls.align;
11297 + libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread)
11298 + + main_tls.size + main_tls.align
11299 + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN;
11301 if (libc.tls_size > sizeof builtin_tls) {
11302 @@ -117,6 +127,5 @@ void __init_tls(size_t *aux)
11303 if (__init_tp(__copy_tls(mem)) < 0)
11307 -void __init_tls(size_t *auxv) { }
11310 +weak_alias(static_init_tls, __init_tls);
11311 --- a/src/env/__libc_start_main.c
11312 +++ b/src/env/__libc_start_main.c
11315 void __init_tls(size_t *);
11318 -static void dummy() {}
11319 +static void dummy(void) {}
11320 weak_alias(dummy, _init);
11321 -extern void (*const __init_array_start)() __attribute__((weak));
11322 -extern void (*const __init_array_end)() __attribute__((weak));
11325 +__attribute__((__weak__, __visibility__("hidden")))
11326 +extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
11328 static void dummy1(void *p) {}
11329 weak_alias(dummy1, __init_ssp);
11336 void __init_libc(char **envp, char *pn)
11338 size_t i, *auxv, aux[AUX_CNT] = { 0 };
11339 @@ -57,20 +53,22 @@ void __init_libc(char **envp, char *pn)
11343 -int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
11344 +static void libc_start_init(void)
11346 - char **envp = argv+argc+1;
11349 - __init_libc(envp, argv[0]);
11351 uintptr_t a = (uintptr_t)&__init_array_start;
11352 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
11353 (*(void (**)())a)();
11355 - void __libc_start_init(void);
11358 +weak_alias(libc_start_init, __libc_start_init);
11360 +int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
11362 + char **envp = argv+argc+1;
11364 + __init_libc(envp, argv[0]);
11365 __libc_start_init();
11368 /* Pass control to the application */
11369 exit(main(argc, argv, envp));
11370 --- a/src/env/__reset_tls.c
11371 +++ b/src/env/__reset_tls.c
11375 #include <string.h>
11376 #include "pthread_impl.h"
11378 -extern struct tls_image {
11380 - size_t len, size, align;
11383 -#define T __static_tls
11388 - if (!T.size) return;
11389 pthread_t self = __pthread_self();
11390 - memcpy(self->dtv[1], T.image, T.len);
11391 - memset((char *)self->dtv[1]+T.len, 0, T.size-T.len);
11392 + struct tls_module *p;
11393 + size_t i, n = (size_t)self->dtv[0];
11394 + if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) {
11395 + if (!self->dtv[i]) continue;
11396 + memcpy(self->dtv[i], p->image, p->len);
11397 + memset((char *)self->dtv[i]+p->len, 0,
11398 + p->size - p->len);
11403 --- a/src/env/__stack_chk_fail.c
11404 +++ b/src/env/__stack_chk_fail.c
11405 @@ -17,16 +17,7 @@ void __stack_chk_fail(void)
11411 __attribute__((__visibility__("hidden")))
11412 -void __stack_chk_fail_local(void)
11418 +void __stack_chk_fail_local(void);
11420 weak_alias(__stack_chk_fail, __stack_chk_fail_local);
11424 +++ b/src/exit/arm/__aeabi_atexit.c
11426 +int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
11428 +int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
11430 + return __cxa_atexit (func, obj, d);
11432 --- a/src/exit/exit.c
11433 +++ b/src/exit/exit.c
11434 @@ -10,25 +10,25 @@ static void dummy()
11435 * as a consequence of linking either __toread.c or __towrite.c. */
11436 weak_alias(dummy, __funcs_on_exit);
11437 weak_alias(dummy, __stdio_exit);
11440 weak_alias(dummy, _fini);
11441 -extern void (*const __fini_array_start)() __attribute__((weak));
11442 -extern void (*const __fini_array_end)() __attribute__((weak));
11445 -_Noreturn void exit(int code)
11447 - __funcs_on_exit();
11448 +__attribute__((__weak__, __visibility__("hidden")))
11449 +extern void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
11452 +static void libc_exit_fini(void)
11454 uintptr_t a = (uintptr_t)&__fini_array_end;
11455 for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
11456 (*(void (**)())(a-sizeof(void(*)())))();
11462 +weak_alias(libc_exit_fini, __libc_exit_fini);
11464 +_Noreturn void exit(int code)
11466 + __funcs_on_exit();
11467 + __libc_exit_fini();
11472 +++ b/src/fenv/arm/fenv-hf.S
11479 +.global fegetround
11480 +.type fegetround,%function
11483 + and r0, r0, #0xc00000
11486 +.global __fesetround
11487 +.type __fesetround,%function
11490 + bic r3, r3, #0xc00000
11496 +.global fetestexcept
11497 +.type fetestexcept,%function
11499 + and r0, r0, #0x1f
11504 +.global feclearexcept
11505 +.type feclearexcept,%function
11507 + and r0, r0, #0x1f
11514 +.global feraiseexcept
11515 +.type feraiseexcept,%function
11517 + and r0, r0, #0x1f
11525 +.type fegetenv,%function
11533 +.type fesetenv,%function
11544 +++ b/src/fenv/arm/fenv.c
11546 +#if !__ARM_PCS_VFP
11547 +#include "../fenv.c"
11549 --- a/src/fenv/armebhf/fenv.sub
11553 --- a/src/fenv/armhf/fenv.s
11558 -.global fegetround
11559 -.type fegetround,%function
11561 - mrc p10, 7, r0, cr1, cr0, 0
11562 - and r0, r0, #0xc00000
11565 -.global __fesetround
11566 -.type __fesetround,%function
11568 - mrc p10, 7, r3, cr1, cr0, 0
11569 - bic r3, r3, #0xc00000
11571 - mcr p10, 7, r3, cr1, cr0, 0
11575 -.global fetestexcept
11576 -.type fetestexcept,%function
11578 - and r0, r0, #0x1f
11579 - mrc p10, 7, r3, cr1, cr0, 0
11583 -.global feclearexcept
11584 -.type feclearexcept,%function
11586 - and r0, r0, #0x1f
11587 - mrc p10, 7, r3, cr1, cr0, 0
11589 - mcr p10, 7, r3, cr1, cr0, 0
11593 -.global feraiseexcept
11594 -.type feraiseexcept,%function
11596 - and r0, r0, #0x1f
11597 - mrc p10, 7, r3, cr1, cr0, 0
11599 - mcr p10, 7, r3, cr1, cr0, 0
11604 -.type fegetenv,%function
11606 - mrc p10, 7, r3, cr1, cr0, 0
11612 -.type fesetenv,%function
11617 - mcr p10, 7, r3, cr1, cr0, 0
11620 --- a/src/fenv/armhf/fenv.sub
11624 --- a/src/fenv/mips-sf/fenv.sub
11629 +++ b/src/fenv/mips/fenv-sf.c
11631 +#ifdef __mips_soft_float
11632 +#include "../fenv.c"
11635 +++ b/src/fenv/mips/fenv.S
11637 +#ifndef __mips_soft_float
11641 +.global feclearexcept
11642 +.type feclearexcept,@function
11652 +.global feraiseexcept
11653 +.type feraiseexcept,@function
11662 +.global fetestexcept
11663 +.type fetestexcept,@function
11670 +.global fegetround
11671 +.type fegetround,@function
11677 +.global __fesetround
11678 +.type __fesetround,@function
11689 +.type fegetenv,@function
11697 +.type fesetenv,@function
11708 --- a/src/fenv/mips/fenv.s
11713 -.global feclearexcept
11714 -.type feclearexcept,@function
11724 -.global feraiseexcept
11725 -.type feraiseexcept,@function
11734 -.global fetestexcept
11735 -.type fetestexcept,@function
11742 -.global fegetround
11743 -.type fegetround,@function
11749 -.global __fesetround
11750 -.type __fesetround,@function
11761 -.type fegetenv,@function
11769 -.type fesetenv,@function
11778 --- a/src/fenv/mipsel-sf/fenv.sub
11782 --- a/src/fenv/sh-nofpu/fenv.sub
11787 +++ b/src/fenv/sh/fenv-nofpu.c
11789 +#if !__SH_FPU_ANY__ && !__SH4__
11790 +#include "../fenv.c"
11793 +++ b/src/fenv/sh/fenv.S
11795 +#if __SH_FPU_ANY__ || __SH4__
11797 +.global fegetround
11798 +.type fegetround, @function
11804 +.global __fesetround
11805 +.type __fesetround, @function
11813 +.global fetestexcept
11814 +.type fetestexcept, @function
11821 +.global feclearexcept
11822 +.type feclearexcept, @function
11833 +.global feraiseexcept
11834 +.type feraiseexcept, @function
11845 +.type fegetenv, @function
11853 +.type fesetenv, @function
11859 + ! the default environment is complicated by the fact that we need to
11860 + ! preserve the current precision bit, which we do not know a priori
11867 +1: mov.l @r4, r0 ! non-default environment
11873 --- a/src/fenv/sh/fenv.s
11876 -.global fegetround
11877 -.type fegetround, @function
11883 -.global __fesetround
11884 -.type __fesetround, @function
11892 -.global fetestexcept
11893 -.type fetestexcept, @function
11900 -.global feclearexcept
11901 -.type feclearexcept, @function
11912 -.global feraiseexcept
11913 -.type feraiseexcept, @function
11924 -.type fegetenv, @function
11932 -.type fesetenv, @function
11938 - ! the default environment is complicated by the fact that we need to
11939 - ! preserve the current precision bit, which we do not know a priori
11946 -1: mov.l @r4, r0 ! non-default environment
11950 --- a/src/fenv/sheb-nofpu/fenv.sub
11954 --- a/src/internal/arm/syscall.s
11955 +++ b/src/internal/arm/syscall.s
11960 .type __syscall,%function
11961 @@ -11,6 +12,4 @@ __syscall:
11962 ldmfd ip,{r3,r4,r5,r6}
11964 ldmfd sp!,{r4,r5,r6,r7}
11969 +++ b/src/internal/atomic.h
11974 +#include <stdint.h>
11976 +#include "atomic_arch.h"
11980 +#ifndef a_pre_llsc
11981 +#define a_pre_llsc()
11984 +#ifndef a_post_llsc
11985 +#define a_post_llsc()
11989 +#define a_cas a_cas
11990 +static inline int a_cas(volatile int *p, int t, int s)
11994 + do old = a_ll(p);
11995 + while (old==t && !a_sc(p, s));
12002 +#define a_swap a_swap
12003 +static inline int a_swap(volatile int *p, int v)
12007 + do old = a_ll(p);
12008 + while (!a_sc(p, v));
12014 +#ifndef a_fetch_add
12015 +#define a_fetch_add a_fetch_add
12016 +static inline int a_fetch_add(volatile int *p, int v)
12020 + do old = a_ll(p);
12021 + while (!a_sc(p, (unsigned)old + v));
12027 +#ifndef a_fetch_and
12028 +#define a_fetch_and a_fetch_and
12029 +static inline int a_fetch_and(volatile int *p, int v)
12033 + do old = a_ll(p);
12034 + while (!a_sc(p, old & v));
12040 +#ifndef a_fetch_or
12041 +#define a_fetch_or a_fetch_or
12042 +static inline int a_fetch_or(volatile int *p, int v)
12046 + do old = a_ll(p);
12047 + while (!a_sc(p, old | v));
12056 +#error missing definition of a_cas
12060 +#define a_swap a_swap
12061 +static inline int a_swap(volatile int *p, int v)
12065 + while (a_cas(p, old, v) != old);
12070 +#ifndef a_fetch_add
12071 +#define a_fetch_add a_fetch_add
12072 +static inline int a_fetch_add(volatile int *p, int v)
12076 + while (a_cas(p, old, (unsigned)old+v) != old);
12081 +#ifndef a_fetch_and
12082 +#define a_fetch_and a_fetch_and
12083 +static inline int a_fetch_and(volatile int *p, int v)
12087 + while (a_cas(p, old, old&v) != old);
12091 +#ifndef a_fetch_or
12092 +#define a_fetch_or a_fetch_or
12093 +static inline int a_fetch_or(volatile int *p, int v)
12097 + while (a_cas(p, old, old|v) != old);
12103 +#define a_and a_and
12104 +static inline void a_and(volatile int *p, int v)
12106 + a_fetch_and(p, v);
12112 +static inline void a_or(volatile int *p, int v)
12114 + a_fetch_or(p, v);
12119 +#define a_inc a_inc
12120 +static inline void a_inc(volatile int *p)
12122 + a_fetch_add(p, 1);
12127 +#define a_dec a_dec
12128 +static inline void a_dec(volatile int *p)
12130 + a_fetch_add(p, -1);
12135 +#define a_store a_store
12136 +static inline void a_store(volatile int *p, int v)
12149 +#define a_barrier a_barrier
12150 +static void a_barrier()
12152 + volatile int tmp = 0;
12153 + a_cas(&tmp, 0, 0);
12158 +#define a_spin a_barrier
12162 +#define a_and_64 a_and_64
12163 +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
12165 + union { uint64_t v; uint32_t r[2]; } u = { v };
12166 + if (u.r[0]+1) a_and((int *)p, u.r[0]);
12167 + if (u.r[1]+1) a_and((int *)p+1, u.r[1]);
12172 +#define a_or_64 a_or_64
12173 +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
12175 + union { uint64_t v; uint32_t r[2]; } u = { v };
12176 + if (u.r[0]) a_or((int *)p, u.r[0]);
12177 + if (u.r[1]) a_or((int *)p+1, u.r[1]);
12182 +#define a_cas_p a_cas_p
12183 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
12185 + return (void *)a_cas((volatile int *)p, (int)t, (int)s);
12190 +#define a_or_l a_or_l
12191 +static inline void a_or_l(volatile void *p, long v)
12193 + if (sizeof(long) == sizeof(int)) a_or(p, v);
12194 + else a_or_64(p, v);
12199 +#define a_crash a_crash
12200 +static inline void a_crash()
12202 + *(volatile char *)0=0;
12207 +#define a_ctz_64 a_ctz_64
12208 +static inline int a_ctz_64(uint64_t x)
12210 + static const char debruijn64[64] = {
12211 + 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
12212 + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
12213 + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
12214 + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
12216 + static const char debruijn32[32] = {
12217 + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
12218 + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
12220 + if (sizeof(long) < 8) {
12224 + return 32 + debruijn32[(y&-y)*0x076be629 >> 27];
12226 + return debruijn32[(y&-y)*0x076be629 >> 27];
12228 + return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58];
12233 +#define a_ctz_l a_ctz_l
12234 +static inline int a_ctz_l(unsigned long x)
12236 + static const char debruijn32[32] = {
12237 + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
12238 + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
12240 + if (sizeof(long) == 8) return a_ctz_64(x);
12241 + return debruijn32[(x&-x)*0x076be629 >> 27];
12246 --- a/src/internal/dynlink.h
12247 +++ b/src/internal/dynlink.h
12248 @@ -64,6 +64,10 @@ struct fdpic_dummy_loadmap {
12252 +#ifndef DL_NOMMU_SUPPORT
12253 +#define DL_NOMMU_SUPPORT 0
12257 #define IS_RELATIVE(x,s) ( \
12258 (R_TYPE(x) == REL_RELATIVE) || \
12259 --- a/src/internal/libc.h
12260 +++ b/src/internal/libc.h
12261 @@ -11,13 +11,20 @@ struct __locale_struct {
12262 const struct __locale_map *volatile cat[6];
12265 +struct tls_module {
12266 + struct tls_module *next;
12268 + size_t len, size, align, offset;
12272 int can_do_threads;
12275 volatile int threads_minus_1;
12278 + struct tls_module *tls_head;
12279 + size_t tls_size, tls_align, tls_cnt;
12281 struct __locale_struct global_locale;
12284 +++ b/src/internal/sh/__shcall.c
12286 +__attribute__((__visibility__("hidden")))
12287 +int __shcall(void *arg, int (*func)(void *))
12289 + return func(arg);
12291 --- a/src/internal/syscall.h
12292 +++ b/src/internal/syscall.h
12294 typedef long syscall_arg_t;
12298 __attribute__((visibility("hidden")))
12300 long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...),
12301 __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
12302 syscall_arg_t, syscall_arg_t, syscall_arg_t);
12303 @@ -65,7 +63,7 @@ long __syscall_ret(unsigned long), __sys
12304 #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
12305 #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
12308 +#ifndef SYSCALL_USE_SOCKETCALL
12309 #define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f)
12310 #define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f)
12312 --- a/src/internal/version.c
12313 +++ b/src/internal/version.c
12317 #include "version.h"
12319 static const char version[] = VERSION;
12321 +__attribute__((__visibility__("hidden")))
12322 const char *__libc_get_version()
12328 --- a/src/internal/vis.h
12329 +++ b/src/internal/vis.h
12331 * override default visibilities to reduce the size and performance costs
12332 * of position-independent code. */
12336 +#if !defined(CRT) && !defined(__ASSEMBLER__)
12338 -/* For shared libc.so, all symbols should be protected, but some toolchains
12339 +/* Conceptually, all symbols should be protected, but some toolchains
12340 * fail to support copy relocations for protected data, so exclude all
12341 * exported data symbols. */
12343 @@ -25,16 +24,4 @@ extern char *optarg, **environ, **__envi
12345 #pragma GCC visibility push(protected)
12347 -#elif defined(__PIC__)
12349 -/* If building static libc.a as position-independent code, try to make
12350 - * everything hidden except possibly-undefined weak references. */
12352 -__attribute__((__visibility__("default")))
12353 -extern void (*const __init_array_start)(), (*const __init_array_end)(),
12354 - (*const __fini_array_start)(), (*const __fini_array_end)();
12356 -#pragma GCC visibility push(hidden)
12361 +++ b/src/ldso/__dlsym.c
12363 +#include <dlfcn.h>
12366 +__attribute__((__visibility__("hidden")))
12367 +void __dl_seterr(const char *, ...);
12369 +static void *stub_dlsym(void *restrict p, const char *restrict s, void *restrict ra)
12371 + __dl_seterr("Symbol not found: %s", s);
12375 +weak_alias(stub_dlsym, __dlsym);
12376 --- a/src/ldso/arm/dlsym.s
12377 +++ b/src/ldso/arm/dlsym.s
12384 +++ b/src/ldso/arm/find_exidx.c
12386 +#define _GNU_SOURCE
12388 +#include <stdint.h>
12390 +struct find_exidx_data {
12391 + uintptr_t pc, exidx_start;
12395 +static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
12397 + struct find_exidx_data *data = ptr;
12398 + const ElfW(Phdr) *phdr = info->dlpi_phdr;
12399 + uintptr_t addr, exidx_start = 0;
12400 + int i, match = 0, exidx_len = 0;
12402 + for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
12403 + addr = info->dlpi_addr + phdr->p_vaddr;
12404 + switch (phdr->p_type) {
12406 + match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
12408 + case PT_ARM_EXIDX:
12409 + exidx_start = addr;
12410 + exidx_len = phdr->p_memsz;
12414 + data->exidx_start = exidx_start;
12415 + data->exidx_len = exidx_len;
12419 +uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
12421 + struct find_exidx_data data;
12423 + if (dl_iterate_phdr(find_exidx, &data) <= 0)
12425 + *pcount = data.exidx_len / 8;
12426 + return data.exidx_start;
12428 --- a/src/ldso/dl_iterate_phdr.c
12429 +++ b/src/ldso/dl_iterate_phdr.c
12439 -int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
12440 +static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
12443 ElfW(Phdr) *phdr, *tls_phdr=0;
12444 @@ -40,4 +38,5 @@ int dl_iterate_phdr(int(*callback)(struc
12446 return (callback)(&info, sizeof (info), data);
12450 +weak_alias(static_dl_iterate_phdr, dl_iterate_phdr);
12451 --- a/src/ldso/dladdr.c
12452 +++ b/src/ldso/dladdr.c
12454 #define _GNU_SOURCE
12458 -int __dladdr(const void *, Dl_info *);
12460 -int dladdr(const void *addr, Dl_info *info)
12461 +static int stub_dladdr(const void *addr, Dl_info *info)
12463 - return __dladdr(addr, info);
12467 +weak_alias(stub_dladdr, dladdr);
12469 +++ b/src/ldso/dlclose.c
12471 +#include <dlfcn.h>
12473 +__attribute__((__visibility__("hidden")))
12474 +int __dl_invalid_handle(void *);
12476 +int dlclose(void *p)
12478 + return __dl_invalid_handle(p);
12481 +++ b/src/ldso/dlerror.c
12483 +#include <dlfcn.h>
12484 +#include <stdlib.h>
12485 +#include <stdarg.h>
12486 +#include "pthread_impl.h"
12491 + pthread_t self = __pthread_self();
12492 + if (!self->dlerror_flag) return 0;
12493 + self->dlerror_flag = 0;
12494 + char *s = self->dlerror_buf;
12495 + if (s == (void *)-1)
12496 + return "Dynamic linker failed to allocate memory for error message";
12501 +void __dl_thread_cleanup(void)
12503 + pthread_t self = __pthread_self();
12504 + if (self->dlerror_buf != (void *)-1)
12505 + free(self->dlerror_buf);
12508 +__attribute__((__visibility__("hidden")))
12509 +void __dl_vseterr(const char *fmt, va_list ap)
12512 + va_copy(ap2, ap);
12513 + pthread_t self = __pthread_self();
12514 + if (self->dlerror_buf != (void *)-1)
12515 + free(self->dlerror_buf);
12516 + size_t len = vsnprintf(0, 0, fmt, ap2);
12518 + char *buf = malloc(len+1);
12520 + vsnprintf(buf, len+1, fmt, ap);
12522 + buf = (void *)-1;
12524 + self->dlerror_buf = buf;
12525 + self->dlerror_flag = 1;
12528 +__attribute__((__visibility__("hidden")))
12529 +void __dl_seterr(const char *fmt, ...)
12532 + va_start(ap, fmt);
12533 + __dl_vseterr(fmt, ap);
12537 +__attribute__((__visibility__("hidden")))
12538 +int __dl_invalid_handle(void *);
12540 +static int stub_invalid_handle(void *h)
12542 + __dl_seterr("Invalid library handle %p", (void *)h);
12546 +weak_alias(stub_invalid_handle, __dl_invalid_handle);
12547 --- a/src/ldso/dlinfo.c
12548 +++ b/src/ldso/dlinfo.c
12550 #define _GNU_SOURCE
12553 -int __dlinfo(void *, int, void *);
12554 +__attribute__((__visibility__("hidden")))
12555 +int __dl_invalid_handle(void *);
12557 +__attribute__((__visibility__("hidden")))
12558 +void __dl_seterr(const char *, ...);
12560 int dlinfo(void *dso, int req, void *res)
12562 - return __dlinfo(dso, req, res);
12563 + if (__dl_invalid_handle(dso)) return -1;
12564 + if (req != RTLD_DI_LINKMAP) {
12565 + __dl_seterr("Unsupported request %d", req);
12568 + *(struct link_map **)res = dso;
12572 +++ b/src/ldso/dlopen.c
12574 +#include <dlfcn.h>
12577 +__attribute__((__visibility__("hidden")))
12578 +void __dl_seterr(const char *, ...);
12580 +static void *stub_dlopen(const char *file, int mode)
12582 + __dl_seterr("Dynamic loading not supported");
12586 +weak_alias(stub_dlopen, dlopen);
12587 --- a/src/ldso/dlstart.c
12590 -#include <stddef.h>
12591 -#include "dynlink.h"
12596 -#define START "_dlstart"
12599 -#include "crt_arch.h"
12601 -#ifndef GETFUNCSYM
12602 -#define GETFUNCSYM(fp, sym, got) do { \
12603 - __attribute__((__visibility__("hidden"))) void sym(); \
12604 - static void (*static_func_ptr)() = sym; \
12605 - __asm__ __volatile__ ( "" : "+m"(static_func_ptr) : : "memory"); \
12606 - *(fp) = static_func_ptr; } while(0)
12609 -__attribute__((__visibility__("hidden")))
12610 -void _dlstart_c(size_t *sp, size_t *dynv)
12612 - size_t i, aux[AUX_CNT], dyn[DYN_CNT];
12613 - size_t *rel, rel_size, base;
12616 - char **argv = (void *)(sp+1);
12618 - for (i=argc+1; argv[i]; i++);
12619 - size_t *auxv = (void *)(argv+i+1);
12621 - for (i=0; i<AUX_CNT; i++) aux[i] = 0;
12622 - for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT)
12623 - aux[auxv[i]] = auxv[i+1];
12626 - struct fdpic_loadseg *segs, fakeseg;
12629 - /* crt_arch.h entry point asm is responsible for reserving
12630 - * space and moving the extra fdpic arguments to the stack
12631 - * vector where they are easily accessible from C. */
12632 - segs = ((struct fdpic_loadmap *)(sp[-1] ? sp[-1] : sp[-2]))->segs;
12634 - /* If dynv is null, the entry point was started from loader
12635 - * that is not fdpic-aware. We can assume normal fixed-
12636 - * displacement ELF loading was performed, but when ldso was
12637 - * run as a command, finding the Ehdr is a heursitic: we
12638 - * have to assume Phdrs start in the first 4k of the file. */
12639 - base = aux[AT_BASE];
12640 - if (!base) base = aux[AT_PHDR] & -4096;
12642 - segs[0].addr = base;
12643 - segs[0].p_vaddr = 0;
12644 - segs[0].p_memsz = -1;
12645 - Ehdr *eh = (void *)base;
12646 - Phdr *ph = (void *)(base + eh->e_phoff);
12647 - size_t phnum = eh->e_phnum;
12648 - size_t phent = eh->e_phentsize;
12649 - while (phnum-- && ph->p_type != PT_DYNAMIC)
12650 - ph = (void *)((size_t)ph + phent);
12651 - dynv = (void *)(base + ph->p_vaddr);
12655 - for (i=0; i<DYN_CNT; i++) dyn[i] = 0;
12656 - for (i=0; dynv[i]; i+=2) if (dynv[i]<DYN_CNT)
12657 - dyn[dynv[i]] = dynv[i+1];
12660 - for (i=0; i<DYN_CNT; i++) {
12661 - if (i==DT_RELASZ || i==DT_RELSZ) continue;
12662 - if (!dyn[i]) continue;
12663 - for (j=0; dyn[i]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
12664 - dyn[i] += segs[j].addr - segs[j].p_vaddr;
12668 - const Sym *syms = (void *)dyn[DT_SYMTAB];
12670 - rel = (void *)dyn[DT_RELA];
12671 - rel_size = dyn[DT_RELASZ];
12672 - for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
12673 - if (!IS_RELATIVE(rel[1], syms)) continue;
12674 - for (j=0; rel[0]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
12675 - size_t *rel_addr = (void *)
12676 - (rel[0] + segs[j].addr - segs[j].p_vaddr);
12677 - if (R_TYPE(rel[1]) == REL_FUNCDESC_VAL) {
12678 - *rel_addr += segs[rel_addr[1]].addr
12679 - - segs[rel_addr[1]].p_vaddr
12680 - + syms[R_SYM(rel[1])].st_value;
12681 - rel_addr[1] = dyn[DT_PLTGOT];
12683 - size_t val = syms[R_SYM(rel[1])].st_value;
12684 - for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
12685 - *rel_addr = rel[2] + segs[j].addr - segs[j].p_vaddr + val;
12689 - /* If the dynamic linker is invoked as a command, its load
12690 - * address is not available in the aux vector. Instead, compute
12691 - * the load address as the difference between &_DYNAMIC and the
12692 - * virtual address in the PT_DYNAMIC program header. */
12693 - base = aux[AT_BASE];
12695 - size_t phnum = aux[AT_PHNUM];
12696 - size_t phentsize = aux[AT_PHENT];
12697 - Phdr *ph = (void *)aux[AT_PHDR];
12698 - for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
12699 - if (ph->p_type == PT_DYNAMIC) {
12700 - base = (size_t)dynv - ph->p_vaddr;
12706 - /* MIPS uses an ugly packed form for GOT relocations. Since we
12707 - * can't make function calls yet and the code is tiny anyway,
12708 - * it's simply inlined here. */
12709 - if (NEED_MIPS_GOT_RELOCS) {
12710 - size_t local_cnt = 0;
12711 - size_t *got = (void *)(base + dyn[DT_PLTGOT]);
12712 - for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
12713 - local_cnt = dynv[i+1];
12714 - for (i=0; i<local_cnt; i++) got[i] += base;
12717 - rel = (void *)(base+dyn[DT_REL]);
12718 - rel_size = dyn[DT_RELSZ];
12719 - for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
12720 - if (!IS_RELATIVE(rel[1], 0)) continue;
12721 - size_t *rel_addr = (void *)(base + rel[0]);
12722 - *rel_addr += base;
12725 - rel = (void *)(base+dyn[DT_RELA]);
12726 - rel_size = dyn[DT_RELASZ];
12727 - for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
12728 - if (!IS_RELATIVE(rel[1], 0)) continue;
12729 - size_t *rel_addr = (void *)(base + rel[0]);
12730 - *rel_addr = base + rel[2];
12734 - stage2_func dls2;
12735 - GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
12736 - dls2((void *)base, sp);
12740 --- a/src/ldso/dynlink.c
12743 -#define _GNU_SOURCE
12744 -#include <stdio.h>
12745 -#include <stdlib.h>
12746 -#include <stdarg.h>
12747 -#include <stddef.h>
12748 -#include <string.h>
12749 -#include <unistd.h>
12750 -#include <stdint.h>
12752 -#include <sys/mman.h>
12753 -#include <limits.h>
12754 -#include <fcntl.h>
12755 -#include <sys/stat.h>
12756 -#include <errno.h>
12758 -#include <setjmp.h>
12759 -#include <pthread.h>
12760 -#include <ctype.h>
12761 -#include <dlfcn.h>
12762 -#include "pthread_impl.h"
12764 -#include "dynlink.h"
12766 -static void error(const char *, ...);
12770 -#define MAXP2(a,b) (-(-(a)&-(b)))
12771 -#define ALIGN(x,y) ((x)+(y)-1 & -(y))
12776 - void (*bp)(void);
12783 - struct td_index *next;
12788 - struct fdpic_loadmap *loadmap;
12790 - unsigned char *base;
12794 - struct dso *next, *prev;
12798 - size_t phentsize;
12801 - uint32_t *hashtab;
12802 - uint32_t *ghashtab;
12805 - unsigned char *map;
12809 - signed char global;
12811 - char constructed;
12812 - char kernel_mapped;
12813 - struct dso **deps, *needed_by;
12814 - char *rpath_orig, *rpath;
12816 - size_t tls_len, tls_size, tls_align, tls_id, tls_offset;
12817 - size_t relro_start, relro_end;
12819 - unsigned char *new_tls;
12820 - volatile int new_dtv_idx, new_tls_idx;
12821 - struct td_index *td_index;
12822 - struct dso *fini_next;
12825 - unsigned char *base;
12827 - struct fdpic_loadmap *loadmap;
12829 - struct funcdesc {
12842 -int __init_tp(void *);
12843 -void __init_libc(char **, char *);
12845 -const char *__libc_get_version(void);
12847 -static struct builtin_tls {
12849 - struct pthread pt;
12852 -#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
12854 -#define ADDEND_LIMIT 4096
12855 -static size_t *saved_addends, *apply_addends_to;
12857 -static struct dso ldso;
12858 -static struct dso *head, *tail, *fini_head;
12859 -static char *env_path, *sys_path;
12860 -static unsigned long long gencnt;
12861 -static int runtime;
12862 -static int ldd_mode;
12863 -static int ldso_fail;
12864 -static int noload;
12865 -static jmp_buf *rtld_fail;
12866 -static pthread_rwlock_t lock;
12867 -static struct debug debug;
12868 -static size_t tls_cnt, tls_offset, tls_align = MIN_TLS_ALIGN;
12869 -static size_t static_tls_cnt;
12870 -static pthread_mutex_t init_fini_lock = { ._m_type = PTHREAD_MUTEX_RECURSIVE };
12871 -static struct fdpic_loadmap *app_loadmap;
12872 -static struct fdpic_dummy_loadmap app_dummy_loadmap;
12874 -struct debug *_dl_debug_addr = &debug;
12876 -static int dl_strcmp(const char *l, const char *r)
12878 - for (; *l==*r && *l; l++, r++);
12879 - return *(unsigned char *)l - *(unsigned char *)r;
12881 -#define strcmp(l,r) dl_strcmp(l,r)
12883 -/* Compute load address for a virtual address in a given dso. */
12885 -static void *laddr(const struct dso *p, size_t v)
12888 - if (!p->loadmap) return p->base + v;
12889 - for (j=0; v-p->loadmap->segs[j].p_vaddr >= p->loadmap->segs[j].p_memsz; j++);
12890 - return (void *)(v - p->loadmap->segs[j].p_vaddr + p->loadmap->segs[j].addr);
12892 -#define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \
12893 - laddr(p, v), (p)->got })
12895 -#define laddr(p, v) (void *)((p)->base + (v))
12896 -#define fpaddr(p, v) ((void (*)())laddr(p, v))
12899 -static void decode_vec(size_t *v, size_t *a, size_t cnt)
12902 - for (i=0; i<cnt; i++) a[i] = 0;
12903 - for (; v[0]; v+=2) if (v[0]-1<cnt-1) {
12904 - a[0] |= 1UL<<v[0];
12909 -static int search_vec(size_t *v, size_t *r, size_t key)
12911 - for (; v[0]!=key; v+=2)
12912 - if (!v[0]) return 0;
12917 -static uint32_t sysv_hash(const char *s0)
12919 - const unsigned char *s = (void *)s0;
12920 - uint_fast32_t h = 0;
12923 - h ^= h>>24 & 0xf0;
12925 - return h & 0xfffffff;
12928 -static uint32_t gnu_hash(const char *s0)
12930 - const unsigned char *s = (void *)s0;
12931 - uint_fast32_t h = 5381;
12937 -static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
12940 - Sym *syms = dso->syms;
12941 - uint32_t *hashtab = dso->hashtab;
12942 - char *strings = dso->strings;
12943 - for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) {
12944 - if ((!dso->versym || dso->versym[i] >= 0)
12945 - && (!strcmp(s, strings+syms[i].st_name)))
12951 -static Sym *gnu_lookup(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s)
12953 - uint32_t nbuckets = hashtab[0];
12954 - uint32_t *buckets = hashtab + 4 + hashtab[2]*(sizeof(size_t)/4);
12955 - uint32_t i = buckets[h1 % nbuckets];
12957 - if (!i) return 0;
12959 - uint32_t *hashval = buckets + nbuckets + (i - hashtab[1]);
12961 - for (h1 |= 1; ; i++) {
12962 - uint32_t h2 = *hashval++;
12963 - if ((h1 == (h2|1)) && (!dso->versym || dso->versym[i] >= 0)
12964 - && !strcmp(s, dso->strings + dso->syms[i].st_name))
12965 - return dso->syms+i;
12966 - if (h2 & 1) break;
12972 -static Sym *gnu_lookup_filtered(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s, uint32_t fofs, size_t fmask)
12974 - const size_t *bloomwords = (const void *)(hashtab+4);
12975 - size_t f = bloomwords[fofs & (hashtab[2]-1)];
12976 - if (!(f & fmask)) return 0;
12978 - f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
12979 - if (!(f & 1)) return 0;
12981 - return gnu_lookup(h1, hashtab, dso, s);
12984 -#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON | 1<<STT_TLS)
12985 -#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
12987 -#ifndef ARCH_SYM_REJECT_UND
12988 -#define ARCH_SYM_REJECT_UND(s) 0
12991 -static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
12993 - uint32_t h = 0, gh, gho, *ght;
12995 - struct symdef def = {0};
12996 - for (; dso; dso=dso->next) {
12998 - if (!dso->global) continue;
12999 - if ((ght = dso->ghashtab)) {
13001 - gh = gnu_hash(s);
13002 - int maskbits = 8 * sizeof ghm;
13003 - gho = gh / maskbits;
13004 - ghm = 1ul << gh % maskbits;
13006 - sym = gnu_lookup_filtered(gh, ght, dso, s, gho, ghm);
13008 - if (!h) h = sysv_hash(s);
13009 - sym = sysv_lookup(s, h, dso);
13011 - if (!sym) continue;
13012 - if (!sym->st_shndx)
13013 - if (need_def || (sym->st_info&0xf) == STT_TLS
13014 - || ARCH_SYM_REJECT_UND(sym))
13016 - if (!sym->st_value)
13017 - if ((sym->st_info&0xf) != STT_TLS)
13019 - if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
13020 - if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
13022 - if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
13025 - if (sym->st_info>>4 == STB_GLOBAL) break;
13030 -__attribute__((__visibility__("hidden")))
13031 -ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
13033 -static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
13035 - unsigned char *base = dso->base;
13036 - Sym *syms = dso->syms;
13037 - char *strings = dso->strings;
13039 - const char *name;
13043 - struct symdef def;
13044 - size_t *reloc_addr;
13048 - int skip_relative = 0, reuse_addends = 0, save_slot = 0;
13050 - if (dso == &ldso) {
13051 - /* Only ldso's REL table needs addend saving/reuse. */
13052 - if (rel == apply_addends_to)
13053 - reuse_addends = 1;
13054 - skip_relative = 1;
13057 - for (; rel_size; rel+=stride, rel_size-=stride*sizeof(size_t)) {
13058 - if (skip_relative && IS_RELATIVE(rel[1], dso->syms)) continue;
13059 - type = R_TYPE(rel[1]);
13060 - if (type == REL_NONE) continue;
13061 - sym_index = R_SYM(rel[1]);
13062 - reloc_addr = laddr(dso, rel[0]);
13064 - sym = syms + sym_index;
13065 - name = strings + sym->st_name;
13066 - ctx = type==REL_COPY ? head->next : head;
13067 - def = (sym->st_info&0xf) == STT_SECTION
13068 - ? (struct symdef){ .dso = dso, .sym = sym }
13069 - : find_sym(ctx, name, type==REL_PLT);
13070 - if (!def.sym && (sym->st_shndx != SHN_UNDEF
13071 - || sym->st_info>>4 != STB_WEAK)) {
13072 - error("Error relocating %s: %s: symbol not found",
13073 - dso->name, name);
13074 - if (runtime) longjmp(*rtld_fail, 1);
13083 - if (stride > 2) {
13085 - } else if (type==REL_GOT || type==REL_PLT|| type==REL_COPY) {
13087 - } else if (reuse_addends) {
13088 - /* Save original addend in stage 2 where the dso
13089 - * chain consists of just ldso; otherwise read back
13090 - * saved addend since the inline one was clobbered. */
13092 - saved_addends[save_slot] = *reloc_addr;
13093 - addend = saved_addends[save_slot++];
13095 - addend = *reloc_addr;
13098 - sym_val = def.sym ? (size_t)laddr(def.dso, def.sym->st_value) : 0;
13099 - tls_val = def.sym ? def.sym->st_value : 0;
13105 - addend -= (size_t)reloc_addr;
13106 - case REL_SYMBOLIC:
13109 - *reloc_addr = sym_val + addend;
13111 - case REL_RELATIVE:
13112 - *reloc_addr = (size_t)base + addend;
13114 - case REL_SYM_OR_REL:
13115 - if (sym) *reloc_addr = sym_val + addend;
13116 - else *reloc_addr = (size_t)base + addend;
13119 - memcpy(reloc_addr, (void *)sym_val, sym->st_size);
13121 - case REL_OFFSET32:
13122 - *(uint32_t *)reloc_addr = sym_val + addend
13123 - - (size_t)reloc_addr;
13125 - case REL_FUNCDESC:
13126 - *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs
13127 - + (def.sym - def.dso->syms)) : 0;
13129 - case REL_FUNCDESC_VAL:
13130 - if ((sym->st_info&0xf) == STT_SECTION) *reloc_addr += sym_val;
13131 - else *reloc_addr = sym_val;
13132 - reloc_addr[1] = def.sym ? (size_t)def.dso->got : 0;
13135 - *reloc_addr = def.dso->tls_id;
13138 - *reloc_addr = tls_val + addend - DTP_OFFSET;
13140 -#ifdef TLS_ABOVE_TP
13142 - *reloc_addr = tls_val + def.dso->tls_offset + TPOFF_K + addend;
13146 - *reloc_addr = tls_val - def.dso->tls_offset + addend;
13148 - case REL_TPOFF_NEG:
13149 - *reloc_addr = def.dso->tls_offset - tls_val + addend;
13152 - case REL_TLSDESC:
13153 - if (stride<3) addend = reloc_addr[1];
13154 - if (runtime && def.dso->tls_id >= static_tls_cnt) {
13155 - struct td_index *new = malloc(sizeof *new);
13158 - "Error relocating %s: cannot allocate TLSDESC for %s",
13159 - dso->name, sym ? name : "(local)" );
13160 - longjmp(*rtld_fail, 1);
13162 - new->next = dso->td_index;
13163 - dso->td_index = new;
13164 - new->args[0] = def.dso->tls_id;
13165 - new->args[1] = tls_val + addend;
13166 - reloc_addr[0] = (size_t)__tlsdesc_dynamic;
13167 - reloc_addr[1] = (size_t)new;
13169 - reloc_addr[0] = (size_t)__tlsdesc_static;
13170 -#ifdef TLS_ABOVE_TP
13171 - reloc_addr[1] = tls_val + def.dso->tls_offset
13172 - + TPOFF_K + addend;
13174 - reloc_addr[1] = tls_val - def.dso->tls_offset
13180 - error("Error relocating %s: unsupported relocation type %d",
13181 - dso->name, type);
13182 - if (runtime) longjmp(*rtld_fail, 1);
13188 -/* A huge hack: to make up for the wastefulness of shared libraries
13189 - * needing at least a page of dirty memory even if they have no global
13190 - * data, we reclaim the gaps at the beginning and end of writable maps
13191 - * and "donate" them to the heap by setting up minimal malloc
13192 - * structures and then freeing them. */
13194 -static void reclaim(struct dso *dso, size_t start, size_t end)
13197 - if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end;
13198 - if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start;
13199 - start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t);
13200 - end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t);
13201 - if (start>end || end-start < 4*sizeof(size_t)) return;
13202 - a = laddr(dso, start);
13203 - z = laddr(dso, end);
13205 - a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1;
13210 -static void reclaim_gaps(struct dso *dso)
13212 - Phdr *ph = dso->phdr;
13213 - size_t phcnt = dso->phnum;
13215 - if (DL_FDPIC) return; // FIXME
13216 - for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
13217 - if (ph->p_type!=PT_LOAD) continue;
13218 - if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
13219 - reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
13220 - reclaim(dso, ph->p_vaddr+ph->p_memsz,
13221 - ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
13225 -static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t off)
13227 - char *q = mmap(p, n, prot, flags, fd, off);
13228 - if (q != MAP_FAILED || errno != EINVAL) return q;
13229 - /* Fallbacks for MAP_FIXED failure on NOMMU kernels. */
13230 - if (flags & MAP_ANONYMOUS) {
13235 - if (lseek(fd, off, SEEK_SET) < 0) return MAP_FAILED;
13236 - for (q=p; n; q+=r, off+=r, n-=r) {
13237 - r = read(fd, q, n);
13238 - if (r < 0 && errno != EINTR) return MAP_FAILED;
13247 -static void unmap_library(struct dso *dso)
13249 - if (dso->loadmap) {
13251 - for (i=0; i<dso->loadmap->nsegs; i++) {
13252 - if (!dso->loadmap->segs[i].p_memsz)
13254 - munmap((void *)dso->loadmap->segs[i].addr,
13255 - dso->loadmap->segs[i].p_memsz);
13257 - free(dso->loadmap);
13258 - } else if (dso->map && dso->map_len) {
13259 - munmap(dso->map, dso->map_len);
13263 -static void *map_library(int fd, struct dso *dso)
13265 - Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
13266 - void *allocated_buf=0;
13268 - size_t addr_min=SIZE_MAX, addr_max=0, map_len;
13269 - size_t this_min, this_max;
13270 - size_t nsegs = 0;
13275 - unsigned char *map=MAP_FAILED, *base;
13277 - size_t tls_image=0;
13280 - ssize_t l = read(fd, buf, sizeof buf);
13282 - if (l<0) return 0;
13283 - if (l<sizeof *eh || (eh->e_type != ET_DYN && eh->e_type != ET_EXEC))
13285 - phsize = eh->e_phentsize * eh->e_phnum;
13286 - if (phsize > sizeof buf - sizeof *eh) {
13287 - allocated_buf = malloc(phsize);
13288 - if (!allocated_buf) return 0;
13289 - l = pread(fd, allocated_buf, phsize, eh->e_phoff);
13290 - if (l < 0) goto error;
13291 - if (l != phsize) goto noexec;
13292 - ph = ph0 = allocated_buf;
13293 - } else if (eh->e_phoff + phsize > l) {
13294 - l = pread(fd, buf+1, phsize, eh->e_phoff);
13295 - if (l < 0) goto error;
13296 - if (l != phsize) goto noexec;
13297 - ph = ph0 = (void *)(buf + 1);
13299 - ph = ph0 = (void *)((char *)buf + eh->e_phoff);
13301 - for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
13302 - if (ph->p_type == PT_DYNAMIC) {
13303 - dyn = ph->p_vaddr;
13304 - } else if (ph->p_type == PT_TLS) {
13305 - tls_image = ph->p_vaddr;
13306 - dso->tls_align = ph->p_align;
13307 - dso->tls_len = ph->p_filesz;
13308 - dso->tls_size = ph->p_memsz;
13309 - } else if (ph->p_type == PT_GNU_RELRO) {
13310 - dso->relro_start = ph->p_vaddr & -PAGE_SIZE;
13311 - dso->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
13313 - if (ph->p_type != PT_LOAD) continue;
13315 - if (ph->p_vaddr < addr_min) {
13316 - addr_min = ph->p_vaddr;
13317 - off_start = ph->p_offset;
13318 - prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
13319 - ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
13320 - ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
13322 - if (ph->p_vaddr+ph->p_memsz > addr_max) {
13323 - addr_max = ph->p_vaddr+ph->p_memsz;
13326 - if (!dyn) goto noexec;
13327 - if (DL_FDPIC && !(eh->e_flags & FDPIC_CONSTDISP_FLAG)) {
13328 - dso->loadmap = calloc(1, sizeof *dso->loadmap
13329 - + nsegs * sizeof *dso->loadmap->segs);
13330 - if (!dso->loadmap) goto error;
13331 - dso->loadmap->nsegs = nsegs;
13332 - for (ph=ph0, i=0; i<nsegs; ph=(void *)((char *)ph+eh->e_phentsize)) {
13333 - if (ph->p_type != PT_LOAD) continue;
13334 - prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
13335 - ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
13336 - ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
13337 - map = mmap(0, ph->p_memsz + (ph->p_vaddr & PAGE_SIZE-1),
13338 - prot, (prot&PROT_WRITE) ? MAP_PRIVATE : MAP_SHARED,
13339 - fd, ph->p_offset & -PAGE_SIZE);
13340 - if (map == MAP_FAILED) {
13341 - unmap_library(dso);
13344 - dso->loadmap->segs[i].addr = (size_t)map +
13345 - (ph->p_vaddr & PAGE_SIZE-1);
13346 - dso->loadmap->segs[i].p_vaddr = ph->p_vaddr;
13347 - dso->loadmap->segs[i].p_memsz = ph->p_memsz;
13350 - map = (void *)dso->loadmap->segs[0].addr;
13352 - goto done_mapping;
13354 - addr_max += PAGE_SIZE-1;
13355 - addr_max &= -PAGE_SIZE;
13356 - addr_min &= -PAGE_SIZE;
13357 - off_start &= -PAGE_SIZE;
13358 - map_len = addr_max - addr_min + off_start;
13359 - /* The first time, we map too much, possibly even more than
13360 - * the length of the file. This is okay because we will not
13361 - * use the invalid part; we just need to reserve the right
13362 - * amount of virtual address space to map over later. */
13363 - map = mmap((void *)addr_min, map_len, prot, MAP_PRIVATE, fd, off_start);
13364 - if (map==MAP_FAILED) goto error;
13366 - dso->map_len = map_len;
13367 - /* If the loaded file is not relocatable and the requested address is
13368 - * not available, then the load operation must fail. */
13369 - if (eh->e_type != ET_DYN && addr_min && map!=(void *)addr_min) {
13373 - base = map - addr_min;
13376 - for (ph=ph0, i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) {
13377 - if (ph->p_type != PT_LOAD) continue;
13378 - /* Check if the programs headers are in this load segment, and
13379 - * if so, record the address for use by dl_iterate_phdr. */
13380 - if (!dso->phdr && eh->e_phoff >= ph->p_offset
13381 - && eh->e_phoff+phsize <= ph->p_offset+ph->p_filesz) {
13382 - dso->phdr = (void *)(base + ph->p_vaddr
13383 - + (eh->e_phoff-ph->p_offset));
13384 - dso->phnum = eh->e_phnum;
13385 - dso->phentsize = eh->e_phentsize;
13387 - /* Reuse the existing mapping for the lowest-address LOAD */
13388 - if ((ph->p_vaddr & -PAGE_SIZE) == addr_min) continue;
13389 - this_min = ph->p_vaddr & -PAGE_SIZE;
13390 - this_max = ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE;
13391 - off_start = ph->p_offset & -PAGE_SIZE;
13392 - prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) |
13393 - ((ph->p_flags&PF_W) ? PROT_WRITE: 0) |
13394 - ((ph->p_flags&PF_X) ? PROT_EXEC : 0));
13395 - if (mmap_fixed(base+this_min, this_max-this_min, prot, MAP_PRIVATE|MAP_FIXED, fd, off_start) == MAP_FAILED)
13397 - if (ph->p_memsz > ph->p_filesz) {
13398 - size_t brk = (size_t)base+ph->p_vaddr+ph->p_filesz;
13399 - size_t pgbrk = brk+PAGE_SIZE-1 & -PAGE_SIZE;
13400 - memset((void *)brk, 0, pgbrk-brk & PAGE_SIZE-1);
13401 - if (pgbrk-(size_t)base < this_max && mmap_fixed((void *)pgbrk, (size_t)base+this_max-pgbrk, prot, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED)
13405 - for (i=0; ((size_t *)(base+dyn))[i]; i+=2)
13406 - if (((size_t *)(base+dyn))[i]==DT_TEXTREL) {
13407 - if (mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC)
13408 - && errno != ENOSYS)
13413 - dso->base = base;
13414 - dso->dynv = laddr(dso, dyn);
13415 - if (dso->tls_size) dso->tls_image = laddr(dso, tls_image);
13416 - if (!runtime) reclaim_gaps(dso);
13417 - free(allocated_buf);
13422 - if (map!=MAP_FAILED) unmap_library(dso);
13423 - free(allocated_buf);
13427 -static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
13432 - s += strspn(s, ":\n");
13433 - l = strcspn(s, ":\n");
13434 - if (l-1 >= INT_MAX) return -1;
13435 - if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
13436 - if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd;
13441 - case ENAMETOOLONG:
13444 - /* Any negative value but -1 will inhibit
13445 - * futher path search. */
13453 -static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
13456 - const char *s, *t, *origin;
13458 - if (p->rpath || !p->rpath_orig) return 0;
13459 - if (!strchr(p->rpath_orig, '$')) {
13460 - p->rpath = p->rpath_orig;
13464 - s = p->rpath_orig;
13465 - while ((t=strchr(s, '$'))) {
13466 - if (strncmp(t, "$ORIGIN", 7) && strncmp(t, "${ORIGIN}", 9))
13471 - if (n > SSIZE_MAX/PATH_MAX) return 0;
13473 - if (p->kernel_mapped) {
13474 - /* $ORIGIN searches cannot be performed for the main program
13475 - * when it is suid/sgid/AT_SECURE. This is because the
13476 - * pathname is under the control of the caller of execve.
13477 - * For libraries, however, $ORIGIN can be processed safely
13478 - * since the library's pathname came from a trusted source
13479 - * (either system paths or a call to dlopen). */
13482 - l = readlink("/proc/self/exe", buf, buf_size);
13483 - if (l == -1) switch (errno) {
13491 - if (l >= buf_size)
13496 - origin = p->name;
13498 - t = strrchr(origin, '/');
13499 - l = t ? t-origin : 0;
13500 - p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1);
13501 - if (!p->rpath) return -1;
13504 - s = p->rpath_orig;
13505 - while ((t=strchr(s, '$'))) {
13506 - memcpy(d, s, t-s);
13508 - memcpy(d, origin, l);
13510 - /* It was determined previously that the '$' is followed
13511 - * either by "ORIGIN" or "{ORIGIN}". */
13512 - s = t + 7 + 2*(t[1]=='{');
13518 -static void decode_dyn(struct dso *p)
13520 - size_t dyn[DYN_CNT];
13521 - decode_vec(p->dynv, dyn, DYN_CNT);
13522 - p->syms = laddr(p, dyn[DT_SYMTAB]);
13523 - p->strings = laddr(p, dyn[DT_STRTAB]);
13524 - if (dyn[0]&(1<<DT_HASH))
13525 - p->hashtab = laddr(p, dyn[DT_HASH]);
13526 - if (dyn[0]&(1<<DT_RPATH))
13527 - p->rpath_orig = p->strings + dyn[DT_RPATH];
13528 - if (dyn[0]&(1<<DT_RUNPATH))
13529 - p->rpath_orig = p->strings + dyn[DT_RUNPATH];
13530 - if (dyn[0]&(1<<DT_PLTGOT))
13531 - p->got = laddr(p, dyn[DT_PLTGOT]);
13532 - if (search_vec(p->dynv, dyn, DT_GNU_HASH))
13533 - p->ghashtab = laddr(p, *dyn);
13534 - if (search_vec(p->dynv, dyn, DT_VERSYM))
13535 - p->versym = laddr(p, *dyn);
13538 -static size_t count_syms(struct dso *p)
13540 - if (p->hashtab) return p->hashtab[1];
13543 - uint32_t *buckets = p->ghashtab + 4 + (p->ghashtab[2]*sizeof(size_t)/4);
13544 - uint32_t *hashval;
13545 - for (i = nsym = 0; i < p->ghashtab[0]; i++) {
13546 - if (buckets[i] > nsym)
13547 - nsym = buckets[i];
13550 - hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
13552 - while (!(*hashval++ & 1));
13557 -static void *dl_mmap(size_t n)
13560 - int prot = PROT_READ|PROT_WRITE, flags = MAP_ANONYMOUS|MAP_PRIVATE;
13562 - p = (void *)__syscall(SYS_mmap2, 0, n, prot, flags, -1, 0);
13564 - p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
13566 - return p == MAP_FAILED ? 0 : p;
13569 -static void makefuncdescs(struct dso *p)
13571 - static int self_done;
13572 - size_t nsym = count_syms(p);
13573 - size_t i, size = nsym * sizeof(*p->funcdescs);
13575 - if (!self_done) {
13576 - p->funcdescs = dl_mmap(size);
13579 - p->funcdescs = malloc(size);
13581 - if (!p->funcdescs) {
13582 - if (!runtime) a_crash();
13583 - error("Error allocating function descriptors for %s", p->name);
13584 - longjmp(*rtld_fail, 1);
13586 - for (i=0; i<nsym; i++) {
13587 - if ((p->syms[i].st_info&0xf)==STT_FUNC && p->syms[i].st_shndx) {
13588 - p->funcdescs[i].addr = laddr(p, p->syms[i].st_value);
13589 - p->funcdescs[i].got = p->got;
13591 - p->funcdescs[i].addr = 0;
13592 - p->funcdescs[i].got = 0;
13597 -static struct dso *load_library(const char *name, struct dso *needed_by)
13599 - char buf[2*NAME_MAX+2];
13600 - const char *pathname;
13601 - unsigned char *map;
13602 - struct dso *p, temp_dso = {0};
13605 - size_t alloc_size;
13614 - /* Catch and block attempts to reload the implementation itself */
13615 - if (name[0]=='l' && name[1]=='i' && name[2]=='b') {
13616 - static const char *rp, reserved[] =
13617 - "c\0pthread\0rt\0m\0dl\0util\0xnet\0";
13618 - char *z = strchr(name, '.');
13620 - size_t l = z-name;
13621 - for (rp=reserved; *rp && strncmp(name+3, rp, l-3); rp+=strlen(rp)+1);
13624 - /* Track which names have been resolved
13625 - * and only report each one once. */
13626 - static unsigned reported;
13627 - unsigned mask = 1U<<(rp-reserved);
13628 - if (!(reported & mask)) {
13629 - reported |= mask;
13630 - dprintf(1, "\t%s => %s (%p)\n",
13639 - if (!strcmp(name, ldso.name)) is_self = 1;
13641 - if (!ldso.prev) {
13642 - tail->next = &ldso;
13643 - ldso.prev = tail;
13644 - tail = ldso.next ? ldso.next : &ldso;
13648 - if (strchr(name, '/')) {
13650 - fd = open(name, O_RDONLY|O_CLOEXEC);
13652 - /* Search for the name to see if it's already loaded */
13653 - for (p=head->next; p; p=p->next) {
13654 - if (p->shortname && !strcmp(p->shortname, name)) {
13659 - if (strlen(name) > NAME_MAX) return 0;
13661 - if (env_path) fd = path_open(name, env_path, buf, sizeof buf);
13662 - for (p=needed_by; fd == -1 && p; p=p->needed_by) {
13663 - if (fixup_rpath(p, buf, sizeof buf) < 0)
13664 - fd = -2; /* Inhibit further search. */
13666 - fd = path_open(name, p->rpath, buf, sizeof buf);
13670 - char *prefix = 0;
13671 - size_t prefix_len;
13672 - if (ldso.name[0]=='/') {
13674 - for (s=t=z=ldso.name; *s; s++)
13675 - if (*s=='/') z=t, t=s;
13676 - prefix_len = z-ldso.name;
13677 - if (prefix_len < PATH_MAX)
13678 - prefix = ldso.name;
13684 - char etc_ldso_path[prefix_len + 1
13685 - + sizeof "/etc/ld-musl-" LDSO_ARCH ".path"];
13686 - snprintf(etc_ldso_path, sizeof etc_ldso_path,
13687 - "%.*s/etc/ld-musl-" LDSO_ARCH ".path",
13688 - (int)prefix_len, prefix);
13689 - FILE *f = fopen(etc_ldso_path, "rbe");
13691 - if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
13696 - } else if (errno != ENOENT) {
13700 - if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
13701 - fd = path_open(name, sys_path, buf, sizeof buf);
13705 - if (fd < 0) return 0;
13706 - if (fstat(fd, &st) < 0) {
13710 - for (p=head->next; p; p=p->next) {
13711 - if (p->dev == st.st_dev && p->ino == st.st_ino) {
13712 - /* If this library was previously loaded with a
13713 - * pathname but a search found the same inode,
13714 - * setup its shortname so it can be found by name. */
13715 - if (!p->shortname && pathname != name)
13716 - p->shortname = strrchr(p->name, '/')+1;
13722 - map = noload ? 0 : map_library(fd, &temp_dso);
13724 - if (!map) return 0;
13726 - /* Allocate storage for the new DSO. When there is TLS, this
13727 - * storage must include a reservation for all pre-existing
13728 - * threads to obtain copies of both the new TLS, and an
13729 - * extended DTV capable of storing an additional slot for
13730 - * the newly-loaded DSO. */
13731 - alloc_size = sizeof *p + strlen(pathname) + 1;
13732 - if (runtime && temp_dso.tls_image) {
13733 - size_t per_th = temp_dso.tls_size + temp_dso.tls_align
13734 - + sizeof(void *) * (tls_cnt+3);
13735 - n_th = libc.threads_minus_1 + 1;
13736 - if (n_th > SSIZE_MAX / per_th) alloc_size = SIZE_MAX;
13737 - else alloc_size += n_th * per_th;
13739 - p = calloc(1, alloc_size);
13741 - unmap_library(&temp_dso);
13744 - memcpy(p, &temp_dso, sizeof temp_dso);
13746 - p->dev = st.st_dev;
13747 - p->ino = st.st_ino;
13749 - p->needed_by = needed_by;
13750 - p->name = p->buf;
13751 - strcpy(p->name, pathname);
13752 - /* Add a shortname only if name arg was not an explicit pathname. */
13753 - if (pathname != name) p->shortname = strrchr(p->name, '/')+1;
13754 - if (p->tls_image) {
13755 - p->tls_id = ++tls_cnt;
13756 - tls_align = MAXP2(tls_align, p->tls_align);
13757 -#ifdef TLS_ABOVE_TP
13758 - p->tls_offset = tls_offset + ( (tls_align-1) &
13759 - -(tls_offset + (uintptr_t)p->tls_image) );
13760 - tls_offset += p->tls_size;
13762 - tls_offset += p->tls_size + p->tls_align - 1;
13763 - tls_offset -= (tls_offset + (uintptr_t)p->tls_image)
13764 - & (p->tls_align-1);
13765 - p->tls_offset = tls_offset;
13767 - p->new_dtv = (void *)(-sizeof(size_t) &
13768 - (uintptr_t)(p->name+strlen(p->name)+sizeof(size_t)));
13769 - p->new_tls = (void *)(p->new_dtv + n_th*(tls_cnt+1));
13776 - if (DL_FDPIC) makefuncdescs(p);
13778 - if (ldd_mode) dprintf(1, "\t%s => %s (%p)\n", name, pathname, p->base);
13783 -static void load_deps(struct dso *p)
13785 - size_t i, ndeps=0;
13786 - struct dso ***deps = &p->deps, **tmp, *dep;
13787 - for (; p; p=p->next) {
13788 - for (i=0; p->dynv[i]; i+=2) {
13789 - if (p->dynv[i] != DT_NEEDED) continue;
13790 - dep = load_library(p->strings + p->dynv[i+1], p);
13792 - error("Error loading shared library %s: %m (needed by %s)",
13793 - p->strings + p->dynv[i+1], p->name);
13794 - if (runtime) longjmp(*rtld_fail, 1);
13798 - tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2));
13799 - if (!tmp) longjmp(*rtld_fail, 1);
13800 - tmp[ndeps++] = dep;
13808 -static void load_preload(char *s)
13812 - for (z=s; *z; s=z) {
13813 - for ( ; *s && (isspace(*s) || *s==':'); s++);
13814 - for (z=s; *z && !isspace(*z) && *z!=':'; z++);
13817 - load_library(s, 0);
13822 -static void make_global(struct dso *p)
13824 - for (; p; p=p->next) p->global = 1;
13827 -static void do_mips_relocs(struct dso *p, size_t *got)
13829 - size_t i, j, rel[2];
13830 - unsigned char *base = p->base;
13831 - i=0; search_vec(p->dynv, &i, DT_MIPS_LOCAL_GOTNO);
13835 - while (i--) *got++ += (size_t)base;
13837 - j=0; search_vec(p->dynv, &j, DT_MIPS_GOTSYM);
13838 - i=0; search_vec(p->dynv, &i, DT_MIPS_SYMTABNO);
13839 - Sym *sym = p->syms + j;
13840 - rel[0] = (unsigned char *)got - base;
13841 - for (i-=j; i; i--, sym++, rel[0]+=sizeof(size_t)) {
13842 - rel[1] = sym-p->syms << 8 | R_MIPS_JUMP_SLOT;
13843 - do_relocs(p, rel, sizeof rel, 2);
13847 -static void reloc_all(struct dso *p)
13849 - size_t dyn[DYN_CNT];
13850 - for (; p; p=p->next) {
13851 - if (p->relocated) continue;
13852 - decode_vec(p->dynv, dyn, DYN_CNT);
13853 - if (NEED_MIPS_GOT_RELOCS)
13854 - do_mips_relocs(p, laddr(p, dyn[DT_PLTGOT]));
13855 - do_relocs(p, laddr(p, dyn[DT_JMPREL]), dyn[DT_PLTRELSZ],
13856 - 2+(dyn[DT_PLTREL]==DT_RELA));
13857 - do_relocs(p, laddr(p, dyn[DT_REL]), dyn[DT_RELSZ], 2);
13858 - do_relocs(p, laddr(p, dyn[DT_RELA]), dyn[DT_RELASZ], 3);
13860 - if (head != &ldso && p->relro_start != p->relro_end &&
13861 - mprotect(laddr(p, p->relro_start), p->relro_end-p->relro_start, PROT_READ)
13862 - && errno != ENOSYS) {
13863 - error("Error relocating %s: RELRO protection failed: %m",
13865 - if (runtime) longjmp(*rtld_fail, 1);
13868 - p->relocated = 1;
13872 -static void kernel_mapped_dso(struct dso *p)
13874 - size_t min_addr = -1, max_addr = 0, cnt;
13875 - Phdr *ph = p->phdr;
13876 - for (cnt = p->phnum; cnt--; ph = (void *)((char *)ph + p->phentsize)) {
13877 - if (ph->p_type == PT_DYNAMIC) {
13878 - p->dynv = laddr(p, ph->p_vaddr);
13879 - } else if (ph->p_type == PT_GNU_RELRO) {
13880 - p->relro_start = ph->p_vaddr & -PAGE_SIZE;
13881 - p->relro_end = (ph->p_vaddr + ph->p_memsz) & -PAGE_SIZE;
13883 - if (ph->p_type != PT_LOAD) continue;
13884 - if (ph->p_vaddr < min_addr)
13885 - min_addr = ph->p_vaddr;
13886 - if (ph->p_vaddr+ph->p_memsz > max_addr)
13887 - max_addr = ph->p_vaddr+ph->p_memsz;
13889 - min_addr &= -PAGE_SIZE;
13890 - max_addr = (max_addr + PAGE_SIZE-1) & -PAGE_SIZE;
13891 - p->map = p->base + min_addr;
13892 - p->map_len = max_addr - min_addr;
13893 - p->kernel_mapped = 1;
13896 -static void do_fini()
13899 - size_t dyn[DYN_CNT];
13900 - for (p=fini_head; p; p=p->fini_next) {
13901 - if (!p->constructed) continue;
13902 - decode_vec(p->dynv, dyn, DYN_CNT);
13903 - if (dyn[0] & (1<<DT_FINI_ARRAY)) {
13904 - size_t n = dyn[DT_FINI_ARRAYSZ]/sizeof(size_t);
13905 - size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY])+n;
13906 - while (n--) ((void (*)(void))*--fn)();
13908 -#ifndef NO_LEGACY_INITFINI
13909 - if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
13910 - fpaddr(p, dyn[DT_FINI])();
13915 -static void do_init_fini(struct dso *p)
13917 - size_t dyn[DYN_CNT];
13918 - int need_locking = libc.threads_minus_1;
13919 - /* Allow recursive calls that arise when a library calls
13920 - * dlopen from one of its constructors, but block any
13921 - * other threads until all ctors have finished. */
13922 - if (need_locking) pthread_mutex_lock(&init_fini_lock);
13923 - for (; p; p=p->prev) {
13924 - if (p->constructed) continue;
13925 - p->constructed = 1;
13926 - decode_vec(p->dynv, dyn, DYN_CNT);
13927 - if (dyn[0] & ((1<<DT_FINI) | (1<<DT_FINI_ARRAY))) {
13928 - p->fini_next = fini_head;
13931 -#ifndef NO_LEGACY_INITFINI
13932 - if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
13933 - fpaddr(p, dyn[DT_INIT])();
13935 - if (dyn[0] & (1<<DT_INIT_ARRAY)) {
13936 - size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t);
13937 - size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]);
13938 - while (n--) ((void (*)(void))*fn++)();
13940 - if (!need_locking && libc.threads_minus_1) {
13941 - need_locking = 1;
13942 - pthread_mutex_lock(&init_fini_lock);
13945 - if (need_locking) pthread_mutex_unlock(&init_fini_lock);
13948 -void __libc_start_init(void)
13950 - do_init_fini(tail);
13953 -static void dl_debug_state(void)
13957 -weak_alias(dl_debug_state, _dl_debug_state);
13959 -void __reset_tls()
13961 - pthread_t self = __pthread_self();
13963 - for (p=head; p; p=p->next) {
13964 - if (!p->tls_id || !self->dtv[p->tls_id]) continue;
13965 - memcpy(self->dtv[p->tls_id], p->tls_image, p->tls_len);
13966 - memset((char *)self->dtv[p->tls_id]+p->tls_len, 0,
13967 - p->tls_size - p->tls_len);
13968 - if (p->tls_id == (size_t)self->dtv[0]) break;
13972 -void *__copy_tls(unsigned char *mem)
13978 -#ifdef TLS_ABOVE_TP
13979 - dtv = (void **)(mem + libc.tls_size) - (tls_cnt + 1);
13981 - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (tls_align-1);
13982 - td = (pthread_t)mem;
13983 - mem += sizeof(struct pthread);
13985 - for (p=head; p; p=p->next) {
13986 - if (!p->tls_id) continue;
13987 - dtv[p->tls_id] = mem + p->tls_offset;
13988 - memcpy(dtv[p->tls_id], p->tls_image, p->tls_len);
13991 - dtv = (void **)mem;
13993 - mem += libc.tls_size - sizeof(struct pthread);
13994 - mem -= (uintptr_t)mem & (tls_align-1);
13995 - td = (pthread_t)mem;
13997 - for (p=head; p; p=p->next) {
13998 - if (!p->tls_id) continue;
13999 - dtv[p->tls_id] = mem - p->tls_offset;
14000 - memcpy(dtv[p->tls_id], p->tls_image, p->tls_len);
14003 - dtv[0] = (void *)tls_cnt;
14004 - td->dtv = td->dtv_copy = dtv;
14008 -__attribute__((__visibility__("hidden")))
14009 -void *__tls_get_new(size_t *v)
14011 - pthread_t self = __pthread_self();
14013 - /* Block signals to make accessing new TLS async-signal-safe */
14015 - __block_all_sigs(&set);
14016 - if (v[0]<=(size_t)self->dtv[0]) {
14017 - __restore_sigs(&set);
14018 - return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET;
14021 - /* This is safe without any locks held because, if the caller
14022 - * is able to request the Nth entry of the DTV, the DSO list
14023 - * must be valid at least that far out and it was synchronized
14024 - * at program startup or by an already-completed call to dlopen. */
14026 - for (p=head; p->tls_id != v[0]; p=p->next);
14028 - /* Get new DTV space from new DSO if needed */
14029 - if (v[0] > (size_t)self->dtv[0]) {
14030 - void **newdtv = p->new_dtv +
14031 - (v[0]+1)*sizeof(void *)*a_fetch_add(&p->new_dtv_idx,1);
14032 - memcpy(newdtv, self->dtv,
14033 - ((size_t)self->dtv[0]+1) * sizeof(void *));
14034 - newdtv[0] = (void *)v[0];
14035 - self->dtv = self->dtv_copy = newdtv;
14038 - /* Get new TLS memory from all new DSOs up to the requested one */
14039 - unsigned char *mem;
14040 - for (p=head; ; p=p->next) {
14041 - if (!p->tls_id || self->dtv[p->tls_id]) continue;
14042 - mem = p->new_tls + (p->tls_size + p->tls_align)
14043 - * a_fetch_add(&p->new_tls_idx,1);
14044 - mem += ((uintptr_t)p->tls_image - (uintptr_t)mem)
14045 - & (p->tls_align-1);
14046 - self->dtv[p->tls_id] = mem;
14047 - memcpy(mem, p->tls_image, p->tls_len);
14048 - if (p->tls_id == v[0]) break;
14050 - __restore_sigs(&set);
14051 - return mem + v[1] + DTP_OFFSET;
14054 -static void update_tls_size()
14056 - libc.tls_size = ALIGN(
14057 - (1+tls_cnt) * sizeof(void *) +
14059 - sizeof(struct pthread) +
14064 -/* Stage 1 of the dynamic linker is defined in dlstart.c. It calls the
14065 - * following stage 2 and stage 3 functions via primitive symbolic lookup
14066 - * since it does not have access to their addresses to begin with. */
14068 -/* Stage 2 of the dynamic linker is called after relative relocations
14069 - * have been processed. It can make function calls to static functions
14070 - * and access string literals and static data, but cannot use extern
14071 - * symbols. Its job is to perform symbolic relocations on the dynamic
14072 - * linker itself, but some of the relocations performed may need to be
14073 - * replaced later due to copy relocations in the main program. */
14075 -__attribute__((__visibility__("hidden")))
14076 -void __dls2(unsigned char *base, size_t *sp)
14079 - void *p1 = (void *)sp[-2];
14080 - void *p2 = (void *)sp[-1];
14082 - size_t *auxv, aux[AUX_CNT];
14083 - for (auxv=sp+1+*sp+1; *auxv; auxv++); auxv++;
14084 - decode_vec(auxv, aux, AUX_CNT);
14085 - if (aux[AT_BASE]) ldso.base = (void *)aux[AT_BASE];
14086 - else ldso.base = (void *)(aux[AT_PHDR] & -4096);
14088 - app_loadmap = p2 ? p1 : 0;
14089 - ldso.loadmap = p2 ? p2 : p1;
14090 - ldso.base = laddr(&ldso, 0);
14092 - ldso.base = base;
14094 - Ehdr *ehdr = (void *)ldso.base;
14095 - ldso.name = ldso.shortname = "libc.so";
14097 - ldso.phnum = ehdr->e_phnum;
14098 - ldso.phdr = laddr(&ldso, ehdr->e_phoff);
14099 - ldso.phentsize = ehdr->e_phentsize;
14100 - kernel_mapped_dso(&ldso);
14101 - decode_dyn(&ldso);
14103 - if (DL_FDPIC) makefuncdescs(&ldso);
14105 - /* Prepare storage for to save clobbered REL addends so they
14106 - * can be reused in stage 3. There should be very few. If
14107 - * something goes wrong and there are a huge number, abort
14108 - * instead of risking stack overflow. */
14109 - size_t dyn[DYN_CNT];
14110 - decode_vec(ldso.dynv, dyn, DYN_CNT);
14111 - size_t *rel = laddr(&ldso, dyn[DT_REL]);
14112 - size_t rel_size = dyn[DT_RELSZ];
14113 - size_t symbolic_rel_cnt = 0;
14114 - apply_addends_to = rel;
14115 - for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t))
14116 - if (!IS_RELATIVE(rel[1], ldso.syms)) symbolic_rel_cnt++;
14117 - if (symbolic_rel_cnt >= ADDEND_LIMIT) a_crash();
14118 - size_t addends[symbolic_rel_cnt+1];
14119 - saved_addends = addends;
14122 - reloc_all(&ldso);
14124 - ldso.relocated = 0;
14126 - /* Call dynamic linker stage-3, __dls3, looking it up
14127 - * symbolically as a barrier against moving the address
14128 - * load across the above relocation processing. */
14129 - struct symdef dls3_def = find_sym(&ldso, "__dls3", 0);
14130 - if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls3_def.sym-ldso.syms])(sp);
14131 - else ((stage3_func)laddr(&ldso, dls3_def.sym->st_value))(sp);
14134 -/* Stage 3 of the dynamic linker is called with the dynamic linker/libc
14135 - * fully functional. Its job is to load (if not already loaded) and
14136 - * process dependencies and relocations for the main application and
14137 - * transfer control to its entry point. */
14139 -_Noreturn void __dls3(size_t *sp)
14141 - static struct dso app, vdso;
14142 - size_t aux[AUX_CNT], *auxv;
14144 - char *env_preload=0;
14145 - size_t vdso_base;
14147 - char **argv = (void *)(sp+1);
14148 - char **argv_orig = argv;
14149 - char **envp = argv+argc+1;
14151 - /* Find aux vector just past environ[] and use it to initialize
14152 - * global data that may be needed before we can make syscalls. */
14153 - __environ = envp;
14154 - for (i=argc+1; argv[i]; i++);
14155 - libc.auxv = auxv = (void *)(argv+i+1);
14156 - decode_vec(auxv, aux, AUX_CNT);
14157 - __hwcap = aux[AT_HWCAP];
14158 - libc.page_size = aux[AT_PAGESZ];
14159 - libc.secure = ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID]
14160 - || aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]);
14162 - /* Setup early thread pointer in builtin_tls for ldso/libc itself to
14163 - * use during dynamic linking. If possible it will also serve as the
14164 - * thread pointer at runtime. */
14165 - libc.tls_size = sizeof builtin_tls;
14166 - if (__init_tp(__copy_tls((void *)builtin_tls)) < 0) {
14170 - /* Only trust user/env if kernel says we're not suid/sgid */
14171 - if (!libc.secure) {
14172 - env_path = getenv("LD_LIBRARY_PATH");
14173 - env_preload = getenv("LD_PRELOAD");
14176 - /* If the main program was already loaded by the kernel,
14177 - * AT_PHDR will point to some location other than the dynamic
14178 - * linker's program headers. */
14179 - if (aux[AT_PHDR] != (size_t)ldso.phdr) {
14180 - size_t interp_off = 0;
14181 - size_t tls_image = 0;
14182 - /* Find load address of the main program, via AT_PHDR vs PT_PHDR. */
14183 - Phdr *phdr = app.phdr = (void *)aux[AT_PHDR];
14184 - app.phnum = aux[AT_PHNUM];
14185 - app.phentsize = aux[AT_PHENT];
14186 - for (i=aux[AT_PHNUM]; i; i--, phdr=(void *)((char *)phdr + aux[AT_PHENT])) {
14187 - if (phdr->p_type == PT_PHDR)
14188 - app.base = (void *)(aux[AT_PHDR] - phdr->p_vaddr);
14189 - else if (phdr->p_type == PT_INTERP)
14190 - interp_off = (size_t)phdr->p_vaddr;
14191 - else if (phdr->p_type == PT_TLS) {
14192 - tls_image = phdr->p_vaddr;
14193 - app.tls_len = phdr->p_filesz;
14194 - app.tls_size = phdr->p_memsz;
14195 - app.tls_align = phdr->p_align;
14198 - if (DL_FDPIC) app.loadmap = app_loadmap;
14199 - if (app.tls_size) app.tls_image = laddr(&app, tls_image);
14200 - if (interp_off) ldso.name = laddr(&app, interp_off);
14201 - if ((aux[0] & (1UL<<AT_EXECFN))
14202 - && strncmp((char *)aux[AT_EXECFN], "/proc/", 6))
14203 - app.name = (char *)aux[AT_EXECFN];
14205 - app.name = argv[0];
14206 - kernel_mapped_dso(&app);
14209 - char *ldname = argv[0];
14210 - size_t l = strlen(ldname);
14211 - if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
14213 - while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
14214 - char *opt = argv[0]+2;
14215 - *argv++ = (void *)-1;
14218 - } else if (!memcmp(opt, "list", 5)) {
14220 - } else if (!memcmp(opt, "library-path", 12)) {
14221 - if (opt[12]=='=') env_path = opt+13;
14222 - else if (opt[12]) *argv = 0;
14223 - else if (*argv) env_path = *argv++;
14224 - } else if (!memcmp(opt, "preload", 7)) {
14225 - if (opt[7]=='=') env_preload = opt+8;
14226 - else if (opt[7]) *argv = 0;
14227 - else if (*argv) env_preload = *argv++;
14232 - argv[-1] = (void *)(argc - (argv-argv_orig));
14234 - dprintf(2, "musl libc\n"
14236 - "Dynamic Program Loader\n"
14237 - "Usage: %s [options] [--] pathname%s\n",
14238 - __libc_get_version(), ldname,
14239 - ldd_mode ? "" : " [args]");
14242 - fd = open(argv[0], O_RDONLY);
14244 - dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
14248 - Ehdr *ehdr = (void *)map_library(fd, &app);
14250 - dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
14255 - ldso.name = ldname;
14256 - app.name = argv[0];
14257 - aux[AT_ENTRY] = (size_t)laddr(&app, ehdr->e_entry);
14258 - /* Find the name that would have been used for the dynamic
14259 - * linker had ldd not taken its place. */
14261 - for (i=0; i<app.phnum; i++) {
14262 - if (app.phdr[i].p_type == PT_INTERP)
14263 - ldso.name = laddr(&app, app.phdr[i].p_vaddr);
14265 - dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
14268 - if (app.tls_size) {
14269 - app.tls_id = tls_cnt = 1;
14270 -#ifdef TLS_ABOVE_TP
14271 - app.tls_offset = 0;
14272 - tls_offset = app.tls_size
14273 - + ( -((uintptr_t)app.tls_image + app.tls_size)
14274 - & (app.tls_align-1) );
14276 - tls_offset = app.tls_offset = app.tls_size
14277 - + ( -((uintptr_t)app.tls_image + app.tls_size)
14278 - & (app.tls_align-1) );
14280 - tls_align = MAXP2(tls_align, app.tls_align);
14283 - decode_dyn(&app);
14285 - makefuncdescs(&app);
14286 - if (!app.loadmap) {
14287 - app.loadmap = (void *)&app_dummy_loadmap;
14288 - app.loadmap->nsegs = 1;
14289 - app.loadmap->segs[0].addr = (size_t)app.map;
14290 - app.loadmap->segs[0].p_vaddr = (size_t)app.map
14291 - - (size_t)app.base;
14292 - app.loadmap->segs[0].p_memsz = app.map_len;
14294 - argv[-3] = (void *)app.loadmap;
14297 - /* Attach to vdso, if provided by the kernel */
14298 - if (search_vec(auxv, &vdso_base, AT_SYSINFO_EHDR)) {
14299 - Ehdr *ehdr = (void *)vdso_base;
14300 - Phdr *phdr = vdso.phdr = (void *)(vdso_base + ehdr->e_phoff);
14301 - vdso.phnum = ehdr->e_phnum;
14302 - vdso.phentsize = ehdr->e_phentsize;
14303 - for (i=ehdr->e_phnum; i; i--, phdr=(void *)((char *)phdr + ehdr->e_phentsize)) {
14304 - if (phdr->p_type == PT_DYNAMIC)
14305 - vdso.dynv = (void *)(vdso_base + phdr->p_offset);
14306 - if (phdr->p_type == PT_LOAD)
14307 - vdso.base = (void *)(vdso_base - phdr->p_vaddr + phdr->p_offset);
14310 - vdso.shortname = "linux-gate.so.1";
14312 - vdso.relocated = 1;
14313 - decode_dyn(&vdso);
14314 - vdso.prev = &ldso;
14315 - ldso.next = &vdso;
14318 - /* Initial dso chain consists only of the app. */
14319 - head = tail = &app;
14321 - /* Donate unused parts of app and library mapping to malloc */
14322 - reclaim_gaps(&app);
14323 - reclaim_gaps(&ldso);
14325 - /* Load preload/needed libraries, add their symbols to the global
14326 - * namespace, and perform all remaining relocations. */
14327 - if (env_preload) load_preload(env_preload);
14329 - make_global(&app);
14331 -#ifndef DYNAMIC_IS_RO
14332 - for (i=0; app.dynv[i]; i+=2)
14333 - if (app.dynv[i]==DT_DEBUG)
14334 - app.dynv[i+1] = (size_t)&debug;
14337 - /* The main program must be relocated LAST since it may contin
14338 - * copy relocations which depend on libraries' relocations. */
14339 - reloc_all(app.next);
14342 - update_tls_size();
14343 - if (libc.tls_size > sizeof builtin_tls || tls_align > MIN_TLS_ALIGN) {
14344 - void *initial_tls = calloc(libc.tls_size, 1);
14345 - if (!initial_tls) {
14346 - dprintf(2, "%s: Error getting %zu bytes thread-local storage: %m\n",
14347 - argv[0], libc.tls_size);
14350 - if (__init_tp(__copy_tls(initial_tls)) < 0) {
14354 - size_t tmp_tls_size = libc.tls_size;
14355 - pthread_t self = __pthread_self();
14356 - /* Temporarily set the tls size to the full size of
14357 - * builtin_tls so that __copy_tls will use the same layout
14358 - * as it did for before. Then check, just to be safe. */
14359 - libc.tls_size = sizeof builtin_tls;
14360 - if (__copy_tls((void*)builtin_tls) != self) a_crash();
14361 - libc.tls_size = tmp_tls_size;
14363 - static_tls_cnt = tls_cnt;
14365 - if (ldso_fail) _exit(127);
14366 - if (ldd_mode) _exit(0);
14368 - /* Switch to runtime mode: any further failures in the dynamic
14369 - * linker are a reportable failure rather than a fatal startup
14374 - debug.bp = dl_debug_state;
14375 - debug.head = head;
14376 - debug.base = ldso.base;
14378 - _dl_debug_state();
14380 - __init_libc(envp, argv[0]);
14384 - CRTJMP((void *)aux[AT_ENTRY], argv-1);
14388 -void *dlopen(const char *file, int mode)
14390 - struct dso *volatile p, *orig_tail, *next;
14391 - size_t orig_tls_cnt, orig_tls_offset, orig_tls_align;
14396 - if (!file) return head;
14398 - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
14399 - pthread_rwlock_wrlock(&lock);
14403 - orig_tls_cnt = tls_cnt;
14404 - orig_tls_offset = tls_offset;
14405 - orig_tls_align = tls_align;
14406 - orig_tail = tail;
14407 - noload = mode & RTLD_NOLOAD;
14410 - if (setjmp(*rtld_fail)) {
14411 - /* Clean up anything new that was (partially) loaded */
14412 - if (p && p->deps) for (i=0; p->deps[i]; i++)
14413 - if (p->deps[i]->global < 0)
14414 - p->deps[i]->global = 0;
14415 - for (p=orig_tail->next; p; p=next) {
14417 - while (p->td_index) {
14418 - void *tmp = p->td_index->next;
14419 - free(p->td_index);
14420 - p->td_index = tmp;
14422 - free(p->funcdescs);
14423 - if (p->rpath != p->rpath_orig)
14426 - unmap_library(p);
14429 - tls_cnt = orig_tls_cnt;
14430 - tls_offset = orig_tls_offset;
14431 - tls_align = orig_tls_align;
14432 - tail = orig_tail;
14436 - } else p = load_library(file, head);
14440 - "Library %s is not already loaded" :
14441 - "Error loading shared library %s: %m",
14446 - /* First load handling */
14449 - if (p->deps) for (i=0; p->deps[i]; i++)
14450 - if (!p->deps[i]->global)
14451 - p->deps[i]->global = -1;
14452 - if (!p->global) p->global = -1;
14454 - if (p->deps) for (i=0; p->deps[i]; i++)
14455 - if (p->deps[i]->global < 0)
14456 - p->deps[i]->global = 0;
14457 - if (p->global < 0) p->global = 0;
14460 - if (mode & RTLD_GLOBAL) {
14461 - if (p->deps) for (i=0; p->deps[i]; i++)
14462 - p->deps[i]->global = 1;
14466 - update_tls_size();
14467 - _dl_debug_state();
14468 - orig_tail = tail;
14472 - pthread_rwlock_unlock(&lock);
14473 - if (p) do_init_fini(orig_tail);
14474 - pthread_setcancelstate(cs, 0);
14478 -static int invalid_dso_handle(void *h)
14481 - for (p=head; p; p=p->next) if (h==p) return 0;
14482 - error("Invalid library handle %p", (void *)h);
14486 -static void *addr2dso(size_t a)
14490 - if (DL_FDPIC) for (p=head; p; p=p->next) {
14491 - i = count_syms(p);
14492 - if (a-(size_t)p->funcdescs < i*sizeof(*p->funcdescs))
14495 - for (p=head; p; p=p->next) {
14496 - if (DL_FDPIC && p->loadmap) {
14497 - for (i=0; i<p->loadmap->nsegs; i++) {
14498 - if (a-p->loadmap->segs[i].p_vaddr
14499 - < p->loadmap->segs[i].p_memsz)
14503 - if (a-(size_t)p->map < p->map_len)
14510 -void *__tls_get_addr(size_t *);
14512 -static void *do_dlsym(struct dso *p, const char *s, void *ra)
14515 - uint32_t h = 0, gh = 0, *ght;
14517 - if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) {
14518 - if (p == RTLD_DEFAULT) {
14520 - } else if (p == RTLD_NEXT) {
14521 - p = addr2dso((size_t)ra);
14525 - struct symdef def = find_sym(p, s, 0);
14526 - if (!def.sym) goto failed;
14527 - if ((def.sym->st_info&0xf) == STT_TLS)
14528 - return __tls_get_addr((size_t []){def.dso->tls_id, def.sym->st_value});
14529 - if (DL_FDPIC && (def.sym->st_info&0xf) == STT_FUNC)
14530 - return def.dso->funcdescs + (def.sym - def.dso->syms);
14531 - return laddr(def.dso, def.sym->st_value);
14533 - if (invalid_dso_handle(p))
14535 - if ((ght = p->ghashtab)) {
14536 - gh = gnu_hash(s);
14537 - sym = gnu_lookup(gh, ght, p, s);
14539 - h = sysv_hash(s);
14540 - sym = sysv_lookup(s, h, p);
14542 - if (sym && (sym->st_info&0xf) == STT_TLS)
14543 - return __tls_get_addr((size_t []){p->tls_id, sym->st_value});
14544 - if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
14545 - return p->funcdescs + (sym - p->syms);
14546 - if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
14547 - return laddr(p, sym->st_value);
14548 - if (p->deps) for (i=0; p->deps[i]; i++) {
14549 - if ((ght = p->deps[i]->ghashtab)) {
14550 - if (!gh) gh = gnu_hash(s);
14551 - sym = gnu_lookup(gh, ght, p->deps[i], s);
14553 - if (!h) h = sysv_hash(s);
14554 - sym = sysv_lookup(s, h, p->deps[i]);
14556 - if (sym && (sym->st_info&0xf) == STT_TLS)
14557 - return __tls_get_addr((size_t []){p->deps[i]->tls_id, sym->st_value});
14558 - if (DL_FDPIC && sym && sym->st_shndx && (sym->st_info&0xf) == STT_FUNC)
14559 - return p->deps[i]->funcdescs + (sym - p->deps[i]->syms);
14560 - if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))
14561 - return laddr(p->deps[i], sym->st_value);
14564 - error("Symbol not found: %s", s);
14568 -int __dladdr(const void *addr, Dl_info *info)
14571 - Sym *sym, *bestsym;
14576 - pthread_rwlock_rdlock(&lock);
14577 - p = addr2dso((size_t)addr);
14578 - pthread_rwlock_unlock(&lock);
14580 - if (!p) return 0;
14583 - strings = p->strings;
14584 - nsym = count_syms(p);
14587 - size_t idx = ((size_t)addr-(size_t)p->funcdescs)
14588 - / sizeof(*p->funcdescs);
14589 - if (idx < nsym && (sym[idx].st_info&0xf) == STT_FUNC) {
14590 - best = p->funcdescs + idx;
14591 - bestsym = sym + idx;
14595 - if (!best) for (; nsym; nsym--, sym++) {
14596 - if (sym->st_value
14597 - && (1<<(sym->st_info&0xf) & OK_TYPES)
14598 - && (1<<(sym->st_info>>4) & OK_BINDS)) {
14599 - void *symaddr = laddr(p, sym->st_value);
14600 - if (symaddr > addr || symaddr < best)
14604 - if (addr == symaddr)
14609 - if (!best) return 0;
14611 - if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
14612 - best = p->funcdescs + (bestsym - p->syms);
14614 - info->dli_fname = p->name;
14615 - info->dli_fbase = p->base;
14616 - info->dli_sname = strings + bestsym->st_name;
14617 - info->dli_saddr = best;
14622 -__attribute__((__visibility__("hidden")))
14623 -void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
14626 - pthread_rwlock_rdlock(&lock);
14627 - res = do_dlsym(p, s, ra);
14628 - pthread_rwlock_unlock(&lock);
14632 -int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
14634 - struct dso *current;
14635 - struct dl_phdr_info info;
14637 - for(current = head; current;) {
14638 - info.dlpi_addr = (uintptr_t)current->base;
14639 - info.dlpi_name = current->name;
14640 - info.dlpi_phdr = current->phdr;
14641 - info.dlpi_phnum = current->phnum;
14642 - info.dlpi_adds = gencnt;
14643 - info.dlpi_subs = 0;
14644 - info.dlpi_tls_modid = current->tls_id;
14645 - info.dlpi_tls_data = current->tls_image;
14647 - ret = (callback)(&info, sizeof (info), data);
14649 - if (ret != 0) break;
14651 - pthread_rwlock_rdlock(&lock);
14652 - current = current->next;
14653 - pthread_rwlock_unlock(&lock);
14658 -static int invalid_dso_handle(void *h)
14660 - error("Invalid library handle %p", (void *)h);
14663 -void *dlopen(const char *file, int mode)
14665 - error("Dynamic loading not supported");
14668 -void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
14670 - error("Symbol not found: %s", s);
14673 -int __dladdr (const void *addr, Dl_info *info)
14679 -int __dlinfo(void *dso, int req, void *res)
14681 - if (invalid_dso_handle(dso)) return -1;
14682 - if (req != RTLD_DI_LINKMAP) {
14683 - error("Unsupported request %d", req);
14686 - *(struct link_map **)res = dso;
14692 - pthread_t self = __pthread_self();
14693 - if (!self->dlerror_flag) return 0;
14694 - self->dlerror_flag = 0;
14695 - char *s = self->dlerror_buf;
14696 - if (s == (void *)-1)
14697 - return "Dynamic linker failed to allocate memory for error message";
14702 -int dlclose(void *p)
14704 - return invalid_dso_handle(p);
14707 -void __dl_thread_cleanup(void)
14709 - pthread_t self = __pthread_self();
14710 - if (self->dlerror_buf != (void *)-1)
14711 - free(self->dlerror_buf);
14714 -static void error(const char *fmt, ...)
14717 - va_start(ap, fmt);
14720 - vdprintf(2, fmt, ap);
14721 - dprintf(2, "\n");
14727 - pthread_t self = __pthread_self();
14728 - if (self->dlerror_buf != (void *)-1)
14729 - free(self->dlerror_buf);
14730 - size_t len = vsnprintf(0, 0, fmt, ap);
14732 - char *buf = malloc(len+1);
14734 - va_start(ap, fmt);
14735 - vsnprintf(buf, len+1, fmt, ap);
14738 - buf = (void *)-1;
14740 - self->dlerror_buf = buf;
14741 - self->dlerror_flag = 1;
14743 --- a/src/ldso/tlsdesc.c
14744 +++ b/src/ldso/tlsdesc.c
14748 #include <stddef.h>
14751 @@ -12,5 +10,3 @@ ptrdiff_t __tlsdesc_static()
14754 weak_alias(__tlsdesc_static, __tlsdesc_dynamic);
14757 --- a/src/legacy/utmpx.c
14758 +++ b/src/legacy/utmpx.c
14761 #include <stddef.h>
14762 +#include <errno.h>
14765 void endutxent(void)
14766 @@ -34,6 +35,12 @@ void updwtmpx(const char *f, const struc
14770 +int __utmpxname(const char *f)
14776 weak_alias(endutxent, endutent);
14777 weak_alias(setutxent, setutent);
14778 weak_alias(getutxent, getutent);
14779 @@ -41,3 +48,5 @@ weak_alias(getutxid, getutid);
14780 weak_alias(getutxline, getutline);
14781 weak_alias(pututxline, pututline);
14782 weak_alias(updwtmpx, updwtmp);
14783 +weak_alias(__utmpxname, utmpname);
14784 +weak_alias(__utmpxname, utmpxname);
14786 +++ b/src/linux/x32/sysinfo.c
14788 +#include <sys/sysinfo.h>
14789 +#include "syscall.h"
14792 +#define klong long long
14793 +#define kulong unsigned long long
14795 +struct kernel_sysinfo {
14800 + kulong sharedram;
14801 + kulong bufferram;
14802 + kulong totalswap;
14806 + kulong totalhigh;
14808 + unsigned mem_unit;
14811 +int __lsysinfo(struct sysinfo *info)
14813 + struct kernel_sysinfo tmp;
14814 + int ret = syscall(SYS_sysinfo, &tmp);
14815 + if(ret == -1) return ret;
14816 + info->uptime = tmp.uptime;
14817 + info->loads[0] = tmp.loads[0];
14818 + info->loads[1] = tmp.loads[1];
14819 + info->loads[2] = tmp.loads[2];
14821 + kulong max = tmp.totalram | tmp.totalswap;
14822 + __asm__("bsr %1,%0" : "=r"(shifts) : "r"(max));
14823 + shifts = shifts >= 32 ? shifts - 31 : 0;
14824 + info->totalram = tmp.totalram >> shifts;
14825 + info->freeram = tmp.freeram >> shifts;
14826 + info->sharedram = tmp.sharedram >> shifts;
14827 + info->bufferram = tmp.bufferram >> shifts;
14828 + info->totalswap = tmp.totalswap >> shifts;
14829 + info->freeswap = tmp.freeswap >> shifts;
14830 + info->procs = tmp.procs ;
14831 + info->totalhigh = tmp.totalhigh >> shifts;
14832 + info->freehigh = tmp.freehigh >> shifts;
14833 + info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts;
14837 +weak_alias(__lsysinfo, sysinfo);
14838 --- a/src/linux/x32/sysinfo.s
14841 -# see arch/x32/src/sysinfo.c
14842 --- a/src/locale/langinfo.c
14843 +++ b/src/locale/langinfo.c
14844 @@ -37,23 +37,23 @@ char *__nl_langinfo_l(nl_item item, loca
14848 - if (idx > 1) return NULL;
14849 + if (idx > 1) return "";
14853 - if (idx > 0x31) return NULL;
14854 + if (idx > 0x31) return "";
14858 - if (idx > 0) return NULL;
14859 + if (idx > 0) return "";
14863 - if (idx > 3) return NULL;
14864 + if (idx > 3) return "";
14872 for (; idx; idx--, str++) for (; *str; str++);
14873 --- a/src/malloc/lite_malloc.c
14874 +++ b/src/malloc/lite_malloc.c
14877 void *__expand_heap(size_t *);
14879 -void *__simple_malloc(size_t n)
14880 +static void *__simple_malloc(size_t n)
14882 static char *cur, *end;
14883 static volatile int lock[2];
14884 --- a/src/math/__rem_pio2.c
14885 +++ b/src/math/__rem_pio2.c
14886 @@ -118,7 +118,7 @@ int __rem_pio2(double x, double *y)
14887 if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
14889 /* rint(x/(pi/2)), Assume round-to-nearest. */
14890 - fn = x*invpio2 + toint - toint;
14891 + fn = (double_t)x*invpio2 + toint - toint;
14894 w = fn*pio2_1t; /* 1st round, good to 85 bits */
14895 --- a/src/math/__rem_pio2f.c
14896 +++ b/src/math/__rem_pio2f.c
14897 @@ -51,7 +51,7 @@ int __rem_pio2f(float x, double *y)
14898 /* 25+53 bit pi is good enough for medium size */
14899 if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */
14900 /* Use a specialized rint() to get fn. Assume round-to-nearest. */
14901 - fn = x*invpio2 + toint - toint;
14902 + fn = (double_t)x*invpio2 + toint - toint;
14904 *y = x - fn*pio2_1 - fn*pio2_1t;
14907 +++ b/src/math/arm/fabs.c
14913 +double fabs(double x)
14915 + __asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x));
14921 +#include "../fabs.c"
14925 +++ b/src/math/arm/fabsf.c
14931 +float fabsf(float x)
14933 + __asm__ ("vabs.f32 %0, %1" : "=t"(x) : "t"(x));
14939 +#include "../fabsf.c"
14943 +++ b/src/math/arm/sqrt.c
14947 +#if __VFP_FP__ && !__SOFTFP__
14949 +double sqrt(double x)
14951 + __asm__ ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x));
14957 +#include "../sqrt.c"
14961 +++ b/src/math/arm/sqrtf.c
14965 +#if __VFP_FP__ && !__SOFTFP__
14967 +float sqrtf(float x)
14969 + __asm__ ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x));
14975 +#include "../sqrtf.c"
14978 --- a/src/math/armebhf/fabs.sub
14982 --- a/src/math/armebhf/fabsf.sub
14986 --- a/src/math/armebhf/sqrt.sub
14990 --- a/src/math/armebhf/sqrtf.sub
14994 --- a/src/math/armhf/fabs.s
15000 -.type fabs,%function
15004 --- a/src/math/armhf/fabs.sub
15008 --- a/src/math/armhf/fabsf.s
15014 -.type fabsf,%function
15018 --- a/src/math/armhf/fabsf.sub
15022 --- a/src/math/armhf/sqrt.s
15028 -.type sqrt,%function
15032 --- a/src/math/armhf/sqrt.sub
15036 --- a/src/math/armhf/sqrtf.s
15042 -.type sqrtf,%function
15046 --- a/src/math/armhf/sqrtf.sub
15050 --- a/src/math/hypot.c
15051 +++ b/src/math/hypot.c
15052 @@ -12,10 +12,10 @@ static void sq(double_t *hi, double_t *l
15054 double_t xh, xl, xc;
15057 + xc = (double_t)x*SPLIT;
15061 + *hi = (double_t)x*x;
15062 *lo = xh*xh - *hi + 2*xh*xl + xl*xl;
15065 --- a/src/mman/mremap.c
15066 +++ b/src/mman/mremap.c
15068 +#define _GNU_SOURCE
15069 #include <unistd.h>
15070 #include <sys/mman.h>
15071 +#include <errno.h>
15072 +#include <stdint.h>
15073 #include <stdarg.h>
15074 #include "syscall.h"
15077 +static void dummy(void) { }
15078 +weak_alias(dummy, __vm_wait);
15080 void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
15085 - va_start(ap, flags);
15086 - new_addr = va_arg(ap, void *);
15088 + void *new_addr = 0;
15090 + if (new_len >= PTRDIFF_MAX) {
15092 + return MAP_FAILED;
15095 + if (flags & MREMAP_FIXED) {
15097 + va_start(ap, flags);
15098 + new_addr = va_arg(ap, void *);
15102 return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
15104 --- a/src/network/getifaddrs.c
15105 +++ b/src/network/getifaddrs.c
15106 @@ -162,13 +162,26 @@ static int netlink_msg_to_ifaddr(void *p
15107 for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) {
15108 switch (rta->rta_type) {
15110 - copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15111 + /* If ifa_addr is already set we, received an IFA_LOCAL before
15112 + * so treat this as destination address */
15113 + if (ifs->ifa.ifa_addr)
15114 + copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15116 + copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15118 case IFA_BROADCAST:
15119 - /* For point-to-point links this is peer, but ifa_broadaddr
15120 - * and ifa_dstaddr are union, so this works for both. */
15121 copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15124 + /* If ifa_addr is set and we get IFA_LOCAL, assume we have
15125 + * a point-to-point network. Move address to correct field. */
15126 + if (ifs->ifa.ifa_addr) {
15127 + ifs->ifu = ifs->addr;
15128 + ifs->ifa.ifa_dstaddr = &ifs->ifu.sa;
15129 + memset(&ifs->addr, 0, sizeof(ifs->addr));
15131 + copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15134 if (RTA_DATALEN(rta) < sizeof(ifs->name)) {
15135 memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta));
15136 --- a/src/network/getnameinfo.c
15137 +++ b/src/network/getnameinfo.c
15138 @@ -135,13 +135,13 @@ int getnameinfo(const struct sockaddr *r
15141 a = (void *)&((struct sockaddr_in *)sa)->sin_addr;
15142 - if (sl != sizeof(struct sockaddr_in)) return EAI_FAMILY;
15143 + if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY;
15148 a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr;
15149 - if (sl != sizeof(struct sockaddr_in6)) return EAI_FAMILY;
15150 + if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY;
15151 if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12))
15154 --- a/src/network/if_nametoindex.c
15155 +++ b/src/network/if_nametoindex.c
15156 @@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name
15160 - if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
15161 + if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
15162 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
15163 r = ioctl(fd, SIOCGIFINDEX, &ifr);
15164 __syscall(SYS_close, fd);
15165 --- a/src/network/lookup.h
15166 +++ b/src/network/lookup.h
15170 #include <stdint.h>
15171 +#include <stddef.h>
15175 @@ -15,6 +16,14 @@ struct service {
15176 unsigned char proto, socktype;
15181 +struct resolvconf {
15182 + struct address ns[MAXNS];
15183 + unsigned nns, attempts, ndots;
15184 + unsigned timeout;
15187 /* The limit of 48 results is a non-sharp bound on the number of addresses
15188 * that can fit in one 512-byte DNS packet full of v4 results and a second
15189 * packet full of v6 results. Due to headers, the actual limit is lower. */
15190 @@ -25,4 +34,6 @@ int __lookup_serv(struct service buf[sta
15191 int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags);
15192 int __lookup_ipliteral(struct address buf[static 1], const char *name, int family);
15194 +int __get_resolv_conf(struct resolvconf *, char *, size_t);
15197 --- a/src/network/lookup_name.c
15198 +++ b/src/network/lookup_name.c
15201 #include <unistd.h>
15202 #include <pthread.h>
15203 +#include <errno.h>
15204 #include "lookup.h"
15205 #include "stdio_impl.h"
15206 #include "syscall.h"
15207 @@ -51,7 +52,14 @@ static int name_from_hosts(struct addres
15209 unsigned char _buf[1032];
15210 FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
15211 - if (!f) return 0;
15212 + if (!f) switch (errno) {
15218 + return EAI_SYSTEM;
15220 while (fgets(line, sizeof line, f) && cnt < MAXADDRS) {
15223 @@ -85,7 +93,7 @@ struct dpc_ctx {
15224 int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *);
15225 int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
15226 int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
15227 -int __res_msend(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int);
15228 +int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *);
15232 @@ -117,7 +125,7 @@ static int dns_parse_callback(void *c, i
15236 -static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
15237 +static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
15239 unsigned char qbuf[2][280], abuf[2][512];
15240 const unsigned char *qp[2] = { qbuf[0], qbuf[1] };
15241 @@ -137,17 +145,59 @@ static int name_from_dns(struct address
15245 - if (__res_msend(nq, qp, qlens, ap, alens, sizeof *abuf) < 0) return EAI_SYSTEM;
15246 + if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0)
15247 + return EAI_SYSTEM;
15249 for (i=0; i<nq; i++)
15250 __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
15252 if (ctx.cnt) return ctx.cnt;
15253 if (alens[0] < 4 || (abuf[0][3] & 15) == 2) return EAI_AGAIN;
15254 - if ((abuf[0][3] & 15) == 3) return EAI_NONAME;
15255 + if ((abuf[0][3] & 15) == 0) return EAI_NONAME;
15256 + if ((abuf[0][3] & 15) == 3) return 0;
15260 +static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
15262 + char search[256];
15263 + struct resolvconf conf;
15267 + if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1;
15269 + /* Count dots, suppress search when >=ndots or name ends in
15270 + * a dot, which is an explicit request for global scope. */
15271 + for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++;
15272 + if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
15274 + /* This can never happen; the caller already checked length. */
15275 + if (l >= 256) return EAI_NONAME;
15277 + /* Name with search domain appended is setup in canon[]. This both
15278 + * provides the desired default canonical name (if the requested
15279 + * name is not a CNAME record) and serves as a buffer for passing
15280 + * the full requested name to name_from_dns. */
15281 + memcpy(canon, name, l);
15284 + for (p=search; *p; p=z) {
15285 + for (; isspace(*p); p++);
15286 + for (z=p; *z && !isspace(*z); z++);
15288 + if (z-p < 256 - l - 1) {
15289 + memcpy(canon+l+1, p, z-p);
15290 + canon[z-p+1+l] = 0;
15291 + int cnt = name_from_dns(buf, canon, canon, family, &conf);
15292 + if (cnt) return cnt;
15297 + return name_from_dns(buf, canon, name, family, &conf);
15300 static const struct policy {
15301 unsigned char addr[16];
15302 unsigned char len, mask;
15303 @@ -248,7 +298,7 @@ int __lookup_name(struct address buf[sta
15304 if (!cnt) cnt = name_from_numeric(buf, name, family);
15305 if (!cnt && !(flags & AI_NUMERICHOST)) {
15306 cnt = name_from_hosts(buf, canon, name, family);
15307 - if (!cnt) cnt = name_from_dns(buf, canon, name, family);
15308 + if (!cnt) cnt = name_from_dns_search(buf, canon, name, family);
15310 if (cnt<=0) return cnt ? cnt : EAI_NONAME;
15312 --- a/src/network/lookup_serv.c
15313 +++ b/src/network/lookup_serv.c
15316 #include <string.h>
15318 +#include <errno.h>
15319 #include "lookup.h"
15320 #include "stdio_impl.h"
15322 @@ -69,7 +70,14 @@ int __lookup_serv(struct service buf[sta
15324 unsigned char _buf[1032];
15325 FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
15326 - if (!f) return EAI_SERVICE;
15327 + if (!f) switch (errno) {
15331 + return EAI_SERVICE;
15333 + return EAI_SYSTEM;
15336 while (fgets(line, sizeof line, f) && cnt < MAXSERVS) {
15337 if ((p=strchr(line, '#'))) *p++='\n', *p=0;
15338 --- a/src/network/proto.c
15339 +++ b/src/network/proto.c
15340 @@ -9,21 +9,36 @@ static const unsigned char protos[] = {
15357 + "\046idpr-cmtp\0"
15378 --- a/src/network/res_msend.c
15379 +++ b/src/network/res_msend.c
15380 @@ -27,18 +27,16 @@ static unsigned long mtime()
15381 + ts.tv_nsec / 1000000;
15384 -int __res_msend(int nqueries, const unsigned char *const *queries,
15385 - const int *qlens, unsigned char *const *answers, int *alens, int asize)
15386 +int __res_msend_rc(int nqueries, const unsigned char *const *queries,
15387 + const int *qlens, unsigned char *const *answers, int *alens, int asize,
15388 + const struct resolvconf *conf)
15392 - unsigned char _buf[256];
15393 - char line[64], *s, *z;
15394 - int timeout = 5000, attempts = 2, retry_interval, servfail_retry;
15395 + int timeout, attempts, retry_interval, servfail_retry;
15397 struct sockaddr_in sin;
15398 struct sockaddr_in6 sin6;
15399 - } sa = {0}, ns[3] = {{0}};
15400 + } sa = {0}, ns[MAXNS] = {{0}};
15401 socklen_t sl = sizeof sa.sin;
15403 int family = AF_INET;
15404 @@ -48,57 +46,27 @@ int __res_msend(int nqueries, const unsi
15407 unsigned long t0, t1, t2;
15408 - struct address iplit;
15410 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
15412 - /* Get nameservers from resolv.conf, fallback to localhost */
15413 - f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
15414 - if (f) for (nns=0; nns<3 && fgets(line, sizeof line, f); ) {
15415 - if (!strncmp(line, "options", 7) && isspace(line[7])) {
15418 - p = strstr(line, "timeout:");
15419 - if (p && isdigit(p[8])) {
15421 - x = strtoul(p, &z, 10);
15422 - if (z != p) timeout = x < 30 ? x*1000 : 30000;
15424 - p = strstr(line, "attempts:");
15425 - if (p && isdigit(p[9])) {
15427 - x = strtoul(p, &z, 10);
15428 - if (z != p) attempts = x < 10 ? x : 10;
15429 - if (!attempts) attempts = 1;
15432 - if (strncmp(line, "nameserver", 10) || !isspace(line[10]))
15434 - for (s=line+11; isspace(*s); s++);
15435 - for (z=s; *z && !isspace(*z); z++);
15437 + timeout = 1000*conf->timeout;
15438 + attempts = conf->attempts;
15440 - if (__lookup_ipliteral(&iplit, s, AF_UNSPEC)>0) {
15441 - if (iplit.family == AF_INET) {
15442 - memcpy(&ns[nns].sin.sin_addr, iplit.addr, 4);
15443 - ns[nns].sin.sin_port = htons(53);
15444 - ns[nns++].sin.sin_family = AF_INET;
15446 - sl = sizeof sa.sin6;
15447 - memcpy(&ns[nns].sin6.sin6_addr, iplit.addr, 16);
15448 - ns[nns].sin6.sin6_port = htons(53);
15449 - ns[nns].sin6.sin6_scope_id = iplit.scopeid;
15450 - ns[nns++].sin6.sin6_family = family = AF_INET6;
15453 + for (nns=0; nns<conf->nns; nns++) {
15454 + const struct address *iplit = &conf->ns[nns];
15455 + if (iplit->family == AF_INET) {
15456 + memcpy(&ns[nns].sin.sin_addr, iplit->addr, 4);
15457 + ns[nns].sin.sin_port = htons(53);
15458 + ns[nns].sin.sin_family = AF_INET;
15460 + sl = sizeof sa.sin6;
15461 + memcpy(&ns[nns].sin6.sin6_addr, iplit->addr, 16);
15462 + ns[nns].sin6.sin6_port = htons(53);
15463 + ns[nns].sin6.sin6_scope_id = iplit->scopeid;
15464 + ns[nns].sin6.sin6_family = family = AF_INET6;
15467 - if (f) __fclose_ca(f);
15469 - ns[0].sin.sin_family = AF_INET;
15470 - ns[0].sin.sin_port = htons(53);
15471 - ns[0].sin.sin_addr.s_addr = htonl(0x7f000001);
15475 /* Get local address and open/bind a socket */
15476 sa.sin.sin_family = family;
15477 @@ -207,3 +175,11 @@ out:
15482 +int __res_msend(int nqueries, const unsigned char *const *queries,
15483 + const int *qlens, unsigned char *const *answers, int *alens, int asize)
15485 + struct resolvconf conf;
15486 + if (__get_resolv_conf(&conf, 0, 0) < 0) return -1;
15487 + return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, &conf);
15490 +++ b/src/network/resolvconf.c
15492 +#include "lookup.h"
15493 +#include "stdio_impl.h"
15494 +#include <ctype.h>
15495 +#include <errno.h>
15496 +#include <string.h>
15497 +#include <netinet/in.h>
15499 +int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
15502 + unsigned char _buf[256];
15507 + conf->timeout = 5;
15508 + conf->attempts = 2;
15509 + if (search) *search = 0;
15511 + f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
15512 + if (!f) switch (errno) {
15516 + goto no_resolv_conf;
15521 + while (fgets(line, sizeof line, f)) {
15523 + if (!strchr(line, '\n') && !feof(f)) {
15524 + /* Ignore lines that get truncated rather than
15525 + * potentially misinterpreting them. */
15528 + while (c != '\n' && c != EOF);
15531 + if (!strncmp(line, "options", 7) && isspace(line[7])) {
15532 + p = strstr(line, "ndots:");
15533 + if (p && isdigit(p[6])) {
15535 + unsigned long x = strtoul(p, &z, 10);
15536 + if (z != p) conf->ndots = x > 15 ? 15 : x;
15538 + p = strstr(line, "attempts:");
15539 + if (p && isdigit(p[6])) {
15541 + unsigned long x = strtoul(p, &z, 10);
15542 + if (z != p) conf->attempts = x > 10 ? 10 : x;
15544 + p = strstr(line, "timeout:");
15545 + if (p && (isdigit(p[8]) || p[8]=='.')) {
15547 + unsigned long x = strtoul(p, &z, 10);
15548 + if (z != p) conf->timeout = x > 60 ? 60 : x;
15552 + if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
15553 + if (nns >= MAXNS) continue;
15554 + for (p=line+11; isspace(*p); p++);
15555 + for (z=p; *z && !isspace(*z); z++);
15557 + if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
15562 + if (!search) continue;
15563 + if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
15564 + || !isspace(line[6]))
15566 + for (p=line+7; isspace(*p); p++);
15567 + size_t l = strlen(p);
15568 + /* This can never happen anyway with chosen buffer sizes. */
15569 + if (l >= search_sz) continue;
15570 + memcpy(search, p, l+1);
15577 + __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);
15585 --- a/src/search/tsearch_avl.c
15586 +++ b/src/search/tsearch_avl.c
15587 @@ -77,38 +77,45 @@ static struct node *find(struct node *n,
15588 return find(n->right, k, cmp);
15591 -static struct node *insert(struct node **n, const void *k,
15592 - int (*cmp)(const void *, const void *), int *new)
15593 +static struct node *insert(struct node *n, const void *k,
15594 + int (*cmp)(const void *, const void *), struct node **found)
15596 - struct node *r = *n;
15601 - *n = r = malloc(sizeof **n);
15604 - r->left = r->right = 0;
15607 + n = malloc(sizeof *n);
15610 + n->left = n->right = 0;
15618 + c = cmp(k, n->key);
15623 + r = insert(c < 0 ? n->left : n->right, k, cmp, found);
15631 - c = cmp(k, r->key);
15635 - r = insert(&r->left, k, cmp, new);
15637 - r = insert(&r->right, k, cmp, new);
15639 - *n = balance(*n);
15643 -static struct node *movr(struct node *n, struct node *r) {
15646 - n->right = movr(n->right, r);
15647 +static struct node *remove_rightmost(struct node *n, struct node **rightmost)
15653 + n->right = remove_rightmost(n->right, rightmost);
15657 @@ -122,7 +129,13 @@ static struct node *remove(struct node *
15658 c = cmp(k, (*n)->key);
15660 struct node *r = *n;
15661 - *n = movr(r->left, r->right);
15663 + r->left = remove_rightmost(r->left, n);
15664 + (*n)->left = r->left;
15665 + (*n)->right = r->right;
15666 + *n = balance(*n);
15672 @@ -138,6 +151,8 @@ static struct node *remove(struct node *
15673 void *tdelete(const void *restrict key, void **restrict rootp,
15674 int(*compar)(const void *, const void *))
15678 struct node *n = *rootp;
15680 /* last argument is arbitrary non-null pointer
15681 @@ -150,17 +165,21 @@ void *tdelete(const void *restrict key,
15682 void *tfind(const void *key, void *const *rootp,
15683 int(*compar)(const void *, const void *))
15687 return find(*rootp, key, compar);
15690 void *tsearch(const void *key, void **rootp,
15691 int (*compar)(const void *, const void *))
15694 - struct node *n = *rootp;
15695 + struct node *update;
15697 - ret = insert(&n, key, compar, &new);
15701 + update = insert(*rootp, key, compar, &ret);
15707 --- a/src/setjmp/arm/longjmp.s
15708 +++ b/src/setjmp/arm/longjmp.s
15713 .type _longjmp,%function
15714 @@ -20,7 +21,11 @@ longjmp:
15715 ldc p2, cr4, [ip], #48
15718 - .word 0xecbc8b10 /* vldmia ip!, {d8-d15} */
15720 + vldmia ip!, {d8-d15}
15722 + .eabi_attribute 10, 0
15723 + .eabi_attribute 27, 0
15726 ldcl p1, cr10, [ip], #8
15727 @@ -29,9 +34,7 @@ longjmp:
15728 ldcl p1, cr13, [ip], #8
15729 ldcl p1, cr14, [ip], #8
15730 ldcl p1, cr15, [ip], #8
15737 1: .word __hwcap-1b
15738 --- a/src/setjmp/arm/setjmp.s
15739 +++ b/src/setjmp/arm/setjmp.s
15745 @@ -22,7 +23,11 @@ setjmp:
15746 stc p2, cr4, [ip], #48
15749 - .word 0xecac8b10 /* vstmia ip!, {d8-d15} */
15751 + vstmia ip!, {d8-d15}
15753 + .eabi_attribute 10, 0
15754 + .eabi_attribute 27, 0
15757 stcl p1, cr10, [ip], #8
15758 @@ -31,9 +36,7 @@ setjmp:
15759 stcl p1, cr13, [ip], #8
15760 stcl p1, cr14, [ip], #8
15761 stcl p1, cr15, [ip], #8
15768 1: .word __hwcap-1b
15769 --- a/src/setjmp/mips-sf/longjmp.s
15776 -.type _longjmp,@function
15777 -.type longjmp,@function
15797 --- a/src/setjmp/mips-sf/longjmp.sub
15801 --- a/src/setjmp/mips-sf/setjmp.s
15809 -.type __setjmp,@function
15810 -.type _setjmp,@function
15811 -.type setjmp,@function
15829 --- a/src/setjmp/mips-sf/setjmp.sub
15834 +++ b/src/setjmp/mips/longjmp.S
15840 +.type _longjmp,@function
15841 +.type longjmp,@function
15849 +#ifndef __mips_soft_float
15861 + lwc1 $31, 100($4)
15876 --- a/src/setjmp/mips/longjmp.s
15883 -.type _longjmp,@function
15884 -.type longjmp,@function
15891 -1: lwc1 $20, 56($4)
15902 - lwc1 $31, 100($4)
15917 +++ b/src/setjmp/mips/setjmp.S
15924 +.type __setjmp,@function
15925 +.type _setjmp,@function
15926 +.type setjmp,@function
15942 +#ifndef __mips_soft_float
15954 + swc1 $31, 100($4)
15958 --- a/src/setjmp/mips/setjmp.s
15966 -.type __setjmp,@function
15967 -.type _setjmp,@function
15968 -.type setjmp,@function
15995 - swc1 $31, 100($4)
15998 --- a/src/setjmp/mipsel-sf/longjmp.sub
16001 -../mips-sf/longjmp.s
16002 --- a/src/setjmp/mipsel-sf/setjmp.sub
16005 -../mips-sf/setjmp.s
16006 --- a/src/setjmp/sh-nofpu/longjmp.s
16011 -.type _longjmp, @function
16012 -.type longjmp, @function
16031 --- a/src/setjmp/sh-nofpu/longjmp.sub
16035 --- a/src/setjmp/sh-nofpu/setjmp.s
16043 -.type __setjmp, @function
16044 -.type _setjmp, @function
16045 -.type setjmp, @function
16062 --- a/src/setjmp/sh-nofpu/setjmp.sub
16067 +++ b/src/setjmp/sh/longjmp.S
16071 +.type _longjmp, @function
16072 +.type longjmp, @function
16084 +#if __SH_FPU_ANY__ || __SH4__
16085 + fmov.s @r4+, fr12
16086 + fmov.s @r4+, fr13
16087 + fmov.s @r4+, fr14
16088 + fmov.s @r4+, fr15
16097 --- a/src/setjmp/sh/longjmp.s
16102 -.type _longjmp, @function
16103 -.type longjmp, @function
16115 - fmov.s @r4+, fr12
16116 - fmov.s @r4+, fr13
16117 - fmov.s @r4+, fr14
16118 - fmov.s @r4+, fr15
16127 +++ b/src/setjmp/sh/setjmp.S
16134 +.type __setjmp, @function
16135 +.type _setjmp, @function
16136 +.type setjmp, @function
16141 +#if __SH_FPU_ANY__ || __SH4__
16143 + fmov.s fr15, @-r4
16144 + fmov.s fr14, @-r4
16145 + fmov.s fr13, @-r4
16146 + fmov.s fr12, @-r4
16161 --- a/src/setjmp/sh/setjmp.s
16169 -.type __setjmp, @function
16170 -.type _setjmp, @function
16171 -.type setjmp, @function
16177 - fmov.s fr15, @-r4
16178 - fmov.s fr14, @-r4
16179 - fmov.s fr13, @-r4
16180 - fmov.s fr12, @-r4
16192 --- a/src/setjmp/sheb-nofpu/longjmp.sub
16195 -../sh-nofpu/longjmp.s
16196 --- a/src/setjmp/sheb-nofpu/setjmp.sub
16199 -../sh-nofpu/setjmp.s
16200 --- a/src/signal/arm/restore.s
16201 +++ b/src/signal/arm/restore.s
16206 .type __restore,%function
16208 --- a/src/signal/arm/sigsetjmp.s
16209 +++ b/src/signal/arm/sigsetjmp.s
16213 .global __sigsetjmp
16214 .type sigsetjmp,%function
16215 --- a/src/signal/sigaction.c
16216 +++ b/src/signal/sigaction.c
16217 @@ -17,10 +17,6 @@ void __get_handler_set(sigset_t *set)
16218 int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
16220 struct k_sigaction ksa, ksa_old;
16221 - if (sig >= (unsigned)_NSIG) {
16226 if ((uintptr_t)sa->sa_handler > 1UL) {
16227 a_or_l(handler_set+(sig-1)/(8*sizeof(long)),
16228 @@ -57,7 +53,7 @@ int __libc_sigaction(int sig, const stru
16230 int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
16232 - if (sig-32U < 3) {
16233 + if (sig-32U < 3 || sig-1U >= _NSIG-1) {
16237 --- a/src/signal/sigsetjmp_tail.c
16238 +++ b/src/signal/sigsetjmp_tail.c
16240 #include <signal.h>
16241 #include "syscall.h"
16244 __attribute__((__visibility__("hidden")))
16246 int __sigsetjmp_tail(sigjmp_buf jb, int ret)
16248 void *p = jb->__ss;
16249 --- a/src/stdio/getdelim.c
16250 +++ b/src/stdio/getdelim.c
16251 @@ -27,17 +27,18 @@ ssize_t getdelim(char **restrict s, size
16253 z = memchr(f->rpos, delim, f->rend - f->rpos);
16254 k = z ? z - f->rpos + 1 : f->rend - f->rpos;
16256 + if (i+k+1 >= *n) {
16257 if (k >= SIZE_MAX/2-i) goto oom;
16259 - if (*n < SIZE_MAX/4) *n *= 2;
16260 - tmp = realloc(*s, *n);
16261 + size_t m = i+k+2;
16262 + if (!z && m < SIZE_MAX/4) m += m/2;
16263 + tmp = realloc(*s, m);
16266 - tmp = realloc(*s, *n);
16268 + tmp = realloc(*s, m);
16269 if (!tmp) goto oom;
16274 memcpy(*s+i, f->rpos, k);
16277 +++ b/src/string/arm/__aeabi_memclr.c
16279 +#include <string.h>
16282 +void __aeabi_memclr(void *dest, size_t n)
16284 + memset(dest, 0, n);
16286 +weak_alias(__aeabi_memclr, __aeabi_memclr4);
16287 +weak_alias(__aeabi_memclr, __aeabi_memclr8);
16289 +++ b/src/string/arm/__aeabi_memcpy.c
16291 +#include <string.h>
16294 +void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
16296 + memcpy(dest, src, n);
16298 +weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
16299 +weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
16301 +++ b/src/string/arm/__aeabi_memmove.c
16303 +#include <string.h>
16306 +void __aeabi_memmove(void *dest, const void *src, size_t n)
16308 + memmove(dest, src, n);
16310 +weak_alias(__aeabi_memmove, __aeabi_memmove4);
16311 +weak_alias(__aeabi_memmove, __aeabi_memmove8);
16313 +++ b/src/string/arm/__aeabi_memset.c
16315 +#include <string.h>
16318 +void __aeabi_memset(void *dest, size_t n, int c)
16320 + memset(dest, c, n);
16322 +weak_alias(__aeabi_memset, __aeabi_memset4);
16323 +weak_alias(__aeabi_memset, __aeabi_memset8);
16325 +++ b/src/string/arm/memcpy.c
16328 +#include "../memcpy.c"
16331 +++ b/src/string/arm/memcpy_le.S
16336 + * Copyright (C) 2008 The Android Open Source Project
16337 + * All rights reserved.
16339 + * Redistribution and use in source and binary forms, with or without
16340 + * modification, are permitted provided that the following conditions
16342 + * * Redistributions of source code must retain the above copyright
16343 + * notice, this list of conditions and the following disclaimer.
16344 + * * Redistributions in binary form must reproduce the above copyright
16345 + * notice, this list of conditions and the following disclaimer in
16346 + * the documentation and/or other materials provided with the
16349 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16350 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16351 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16352 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16353 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16354 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
16355 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
16356 + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
16357 + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
16358 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
16359 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16365 + * Optimized memcpy() for ARM.
16367 + * note that memcpy() always returns the destination pointer,
16368 + * so we have to preserve R0.
16372 + * This file has been modified from the original for use in musl libc.
16373 + * The main changes are: addition of .type memcpy,%function to make the
16374 + * code safely callable from thumb mode, adjusting the return
16375 + * instructions to be compatible with pre-thumb ARM cpus, and removal
16376 + * of prefetch code that is not compatible with older cpus.
16382 +.type memcpy,%function
16384 + /* The stack must always be 64-bits aligned to be compliant with the
16385 + * ARM ABI. Since we have to save R0, we might as well save R4
16386 + * which we can use for better pipelining of the reads below
16389 + .save {r0, r4, lr}
16390 + stmfd sp!, {r0, r4, lr}
16391 + /* Making room for r5-r11 which will be spilled later */
16395 + /* it simplifies things to take care of len<4 early */
16397 + blo copy_last_3_and_return
16399 + /* compute the offset to align the source
16400 + * offset = (4-(src&3))&3 = -src & 3
16406 + /* align source to 32 bits. We need to insert 2 instructions between
16407 + * a ldr[b|h] and str[b|h] because byte and half-word instructions
16408 + * stall 2 cycles.
16410 + movs r12, r3, lsl #31
16411 + sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
16412 + ldrbmi r3, [r1], #1
16413 + ldrbcs r4, [r1], #1
16414 + ldrbcs r12,[r1], #1
16415 + strbmi r3, [r0], #1
16416 + strbcs r4, [r0], #1
16417 + strbcs r12,[r0], #1
16421 + /* see if src and dst are aligned together (congruent) */
16424 + bne non_congruent
16426 + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16427 + * frame. Don't update sp.
16429 + stmea sp, {r5-r11}
16431 + /* align the destination to a cache-line */
16433 + ands r3, r3, #0x1C
16434 + beq congruent_aligned32
16436 + andhi r3, r2, #0x1C
16438 + /* conditionnaly copies 0 to 7 words (length in r3) */
16439 + movs r12, r3, lsl #28
16440 + ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
16441 + ldmmi r1!, {r8, r9} /* 8 bytes */
16442 + stmcs r0!, {r4, r5, r6, r7}
16443 + stmmi r0!, {r8, r9}
16445 + ldrne r10,[r1], #4 /* 4 bytes */
16446 + strne r10,[r0], #4
16449 +congruent_aligned32:
16451 + * here source is aligned to 32 bytes.
16456 + blo less_than_32_left
16459 + * We preload a cache-line up to 64 bytes ahead. On the 926, this will
16460 + * stall only until the requested world is fetched, but the linefill
16461 + * continues in the the background.
16462 + * While the linefill is going, we write our previous cache-line
16463 + * into the write-buffer (which should have some free space).
16464 + * When the linefill is done, the writebuffer will
16465 + * start dumping its content into memory
16467 + * While all this is going, we then load a full cache line into
16468 + * 8 registers, this cache line should be in the cache by now
16469 + * (or partly in the cache).
16471 + * This code should work well regardless of the source/dest alignment.
16475 + /* Align the preload register to a cache-line because the cpu does
16476 + * "critical word first" (the first word requested is loaded first).
16478 + @ bic r12, r1, #0x1F
16479 + @ add r12, r12, #64
16481 +1: ldmia r1!, { r4-r11 }
16485 + * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi
16486 + * for ARM9 preload will not be safely guarded by the preceding subs.
16487 + * When it is safely guarded the only possibility to have SIGSEGV here
16488 + * is because the caller overstates the length.
16490 + @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
16491 + stmia r0!, { r4-r11 }
16496 +less_than_32_left:
16498 + * less than 32 bytes left at this point (length in r2)
16501 + /* skip all this if there is nothing to do, which should
16502 + * be a common case (if not executed the code below takes
16503 + * about 16 cycles)
16508 + /* conditionnaly copies 0 to 31 bytes */
16509 + movs r12, r2, lsl #28
16510 + ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
16511 + ldmmi r1!, {r8, r9} /* 8 bytes */
16512 + stmcs r0!, {r4, r5, r6, r7}
16513 + stmmi r0!, {r8, r9}
16514 + movs r12, r2, lsl #30
16515 + ldrcs r3, [r1], #4 /* 4 bytes */
16516 + ldrhmi r4, [r1], #2 /* 2 bytes */
16517 + strcs r3, [r0], #4
16518 + strhmi r4, [r0], #2
16520 + ldrbne r3, [r1] /* last byte */
16523 + /* we're done! restore everything and return */
16524 +1: ldmfd sp!, {r5-r11}
16525 + ldmfd sp!, {r0, r4, lr}
16528 + /********************************************************************/
16532 + * here source is aligned to 4 bytes
16533 + * but destination is not.
16535 + * in the code below r2 is the number of bytes read
16536 + * (the number of bytes written is always smaller, because we have
16537 + * partial words in the shift queue)
16540 + blo copy_last_3_and_return
16542 + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16543 + * frame. Don't update sp.
16545 + stmea sp, {r5-r11}
16547 + /* compute shifts needed to align src to dest */
16549 + and r5, r5, #3 /* r5 = # bytes in partial words */
16550 + mov r12, r5, lsl #3 /* r12 = right */
16551 + rsb lr, r12, #32 /* lr = left */
16553 + /* read the first word */
16557 + /* write a partial word (0 to 3 bytes), such that destination
16558 + * becomes aligned to 32 bits (r5 = nb of words to copy for alignment)
16560 + movs r5, r5, lsl #31
16561 + strbmi r3, [r0], #1
16562 + movmi r3, r3, lsr #8
16563 + strbcs r3, [r0], #1
16564 + movcs r3, r3, lsr #8
16565 + strbcs r3, [r0], #1
16566 + movcs r3, r3, lsr #8
16569 + blo partial_word_tail
16571 + /* Align destination to 32 bytes (cache line boundary) */
16576 + orr r4, r3, r5, lsl lr
16577 + mov r3, r5, lsr r12
16581 + blo partial_word_tail
16583 + /* copy 32 bytes at a time */
16584 +2: subs r2, r2, #32
16585 + blo less_than_thirtytwo
16587 + /* Use immediate mode for the shifts, because there is an extra cycle
16588 + * for register shifts, which could account for up to 50% of
16589 + * performance hit.
16598 + ldr r12, [r1], #4
16600 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16602 + ldrhs r12, [r1], #4
16603 + orr r3, r3, r4, lsl #16
16604 + mov r4, r4, lsr #16
16605 + orr r4, r4, r5, lsl #16
16606 + mov r5, r5, lsr #16
16607 + orr r5, r5, r6, lsl #16
16608 + mov r6, r6, lsr #16
16609 + orr r6, r6, r7, lsl #16
16610 + mov r7, r7, lsr #16
16611 + orr r7, r7, r8, lsl #16
16612 + mov r8, r8, lsr #16
16613 + orr r8, r8, r9, lsl #16
16614 + mov r9, r9, lsr #16
16615 + orr r9, r9, r10, lsl #16
16616 + mov r10, r10, lsr #16
16617 + orr r10, r10, r11, lsl #16
16618 + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
16619 + mov r3, r11, lsr #16
16621 + b less_than_thirtytwo
16624 + ldr r12, [r1], #4
16626 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16628 + ldrhs r12, [r1], #4
16629 + orr r3, r3, r4, lsl #24
16630 + mov r4, r4, lsr #8
16631 + orr r4, r4, r5, lsl #24
16632 + mov r5, r5, lsr #8
16633 + orr r5, r5, r6, lsl #24
16634 + mov r6, r6, lsr #8
16635 + orr r6, r6, r7, lsl #24
16636 + mov r7, r7, lsr #8
16637 + orr r7, r7, r8, lsl #24
16638 + mov r8, r8, lsr #8
16639 + orr r8, r8, r9, lsl #24
16640 + mov r9, r9, lsr #8
16641 + orr r9, r9, r10, lsl #24
16642 + mov r10, r10, lsr #8
16643 + orr r10, r10, r11, lsl #24
16644 + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
16645 + mov r3, r11, lsr #8
16647 + b less_than_thirtytwo
16650 + ldr r12, [r1], #4
16652 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16654 + ldrhs r12, [r1], #4
16655 + orr r3, r3, r4, lsl #8
16656 + mov r4, r4, lsr #24
16657 + orr r4, r4, r5, lsl #8
16658 + mov r5, r5, lsr #24
16659 + orr r5, r5, r6, lsl #8
16660 + mov r6, r6, lsr #24
16661 + orr r6, r6, r7, lsl #8
16662 + mov r7, r7, lsr #24
16663 + orr r7, r7, r8, lsl #8
16664 + mov r8, r8, lsr #24
16665 + orr r8, r8, r9, lsl #8
16666 + mov r9, r9, lsr #24
16667 + orr r9, r9, r10, lsl #8
16668 + mov r10, r10, lsr #24
16669 + orr r10, r10, r11, lsl #8
16670 + stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
16671 + mov r3, r11, lsr #24
16674 +less_than_thirtytwo:
16675 + /* copy the last 0 to 31 bytes of the source */
16676 + rsb r12, lr, #32 /* we corrupted r12, recompute it */
16679 + blo partial_word_tail
16681 +1: ldr r5, [r1], #4
16683 + orr r4, r3, r5, lsl lr
16684 + mov r3, r5, lsr r12
16689 +partial_word_tail:
16690 + /* we have a partial word in the input buffer */
16691 + movs r5, lr, lsl #(31-3)
16692 + strbmi r3, [r0], #1
16693 + movmi r3, r3, lsr #8
16694 + strbcs r3, [r0], #1
16695 + movcs r3, r3, lsr #8
16696 + strbcs r3, [r0], #1
16698 + /* Refill spilled registers from the stack. Don't update sp. */
16699 + ldmfd sp, {r5-r11}
16701 +copy_last_3_and_return:
16702 + movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */
16703 + ldrbmi r2, [r1], #1
16704 + ldrbcs r3, [r1], #1
16706 + strbmi r2, [r0], #1
16707 + strbcs r3, [r0], #1
16710 + /* we're done! restore sp and spilled registers and return */
16712 + ldmfd sp!, {r0, r4, lr}
16716 --- a/src/string/armel/memcpy.s
16720 - * Copyright (C) 2008 The Android Open Source Project
16721 - * All rights reserved.
16723 - * Redistribution and use in source and binary forms, with or without
16724 - * modification, are permitted provided that the following conditions
16726 - * * Redistributions of source code must retain the above copyright
16727 - * notice, this list of conditions and the following disclaimer.
16728 - * * Redistributions in binary form must reproduce the above copyright
16729 - * notice, this list of conditions and the following disclaimer in
16730 - * the documentation and/or other materials provided with the
16733 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16734 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16735 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16736 - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16737 - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16738 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
16739 - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
16740 - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
16741 - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
16742 - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
16743 - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16749 - * Optimized memcpy() for ARM.
16751 - * note that memcpy() always returns the destination pointer,
16752 - * so we have to preserve R0.
16756 - * This file has been modified from the original for use in musl libc.
16757 - * The main changes are: addition of .type memcpy,%function to make the
16758 - * code safely callable from thumb mode, adjusting the return
16759 - * instructions to be compatible with pre-thumb ARM cpus, and removal
16760 - * of prefetch code that is not compatible with older cpus.
16764 -.type memcpy,%function
16766 - /* The stack must always be 64-bits aligned to be compliant with the
16767 - * ARM ABI. Since we have to save R0, we might as well save R4
16768 - * which we can use for better pipelining of the reads below
16771 - .save {r0, r4, lr}
16772 - stmfd sp!, {r0, r4, lr}
16773 - /* Making room for r5-r11 which will be spilled later */
16777 - /* it simplifies things to take care of len<4 early */
16779 - blo copy_last_3_and_return
16781 - /* compute the offset to align the source
16782 - * offset = (4-(src&3))&3 = -src & 3
16788 - /* align source to 32 bits. We need to insert 2 instructions between
16789 - * a ldr[b|h] and str[b|h] because byte and half-word instructions
16790 - * stall 2 cycles.
16792 - movs r12, r3, lsl #31
16793 - sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
16794 - .word 0x44d13001 /* ldrbmi r3, [r1], #1 */
16795 - .word 0x24d14001 /* ldrbcs r4, [r1], #1 */
16796 - .word 0x24d1c001 /* ldrbcs r12,[r1], #1 */
16797 - .word 0x44c03001 /* strbmi r3, [r0], #1 */
16798 - .word 0x24c04001 /* strbcs r4, [r0], #1 */
16799 - .word 0x24c0c001 /* strbcs r12,[r0], #1 */
16803 - /* see if src and dst are aligned together (congruent) */
16806 - bne non_congruent
16808 - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16809 - * frame. Don't update sp.
16811 - stmea sp, {r5-r11}
16813 - /* align the destination to a cache-line */
16815 - ands r3, r3, #0x1C
16816 - beq congruent_aligned32
16818 - andhi r3, r2, #0x1C
16820 - /* conditionnaly copies 0 to 7 words (length in r3) */
16821 - movs r12, r3, lsl #28
16822 - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
16823 - ldmmi r1!, {r8, r9} /* 8 bytes */
16824 - stmcs r0!, {r4, r5, r6, r7}
16825 - stmmi r0!, {r8, r9}
16827 - ldrne r10,[r1], #4 /* 4 bytes */
16828 - strne r10,[r0], #4
16831 -congruent_aligned32:
16833 - * here source is aligned to 32 bytes.
16838 - blo less_than_32_left
16841 - * We preload a cache-line up to 64 bytes ahead. On the 926, this will
16842 - * stall only until the requested world is fetched, but the linefill
16843 - * continues in the the background.
16844 - * While the linefill is going, we write our previous cache-line
16845 - * into the write-buffer (which should have some free space).
16846 - * When the linefill is done, the writebuffer will
16847 - * start dumping its content into memory
16849 - * While all this is going, we then load a full cache line into
16850 - * 8 registers, this cache line should be in the cache by now
16851 - * (or partly in the cache).
16853 - * This code should work well regardless of the source/dest alignment.
16857 - /* Align the preload register to a cache-line because the cpu does
16858 - * "critical word first" (the first word requested is loaded first).
16860 - @ bic r12, r1, #0x1F
16861 - @ add r12, r12, #64
16863 -1: ldmia r1!, { r4-r11 }
16867 - * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi
16868 - * for ARM9 preload will not be safely guarded by the preceding subs.
16869 - * When it is safely guarded the only possibility to have SIGSEGV here
16870 - * is because the caller overstates the length.
16872 - @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
16873 - stmia r0!, { r4-r11 }
16878 -less_than_32_left:
16880 - * less than 32 bytes left at this point (length in r2)
16883 - /* skip all this if there is nothing to do, which should
16884 - * be a common case (if not executed the code below takes
16885 - * about 16 cycles)
16890 - /* conditionnaly copies 0 to 31 bytes */
16891 - movs r12, r2, lsl #28
16892 - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */
16893 - ldmmi r1!, {r8, r9} /* 8 bytes */
16894 - stmcs r0!, {r4, r5, r6, r7}
16895 - stmmi r0!, {r8, r9}
16896 - movs r12, r2, lsl #30
16897 - ldrcs r3, [r1], #4 /* 4 bytes */
16898 - .word 0x40d140b2 /* ldrhmi r4, [r1], #2 */ /* 2 bytes */
16899 - strcs r3, [r0], #4
16900 - .word 0x40c040b2 /* strhmi r4, [r0], #2 */
16902 - .word 0x15d13000 /* ldrbne r3, [r1] */ /* last byte */
16903 - .word 0x15c03000 /* strbne r3, [r0] */
16905 - /* we're done! restore everything and return */
16906 -1: ldmfd sp!, {r5-r11}
16907 - ldmfd sp!, {r0, r4, lr}
16912 - /********************************************************************/
16916 - * here source is aligned to 4 bytes
16917 - * but destination is not.
16919 - * in the code below r2 is the number of bytes read
16920 - * (the number of bytes written is always smaller, because we have
16921 - * partial words in the shift queue)
16924 - blo copy_last_3_and_return
16926 - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16927 - * frame. Don't update sp.
16929 - stmea sp, {r5-r11}
16931 - /* compute shifts needed to align src to dest */
16933 - and r5, r5, #3 /* r5 = # bytes in partial words */
16934 - mov r12, r5, lsl #3 /* r12 = right */
16935 - rsb lr, r12, #32 /* lr = left */
16937 - /* read the first word */
16941 - /* write a partial word (0 to 3 bytes), such that destination
16942 - * becomes aligned to 32 bits (r5 = nb of words to copy for alignment)
16944 - movs r5, r5, lsl #31
16945 - .word 0x44c03001 /* strbmi r3, [r0], #1 */
16946 - movmi r3, r3, lsr #8
16947 - .word 0x24c03001 /* strbcs r3, [r0], #1 */
16948 - movcs r3, r3, lsr #8
16949 - .word 0x24c03001 /* strbcs r3, [r0], #1 */
16950 - movcs r3, r3, lsr #8
16953 - blo partial_word_tail
16955 - /* Align destination to 32 bytes (cache line boundary) */
16960 - orr r4, r3, r5, lsl lr
16961 - mov r3, r5, lsr r12
16965 - blo partial_word_tail
16967 - /* copy 32 bytes at a time */
16968 -2: subs r2, r2, #32
16969 - blo less_than_thirtytwo
16971 - /* Use immediate mode for the shifts, because there is an extra cycle
16972 - * for register shifts, which could account for up to 50% of
16973 - * performance hit.
16982 - ldr r12, [r1], #4
16984 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16986 - ldrhs r12, [r1], #4
16987 - orr r3, r3, r4, lsl #16
16988 - mov r4, r4, lsr #16
16989 - orr r4, r4, r5, lsl #16
16990 - mov r5, r5, lsr #16
16991 - orr r5, r5, r6, lsl #16
16992 - mov r6, r6, lsr #16
16993 - orr r6, r6, r7, lsl #16
16994 - mov r7, r7, lsr #16
16995 - orr r7, r7, r8, lsl #16
16996 - mov r8, r8, lsr #16
16997 - orr r8, r8, r9, lsl #16
16998 - mov r9, r9, lsr #16
16999 - orr r9, r9, r10, lsl #16
17000 - mov r10, r10, lsr #16
17001 - orr r10, r10, r11, lsl #16
17002 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
17003 - mov r3, r11, lsr #16
17005 - b less_than_thirtytwo
17008 - ldr r12, [r1], #4
17010 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
17012 - ldrhs r12, [r1], #4
17013 - orr r3, r3, r4, lsl #24
17014 - mov r4, r4, lsr #8
17015 - orr r4, r4, r5, lsl #24
17016 - mov r5, r5, lsr #8
17017 - orr r5, r5, r6, lsl #24
17018 - mov r6, r6, lsr #8
17019 - orr r6, r6, r7, lsl #24
17020 - mov r7, r7, lsr #8
17021 - orr r7, r7, r8, lsl #24
17022 - mov r8, r8, lsr #8
17023 - orr r8, r8, r9, lsl #24
17024 - mov r9, r9, lsr #8
17025 - orr r9, r9, r10, lsl #24
17026 - mov r10, r10, lsr #8
17027 - orr r10, r10, r11, lsl #24
17028 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
17029 - mov r3, r11, lsr #8
17031 - b less_than_thirtytwo
17034 - ldr r12, [r1], #4
17036 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
17038 - ldrhs r12, [r1], #4
17039 - orr r3, r3, r4, lsl #8
17040 - mov r4, r4, lsr #24
17041 - orr r4, r4, r5, lsl #8
17042 - mov r5, r5, lsr #24
17043 - orr r5, r5, r6, lsl #8
17044 - mov r6, r6, lsr #24
17045 - orr r6, r6, r7, lsl #8
17046 - mov r7, r7, lsr #24
17047 - orr r7, r7, r8, lsl #8
17048 - mov r8, r8, lsr #24
17049 - orr r8, r8, r9, lsl #8
17050 - mov r9, r9, lsr #24
17051 - orr r9, r9, r10, lsl #8
17052 - mov r10, r10, lsr #24
17053 - orr r10, r10, r11, lsl #8
17054 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10}
17055 - mov r3, r11, lsr #24
17058 -less_than_thirtytwo:
17059 - /* copy the last 0 to 31 bytes of the source */
17060 - rsb r12, lr, #32 /* we corrupted r12, recompute it */
17063 - blo partial_word_tail
17065 -1: ldr r5, [r1], #4
17067 - orr r4, r3, r5, lsl lr
17068 - mov r3, r5, lsr r12
17073 -partial_word_tail:
17074 - /* we have a partial word in the input buffer */
17075 - movs r5, lr, lsl #(31-3)
17076 - .word 0x44c03001 /* strbmi r3, [r0], #1 */
17077 - movmi r3, r3, lsr #8
17078 - .word 0x24c03001 /* strbcs r3, [r0], #1 */
17079 - movcs r3, r3, lsr #8
17080 - .word 0x24c03001 /* strbcs r3, [r0], #1 */
17082 - /* Refill spilled registers from the stack. Don't update sp. */
17083 - ldmfd sp, {r5-r11}
17085 -copy_last_3_and_return:
17086 - movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */
17087 - .word 0x44d12001 /* ldrbmi r2, [r1], #1 */
17088 - .word 0x24d13001 /* ldrbcs r3, [r1], #1 */
17089 - .word 0x25d1c000 /* ldrbcs r12,[r1] */
17090 - .word 0x44c02001 /* strbmi r2, [r0], #1 */
17091 - .word 0x24c03001 /* strbcs r3, [r0], #1 */
17092 - .word 0x25c0c000 /* strbcs r12,[r0] */
17094 - /* we're done! restore sp and spilled registers and return */
17096 - ldmfd sp!, {r0, r4, lr}
17100 --- a/src/string/armel/memcpy.sub
17104 --- a/src/string/armhf/memcpy.sub
17108 --- a/src/thread/__syscall_cp.c
17109 +++ b/src/thread/__syscall_cp.c
17111 #include "pthread_impl.h"
17112 #include "syscall.h"
17115 __attribute__((__visibility__("hidden")))
17117 long __syscall_cp_c();
17119 static long sccp(syscall_arg_t nr,
17120 --- a/src/thread/__tls_get_addr.c
17121 +++ b/src/thread/__tls_get_addr.c
17123 #include <stddef.h>
17124 #include "pthread_impl.h"
17127 +__attribute__((__visibility__("hidden")))
17128 +void *__tls_get_new(size_t *);
17130 void *__tls_get_addr(size_t *v)
17132 pthread_t self = __pthread_self();
17134 - __attribute__((__visibility__("hidden")))
17135 - void *__tls_get_new(size_t *);
17136 if (v[0]<=(size_t)self->dtv[0])
17137 return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET;
17138 return __tls_get_new(v);
17140 - return (char *)self->dtv[1]+v[1]+DTP_OFFSET;
17144 +weak_alias(__tls_get_addr, __tls_get_new);
17145 --- a/src/thread/aarch64/syscall_cp.s
17146 +++ b/src/thread/aarch64/syscall_cp.s
17152 + cbnz w0,__cp_cancel
17156 @@ -28,6 +28,5 @@ __cp_begin:
17161 - // cbnz might not be able to jump far enough
17166 +++ b/src/thread/arm/__set_thread_area.c
17168 +#include <stdint.h>
17170 +#include "pthread_impl.h"
17173 +#define HWCAP_TLS (1 << 15)
17175 +extern const unsigned char __attribute__((__visibility__("hidden")))
17176 + __a_barrier_dummy[], __a_barrier_oldkuser[],
17177 + __a_barrier_v6[], __a_barrier_v7[],
17178 + __a_cas_dummy[], __a_cas_v6[], __a_cas_v7[],
17179 + __a_gettp_dummy[];
17181 +#define __a_barrier_kuser 0xffff0fa0
17182 +#define __a_cas_kuser 0xffff0fc0
17183 +#define __a_gettp_kuser 0xffff0fe0
17185 +extern uintptr_t __attribute__((__visibility__("hidden")))
17186 + __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
17188 +#define SET(op,ver) (__a_##op##_ptr = \
17189 + (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
17191 +int __set_thread_area(void *p)
17193 +#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
17194 + if (__hwcap & HWCAP_TLS) {
17197 + SET(barrier, v7);
17198 + for (aux=libc.auxv; *aux; aux+=2) {
17199 + if (*aux != AT_PLATFORM) continue;
17200 + const char *s = (void *)aux[1];
17201 + if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break;
17203 + SET(barrier, v6);
17207 + int ver = *(int *)0xffff0ffc;
17208 + SET(gettp, kuser);
17210 + SET(barrier, kuser);
17211 + if (ver < 2) a_crash();
17212 + if (ver < 3) SET(barrier, oldkuser);
17215 + return __syscall(0xf0005, p);
17217 --- a/src/thread/arm/__set_thread_area.s
17220 -/* Replaced by C code in arch/arm/src */
17221 --- a/src/thread/arm/__unmapself.s
17222 +++ b/src/thread/arm/__unmapself.s
17226 .global __unmapself
17227 .type __unmapself,%function
17229 +++ b/src/thread/arm/atomics.s
17234 +.global __a_barrier
17235 +.hidden __a_barrier
17236 +.type __a_barrier,%function
17241 +1: .word __a_barrier_ptr-1b
17242 +.global __a_barrier_dummy
17243 +.hidden __a_barrier_dummy
17244 +__a_barrier_dummy:
17246 +.global __a_barrier_oldkuser
17247 +.hidden __a_barrier_oldkuser
17248 +__a_barrier_oldkuser:
17249 + push {r0,r1,r2,r3,ip,lr}
17252 + ldr ip,=0xffff0fc0
17255 + pop {r0,r1,r2,r3,ip,lr}
17257 +.global __a_barrier_v6
17258 +.hidden __a_barrier_v6
17260 + mcr p15,0,r0,c7,c10,5
17262 +.global __a_barrier_v7
17263 +.hidden __a_barrier_v7
17265 + .word 0xf57ff05b /* dmb ish */
17270 +.type __a_cas,%function
17275 +1: .word __a_cas_ptr-1b
17276 +.global __a_cas_dummy
17277 +.hidden __a_cas_dummy
17284 +.global __a_cas_v6
17285 +.hidden __a_cas_v6
17288 + mcr p15,0,r0,c7,c10,5
17289 +1: .word 0xe1920f9f /* ldrex r0,[r2] */
17291 + .word 0x01820f91 /* strexeq r0,r1,[r2] */
17294 + mcr p15,0,r0,c7,c10,5
17296 +.global __a_cas_v7
17297 +.hidden __a_cas_v7
17300 + .word 0xf57ff05b /* dmb ish */
17301 +1: .word 0xe1920f9f /* ldrex r0,[r2] */
17303 + .word 0x01820f91 /* strexeq r0,r1,[r2] */
17306 + .word 0xf57ff05b /* dmb ish */
17309 +.global __aeabi_read_tp
17310 +.type __aeabi_read_tp,%function
17315 +.type __a_gettp,%function
17320 +1: .word __a_gettp_ptr-1b
17321 +.global __a_gettp_dummy
17322 +.hidden __a_gettp_dummy
17324 + mrc p15,0,r0,c13,c0,3
17328 +.global __a_barrier_ptr
17329 +.hidden __a_barrier_ptr
17333 +.global __a_cas_ptr
17334 +.hidden __a_cas_ptr
17338 +.global __a_gettp_ptr
17339 +.hidden __a_gettp_ptr
17342 --- a/src/thread/arm/clone.s
17343 +++ b/src/thread/arm/clone.s
17348 .type __clone,%function
17349 @@ -15,8 +16,6 @@ __clone:
17352 ldmfd sp!,{r4,r5,r6,r7}
17358 --- a/src/thread/arm/syscall_cp.s
17359 +++ b/src/thread/arm/syscall_cp.s
17365 @@ -22,8 +23,6 @@ __cp_begin:
17368 ldmfd sp!,{r4,r5,r6,r7,lr}
17373 ldmfd sp!,{r4,r5,r6,r7,lr}
17374 --- a/src/thread/microblaze/syscall_cp.s
17375 +++ b/src/thread/microblaze/syscall_cp.s
17380 - bnei r5, __cancel
17381 + bnei r5, __cp_cancel
17385 @@ -23,3 +23,5 @@ __cp_begin:
17391 --- a/src/thread/or1k/syscall_cp.s
17392 +++ b/src/thread/or1k/syscall_cp.s
17393 @@ -12,7 +12,7 @@ __syscall_cp_asm:
17398 + l.bnf __cp_cancel
17402 @@ -24,3 +24,6 @@ __cp_begin:
17409 --- a/src/thread/powerpc/syscall_cp.s
17410 +++ b/src/thread/powerpc/syscall_cp.s
17411 @@ -38,7 +38,7 @@ __cp_begin:
17412 cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7.
17413 beq+ cr7, 1f #jump to label 1 if r0 was 0
17415 - b __cancel #else call cancel
17416 + b __cp_cancel #else call cancel
17418 #ok, the cancel flag was not set
17419 # syscall: number goes to r0, the rest 3-8
17420 @@ -55,3 +55,5 @@ __cp_end:
17421 #else negate result.
17426 --- a/src/thread/pthread_cancel.c
17427 +++ b/src/thread/pthread_cancel.c
17429 +#define _GNU_SOURCE
17430 #include <string.h>
17431 #include "pthread_impl.h"
17432 #include "syscall.h"
17436 __attribute__((__visibility__("hidden")))
17438 -long __cancel(), __cp_cancel(), __syscall_cp_asm(), __syscall_cp_c();
17439 +long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
17443 @@ -17,12 +16,6 @@ long __cancel()
17447 -/* If __syscall_cp_asm has adjusted the stack pointer, it must provide a
17448 - * definition of __cp_cancel to undo those adjustments and call __cancel.
17449 - * Otherwise, __cancel provides a definition for __cp_cancel. */
17451 -weak_alias(__cancel, __cp_cancel);
17453 long __syscall_cp_asm(volatile void *, syscall_arg_t,
17454 syscall_arg_t, syscall_arg_t, syscall_arg_t,
17455 syscall_arg_t, syscall_arg_t, syscall_arg_t);
17456 @@ -52,24 +45,22 @@ static void _sigaddset(sigset_t *set, in
17457 set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
17461 __attribute__((__visibility__("hidden")))
17463 -extern const char __cp_begin[1], __cp_end[1];
17464 +extern const char __cp_begin[1], __cp_end[1], __cp_cancel[1];
17466 static void cancel_handler(int sig, siginfo_t *si, void *ctx)
17468 pthread_t self = __pthread_self();
17469 ucontext_t *uc = ctx;
17470 - const char *ip = ((char **)&uc->uc_mcontext)[CANCEL_REG_IP];
17471 + uintptr_t pc = uc->uc_mcontext.MC_PC;
17474 if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return;
17476 _sigaddset(&uc->uc_sigmask, SIGCANCEL);
17478 - if (self->cancelasync || ip >= __cp_begin && ip < __cp_end) {
17479 - ((char **)&uc->uc_mcontext)[CANCEL_REG_IP] = (char *)__cp_cancel;
17480 + if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
17481 + uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
17486 +++ b/src/thread/sh/__set_thread_area.c
17488 +#include "pthread_impl.h"
17492 +/* Also perform sh-specific init */
17494 +#define CPU_HAS_LLSC 0x0040
17495 +#define CPU_HAS_CAS_L 0x0400
17497 +__attribute__((__visibility__("hidden")))
17498 +extern const char __sh_cas_gusa[], __sh_cas_llsc[], __sh_cas_imask[], __sh_cas_cas_l[];
17500 +__attribute__((__visibility__("hidden")))
17501 +const void *__sh_cas_ptr;
17503 +__attribute__((__visibility__("hidden")))
17504 +unsigned __sh_nommu;
17506 +int __set_thread_area(void *p)
17509 + __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
17511 + __sh_cas_ptr = __sh_cas_gusa;
17512 +#if !defined(__SH3__) && !defined(__SH4__)
17513 + for (aux=libc.auxv; *aux; aux+=2) {
17514 + if (*aux != AT_PLATFORM) continue;
17515 + const char *s = (void *)aux[1];
17516 + if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
17517 + __sh_cas_ptr = __sh_cas_imask;
17521 + if (__hwcap & CPU_HAS_CAS_L)
17522 + __sh_cas_ptr = __sh_cas_cas_l;
17523 + else if (__hwcap & CPU_HAS_LLSC)
17524 + __sh_cas_ptr = __sh_cas_llsc;
17529 +++ b/src/thread/sh/__unmapself.c
17531 +#include "pthread_impl.h"
17533 +void __unmapself_sh_mmu(void *, size_t);
17534 +void __unmapself_sh_nommu(void *, size_t);
17536 +#if !defined(__SH3__) && !defined(__SH4__)
17537 +#define __unmapself __unmapself_sh_nommu
17538 +#include "dynlink.h"
17540 +#define CRTJMP(pc,sp) __asm__ __volatile__( \
17541 + "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
17542 + : : "r"(pc), "r"(sp) : "r0", "memory" )
17543 +#include "../__unmapself.c"
17544 +#undef __unmapself
17545 +extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
17547 +#define __sh_nommu 0
17550 +void __unmapself(void *base, size_t size)
17552 + if (__sh_nommu) __unmapself_sh_nommu(base, size);
17553 + else __unmapself_sh_mmu(base, size);
17555 --- a/src/thread/sh/__unmapself.s
17559 -.global __unmapself_sh_mmu
17560 -.type __unmapself_sh_mmu, @function
17561 -__unmapself_sh_mmu:
17562 - mov #91, r3 ! SYS_munmap
17571 - mov #1, r3 ! SYS_exit
17581 +++ b/src/thread/sh/__unmapself_mmu.s
17584 +.global __unmapself_sh_mmu
17585 +.type __unmapself_sh_mmu, @function
17586 +__unmapself_sh_mmu:
17587 + mov #91, r3 ! SYS_munmap
17596 + mov #1, r3 ! SYS_exit
17606 +++ b/src/thread/sh/atomics.s
17608 +/* Contract for all versions is same as cas.l r2,r3,@r0
17609 + * pr and r1 are also clobbered (by jsr & r1 as temp).
17610 + * r0,r2,r4-r15 must be preserved.
17611 + * r3 contains result (==r2 iff cas succeeded). */
17614 +.global __sh_cas_gusa
17615 +.hidden __sh_cas_gusa
17634 +.global __sh_cas_llsc
17635 +.hidden __sh_cas_llsc
17651 +.global __sh_cas_imask
17652 +.hidden __sh_cas_imask
17668 +.global __sh_cas_cas_l
17669 +.hidden __sh_cas_cas_l
17672 + .word 0x2323 /* cas.l r2,r3,@r0 */
17673 --- a/src/thread/sh/syscall_cp.s
17674 +++ b/src/thread/sh/syscall_cp.s
17675 @@ -14,17 +14,8 @@ __syscall_cp_asm:
17687 -L1: .long __cancel@PLT-(1b-.)
17695 @@ -43,3 +34,12 @@ __cp_end:
17707 +2: .long __cancel@PCREL-(1b-.)
17708 --- a/src/thread/x32/syscall_cp.s
17709 +++ b/src/thread/x32/syscall_cp.s
17710 @@ -14,7 +14,7 @@ __syscall_cp_internal:
17719 @@ -27,3 +27,5 @@ __cp_begin:
17726 +++ b/src/thread/x32/syscall_cp_fixup.c
17728 +#include <sys/syscall.h>
17730 +__attribute__((__visibility__("hidden")))
17731 +long __syscall_cp_internal(volatile void*, long long, long long, long long, long long,
17732 + long long, long long, long long);
17734 +struct __timespec { long long tv_sec; long tv_nsec; };
17735 +struct __timespec_kernel { long long tv_sec; long long tv_nsec; };
17736 +#define __tsc(X) ((struct __timespec*)(unsigned long)(X))
17737 +#define __fixup(X) do { if(X) { \
17738 + ts->tv_sec = __tsc(X)->tv_sec; \
17739 + ts->tv_nsec = __tsc(X)->tv_nsec; \
17740 + (X) = (unsigned long)ts; } } while(0)
17742 +__attribute__((__visibility__("hidden")))
17743 +long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3,
17744 + long long a4, long long a5, long long a6)
17746 + struct __timespec_kernel ts[1];
17748 + case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6:
17752 + if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */)
17755 + case SYS_clock_nanosleep:
17756 + case SYS_rt_sigtimedwait: case SYS_ppoll:
17759 + case SYS_nanosleep:
17763 + return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6);
17766 --- a/src/thread/x86_64/syscall_cp.s
17767 +++ b/src/thread/x86_64/syscall_cp.s
17768 @@ -14,7 +14,7 @@ __syscall_cp_asm:
17777 @@ -27,3 +27,5 @@ __cp_begin:
17783 --- a/src/time/clock_gettime.c
17784 +++ b/src/time/clock_gettime.c
17787 #include "atomic.h"
17789 -static int sc_clock_gettime(clockid_t clk, struct timespec *ts)
17790 +#ifdef VDSO_CGT_SYM
17792 +void *__vdsosym(const char *, const char *);
17794 +static void *volatile vdso_func;
17796 +static int cgt_init(clockid_t clk, struct timespec *ts)
17798 - int r = __syscall(SYS_clock_gettime, clk, ts);
17799 - if (!r) return r;
17800 - if (r == -ENOSYS) {
17801 - if (clk == CLOCK_REALTIME) {
17802 - __syscall(SYS_gettimeofday, ts, 0);
17803 - ts->tv_nsec = (int)ts->tv_nsec * 1000;
17810 + void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
17811 + int (*f)(clockid_t, struct timespec *) =
17812 + (int (*)(clockid_t, struct timespec *))p;
17813 + a_cas_p(&vdso_func, (void *)cgt_init, p);
17814 + return f ? f(clk, ts) : -ENOSYS;
17817 -void *__vdsosym(const char *, const char *);
17818 +static void *volatile vdso_func = (void *)cgt_init;
17822 int __clock_gettime(clockid_t clk, struct timespec *ts)
17826 #ifdef VDSO_CGT_SYM
17827 - static int (*volatile cgt)(clockid_t, struct timespec *);
17829 - void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
17830 - if (!f) f = (void *)sc_clock_gettime;
17831 - a_cas_p(&cgt, 0, f);
17832 + int (*f)(clockid_t, struct timespec *) =
17833 + (int (*)(clockid_t, struct timespec *))vdso_func;
17836 + if (!r) return r;
17837 + if (r == -EINVAL) return __syscall_ret(r);
17838 + /* Fall through on errors other than EINVAL. Some buggy
17839 + * vdso implementations return ENOSYS for clocks they
17840 + * can't handle, rather than making the syscall. This
17841 + * also handles the case where cgt_init fails to find
17842 + * a vdso function to use. */
17844 - return cgt(clk, ts);
17846 - return sc_clock_gettime(clk, ts);
17849 + r = __syscall(SYS_clock_gettime, clk, ts);
17850 + if (r == -ENOSYS) {
17851 + if (clk == CLOCK_REALTIME) {
17852 + __syscall(SYS_gettimeofday, ts, 0);
17853 + ts->tv_nsec = (int)ts->tv_nsec * 1000;
17858 + return __syscall_ret(r);
17861 weak_alias(__clock_gettime, clock_gettime);