7e83869ca2efffea5973f92ee848ae1512431c91
[openwrt/openwrt.git] / toolchain / musl / patches / 000-update-to-git-2016-01-30.patch
1 --- a/.gitignore
2 +++ b/.gitignore
3 @@ -5,9 +5,6 @@
4 *.so.1
5 arch/*/bits/alltypes.h
6 config.mak
7 -include/bits
8 -tools/musl-gcc
9 -tools/musl-clang
10 -tools/ld.musl-clang
11 lib/musl-gcc.specs
12 src/internal/version.h
13 +/obj/
14 --- a/Makefile
15 +++ b/Makefile
16 @@ -8,6 +8,7 @@
17 # Do not make changes here.
18 #
19
20 +srcdir = .
21 exec_prefix = /usr/local
22 bindir = $(exec_prefix)/bin
23
24 @@ -16,31 +17,42 @@ includedir = $(prefix)/include
25 libdir = $(prefix)/lib
26 syslibdir = /lib
27
28 -SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
29 -OBJS = $(SRCS:.c=.o)
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))))
38 +AOBJS = $(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)
46
47 -LDFLAGS =
48 +LDFLAGS =
49 +LDFLAGS_AUTO =
50 LIBCC = -lgcc
51 CPPFLAGS =
52 -CFLAGS = -Os -pipe
53 +CFLAGS =
54 +CFLAGS_AUTO = -Os -pipe
55 CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
56
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)
64 +
65 +LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
66
67 AR = $(CROSS_COMPILE)ar
68 RANLIB = $(CROSS_COMPILE)ranlib
69 -INSTALL = ./tools/install.sh
70 +INSTALL = $(srcdir)/tools/install.sh
71
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/%))
78
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
87
88 WRAPCC_GCC = gcc
89 WRAPCC_CLANG = clang
90 @@ -58,122 +70,128 @@ LDSO_PATHNAME = $(syslibdir)/ld-musl-$(A
91
92 -include config.mak
93
94 +ifeq ($(ARCH),)
95 +$(error Please set ARCH in config.mak before running make.)
96 +endif
97 +
98 all: $(ALL_LIBS) $(ALL_TOOLS)
99
100 +OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(LDSO_OBJS) $(GENH) $(GENH_INT))) $(addprefix obj/, crt crt/$(ARCH) include))
101 +
102 +$(ALL_LIBS) $(ALL_TOOLS) $(CRT_LIBS:lib/%=obj/crt/%) $(OBJS) $(LOBJS) $(GENH) $(GENH_INT): | $(OBJ_DIRS)
103 +
104 +$(OBJ_DIRS):
105 + mkdir -p $@
106 +
107 install: install-libs install-headers install-tools
108
109 clean:
110 - rm -f crt/*.o
111 - rm -f $(OBJS)
112 - rm -f $(LOBJS)
113 - rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
114 - rm -f $(ALL_TOOLS)
115 - rm -f $(GENH) $(GENH_INT)
116 - rm -f include/bits
117 + rm -rf obj lib
118
119 distclean: clean
120 rm -f config.mak
121
122 -include/bits:
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 > $@
127
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)" > $@
131
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
135
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
139
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
142
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
145
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
148
149 -crt/rcrt1.o: src/ldso/dlstart.c
150 +obj/crt/$(ARCH)/crti.o: $(srcdir)/crt/$(ARCH)/crti.s
151
152 -crt/Scrt1.o crt/rcrt1.o: CFLAGS += -fPIC
153 +obj/crt/$(ARCH)/crtn.o: $(srcdir)/crt/$(ARCH)/crtn.s
154
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
159
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)
163
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)
176
177 -$(CRT_LIBS:lib/%=crt/%): CFLAGS += -DCRT
178 +$(CRT_LIBS:lib/%=obj/crt/%): CFLAGS_ALL += -DCRT
179
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.
183 -define mkasmdep
184 -$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
185 -endef
186 -$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
187 +$(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC
188 +
189 +CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $<
190
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 $@ -
196 else
197 - AS_CMD = $(CC) -c -o $@ $<
198 + AS_CMD = $(CC_CMD)
199 endif
200
201 -%.o: $(ARCH)$(ASMSUBARCH)/%.sub
202 - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
203 +obj/%.o: $(srcdir)/%.s
204 + $(AS_CMD)
205
206 -%.o: $(ARCH)/%.s
207 - $(AS_CMD) $(CFLAGS_ALL_STATIC)
208 +obj/%.o: $(srcdir)/%.S
209 + $(CC_CMD)
210
211 -%.o: %.c $(GENH) $(IMPH)
212 - $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
213 +obj/%.o: $(srcdir)/%.c $(GENH) $(IMPH)
214 + $(CC_CMD)
215
216 -%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
217 - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
218 +obj/%.lo: $(srcdir)/%.s
219 + $(AS_CMD)
220
221 -%.lo: $(ARCH)/%.s
222 - $(AS_CMD) $(CFLAGS_ALL_SHARED)
223 +obj/%.lo: $(srcdir)/%.S
224 + $(CC_CMD)
225
226 -%.lo: %.c $(GENH) $(IMPH)
227 - $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
228 +obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
229 + $(CC_CMD)
230
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)
238
239 -lib/libc.a: $(OBJS)
240 +lib/libc.a: $(AOBJS)
241 rm -f $@
242 - $(AR) rc $@ $(OBJS)
243 + $(AR) rc $@ $(AOBJS)
244 $(RANLIB) $@
245
246 $(EMPTY_LIBS):
247 rm -f $@
248 $(AR) rc $@
249
250 -lib/%.o: crt/%.o
251 +lib/%.o: obj/crt/%.o
252 cp $< $@
253
254 -lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
255 +lib/crti.o: obj/crt/$(ARCH)/crti.o
256 + cp $< $@
257 +
258 +lib/crtn.o: obj/crt/$(ARCH)/crtn.o
259 + cp $< $@
260 +
261 +lib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak
262 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
263
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)" > $@
267 chmod +x $@
268
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' $< > $@
272 chmod +x $@
273
274 -$(DESTDIR)$(bindir)/%: tools/%
275 +$(DESTDIR)$(bindir)/%: obj/%
276 $(INSTALL) -D $< $@
277
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 $< $@
282
283 -$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
284 +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/%
285 $(INSTALL) -D -m 644 $< $@
286
287 -$(DESTDIR)$(includedir)/%: include/%
288 +$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/generic/bits/%
289 + $(INSTALL) -D -m 644 $< $@
290 +
291 +$(DESTDIR)$(includedir)/bits/%: obj/include/bits/%
292 + $(INSTALL) -D -m 644 $< $@
293 +
294 +$(DESTDIR)$(includedir)/%: $(srcdir)/include/%
295 $(INSTALL) -D -m 644 $< $@
296
297 $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
298 @@ -195,12 +219,12 @@ install-libs: $(ALL_LIBS:lib/%=$(DESTDIR
299
300 install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
301
302 -install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
303 +install-tools: $(ALL_TOOLS:obj/%=$(DESTDIR)$(bindir)/%)
304
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,%,$@)
308
309 musl-%.tar.gz: .git
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,%,$@)
312
313 .PHONY: all clean install install-libs install-headers install-tools
314 --- a/arch/aarch64/atomic.h
315 +++ /dev/null
316 @@ -1,206 +0,0 @@
317 -#ifndef _INTERNAL_ATOMIC_H
318 -#define _INTERNAL_ATOMIC_H
319 -
320 -#include <stdint.h>
321 -
322 -static inline int a_ctz_64(uint64_t x)
323 -{
324 - __asm__(
325 - " rbit %0, %1\n"
326 - " clz %0, %0\n"
327 - : "=r"(x) : "r"(x));
328 - return x;
329 -}
330 -
331 -static inline int a_ctz_l(unsigned long x)
332 -{
333 - return a_ctz_64(x);
334 -}
335 -
336 -static inline void a_barrier()
337 -{
338 - __asm__ __volatile__("dmb ish");
339 -}
340 -
341 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
342 -{
343 - void *old;
344 - __asm__ __volatile__(
345 - " dmb ish\n"
346 - "1: ldxr %0,%3\n"
347 - " cmp %0,%1\n"
348 - " b.ne 1f\n"
349 - " stxr %w0,%2,%3\n"
350 - " cbnz %w0,1b\n"
351 - " mov %0,%1\n"
352 - "1: dmb ish\n"
353 - : "=&r"(old)
354 - : "r"(t), "r"(s), "Q"(*(long*)p)
355 - : "memory", "cc");
356 - return old;
357 -}
358 -
359 -static inline int a_cas(volatile int *p, int t, int s)
360 -{
361 - int old;
362 - __asm__ __volatile__(
363 - " dmb ish\n"
364 - "1: ldxr %w0,%3\n"
365 - " cmp %w0,%w1\n"
366 - " b.ne 1f\n"
367 - " stxr %w0,%w2,%3\n"
368 - " cbnz %w0,1b\n"
369 - " mov %w0,%w1\n"
370 - "1: dmb ish\n"
371 - : "=&r"(old)
372 - : "r"(t), "r"(s), "Q"(*p)
373 - : "memory", "cc");
374 - return old;
375 -}
376 -
377 -static inline int a_swap(volatile int *x, int v)
378 -{
379 - int old, tmp;
380 - __asm__ __volatile__(
381 - " dmb ish\n"
382 - "1: ldxr %w0,%3\n"
383 - " stxr %w1,%w2,%3\n"
384 - " cbnz %w1,1b\n"
385 - " dmb ish\n"
386 - : "=&r"(old), "=&r"(tmp)
387 - : "r"(v), "Q"(*x)
388 - : "memory", "cc" );
389 - return old;
390 -}
391 -
392 -static inline int a_fetch_add(volatile int *x, int v)
393 -{
394 - int old, tmp;
395 - __asm__ __volatile__(
396 - " dmb ish\n"
397 - "1: ldxr %w0,%3\n"
398 - " add %w0,%w0,%w2\n"
399 - " stxr %w1,%w0,%3\n"
400 - " cbnz %w1,1b\n"
401 - " dmb ish\n"
402 - : "=&r"(old), "=&r"(tmp)
403 - : "r"(v), "Q"(*x)
404 - : "memory", "cc" );
405 - return old-v;
406 -}
407 -
408 -static inline void a_inc(volatile int *x)
409 -{
410 - int tmp, tmp2;
411 - __asm__ __volatile__(
412 - " dmb ish\n"
413 - "1: ldxr %w0,%2\n"
414 - " add %w0,%w0,#1\n"
415 - " stxr %w1,%w0,%2\n"
416 - " cbnz %w1,1b\n"
417 - " dmb ish\n"
418 - : "=&r"(tmp), "=&r"(tmp2)
419 - : "Q"(*x)
420 - : "memory", "cc" );
421 -}
422 -
423 -static inline void a_dec(volatile int *x)
424 -{
425 - int tmp, tmp2;
426 - __asm__ __volatile__(
427 - " dmb ish\n"
428 - "1: ldxr %w0,%2\n"
429 - " sub %w0,%w0,#1\n"
430 - " stxr %w1,%w0,%2\n"
431 - " cbnz %w1,1b\n"
432 - " dmb ish\n"
433 - : "=&r"(tmp), "=&r"(tmp2)
434 - : "Q"(*x)
435 - : "memory", "cc" );
436 -}
437 -
438 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
439 -{
440 - int tmp, tmp2;
441 - __asm__ __volatile__(
442 - " dmb ish\n"
443 - "1: ldxr %0,%3\n"
444 - " and %0,%0,%2\n"
445 - " stxr %w1,%0,%3\n"
446 - " cbnz %w1,1b\n"
447 - " dmb ish\n"
448 - : "=&r"(tmp), "=&r"(tmp2)
449 - : "r"(v), "Q"(*p)
450 - : "memory", "cc" );
451 -}
452 -
453 -static inline void a_and(volatile int *p, int v)
454 -{
455 - int tmp, tmp2;
456 - __asm__ __volatile__(
457 - " dmb ish\n"
458 - "1: ldxr %w0,%3\n"
459 - " and %w0,%w0,%w2\n"
460 - " stxr %w1,%w0,%3\n"
461 - " cbnz %w1,1b\n"
462 - " dmb ish\n"
463 - : "=&r"(tmp), "=&r"(tmp2)
464 - : "r"(v), "Q"(*p)
465 - : "memory", "cc" );
466 -}
467 -
468 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
469 -{
470 - int tmp, tmp2;
471 - __asm__ __volatile__(
472 - " dmb ish\n"
473 - "1: ldxr %0,%3\n"
474 - " orr %0,%0,%2\n"
475 - " stxr %w1,%0,%3\n"
476 - " cbnz %w1,1b\n"
477 - " dmb ish\n"
478 - : "=&r"(tmp), "=&r"(tmp2)
479 - : "r"(v), "Q"(*p)
480 - : "memory", "cc" );
481 -}
482 -
483 -static inline void a_or_l(volatile void *p, long v)
484 -{
485 - return a_or_64(p, v);
486 -}
487 -
488 -static inline void a_or(volatile int *p, int v)
489 -{
490 - int tmp, tmp2;
491 - __asm__ __volatile__(
492 - " dmb ish\n"
493 - "1: ldxr %w0,%3\n"
494 - " orr %w0,%w0,%w2\n"
495 - " stxr %w1,%w0,%3\n"
496 - " cbnz %w1,1b\n"
497 - " dmb ish\n"
498 - : "=&r"(tmp), "=&r"(tmp2)
499 - : "r"(v), "Q"(*p)
500 - : "memory", "cc" );
501 -}
502 -
503 -static inline void a_store(volatile int *p, int x)
504 -{
505 - __asm__ __volatile__(
506 - " dmb ish\n"
507 - " str %w1,%0\n"
508 - " dmb ish\n"
509 - : "=m"(*p)
510 - : "r"(x)
511 - : "memory", "cc" );
512 -}
513 -
514 -#define a_spin a_barrier
515 -
516 -static inline void a_crash()
517 -{
518 - *(volatile char *)0=0;
519 -}
520 -
521 -
522 -#endif
523 --- /dev/null
524 +++ b/arch/aarch64/atomic_arch.h
525 @@ -0,0 +1,73 @@
526 +#define a_ll a_ll
527 +static inline int a_ll(volatile int *p)
528 +{
529 + int v;
530 + __asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p));
531 + return v;
532 +}
533 +
534 +#define a_sc a_sc
535 +static inline int a_sc(volatile int *p, int v)
536 +{
537 + int r;
538 + __asm__ __volatile__ ("stlxr %w0,%w1,%2" : "=&r"(r) : "r"(v), "Q"(*p) : "memory");
539 + return !r;
540 +}
541 +
542 +#define a_barrier a_barrier
543 +static inline void a_barrier()
544 +{
545 + __asm__ __volatile__ ("dmb ish" : : : "memory");
546 +}
547 +
548 +#define a_cas a_cas
549 +static inline int a_cas(volatile int *p, int t, int s)
550 +{
551 + int old;
552 + do {
553 + old = a_ll(p);
554 + if (old != t) {
555 + a_barrier();
556 + break;
557 + }
558 + } while (!a_sc(p, s));
559 + return old;
560 +}
561 +
562 +static inline void *a_ll_p(volatile void *p)
563 +{
564 + void *v;
565 + __asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *)p));
566 + return v;
567 +}
568 +
569 +static inline int a_sc_p(volatile int *p, void *v)
570 +{
571 + int r;
572 + __asm__ __volatile__ ("stlxr %w0,%1,%2" : "=&r"(r) : "r"(v), "Q"(*(void *volatile *)p) : "memory");
573 + return !r;
574 +}
575 +
576 +#define a_cas_p a_cas_p
577 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
578 +{
579 + void *old;
580 + do {
581 + old = a_ll_p(p);
582 + if (old != t) {
583 + a_barrier();
584 + break;
585 + }
586 + } while (!a_sc_p(p, s));
587 + return old;
588 +}
589 +
590 +#define a_ctz_64 a_ctz_64
591 +static inline int a_ctz_64(uint64_t x)
592 +{
593 + __asm__(
594 + " rbit %0, %1\n"
595 + " clz %0, %0\n"
596 + : "=r"(x) : "r"(x));
597 + return x;
598 +}
599 --- a/arch/aarch64/bits/errno.h
600 +++ /dev/null
601 @@ -1,134 +0,0 @@
602 -#define EPERM 1
603 -#define ENOENT 2
604 -#define ESRCH 3
605 -#define EINTR 4
606 -#define EIO 5
607 -#define ENXIO 6
608 -#define E2BIG 7
609 -#define ENOEXEC 8
610 -#define EBADF 9
611 -#define ECHILD 10
612 -#define EAGAIN 11
613 -#define ENOMEM 12
614 -#define EACCES 13
615 -#define EFAULT 14
616 -#define ENOTBLK 15
617 -#define EBUSY 16
618 -#define EEXIST 17
619 -#define EXDEV 18
620 -#define ENODEV 19
621 -#define ENOTDIR 20
622 -#define EISDIR 21
623 -#define EINVAL 22
624 -#define ENFILE 23
625 -#define EMFILE 24
626 -#define ENOTTY 25
627 -#define ETXTBSY 26
628 -#define EFBIG 27
629 -#define ENOSPC 28
630 -#define ESPIPE 29
631 -#define EROFS 30
632 -#define EMLINK 31
633 -#define EPIPE 32
634 -#define EDOM 33
635 -#define ERANGE 34
636 -#define EDEADLK 35
637 -#define ENAMETOOLONG 36
638 -#define ENOLCK 37
639 -#define ENOSYS 38
640 -#define ENOTEMPTY 39
641 -#define ELOOP 40
642 -#define EWOULDBLOCK EAGAIN
643 -#define ENOMSG 42
644 -#define EIDRM 43
645 -#define ECHRNG 44
646 -#define EL2NSYNC 45
647 -#define EL3HLT 46
648 -#define EL3RST 47
649 -#define ELNRNG 48
650 -#define EUNATCH 49
651 -#define ENOCSI 50
652 -#define EL2HLT 51
653 -#define EBADE 52
654 -#define EBADR 53
655 -#define EXFULL 54
656 -#define ENOANO 55
657 -#define EBADRQC 56
658 -#define EBADSLT 57
659 -#define EDEADLOCK EDEADLK
660 -#define EBFONT 59
661 -#define ENOSTR 60
662 -#define ENODATA 61
663 -#define ETIME 62
664 -#define ENOSR 63
665 -#define ENONET 64
666 -#define ENOPKG 65
667 -#define EREMOTE 66
668 -#define ENOLINK 67
669 -#define EADV 68
670 -#define ESRMNT 69
671 -#define ECOMM 70
672 -#define EPROTO 71
673 -#define EMULTIHOP 72
674 -#define EDOTDOT 73
675 -#define EBADMSG 74
676 -#define EOVERFLOW 75
677 -#define ENOTUNIQ 76
678 -#define EBADFD 77
679 -#define EREMCHG 78
680 -#define ELIBACC 79
681 -#define ELIBBAD 80
682 -#define ELIBSCN 81
683 -#define ELIBMAX 82
684 -#define ELIBEXEC 83
685 -#define EILSEQ 84
686 -#define ERESTART 85
687 -#define ESTRPIPE 86
688 -#define EUSERS 87
689 -#define ENOTSOCK 88
690 -#define EDESTADDRREQ 89
691 -#define EMSGSIZE 90
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
707 -#define ENOBUFS 105
708 -#define EISCONN 106
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
718 -#define ESTALE 116
719 -#define EUCLEAN 117
720 -#define ENOTNAM 118
721 -#define ENAVAIL 119
722 -#define EISNAM 120
723 -#define EREMOTEIO 121
724 -#define EDQUOT 122
725 -#define ENOMEDIUM 123
726 -#define EMEDIUMTYPE 124
727 -#define ECANCELED 125
728 -#define ENOKEY 126
729 -#define EKEYEXPIRED 127
730 -#define EKEYREVOKED 128
731 -#define EKEYREJECTED 129
732 -#define EOWNERDEAD 130
733 -#define ENOTRECOVERABLE 131
734 -#define ERFKILL 132
735 -#define EHWPOISON 133
736 --- a/arch/aarch64/bits/mman.h
737 +++ b/arch/aarch64/bits/mman.h
738 @@ -36,6 +36,7 @@
739
740 #define MCL_CURRENT 1
741 #define MCL_FUTURE 2
742 +#define MCL_ONFAULT 4
743
744 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
745 #define MADV_NORMAL 0
746 --- a/arch/aarch64/bits/statfs.h
747 +++ /dev/null
748 @@ -1,7 +0,0 @@
749 -struct statfs {
750 - unsigned long f_type, f_bsize;
751 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
752 - fsfilcnt_t f_files, f_ffree;
753 - fsid_t f_fsid;
754 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
755 -};
756 --- a/arch/aarch64/bits/stdarg.h
757 +++ /dev/null
758 @@ -1,4 +0,0 @@
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
765 @@ -265,6 +265,9 @@
766 #define __NR_memfd_create 279
767 #define __NR_bpf 280
768 #define __NR_execveat 281
769 +#define __NR_userfaultfd 282
770 +#define __NR_membarrier 283
771 +#define __NR_mlock2 284
772
773 #define SYS_io_setup __NR_io_setup
774 #define SYS_io_destroy __NR_io_destroy
775 @@ -533,3 +536,6 @@
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
783 +++ /dev/null
784 @@ -1,160 +0,0 @@
785 -struct termios
786 -{
787 - tcflag_t c_iflag;
788 - tcflag_t c_oflag;
789 - tcflag_t c_cflag;
790 - tcflag_t c_lflag;
791 - cc_t c_line;
792 - cc_t c_cc[NCCS];
793 - speed_t __c_ispeed;
794 - speed_t __c_ospeed;
795 -};
796 -
797 -#define VINTR 0
798 -#define VQUIT 1
799 -#define VERASE 2
800 -#define VKILL 3
801 -#define VEOF 4
802 -#define VTIME 5
803 -#define VMIN 6
804 -#define VSWTC 7
805 -#define VSTART 8
806 -#define VSTOP 9
807 -#define VSUSP 10
808 -#define VEOL 11
809 -#define VREPRINT 12
810 -#define VDISCARD 13
811 -#define VWERASE 14
812 -#define VLNEXT 15
813 -#define VEOL2 16
814 -
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
830 -
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
840 -#define NL0 0000000
841 -#define NL1 0000400
842 -#define CRDLY 0003000
843 -#define CR0 0000000
844 -#define CR1 0001000
845 -#define CR2 0002000
846 -#define CR3 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
853 -#define BS0 0000000
854 -#define BS1 0020000
855 -#define FFDLY 0100000
856 -#define FF0 0000000
857 -#define FF1 0100000
858 -
859 -#define VTDLY 0040000
860 -#define VT0 0000000
861 -#define VT1 0040000
862 -
863 -#define B0 0000000
864 -#define B50 0000001
865 -#define B75 0000002
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
879 -
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
895 -
896 -#define CBAUD 0010017
897 -
898 -#define CSIZE 0000060
899 -#define CS5 0000000
900 -#define CS6 0000020
901 -#define CS7 0000040
902 -#define CS8 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
909 -
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
919 -
920 -#define ECHOCTL 0001000
921 -#define ECHOPRT 0002000
922 -#define ECHOKE 0004000
923 -#define FLUSHO 0010000
924 -#define PENDIN 0040000
925 -
926 -#define TCOOFF 0
927 -#define TCOON 1
928 -#define TCIOFF 2
929 -#define TCION 3
930 -
931 -#define TCIFLUSH 0
932 -#define TCOFLUSH 1
933 -#define TCIOFLUSH 2
934 -
935 -#define TCSANOW 0
936 -#define TCSADRAIN 1
937 -#define TCSAFLUSH 2
938 -
939 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
940 -#define CBAUDEX 0010000
941 -#define CRTSCTS 020000000000
942 -#define EXTPROC 0200000
943 -#define XTABS 0014000
944 -#endif
945 --- a/arch/aarch64/pthread_arch.h
946 +++ b/arch/aarch64/pthread_arch.h
947 @@ -8,4 +8,4 @@ static inline struct pthread *__pthread_
948 #define TLS_ABOVE_TP
949 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 16)
950
951 -#define CANCEL_REG_IP 33
952 +#define MC_PC pc
953 --- a/arch/arm/atomic.h
954 +++ /dev/null
955 @@ -1,261 +0,0 @@
956 -#ifndef _INTERNAL_ATOMIC_H
957 -#define _INTERNAL_ATOMIC_H
958 -
959 -#include <stdint.h>
960 -
961 -static inline int a_ctz_l(unsigned long x)
962 -{
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
966 - };
967 - return debruijn32[(x&-x)*0x076be629 >> 27];
968 -}
969 -
970 -static inline int a_ctz_64(uint64_t x)
971 -{
972 - uint32_t y = x;
973 - if (!y) {
974 - y = x>>32;
975 - return 32 + a_ctz_l(y);
976 - }
977 - return a_ctz_l(y);
978 -}
979 -
980 -#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
981 -
982 -static inline void a_barrier()
983 -{
984 - __asm__ __volatile__("dmb ish");
985 -}
986 -
987 -static inline int a_cas(volatile int *p, int t, int s)
988 -{
989 - int old;
990 - __asm__ __volatile__(
991 - " dmb ish\n"
992 - "1: ldrex %0,%3\n"
993 - " cmp %0,%1\n"
994 - " bne 1f\n"
995 - " strex %0,%2,%3\n"
996 - " cmp %0, #0\n"
997 - " bne 1b\n"
998 - " mov %0, %1\n"
999 - "1: dmb ish\n"
1000 - : "=&r"(old)
1001 - : "r"(t), "r"(s), "Q"(*p)
1002 - : "memory", "cc" );
1003 - return old;
1004 -}
1005 -
1006 -static inline int a_swap(volatile int *x, int v)
1007 -{
1008 - int old, tmp;
1009 - __asm__ __volatile__(
1010 - " dmb ish\n"
1011 - "1: ldrex %0,%3\n"
1012 - " strex %1,%2,%3\n"
1013 - " cmp %1, #0\n"
1014 - " bne 1b\n"
1015 - " dmb ish\n"
1016 - : "=&r"(old), "=&r"(tmp)
1017 - : "r"(v), "Q"(*x)
1018 - : "memory", "cc" );
1019 - return old;
1020 -}
1021 -
1022 -static inline int a_fetch_add(volatile int *x, int v)
1023 -{
1024 - int old, tmp;
1025 - __asm__ __volatile__(
1026 - " dmb ish\n"
1027 - "1: ldrex %0,%3\n"
1028 - " add %0,%0,%2\n"
1029 - " strex %1,%0,%3\n"
1030 - " cmp %1, #0\n"
1031 - " bne 1b\n"
1032 - " dmb ish\n"
1033 - : "=&r"(old), "=&r"(tmp)
1034 - : "r"(v), "Q"(*x)
1035 - : "memory", "cc" );
1036 - return old-v;
1037 -}
1038 -
1039 -static inline void a_inc(volatile int *x)
1040 -{
1041 - int tmp, tmp2;
1042 - __asm__ __volatile__(
1043 - " dmb ish\n"
1044 - "1: ldrex %0,%2\n"
1045 - " add %0,%0,#1\n"
1046 - " strex %1,%0,%2\n"
1047 - " cmp %1, #0\n"
1048 - " bne 1b\n"
1049 - " dmb ish\n"
1050 - : "=&r"(tmp), "=&r"(tmp2)
1051 - : "Q"(*x)
1052 - : "memory", "cc" );
1053 -}
1054 -
1055 -static inline void a_dec(volatile int *x)
1056 -{
1057 - int tmp, tmp2;
1058 - __asm__ __volatile__(
1059 - " dmb ish\n"
1060 - "1: ldrex %0,%2\n"
1061 - " sub %0,%0,#1\n"
1062 - " strex %1,%0,%2\n"
1063 - " cmp %1, #0\n"
1064 - " bne 1b\n"
1065 - " dmb ish\n"
1066 - : "=&r"(tmp), "=&r"(tmp2)
1067 - : "Q"(*x)
1068 - : "memory", "cc" );
1069 -}
1070 -
1071 -static inline void a_and(volatile int *x, int v)
1072 -{
1073 - int tmp, tmp2;
1074 - __asm__ __volatile__(
1075 - " dmb ish\n"
1076 - "1: ldrex %0,%3\n"
1077 - " and %0,%0,%2\n"
1078 - " strex %1,%0,%3\n"
1079 - " cmp %1, #0\n"
1080 - " bne 1b\n"
1081 - " dmb ish\n"
1082 - : "=&r"(tmp), "=&r"(tmp2)
1083 - : "r"(v), "Q"(*x)
1084 - : "memory", "cc" );
1085 -}
1086 -
1087 -static inline void a_or(volatile int *x, int v)
1088 -{
1089 - int tmp, tmp2;
1090 - __asm__ __volatile__(
1091 - " dmb ish\n"
1092 - "1: ldrex %0,%3\n"
1093 - " orr %0,%0,%2\n"
1094 - " strex %1,%0,%3\n"
1095 - " cmp %1, #0\n"
1096 - " bne 1b\n"
1097 - " dmb ish\n"
1098 - : "=&r"(tmp), "=&r"(tmp2)
1099 - : "r"(v), "Q"(*x)
1100 - : "memory", "cc" );
1101 -}
1102 -
1103 -static inline void a_store(volatile int *p, int x)
1104 -{
1105 - __asm__ __volatile__(
1106 - " dmb ish\n"
1107 - " str %1,%0\n"
1108 - " dmb ish\n"
1109 - : "=m"(*p)
1110 - : "r"(x)
1111 - : "memory", "cc" );
1112 -}
1113 -
1114 -#else
1115 -
1116 -int __a_cas(int, int, volatile int *) __attribute__((__visibility__("hidden")));
1117 -#define __k_cas __a_cas
1118 -
1119 -static inline void a_barrier()
1120 -{
1121 - __asm__ __volatile__("bl __a_barrier"
1122 - : : : "memory", "cc", "ip", "lr" );
1123 -}
1124 -
1125 -static inline int a_cas(volatile int *p, int t, int s)
1126 -{
1127 - int old;
1128 - for (;;) {
1129 - if (!__k_cas(t, s, p))
1130 - return t;
1131 - if ((old=*p) != t)
1132 - return old;
1133 - }
1134 -}
1135 -
1136 -static inline int a_swap(volatile int *x, int v)
1137 -{
1138 - int old;
1139 - do old = *x;
1140 - while (__k_cas(old, v, x));
1141 - return old;
1142 -}
1143 -
1144 -static inline int a_fetch_add(volatile int *x, int v)
1145 -{
1146 - int old;
1147 - do old = *x;
1148 - while (__k_cas(old, old+v, x));
1149 - return old;
1150 -}
1151 -
1152 -static inline void a_inc(volatile int *x)
1153 -{
1154 - a_fetch_add(x, 1);
1155 -}
1156 -
1157 -static inline void a_dec(volatile int *x)
1158 -{
1159 - a_fetch_add(x, -1);
1160 -}
1161 -
1162 -static inline void a_store(volatile int *p, int x)
1163 -{
1164 - a_barrier();
1165 - *p = x;
1166 - a_barrier();
1167 -}
1168 -
1169 -static inline void a_and(volatile int *p, int v)
1170 -{
1171 - int old;
1172 - do old = *p;
1173 - while (__k_cas(old, old&v, p));
1174 -}
1175 -
1176 -static inline void a_or(volatile int *p, int v)
1177 -{
1178 - int old;
1179 - do old = *p;
1180 - while (__k_cas(old, old|v, p));
1181 -}
1182 -
1183 -#endif
1184 -
1185 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
1186 -{
1187 - return (void *)a_cas(p, (int)t, (int)s);
1188 -}
1189 -
1190 -#define a_spin a_barrier
1191 -
1192 -static inline void a_crash()
1193 -{
1194 - *(volatile char *)0=0;
1195 -}
1196 -
1197 -static inline void a_or_l(volatile void *p, long v)
1198 -{
1199 - a_or(p, v);
1200 -}
1201 -
1202 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
1203 -{
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]);
1207 -}
1208 -
1209 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
1210 -{
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]);
1214 -}
1215 -
1216 -#endif
1217 --- /dev/null
1218 +++ b/arch/arm/atomic_arch.h
1219 @@ -0,0 +1,76 @@
1220 +__attribute__((__visibility__("hidden")))
1221 +extern const void *__arm_atomics[3]; /* gettp, cas, barrier */
1222 +
1223 +#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
1224 + || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
1225 +
1226 +#define a_ll a_ll
1227 +static inline int a_ll(volatile int *p)
1228 +{
1229 + int v;
1230 + __asm__ __volatile__ ("ldrex %0, %1" : "=r"(v) : "Q"(*p));
1231 + return v;
1232 +}
1233 +
1234 +#define a_sc a_sc
1235 +static inline int a_sc(volatile int *p, int v)
1236 +{
1237 + int r;
1238 + __asm__ __volatile__ ("strex %0,%1,%2" : "=&r"(r) : "r"(v), "Q"(*p) : "memory");
1239 + return !r;
1240 +}
1241 +
1242 +#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
1243 +
1244 +#define a_barrier a_barrier
1245 +static inline void a_barrier()
1246 +{
1247 + __asm__ __volatile__ ("dmb ish" : : : "memory");
1248 +}
1249 +
1250 +#endif
1251 +
1252 +#define a_pre_llsc a_barrier
1253 +#define a_post_llsc a_barrier
1254 +
1255 +#else
1256 +
1257 +#define a_cas a_cas
1258 +static inline int a_cas(volatile int *p, int t, int s)
1259 +{
1260 + for (;;) {
1261 + register int r0 __asm__("r0") = t;
1262 + register int r1 __asm__("r1") = s;
1263 + register volatile int *r2 __asm__("r2") = p;
1264 + int old;
1265 + __asm__ __volatile__ (
1266 + "bl __a_cas"
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;
1271 + }
1272 +}
1273 +
1274 +#endif
1275 +
1276 +#ifndef a_barrier
1277 +#define a_barrier a_barrier
1278 +static inline void a_barrier()
1279 +{
1280 + __asm__ __volatile__("bl __a_barrier"
1281 + : : : "memory", "cc", "ip", "lr" );
1282 +}
1283 +#endif
1284 +
1285 +#define a_crash a_crash
1286 +static inline void a_crash()
1287 +{
1288 + __asm__ __volatile__(
1289 +#ifndef __thumb__
1290 + ".word 0xe7f000f0"
1291 +#else
1292 + ".short 0xdeff"
1293 +#endif
1294 + : : : "memory");
1295 +}
1296 --- a/arch/arm/bits/errno.h
1297 +++ /dev/null
1298 @@ -1,134 +0,0 @@
1299 -#define EPERM 1
1300 -#define ENOENT 2
1301 -#define ESRCH 3
1302 -#define EINTR 4
1303 -#define EIO 5
1304 -#define ENXIO 6
1305 -#define E2BIG 7
1306 -#define ENOEXEC 8
1307 -#define EBADF 9
1308 -#define ECHILD 10
1309 -#define EAGAIN 11
1310 -#define ENOMEM 12
1311 -#define EACCES 13
1312 -#define EFAULT 14
1313 -#define ENOTBLK 15
1314 -#define EBUSY 16
1315 -#define EEXIST 17
1316 -#define EXDEV 18
1317 -#define ENODEV 19
1318 -#define ENOTDIR 20
1319 -#define EISDIR 21
1320 -#define EINVAL 22
1321 -#define ENFILE 23
1322 -#define EMFILE 24
1323 -#define ENOTTY 25
1324 -#define ETXTBSY 26
1325 -#define EFBIG 27
1326 -#define ENOSPC 28
1327 -#define ESPIPE 29
1328 -#define EROFS 30
1329 -#define EMLINK 31
1330 -#define EPIPE 32
1331 -#define EDOM 33
1332 -#define ERANGE 34
1333 -#define EDEADLK 35
1334 -#define ENAMETOOLONG 36
1335 -#define ENOLCK 37
1336 -#define ENOSYS 38
1337 -#define ENOTEMPTY 39
1338 -#define ELOOP 40
1339 -#define EWOULDBLOCK EAGAIN
1340 -#define ENOMSG 42
1341 -#define EIDRM 43
1342 -#define ECHRNG 44
1343 -#define EL2NSYNC 45
1344 -#define EL3HLT 46
1345 -#define EL3RST 47
1346 -#define ELNRNG 48
1347 -#define EUNATCH 49
1348 -#define ENOCSI 50
1349 -#define EL2HLT 51
1350 -#define EBADE 52
1351 -#define EBADR 53
1352 -#define EXFULL 54
1353 -#define ENOANO 55
1354 -#define EBADRQC 56
1355 -#define EBADSLT 57
1356 -#define EDEADLOCK EDEADLK
1357 -#define EBFONT 59
1358 -#define ENOSTR 60
1359 -#define ENODATA 61
1360 -#define ETIME 62
1361 -#define ENOSR 63
1362 -#define ENONET 64
1363 -#define ENOPKG 65
1364 -#define EREMOTE 66
1365 -#define ENOLINK 67
1366 -#define EADV 68
1367 -#define ESRMNT 69
1368 -#define ECOMM 70
1369 -#define EPROTO 71
1370 -#define EMULTIHOP 72
1371 -#define EDOTDOT 73
1372 -#define EBADMSG 74
1373 -#define EOVERFLOW 75
1374 -#define ENOTUNIQ 76
1375 -#define EBADFD 77
1376 -#define EREMCHG 78
1377 -#define ELIBACC 79
1378 -#define ELIBBAD 80
1379 -#define ELIBSCN 81
1380 -#define ELIBMAX 82
1381 -#define ELIBEXEC 83
1382 -#define EILSEQ 84
1383 -#define ERESTART 85
1384 -#define ESTRPIPE 86
1385 -#define EUSERS 87
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
1415 -#define ESTALE 116
1416 -#define EUCLEAN 117
1417 -#define ENOTNAM 118
1418 -#define ENAVAIL 119
1419 -#define EISNAM 120
1420 -#define EREMOTEIO 121
1421 -#define EDQUOT 122
1422 -#define ENOMEDIUM 123
1423 -#define EMEDIUMTYPE 124
1424 -#define ECANCELED 125
1425 -#define ENOKEY 126
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
1434 +++ /dev/null
1435 @@ -1,197 +0,0 @@
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
1440 -
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))
1445 -
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
1494 -
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
1507 -
1508 -#define TIOCMIWAIT 0x545C
1509 -#define TIOCGICOUNT 0x545D
1510 -#define TIOCGHAYESESP 0x545E
1511 -#define TIOCSHAYESESP 0x545F
1512 -#define FIOQSIZE 0x5460
1513 -
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
1522 -
1523 -#define TIOCSER_TEMT 0x01
1524 -
1525 -struct winsize {
1526 - unsigned short ws_row;
1527 - unsigned short ws_col;
1528 - unsigned short ws_xpixel;
1529 - unsigned short ws_ypixel;
1530 -};
1531 -
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
1547 -
1548 -#define N_TTY 0
1549 -#define N_SLIP 1
1550 -#define N_MOUSE 2
1551 -#define N_PPP 3
1552 -#define N_STRIP 4
1553 -#define N_AX25 5
1554 -#define N_X25 6
1555 -#define N_6PACK 7
1556 -#define N_MASC 8
1557 -#define N_R3964 9
1558 -#define N_PROFIBUS_FDL 10
1559 -#define N_IRDA 11
1560 -#define N_SMSBLOCK 12
1561 -#define N_HDLC 13
1562 -#define N_SYNC_PPP 14
1563 -#define N_HCI 15
1564 -
1565 -#define FIOSETOWN 0x8901
1566 -#define SIOCSPGRP 0x8902
1567 -#define FIOGETOWN 0x8903
1568 -#define SIOCGPGRP 0x8904
1569 -#define SIOCATMARK 0x8905
1570 -#define SIOCGSTAMP 0x8906
1571 -
1572 -#define SIOCADDRT 0x890B
1573 -#define SIOCDELRT 0x890C
1574 -#define SIOCRTMSG 0x890D
1575 -
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
1610 -
1611 -#define SIOCGIFBR 0x8940
1612 -#define SIOCSIFBR 0x8941
1613 -
1614 -#define SIOCGIFTXQLEN 0x8942
1615 -#define SIOCSIFTXQLEN 0x8943
1616 -
1617 -#define SIOCDARP 0x8953
1618 -#define SIOCGARP 0x8954
1619 -#define SIOCSARP 0x8955
1620 -
1621 -#define SIOCDRARP 0x8960
1622 -#define SIOCGRARP 0x8961
1623 -#define SIOCSRARP 0x8962
1624 -
1625 -#define SIOCGIFMAP 0x8970
1626 -#define SIOCSIFMAP 0x8971
1627 -
1628 -#define SIOCADDDLCI 0x8980
1629 -#define SIOCDELDLCI 0x8981
1630 -
1631 -#define SIOCDEVPRIVATE 0x89F0
1632 -#define SIOCPROTOPRIVATE 0x89E0
1633 --- a/arch/arm/bits/ipc.h
1634 +++ /dev/null
1635 @@ -1,14 +0,0 @@
1636 -struct ipc_perm
1637 -{
1638 - key_t __ipc_perm_key;
1639 - uid_t uid;
1640 - gid_t gid;
1641 - uid_t cuid;
1642 - gid_t cgid;
1643 - mode_t mode;
1644 - int __ipc_perm_seq;
1645 - long __pad1;
1646 - long __pad2;
1647 -};
1648 -
1649 -#define IPC_64 0x100
1650 --- a/arch/arm/bits/mman.h
1651 +++ b/arch/arm/bits/mman.h
1652 @@ -37,6 +37,7 @@
1653
1654 #define MCL_CURRENT 1
1655 #define MCL_FUTURE 2
1656 +#define MCL_ONFAULT 4
1657
1658 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
1659 #define MADV_NORMAL 0
1660 --- a/arch/arm/bits/msg.h
1661 +++ /dev/null
1662 @@ -1,16 +0,0 @@
1663 -struct msqid_ds
1664 -{
1665 - struct ipc_perm msg_perm;
1666 - time_t msg_stime;
1667 - int __unused1;
1668 - time_t msg_rtime;
1669 - int __unused2;
1670 - time_t msg_ctime;
1671 - int __unused3;
1672 - unsigned long msg_cbytes;
1673 - msgqnum_t msg_qnum;
1674 - msglen_t msg_qbytes;
1675 - pid_t msg_lspid;
1676 - pid_t msg_lrpid;
1677 - unsigned long __unused[2];
1678 -};
1679 --- a/arch/arm/bits/sem.h
1680 +++ /dev/null
1681 @@ -1,16 +0,0 @@
1682 -struct semid_ds {
1683 - struct ipc_perm sem_perm;
1684 - time_t sem_otime;
1685 - time_t __unused1;
1686 - time_t sem_ctime;
1687 - time_t __unused2;
1688 -#if __BYTE_ORDER == __LITTLE_ENDIAN
1689 - unsigned short sem_nsems;
1690 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
1691 -#else
1692 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
1693 - unsigned short sem_nsems;
1694 -#endif
1695 - time_t __unused3;
1696 - time_t __unused4;
1697 -};
1698 --- a/arch/arm/bits/shm.h
1699 +++ /dev/null
1700 @@ -1,29 +0,0 @@
1701 -#define SHMLBA 4096
1702 -
1703 -struct shmid_ds
1704 -{
1705 - struct ipc_perm shm_perm;
1706 - size_t shm_segsz;
1707 - time_t shm_atime;
1708 - int __unused1;
1709 - time_t shm_dtime;
1710 - int __unused2;
1711 - time_t shm_ctime;
1712 - int __unused3;
1713 - pid_t shm_cpid;
1714 - pid_t shm_lpid;
1715 - unsigned long shm_nattch;
1716 - unsigned long __pad1;
1717 - unsigned long __pad2;
1718 -};
1719 -
1720 -struct shminfo {
1721 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
1722 -};
1723 -
1724 -struct shm_info {
1725 - int __used_ids;
1726 - unsigned long shm_tot, shm_rss, shm_swp;
1727 - unsigned long __swap_attempts, __swap_successes;
1728 -};
1729 -
1730 --- a/arch/arm/bits/socket.h
1731 +++ /dev/null
1732 @@ -1,17 +0,0 @@
1733 -struct msghdr
1734 -{
1735 - void *msg_name;
1736 - socklen_t msg_namelen;
1737 - struct iovec *msg_iov;
1738 - int msg_iovlen;
1739 - void *msg_control;
1740 - socklen_t msg_controllen;
1741 - int msg_flags;
1742 -};
1743 -
1744 -struct cmsghdr
1745 -{
1746 - socklen_t cmsg_len;
1747 - int cmsg_level;
1748 - int cmsg_type;
1749 -};
1750 --- a/arch/arm/bits/statfs.h
1751 +++ /dev/null
1752 @@ -1,7 +0,0 @@
1753 -struct statfs {
1754 - unsigned long f_type, f_bsize;
1755 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
1756 - fsfilcnt_t f_files, f_ffree;
1757 - fsid_t f_fsid;
1758 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
1759 -};
1760 --- a/arch/arm/bits/stdarg.h
1761 +++ /dev/null
1762 @@ -1,4 +0,0 @@
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
1769 @@ -341,6 +341,9 @@
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
1776
1777 #define __ARM_NR_breakpoint 0x0f0001
1778 #define __ARM_NR_cacheflush 0x0f0002
1779 @@ -693,3 +696,6 @@
1780 #define SYS_memfd_create 385
1781 #define SYS_bpf 386
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
1787 +++ /dev/null
1788 @@ -1,160 +0,0 @@
1789 -struct termios
1790 -{
1791 - tcflag_t c_iflag;
1792 - tcflag_t c_oflag;
1793 - tcflag_t c_cflag;
1794 - tcflag_t c_lflag;
1795 - cc_t c_line;
1796 - cc_t c_cc[NCCS];
1797 - speed_t __c_ispeed;
1798 - speed_t __c_ospeed;
1799 -};
1800 -
1801 -#define VINTR 0
1802 -#define VQUIT 1
1803 -#define VERASE 2
1804 -#define VKILL 3
1805 -#define VEOF 4
1806 -#define VTIME 5
1807 -#define VMIN 6
1808 -#define VSWTC 7
1809 -#define VSTART 8
1810 -#define VSTOP 9
1811 -#define VSUSP 10
1812 -#define VEOL 11
1813 -#define VREPRINT 12
1814 -#define VDISCARD 13
1815 -#define VWERASE 14
1816 -#define VLNEXT 15
1817 -#define VEOL2 16
1818 -
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
1834 -
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
1862 -
1863 -#define VTDLY 0040000
1864 -#define VT0 0000000
1865 -#define VT1 0040000
1866 -
1867 -#define B0 0000000
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
1883 -
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
1899 -
1900 -#define CBAUD 0010017
1901 -
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
1913 -
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
1923 -
1924 -#define ECHOCTL 0001000
1925 -#define ECHOPRT 0002000
1926 -#define ECHOKE 0004000
1927 -#define FLUSHO 0010000
1928 -#define PENDIN 0040000
1929 -
1930 -#define TCOOFF 0
1931 -#define TCOON 1
1932 -#define TCIOFF 2
1933 -#define TCION 3
1934 -
1935 -#define TCIFLUSH 0
1936 -#define TCOFLUSH 1
1937 -#define TCIOFLUSH 2
1938 -
1939 -#define TCSANOW 0
1940 -#define TCSADRAIN 1
1941 -#define TCSAFLUSH 2
1942 -
1943 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
1944 -#define CBAUDEX 0010000
1945 -#define CRTSCTS 020000000000
1946 -#define EXTPROC 0200000
1947 -#define XTABS 0014000
1948 -#endif
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)
1954
1955 -#define CANCEL_REG_IP 18
1956 +#define MC_PC arm_pc
1957 --- a/arch/arm/reloc.h
1958 +++ b/arch/arm/reloc.h
1959 @@ -6,10 +6,10 @@
1960 #define ENDIAN_SUFFIX ""
1961 #endif
1962
1963 -#if __SOFTFP__
1964 -#define FP_SUFFIX ""
1965 -#else
1966 +#if __ARM_PCS_VFP
1967 #define FP_SUFFIX "hf"
1968 +#else
1969 +#define FP_SUFFIX ""
1970 #endif
1971
1972 #define LDSO_ARCH "arm" ENDIAN_SUFFIX FP_SUFFIX
1973 @@ -28,10 +28,5 @@
1974 #define REL_TPOFF R_ARM_TLS_TPOFF32
1975 //#define REL_TLSDESC R_ARM_TLS_DESC
1976
1977 -#ifdef __thumb__
1978 #define CRTJMP(pc,sp) __asm__ __volatile__( \
1979 "mov sp,%1 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
1980 -#else
1981 -#define CRTJMP(pc,sp) __asm__ __volatile__( \
1982 - "mov sp,%1 ; tst %0,#1 ; moveq pc,%0 ; bx %0" : : "r"(pc), "r"(sp) : "memory" )
1983 -#endif
1984 --- a/arch/arm/src/__aeabi_atexit.c
1985 +++ /dev/null
1986 @@ -1,6 +0,0 @@
1987 -int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
1988 -
1989 -int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
1990 -{
1991 - return __cxa_atexit (func, obj, d);
1992 -}
1993 --- a/arch/arm/src/__aeabi_memclr.c
1994 +++ /dev/null
1995 @@ -1,9 +0,0 @@
1996 -#include <string.h>
1997 -#include "libc.h"
1998 -
1999 -void __aeabi_memclr(void *dest, size_t n)
2000 -{
2001 - memset(dest, 0, n);
2002 -}
2003 -weak_alias(__aeabi_memclr, __aeabi_memclr4);
2004 -weak_alias(__aeabi_memclr, __aeabi_memclr8);
2005 --- a/arch/arm/src/__aeabi_memcpy.c
2006 +++ /dev/null
2007 @@ -1,9 +0,0 @@
2008 -#include <string.h>
2009 -#include "libc.h"
2010 -
2011 -void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
2012 -{
2013 - memcpy(dest, src, n);
2014 -}
2015 -weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
2016 -weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
2017 --- a/arch/arm/src/__aeabi_memmove.c
2018 +++ /dev/null
2019 @@ -1,9 +0,0 @@
2020 -#include <string.h>
2021 -#include "libc.h"
2022 -
2023 -void __aeabi_memmove(void *dest, const void *src, size_t n)
2024 -{
2025 - memmove(dest, src, n);
2026 -}
2027 -weak_alias(__aeabi_memmove, __aeabi_memmove4);
2028 -weak_alias(__aeabi_memmove, __aeabi_memmove8);
2029 --- a/arch/arm/src/__aeabi_memset.c
2030 +++ /dev/null
2031 @@ -1,9 +0,0 @@
2032 -#include <string.h>
2033 -#include "libc.h"
2034 -
2035 -void __aeabi_memset(void *dest, size_t n, int c)
2036 -{
2037 - memset(dest, c, n);
2038 -}
2039 -weak_alias(__aeabi_memset, __aeabi_memset4);
2040 -weak_alias(__aeabi_memset, __aeabi_memset8);
2041 --- a/arch/arm/src/__set_thread_area.c
2042 +++ /dev/null
2043 @@ -1,49 +0,0 @@
2044 -#include <stdint.h>
2045 -#include <elf.h>
2046 -#include "pthread_impl.h"
2047 -#include "libc.h"
2048 -
2049 -#define HWCAP_TLS (1 << 15)
2050 -
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[];
2056 -
2057 -#define __a_barrier_kuser 0xffff0fa0
2058 -#define __a_cas_kuser 0xffff0fc0
2059 -#define __a_gettp_kuser 0xffff0fe0
2060 -
2061 -extern uintptr_t __attribute__((__visibility__("hidden")))
2062 - __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
2063 -
2064 -#define SET(op,ver) (__a_##op##_ptr = \
2065 - (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
2066 -
2067 -int __set_thread_area(void *p)
2068 -{
2069 -#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
2070 - if (__hwcap & HWCAP_TLS) {
2071 - size_t *aux;
2072 - SET(cas, v7);
2073 - SET(barrier, v7);
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;
2078 - SET(cas, v6);
2079 - SET(barrier, v6);
2080 - break;
2081 - }
2082 - } else {
2083 - int ver = *(int *)0xffff0ffc;
2084 - SET(gettp, kuser);
2085 - SET(cas, kuser);
2086 - SET(barrier, kuser);
2087 - if (ver < 2) a_crash();
2088 - if (ver < 3) SET(barrier, oldkuser);
2089 - }
2090 -#endif
2091 - return __syscall(0xf0005, p);
2092 -}
2093 --- a/arch/arm/src/arm/atomics.s
2094 +++ /dev/null
2095 @@ -1,116 +0,0 @@
2096 -.text
2097 -
2098 -.global __a_barrier
2099 -.hidden __a_barrier
2100 -.type __a_barrier,%function
2101 -__a_barrier:
2102 - ldr ip,1f
2103 - ldr ip,[pc,ip]
2104 - add pc,pc,ip
2105 -1: .word __a_barrier_ptr-1b
2106 -.global __a_barrier_dummy
2107 -.hidden __a_barrier_dummy
2108 -__a_barrier_dummy:
2109 - tst lr,#1
2110 - moveq pc,lr
2111 - bx lr
2112 -.global __a_barrier_oldkuser
2113 -.hidden __a_barrier_oldkuser
2114 -__a_barrier_oldkuser:
2115 - push {r0,r1,r2,r3,ip,lr}
2116 - mov r1,r0
2117 - mov r2,sp
2118 - ldr ip,=0xffff0fc0
2119 - mov lr,pc
2120 - mov pc,ip
2121 - pop {r0,r1,r2,r3,ip,lr}
2122 - tst lr,#1
2123 - moveq pc,lr
2124 - bx lr
2125 -.global __a_barrier_v6
2126 -.hidden __a_barrier_v6
2127 -__a_barrier_v6:
2128 - mcr p15,0,r0,c7,c10,5
2129 - bx lr
2130 -.global __a_barrier_v7
2131 -.hidden __a_barrier_v7
2132 -__a_barrier_v7:
2133 - .word 0xf57ff05b /* dmb ish */
2134 - bx lr
2135 -
2136 -.global __a_cas
2137 -.hidden __a_cas
2138 -.type __a_cas,%function
2139 -__a_cas:
2140 - ldr ip,1f
2141 - ldr ip,[pc,ip]
2142 - add pc,pc,ip
2143 -1: .word __a_cas_ptr-1b
2144 -.global __a_cas_dummy
2145 -.hidden __a_cas_dummy
2146 -__a_cas_dummy:
2147 - mov r3,r0
2148 - ldr r0,[r2]
2149 - subs r0,r3,r0
2150 - streq r1,[r2]
2151 - tst lr,#1
2152 - moveq pc,lr
2153 - bx lr
2154 -.global __a_cas_v6
2155 -.hidden __a_cas_v6
2156 -__a_cas_v6:
2157 - mov r3,r0
2158 - mcr p15,0,r0,c7,c10,5
2159 -1: .word 0xe1920f9f /* ldrex r0,[r2] */
2160 - subs r0,r3,r0
2161 - .word 0x01820f91 /* strexeq r0,r1,[r2] */
2162 - teqeq r0,#1
2163 - beq 1b
2164 - mcr p15,0,r0,c7,c10,5
2165 - bx lr
2166 -.global __a_cas_v7
2167 -.hidden __a_cas_v7
2168 -__a_cas_v7:
2169 - mov r3,r0
2170 - .word 0xf57ff05b /* dmb ish */
2171 -1: .word 0xe1920f9f /* ldrex r0,[r2] */
2172 - subs r0,r3,r0
2173 - .word 0x01820f91 /* strexeq r0,r1,[r2] */
2174 - teqeq r0,#1
2175 - beq 1b
2176 - .word 0xf57ff05b /* dmb ish */
2177 - bx lr
2178 -
2179 -.global __aeabi_read_tp
2180 -.type __aeabi_read_tp,%function
2181 -__aeabi_read_tp:
2182 -
2183 -.global __a_gettp
2184 -.hidden __a_gettp
2185 -.type __a_gettp,%function
2186 -__a_gettp:
2187 - ldr r0,1f
2188 - ldr r0,[pc,r0]
2189 - add pc,pc,r0
2190 -1: .word __a_gettp_ptr-1b
2191 -.global __a_gettp_dummy
2192 -.hidden __a_gettp_dummy
2193 -__a_gettp_dummy:
2194 - mrc p15,0,r0,c13,c0,3
2195 - bx lr
2196 -
2197 -.data
2198 -.global __a_barrier_ptr
2199 -.hidden __a_barrier_ptr
2200 -__a_barrier_ptr:
2201 - .word 0
2202 -
2203 -.global __a_cas_ptr
2204 -.hidden __a_cas_ptr
2205 -__a_cas_ptr:
2206 - .word 0
2207 -
2208 -.global __a_gettp_ptr
2209 -.hidden __a_gettp_ptr
2210 -__a_gettp_ptr:
2211 - .word 0
2212 --- a/arch/arm/src/find_exidx.c
2213 +++ /dev/null
2214 @@ -1,42 +0,0 @@
2215 -#define _GNU_SOURCE
2216 -#include <link.h>
2217 -#include <stdint.h>
2218 -
2219 -struct find_exidx_data {
2220 - uintptr_t pc, exidx_start;
2221 - int exidx_len;
2222 -};
2223 -
2224 -static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
2225 -{
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;
2230 -
2231 - for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
2232 - addr = info->dlpi_addr + phdr->p_vaddr;
2233 - switch (phdr->p_type) {
2234 - case PT_LOAD:
2235 - match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
2236 - break;
2237 - case PT_ARM_EXIDX:
2238 - exidx_start = addr;
2239 - exidx_len = phdr->p_memsz;
2240 - break;
2241 - }
2242 - }
2243 - data->exidx_start = exidx_start;
2244 - data->exidx_len = exidx_len;
2245 - return match;
2246 -}
2247 -
2248 -uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
2249 -{
2250 - struct find_exidx_data data;
2251 - data.pc = pc;
2252 - if (dl_iterate_phdr(find_exidx, &data) <= 0)
2253 - return 0;
2254 - *pcount = data.exidx_len / 8;
2255 - return data.exidx_start;
2256 -}
2257 --- /dev/null
2258 +++ b/arch/generic/bits/errno.h
2259 @@ -0,0 +1,134 @@
2260 +#define EPERM 1
2261 +#define ENOENT 2
2262 +#define ESRCH 3
2263 +#define EINTR 4
2264 +#define EIO 5
2265 +#define ENXIO 6
2266 +#define E2BIG 7
2267 +#define ENOEXEC 8
2268 +#define EBADF 9
2269 +#define ECHILD 10
2270 +#define EAGAIN 11
2271 +#define ENOMEM 12
2272 +#define EACCES 13
2273 +#define EFAULT 14
2274 +#define ENOTBLK 15
2275 +#define EBUSY 16
2276 +#define EEXIST 17
2277 +#define EXDEV 18
2278 +#define ENODEV 19
2279 +#define ENOTDIR 20
2280 +#define EISDIR 21
2281 +#define EINVAL 22
2282 +#define ENFILE 23
2283 +#define EMFILE 24
2284 +#define ENOTTY 25
2285 +#define ETXTBSY 26
2286 +#define EFBIG 27
2287 +#define ENOSPC 28
2288 +#define ESPIPE 29
2289 +#define EROFS 30
2290 +#define EMLINK 31
2291 +#define EPIPE 32
2292 +#define EDOM 33
2293 +#define ERANGE 34
2294 +#define EDEADLK 35
2295 +#define ENAMETOOLONG 36
2296 +#define ENOLCK 37
2297 +#define ENOSYS 38
2298 +#define ENOTEMPTY 39
2299 +#define ELOOP 40
2300 +#define EWOULDBLOCK EAGAIN
2301 +#define ENOMSG 42
2302 +#define EIDRM 43
2303 +#define ECHRNG 44
2304 +#define EL2NSYNC 45
2305 +#define EL3HLT 46
2306 +#define EL3RST 47
2307 +#define ELNRNG 48
2308 +#define EUNATCH 49
2309 +#define ENOCSI 50
2310 +#define EL2HLT 51
2311 +#define EBADE 52
2312 +#define EBADR 53
2313 +#define EXFULL 54
2314 +#define ENOANO 55
2315 +#define EBADRQC 56
2316 +#define EBADSLT 57
2317 +#define EDEADLOCK EDEADLK
2318 +#define EBFONT 59
2319 +#define ENOSTR 60
2320 +#define ENODATA 61
2321 +#define ETIME 62
2322 +#define ENOSR 63
2323 +#define ENONET 64
2324 +#define ENOPKG 65
2325 +#define EREMOTE 66
2326 +#define ENOLINK 67
2327 +#define EADV 68
2328 +#define ESRMNT 69
2329 +#define ECOMM 70
2330 +#define EPROTO 71
2331 +#define EMULTIHOP 72
2332 +#define EDOTDOT 73
2333 +#define EBADMSG 74
2334 +#define EOVERFLOW 75
2335 +#define ENOTUNIQ 76
2336 +#define EBADFD 77
2337 +#define EREMCHG 78
2338 +#define ELIBACC 79
2339 +#define ELIBBAD 80
2340 +#define ELIBSCN 81
2341 +#define ELIBMAX 82
2342 +#define ELIBEXEC 83
2343 +#define EILSEQ 84
2344 +#define ERESTART 85
2345 +#define ESTRPIPE 86
2346 +#define EUSERS 87
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
2376 +#define ESTALE 116
2377 +#define EUCLEAN 117
2378 +#define ENOTNAM 118
2379 +#define ENAVAIL 119
2380 +#define EISNAM 120
2381 +#define EREMOTEIO 121
2382 +#define EDQUOT 122
2383 +#define ENOMEDIUM 123
2384 +#define EMEDIUMTYPE 124
2385 +#define ECANCELED 125
2386 +#define ENOKEY 126
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
2394 --- /dev/null
2395 +++ b/arch/generic/bits/fcntl.h
2396 @@ -0,0 +1,40 @@
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
2409 +
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
2417 +
2418 +#define F_DUPFD 0
2419 +#define F_GETFD 1
2420 +#define F_SETFD 2
2421 +#define F_GETFL 3
2422 +#define F_SETFL 4
2423 +
2424 +#define F_SETOWN 8
2425 +#define F_GETOWN 9
2426 +#define F_SETSIG 10
2427 +#define F_GETSIG 11
2428 +
2429 +#define F_GETLK 12
2430 +#define F_SETLK 13
2431 +#define F_SETLKW 14
2432 +
2433 +#define F_SETOWN_EX 15
2434 +#define F_GETOWN_EX 16
2435 +
2436 +#define F_GETOWNER_UIDS 17
2437 --- /dev/null
2438 +++ b/arch/generic/bits/fenv.h
2439 @@ -0,0 +1,10 @@
2440 +#define FE_ALL_EXCEPT 0
2441 +#define FE_TONEAREST 0
2442 +
2443 +typedef unsigned long fexcept_t;
2444 +
2445 +typedef struct {
2446 + unsigned long __cw;
2447 +} fenv_t;
2448 +
2449 +#define FE_DFL_ENV ((const fenv_t *) -1)
2450 --- /dev/null
2451 +++ b/arch/generic/bits/ioctl.h
2452 @@ -0,0 +1,197 @@
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
2457 +
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))
2462 +
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
2511 +
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
2524 +
2525 +#define TIOCMIWAIT 0x545C
2526 +#define TIOCGICOUNT 0x545D
2527 +#define TIOCGHAYESESP 0x545E
2528 +#define TIOCSHAYESESP 0x545F
2529 +#define FIOQSIZE 0x5460
2530 +
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
2539 +
2540 +#define TIOCSER_TEMT 0x01
2541 +
2542 +struct winsize {
2543 + unsigned short ws_row;
2544 + unsigned short ws_col;
2545 + unsigned short ws_xpixel;
2546 + unsigned short ws_ypixel;
2547 +};
2548 +
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
2564 +
2565 +#define N_TTY 0
2566 +#define N_SLIP 1
2567 +#define N_MOUSE 2
2568 +#define N_PPP 3
2569 +#define N_STRIP 4
2570 +#define N_AX25 5
2571 +#define N_X25 6
2572 +#define N_6PACK 7
2573 +#define N_MASC 8
2574 +#define N_R3964 9
2575 +#define N_PROFIBUS_FDL 10
2576 +#define N_IRDA 11
2577 +#define N_SMSBLOCK 12
2578 +#define N_HDLC 13
2579 +#define N_SYNC_PPP 14
2580 +#define N_HCI 15
2581 +
2582 +#define FIOSETOWN 0x8901
2583 +#define SIOCSPGRP 0x8902
2584 +#define FIOGETOWN 0x8903
2585 +#define SIOCGPGRP 0x8904
2586 +#define SIOCATMARK 0x8905
2587 +#define SIOCGSTAMP 0x8906
2588 +
2589 +#define SIOCADDRT 0x890B
2590 +#define SIOCDELRT 0x890C
2591 +#define SIOCRTMSG 0x890D
2592 +
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
2627 +
2628 +#define SIOCGIFBR 0x8940
2629 +#define SIOCSIFBR 0x8941
2630 +
2631 +#define SIOCGIFTXQLEN 0x8942
2632 +#define SIOCSIFTXQLEN 0x8943
2633 +
2634 +#define SIOCDARP 0x8953
2635 +#define SIOCGARP 0x8954
2636 +#define SIOCSARP 0x8955
2637 +
2638 +#define SIOCDRARP 0x8960
2639 +#define SIOCGRARP 0x8961
2640 +#define SIOCSRARP 0x8962
2641 +
2642 +#define SIOCGIFMAP 0x8970
2643 +#define SIOCSIFMAP 0x8971
2644 +
2645 +#define SIOCADDDLCI 0x8980
2646 +#define SIOCDELDLCI 0x8981
2647 +
2648 +#define SIOCDEVPRIVATE 0x89F0
2649 +#define SIOCPROTOPRIVATE 0x89E0
2650 --- /dev/null
2651 +++ b/arch/generic/bits/ipc.h
2652 @@ -0,0 +1,14 @@
2653 +struct ipc_perm
2654 +{
2655 + key_t __ipc_perm_key;
2656 + uid_t uid;
2657 + gid_t gid;
2658 + uid_t cuid;
2659 + gid_t cgid;
2660 + mode_t mode;
2661 + int __ipc_perm_seq;
2662 + long __pad1;
2663 + long __pad2;
2664 +};
2665 +
2666 +#define IPC_64 0x100
2667 --- /dev/null
2668 +++ b/arch/generic/bits/msg.h
2669 @@ -0,0 +1,16 @@
2670 +struct msqid_ds
2671 +{
2672 + struct ipc_perm msg_perm;
2673 + time_t msg_stime;
2674 + int __unused1;
2675 + time_t msg_rtime;
2676 + int __unused2;
2677 + time_t msg_ctime;
2678 + int __unused3;
2679 + unsigned long msg_cbytes;
2680 + msgqnum_t msg_qnum;
2681 + msglen_t msg_qbytes;
2682 + pid_t msg_lspid;
2683 + pid_t msg_lrpid;
2684 + unsigned long __unused[2];
2685 +};
2686 --- /dev/null
2687 +++ b/arch/generic/bits/sem.h
2688 @@ -0,0 +1,16 @@
2689 +struct semid_ds {
2690 + struct ipc_perm sem_perm;
2691 + time_t sem_otime;
2692 + time_t __unused1;
2693 + time_t sem_ctime;
2694 + time_t __unused2;
2695 +#if __BYTE_ORDER == __LITTLE_ENDIAN
2696 + unsigned short sem_nsems;
2697 + char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
2698 +#else
2699 + char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
2700 + unsigned short sem_nsems;
2701 +#endif
2702 + time_t __unused3;
2703 + time_t __unused4;
2704 +};
2705 --- /dev/null
2706 +++ b/arch/generic/bits/shm.h
2707 @@ -0,0 +1,29 @@
2708 +#define SHMLBA 4096
2709 +
2710 +struct shmid_ds
2711 +{
2712 + struct ipc_perm shm_perm;
2713 + size_t shm_segsz;
2714 + time_t shm_atime;
2715 + int __unused1;
2716 + time_t shm_dtime;
2717 + int __unused2;
2718 + time_t shm_ctime;
2719 + int __unused3;
2720 + pid_t shm_cpid;
2721 + pid_t shm_lpid;
2722 + unsigned long shm_nattch;
2723 + unsigned long __pad1;
2724 + unsigned long __pad2;
2725 +};
2726 +
2727 +struct shminfo {
2728 + unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
2729 +};
2730 +
2731 +struct shm_info {
2732 + int __used_ids;
2733 + unsigned long shm_tot, shm_rss, shm_swp;
2734 + unsigned long __swap_attempts, __swap_successes;
2735 +};
2736 +
2737 --- /dev/null
2738 +++ b/arch/generic/bits/socket.h
2739 @@ -0,0 +1,17 @@
2740 +struct msghdr
2741 +{
2742 + void *msg_name;
2743 + socklen_t msg_namelen;
2744 + struct iovec *msg_iov;
2745 + int msg_iovlen;
2746 + void *msg_control;
2747 + socklen_t msg_controllen;
2748 + int msg_flags;
2749 +};
2750 +
2751 +struct cmsghdr
2752 +{
2753 + socklen_t cmsg_len;
2754 + int cmsg_level;
2755 + int cmsg_type;
2756 +};
2757 --- /dev/null
2758 +++ b/arch/generic/bits/statfs.h
2759 @@ -0,0 +1,7 @@
2760 +struct statfs {
2761 + unsigned long f_type, f_bsize;
2762 + fsblkcnt_t f_blocks, f_bfree, f_bavail;
2763 + fsfilcnt_t f_files, f_ffree;
2764 + fsid_t f_fsid;
2765 + unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
2766 +};
2767 --- /dev/null
2768 +++ b/arch/generic/bits/stdarg.h
2769 @@ -0,0 +1,4 @@
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)
2774 --- /dev/null
2775 +++ b/arch/generic/bits/termios.h
2776 @@ -0,0 +1,160 @@
2777 +struct termios
2778 +{
2779 + tcflag_t c_iflag;
2780 + tcflag_t c_oflag;
2781 + tcflag_t c_cflag;
2782 + tcflag_t c_lflag;
2783 + cc_t c_line;
2784 + cc_t c_cc[NCCS];
2785 + speed_t __c_ispeed;
2786 + speed_t __c_ospeed;
2787 +};
2788 +
2789 +#define VINTR 0
2790 +#define VQUIT 1
2791 +#define VERASE 2
2792 +#define VKILL 3
2793 +#define VEOF 4
2794 +#define VTIME 5
2795 +#define VMIN 6
2796 +#define VSWTC 7
2797 +#define VSTART 8
2798 +#define VSTOP 9
2799 +#define VSUSP 10
2800 +#define VEOL 11
2801 +#define VREPRINT 12
2802 +#define VDISCARD 13
2803 +#define VWERASE 14
2804 +#define VLNEXT 15
2805 +#define VEOL2 16
2806 +
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
2822 +
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
2850 +
2851 +#define VTDLY 0040000
2852 +#define VT0 0000000
2853 +#define VT1 0040000
2854 +
2855 +#define B0 0000000
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
2871 +
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
2887 +
2888 +#define CBAUD 0010017
2889 +
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
2901 +
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
2911 +
2912 +#define ECHOCTL 0001000
2913 +#define ECHOPRT 0002000
2914 +#define ECHOKE 0004000
2915 +#define FLUSHO 0010000
2916 +#define PENDIN 0040000
2917 +
2918 +#define TCOOFF 0
2919 +#define TCOON 1
2920 +#define TCIOFF 2
2921 +#define TCION 3
2922 +
2923 +#define TCIFLUSH 0
2924 +#define TCOFLUSH 1
2925 +#define TCIOFLUSH 2
2926 +
2927 +#define TCSANOW 0
2928 +#define TCSADRAIN 1
2929 +#define TCSAFLUSH 2
2930 +
2931 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
2932 +#define CBAUDEX 0010000
2933 +#define CRTSCTS 020000000000
2934 +#define EXTPROC 0200000
2935 +#define XTABS 0014000
2936 +#endif
2937 --- a/arch/i386/atomic.h
2938 +++ /dev/null
2939 @@ -1,110 +0,0 @@
2940 -#ifndef _INTERNAL_ATOMIC_H
2941 -#define _INTERNAL_ATOMIC_H
2942 -
2943 -#include <stdint.h>
2944 -
2945 -static inline int a_ctz_64(uint64_t x)
2946 -{
2947 - int r;
2948 - __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; addl $32,%0\n1:"
2949 - : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
2950 - return r;
2951 -}
2952 -
2953 -static inline int a_ctz_l(unsigned long x)
2954 -{
2955 - long r;
2956 - __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
2957 - return r;
2958 -}
2959 -
2960 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
2961 -{
2962 - __asm__( "lock ; andl %1, (%0) ; lock ; andl %2, 4(%0)"
2963 - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
2964 -}
2965 -
2966 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
2967 -{
2968 - __asm__( "lock ; orl %1, (%0) ; lock ; orl %2, 4(%0)"
2969 - : : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
2970 -}
2971 -
2972 -static inline void a_or_l(volatile void *p, long v)
2973 -{
2974 - __asm__( "lock ; orl %1, %0"
2975 - : "=m"(*(long *)p) : "r"(v) : "memory" );
2976 -}
2977 -
2978 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
2979 -{
2980 - __asm__( "lock ; cmpxchg %3, %1"
2981 - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
2982 - return t;
2983 -}
2984 -
2985 -static inline int a_cas(volatile int *p, int t, int s)
2986 -{
2987 - __asm__( "lock ; cmpxchg %3, %1"
2988 - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
2989 - return t;
2990 -}
2991 -
2992 -static inline void a_or(volatile int *p, int v)
2993 -{
2994 - __asm__( "lock ; orl %1, %0"
2995 - : "=m"(*p) : "r"(v) : "memory" );
2996 -}
2997 -
2998 -static inline void a_and(volatile int *p, int v)
2999 -{
3000 - __asm__( "lock ; andl %1, %0"
3001 - : "=m"(*p) : "r"(v) : "memory" );
3002 -}
3003 -
3004 -static inline int a_swap(volatile int *x, int v)
3005 -{
3006 - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
3007 - return v;
3008 -}
3009 -
3010 -#define a_xchg a_swap
3011 -
3012 -static inline int a_fetch_add(volatile int *x, int v)
3013 -{
3014 - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
3015 - return v;
3016 -}
3017 -
3018 -static inline void a_inc(volatile int *x)
3019 -{
3020 - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
3021 -}
3022 -
3023 -static inline void a_dec(volatile int *x)
3024 -{
3025 - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
3026 -}
3027 -
3028 -static inline void a_store(volatile int *p, int x)
3029 -{
3030 - __asm__( "movl %1, %0 ; lock ; orl $0,(%%esp)" : "=m"(*p) : "r"(x) : "memory" );
3031 -}
3032 -
3033 -static inline void a_spin()
3034 -{
3035 - __asm__ __volatile__( "pause" : : : "memory" );
3036 -}
3037 -
3038 -static inline void a_barrier()
3039 -{
3040 - __asm__ __volatile__( "" : : : "memory" );
3041 -}
3042 -
3043 -static inline void a_crash()
3044 -{
3045 - __asm__ __volatile__( "hlt" : : : "memory" );
3046 -}
3047 -
3048 -
3049 -#endif
3050 --- /dev/null
3051 +++ b/arch/i386/atomic_arch.h
3052 @@ -0,0 +1,101 @@
3053 +#define a_cas a_cas
3054 +static inline int a_cas(volatile int *p, int t, int s)
3055 +{
3056 + __asm__ __volatile__ (
3057 + "lock ; cmpxchg %3, %1"
3058 + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
3059 + return t;
3060 +}
3061 +
3062 +#define a_swap a_swap
3063 +static inline int a_swap(volatile int *p, int v)
3064 +{
3065 + __asm__ __volatile__(
3066 + "xchg %0, %1"
3067 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
3068 + return v;
3069 +}
3070 +
3071 +#define a_fetch_add a_fetch_add
3072 +static inline int a_fetch_add(volatile int *p, int v)
3073 +{
3074 + __asm__ __volatile__(
3075 + "lock ; xadd %0, %1"
3076 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
3077 + return v;
3078 +}
3079 +
3080 +#define a_and a_and
3081 +static inline void a_and(volatile int *p, int v)
3082 +{
3083 + __asm__ __volatile__(
3084 + "lock ; and %1, %0"
3085 + : "=m"(*p) : "r"(v) : "memory" );
3086 +}
3087 +
3088 +#define a_or a_or
3089 +static inline void a_or(volatile int *p, int v)
3090 +{
3091 + __asm__ __volatile__(
3092 + "lock ; or %1, %0"
3093 + : "=m"(*p) : "r"(v) : "memory" );
3094 +}
3095 +
3096 +#define a_inc a_inc
3097 +static inline void a_inc(volatile int *p)
3098 +{
3099 + __asm__ __volatile__(
3100 + "lock ; incl %0"
3101 + : "=m"(*p) : "m"(*p) : "memory" );
3102 +}
3103 +
3104 +#define a_dec a_dec
3105 +static inline void a_dec(volatile int *p)
3106 +{
3107 + __asm__ __volatile__(
3108 + "lock ; decl %0"
3109 + : "=m"(*p) : "m"(*p) : "memory" );
3110 +}
3111 +
3112 +#define a_store a_store
3113 +static inline void a_store(volatile int *p, int x)
3114 +{
3115 + __asm__ __volatile__(
3116 + "mov %1, %0 ; lock ; orl $0,(%%esp)"
3117 + : "=m"(*p) : "r"(x) : "memory" );
3118 +}
3119 +
3120 +#define a_barrier a_barrier
3121 +static inline void a_barrier()
3122 +{
3123 + __asm__ __volatile__( "" : : : "memory" );
3124 +}
3125 +
3126 +#define a_pause a_pause
3127 +static inline void a_spin()
3128 +{
3129 + __asm__ __volatile__( "pause" : : : "memory" );
3130 +}
3131 +
3132 +#define a_crash a_crash
3133 +static inline void a_crash()
3134 +{
3135 + __asm__ __volatile__( "hlt" : : : "memory" );
3136 +}
3137 +
3138 +#define a_ctz_64 a_ctz_64
3139 +static inline int a_ctz_64(uint64_t x)
3140 +{
3141 + int r;
3142 + __asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; add $32,%0\n1:"
3143 + : "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
3144 + return r;
3145 +}
3146 +
3147 +#define a_ctz_l a_ctz_l
3148 +static inline int a_ctz_l(unsigned long x)
3149 +{
3150 + long r;
3151 + __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
3152 + return r;
3153 +}
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;
3158 #endif
3159
3160 -#ifdef __cplusplus
3161 -TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t;
3162 -#else
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;
3167 +#else
3168 +TYPEDEF struct { alignas(8) long long __ll; long double __ld; } max_align_t;
3169 #endif
3170
3171 TYPEDEF long time_t;
3172 --- a/arch/i386/bits/errno.h
3173 +++ /dev/null
3174 @@ -1,134 +0,0 @@
3175 -#define EPERM 1
3176 -#define ENOENT 2
3177 -#define ESRCH 3
3178 -#define EINTR 4
3179 -#define EIO 5
3180 -#define ENXIO 6
3181 -#define E2BIG 7
3182 -#define ENOEXEC 8
3183 -#define EBADF 9
3184 -#define ECHILD 10
3185 -#define EAGAIN 11
3186 -#define ENOMEM 12
3187 -#define EACCES 13
3188 -#define EFAULT 14
3189 -#define ENOTBLK 15
3190 -#define EBUSY 16
3191 -#define EEXIST 17
3192 -#define EXDEV 18
3193 -#define ENODEV 19
3194 -#define ENOTDIR 20
3195 -#define EISDIR 21
3196 -#define EINVAL 22
3197 -#define ENFILE 23
3198 -#define EMFILE 24
3199 -#define ENOTTY 25
3200 -#define ETXTBSY 26
3201 -#define EFBIG 27
3202 -#define ENOSPC 28
3203 -#define ESPIPE 29
3204 -#define EROFS 30
3205 -#define EMLINK 31
3206 -#define EPIPE 32
3207 -#define EDOM 33
3208 -#define ERANGE 34
3209 -#define EDEADLK 35
3210 -#define ENAMETOOLONG 36
3211 -#define ENOLCK 37
3212 -#define ENOSYS 38
3213 -#define ENOTEMPTY 39
3214 -#define ELOOP 40
3215 -#define EWOULDBLOCK EAGAIN
3216 -#define ENOMSG 42
3217 -#define EIDRM 43
3218 -#define ECHRNG 44
3219 -#define EL2NSYNC 45
3220 -#define EL3HLT 46
3221 -#define EL3RST 47
3222 -#define ELNRNG 48
3223 -#define EUNATCH 49
3224 -#define ENOCSI 50
3225 -#define EL2HLT 51
3226 -#define EBADE 52
3227 -#define EBADR 53
3228 -#define EXFULL 54
3229 -#define ENOANO 55
3230 -#define EBADRQC 56
3231 -#define EBADSLT 57
3232 -#define EDEADLOCK EDEADLK
3233 -#define EBFONT 59
3234 -#define ENOSTR 60
3235 -#define ENODATA 61
3236 -#define ETIME 62
3237 -#define ENOSR 63
3238 -#define ENONET 64
3239 -#define ENOPKG 65
3240 -#define EREMOTE 66
3241 -#define ENOLINK 67
3242 -#define EADV 68
3243 -#define ESRMNT 69
3244 -#define ECOMM 70
3245 -#define EPROTO 71
3246 -#define EMULTIHOP 72
3247 -#define EDOTDOT 73
3248 -#define EBADMSG 74
3249 -#define EOVERFLOW 75
3250 -#define ENOTUNIQ 76
3251 -#define EBADFD 77
3252 -#define EREMCHG 78
3253 -#define ELIBACC 79
3254 -#define ELIBBAD 80
3255 -#define ELIBSCN 81
3256 -#define ELIBMAX 82
3257 -#define ELIBEXEC 83
3258 -#define EILSEQ 84
3259 -#define ERESTART 85
3260 -#define ESTRPIPE 86
3261 -#define EUSERS 87
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
3291 -#define ESTALE 116
3292 -#define EUCLEAN 117
3293 -#define ENOTNAM 118
3294 -#define ENAVAIL 119
3295 -#define EISNAM 120
3296 -#define EREMOTEIO 121
3297 -#define EDQUOT 122
3298 -#define ENOMEDIUM 123
3299 -#define EMEDIUMTYPE 124
3300 -#define ECANCELED 125
3301 -#define ENOKEY 126
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
3310 +++ /dev/null
3311 @@ -1,40 +0,0 @@
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
3324 -
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
3332 -
3333 -#define F_DUPFD 0
3334 -#define F_GETFD 1
3335 -#define F_SETFD 2
3336 -#define F_GETFL 3
3337 -#define F_SETFL 4
3338 -
3339 -#define F_SETOWN 8
3340 -#define F_GETOWN 9
3341 -#define F_SETSIG 10
3342 -#define F_GETSIG 11
3343 -
3344 -#define F_GETLK 12
3345 -#define F_SETLK 13
3346 -#define F_SETLKW 14
3347 -
3348 -#define F_SETOWN_EX 15
3349 -#define F_GETOWN_EX 16
3350 -
3351 -#define F_GETOWNER_UIDS 17
3352 --- a/arch/i386/bits/ioctl.h
3353 +++ /dev/null
3354 @@ -1,197 +0,0 @@
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
3359 -
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))
3364 -
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
3413 -
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
3426 -
3427 -#define TIOCMIWAIT 0x545C
3428 -#define TIOCGICOUNT 0x545D
3429 -#define TIOCGHAYESESP 0x545E
3430 -#define TIOCSHAYESESP 0x545F
3431 -#define FIOQSIZE 0x5460
3432 -
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
3441 -
3442 -#define TIOCSER_TEMT 0x01
3443 -
3444 -struct winsize {
3445 - unsigned short ws_row;
3446 - unsigned short ws_col;
3447 - unsigned short ws_xpixel;
3448 - unsigned short ws_ypixel;
3449 -};
3450 -
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
3466 -
3467 -#define N_TTY 0
3468 -#define N_SLIP 1
3469 -#define N_MOUSE 2
3470 -#define N_PPP 3
3471 -#define N_STRIP 4
3472 -#define N_AX25 5
3473 -#define N_X25 6
3474 -#define N_6PACK 7
3475 -#define N_MASC 8
3476 -#define N_R3964 9
3477 -#define N_PROFIBUS_FDL 10
3478 -#define N_IRDA 11
3479 -#define N_SMSBLOCK 12
3480 -#define N_HDLC 13
3481 -#define N_SYNC_PPP 14
3482 -#define N_HCI 15
3483 -
3484 -#define FIOSETOWN 0x8901
3485 -#define SIOCSPGRP 0x8902
3486 -#define FIOGETOWN 0x8903
3487 -#define SIOCGPGRP 0x8904
3488 -#define SIOCATMARK 0x8905
3489 -#define SIOCGSTAMP 0x8906
3490 -
3491 -#define SIOCADDRT 0x890B
3492 -#define SIOCDELRT 0x890C
3493 -#define SIOCRTMSG 0x890D
3494 -
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
3529 -
3530 -#define SIOCGIFBR 0x8940
3531 -#define SIOCSIFBR 0x8941
3532 -
3533 -#define SIOCGIFTXQLEN 0x8942
3534 -#define SIOCSIFTXQLEN 0x8943
3535 -
3536 -#define SIOCDARP 0x8953
3537 -#define SIOCGARP 0x8954
3538 -#define SIOCSARP 0x8955
3539 -
3540 -#define SIOCDRARP 0x8960
3541 -#define SIOCGRARP 0x8961
3542 -#define SIOCSRARP 0x8962
3543 -
3544 -#define SIOCGIFMAP 0x8970
3545 -#define SIOCSIFMAP 0x8971
3546 -
3547 -#define SIOCADDDLCI 0x8980
3548 -#define SIOCDELDLCI 0x8981
3549 -
3550 -#define SIOCDEVPRIVATE 0x89F0
3551 -#define SIOCPROTOPRIVATE 0x89E0
3552 --- a/arch/i386/bits/ipc.h
3553 +++ /dev/null
3554 @@ -1,14 +0,0 @@
3555 -struct ipc_perm
3556 -{
3557 - key_t __ipc_perm_key;
3558 - uid_t uid;
3559 - gid_t gid;
3560 - uid_t cuid;
3561 - gid_t cgid;
3562 - mode_t mode;
3563 - int __ipc_perm_seq;
3564 - long __pad1;
3565 - long __pad2;
3566 -};
3567 -
3568 -#define IPC_64 0x100
3569 --- a/arch/i386/bits/mman.h
3570 +++ b/arch/i386/bits/mman.h
3571 @@ -38,6 +38,7 @@
3572
3573 #define MCL_CURRENT 1
3574 #define MCL_FUTURE 2
3575 +#define MCL_ONFAULT 4
3576
3577 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
3578 #define MADV_NORMAL 0
3579 --- a/arch/i386/bits/msg.h
3580 +++ /dev/null
3581 @@ -1,16 +0,0 @@
3582 -struct msqid_ds
3583 -{
3584 - struct ipc_perm msg_perm;
3585 - time_t msg_stime;
3586 - int __unused1;
3587 - time_t msg_rtime;
3588 - int __unused2;
3589 - time_t msg_ctime;
3590 - int __unused3;
3591 - unsigned long msg_cbytes;
3592 - msgqnum_t msg_qnum;
3593 - msglen_t msg_qbytes;
3594 - pid_t msg_lspid;
3595 - pid_t msg_lrpid;
3596 - unsigned long __unused[2];
3597 -};
3598 --- a/arch/i386/bits/sem.h
3599 +++ /dev/null
3600 @@ -1,16 +0,0 @@
3601 -struct semid_ds {
3602 - struct ipc_perm sem_perm;
3603 - time_t sem_otime;
3604 - time_t __unused1;
3605 - time_t sem_ctime;
3606 - time_t __unused2;
3607 -#if __BYTE_ORDER == __LITTLE_ENDIAN
3608 - unsigned short sem_nsems;
3609 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
3610 -#else
3611 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
3612 - unsigned short sem_nsems;
3613 -#endif
3614 - time_t __unused3;
3615 - time_t __unused4;
3616 -};
3617 --- a/arch/i386/bits/shm.h
3618 +++ /dev/null
3619 @@ -1,29 +0,0 @@
3620 -#define SHMLBA 4096
3621 -
3622 -struct shmid_ds
3623 -{
3624 - struct ipc_perm shm_perm;
3625 - size_t shm_segsz;
3626 - time_t shm_atime;
3627 - int __unused1;
3628 - time_t shm_dtime;
3629 - int __unused2;
3630 - time_t shm_ctime;
3631 - int __unused3;
3632 - pid_t shm_cpid;
3633 - pid_t shm_lpid;
3634 - unsigned long shm_nattch;
3635 - unsigned long __pad1;
3636 - unsigned long __pad2;
3637 -};
3638 -
3639 -struct shminfo {
3640 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
3641 -};
3642 -
3643 -struct shm_info {
3644 - int __used_ids;
3645 - unsigned long shm_tot, shm_rss, shm_swp;
3646 - unsigned long __swap_attempts, __swap_successes;
3647 -};
3648 -
3649 --- a/arch/i386/bits/socket.h
3650 +++ /dev/null
3651 @@ -1,17 +0,0 @@
3652 -struct msghdr
3653 -{
3654 - void *msg_name;
3655 - socklen_t msg_namelen;
3656 - struct iovec *msg_iov;
3657 - int msg_iovlen;
3658 - void *msg_control;
3659 - socklen_t msg_controllen;
3660 - int msg_flags;
3661 -};
3662 -
3663 -struct cmsghdr
3664 -{
3665 - socklen_t cmsg_len;
3666 - int cmsg_level;
3667 - int cmsg_type;
3668 -};
3669 --- a/arch/i386/bits/statfs.h
3670 +++ /dev/null
3671 @@ -1,7 +0,0 @@
3672 -struct statfs {
3673 - unsigned long f_type, f_bsize;
3674 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
3675 - fsfilcnt_t f_files, f_ffree;
3676 - fsid_t f_fsid;
3677 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
3678 -};
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
3703
3704
3705 /* Repeated with SYS_ prefix */
3706 @@ -720,3 +738,21 @@
3707 #define SYS_memfd_create 356
3708 #define SYS_bpf 357
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
3729 +++ /dev/null
3730 @@ -1,160 +0,0 @@
3731 -struct termios
3732 -{
3733 - tcflag_t c_iflag;
3734 - tcflag_t c_oflag;
3735 - tcflag_t c_cflag;
3736 - tcflag_t c_lflag;
3737 - cc_t c_line;
3738 - cc_t c_cc[NCCS];
3739 - speed_t __c_ispeed;
3740 - speed_t __c_ospeed;
3741 -};
3742 -
3743 -#define VINTR 0
3744 -#define VQUIT 1
3745 -#define VERASE 2
3746 -#define VKILL 3
3747 -#define VEOF 4
3748 -#define VTIME 5
3749 -#define VMIN 6
3750 -#define VSWTC 7
3751 -#define VSTART 8
3752 -#define VSTOP 9
3753 -#define VSUSP 10
3754 -#define VEOL 11
3755 -#define VREPRINT 12
3756 -#define VDISCARD 13
3757 -#define VWERASE 14
3758 -#define VLNEXT 15
3759 -#define VEOL2 16
3760 -
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
3776 -
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
3804 -
3805 -#define VTDLY 0040000
3806 -#define VT0 0000000
3807 -#define VT1 0040000
3808 -
3809 -#define B0 0000000
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
3825 -
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
3841 -
3842 -#define CBAUD 0010017
3843 -
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
3855 -
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
3865 -
3866 -#define ECHOCTL 0001000
3867 -#define ECHOPRT 0002000
3868 -#define ECHOKE 0004000
3869 -#define FLUSHO 0010000
3870 -#define PENDIN 0040000
3871 -
3872 -#define TCOOFF 0
3873 -#define TCOON 1
3874 -#define TCIOFF 2
3875 -#define TCION 3
3876 -
3877 -#define TCIFLUSH 0
3878 -#define TCOFLUSH 1
3879 -#define TCIOFLUSH 2
3880 -
3881 -#define TCSANOW 0
3882 -#define TCSADRAIN 1
3883 -#define TCSAFLUSH 2
3884 -
3885 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
3886 -#define CBAUDEX 0010000
3887 -#define CRTSCTS 020000000000
3888 -#define EXTPROC 0200000
3889 -#define XTABS 0014000
3890 -#endif
3891 --- a/arch/i386/pthread_arch.h
3892 +++ b/arch/i386/pthread_arch.h
3893 @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
3894
3895 #define TP_ADJ(p) (p)
3896
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
3902 #define VDSO_USEFUL
3903 #define VDSO_CGT_SYM "__vdso_clock_gettime"
3904 #define VDSO_CGT_VER "LINUX_2.6"
3905 +
3906 +#define SYSCALL_USE_SOCKETCALL
3907 --- a/arch/microblaze/atomic.h
3908 +++ /dev/null
3909 @@ -1,143 +0,0 @@
3910 -#ifndef _INTERNAL_ATOMIC_H
3911 -#define _INTERNAL_ATOMIC_H
3912 -
3913 -#include <stdint.h>
3914 -
3915 -static inline int a_ctz_l(unsigned long x)
3916 -{
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
3920 - };
3921 - return debruijn32[(x&-x)*0x076be629 >> 27];
3922 -}
3923 -
3924 -static inline int a_ctz_64(uint64_t x)
3925 -{
3926 - uint32_t y = x;
3927 - if (!y) {
3928 - y = x>>32;
3929 - return 32 + a_ctz_l(y);
3930 - }
3931 - return a_ctz_l(y);
3932 -}
3933 -
3934 -static inline int a_cas(volatile int *p, int t, int s)
3935 -{
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"
3941 - " bnei %1, 1f\n"
3942 - " swx %4, %2, r0\n"
3943 - " addic %1, r0, 0\n"
3944 - " bnei %1, 1b\n"
3945 - "1: "
3946 - : "=&r"(old), "=&r"(tmp)
3947 - : "r"(p), "r"(t), "r"(s)
3948 - : "cc", "memory" );
3949 - return old;
3950 -}
3951 -
3952 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
3953 -{
3954 - return (void *)a_cas(p, (int)t, (int)s);
3955 -}
3956 -
3957 -static inline int a_swap(volatile int *x, int v)
3958 -{
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"
3965 - " bnei %1, 1b\n"
3966 - "1: "
3967 - : "=&r"(old), "=&r"(tmp)
3968 - : "r"(x), "r"(v)
3969 - : "cc", "memory" );
3970 - return old;
3971 -}
3972 -
3973 -static inline int a_fetch_add(volatile int *x, int v)
3974 -{
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"
3982 - " bnei %1, 1b\n"
3983 - "1: "
3984 - : "=&r"(new), "=&r"(tmp)
3985 - : "r"(x), "r"(v)
3986 - : "cc", "memory" );
3987 - return new-v;
3988 -}
3989 -
3990 -static inline void a_inc(volatile int *x)
3991 -{
3992 - a_fetch_add(x, 1);
3993 -}
3994 -
3995 -static inline void a_dec(volatile int *x)
3996 -{
3997 - a_fetch_add(x, -1);
3998 -}
3999 -
4000 -static inline void a_store(volatile int *p, int x)
4001 -{
4002 - __asm__ __volatile__ (
4003 - "swi %1, %0"
4004 - : "=m"(*p) : "r"(x) : "memory" );
4005 -}
4006 -
4007 -#define a_spin a_barrier
4008 -
4009 -static inline void a_barrier()
4010 -{
4011 - a_cas(&(int){0}, 0, 0);
4012 -}
4013 -
4014 -static inline void a_crash()
4015 -{
4016 - *(volatile char *)0=0;
4017 -}
4018 -
4019 -static inline void a_and(volatile int *p, int v)
4020 -{
4021 - int old;
4022 - do old = *p;
4023 - while (a_cas(p, old, old&v) != old);
4024 -}
4025 -
4026 -static inline void a_or(volatile int *p, int v)
4027 -{
4028 - int old;
4029 - do old = *p;
4030 - while (a_cas(p, old, old|v) != old);
4031 -}
4032 -
4033 -static inline void a_or_l(volatile void *p, long v)
4034 -{
4035 - a_or(p, v);
4036 -}
4037 -
4038 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
4039 -{
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]);
4043 -}
4044 -
4045 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
4046 -{
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]);
4050 -}
4051 -
4052 -#endif
4053 --- /dev/null
4054 +++ b/arch/microblaze/atomic_arch.h
4055 @@ -0,0 +1,53 @@
4056 +#define a_cas a_cas
4057 +static inline int a_cas(volatile int *p, int t, int s)
4058 +{
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"
4064 + " bnei %1, 1f\n"
4065 + " swx %4, %2, r0\n"
4066 + " addic %1, r0, 0\n"
4067 + " bnei %1, 1b\n"
4068 + "1: "
4069 + : "=&r"(old), "=&r"(tmp)
4070 + : "r"(p), "r"(t), "r"(s)
4071 + : "cc", "memory" );
4072 + return old;
4073 +}
4074 +
4075 +#define a_swap a_swap
4076 +static inline int a_swap(volatile int *x, int v)
4077 +{
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"
4084 + " bnei %1, 1b\n"
4085 + "1: "
4086 + : "=&r"(old), "=&r"(tmp)
4087 + : "r"(x), "r"(v)
4088 + : "cc", "memory" );
4089 + return old;
4090 +}
4091 +
4092 +#define a_fetch_add a_fetch_add
4093 +static inline int a_fetch_add(volatile int *x, int v)
4094 +{
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"
4102 + " bnei %1, 1b\n"
4103 + "1: "
4104 + : "=&r"(new), "=&r"(tmp)
4105 + : "r"(x), "r"(v)
4106 + : "cc", "memory" );
4107 + return new-v;
4108 +}
4109 --- a/arch/microblaze/bits/errno.h
4110 +++ /dev/null
4111 @@ -1,134 +0,0 @@
4112 -#define EPERM 1
4113 -#define ENOENT 2
4114 -#define ESRCH 3
4115 -#define EINTR 4
4116 -#define EIO 5
4117 -#define ENXIO 6
4118 -#define E2BIG 7
4119 -#define ENOEXEC 8
4120 -#define EBADF 9
4121 -#define ECHILD 10
4122 -#define EAGAIN 11
4123 -#define ENOMEM 12
4124 -#define EACCES 13
4125 -#define EFAULT 14
4126 -#define ENOTBLK 15
4127 -#define EBUSY 16
4128 -#define EEXIST 17
4129 -#define EXDEV 18
4130 -#define ENODEV 19
4131 -#define ENOTDIR 20
4132 -#define EISDIR 21
4133 -#define EINVAL 22
4134 -#define ENFILE 23
4135 -#define EMFILE 24
4136 -#define ENOTTY 25
4137 -#define ETXTBSY 26
4138 -#define EFBIG 27
4139 -#define ENOSPC 28
4140 -#define ESPIPE 29
4141 -#define EROFS 30
4142 -#define EMLINK 31
4143 -#define EPIPE 32
4144 -#define EDOM 33
4145 -#define ERANGE 34
4146 -#define EDEADLK 35
4147 -#define ENAMETOOLONG 36
4148 -#define ENOLCK 37
4149 -#define ENOSYS 38
4150 -#define ENOTEMPTY 39
4151 -#define ELOOP 40
4152 -#define EWOULDBLOCK EAGAIN
4153 -#define ENOMSG 42
4154 -#define EIDRM 43
4155 -#define ECHRNG 44
4156 -#define EL2NSYNC 45
4157 -#define EL3HLT 46
4158 -#define EL3RST 47
4159 -#define ELNRNG 48
4160 -#define EUNATCH 49
4161 -#define ENOCSI 50
4162 -#define EL2HLT 51
4163 -#define EBADE 52
4164 -#define EBADR 53
4165 -#define EXFULL 54
4166 -#define ENOANO 55
4167 -#define EBADRQC 56
4168 -#define EBADSLT 57
4169 -#define EDEADLOCK EDEADLK
4170 -#define EBFONT 59
4171 -#define ENOSTR 60
4172 -#define ENODATA 61
4173 -#define ETIME 62
4174 -#define ENOSR 63
4175 -#define ENONET 64
4176 -#define ENOPKG 65
4177 -#define EREMOTE 66
4178 -#define ENOLINK 67
4179 -#define EADV 68
4180 -#define ESRMNT 69
4181 -#define ECOMM 70
4182 -#define EPROTO 71
4183 -#define EMULTIHOP 72
4184 -#define EDOTDOT 73
4185 -#define EBADMSG 74
4186 -#define EOVERFLOW 75
4187 -#define ENOTUNIQ 76
4188 -#define EBADFD 77
4189 -#define EREMCHG 78
4190 -#define ELIBACC 79
4191 -#define ELIBBAD 80
4192 -#define ELIBSCN 81
4193 -#define ELIBMAX 82
4194 -#define ELIBEXEC 83
4195 -#define EILSEQ 84
4196 -#define ERESTART 85
4197 -#define ESTRPIPE 86
4198 -#define EUSERS 87
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
4228 -#define ESTALE 116
4229 -#define EUCLEAN 117
4230 -#define ENOTNAM 118
4231 -#define ENAVAIL 119
4232 -#define EISNAM 120
4233 -#define EREMOTEIO 121
4234 -#define EDQUOT 122
4235 -#define ENOMEDIUM 123
4236 -#define EMEDIUMTYPE 124
4237 -#define ECANCELED 125
4238 -#define ENOKEY 126
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
4247 +++ /dev/null
4248 @@ -1,40 +0,0 @@
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
4261 -
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
4269 -
4270 -#define F_DUPFD 0
4271 -#define F_GETFD 1
4272 -#define F_SETFD 2
4273 -#define F_GETFL 3
4274 -#define F_SETFL 4
4275 -
4276 -#define F_SETOWN 8
4277 -#define F_GETOWN 9
4278 -#define F_SETSIG 10
4279 -#define F_GETSIG 11
4280 -
4281 -#define F_GETLK 12
4282 -#define F_SETLK 13
4283 -#define F_SETLKW 14
4284 -
4285 -#define F_SETOWN_EX 15
4286 -#define F_GETOWN_EX 16
4287 -
4288 -#define F_GETOWNER_UIDS 17
4289 --- a/arch/microblaze/bits/fenv.h
4290 +++ /dev/null
4291 @@ -1,10 +0,0 @@
4292 -#define FE_ALL_EXCEPT 0
4293 -#define FE_TONEAREST 0
4294 -
4295 -typedef unsigned long fexcept_t;
4296 -
4297 -typedef struct {
4298 - unsigned long __cw;
4299 -} fenv_t;
4300 -
4301 -#define FE_DFL_ENV ((const fenv_t *) -1)
4302 --- a/arch/microblaze/bits/ioctl.h
4303 +++ /dev/null
4304 @@ -1,197 +0,0 @@
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
4309 -
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))
4314 -
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
4363 -
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
4376 -
4377 -#define TIOCMIWAIT 0x545C
4378 -#define TIOCGICOUNT 0x545D
4379 -#define TIOCGHAYESESP 0x545E
4380 -#define TIOCSHAYESESP 0x545F
4381 -#define FIOQSIZE 0x5460
4382 -
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
4391 -
4392 -#define TIOCSER_TEMT 0x01
4393 -
4394 -struct winsize {
4395 - unsigned short ws_row;
4396 - unsigned short ws_col;
4397 - unsigned short ws_xpixel;
4398 - unsigned short ws_ypixel;
4399 -};
4400 -
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
4416 -
4417 -#define N_TTY 0
4418 -#define N_SLIP 1
4419 -#define N_MOUSE 2
4420 -#define N_PPP 3
4421 -#define N_STRIP 4
4422 -#define N_AX25 5
4423 -#define N_X25 6
4424 -#define N_6PACK 7
4425 -#define N_MASC 8
4426 -#define N_R3964 9
4427 -#define N_PROFIBUS_FDL 10
4428 -#define N_IRDA 11
4429 -#define N_SMSBLOCK 12
4430 -#define N_HDLC 13
4431 -#define N_SYNC_PPP 14
4432 -#define N_HCI 15
4433 -
4434 -#define FIOSETOWN 0x8901
4435 -#define SIOCSPGRP 0x8902
4436 -#define FIOGETOWN 0x8903
4437 -#define SIOCGPGRP 0x8904
4438 -#define SIOCATMARK 0x8905
4439 -#define SIOCGSTAMP 0x8906
4440 -
4441 -#define SIOCADDRT 0x890B
4442 -#define SIOCDELRT 0x890C
4443 -#define SIOCRTMSG 0x890D
4444 -
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
4479 -
4480 -#define SIOCGIFBR 0x8940
4481 -#define SIOCSIFBR 0x8941
4482 -
4483 -#define SIOCGIFTXQLEN 0x8942
4484 -#define SIOCSIFTXQLEN 0x8943
4485 -
4486 -#define SIOCDARP 0x8953
4487 -#define SIOCGARP 0x8954
4488 -#define SIOCSARP 0x8955
4489 -
4490 -#define SIOCDRARP 0x8960
4491 -#define SIOCGRARP 0x8961
4492 -#define SIOCSRARP 0x8962
4493 -
4494 -#define SIOCGIFMAP 0x8970
4495 -#define SIOCSIFMAP 0x8971
4496 -
4497 -#define SIOCADDDLCI 0x8980
4498 -#define SIOCDELDLCI 0x8981
4499 -
4500 -#define SIOCDEVPRIVATE 0x89F0
4501 -#define SIOCPROTOPRIVATE 0x89E0
4502 --- a/arch/microblaze/bits/ipc.h
4503 +++ /dev/null
4504 @@ -1,14 +0,0 @@
4505 -struct ipc_perm
4506 -{
4507 - key_t __ipc_perm_key;
4508 - uid_t uid;
4509 - gid_t gid;
4510 - uid_t cuid;
4511 - gid_t cgid;
4512 - mode_t mode;
4513 - int __ipc_perm_seq;
4514 - long __pad1;
4515 - long __pad2;
4516 -};
4517 -
4518 -#define IPC_64 0x100
4519 --- a/arch/microblaze/bits/mman.h
4520 +++ b/arch/microblaze/bits/mman.h
4521 @@ -37,6 +37,7 @@
4522
4523 #define MCL_CURRENT 1
4524 #define MCL_FUTURE 2
4525 +#define MCL_ONFAULT 4
4526
4527 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
4528 #define MADV_NORMAL 0
4529 --- a/arch/microblaze/bits/msg.h
4530 +++ /dev/null
4531 @@ -1,16 +0,0 @@
4532 -struct msqid_ds
4533 -{
4534 - struct ipc_perm msg_perm;
4535 - time_t msg_stime;
4536 - int __unused1;
4537 - time_t msg_rtime;
4538 - int __unused2;
4539 - time_t msg_ctime;
4540 - int __unused3;
4541 - unsigned long msg_cbytes;
4542 - msgqnum_t msg_qnum;
4543 - msglen_t msg_qbytes;
4544 - pid_t msg_lspid;
4545 - pid_t msg_lrpid;
4546 - unsigned long __unused[2];
4547 -};
4548 --- a/arch/microblaze/bits/sem.h
4549 +++ /dev/null
4550 @@ -1,16 +0,0 @@
4551 -struct semid_ds {
4552 - struct ipc_perm sem_perm;
4553 - time_t sem_otime;
4554 - time_t __unused1;
4555 - time_t sem_ctime;
4556 - time_t __unused2;
4557 -#if __BYTE_ORDER == __LITTLE_ENDIAN
4558 - unsigned short sem_nsems;
4559 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
4560 -#else
4561 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
4562 - unsigned short sem_nsems;
4563 -#endif
4564 - time_t __unused3;
4565 - time_t __unused4;
4566 -};
4567 --- a/arch/microblaze/bits/shm.h
4568 +++ /dev/null
4569 @@ -1,29 +0,0 @@
4570 -#define SHMLBA 4096
4571 -
4572 -struct shmid_ds
4573 -{
4574 - struct ipc_perm shm_perm;
4575 - size_t shm_segsz;
4576 - time_t shm_atime;
4577 - int __unused1;
4578 - time_t shm_dtime;
4579 - int __unused2;
4580 - time_t shm_ctime;
4581 - int __unused3;
4582 - pid_t shm_cpid;
4583 - pid_t shm_lpid;
4584 - unsigned long shm_nattch;
4585 - unsigned long __pad1;
4586 - unsigned long __pad2;
4587 -};
4588 -
4589 -struct shminfo {
4590 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
4591 -};
4592 -
4593 -struct shm_info {
4594 - int __used_ids;
4595 - unsigned long shm_tot, shm_rss, shm_swp;
4596 - unsigned long __swap_attempts, __swap_successes;
4597 -};
4598 -
4599 --- a/arch/microblaze/bits/socket.h
4600 +++ /dev/null
4601 @@ -1,17 +0,0 @@
4602 -struct msghdr
4603 -{
4604 - void *msg_name;
4605 - socklen_t msg_namelen;
4606 - struct iovec *msg_iov;
4607 - int msg_iovlen;
4608 - void *msg_control;
4609 - socklen_t msg_controllen;
4610 - int msg_flags;
4611 -};
4612 -
4613 -struct cmsghdr
4614 -{
4615 - socklen_t cmsg_len;
4616 - int cmsg_level;
4617 - int cmsg_type;
4618 -};
4619 --- a/arch/microblaze/bits/statfs.h
4620 +++ /dev/null
4621 @@ -1,7 +0,0 @@
4622 -struct statfs {
4623 - unsigned long f_type, f_bsize;
4624 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
4625 - fsfilcnt_t f_files, f_ffree;
4626 - fsid_t f_fsid;
4627 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
4628 -};
4629 --- a/arch/microblaze/bits/stdarg.h
4630 +++ /dev/null
4631 @@ -1,4 +0,0 @@
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
4637 +++ /dev/null
4638 @@ -1,160 +0,0 @@
4639 -struct termios
4640 -{
4641 - tcflag_t c_iflag;
4642 - tcflag_t c_oflag;
4643 - tcflag_t c_cflag;
4644 - tcflag_t c_lflag;
4645 - cc_t c_line;
4646 - cc_t c_cc[NCCS];
4647 - speed_t __c_ispeed;
4648 - speed_t __c_ospeed;
4649 -};
4650 -
4651 -#define VINTR 0
4652 -#define VQUIT 1
4653 -#define VERASE 2
4654 -#define VKILL 3
4655 -#define VEOF 4
4656 -#define VTIME 5
4657 -#define VMIN 6
4658 -#define VSWTC 7
4659 -#define VSTART 8
4660 -#define VSTOP 9
4661 -#define VSUSP 10
4662 -#define VEOL 11
4663 -#define VREPRINT 12
4664 -#define VDISCARD 13
4665 -#define VWERASE 14
4666 -#define VLNEXT 15
4667 -#define VEOL2 16
4668 -
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
4684 -
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
4712 -
4713 -#define VTDLY 0040000
4714 -#define VT0 0000000
4715 -#define VT1 0040000
4716 -
4717 -#define B0 0000000
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
4733 -
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
4749 -
4750 -#define CBAUD 0010017
4751 -
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
4763 -
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
4773 -
4774 -#define ECHOCTL 0001000
4775 -#define ECHOPRT 0002000
4776 -#define ECHOKE 0004000
4777 -#define FLUSHO 0010000
4778 -#define PENDIN 0040000
4779 -
4780 -#define TCOOFF 0
4781 -#define TCOON 1
4782 -#define TCIOFF 2
4783 -#define TCION 3
4784 -
4785 -#define TCIFLUSH 0
4786 -#define TCOFLUSH 1
4787 -#define TCIOFLUSH 2
4788 -
4789 -#define TCSANOW 0
4790 -#define TCSADRAIN 1
4791 -#define TCSAFLUSH 2
4792 -
4793 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
4794 -#define CBAUDEX 0010000
4795 -#define CRTSCTS 020000000000
4796 -#define EXTPROC 0200000
4797 -#define XTABS 0014000
4798 -#endif
4799 --- a/arch/microblaze/pthread_arch.h
4800 +++ b/arch/microblaze/pthread_arch.h
4801 @@ -7,4 +7,4 @@ static inline struct pthread *__pthread_
4802
4803 #define TP_ADJ(p) (p)
4804
4805 -#define CANCEL_REG_IP 32
4806 +#define MC_PC regs.pc
4807 --- a/arch/mips/atomic.h
4808 +++ /dev/null
4809 @@ -1,205 +0,0 @@
4810 -#ifndef _INTERNAL_ATOMIC_H
4811 -#define _INTERNAL_ATOMIC_H
4812 -
4813 -#include <stdint.h>
4814 -
4815 -static inline int a_ctz_l(unsigned long x)
4816 -{
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
4820 - };
4821 - return debruijn32[(x&-x)*0x076be629 >> 27];
4822 -}
4823 -
4824 -static inline int a_ctz_64(uint64_t x)
4825 -{
4826 - uint32_t y = x;
4827 - if (!y) {
4828 - y = x>>32;
4829 - return 32 + a_ctz_l(y);
4830 - }
4831 - return a_ctz_l(y);
4832 -}
4833 -
4834 -static inline int a_cas(volatile int *p, int t, int s)
4835 -{
4836 - int dummy;
4837 - __asm__ __volatile__(
4838 - ".set push\n"
4839 - ".set mips2\n"
4840 - ".set noreorder\n"
4841 - " sync\n"
4842 - "1: ll %0, %2\n"
4843 - " bne %0, %3, 1f\n"
4844 - " addu %1, %4, $0\n"
4845 - " sc %1, %2\n"
4846 - " beq %1, $0, 1b\n"
4847 - " nop\n"
4848 - " sync\n"
4849 - "1: \n"
4850 - ".set pop\n"
4851 - : "=&r"(t), "=&r"(dummy), "+m"(*p) : "r"(t), "r"(s) : "memory" );
4852 - return t;
4853 -}
4854 -
4855 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
4856 -{
4857 - return (void *)a_cas(p, (int)t, (int)s);
4858 -}
4859 -
4860 -static inline int a_swap(volatile int *x, int v)
4861 -{
4862 - int old, dummy;
4863 - __asm__ __volatile__(
4864 - ".set push\n"
4865 - ".set mips2\n"
4866 - ".set noreorder\n"
4867 - " sync\n"
4868 - "1: ll %0, %2\n"
4869 - " addu %1, %3, $0\n"
4870 - " sc %1, %2\n"
4871 - " beq %1, $0, 1b\n"
4872 - " nop\n"
4873 - " sync\n"
4874 - ".set pop\n"
4875 - : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
4876 - return old;
4877 -}
4878 -
4879 -static inline int a_fetch_add(volatile int *x, int v)
4880 -{
4881 - int old, dummy;
4882 - __asm__ __volatile__(
4883 - ".set push\n"
4884 - ".set mips2\n"
4885 - ".set noreorder\n"
4886 - " sync\n"
4887 - "1: ll %0, %2\n"
4888 - " addu %1, %0, %3\n"
4889 - " sc %1, %2\n"
4890 - " beq %1, $0, 1b\n"
4891 - " nop\n"
4892 - " sync\n"
4893 - ".set pop\n"
4894 - : "=&r"(old), "=&r"(dummy), "+m"(*x) : "r"(v) : "memory" );
4895 - return old;
4896 -}
4897 -
4898 -static inline void a_inc(volatile int *x)
4899 -{
4900 - int dummy;
4901 - __asm__ __volatile__(
4902 - ".set push\n"
4903 - ".set mips2\n"
4904 - ".set noreorder\n"
4905 - " sync\n"
4906 - "1: ll %0, %1\n"
4907 - " addu %0, %0, 1\n"
4908 - " sc %0, %1\n"
4909 - " beq %0, $0, 1b\n"
4910 - " nop\n"
4911 - " sync\n"
4912 - ".set pop\n"
4913 - : "=&r"(dummy), "+m"(*x) : : "memory" );
4914 -}
4915 -
4916 -static inline void a_dec(volatile int *x)
4917 -{
4918 - int dummy;
4919 - __asm__ __volatile__(
4920 - ".set push\n"
4921 - ".set mips2\n"
4922 - ".set noreorder\n"
4923 - " sync\n"
4924 - "1: ll %0, %1\n"
4925 - " subu %0, %0, 1\n"
4926 - " sc %0, %1\n"
4927 - " beq %0, $0, 1b\n"
4928 - " nop\n"
4929 - " sync\n"
4930 - ".set pop\n"
4931 - : "=&r"(dummy), "+m"(*x) : : "memory" );
4932 -}
4933 -
4934 -static inline void a_store(volatile int *p, int x)
4935 -{
4936 - __asm__ __volatile__(
4937 - ".set push\n"
4938 - ".set mips2\n"
4939 - ".set noreorder\n"
4940 - " sync\n"
4941 - " sw %1, %0\n"
4942 - " sync\n"
4943 - ".set pop\n"
4944 - : "+m"(*p) : "r"(x) : "memory" );
4945 -}
4946 -
4947 -#define a_spin a_barrier
4948 -
4949 -static inline void a_barrier()
4950 -{
4951 - a_cas(&(int){0}, 0, 0);
4952 -}
4953 -
4954 -static inline void a_crash()
4955 -{
4956 - *(volatile char *)0=0;
4957 -}
4958 -
4959 -static inline void a_and(volatile int *p, int v)
4960 -{
4961 - int dummy;
4962 - __asm__ __volatile__(
4963 - ".set push\n"
4964 - ".set mips2\n"
4965 - ".set noreorder\n"
4966 - " sync\n"
4967 - "1: ll %0, %1\n"
4968 - " and %0, %0, %2\n"
4969 - " sc %0, %1\n"
4970 - " beq %0, $0, 1b\n"
4971 - " nop\n"
4972 - " sync\n"
4973 - ".set pop\n"
4974 - : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
4975 -}
4976 -
4977 -static inline void a_or(volatile int *p, int v)
4978 -{
4979 - int dummy;
4980 - __asm__ __volatile__(
4981 - ".set push\n"
4982 - ".set mips2\n"
4983 - ".set noreorder\n"
4984 - " sync\n"
4985 - "1: ll %0, %1\n"
4986 - " or %0, %0, %2\n"
4987 - " sc %0, %1\n"
4988 - " beq %0, $0, 1b\n"
4989 - " nop\n"
4990 - " sync\n"
4991 - ".set pop\n"
4992 - : "=&r"(dummy), "+m"(*p) : "r"(v) : "memory" );
4993 -}
4994 -
4995 -static inline void a_or_l(volatile void *p, long v)
4996 -{
4997 - a_or(p, v);
4998 -}
4999 -
5000 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
5001 -{
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]);
5005 -}
5006 -
5007 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
5008 -{
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]);
5012 -}
5013 -
5014 -#endif
5015 --- /dev/null
5016 +++ b/arch/mips/atomic_arch.h
5017 @@ -0,0 +1,39 @@
5018 +#define a_ll a_ll
5019 +static inline int a_ll(volatile int *p)
5020 +{
5021 + int v;
5022 + __asm__ __volatile__ (
5023 + ".set push ; .set mips2\n\t"
5024 + "ll %0, %1"
5025 + "\n\t.set pop"
5026 + : "=r"(v) : "m"(*p));
5027 + return v;
5028 +}
5029 +
5030 +#define a_sc a_sc
5031 +static inline int a_sc(volatile int *p, int v)
5032 +{
5033 + int r;
5034 + __asm__ __volatile__ (
5035 + ".set push ; .set mips2\n\t"
5036 + "sc %0, %1"
5037 + "\n\t.set pop"
5038 + : "=r"(r), "=m"(*p) : "0"(v) : "memory");
5039 + return r;
5040 +}
5041 +
5042 +#define a_barrier a_barrier
5043 +static inline void a_barrier()
5044 +{
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");
5048 +#if 0
5049 + __asm__ __volatile__ (
5050 + ".set push ; .set mips2 ; sync ; .set pop"
5051 + : : : "memory");
5052 +#endif
5053 +}
5054 +
5055 +#define a_pre_llsc a_barrier
5056 +#define a_post_llsc a_barrier
5057 --- a/arch/mips/bits/ipc.h
5058 +++ /dev/null
5059 @@ -1,14 +0,0 @@
5060 -struct ipc_perm
5061 -{
5062 - key_t __ipc_perm_key;
5063 - uid_t uid;
5064 - gid_t gid;
5065 - uid_t cuid;
5066 - gid_t cgid;
5067 - mode_t mode;
5068 - int __ipc_perm_seq;
5069 - long __pad1;
5070 - long __pad2;
5071 -};
5072 -
5073 -#define IPC_64 0x100
5074 --- a/arch/mips/bits/mman.h
5075 +++ b/arch/mips/bits/mman.h
5076 @@ -37,6 +37,7 @@
5077
5078 #define MCL_CURRENT 1
5079 #define MCL_FUTURE 2
5080 +#define MCL_ONFAULT 4
5081
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
5089
5090 +#undef SI_ASYNCIO
5091 +#undef SI_MESGQ
5092 +#undef SI_TIMER
5093 +#define SI_ASYNCIO (-2)
5094 +#define SI_MESGQ (-4)
5095 +#define SI_TIMER (-3)
5096 +
5097 +#define __SI_SWAP_ERRNO_CODE
5098 +
5099 #endif
5100
5101 #define SIGHUP 1
5102 --- a/arch/mips/bits/stdarg.h
5103 +++ /dev/null
5104 @@ -1,4 +0,0 @@
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
5111 @@ -354,6 +354,9 @@
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
5118
5119
5120 /* Repeated with SYS_ prefix */
5121 @@ -713,3 +716,6 @@
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__(
5131 ".text \n"
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"
5138 "_" START ":\n"
5139 "" START ":\n"
5140 " bal 1f \n"
5141 " move $fp, $0 \n"
5142 -"2: .gpword 2b \n"
5143 +"" START "_data: \n"
5144 +" .gpword " START "_data \n"
5145 " .gpword " START "_c \n"
5146 ".weak _DYNAMIC \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_
5151
5152 #define DTP_OFFSET 0x8000
5153
5154 -#define CANCEL_REG_IP (3-(union {int __i; char __b;}){1}.__b)
5155 +#define MC_PC pc
5156 --- a/arch/mips/syscall_arch.h
5157 +++ b/arch/mips/syscall_arch.h
5158 @@ -3,9 +3,7 @@
5159 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
5160 #define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x))
5161
5162 -#ifdef SHARED
5163 __attribute__((visibility("hidden")))
5164 -#endif
5165 long (__syscall)(long, ...);
5166
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);
5170 return r2;
5171 }
5172 +
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
5177 +++ /dev/null
5178 @@ -1,120 +0,0 @@
5179 -#ifndef _INTERNAL_ATOMIC_H
5180 -#define _INTERNAL_ATOMIC_H
5181 -
5182 -#include <stdint.h>
5183 -
5184 -static inline int a_ctz_l(unsigned long x)
5185 -{
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
5189 - };
5190 - return debruijn32[(x&-x)*0x076be629 >> 27];
5191 -}
5192 -
5193 -static inline int a_ctz_64(uint64_t x)
5194 -{
5195 - uint32_t y = x;
5196 - if (!y) {
5197 - y = x>>32;
5198 - return 32 + a_ctz_l(y);
5199 - }
5200 - return a_ctz_l(y);
5201 -}
5202 -
5203 -static inline int a_cas(volatile int *p, int t, int s)
5204 -{
5205 - __asm__("1: l.lwa %0, %1\n"
5206 - " l.sfeq %0, %2\n"
5207 - " l.bnf 1f\n"
5208 - " l.nop\n"
5209 - " l.swa %1, %3\n"
5210 - " l.bnf 1b\n"
5211 - " l.nop\n"
5212 - "1: \n"
5213 - : "=&r"(t), "+m"(*p) : "r"(t), "r"(s) : "cc", "memory" );
5214 - return t;
5215 -}
5216 -
5217 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
5218 -{
5219 - return (void *)a_cas(p, (int)t, (int)s);
5220 -}
5221 -
5222 -static inline int a_swap(volatile int *x, int v)
5223 -{
5224 - int old;
5225 - do old = *x;
5226 - while (a_cas(x, old, v) != old);
5227 - return old;
5228 -}
5229 -
5230 -static inline int a_fetch_add(volatile int *x, int v)
5231 -{
5232 - int old;
5233 - do old = *x;
5234 - while (a_cas(x, old, old+v) != old);
5235 - return old;
5236 -}
5237 -
5238 -static inline void a_inc(volatile int *x)
5239 -{
5240 - a_fetch_add(x, 1);
5241 -}
5242 -
5243 -static inline void a_dec(volatile int *x)
5244 -{
5245 - a_fetch_add(x, -1);
5246 -}
5247 -
5248 -static inline void a_store(volatile int *p, int x)
5249 -{
5250 - a_swap(p, x);
5251 -}
5252 -
5253 -#define a_spin a_barrier
5254 -
5255 -static inline void a_barrier()
5256 -{
5257 - a_cas(&(int){0}, 0, 0);
5258 -}
5259 -
5260 -static inline void a_crash()
5261 -{
5262 - *(volatile char *)0=0;
5263 -}
5264 -
5265 -static inline void a_and(volatile int *p, int v)
5266 -{
5267 - int old;
5268 - do old = *p;
5269 - while (a_cas(p, old, old&v) != old);
5270 -}
5271 -
5272 -static inline void a_or(volatile int *p, int v)
5273 -{
5274 - int old;
5275 - do old = *p;
5276 - while (a_cas(p, old, old|v) != old);
5277 -}
5278 -
5279 -static inline void a_or_l(volatile void *p, long v)
5280 -{
5281 - a_or(p, v);
5282 -}
5283 -
5284 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
5285 -{
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]);
5289 -}
5290 -
5291 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
5292 -{
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]);
5296 -}
5297 -
5298 -#endif
5299 --- /dev/null
5300 +++ b/arch/or1k/atomic_arch.h
5301 @@ -0,0 +1,14 @@
5302 +#define a_cas a_cas
5303 +static inline int a_cas(volatile int *p, int t, int s)
5304 +{
5305 + __asm__("1: l.lwa %0, %1\n"
5306 + " l.sfeq %0, %2\n"
5307 + " l.bnf 1f\n"
5308 + " l.nop\n"
5309 + " l.swa %1, %3\n"
5310 + " l.bnf 1b\n"
5311 + " l.nop\n"
5312 + "1: \n"
5313 + : "=&r"(t), "+m"(*p) : "r"(t), "r"(s) : "cc", "memory" );
5314 + return t;
5315 +}
5316 --- a/arch/or1k/bits/errno.h
5317 +++ /dev/null
5318 @@ -1,134 +0,0 @@
5319 -#define EPERM 1
5320 -#define ENOENT 2
5321 -#define ESRCH 3
5322 -#define EINTR 4
5323 -#define EIO 5
5324 -#define ENXIO 6
5325 -#define E2BIG 7
5326 -#define ENOEXEC 8
5327 -#define EBADF 9
5328 -#define ECHILD 10
5329 -#define EAGAIN 11
5330 -#define ENOMEM 12
5331 -#define EACCES 13
5332 -#define EFAULT 14
5333 -#define ENOTBLK 15
5334 -#define EBUSY 16
5335 -#define EEXIST 17
5336 -#define EXDEV 18
5337 -#define ENODEV 19
5338 -#define ENOTDIR 20
5339 -#define EISDIR 21
5340 -#define EINVAL 22
5341 -#define ENFILE 23
5342 -#define EMFILE 24
5343 -#define ENOTTY 25
5344 -#define ETXTBSY 26
5345 -#define EFBIG 27
5346 -#define ENOSPC 28
5347 -#define ESPIPE 29
5348 -#define EROFS 30
5349 -#define EMLINK 31
5350 -#define EPIPE 32
5351 -#define EDOM 33
5352 -#define ERANGE 34
5353 -#define EDEADLK 35
5354 -#define ENAMETOOLONG 36
5355 -#define ENOLCK 37
5356 -#define ENOSYS 38
5357 -#define ENOTEMPTY 39
5358 -#define ELOOP 40
5359 -#define EWOULDBLOCK EAGAIN
5360 -#define ENOMSG 42
5361 -#define EIDRM 43
5362 -#define ECHRNG 44
5363 -#define EL2NSYNC 45
5364 -#define EL3HLT 46
5365 -#define EL3RST 47
5366 -#define ELNRNG 48
5367 -#define EUNATCH 49
5368 -#define ENOCSI 50
5369 -#define EL2HLT 51
5370 -#define EBADE 52
5371 -#define EBADR 53
5372 -#define EXFULL 54
5373 -#define ENOANO 55
5374 -#define EBADRQC 56
5375 -#define EBADSLT 57
5376 -#define EDEADLOCK EDEADLK
5377 -#define EBFONT 59
5378 -#define ENOSTR 60
5379 -#define ENODATA 61
5380 -#define ETIME 62
5381 -#define ENOSR 63
5382 -#define ENONET 64
5383 -#define ENOPKG 65
5384 -#define EREMOTE 66
5385 -#define ENOLINK 67
5386 -#define EADV 68
5387 -#define ESRMNT 69
5388 -#define ECOMM 70
5389 -#define EPROTO 71
5390 -#define EMULTIHOP 72
5391 -#define EDOTDOT 73
5392 -#define EBADMSG 74
5393 -#define EOVERFLOW 75
5394 -#define ENOTUNIQ 76
5395 -#define EBADFD 77
5396 -#define EREMCHG 78
5397 -#define ELIBACC 79
5398 -#define ELIBBAD 80
5399 -#define ELIBSCN 81
5400 -#define ELIBMAX 82
5401 -#define ELIBEXEC 83
5402 -#define EILSEQ 84
5403 -#define ERESTART 85
5404 -#define ESTRPIPE 86
5405 -#define EUSERS 87
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
5435 -#define ESTALE 116
5436 -#define EUCLEAN 117
5437 -#define ENOTNAM 118
5438 -#define ENAVAIL 119
5439 -#define EISNAM 120
5440 -#define EREMOTEIO 121
5441 -#define EDQUOT 122
5442 -#define ENOMEDIUM 123
5443 -#define EMEDIUMTYPE 124
5444 -#define ECANCELED 125
5445 -#define ENOKEY 126
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
5454 +++ /dev/null
5455 @@ -1,40 +0,0 @@
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
5468 -
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
5476 -
5477 -#define F_DUPFD 0
5478 -#define F_GETFD 1
5479 -#define F_SETFD 2
5480 -#define F_GETFL 3
5481 -#define F_SETFL 4
5482 -
5483 -#define F_SETOWN 8
5484 -#define F_GETOWN 9
5485 -#define F_SETSIG 10
5486 -#define F_GETSIG 11
5487 -
5488 -#define F_GETLK 12
5489 -#define F_SETLK 13
5490 -#define F_SETLKW 14
5491 -
5492 -#define F_SETOWN_EX 15
5493 -#define F_GETOWN_EX 16
5494 -
5495 -#define F_GETOWNER_UIDS 17
5496 --- a/arch/or1k/bits/fenv.h
5497 +++ /dev/null
5498 @@ -1,10 +0,0 @@
5499 -#define FE_ALL_EXCEPT 0
5500 -#define FE_TONEAREST 0
5501 -
5502 -typedef unsigned long fexcept_t;
5503 -
5504 -typedef struct {
5505 - unsigned long __cw;
5506 -} fenv_t;
5507 -
5508 -#define FE_DFL_ENV ((const fenv_t *) -1)
5509 --- a/arch/or1k/bits/ioctl.h
5510 +++ /dev/null
5511 @@ -1,197 +0,0 @@
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
5516 -
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))
5521 -
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
5570 -
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
5583 -
5584 -#define TIOCMIWAIT 0x545C
5585 -#define TIOCGICOUNT 0x545D
5586 -#define TIOCGHAYESESP 0x545E
5587 -#define TIOCSHAYESESP 0x545F
5588 -#define FIOQSIZE 0x5460
5589 -
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
5598 -
5599 -#define TIOCSER_TEMT 0x01
5600 -
5601 -struct winsize {
5602 - unsigned short ws_row;
5603 - unsigned short ws_col;
5604 - unsigned short ws_xpixel;
5605 - unsigned short ws_ypixel;
5606 -};
5607 -
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
5623 -
5624 -#define N_TTY 0
5625 -#define N_SLIP 1
5626 -#define N_MOUSE 2
5627 -#define N_PPP 3
5628 -#define N_STRIP 4
5629 -#define N_AX25 5
5630 -#define N_X25 6
5631 -#define N_6PACK 7
5632 -#define N_MASC 8
5633 -#define N_R3964 9
5634 -#define N_PROFIBUS_FDL 10
5635 -#define N_IRDA 11
5636 -#define N_SMSBLOCK 12
5637 -#define N_HDLC 13
5638 -#define N_SYNC_PPP 14
5639 -#define N_HCI 15
5640 -
5641 -#define FIOSETOWN 0x8901
5642 -#define SIOCSPGRP 0x8902
5643 -#define FIOGETOWN 0x8903
5644 -#define SIOCGPGRP 0x8904
5645 -#define SIOCATMARK 0x8905
5646 -#define SIOCGSTAMP 0x8906
5647 -
5648 -#define SIOCADDRT 0x890B
5649 -#define SIOCDELRT 0x890C
5650 -#define SIOCRTMSG 0x890D
5651 -
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
5686 -
5687 -#define SIOCGIFBR 0x8940
5688 -#define SIOCSIFBR 0x8941
5689 -
5690 -#define SIOCGIFTXQLEN 0x8942
5691 -#define SIOCSIFTXQLEN 0x8943
5692 -
5693 -#define SIOCDARP 0x8953
5694 -#define SIOCGARP 0x8954
5695 -#define SIOCSARP 0x8955
5696 -
5697 -#define SIOCDRARP 0x8960
5698 -#define SIOCGRARP 0x8961
5699 -#define SIOCSRARP 0x8962
5700 -
5701 -#define SIOCGIFMAP 0x8970
5702 -#define SIOCSIFMAP 0x8971
5703 -
5704 -#define SIOCADDDLCI 0x8980
5705 -#define SIOCDELDLCI 0x8981
5706 -
5707 -#define SIOCDEVPRIVATE 0x89F0
5708 -#define SIOCPROTOPRIVATE 0x89E0
5709 --- a/arch/or1k/bits/mman.h
5710 +++ b/arch/or1k/bits/mman.h
5711 @@ -37,6 +37,7 @@
5712
5713 #define MCL_CURRENT 1
5714 #define MCL_FUTURE 2
5715 +#define MCL_ONFAULT 4
5716
5717 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
5718 #define MADV_NORMAL 0
5719 --- a/arch/or1k/bits/shm.h
5720 +++ /dev/null
5721 @@ -1,27 +0,0 @@
5722 -#define SHMLBA 4096
5723 -
5724 -struct shmid_ds {
5725 - struct ipc_perm shm_perm;
5726 - size_t shm_segsz;
5727 - time_t shm_atime;
5728 - int __unused1;
5729 - time_t shm_dtime;
5730 - int __unused2;
5731 - time_t shm_ctime;
5732 - int __unused3;
5733 - pid_t shm_cpid;
5734 - pid_t shm_lpid;
5735 - unsigned long shm_nattch;
5736 - unsigned long __pad1;
5737 - unsigned long __pad2;
5738 -};
5739 -
5740 -struct shminfo {
5741 - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
5742 -};
5743 -
5744 -struct shm_info {
5745 - int __used_ids;
5746 - unsigned long shm_tot, shm_rss, shm_swp;
5747 - unsigned long __swap_attempts, __swap_successes;
5748 -};
5749 --- a/arch/or1k/bits/socket.h
5750 +++ /dev/null
5751 @@ -1,15 +0,0 @@
5752 -struct msghdr {
5753 - void *msg_name;
5754 - socklen_t msg_namelen;
5755 - struct iovec *msg_iov;
5756 - int msg_iovlen;
5757 - void *msg_control;
5758 - socklen_t msg_controllen;
5759 - int msg_flags;
5760 -};
5761 -
5762 -struct cmsghdr {
5763 - socklen_t cmsg_len;
5764 - int cmsg_level;
5765 - int cmsg_type;
5766 -};
5767 --- a/arch/or1k/bits/statfs.h
5768 +++ /dev/null
5769 @@ -1,7 +0,0 @@
5770 -struct statfs {
5771 - unsigned long f_type, f_bsize;
5772 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
5773 - fsfilcnt_t f_files, f_ffree;
5774 - fsid_t f_fsid;
5775 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
5776 -};
5777 --- a/arch/or1k/bits/stdarg.h
5778 +++ /dev/null
5779 @@ -1,4 +0,0 @@
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
5786 @@ -265,6 +265,9 @@
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
5793
5794 #define SYS_io_setup __NR_io_setup
5795 #define SYS_io_destroy __NR_io_destroy
5796 @@ -533,3 +536,6 @@
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
5804 +++ /dev/null
5805 @@ -1,159 +0,0 @@
5806 -struct termios {
5807 - tcflag_t c_iflag;
5808 - tcflag_t c_oflag;
5809 - tcflag_t c_cflag;
5810 - tcflag_t c_lflag;
5811 - cc_t c_line;
5812 - cc_t c_cc[NCCS];
5813 - speed_t __c_ispeed;
5814 - speed_t __c_ospeed;
5815 -};
5816 -
5817 -#define VINTR 0
5818 -#define VQUIT 1
5819 -#define VERASE 2
5820 -#define VKILL 3
5821 -#define VEOF 4
5822 -#define VTIME 5
5823 -#define VMIN 6
5824 -#define VSWTC 7
5825 -#define VSTART 8
5826 -#define VSTOP 9
5827 -#define VSUSP 10
5828 -#define VEOL 11
5829 -#define VREPRINT 12
5830 -#define VDISCARD 13
5831 -#define VWERASE 14
5832 -#define VLNEXT 15
5833 -#define VEOL2 16
5834 -
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
5850 -
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
5878 -
5879 -#define VTDLY 0040000
5880 -#define VT0 0000000
5881 -#define VT1 0040000
5882 -
5883 -#define B0 0000000
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
5899 -
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
5915 -
5916 -#define CBAUD 0010017
5917 -
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
5929 -
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
5939 -
5940 -#define ECHOCTL 0001000
5941 -#define ECHOPRT 0002000
5942 -#define ECHOKE 0004000
5943 -#define FLUSHO 0010000
5944 -#define PENDIN 0040000
5945 -
5946 -#define TCOOFF 0
5947 -#define TCOON 1
5948 -#define TCIOFF 2
5949 -#define TCION 3
5950 -
5951 -#define TCIFLUSH 0
5952 -#define TCOFLUSH 1
5953 -#define TCIOFLUSH 2
5954 -
5955 -#define TCSANOW 0
5956 -#define TCSADRAIN 1
5957 -#define TCSAFLUSH 2
5958 -
5959 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
5960 -#define CBAUDEX 0010000
5961 -#define CRTSCTS 020000000000
5962 -#define EXTPROC 0200000
5963 -#define XTABS 0014000
5964 -#endif
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))
5970
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
5975 +++ /dev/null
5976 @@ -1,126 +0,0 @@
5977 -#ifndef _INTERNAL_ATOMIC_H
5978 -#define _INTERNAL_ATOMIC_H
5979 -
5980 -#include <stdint.h>
5981 -#include <endian.h>
5982 -
5983 -static inline int a_ctz_l(unsigned long x)
5984 -{
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
5988 - };
5989 - return debruijn32[(x&-x)*0x076be629 >> 27];
5990 -}
5991 -
5992 -static inline int a_ctz_64(uint64_t x)
5993 -{
5994 - uint32_t y = x;
5995 - if (!y) {
5996 - y = x>>32;
5997 - return 32 + a_ctz_l(y);
5998 - }
5999 - return a_ctz_l(y);
6000 -}
6001 -
6002 -static inline int a_cas(volatile int *p, int t, int s)
6003 -{
6004 - __asm__("\n"
6005 - " sync\n"
6006 - "1: lwarx %0, 0, %4\n"
6007 - " cmpw %0, %2\n"
6008 - " bne 1f\n"
6009 - " stwcx. %3, 0, %4\n"
6010 - " bne- 1b\n"
6011 - " isync\n"
6012 - "1: \n"
6013 - : "=&r"(t), "+m"(*p) : "r"(t), "r"(s), "r"(p) : "cc", "memory" );
6014 - return t;
6015 -}
6016 -
6017 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
6018 -{
6019 - return (void *)a_cas(p, (int)t, (int)s);
6020 -}
6021 -
6022 -static inline int a_swap(volatile int *x, int v)
6023 -{
6024 - int old;
6025 - do old = *x;
6026 - while (a_cas(x, old, v) != old);
6027 - return old;
6028 -}
6029 -
6030 -static inline int a_fetch_add(volatile int *x, int v)
6031 -{
6032 - int old;
6033 - do old = *x;
6034 - while (a_cas(x, old, old+v) != old);
6035 - return old;
6036 -}
6037 -
6038 -static inline void a_inc(volatile int *x)
6039 -{
6040 - a_fetch_add(x, 1);
6041 -}
6042 -
6043 -static inline void a_dec(volatile int *x)
6044 -{
6045 - a_fetch_add(x, -1);
6046 -}
6047 -
6048 -static inline void a_store(volatile int *p, int x)
6049 -{
6050 - __asm__ __volatile__ ("\n"
6051 - " sync\n"
6052 - " stw %1, %0\n"
6053 - " isync\n"
6054 - : "=m"(*p) : "r"(x) : "memory" );
6055 -}
6056 -
6057 -#define a_spin a_barrier
6058 -
6059 -static inline void a_barrier()
6060 -{
6061 - a_cas(&(int){0}, 0, 0);
6062 -}
6063 -
6064 -static inline void a_crash()
6065 -{
6066 - *(volatile char *)0=0;
6067 -}
6068 -
6069 -static inline void a_and(volatile int *p, int v)
6070 -{
6071 - int old;
6072 - do old = *p;
6073 - while (a_cas(p, old, old&v) != old);
6074 -}
6075 -
6076 -static inline void a_or(volatile int *p, int v)
6077 -{
6078 - int old;
6079 - do old = *p;
6080 - while (a_cas(p, old, old|v) != old);
6081 -}
6082 -
6083 -static inline void a_or_l(volatile void *p, long v)
6084 -{
6085 - a_or(p, v);
6086 -}
6087 -
6088 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
6089 -{
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]);
6093 -}
6094 -
6095 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
6096 -{
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]);
6100 -}
6101 -
6102 -#endif
6103 --- /dev/null
6104 +++ b/arch/powerpc/atomic_arch.h
6105 @@ -0,0 +1,39 @@
6106 +#define a_ll a_ll
6107 +static inline int a_ll(volatile int *p)
6108 +{
6109 + int v;
6110 + __asm__ __volatile__ ("lwarx %0, 0, %2" : "=r"(v) : "m"(*p), "r"(p));
6111 + return v;
6112 +}
6113 +
6114 +#define a_sc a_sc
6115 +static inline int a_sc(volatile int *p, int v)
6116 +{
6117 + int r;
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) */
6122 +}
6123 +
6124 +#define a_barrier a_barrier
6125 +static inline void a_barrier()
6126 +{
6127 + __asm__ __volatile__ ("sync" : : : "memory");
6128 +}
6129 +
6130 +#define a_pre_llsc a_barrier
6131 +
6132 +#define a_post_llsc a_post_llsc
6133 +static inline void a_post_llsc()
6134 +{
6135 + __asm__ __volatile__ ("isync" : : : "memory");
6136 +}
6137 +
6138 +#define a_store a_store
6139 +static inline void a_store(volatile int *p, int v)
6140 +{
6141 + a_pre_llsc();
6142 + *p = v;
6143 + a_post_llsc();
6144 +}
6145 --- a/arch/powerpc/bits/mman.h
6146 +++ b/arch/powerpc/bits/mman.h
6147 @@ -4,6 +4,7 @@
6148 #define PROT_READ 1
6149 #define PROT_WRITE 2
6150 #define PROT_EXEC 4
6151 +#define PROT_SAO 0x10
6152 #define PROT_GROWSDOWN 0x01000000
6153 #define PROT_GROWSUP 0x02000000
6154
6155 @@ -35,8 +36,9 @@
6156 #define MS_INVALIDATE 2
6157 #define MS_SYNC 4
6158
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
6164
6165 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
6166 #define MADV_NORMAL 0
6167 --- a/arch/powerpc/bits/statfs.h
6168 +++ /dev/null
6169 @@ -1,7 +0,0 @@
6170 -struct statfs {
6171 - unsigned long f_type, f_bsize;
6172 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
6173 - fsfilcnt_t f_files, f_ffree;
6174 - fsid_t f_fsid;
6175 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
6176 -};
6177 --- a/arch/powerpc/bits/stdarg.h
6178 +++ /dev/null
6179 @@ -1,4 +0,0 @@
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
6197 -#endif
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
6206 -#endif
6207 #define __NR_madvise 205
6208 #define __NR_mincore 206
6209 #define __NR_gettid 207
6210 @@ -231,9 +227,7 @@
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
6216 -#endif
6217 #define __NR_io_setup 227
6218 #define __NR_io_destroy 228
6219 #define __NR_io_getevents 229
6220 @@ -261,9 +255,7 @@
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
6226 -#endif
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
6236 -#else
6237 #define __NR_fstatat64 291
6238 -#endif
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
6250
6251 /*
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
6264 -#endif
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
6273 -#endif
6274 #define SYS_madvise 205
6275 #define SYS_mincore 206
6276 #define SYS_gettid 207
6277 @@ -613,9 +601,7 @@
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
6283 -#endif
6284 #define SYS_io_setup 227
6285 #define SYS_io_destroy 228
6286 #define SYS_io_getevents 229
6287 @@ -643,9 +629,7 @@
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
6293 -#endif
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
6303 -#else
6304 #define SYS_fstatat64 291
6305 -#endif
6306 #define SYS_unlinkat 292
6307 #define SYS_renameat 293
6308 #define SYS_linkat 294
6309 @@ -758,3 +738,7 @@
6310 #define SYS_memfd_create 360
6311 #define SYS_bpf 361
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_
6320
6321 #define DTP_OFFSET 0x8000
6322
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
6325 // GPRs.
6326 -#define CANCEL_REG_IP 32
6327 +#define MC_PC gregs[32]
6328
6329 #define CANARY canary_at_end
6330 --- a/arch/sh/atomic.h
6331 +++ /dev/null
6332 @@ -1,168 +0,0 @@
6333 -#ifndef _INTERNAL_ATOMIC_H
6334 -#define _INTERNAL_ATOMIC_H
6335 -
6336 -#include <stdint.h>
6337 -
6338 -static inline int a_ctz_l(unsigned long x)
6339 -{
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
6343 - };
6344 - return debruijn32[(x&-x)*0x076be629 >> 27];
6345 -}
6346 -
6347 -static inline int a_ctz_64(uint64_t x)
6348 -{
6349 - uint32_t y = x;
6350 - if (!y) {
6351 - y = x>>32;
6352 - return 32 + a_ctz_l(y);
6353 - }
6354 - return a_ctz_l(y);
6355 -}
6356 -
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" \
6362 - " bf 0b\n" \
6363 - " synco\n"
6364 -
6365 -static inline int __sh_cas_llsc(volatile int *p, int t, int s)
6366 -{
6367 - int old;
6368 - __asm__ __volatile__(
6369 - LLSC_START("%1")
6370 - " mov r0, %0\n"
6371 - " cmp/eq %0, %2\n"
6372 - " bf 1f\n"
6373 - " mov %3, r0\n"
6374 - LLSC_END("%1")
6375 - : "=&r"(old) : "r"(p), "r"(t), "r"(s) : LLSC_CLOBBERS);
6376 - return old;
6377 -}
6378 -
6379 -static inline int __sh_swap_llsc(volatile int *x, int v)
6380 -{
6381 - int old;
6382 - __asm__ __volatile__(
6383 - LLSC_START("%1")
6384 - " mov r0, %0\n"
6385 - " mov %2, r0\n"
6386 - LLSC_END("%1")
6387 - : "=&r"(old) : "r"(x), "r"(v) : LLSC_CLOBBERS);
6388 - return old;
6389 -}
6390 -
6391 -static inline int __sh_fetch_add_llsc(volatile int *x, int v)
6392 -{
6393 - int old;
6394 - __asm__ __volatile__(
6395 - LLSC_START("%1")
6396 - " mov r0, %0\n"
6397 - " add %2, r0\n"
6398 - LLSC_END("%1")
6399 - : "=&r"(old) : "r"(x), "r"(v) : LLSC_CLOBBERS);
6400 - return old;
6401 -}
6402 -
6403 -static inline void __sh_store_llsc(volatile int *p, int x)
6404 -{
6405 - __asm__ __volatile__(
6406 - " synco\n"
6407 - " mov.l %1, @%0\n"
6408 - " synco\n"
6409 - : : "r"(p), "r"(x) : "memory");
6410 -}
6411 -
6412 -static inline void __sh_and_llsc(volatile int *x, int v)
6413 -{
6414 - __asm__ __volatile__(
6415 - LLSC_START("%0")
6416 - " and %1, r0\n"
6417 - LLSC_END("%0")
6418 - : : "r"(x), "r"(v) : LLSC_CLOBBERS);
6419 -}
6420 -
6421 -static inline void __sh_or_llsc(volatile int *x, int v)
6422 -{
6423 - __asm__ __volatile__(
6424 - LLSC_START("%0")
6425 - " or %1, r0\n"
6426 - LLSC_END("%0")
6427 - : : "r"(x), "r"(v) : LLSC_CLOBBERS);
6428 -}
6429 -
6430 -#ifdef __SH4A__
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)
6437 -#else
6438 -
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);
6445 -
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)
6452 -#endif
6453 -
6454 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
6455 -{
6456 - return (void *)a_cas(p, (int)t, (int)s);
6457 -}
6458 -
6459 -static inline void a_inc(volatile int *x)
6460 -{
6461 - a_fetch_add(x, 1);
6462 -}
6463 -
6464 -static inline void a_dec(volatile int *x)
6465 -{
6466 - a_fetch_add(x, -1);
6467 -}
6468 -
6469 -#define a_spin a_barrier
6470 -
6471 -static inline void a_barrier()
6472 -{
6473 - a_cas(&(int){0}, 0, 0);
6474 -}
6475 -
6476 -static inline void a_crash()
6477 -{
6478 - *(volatile char *)0=0;
6479 -}
6480 -
6481 -static inline void a_or_l(volatile void *p, long v)
6482 -{
6483 - a_or(p, v);
6484 -}
6485 -
6486 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
6487 -{
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]);
6491 -}
6492 -
6493 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
6494 -{
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]);
6498 -}
6499 -
6500 -#endif
6501 --- /dev/null
6502 +++ b/arch/sh/atomic_arch.h
6503 @@ -0,0 +1,46 @@
6504 +#if defined(__SH4A__)
6505 +
6506 +#define a_ll a_ll
6507 +static inline int a_ll(volatile int *p)
6508 +{
6509 + int v;
6510 + __asm__ __volatile__ ("movli.l @%1, %0" : "=z"(v) : "r"(p), "m"(*p));
6511 + return v;
6512 +}
6513 +
6514 +#define a_sc a_sc
6515 +static inline int a_sc(volatile int *p, int v)
6516 +{
6517 + int r;
6518 + __asm__ __volatile__ (
6519 + "movco.l %2, @%3 ; movt %0"
6520 + : "=r"(r), "=m"(*p) : "z"(v), "r"(p) : "memory", "cc");
6521 + return r;
6522 +}
6523 +
6524 +#define a_barrier a_barrier
6525 +static inline void a_barrier()
6526 +{
6527 + __asm__ __volatile__ ("synco" : : "memory");
6528 +}
6529 +
6530 +#define a_pre_llsc a_barrier
6531 +#define a_post_llsc a_barrier
6532 +
6533 +#else
6534 +
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)
6538 +{
6539 + register int r1 __asm__("r1");
6540 + register int r2 __asm__("r2") = t;
6541 + register int r3 __asm__("r3") = s;
6542 + __asm__ __volatile__ (
6543 + "jsr @%4 ; nop"
6544 + : "=r"(r1), "+r"(r3) : "z"(p), "r"(r2), "r"(__sh_cas_ptr)
6545 + : "memory", "pr", "cc");
6546 + return r3;
6547 +}
6548 +
6549 +#endif
6550 --- a/arch/sh/bits/errno.h
6551 +++ /dev/null
6552 @@ -1,134 +0,0 @@
6553 -#define EPERM 1
6554 -#define ENOENT 2
6555 -#define ESRCH 3
6556 -#define EINTR 4
6557 -#define EIO 5
6558 -#define ENXIO 6
6559 -#define E2BIG 7
6560 -#define ENOEXEC 8
6561 -#define EBADF 9
6562 -#define ECHILD 10
6563 -#define EAGAIN 11
6564 -#define ENOMEM 12
6565 -#define EACCES 13
6566 -#define EFAULT 14
6567 -#define ENOTBLK 15
6568 -#define EBUSY 16
6569 -#define EEXIST 17
6570 -#define EXDEV 18
6571 -#define ENODEV 19
6572 -#define ENOTDIR 20
6573 -#define EISDIR 21
6574 -#define EINVAL 22
6575 -#define ENFILE 23
6576 -#define EMFILE 24
6577 -#define ENOTTY 25
6578 -#define ETXTBSY 26
6579 -#define EFBIG 27
6580 -#define ENOSPC 28
6581 -#define ESPIPE 29
6582 -#define EROFS 30
6583 -#define EMLINK 31
6584 -#define EPIPE 32
6585 -#define EDOM 33
6586 -#define ERANGE 34
6587 -#define EDEADLK 35
6588 -#define ENAMETOOLONG 36
6589 -#define ENOLCK 37
6590 -#define ENOSYS 38
6591 -#define ENOTEMPTY 39
6592 -#define ELOOP 40
6593 -#define EWOULDBLOCK EAGAIN
6594 -#define ENOMSG 42
6595 -#define EIDRM 43
6596 -#define ECHRNG 44
6597 -#define EL2NSYNC 45
6598 -#define EL3HLT 46
6599 -#define EL3RST 47
6600 -#define ELNRNG 48
6601 -#define EUNATCH 49
6602 -#define ENOCSI 50
6603 -#define EL2HLT 51
6604 -#define EBADE 52
6605 -#define EBADR 53
6606 -#define EXFULL 54
6607 -#define ENOANO 55
6608 -#define EBADRQC 56
6609 -#define EBADSLT 57
6610 -#define EDEADLOCK EDEADLK
6611 -#define EBFONT 59
6612 -#define ENOSTR 60
6613 -#define ENODATA 61
6614 -#define ETIME 62
6615 -#define ENOSR 63
6616 -#define ENONET 64
6617 -#define ENOPKG 65
6618 -#define EREMOTE 66
6619 -#define ENOLINK 67
6620 -#define EADV 68
6621 -#define ESRMNT 69
6622 -#define ECOMM 70
6623 -#define EPROTO 71
6624 -#define EMULTIHOP 72
6625 -#define EDOTDOT 73
6626 -#define EBADMSG 74
6627 -#define EOVERFLOW 75
6628 -#define ENOTUNIQ 76
6629 -#define EBADFD 77
6630 -#define EREMCHG 78
6631 -#define ELIBACC 79
6632 -#define ELIBBAD 80
6633 -#define ELIBSCN 81
6634 -#define ELIBMAX 82
6635 -#define ELIBEXEC 83
6636 -#define EILSEQ 84
6637 -#define ERESTART 85
6638 -#define ESTRPIPE 86
6639 -#define EUSERS 87
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
6669 -#define ESTALE 116
6670 -#define EUCLEAN 117
6671 -#define ENOTNAM 118
6672 -#define ENAVAIL 119
6673 -#define EISNAM 120
6674 -#define EREMOTEIO 121
6675 -#define EDQUOT 122
6676 -#define ENOMEDIUM 123
6677 -#define EMEDIUMTYPE 124
6678 -#define ECANCELED 125
6679 -#define ENOKEY 126
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
6688 +++ /dev/null
6689 @@ -1,40 +0,0 @@
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
6702 -
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
6710 -
6711 -#define F_DUPFD 0
6712 -#define F_GETFD 1
6713 -#define F_SETFD 2
6714 -#define F_GETFL 3
6715 -#define F_SETFL 4
6716 -
6717 -#define F_SETOWN 8
6718 -#define F_GETOWN 9
6719 -#define F_SETSIG 10
6720 -#define F_GETSIG 11
6721 -
6722 -#define F_GETLK 12
6723 -#define F_SETLK 13
6724 -#define F_SETLKW 14
6725 -
6726 -#define F_SETOWN_EX 15
6727 -#define F_GETOWN_EX 16
6728 -
6729 -#define F_GETOWNER_UIDS 17
6730 --- a/arch/sh/bits/ipc.h
6731 +++ /dev/null
6732 @@ -1,14 +0,0 @@
6733 -struct ipc_perm
6734 -{
6735 - key_t __ipc_perm_key;
6736 - uid_t uid;
6737 - gid_t gid;
6738 - uid_t cuid;
6739 - gid_t cgid;
6740 - mode_t mode;
6741 - int __ipc_perm_seq;
6742 - long __pad1;
6743 - long __pad2;
6744 -};
6745 -
6746 -#define IPC_64 0x100
6747 --- a/arch/sh/bits/mman.h
6748 +++ b/arch/sh/bits/mman.h
6749 @@ -38,6 +38,7 @@
6750
6751 #define MCL_CURRENT 1
6752 #define MCL_FUTURE 2
6753 +#define MCL_ONFAULT 4
6754
6755 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
6756 #define MADV_NORMAL 0
6757 --- a/arch/sh/bits/msg.h
6758 +++ /dev/null
6759 @@ -1,16 +0,0 @@
6760 -struct msqid_ds
6761 -{
6762 - struct ipc_perm msg_perm;
6763 - time_t msg_stime;
6764 - int __unused1;
6765 - time_t msg_rtime;
6766 - int __unused2;
6767 - time_t msg_ctime;
6768 - int __unused3;
6769 - unsigned long msg_cbytes;
6770 - msgqnum_t msg_qnum;
6771 - msglen_t msg_qbytes;
6772 - pid_t msg_lspid;
6773 - pid_t msg_lrpid;
6774 - unsigned long __unused[2];
6775 -};
6776 --- a/arch/sh/bits/sem.h
6777 +++ /dev/null
6778 @@ -1,16 +0,0 @@
6779 -struct semid_ds {
6780 - struct ipc_perm sem_perm;
6781 - time_t sem_otime;
6782 - time_t __unused1;
6783 - time_t sem_ctime;
6784 - time_t __unused2;
6785 -#if __BYTE_ORDER == __LITTLE_ENDIAN
6786 - unsigned short sem_nsems;
6787 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
6788 -#else
6789 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
6790 - unsigned short sem_nsems;
6791 -#endif
6792 - time_t __unused3;
6793 - time_t __unused4;
6794 -};
6795 --- a/arch/sh/bits/socket.h
6796 +++ /dev/null
6797 @@ -1,17 +0,0 @@
6798 -struct msghdr
6799 -{
6800 - void *msg_name;
6801 - socklen_t msg_namelen;
6802 - struct iovec *msg_iov;
6803 - int msg_iovlen;
6804 - void *msg_control;
6805 - socklen_t msg_controllen;
6806 - int msg_flags;
6807 -};
6808 -
6809 -struct cmsghdr
6810 -{
6811 - socklen_t cmsg_len;
6812 - int cmsg_level;
6813 - int cmsg_type;
6814 -};
6815 --- a/arch/sh/bits/statfs.h
6816 +++ /dev/null
6817 @@ -1,7 +0,0 @@
6818 -struct statfs {
6819 - unsigned long f_type, f_bsize;
6820 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
6821 - fsfilcnt_t f_files, f_ffree;
6822 - fsid_t f_fsid;
6823 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
6824 -};
6825 --- a/arch/sh/bits/stdarg.h
6826 +++ /dev/null
6827 @@ -1,4 +0,0 @@
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
6833 +++ /dev/null
6834 @@ -1,160 +0,0 @@
6835 -struct termios
6836 -{
6837 - tcflag_t c_iflag;
6838 - tcflag_t c_oflag;
6839 - tcflag_t c_cflag;
6840 - tcflag_t c_lflag;
6841 - cc_t c_line;
6842 - cc_t c_cc[NCCS];
6843 - speed_t __c_ispeed;
6844 - speed_t __c_ospeed;
6845 -};
6846 -
6847 -#define VINTR 0
6848 -#define VQUIT 1
6849 -#define VERASE 2
6850 -#define VKILL 3
6851 -#define VEOF 4
6852 -#define VTIME 5
6853 -#define VMIN 6
6854 -#define VSWTC 7
6855 -#define VSTART 8
6856 -#define VSTOP 9
6857 -#define VSUSP 10
6858 -#define VEOL 11
6859 -#define VREPRINT 12
6860 -#define VDISCARD 13
6861 -#define VWERASE 14
6862 -#define VLNEXT 15
6863 -#define VEOL2 16
6864 -
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
6880 -
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
6908 -
6909 -#define VTDLY 0040000
6910 -#define VT0 0000000
6911 -#define VT1 0040000
6912 -
6913 -#define B0 0000000
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
6929 -
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
6945 -
6946 -#define CBAUD 0010017
6947 -
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
6959 -
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
6969 -
6970 -#define ECHOCTL 0001000
6971 -#define ECHOPRT 0002000
6972 -#define ECHOKE 0004000
6973 -#define FLUSHO 0010000
6974 -#define PENDIN 0040000
6975 -
6976 -#define TCOOFF 0
6977 -#define TCOON 1
6978 -#define TCIOFF 2
6979 -#define TCION 3
6980 -
6981 -#define TCIFLUSH 0
6982 -#define TCOFLUSH 1
6983 -#define TCIOFLUSH 2
6984 -
6985 -#define TCSANOW 0
6986 -#define TCSADRAIN 1
6987 -#define TCSAFLUSH 2
6988 -
6989 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
6990 -#define CBAUDEX 0010000
6991 -#define CRTSCTS 020000000000
6992 -#define EXTPROC 0200000
6993 -#define XTABS 0014000
6994 -#endif
6995 --- a/arch/sh/crt_arch.h
6996 +++ b/arch/sh/crt_arch.h
6997 @@ -22,7 +22,8 @@ START ": \n"
6998 " mov.l 1f, r5 \n"
6999 " mov.l 1f+4, r6 \n"
7000 " add r0, r5 \n"
7001 -" bsr __fdpic_fixup \n"
7002 +" mov.l 4f, r1 \n"
7003 +"5: bsrf r1 \n"
7004 " add r0, r6 \n"
7005 " mov r0, r12 \n"
7006 #endif
7007 @@ -31,11 +32,16 @@ START ": \n"
7008 " mov.l r9, @-r15 \n"
7009 " mov.l r8, @-r15 \n"
7010 " mov #-16, r0 \n"
7011 -" bsr " START "_c \n"
7012 +" mov.l 2f, r1 \n"
7013 +"3: bsrf r1 \n"
7014 " and r0, r15 \n"
7015 ".align 2 \n"
7016 "1: .long __ROFIXUP_LIST__@PCREL \n"
7017 " .long __ROFIXUP_END__@PCREL + 4 \n"
7018 +"2: .long " START "_c@PCREL - (3b+4-.) \n"
7019 +#ifndef SHARED
7020 +"4: .long __fdpic_fixup@PCREL - (5b+4-.) \n"
7021 +#endif
7022 );
7023
7024 #ifndef SHARED
7025 @@ -53,13 +59,14 @@ START ": \n"
7026 " add r0, r5 \n"
7027 " mov r15, r4 \n"
7028 " mov #-16, r0 \n"
7029 -" and r0, r15 \n"
7030 -" bsr " START "_c \n"
7031 -" nop \n"
7032 +" mov.l 2f, r1 \n"
7033 +"3: bsrf r1 \n"
7034 +" and r0, r15 \n"
7035 ".align 2 \n"
7036 ".weak _DYNAMIC \n"
7037 ".hidden _DYNAMIC \n"
7038 "1: .long _DYNAMIC-. \n"
7039 +"2: .long " START "_c@PCREL - (3b+4-.) \n"
7040 );
7041
7042 #endif
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)
7048
7049 -#define CANCEL_REG_IP 17
7050 +#define MC_PC sc_pc
7051 --- a/arch/sh/reloc.h
7052 +++ b/arch/sh/reloc.h
7053 @@ -32,6 +32,8 @@
7054 #define REL_DTPOFF R_SH_TLS_DTPOFF32
7055 #define REL_TPOFF R_SH_TLS_TPOFF32
7056
7057 +#define DL_NOMMU_SUPPORT 1
7058 +
7059 #if __SH_FDPIC__
7060 #define REL_FUNCDESC R_SH_FUNCDESC
7061 #define REL_FUNCDESC_VAL R_SH_FUNCDESC_VALUE
7062 --- a/arch/sh/src/__fpscr_values.c
7063 +++ /dev/null
7064 @@ -1,5 +0,0 @@
7065 -#include "libc.h"
7066 -
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 };
7069 -
7070 --- a/arch/sh/src/__set_thread_area.c
7071 +++ /dev/null
7072 @@ -1,34 +0,0 @@
7073 -#include "pthread_impl.h"
7074 -#include "libc.h"
7075 -#include "sh_atomic.h"
7076 -#include <elf.h>
7077 -
7078 -/* Also perform sh-specific init */
7079 -
7080 -#define CPU_HAS_LLSC 0x0040
7081 -
7082 -__attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model, __sh_nommu;
7083 -
7084 -int __set_thread_area(void *p)
7085 -{
7086 - size_t *aux;
7087 - __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
7088 -#ifndef __SH4A__
7089 - if (__hwcap & CPU_HAS_LLSC) {
7090 - __sh_atomic_model = SH_A_LLSC;
7091 - return 0;
7092 - }
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;
7099 - __sh_nommu = 1;
7100 - return 0;
7101 - }
7102 -#endif
7103 - /* __sh_atomic_model = SH_A_GUSA; */ /* 0, default */
7104 -#endif
7105 - return 0;
7106 -}
7107 --- a/arch/sh/src/__shcall.c
7108 +++ /dev/null
7109 @@ -1,5 +0,0 @@
7110 -__attribute__((__visibility__("hidden")))
7111 -int __shcall(void *arg, int (*func)(void *))
7112 -{
7113 - return func(arg);
7114 -}
7115 --- a/arch/sh/src/__unmapself.c
7116 +++ /dev/null
7117 @@ -1,24 +0,0 @@
7118 -#include "pthread_impl.h"
7119 -
7120 -void __unmapself_sh_mmu(void *, size_t);
7121 -void __unmapself_sh_nommu(void *, size_t);
7122 -
7123 -#if !defined(__SH3__) && !defined(__SH4__)
7124 -#define __unmapself __unmapself_sh_nommu
7125 -#include "dynlink.h"
7126 -#undef CRTJMP
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"
7131 -#undef __unmapself
7132 -extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
7133 -#else
7134 -#define __sh_nommu 0
7135 -#endif
7136 -
7137 -void __unmapself(void *base, size_t size)
7138 -{
7139 - if (__sh_nommu) __unmapself_sh_nommu(base, size);
7140 - else __unmapself_sh_mmu(base, size);
7141 -}
7142 --- a/arch/sh/src/atomic.c
7143 +++ /dev/null
7144 @@ -1,158 +0,0 @@
7145 -#ifndef __SH4A__
7146 -
7147 -#include "sh_atomic.h"
7148 -#include "atomic.h"
7149 -#include "libc.h"
7150 -
7151 -static inline unsigned mask()
7152 -{
7153 - unsigned sr;
7154 - __asm__ __volatile__ ( "\n"
7155 - " stc sr,r0 \n"
7156 - " mov r0,%0 \n"
7157 - " or #0xf0,r0 \n"
7158 - " ldc r0,sr \n"
7159 - : "=&r"(sr) : : "memory", "r0" );
7160 - return sr;
7161 -}
7162 -
7163 -static inline void unmask(unsigned sr)
7164 -{
7165 - __asm__ __volatile__ ( "ldc %0,sr" : : "r"(sr) : "memory" );
7166 -}
7167 -
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
7174 - */
7175 -#define GUSA_CLOBBERS "r0", "r1", "memory"
7176 -#define GUSA_START(mem,old,nop) \
7177 - " .align 2\n" \
7178 - " mova 1f, r0\n" \
7179 - nop \
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"
7189 -
7190 -int __sh_cas(volatile int *p, int t, int s)
7191 -{
7192 - if (__sh_atomic_model == SH_A_LLSC) return __sh_cas_llsc(p, t, s);
7193 -
7194 - if (__sh_atomic_model == SH_A_IMASK) {
7195 - unsigned sr = mask();
7196 - int old = *p;
7197 - if (old==t) *p = s;
7198 - unmask(sr);
7199 - return old;
7200 - }
7201 -
7202 - int old;
7203 - __asm__ __volatile__(
7204 - GUSA_START_EVEN("%1", "%0")
7205 - " cmp/eq %0, %2\n"
7206 - " bf 1f\n"
7207 - GUSA_END("%1", "%3")
7208 - : "=&r"(old) : "r"(p), "r"(t), "r"(s) : GUSA_CLOBBERS, "t");
7209 - return old;
7210 -}
7211 -
7212 -int __sh_swap(volatile int *x, int v)
7213 -{
7214 - if (__sh_atomic_model == SH_A_LLSC) return __sh_swap_llsc(x, v);
7215 -
7216 - if (__sh_atomic_model == SH_A_IMASK) {
7217 - unsigned sr = mask();
7218 - int old = *x;
7219 - *x = v;
7220 - unmask(sr);
7221 - return old;
7222 - }
7223 -
7224 - int old;
7225 - __asm__ __volatile__(
7226 - GUSA_START_EVEN("%1", "%0")
7227 - GUSA_END("%1", "%2")
7228 - : "=&r"(old) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7229 - return old;
7230 -}
7231 -
7232 -int __sh_fetch_add(volatile int *x, int v)
7233 -{
7234 - if (__sh_atomic_model == SH_A_LLSC) return __sh_fetch_add_llsc(x, v);
7235 -
7236 - if (__sh_atomic_model == SH_A_IMASK) {
7237 - unsigned sr = mask();
7238 - int old = *x;
7239 - *x = old + v;
7240 - unmask(sr);
7241 - return old;
7242 - }
7243 -
7244 - int old, dummy;
7245 - __asm__ __volatile__(
7246 - GUSA_START_EVEN("%2", "%0")
7247 - " mov %0, %1\n"
7248 - " add %3, %1\n"
7249 - GUSA_END("%2", "%1")
7250 - : "=&r"(old), "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7251 - return old;
7252 -}
7253 -
7254 -void __sh_store(volatile int *p, int x)
7255 -{
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");
7260 -}
7261 -
7262 -void __sh_and(volatile int *x, int v)
7263 -{
7264 - if (__sh_atomic_model == SH_A_LLSC) return __sh_and_llsc(x, v);
7265 -
7266 - if (__sh_atomic_model == SH_A_IMASK) {
7267 - unsigned sr = mask();
7268 - int old = *x;
7269 - *x = old & v;
7270 - unmask(sr);
7271 - return;
7272 - }
7273 -
7274 - int dummy;
7275 - __asm__ __volatile__(
7276 - GUSA_START_ODD("%1", "%0")
7277 - " and %2, %0\n"
7278 - GUSA_END("%1", "%0")
7279 - : "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7280 -}
7281 -
7282 -void __sh_or(volatile int *x, int v)
7283 -{
7284 - if (__sh_atomic_model == SH_A_LLSC) return __sh_or_llsc(x, v);
7285 -
7286 - if (__sh_atomic_model == SH_A_IMASK) {
7287 - unsigned sr = mask();
7288 - int old = *x;
7289 - *x = old | v;
7290 - unmask(sr);
7291 - return;
7292 - }
7293 -
7294 - int dummy;
7295 - __asm__ __volatile__(
7296 - GUSA_START_ODD("%1", "%0")
7297 - " or %2, %0\n"
7298 - GUSA_END("%1", "%0")
7299 - : "=&r"(dummy) : "r"(x), "r"(v) : GUSA_CLOBBERS);
7300 -}
7301 -
7302 -#endif
7303 --- a/arch/sh/src/sh_atomic.h
7304 +++ /dev/null
7305 @@ -1,15 +0,0 @@
7306 -#ifndef _SH_ATOMIC_H
7307 -#define _SH_ATOMIC_H
7308 -
7309 -#define SH_A_GUSA 0
7310 -#define SH_A_LLSC 1
7311 -#define SH_A_CAS 2
7312 -#if !defined(__SH3__) && !defined(__SH4__)
7313 -#define SH_A_IMASK 3
7314 -#else
7315 -#define SH_A_IMASK -1LL /* unmatchable by unsigned int */
7316 -#endif
7317 -
7318 -extern __attribute__((__visibility__("hidden"))) unsigned __sh_atomic_model;
7319 -
7320 -#endif
7321 --- a/arch/x32/atomic.h
7322 +++ /dev/null
7323 @@ -1,105 +0,0 @@
7324 -#ifndef _INTERNAL_ATOMIC_H
7325 -#define _INTERNAL_ATOMIC_H
7326 -
7327 -#include <stdint.h>
7328 -
7329 -static inline int a_ctz_64(uint64_t x)
7330 -{
7331 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7332 - return x;
7333 -}
7334 -
7335 -static inline int a_ctz_l(unsigned long x)
7336 -{
7337 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7338 - return x;
7339 -}
7340 -
7341 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
7342 -{
7343 - __asm__( "lock ; and %1, %0"
7344 - : "=m"(*p) : "r"(v) : "memory" );
7345 -}
7346 -
7347 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
7348 -{
7349 - __asm__( "lock ; or %1, %0"
7350 - : "=m"(*p) : "r"(v) : "memory" );
7351 -}
7352 -
7353 -static inline void a_or_l(volatile void *p, long v)
7354 -{
7355 - __asm__( "lock ; or %1, %0"
7356 - : "=m"(*(long *)p) : "r"(v) : "memory" );
7357 -}
7358 -
7359 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
7360 -{
7361 - __asm__( "lock ; cmpxchg %3, %1"
7362 - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
7363 - return t;
7364 -}
7365 -
7366 -static inline int a_cas(volatile int *p, int t, int s)
7367 -{
7368 - __asm__( "lock ; cmpxchg %3, %1"
7369 - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
7370 - return t;
7371 -}
7372 -
7373 -static inline void a_or(volatile int *p, int v)
7374 -{
7375 - __asm__( "lock ; or %1, %0"
7376 - : "=m"(*p) : "r"(v) : "memory" );
7377 -}
7378 -
7379 -static inline void a_and(volatile int *p, int v)
7380 -{
7381 - __asm__( "lock ; and %1, %0"
7382 - : "=m"(*p) : "r"(v) : "memory" );
7383 -}
7384 -
7385 -static inline int a_swap(volatile int *x, int v)
7386 -{
7387 - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
7388 - return v;
7389 -}
7390 -
7391 -static inline int a_fetch_add(volatile int *x, int v)
7392 -{
7393 - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
7394 - return v;
7395 -}
7396 -
7397 -static inline void a_inc(volatile int *x)
7398 -{
7399 - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
7400 -}
7401 -
7402 -static inline void a_dec(volatile int *x)
7403 -{
7404 - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
7405 -}
7406 -
7407 -static inline void a_store(volatile int *p, int x)
7408 -{
7409 - __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
7410 -}
7411 -
7412 -static inline void a_spin()
7413 -{
7414 - __asm__ __volatile__( "pause" : : : "memory" );
7415 -}
7416 -
7417 -static inline void a_barrier()
7418 -{
7419 - __asm__ __volatile__( "" : : : "memory" );
7420 -}
7421 -
7422 -static inline void a_crash()
7423 -{
7424 - __asm__ __volatile__( "hlt" : : : "memory" );
7425 -}
7426 -
7427 -
7428 -#endif
7429 --- /dev/null
7430 +++ b/arch/x32/atomic_arch.h
7431 @@ -0,0 +1,114 @@
7432 +#define a_cas a_cas
7433 +static inline int a_cas(volatile int *p, int t, int s)
7434 +{
7435 + __asm__ __volatile__ (
7436 + "lock ; cmpxchg %3, %1"
7437 + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
7438 + return t;
7439 +}
7440 +
7441 +#define a_swap a_swap
7442 +static inline int a_swap(volatile int *p, int v)
7443 +{
7444 + __asm__ __volatile__(
7445 + "xchg %0, %1"
7446 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
7447 + return v;
7448 +}
7449 +
7450 +#define a_fetch_add a_fetch_add
7451 +static inline int a_fetch_add(volatile int *p, int v)
7452 +{
7453 + __asm__ __volatile__(
7454 + "lock ; xadd %0, %1"
7455 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
7456 + return v;
7457 +}
7458 +
7459 +#define a_and a_and
7460 +static inline void a_and(volatile int *p, int v)
7461 +{
7462 + __asm__ __volatile__(
7463 + "lock ; and %1, %0"
7464 + : "=m"(*p) : "r"(v) : "memory" );
7465 +}
7466 +
7467 +#define a_or a_or
7468 +static inline void a_or(volatile int *p, int v)
7469 +{
7470 + __asm__ __volatile__(
7471 + "lock ; or %1, %0"
7472 + : "=m"(*p) : "r"(v) : "memory" );
7473 +}
7474 +
7475 +#define a_and_64 a_and_64
7476 +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
7477 +{
7478 + __asm__ __volatile(
7479 + "lock ; and %1, %0"
7480 + : "=m"(*p) : "r"(v) : "memory" );
7481 +}
7482 +
7483 +#define a_or_64 a_or_64
7484 +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
7485 +{
7486 + __asm__ __volatile__(
7487 + "lock ; or %1, %0"
7488 + : "=m"(*p) : "r"(v) : "memory" );
7489 +}
7490 +
7491 +#define a_inc a_inc
7492 +static inline void a_inc(volatile int *p)
7493 +{
7494 + __asm__ __volatile__(
7495 + "lock ; incl %0"
7496 + : "=m"(*p) : "m"(*p) : "memory" );
7497 +}
7498 +
7499 +#define a_dec a_dec
7500 +static inline void a_dec(volatile int *p)
7501 +{
7502 + __asm__ __volatile__(
7503 + "lock ; decl %0"
7504 + : "=m"(*p) : "m"(*p) : "memory" );
7505 +}
7506 +
7507 +#define a_store a_store
7508 +static inline void a_store(volatile int *p, int x)
7509 +{
7510 + __asm__ __volatile__(
7511 + "mov %1, %0 ; lock ; orl $0,(%%rsp)"
7512 + : "=m"(*p) : "r"(x) : "memory" );
7513 +}
7514 +
7515 +#define a_barrier a_barrier
7516 +static inline void a_barrier()
7517 +{
7518 + __asm__ __volatile__( "" : : : "memory" );
7519 +}
7520 +
7521 +#define a_pause a_pause
7522 +static inline void a_spin()
7523 +{
7524 + __asm__ __volatile__( "pause" : : : "memory" );
7525 +}
7526 +
7527 +#define a_crash a_crash
7528 +static inline void a_crash()
7529 +{
7530 + __asm__ __volatile__( "hlt" : : : "memory" );
7531 +}
7532 +
7533 +#define a_ctz_64 a_ctz_64
7534 +static inline int a_ctz_64(uint64_t x)
7535 +{
7536 + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7537 + return x;
7538 +}
7539 +
7540 +#define a_ctz_l a_ctz_l
7541 +static inline int a_ctz_l(unsigned long x)
7542 +{
7543 + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
7544 + return x;
7545 +}
7546 --- a/arch/x32/bits/errno.h
7547 +++ /dev/null
7548 @@ -1,134 +0,0 @@
7549 -#define EPERM 1
7550 -#define ENOENT 2
7551 -#define ESRCH 3
7552 -#define EINTR 4
7553 -#define EIO 5
7554 -#define ENXIO 6
7555 -#define E2BIG 7
7556 -#define ENOEXEC 8
7557 -#define EBADF 9
7558 -#define ECHILD 10
7559 -#define EAGAIN 11
7560 -#define ENOMEM 12
7561 -#define EACCES 13
7562 -#define EFAULT 14
7563 -#define ENOTBLK 15
7564 -#define EBUSY 16
7565 -#define EEXIST 17
7566 -#define EXDEV 18
7567 -#define ENODEV 19
7568 -#define ENOTDIR 20
7569 -#define EISDIR 21
7570 -#define EINVAL 22
7571 -#define ENFILE 23
7572 -#define EMFILE 24
7573 -#define ENOTTY 25
7574 -#define ETXTBSY 26
7575 -#define EFBIG 27
7576 -#define ENOSPC 28
7577 -#define ESPIPE 29
7578 -#define EROFS 30
7579 -#define EMLINK 31
7580 -#define EPIPE 32
7581 -#define EDOM 33
7582 -#define ERANGE 34
7583 -#define EDEADLK 35
7584 -#define ENAMETOOLONG 36
7585 -#define ENOLCK 37
7586 -#define ENOSYS 38
7587 -#define ENOTEMPTY 39
7588 -#define ELOOP 40
7589 -#define EWOULDBLOCK EAGAIN
7590 -#define ENOMSG 42
7591 -#define EIDRM 43
7592 -#define ECHRNG 44
7593 -#define EL2NSYNC 45
7594 -#define EL3HLT 46
7595 -#define EL3RST 47
7596 -#define ELNRNG 48
7597 -#define EUNATCH 49
7598 -#define ENOCSI 50
7599 -#define EL2HLT 51
7600 -#define EBADE 52
7601 -#define EBADR 53
7602 -#define EXFULL 54
7603 -#define ENOANO 55
7604 -#define EBADRQC 56
7605 -#define EBADSLT 57
7606 -#define EDEADLOCK EDEADLK
7607 -#define EBFONT 59
7608 -#define ENOSTR 60
7609 -#define ENODATA 61
7610 -#define ETIME 62
7611 -#define ENOSR 63
7612 -#define ENONET 64
7613 -#define ENOPKG 65
7614 -#define EREMOTE 66
7615 -#define ENOLINK 67
7616 -#define EADV 68
7617 -#define ESRMNT 69
7618 -#define ECOMM 70
7619 -#define EPROTO 71
7620 -#define EMULTIHOP 72
7621 -#define EDOTDOT 73
7622 -#define EBADMSG 74
7623 -#define EOVERFLOW 75
7624 -#define ENOTUNIQ 76
7625 -#define EBADFD 77
7626 -#define EREMCHG 78
7627 -#define ELIBACC 79
7628 -#define ELIBBAD 80
7629 -#define ELIBSCN 81
7630 -#define ELIBMAX 82
7631 -#define ELIBEXEC 83
7632 -#define EILSEQ 84
7633 -#define ERESTART 85
7634 -#define ESTRPIPE 86
7635 -#define EUSERS 87
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
7665 -#define ESTALE 116
7666 -#define EUCLEAN 117
7667 -#define ENOTNAM 118
7668 -#define ENAVAIL 119
7669 -#define EISNAM 120
7670 -#define EREMOTEIO 121
7671 -#define EDQUOT 122
7672 -#define ENOMEDIUM 123
7673 -#define EMEDIUMTYPE 124
7674 -#define ECANCELED 125
7675 -#define ENOKEY 126
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
7685 @@ -38,6 +38,7 @@
7686
7687 #define MCL_CURRENT 1
7688 #define MCL_FUTURE 2
7689 +#define MCL_ONFAULT 4
7690
7691 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
7692 #define MADV_NORMAL 0
7693 --- a/arch/x32/bits/sem.h
7694 +++ /dev/null
7695 @@ -1,16 +0,0 @@
7696 -struct semid_ds {
7697 - struct ipc_perm sem_perm;
7698 - time_t sem_otime;
7699 - time_t __unused1;
7700 - time_t sem_ctime;
7701 - time_t __unused2;
7702 -#if __BYTE_ORDER == __LITTLE_ENDIAN
7703 - unsigned short sem_nsems;
7704 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
7705 -#else
7706 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
7707 - unsigned short sem_nsems;
7708 -#endif
7709 - time_t __unused3;
7710 - time_t __unused4;
7711 -};
7712 --- a/arch/x32/bits/stdarg.h
7713 +++ /dev/null
7714 @@ -1,4 +0,0 @@
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
7721 @@ -277,6 +277,9 @@
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)
7728
7729 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
7730 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
7731 @@ -607,6 +610,9 @@
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
7738
7739
7740 #define SYS_rt_sigaction __NR_rt_sigaction
7741 --- a/arch/x32/bits/termios.h
7742 +++ /dev/null
7743 @@ -1,160 +0,0 @@
7744 -struct termios
7745 -{
7746 - tcflag_t c_iflag;
7747 - tcflag_t c_oflag;
7748 - tcflag_t c_cflag;
7749 - tcflag_t c_lflag;
7750 - cc_t c_line;
7751 - cc_t c_cc[NCCS];
7752 - speed_t __c_ispeed;
7753 - speed_t __c_ospeed;
7754 -};
7755 -
7756 -#define VINTR 0
7757 -#define VQUIT 1
7758 -#define VERASE 2
7759 -#define VKILL 3
7760 -#define VEOF 4
7761 -#define VTIME 5
7762 -#define VMIN 6
7763 -#define VSWTC 7
7764 -#define VSTART 8
7765 -#define VSTOP 9
7766 -#define VSUSP 10
7767 -#define VEOL 11
7768 -#define VREPRINT 12
7769 -#define VDISCARD 13
7770 -#define VWERASE 14
7771 -#define VLNEXT 15
7772 -#define VEOL2 16
7773 -
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
7789 -
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
7817 -
7818 -#define VTDLY 0040000
7819 -#define VT0 0000000
7820 -#define VT1 0040000
7821 -
7822 -#define B0 0000000
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
7838 -
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
7854 -
7855 -#define CBAUD 0010017
7856 -
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
7868 -
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
7878 -
7879 -#define ECHOCTL 0001000
7880 -#define ECHOPRT 0002000
7881 -#define ECHOKE 0004000
7882 -#define FLUSHO 0010000
7883 -#define PENDIN 0040000
7884 -
7885 -#define TCOOFF 0
7886 -#define TCOON 1
7887 -#define TCIOFF 2
7888 -#define TCION 3
7889 -
7890 -#define TCIFLUSH 0
7891 -#define TCOFLUSH 1
7892 -#define TCIOFLUSH 2
7893 -
7894 -#define TCSANOW 0
7895 -#define TCSADRAIN 1
7896 -#define TCSAFLUSH 2
7897 -
7898 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
7899 -#define CBAUDEX 0010000
7900 -#define CRTSCTS 020000000000
7901 -#define EXTPROC 0200000
7902 -#define XTABS 0014000
7903 -#endif
7904 --- a/arch/x32/pthread_arch.h
7905 +++ b/arch/x32/pthread_arch.h
7906 @@ -7,6 +7,6 @@ static inline struct pthread *__pthread_
7907
7908 #define TP_ADJ(p) (p)
7909
7910 -#define CANCEL_REG_IP 32
7911 +#define MC_PC gregs[REG_RIP]
7912
7913 #define CANARY canary2
7914 --- a/arch/x32/src/syscall_cp_fixup.c
7915 +++ /dev/null
7916 @@ -1,42 +0,0 @@
7917 -#include <sys/syscall.h>
7918 -
7919 -#ifdef SHARED
7920 -__attribute__((__visibility__("hidden")))
7921 -#endif
7922 -long __syscall_cp_internal(volatile void*, long long, long long, long long, long long,
7923 - long long, long long, long long);
7924 -
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)
7932 -
7933 -#ifdef SHARED
7934 -__attribute__((__visibility__("hidden")))
7935 -#endif
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)
7938 -{
7939 - struct __timespec_kernel ts[1];
7940 - switch (n) {
7941 - case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6:
7942 - __fixup(a5);
7943 - break;
7944 - case SYS_futex:
7945 - if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */)
7946 - __fixup(a4);
7947 - break;
7948 - case SYS_clock_nanosleep:
7949 - case SYS_rt_sigtimedwait: case SYS_ppoll:
7950 - __fixup(a3);
7951 - break;
7952 - case SYS_nanosleep:
7953 - __fixup(a1);
7954 - break;
7955 - }
7956 - return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6);
7957 -}
7958 -
7959 --- a/arch/x32/src/sysinfo.c
7960 +++ /dev/null
7961 @@ -1,50 +0,0 @@
7962 -#include <sys/sysinfo.h>
7963 -#include "syscall.h"
7964 -#include "libc.h"
7965 -
7966 -#define klong long long
7967 -#define kulong unsigned long long
7968 -
7969 -struct kernel_sysinfo {
7970 - klong uptime;
7971 - kulong loads[3];
7972 - kulong totalram;
7973 - kulong freeram;
7974 - kulong sharedram;
7975 - kulong bufferram;
7976 - kulong totalswap;
7977 - kulong freeswap;
7978 - short procs;
7979 - short pad;
7980 - kulong totalhigh;
7981 - kulong freehigh;
7982 - unsigned mem_unit;
7983 -};
7984 -
7985 -int __lsysinfo(struct sysinfo *info)
7986 -{
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];
7994 - kulong shifts;
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;
8008 - return ret;
8009 -}
8010 -
8011 -weak_alias(__lsysinfo, sysinfo);
8012 --- a/arch/x86_64/atomic.h
8013 +++ /dev/null
8014 @@ -1,105 +0,0 @@
8015 -#ifndef _INTERNAL_ATOMIC_H
8016 -#define _INTERNAL_ATOMIC_H
8017 -
8018 -#include <stdint.h>
8019 -
8020 -static inline int a_ctz_64(uint64_t x)
8021 -{
8022 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
8023 - return x;
8024 -}
8025 -
8026 -static inline int a_ctz_l(unsigned long x)
8027 -{
8028 - __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
8029 - return x;
8030 -}
8031 -
8032 -static inline void a_and_64(volatile uint64_t *p, uint64_t v)
8033 -{
8034 - __asm__( "lock ; and %1, %0"
8035 - : "=m"(*p) : "r"(v) : "memory" );
8036 -}
8037 -
8038 -static inline void a_or_64(volatile uint64_t *p, uint64_t v)
8039 -{
8040 - __asm__( "lock ; or %1, %0"
8041 - : "=m"(*p) : "r"(v) : "memory" );
8042 -}
8043 -
8044 -static inline void a_or_l(volatile void *p, long v)
8045 -{
8046 - __asm__( "lock ; or %1, %0"
8047 - : "=m"(*(long *)p) : "r"(v) : "memory" );
8048 -}
8049 -
8050 -static inline void *a_cas_p(volatile void *p, void *t, void *s)
8051 -{
8052 - __asm__( "lock ; cmpxchg %3, %1"
8053 - : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
8054 - return t;
8055 -}
8056 -
8057 -static inline int a_cas(volatile int *p, int t, int s)
8058 -{
8059 - __asm__( "lock ; cmpxchg %3, %1"
8060 - : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
8061 - return t;
8062 -}
8063 -
8064 -static inline void a_or(volatile int *p, int v)
8065 -{
8066 - __asm__( "lock ; or %1, %0"
8067 - : "=m"(*p) : "r"(v) : "memory" );
8068 -}
8069 -
8070 -static inline void a_and(volatile int *p, int v)
8071 -{
8072 - __asm__( "lock ; and %1, %0"
8073 - : "=m"(*p) : "r"(v) : "memory" );
8074 -}
8075 -
8076 -static inline int a_swap(volatile int *x, int v)
8077 -{
8078 - __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
8079 - return v;
8080 -}
8081 -
8082 -static inline int a_fetch_add(volatile int *x, int v)
8083 -{
8084 - __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
8085 - return v;
8086 -}
8087 -
8088 -static inline void a_inc(volatile int *x)
8089 -{
8090 - __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
8091 -}
8092 -
8093 -static inline void a_dec(volatile int *x)
8094 -{
8095 - __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
8096 -}
8097 -
8098 -static inline void a_store(volatile int *p, int x)
8099 -{
8100 - __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
8101 -}
8102 -
8103 -static inline void a_spin()
8104 -{
8105 - __asm__ __volatile__( "pause" : : : "memory" );
8106 -}
8107 -
8108 -static inline void a_barrier()
8109 -{
8110 - __asm__ __volatile__( "" : : : "memory" );
8111 -}
8112 -
8113 -static inline void a_crash()
8114 -{
8115 - __asm__ __volatile__( "hlt" : : : "memory" );
8116 -}
8117 -
8118 -
8119 -#endif
8120 --- /dev/null
8121 +++ b/arch/x86_64/atomic_arch.h
8122 @@ -0,0 +1,116 @@
8123 +#define a_cas a_cas
8124 +static inline int a_cas(volatile int *p, int t, int s)
8125 +{
8126 + __asm__ __volatile__ (
8127 + "lock ; cmpxchg %3, %1"
8128 + : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
8129 + return t;
8130 +}
8131 +
8132 +#define a_cas_p a_cas_p
8133 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
8134 +{
8135 + __asm__( "lock ; cmpxchg %3, %1"
8136 + : "=a"(t), "=m"(*(void *volatile *)p)
8137 + : "a"(t), "r"(s) : "memory" );
8138 + return t;
8139 +}
8140 +
8141 +#define a_swap a_swap
8142 +static inline int a_swap(volatile int *p, int v)
8143 +{
8144 + __asm__ __volatile__(
8145 + "xchg %0, %1"
8146 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
8147 + return v;
8148 +}
8149 +
8150 +#define a_fetch_add a_fetch_add
8151 +static inline int a_fetch_add(volatile int *p, int v)
8152 +{
8153 + __asm__ __volatile__(
8154 + "lock ; xadd %0, %1"
8155 + : "=r"(v), "=m"(*p) : "0"(v) : "memory" );
8156 + return v;
8157 +}
8158 +
8159 +#define a_and a_and
8160 +static inline void a_and(volatile int *p, int v)
8161 +{
8162 + __asm__ __volatile__(
8163 + "lock ; and %1, %0"
8164 + : "=m"(*p) : "r"(v) : "memory" );
8165 +}
8166 +
8167 +#define a_or a_or
8168 +static inline void a_or(volatile int *p, int v)
8169 +{
8170 + __asm__ __volatile__(
8171 + "lock ; or %1, %0"
8172 + : "=m"(*p) : "r"(v) : "memory" );
8173 +}
8174 +
8175 +#define a_and_64 a_and_64
8176 +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
8177 +{
8178 + __asm__ __volatile(
8179 + "lock ; and %1, %0"
8180 + : "=m"(*p) : "r"(v) : "memory" );
8181 +}
8182 +
8183 +#define a_or_64 a_or_64
8184 +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
8185 +{
8186 + __asm__ __volatile__(
8187 + "lock ; or %1, %0"
8188 + : "=m"(*p) : "r"(v) : "memory" );
8189 +}
8190 +
8191 +#define a_inc a_inc
8192 +static inline void a_inc(volatile int *p)
8193 +{
8194 + __asm__ __volatile__(
8195 + "lock ; incl %0"
8196 + : "=m"(*p) : "m"(*p) : "memory" );
8197 +}
8198 +
8199 +#define a_dec a_dec
8200 +static inline void a_dec(volatile int *p)
8201 +{
8202 + __asm__ __volatile__(
8203 + "lock ; decl %0"
8204 + : "=m"(*p) : "m"(*p) : "memory" );
8205 +}
8206 +
8207 +#define a_store a_store
8208 +static inline void a_store(volatile int *p, int x)
8209 +{
8210 + __asm__ __volatile__(
8211 + "mov %1, %0 ; lock ; orl $0,(%%rsp)"
8212 + : "=m"(*p) : "r"(x) : "memory" );
8213 +}
8214 +
8215 +#define a_barrier a_barrier
8216 +static inline void a_barrier()
8217 +{
8218 + __asm__ __volatile__( "" : : : "memory" );
8219 +}
8220 +
8221 +#define a_pause a_pause
8222 +static inline void a_spin()
8223 +{
8224 + __asm__ __volatile__( "pause" : : : "memory" );
8225 +}
8226 +
8227 +#define a_crash a_crash
8228 +static inline void a_crash()
8229 +{
8230 + __asm__ __volatile__( "hlt" : : : "memory" );
8231 +}
8232 +
8233 +#define a_ctz_64 a_ctz_64
8234 +static inline int a_ctz_64(uint64_t x)
8235 +{
8236 + __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
8237 + return x;
8238 +}
8239 --- a/arch/x86_64/bits/errno.h
8240 +++ /dev/null
8241 @@ -1,134 +0,0 @@
8242 -#define EPERM 1
8243 -#define ENOENT 2
8244 -#define ESRCH 3
8245 -#define EINTR 4
8246 -#define EIO 5
8247 -#define ENXIO 6
8248 -#define E2BIG 7
8249 -#define ENOEXEC 8
8250 -#define EBADF 9
8251 -#define ECHILD 10
8252 -#define EAGAIN 11
8253 -#define ENOMEM 12
8254 -#define EACCES 13
8255 -#define EFAULT 14
8256 -#define ENOTBLK 15
8257 -#define EBUSY 16
8258 -#define EEXIST 17
8259 -#define EXDEV 18
8260 -#define ENODEV 19
8261 -#define ENOTDIR 20
8262 -#define EISDIR 21
8263 -#define EINVAL 22
8264 -#define ENFILE 23
8265 -#define EMFILE 24
8266 -#define ENOTTY 25
8267 -#define ETXTBSY 26
8268 -#define EFBIG 27
8269 -#define ENOSPC 28
8270 -#define ESPIPE 29
8271 -#define EROFS 30
8272 -#define EMLINK 31
8273 -#define EPIPE 32
8274 -#define EDOM 33
8275 -#define ERANGE 34
8276 -#define EDEADLK 35
8277 -#define ENAMETOOLONG 36
8278 -#define ENOLCK 37
8279 -#define ENOSYS 38
8280 -#define ENOTEMPTY 39
8281 -#define ELOOP 40
8282 -#define EWOULDBLOCK EAGAIN
8283 -#define ENOMSG 42
8284 -#define EIDRM 43
8285 -#define ECHRNG 44
8286 -#define EL2NSYNC 45
8287 -#define EL3HLT 46
8288 -#define EL3RST 47
8289 -#define ELNRNG 48
8290 -#define EUNATCH 49
8291 -#define ENOCSI 50
8292 -#define EL2HLT 51
8293 -#define EBADE 52
8294 -#define EBADR 53
8295 -#define EXFULL 54
8296 -#define ENOANO 55
8297 -#define EBADRQC 56
8298 -#define EBADSLT 57
8299 -#define EDEADLOCK EDEADLK
8300 -#define EBFONT 59
8301 -#define ENOSTR 60
8302 -#define ENODATA 61
8303 -#define ETIME 62
8304 -#define ENOSR 63
8305 -#define ENONET 64
8306 -#define ENOPKG 65
8307 -#define EREMOTE 66
8308 -#define ENOLINK 67
8309 -#define EADV 68
8310 -#define ESRMNT 69
8311 -#define ECOMM 70
8312 -#define EPROTO 71
8313 -#define EMULTIHOP 72
8314 -#define EDOTDOT 73
8315 -#define EBADMSG 74
8316 -#define EOVERFLOW 75
8317 -#define ENOTUNIQ 76
8318 -#define EBADFD 77
8319 -#define EREMCHG 78
8320 -#define ELIBACC 79
8321 -#define ELIBBAD 80
8322 -#define ELIBSCN 81
8323 -#define ELIBMAX 82
8324 -#define ELIBEXEC 83
8325 -#define EILSEQ 84
8326 -#define ERESTART 85
8327 -#define ESTRPIPE 86
8328 -#define EUSERS 87
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
8358 -#define ESTALE 116
8359 -#define EUCLEAN 117
8360 -#define ENOTNAM 118
8361 -#define ENAVAIL 119
8362 -#define EISNAM 120
8363 -#define EREMOTEIO 121
8364 -#define EDQUOT 122
8365 -#define ENOMEDIUM 123
8366 -#define EMEDIUMTYPE 124
8367 -#define ECANCELED 125
8368 -#define ENOKEY 126
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
8378 @@ -38,6 +38,7 @@
8379
8380 #define MCL_CURRENT 1
8381 #define MCL_FUTURE 2
8382 +#define MCL_ONFAULT 4
8383
8384 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
8385 #define MADV_NORMAL 0
8386 --- a/arch/x86_64/bits/sem.h
8387 +++ /dev/null
8388 @@ -1,16 +0,0 @@
8389 -struct semid_ds {
8390 - struct ipc_perm sem_perm;
8391 - time_t sem_otime;
8392 - time_t __unused1;
8393 - time_t sem_ctime;
8394 - time_t __unused2;
8395 -#if __BYTE_ORDER == __LITTLE_ENDIAN
8396 - unsigned short sem_nsems;
8397 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
8398 -#else
8399 - char __sem_nsems_pad[sizeof(time_t)-sizeof(short)];
8400 - unsigned short sem_nsems;
8401 -#endif
8402 - time_t __unused3;
8403 - time_t __unused4;
8404 -};
8405 --- a/arch/x86_64/bits/statfs.h
8406 +++ /dev/null
8407 @@ -1,7 +0,0 @@
8408 -struct statfs {
8409 - unsigned long f_type, f_bsize;
8410 - fsblkcnt_t f_blocks, f_bfree, f_bavail;
8411 - fsfilcnt_t f_files, f_ffree;
8412 - fsid_t f_fsid;
8413 - unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
8414 -};
8415 --- a/arch/x86_64/bits/stdarg.h
8416 +++ /dev/null
8417 @@ -1,4 +0,0 @@
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
8424 @@ -321,6 +321,9 @@
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
8431
8432
8433
8434 @@ -649,3 +652,6 @@
8435 #define SYS_kexec_file_load 320
8436 #define SYS_bpf 321
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
8442 +++ /dev/null
8443 @@ -1,160 +0,0 @@
8444 -struct termios
8445 -{
8446 - tcflag_t c_iflag;
8447 - tcflag_t c_oflag;
8448 - tcflag_t c_cflag;
8449 - tcflag_t c_lflag;
8450 - cc_t c_line;
8451 - cc_t c_cc[NCCS];
8452 - speed_t __c_ispeed;
8453 - speed_t __c_ospeed;
8454 -};
8455 -
8456 -#define VINTR 0
8457 -#define VQUIT 1
8458 -#define VERASE 2
8459 -#define VKILL 3
8460 -#define VEOF 4
8461 -#define VTIME 5
8462 -#define VMIN 6
8463 -#define VSWTC 7
8464 -#define VSTART 8
8465 -#define VSTOP 9
8466 -#define VSUSP 10
8467 -#define VEOL 11
8468 -#define VREPRINT 12
8469 -#define VDISCARD 13
8470 -#define VWERASE 14
8471 -#define VLNEXT 15
8472 -#define VEOL2 16
8473 -
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
8489 -
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
8517 -
8518 -#define VTDLY 0040000
8519 -#define VT0 0000000
8520 -#define VT1 0040000
8521 -
8522 -#define B0 0000000
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
8538 -
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
8554 -
8555 -#define CBAUD 0010017
8556 -
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
8568 -
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
8578 -
8579 -#define ECHOCTL 0001000
8580 -#define ECHOPRT 0002000
8581 -#define ECHOKE 0004000
8582 -#define FLUSHO 0010000
8583 -#define PENDIN 0040000
8584 -
8585 -#define TCOOFF 0
8586 -#define TCOON 1
8587 -#define TCIOFF 2
8588 -#define TCION 3
8589 -
8590 -#define TCIFLUSH 0
8591 -#define TCOFLUSH 1
8592 -#define TCIOFLUSH 2
8593 -
8594 -#define TCSANOW 0
8595 -#define TCSADRAIN 1
8596 -#define TCSAFLUSH 2
8597 -
8598 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
8599 -#define CBAUDEX 0010000
8600 -#define CRTSCTS 020000000000
8601 -#define EXTPROC 0200000
8602 -#define XTABS 0014000
8603 -#endif
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_
8607
8608 #define TP_ADJ(p) (p)
8609
8610 -#define CANCEL_REG_IP 16
8611 +#define MC_PC gregs[REG_RIP]
8612 --- a/configure
8613 +++ b/configure
8614 @@ -9,6 +9,9 @@ VAR=VALUE. See below for descriptions o
8615
8616 Defaults for the options are specified in brackets.
8617
8618 +Configuration:
8619 + --srcdir=DIR source directory [detected]
8620 +
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=
8625 LDFLAGS_AUTO=
8626 LDFLAGS_TRY=
8627 OPTIMIZE_GLOBS=
8628 +srcdir=
8629 prefix=/usr/local/musl
8630 exec_prefix='$(prefix)'
8631 bindir='$(exec_prefix)/bin'
8632 @@ -139,6 +143,7 @@ clang_wrapper=no
8633 for arg ; do
8634 case "$arg" in
8635 --help) usage ;;
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#*=} ;;
8641 esac
8642 done
8643
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
8646 stripdir $i
8647 done
8648
8649 #
8650 +# Get the source dir for out-of-tree builds
8651 +#
8652 +if test -z "$srcdir" ; then
8653 +srcdir="${0%/configure}"
8654 +stripdir srcdir
8655 +fi
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"
8660 +
8661 +#
8662 # Get a temp filename we can use
8663 #
8664 i=0
8665 @@ -263,11 +280,11 @@ fi
8666 fi
8667
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"
8672 fi
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"
8676 fi
8677
8678 #
8679 @@ -321,7 +338,7 @@ __attribute__((__may_alias__))
8680 #endif
8681 x;
8682 EOF
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
8686 printf "no\n"
8687 else
8688 @@ -330,6 +347,13 @@ CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_al
8689 fi
8690
8691 #
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.
8695 +#
8696 +tryflag CFLAGS_C99FSE -Wa,--noexecstack
8697 +
8698 +#
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
8704
8705 #
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.
8715 #
8716 -tryflag CFLAGS_AUTO -Wa,--noexecstack
8717 +tryflag CFLAGS_AUTO -ffunction-sections
8718 +tryflag CFLAGS_AUTO -fdata-sections
8719
8720 #
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(); }
8724 EOF
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
8730 visibility=yes
8731 @@ -504,6 +532,25 @@ CFLAGS_AUTO="$CFLAGS_AUTO -include vis.h
8732 CFLAGS_AUTO="${CFLAGS_AUTO# }"
8733 fi
8734
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
8739 +pic_default=yes
8740 +else
8741 +pic_default=no
8742 +fi
8743 +
8744 +# Reduce space lost to padding for alignment purposes by sorting data
8745 +# objects according to their alignment reqirements. This approximates
8746 +# optimal packing.
8747 +tryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment
8748 +tryldflag LDFLAGS_AUTO -Wl,--sort-common
8749 +
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
8753 +
8754 # Some patched GCC builds have these defaults messed up...
8755 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
8756
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
8760
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
8765 +
8766 test "$shared" = "no" || {
8767 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
8768 LDFLAGS_DUMMY=
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
8778 printf "yes\n"
8779 else
8780 printf "no\n"
8781 @@ -622,6 +675,7 @@ cat << EOF
8782 ARCH = $ARCH
8783 SUBARCH = $SUBARCH
8784 ASMSUBARCH = $ASMSUBARCH
8785 +srcdir = $srcdir
8786 prefix = $prefix
8787 exec_prefix = $exec_prefix
8788 bindir = $bindir
8789 @@ -629,12 +683,14 @@ libdir = $libdir
8790 includedir = $includedir
8791 syslibdir = $syslibdir
8792 CC = $CC
8793 -CFLAGS = $CFLAGS_AUTO $CFLAGS
8794 +CFLAGS = $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
8801 +LDFLAGS = $LDFLAGS
8802 +LDFLAGS_AUTO = $LDFLAGS_AUTO
8803 CROSS_COMPILE = $CROSS_COMPILE
8804 LIBCC = $LIBCC
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)'
8811 exec 1>&3 3>&-
8812
8813 +test "$srcdir" = "." || ln -sf $srcdir/Makefile .
8814 +
8815 printf "done\n"
8816 --- a/crt/arm/crti.s
8817 +++ b/crt/arm/crti.s
8818 @@ -1,3 +1,5 @@
8819 +.syntax unified
8820 +
8821 .section .init
8822 .global _init
8823 .type _init,%function
8824 --- a/crt/arm/crtn.s
8825 +++ b/crt/arm/crtn.s
8826 @@ -1,11 +1,9 @@
8827 +.syntax unified
8828 +
8829 .section .init
8830 pop {r0,lr}
8831 - tst lr,#1
8832 - moveq pc,lr
8833 bx lr
8834
8835 .section .fini
8836 pop {r0,lr}
8837 - tst lr,#1
8838 - moveq pc,lr
8839 bx lr
8840 --- a/crt/rcrt1.c
8841 +++ b/crt/rcrt1.c
8842 @@ -1,7 +1,7 @@
8843 #define SHARED
8844 #define START "_start"
8845 #define _dlstart_c _start_c
8846 -#include "../src/ldso/dlstart.c"
8847 +#include "../ldso/dlstart.c"
8848
8849 int main();
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);
8854
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) })
8861 #else
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
8871
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
8882 @@ -27,6 +27,9 @@
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
8889
8890 #define TCP_ESTABLISHED 1
8891 #define TCP_SYN_SENT 2
8892 @@ -41,7 +44,20 @@
8893 #define TCP_CLOSING 11
8894
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
8907 +
8908 #define SOL_TCP 6
8909 +
8910 #include <sys/types.h>
8911 #include <sys/socket.h>
8912 #include <stdint.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;
8921 };
8922
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
8946
8947 #define PACKET_MR_MULTICAST 0
8948 #define PACKET_MR_PROMISC 1
8949 #define PACKET_MR_ALLMULTI 2
8950 +#define PACKET_MR_UNICAST 3
8951
8952 #ifdef __cplusplus
8953 }
8954 --- a/include/signal.h
8955 +++ b/include/signal.h
8956 @@ -27,8 +27,6 @@ extern "C" {
8957
8958 #include <bits/alltypes.h>
8959
8960 -#define SIG_HOLD ((void (*)(int)) 2)
8961 -
8962 #define SIG_BLOCK 0
8963 #define SIG_UNBLOCK 1
8964 #define SIG_SETMASK 2
8965 @@ -43,6 +41,18 @@ extern "C" {
8966 #define SI_USER 0
8967 #define SI_KERNEL 128
8968
8969 +typedef struct sigaltstack stack_t;
8970 +
8971 +#endif
8972 +
8973 +#include <bits/signal.h>
8974 +
8975 +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
8976 + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
8977 + || defined(_BSD_SOURCE)
8978 +
8979 +#define SIG_HOLD ((void (*)(int)) 2)
8980 +
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
8987
8988 -typedef struct sigaltstack stack_t;
8989 -
8990 union sigval {
8991 int sival_int;
8992 void *sival_ptr;
8993 };
8994
8995 typedef struct {
8996 +#ifdef __SI_SWAP_ERRNO_CODE
8997 + int si_signo, si_code, si_errno;
8998 +#else
8999 int si_signo, si_errno, si_code;
9000 +#endif
9001 union {
9002 char __pad[128 - 2*sizeof(int) - sizeof(long)];
9003 struct {
9004 @@ -240,8 +252,6 @@ int sigandset(sigset_t *, const sigset_t
9005 #define SA_ONESHOT SA_RESETHAND
9006 #endif
9007
9008 -#include <bits/signal.h>
9009 -
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
9016 #endif
9017
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 *);
9022 #endif
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)
9034
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)
9037
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)
9045
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
9051 +
9052 int prctl (int, ...);
9053
9054 #ifdef __cplusplus
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
9062
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
9072
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
9079 #define PF_LLC 26
9080 #define PF_IB 27
9081 +#define PF_MPLS 28
9082 #define PF_CAN 29
9083 #define PF_TIPC 30
9084 #define PF_BLUETOOTH 31
9085 @@ -141,6 +142,7 @@ struct linger
9086 #define AF_WANPIPE PF_WANPIPE
9087 #define AF_LLC PF_LLC
9088 #define AF_IB PF_IB
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
9099
9100 #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
9101 --- /dev/null
9102 +++ b/ldso/dlstart.c
9103 @@ -0,0 +1,146 @@
9104 +#include <stddef.h>
9105 +#include "dynlink.h"
9106 +
9107 +#ifndef START
9108 +#define START "_dlstart"
9109 +#endif
9110 +
9111 +#include "crt_arch.h"
9112 +
9113 +#ifndef GETFUNCSYM
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)
9119 +#endif
9120 +
9121 +__attribute__((__visibility__("hidden")))
9122 +void _dlstart_c(size_t *sp, size_t *dynv)
9123 +{
9124 + size_t i, aux[AUX_CNT], dyn[DYN_CNT];
9125 + size_t *rel, rel_size, base;
9126 +
9127 + int argc = *sp;
9128 + char **argv = (void *)(sp+1);
9129 +
9130 + for (i=argc+1; argv[i]; i++);
9131 + size_t *auxv = (void *)(argv+i+1);
9132 +
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];
9136 +
9137 +#if DL_FDPIC
9138 + struct fdpic_loadseg *segs, fakeseg;
9139 + size_t j;
9140 + if (dynv) {
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;
9145 + } else {
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;
9153 + segs = &fakeseg;
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);
9164 + }
9165 +#endif
9166 +
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];
9170 +
9171 +#if DL_FDPIC
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;
9177 + }
9178 + base = 0;
9179 +
9180 + const Sym *syms = (void *)dyn[DT_SYMTAB];
9181 +
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];
9194 + } else {
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;
9198 + }
9199 + }
9200 +#else
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];
9206 + if (!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;
9213 + break;
9214 + }
9215 + }
9216 + }
9217 +
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;
9227 + }
9228 +
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;
9235 + }
9236 +
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];
9243 + }
9244 +#endif
9245 +
9246 + stage2_func dls2;
9247 + GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
9248 + dls2((void *)base, sp);
9249 +}
9250 --- /dev/null
9251 +++ b/ldso/dynlink.c
9252 @@ -0,0 +1,1931 @@
9253 +#define _GNU_SOURCE
9254 +#include <stdio.h>
9255 +#include <stdlib.h>
9256 +#include <stdarg.h>
9257 +#include <stddef.h>
9258 +#include <string.h>
9259 +#include <unistd.h>
9260 +#include <stdint.h>
9261 +#include <elf.h>
9262 +#include <sys/mman.h>
9263 +#include <limits.h>
9264 +#include <fcntl.h>
9265 +#include <sys/stat.h>
9266 +#include <errno.h>
9267 +#include <link.h>
9268 +#include <setjmp.h>
9269 +#include <pthread.h>
9270 +#include <ctype.h>
9271 +#include <dlfcn.h>
9272 +#include "pthread_impl.h"
9273 +#include "libc.h"
9274 +#include "dynlink.h"
9275 +
9276 +static void error(const char *, ...);
9277 +
9278 +#define MAXP2(a,b) (-(-(a)&-(b)))
9279 +#define ALIGN(x,y) ((x)+(y)-1 & -(y))
9280 +
9281 +struct debug {
9282 + int ver;
9283 + void *head;
9284 + void (*bp)(void);
9285 + int state;
9286 + void *base;
9287 +};
9288 +
9289 +struct td_index {
9290 + size_t args[2];
9291 + struct td_index *next;
9292 +};
9293 +
9294 +struct dso {
9295 +#if DL_FDPIC
9296 + struct fdpic_loadmap *loadmap;
9297 +#else
9298 + unsigned char *base;
9299 +#endif
9300 + char *name;
9301 + size_t *dynv;
9302 + struct dso *next, *prev;
9303 +
9304 + Phdr *phdr;
9305 + int phnum;
9306 + size_t phentsize;
9307 + int refcnt;
9308 + Sym *syms;
9309 + uint32_t *hashtab;
9310 + uint32_t *ghashtab;
9311 + int16_t *versym;
9312 + char *strings;
9313 + unsigned char *map;
9314 + size_t map_len;
9315 + dev_t dev;
9316 + ino_t ino;
9317 + signed char global;
9318 + char relocated;
9319 + char constructed;
9320 + char kernel_mapped;
9321 + struct dso **deps, *needed_by;
9322 + char *rpath_orig, *rpath;
9323 + struct tls_module tls;
9324 + size_t tls_id;
9325 + size_t relro_start, relro_end;
9326 + void **new_dtv;
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;
9331 + char *shortname;
9332 +#if DL_FDPIC
9333 + unsigned char *base;
9334 +#else
9335 + struct fdpic_loadmap *loadmap;
9336 +#endif
9337 + struct funcdesc {
9338 + void *addr;
9339 + size_t *got;
9340 + } *funcdescs;
9341 + size_t *got;
9342 + char buf[];
9343 +};
9344 +
9345 +struct symdef {
9346 + Sym *sym;
9347 + struct dso *dso;
9348 +};
9349 +
9350 +int __init_tp(void *);
9351 +void __init_libc(char **, char *);
9352 +void *__copy_tls(unsigned char *);
9353 +
9354 +__attribute__((__visibility__("hidden")))
9355 +const char *__libc_get_version(void);
9356 +
9357 +static struct builtin_tls {
9358 + char c;
9359 + struct pthread pt;
9360 + void *space[16];
9361 +} builtin_tls[1];
9362 +#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
9363 +
9364 +#define ADDEND_LIMIT 4096
9365 +static size_t *saved_addends, *apply_addends_to;
9366 +
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;
9374 +static int noload;
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;
9384 +
9385 +struct debug *_dl_debug_addr = &debug;
9386 +
9387 +__attribute__((__visibility__("hidden")))
9388 +void (*const __init_array_start)(void)=0, (*const __fini_array_start)(void)=0;
9389 +
9390 +__attribute__((__visibility__("hidden")))
9391 +extern void (*const __init_array_end)(void), (*const __fini_array_end)(void);
9392 +
9393 +weak_alias(__init_array_start, __init_array_end);
9394 +weak_alias(__fini_array_start, __fini_array_end);
9395 +
9396 +static int dl_strcmp(const char *l, const char *r)
9397 +{
9398 + for (; *l==*r && *l; l++, r++);
9399 + return *(unsigned char *)l - *(unsigned char *)r;
9400 +}
9401 +#define strcmp(l,r) dl_strcmp(l,r)
9402 +
9403 +/* Compute load address for a virtual address in a given dso. */
9404 +#if DL_FDPIC
9405 +static void *laddr(const struct dso *p, size_t v)
9406 +{
9407 + size_t j=0;
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);
9411 +}
9412 +#define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \
9413 + laddr(p, v), (p)->got })
9414 +#else
9415 +#define laddr(p, v) (void *)((p)->base + (v))
9416 +#define fpaddr(p, v) ((void (*)())laddr(p, v))
9417 +#endif
9418 +
9419 +static void decode_vec(size_t *v, size_t *a, size_t cnt)
9420 +{
9421 + size_t i;
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];
9425 + a[v[0]] = v[1];
9426 + }
9427 +}
9428 +
9429 +static int search_vec(size_t *v, size_t *r, size_t key)
9430 +{
9431 + for (; v[0]!=key; v+=2)
9432 + if (!v[0]) return 0;
9433 + *r = v[1];
9434 + return 1;
9435 +}
9436 +
9437 +static uint32_t sysv_hash(const char *s0)
9438 +{
9439 + const unsigned char *s = (void *)s0;
9440 + uint_fast32_t h = 0;
9441 + while (*s) {
9442 + h = 16*h + *s++;
9443 + h ^= h>>24 & 0xf0;
9444 + }
9445 + return h & 0xfffffff;
9446 +}
9447 +
9448 +static uint32_t gnu_hash(const char *s0)
9449 +{
9450 + const unsigned char *s = (void *)s0;
9451 + uint_fast32_t h = 5381;
9452 + for (; *s; s++)
9453 + h += h*32 + *s;
9454 + return h;
9455 +}
9456 +
9457 +static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
9458 +{
9459 + size_t i;
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)))
9466 + return syms+i;
9467 + }
9468 + return 0;
9469 +}
9470 +
9471 +static Sym *gnu_lookup(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s)
9472 +{
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];
9476 +
9477 + if (!i) return 0;
9478 +
9479 + uint32_t *hashval = buckets + nbuckets + (i - hashtab[1]);
9480 +
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;
9487 + }
9488 +
9489 + return 0;
9490 +}
9491 +
9492 +static Sym *gnu_lookup_filtered(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s, uint32_t fofs, size_t fmask)
9493 +{
9494 + const size_t *bloomwords = (const void *)(hashtab+4);
9495 + size_t f = bloomwords[fofs & (hashtab[2]-1)];
9496 + if (!(f & fmask)) return 0;
9497 +
9498 + f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
9499 + if (!(f & 1)) return 0;
9500 +
9501 + return gnu_lookup(h1, hashtab, dso, s);
9502 +}
9503 +
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)
9506 +
9507 +#ifndef ARCH_SYM_REJECT_UND
9508 +#define ARCH_SYM_REJECT_UND(s) 0
9509 +#endif
9510 +
9511 +static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
9512 +{
9513 + uint32_t h = 0, gh, gho, *ght;
9514 + size_t ghm = 0;
9515 + struct symdef def = {0};
9516 + for (; dso; dso=dso->next) {
9517 + Sym *sym;
9518 + if (!dso->global) continue;
9519 + if ((ght = dso->ghashtab)) {
9520 + if (!ghm) {
9521 + gh = gnu_hash(s);
9522 + int maskbits = 8 * sizeof ghm;
9523 + gho = gh / maskbits;
9524 + ghm = 1ul << gh % maskbits;
9525 + }
9526 + sym = gnu_lookup_filtered(gh, ght, dso, s, gho, ghm);
9527 + } else {
9528 + if (!h) h = sysv_hash(s);
9529 + sym = sysv_lookup(s, h, dso);
9530 + }
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))
9535 + continue;
9536 + if (!sym->st_value)
9537 + if ((sym->st_info&0xf) != STT_TLS)
9538 + continue;
9539 + if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
9540 + if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
9541 +
9542 + if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
9543 + def.sym = sym;
9544 + def.dso = dso;
9545 + if (sym->st_info>>4 == STB_GLOBAL) break;
9546 + }
9547 + return def;
9548 +}
9549 +
9550 +__attribute__((__visibility__("hidden")))
9551 +ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
9552 +
9553 +static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
9554 +{
9555 + unsigned char *base = dso->base;
9556 + Sym *syms = dso->syms;
9557 + char *strings = dso->strings;
9558 + Sym *sym;
9559 + const char *name;
9560 + void *ctx;
9561 + int type;
9562 + int sym_index;
9563 + struct symdef def;
9564 + size_t *reloc_addr;
9565 + size_t sym_val;
9566 + size_t tls_val;
9567 + size_t addend;
9568 + int skip_relative = 0, reuse_addends = 0, save_slot = 0;
9569 +
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;
9575 + }
9576 +
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]);
9583 + if (sym_index) {
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",
9593 + dso->name, name);
9594 + if (runtime) longjmp(*rtld_fail, 1);
9595 + continue;
9596 + }
9597 + } else {
9598 + sym = 0;
9599 + def.sym = 0;
9600 + def.dso = dso;
9601 + }
9602 +
9603 + if (stride > 2) {
9604 + addend = rel[2];
9605 + } else if (type==REL_GOT || type==REL_PLT|| type==REL_COPY) {
9606 + addend = 0;
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. */
9611 + if (head==&ldso)
9612 + saved_addends[save_slot] = *reloc_addr;
9613 + addend = saved_addends[save_slot++];
9614 + } else {
9615 + addend = *reloc_addr;
9616 + }
9617 +
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;
9620 +
9621 + switch(type) {
9622 + case REL_NONE:
9623 + break;
9624 + case REL_OFFSET:
9625 + addend -= (size_t)reloc_addr;
9626 + case REL_SYMBOLIC:
9627 + case REL_GOT:
9628 + case REL_PLT:
9629 + *reloc_addr = sym_val + addend;
9630 + break;
9631 + case REL_RELATIVE:
9632 + *reloc_addr = (size_t)base + addend;
9633 + break;
9634 + case REL_SYM_OR_REL:
9635 + if (sym) *reloc_addr = sym_val + addend;
9636 + else *reloc_addr = (size_t)base + addend;
9637 + break;
9638 + case REL_COPY:
9639 + memcpy(reloc_addr, (void *)sym_val, sym->st_size);
9640 + break;
9641 + case REL_OFFSET32:
9642 + *(uint32_t *)reloc_addr = sym_val + addend
9643 + - (size_t)reloc_addr;
9644 + break;
9645 + case REL_FUNCDESC:
9646 + *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs
9647 + + (def.sym - def.dso->syms)) : 0;
9648 + break;
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;
9653 + break;
9654 + case REL_DTPMOD:
9655 + *reloc_addr = def.dso->tls_id;
9656 + break;
9657 + case REL_DTPOFF:
9658 + *reloc_addr = tls_val + addend - DTP_OFFSET;
9659 + break;
9660 +#ifdef TLS_ABOVE_TP
9661 + case REL_TPOFF:
9662 + *reloc_addr = tls_val + def.dso->tls.offset + TPOFF_K + addend;
9663 + break;
9664 +#else
9665 + case REL_TPOFF:
9666 + *reloc_addr = tls_val - def.dso->tls.offset + addend;
9667 + break;
9668 + case REL_TPOFF_NEG:
9669 + *reloc_addr = def.dso->tls.offset - tls_val + addend;
9670 + break;
9671 +#endif
9672 + case REL_TLSDESC:
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);
9676 + if (!new) {
9677 + error(
9678 + "Error relocating %s: cannot allocate TLSDESC for %s",
9679 + dso->name, sym ? name : "(local)" );
9680 + longjmp(*rtld_fail, 1);
9681 + }
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;
9688 + } else {
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;
9693 +#else
9694 + reloc_addr[1] = tls_val - def.dso->tls.offset
9695 + + addend;
9696 +#endif
9697 + }
9698 + break;
9699 + default:
9700 + error("Error relocating %s: unsupported relocation type %d",
9701 + dso->name, type);
9702 + if (runtime) longjmp(*rtld_fail, 1);
9703 + continue;
9704 + }
9705 + }
9706 +}
9707 +
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. */
9713 +
9714 +static void reclaim(struct dso *dso, size_t start, size_t end)
9715 +{
9716 + size_t *a, *z;
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);
9724 + a[-2] = 1;
9725 + a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1;
9726 + z[1] = 1;
9727 + free(a);
9728 +}
9729 +
9730 +static void reclaim_gaps(struct dso *dso)
9731 +{
9732 + Phdr *ph = dso->phdr;
9733 + size_t phcnt = dso->phnum;
9734 +
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);
9742 + }
9743 +}
9744 +
9745 +static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t off)
9746 +{
9747 + static int no_map_fixed;
9748 + char *q;
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)
9752 + return q;
9753 + no_map_fixed = 1;
9754 + }
9755 + /* Fallbacks for MAP_FIXED failure on NOMMU kernels. */
9756 + if (flags & MAP_ANONYMOUS) {
9757 + memset(p, 0, n);
9758 + return p;
9759 + }
9760 + ssize_t r;
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;
9765 + if (!r) {
9766 + memset(q, 0, n);
9767 + break;
9768 + }
9769 + }
9770 + return p;
9771 +}
9772 +
9773 +static void unmap_library(struct dso *dso)
9774 +{
9775 + if (dso->loadmap) {
9776 + size_t i;
9777 + for (i=0; i<dso->loadmap->nsegs; i++) {
9778 + if (!dso->loadmap->segs[i].p_memsz)
9779 + continue;
9780 + munmap((void *)dso->loadmap->segs[i].addr,
9781 + dso->loadmap->segs[i].p_memsz);
9782 + }
9783 + free(dso->loadmap);
9784 + } else if (dso->map && dso->map_len) {
9785 + munmap(dso->map, dso->map_len);
9786 + }
9787 +}
9788 +
9789 +static void *map_library(int fd, struct dso *dso)
9790 +{
9791 + Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
9792 + void *allocated_buf=0;
9793 + size_t phsize;
9794 + size_t addr_min=SIZE_MAX, addr_max=0, map_len;
9795 + size_t this_min, this_max;
9796 + size_t nsegs = 0;
9797 + off_t off_start;
9798 + Ehdr *eh;
9799 + Phdr *ph, *ph0;
9800 + unsigned prot;
9801 + unsigned char *map=MAP_FAILED, *base;
9802 + size_t dyn=0;
9803 + size_t tls_image=0;
9804 + size_t i;
9805 +
9806 + ssize_t l = read(fd, buf, sizeof buf);
9807 + eh = buf;
9808 + if (l<0) return 0;
9809 + if (l<sizeof *eh || (eh->e_type != ET_DYN && eh->e_type != ET_EXEC))
9810 + goto noexec;
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);
9824 + } else {
9825 + ph = ph0 = (void *)((char *)buf + eh->e_phoff);
9826 + }
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;
9838 + }
9839 + if (ph->p_type != PT_LOAD) continue;
9840 + nsegs++;
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));
9847 + }
9848 + if (ph->p_vaddr+ph->p_memsz > addr_max) {
9849 + addr_max = ph->p_vaddr+ph->p_memsz;
9850 + }
9851 + }
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);
9868 + goto error;
9869 + }
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;
9874 + i++;
9875 + if (prot & PROT_WRITE) {
9876 + size_t brk = (ph->p_vaddr & PAGE_SIZE-1)
9877 + + ph->p_filesz;
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)
9885 + goto error;
9886 + memset(map + brk, 0, pgbrk-brk);
9887 + }
9888 + }
9889 + map = (void *)dso->loadmap->segs[0].addr;
9890 + map_len = 0;
9891 + goto done_mapping;
9892 + }
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;
9908 + dso->map = map;
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) {
9913 + errno = EBUSY;
9914 + goto error;
9915 + }
9916 + base = map - addr_min;
9917 + dso->phdr = 0;
9918 + dso->phnum = 0;
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;
9929 + }
9930 + /* Reuse the existing mapping for the lowest-address LOAD */
9931 + if ((ph->p_vaddr & -PAGE_SIZE) == addr_min && !DL_NOMMU_SUPPORT)
9932 + continue;
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)
9940 + goto error;
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)
9946 + goto error;
9947 + }
9948 + }
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)
9953 + goto error;
9954 + break;
9955 + }
9956 +done_mapping:
9957 + dso->base = base;
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);
9962 + return map;
9963 +noexec:
9964 + errno = ENOEXEC;
9965 +error:
9966 + if (map!=MAP_FAILED) unmap_library(dso);
9967 + free(allocated_buf);
9968 + return 0;
9969 +}
9970 +
9971 +static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
9972 +{
9973 + size_t l;
9974 + int fd;
9975 + for (;;) {
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;
9981 + switch (errno) {
9982 + case ENOENT:
9983 + case ENOTDIR:
9984 + case EACCES:
9985 + case ENAMETOOLONG:
9986 + break;
9987 + default:
9988 + /* Any negative value but -1 will inhibit
9989 + * futher path search. */
9990 + return -2;
9991 + }
9992 + }
9993 + s += l;
9994 + }
9995 +}
9996 +
9997 +static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
9998 +{
9999 + size_t n, l;
10000 + const char *s, *t, *origin;
10001 + char *d;
10002 + if (p->rpath || !p->rpath_orig) return 0;
10003 + if (!strchr(p->rpath_orig, '$')) {
10004 + p->rpath = p->rpath_orig;
10005 + return 0;
10006 + }
10007 + n = 0;
10008 + s = p->rpath_orig;
10009 + while ((t=strchr(s, '$'))) {
10010 + if (strncmp(t, "$ORIGIN", 7) && strncmp(t, "${ORIGIN}", 9))
10011 + return 0;
10012 + s = t+1;
10013 + n++;
10014 + }
10015 + if (n > SSIZE_MAX/PATH_MAX) return 0;
10016 +
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). */
10024 + if (libc.secure)
10025 + return 0;
10026 + l = readlink("/proc/self/exe", buf, buf_size);
10027 + if (l == -1) switch (errno) {
10028 + case ENOENT:
10029 + case ENOTDIR:
10030 + case EACCES:
10031 + break;
10032 + default:
10033 + return -1;
10034 + }
10035 + if (l >= buf_size)
10036 + return 0;
10037 + buf[l] = 0;
10038 + origin = buf;
10039 + } else {
10040 + origin = p->name;
10041 + }
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;
10046 +
10047 + d = p->rpath;
10048 + s = p->rpath_orig;
10049 + while ((t=strchr(s, '$'))) {
10050 + memcpy(d, s, t-s);
10051 + d += t-s;
10052 + memcpy(d, origin, l);
10053 + d += l;
10054 + /* It was determined previously that the '$' is followed
10055 + * either by "ORIGIN" or "{ORIGIN}". */
10056 + s = t + 7 + 2*(t[1]=='{');
10057 + }
10058 + strcpy(d, s);
10059 + return 0;
10060 +}
10061 +
10062 +static void decode_dyn(struct dso *p)
10063 +{
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);
10080 +}
10081 +
10082 +static size_t count_syms(struct dso *p)
10083 +{
10084 + if (p->hashtab) return p->hashtab[1];
10085 +
10086 + size_t nsym, i;
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];
10092 + }
10093 + if (nsym) {
10094 + hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
10095 + do nsym++;
10096 + while (!(*hashval++ & 1));
10097 + }
10098 + return nsym;
10099 +}
10100 +
10101 +static void *dl_mmap(size_t n)
10102 +{
10103 + void *p;
10104 + int prot = PROT_READ|PROT_WRITE, flags = MAP_ANONYMOUS|MAP_PRIVATE;
10105 +#ifdef SYS_mmap2
10106 + p = (void *)__syscall(SYS_mmap2, 0, n, prot, flags, -1, 0);
10107 +#else
10108 + p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
10109 +#endif
10110 + return p == MAP_FAILED ? 0 : p;
10111 +}
10112 +
10113 +static void makefuncdescs(struct dso *p)
10114 +{
10115 + static int self_done;
10116 + size_t nsym = count_syms(p);
10117 + size_t i, size = nsym * sizeof(*p->funcdescs);
10118 +
10119 + if (!self_done) {
10120 + p->funcdescs = dl_mmap(size);
10121 + self_done = 1;
10122 + } else {
10123 + p->funcdescs = malloc(size);
10124 + }
10125 + if (!p->funcdescs) {
10126 + if (!runtime) a_crash();
10127 + error("Error allocating function descriptors for %s", p->name);
10128 + longjmp(*rtld_fail, 1);
10129 + }
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;
10134 + } else {
10135 + p->funcdescs[i].addr = 0;
10136 + p->funcdescs[i].got = 0;
10137 + }
10138 + }
10139 +}
10140 +
10141 +static struct dso *load_library(const char *name, struct dso *needed_by)
10142 +{
10143 + char buf[2*NAME_MAX+2];
10144 + const char *pathname;
10145 + unsigned char *map;
10146 + struct dso *p, temp_dso = {0};
10147 + int fd;
10148 + struct stat st;
10149 + size_t alloc_size;
10150 + int n_th = 0;
10151 + int is_self = 0;
10152 +
10153 + if (!*name) {
10154 + errno = EINVAL;
10155 + return 0;
10156 + }
10157 +
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, '.');
10163 + if (z) {
10164 + size_t l = z-name;
10165 + for (rp=reserved; *rp && strncmp(name+3, rp, l-3); rp+=strlen(rp)+1);
10166 + if (*rp) {
10167 + if (ldd_mode) {
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",
10175 + name, ldso.name,
10176 + ldso.base);
10177 + }
10178 + }
10179 + is_self = 1;
10180 + }
10181 + }
10182 + }
10183 + if (!strcmp(name, ldso.name)) is_self = 1;
10184 + if (is_self) {
10185 + if (!ldso.prev) {
10186 + tail->next = &ldso;
10187 + ldso.prev = tail;
10188 + tail = ldso.next ? ldso.next : &ldso;
10189 + }
10190 + return &ldso;
10191 + }
10192 + if (strchr(name, '/')) {
10193 + pathname = name;
10194 + fd = open(name, O_RDONLY|O_CLOEXEC);
10195 + } else {
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)) {
10199 + p->refcnt++;
10200 + return p;
10201 + }
10202 + }
10203 + if (strlen(name) > NAME_MAX) return 0;
10204 + fd = -1;
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. */
10209 + if (p->rpath)
10210 + fd = path_open(name, p->rpath, buf, sizeof buf);
10211 + }
10212 + if (fd == -1) {
10213 + if (!sys_path) {
10214 + char *prefix = 0;
10215 + size_t prefix_len;
10216 + if (ldso.name[0]=='/') {
10217 + char *s, *t, *z;
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;
10223 + }
10224 + if (!prefix) {
10225 + prefix = "";
10226 + prefix_len = 0;
10227 + }
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");
10234 + if (f) {
10235 + if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
10236 + free(sys_path);
10237 + sys_path = "";
10238 + }
10239 + fclose(f);
10240 + } else if (errno != ENOENT) {
10241 + sys_path = "";
10242 + }
10243 + }
10244 + if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
10245 + fd = path_open(name, sys_path, buf, sizeof buf);
10246 + }
10247 + pathname = buf;
10248 + }
10249 + if (fd < 0) return 0;
10250 + if (fstat(fd, &st) < 0) {
10251 + close(fd);
10252 + return 0;
10253 + }
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;
10261 + close(fd);
10262 + p->refcnt++;
10263 + return p;
10264 + }
10265 + }
10266 + map = noload ? 0 : map_library(fd, &temp_dso);
10267 + close(fd);
10268 + if (!map) return 0;
10269 +
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;
10282 + }
10283 + p = calloc(1, alloc_size);
10284 + if (!p) {
10285 + unmap_library(&temp_dso);
10286 + return 0;
10287 + }
10288 + memcpy(p, &temp_dso, sizeof temp_dso);
10289 + decode_dyn(p);
10290 + p->dev = st.st_dev;
10291 + p->ino = st.st_ino;
10292 + p->refcnt = 1;
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;
10305 +#else
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;
10310 +#endif
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;
10317 + }
10318 +
10319 + tail->next = p;
10320 + p->prev = tail;
10321 + tail = p;
10322 +
10323 + if (DL_FDPIC) makefuncdescs(p);
10324 +
10325 + if (ldd_mode) dprintf(1, "\t%s => %s (%p)\n", name, pathname, p->base);
10326 +
10327 + return p;
10328 +}
10329 +
10330 +static void load_deps(struct dso *p)
10331 +{
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);
10338 + if (!dep) {
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);
10342 + continue;
10343 + }
10344 + if (runtime) {
10345 + tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2));
10346 + if (!tmp) longjmp(*rtld_fail, 1);
10347 + tmp[ndeps++] = dep;
10348 + tmp[ndeps] = 0;
10349 + *deps = tmp;
10350 + }
10351 + }
10352 + }
10353 +}
10354 +
10355 +static void load_preload(char *s)
10356 +{
10357 + int tmp;
10358 + char *z;
10359 + for (z=s; *z; s=z) {
10360 + for ( ; *s && (isspace(*s) || *s==':'); s++);
10361 + for (z=s; *z && !isspace(*z) && *z!=':'; z++);
10362 + tmp = *z;
10363 + *z = 0;
10364 + load_library(s, 0);
10365 + *z = tmp;
10366 + }
10367 +}
10368 +
10369 +static void make_global(struct dso *p)
10370 +{
10371 + for (; p; p=p->next) p->global = 1;
10372 +}
10373 +
10374 +static void do_mips_relocs(struct dso *p, size_t *got)
10375 +{
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);
10379 + if (p==&ldso) {
10380 + got += i;
10381 + } else {
10382 + while (i--) *got++ += (size_t)base;
10383 + }
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);
10391 + }
10392 +}
10393 +
10394 +static void reloc_all(struct dso *p)
10395 +{
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);
10406 +
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",
10411 + p->name);
10412 + if (runtime) longjmp(*rtld_fail, 1);
10413 + }
10414 +
10415 + p->relocated = 1;
10416 + }
10417 +}
10418 +
10419 +static void kernel_mapped_dso(struct dso *p)
10420 +{
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;
10429 + }
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;
10435 + }
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;
10441 +}
10442 +
10443 +void __libc_exit_fini()
10444 +{
10445 + struct dso *p;
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)();
10454 + }
10455 +#ifndef NO_LEGACY_INITFINI
10456 + if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
10457 + fpaddr(p, dyn[DT_FINI])();
10458 +#endif
10459 + }
10460 +}
10461 +
10462 +static void do_init_fini(struct dso *p)
10463 +{
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;
10476 + fini_head = p;
10477 + }
10478 +#ifndef NO_LEGACY_INITFINI
10479 + if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
10480 + fpaddr(p, dyn[DT_INIT])();
10481 +#endif
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++)();
10486 + }
10487 + if (!need_locking && libc.threads_minus_1) {
10488 + need_locking = 1;
10489 + pthread_mutex_lock(&init_fini_lock);
10490 + }
10491 + }
10492 + if (need_locking) pthread_mutex_unlock(&init_fini_lock);
10493 +}
10494 +
10495 +void __libc_start_init(void)
10496 +{
10497 + do_init_fini(tail);
10498 +}
10499 +
10500 +static void dl_debug_state(void)
10501 +{
10502 +}
10503 +
10504 +weak_alias(dl_debug_state, _dl_debug_state);
10505 +
10506 +void __init_tls(size_t *auxv)
10507 +{
10508 +}
10509 +
10510 +__attribute__((__visibility__("hidden")))
10511 +void *__tls_get_new(size_t *v)
10512 +{
10513 + pthread_t self = __pthread_self();
10514 +
10515 + /* Block signals to make accessing new TLS async-signal-safe */
10516 + sigset_t set;
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;
10521 + }
10522 +
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. */
10527 + struct dso *p;
10528 + for (p=head; p->tls_id != v[0]; p=p->next);
10529 +
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;
10538 + }
10539 +
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;
10551 + }
10552 + __restore_sigs(&set);
10553 + return mem + v[1] + DTP_OFFSET;
10554 +}
10555 +
10556 +static void update_tls_size()
10557 +{
10558 + libc.tls_cnt = tls_cnt;
10559 + libc.tls_align = tls_align;
10560 + libc.tls_size = ALIGN(
10561 + (1+tls_cnt) * sizeof(void *) +
10562 + tls_offset +
10563 + sizeof(struct pthread) +
10564 + tls_align * 2,
10565 + tls_align);
10566 +}
10567 +
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. */
10571 +
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. */
10578 +
10579 +__attribute__((__visibility__("hidden")))
10580 +void __dls2(unsigned char *base, size_t *sp)
10581 +{
10582 + if (DL_FDPIC) {
10583 + void *p1 = (void *)sp[-2];
10584 + void *p2 = (void *)sp[-1];
10585 + if (!p1) {
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);
10591 + }
10592 + app_loadmap = p2 ? p1 : 0;
10593 + ldso.loadmap = p2 ? p2 : p1;
10594 + ldso.base = laddr(&ldso, 0);
10595 + } else {
10596 + ldso.base = base;
10597 + }
10598 + Ehdr *ehdr = (void *)ldso.base;
10599 + ldso.name = ldso.shortname = "libc.so";
10600 + ldso.global = 1;
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);
10606 +
10607 + if (DL_FDPIC) makefuncdescs(&ldso);
10608 +
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;
10624 +
10625 + head = &ldso;
10626 + reloc_all(&ldso);
10627 +
10628 + ldso.relocated = 0;
10629 +
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);
10636 +}
10637 +
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. */
10642 +
10643 +_Noreturn void __dls3(size_t *sp)
10644 +{
10645 + static struct dso app, vdso;
10646 + size_t aux[AUX_CNT], *auxv;
10647 + size_t i;
10648 + char *env_preload=0;
10649 + size_t vdso_base;
10650 + int argc = *sp;
10651 + char **argv = (void *)(sp+1);
10652 + char **argv_orig = argv;
10653 + char **envp = argv+argc+1;
10654 +
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]);
10665 +
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) {
10672 + a_crash();
10673 + }
10674 +
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");
10679 + }
10680 +
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;
10701 + }
10702 + }
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];
10709 + else
10710 + app.name = argv[0];
10711 + kernel_mapped_dso(&app);
10712 + } else {
10713 + int fd;
10714 + char *ldname = argv[0];
10715 + size_t l = strlen(ldname);
10716 + if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
10717 + argv++;
10718 + while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
10719 + char *opt = argv[0]+2;
10720 + *argv++ = (void *)-1;
10721 + if (!*opt) {
10722 + break;
10723 + } else if (!memcmp(opt, "list", 5)) {
10724 + ldd_mode = 1;
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++;
10733 + } else {
10734 + argv[0] = 0;
10735 + }
10736 + }
10737 + argv[-1] = (void *)(argc - (argv-argv_orig));
10738 + if (!argv[0]) {
10739 + dprintf(2, "musl libc (" LDSO_ARCH ")\n"
10740 + "Version %s\n"
10741 + "Dynamic Program Loader\n"
10742 + "Usage: %s [options] [--] pathname%s\n",
10743 + __libc_get_version(), ldname,
10744 + ldd_mode ? "" : " [args]");
10745 + _exit(1);
10746 + }
10747 + fd = open(argv[0], O_RDONLY);
10748 + if (fd < 0) {
10749 + dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
10750 + _exit(1);
10751 + }
10752 + runtime = 1;
10753 + Ehdr *ehdr = (void *)map_library(fd, &app);
10754 + if (!ehdr) {
10755 + dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
10756 + _exit(1);
10757 + }
10758 + runtime = 0;
10759 + close(fd);
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. */
10765 + if (ldd_mode) {
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);
10769 + }
10770 + dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
10771 + }
10772 + }
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) );
10781 +#else
10782 + tls_offset = app.tls.offset = app.tls.size
10783 + + ( -((uintptr_t)app.tls.image + app.tls.size)
10784 + & (app.tls.align-1) );
10785 +#endif
10786 + tls_align = MAXP2(tls_align, app.tls.align);
10787 + }
10788 + app.global = 1;
10789 + decode_dyn(&app);
10790 + if (DL_FDPIC) {
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;
10799 + }
10800 + argv[-3] = (void *)app.loadmap;
10801 + }
10802 +
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);
10814 + }
10815 + vdso.name = "";
10816 + vdso.shortname = "linux-gate.so.1";
10817 + vdso.global = 1;
10818 + vdso.relocated = 1;
10819 + decode_dyn(&vdso);
10820 + vdso.prev = &ldso;
10821 + ldso.next = &vdso;
10822 + }
10823 +
10824 + /* Initial dso chain consists only of the app. */
10825 + head = tail = &app;
10826 +
10827 + /* Donate unused parts of app and library mapping to malloc */
10828 + reclaim_gaps(&app);
10829 + reclaim_gaps(&ldso);
10830 +
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);
10834 + load_deps(&app);
10835 + make_global(&app);
10836 +
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;
10841 +#endif
10842 +
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);
10846 + reloc_all(&app);
10847 +
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);
10854 + _exit(127);
10855 + }
10856 + if (__init_tp(__copy_tls(initial_tls)) < 0) {
10857 + a_crash();
10858 + }
10859 + } else {
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;
10868 + }
10869 + static_tls_cnt = tls_cnt;
10870 +
10871 + if (ldso_fail) _exit(127);
10872 + if (ldd_mode) _exit(0);
10873 +
10874 + /* Switch to runtime mode: any further failures in the dynamic
10875 + * linker are a reportable failure rather than a fatal startup
10876 + * error. */
10877 + runtime = 1;
10878 +
10879 + debug.ver = 1;
10880 + debug.bp = dl_debug_state;
10881 + debug.head = head;
10882 + debug.base = ldso.base;
10883 + debug.state = 0;
10884 + _dl_debug_state();
10885 +
10886 + errno = 0;
10887 +
10888 + CRTJMP((void *)aux[AT_ENTRY], argv-1);
10889 + for(;;);
10890 +}
10891 +
10892 +void *dlopen(const char *file, int mode)
10893 +{
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;
10897 + size_t i;
10898 + int cs;
10899 + jmp_buf jb;
10900 +
10901 + if (!file) return head;
10902 +
10903 + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
10904 + pthread_rwlock_wrlock(&lock);
10905 + __inhibit_ptc();
10906 +
10907 + p = 0;
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;
10914 +
10915 + rtld_fail = &jb;
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) {
10922 + next = p->next;
10923 + while (p->td_index) {
10924 + void *tmp = p->td_index->next;
10925 + free(p->td_index);
10926 + p->td_index = tmp;
10927 + }
10928 + free(p->funcdescs);
10929 + if (p->rpath != p->rpath_orig)
10930 + free(p->rpath);
10931 + free(p->deps);
10932 + unmap_library(p);
10933 + free(p);
10934 + }
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;
10941 + tail->next = 0;
10942 + p = 0;
10943 + goto end;
10944 + } else p = load_library(file, head);
10945 +
10946 + if (!p) {
10947 + error(noload ?
10948 + "Library %s is not already loaded" :
10949 + "Error loading shared library %s: %m",
10950 + file);
10951 + goto end;
10952 + }
10953 +
10954 + /* First load handling */
10955 + if (!p->deps) {
10956 + load_deps(p);
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;
10961 + reloc_all(p);
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;
10966 + }
10967 +
10968 + if (mode & RTLD_GLOBAL) {
10969 + if (p->deps) for (i=0; p->deps[i]; i++)
10970 + p->deps[i]->global = 1;
10971 + p->global = 1;
10972 + }
10973 +
10974 + update_tls_size();
10975 + _dl_debug_state();
10976 + orig_tail = tail;
10977 +end:
10978 + __release_ptc();
10979 + if (p) gencnt++;
10980 + pthread_rwlock_unlock(&lock);
10981 + if (p) do_init_fini(orig_tail);
10982 + pthread_setcancelstate(cs, 0);
10983 + return p;
10984 +}
10985 +
10986 +__attribute__((__visibility__("hidden")))
10987 +int __dl_invalid_handle(void *h)
10988 +{
10989 + struct dso *p;
10990 + for (p=head; p; p=p->next) if (h==p) return 0;
10991 + error("Invalid library handle %p", (void *)h);
10992 + return 1;
10993 +}
10994 +
10995 +static void *addr2dso(size_t a)
10996 +{
10997 + struct dso *p;
10998 + size_t i;
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))
11002 + return p;
11003 + }
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)
11009 + return p;
11010 + }
11011 + } else {
11012 + if (a-(size_t)p->map < p->map_len)
11013 + return p;
11014 + }
11015 + }
11016 + return 0;
11017 +}
11018 +
11019 +void *__tls_get_addr(size_t *);
11020 +
11021 +static void *do_dlsym(struct dso *p, const char *s, void *ra)
11022 +{
11023 + size_t i;
11024 + uint32_t h = 0, gh = 0, *ght;
11025 + Sym *sym;
11026 + if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) {
11027 + if (p == RTLD_DEFAULT) {
11028 + p = head;
11029 + } else if (p == RTLD_NEXT) {
11030 + p = addr2dso((size_t)ra);
11031 + if (!p) p=head;
11032 + p = p->next;
11033 + }
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);
11041 + }
11042 + if (__dl_invalid_handle(p))
11043 + return 0;
11044 + if ((ght = p->ghashtab)) {
11045 + gh = gnu_hash(s);
11046 + sym = gnu_lookup(gh, ght, p, s);
11047 + } else {
11048 + h = sysv_hash(s);
11049 + sym = sysv_lookup(s, h, p);
11050 + }
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);
11061 + } else {
11062 + if (!h) h = sysv_hash(s);
11063 + sym = sysv_lookup(s, h, p->deps[i]);
11064 + }
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);
11071 + }
11072 +failed:
11073 + error("Symbol not found: %s", s);
11074 + return 0;
11075 +}
11076 +
11077 +int dladdr(const void *addr, Dl_info *info)
11078 +{
11079 + struct dso *p;
11080 + Sym *sym, *bestsym;
11081 + uint32_t nsym;
11082 + char *strings;
11083 + void *best = 0;
11084 +
11085 + pthread_rwlock_rdlock(&lock);
11086 + p = addr2dso((size_t)addr);
11087 + pthread_rwlock_unlock(&lock);
11088 +
11089 + if (!p) return 0;
11090 +
11091 + sym = p->syms;
11092 + strings = p->strings;
11093 + nsym = count_syms(p);
11094 +
11095 + if (DL_FDPIC) {
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;
11101 + }
11102 + }
11103 +
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)
11110 + continue;
11111 + best = symaddr;
11112 + bestsym = sym;
11113 + if (addr == symaddr)
11114 + break;
11115 + }
11116 + }
11117 +
11118 + if (!best) return 0;
11119 +
11120 + if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
11121 + best = p->funcdescs + (bestsym - p->syms);
11122 +
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;
11127 +
11128 + return 1;
11129 +}
11130 +
11131 +__attribute__((__visibility__("hidden")))
11132 +void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
11133 +{
11134 + void *res;
11135 + pthread_rwlock_rdlock(&lock);
11136 + res = do_dlsym(p, s, ra);
11137 + pthread_rwlock_unlock(&lock);
11138 + return res;
11139 +}
11140 +
11141 +int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
11142 +{
11143 + struct dso *current;
11144 + struct dl_phdr_info info;
11145 + int ret = 0;
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;
11155 +
11156 + ret = (callback)(&info, sizeof (info), data);
11157 +
11158 + if (ret != 0) break;
11159 +
11160 + pthread_rwlock_rdlock(&lock);
11161 + current = current->next;
11162 + pthread_rwlock_unlock(&lock);
11163 + }
11164 + return ret;
11165 +}
11166 +
11167 +__attribute__((__visibility__("hidden")))
11168 +void __dl_vseterr(const char *, va_list);
11169 +
11170 +static void error(const char *fmt, ...)
11171 +{
11172 + va_list ap;
11173 + va_start(ap, fmt);
11174 + if (!runtime) {
11175 + vdprintf(2, fmt, ap);
11176 + dprintf(2, "\n");
11177 + ldso_fail = 1;
11178 + va_end(ap);
11179 + return;
11180 + }
11181 + __dl_vseterr(fmt, ap);
11182 + va_end(ap);
11183 +}
11184 --- a/src/env/__init_tls.c
11185 +++ b/src/env/__init_tls.c
11186 @@ -8,9 +8,6 @@
11187 #include "atomic.h"
11188 #include "syscall.h"
11189
11190 -#ifndef SHARED
11191 -static
11192 -#endif
11193 int __init_tp(void *p)
11194 {
11195 pthread_t td = p;
11196 @@ -24,8 +21,6 @@ int __init_tp(void *p)
11197 return 0;
11198 }
11199
11200 -#ifndef SHARED
11201 -
11202 static struct builtin_tls {
11203 char c;
11204 struct pthread pt;
11205 @@ -33,33 +28,40 @@ static struct builtin_tls {
11206 } builtin_tls[1];
11207 #define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
11208
11209 -struct tls_image {
11210 - void *image;
11211 - size_t len, size, align;
11212 -} __static_tls;
11213 -
11214 -#define T __static_tls
11215 +static struct tls_module main_tls;
11216
11217 void *__copy_tls(unsigned char *mem)
11218 {
11219 pthread_t td;
11220 - if (!T.image) return mem;
11221 - void **dtv = (void *)mem;
11222 - dtv[0] = (void *)1;
11223 + struct tls_module *p;
11224 + size_t i;
11225 + void **dtv;
11226 +
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);
11231 +
11232 + mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1);
11233 td = (pthread_t)mem;
11234 mem += sizeof(struct pthread);
11235 +
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);
11239 + }
11240 #else
11241 + dtv = (void **)mem;
11242 +
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;
11247 - mem -= T.size;
11248 +
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);
11252 + }
11253 #endif
11254 + dtv[0] = (void *)libc.tls_cnt;
11255 td->dtv = td->dtv_copy = dtv;
11256 - dtv[1] = mem;
11257 - memcpy(mem, T.image, T.len);
11258 return td;
11259 }
11260
11261 @@ -69,7 +71,7 @@ typedef Elf32_Phdr Phdr;
11262 typedef Elf64_Phdr Phdr;
11263 #endif
11264
11265 -void __init_tls(size_t *aux)
11266 +static void static_init_tls(size_t *aux)
11267 {
11268 unsigned char *p;
11269 size_t n;
11270 @@ -86,16 +88,24 @@ void __init_tls(size_t *aux)
11271 }
11272
11273 if (tls_phdr) {
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;
11284 }
11285
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;
11293 +#endif
11294
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;
11300
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)
11304 a_crash();
11305 }
11306 -#else
11307 -void __init_tls(size_t *auxv) { }
11308 -#endif
11309 +
11310 +weak_alias(static_init_tls, __init_tls);
11311 --- a/src/env/__libc_start_main.c
11312 +++ b/src/env/__libc_start_main.c
11313 @@ -8,21 +8,17 @@
11314
11315 void __init_tls(size_t *);
11316
11317 -#ifndef SHARED
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));
11323 -#endif
11324 +
11325 +__attribute__((__weak__, __visibility__("hidden")))
11326 +extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
11327
11328 static void dummy1(void *p) {}
11329 weak_alias(dummy1, __init_ssp);
11330
11331 #define AUX_CNT 38
11332
11333 -#ifndef SHARED
11334 -static
11335 -#endif
11336 void __init_libc(char **envp, char *pn)
11337 {
11338 size_t i, *auxv, aux[AUX_CNT] = { 0 };
11339 @@ -57,20 +53,22 @@ void __init_libc(char **envp, char *pn)
11340 libc.secure = 1;
11341 }
11342
11343 -int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
11344 +static void libc_start_init(void)
11345 {
11346 - char **envp = argv+argc+1;
11347 -
11348 -#ifndef SHARED
11349 - __init_libc(envp, argv[0]);
11350 _init();
11351 uintptr_t a = (uintptr_t)&__init_array_start;
11352 for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
11353 (*(void (**)())a)();
11354 -#else
11355 - void __libc_start_init(void);
11356 +}
11357 +
11358 +weak_alias(libc_start_init, __libc_start_init);
11359 +
11360 +int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
11361 +{
11362 + char **envp = argv+argc+1;
11363 +
11364 + __init_libc(envp, argv[0]);
11365 __libc_start_init();
11366 -#endif
11367
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
11372 @@ -1,21 +1,16 @@
11373 -#ifndef SHARED
11374 -
11375 #include <string.h>
11376 #include "pthread_impl.h"
11377 -
11378 -extern struct tls_image {
11379 - void *image;
11380 - size_t len, size, align;
11381 -} __static_tls;
11382 -
11383 -#define T __static_tls
11384 +#include "libc.h"
11385
11386 void __reset_tls()
11387 {
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);
11399 + }
11400 }
11401 -
11402 -#endif
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)
11406 a_crash();
11407 }
11408
11409 -#ifdef SHARED
11410 -
11411 __attribute__((__visibility__("hidden")))
11412 -void __stack_chk_fail_local(void)
11413 -{
11414 - a_crash();
11415 -}
11416 -
11417 -#else
11418 +void __stack_chk_fail_local(void);
11419
11420 weak_alias(__stack_chk_fail, __stack_chk_fail_local);
11421 -
11422 -#endif
11423 --- /dev/null
11424 +++ b/src/exit/arm/__aeabi_atexit.c
11425 @@ -0,0 +1,6 @@
11426 +int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
11427 +
11428 +int __aeabi_atexit (void *obj, void (*func) (void *), void *d)
11429 +{
11430 + return __cxa_atexit (func, obj, d);
11431 +}
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);
11438 -
11439 -#ifndef SHARED
11440 weak_alias(dummy, _fini);
11441 -extern void (*const __fini_array_start)() __attribute__((weak));
11442 -extern void (*const __fini_array_end)() __attribute__((weak));
11443 -#endif
11444
11445 -_Noreturn void exit(int code)
11446 -{
11447 - __funcs_on_exit();
11448 +__attribute__((__weak__, __visibility__("hidden")))
11449 +extern void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
11450
11451 -#ifndef SHARED
11452 +static void libc_exit_fini(void)
11453 +{
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(*)())))();
11457 _fini();
11458 -#endif
11459 +}
11460
11461 - __stdio_exit();
11462 +weak_alias(libc_exit_fini, __libc_exit_fini);
11463
11464 +_Noreturn void exit(int code)
11465 +{
11466 + __funcs_on_exit();
11467 + __libc_exit_fini();
11468 + __stdio_exit();
11469 _Exit(code);
11470 }
11471 --- /dev/null
11472 +++ b/src/fenv/arm/fenv-hf.S
11473 @@ -0,0 +1,69 @@
11474 +#if __ARM_PCS_VFP
11475 +
11476 +.syntax unified
11477 +.fpu vfp
11478 +
11479 +.global fegetround
11480 +.type fegetround,%function
11481 +fegetround:
11482 + fmrx r0, fpscr
11483 + and r0, r0, #0xc00000
11484 + bx lr
11485 +
11486 +.global __fesetround
11487 +.type __fesetround,%function
11488 +__fesetround:
11489 + fmrx r3, fpscr
11490 + bic r3, r3, #0xc00000
11491 + orr r3, r3, r0
11492 + fmxr fpscr, r3
11493 + mov r0, #0
11494 + bx lr
11495 +
11496 +.global fetestexcept
11497 +.type fetestexcept,%function
11498 +fetestexcept:
11499 + and r0, r0, #0x1f
11500 + fmrx r3, fpscr
11501 + and r0, r0, r3
11502 + bx lr
11503 +
11504 +.global feclearexcept
11505 +.type feclearexcept,%function
11506 +feclearexcept:
11507 + and r0, r0, #0x1f
11508 + fmrx r3, fpscr
11509 + bic r3, r3, r0
11510 + fmxr fpscr, r3
11511 + mov r0, #0
11512 + bx lr
11513 +
11514 +.global feraiseexcept
11515 +.type feraiseexcept,%function
11516 +feraiseexcept:
11517 + and r0, r0, #0x1f
11518 + fmrx r3, fpscr
11519 + orr r3, r3, r0
11520 + fmxr fpscr, r3
11521 + mov r0, #0
11522 + bx lr
11523 +
11524 +.global fegetenv
11525 +.type fegetenv,%function
11526 +fegetenv:
11527 + fmrx r3, fpscr
11528 + str r3, [r0]
11529 + mov r0, #0
11530 + bx lr
11531 +
11532 +.global fesetenv
11533 +.type fesetenv,%function
11534 +fesetenv:
11535 + cmn r0, #1
11536 + moveq r3, #0
11537 + ldrne r3, [r0]
11538 + fmxr fpscr, r3
11539 + mov r0, #0
11540 + bx lr
11541 +
11542 +#endif
11543 --- /dev/null
11544 +++ b/src/fenv/arm/fenv.c
11545 @@ -0,0 +1,3 @@
11546 +#if !__ARM_PCS_VFP
11547 +#include "../fenv.c"
11548 +#endif
11549 --- a/src/fenv/armebhf/fenv.sub
11550 +++ /dev/null
11551 @@ -1 +0,0 @@
11552 -../armhf/fenv.s
11553 --- a/src/fenv/armhf/fenv.s
11554 +++ /dev/null
11555 @@ -1,64 +0,0 @@
11556 -.fpu vfp
11557 -
11558 -.global fegetround
11559 -.type fegetround,%function
11560 -fegetround:
11561 - mrc p10, 7, r0, cr1, cr0, 0
11562 - and r0, r0, #0xc00000
11563 - bx lr
11564 -
11565 -.global __fesetround
11566 -.type __fesetround,%function
11567 -__fesetround:
11568 - mrc p10, 7, r3, cr1, cr0, 0
11569 - bic r3, r3, #0xc00000
11570 - orr r3, r3, r0
11571 - mcr p10, 7, r3, cr1, cr0, 0
11572 - mov r0, #0
11573 - bx lr
11574 -
11575 -.global fetestexcept
11576 -.type fetestexcept,%function
11577 -fetestexcept:
11578 - and r0, r0, #0x1f
11579 - mrc p10, 7, r3, cr1, cr0, 0
11580 - and r0, r0, r3
11581 - bx lr
11582 -
11583 -.global feclearexcept
11584 -.type feclearexcept,%function
11585 -feclearexcept:
11586 - and r0, r0, #0x1f
11587 - mrc p10, 7, r3, cr1, cr0, 0
11588 - bic r3, r3, r0
11589 - mcr p10, 7, r3, cr1, cr0, 0
11590 - mov r0, #0
11591 - bx lr
11592 -
11593 -.global feraiseexcept
11594 -.type feraiseexcept,%function
11595 -feraiseexcept:
11596 - and r0, r0, #0x1f
11597 - mrc p10, 7, r3, cr1, cr0, 0
11598 - orr r3, r3, r0
11599 - mcr p10, 7, r3, cr1, cr0, 0
11600 - mov r0, #0
11601 - bx lr
11602 -
11603 -.global fegetenv
11604 -.type fegetenv,%function
11605 -fegetenv:
11606 - mrc p10, 7, r3, cr1, cr0, 0
11607 - str r3, [r0]
11608 - mov r0, #0
11609 - bx lr
11610 -
11611 -.global fesetenv
11612 -.type fesetenv,%function
11613 -fesetenv:
11614 - cmn r0, #1
11615 - moveq r3, #0
11616 - ldrne r3, [r0]
11617 - mcr p10, 7, r3, cr1, cr0, 0
11618 - mov r0, #0
11619 - bx lr
11620 --- a/src/fenv/armhf/fenv.sub
11621 +++ /dev/null
11622 @@ -1 +0,0 @@
11623 -fenv.s
11624 --- a/src/fenv/mips-sf/fenv.sub
11625 +++ /dev/null
11626 @@ -1 +0,0 @@
11627 -../fenv.c
11628 --- /dev/null
11629 +++ b/src/fenv/mips/fenv-sf.c
11630 @@ -0,0 +1,3 @@
11631 +#ifdef __mips_soft_float
11632 +#include "../fenv.c"
11633 +#endif
11634 --- /dev/null
11635 +++ b/src/fenv/mips/fenv.S
11636 @@ -0,0 +1,71 @@
11637 +#ifndef __mips_soft_float
11638 +
11639 +.set noreorder
11640 +
11641 +.global feclearexcept
11642 +.type feclearexcept,@function
11643 +feclearexcept:
11644 + and $4, $4, 0x7c
11645 + cfc1 $5, $31
11646 + or $5, $5, $4
11647 + xor $5, $5, $4
11648 + ctc1 $5, $31
11649 + jr $ra
11650 + li $2, 0
11651 +
11652 +.global feraiseexcept
11653 +.type feraiseexcept,@function
11654 +feraiseexcept:
11655 + and $4, $4, 0x7c
11656 + cfc1 $5, $31
11657 + or $5, $5, $4
11658 + ctc1 $5, $31
11659 + jr $ra
11660 + li $2, 0
11661 +
11662 +.global fetestexcept
11663 +.type fetestexcept,@function
11664 +fetestexcept:
11665 + and $4, $4, 0x7c
11666 + cfc1 $2, $31
11667 + jr $ra
11668 + and $2, $2, $4
11669 +
11670 +.global fegetround
11671 +.type fegetround,@function
11672 +fegetround:
11673 + cfc1 $2, $31
11674 + jr $ra
11675 + andi $2, $2, 3
11676 +
11677 +.global __fesetround
11678 +.type __fesetround,@function
11679 +__fesetround:
11680 + cfc1 $5, $31
11681 + li $6, -4
11682 + and $5, $5, $6
11683 + or $5, $5, $4
11684 + ctc1 $5, $31
11685 + jr $ra
11686 + li $2, 0
11687 +
11688 +.global fegetenv
11689 +.type fegetenv,@function
11690 +fegetenv:
11691 + cfc1 $5, $31
11692 + sw $5, 0($4)
11693 + jr $ra
11694 + li $2, 0
11695 +
11696 +.global fesetenv
11697 +.type fesetenv,@function
11698 +fesetenv:
11699 + addiu $5, $4, 1
11700 + beq $5, $0, 1f
11701 + nop
11702 + lw $5, 0($4)
11703 +1: ctc1 $5, $31
11704 + jr $ra
11705 + li $2, 0
11706 +
11707 +#endif
11708 --- a/src/fenv/mips/fenv.s
11709 +++ /dev/null
11710 @@ -1,67 +0,0 @@
11711 -.set noreorder
11712 -
11713 -.global feclearexcept
11714 -.type feclearexcept,@function
11715 -feclearexcept:
11716 - and $4, $4, 0x7c
11717 - cfc1 $5, $31
11718 - or $5, $5, $4
11719 - xor $5, $5, $4
11720 - ctc1 $5, $31
11721 - jr $ra
11722 - li $2, 0
11723 -
11724 -.global feraiseexcept
11725 -.type feraiseexcept,@function
11726 -feraiseexcept:
11727 - and $4, $4, 0x7c
11728 - cfc1 $5, $31
11729 - or $5, $5, $4
11730 - ctc1 $5, $31
11731 - jr $ra
11732 - li $2, 0
11733 -
11734 -.global fetestexcept
11735 -.type fetestexcept,@function
11736 -fetestexcept:
11737 - and $4, $4, 0x7c
11738 - cfc1 $2, $31
11739 - jr $ra
11740 - and $2, $2, $4
11741 -
11742 -.global fegetround
11743 -.type fegetround,@function
11744 -fegetround:
11745 - cfc1 $2, $31
11746 - jr $ra
11747 - andi $2, $2, 3
11748 -
11749 -.global __fesetround
11750 -.type __fesetround,@function
11751 -__fesetround:
11752 - cfc1 $5, $31
11753 - li $6, -4
11754 - and $5, $5, $6
11755 - or $5, $5, $4
11756 - ctc1 $5, $31
11757 - jr $ra
11758 - li $2, 0
11759 -
11760 -.global fegetenv
11761 -.type fegetenv,@function
11762 -fegetenv:
11763 - cfc1 $5, $31
11764 - sw $5, 0($4)
11765 - jr $ra
11766 - li $2, 0
11767 -
11768 -.global fesetenv
11769 -.type fesetenv,@function
11770 -fesetenv:
11771 - addiu $5, $4, 1
11772 - beq $5, $0, 1f
11773 - nop
11774 - lw $5, 0($4)
11775 -1: ctc1 $5, $31
11776 - jr $ra
11777 - li $2, 0
11778 --- a/src/fenv/mipsel-sf/fenv.sub
11779 +++ /dev/null
11780 @@ -1 +0,0 @@
11781 -../fenv.c
11782 --- a/src/fenv/sh-nofpu/fenv.sub
11783 +++ /dev/null
11784 @@ -1 +0,0 @@
11785 -../fenv.c
11786 --- /dev/null
11787 +++ b/src/fenv/sh/fenv-nofpu.c
11788 @@ -0,0 +1,3 @@
11789 +#if !__SH_FPU_ANY__ && !__SH4__
11790 +#include "../fenv.c"
11791 +#endif
11792 --- /dev/null
11793 +++ b/src/fenv/sh/fenv.S
11794 @@ -0,0 +1,78 @@
11795 +#if __SH_FPU_ANY__ || __SH4__
11796 +
11797 +.global fegetround
11798 +.type fegetround, @function
11799 +fegetround:
11800 + sts fpscr, r0
11801 + rts
11802 + and #3, r0
11803 +
11804 +.global __fesetround
11805 +.type __fesetround, @function
11806 +__fesetround:
11807 + sts fpscr, r0
11808 + or r4, r0
11809 + lds r0, fpscr
11810 + rts
11811 + mov #0, r0
11812 +
11813 +.global fetestexcept
11814 +.type fetestexcept, @function
11815 +fetestexcept:
11816 + sts fpscr, r0
11817 + and r4, r0
11818 + rts
11819 + and #0x7c, r0
11820 +
11821 +.global feclearexcept
11822 +.type feclearexcept, @function
11823 +feclearexcept:
11824 + mov r4, r0
11825 + and #0x7c, r0
11826 + not r0, r4
11827 + sts fpscr, r0
11828 + and r4, r0
11829 + lds r0, fpscr
11830 + rts
11831 + mov #0, r0
11832 +
11833 +.global feraiseexcept
11834 +.type feraiseexcept, @function
11835 +feraiseexcept:
11836 + mov r4, r0
11837 + and #0x7c, r0
11838 + sts fpscr, r4
11839 + or r4, r0
11840 + lds r0, fpscr
11841 + rts
11842 + mov #0, r0
11843 +
11844 +.global fegetenv
11845 +.type fegetenv, @function
11846 +fegetenv:
11847 + sts fpscr, r0
11848 + mov.l r0, @r4
11849 + rts
11850 + mov #0, r0
11851 +
11852 +.global fesetenv
11853 +.type fesetenv, @function
11854 +fesetenv:
11855 + mov r4, r0
11856 + cmp/eq #-1, r0
11857 + bf 1f
11858 +
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
11861 + sts fpscr, r0
11862 + mov #8, r1
11863 + swap.w r1, r1
11864 + bra 2f
11865 + and r1, r0
11866 +
11867 +1: mov.l @r4, r0 ! non-default environment
11868 +2: lds r0, fpscr
11869 + rts
11870 + mov #0, r0
11871 +
11872 +#endif
11873 --- a/src/fenv/sh/fenv.s
11874 +++ /dev/null
11875 @@ -1,74 +0,0 @@
11876 -.global fegetround
11877 -.type fegetround, @function
11878 -fegetround:
11879 - sts fpscr, r0
11880 - rts
11881 - and #3, r0
11882 -
11883 -.global __fesetround
11884 -.type __fesetround, @function
11885 -__fesetround:
11886 - sts fpscr, r0
11887 - or r4, r0
11888 - lds r0, fpscr
11889 - rts
11890 - mov #0, r0
11891 -
11892 -.global fetestexcept
11893 -.type fetestexcept, @function
11894 -fetestexcept:
11895 - sts fpscr, r0
11896 - and r4, r0
11897 - rts
11898 - and #0x7c, r0
11899 -
11900 -.global feclearexcept
11901 -.type feclearexcept, @function
11902 -feclearexcept:
11903 - mov r4, r0
11904 - and #0x7c, r0
11905 - not r0, r4
11906 - sts fpscr, r0
11907 - and r4, r0
11908 - lds r0, fpscr
11909 - rts
11910 - mov #0, r0
11911 -
11912 -.global feraiseexcept
11913 -.type feraiseexcept, @function
11914 -feraiseexcept:
11915 - mov r4, r0
11916 - and #0x7c, r0
11917 - sts fpscr, r4
11918 - or r4, r0
11919 - lds r0, fpscr
11920 - rts
11921 - mov #0, r0
11922 -
11923 -.global fegetenv
11924 -.type fegetenv, @function
11925 -fegetenv:
11926 - sts fpscr, r0
11927 - mov.l r0, @r4
11928 - rts
11929 - mov #0, r0
11930 -
11931 -.global fesetenv
11932 -.type fesetenv, @function
11933 -fesetenv:
11934 - mov r4, r0
11935 - cmp/eq #-1, r0
11936 - bf 1f
11937 -
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
11940 - sts fpscr, r0
11941 - mov #8, r1
11942 - swap.w r1, r1
11943 - bra 2f
11944 - and r1, r0
11945 -
11946 -1: mov.l @r4, r0 ! non-default environment
11947 -2: lds r0, fpscr
11948 - rts
11949 - mov #0, r0
11950 --- a/src/fenv/sheb-nofpu/fenv.sub
11951 +++ /dev/null
11952 @@ -1 +0,0 @@
11953 -../fenv.c
11954 --- a/src/internal/arm/syscall.s
11955 +++ b/src/internal/arm/syscall.s
11956 @@ -1,3 +1,4 @@
11957 +.syntax unified
11958 .global __syscall
11959 .hidden __syscall
11960 .type __syscall,%function
11961 @@ -11,6 +12,4 @@ __syscall:
11962 ldmfd ip,{r3,r4,r5,r6}
11963 svc 0
11964 ldmfd sp!,{r4,r5,r6,r7}
11965 - tst lr,#1
11966 - moveq pc,lr
11967 bx lr
11968 --- /dev/null
11969 +++ b/src/internal/atomic.h
11970 @@ -0,0 +1,275 @@
11971 +#ifndef _ATOMIC_H
11972 +#define _ATOMIC_H
11973 +
11974 +#include <stdint.h>
11975 +
11976 +#include "atomic_arch.h"
11977 +
11978 +#ifdef a_ll
11979 +
11980 +#ifndef a_pre_llsc
11981 +#define a_pre_llsc()
11982 +#endif
11983 +
11984 +#ifndef a_post_llsc
11985 +#define a_post_llsc()
11986 +#endif
11987 +
11988 +#ifndef a_cas
11989 +#define a_cas a_cas
11990 +static inline int a_cas(volatile int *p, int t, int s)
11991 +{
11992 + int old;
11993 + a_pre_llsc();
11994 + do old = a_ll(p);
11995 + while (old==t && !a_sc(p, s));
11996 + a_post_llsc();
11997 + return old;
11998 +}
11999 +#endif
12000 +
12001 +#ifndef a_swap
12002 +#define a_swap a_swap
12003 +static inline int a_swap(volatile int *p, int v)
12004 +{
12005 + int old;
12006 + a_pre_llsc();
12007 + do old = a_ll(p);
12008 + while (!a_sc(p, v));
12009 + a_post_llsc();
12010 + return old;
12011 +}
12012 +#endif
12013 +
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)
12017 +{
12018 + int old;
12019 + a_pre_llsc();
12020 + do old = a_ll(p);
12021 + while (!a_sc(p, (unsigned)old + v));
12022 + a_post_llsc();
12023 + return old;
12024 +}
12025 +#endif
12026 +
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)
12030 +{
12031 + int old;
12032 + a_pre_llsc();
12033 + do old = a_ll(p);
12034 + while (!a_sc(p, old & v));
12035 + a_post_llsc();
12036 + return old;
12037 +}
12038 +#endif
12039 +
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)
12043 +{
12044 + int old;
12045 + a_pre_llsc();
12046 + do old = a_ll(p);
12047 + while (!a_sc(p, old | v));
12048 + a_post_llsc();
12049 + return old;
12050 +}
12051 +#endif
12052 +
12053 +#endif
12054 +
12055 +#ifndef a_cas
12056 +#error missing definition of a_cas
12057 +#endif
12058 +
12059 +#ifndef a_swap
12060 +#define a_swap a_swap
12061 +static inline int a_swap(volatile int *p, int v)
12062 +{
12063 + int old;
12064 + do old = *p;
12065 + while (a_cas(p, old, v) != old);
12066 + return old;
12067 +}
12068 +#endif
12069 +
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)
12073 +{
12074 + int old;
12075 + do old = *p;
12076 + while (a_cas(p, old, (unsigned)old+v) != old);
12077 + return old;
12078 +}
12079 +#endif
12080 +
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)
12084 +{
12085 + int old;
12086 + do old = *p;
12087 + while (a_cas(p, old, old&v) != old);
12088 + return old;
12089 +}
12090 +#endif
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)
12094 +{
12095 + int old;
12096 + do old = *p;
12097 + while (a_cas(p, old, old|v) != old);
12098 + return old;
12099 +}
12100 +#endif
12101 +
12102 +#ifndef a_and
12103 +#define a_and a_and
12104 +static inline void a_and(volatile int *p, int v)
12105 +{
12106 + a_fetch_and(p, v);
12107 +}
12108 +#endif
12109 +
12110 +#ifndef a_or
12111 +#define a_or a_or
12112 +static inline void a_or(volatile int *p, int v)
12113 +{
12114 + a_fetch_or(p, v);
12115 +}
12116 +#endif
12117 +
12118 +#ifndef a_inc
12119 +#define a_inc a_inc
12120 +static inline void a_inc(volatile int *p)
12121 +{
12122 + a_fetch_add(p, 1);
12123 +}
12124 +#endif
12125 +
12126 +#ifndef a_dec
12127 +#define a_dec a_dec
12128 +static inline void a_dec(volatile int *p)
12129 +{
12130 + a_fetch_add(p, -1);
12131 +}
12132 +#endif
12133 +
12134 +#ifndef a_store
12135 +#define a_store a_store
12136 +static inline void a_store(volatile int *p, int v)
12137 +{
12138 +#ifdef a_barrier
12139 + a_barrier();
12140 + *p = v;
12141 + a_barrier();
12142 +#else
12143 + a_swap(p, v);
12144 +#endif
12145 +}
12146 +#endif
12147 +
12148 +#ifndef a_barrier
12149 +#define a_barrier a_barrier
12150 +static void a_barrier()
12151 +{
12152 + volatile int tmp = 0;
12153 + a_cas(&tmp, 0, 0);
12154 +}
12155 +#endif
12156 +
12157 +#ifndef a_spin
12158 +#define a_spin a_barrier
12159 +#endif
12160 +
12161 +#ifndef a_and_64
12162 +#define a_and_64 a_and_64
12163 +static inline void a_and_64(volatile uint64_t *p, uint64_t v)
12164 +{
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]);
12168 +}
12169 +#endif
12170 +
12171 +#ifndef a_or_64
12172 +#define a_or_64 a_or_64
12173 +static inline void a_or_64(volatile uint64_t *p, uint64_t v)
12174 +{
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]);
12178 +}
12179 +#endif
12180 +
12181 +#ifndef a_cas_p
12182 +#define a_cas_p a_cas_p
12183 +static inline void *a_cas_p(volatile void *p, void *t, void *s)
12184 +{
12185 + return (void *)a_cas((volatile int *)p, (int)t, (int)s);
12186 +}
12187 +#endif
12188 +
12189 +#ifndef a_or_l
12190 +#define a_or_l a_or_l
12191 +static inline void a_or_l(volatile void *p, long v)
12192 +{
12193 + if (sizeof(long) == sizeof(int)) a_or(p, v);
12194 + else a_or_64(p, v);
12195 +}
12196 +#endif
12197 +
12198 +#ifndef a_crash
12199 +#define a_crash a_crash
12200 +static inline void a_crash()
12201 +{
12202 + *(volatile char *)0=0;
12203 +}
12204 +#endif
12205 +
12206 +#ifndef a_ctz_64
12207 +#define a_ctz_64 a_ctz_64
12208 +static inline int a_ctz_64(uint64_t x)
12209 +{
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
12215 + };
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
12219 + };
12220 + if (sizeof(long) < 8) {
12221 + uint32_t y = x;
12222 + if (!y) {
12223 + y = x>>32;
12224 + return 32 + debruijn32[(y&-y)*0x076be629 >> 27];
12225 + }
12226 + return debruijn32[(y&-y)*0x076be629 >> 27];
12227 + }
12228 + return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58];
12229 +}
12230 +#endif
12231 +
12232 +#ifndef a_ctz_l
12233 +#define a_ctz_l a_ctz_l
12234 +static inline int a_ctz_l(unsigned long x)
12235 +{
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
12239 + };
12240 + if (sizeof(long) == 8) return a_ctz_64(x);
12241 + return debruijn32[(x&-x)*0x076be629 >> 27];
12242 +}
12243 +#endif
12244 +
12245 +#endif
12246 --- a/src/internal/dynlink.h
12247 +++ b/src/internal/dynlink.h
12248 @@ -64,6 +64,10 @@ struct fdpic_dummy_loadmap {
12249 #define DL_FDPIC 0
12250 #endif
12251
12252 +#ifndef DL_NOMMU_SUPPORT
12253 +#define DL_NOMMU_SUPPORT 0
12254 +#endif
12255 +
12256 #if !DL_FDPIC
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];
12263 };
12264
12265 +struct tls_module {
12266 + struct tls_module *next;
12267 + void *image;
12268 + size_t len, size, align, offset;
12269 +};
12270 +
12271 struct __libc {
12272 int can_do_threads;
12273 int threaded;
12274 int secure;
12275 volatile int threads_minus_1;
12276 size_t *auxv;
12277 - size_t tls_size;
12278 + struct tls_module *tls_head;
12279 + size_t tls_size, tls_align, tls_cnt;
12280 size_t page_size;
12281 struct __locale_struct global_locale;
12282 };
12283 --- /dev/null
12284 +++ b/src/internal/sh/__shcall.c
12285 @@ -0,0 +1,5 @@
12286 +__attribute__((__visibility__("hidden")))
12287 +int __shcall(void *arg, int (*func)(void *))
12288 +{
12289 + return func(arg);
12290 +}
12291 --- a/src/internal/syscall.h
12292 +++ b/src/internal/syscall.h
12293 @@ -17,9 +17,7 @@
12294 typedef long syscall_arg_t;
12295 #endif
12296
12297 -#ifdef SHARED
12298 __attribute__((visibility("hidden")))
12299 -#endif
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__))
12306
12307 -#ifdef SYS_socket
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)
12311 #else
12312 --- a/src/internal/version.c
12313 +++ b/src/internal/version.c
12314 @@ -1,12 +1,9 @@
12315 -#ifdef SHARED
12316 -
12317 #include "version.h"
12318
12319 static const char version[] = VERSION;
12320
12321 +__attribute__((__visibility__("hidden")))
12322 const char *__libc_get_version()
12323 {
12324 return version;
12325 }
12326 -
12327 -#endif
12328 --- a/src/internal/vis.h
12329 +++ b/src/internal/vis.h
12330 @@ -4,10 +4,9 @@
12331 * override default visibilities to reduce the size and performance costs
12332 * of position-independent code. */
12333
12334 -#ifndef CRT
12335 -#ifdef SHARED
12336 +#if !defined(CRT) && !defined(__ASSEMBLER__)
12337
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. */
12342
12343 @@ -25,16 +24,4 @@ extern char *optarg, **environ, **__envi
12344
12345 #pragma GCC visibility push(protected)
12346
12347 -#elif defined(__PIC__)
12348 -
12349 -/* If building static libc.a as position-independent code, try to make
12350 - * everything hidden except possibly-undefined weak references. */
12351 -
12352 -__attribute__((__visibility__("default")))
12353 -extern void (*const __init_array_start)(), (*const __init_array_end)(),
12354 - (*const __fini_array_start)(), (*const __fini_array_end)();
12355 -
12356 -#pragma GCC visibility push(hidden)
12357 -
12358 -#endif
12359 #endif
12360 --- /dev/null
12361 +++ b/src/ldso/__dlsym.c
12362 @@ -0,0 +1,13 @@
12363 +#include <dlfcn.h>
12364 +#include "libc.h"
12365 +
12366 +__attribute__((__visibility__("hidden")))
12367 +void __dl_seterr(const char *, ...);
12368 +
12369 +static void *stub_dlsym(void *restrict p, const char *restrict s, void *restrict ra)
12370 +{
12371 + __dl_seterr("Symbol not found: %s", s);
12372 + return 0;
12373 +}
12374 +
12375 +weak_alias(stub_dlsym, __dlsym);
12376 --- a/src/ldso/arm/dlsym.s
12377 +++ b/src/ldso/arm/dlsym.s
12378 @@ -1,3 +1,4 @@
12379 +.syntax unified
12380 .text
12381 .global dlsym
12382 .hidden __dlsym
12383 --- /dev/null
12384 +++ b/src/ldso/arm/find_exidx.c
12385 @@ -0,0 +1,42 @@
12386 +#define _GNU_SOURCE
12387 +#include <link.h>
12388 +#include <stdint.h>
12389 +
12390 +struct find_exidx_data {
12391 + uintptr_t pc, exidx_start;
12392 + int exidx_len;
12393 +};
12394 +
12395 +static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr)
12396 +{
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;
12401 +
12402 + for (i = info->dlpi_phnum; i > 0; i--, phdr++) {
12403 + addr = info->dlpi_addr + phdr->p_vaddr;
12404 + switch (phdr->p_type) {
12405 + case PT_LOAD:
12406 + match |= data->pc >= addr && data->pc < addr + phdr->p_memsz;
12407 + break;
12408 + case PT_ARM_EXIDX:
12409 + exidx_start = addr;
12410 + exidx_len = phdr->p_memsz;
12411 + break;
12412 + }
12413 + }
12414 + data->exidx_start = exidx_start;
12415 + data->exidx_len = exidx_len;
12416 + return match;
12417 +}
12418 +
12419 +uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount)
12420 +{
12421 + struct find_exidx_data data;
12422 + data.pc = pc;
12423 + if (dl_iterate_phdr(find_exidx, &data) <= 0)
12424 + return 0;
12425 + *pcount = data.exidx_len / 8;
12426 + return data.exidx_start;
12427 +}
12428 --- a/src/ldso/dl_iterate_phdr.c
12429 +++ b/src/ldso/dl_iterate_phdr.c
12430 @@ -1,12 +1,10 @@
12431 -#ifndef SHARED
12432 -
12433 #include <elf.h>
12434 #include <link.h>
12435 #include "libc.h"
12436
12437 #define AUX_CNT 38
12438
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)
12441 {
12442 unsigned char *p;
12443 ElfW(Phdr) *phdr, *tls_phdr=0;
12444 @@ -40,4 +38,5 @@ int dl_iterate_phdr(int(*callback)(struc
12445 }
12446 return (callback)(&info, sizeof (info), data);
12447 }
12448 -#endif
12449 +
12450 +weak_alias(static_dl_iterate_phdr, dl_iterate_phdr);
12451 --- a/src/ldso/dladdr.c
12452 +++ b/src/ldso/dladdr.c
12453 @@ -1,9 +1,10 @@
12454 #define _GNU_SOURCE
12455 #include <dlfcn.h>
12456 +#include "libc.h"
12457
12458 -int __dladdr(const void *, Dl_info *);
12459 -
12460 -int dladdr(const void *addr, Dl_info *info)
12461 +static int stub_dladdr(const void *addr, Dl_info *info)
12462 {
12463 - return __dladdr(addr, info);
12464 + return 0;
12465 }
12466 +
12467 +weak_alias(stub_dladdr, dladdr);
12468 --- /dev/null
12469 +++ b/src/ldso/dlclose.c
12470 @@ -0,0 +1,9 @@
12471 +#include <dlfcn.h>
12472 +
12473 +__attribute__((__visibility__("hidden")))
12474 +int __dl_invalid_handle(void *);
12475 +
12476 +int dlclose(void *p)
12477 +{
12478 + return __dl_invalid_handle(p);
12479 +}
12480 --- /dev/null
12481 +++ b/src/ldso/dlerror.c
12482 @@ -0,0 +1,64 @@
12483 +#include <dlfcn.h>
12484 +#include <stdlib.h>
12485 +#include <stdarg.h>
12486 +#include "pthread_impl.h"
12487 +#include "libc.h"
12488 +
12489 +char *dlerror()
12490 +{
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";
12497 + else
12498 + return s;
12499 +}
12500 +
12501 +void __dl_thread_cleanup(void)
12502 +{
12503 + pthread_t self = __pthread_self();
12504 + if (self->dlerror_buf != (void *)-1)
12505 + free(self->dlerror_buf);
12506 +}
12507 +
12508 +__attribute__((__visibility__("hidden")))
12509 +void __dl_vseterr(const char *fmt, va_list ap)
12510 +{
12511 + va_list ap2;
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);
12517 + va_end(ap2);
12518 + char *buf = malloc(len+1);
12519 + if (buf) {
12520 + vsnprintf(buf, len+1, fmt, ap);
12521 + } else {
12522 + buf = (void *)-1;
12523 + }
12524 + self->dlerror_buf = buf;
12525 + self->dlerror_flag = 1;
12526 +}
12527 +
12528 +__attribute__((__visibility__("hidden")))
12529 +void __dl_seterr(const char *fmt, ...)
12530 +{
12531 + va_list ap;
12532 + va_start(ap, fmt);
12533 + __dl_vseterr(fmt, ap);
12534 + va_end(ap);
12535 +}
12536 +
12537 +__attribute__((__visibility__("hidden")))
12538 +int __dl_invalid_handle(void *);
12539 +
12540 +static int stub_invalid_handle(void *h)
12541 +{
12542 + __dl_seterr("Invalid library handle %p", (void *)h);
12543 + return 1;
12544 +}
12545 +
12546 +weak_alias(stub_invalid_handle, __dl_invalid_handle);
12547 --- a/src/ldso/dlinfo.c
12548 +++ b/src/ldso/dlinfo.c
12549 @@ -1,9 +1,19 @@
12550 #define _GNU_SOURCE
12551 #include <dlfcn.h>
12552
12553 -int __dlinfo(void *, int, void *);
12554 +__attribute__((__visibility__("hidden")))
12555 +int __dl_invalid_handle(void *);
12556 +
12557 +__attribute__((__visibility__("hidden")))
12558 +void __dl_seterr(const char *, ...);
12559
12560 int dlinfo(void *dso, int req, void *res)
12561 {
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);
12566 + return -1;
12567 + }
12568 + *(struct link_map **)res = dso;
12569 + return 0;
12570 }
12571 --- /dev/null
12572 +++ b/src/ldso/dlopen.c
12573 @@ -0,0 +1,13 @@
12574 +#include <dlfcn.h>
12575 +#include "libc.h"
12576 +
12577 +__attribute__((__visibility__("hidden")))
12578 +void __dl_seterr(const char *, ...);
12579 +
12580 +static void *stub_dlopen(const char *file, int mode)
12581 +{
12582 + __dl_seterr("Dynamic loading not supported");
12583 + return 0;
12584 +}
12585 +
12586 +weak_alias(stub_dlopen, dlopen);
12587 --- a/src/ldso/dlstart.c
12588 +++ /dev/null
12589 @@ -1,150 +0,0 @@
12590 -#include <stddef.h>
12591 -#include "dynlink.h"
12592 -
12593 -#ifdef SHARED
12594 -
12595 -#ifndef START
12596 -#define START "_dlstart"
12597 -#endif
12598 -
12599 -#include "crt_arch.h"
12600 -
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)
12607 -#endif
12608 -
12609 -__attribute__((__visibility__("hidden")))
12610 -void _dlstart_c(size_t *sp, size_t *dynv)
12611 -{
12612 - size_t i, aux[AUX_CNT], dyn[DYN_CNT];
12613 - size_t *rel, rel_size, base;
12614 -
12615 - int argc = *sp;
12616 - char **argv = (void *)(sp+1);
12617 -
12618 - for (i=argc+1; argv[i]; i++);
12619 - size_t *auxv = (void *)(argv+i+1);
12620 -
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];
12624 -
12625 -#if DL_FDPIC
12626 - struct fdpic_loadseg *segs, fakeseg;
12627 - size_t j;
12628 - if (dynv) {
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;
12633 - } else {
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;
12641 - segs = &fakeseg;
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);
12652 - }
12653 -#endif
12654 -
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];
12658 -
12659 -#if DL_FDPIC
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;
12665 - }
12666 - base = 0;
12667 -
12668 - const Sym *syms = (void *)dyn[DT_SYMTAB];
12669 -
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];
12682 - } else {
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;
12686 - }
12687 - }
12688 -#else
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];
12694 - if (!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;
12701 - break;
12702 - }
12703 - }
12704 - }
12705 -
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;
12715 - }
12716 -
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;
12723 - }
12724 -
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];
12731 - }
12732 -#endif
12733 -
12734 - stage2_func dls2;
12735 - GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
12736 - dls2((void *)base, sp);
12737 -}
12738 -
12739 -#endif
12740 --- a/src/ldso/dynlink.c
12741 +++ /dev/null
12742 @@ -1,2000 +0,0 @@
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>
12751 -#include <elf.h>
12752 -#include <sys/mman.h>
12753 -#include <limits.h>
12754 -#include <fcntl.h>
12755 -#include <sys/stat.h>
12756 -#include <errno.h>
12757 -#include <link.h>
12758 -#include <setjmp.h>
12759 -#include <pthread.h>
12760 -#include <ctype.h>
12761 -#include <dlfcn.h>
12762 -#include "pthread_impl.h"
12763 -#include "libc.h"
12764 -#include "dynlink.h"
12765 -
12766 -static void error(const char *, ...);
12767 -
12768 -#ifdef SHARED
12769 -
12770 -#define MAXP2(a,b) (-(-(a)&-(b)))
12771 -#define ALIGN(x,y) ((x)+(y)-1 & -(y))
12772 -
12773 -struct debug {
12774 - int ver;
12775 - void *head;
12776 - void (*bp)(void);
12777 - int state;
12778 - void *base;
12779 -};
12780 -
12781 -struct td_index {
12782 - size_t args[2];
12783 - struct td_index *next;
12784 -};
12785 -
12786 -struct dso {
12787 -#if DL_FDPIC
12788 - struct fdpic_loadmap *loadmap;
12789 -#else
12790 - unsigned char *base;
12791 -#endif
12792 - char *name;
12793 - size_t *dynv;
12794 - struct dso *next, *prev;
12795 -
12796 - Phdr *phdr;
12797 - int phnum;
12798 - size_t phentsize;
12799 - int refcnt;
12800 - Sym *syms;
12801 - uint32_t *hashtab;
12802 - uint32_t *ghashtab;
12803 - int16_t *versym;
12804 - char *strings;
12805 - unsigned char *map;
12806 - size_t map_len;
12807 - dev_t dev;
12808 - ino_t ino;
12809 - signed char global;
12810 - char relocated;
12811 - char constructed;
12812 - char kernel_mapped;
12813 - struct dso **deps, *needed_by;
12814 - char *rpath_orig, *rpath;
12815 - void *tls_image;
12816 - size_t tls_len, tls_size, tls_align, tls_id, tls_offset;
12817 - size_t relro_start, relro_end;
12818 - void **new_dtv;
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;
12823 - char *shortname;
12824 -#if DL_FDPIC
12825 - unsigned char *base;
12826 -#else
12827 - struct fdpic_loadmap *loadmap;
12828 -#endif
12829 - struct funcdesc {
12830 - void *addr;
12831 - size_t *got;
12832 - } *funcdescs;
12833 - size_t *got;
12834 - char buf[];
12835 -};
12836 -
12837 -struct symdef {
12838 - Sym *sym;
12839 - struct dso *dso;
12840 -};
12841 -
12842 -int __init_tp(void *);
12843 -void __init_libc(char **, char *);
12844 -
12845 -const char *__libc_get_version(void);
12846 -
12847 -static struct builtin_tls {
12848 - char c;
12849 - struct pthread pt;
12850 - void *space[16];
12851 -} builtin_tls[1];
12852 -#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt)
12853 -
12854 -#define ADDEND_LIMIT 4096
12855 -static size_t *saved_addends, *apply_addends_to;
12856 -
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;
12873 -
12874 -struct debug *_dl_debug_addr = &debug;
12875 -
12876 -static int dl_strcmp(const char *l, const char *r)
12877 -{
12878 - for (; *l==*r && *l; l++, r++);
12879 - return *(unsigned char *)l - *(unsigned char *)r;
12880 -}
12881 -#define strcmp(l,r) dl_strcmp(l,r)
12882 -
12883 -/* Compute load address for a virtual address in a given dso. */
12884 -#if DL_FDPIC
12885 -static void *laddr(const struct dso *p, size_t v)
12886 -{
12887 - size_t j=0;
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);
12891 -}
12892 -#define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \
12893 - laddr(p, v), (p)->got })
12894 -#else
12895 -#define laddr(p, v) (void *)((p)->base + (v))
12896 -#define fpaddr(p, v) ((void (*)())laddr(p, v))
12897 -#endif
12898 -
12899 -static void decode_vec(size_t *v, size_t *a, size_t cnt)
12900 -{
12901 - size_t i;
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];
12905 - a[v[0]] = v[1];
12906 - }
12907 -}
12908 -
12909 -static int search_vec(size_t *v, size_t *r, size_t key)
12910 -{
12911 - for (; v[0]!=key; v+=2)
12912 - if (!v[0]) return 0;
12913 - *r = v[1];
12914 - return 1;
12915 -}
12916 -
12917 -static uint32_t sysv_hash(const char *s0)
12918 -{
12919 - const unsigned char *s = (void *)s0;
12920 - uint_fast32_t h = 0;
12921 - while (*s) {
12922 - h = 16*h + *s++;
12923 - h ^= h>>24 & 0xf0;
12924 - }
12925 - return h & 0xfffffff;
12926 -}
12927 -
12928 -static uint32_t gnu_hash(const char *s0)
12929 -{
12930 - const unsigned char *s = (void *)s0;
12931 - uint_fast32_t h = 5381;
12932 - for (; *s; s++)
12933 - h += h*32 + *s;
12934 - return h;
12935 -}
12936 -
12937 -static Sym *sysv_lookup(const char *s, uint32_t h, struct dso *dso)
12938 -{
12939 - size_t i;
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)))
12946 - return syms+i;
12947 - }
12948 - return 0;
12949 -}
12950 -
12951 -static Sym *gnu_lookup(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s)
12952 -{
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];
12956 -
12957 - if (!i) return 0;
12958 -
12959 - uint32_t *hashval = buckets + nbuckets + (i - hashtab[1]);
12960 -
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;
12967 - }
12968 -
12969 - return 0;
12970 -}
12971 -
12972 -static Sym *gnu_lookup_filtered(uint32_t h1, uint32_t *hashtab, struct dso *dso, const char *s, uint32_t fofs, size_t fmask)
12973 -{
12974 - const size_t *bloomwords = (const void *)(hashtab+4);
12975 - size_t f = bloomwords[fofs & (hashtab[2]-1)];
12976 - if (!(f & fmask)) return 0;
12977 -
12978 - f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
12979 - if (!(f & 1)) return 0;
12980 -
12981 - return gnu_lookup(h1, hashtab, dso, s);
12982 -}
12983 -
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)
12986 -
12987 -#ifndef ARCH_SYM_REJECT_UND
12988 -#define ARCH_SYM_REJECT_UND(s) 0
12989 -#endif
12990 -
12991 -static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
12992 -{
12993 - uint32_t h = 0, gh, gho, *ght;
12994 - size_t ghm = 0;
12995 - struct symdef def = {0};
12996 - for (; dso; dso=dso->next) {
12997 - Sym *sym;
12998 - if (!dso->global) continue;
12999 - if ((ght = dso->ghashtab)) {
13000 - if (!ghm) {
13001 - gh = gnu_hash(s);
13002 - int maskbits = 8 * sizeof ghm;
13003 - gho = gh / maskbits;
13004 - ghm = 1ul << gh % maskbits;
13005 - }
13006 - sym = gnu_lookup_filtered(gh, ght, dso, s, gho, ghm);
13007 - } else {
13008 - if (!h) h = sysv_hash(s);
13009 - sym = sysv_lookup(s, h, dso);
13010 - }
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))
13015 - continue;
13016 - if (!sym->st_value)
13017 - if ((sym->st_info&0xf) != STT_TLS)
13018 - continue;
13019 - if (!(1<<(sym->st_info&0xf) & OK_TYPES)) continue;
13020 - if (!(1<<(sym->st_info>>4) & OK_BINDS)) continue;
13021 -
13022 - if (def.sym && sym->st_info>>4 == STB_WEAK) continue;
13023 - def.sym = sym;
13024 - def.dso = dso;
13025 - if (sym->st_info>>4 == STB_GLOBAL) break;
13026 - }
13027 - return def;
13028 -}
13029 -
13030 -__attribute__((__visibility__("hidden")))
13031 -ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic();
13032 -
13033 -static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
13034 -{
13035 - unsigned char *base = dso->base;
13036 - Sym *syms = dso->syms;
13037 - char *strings = dso->strings;
13038 - Sym *sym;
13039 - const char *name;
13040 - void *ctx;
13041 - int type;
13042 - int sym_index;
13043 - struct symdef def;
13044 - size_t *reloc_addr;
13045 - size_t sym_val;
13046 - size_t tls_val;
13047 - size_t addend;
13048 - int skip_relative = 0, reuse_addends = 0, save_slot = 0;
13049 -
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;
13055 - }
13056 -
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]);
13063 - if (sym_index) {
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);
13075 - continue;
13076 - }
13077 - } else {
13078 - sym = 0;
13079 - def.sym = 0;
13080 - def.dso = dso;
13081 - }
13082 -
13083 - if (stride > 2) {
13084 - addend = rel[2];
13085 - } else if (type==REL_GOT || type==REL_PLT|| type==REL_COPY) {
13086 - addend = 0;
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. */
13091 - if (head==&ldso)
13092 - saved_addends[save_slot] = *reloc_addr;
13093 - addend = saved_addends[save_slot++];
13094 - } else {
13095 - addend = *reloc_addr;
13096 - }
13097 -
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;
13100 -
13101 - switch(type) {
13102 - case REL_NONE:
13103 - break;
13104 - case REL_OFFSET:
13105 - addend -= (size_t)reloc_addr;
13106 - case REL_SYMBOLIC:
13107 - case REL_GOT:
13108 - case REL_PLT:
13109 - *reloc_addr = sym_val + addend;
13110 - break;
13111 - case REL_RELATIVE:
13112 - *reloc_addr = (size_t)base + addend;
13113 - break;
13114 - case REL_SYM_OR_REL:
13115 - if (sym) *reloc_addr = sym_val + addend;
13116 - else *reloc_addr = (size_t)base + addend;
13117 - break;
13118 - case REL_COPY:
13119 - memcpy(reloc_addr, (void *)sym_val, sym->st_size);
13120 - break;
13121 - case REL_OFFSET32:
13122 - *(uint32_t *)reloc_addr = sym_val + addend
13123 - - (size_t)reloc_addr;
13124 - break;
13125 - case REL_FUNCDESC:
13126 - *reloc_addr = def.sym ? (size_t)(def.dso->funcdescs
13127 - + (def.sym - def.dso->syms)) : 0;
13128 - break;
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;
13133 - break;
13134 - case REL_DTPMOD:
13135 - *reloc_addr = def.dso->tls_id;
13136 - break;
13137 - case REL_DTPOFF:
13138 - *reloc_addr = tls_val + addend - DTP_OFFSET;
13139 - break;
13140 -#ifdef TLS_ABOVE_TP
13141 - case REL_TPOFF:
13142 - *reloc_addr = tls_val + def.dso->tls_offset + TPOFF_K + addend;
13143 - break;
13144 -#else
13145 - case REL_TPOFF:
13146 - *reloc_addr = tls_val - def.dso->tls_offset + addend;
13147 - break;
13148 - case REL_TPOFF_NEG:
13149 - *reloc_addr = def.dso->tls_offset - tls_val + addend;
13150 - break;
13151 -#endif
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);
13156 - if (!new) {
13157 - error(
13158 - "Error relocating %s: cannot allocate TLSDESC for %s",
13159 - dso->name, sym ? name : "(local)" );
13160 - longjmp(*rtld_fail, 1);
13161 - }
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;
13168 - } else {
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;
13173 -#else
13174 - reloc_addr[1] = tls_val - def.dso->tls_offset
13175 - + addend;
13176 -#endif
13177 - }
13178 - break;
13179 - default:
13180 - error("Error relocating %s: unsupported relocation type %d",
13181 - dso->name, type);
13182 - if (runtime) longjmp(*rtld_fail, 1);
13183 - continue;
13184 - }
13185 - }
13186 -}
13187 -
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. */
13193 -
13194 -static void reclaim(struct dso *dso, size_t start, size_t end)
13195 -{
13196 - size_t *a, *z;
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);
13204 - a[-2] = 1;
13205 - a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1;
13206 - z[1] = 1;
13207 - free(a);
13208 -}
13209 -
13210 -static void reclaim_gaps(struct dso *dso)
13211 -{
13212 - Phdr *ph = dso->phdr;
13213 - size_t phcnt = dso->phnum;
13214 -
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);
13222 - }
13223 -}
13224 -
13225 -static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t off)
13226 -{
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) {
13231 - memset(p, 0, n);
13232 - return p;
13233 - }
13234 - ssize_t r;
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;
13239 - if (!r) {
13240 - memset(q, 0, n);
13241 - break;
13242 - }
13243 - }
13244 - return p;
13245 -}
13246 -
13247 -static void unmap_library(struct dso *dso)
13248 -{
13249 - if (dso->loadmap) {
13250 - size_t i;
13251 - for (i=0; i<dso->loadmap->nsegs; i++) {
13252 - if (!dso->loadmap->segs[i].p_memsz)
13253 - continue;
13254 - munmap((void *)dso->loadmap->segs[i].addr,
13255 - dso->loadmap->segs[i].p_memsz);
13256 - }
13257 - free(dso->loadmap);
13258 - } else if (dso->map && dso->map_len) {
13259 - munmap(dso->map, dso->map_len);
13260 - }
13261 -}
13262 -
13263 -static void *map_library(int fd, struct dso *dso)
13264 -{
13265 - Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)];
13266 - void *allocated_buf=0;
13267 - size_t phsize;
13268 - size_t addr_min=SIZE_MAX, addr_max=0, map_len;
13269 - size_t this_min, this_max;
13270 - size_t nsegs = 0;
13271 - off_t off_start;
13272 - Ehdr *eh;
13273 - Phdr *ph, *ph0;
13274 - unsigned prot;
13275 - unsigned char *map=MAP_FAILED, *base;
13276 - size_t dyn=0;
13277 - size_t tls_image=0;
13278 - size_t i;
13279 -
13280 - ssize_t l = read(fd, buf, sizeof buf);
13281 - eh = buf;
13282 - if (l<0) return 0;
13283 - if (l<sizeof *eh || (eh->e_type != ET_DYN && eh->e_type != ET_EXEC))
13284 - goto noexec;
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);
13298 - } else {
13299 - ph = ph0 = (void *)((char *)buf + eh->e_phoff);
13300 - }
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;
13312 - }
13313 - if (ph->p_type != PT_LOAD) continue;
13314 - nsegs++;
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));
13321 - }
13322 - if (ph->p_vaddr+ph->p_memsz > addr_max) {
13323 - addr_max = ph->p_vaddr+ph->p_memsz;
13324 - }
13325 - }
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);
13342 - goto error;
13343 - }
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;
13348 - i++;
13349 - }
13350 - map = (void *)dso->loadmap->segs[0].addr;
13351 - map_len = 0;
13352 - goto done_mapping;
13353 - }
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;
13365 - dso->map = map;
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) {
13370 - errno = EBUSY;
13371 - goto error;
13372 - }
13373 - base = map - addr_min;
13374 - dso->phdr = 0;
13375 - dso->phnum = 0;
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;
13386 - }
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)
13396 - goto error;
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)
13402 - goto error;
13403 - }
13404 - }
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)
13409 - goto error;
13410 - break;
13411 - }
13412 -done_mapping:
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);
13418 - return map;
13419 -noexec:
13420 - errno = ENOEXEC;
13421 -error:
13422 - if (map!=MAP_FAILED) unmap_library(dso);
13423 - free(allocated_buf);
13424 - return 0;
13425 -}
13426 -
13427 -static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
13428 -{
13429 - size_t l;
13430 - int fd;
13431 - for (;;) {
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;
13437 - switch (errno) {
13438 - case ENOENT:
13439 - case ENOTDIR:
13440 - case EACCES:
13441 - case ENAMETOOLONG:
13442 - break;
13443 - default:
13444 - /* Any negative value but -1 will inhibit
13445 - * futher path search. */
13446 - return -2;
13447 - }
13448 - }
13449 - s += l;
13450 - }
13451 -}
13452 -
13453 -static int fixup_rpath(struct dso *p, char *buf, size_t buf_size)
13454 -{
13455 - size_t n, l;
13456 - const char *s, *t, *origin;
13457 - char *d;
13458 - if (p->rpath || !p->rpath_orig) return 0;
13459 - if (!strchr(p->rpath_orig, '$')) {
13460 - p->rpath = p->rpath_orig;
13461 - return 0;
13462 - }
13463 - n = 0;
13464 - s = p->rpath_orig;
13465 - while ((t=strchr(s, '$'))) {
13466 - if (strncmp(t, "$ORIGIN", 7) && strncmp(t, "${ORIGIN}", 9))
13467 - return 0;
13468 - s = t+1;
13469 - n++;
13470 - }
13471 - if (n > SSIZE_MAX/PATH_MAX) return 0;
13472 -
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). */
13480 - if (libc.secure)
13481 - return 0;
13482 - l = readlink("/proc/self/exe", buf, buf_size);
13483 - if (l == -1) switch (errno) {
13484 - case ENOENT:
13485 - case ENOTDIR:
13486 - case EACCES:
13487 - break;
13488 - default:
13489 - return -1;
13490 - }
13491 - if (l >= buf_size)
13492 - return 0;
13493 - buf[l] = 0;
13494 - origin = buf;
13495 - } else {
13496 - origin = p->name;
13497 - }
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;
13502 -
13503 - d = p->rpath;
13504 - s = p->rpath_orig;
13505 - while ((t=strchr(s, '$'))) {
13506 - memcpy(d, s, t-s);
13507 - d += t-s;
13508 - memcpy(d, origin, l);
13509 - d += l;
13510 - /* It was determined previously that the '$' is followed
13511 - * either by "ORIGIN" or "{ORIGIN}". */
13512 - s = t + 7 + 2*(t[1]=='{');
13513 - }
13514 - strcpy(d, s);
13515 - return 0;
13516 -}
13517 -
13518 -static void decode_dyn(struct dso *p)
13519 -{
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);
13536 -}
13537 -
13538 -static size_t count_syms(struct dso *p)
13539 -{
13540 - if (p->hashtab) return p->hashtab[1];
13541 -
13542 - size_t nsym, i;
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];
13548 - }
13549 - if (nsym) {
13550 - hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
13551 - do nsym++;
13552 - while (!(*hashval++ & 1));
13553 - }
13554 - return nsym;
13555 -}
13556 -
13557 -static void *dl_mmap(size_t n)
13558 -{
13559 - void *p;
13560 - int prot = PROT_READ|PROT_WRITE, flags = MAP_ANONYMOUS|MAP_PRIVATE;
13561 -#ifdef SYS_mmap2
13562 - p = (void *)__syscall(SYS_mmap2, 0, n, prot, flags, -1, 0);
13563 -#else
13564 - p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0);
13565 -#endif
13566 - return p == MAP_FAILED ? 0 : p;
13567 -}
13568 -
13569 -static void makefuncdescs(struct dso *p)
13570 -{
13571 - static int self_done;
13572 - size_t nsym = count_syms(p);
13573 - size_t i, size = nsym * sizeof(*p->funcdescs);
13574 -
13575 - if (!self_done) {
13576 - p->funcdescs = dl_mmap(size);
13577 - self_done = 1;
13578 - } else {
13579 - p->funcdescs = malloc(size);
13580 - }
13581 - if (!p->funcdescs) {
13582 - if (!runtime) a_crash();
13583 - error("Error allocating function descriptors for %s", p->name);
13584 - longjmp(*rtld_fail, 1);
13585 - }
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;
13590 - } else {
13591 - p->funcdescs[i].addr = 0;
13592 - p->funcdescs[i].got = 0;
13593 - }
13594 - }
13595 -}
13596 -
13597 -static struct dso *load_library(const char *name, struct dso *needed_by)
13598 -{
13599 - char buf[2*NAME_MAX+2];
13600 - const char *pathname;
13601 - unsigned char *map;
13602 - struct dso *p, temp_dso = {0};
13603 - int fd;
13604 - struct stat st;
13605 - size_t alloc_size;
13606 - int n_th = 0;
13607 - int is_self = 0;
13608 -
13609 - if (!*name) {
13610 - errno = EINVAL;
13611 - return 0;
13612 - }
13613 -
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, '.');
13619 - if (z) {
13620 - size_t l = z-name;
13621 - for (rp=reserved; *rp && strncmp(name+3, rp, l-3); rp+=strlen(rp)+1);
13622 - if (*rp) {
13623 - if (ldd_mode) {
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",
13631 - name, ldso.name,
13632 - ldso.base);
13633 - }
13634 - }
13635 - is_self = 1;
13636 - }
13637 - }
13638 - }
13639 - if (!strcmp(name, ldso.name)) is_self = 1;
13640 - if (is_self) {
13641 - if (!ldso.prev) {
13642 - tail->next = &ldso;
13643 - ldso.prev = tail;
13644 - tail = ldso.next ? ldso.next : &ldso;
13645 - }
13646 - return &ldso;
13647 - }
13648 - if (strchr(name, '/')) {
13649 - pathname = name;
13650 - fd = open(name, O_RDONLY|O_CLOEXEC);
13651 - } else {
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)) {
13655 - p->refcnt++;
13656 - return p;
13657 - }
13658 - }
13659 - if (strlen(name) > NAME_MAX) return 0;
13660 - fd = -1;
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. */
13665 - if (p->rpath)
13666 - fd = path_open(name, p->rpath, buf, sizeof buf);
13667 - }
13668 - if (fd == -1) {
13669 - if (!sys_path) {
13670 - char *prefix = 0;
13671 - size_t prefix_len;
13672 - if (ldso.name[0]=='/') {
13673 - char *s, *t, *z;
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;
13679 - }
13680 - if (!prefix) {
13681 - prefix = "";
13682 - prefix_len = 0;
13683 - }
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");
13690 - if (f) {
13691 - if (getdelim(&sys_path, (size_t[1]){0}, 0, f) <= 0) {
13692 - free(sys_path);
13693 - sys_path = "";
13694 - }
13695 - fclose(f);
13696 - } else if (errno != ENOENT) {
13697 - sys_path = "";
13698 - }
13699 - }
13700 - if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
13701 - fd = path_open(name, sys_path, buf, sizeof buf);
13702 - }
13703 - pathname = buf;
13704 - }
13705 - if (fd < 0) return 0;
13706 - if (fstat(fd, &st) < 0) {
13707 - close(fd);
13708 - return 0;
13709 - }
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;
13717 - close(fd);
13718 - p->refcnt++;
13719 - return p;
13720 - }
13721 - }
13722 - map = noload ? 0 : map_library(fd, &temp_dso);
13723 - close(fd);
13724 - if (!map) return 0;
13725 -
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;
13738 - }
13739 - p = calloc(1, alloc_size);
13740 - if (!p) {
13741 - unmap_library(&temp_dso);
13742 - return 0;
13743 - }
13744 - memcpy(p, &temp_dso, sizeof temp_dso);
13745 - decode_dyn(p);
13746 - p->dev = st.st_dev;
13747 - p->ino = st.st_ino;
13748 - p->refcnt = 1;
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;
13761 -#else
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;
13766 -#endif
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));
13770 - }
13771 -
13772 - tail->next = p;
13773 - p->prev = tail;
13774 - tail = p;
13775 -
13776 - if (DL_FDPIC) makefuncdescs(p);
13777 -
13778 - if (ldd_mode) dprintf(1, "\t%s => %s (%p)\n", name, pathname, p->base);
13779 -
13780 - return p;
13781 -}
13782 -
13783 -static void load_deps(struct dso *p)
13784 -{
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);
13791 - if (!dep) {
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);
13795 - continue;
13796 - }
13797 - if (runtime) {
13798 - tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2));
13799 - if (!tmp) longjmp(*rtld_fail, 1);
13800 - tmp[ndeps++] = dep;
13801 - tmp[ndeps] = 0;
13802 - *deps = tmp;
13803 - }
13804 - }
13805 - }
13806 -}
13807 -
13808 -static void load_preload(char *s)
13809 -{
13810 - int tmp;
13811 - char *z;
13812 - for (z=s; *z; s=z) {
13813 - for ( ; *s && (isspace(*s) || *s==':'); s++);
13814 - for (z=s; *z && !isspace(*z) && *z!=':'; z++);
13815 - tmp = *z;
13816 - *z = 0;
13817 - load_library(s, 0);
13818 - *z = tmp;
13819 - }
13820 -}
13821 -
13822 -static void make_global(struct dso *p)
13823 -{
13824 - for (; p; p=p->next) p->global = 1;
13825 -}
13826 -
13827 -static void do_mips_relocs(struct dso *p, size_t *got)
13828 -{
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);
13832 - if (p==&ldso) {
13833 - got += i;
13834 - } else {
13835 - while (i--) *got++ += (size_t)base;
13836 - }
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);
13844 - }
13845 -}
13846 -
13847 -static void reloc_all(struct dso *p)
13848 -{
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);
13859 -
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",
13864 - p->name);
13865 - if (runtime) longjmp(*rtld_fail, 1);
13866 - }
13867 -
13868 - p->relocated = 1;
13869 - }
13870 -}
13871 -
13872 -static void kernel_mapped_dso(struct dso *p)
13873 -{
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;
13882 - }
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;
13888 - }
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;
13894 -}
13895 -
13896 -static void do_fini()
13897 -{
13898 - struct dso *p;
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)();
13907 - }
13908 -#ifndef NO_LEGACY_INITFINI
13909 - if ((dyn[0] & (1<<DT_FINI)) && dyn[DT_FINI])
13910 - fpaddr(p, dyn[DT_FINI])();
13911 -#endif
13912 - }
13913 -}
13914 -
13915 -static void do_init_fini(struct dso *p)
13916 -{
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;
13929 - fini_head = p;
13930 - }
13931 -#ifndef NO_LEGACY_INITFINI
13932 - if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
13933 - fpaddr(p, dyn[DT_INIT])();
13934 -#endif
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++)();
13939 - }
13940 - if (!need_locking && libc.threads_minus_1) {
13941 - need_locking = 1;
13942 - pthread_mutex_lock(&init_fini_lock);
13943 - }
13944 - }
13945 - if (need_locking) pthread_mutex_unlock(&init_fini_lock);
13946 -}
13947 -
13948 -void __libc_start_init(void)
13949 -{
13950 - do_init_fini(tail);
13951 -}
13952 -
13953 -static void dl_debug_state(void)
13954 -{
13955 -}
13956 -
13957 -weak_alias(dl_debug_state, _dl_debug_state);
13958 -
13959 -void __reset_tls()
13960 -{
13961 - pthread_t self = __pthread_self();
13962 - struct dso *p;
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;
13969 - }
13970 -}
13971 -
13972 -void *__copy_tls(unsigned char *mem)
13973 -{
13974 - pthread_t td;
13975 - struct dso *p;
13976 - void **dtv;
13977 -
13978 -#ifdef TLS_ABOVE_TP
13979 - dtv = (void **)(mem + libc.tls_size) - (tls_cnt + 1);
13980 -
13981 - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (tls_align-1);
13982 - td = (pthread_t)mem;
13983 - mem += sizeof(struct pthread);
13984 -
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);
13989 - }
13990 -#else
13991 - dtv = (void **)mem;
13992 -
13993 - mem += libc.tls_size - sizeof(struct pthread);
13994 - mem -= (uintptr_t)mem & (tls_align-1);
13995 - td = (pthread_t)mem;
13996 -
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);
14001 - }
14002 -#endif
14003 - dtv[0] = (void *)tls_cnt;
14004 - td->dtv = td->dtv_copy = dtv;
14005 - return td;
14006 -}
14007 -
14008 -__attribute__((__visibility__("hidden")))
14009 -void *__tls_get_new(size_t *v)
14010 -{
14011 - pthread_t self = __pthread_self();
14012 -
14013 - /* Block signals to make accessing new TLS async-signal-safe */
14014 - sigset_t set;
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;
14019 - }
14020 -
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. */
14025 - struct dso *p;
14026 - for (p=head; p->tls_id != v[0]; p=p->next);
14027 -
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;
14036 - }
14037 -
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;
14049 - }
14050 - __restore_sigs(&set);
14051 - return mem + v[1] + DTP_OFFSET;
14052 -}
14053 -
14054 -static void update_tls_size()
14055 -{
14056 - libc.tls_size = ALIGN(
14057 - (1+tls_cnt) * sizeof(void *) +
14058 - tls_offset +
14059 - sizeof(struct pthread) +
14060 - tls_align * 2,
14061 - tls_align);
14062 -}
14063 -
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. */
14067 -
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. */
14074 -
14075 -__attribute__((__visibility__("hidden")))
14076 -void __dls2(unsigned char *base, size_t *sp)
14077 -{
14078 - if (DL_FDPIC) {
14079 - void *p1 = (void *)sp[-2];
14080 - void *p2 = (void *)sp[-1];
14081 - if (!p1) {
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);
14087 - }
14088 - app_loadmap = p2 ? p1 : 0;
14089 - ldso.loadmap = p2 ? p2 : p1;
14090 - ldso.base = laddr(&ldso, 0);
14091 - } else {
14092 - ldso.base = base;
14093 - }
14094 - Ehdr *ehdr = (void *)ldso.base;
14095 - ldso.name = ldso.shortname = "libc.so";
14096 - ldso.global = 1;
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);
14102 -
14103 - if (DL_FDPIC) makefuncdescs(&ldso);
14104 -
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;
14120 -
14121 - head = &ldso;
14122 - reloc_all(&ldso);
14123 -
14124 - ldso.relocated = 0;
14125 -
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);
14132 -}
14133 -
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. */
14138 -
14139 -_Noreturn void __dls3(size_t *sp)
14140 -{
14141 - static struct dso app, vdso;
14142 - size_t aux[AUX_CNT], *auxv;
14143 - size_t i;
14144 - char *env_preload=0;
14145 - size_t vdso_base;
14146 - int argc = *sp;
14147 - char **argv = (void *)(sp+1);
14148 - char **argv_orig = argv;
14149 - char **envp = argv+argc+1;
14150 -
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]);
14161 -
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) {
14167 - a_crash();
14168 - }
14169 -
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");
14174 - }
14175 -
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;
14196 - }
14197 - }
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];
14204 - else
14205 - app.name = argv[0];
14206 - kernel_mapped_dso(&app);
14207 - } else {
14208 - int fd;
14209 - char *ldname = argv[0];
14210 - size_t l = strlen(ldname);
14211 - if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
14212 - argv++;
14213 - while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
14214 - char *opt = argv[0]+2;
14215 - *argv++ = (void *)-1;
14216 - if (!*opt) {
14217 - break;
14218 - } else if (!memcmp(opt, "list", 5)) {
14219 - ldd_mode = 1;
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++;
14228 - } else {
14229 - argv[0] = 0;
14230 - }
14231 - }
14232 - argv[-1] = (void *)(argc - (argv-argv_orig));
14233 - if (!argv[0]) {
14234 - dprintf(2, "musl libc\n"
14235 - "Version %s\n"
14236 - "Dynamic Program Loader\n"
14237 - "Usage: %s [options] [--] pathname%s\n",
14238 - __libc_get_version(), ldname,
14239 - ldd_mode ? "" : " [args]");
14240 - _exit(1);
14241 - }
14242 - fd = open(argv[0], O_RDONLY);
14243 - if (fd < 0) {
14244 - dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
14245 - _exit(1);
14246 - }
14247 - runtime = 1;
14248 - Ehdr *ehdr = (void *)map_library(fd, &app);
14249 - if (!ehdr) {
14250 - dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
14251 - _exit(1);
14252 - }
14253 - runtime = 0;
14254 - close(fd);
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. */
14260 - if (ldd_mode) {
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);
14264 - }
14265 - dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
14266 - }
14267 - }
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) );
14275 -#else
14276 - tls_offset = app.tls_offset = app.tls_size
14277 - + ( -((uintptr_t)app.tls_image + app.tls_size)
14278 - & (app.tls_align-1) );
14279 -#endif
14280 - tls_align = MAXP2(tls_align, app.tls_align);
14281 - }
14282 - app.global = 1;
14283 - decode_dyn(&app);
14284 - if (DL_FDPIC) {
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;
14293 - }
14294 - argv[-3] = (void *)app.loadmap;
14295 - }
14296 -
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);
14308 - }
14309 - vdso.name = "";
14310 - vdso.shortname = "linux-gate.so.1";
14311 - vdso.global = 1;
14312 - vdso.relocated = 1;
14313 - decode_dyn(&vdso);
14314 - vdso.prev = &ldso;
14315 - ldso.next = &vdso;
14316 - }
14317 -
14318 - /* Initial dso chain consists only of the app. */
14319 - head = tail = &app;
14320 -
14321 - /* Donate unused parts of app and library mapping to malloc */
14322 - reclaim_gaps(&app);
14323 - reclaim_gaps(&ldso);
14324 -
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);
14328 - load_deps(&app);
14329 - make_global(&app);
14330 -
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;
14335 -#endif
14336 -
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);
14340 - reloc_all(&app);
14341 -
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);
14348 - _exit(127);
14349 - }
14350 - if (__init_tp(__copy_tls(initial_tls)) < 0) {
14351 - a_crash();
14352 - }
14353 - } else {
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;
14362 - }
14363 - static_tls_cnt = tls_cnt;
14364 -
14365 - if (ldso_fail) _exit(127);
14366 - if (ldd_mode) _exit(0);
14367 -
14368 - /* Switch to runtime mode: any further failures in the dynamic
14369 - * linker are a reportable failure rather than a fatal startup
14370 - * error. */
14371 - runtime = 1;
14372 -
14373 - debug.ver = 1;
14374 - debug.bp = dl_debug_state;
14375 - debug.head = head;
14376 - debug.base = ldso.base;
14377 - debug.state = 0;
14378 - _dl_debug_state();
14379 -
14380 - __init_libc(envp, argv[0]);
14381 - atexit(do_fini);
14382 - errno = 0;
14383 -
14384 - CRTJMP((void *)aux[AT_ENTRY], argv-1);
14385 - for(;;);
14386 -}
14387 -
14388 -void *dlopen(const char *file, int mode)
14389 -{
14390 - struct dso *volatile p, *orig_tail, *next;
14391 - size_t orig_tls_cnt, orig_tls_offset, orig_tls_align;
14392 - size_t i;
14393 - int cs;
14394 - jmp_buf jb;
14395 -
14396 - if (!file) return head;
14397 -
14398 - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
14399 - pthread_rwlock_wrlock(&lock);
14400 - __inhibit_ptc();
14401 -
14402 - p = 0;
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;
14408 -
14409 - rtld_fail = &jb;
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) {
14416 - next = p->next;
14417 - while (p->td_index) {
14418 - void *tmp = p->td_index->next;
14419 - free(p->td_index);
14420 - p->td_index = tmp;
14421 - }
14422 - free(p->funcdescs);
14423 - if (p->rpath != p->rpath_orig)
14424 - free(p->rpath);
14425 - free(p->deps);
14426 - unmap_library(p);
14427 - free(p);
14428 - }
14429 - tls_cnt = orig_tls_cnt;
14430 - tls_offset = orig_tls_offset;
14431 - tls_align = orig_tls_align;
14432 - tail = orig_tail;
14433 - tail->next = 0;
14434 - p = 0;
14435 - goto end;
14436 - } else p = load_library(file, head);
14437 -
14438 - if (!p) {
14439 - error(noload ?
14440 - "Library %s is not already loaded" :
14441 - "Error loading shared library %s: %m",
14442 - file);
14443 - goto end;
14444 - }
14445 -
14446 - /* First load handling */
14447 - if (!p->deps) {
14448 - load_deps(p);
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;
14453 - reloc_all(p);
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;
14458 - }
14459 -
14460 - if (mode & RTLD_GLOBAL) {
14461 - if (p->deps) for (i=0; p->deps[i]; i++)
14462 - p->deps[i]->global = 1;
14463 - p->global = 1;
14464 - }
14465 -
14466 - update_tls_size();
14467 - _dl_debug_state();
14468 - orig_tail = tail;
14469 -end:
14470 - __release_ptc();
14471 - if (p) gencnt++;
14472 - pthread_rwlock_unlock(&lock);
14473 - if (p) do_init_fini(orig_tail);
14474 - pthread_setcancelstate(cs, 0);
14475 - return p;
14476 -}
14477 -
14478 -static int invalid_dso_handle(void *h)
14479 -{
14480 - struct dso *p;
14481 - for (p=head; p; p=p->next) if (h==p) return 0;
14482 - error("Invalid library handle %p", (void *)h);
14483 - return 1;
14484 -}
14485 -
14486 -static void *addr2dso(size_t a)
14487 -{
14488 - struct dso *p;
14489 - size_t i;
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))
14493 - return p;
14494 - }
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)
14500 - return p;
14501 - }
14502 - } else {
14503 - if (a-(size_t)p->map < p->map_len)
14504 - return p;
14505 - }
14506 - }
14507 - return 0;
14508 -}
14509 -
14510 -void *__tls_get_addr(size_t *);
14511 -
14512 -static void *do_dlsym(struct dso *p, const char *s, void *ra)
14513 -{
14514 - size_t i;
14515 - uint32_t h = 0, gh = 0, *ght;
14516 - Sym *sym;
14517 - if (p == head || p == RTLD_DEFAULT || p == RTLD_NEXT) {
14518 - if (p == RTLD_DEFAULT) {
14519 - p = head;
14520 - } else if (p == RTLD_NEXT) {
14521 - p = addr2dso((size_t)ra);
14522 - if (!p) p=head;
14523 - p = p->next;
14524 - }
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);
14532 - }
14533 - if (invalid_dso_handle(p))
14534 - return 0;
14535 - if ((ght = p->ghashtab)) {
14536 - gh = gnu_hash(s);
14537 - sym = gnu_lookup(gh, ght, p, s);
14538 - } else {
14539 - h = sysv_hash(s);
14540 - sym = sysv_lookup(s, h, p);
14541 - }
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);
14552 - } else {
14553 - if (!h) h = sysv_hash(s);
14554 - sym = sysv_lookup(s, h, p->deps[i]);
14555 - }
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);
14562 - }
14563 -failed:
14564 - error("Symbol not found: %s", s);
14565 - return 0;
14566 -}
14567 -
14568 -int __dladdr(const void *addr, Dl_info *info)
14569 -{
14570 - struct dso *p;
14571 - Sym *sym, *bestsym;
14572 - uint32_t nsym;
14573 - char *strings;
14574 - void *best = 0;
14575 -
14576 - pthread_rwlock_rdlock(&lock);
14577 - p = addr2dso((size_t)addr);
14578 - pthread_rwlock_unlock(&lock);
14579 -
14580 - if (!p) return 0;
14581 -
14582 - sym = p->syms;
14583 - strings = p->strings;
14584 - nsym = count_syms(p);
14585 -
14586 - if (DL_FDPIC) {
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;
14592 - }
14593 - }
14594 -
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)
14601 - continue;
14602 - best = symaddr;
14603 - bestsym = sym;
14604 - if (addr == symaddr)
14605 - break;
14606 - }
14607 - }
14608 -
14609 - if (!best) return 0;
14610 -
14611 - if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC)
14612 - best = p->funcdescs + (bestsym - p->syms);
14613 -
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;
14618 -
14619 - return 1;
14620 -}
14621 -
14622 -__attribute__((__visibility__("hidden")))
14623 -void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
14624 -{
14625 - void *res;
14626 - pthread_rwlock_rdlock(&lock);
14627 - res = do_dlsym(p, s, ra);
14628 - pthread_rwlock_unlock(&lock);
14629 - return res;
14630 -}
14631 -
14632 -int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
14633 -{
14634 - struct dso *current;
14635 - struct dl_phdr_info info;
14636 - int ret = 0;
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;
14646 -
14647 - ret = (callback)(&info, sizeof (info), data);
14648 -
14649 - if (ret != 0) break;
14650 -
14651 - pthread_rwlock_rdlock(&lock);
14652 - current = current->next;
14653 - pthread_rwlock_unlock(&lock);
14654 - }
14655 - return ret;
14656 -}
14657 -#else
14658 -static int invalid_dso_handle(void *h)
14659 -{
14660 - error("Invalid library handle %p", (void *)h);
14661 - return 1;
14662 -}
14663 -void *dlopen(const char *file, int mode)
14664 -{
14665 - error("Dynamic loading not supported");
14666 - return 0;
14667 -}
14668 -void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
14669 -{
14670 - error("Symbol not found: %s", s);
14671 - return 0;
14672 -}
14673 -int __dladdr (const void *addr, Dl_info *info)
14674 -{
14675 - return 0;
14676 -}
14677 -#endif
14678 -
14679 -int __dlinfo(void *dso, int req, void *res)
14680 -{
14681 - if (invalid_dso_handle(dso)) return -1;
14682 - if (req != RTLD_DI_LINKMAP) {
14683 - error("Unsupported request %d", req);
14684 - return -1;
14685 - }
14686 - *(struct link_map **)res = dso;
14687 - return 0;
14688 -}
14689 -
14690 -char *dlerror()
14691 -{
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";
14698 - else
14699 - return s;
14700 -}
14701 -
14702 -int dlclose(void *p)
14703 -{
14704 - return invalid_dso_handle(p);
14705 -}
14706 -
14707 -void __dl_thread_cleanup(void)
14708 -{
14709 - pthread_t self = __pthread_self();
14710 - if (self->dlerror_buf != (void *)-1)
14711 - free(self->dlerror_buf);
14712 -}
14713 -
14714 -static void error(const char *fmt, ...)
14715 -{
14716 - va_list ap;
14717 - va_start(ap, fmt);
14718 -#ifdef SHARED
14719 - if (!runtime) {
14720 - vdprintf(2, fmt, ap);
14721 - dprintf(2, "\n");
14722 - ldso_fail = 1;
14723 - va_end(ap);
14724 - return;
14725 - }
14726 -#endif
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);
14731 - va_end(ap);
14732 - char *buf = malloc(len+1);
14733 - if (buf) {
14734 - va_start(ap, fmt);
14735 - vsnprintf(buf, len+1, fmt, ap);
14736 - va_end(ap);
14737 - } else {
14738 - buf = (void *)-1;
14739 - }
14740 - self->dlerror_buf = buf;
14741 - self->dlerror_flag = 1;
14742 -}
14743 --- a/src/ldso/tlsdesc.c
14744 +++ b/src/ldso/tlsdesc.c
14745 @@ -1,5 +1,3 @@
14746 -#ifdef SHARED
14747 -
14748 #include <stddef.h>
14749 #include "libc.h"
14750
14751 @@ -12,5 +10,3 @@ ptrdiff_t __tlsdesc_static()
14752 }
14753
14754 weak_alias(__tlsdesc_static, __tlsdesc_dynamic);
14755 -
14756 -#endif
14757 --- a/src/legacy/utmpx.c
14758 +++ b/src/legacy/utmpx.c
14759 @@ -1,5 +1,6 @@
14760 #include <utmpx.h>
14761 #include <stddef.h>
14762 +#include <errno.h>
14763 #include "libc.h"
14764
14765 void endutxent(void)
14766 @@ -34,6 +35,12 @@ void updwtmpx(const char *f, const struc
14767 {
14768 }
14769
14770 +int __utmpxname(const char *f)
14771 +{
14772 + errno = ENOTSUP;
14773 + return -1;
14774 +}
14775 +
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);
14785 --- /dev/null
14786 +++ b/src/linux/x32/sysinfo.c
14787 @@ -0,0 +1,50 @@
14788 +#include <sys/sysinfo.h>
14789 +#include "syscall.h"
14790 +#include "libc.h"
14791 +
14792 +#define klong long long
14793 +#define kulong unsigned long long
14794 +
14795 +struct kernel_sysinfo {
14796 + klong uptime;
14797 + kulong loads[3];
14798 + kulong totalram;
14799 + kulong freeram;
14800 + kulong sharedram;
14801 + kulong bufferram;
14802 + kulong totalswap;
14803 + kulong freeswap;
14804 + short procs;
14805 + short pad;
14806 + kulong totalhigh;
14807 + kulong freehigh;
14808 + unsigned mem_unit;
14809 +};
14810 +
14811 +int __lsysinfo(struct sysinfo *info)
14812 +{
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];
14820 + kulong shifts;
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;
14834 + return ret;
14835 +}
14836 +
14837 +weak_alias(__lsysinfo, sysinfo);
14838 --- a/src/linux/x32/sysinfo.s
14839 +++ /dev/null
14840 @@ -1 +0,0 @@
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
14845
14846 switch (cat) {
14847 case LC_NUMERIC:
14848 - if (idx > 1) return NULL;
14849 + if (idx > 1) return "";
14850 str = c_numeric;
14851 break;
14852 case LC_TIME:
14853 - if (idx > 0x31) return NULL;
14854 + if (idx > 0x31) return "";
14855 str = c_time;
14856 break;
14857 case LC_MONETARY:
14858 - if (idx > 0) return NULL;
14859 + if (idx > 0) return "";
14860 str = "";
14861 break;
14862 case LC_MESSAGES:
14863 - if (idx > 3) return NULL;
14864 + if (idx > 3) return "";
14865 str = c_messages;
14866 break;
14867 default:
14868 - return NULL;
14869 + return "";
14870 }
14871
14872 for (; idx; idx--, str++) for (; *str; str++);
14873 --- a/src/malloc/lite_malloc.c
14874 +++ b/src/malloc/lite_malloc.c
14875 @@ -8,7 +8,7 @@
14876
14877 void *__expand_heap(size_t *);
14878
14879 -void *__simple_malloc(size_t n)
14880 +static void *__simple_malloc(size_t n)
14881 {
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 */
14888 medium:
14889 /* rint(x/(pi/2)), Assume round-to-nearest. */
14890 - fn = x*invpio2 + toint - toint;
14891 + fn = (double_t)x*invpio2 + toint - toint;
14892 n = (int32_t)fn;
14893 r = x - fn*pio2_1;
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;
14903 n = (int32_t)fn;
14904 *y = x - fn*pio2_1 - fn*pio2_1t;
14905 return n;
14906 --- /dev/null
14907 +++ b/src/math/arm/fabs.c
14908 @@ -0,0 +1,15 @@
14909 +#include <math.h>
14910 +
14911 +#if __ARM_PCS_VFP
14912 +
14913 +double fabs(double x)
14914 +{
14915 + __asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x));
14916 + return x;
14917 +}
14918 +
14919 +#else
14920 +
14921 +#include "../fabs.c"
14922 +
14923 +#endif
14924 --- /dev/null
14925 +++ b/src/math/arm/fabsf.c
14926 @@ -0,0 +1,15 @@
14927 +#include <math.h>
14928 +
14929 +#if __ARM_PCS_VFP
14930 +
14931 +float fabsf(float x)
14932 +{
14933 + __asm__ ("vabs.f32 %0, %1" : "=t"(x) : "t"(x));
14934 + return x;
14935 +}
14936 +
14937 +#else
14938 +
14939 +#include "../fabsf.c"
14940 +
14941 +#endif
14942 --- /dev/null
14943 +++ b/src/math/arm/sqrt.c
14944 @@ -0,0 +1,15 @@
14945 +#include <math.h>
14946 +
14947 +#if __VFP_FP__ && !__SOFTFP__
14948 +
14949 +double sqrt(double x)
14950 +{
14951 + __asm__ ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x));
14952 + return x;
14953 +}
14954 +
14955 +#else
14956 +
14957 +#include "../sqrt.c"
14958 +
14959 +#endif
14960 --- /dev/null
14961 +++ b/src/math/arm/sqrtf.c
14962 @@ -0,0 +1,15 @@
14963 +#include <math.h>
14964 +
14965 +#if __VFP_FP__ && !__SOFTFP__
14966 +
14967 +float sqrtf(float x)
14968 +{
14969 + __asm__ ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x));
14970 + return x;
14971 +}
14972 +
14973 +#else
14974 +
14975 +#include "../sqrtf.c"
14976 +
14977 +#endif
14978 --- a/src/math/armebhf/fabs.sub
14979 +++ /dev/null
14980 @@ -1 +0,0 @@
14981 -../armhf/fabs.s
14982 --- a/src/math/armebhf/fabsf.sub
14983 +++ /dev/null
14984 @@ -1 +0,0 @@
14985 -../armhf/fabsf.s
14986 --- a/src/math/armebhf/sqrt.sub
14987 +++ /dev/null
14988 @@ -1 +0,0 @@
14989 -../armhf/sqrt.s
14990 --- a/src/math/armebhf/sqrtf.sub
14991 +++ /dev/null
14992 @@ -1 +0,0 @@
14993 -../armhf/sqrtf.s
14994 --- a/src/math/armhf/fabs.s
14995 +++ /dev/null
14996 @@ -1,7 +0,0 @@
14997 -.fpu vfp
14998 -.text
14999 -.global fabs
15000 -.type fabs,%function
15001 -fabs:
15002 - vabs.f64 d0, d0
15003 - bx lr
15004 --- a/src/math/armhf/fabs.sub
15005 +++ /dev/null
15006 @@ -1 +0,0 @@
15007 -fabs.s
15008 --- a/src/math/armhf/fabsf.s
15009 +++ /dev/null
15010 @@ -1,7 +0,0 @@
15011 -.fpu vfp
15012 -.text
15013 -.global fabsf
15014 -.type fabsf,%function
15015 -fabsf:
15016 - vabs.f32 s0, s0
15017 - bx lr
15018 --- a/src/math/armhf/fabsf.sub
15019 +++ /dev/null
15020 @@ -1 +0,0 @@
15021 -fabsf.s
15022 --- a/src/math/armhf/sqrt.s
15023 +++ /dev/null
15024 @@ -1,7 +0,0 @@
15025 -.fpu vfp
15026 -.text
15027 -.global sqrt
15028 -.type sqrt,%function
15029 -sqrt:
15030 - vsqrt.f64 d0, d0
15031 - bx lr
15032 --- a/src/math/armhf/sqrt.sub
15033 +++ /dev/null
15034 @@ -1 +0,0 @@
15035 -sqrt.s
15036 --- a/src/math/armhf/sqrtf.s
15037 +++ /dev/null
15038 @@ -1,7 +0,0 @@
15039 -.fpu vfp
15040 -.text
15041 -.global sqrtf
15042 -.type sqrtf,%function
15043 -sqrtf:
15044 - vsqrt.f32 s0, s0
15045 - bx lr
15046 --- a/src/math/armhf/sqrtf.sub
15047 +++ /dev/null
15048 @@ -1 +0,0 @@
15049 -sqrtf.s
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
15053 {
15054 double_t xh, xl, xc;
15055
15056 - xc = x*SPLIT;
15057 + xc = (double_t)x*SPLIT;
15058 xh = x - xc + xc;
15059 xl = x - xh;
15060 - *hi = x*x;
15061 + *hi = (double_t)x*x;
15062 *lo = xh*xh - *hi + 2*xh*xl + xl*xl;
15063 }
15064
15065 --- a/src/mman/mremap.c
15066 +++ b/src/mman/mremap.c
15067 @@ -1,17 +1,31 @@
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"
15075 #include "libc.h"
15076
15077 +static void dummy(void) { }
15078 +weak_alias(dummy, __vm_wait);
15079 +
15080 void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
15081 {
15082 va_list ap;
15083 - void *new_addr;
15084 -
15085 - va_start(ap, flags);
15086 - new_addr = va_arg(ap, void *);
15087 - va_end(ap);
15088 + void *new_addr = 0;
15089 +
15090 + if (new_len >= PTRDIFF_MAX) {
15091 + errno = ENOMEM;
15092 + return MAP_FAILED;
15093 + }
15094 +
15095 + if (flags & MREMAP_FIXED) {
15096 + __vm_wait();
15097 + va_start(ap, flags);
15098 + new_addr = va_arg(ap, void *);
15099 + va_end(ap);
15100 + }
15101
15102 return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
15103 }
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) {
15109 case IFA_ADDRESS:
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);
15115 + else
15116 + copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15117 break;
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);
15122 break;
15123 + case IFA_LOCAL:
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));
15130 + }
15131 + copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index);
15132 + break;
15133 case IFA_LABEL:
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
15139 switch (af) {
15140 case AF_INET:
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;
15144 mkptr4(ptr, a);
15145 scopeid = 0;
15146 break;
15147 case AF_INET6:
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))
15152 mkptr6(ptr, a);
15153 else
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
15157 struct ifreq ifr;
15158 int fd, r;
15159
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
15167 @@ -2,6 +2,7 @@
15168 #define LOOKUP_H
15169
15170 #include <stdint.h>
15171 +#include <stddef.h>
15172
15173 struct address {
15174 int family;
15175 @@ -15,6 +16,14 @@ struct service {
15176 unsigned char proto, socktype;
15177 };
15178
15179 +#define MAXNS 3
15180 +
15181 +struct resolvconf {
15182 + struct address ns[MAXNS];
15183 + unsigned nns, attempts, ndots;
15184 + unsigned timeout;
15185 +};
15186 +
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);
15193
15194 +int __get_resolv_conf(struct resolvconf *, char *, size_t);
15195 +
15196 #endif
15197 --- a/src/network/lookup_name.c
15198 +++ b/src/network/lookup_name.c
15199 @@ -9,6 +9,7 @@
15200 #include <fcntl.h>
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
15208 int cnt = 0;
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) {
15213 + case ENOENT:
15214 + case ENOTDIR:
15215 + case EACCES:
15216 + return 0;
15217 + default:
15218 + return EAI_SYSTEM;
15219 + }
15220 while (fgets(line, sizeof line, f) && cnt < MAXADDRS) {
15221 char *p, *z;
15222
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 *);
15229
15230 #define RR_A 1
15231 #define RR_CNAME 5
15232 @@ -117,7 +125,7 @@ static int dns_parse_callback(void *c, i
15233 return 0;
15234 }
15235
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)
15238 {
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
15242 nq++;
15243 }
15244
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;
15248
15249 for (i=0; i<nq; i++)
15250 __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
15251
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;
15257 return EAI_FAIL;
15258 }
15259
15260 +static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
15261 +{
15262 + char search[256];
15263 + struct resolvconf conf;
15264 + size_t l, dots;
15265 + char *p, *z;
15266 +
15267 + if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1;
15268 +
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;
15273 +
15274 + /* This can never happen; the caller already checked length. */
15275 + if (l >= 256) return EAI_NONAME;
15276 +
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);
15282 + canon[l] = '.';
15283 +
15284 + for (p=search; *p; p=z) {
15285 + for (; isspace(*p); p++);
15286 + for (z=p; *z && !isspace(*z); z++);
15287 + if (z==p) break;
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;
15293 + }
15294 + }
15295 +
15296 + canon[l] = 0;
15297 + return name_from_dns(buf, canon, name, family, &conf);
15298 +}
15299 +
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);
15309 }
15310 if (cnt<=0) return cnt ? cnt : EAI_NONAME;
15311
15312 --- a/src/network/lookup_serv.c
15313 +++ b/src/network/lookup_serv.c
15314 @@ -4,6 +4,7 @@
15315 #include <ctype.h>
15316 #include <string.h>
15317 #include <fcntl.h>
15318 +#include <errno.h>
15319 #include "lookup.h"
15320 #include "stdio_impl.h"
15321
15322 @@ -69,7 +70,14 @@ int __lookup_serv(struct service buf[sta
15323
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) {
15328 + case ENOENT:
15329 + case ENOTDIR:
15330 + case EACCES:
15331 + return EAI_SERVICE;
15332 + default:
15333 + return EAI_SYSTEM;
15334 + }
15335
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[] = {
15341 "\001icmp\0"
15342 "\002igmp\0"
15343 "\003ggp\0"
15344 + "\004ipencap\0"
15345 + "\005st\0"
15346 "\006tcp\0"
15347 + "\008egp\0"
15348 "\014pup\0"
15349 "\021udp\0"
15350 - "\026idp\0"
15351 + "\024hmp\0"
15352 + "\026xns-idp\0"
15353 + "\033rdp\0"
15354 + "\035iso-tp4\0"
15355 + "\044xtp\0"
15356 + "\045ddp\0"
15357 + "\046idpr-cmtp\0"
15358 "\051ipv6\0"
15359 "\053ipv6-route\0"
15360 "\054ipv6-frag\0"
15361 + "\055idrp\0"
15362 + "\056rsvp\0"
15363 "\057gre\0"
15364 "\062esp\0"
15365 "\063ah\0"
15366 + "\071skip\0"
15367 "\072ipv6-icmp\0"
15368 "\073ipv6-nonxt\0"
15369 "\074ipv6-opts\0"
15370 + "\111rspf\0"
15371 + "\121vmtp\0"
15372 "\131ospf\0"
15373 "\136ipip\0"
15374 + "\142encap\0"
15375 "\147pim\0"
15376 "\377raw"
15377 };
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;
15382 }
15383
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)
15389 {
15390 int fd;
15391 - FILE *f, _f;
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;
15396 union {
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;
15402 int nns = 0;
15403 int family = AF_INET;
15404 @@ -48,57 +46,27 @@ int __res_msend(int nqueries, const unsi
15405 int cs;
15406 struct pollfd pfd;
15407 unsigned long t0, t1, t2;
15408 - struct address iplit;
15409
15410 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
15411
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])) {
15416 - unsigned long x;
15417 - char *p, *z;
15418 - p = strstr(line, "timeout:");
15419 - if (p && isdigit(p[8])) {
15420 - p += 8;
15421 - x = strtoul(p, &z, 10);
15422 - if (z != p) timeout = x < 30 ? x*1000 : 30000;
15423 - }
15424 - p = strstr(line, "attempts:");
15425 - if (p && isdigit(p[9])) {
15426 - p += 9;
15427 - x = strtoul(p, &z, 10);
15428 - if (z != p) attempts = x < 10 ? x : 10;
15429 - if (!attempts) attempts = 1;
15430 - }
15431 - }
15432 - if (strncmp(line, "nameserver", 10) || !isspace(line[10]))
15433 - continue;
15434 - for (s=line+11; isspace(*s); s++);
15435 - for (z=s; *z && !isspace(*z); z++);
15436 - *z=0;
15437 + timeout = 1000*conf->timeout;
15438 + attempts = conf->attempts;
15439
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;
15445 - } else {
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;
15451 - }
15452 + nns = conf->nns;
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;
15459 + } else {
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;
15465 }
15466 }
15467 - if (f) __fclose_ca(f);
15468 - if (!nns) {
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);
15472 - nns=1;
15473 - }
15474
15475 /* Get local address and open/bind a socket */
15476 sa.sin.sin_family = family;
15477 @@ -207,3 +175,11 @@ out:
15478
15479 return 0;
15480 }
15481 +
15482 +int __res_msend(int nqueries, const unsigned char *const *queries,
15483 + const int *qlens, unsigned char *const *answers, int *alens, int asize)
15484 +{
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);
15488 +}
15489 --- /dev/null
15490 +++ b/src/network/resolvconf.c
15491 @@ -0,0 +1,93 @@
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>
15498 +
15499 +int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
15500 +{
15501 + char line[256];
15502 + unsigned char _buf[256];
15503 + FILE *f, _f;
15504 + int nns = 0;
15505 +
15506 + conf->ndots = 1;
15507 + conf->timeout = 5;
15508 + conf->attempts = 2;
15509 + if (search) *search = 0;
15510 +
15511 + f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
15512 + if (!f) switch (errno) {
15513 + case ENOENT:
15514 + case ENOTDIR:
15515 + case EACCES:
15516 + goto no_resolv_conf;
15517 + default:
15518 + return -1;
15519 + }
15520 +
15521 + while (fgets(line, sizeof line, f)) {
15522 + char *p, *z;
15523 + if (!strchr(line, '\n') && !feof(f)) {
15524 + /* Ignore lines that get truncated rather than
15525 + * potentially misinterpreting them. */
15526 + int c;
15527 + do c = getc(f);
15528 + while (c != '\n' && c != EOF);
15529 + continue;
15530 + }
15531 + if (!strncmp(line, "options", 7) && isspace(line[7])) {
15532 + p = strstr(line, "ndots:");
15533 + if (p && isdigit(p[6])) {
15534 + p += 6;
15535 + unsigned long x = strtoul(p, &z, 10);
15536 + if (z != p) conf->ndots = x > 15 ? 15 : x;
15537 + }
15538 + p = strstr(line, "attempts:");
15539 + if (p && isdigit(p[6])) {
15540 + p += 6;
15541 + unsigned long x = strtoul(p, &z, 10);
15542 + if (z != p) conf->attempts = x > 10 ? 10 : x;
15543 + }
15544 + p = strstr(line, "timeout:");
15545 + if (p && (isdigit(p[8]) || p[8]=='.')) {
15546 + p += 8;
15547 + unsigned long x = strtoul(p, &z, 10);
15548 + if (z != p) conf->timeout = x > 60 ? 60 : x;
15549 + }
15550 + continue;
15551 + }
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++);
15556 + *z=0;
15557 + if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
15558 + nns++;
15559 + continue;
15560 + }
15561 +
15562 + if (!search) continue;
15563 + if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
15564 + || !isspace(line[6]))
15565 + continue;
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);
15571 + }
15572 +
15573 + __fclose_ca(f);
15574 +
15575 +no_resolv_conf:
15576 + if (!nns) {
15577 + __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);
15578 + nns = 1;
15579 + }
15580 +
15581 + conf->nns = nns;
15582 +
15583 + return 0;
15584 +}
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);
15589 }
15590
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)
15595 {
15596 - struct node *r = *n;
15597 + struct node *r;
15598 int c;
15599
15600 - if (!r) {
15601 - *n = r = malloc(sizeof **n);
15602 - if (r) {
15603 - r->key = k;
15604 - r->left = r->right = 0;
15605 - r->height = 1;
15606 + if (!n) {
15607 + n = malloc(sizeof *n);
15608 + if (n) {
15609 + n->key = k;
15610 + n->left = n->right = 0;
15611 + n->height = 1;
15612 }
15613 - *new = 1;
15614 - return r;
15615 + *found = n;
15616 + return n;
15617 + }
15618 + c = cmp(k, n->key);
15619 + if (c == 0) {
15620 + *found = n;
15621 + return 0;
15622 + }
15623 + r = insert(c < 0 ? n->left : n->right, k, cmp, found);
15624 + if (r) {
15625 + if (c < 0)
15626 + n->left = r;
15627 + else
15628 + n->right = r;
15629 + r = balance(n);
15630 }
15631 - c = cmp(k, r->key);
15632 - if (c == 0)
15633 - return r;
15634 - if (c < 0)
15635 - r = insert(&r->left, k, cmp, new);
15636 - else
15637 - r = insert(&r->right, k, cmp, new);
15638 - if (*new)
15639 - *n = balance(*n);
15640 return r;
15641 }
15642
15643 -static struct node *movr(struct node *n, struct node *r) {
15644 - if (!n)
15645 - return r;
15646 - n->right = movr(n->right, r);
15647 +static struct node *remove_rightmost(struct node *n, struct node **rightmost)
15648 +{
15649 + if (!n->right) {
15650 + *rightmost = n;
15651 + return n->left;
15652 + }
15653 + n->right = remove_rightmost(n->right, rightmost);
15654 return balance(n);
15655 }
15656
15657 @@ -122,7 +129,13 @@ static struct node *remove(struct node *
15658 c = cmp(k, (*n)->key);
15659 if (c == 0) {
15660 struct node *r = *n;
15661 - *n = movr(r->left, r->right);
15662 + if (r->left) {
15663 + r->left = remove_rightmost(r->left, n);
15664 + (*n)->left = r->left;
15665 + (*n)->right = r->right;
15666 + *n = balance(*n);
15667 + } else
15668 + *n = r->right;
15669 free(r);
15670 return parent;
15671 }
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 *))
15675 {
15676 + if (!rootp)
15677 + return 0;
15678 struct node *n = *rootp;
15679 struct node *ret;
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 *))
15684 {
15685 + if (!rootp)
15686 + return 0;
15687 return find(*rootp, key, compar);
15688 }
15689
15690 void *tsearch(const void *key, void **rootp,
15691 int (*compar)(const void *, const void *))
15692 {
15693 - int new = 0;
15694 - struct node *n = *rootp;
15695 + struct node *update;
15696 struct node *ret;
15697 - ret = insert(&n, key, compar, &new);
15698 - *rootp = n;
15699 + if (!rootp)
15700 + return 0;
15701 + update = insert(*rootp, key, compar, &ret);
15702 + if (update)
15703 + *rootp = update;
15704 return ret;
15705 }
15706
15707 --- a/src/setjmp/arm/longjmp.s
15708 +++ b/src/setjmp/arm/longjmp.s
15709 @@ -1,3 +1,4 @@
15710 +.syntax unified
15711 .global _longjmp
15712 .global longjmp
15713 .type _longjmp,%function
15714 @@ -20,7 +21,11 @@ longjmp:
15715 ldc p2, cr4, [ip], #48
15716 2: tst r1,#0x40
15717 beq 2f
15718 - .word 0xecbc8b10 /* vldmia ip!, {d8-d15} */
15719 + .fpu vfp
15720 + vldmia ip!, {d8-d15}
15721 + .fpu softvfp
15722 + .eabi_attribute 10, 0
15723 + .eabi_attribute 27, 0
15724 2: tst r1,#0x200
15725 beq 3f
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
15731 -3: tst lr,#1
15732 - moveq pc,lr
15733 - bx lr
15734 +3: bx lr
15735
15736 .hidden __hwcap
15737 1: .word __hwcap-1b
15738 --- a/src/setjmp/arm/setjmp.s
15739 +++ b/src/setjmp/arm/setjmp.s
15740 @@ -1,3 +1,4 @@
15741 +.syntax unified
15742 .global __setjmp
15743 .global _setjmp
15744 .global setjmp
15745 @@ -22,7 +23,11 @@ setjmp:
15746 stc p2, cr4, [ip], #48
15747 2: tst r1,#0x40
15748 beq 2f
15749 - .word 0xecac8b10 /* vstmia ip!, {d8-d15} */
15750 + .fpu vfp
15751 + vstmia ip!, {d8-d15}
15752 + .fpu softvfp
15753 + .eabi_attribute 10, 0
15754 + .eabi_attribute 27, 0
15755 2: tst r1,#0x200
15756 beq 3f
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
15762 -3: tst lr,#1
15763 - moveq pc,lr
15764 - bx lr
15765 +3: bx lr
15766
15767 .hidden __hwcap
15768 1: .word __hwcap-1b
15769 --- a/src/setjmp/mips-sf/longjmp.s
15770 +++ /dev/null
15771 @@ -1,25 +0,0 @@
15772 -.set noreorder
15773 -
15774 -.global _longjmp
15775 -.global longjmp
15776 -.type _longjmp,@function
15777 -.type longjmp,@function
15778 -_longjmp:
15779 -longjmp:
15780 - move $2, $5
15781 - bne $2, $0, 1f
15782 - nop
15783 - addu $2, $2, 1
15784 -1: lw $ra, 0($4)
15785 - lw $sp, 4($4)
15786 - lw $16, 8($4)
15787 - lw $17, 12($4)
15788 - lw $18, 16($4)
15789 - lw $19, 20($4)
15790 - lw $20, 24($4)
15791 - lw $21, 28($4)
15792 - lw $22, 32($4)
15793 - lw $23, 36($4)
15794 - lw $30, 40($4)
15795 - jr $ra
15796 - lw $28, 44($4)
15797 --- a/src/setjmp/mips-sf/longjmp.sub
15798 +++ /dev/null
15799 @@ -1 +0,0 @@
15800 -longjmp.s
15801 --- a/src/setjmp/mips-sf/setjmp.s
15802 +++ /dev/null
15803 @@ -1,25 +0,0 @@
15804 -.set noreorder
15805 -
15806 -.global __setjmp
15807 -.global _setjmp
15808 -.global setjmp
15809 -.type __setjmp,@function
15810 -.type _setjmp,@function
15811 -.type setjmp,@function
15812 -__setjmp:
15813 -_setjmp:
15814 -setjmp:
15815 - sw $ra, 0($4)
15816 - sw $sp, 4($4)
15817 - sw $16, 8($4)
15818 - sw $17, 12($4)
15819 - sw $18, 16($4)
15820 - sw $19, 20($4)
15821 - sw $20, 24($4)
15822 - sw $21, 28($4)
15823 - sw $22, 32($4)
15824 - sw $23, 36($4)
15825 - sw $30, 40($4)
15826 - sw $28, 44($4)
15827 - jr $ra
15828 - li $2, 0
15829 --- a/src/setjmp/mips-sf/setjmp.sub
15830 +++ /dev/null
15831 @@ -1 +0,0 @@
15832 -setjmp.s
15833 --- /dev/null
15834 +++ b/src/setjmp/mips/longjmp.S
15835 @@ -0,0 +1,40 @@
15836 +.set noreorder
15837 +
15838 +.global _longjmp
15839 +.global longjmp
15840 +.type _longjmp,@function
15841 +.type longjmp,@function
15842 +_longjmp:
15843 +longjmp:
15844 + move $2, $5
15845 + bne $2, $0, 1f
15846 + nop
15847 + addu $2, $2, 1
15848 +1:
15849 +#ifndef __mips_soft_float
15850 + lwc1 $20, 56($4)
15851 + lwc1 $21, 60($4)
15852 + lwc1 $22, 64($4)
15853 + lwc1 $23, 68($4)
15854 + lwc1 $24, 72($4)
15855 + lwc1 $25, 76($4)
15856 + lwc1 $26, 80($4)
15857 + lwc1 $27, 84($4)
15858 + lwc1 $28, 88($4)
15859 + lwc1 $29, 92($4)
15860 + lwc1 $30, 96($4)
15861 + lwc1 $31, 100($4)
15862 +#endif
15863 + lw $ra, 0($4)
15864 + lw $sp, 4($4)
15865 + lw $16, 8($4)
15866 + lw $17, 12($4)
15867 + lw $18, 16($4)
15868 + lw $19, 20($4)
15869 + lw $20, 24($4)
15870 + lw $21, 28($4)
15871 + lw $22, 32($4)
15872 + lw $23, 36($4)
15873 + lw $30, 40($4)
15874 + jr $ra
15875 + lw $28, 44($4)
15876 --- a/src/setjmp/mips/longjmp.s
15877 +++ /dev/null
15878 @@ -1,37 +0,0 @@
15879 -.set noreorder
15880 -
15881 -.global _longjmp
15882 -.global longjmp
15883 -.type _longjmp,@function
15884 -.type longjmp,@function
15885 -_longjmp:
15886 -longjmp:
15887 - move $2, $5
15888 - bne $2, $0, 1f
15889 - nop
15890 - addu $2, $2, 1
15891 -1: lwc1 $20, 56($4)
15892 - lwc1 $21, 60($4)
15893 - lwc1 $22, 64($4)
15894 - lwc1 $23, 68($4)
15895 - lwc1 $24, 72($4)
15896 - lwc1 $25, 76($4)
15897 - lwc1 $26, 80($4)
15898 - lwc1 $27, 84($4)
15899 - lwc1 $28, 88($4)
15900 - lwc1 $29, 92($4)
15901 - lwc1 $30, 96($4)
15902 - lwc1 $31, 100($4)
15903 - lw $ra, 0($4)
15904 - lw $sp, 4($4)
15905 - lw $16, 8($4)
15906 - lw $17, 12($4)
15907 - lw $18, 16($4)
15908 - lw $19, 20($4)
15909 - lw $20, 24($4)
15910 - lw $21, 28($4)
15911 - lw $22, 32($4)
15912 - lw $23, 36($4)
15913 - lw $30, 40($4)
15914 - jr $ra
15915 - lw $28, 44($4)
15916 --- /dev/null
15917 +++ b/src/setjmp/mips/setjmp.S
15918 @@ -0,0 +1,39 @@
15919 +.set noreorder
15920 +
15921 +.global __setjmp
15922 +.global _setjmp
15923 +.global setjmp
15924 +.type __setjmp,@function
15925 +.type _setjmp,@function
15926 +.type setjmp,@function
15927 +__setjmp:
15928 +_setjmp:
15929 +setjmp:
15930 + sw $ra, 0($4)
15931 + sw $sp, 4($4)
15932 + sw $16, 8($4)
15933 + sw $17, 12($4)
15934 + sw $18, 16($4)
15935 + sw $19, 20($4)
15936 + sw $20, 24($4)
15937 + sw $21, 28($4)
15938 + sw $22, 32($4)
15939 + sw $23, 36($4)
15940 + sw $30, 40($4)
15941 + sw $28, 44($4)
15942 +#ifndef __mips_soft_float
15943 + swc1 $20, 56($4)
15944 + swc1 $21, 60($4)
15945 + swc1 $22, 64($4)
15946 + swc1 $23, 68($4)
15947 + swc1 $24, 72($4)
15948 + swc1 $25, 76($4)
15949 + swc1 $26, 80($4)
15950 + swc1 $27, 84($4)
15951 + swc1 $28, 88($4)
15952 + swc1 $29, 92($4)
15953 + swc1 $30, 96($4)
15954 + swc1 $31, 100($4)
15955 +#endif
15956 + jr $ra
15957 + li $2, 0
15958 --- a/src/setjmp/mips/setjmp.s
15959 +++ /dev/null
15960 @@ -1,37 +0,0 @@
15961 -.set noreorder
15962 -
15963 -.global __setjmp
15964 -.global _setjmp
15965 -.global setjmp
15966 -.type __setjmp,@function
15967 -.type _setjmp,@function
15968 -.type setjmp,@function
15969 -__setjmp:
15970 -_setjmp:
15971 -setjmp:
15972 - sw $ra, 0($4)
15973 - sw $sp, 4($4)
15974 - sw $16, 8($4)
15975 - sw $17, 12($4)
15976 - sw $18, 16($4)
15977 - sw $19, 20($4)
15978 - sw $20, 24($4)
15979 - sw $21, 28($4)
15980 - sw $22, 32($4)
15981 - sw $23, 36($4)
15982 - sw $30, 40($4)
15983 - sw $28, 44($4)
15984 - swc1 $20, 56($4)
15985 - swc1 $21, 60($4)
15986 - swc1 $22, 64($4)
15987 - swc1 $23, 68($4)
15988 - swc1 $24, 72($4)
15989 - swc1 $25, 76($4)
15990 - swc1 $26, 80($4)
15991 - swc1 $27, 84($4)
15992 - swc1 $28, 88($4)
15993 - swc1 $29, 92($4)
15994 - swc1 $30, 96($4)
15995 - swc1 $31, 100($4)
15996 - jr $ra
15997 - li $2, 0
15998 --- a/src/setjmp/mipsel-sf/longjmp.sub
15999 +++ /dev/null
16000 @@ -1 +0,0 @@
16001 -../mips-sf/longjmp.s
16002 --- a/src/setjmp/mipsel-sf/setjmp.sub
16003 +++ /dev/null
16004 @@ -1 +0,0 @@
16005 -../mips-sf/setjmp.s
16006 --- a/src/setjmp/sh-nofpu/longjmp.s
16007 +++ /dev/null
16008 @@ -1,22 +0,0 @@
16009 -.global _longjmp
16010 -.global longjmp
16011 -.type _longjmp, @function
16012 -.type longjmp, @function
16013 -_longjmp:
16014 -longjmp:
16015 - mov.l @r4+, r8
16016 - mov.l @r4+, r9
16017 - mov.l @r4+, r10
16018 - mov.l @r4+, r11
16019 - mov.l @r4+, r12
16020 - mov.l @r4+, r13
16021 - mov.l @r4+, r14
16022 - mov.l @r4+, r15
16023 - lds.l @r4+, pr
16024 -
16025 - tst r5, r5
16026 - movt r0
16027 - add r5, r0
16028 -
16029 - rts
16030 - nop
16031 --- a/src/setjmp/sh-nofpu/longjmp.sub
16032 +++ /dev/null
16033 @@ -1 +0,0 @@
16034 -longjmp.s
16035 --- a/src/setjmp/sh-nofpu/setjmp.s
16036 +++ /dev/null
16037 @@ -1,24 +0,0 @@
16038 -.global ___setjmp
16039 -.hidden ___setjmp
16040 -.global __setjmp
16041 -.global _setjmp
16042 -.global setjmp
16043 -.type __setjmp, @function
16044 -.type _setjmp, @function
16045 -.type setjmp, @function
16046 -___setjmp:
16047 -__setjmp:
16048 -_setjmp:
16049 -setjmp:
16050 - add #36, r4
16051 - sts.l pr, @-r4
16052 - mov.l r15 @-r4
16053 - mov.l r14, @-r4
16054 - mov.l r13, @-r4
16055 - mov.l r12, @-r4
16056 - mov.l r11, @-r4
16057 - mov.l r10, @-r4
16058 - mov.l r9, @-r4
16059 - mov.l r8, @-r4
16060 - rts
16061 - mov #0, r0
16062 --- a/src/setjmp/sh-nofpu/setjmp.sub
16063 +++ /dev/null
16064 @@ -1 +0,0 @@
16065 -setjmp.s
16066 --- /dev/null
16067 +++ b/src/setjmp/sh/longjmp.S
16068 @@ -0,0 +1,28 @@
16069 +.global _longjmp
16070 +.global longjmp
16071 +.type _longjmp, @function
16072 +.type longjmp, @function
16073 +_longjmp:
16074 +longjmp:
16075 + mov.l @r4+, r8
16076 + mov.l @r4+, r9
16077 + mov.l @r4+, r10
16078 + mov.l @r4+, r11
16079 + mov.l @r4+, r12
16080 + mov.l @r4+, r13
16081 + mov.l @r4+, r14
16082 + mov.l @r4+, r15
16083 + lds.l @r4+, pr
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
16089 +#endif
16090 +
16091 + tst r5, r5
16092 + movt r0
16093 + add r5, r0
16094 +
16095 + rts
16096 + nop
16097 --- a/src/setjmp/sh/longjmp.s
16098 +++ /dev/null
16099 @@ -1,26 +0,0 @@
16100 -.global _longjmp
16101 -.global longjmp
16102 -.type _longjmp, @function
16103 -.type longjmp, @function
16104 -_longjmp:
16105 -longjmp:
16106 - mov.l @r4+, r8
16107 - mov.l @r4+, r9
16108 - mov.l @r4+, r10
16109 - mov.l @r4+, r11
16110 - mov.l @r4+, r12
16111 - mov.l @r4+, r13
16112 - mov.l @r4+, r14
16113 - mov.l @r4+, r15
16114 - lds.l @r4+, pr
16115 - fmov.s @r4+, fr12
16116 - fmov.s @r4+, fr13
16117 - fmov.s @r4+, fr14
16118 - fmov.s @r4+, fr15
16119 -
16120 - tst r5, r5
16121 - movt r0
16122 - add r5, r0
16123 -
16124 - rts
16125 - nop
16126 --- /dev/null
16127 +++ b/src/setjmp/sh/setjmp.S
16128 @@ -0,0 +1,32 @@
16129 +.global ___setjmp
16130 +.hidden ___setjmp
16131 +.global __setjmp
16132 +.global _setjmp
16133 +.global setjmp
16134 +.type __setjmp, @function
16135 +.type _setjmp, @function
16136 +.type setjmp, @function
16137 +___setjmp:
16138 +__setjmp:
16139 +_setjmp:
16140 +setjmp:
16141 +#if __SH_FPU_ANY__ || __SH4__
16142 + add #52, r4
16143 + fmov.s fr15, @-r4
16144 + fmov.s fr14, @-r4
16145 + fmov.s fr13, @-r4
16146 + fmov.s fr12, @-r4
16147 +#else
16148 + add #36, r4
16149 +#endif
16150 + sts.l pr, @-r4
16151 + mov.l r15, @-r4
16152 + mov.l r14, @-r4
16153 + mov.l r13, @-r4
16154 + mov.l r12, @-r4
16155 + mov.l r11, @-r4
16156 + mov.l r10, @-r4
16157 + mov.l r9, @-r4
16158 + mov.l r8, @-r4
16159 + rts
16160 + mov #0, r0
16161 --- a/src/setjmp/sh/setjmp.s
16162 +++ /dev/null
16163 @@ -1,28 +0,0 @@
16164 -.global ___setjmp
16165 -.hidden ___setjmp
16166 -.global __setjmp
16167 -.global _setjmp
16168 -.global setjmp
16169 -.type __setjmp, @function
16170 -.type _setjmp, @function
16171 -.type setjmp, @function
16172 -___setjmp:
16173 -__setjmp:
16174 -_setjmp:
16175 -setjmp:
16176 - add #52, r4
16177 - fmov.s fr15, @-r4
16178 - fmov.s fr14, @-r4
16179 - fmov.s fr13, @-r4
16180 - fmov.s fr12, @-r4
16181 - sts.l pr, @-r4
16182 - mov.l r15, @-r4
16183 - mov.l r14, @-r4
16184 - mov.l r13, @-r4
16185 - mov.l r12, @-r4
16186 - mov.l r11, @-r4
16187 - mov.l r10, @-r4
16188 - mov.l r9, @-r4
16189 - mov.l r8, @-r4
16190 - rts
16191 - mov #0, r0
16192 --- a/src/setjmp/sheb-nofpu/longjmp.sub
16193 +++ /dev/null
16194 @@ -1 +0,0 @@
16195 -../sh-nofpu/longjmp.s
16196 --- a/src/setjmp/sheb-nofpu/setjmp.sub
16197 +++ /dev/null
16198 @@ -1 +0,0 @@
16199 -../sh-nofpu/setjmp.s
16200 --- a/src/signal/arm/restore.s
16201 +++ b/src/signal/arm/restore.s
16202 @@ -1,3 +1,5 @@
16203 +.syntax unified
16204 +
16205 .global __restore
16206 .type __restore,%function
16207 __restore:
16208 --- a/src/signal/arm/sigsetjmp.s
16209 +++ b/src/signal/arm/sigsetjmp.s
16210 @@ -1,3 +1,4 @@
16211 +.syntax unified
16212 .global sigsetjmp
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)
16219 {
16220 struct k_sigaction ksa, ksa_old;
16221 - if (sig >= (unsigned)_NSIG) {
16222 - errno = EINVAL;
16223 - return -1;
16224 - }
16225 if (sa) {
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
16229
16230 int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
16231 {
16232 - if (sig-32U < 3) {
16233 + if (sig-32U < 3 || sig-1U >= _NSIG-1) {
16234 errno = EINVAL;
16235 return -1;
16236 }
16237 --- a/src/signal/sigsetjmp_tail.c
16238 +++ b/src/signal/sigsetjmp_tail.c
16239 @@ -2,9 +2,7 @@
16240 #include <signal.h>
16241 #include "syscall.h"
16242
16243 -#ifdef SHARED
16244 __attribute__((__visibility__("hidden")))
16245 -#endif
16246 int __sigsetjmp_tail(sigjmp_buf jb, int ret)
16247 {
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
16252 for (;;) {
16253 z = memchr(f->rpos, delim, f->rend - f->rpos);
16254 k = z ? z - f->rpos + 1 : f->rend - f->rpos;
16255 - if (i+k >= *n) {
16256 + if (i+k+1 >= *n) {
16257 if (k >= SIZE_MAX/2-i) goto oom;
16258 - *n = i+k+2;
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);
16264 if (!tmp) {
16265 - *n = i+k+2;
16266 - tmp = realloc(*s, *n);
16267 + m = i+k+2;
16268 + tmp = realloc(*s, m);
16269 if (!tmp) goto oom;
16270 }
16271 *s = tmp;
16272 + *n = m;
16273 }
16274 memcpy(*s+i, f->rpos, k);
16275 f->rpos += k;
16276 --- /dev/null
16277 +++ b/src/string/arm/__aeabi_memclr.c
16278 @@ -0,0 +1,9 @@
16279 +#include <string.h>
16280 +#include "libc.h"
16281 +
16282 +void __aeabi_memclr(void *dest, size_t n)
16283 +{
16284 + memset(dest, 0, n);
16285 +}
16286 +weak_alias(__aeabi_memclr, __aeabi_memclr4);
16287 +weak_alias(__aeabi_memclr, __aeabi_memclr8);
16288 --- /dev/null
16289 +++ b/src/string/arm/__aeabi_memcpy.c
16290 @@ -0,0 +1,9 @@
16291 +#include <string.h>
16292 +#include "libc.h"
16293 +
16294 +void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
16295 +{
16296 + memcpy(dest, src, n);
16297 +}
16298 +weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
16299 +weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
16300 --- /dev/null
16301 +++ b/src/string/arm/__aeabi_memmove.c
16302 @@ -0,0 +1,9 @@
16303 +#include <string.h>
16304 +#include "libc.h"
16305 +
16306 +void __aeabi_memmove(void *dest, const void *src, size_t n)
16307 +{
16308 + memmove(dest, src, n);
16309 +}
16310 +weak_alias(__aeabi_memmove, __aeabi_memmove4);
16311 +weak_alias(__aeabi_memmove, __aeabi_memmove8);
16312 --- /dev/null
16313 +++ b/src/string/arm/__aeabi_memset.c
16314 @@ -0,0 +1,9 @@
16315 +#include <string.h>
16316 +#include "libc.h"
16317 +
16318 +void __aeabi_memset(void *dest, size_t n, int c)
16319 +{
16320 + memset(dest, c, n);
16321 +}
16322 +weak_alias(__aeabi_memset, __aeabi_memset4);
16323 +weak_alias(__aeabi_memset, __aeabi_memset8);
16324 --- /dev/null
16325 +++ b/src/string/arm/memcpy.c
16326 @@ -0,0 +1,3 @@
16327 +#if __ARMEB__
16328 +#include "../memcpy.c"
16329 +#endif
16330 --- /dev/null
16331 +++ b/src/string/arm/memcpy_le.S
16332 @@ -0,0 +1,383 @@
16333 +#ifndef __ARMEB__
16334 +
16335 +/*
16336 + * Copyright (C) 2008 The Android Open Source Project
16337 + * All rights reserved.
16338 + *
16339 + * Redistribution and use in source and binary forms, with or without
16340 + * modification, are permitted provided that the following conditions
16341 + * are met:
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
16347 + * distribution.
16348 + *
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
16360 + * SUCH DAMAGE.
16361 + */
16362 +
16363 +
16364 +/*
16365 + * Optimized memcpy() for ARM.
16366 + *
16367 + * note that memcpy() always returns the destination pointer,
16368 + * so we have to preserve R0.
16369 + */
16370 +
16371 +/*
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.
16377 + */
16378 +
16379 +.syntax unified
16380 +
16381 +.global memcpy
16382 +.type memcpy,%function
16383 +memcpy:
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
16387 + */
16388 + .fnstart
16389 + .save {r0, r4, lr}
16390 + stmfd sp!, {r0, r4, lr}
16391 + /* Making room for r5-r11 which will be spilled later */
16392 + .pad #28
16393 + sub sp, sp, #28
16394 +
16395 + /* it simplifies things to take care of len<4 early */
16396 + cmp r2, #4
16397 + blo copy_last_3_and_return
16398 +
16399 + /* compute the offset to align the source
16400 + * offset = (4-(src&3))&3 = -src & 3
16401 + */
16402 + rsb r3, r1, #0
16403 + ands r3, r3, #3
16404 + beq src_aligned
16405 +
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.
16409 + */
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
16418 +
16419 +src_aligned:
16420 +
16421 + /* see if src and dst are aligned together (congruent) */
16422 + eor r12, r0, r1
16423 + tst r12, #3
16424 + bne non_congruent
16425 +
16426 + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16427 + * frame. Don't update sp.
16428 + */
16429 + stmea sp, {r5-r11}
16430 +
16431 + /* align the destination to a cache-line */
16432 + rsb r3, r0, #0
16433 + ands r3, r3, #0x1C
16434 + beq congruent_aligned32
16435 + cmp r3, r2
16436 + andhi r3, r2, #0x1C
16437 +
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}
16444 + tst r3, #0x4
16445 + ldrne r10,[r1], #4 /* 4 bytes */
16446 + strne r10,[r0], #4
16447 + sub r2, r2, r3
16448 +
16449 +congruent_aligned32:
16450 + /*
16451 + * here source is aligned to 32 bytes.
16452 + */
16453 +
16454 +cached_aligned32:
16455 + subs r2, r2, #32
16456 + blo less_than_32_left
16457 +
16458 + /*
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
16466 + *
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).
16470 + *
16471 + * This code should work well regardless of the source/dest alignment.
16472 + *
16473 + */
16474 +
16475 + /* Align the preload register to a cache-line because the cpu does
16476 + * "critical word first" (the first word requested is loaded first).
16477 + */
16478 + @ bic r12, r1, #0x1F
16479 + @ add r12, r12, #64
16480 +
16481 +1: ldmia r1!, { r4-r11 }
16482 + subs r2, r2, #32
16483 +
16484 + /*
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.
16489 + */
16490 + @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
16491 + stmia r0!, { r4-r11 }
16492 + bhs 1b
16493 +
16494 + add r2, r2, #32
16495 +
16496 +less_than_32_left:
16497 + /*
16498 + * less than 32 bytes left at this point (length in r2)
16499 + */
16500 +
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)
16504 + */
16505 + tst r2, #0x1F
16506 + beq 1f
16507 +
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
16519 + tst r2, #0x1
16520 + ldrbne r3, [r1] /* last byte */
16521 + strbne r3, [r0]
16522 +
16523 + /* we're done! restore everything and return */
16524 +1: ldmfd sp!, {r5-r11}
16525 + ldmfd sp!, {r0, r4, lr}
16526 + bx lr
16527 +
16528 + /********************************************************************/
16529 +
16530 +non_congruent:
16531 + /*
16532 + * here source is aligned to 4 bytes
16533 + * but destination is not.
16534 + *
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)
16538 + */
16539 + cmp r2, #4
16540 + blo copy_last_3_and_return
16541 +
16542 + /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16543 + * frame. Don't update sp.
16544 + */
16545 + stmea sp, {r5-r11}
16546 +
16547 + /* compute shifts needed to align src to dest */
16548 + rsb r5, r0, #0
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 */
16552 +
16553 + /* read the first word */
16554 + ldr r3, [r1], #4
16555 + sub r2, r2, #4
16556 +
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)
16559 + */
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
16567 +
16568 + cmp r2, #4
16569 + blo partial_word_tail
16570 +
16571 + /* Align destination to 32 bytes (cache line boundary) */
16572 +1: tst r0, #0x1c
16573 + beq 2f
16574 + ldr r5, [r1], #4
16575 + sub r2, r2, #4
16576 + orr r4, r3, r5, lsl lr
16577 + mov r3, r5, lsr r12
16578 + str r4, [r0], #4
16579 + cmp r2, #4
16580 + bhs 1b
16581 + blo partial_word_tail
16582 +
16583 + /* copy 32 bytes at a time */
16584 +2: subs r2, r2, #32
16585 + blo less_than_thirtytwo
16586 +
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.
16590 + */
16591 +
16592 + cmp r12, #24
16593 + beq loop24
16594 + cmp r12, #8
16595 + beq loop8
16596 +
16597 +loop16:
16598 + ldr r12, [r1], #4
16599 +1: mov r4, r12
16600 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16601 + subs r2, r2, #32
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
16620 + bhs 1b
16621 + b less_than_thirtytwo
16622 +
16623 +loop8:
16624 + ldr r12, [r1], #4
16625 +1: mov r4, r12
16626 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16627 + subs r2, r2, #32
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
16646 + bhs 1b
16647 + b less_than_thirtytwo
16648 +
16649 +loop24:
16650 + ldr r12, [r1], #4
16651 +1: mov r4, r12
16652 + ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16653 + subs r2, r2, #32
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
16672 + bhs 1b
16673 +
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 */
16677 + add r2, r2, #32
16678 + cmp r2, #4
16679 + blo partial_word_tail
16680 +
16681 +1: ldr r5, [r1], #4
16682 + sub r2, r2, #4
16683 + orr r4, r3, r5, lsl lr
16684 + mov r3, r5, lsr r12
16685 + str r4, [r0], #4
16686 + cmp r2, #4
16687 + bhs 1b
16688 +
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
16697 +
16698 + /* Refill spilled registers from the stack. Don't update sp. */
16699 + ldmfd sp, {r5-r11}
16700 +
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
16705 + ldrbcs r12,[r1]
16706 + strbmi r2, [r0], #1
16707 + strbcs r3, [r0], #1
16708 + strbcs r12,[r0]
16709 +
16710 + /* we're done! restore sp and spilled registers and return */
16711 + add sp, sp, #28
16712 + ldmfd sp!, {r0, r4, lr}
16713 + bx lr
16714 +
16715 +#endif
16716 --- a/src/string/armel/memcpy.s
16717 +++ /dev/null
16718 @@ -1,381 +0,0 @@
16719 -/*
16720 - * Copyright (C) 2008 The Android Open Source Project
16721 - * All rights reserved.
16722 - *
16723 - * Redistribution and use in source and binary forms, with or without
16724 - * modification, are permitted provided that the following conditions
16725 - * are met:
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
16731 - * distribution.
16732 - *
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
16744 - * SUCH DAMAGE.
16745 - */
16746 -
16747 -
16748 -/*
16749 - * Optimized memcpy() for ARM.
16750 - *
16751 - * note that memcpy() always returns the destination pointer,
16752 - * so we have to preserve R0.
16753 - */
16754 -
16755 -/*
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.
16761 - */
16762 -
16763 -.global memcpy
16764 -.type memcpy,%function
16765 -memcpy:
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
16769 - */
16770 - .fnstart
16771 - .save {r0, r4, lr}
16772 - stmfd sp!, {r0, r4, lr}
16773 - /* Making room for r5-r11 which will be spilled later */
16774 - .pad #28
16775 - sub sp, sp, #28
16776 -
16777 - /* it simplifies things to take care of len<4 early */
16778 - cmp r2, #4
16779 - blo copy_last_3_and_return
16780 -
16781 - /* compute the offset to align the source
16782 - * offset = (4-(src&3))&3 = -src & 3
16783 - */
16784 - rsb r3, r1, #0
16785 - ands r3, r3, #3
16786 - beq src_aligned
16787 -
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.
16791 - */
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 */
16800 -
16801 -src_aligned:
16802 -
16803 - /* see if src and dst are aligned together (congruent) */
16804 - eor r12, r0, r1
16805 - tst r12, #3
16806 - bne non_congruent
16807 -
16808 - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16809 - * frame. Don't update sp.
16810 - */
16811 - stmea sp, {r5-r11}
16812 -
16813 - /* align the destination to a cache-line */
16814 - rsb r3, r0, #0
16815 - ands r3, r3, #0x1C
16816 - beq congruent_aligned32
16817 - cmp r3, r2
16818 - andhi r3, r2, #0x1C
16819 -
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}
16826 - tst r3, #0x4
16827 - ldrne r10,[r1], #4 /* 4 bytes */
16828 - strne r10,[r0], #4
16829 - sub r2, r2, r3
16830 -
16831 -congruent_aligned32:
16832 - /*
16833 - * here source is aligned to 32 bytes.
16834 - */
16835 -
16836 -cached_aligned32:
16837 - subs r2, r2, #32
16838 - blo less_than_32_left
16839 -
16840 - /*
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
16848 - *
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).
16852 - *
16853 - * This code should work well regardless of the source/dest alignment.
16854 - *
16855 - */
16856 -
16857 - /* Align the preload register to a cache-line because the cpu does
16858 - * "critical word first" (the first word requested is loaded first).
16859 - */
16860 - @ bic r12, r1, #0x1F
16861 - @ add r12, r12, #64
16862 -
16863 -1: ldmia r1!, { r4-r11 }
16864 - subs r2, r2, #32
16865 -
16866 - /*
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.
16871 - */
16872 - @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */
16873 - stmia r0!, { r4-r11 }
16874 - bhs 1b
16875 -
16876 - add r2, r2, #32
16877 -
16878 -less_than_32_left:
16879 - /*
16880 - * less than 32 bytes left at this point (length in r2)
16881 - */
16882 -
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)
16886 - */
16887 - tst r2, #0x1F
16888 - beq 1f
16889 -
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 */
16901 - tst r2, #0x1
16902 - .word 0x15d13000 /* ldrbne r3, [r1] */ /* last byte */
16903 - .word 0x15c03000 /* strbne r3, [r0] */
16904 -
16905 - /* we're done! restore everything and return */
16906 -1: ldmfd sp!, {r5-r11}
16907 - ldmfd sp!, {r0, r4, lr}
16908 - tst lr, #1
16909 - moveq pc, lr
16910 - bx lr
16911 -
16912 - /********************************************************************/
16913 -
16914 -non_congruent:
16915 - /*
16916 - * here source is aligned to 4 bytes
16917 - * but destination is not.
16918 - *
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)
16922 - */
16923 - cmp r2, #4
16924 - blo copy_last_3_and_return
16925 -
16926 - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack
16927 - * frame. Don't update sp.
16928 - */
16929 - stmea sp, {r5-r11}
16930 -
16931 - /* compute shifts needed to align src to dest */
16932 - rsb r5, r0, #0
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 */
16936 -
16937 - /* read the first word */
16938 - ldr r3, [r1], #4
16939 - sub r2, r2, #4
16940 -
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)
16943 - */
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
16951 -
16952 - cmp r2, #4
16953 - blo partial_word_tail
16954 -
16955 - /* Align destination to 32 bytes (cache line boundary) */
16956 -1: tst r0, #0x1c
16957 - beq 2f
16958 - ldr r5, [r1], #4
16959 - sub r2, r2, #4
16960 - orr r4, r3, r5, lsl lr
16961 - mov r3, r5, lsr r12
16962 - str r4, [r0], #4
16963 - cmp r2, #4
16964 - bhs 1b
16965 - blo partial_word_tail
16966 -
16967 - /* copy 32 bytes at a time */
16968 -2: subs r2, r2, #32
16969 - blo less_than_thirtytwo
16970 -
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.
16974 - */
16975 -
16976 - cmp r12, #24
16977 - beq loop24
16978 - cmp r12, #8
16979 - beq loop8
16980 -
16981 -loop16:
16982 - ldr r12, [r1], #4
16983 -1: mov r4, r12
16984 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
16985 - subs r2, r2, #32
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
17004 - bhs 1b
17005 - b less_than_thirtytwo
17006 -
17007 -loop8:
17008 - ldr r12, [r1], #4
17009 -1: mov r4, r12
17010 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
17011 - subs r2, r2, #32
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
17030 - bhs 1b
17031 - b less_than_thirtytwo
17032 -
17033 -loop24:
17034 - ldr r12, [r1], #4
17035 -1: mov r4, r12
17036 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11}
17037 - subs r2, r2, #32
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
17056 - bhs 1b
17057 -
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 */
17061 - add r2, r2, #32
17062 - cmp r2, #4
17063 - blo partial_word_tail
17064 -
17065 -1: ldr r5, [r1], #4
17066 - sub r2, r2, #4
17067 - orr r4, r3, r5, lsl lr
17068 - mov r3, r5, lsr r12
17069 - str r4, [r0], #4
17070 - cmp r2, #4
17071 - bhs 1b
17072 -
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 */
17081 -
17082 - /* Refill spilled registers from the stack. Don't update sp. */
17083 - ldmfd sp, {r5-r11}
17084 -
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] */
17093 -
17094 - /* we're done! restore sp and spilled registers and return */
17095 - add sp, sp, #28
17096 - ldmfd sp!, {r0, r4, lr}
17097 - tst lr, #1
17098 - moveq pc, lr
17099 - bx lr
17100 --- a/src/string/armel/memcpy.sub
17101 +++ /dev/null
17102 @@ -1 +0,0 @@
17103 -memcpy.s
17104 --- a/src/string/armhf/memcpy.sub
17105 +++ /dev/null
17106 @@ -1 +0,0 @@
17107 -../armel/memcpy.s
17108 --- a/src/thread/__syscall_cp.c
17109 +++ b/src/thread/__syscall_cp.c
17110 @@ -1,9 +1,7 @@
17111 #include "pthread_impl.h"
17112 #include "syscall.h"
17113
17114 -#ifdef SHARED
17115 __attribute__((__visibility__("hidden")))
17116 -#endif
17117 long __syscall_cp_c();
17118
17119 static long sccp(syscall_arg_t nr,
17120 --- a/src/thread/__tls_get_addr.c
17121 +++ b/src/thread/__tls_get_addr.c
17122 @@ -1,16 +1,16 @@
17123 #include <stddef.h>
17124 #include "pthread_impl.h"
17125 +#include "libc.h"
17126 +
17127 +__attribute__((__visibility__("hidden")))
17128 +void *__tls_get_new(size_t *);
17129
17130 void *__tls_get_addr(size_t *v)
17131 {
17132 pthread_t self = __pthread_self();
17133 -#ifdef SHARED
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);
17139 -#else
17140 - return (char *)self->dtv[1]+v[1]+DTP_OFFSET;
17141 -#endif
17142 }
17143 +
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
17147 @@ -17,7 +17,7 @@
17148 __syscall_cp_asm:
17149 __cp_begin:
17150 ldr w0,[x0]
17151 - cbnz w0,1f
17152 + cbnz w0,__cp_cancel
17153 mov x8,x1
17154 mov x0,x2
17155 mov x1,x3
17156 @@ -28,6 +28,5 @@ __cp_begin:
17157 svc 0
17158 __cp_end:
17159 ret
17160 -
17161 - // cbnz might not be able to jump far enough
17162 -1: b __cancel
17163 +__cp_cancel:
17164 + b __cancel
17165 --- /dev/null
17166 +++ b/src/thread/arm/__set_thread_area.c
17167 @@ -0,0 +1,49 @@
17168 +#include <stdint.h>
17169 +#include <elf.h>
17170 +#include "pthread_impl.h"
17171 +#include "libc.h"
17172 +
17173 +#define HWCAP_TLS (1 << 15)
17174 +
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[];
17180 +
17181 +#define __a_barrier_kuser 0xffff0fa0
17182 +#define __a_cas_kuser 0xffff0fc0
17183 +#define __a_gettp_kuser 0xffff0fe0
17184 +
17185 +extern uintptr_t __attribute__((__visibility__("hidden")))
17186 + __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr;
17187 +
17188 +#define SET(op,ver) (__a_##op##_ptr = \
17189 + (uintptr_t)__a_##op##_##ver - (uintptr_t)__a_##op##_dummy)
17190 +
17191 +int __set_thread_area(void *p)
17192 +{
17193 +#if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7
17194 + if (__hwcap & HWCAP_TLS) {
17195 + size_t *aux;
17196 + SET(cas, v7);
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;
17202 + SET(cas, v6);
17203 + SET(barrier, v6);
17204 + break;
17205 + }
17206 + } else {
17207 + int ver = *(int *)0xffff0ffc;
17208 + SET(gettp, kuser);
17209 + SET(cas, kuser);
17210 + SET(barrier, kuser);
17211 + if (ver < 2) a_crash();
17212 + if (ver < 3) SET(barrier, oldkuser);
17213 + }
17214 +#endif
17215 + return __syscall(0xf0005, p);
17216 +}
17217 --- a/src/thread/arm/__set_thread_area.s
17218 +++ /dev/null
17219 @@ -1 +0,0 @@
17220 -/* Replaced by C code in arch/arm/src */
17221 --- a/src/thread/arm/__unmapself.s
17222 +++ b/src/thread/arm/__unmapself.s
17223 @@ -1,3 +1,4 @@
17224 +.syntax unified
17225 .text
17226 .global __unmapself
17227 .type __unmapself,%function
17228 --- /dev/null
17229 +++ b/src/thread/arm/atomics.s
17230 @@ -0,0 +1,113 @@
17231 +.syntax unified
17232 +.text
17233 +
17234 +.global __a_barrier
17235 +.hidden __a_barrier
17236 +.type __a_barrier,%function
17237 +__a_barrier:
17238 + ldr ip,1f
17239 + ldr ip,[pc,ip]
17240 + add pc,pc,ip
17241 +1: .word __a_barrier_ptr-1b
17242 +.global __a_barrier_dummy
17243 +.hidden __a_barrier_dummy
17244 +__a_barrier_dummy:
17245 + bx lr
17246 +.global __a_barrier_oldkuser
17247 +.hidden __a_barrier_oldkuser
17248 +__a_barrier_oldkuser:
17249 + push {r0,r1,r2,r3,ip,lr}
17250 + mov r1,r0
17251 + mov r2,sp
17252 + ldr ip,=0xffff0fc0
17253 + mov lr,pc
17254 + mov pc,ip
17255 + pop {r0,r1,r2,r3,ip,lr}
17256 + bx lr
17257 +.global __a_barrier_v6
17258 +.hidden __a_barrier_v6
17259 +__a_barrier_v6:
17260 + mcr p15,0,r0,c7,c10,5
17261 + bx lr
17262 +.global __a_barrier_v7
17263 +.hidden __a_barrier_v7
17264 +__a_barrier_v7:
17265 + .word 0xf57ff05b /* dmb ish */
17266 + bx lr
17267 +
17268 +.global __a_cas
17269 +.hidden __a_cas
17270 +.type __a_cas,%function
17271 +__a_cas:
17272 + ldr ip,1f
17273 + ldr ip,[pc,ip]
17274 + add pc,pc,ip
17275 +1: .word __a_cas_ptr-1b
17276 +.global __a_cas_dummy
17277 +.hidden __a_cas_dummy
17278 +__a_cas_dummy:
17279 + mov r3,r0
17280 + ldr r0,[r2]
17281 + subs r0,r3,r0
17282 + streq r1,[r2]
17283 + bx lr
17284 +.global __a_cas_v6
17285 +.hidden __a_cas_v6
17286 +__a_cas_v6:
17287 + mov r3,r0
17288 + mcr p15,0,r0,c7,c10,5
17289 +1: .word 0xe1920f9f /* ldrex r0,[r2] */
17290 + subs r0,r3,r0
17291 + .word 0x01820f91 /* strexeq r0,r1,[r2] */
17292 + teqeq r0,#1
17293 + beq 1b
17294 + mcr p15,0,r0,c7,c10,5
17295 + bx lr
17296 +.global __a_cas_v7
17297 +.hidden __a_cas_v7
17298 +__a_cas_v7:
17299 + mov r3,r0
17300 + .word 0xf57ff05b /* dmb ish */
17301 +1: .word 0xe1920f9f /* ldrex r0,[r2] */
17302 + subs r0,r3,r0
17303 + .word 0x01820f91 /* strexeq r0,r1,[r2] */
17304 + teqeq r0,#1
17305 + beq 1b
17306 + .word 0xf57ff05b /* dmb ish */
17307 + bx lr
17308 +
17309 +.global __aeabi_read_tp
17310 +.type __aeabi_read_tp,%function
17311 +__aeabi_read_tp:
17312 +
17313 +.global __a_gettp
17314 +.hidden __a_gettp
17315 +.type __a_gettp,%function
17316 +__a_gettp:
17317 + ldr r0,1f
17318 + ldr r0,[pc,r0]
17319 + add pc,pc,r0
17320 +1: .word __a_gettp_ptr-1b
17321 +.global __a_gettp_dummy
17322 +.hidden __a_gettp_dummy
17323 +__a_gettp_dummy:
17324 + mrc p15,0,r0,c13,c0,3
17325 + bx lr
17326 +
17327 +.data
17328 +.align 2
17329 +
17330 +.global __a_barrier_ptr
17331 +.hidden __a_barrier_ptr
17332 +__a_barrier_ptr:
17333 + .word 0
17334 +
17335 +.global __a_cas_ptr
17336 +.hidden __a_cas_ptr
17337 +__a_cas_ptr:
17338 + .word 0
17339 +
17340 +.global __a_gettp_ptr
17341 +.hidden __a_gettp_ptr
17342 +__a_gettp_ptr:
17343 + .word 0
17344 --- a/src/thread/arm/clone.s
17345 +++ b/src/thread/arm/clone.s
17346 @@ -1,3 +1,4 @@
17347 +.syntax unified
17348 .text
17349 .global __clone
17350 .type __clone,%function
17351 @@ -15,8 +16,6 @@ __clone:
17352 tst r0,r0
17353 beq 1f
17354 ldmfd sp!,{r4,r5,r6,r7}
17355 - tst lr,#1
17356 - moveq pc,lr
17357 bx lr
17358
17359 1: mov r0,r6
17360 --- a/src/thread/arm/syscall_cp.s
17361 +++ b/src/thread/arm/syscall_cp.s
17362 @@ -1,3 +1,4 @@
17363 +.syntax unified
17364 .global __cp_begin
17365 .hidden __cp_begin
17366 .global __cp_end
17367 @@ -22,8 +23,6 @@ __cp_begin:
17368 svc 0
17369 __cp_end:
17370 ldmfd sp!,{r4,r5,r6,r7,lr}
17371 - tst lr,#1
17372 - moveq pc,lr
17373 bx lr
17374 __cp_cancel:
17375 ldmfd sp!,{r4,r5,r6,r7,lr}
17376 --- a/src/thread/microblaze/syscall_cp.s
17377 +++ b/src/thread/microblaze/syscall_cp.s
17378 @@ -11,7 +11,7 @@
17379 __syscall_cp_asm:
17380 __cp_begin:
17381 lwi r5, r5, 0
17382 - bnei r5, __cancel
17383 + bnei r5, __cp_cancel
17384 addi r12, r6, 0
17385 add r5, r7, r0
17386 add r6, r8, r0
17387 @@ -23,3 +23,5 @@ __cp_begin:
17388 __cp_end:
17389 rtsd r15, 8
17390 nop
17391 +__cp_cancel:
17392 + bri __cancel
17393 --- a/src/thread/or1k/syscall_cp.s
17394 +++ b/src/thread/or1k/syscall_cp.s
17395 @@ -12,7 +12,7 @@ __syscall_cp_asm:
17396 __cp_begin:
17397 l.lwz r3, 0(r3)
17398 l.sfeqi r3, 0
17399 - l.bnf __cancel
17400 + l.bnf __cp_cancel
17401 l.ori r11, r4, 0
17402 l.ori r3, r5, 0
17403 l.ori r4, r6, 0
17404 @@ -24,3 +24,6 @@ __cp_begin:
17405 __cp_end:
17406 l.jr r9
17407 l.nop
17408 +__cp_cancel:
17409 + l.j __cancel
17410 + l.nop
17411 --- a/src/thread/powerpc/syscall_cp.s
17412 +++ b/src/thread/powerpc/syscall_cp.s
17413 @@ -38,7 +38,7 @@ __cp_begin:
17414 cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7.
17415 beq+ cr7, 1f #jump to label 1 if r0 was 0
17416
17417 - b __cancel #else call cancel
17418 + b __cp_cancel #else call cancel
17419 1:
17420 #ok, the cancel flag was not set
17421 # syscall: number goes to r0, the rest 3-8
17422 @@ -55,3 +55,5 @@ __cp_end:
17423 #else negate result.
17424 neg 3, 3
17425 blr
17426 +__cp_cancel:
17427 + b __cancel
17428 --- a/src/thread/pthread_cancel.c
17429 +++ b/src/thread/pthread_cancel.c
17430 @@ -1,12 +1,11 @@
17431 +#define _GNU_SOURCE
17432 #include <string.h>
17433 #include "pthread_impl.h"
17434 #include "syscall.h"
17435 #include "libc.h"
17436
17437 -#ifdef SHARED
17438 __attribute__((__visibility__("hidden")))
17439 -#endif
17440 -long __cancel(), __cp_cancel(), __syscall_cp_asm(), __syscall_cp_c();
17441 +long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
17442
17443 long __cancel()
17444 {
17445 @@ -17,12 +16,6 @@ long __cancel()
17446 return -ECANCELED;
17447 }
17448
17449 -/* If __syscall_cp_asm has adjusted the stack pointer, it must provide a
17450 - * definition of __cp_cancel to undo those adjustments and call __cancel.
17451 - * Otherwise, __cancel provides a definition for __cp_cancel. */
17452 -
17453 -weak_alias(__cancel, __cp_cancel);
17454 -
17455 long __syscall_cp_asm(volatile void *, syscall_arg_t,
17456 syscall_arg_t, syscall_arg_t, syscall_arg_t,
17457 syscall_arg_t, syscall_arg_t, syscall_arg_t);
17458 @@ -52,24 +45,22 @@ static void _sigaddset(sigset_t *set, in
17459 set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1);
17460 }
17461
17462 -#ifdef SHARED
17463 __attribute__((__visibility__("hidden")))
17464 -#endif
17465 -extern const char __cp_begin[1], __cp_end[1];
17466 +extern const char __cp_begin[1], __cp_end[1], __cp_cancel[1];
17467
17468 static void cancel_handler(int sig, siginfo_t *si, void *ctx)
17469 {
17470 pthread_t self = __pthread_self();
17471 ucontext_t *uc = ctx;
17472 - const char *ip = ((char **)&uc->uc_mcontext)[CANCEL_REG_IP];
17473 + uintptr_t pc = uc->uc_mcontext.MC_PC;
17474
17475 a_barrier();
17476 if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return;
17477
17478 _sigaddset(&uc->uc_sigmask, SIGCANCEL);
17479
17480 - if (self->cancelasync || ip >= __cp_begin && ip < __cp_end) {
17481 - ((char **)&uc->uc_mcontext)[CANCEL_REG_IP] = (char *)__cp_cancel;
17482 + if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
17483 + uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
17484 return;
17485 }
17486
17487 --- /dev/null
17488 +++ b/src/thread/sh/__set_thread_area.c
17489 @@ -0,0 +1,40 @@
17490 +#include "pthread_impl.h"
17491 +#include "libc.h"
17492 +#include <elf.h>
17493 +
17494 +/* Also perform sh-specific init */
17495 +
17496 +#define CPU_HAS_LLSC 0x0040
17497 +#define CPU_HAS_CAS_L 0x0400
17498 +
17499 +__attribute__((__visibility__("hidden")))
17500 +extern const char __sh_cas_gusa[], __sh_cas_llsc[], __sh_cas_imask[], __sh_cas_cas_l[];
17501 +
17502 +__attribute__((__visibility__("hidden")))
17503 +const void *__sh_cas_ptr;
17504 +
17505 +__attribute__((__visibility__("hidden")))
17506 +unsigned __sh_nommu;
17507 +
17508 +int __set_thread_area(void *p)
17509 +{
17510 + size_t *aux;
17511 + __asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" );
17512 +#ifndef __SH4A__
17513 + __sh_cas_ptr = __sh_cas_gusa;
17514 +#if !defined(__SH3__) && !defined(__SH4__)
17515 + for (aux=libc.auxv; *aux; aux+=2) {
17516 + if (*aux != AT_PLATFORM) continue;
17517 + const char *s = (void *)aux[1];
17518 + if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break;
17519 + __sh_cas_ptr = __sh_cas_imask;
17520 + __sh_nommu = 1;
17521 + }
17522 +#endif
17523 + if (__hwcap & CPU_HAS_CAS_L)
17524 + __sh_cas_ptr = __sh_cas_cas_l;
17525 + else if (__hwcap & CPU_HAS_LLSC)
17526 + __sh_cas_ptr = __sh_cas_llsc;
17527 +#endif
17528 + return 0;
17529 +}
17530 --- /dev/null
17531 +++ b/src/thread/sh/__unmapself.c
17532 @@ -0,0 +1,24 @@
17533 +#include "pthread_impl.h"
17534 +
17535 +void __unmapself_sh_mmu(void *, size_t);
17536 +void __unmapself_sh_nommu(void *, size_t);
17537 +
17538 +#if !defined(__SH3__) && !defined(__SH4__)
17539 +#define __unmapself __unmapself_sh_nommu
17540 +#include "dynlink.h"
17541 +#undef CRTJMP
17542 +#define CRTJMP(pc,sp) __asm__ __volatile__( \
17543 + "mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \
17544 + : : "r"(pc), "r"(sp) : "r0", "memory" )
17545 +#include "../__unmapself.c"
17546 +#undef __unmapself
17547 +extern __attribute__((__visibility__("hidden"))) unsigned __sh_nommu;
17548 +#else
17549 +#define __sh_nommu 0
17550 +#endif
17551 +
17552 +void __unmapself(void *base, size_t size)
17553 +{
17554 + if (__sh_nommu) __unmapself_sh_nommu(base, size);
17555 + else __unmapself_sh_mmu(base, size);
17556 +}
17557 --- a/src/thread/sh/__unmapself.s
17558 +++ /dev/null
17559 @@ -1,22 +0,0 @@
17560 -.text
17561 -.global __unmapself_sh_mmu
17562 -.type __unmapself_sh_mmu, @function
17563 -__unmapself_sh_mmu:
17564 - mov #91, r3 ! SYS_munmap
17565 - trapa #31
17566 -
17567 - or r0, r0
17568 - or r0, r0
17569 - or r0, r0
17570 - or r0, r0
17571 - or r0, r0
17572 -
17573 - mov #1, r3 ! SYS_exit
17574 - mov #0, r4
17575 - trapa #31
17576 -
17577 - or r0, r0
17578 - or r0, r0
17579 - or r0, r0
17580 - or r0, r0
17581 - or r0, r0
17582 --- /dev/null
17583 +++ b/src/thread/sh/__unmapself_mmu.s
17584 @@ -0,0 +1,22 @@
17585 +.text
17586 +.global __unmapself_sh_mmu
17587 +.type __unmapself_sh_mmu, @function
17588 +__unmapself_sh_mmu:
17589 + mov #91, r3 ! SYS_munmap
17590 + trapa #31
17591 +
17592 + or r0, r0
17593 + or r0, r0
17594 + or r0, r0
17595 + or r0, r0
17596 + or r0, r0
17597 +
17598 + mov #1, r3 ! SYS_exit
17599 + mov #0, r4
17600 + trapa #31
17601 +
17602 + or r0, r0
17603 + or r0, r0
17604 + or r0, r0
17605 + or r0, r0
17606 + or r0, r0
17607 --- /dev/null
17608 +++ b/src/thread/sh/atomics.s
17609 @@ -0,0 +1,65 @@
17610 +/* Contract for all versions is same as cas.l r2,r3,@r0
17611 + * pr and r1 are also clobbered (by jsr & r1 as temp).
17612 + * r0,r2,r4-r15 must be preserved.
17613 + * r3 contains result (==r2 iff cas succeeded). */
17614 +
17615 + .align 2
17616 +.global __sh_cas_gusa
17617 +.hidden __sh_cas_gusa
17618 +__sh_cas_gusa:
17619 + mov.l r5,@-r15
17620 + mov.l r4,@-r15
17621 + mov r0,r4
17622 + mova 1f,r0
17623 + mov r15,r1
17624 + mov #(0f-1f),r15
17625 +0: mov.l @r4,r5
17626 + cmp/eq r5,r2
17627 + bf 1f
17628 + mov.l r3,@r4
17629 +1: mov r1,r15
17630 + mov r5,r3
17631 + mov r4,r0
17632 + mov.l @r15+,r4
17633 + rts
17634 + mov.l @r15+,r5
17635 +
17636 +.global __sh_cas_llsc
17637 +.hidden __sh_cas_llsc
17638 +__sh_cas_llsc:
17639 + mov r0,r1
17640 + synco
17641 +0: movli.l @r1,r0
17642 + cmp/eq r0,r2
17643 + bf 1f
17644 + mov r3,r0
17645 + movco.l r0,@r1
17646 + bf 0b
17647 + mov r2,r0
17648 +1: synco
17649 + mov r0,r3
17650 + rts
17651 + mov r1,r0
17652 +
17653 +.global __sh_cas_imask
17654 +.hidden __sh_cas_imask
17655 +__sh_cas_imask:
17656 + mov r0,r1
17657 + stc sr,r0
17658 + mov.l r0,@-r15
17659 + or #0xf0,r0
17660 + ldc r0,sr
17661 + mov.l @r1,r0
17662 + cmp/eq r0,r2
17663 + bf 1f
17664 + mov.l r3,@r1
17665 +1: ldc.l @r15+,sr
17666 + mov r0,r3
17667 + rts
17668 + mov r1,r0
17669 +
17670 +.global __sh_cas_cas_l
17671 +.hidden __sh_cas_cas_l
17672 +__sh_cas_cas_l:
17673 + rts
17674 + .word 0x2323 /* cas.l r2,r3,@r0 */
17675 --- a/src/thread/sh/syscall_cp.s
17676 +++ b/src/thread/sh/syscall_cp.s
17677 @@ -14,17 +14,8 @@ __syscall_cp_asm:
17678 __cp_begin:
17679 mov.l @r4, r4
17680 tst r4, r4
17681 - bt 2f
17682 -
17683 - mov.l L1, r0
17684 - braf r0
17685 - nop
17686 -1:
17687 -
17688 -.align 2
17689 -L1: .long __cancel@PLT-(1b-.)
17690 -
17691 -2: mov r5, r3
17692 + bf __cp_cancel
17693 + mov r5, r3
17694 mov r6, r4
17695 mov r7, r5
17696 mov.l @r15, r6
17697 @@ -43,3 +34,12 @@ __cp_end:
17698
17699 rts
17700 nop
17701 +
17702 +__cp_cancel:
17703 + mov.l 2f, r0
17704 + braf r0
17705 + nop
17706 +1:
17707 +
17708 +.align 2
17709 +2: .long __cancel@PCREL-(1b-.)
17710 --- a/src/thread/x32/syscall_cp.s
17711 +++ b/src/thread/x32/syscall_cp.s
17712 @@ -14,7 +14,7 @@ __syscall_cp_internal:
17713 __cp_begin:
17714 mov (%rdi),%eax
17715 test %eax,%eax
17716 - jnz __cancel
17717 + jnz __cp_cancel
17718 mov %rdi,%r11
17719 mov %rsi,%rax
17720 mov %rdx,%rdi
17721 @@ -27,3 +27,5 @@ __cp_begin:
17722 syscall
17723 __cp_end:
17724 ret
17725 +__cp_cancel:
17726 + jmp __cancel
17727 --- /dev/null
17728 +++ b/src/thread/x32/syscall_cp_fixup.c
17729 @@ -0,0 +1,38 @@
17730 +#include <sys/syscall.h>
17731 +
17732 +__attribute__((__visibility__("hidden")))
17733 +long __syscall_cp_internal(volatile void*, long long, long long, long long, long long,
17734 + long long, long long, long long);
17735 +
17736 +struct __timespec { long long tv_sec; long tv_nsec; };
17737 +struct __timespec_kernel { long long tv_sec; long long tv_nsec; };
17738 +#define __tsc(X) ((struct __timespec*)(unsigned long)(X))
17739 +#define __fixup(X) do { if(X) { \
17740 + ts->tv_sec = __tsc(X)->tv_sec; \
17741 + ts->tv_nsec = __tsc(X)->tv_nsec; \
17742 + (X) = (unsigned long)ts; } } while(0)
17743 +
17744 +__attribute__((__visibility__("hidden")))
17745 +long __syscall_cp_asm (volatile void * foo, long long n, long long a1, long long a2, long long a3,
17746 + long long a4, long long a5, long long a6)
17747 +{
17748 + struct __timespec_kernel ts[1];
17749 + switch (n) {
17750 + case SYS_mq_timedsend: case SYS_mq_timedreceive: case SYS_pselect6:
17751 + __fixup(a5);
17752 + break;
17753 + case SYS_futex:
17754 + if((a2 & (~128 /* FUTEX_PRIVATE_FLAG */)) == 0 /* FUTEX_WAIT */)
17755 + __fixup(a4);
17756 + break;
17757 + case SYS_clock_nanosleep:
17758 + case SYS_rt_sigtimedwait: case SYS_ppoll:
17759 + __fixup(a3);
17760 + break;
17761 + case SYS_nanosleep:
17762 + __fixup(a1);
17763 + break;
17764 + }
17765 + return __syscall_cp_internal(foo, n, a1, a2, a3, a4, a5, a6);
17766 +}
17767 +
17768 --- a/src/thread/x86_64/syscall_cp.s
17769 +++ b/src/thread/x86_64/syscall_cp.s
17770 @@ -14,7 +14,7 @@ __syscall_cp_asm:
17771 __cp_begin:
17772 mov (%rdi),%eax
17773 test %eax,%eax
17774 - jnz __cancel
17775 + jnz __cp_cancel
17776 mov %rdi,%r11
17777 mov %rsi,%rax
17778 mov %rdx,%rdi
17779 @@ -27,3 +27,5 @@ __cp_begin:
17780 syscall
17781 __cp_end:
17782 ret
17783 +__cp_cancel:
17784 + jmp __cancel
17785 --- a/src/time/clock_gettime.c
17786 +++ b/src/time/clock_gettime.c
17787 @@ -5,37 +5,54 @@
17788 #include "libc.h"
17789 #include "atomic.h"
17790
17791 -static int sc_clock_gettime(clockid_t clk, struct timespec *ts)
17792 +#ifdef VDSO_CGT_SYM
17793 +
17794 +void *__vdsosym(const char *, const char *);
17795 +
17796 +static void *volatile vdso_func;
17797 +
17798 +static int cgt_init(clockid_t clk, struct timespec *ts)
17799 {
17800 - int r = __syscall(SYS_clock_gettime, clk, ts);
17801 - if (!r) return r;
17802 - if (r == -ENOSYS) {
17803 - if (clk == CLOCK_REALTIME) {
17804 - __syscall(SYS_gettimeofday, ts, 0);
17805 - ts->tv_nsec = (int)ts->tv_nsec * 1000;
17806 - return 0;
17807 - }
17808 - r = -EINVAL;
17809 - }
17810 - errno = -r;
17811 - return -1;
17812 + void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
17813 + int (*f)(clockid_t, struct timespec *) =
17814 + (int (*)(clockid_t, struct timespec *))p;
17815 + a_cas_p(&vdso_func, (void *)cgt_init, p);
17816 + return f ? f(clk, ts) : -ENOSYS;
17817 }
17818
17819 -void *__vdsosym(const char *, const char *);
17820 +static void *volatile vdso_func = (void *)cgt_init;
17821 +
17822 +#endif
17823
17824 int __clock_gettime(clockid_t clk, struct timespec *ts)
17825 {
17826 + int r;
17827 +
17828 #ifdef VDSO_CGT_SYM
17829 - static int (*volatile cgt)(clockid_t, struct timespec *);
17830 - if (!cgt) {
17831 - void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
17832 - if (!f) f = (void *)sc_clock_gettime;
17833 - a_cas_p(&cgt, 0, f);
17834 + int (*f)(clockid_t, struct timespec *) =
17835 + (int (*)(clockid_t, struct timespec *))vdso_func;
17836 + if (f) {
17837 + r = f(clk, ts);
17838 + if (!r) return r;
17839 + if (r == -EINVAL) return __syscall_ret(r);
17840 + /* Fall through on errors other than EINVAL. Some buggy
17841 + * vdso implementations return ENOSYS for clocks they
17842 + * can't handle, rather than making the syscall. This
17843 + * also handles the case where cgt_init fails to find
17844 + * a vdso function to use. */
17845 }
17846 - return cgt(clk, ts);
17847 -#else
17848 - return sc_clock_gettime(clk, ts);
17849 #endif
17850 +
17851 + r = __syscall(SYS_clock_gettime, clk, ts);
17852 + if (r == -ENOSYS) {
17853 + if (clk == CLOCK_REALTIME) {
17854 + __syscall(SYS_gettimeofday, ts, 0);
17855 + ts->tv_nsec = (int)ts->tv_nsec * 1000;
17856 + return 0;
17857 + }
17858 + r = -EINVAL;
17859 + }
17860 + return __syscall_ret(r);
17861 }
17862
17863 weak_alias(__clock_gettime, clock_gettime);