summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux')
-rw-r--r--libc/sysdeps/linux/aarch64/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/aarch64/bits/fcntl.h26
-rw-r--r--libc/sysdeps/linux/aarch64/bits/hwcap.h99
-rw-r--r--libc/sysdeps/linux/aarch64/bits/sigstack.h56
-rw-r--r--libc/sysdeps/linux/aarch64/bits/syscalls.h51
-rw-r--r--libc/sysdeps/linux/aarch64/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/aarch64/crt1.S14
-rw-r--r--libc/sysdeps/linux/aarch64/sys/ucontext.h5
-rw-r--r--libc/sysdeps/linux/alpha/__syscall_error.c2
-rw-r--r--libc/sysdeps/linux/alpha/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/alpha/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/alpha/bits/msq.h4
-rw-r--r--libc/sysdeps/linux/alpha/bits/resource.h23
-rw-r--r--libc/sysdeps/linux/alpha/bits/sem.h4
-rw-r--r--libc/sysdeps/linux/alpha/bits/shm.h12
-rw-r--r--libc/sysdeps/linux/alpha/bits/stat.h4
-rw-r--r--libc/sysdeps/linux/alpha/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/arc/__syscall_error.c2
-rw-r--r--libc/sysdeps/linux/arc/asm.h91
-rw-r--r--libc/sysdeps/linux/arc/bits/atomic.h76
-rwxr-xr-xlibc/sysdeps/linux/arc/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/arc/bits/syscalls.h6
-rw-r--r--libc/sysdeps/linux/arc/crt1.S4
-rw-r--r--libc/sysdeps/linux/arc/sigrestorer.S3
-rw-r--r--libc/sysdeps/linux/arm/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/arm/bits/elf-fdpic.h2
-rw-r--r--libc/sysdeps/linux/arm/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/arm/bits/hwcap.h50
-rw-r--r--libc/sysdeps/linux/arm/bits/kernel_stat.h5
-rw-r--r--libc/sysdeps/linux/arm/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/arm/crt1.S21
-rw-r--r--libc/sysdeps/linux/avr32/bits/fcntl.h1
-rw-r--r--libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/bfin/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/bfin/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/bfin/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/c6x/bits/fcntl.h1
-rw-r--r--libc/sysdeps/linux/c6x/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/c6x/bits/resource.h9
-rwxr-xr-x[-rw-r--r--]libc/sysdeps/linux/c6x/bits/syscalls.h4
-rw-r--r--libc/sysdeps/linux/c6x/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/common-generic/bits/kernel_stat.h2
-rw-r--r--libc/sysdeps/linux/common-generic/bits/stat.h12
-rw-r--r--libc/sysdeps/linux/common/Makefile.in3
-rw-r--r--libc/sysdeps/linux/common/__rt_sigtimedwait.c16
-rw-r--r--libc/sysdeps/linux/common/__rt_sigwaitinfo.c2
-rw-r--r--libc/sysdeps/linux/common/adjtimex.c10
-rw-r--r--libc/sysdeps/linux/common/alarm.c2
-rw-r--r--libc/sysdeps/linux/common/bits/hwcap.h22
-rw-r--r--libc/sysdeps/linux/common/bits/ipc.h9
-rw-r--r--libc/sysdeps/linux/common/bits/jmp_buf_tag.h37
-rw-r--r--libc/sysdeps/linux/common/bits/kernel-features.h5
-rw-r--r--libc/sysdeps/linux/common/bits/mman-linux.h1
-rw-r--r--libc/sysdeps/linux/common/bits/msq.h10
-rw-r--r--libc/sysdeps/linux/common/bits/resource.h17
-rw-r--r--libc/sysdeps/linux/common/bits/sched.h1
-rw-r--r--libc/sysdeps/linux/common/bits/sem.h29
-rw-r--r--libc/sysdeps/linux/common/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/common/bits/stab.def4
-rw-r--r--libc/sysdeps/linux/common/bits/stat.h4
-rw-r--r--libc/sysdeps/linux/common/bits/statx.h93
-rwxr-xr-x[-rw-r--r--]libc/sysdeps/linux/common/bits/syscalls-common.h54
-rw-r--r--libc/sysdeps/linux/common/bits/typesizes.h12
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_uwchar.h1
-rw-r--r--libc/sysdeps/linux/common/bits/utmp.h2
-rw-r--r--libc/sysdeps/linux/common/bits/utmpx.h2
-rw-r--r--libc/sysdeps/linux/common/bits/wchar.h32
-rw-r--r--libc/sysdeps/linux/common/clock_adjtime.c6
-rw-r--r--libc/sysdeps/linux/common/clock_getres.c16
-rw-r--r--libc/sysdeps/linux/common/clock_gettime.c36
-rw-r--r--libc/sysdeps/linux/common/clock_settime.c10
-rw-r--r--libc/sysdeps/linux/common/fexecve.c52
-rw-r--r--libc/sysdeps/linux/common/fstat.c21
-rw-r--r--libc/sysdeps/linux/common/fstat64.c19
-rw-r--r--libc/sysdeps/linux/common/fstatat.c42
-rw-r--r--libc/sysdeps/linux/common/fstatat64.c23
-rw-r--r--libc/sysdeps/linux/common/futimens.c2
-rw-r--r--libc/sysdeps/linux/common/futimesat.c27
-rw-r--r--libc/sysdeps/linux/common/getrlimit.c56
-rw-r--r--libc/sysdeps/linux/common/getrlimit64.c26
-rwxr-xr-x[-rw-r--r--]libc/sysdeps/linux/common/gettimeofday.c21
-rw-r--r--libc/sysdeps/linux/common/lstat.c22
-rw-r--r--libc/sysdeps/linux/common/lstat64.c19
-rw-r--r--libc/sysdeps/linux/common/name_to_handle_at.c36
-rw-r--r--libc/sysdeps/linux/common/nanosleep.c16
-rw-r--r--libc/sysdeps/linux/common/not-cancel.h4
-rw-r--r--libc/sysdeps/linux/common/open.c2
-rw-r--r--libc/sysdeps/linux/common/open64.c4
-rw-r--r--libc/sysdeps/linux/common/open_by_handle_at.c34
-rw-r--r--libc/sysdeps/linux/common/openat64.c10
-rw-r--r--libc/sysdeps/linux/common/poll.c7
-rw-r--r--libc/sysdeps/linux/common/ppoll.c11
-rw-r--r--libc/sysdeps/linux/common/prlimit.c76
-rw-r--r--libc/sysdeps/linux/common/prlimit64.c36
-rw-r--r--libc/sysdeps/linux/common/pselect.c12
-rw-r--r--libc/sysdeps/linux/common/renameat.c14
-rw-r--r--libc/sysdeps/linux/common/sched_rr_get_interval.c5
-rw-r--r--libc/sysdeps/linux/common/select.c16
-rw-r--r--libc/sysdeps/linux/common/setitimer.c32
-rw-r--r--libc/sysdeps/linux/common/setrlimit.c53
-rw-r--r--libc/sysdeps/linux/common/setrlimit64.c24
-rw-r--r--libc/sysdeps/linux/common/settimeofday.c21
-rw-r--r--libc/sysdeps/linux/common/stat.c20
-rw-r--r--libc/sysdeps/linux/common/stat64.c18
-rw-r--r--libc/sysdeps/linux/common/statx_cp.c76
-rw-r--r--libc/sysdeps/linux/common/statx_cp.h22
-rw-r--r--libc/sysdeps/linux/common/stubs.c6
-rw-r--r--libc/sysdeps/linux/common/sys/ptrace.h2
-rw-r--r--libc/sysdeps/linux/common/sys/random.h1
-rw-r--r--libc/sysdeps/linux/common/sysctl.c2
-rw-r--r--libc/sysdeps/linux/common/time.c2
-rw-r--r--libc/sysdeps/linux/common/timerfd.c21
-rw-r--r--libc/sysdeps/linux/common/umount2.c2
-rw-r--r--libc/sysdeps/linux/common/utimensat.c25
-rw-r--r--libc/sysdeps/linux/common/utimes.c4
-rw-r--r--libc/sysdeps/linux/common/wait4.c69
-rw-r--r--libc/sysdeps/linux/cris/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/cris/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/cris/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/csky/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/csky/__syscall_error.c2
-rw-r--r--libc/sysdeps/linux/csky/bits/fcntl.h13
-rw-r--r--libc/sysdeps/linux/csky/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/csky/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/csky/clone.c2
-rw-r--r--libc/sysdeps/linux/frv/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/frv/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/frv/bits/stat.h16
-rw-r--r--libc/sysdeps/linux/frv/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/frv/sysdep.c2
-rw-r--r--libc/sysdeps/linux/h8300/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/h8300/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/hppa/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/hppa/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/hppa/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/hppa/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/i386/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/i386/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/i386/bits/fenv.h10
-rw-r--r--libc/sysdeps/linux/i386/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/i386/crt1.S20
-rw-r--r--libc/sysdeps/linux/i386/sigaction.c7
-rw-r--r--libc/sysdeps/linux/ia64/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/ia64/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/ia64/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/ia64/bits/msq.h4
-rw-r--r--libc/sysdeps/linux/ia64/bits/sem.h4
-rw-r--r--libc/sysdeps/linux/ia64/bits/shm.h12
-rw-r--r--libc/sysdeps/linux/ia64/bits/stat.h4
-rw-r--r--libc/sysdeps/linux/ia64/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/kvx/Makefile13
-rw-r--r--libc/sysdeps/linux/kvx/Makefile.arch10
-rw-r--r--libc/sysdeps/linux/kvx/__longjmp.S53
-rw-r--r--libc/sysdeps/linux/kvx/__syscall_error.c19
-rw-r--r--libc/sysdeps/linux/kvx/bits/atomic.h195
-rw-r--r--libc/sysdeps/linux/kvx/bits/endian.h13
-rw-r--r--libc/sysdeps/linux/kvx/bits/fcntl.h229
-rw-r--r--libc/sysdeps/linux/kvx/bits/fenv.h106
-rw-r--r--libc/sysdeps/linux/kvx/bits/kernel_types.h44
-rw-r--r--libc/sysdeps/linux/kvx/bits/posix_types.h14
-rw-r--r--libc/sysdeps/linux/kvx/bits/sem.h84
-rw-r--r--libc/sysdeps/linux/kvx/bits/setjmp.h46
-rw-r--r--libc/sysdeps/linux/kvx/bits/stackinfo.h (renamed from libc/sysdeps/linux/i386/bits/wchar.h)18
-rw-r--r--libc/sysdeps/linux/kvx/bits/stat.h145
-rw-r--r--libc/sysdeps/linux/kvx/bits/statfs.h64
-rw-r--r--libc/sysdeps/linux/kvx/bits/syscalls.h80
-rw-r--r--libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h44
-rw-r--r--libc/sysdeps/linux/kvx/bits/wordsize.h9
-rw-r--r--libc/sysdeps/linux/kvx/bsd-_setjmp.S18
-rw-r--r--libc/sysdeps/linux/kvx/bsd-setjmp.S17
-rw-r--r--libc/sysdeps/linux/kvx/cachectl.c15
-rw-r--r--libc/sysdeps/linux/kvx/clone.S100
-rw-r--r--libc/sysdeps/linux/kvx/crt1.S83
-rw-r--r--libc/sysdeps/linux/kvx/crti.S31
-rw-r--r--libc/sysdeps/linux/kvx/crtn.S33
-rw-r--r--libc/sysdeps/linux/kvx/jmpbuf-offsets.h50
-rw-r--r--libc/sysdeps/linux/kvx/jmpbuf-unwind.h30
-rw-r--r--libc/sysdeps/linux/kvx/setjmp.S59
-rw-r--r--libc/sysdeps/linux/kvx/sys/cachectl.h21
-rw-r--r--libc/sysdeps/linux/kvx/sys/procfs.h96
-rw-r--r--libc/sysdeps/linux/kvx/sys/ucontext.h28
-rw-r--r--libc/sysdeps/linux/kvx/sys/user.h1
-rw-r--r--libc/sysdeps/linux/kvx/sysdep.h49
-rw-r--r--libc/sysdeps/linux/kvx/vfork.S47
-rw-r--r--libc/sysdeps/linux/lm32/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/lm32/bits/kernel_stat.h8
-rw-r--r--libc/sysdeps/linux/lm32/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/m68k/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/m68k/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/m68k/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/m68k/bits/stat.h4
-rw-r--r--libc/sysdeps/linux/m68k/crt1.S10
-rw-r--r--libc/sysdeps/linux/metag/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/metag/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/metag/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/metag/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/microblaze/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/microblaze/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/mips/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/mips/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/mips/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/mips/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/mips/bits/msq.h4
-rw-r--r--libc/sysdeps/linux/mips/bits/resource.h21
-rw-r--r--libc/sysdeps/linux/mips/bits/sem.h17
-rw-r--r--libc/sysdeps/linux/mips/bits/shm.h12
-rw-r--r--libc/sysdeps/linux/mips/bits/syscalls.h18
-rw-r--r--libc/sysdeps/linux/mips/crt1.S23
-rw-r--r--libc/sysdeps/linux/nds32/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/nds32/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/nds32/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/nds32/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/nds32/bits/kernel_types.h22
-rw-r--r--libc/sysdeps/linux/nds32/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/nds32/bits/stat.h4
-rw-r--r--libc/sysdeps/linux/nds32/bits/syscalls.h3
-rw-r--r--libc/sysdeps/linux/nds32/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/nds32/sys/ucontext.h6
-rw-r--r--libc/sysdeps/linux/nds32/vfork.S129
-rw-r--r--libc/sysdeps/linux/nios2/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/nios2/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/nios2/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/or1k/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/or1k/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/or1k/bits/kernel_stat.h27
-rw-r--r--libc/sysdeps/linux/or1k/or1k_clone.S8
-rw-r--r--libc/sysdeps/linux/or1k/sysdep.h32
-rw-r--r--libc/sysdeps/linux/powerpc/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/powerpc/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/powerpc/bits/ioctl-types.h74
-rw-r--r--libc/sysdeps/linux/powerpc/bits/ipc.h8
-rw-r--r--libc/sysdeps/linux/powerpc/bits/kernel_stat.h10
-rw-r--r--libc/sysdeps/linux/powerpc/bits/msq.h10
-rw-r--r--libc/sysdeps/linux/powerpc/bits/sem.h24
-rw-r--r--libc/sysdeps/linux/powerpc/bits/shm.h20
-rw-r--r--libc/sysdeps/linux/powerpc/bits/stat.h8
-rw-r--r--libc/sysdeps/linux/powerpc/bits/termios.h48
-rw-r--r--libc/sysdeps/linux/powerpc/crt1.S23
-rw-r--r--libc/sysdeps/linux/powerpc/sys/procfs.h2
-rw-r--r--libc/sysdeps/linux/riscv32/Makefile6
-rw-r--r--libc/sysdeps/linux/riscv32/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/riscv32/__longjmp.S57
-rw-r--r--libc/sysdeps/linux/riscv32/__syscall_error.c18
-rw-r--r--libc/sysdeps/linux/riscv32/bits/atomic.h170
-rw-r--r--libc/sysdeps/linux/riscv32/bits/endian.h5
-rw-r--r--libc/sysdeps/linux/riscv32/bits/fcntl.h231
-rw-r--r--libc/sysdeps/linux/riscv32/bits/fenv.h73
-rw-r--r--libc/sysdeps/linux/riscv32/bits/kernel_types.h42
-rw-r--r--libc/sysdeps/linux/riscv32/bits/mman.h38
-rw-r--r--libc/sysdeps/linux/riscv32/bits/setjmp.h38
-rw-r--r--libc/sysdeps/linux/riscv32/bits/shm.h90
-rw-r--r--libc/sysdeps/linux/riscv32/bits/sigcontext.h32
-rw-r--r--libc/sysdeps/linux/riscv32/bits/stackinfo.h11
-rw-r--r--libc/sysdeps/linux/riscv32/bits/syscalls.h85
-rw-r--r--libc/sysdeps/linux/riscv32/bits/uClibc_arch_features.h36
-rw-r--r--libc/sysdeps/linux/riscv32/bits/uClibc_page.h28
-rw-r--r--libc/sysdeps/linux/riscv32/bits/wordsize.h30
-rw-r--r--libc/sysdeps/linux/riscv32/bsd-_setjmp.c1
-rw-r--r--libc/sysdeps/linux/riscv32/bsd-setjmp.c1
-rw-r--r--libc/sysdeps/linux/riscv32/cache.c55
-rw-r--r--libc/sysdeps/linux/riscv32/clone.S86
-rw-r--r--libc/sysdeps/linux/riscv32/crt1.S85
-rw-r--r--libc/sysdeps/linux/riscv32/crti.S17
-rw-r--r--libc/sysdeps/linux/riscv32/crtn.S13
-rw-r--r--libc/sysdeps/linux/riscv32/getcontext.S74
-rw-r--r--libc/sysdeps/linux/riscv32/jmpbuf-offsets.h23
-rw-r--r--libc/sysdeps/linux/riscv32/jmpbuf-unwind.h43
-rw-r--r--libc/sysdeps/linux/riscv32/setcontext.S112
-rw-r--r--libc/sysdeps/linux/riscv32/setjmp.S73
-rw-r--r--libc/sysdeps/linux/riscv32/swapcontext.S122
-rw-r--r--libc/sysdeps/linux/riscv32/sys/asm.h67
-rw-r--r--libc/sysdeps/linux/riscv32/sys/procfs.h114
-rw-r--r--libc/sysdeps/linux/riscv32/sys/ucontext.h108
-rw-r--r--libc/sysdeps/linux/riscv32/sys/user.h1
-rw-r--r--libc/sysdeps/linux/riscv32/sysdep.h126
-rw-r--r--libc/sysdeps/linux/riscv32/vfork.S42
-rw-r--r--libc/sysdeps/linux/riscv64/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/riscv64/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/riscv64/bits/atomic.h170
-rw-r--r--libc/sysdeps/linux/riscv64/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/riscv64/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/riscv64/bits/uClibc_arch_features.h9
-rw-r--r--libc/sysdeps/linux/riscv64/bits/uClibc_page.h34
-rw-r--r--libc/sysdeps/linux/riscv64/bits/wordsize.h3
-rw-r--r--libc/sysdeps/linux/riscv64/cache.c55
-rw-r--r--libc/sysdeps/linux/riscv64/clone.S8
-rw-r--r--libc/sysdeps/linux/riscv64/crt1.S3
-rw-r--r--libc/sysdeps/linux/riscv64/jmpbuf-unwind.h7
-rw-r--r--libc/sysdeps/linux/riscv64/setjmp.S2
-rw-r--r--libc/sysdeps/linux/riscv64/sys/asm.h6
-rw-r--r--libc/sysdeps/linux/riscv64/sys/ucontext.h2
-rw-r--r--libc/sysdeps/linux/riscv64/sysdep.h1
-rw-r--r--libc/sysdeps/linux/sh/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/sh/bits/kernel_stat.h4
-rw-r--r--libc/sysdeps/linux/sh/bits/kernel_types.h2
-rw-r--r--libc/sysdeps/linux/sh/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/sparc/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/sparc/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/sparc/bits/fcntl.h11
-rw-r--r--libc/sysdeps/linux/sparc/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/sparc/bits/msq.h4
-rw-r--r--libc/sysdeps/linux/sparc/bits/resource.h21
-rw-r--r--libc/sysdeps/linux/sparc/bits/sem.h22
-rw-r--r--libc/sysdeps/linux/sparc/bits/shm.h12
-rw-r--r--libc/sysdeps/linux/sparc/bits/stat.h8
-rw-r--r--libc/sysdeps/linux/sparc/bits/typesizes.h12
-rw-r--r--libc/sysdeps/linux/sparc/sigaction.c25
-rw-r--r--libc/sysdeps/linux/sparc/sigreturn_stub.S14
-rw-r--r--libc/sysdeps/linux/sparc/sysdep.h9
-rw-r--r--libc/sysdeps/linux/sparc64/Makefile.arch2
-rw-r--r--libc/sysdeps/linux/sparc64/__longjmp.S7
-rw-r--r--libc/sysdeps/linux/sparc64/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/sparc64/bits/fcntl.h11
-rw-r--r--libc/sysdeps/linux/sparc64/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/sparc64/bits/msq.h4
-rw-r--r--libc/sysdeps/linux/sparc64/bits/resource.h21
-rw-r--r--libc/sysdeps/linux/sparc64/bits/sem.h4
-rw-r--r--libc/sysdeps/linux/sparc64/bits/setjmp.h1
-rw-r--r--libc/sysdeps/linux/sparc64/bits/shm.h12
-rw-r--r--libc/sysdeps/linux/sparc64/bits/stat.h8
-rw-r--r--libc/sysdeps/linux/sparc64/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/sparc64/jmpbuf-offsets.h2
-rw-r--r--libc/sysdeps/linux/sparc64/setjmp.S7
-rw-r--r--libc/sysdeps/linux/sparc64/sigaction.c10
-rw-r--r--libc/sysdeps/linux/sparc64/sigreturn_stub.S10
-rw-r--r--libc/sysdeps/linux/sparc64/sysdep.h9
-rw-r--r--libc/sysdeps/linux/tile/__syscall_error.c2
-rw-r--r--libc/sysdeps/linux/tile/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/tile/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/tile/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/x86_64/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/x86_64/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/x86_64/bits/fenv.h10
-rw-r--r--libc/sysdeps/linux/x86_64/bits/kernel_stat.h2
-rw-r--r--libc/sysdeps/linux/x86_64/bits/msq.h10
-rw-r--r--libc/sysdeps/linux/x86_64/bits/sem.h8
-rw-r--r--libc/sysdeps/linux/x86_64/bits/shm.h18
-rw-r--r--libc/sysdeps/linux/x86_64/bits/stat.h8
-rw-r--r--libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h3
-rw-r--r--libc/sysdeps/linux/x86_64/crt1.S16
-rw-r--r--libc/sysdeps/linux/xtensa/Makefile.arch3
-rw-r--r--libc/sysdeps/linux/xtensa/__start_context.S100
-rw-r--r--libc/sysdeps/linux/xtensa/__syscall_error.c4
-rw-r--r--libc/sysdeps/linux/xtensa/bits/atomic.h177
-rw-r--r--libc/sysdeps/linux/xtensa/bits/fcntl.h7
-rw-r--r--libc/sysdeps/linux/xtensa/bits/ipc.h4
-rw-r--r--libc/sysdeps/linux/xtensa/bits/kernel_stat.h6
-rw-r--r--libc/sysdeps/linux/xtensa/bits/msq.h16
-rw-r--r--libc/sysdeps/linux/xtensa/bits/shm.h24
-rw-r--r--libc/sysdeps/linux/xtensa/bits/stat.h8
-rw-r--r--libc/sysdeps/linux/xtensa/bits/xtensa-config.h6
-rw-r--r--libc/sysdeps/linux/xtensa/crt1.S27
-rw-r--r--libc/sysdeps/linux/xtensa/getcontext.S99
-rw-r--r--libc/sysdeps/linux/xtensa/makecontext.c179
-rw-r--r--libc/sysdeps/linux/xtensa/setcontext.S116
-rw-r--r--libc/sysdeps/linux/xtensa/swapcontext.S173
-rw-r--r--libc/sysdeps/linux/xtensa/sysdep.h7
-rw-r--r--libc/sysdeps/linux/xtensa/ucontext_i.sym15
359 files changed, 7908 insertions, 898 deletions
diff --git a/libc/sysdeps/linux/aarch64/__syscall_error.c b/libc/sysdeps/linux/aarch64/__syscall_error.c
index 2b642e816..c682aae49 100644
--- a/libc/sysdeps/linux/aarch64/__syscall_error.c
+++ b/libc/sysdeps/linux/aarch64/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/aarch64/bits/fcntl.h b/libc/sysdeps/linux/aarch64/bits/fcntl.h
index 80657c008..dbe929351 100644
--- a/libc/sysdeps/linux/aarch64/bits/fcntl.h
+++ b/libc/sysdeps/linux/aarch64/bits/fcntl.h
@@ -52,6 +52,7 @@
# define O_DIRECT 0200000
# define O_NOATIME 01000000
# define O_PATH 010000000
+# define O_TMPFILE 020040000
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -93,8 +94,6 @@
#ifdef __USE_GNU
# define F_SETSIG 10 /* Set number of signal to be sent. */
# define F_GETSIG 11 /* Get number of signal to be sent. */
-# define F_SETOWN_EX 15 /* Get owner (thread receiving SIGIO). */
-# define F_GETOWN_EX 16 /* Set owner (thread receiving SIGIO). */
#endif
@@ -105,9 +104,9 @@
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Set pipe page size array. */
#endif
-#ifdef __USE_XOPEN2K8
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set. */
+ close-on-exit set on new fd. */
#endif
/* For F_[GET|SET]FD. */
@@ -169,25 +168,6 @@ struct flock64
};
#endif
-
-#ifdef __USE_GNU
-/* Owner types. */
-enum __pid_type
- {
- F_OWNER_TID = 0, /* Kernel thread. */
- F_OWNER_PID, /* Process. */
- F_OWNER_PGRP, /* Process group. */
- F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */
- };
-
-/* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */
-struct f_owner_ex
- {
- enum __pid_type type; /* Owner type of ID. */
- __pid_t pid; /* ID of owner. */
- };
-#endif
-
/* Define some more compatibility macros to be backward compatible with
BSD systems which did not managed to hide these kernel macros. */
#ifdef __USE_BSD
diff --git a/libc/sysdeps/linux/aarch64/bits/hwcap.h b/libc/sysdeps/linux/aarch64/bits/hwcap.h
new file mode 100644
index 000000000..20061f5d1
--- /dev/null
+++ b/libc/sysdeps/linux/aarch64/bits/hwcap.h
@@ -0,0 +1,99 @@
+/* Defines for bits in AT_HWCAP. AArch64 Linux version.
+ Copyright (C) 2016-2023 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#if !defined (_SYS_AUXV_H)
+# error "Never include <bits/hwcap.h> directly; use <sys/auxv.h> instead."
+#endif
+
+/* The following must match the kernel's <asm/hwcap.h> and update the
+ list together with sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c. */
+#define HWCAP_FP (1 << 0)
+#define HWCAP_ASIMD (1 << 1)
+#define HWCAP_EVTSTRM (1 << 2)
+#define HWCAP_AES (1 << 3)
+#define HWCAP_PMULL (1 << 4)
+#define HWCAP_SHA1 (1 << 5)
+#define HWCAP_SHA2 (1 << 6)
+#define HWCAP_CRC32 (1 << 7)
+#define HWCAP_ATOMICS (1 << 8)
+#define HWCAP_FPHP (1 << 9)
+#define HWCAP_ASIMDHP (1 << 10)
+#define HWCAP_CPUID (1 << 11)
+#define HWCAP_ASIMDRDM (1 << 12)
+#define HWCAP_JSCVT (1 << 13)
+#define HWCAP_FCMA (1 << 14)
+#define HWCAP_LRCPC (1 << 15)
+#define HWCAP_DCPOP (1 << 16)
+#define HWCAP_SHA3 (1 << 17)
+#define HWCAP_SM3 (1 << 18)
+#define HWCAP_SM4 (1 << 19)
+#define HWCAP_ASIMDDP (1 << 20)
+#define HWCAP_SHA512 (1 << 21)
+#define HWCAP_SVE (1 << 22)
+#define HWCAP_ASIMDFHM (1 << 23)
+#define HWCAP_DIT (1 << 24)
+#define HWCAP_USCAT (1 << 25)
+#define HWCAP_ILRCPC (1 << 26)
+#define HWCAP_FLAGM (1 << 27)
+#define HWCAP_SSBS (1 << 28)
+#define HWCAP_SB (1 << 29)
+#define HWCAP_PACA (1 << 30)
+#define HWCAP_PACG (1UL << 31)
+
+#define HWCAP2_DCPODP (1 << 0)
+#define HWCAP2_SVE2 (1 << 1)
+#define HWCAP2_SVEAES (1 << 2)
+#define HWCAP2_SVEPMULL (1 << 3)
+#define HWCAP2_SVEBITPERM (1 << 4)
+#define HWCAP2_SVESHA3 (1 << 5)
+#define HWCAP2_SVESM4 (1 << 6)
+#define HWCAP2_FLAGM2 (1 << 7)
+#define HWCAP2_FRINT (1 << 8)
+#define HWCAP2_SVEI8MM (1 << 9)
+#define HWCAP2_SVEF32MM (1 << 10)
+#define HWCAP2_SVEF64MM (1 << 11)
+#define HWCAP2_SVEBF16 (1 << 12)
+#define HWCAP2_I8MM (1 << 13)
+#define HWCAP2_BF16 (1 << 14)
+#define HWCAP2_DGH (1 << 15)
+#define HWCAP2_RNG (1 << 16)
+#define HWCAP2_BTI (1 << 17)
+#define HWCAP2_MTE (1 << 18)
+#define HWCAP2_ECV (1 << 19)
+#define HWCAP2_AFP (1 << 20)
+#define HWCAP2_RPRES (1 << 21)
+#define HWCAP2_MTE3 (1 << 22)
+#define HWCAP2_SME (1 << 23)
+#define HWCAP2_SME_I16I64 (1 << 24)
+#define HWCAP2_SME_F64F64 (1 << 25)
+#define HWCAP2_SME_I8I32 (1 << 26)
+#define HWCAP2_SME_F16F32 (1 << 27)
+#define HWCAP2_SME_B16F32 (1 << 28)
+#define HWCAP2_SME_F32F32 (1 << 29)
+#define HWCAP2_SME_FA64 (1 << 30)
+#define HWCAP2_WFXT (1UL << 31)
+#define HWCAP2_EBF16 (1UL << 32)
+#define HWCAP2_SVE_EBF16 (1UL << 33)
+#define HWCAP2_CSSC (1UL << 34)
+#define HWCAP2_RPRFM (1UL << 35)
+#define HWCAP2_SVE2P1 (1UL << 36)
+#define HWCAP2_SME2 (1UL << 37)
+#define HWCAP2_SME2P1 (1UL << 38)
+#define HWCAP2_SME_I16I32 (1UL << 39)
+#define HWCAP2_SME_BI32I32 (1UL << 40)
+#define HWCAP2_SME_B16B16 (1UL << 41)
+#define HWCAP2_SME_F16F16 (1UL << 42)
diff --git a/libc/sysdeps/linux/aarch64/bits/sigstack.h b/libc/sysdeps/linux/aarch64/bits/sigstack.h
new file mode 100644
index 000000000..7cb89265d
--- /dev/null
+++ b/libc/sysdeps/linux/aarch64/bits/sigstack.h
@@ -0,0 +1,56 @@
+/* sigstack, sigaltstack definitions.
+ Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SIGNAL_H
+# error "Never include this file directly. Use <signal.h> instead"
+#endif
+
+
+#if defined __UCLIBC_SUSV4_LEGACY__ || !defined __UCLIBC_STRICT_HEADERS__
+/* Structure describing a signal stack (obsolete). */
+struct sigstack
+ {
+ void *ss_sp; /* Signal stack pointer. */
+ int ss_onstack; /* Nonzero if executing on this stack. */
+ };
+#endif
+
+
+/* Possible values for `ss_flags.'. */
+enum
+{
+ SS_ONSTACK = 1,
+#define SS_ONSTACK SS_ONSTACK
+ SS_DISABLE
+#define SS_DISABLE SS_DISABLE
+};
+
+/* Minimum stack size for a signal handler. */
+#define MINSIGSTKSZ 5120
+
+/* System default stack size. */
+#define SIGSTKSZ 16384
+
+
+/* Alternate, preferred interface. */
+typedef struct sigaltstack
+ {
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+ } stack_t;
diff --git a/libc/sysdeps/linux/aarch64/bits/syscalls.h b/libc/sysdeps/linux/aarch64/bits/syscalls.h
index 3c0d840ea..489736fe6 100644
--- a/libc/sysdeps/linux/aarch64/bits/syscalls.h
+++ b/libc/sysdeps/linux/aarch64/bits/syscalls.h
@@ -31,22 +31,55 @@ License along with the GNU C Library; if not, see
#ifndef __ASSEMBLER__
#include <errno.h>
-#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+/* For Linux we can use the system call table in the header file
+ * /usr/include/asm/unistd.h
+ * of the kernel. But these symbols do not follow the SYS_* syntax
+ * so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#define SYS_ify(syscall_name) (__NR_##syscall_name)
+
+/* Define a macro which expands into the inline wrapper code for a system
+ call. */
+# undef INLINE_SYSCALL
+# define INLINE_SYSCALL(name, nr, args...) \
+ ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
+ _sys_result = (unsigned long) -1; \
+ } \
+ (long) _sys_result; })
+
+# undef INTERNAL_SYSCALL_DECL
+# define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
({ long _sys_result; \
{ \
- register long _x8 __asm__ ("x8"); \
LOAD_ARGS_##nr (args) \
- _x8 = (name); \
- \
+ register long _x8 __asm__ ("x8") = (name); \
__asm__ volatile ( \
"svc 0 // syscall " # name \
- : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr \
- : "memory"); \
- \
+ : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \
_sys_result = _x0; \
} \
_sys_result; })
+# undef INTERNAL_SYSCALL
+# define INTERNAL_SYSCALL(name, err, nr, args...) \
+ INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
+
+# undef INTERNAL_SYSCALL_AARCH64
+# define INTERNAL_SYSCALL_AARCH64(name, err, nr, args...) \
+ INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
+
+# undef INTERNAL_SYSCALL_ERROR_P
+# define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned long) (val) >= (unsigned long) -4095)
+
+# undef INTERNAL_SYSCALL_ERRNO
+# define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
+
/* Macros for setting up inline __asm__ input regs */
# define ASM_ARGS_0
# define ASM_ARGS_1 , "r" (_x0)
@@ -102,5 +135,9 @@ License along with the GNU C Library; if not, see
_x6tmp = (long) (x6); \
_x6 = _x6tmp;
+# undef INTERNAL_SYSCALL_NCS
+# define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
+ INTERNAL_SYSCALL_RAW (number, err, nr, args)
+
#endif /* ! __ASSEMBLER__ */
#endif /* _BITS_SYSCALLS_H */
diff --git a/libc/sysdeps/linux/aarch64/bits/uClibc_arch_features.h b/libc/sysdeps/linux/aarch64/bits/uClibc_arch_features.h
index 7cae090ec..90042e815 100644
--- a/libc/sysdeps/linux/aarch64/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/aarch64/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target have a broken create_module() ? */
#define __UCLIBC_BROKEN_CREATE_MODULE__
diff --git a/libc/sysdeps/linux/aarch64/crt1.S b/libc/sysdeps/linux/aarch64/crt1.S
index 09d0327ac..e9f946894 100644
--- a/libc/sysdeps/linux/aarch64/crt1.S
+++ b/libc/sysdeps/linux/aarch64/crt1.S
@@ -48,6 +48,20 @@ _start:
mov x29, #0
mov x30, #0
+#ifdef L_rcrt1
+ /* Save off the atexit pointer */
+ mov x19, x0
+
+ /* Calculate load address... idk how this works, but it does */
+ adrp x0, _start
+
+ /* Do relocations */
+ bl reloc_static_pie
+
+ /* restore atexit pointer */
+ mov x0, x19
+#endif
+
/* Setup _fini in argument register */
mov x5, x0
diff --git a/libc/sysdeps/linux/aarch64/sys/ucontext.h b/libc/sysdeps/linux/aarch64/sys/ucontext.h
index dc7303b54..5f75cbbf3 100644
--- a/libc/sysdeps/linux/aarch64/sys/ucontext.h
+++ b/libc/sysdeps/linux/aarch64/sys/ucontext.h
@@ -45,12 +45,13 @@ typedef elf_fpregset_t fpregset_t;
typedef struct sigcontext mcontext_t;
/* Userlevel context. */
-typedef struct ucontext
+typedef struct ucontext_t
{
unsigned long uc_flags;
- struct ucontext *uc_link;
+ struct ucontext_t *uc_link;
stack_t uc_stack;
__sigset_t uc_sigmask;
+ unsigned char __reserved[128];
mcontext_t uc_mcontext;
} ucontext_t;
diff --git a/libc/sysdeps/linux/alpha/__syscall_error.c b/libc/sysdeps/linux/alpha/__syscall_error.c
index 7c081f3b5..c986e484d 100644
--- a/libc/sysdeps/linux/alpha/__syscall_error.c
+++ b/libc/sysdeps/linux/alpha/__syscall_error.c
@@ -8,7 +8,7 @@
/* This routine is jumped to by all the syscall handlers, to stash
an error number into errno. */
-int attribute_hidden __syscall_error (void)
+long attribute_hidden __syscall_error (void)
{
register int err_no __asm__("$0");
__set_errno (err_no);
diff --git a/libc/sysdeps/linux/alpha/bits/fcntl.h b/libc/sysdeps/linux/alpha/bits/fcntl.h
index 35f8a704f..11e68214e 100644
--- a/libc/sysdeps/linux/alpha/bits/fcntl.h
+++ b/libc/sysdeps/linux/alpha/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 02000000 /* Direct disk access. */
# define O_NOATIME 04000000 /* Do not set atime. */
# define O_PATH 040000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 0100100000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -96,11 +97,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* for F_[GET|SET]FD */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/alpha/bits/ipc.h b/libc/sysdeps/linux/alpha/bits/ipc.h
index e2e20d149..28b21544d 100644
--- a/libc/sysdeps/linux/alpha/bits/ipc.h
+++ b/libc/sysdeps/linux/alpha/bits/ipc.h
@@ -49,6 +49,6 @@ struct ipc_perm
unsigned int mode; /* Read/write permission. */
unsigned short int __seq; /* Sequence number. */
unsigned short int __pad1;
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/alpha/bits/msq.h b/libc/sysdeps/linux/alpha/bits/msq.h
index ea0dba0cc..3020f6ff5 100644
--- a/libc/sysdeps/linux/alpha/bits/msq.h
+++ b/libc/sysdeps/linux/alpha/bits/msq.h
@@ -45,8 +45,8 @@ struct msqid_ds
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/alpha/bits/resource.h b/libc/sysdeps/linux/alpha/bits/resource.h
index 74f4eed69..dba818714 100644
--- a/libc/sysdeps/linux/alpha/bits/resource.h
+++ b/libc/sysdeps/linux/alpha/bits/resource.h
@@ -99,7 +99,13 @@ enum __rlimit_resource
__RLIMIT_RTPRIO = 14,
#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
- __RLIMIT_NLIMITS = 15,
+ /* Maximum CPU time in µs that a process scheduled under a real-time
+ scheduling policy may consume without making a blocking system
+ call before being forcibly descheduled. */
+ __RLIMIT_RTTIME = 15,
+#define RLIMIT_RTTIME __RLIMIT_RTTIME
+
+ __RLIMIT_NLIMITS = 16,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
@@ -107,13 +113,13 @@ enum __rlimit_resource
/* Value to indicate that there is no limit. */
#ifndef __USE_FILE_OFFSET64
-# define RLIM_INFINITY ((long int)(~0UL >> 1))
+# define RLIM_INFINITY ((unsigned long int)(~0UL))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
#endif
/* We can represent all limits. */
@@ -159,6 +165,15 @@ enum __rusage_who
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+
+#ifdef __USE_GNU
+ ,
+ /* The calling thread. */
+ RUSAGE_THREAD = 1
+# define RUSAGE_THREAD RUSAGE_THREAD
+ /* Name for the same functionality on Solaris. */
+# define RUSAGE_LWP RUSAGE_THREAD
+#endif
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/alpha/bits/sem.h b/libc/sysdeps/linux/alpha/bits/sem.h
index 0bd103620..2092009e7 100644
--- a/libc/sysdeps/linux/alpha/bits/sem.h
+++ b/libc/sysdeps/linux/alpha/bits/sem.h
@@ -41,8 +41,8 @@ struct semid_ds
__time_t sem_otime; /* last semop() time */
__time_t sem_ctime; /* last time changed by semctl() */
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/alpha/bits/shm.h b/libc/sysdeps/linux/alpha/bits/shm.h
index e62b05afb..4b6ae8d46 100644
--- a/libc/sysdeps/linux/alpha/bits/shm.h
+++ b/libc/sysdeps/linux/alpha/bits/shm.h
@@ -56,8 +56,8 @@ struct shmid_ds
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
@@ -79,10 +79,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/alpha/bits/stat.h b/libc/sysdeps/linux/alpha/bits/stat.h
index cbcdf2145..88bc6617d 100644
--- a/libc/sysdeps/linux/alpha/bits/stat.h
+++ b/libc/sysdeps/linux/alpha/bits/stat.h
@@ -89,7 +89,7 @@ struct stat
__ST_TIME(a); /* Time of last access. */
__ST_TIME(m); /* Time of last modification. */
__ST_TIME(c); /* Time of last status change. */
- long __unused[3];
+ long __uclibc_unused[3];
};
#ifdef __USE_LARGEFILE64
@@ -110,7 +110,7 @@ struct stat64
__ST_TIME(a); /* Time of last access. */
__ST_TIME(m); /* Time of last modification. */
__ST_TIME(c); /* Time of last status change. */
- long __unused[3];
+ long __uclibc_unused[3];
};
#endif
diff --git a/libc/sysdeps/linux/alpha/bits/uClibc_arch_features.h b/libc/sysdeps/linux/alpha/bits/uClibc_arch_features.h
index 18c18f92d..844fb8bcd 100644
--- a/libc/sysdeps/linux/alpha/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/alpha/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/arc/__syscall_error.c b/libc/sysdeps/linux/arc/__syscall_error.c
index 962d743e4..7f30485a8 100644
--- a/libc/sysdeps/linux/arc/__syscall_error.c
+++ b/libc/sysdeps/linux/arc/__syscall_error.c
@@ -8,7 +8,7 @@
#include <errno.h>
#include <sys/syscall.h>
-int __syscall_error(int err_no)
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/arc/asm.h b/libc/sysdeps/linux/arc/asm.h
new file mode 100644
index 000000000..f83075ea1
--- /dev/null
+++ b/libc/sysdeps/linux/arc/asm.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2022, Synopsys, Inc. (www.synopsys.com)
+ *
+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
+ */
+
+#ifndef _ARC_ASM_H
+#define _ARC_ASM_H
+
+/*
+ * Some 16-bit instructions were excluded from the ARCv3 ISA
+ * the following macros are introduced to handle these changes in one place.
+ * This will allow not to change existing ARCv2 code and use 16-bit versions
+ * of instructions for ARCv2 and replace them with 32-bit vesrions for ARCv3
+ */
+
+#if defined (__ARC64_ARCH32__)
+
+.macro PUSHR reg
+ push \reg
+.endm
+
+.macro PUSHR_S reg
+ push \reg
+.endm
+
+.macro POPR reg
+ pop \reg
+.endm
+
+.macro POPR_S reg
+ pop \reg
+.endm
+
+.macro SUBR_S dst,src1,src2
+ sub \dst, \src1, \src2
+.endm
+
+.macro ADDR_S dst,src1,src2
+ add \dst, \src1, \src2
+.endm
+
+.macro ASRR_S dst,src1,src2
+ asr \dst, \src1, \src2
+.endm
+
+.macro ASLR_S dst,src1,src2
+ asl \dst, \src1, \src2
+.endm
+
+#elif defined (__ARC64_ARCH64__)
+
+# error ARCv3 64-bit is not supported by uClibc-ng
+
+#else /* ARCHS || ARC700 */
+
+.macro PUSHR reg
+ push \reg
+.endm
+
+.macro PUSHR_S reg
+ push_s \reg
+.endm
+
+.macro POPR reg
+ pop \reg
+.endm
+
+.macro POPR_S reg
+ pop_s \reg
+.endm
+
+.macro SUBR_S dst,src1,src2
+ sub_s \dst, \src1, \src2
+.endm
+
+.macro ADDR_S dst,src1,src2
+ add_s \dst, \src1, \src2
+.endm
+
+.macro ASRR_S dst,src1,src2
+ asr_s \dst, \src1, \src2
+.endm
+
+.macro ASLR_S dst,src1,src2
+ asl_s \dst, \src1, \src2
+.endm
+
+#endif
+
+#endif /* _ARC_ASM_H */
diff --git a/libc/sysdeps/linux/arc/bits/atomic.h b/libc/sysdeps/linux/arc/bits/atomic.h
index 587860964..610b3c7c7 100644
--- a/libc/sysdeps/linux/arc/bits/atomic.h
+++ b/libc/sysdeps/linux/arc/bits/atomic.h
@@ -26,8 +26,10 @@ void __arc_link_error (void);
#ifdef __A7__
#define atomic_full_barrier() __asm__ __volatile__("": : :"memory")
+#define ARC_BARRIER_INSTR ""
#else
#define atomic_full_barrier() __asm__ __volatile__("dmb 3": : :"memory")
+#define ARC_BARRIER_INSTR "dmb 3"
#endif
/* Atomic compare and exchange. */
@@ -38,11 +40,12 @@ void __arc_link_error (void);
#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \
({ __arc_link_error (); oldval; })
-#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
+#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
({ __arc_link_error (); oldval; })
#ifdef __CONFIG_ARC_HAS_ATOMICS__
+#ifdef __A7__
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
({ \
__typeof(oldval) prev; \
@@ -60,8 +63,55 @@ void __arc_link_error (void);
\
prev; \
})
+#else /* !__A7__ */
+#define USE_ATOMIC_COMPILER_BUILTINS 1
-#else
+#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
+ ({ \
+ __typeof(*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n(mem, (void *) &__oldval, newval, 0, \
+ __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+#define __arch_compare_and_exchange_val_8_rel(mem, newval, oldval) \
+ ({ __arc_link_error (); oldval; })
+
+#define __arch_compare_and_exchange_val_16_rel(mem, newval, oldval) \
+ ({ __arc_link_error (); oldval; })
+
+#define __arch_compare_and_exchange_val_64_rel(mem, newval, oldval) \
+ ({ __arc_link_error (); oldval; })
+
+#define __arch_compare_and_exchange_val_32_rel(mem, newval, oldval) \
+ ({ \
+ __typeof(*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n(mem, (void *) &__oldval, newval, 0, \
+ __ATOMIC_RELEASE, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+/* Compare and exchange with "acquire" semantics, ie barrier after */
+#define atomic_compare_and_exchange_val_acq(mem, new, old) \
+ __atomic_val_bysize(__arch_compare_and_exchange_val, acq, \
+ mem, new, old)
+
+/* Compare and exchange with "release" semantics, ie barrier before */
+#define atomic_compare_and_exchange_val_rel(mem, new, old) \
+ __atomic_val_bysize(__arch_compare_and_exchange_val, rel, \
+ mem, new, old)
+
+/* Explicitly define here to use release semantics*/
+#define atomic_compare_and_exchange_bool_rel(mem, newval, oldval) \
+ ({ \
+ __typeof (oldval) __atg3_old = (oldval); \
+ atomic_compare_and_exchange_val_rel (mem, newval, __atg3_old) \
+ != __atg3_old; \
+ })
+
+#endif /* __A7__ */
+
+#else /* !__CONFIG_ARC_HAS_ATOMICS__ */
#ifndef __NR_arc_usr_cmpxchg
#error "__NR_arc_usr_cmpxchg missing: Please upgrade to kernel 4.9+ headers"
@@ -101,6 +151,21 @@ void __arc_link_error (void);
__typeof__(*(mem)) val = newval; \
\
__asm__ __volatile__( \
+ "ex %0, [%1]\n" \
+ ARC_BARRIER_INSTR \
+ : "+r" (val) \
+ : "r" (mem) \
+ : "memory" ); \
+ \
+ val; \
+ })
+
+#define __arch_exchange_32_rel(mem, newval) \
+ ({ \
+ __typeof__(*(mem)) val = newval; \
+ \
+ __asm__ __volatile__( \
+ ARC_BARRIER_INSTR"\n" \
"ex %0, [%1]" \
: "+r" (val) \
: "r" (mem) \
@@ -115,3 +180,10 @@ void __arc_link_error (void);
abort(); \
__arch_exchange_32_acq(mem, newval); \
})
+
+#define atomic_exchange_rel(mem, newval) \
+ ({ \
+ if (sizeof(*(mem)) != 4) \
+ abort(); \
+ __arch_exchange_32_rel(mem, newval); \
+ })
diff --git a/libc/sysdeps/linux/arc/bits/fcntl.h b/libc/sysdeps/linux/arc/bits/fcntl.h
index 0e8227e29..beb32e41e 100755
--- a/libc/sysdeps/linux/arc/bits/fcntl.h
+++ b/libc/sysdeps/linux/arc/bits/fcntl.h
@@ -41,6 +41,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -89,11 +90,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/arc/bits/syscalls.h b/libc/sysdeps/linux/arc/bits/syscalls.h
index 248ef7844..000b6b631 100644
--- a/libc/sysdeps/linux/arc/bits/syscalls.h
+++ b/libc/sysdeps/linux/arc/bits/syscalls.h
@@ -34,7 +34,7 @@
/* ldso doesn't have real errno */
#define ERRNO_ERRANDS(_sys_result)
#else /* !IS_IN_rtld */
-extern int __syscall_error (int);
+extern long __syscall_error (int);
#ifndef IS_IN_libc
/* Inter-libc callers use PLT */
#define CALL_ERRNO_SETTER "bl __syscall_error@plt \n\t"
@@ -100,7 +100,7 @@ extern int __syscall_error (int);
#ifdef __A7__
#define ARC_TRAP_INSN "trap0 \n\t"
-#elif defined(__HS__)
+#else
#define ARC_TRAP_INSN "trap_s 0 \n\t"
#endif
@@ -182,7 +182,7 @@ extern int __syscall_error (int);
#ifdef __A7__
#define ARC_TRAP_INSN trap0
-#elif defined(__HS__)
+#else
#define ARC_TRAP_INSN trap_s 0
#endif
diff --git a/libc/sysdeps/linux/arc/crt1.S b/libc/sysdeps/linux/arc/crt1.S
index 70a06e058..ff36d252e 100644
--- a/libc/sysdeps/linux/arc/crt1.S
+++ b/libc/sysdeps/linux/arc/crt1.S
@@ -40,7 +40,9 @@ __start:
ld_s r1, [sp] ; argc
mov_s r5, r0 ; rltd_fini
- add_s r2, sp, 4 ; argv
+ /* Use the universal 32-bit add instruction as 16-bit add_s was excluded from
+ ARCv3 ISA */
+ add r2, sp, 4 ; argv
#ifdef L_Scrt1
ld r0, [pcl, @main@gotpc]
ld r3, [pcl, @_init@gotpc]
diff --git a/libc/sysdeps/linux/arc/sigrestorer.S b/libc/sysdeps/linux/arc/sigrestorer.S
index e4deb6bd4..60d35ab3e 100644
--- a/libc/sysdeps/linux/arc/sigrestorer.S
+++ b/libc/sysdeps/linux/arc/sigrestorer.S
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Synopsys, Inc. (www.synopsys.com)
+ * Copyright (C) 2017-2022 Synopsys, Inc. (www.synopsys.com)
*
* Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
*/
@@ -22,4 +22,5 @@
__default_rt_sa_restorer:
mov r8, __NR_rt_sigreturn
ARC_TRAP_INSN
+ j_s [blink]
diff --git a/libc/sysdeps/linux/arm/__syscall_error.c b/libc/sysdeps/linux/arm/__syscall_error.c
index 2b642e816..c682aae49 100644
--- a/libc/sysdeps/linux/arm/__syscall_error.c
+++ b/libc/sysdeps/linux/arm/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/arm/bits/elf-fdpic.h b/libc/sysdeps/linux/arm/bits/elf-fdpic.h
index 3d6db54af..f2ef9aeca 100644
--- a/libc/sysdeps/linux/arm/bits/elf-fdpic.h
+++ b/libc/sysdeps/linux/arm/bits/elf-fdpic.h
@@ -91,7 +91,7 @@ __reloc_pointer (void *p,
/* This should be computed as part of the pointer comparison
above, but we want to use the carry in the comparison, so we
can't convert it to an integer type beforehand. */
- unsigned long offset = p - (void*)map->segs[c].p_vaddr;
+ unsigned long offset = (char*)p - (char*)map->segs[c].p_vaddr;
/* We only check for one-past-the-end for the last segment,
assumed to be the data segment, because other cases are
ambiguous in the absence of padding between segments, and
diff --git a/libc/sysdeps/linux/arm/bits/fcntl.h b/libc/sysdeps/linux/arm/bits/fcntl.h
index 02495c763..823660648 100644
--- a/libc/sysdeps/linux/arm/bits/fcntl.h
+++ b/libc/sysdeps/linux/arm/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 0200000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020040000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/arm/bits/hwcap.h b/libc/sysdeps/linux/arm/bits/hwcap.h
new file mode 100644
index 000000000..0a741b469
--- /dev/null
+++ b/libc/sysdeps/linux/arm/bits/hwcap.h
@@ -0,0 +1,50 @@
+/* Defines for bits in AT_HWCAP. ARM Linux version.
+ Copyright (C) 2012-2023 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#if !defined (_SYS_AUXV_H) && !defined (_LINUX_ARM_SYSDEP_H)
+# error "Never include <bits/hwcap.h> directly; use <sys/auxv.h> instead."
+#endif
+
+/* The following must match the kernel's <asm/hwcap.h>. */
+#define HWCAP_ARM_SWP 1
+#define HWCAP_ARM_HALF 2
+#define HWCAP_ARM_THUMB 4
+#define HWCAP_ARM_26BIT 8
+#define HWCAP_ARM_FAST_MULT 16
+#define HWCAP_ARM_FPA 32
+#define HWCAP_ARM_VFP 64
+#define HWCAP_ARM_EDSP 128
+#define HWCAP_ARM_JAVA 256
+#define HWCAP_ARM_IWMMXT 512
+#define HWCAP_ARM_CRUNCH 1024
+#define HWCAP_ARM_THUMBEE 2048
+#define HWCAP_ARM_NEON 4096
+#define HWCAP_ARM_VFPv3 8192
+#define HWCAP_ARM_VFPv3D16 16384
+#define HWCAP_ARM_TLS 32768
+#define HWCAP_ARM_VFPv4 65536
+#define HWCAP_ARM_IDIVA 131072
+#define HWCAP_ARM_IDIVT 262144
+#define HWCAP_ARM_VFPD32 524288
+#define HWCAP_ARM_LPAE 1048576
+#define HWCAP_ARM_EVTSTRM 2097152
+#define HWCAP_FPHP 4194304
+#define HWCAP_ASIMDHP 8388608
+#define HWCAP_ASIMDDP 16777216
+#define HWCAP_ASIMDFHM 33554432
+#define HWCAP_ASIMDBF16 67108864
+#define HWCAP_I8MM 134217728
diff --git a/libc/sysdeps/linux/arm/bits/kernel_stat.h b/libc/sysdeps/linux/arm/bits/kernel_stat.h
index 7bd89f9ab..cdbeeb4de 100644
--- a/libc/sysdeps/linux/arm/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/arm/bits/kernel_stat.h
@@ -29,8 +29,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
@@ -50,7 +50,6 @@ struct kernel_stat64 {
long long st_size;
unsigned long st_blksize;
unsigned long long st_blocks; /* Number 512-byte blocks allocated. */
-
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
diff --git a/libc/sysdeps/linux/arm/bits/shm.h b/libc/sysdeps/linux/arm/bits/shm.h
index 2708c58ff..86245faff 100644
--- a/libc/sysdeps/linux/arm/bits/shm.h
+++ b/libc/sysdeps/linux/arm/bits/shm.h
@@ -50,16 +50,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -81,10 +81,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/arm/crt1.S b/libc/sysdeps/linux/arm/crt1.S
index a1d7f0f23..799f11080 100644
--- a/libc/sysdeps/linux/arm/crt1.S
+++ b/libc/sysdeps/linux/arm/crt1.S
@@ -245,7 +245,23 @@ _start:
mov fp, #0
mov lr, #0
-#ifdef __ARCH_USE_MMU__
+#if defined(__ARCH_USE_MMU__) || defined(__UCLIBC_FORMAT_ELF__)
+#ifdef L_rcrt1
+ /* We don't need to save a1 since no dynamic linker should have run */
+ ldr a1, .L_GOT /* Get value at .L_GOT + 0 (offset to GOT)*/
+ adr a2, .L_GOT /* Get address of .L_GOT */
+ ldr a3, .L_GOT+16 /* Get value of _start(GOT) stored in .L_GOT */
+ adr a4, _start /* Get address of _start after relocation (changes to pc - ~30 or so) */
+ add a1, a1, a2 /* Calculate where the GOT is */
+ ldr a2, [a1, a3] /* GOT + _start(GOT) = offset of _start from begin of file */
+ sub a1, a4, a2 /* Current addr of _start - offset from beginning of file = load addr */
+ bl reloc_static_pie
+ mov a1, #0 /* Clean up a1 so that a random address won't get called at the end of program */
+
+ /* Clear the frame pointer and link register again since it might be modified by previous call */
+ mov fp, #0
+ mov lr, #0
+#endif
/* Pop argc off the stack and save a pointer to argv */
ldr a2, [sp], #4
mov a3, sp
@@ -309,6 +325,9 @@ _start:
.word _fini(GOT)
.word _init(GOT)
.word main(GOT)
+#ifdef L_rcrt1
+ .word _start(GOT)
+#endif
#endif
#endif
diff --git a/libc/sysdeps/linux/avr32/bits/fcntl.h b/libc/sysdeps/linux/avr32/bits/fcntl.h
index 6f1039a34..ec0a3b55d 100644
--- a/libc/sysdeps/linux/avr32/bits/fcntl.h
+++ b/libc/sysdeps/linux/avr32/bits/fcntl.h
@@ -35,6 +35,7 @@
# define O_DIRECT 00040000 /* must be a directory */
# define O_NOATIME 01000000 /* don't set atime */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
diff --git a/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
index cb0eae804..bda862fcd 100644
--- a/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/avr32/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/bfin/bits/fcntl.h b/libc/sysdeps/linux/bfin/bits/fcntl.h
index 2527a176a..0909ae6c4 100644
--- a/libc/sysdeps/linux/bfin/bits/fcntl.h
+++ b/libc/sysdeps/linux/bfin/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 0200000 /* Direct disk access. */
# define O_NOATIME 01000000 /* don't set atime */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020040000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/bfin/bits/kernel_stat.h b/libc/sysdeps/linux/bfin/bits/kernel_stat.h
index 7700d6109..2c2e818d6 100644
--- a/libc/sysdeps/linux/bfin/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/bfin/bits/kernel_stat.h
@@ -21,8 +21,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
diff --git a/libc/sysdeps/linux/bfin/bits/uClibc_arch_features.h b/libc/sysdeps/linux/bfin/bits/uClibc_arch_features.h
index 9646aac45..95f4d27e5 100644
--- a/libc/sysdeps/linux/bfin/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/bfin/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/c6x/bits/fcntl.h b/libc/sysdeps/linux/c6x/bits/fcntl.h
index 02c2ee131..14aea565e 100644
--- a/libc/sysdeps/linux/c6x/bits/fcntl.h
+++ b/libc/sysdeps/linux/c6x/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_LARGEFILE 0100000
# define O_NOATIME 01000000
# define O_PATH 010000000/* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000/* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
diff --git a/libc/sysdeps/linux/c6x/bits/ipc.h b/libc/sysdeps/linux/c6x/bits/ipc.h
index 4e9236eb6..c28a2ee3b 100644
--- a/libc/sysdeps/linux/c6x/bits/ipc.h
+++ b/libc/sysdeps/linux/c6x/bits/ipc.h
@@ -49,6 +49,6 @@ struct ipc_perm
__mode_t mode; /* Read/write permission. */
unsigned short int __seq; /* Sequence number. */
unsigned short int __pad2;
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/c6x/bits/resource.h b/libc/sysdeps/linux/c6x/bits/resource.h
index 72b08ce84..438827542 100644
--- a/libc/sysdeps/linux/c6x/bits/resource.h
+++ b/libc/sysdeps/linux/c6x/bits/resource.h
@@ -143,6 +143,15 @@ enum __rusage_who
/* Both. */
RUSAGE_BOTH = -2
#define RUSAGE_BOTH RUSAGE_BOTH
+
+#ifdef __USE_GNU
+ ,
+ /* The calling thread. */
+ RUSAGE_THREAD = 1
+# define RUSAGE_THREAD RUSAGE_THREAD
+ /* Name for the same functionality on Solaris. */
+# define RUSAGE_LWP RUSAGE_THREAD
+#endif
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/c6x/bits/syscalls.h b/libc/sysdeps/linux/c6x/bits/syscalls.h
index 70b708d70..451271725 100644..100755
--- a/libc/sysdeps/linux/c6x/bits/syscalls.h
+++ b/libc/sysdeps/linux/c6x/bits/syscalls.h
@@ -167,11 +167,15 @@ type name(C_DECL_ARGS_##nargs(args)) { \
return (type)INLINE_SYSCALL_NOERR(name, nargs, C_ARGS_##nargs(args)); \
}
+#define SYSCALL_FUNC_BODY(nargs, type, name, args...) \
+ return (type)INLINE_SYSCALL(name, nargs, C_ARGS_##nargs(args));
+
#define _syscall0(args...) SYSCALL_FUNC(0, args)
#define _syscall_noerr0(args...) SYSCALL_NOERR_FUNC(0, args)
#define _syscall1(args...) SYSCALL_FUNC(1, args)
#define _syscall_noerr1(args...) SYSCALL_NOERR_FUNC(1, args)
#define _syscall2(args...) SYSCALL_FUNC(2, args)
+#define _syscall2_body(args...) SYSCALL_FUNC_BODY(2, args)
#define _syscall3(args...) SYSCALL_FUNC(3, args)
#define _syscall4(args...) SYSCALL_FUNC(4, args)
#define _syscall5(args...) SYSCALL_FUNC(5, args)
diff --git a/libc/sysdeps/linux/c6x/bits/uClibc_arch_features.h b/libc/sysdeps/linux/c6x/bits/uClibc_arch_features.h
index 7b6077e3e..ef34fa295 100644
--- a/libc/sysdeps/linux/c6x/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/c6x/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/common-generic/bits/kernel_stat.h b/libc/sysdeps/linux/common-generic/bits/kernel_stat.h
index 7a97bb4d7..e874a4a9f 100644
--- a/libc/sysdeps/linux/common-generic/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/common-generic/bits/kernel_stat.h
@@ -18,7 +18,7 @@
* However that requires more #ifndef in relevant wrappers,
* further uglifying them
*/
-#define kernel_stat64 stat
+#define kernel_stat64 stat64
#endif /* _BITS_STAT_STRUCT_H */
diff --git a/libc/sysdeps/linux/common-generic/bits/stat.h b/libc/sysdeps/linux/common-generic/bits/stat.h
index 4ade63f6f..045c0f486 100644
--- a/libc/sysdeps/linux/common-generic/bits/stat.h
+++ b/libc/sysdeps/linux/common-generic/bits/stat.h
@@ -47,7 +47,7 @@ struct stat
int st_blksize; /* Optimal block size for I/O. */
int __pad2;
long long st_blocks; /* Number 512-byte blocks allocated */
-#ifdef __USE_MISC
+#if defined(__USE_MISC) || defined(__USE_XOPEN2K8)
/* Nanosecond resolution timestamps are stored in a format
equivalent to 'struct timespec'. This is the type used
whenever possible but the Unix namespace rules do not allow the
@@ -68,8 +68,8 @@ struct stat
int st_ctime; /* Time of last status change. */
unsigned int st_ctime_nsec;
#endif
- unsigned int __unused4;
- unsigned int __unused5;
+ unsigned int __uclibc_unused4;
+ unsigned int __uclibc_unused5;
} __ARCH_64BIT_ALIGNMENT__;
@@ -88,7 +88,7 @@ struct stat64
int st_blksize; /* Optimal block size for I/O. */
int __pad4;
long long st_blocks; /* Number 512-byte blocks allocated */
-# ifdef __USE_MISC
+# if defined(__USE_MISC) || defined(__USE_XOPEN2K8)
/* Nanosecond resolution timestamps are stored in a format
equivalent to 'struct timespec'. This is the type used
whenever possible but the Unix namespace rules do not allow the
@@ -106,8 +106,8 @@ struct stat64
int st_ctime; /* Time of last status change. */
unsigned int st_ctime_nsec;
# endif
- unsigned int __unused4;
- unsigned int __unused5;
+ unsigned int __uclibc_unused4;
+ unsigned int __uclibc_unused5;
};
#endif
diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
index f114a5bd1..848bc1e4a 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -32,10 +32,13 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \
iopl.c \
modify_ldt.c \
module.c \
+ name_to_handle_at.c \
+ open_by_handle_at.c \
personality.c \
pipe2.c \
ppoll.c \
prctl.c \
+ prlimit.c \
readahead.c \
reboot.c \
remap_file_pages.c \
diff --git a/libc/sysdeps/linux/common/__rt_sigtimedwait.c b/libc/sysdeps/linux/common/__rt_sigtimedwait.c
index f4244148d..aff5299a1 100644
--- a/libc/sysdeps/linux/common/__rt_sigtimedwait.c
+++ b/libc/sysdeps/linux/common/__rt_sigtimedwait.c
@@ -9,7 +9,7 @@
#include <sys/syscall.h>
-#ifdef __NR_rt_sigtimedwait
+#if defined(__NR_rt_sigtimedwait) || (defined(__NR_rt_sigtimedwait_time64) && defined(__UCLIBC_USE_TIME64__))
# include <signal.h>
# include <cancel.h>
# ifdef __UCLIBC_HAS_THREADS_NATIVE__
@@ -21,6 +21,10 @@
# include <string.h>
# endif
+#if defined(__UCLIBC_USE_TIME64__)
+#include "internal/time64_helpers.h"
+#endif
+
int __NC(sigtimedwait)(const sigset_t *set, siginfo_t *info,
const struct timespec *timeout)
{
@@ -52,8 +56,13 @@ int __NC(sigtimedwait)(const sigset_t *set, siginfo_t *info,
/* XXX The size argument hopefully will have to be changed to the
real size of the user-level sigset_t. */
/* on uClibc we use the kernel sigset_t size */
+# if defined(__UCLIBC_USE_TIME64__) && defined(__NR_rt_sigtimedwait_time64)
+ result = INLINE_SYSCALL(rt_sigtimedwait_time64, 4, set, info,
+ TO_TS64_P(timeout), __SYSCALL_SIGSET_T_SIZE);
+# else
result = INLINE_SYSCALL(rt_sigtimedwait, 4, set, info,
timeout, __SYSCALL_SIGSET_T_SIZE);
+# endif
/* The kernel generates a SI_TKILL code in si_code in case tkill is
used. tkill is transparently used in raise(). Since having
@@ -65,9 +74,14 @@ int __NC(sigtimedwait)(const sigset_t *set, siginfo_t *info,
return result;
# else
/* on uClibc we use the kernel sigset_t size */
+# if defined(__UCLIBC_USE_TIME64__) && defined(__NR_rt_sigtimedwait_time64)
+ return INLINE_SYSCALL(rt_sigtimedwait_time64, 4, set, info,
+ TO_TS64_P(timeout), __SYSCALL_SIGSET_T_SIZE);
+# else
return INLINE_SYSCALL(rt_sigtimedwait, 4, set, info,
timeout, __SYSCALL_SIGSET_T_SIZE);
# endif
+# endif
}
CANCELLABLE_SYSCALL(int, sigtimedwait,
(const sigset_t *set, siginfo_t *info, const struct timespec *timeout),
diff --git a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c
index d2d176a64..7830b2e2c 100644
--- a/libc/sysdeps/linux/common/__rt_sigwaitinfo.c
+++ b/libc/sysdeps/linux/common/__rt_sigwaitinfo.c
@@ -9,7 +9,7 @@
#include <sys/syscall.h>
-#ifdef __NR_rt_sigtimedwait
+#if defined(__NR_rt_sigtimedwait) || (defined(__UCLIBC_USE_TIME64__) && defined(__NR_rt_sigtimedwait_time64))
# define __need_NULL
# include <stddef.h>
# include <signal.h>
diff --git a/libc/sysdeps/linux/common/adjtimex.c b/libc/sysdeps/linux/common/adjtimex.c
index f45d54371..2fd7977f6 100644
--- a/libc/sysdeps/linux/common/adjtimex.c
+++ b/libc/sysdeps/linux/common/adjtimex.c
@@ -9,8 +9,16 @@
#include <sys/syscall.h>
#include <sys/timex.h>
-
+#if defined(__NR_adjtimex)
_syscall1(int, adjtimex, struct timex *, buf)
+#else
+#include <time.h>
+int adjtimex(struct timex *buf)
+{
+ return clock_adjtime(CLOCK_REALTIME, buf);
+}
+#endif
+
libc_hidden_def(adjtimex)
weak_alias(adjtimex,__adjtimex)
#if defined __UCLIBC_NTP_LEGACY__
diff --git a/libc/sysdeps/linux/common/alarm.c b/libc/sysdeps/linux/common/alarm.c
index dc43fe732..861f6ad8e 100644
--- a/libc/sysdeps/linux/common/alarm.c
+++ b/libc/sysdeps/linux/common/alarm.c
@@ -9,7 +9,7 @@
#include <sys/syscall.h>
#include <unistd.h>
-#ifdef __NR_alarm
+#if defined(__NR_alarm) && !defined(__UCLIBC_USE_TIME64__)
_syscall1(unsigned int, alarm, unsigned int, seconds)
#else
# include <sys/time.h>
diff --git a/libc/sysdeps/linux/common/bits/hwcap.h b/libc/sysdeps/linux/common/bits/hwcap.h
new file mode 100644
index 000000000..e7b899df0
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/hwcap.h
@@ -0,0 +1,22 @@
+/* Defines for bits in AT_HWCAP.
+ Copyright (C) 2012-2023 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_AUXV_H
+# error "Never include <bits/hwcap.h> directly; use <sys/auxv.h> instead."
+#endif
+
+/* No bits defined for this architecture. */
diff --git a/libc/sysdeps/linux/common/bits/ipc.h b/libc/sysdeps/linux/common/bits/ipc.h
index 3bd5f1b6f..cf7da2a29 100644
--- a/libc/sysdeps/linux/common/bits/ipc.h
+++ b/libc/sysdeps/linux/common/bits/ipc.h
@@ -20,6 +20,7 @@
#endif
#include <bits/types.h>
+#include <bits/wordsize.h>
/* Mode bits for `msgget', `semget', and `shmget'. */
#define IPC_CREAT 01000 /* Create key if key does not exist. */
@@ -46,10 +47,14 @@ struct ipc_perm
__gid_t gid; /* Owner's group ID. */
__uid_t cuid; /* Creator's user ID. */
__gid_t cgid; /* Creator's group ID. */
+#if __WORDSIZE == 64
+ unsigned int mode;
+#else
unsigned short int mode; /* Read/write permission. */
unsigned short int __pad1;
+#endif
unsigned short int __seq; /* Sequence number. */
unsigned short int __pad2;
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/common/bits/jmp_buf_tag.h b/libc/sysdeps/linux/common/bits/jmp_buf_tag.h
new file mode 100644
index 000000000..367b7bc66
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/jmp_buf_tag.h
@@ -0,0 +1,37 @@
+/* Define struct __jmp_buf_tag.
+ Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef __jmp_buf_tag_defined
+#define __jmp_buf_tag_defined 1
+
+#include <bits/setjmp.h>
+#include <bits/sigset.h>
+
+/* Calling environment, plus possibly a saved signal mask. */
+struct __jmp_buf_tag
+ {
+ /* NOTE: The machine-dependent definitions of `__sigsetjmp'
+ assume that a `jmp_buf' begins with a `__jmp_buf' and that
+ `__mask_was_saved' follows it. Do not move these members
+ or add others before it. */
+ __jmp_buf __jmpbuf; /* Calling environment. */
+ int __mask_was_saved; /* Saved the signal mask? */
+ __sigset_t __saved_mask; /* Saved signal mask. */
+ };
+
+#endif
diff --git a/libc/sysdeps/linux/common/bits/kernel-features.h b/libc/sysdeps/linux/common/bits/kernel-features.h
index f1ebe0204..2f4f407bd 100644
--- a/libc/sysdeps/linux/common/bits/kernel-features.h
+++ b/libc/sysdeps/linux/common/bits/kernel-features.h
@@ -490,6 +490,11 @@
# define __ASSUME_FALLOCATE 1
#endif
+/* prlimit64 is available in 2.6.36. */
+#if __LINUX_KERNEL_VERSION >= 0x020624
+# define __ASSUME_PRLIMIT64 1
+#endif
+
/* getcpu is a syscall for x86-64 since 3.1. */
#if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100
# define __ASSUME_GETCPU_SYSCALL 1
diff --git a/libc/sysdeps/linux/common/bits/mman-linux.h b/libc/sysdeps/linux/common/bits/mman-linux.h
index 6ca08415a..4947ddd89 100644
--- a/libc/sysdeps/linux/common/bits/mman-linux.h
+++ b/libc/sysdeps/linux/common/bits/mman-linux.h
@@ -46,6 +46,7 @@
/* Other flags. */
#define MAP_FIXED 0x10 /* Interpret addr exactly. */
+# define MAP_FIXED_NOREPLACE 0x100000 /* Used to solve problem with MAP_FIXED */
#ifdef __USE_MISC
# define MAP_FILE 0
# ifdef __MAP_ANONYMOUS
diff --git a/libc/sysdeps/linux/common/bits/msq.h b/libc/sysdeps/linux/common/bits/msq.h
index a1c3ea43d..b594cfff2 100644
--- a/libc/sysdeps/linux/common/bits/msq.h
+++ b/libc/sysdeps/linux/common/bits/msq.h
@@ -38,18 +38,18 @@ struct msqid_ds
{
struct ipc_perm msg_perm; /* structure describing operation permission */
__time_t msg_stime; /* time of last msgsnd command */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t msg_rtime; /* time of last msgrcv command */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t msg_ctime; /* time of last change */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
unsigned long int __msg_cbytes; /* current number of bytes on queue */
msgqnum_t msg_qnum; /* number of messages currently on queue */
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/common/bits/resource.h b/libc/sysdeps/linux/common/bits/resource.h
index df0ba56d9..89c3d4e41 100644
--- a/libc/sysdeps/linux/common/bits/resource.h
+++ b/libc/sysdeps/linux/common/bits/resource.h
@@ -99,7 +99,13 @@ enum __rlimit_resource
__RLIMIT_RTPRIO = 14,
#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
- __RLIMIT_NLIMITS = 15,
+ /* Maximum CPU time in µs that a process scheduled under a real-time
+ scheduling policy may consume without making a blocking system
+ call before being forcibly descheduled. */
+ __RLIMIT_RTTIME = 15,
+#define RLIMIT_RTTIME __RLIMIT_RTTIME
+
+ __RLIMIT_NLIMITS = 16,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
@@ -159,6 +165,15 @@ enum __rusage_who
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+
+#ifdef __USE_GNU
+ ,
+ /* The calling thread. */
+ RUSAGE_THREAD = 1
+# define RUSAGE_THREAD RUSAGE_THREAD
+ /* Name for the same functionality on Solaris. */
+# define RUSAGE_LWP RUSAGE_THREAD
+#endif
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/common/bits/sched.h b/libc/sysdeps/linux/common/bits/sched.h
index 9d05314f5..18a9fb98d 100644
--- a/libc/sysdeps/linux/common/bits/sched.h
+++ b/libc/sysdeps/linux/common/bits/sched.h
@@ -31,6 +31,7 @@
#ifdef __USE_GNU
# define SCHED_BATCH 3
# define SCHED_IDLE 5
+# define SCHED_DEADLINE 6
# define SCHED_RESET_ON_FORK 0x40000000
#endif
diff --git a/libc/sysdeps/linux/common/bits/sem.h b/libc/sysdeps/linux/common/bits/sem.h
index 501e0803b..24a130981 100644
--- a/libc/sysdeps/linux/common/bits/sem.h
+++ b/libc/sysdeps/linux/common/bits/sem.h
@@ -20,6 +20,7 @@
#endif
#include <sys/types.h>
+#include <bits/wordsize.h>
/* Flags for `semop'. */
#define SEM_UNDO 0x1000 /* undo the operation on exit */
@@ -38,13 +39,33 @@
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_otime_internal_1;
+ unsigned long int __sem_otime_internal_2;
+#else
__time_t sem_otime; /* last semop() time */
- unsigned long int __unused1;
+#endif
+#if (__WORDSIZE == 32 && !defined(__ARC64_ARCH32__) && !defined(__arc__) && !defined(__arm__) && !defined(__or1k__) && !defined(__xtensa__)) || \
+ ((defined(__ARC64_ARCH32__) || defined(__arc__) || defined(__arm__) || defined(__or1k__) || defined(__xtensa__)) && !defined(__UCLIBC_USE_TIME64__))
+ unsigned long int __uclibc_unused1;
+#endif
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_ctime_internal_1;
+ unsigned long int __sem_ctime_internal_2;
+#else
__time_t sem_ctime; /* last time changed by semctl() */
- unsigned long int __unused2;
+#endif
+#if (__WORDSIZE == 32 && !defined(__ARC64_ARCH32__) && !defined(__arc__) && !defined(__arm__) && !defined(__or1k__) && !defined(__xtensa__)) || \
+ ((defined(__ARC64_ARCH32__) || defined(__arc__) || defined(__arm__) || defined(__or1k__) || defined(__xtensa__)) && !defined(__UCLIBC_USE_TIME64__))
+ unsigned long int __uclibc_unused2;
+#endif
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused3;
- unsigned long int __unused4;
+#if defined(__UCLIBC_USE_TIME64__)
+ __time_t sem_otime; /* last semop() time */
+ __time_t sem_ctime; /* last time changed by semctl() */
+#endif
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/common/bits/shm.h b/libc/sysdeps/linux/common/bits/shm.h
index 88bf7a8aa..8906e262b 100644
--- a/libc/sysdeps/linux/common/bits/shm.h
+++ b/libc/sysdeps/linux/common/bits/shm.h
@@ -50,16 +50,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -81,10 +81,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/common/bits/stab.def b/libc/sysdeps/linux/common/bits/stab.def
index 8a2b8f39d..8d16c5c2c 100644
--- a/libc/sysdeps/linux/common/bits/stab.def
+++ b/libc/sysdeps/linux/common/bits/stab.def
@@ -17,7 +17,7 @@
<http://www.gnu.org/licenses/>. */
/* This contains contribution from Cygnus Support. */
-
+
/* Global variable. Only the name is significant.
To find the address, look in the corresponding external symbol. */
__define_stab (N_GSYM, 0x20, "GSYM")
@@ -177,7 +177,7 @@ __define_stab (N_NBLCS, 0xF8, "NBLCS")
/* Second symbol entry containing a length-value for the preceding entry.
The value is the length. */
__define_stab (N_LENG, 0xfe, "LENG")
-
+
/* The above information, in matrix format.
STAB MATRIX
diff --git a/libc/sysdeps/linux/common/bits/stat.h b/libc/sysdeps/linux/common/bits/stat.h
index 19e2f4e13..07c09f50a 100644
--- a/libc/sysdeps/linux/common/bits/stat.h
+++ b/libc/sysdeps/linux/common/bits/stat.h
@@ -83,8 +83,8 @@ struct stat
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
#ifndef __USE_FILE_OFFSET64
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
#else
__ino64_t st_ino; /* File serial number. */
#endif
diff --git a/libc/sysdeps/linux/common/bits/statx.h b/libc/sysdeps/linux/common/bits/statx.h
new file mode 100644
index 000000000..eb9b8535c
--- /dev/null
+++ b/libc/sysdeps/linux/common/bits/statx.h
@@ -0,0 +1,93 @@
+/* Generic statx-related definitions and declarations.
+ Copyright (C) 2018-2019 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+/* This interface is based on <linux/stat.h> in Linux. */
+
+#ifndef _SYS_STAT_H
+# error Never include <bits/statx.h> directly, include <sys/stat.h> instead.
+#endif
+
+struct statx_timestamp
+{
+ __int64_t tv_sec;
+ __uint32_t tv_nsec;
+ __int32_t __statx_timestamp_pad1[1];
+};
+
+/* Warning: The kernel may add additional fields to this struct in the
+ future. Only use this struct for calling the statx function, not
+ for storing data. (Expansion will be controlled by the mask
+ argument of the statx function.) */
+struct statx
+{
+ __uint32_t stx_mask;
+ __uint32_t stx_blksize;
+ __uint64_t stx_attributes;
+ __uint32_t stx_nlink;
+ __uint32_t stx_uid;
+ __uint32_t stx_gid;
+ __uint16_t stx_mode;
+ __uint16_t __statx_pad1[1];
+ __uint64_t stx_ino;
+ __uint64_t stx_size;
+ __uint64_t stx_blocks;
+ __uint64_t stx_attributes_mask;
+ struct statx_timestamp stx_atime;
+ struct statx_timestamp stx_btime;
+ struct statx_timestamp stx_ctime;
+ struct statx_timestamp stx_mtime;
+ __uint32_t stx_rdev_major;
+ __uint32_t stx_rdev_minor;
+ __uint32_t stx_dev_major;
+ __uint32_t stx_dev_minor;
+ __uint64_t __statx_pad2[14];
+};
+
+#ifndef STATX_TYPE
+# define STATX_TYPE 0x0001U
+# define STATX_MODE 0x0002U
+# define STATX_NLINK 0x0004U
+# define STATX_UID 0x0008U
+# define STATX_GID 0x0010U
+# define STATX_ATIME 0x0020U
+# define STATX_MTIME 0x0040U
+# define STATX_CTIME 0x0080U
+# define STATX_INO 0x0100U
+# define STATX_SIZE 0x0200U
+# define STATX_BLOCKS 0x0400U
+# define STATX_BASIC_STATS 0x07ffU
+# define STATX_ALL 0x0fffU
+# define STATX_BTIME 0x0800U
+# define STATX__RESERVED 0x80000000U
+
+# define STATX_ATTR_COMPRESSED 0x0004
+# define STATX_ATTR_IMMUTABLE 0x0010
+# define STATX_ATTR_APPEND 0x0020
+# define STATX_ATTR_NODUMP 0x0040
+# define STATX_ATTR_ENCRYPTED 0x0800
+# define STATX_ATTR_AUTOMOUNT 0x1000
+#endif /* !STATX_TYPE */
+
+__BEGIN_DECLS
+
+/* Fill *BUF with information about PATH in DIRFD. */
+int statx (int __dirfd, const char *__restrict __path, int __flags,
+ unsigned int __mask, struct statx *__restrict __buf)
+ __THROW __nonnull ((2, 5));
+
+__END_DECLS
+
diff --git a/libc/sysdeps/linux/common/bits/syscalls-common.h b/libc/sysdeps/linux/common/bits/syscalls-common.h
index 3665345a6..c3b193e6f 100644..100755
--- a/libc/sysdeps/linux/common/bits/syscalls-common.h
+++ b/libc/sysdeps/linux/common/bits/syscalls-common.h
@@ -99,21 +99,75 @@ type name(C_DECL_ARGS_##nargs(args)) { \
return (type)INLINE_SYSCALL(name, nargs, C_ARGS_##nargs(args)); \
}
+#define SYSCALL_FUNC_TIME64(nargs, type, name, args...) \
+type name(C_DECL_ARGS_##nargs(args)) { \
+ return (type)INLINE_SYSCALL(name##_time64, nargs, C_ARGS_##nargs(args)); \
+}
+
+#define SYSCALL_FUNC_64(nargs, type, name, args...) \
+type name(C_DECL_ARGS_##nargs(args)) { \
+ return (type)INLINE_SYSCALL(name##64, nargs, C_ARGS_##nargs(args)); \
+}
+
+
#define SYSCALL_NOERR_FUNC(nargs, type, name, args...) \
type name(C_DECL_ARGS_##nargs(args)) { \
return (type)INLINE_SYSCALL_NOERR(name, nargs, C_ARGS_##nargs(args)); \
}
+#define SYSCALL_NOERR_FUNC_TIME64(nargs, type, name, args...) \
+type name(C_DECL_ARGS_##nargs(args)) { \
+ return (type)INLINE_SYSCALL_NOERR(name##_time64, nargs, C_ARGS_##nargs(args)); \
+}
+
+#define SYSCALL_NOERR_FUNC_64(nargs, type, name, args...) \
+type name(C_DECL_ARGS_##nargs(args)) { \
+ return (type)INLINE_SYSCALL_NOERR(name##64, nargs, C_ARGS_##nargs(args)); \
+}
+
+#define SYSCALL_FUNC_BODY(nargs, type, name, args...) \
+ return (type)INLINE_SYSCALL(name, nargs, C_ARGS_##nargs(args));
+
+#define SYSCALL_FUNC_BODY_TIME64(nargs, type, name, args...) \
+ return (type)INLINE_SYSCALL(name##_time64, nargs, C_ARGS_##nargs(args));
+
+#define SYSCALL_FUNC_BODY_64(nargs, type, name, args...) \
+ return (type)INLINE_SYSCALL(name##64, nargs, C_ARGS_##nargs(args));
+
#define _syscall0(args...) SYSCALL_FUNC(0, args)
#define _syscall_noerr0(args...) SYSCALL_NOERR_FUNC(0, args)
#define _syscall1(args...) SYSCALL_FUNC(1, args)
#define _syscall_noerr1(args...) SYSCALL_NOERR_FUNC(1, args)
#define _syscall2(args...) SYSCALL_FUNC(2, args)
+#define _syscall2_body(args...) SYSCALL_FUNC_BODY(2, args)
#define _syscall3(args...) SYSCALL_FUNC(3, args)
#define _syscall4(args...) SYSCALL_FUNC(4, args)
#define _syscall5(args...) SYSCALL_FUNC(5, args)
#define _syscall6(args...) SYSCALL_FUNC(6, args)
+#define _syscall0_time64(args...) SYSCALL_FUNC_TIME64(0, args)
+#define _syscall_noerr0_time64(args...) SYSCALL_NOERR_FUNC_TIME64(0, args)
+#define _syscall1_time64(args...) SYSCALL_FUNC_TIME64(1, args)
+#define _syscall_noerr1_time64(args...) SYSCALL_NOERR_FUNC_TIME64(1, args)
+#define _syscall2_time64(args...) SYSCALL_FUNC_TIME64(2, args)
+#define _syscall2_body_time64(args...) SYSCALL_FUNC_BODY_TIME64(2, args)
+#define _syscall3_time64(args...) SYSCALL_FUNC_TIME64(3, args)
+#define _syscall4_time64(args...) SYSCALL_FUNC_TIME64(4, args)
+#define _syscall5_time64(args...) SYSCALL_FUNC_TIME64(5, args)
+#define _syscall6_time64(args...) SYSCALL_FUNC_TIME64(6, args)
+
+#define _syscall0_64(args...) SYSCALL_FUNC_64(0, args)
+#define _syscall_noerr0_64(args...) SYSCALL_NOERR_FUNC_64(0, args)
+#define _syscall1_64(args...) SYSCALL_FUNC_64(1, args)
+#define _syscall_noerr1_64(args...) SYSCALL_NOERR_FUNC_64(1, args)
+#define _syscall2_64(args...) SYSCALL_FUNC_64(2, args)
+#define _syscall2_body_64(args...) SYSCALL_FUNC_BODY_64(2, args)
+#define _syscall3_64(args...) SYSCALL_FUNC_64(3, args)
+#define _syscall4_64(args...) SYSCALL_FUNC_64(4, args)
+#define _syscall5_64(args...) SYSCALL_FUNC_64(5, args)
+#define _syscall6_64(args...) SYSCALL_FUNC_64(6, args)
+
+
#endif /* _syscall0 */
#endif /* __ASSEMBLER__ */
diff --git a/libc/sysdeps/linux/common/bits/typesizes.h b/libc/sysdeps/linux/common/bits/typesizes.h
index e1c5a27bb..dcb2c3b0a 100644
--- a/libc/sysdeps/linux/common/bits/typesizes.h
+++ b/libc/sysdeps/linux/common/bits/typesizes.h
@@ -46,9 +46,21 @@
#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
#define __ID_T_TYPE __U32_TYPE
#define __CLOCK_T_TYPE __SLONGWORD_TYPE
+
+#ifdef __UCLIBC_USE_TIME64__
+#define __TIME_T_TYPE __S64_TYPE
+#else
#define __TIME_T_TYPE __SLONGWORD_TYPE
+#endif /* __UCLIBC_USE_TIME64__ */
+
#define __USECONDS_T_TYPE __U32_TYPE
+
+#ifdef __UCLIBC_USE_TIME64__
+#define __SUSECONDS_T_TYPE __S64_TYPE
+#else
#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
+#endif
+
#define __DADDR_T_TYPE __S32_TYPE
#define __SWBLK_T_TYPE __SLONGWORD_TYPE
#define __KEY_T_TYPE __S32_TYPE
diff --git a/libc/sysdeps/linux/common/bits/uClibc_arch_features.h b/libc/sysdeps/linux/common/bits/uClibc_arch_features.h
index 37c7ceb60..c79ca7dfa 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_arch_features.h
@@ -14,6 +14,9 @@
/* can your target use syscall6() for mmap ? */
#undef __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/common/bits/uClibc_uwchar.h b/libc/sysdeps/linux/common/bits/uClibc_uwchar.h
index 47ea3cda1..91b789c80 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_uwchar.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_uwchar.h
@@ -36,6 +36,7 @@
#include <limits.h>
#include <stdint.h>
+#include <wchar.h>
#if WCHAR_MIN == 0
typedef wchar_t __uwchar_t;
diff --git a/libc/sysdeps/linux/common/bits/utmp.h b/libc/sysdeps/linux/common/bits/utmp.h
index 6ece31e34..9671d9382 100644
--- a/libc/sysdeps/linux/common/bits/utmp.h
+++ b/libc/sysdeps/linux/common/bits/utmp.h
@@ -82,7 +82,7 @@ struct utmp
#endif
int32_t ut_addr_v6[4]; /* Internet address of remote host. */
- char __unused[20]; /* Reserved for future use. */
+ char __uclibc_unused[20]; /* Reserved for future use. */
};
/* Backwards compatibility hacks. */
diff --git a/libc/sysdeps/linux/common/bits/utmpx.h b/libc/sysdeps/linux/common/bits/utmpx.h
index 815fc90b8..3315ef5e6 100644
--- a/libc/sysdeps/linux/common/bits/utmpx.h
+++ b/libc/sysdeps/linux/common/bits/utmpx.h
@@ -78,7 +78,7 @@ struct utmpx
struct timeval ut_tv; /* Time entry was made. */
#endif
__int32_t ut_addr_v6[4]; /* Internet address of remote host. */
- char __unused[20]; /* Reserved for future use. */
+ char __uclibc_unused[20]; /* Reserved for future use. */
};
diff --git a/libc/sysdeps/linux/common/bits/wchar.h b/libc/sysdeps/linux/common/bits/wchar.h
index a3ff5319e..ce951d9b6 100644
--- a/libc/sysdeps/linux/common/bits/wchar.h
+++ b/libc/sysdeps/linux/common/bits/wchar.h
@@ -1,5 +1,5 @@
/* wchar_t type related definitions.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000-2023 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -14,12 +14,36 @@
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#ifndef _BITS_WCHAR_H
#define _BITS_WCHAR_H 1
-#define __WCHAR_MIN (-2147483647 - 1)
-#define __WCHAR_MAX (2147483647)
+/* The fallback definitions, for when __WCHAR_MAX__ or __WCHAR_MIN__
+ are not defined, give the right value and type as long as both int
+ and wchar_t are 32-bit types. Adding L'\0' to a constant value
+ ensures that the type is correct; it is necessary to use (L'\0' +
+ 0) rather than just L'\0' so that the type in C++ is the promoted
+ version of wchar_t rather than the distinct wchar_t type itself.
+ Because wchar_t in preprocessor #if expressions is treated as
+ intmax_t or uintmax_t, the expression (L'\0' - 1) would have the
+ wrong value for WCHAR_MAX in such expressions and so cannot be used
+ to define __WCHAR_MAX in the unsigned case. */
+
+#ifdef __WCHAR_MAX__
+# define __WCHAR_MAX __WCHAR_MAX__
+#elif L'\0' - 1 > 0
+# define __WCHAR_MAX (0xffffffffu + L'\0')
+#else
+# define __WCHAR_MAX (0x7fffffff + L'\0')
+#endif
+
+#ifdef __WCHAR_MIN__
+# define __WCHAR_MIN __WCHAR_MIN__
+#elif L'\0' - 1 > 0
+# define __WCHAR_MIN (L'\0' + 0)
+#else
+# define __WCHAR_MIN (-__WCHAR_MAX - 1)
+#endif
#endif /* bits/wchar.h */
diff --git a/libc/sysdeps/linux/common/clock_adjtime.c b/libc/sysdeps/linux/common/clock_adjtime.c
index 9f55d4527..53f64e9d5 100644
--- a/libc/sysdeps/linux/common/clock_adjtime.c
+++ b/libc/sysdeps/linux/common/clock_adjtime.c
@@ -10,6 +10,10 @@
#include <sys/syscall.h>
#include <sys/timex.h>
-#ifdef __NR_clock_adjtime
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_adjtime64)
+_syscall2_64(int, clock_adjtime, clockid_t, clock_id, struct timex*, ntx)
+#elif defined(__NR_clock_adjtime)
_syscall2(int, clock_adjtime, clockid_t, clock_id, struct timex*, ntx)
+#else
+#error "clock_adjtime syscall is not defined!"
#endif
diff --git a/libc/sysdeps/linux/common/clock_getres.c b/libc/sysdeps/linux/common/clock_getres.c
index 532047ede..fd0f8c14c 100644
--- a/libc/sysdeps/linux/common/clock_getres.c
+++ b/libc/sysdeps/linux/common/clock_getres.c
@@ -10,7 +10,21 @@
#include <sys/syscall.h>
#include <time.h>
-#ifdef __NR_clock_getres
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_getres_time64)
+#include "internal/time64_helpers.h"
+
+int clock_getres(clockid_t clock_id, struct timespec *res)
+{
+ struct __ts64_struct __ts64;
+ int __ret = INLINE_SYSCALL(clock_getres_time64, 2, clock_id, &__ts64);
+ if (__ret == 0 && res) {
+ res->tv_sec = __ts64.tv_sec;
+ res->tv_nsec = __ts64.tv_nsec;
+ };
+
+ return __ret;
+}
+#elif defined(__NR_clock_getres)
_syscall2(int, clock_getres, clockid_t, clock_id, struct timespec*, res)
#else
# include <unistd.h>
diff --git a/libc/sysdeps/linux/common/clock_gettime.c b/libc/sysdeps/linux/common/clock_gettime.c
index 95d398239..b924d860b 100644
--- a/libc/sysdeps/linux/common/clock_gettime.c
+++ b/libc/sysdeps/linux/common/clock_gettime.c
@@ -11,12 +11,33 @@
#include <sys/syscall.h>
#include <time.h>
-#ifdef __NR_clock_gettime
-_syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp)
+#ifdef __VDSO_SUPPORT__
+#include "ldso.h"
+#endif
+
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_gettime64)
+#include "internal/time64_helpers.h"
+
+int __libc_clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+ struct __ts64_struct __ts64;
+ int __ret = INLINE_SYSCALL(clock_gettime64, 2, clock_id, &__ts64);
+ if (tp) {
+ tp->tv_sec = __ts64.tv_sec;
+ tp->tv_nsec = __ts64.tv_nsec;
+ }
+
+ return __ret;
+}
+#elif defined(__NR_clock_gettime)
+int __libc_clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+ return INLINE_SYSCALL(clock_gettime, 2, clock_id, tp);
+}
#else
# include <sys/time.h>
-int clock_gettime(clockid_t clock_id, struct timespec* tp)
+int __libc_clock_gettime(clockid_t clock_id, struct timespec* tp)
{
struct timeval tv;
int retval = -1;
@@ -39,3 +60,12 @@ int clock_gettime(clockid_t clock_id, struct timespec* tp)
return retval;
}
#endif
+
+int clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+#if defined(__VDSO_SUPPORT__) && defined(ARCH_VDSO_CLOCK_GETTIME)
+ return ARCH_VDSO_CLOCK_GETTIME(clock_id, tp);
+#else
+ return __libc_clock_gettime(clock_id, tp);
+#endif
+}
diff --git a/libc/sysdeps/linux/common/clock_settime.c b/libc/sysdeps/linux/common/clock_settime.c
index 636f18417..3abc5f49b 100644
--- a/libc/sysdeps/linux/common/clock_settime.c
+++ b/libc/sysdeps/linux/common/clock_settime.c
@@ -10,7 +10,15 @@
#include <sys/syscall.h>
#include <time.h>
-#ifdef __NR_clock_settime
+
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_settime64)
+#include "internal/time64_helpers.h"
+
+int clock_settime(clockid_t clock_id, const struct timespec *tp)
+{
+ return INLINE_SYSCALL(clock_settime64, 2, clock_id, TO_TS64_P(tp));
+}
+#elif defined(__NR_clock_settime)
_syscall2(int, clock_settime, clockid_t, clock_id, const struct timespec*, tp)
#else
# include <sys/time.h>
diff --git a/libc/sysdeps/linux/common/fexecve.c b/libc/sysdeps/linux/common/fexecve.c
new file mode 100644
index 000000000..99a35c5b8
--- /dev/null
+++ b/libc/sysdeps/linux/common/fexecve.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 1994-2019 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+int
+fexecve (int fd, char *const argv[], char *const envp[])
+{
+ if (fd < 0 || argv == NULL || envp == NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ /* We use the /proc filesystem to get the information. If it is not
+ mounted we fail. */
+ char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3];
+ snprintf (buf, sizeof (buf), "/proc/self/fd/%d", fd);
+
+ /* We do not need the return value. */
+ execve (buf, argv, envp);
+
+ int save = errno;
+
+ /* We come here only if the 'execve' call fails. Determine whether
+ /proc is mounted. If not we return ENOSYS. */
+ struct stat st;
+ if (stat ("/proc/self/fd", &st) != 0 && errno == ENOENT)
+ save = ENOSYS;
+
+ __set_errno (save);
+
+ return -1;
+}
+libc_hidden_def(fexecve)
diff --git a/libc/sysdeps/linux/common/fstat.c b/libc/sysdeps/linux/common/fstat.c
index 030360dfc..65e879799 100644
--- a/libc/sysdeps/linux/common/fstat.c
+++ b/libc/sysdeps/linux/common/fstat.c
@@ -10,10 +10,11 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/syscall.h>
+#include <bits/uClibc_arch_features.h>
#include "xstatconv.h"
-#if defined __NR_fstat64 && !defined __NR_fstat
+#if defined __NR_fstat64 && !defined __NR_fstat && !defined(__UCLIBC_USE_TIME64__)
int fstat(int fd, struct stat *buf)
{
return INLINE_SYSCALL(fstat64, 2, fd, buf);
@@ -29,6 +30,22 @@ int fstat(int fd, struct stat *buf)
}
libc_hidden_def(fstat)
+#elif defined __NR_statx && defined __UCLIBC_HAVE_STATX__
+# include <fcntl.h>
+# include <statx_cp.h>
+
+int fstat(int fd, struct stat *buf)
+{
+ struct statx tmp;
+ int rc = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH,
+ STATX_BASIC_STATS, &tmp);
+ if (rc == 0)
+ __cp_stat_statx ((struct stat *)buf, &tmp);
+
+ return rc;
+}
+libc_hidden_def(fstat)
+
#elif defined __NR_fstat
int fstat(int fd, struct stat *buf)
{
@@ -57,7 +74,7 @@ int fstat(int fd, struct stat *buf)
libc_hidden_def(fstat)
#endif
-# if ! defined __NR_fstat64
+# if ! defined __NR_fstat64 && ! defined __UCLIBC_HAVE_STATX__
strong_alias_untyped(fstat,fstat64)
libc_hidden_def(fstat64)
#endif
diff --git a/libc/sysdeps/linux/common/fstat64.c b/libc/sysdeps/linux/common/fstat64.c
index 62995b2dc..359c22af6 100644
--- a/libc/sysdeps/linux/common/fstat64.c
+++ b/libc/sysdeps/linux/common/fstat64.c
@@ -9,7 +9,7 @@
#include <_lfs_64.h>
#include <sys/syscall.h>
-#ifdef __NR_fstat64
+#if defined(__NR_fstat64) && !defined(__UCLIBC_USE_TIME64__)
# include <unistd.h>
# include <sys/stat.h>
# include "xstatconv.h"
@@ -28,9 +28,26 @@ int fstat64(int fd, struct stat64 *buf)
__xstat64_conv(&kbuf, buf);
}
return result;
+
#else
return __syscall_fstat64(fd, buf);
#endif
}
libc_hidden_def(fstat64)
+
+#elif __NR_statx && defined __UCLIBC_HAVE_STATX__
+# include <fcntl.h>
+# include <statx_cp.h>
+
+int fstat64(int fd, struct stat64 *buf)
+{
+ struct statx tmp;
+ int rc = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH,
+ STATX_BASIC_STATS, &tmp);
+ if (rc == 0)
+ __cp_stat64_statx ((struct stat64 *)buf, &tmp);
+
+ return rc;
+}
+libc_hidden_def(fstat64)
#endif
diff --git a/libc/sysdeps/linux/common/fstatat.c b/libc/sysdeps/linux/common/fstatat.c
index 13673d76c..14b118cc0 100644
--- a/libc/sysdeps/linux/common/fstatat.c
+++ b/libc/sysdeps/linux/common/fstatat.c
@@ -9,13 +9,14 @@
#include <sys/syscall.h>
#include <sys/stat.h>
#include "xstatconv.h"
+#include <bits/uClibc_arch_features.h>
/* 64bit ports tend to favor newfstatat() */
#if __WORDSIZE == 64 && defined __NR_newfstatat
# define __NR_fstatat64 __NR_newfstatat
#endif
-#ifdef __NR_fstatat64
+#if defined(__NR_fstatat64) && !defined(__UCLIBC_USE_TIME64__)
int fstatat(int fd, const char *file, struct stat *buf, int flag)
{
int ret;
@@ -31,5 +32,44 @@ int fstatat(int fd, const char *file, struct stat *buf, int flag)
}
libc_hidden_def(fstatat)
#else
+
+#if defined(__NR_statx) && defined __UCLIBC_HAVE_STATX__
+#include <sys/sysmacros.h> // for makedev
+
+int fstatat(int fd, const char *file, struct stat *buf, int flag)
+{
+ int ret;
+ struct statx tmp;
+
+ ret = INLINE_SYSCALL(statx, 5, fd, file, flag,
+ STATX_BASIC_STATS, &tmp);
+ if (ret != 0)
+ return ret;
+
+ *buf = (struct stat) {
+ .st_dev = makedev(tmp.stx_dev_major, tmp.stx_dev_minor),
+ .st_ino = tmp.stx_ino,
+ .st_mode = tmp.stx_mode,
+ .st_nlink = tmp.stx_nlink,
+ .st_uid = tmp.stx_uid,
+ .st_gid = tmp.stx_gid,
+ .st_rdev = makedev(tmp.stx_rdev_major, tmp.stx_rdev_minor),
+ .st_size = tmp.stx_size,
+ .st_blksize = tmp.stx_blksize,
+ .st_blocks = tmp.stx_blocks,
+ .st_atim.tv_sec = tmp.stx_atime.tv_sec,
+ .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
+ .st_mtim.tv_sec = tmp.stx_mtime.tv_sec,
+ .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
+ .st_ctim.tv_sec = tmp.stx_ctime.tv_sec,
+ .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
+ };
+
+ return ret;
+}
+libc_hidden_def(fstatat)
+
+#endif
+
/* should add emulation with fstat() and /proc/self/fd/ ... */
#endif
diff --git a/libc/sysdeps/linux/common/fstatat64.c b/libc/sysdeps/linux/common/fstatat64.c
index 711521a6a..16dbf9215 100644
--- a/libc/sysdeps/linux/common/fstatat64.c
+++ b/libc/sysdeps/linux/common/fstatat64.c
@@ -23,7 +23,7 @@
# define __NR_fstatat64 __NR_newfstatat
#endif
-#ifdef __NR_fstatat64
+#if defined(__NR_fstatat64) && !defined(__UCLIBC_USE_TIME64__)
# include <sys/stat.h>
# include "xstatconv.h"
int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
@@ -43,5 +43,26 @@ int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
}
libc_hidden_def(fstatat64)
#else
+
+#if defined(__NR_statx) && defined(__UCLIBC_HAVE_STATX__)
+# include <sys/stat.h>
+# include <statx_cp.h>
+# include <fcntl.h> // for AT_NO_AUTOMOUNT
+
+int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
+{
+ struct statx tmp;
+
+ int r = INLINE_SYSCALL(statx, 5, fd, file, AT_NO_AUTOMOUNT | flag,
+ STATX_BASIC_STATS, &tmp);
+
+ if (r == 0)
+ __cp_stat64_statx ((struct stat64 *)buf, &tmp);
+
+ return r;
+}
+libc_hidden_def(fstatat64)
+#endif
+
/* should add emulation with fstat64() and /proc/self/fd/ ... */
#endif
diff --git a/libc/sysdeps/linux/common/futimens.c b/libc/sysdeps/linux/common/futimens.c
index 03e58f4b5..2f3d72420 100644
--- a/libc/sysdeps/linux/common/futimens.c
+++ b/libc/sysdeps/linux/common/futimens.c
@@ -8,7 +8,7 @@
#include <sys/syscall.h>
#include <time.h>
-#ifdef __NR_utimensat
+#if defined(__NR_utimensat) || defined(__NR_utimensat_time64)
/* To avoid superfluous warnings about passing NULL to the non-null annotated
* 2nd param "__path" below, we bypass inclusion of sys/stat.h and use
* a non annotated, local decl.
diff --git a/libc/sysdeps/linux/common/futimesat.c b/libc/sysdeps/linux/common/futimesat.c
index bd73eae7e..bf36550dd 100644
--- a/libc/sysdeps/linux/common/futimesat.c
+++ b/libc/sysdeps/linux/common/futimesat.c
@@ -7,10 +7,33 @@
*/
#include <sys/syscall.h>
+#include <sys/stat.h>
#include <sys/time.h>
#ifdef __NR_futimesat
_syscall3(int, futimesat, int, fd, const char *, file, const struct timeval *, tvp)
-#else
-/* should add emulation with futimes() and /proc/self/fd/ ... */
+#elif defined __NR_utimensat
+#include <errno.h>
+#define __need_NULL
+#include <stddef.h>
+
+int futimesat(int dirfd, const char *file, const struct timeval tvp[2])
+{
+ struct timespec ts[2];
+
+ if (tvp != NULL)
+ {
+ if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
+ || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
+ {
+ __set_errno(EINVAL);
+ return -1;
+ }
+
+ TIMEVAL_TO_TIMESPEC(&tvp[0], &ts[0]);
+ TIMEVAL_TO_TIMESPEC(&tvp[1], &ts[1]);
+ }
+
+ return utimensat(dirfd, file, tvp ? ts : NULL, 0);
+}
#endif
diff --git a/libc/sysdeps/linux/common/getrlimit.c b/libc/sysdeps/linux/common/getrlimit.c
index 26d3d2946..46726fcbd 100644
--- a/libc/sysdeps/linux/common/getrlimit.c
+++ b/libc/sysdeps/linux/common/getrlimit.c
@@ -9,10 +9,11 @@
#include <sys/syscall.h>
#include <sys/resource.h>
#include <bits/wordsize.h>
+#include <stddef.h> // needed for NULL to be defined
/* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
-#if defined __NR_ugetrlimit
+#if defined(__NR_ugetrlimit)
/* just call ugetrlimit() */
# define __NR___syscall_ugetrlimit __NR_ugetrlimit
@@ -23,17 +24,58 @@ int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
{
return __syscall_ugetrlimit(resource, rlimits);
}
+libc_hidden_def(getrlimit)
+
+#elif defined(__NR_prlimit64)
+/* Use prlimit64 if present, the prlimit64 syscall is free from a back
+ compatibility stuff for an old getrlimit */
+
+# if __WORDSIZE == 32 && !defined(__USE_FILE_OFFSET64)
+/* If struct rlimit has 64-bit fields (if __WORDSIZE == 64 or __USE_FILE_OFFSET64
+ is defined), then use getrlimit as an alias to getrlimit64, see getrlimit64.c */
+int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
+{
+ struct rlimit64 rlimits64;
+ int res = INLINE_SYSCALL (prlimit64, 4, 0, resource, NULL, &rlimits64);
+
+ if (res == 0) {
+ /* If the syscall succeeds but the values do not fit into a
+ rlimit structure set EOVERFLOW errno and retrun -1. */
+ rlimits->rlim_cur = rlimits64.rlim_cur;
+ if (rlimits64.rlim_cur != rlimits->rlim_cur) {
+ if (rlimits64.rlim_cur != RLIM64_INFINITY) {
+ __set_errno(EOVERFLOW);
+ return -1;
+ }
+ rlimits->rlim_cur = RLIM_INFINITY;
+ }
-#elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
+ rlimits->rlim_max = rlimits64.rlim_max;
+ if (rlimits64.rlim_max != rlimits->rlim_max) {
+ if (rlimits64.rlim_max != RLIM64_INFINITY) {
+ __set_errno(EOVERFLOW);
+ return -1;
+ }
+ rlimits->rlim_max = RLIM_INFINITY;
+ }
+ }
+ return res;
+}
+libc_hidden_def(getrlimit)
+# endif
+
+#else
+
+# if !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
/* We don't need to wrap getrlimit() */
_syscall2(int, getrlimit, __rlimit_resource_t, resource,
struct rlimit *, rlim)
-#else
+# else
/* we have to handle old style getrlimit() */
-# define __NR___syscall_getrlimit __NR_getrlimit
+# define __NR___syscall_getrlimit __NR_getrlimit
static __always_inline
_syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim)
@@ -54,9 +96,7 @@ int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
rlimits->rlim_max = RLIM_INFINITY;
return result;
}
-#endif
-libc_hidden_def(getrlimit)
+# endif
-#if __WORDSIZE == 64
-strong_alias_untyped(getrlimit, getrlimit64)
+libc_hidden_def(getrlimit)
#endif
diff --git a/libc/sysdeps/linux/common/getrlimit64.c b/libc/sysdeps/linux/common/getrlimit64.c
index be98098a1..47f1410fb 100644
--- a/libc/sysdeps/linux/common/getrlimit64.c
+++ b/libc/sysdeps/linux/common/getrlimit64.c
@@ -17,14 +17,31 @@
#include <_lfs_64.h>
#include <bits/wordsize.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <stddef.h> // needed for NULL to be defined
-/* the regular getrlimit will work just fine for 64bit users */
-#if __WORDSIZE == 32
-# include <sys/resource.h>
+#if defined(__NR_prlimit64)
+
+/* the regular prlimit64 will work just fine for 64-bit users */
+int getrlimit64 (__rlimit_resource_t resource, struct rlimit64 *rlimits)
+{
+ return INLINE_SYSCALL (prlimit64, 4, 0, resource, NULL, rlimits);
+}
+
+# if !defined(__NR_ugetrlimit) && (__WORDSIZE == 64 || defined (__USE_FILE_OFFSET64))
+/* If getrlimit is not implemented through the __NR_ugetrlimit and size of
+ rlimit_t == rlimit64_t then use getrlimit as an alias to getrlimit64 */
+strong_alias_untyped(getrlimit64, getrlimit)
+libc_hidden_def(getrlimit)
+# endif
+
+#else
/* Put the soft and hard limits for RESOURCE in *RLIMITS.
- Returns 0 if successful, -1 if not (and sets errno). */
+ Returns 0 if successful, -1 if not (and sets errno).
+ The regular getrlimit will work just fine for 64-bit users */
int getrlimit64 (__rlimit_resource_t resource, struct rlimit64 *rlimits)
{
struct rlimit rlimits32;
@@ -44,3 +61,4 @@ int getrlimit64 (__rlimit_resource_t resource, struct rlimit64 *rlimits)
return 0;
}
#endif
+
diff --git a/libc/sysdeps/linux/common/gettimeofday.c b/libc/sysdeps/linux/common/gettimeofday.c
index 1c62b3937..9b29fe5a0 100644..100755
--- a/libc/sysdeps/linux/common/gettimeofday.c
+++ b/libc/sysdeps/linux/common/gettimeofday.c
@@ -8,6 +8,25 @@
#include <sys/syscall.h>
#include <sys/time.h>
+#include <time.h>
+
+#ifdef __VDSO_SUPPORT__
+#include "ldso.h"
+#endif
+
+int gettimeofday(struct timeval * tv, __timezone_ptr_t tz) {
+ if (!tv)
+ return 0;
+#if defined(__VDSO_SUPPORT__) && defined(ARCH_VDSO_GETTIMEOFDAY)
+ return ARCH_VDSO_GETTIMEOFDAY(tv, tz);
+#else
+ struct timespec __ts;
+ int __ret = clock_gettime(CLOCK_REALTIME, &__ts);
+ tv->tv_sec = __ts.tv_sec;
+ tv->tv_usec = (suseconds_t)__ts.tv_nsec / 1000;
+ return __ret;
+#endif
+}
+
-_syscall2(int, gettimeofday, struct timeval *, tv, __timezone_ptr_t, tz)
libc_hidden_def(gettimeofday)
diff --git a/libc/sysdeps/linux/common/lstat.c b/libc/sysdeps/linux/common/lstat.c
index 9d2024972..2ebd8615e 100644
--- a/libc/sysdeps/linux/common/lstat.c
+++ b/libc/sysdeps/linux/common/lstat.c
@@ -9,8 +9,9 @@
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <bits/uClibc_arch_features.h>
-#if defined __NR_fstatat64 && !defined __NR_lstat
+#if defined __NR_fstatat64 && !defined __NR_lstat && !defined(__UCLIBC_USE_TIME64__)
# include <fcntl.h>
int lstat(const char *file_name, struct stat *buf)
@@ -28,6 +29,23 @@ int lstat(const char *file_name, struct stat *buf)
}
libc_hidden_def(lstat)
+#elif defined __NR_statx && defined __UCLIBC_HAVE_STATX__
+# include <fcntl.h>
+# include <statx_cp.h>
+
+int lstat(const char *file_name, struct stat *buf)
+{
+ struct statx tmp;
+ int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name,
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW,
+ STATX_BASIC_STATS, &tmp);
+ if (rc == 0)
+ __cp_stat_statx ((struct stat *)buf, &tmp);
+
+ return rc;
+}
+libc_hidden_def(lstat)
+
/* For systems which have both, prefer the old one */
#else
# include "xstatconv.h"
@@ -57,7 +75,7 @@ int lstat(const char *file_name, struct stat *buf)
}
libc_hidden_def(lstat)
-# if ! defined __NR_fstatat64 && ! defined __NR_lstat64
+# if ! defined __NR_fstatat64 && ! defined __NR_lstat64 && ! defined __UCLIBC_HAS_STATX__
strong_alias_untyped(lstat,lstat64)
libc_hidden_def(lstat64)
# endif
diff --git a/libc/sysdeps/linux/common/lstat64.c b/libc/sysdeps/linux/common/lstat64.c
index 2f66e7ca2..efc5b1b7f 100644
--- a/libc/sysdeps/linux/common/lstat64.c
+++ b/libc/sysdeps/linux/common/lstat64.c
@@ -11,7 +11,7 @@
#include <unistd.h>
#include <sys/stat.h>
-#if defined __NR_fstatat64 && !defined __NR_lstat
+#if defined __NR_fstatat64 && !defined __NR_lstat && !defined(__UCLIBC_USE_TIME64__)
# include <fcntl.h>
int lstat64(const char *file_name, struct stat64 *buf)
@@ -29,6 +29,23 @@ int lstat64(const char *file_name, struct stat64 *buf)
}
libc_hidden_def(lstat64)
+#elif defined __NR_statx && defined __UCLIBC_HAVE_STATX__
+# include <fcntl.h>
+# include <statx_cp.h>
+
+int lstat64(const char *file_name, struct stat64 *buf)
+{
+ struct statx tmp;
+ int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name,
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW,
+ STATX_BASIC_STATS, &tmp);
+ if (rc == 0)
+ __cp_stat64_statx ((struct stat64 *)buf, &tmp);
+
+ return rc;
+}
+libc_hidden_def(lstat64)
+
/* For systems which have both, prefer the old one */
#elif defined __NR_lstat64
# include "xstatconv.h"
diff --git a/libc/sysdeps/linux/common/name_to_handle_at.c b/libc/sysdeps/linux/common/name_to_handle_at.c
new file mode 100644
index 000000000..20c67cbca
--- /dev/null
+++ b/libc/sysdeps/linux/common/name_to_handle_at.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2005-2020 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Imported from musl C library
+ */
+
+#include <sys/syscall.h>
+
+#ifdef __NR_open_by_handle_at
+#include <fcntl.h>
+int name_to_handle_at(int dirfd, const char *pathname,
+ struct file_handle *handle, int *mount_id, int flags)
+{
+ return INLINE_SYSCALL(name_to_handle_at, 5, dirfd, pathname, handle,
+ mount_id, flags);
+}
+#endif
diff --git a/libc/sysdeps/linux/common/nanosleep.c b/libc/sysdeps/linux/common/nanosleep.c
index 4463e108a..2b59fefef 100644
--- a/libc/sysdeps/linux/common/nanosleep.c
+++ b/libc/sysdeps/linux/common/nanosleep.c
@@ -10,11 +10,21 @@
#include <time.h>
#include <cancel.h>
-#define __NR___nanosleep_nocancel __NR_nanosleep
-static _syscall2(int, __NC(nanosleep), const struct timespec *, req,
- struct timespec *, rem);
+
+int _NC(nanosleep)(const struct timespec *req, struct timespec *rem)
+{
+ int __ret = clock_nanosleep(CLOCK_REALTIME, 0, req, rem);
+
+ if (__ret != 0) {
+ __set_errno(__ret);
+ return -1;
+ }
+
+ return __ret;
+};
CANCELLABLE_SYSCALL(int, nanosleep,
(const struct timespec *req, struct timespec *rem),
(req, rem))
+
lt_libc_hidden(nanosleep)
diff --git a/libc/sysdeps/linux/common/not-cancel.h b/libc/sysdeps/linux/common/not-cancel.h
index 9d1588494..e4fb1d7fe 100644
--- a/libc/sysdeps/linux/common/not-cancel.h
+++ b/libc/sysdeps/linux/common/not-cancel.h
@@ -113,9 +113,9 @@ extern __typeof(pause) __pause_nocancel;
#ifdef __NR_nanosleep
# define nanosleep_not_cancel(requested_time, remaining) \
INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
-/*#else
+#else
# define nanosleep_not_cancel(requested_time, remaining) \
- __nanosleep_nocancel (requested_time, remaining)*/
+ __nanosleep_nocancel (requested_time, remaining)
#endif
#if 0
diff --git a/libc/sysdeps/linux/common/open.c b/libc/sysdeps/linux/common/open.c
index ccdcf3848..ac09d40f0 100644
--- a/libc/sysdeps/linux/common/open.c
+++ b/libc/sysdeps/linux/common/open.c
@@ -31,7 +31,7 @@ int open(const char *file, int oflag, ...)
int oldtype, result;
#endif
- if (oflag & O_CREAT) {
+ if (oflag & (O_CREAT | (O_TMPFILE &~ O_DIRECTORY))) {
va_list arg;
va_start(arg, oflag);
mode = va_arg(arg, mode_t);
diff --git a/libc/sysdeps/linux/common/open64.c b/libc/sysdeps/linux/common/open64.c
index 6e65a988e..9d4c06b18 100644
--- a/libc/sysdeps/linux/common/open64.c
+++ b/libc/sysdeps/linux/common/open64.c
@@ -10,13 +10,13 @@
#include <stdarg.h>
#include <cancel.h>
-/* Open FILE with access OFLAG. If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG. If OFLAG includes O_CREAT or O_TMPFILE,
a third argument is the file protection. */
int open64(const char *file, int oflag, ...)
{
mode_t mode = 0;
- if (oflag & O_CREAT) {
+ if (oflag & (O_CREAT | (O_TMPFILE &~ O_DIRECTORY))) {
va_list arg;
va_start (arg, oflag);
mode = va_arg (arg, mode_t);
diff --git a/libc/sysdeps/linux/common/open_by_handle_at.c b/libc/sysdeps/linux/common/open_by_handle_at.c
new file mode 100644
index 000000000..5e65648a6
--- /dev/null
+++ b/libc/sysdeps/linux/common/open_by_handle_at.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2005-2020 Rich Felker, et al.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Imported from musl C library
+ */
+
+#include <sys/syscall.h>
+
+#ifdef __NR_open_by_handle_at
+#include <fcntl.h>
+int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags)
+{
+ return INLINE_SYSCALL(open_by_handle_at, 3, mount_fd, handle, flags);
+}
+#endif
diff --git a/libc/sysdeps/linux/common/openat64.c b/libc/sysdeps/linux/common/openat64.c
index eda3e7db1..cd1b23fa5 100644
--- a/libc/sysdeps/linux/common/openat64.c
+++ b/libc/sysdeps/linux/common/openat64.c
@@ -9,10 +9,18 @@
#include <_lfs_64.h>
#include <sys/syscall.h>
#include <fcntl.h>
+#include <stdarg.h>
#ifdef __NR_openat
-static int __openat64(int fd, const char *file, int oflag, mode_t mode)
+static int __openat64(int fd, const char *file, int oflag, ...)
{
+ va_list ap;
+ mode_t mode;
+
+ va_start(ap, oflag);
+ mode = va_arg(ap, int);
+ va_end(ap);
+
return openat(fd, file, oflag | O_LARGEFILE, mode);
}
strong_alias_untyped(__openat64,openat64)
diff --git a/libc/sysdeps/linux/common/poll.c b/libc/sysdeps/linux/common/poll.c
index d1f1f1723..3d46d5bee 100644
--- a/libc/sysdeps/linux/common/poll.c
+++ b/libc/sysdeps/linux/common/poll.c
@@ -53,6 +53,7 @@ int __NC(poll)(struct pollfd *fds, nfds_t nfds, int timeout)
fd_set *rset, *wset, *xset;
struct pollfd *f;
int ready;
+ int error_num;
int maxfd = 0;
int bytes;
@@ -142,6 +143,7 @@ int __NC(poll)(struct pollfd *fds, nfds_t nfds, int timeout)
/* Reset the return value. */
ready = 0;
+ error_num = 0;
for (f = fds; f < &fds[nfds]; ++f)
if (f->fd != -1 && (f->events & (POLLIN|POLLOUT|POLLPRI))
@@ -178,8 +180,13 @@ int __NC(poll)(struct pollfd *fds, nfds_t nfds, int timeout)
++ready;
}
else if (errno == EBADF)
+ {
f->revents |= POLLNVAL;
+ error_num++;
+ }
}
+ if (ready == 0)
+ return error_num;
/* Try again. */
continue;
}
diff --git a/libc/sysdeps/linux/common/ppoll.c b/libc/sysdeps/linux/common/ppoll.c
index 781f1ff1c..870717bd7 100644
--- a/libc/sysdeps/linux/common/ppoll.c
+++ b/libc/sysdeps/linux/common/ppoll.c
@@ -18,7 +18,7 @@
#include <sys/syscall.h>
-#if defined __NR_ppoll && defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
+#if (defined __NR_ppoll || defined(__NR_ppoll_time64)) && defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
#define __need_NULL
#include <stddef.h>
@@ -26,6 +26,10 @@
#include <sys/poll.h>
#include <cancel.h>
+#if defined(__UCLIBC_USE_TIME64__)
+#include "internal/time64_helpers.h"
+#endif
+
static int
__NC(ppoll)(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
const sigset_t *sigmask)
@@ -37,11 +41,14 @@ __NC(ppoll)(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
tval = *timeout;
timeout = &tval;
}
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_ppoll_time64)
+ return INLINE_SYSCALL(ppoll_time64, 5, fds, nfds, TO_TS64_P(timeout), sigmask, __SYSCALL_SIGSET_T_SIZE);
+#else
return INLINE_SYSCALL(ppoll, 5, fds, nfds, timeout, sigmask, __SYSCALL_SIGSET_T_SIZE);
+#endif
}
CANCELLABLE_SYSCALL(int, ppoll, (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
const sigset_t *sigmask),
(fds, nfds, timeout, sigmask))
-
#endif
diff --git a/libc/sysdeps/linux/common/prlimit.c b/libc/sysdeps/linux/common/prlimit.c
new file mode 100644
index 000000000..81c0f4619
--- /dev/null
+++ b/libc/sysdeps/linux/common/prlimit.c
@@ -0,0 +1,76 @@
+/* Get/set resource limits. Linux specific syscall.
+ Copyright (C) 2021-2022 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sys/resource.h>
+#include <sysdep.h>
+#include <stddef.h> // needed for NULL to be defined
+
+#if defined(__NR_prlimit64) && __WORDSIZE == 32 && !defined(__USE_FILE_OFFSET64)
+int
+prlimit (__pid_t pid, enum __rlimit_resource resource,
+ const struct rlimit *new_rlimit, struct rlimit *old_rlimit)
+{
+ struct rlimit64 new_rlimit64;
+ struct rlimit64 *new_rlimit64_ptr = NULL;
+ struct rlimit64 old_rlimit64;
+ struct rlimit64 *old_rlimit64_ptr = (old_rlimit != NULL ? &old_rlimit64 : NULL);
+ int res;
+
+ if (new_rlimit != NULL) {
+ if (new_rlimit->rlim_cur == RLIM_INFINITY)
+ new_rlimit64.rlim_cur = RLIM64_INFINITY;
+ else
+ new_rlimit64.rlim_cur = new_rlimit->rlim_cur;
+ if (new_rlimit->rlim_max == RLIM_INFINITY)
+ new_rlimit64.rlim_max = RLIM64_INFINITY;
+ else
+ new_rlimit64.rlim_max = new_rlimit->rlim_max;
+ new_rlimit64_ptr = &new_rlimit64;
+ }
+
+ res = INLINE_SYSCALL (prlimit64, 4, pid, resource, new_rlimit64_ptr,
+ old_rlimit64_ptr);
+
+ if (res == 0 && old_rlimit != NULL) {
+ /* If the syscall succeeds but the values do not fit into a
+ rlimit structure set EOVERFLOW errno and retrun -1.
+ With current Linux implementation of the prlimit64 syscall,
+ overflow can't happen. An extra condition has been added to get
+ the same behavior as in glibc for future potential overflows. */
+ old_rlimit->rlim_cur = old_rlimit64.rlim_cur;
+ if (old_rlimit64.rlim_cur != old_rlimit->rlim_cur) {
+ if (new_rlimit == NULL &&
+ old_rlimit64.rlim_cur != RLIM64_INFINITY) {
+ __set_errno(EOVERFLOW);
+ return -1;
+ }
+ old_rlimit->rlim_cur = RLIM_INFINITY;
+ }
+ old_rlimit->rlim_max = old_rlimit64.rlim_max;
+ if (old_rlimit64.rlim_max != old_rlimit->rlim_max) {
+ if (new_rlimit == NULL &&
+ old_rlimit64.rlim_max != RLIM64_INFINITY) {
+ __set_errno(EOVERFLOW);
+ return -1;
+ }
+ old_rlimit->rlim_max = RLIM_INFINITY;
+ }
+ }
+
+ return res;
+}
+#endif
diff --git a/libc/sysdeps/linux/common/prlimit64.c b/libc/sysdeps/linux/common/prlimit64.c
new file mode 100644
index 000000000..6f57b939e
--- /dev/null
+++ b/libc/sysdeps/linux/common/prlimit64.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2023 uClibc-ng
+ * An prlimit64() - get/set resource limits Linux specific syscall.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/resource.h>
+#include <sysdep.h>
+
+#if defined(__NR_prlimit64)
+
+int
+prlimit64 (__pid_t pid, enum __rlimit_resource resource,
+ const struct rlimit64 *new_rlimit, struct rlimit64 *old_rlimit)
+{
+ return INLINE_SYSCALL (prlimit64, 4, pid, resource, new_rlimit,
+ old_rlimit);
+}
+
+# if __WORDSIZE == 64 || defined (__USE_FILE_OFFSET64)
+strong_alias_untyped(prlimit64, prlimit)
+# endif
+
+#endif \ No newline at end of file
diff --git a/libc/sysdeps/linux/common/pselect.c b/libc/sysdeps/linux/common/pselect.c
index bf2c08375..f9d16d6c8 100644
--- a/libc/sysdeps/linux/common/pselect.c
+++ b/libc/sysdeps/linux/common/pselect.c
@@ -26,11 +26,15 @@
#include <signal.h>
#include <cancel.h>
+#if defined(__UCLIBC_USE_TIME64__)
+#include "internal/time64_helpers.h"
+#endif
+
static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timespec *timeout,
const sigset_t *sigmask)
{
-#ifdef __NR_pselect6
+#if defined(__NR_pselect6) || defined(__NR_pselect6_time64)
/* The Linux kernel can in some situations update the timeout value.
* We do not want that so use a local variable.
*/
@@ -56,8 +60,11 @@ static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
sigmask = (void *)&data;
}
-
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_pselect6_time64)
+ return INLINE_SYSCALL(pselect6_time64, 6, nfds, readfds, writefds, exceptfds, TO_TS64_P(timeout), sigmask);
+#else
return INLINE_SYSCALL(pselect6, 6, nfds, readfds, writefds, exceptfds, timeout, sigmask);
+#endif
#else
struct timeval tval;
int retval;
@@ -88,6 +95,7 @@ static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
return retval;
#endif
}
+
CANCELLABLE_SYSCALL(int, pselect, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask),
(nfds, readfds, writefds, exceptfds, timeout, sigmask))
diff --git a/libc/sysdeps/linux/common/renameat.c b/libc/sysdeps/linux/common/renameat.c
index b0b91fa3e..0156981de 100644
--- a/libc/sysdeps/linux/common/renameat.c
+++ b/libc/sysdeps/linux/common/renameat.c
@@ -6,12 +6,18 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#include <sys/syscall.h>
#include <stdio.h>
+#include <fcntl.h>
+#include <sysdep.h>
+#include <errno.h>
+int
+renameat (int oldfd, const char *old, int newfd, const char *new)
+{
#ifdef __NR_renameat
-_syscall4(int, renameat, int, oldfd, const char *, old, int, newfd, const char *, new)
-libc_hidden_def(renameat)
+ return INLINE_SYSCALL (renameat, 4, oldfd, old, newfd, new);
#else
-/* should add emulation with rename() and /proc/self/fd/ ... */
+ return INLINE_SYSCALL (renameat2, 5, oldfd, old, newfd, new, 0);
#endif
+}
+libc_hidden_def (renameat)
diff --git a/libc/sysdeps/linux/common/sched_rr_get_interval.c b/libc/sysdeps/linux/common/sched_rr_get_interval.c
index 7a7de2bc5..c9be134cb 100644
--- a/libc/sysdeps/linux/common/sched_rr_get_interval.c
+++ b/libc/sysdeps/linux/common/sched_rr_get_interval.c
@@ -10,7 +10,12 @@
#include <sys/types.h>
#include <sys/syscall.h>
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_sched_rr_get_interval_time64)
+#define __NR___syscall_sched_rr_get_interval __NR_sched_rr_get_interval_time64
+#else
#define __NR___syscall_sched_rr_get_interval __NR_sched_rr_get_interval
+#endif
+
static __inline__ _syscall2(int, __syscall_sched_rr_get_interval,
__kernel_pid_t, pid, struct timespec *, tp)
diff --git a/libc/sysdeps/linux/common/select.c b/libc/sysdeps/linux/common/select.c
index 3132a109c..84016dd0b 100644
--- a/libc/sysdeps/linux/common/select.c
+++ b/libc/sysdeps/linux/common/select.c
@@ -15,17 +15,19 @@
# define __NR_select __NR__newselect
#endif
-#if !defined __NR_select && defined __NR_pselect6
+#if defined(__NR_pselect6) || defined(__NR_pselect6_time64)
# include <stdint.h>
# define USEC_PER_SEC 1000000L
#endif
+#if defined(__UCLIBC_USE_TIME64__)
+#include "internal/time64_helpers.h"
+#endif
+
int __NC(select)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
-#ifdef __NR_select
- return INLINE_SYSCALL(select, 5, n, readfds, writefds, exceptfds, timeout);
-#elif defined __NR_pselect6
+#if defined(__NR_pselect6) || defined(__NR_pselect6_time64)
struct timespec _ts, *ts = 0;
if (timeout) {
uint32_t usec;
@@ -47,8 +49,14 @@ int __NC(select)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
ts = &_ts;
}
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_pselect6_time64)
+ return INLINE_SYSCALL(pselect6_time64, 6, n, readfds, writefds, exceptfds, TO_TS64_P(ts), 0);
+#else
return INLINE_SYSCALL(pselect6, 6, n, readfds, writefds, exceptfds, ts, 0);
#endif
+#elif defined(__NR_select)
+ return INLINE_SYSCALL(select, 5, n, readfds, writefds, exceptfds, ts);
+#endif
}
/* we should guard it, but we need it in other files, so let it fail
* if we miss any of the syscalls */
diff --git a/libc/sysdeps/linux/common/setitimer.c b/libc/sysdeps/linux/common/setitimer.c
index 2febabbc8..eab541329 100644
--- a/libc/sysdeps/linux/common/setitimer.c
+++ b/libc/sysdeps/linux/common/setitimer.c
@@ -10,6 +10,38 @@
#include <sys/time.h>
+#if defined(__UCLIBC_USE_TIME64__)
+
+struct itimerval32_struct {
+ __S32_TYPE __interval_sec;
+ __S32_TYPE __interval_usec;
+ __S32_TYPE __value_sec;
+ __S32_TYPE __value_usec;
+};
+
+int setitimer(__itimer_which_t which, const struct itimerval *restrict new, struct itimerval *restrict old)
+{
+ struct itimerval32_struct __itv32 = {
+ .__interval_sec = new->it_interval.tv_sec,
+ .__interval_usec = new->it_interval.tv_usec,
+ .__value_sec = new->it_value.tv_sec,
+ .__value_usec = new->it_value.tv_usec
+ };
+ struct itimerval32_struct __itv32_old;
+
+ int __ret = INLINE_SYSCALL(setitimer, 3, which, &__itv32, &__itv32_old);
+ if (__ret == 0 && old) {
+ old->it_interval.tv_sec = __itv32_old.__interval_sec;
+ old->it_interval.tv_usec = __itv32_old.__interval_usec;
+ old->it_value.tv_sec = __itv32_old.__value_sec;
+ old->it_value.tv_usec = __itv32_old.__value_usec;
+ }
+
+ return __ret;
+}
+#else
_syscall3(int, setitimer, __itimer_which_t, which,
const struct itimerval *, new, struct itimerval *, old)
+
+#endif
libc_hidden_def(setitimer)
diff --git a/libc/sysdeps/linux/common/setrlimit.c b/libc/sysdeps/linux/common/setrlimit.c
index 8f4973b72..9c6707235 100644
--- a/libc/sysdeps/linux/common/setrlimit.c
+++ b/libc/sysdeps/linux/common/setrlimit.c
@@ -9,36 +9,65 @@
#include <sys/syscall.h>
#include <sys/resource.h>
#include <bits/wordsize.h>
+#include <stddef.h> // needed for NULL to be defined
/* Only wrap setrlimit if the new usetrlimit is not present and setrlimit sucks */
#if defined(__NR_usetrlimit)
-
/* just call usetrlimit() */
# define __NR___syscall_usetrlimit __NR_usetrlimit
static __always_inline
_syscall2(int, __syscall_usetrlimit, enum __rlimit_resource, resource,
const struct rlimit *, rlim)
-int setrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
+int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlimits)
{
return __syscall_usetrlimit(resource, rlimits);
}
+libc_hidden_def(setrlimit)
+
+#elif defined(__NR_prlimit64)
+
+/* Use prlimit64 if present, the prlimit64 syscall is free from a back
+ compatibility stuff for setrlimit */
+
+ # if __WORDSIZE == 32 && !defined(__USE_FILE_OFFSET64)
+/* If struct rlimit has 64-bit fields (if __WORDSIZE == 64 or __USE_FILE_OFFSET64
+ is defined), then use setrlimit as an alias to setrlimit64, see setrlimit64.c */
+int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlimits)
+{
+ struct rlimit64 rlimits64;
+
+ if (rlimits->rlim_cur == RLIM_INFINITY)
+ rlimits64.rlim_cur = RLIM64_INFINITY;
+ else
+ rlimits64.rlim_cur = rlimits->rlim_cur;
+ if (rlimits->rlim_max == RLIM_INFINITY)
+ rlimits64.rlim_max = RLIM64_INFINITY;
+ else
+ rlimits64.rlim_max = rlimits->rlim_max;
+
+ return INLINE_SYSCALL (prlimit64, 4, 0, resource, &rlimits64, NULL);
+}
+libc_hidden_def(setrlimit)
+# endif
+
+#else
-#elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
+# if !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
/* We don't need to wrap setrlimit() */
_syscall2(int, setrlimit, __rlimit_resource_t, resource,
const struct rlimit *, rlim)
-#else
+# else
-# define __need_NULL
-# include <stddef.h>
-# include <errno.h>
-# include <sys/param.h>
+# define __need_NULL
+# include <stddef.h>
+# include <errno.h>
+# include <sys/param.h>
/* we have to handle old style setrlimit() */
-# define __NR___syscall_setrlimit __NR_setrlimit
+# define __NR___syscall_setrlimit __NR_setrlimit
static __always_inline
_syscall2(int, __syscall_setrlimit, int, resource, const struct rlimit *, rlim)
@@ -59,9 +88,7 @@ int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlimits)
RLIM_INFINITY >> 1);
return __syscall_setrlimit(resource, &rlimits_small);
}
-#endif
-libc_hidden_def(setrlimit)
+# endif
-#if __WORDSIZE == 64
-strong_alias_untyped(setrlimit, setrlimit64)
+libc_hidden_def(setrlimit)
#endif
diff --git a/libc/sysdeps/linux/common/setrlimit64.c b/libc/sysdeps/linux/common/setrlimit64.c
index fee14f4ad..3446c58fe 100644
--- a/libc/sysdeps/linux/common/setrlimit64.c
+++ b/libc/sysdeps/linux/common/setrlimit64.c
@@ -17,15 +17,31 @@
#include <_lfs_64.h>
#include <bits/wordsize.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <stddef.h> // needed for NULL to be defined
-/* the regular setrlimit will work just fine for 64bit users */
-#if __WORDSIZE == 32
-# include <sys/resource.h>
+#if defined(__NR_prlimit64)
+
+int setrlimit64 (__rlimit_resource_t resource, const struct rlimit64 *rlimits)
+{
+ return INLINE_SYSCALL (prlimit64, 4, 0, resource, rlimits, NULL);
+}
+
+# if !defined(__NR_usetrlimit) && (__WORDSIZE == 64 || defined (__USE_FILE_OFFSET64))
+/* If setrlimit is not implemented through the __NR_usetrlimit and size of
+ rlimit_t == rlimit64_t then use setrlimit as an alias to setrlimit64 */
+strong_alias_untyped(setrlimit64, setrlimit)
+libc_hidden_def(setrlimit)
+# endif
+
+#else
/* Set the soft and hard limits for RESOURCE to *RLIMITS.
Only the super-user can increase hard limits.
- Return 0 if successful, -1 if not (and sets errno). */
+ Return 0 if successful, -1 if not (and sets errno).
+ The regular setrlimit will work just fine for 64bit users */
int setrlimit64 (__rlimit_resource_t resource, const struct rlimit64 *rlimits)
{
struct rlimit rlimits32;
diff --git a/libc/sysdeps/linux/common/settimeofday.c b/libc/sysdeps/linux/common/settimeofday.c
index 14a261794..75d18ffc2 100644
--- a/libc/sysdeps/linux/common/settimeofday.c
+++ b/libc/sysdeps/linux/common/settimeofday.c
@@ -10,9 +10,21 @@
#ifdef __USE_BSD
# include <sys/time.h>
-# ifdef __NR_settimeofday
-_syscall2(int, settimeofday, const struct timeval *, tv,
- const struct timezone *, tz)
+# include <time.h>
+
+int settimeofday(const struct timeval *tv, const struct timezone *tz)
+{
+ if (!tv)
+ return 0;
+
+ struct timespec __ts = {
+ .tv_sec = tv->tv_sec,
+ .tv_nsec = tv->tv_usec * 1000
+ };
+
+ return clock_settime(CLOCK_REALTIME, &__ts);
+}
+
# elif defined __USE_SVID && defined __NR_stime
# define __need_NULL
# include <stddef.h>
@@ -36,7 +48,6 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
return stime(&when);
}
# endif
-# if defined __NR_settimeofday || (defined __USE_SVID && defined __NR_stime)
+# if defined __NR_settimeofday || defined(__UCLIBC_USE_TIME64__) || (defined __USE_SVID && defined __NR_stime)
libc_hidden_def(settimeofday)
# endif
-#endif
diff --git a/libc/sysdeps/linux/common/stat.c b/libc/sysdeps/linux/common/stat.c
index 6489d229b..42f39aea6 100644
--- a/libc/sysdeps/linux/common/stat.c
+++ b/libc/sysdeps/linux/common/stat.c
@@ -9,10 +9,11 @@
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <bits/uClibc_arch_features.h>
#undef stat
-#if defined __NR_fstatat64 && !defined __NR_stat
+#if defined __NR_fstatat64 && !defined __NR_stat && !defined(__UCLIBC_USE_TIME64__)
# include <fcntl.h>
int stat(const char *file_name, struct stat *buf)
@@ -25,9 +26,22 @@ int stat(const char *file_name, struct stat *buf)
int stat(const char *file_name, struct stat *buf)
{
- return fstatat64(AT_FDCWD, file_name, buf, 0);
+ return fstatat64(AT_FDCWD, file_name, (struct stat64 *)buf, 0);
}
+#elif __NR_statx && defined __UCLIBC_HAVE_STATX__
+# include <fcntl.h>
+# include <statx_cp.h>
+int stat(const char *file_name, struct stat *buf)
+{
+ struct statx tmp;
+ int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name, AT_NO_AUTOMOUNT,
+ STATX_BASIC_STATS, &tmp);
+ if (rc == 0)
+ __cp_stat_statx ((struct stat *)buf, &tmp);
+
+ return rc;
+}
#else
# include "xstatconv.h"
@@ -58,7 +72,7 @@ int stat(const char *file_name, struct stat *buf)
#endif /* __NR_fstat64 */
libc_hidden_def(stat)
-#if ! defined __NR_stat64 && ! defined __NR_fstatat64
+#if ! defined __NR_stat64 && ! defined __NR_fstatat64 && ! defined __UCLIBC_HAVE_STATX__
strong_alias_untyped(stat,stat64)
libc_hidden_def(stat64)
#endif
diff --git a/libc/sysdeps/linux/common/stat64.c b/libc/sysdeps/linux/common/stat64.c
index ef365c7e7..0875ba39d 100644
--- a/libc/sysdeps/linux/common/stat64.c
+++ b/libc/sysdeps/linux/common/stat64.c
@@ -10,7 +10,7 @@
#include <sys/syscall.h>
#include <sys/stat.h>
-#if defined __NR_fstatat64 && !defined __NR_stat64
+#if defined __NR_fstatat64 && !defined __NR_stat64 && !defined(__UCLIBC_USE_TIME64__)
#include <fcntl.h>
#include <unistd.h>
@@ -20,6 +20,22 @@ int stat64(const char *file_name, struct stat64 *buf)
}
libc_hidden_def(stat64)
+#elif __NR_statx && defined __UCLIBC_HAVE_STATX__
+# include <fcntl.h>
+# include <statx_cp.h>
+
+int stat64(const char *file_name, struct stat64 *buf)
+{
+ struct statx tmp;
+ int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name, AT_NO_AUTOMOUNT,
+ STATX_BASIC_STATS, &tmp);
+ if (rc == 0)
+ __cp_stat64_statx ((struct stat64 *)buf, &tmp);
+
+ return rc;
+}
+libc_hidden_def(stat64)
+
/* For systems which have both, prefer the old one */
# elif defined __NR_stat64
# define __NR___syscall_stat64 __NR_stat64
diff --git a/libc/sysdeps/linux/common/statx_cp.c b/libc/sysdeps/linux/common/statx_cp.c
new file mode 100644
index 000000000..c50d28ecb
--- /dev/null
+++ b/libc/sysdeps/linux/common/statx_cp.c
@@ -0,0 +1,76 @@
+/* Struct statx to stat/stat64 conversion for Linux.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <bits/uClibc_arch_features.h>
+#include <stddef.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#if defined __UCLIBC_HAVE_STATX__
+
+#include <statx_cp.h>
+
+#if (!defined(__NR_fstat64) || !defined(__NR_fstatat64)) || defined(__UCLIBC_USE_TIME64__)
+void
+__cp_stat64_statx (struct stat64 *to, struct statx *from)
+{
+ memset (to, 0, sizeof (struct stat64));
+ to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8)
+ | ((from->stx_dev_minor & ~0xff) << 12));
+ to->st_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8)
+ | ((from->stx_rdev_minor & ~0xff) << 12));
+ to->st_ino = from->stx_ino;
+ to->st_mode = from->stx_mode;
+ to->st_nlink = from->stx_nlink;
+ to->st_uid = from->stx_uid;
+ to->st_gid = from->stx_gid;
+ to->st_atime = from->stx_atime.tv_sec;
+ to->st_atim.tv_nsec = from->stx_atime.tv_nsec;
+ to->st_mtime = from->stx_mtime.tv_sec;
+ to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec;
+ to->st_ctime = from->stx_ctime.tv_sec;
+ to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec;
+ to->st_size = from->stx_size;
+ to->st_blocks = from->stx_blocks;
+ to->st_blksize = from->stx_blksize;
+}
+
+void
+__cp_stat_statx (struct stat *to, struct statx *from)
+{
+ memset (to, 0, sizeof (struct stat));
+ to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8)
+ | ((from->stx_dev_minor & ~0xff) << 12));
+ to->st_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8)
+ | ((from->stx_rdev_minor & ~0xff) << 12));
+ to->st_ino = from->stx_ino;
+ to->st_mode = from->stx_mode;
+ to->st_nlink = from->stx_nlink;
+ to->st_uid = from->stx_uid;
+ to->st_gid = from->stx_gid;
+ to->st_atime = from->stx_atime.tv_sec;
+ to->st_atim.tv_nsec = from->stx_atime.tv_nsec;
+ to->st_mtime = from->stx_mtime.tv_sec;
+ to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec;
+ to->st_ctime = from->stx_ctime.tv_sec;
+ to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec;
+ to->st_size = from->stx_size;
+ to->st_blocks = from->stx_blocks;
+ to->st_blksize = from->stx_blksize;
+}
+#endif
+#endif
diff --git a/libc/sysdeps/linux/common/statx_cp.h b/libc/sysdeps/linux/common/statx_cp.h
new file mode 100644
index 000000000..ff8fc9931
--- /dev/null
+++ b/libc/sysdeps/linux/common/statx_cp.h
@@ -0,0 +1,22 @@
+/* Struct statx to stat/stat64 conversion for Linux.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+extern void __cp_stat64_statx (struct stat64 *to, struct statx *from)
+ attribute_hidden;
+
+extern void __cp_stat_statx (struct stat *to, struct statx *from)
+ attribute_hidden;
diff --git a/libc/sysdeps/linux/common/stubs.c b/libc/sysdeps/linux/common/stubs.c
index c17e509b9..634dcde0d 100644
--- a/libc/sysdeps/linux/common/stubs.c
+++ b/libc/sysdeps/linux/common/stubs.c
@@ -34,10 +34,6 @@ __attribute_used__ static int ret_enosys_stub(void)
link_warning(stub, #stub ": this function is not implemented") \
strong_alias(ret_enosys_stub, stub)
-#ifndef __ARCH_USE_MMU__
-# undef __NR_fork
-#endif
-
#ifdef __arm__
# define __NR_fadvise64_64 __NR_arm_fadvise64_64
# define __NR_fadvise64 __NR_arm_fadvise64_64
@@ -120,7 +116,7 @@ make_stub(fgetxattr)
make_stub(flistxattr)
#endif
-#if !defined __NR_fork && !defined __NR_clone
+#if !defined __ARCH_USE_MMU__ || (!defined __NR_fork && !defined __NR_clone)
make_stub(fork)
#endif
diff --git a/libc/sysdeps/linux/common/sys/ptrace.h b/libc/sysdeps/linux/common/sys/ptrace.h
index 6b3c7b574..ebafe4e27 100644
--- a/libc/sysdeps/linux/common/sys/ptrace.h
+++ b/libc/sysdeps/linux/common/sys/ptrace.h
@@ -171,7 +171,7 @@ enum __ptrace_eventcodes
PTRACE_EVENT_EXEC = 4,
PTRACE_EVENT_VFORK_DONE = 5,
PTRACE_EVENT_EXIT = 6,
- PTRAVE_EVENT_SECCOMP = 7
+ PTRACE_EVENT_SECCOMP = 7
};
/* Perform process tracing functions. REQUEST is one of the values
diff --git a/libc/sysdeps/linux/common/sys/random.h b/libc/sysdeps/linux/common/sys/random.h
index 42f802576..3d12744ad 100644
--- a/libc/sysdeps/linux/common/sys/random.h
+++ b/libc/sysdeps/linux/common/sys/random.h
@@ -5,6 +5,7 @@
#ifndef _SYS_RANDOM_H
#define _SYS_RANDOM_H 1
#include <features.h>
+#include <stddef.h>
__BEGIN_DECLS
diff --git a/libc/sysdeps/linux/common/sysctl.c b/libc/sysdeps/linux/common/sysctl.c
index 75f9236d0..d3e28f919 100644
--- a/libc/sysdeps/linux/common/sysctl.c
+++ b/libc/sysdeps/linux/common/sysctl.c
@@ -17,7 +17,7 @@ struct __sysctl_args {
size_t *oldlenp;
void *newval;
size_t newlen;
- unsigned long __unused[4];
+ unsigned long __uclibc_unused[4];
};
extern int sysctl (int *__name, int __nlen, void *__oldval,
size_t *__oldlenp, void *__newval, size_t __newlen) __THROW;
diff --git a/libc/sysdeps/linux/common/time.c b/libc/sysdeps/linux/common/time.c
index 22403f174..d084ffaad 100644
--- a/libc/sysdeps/linux/common/time.c
+++ b/libc/sysdeps/linux/common/time.c
@@ -9,7 +9,7 @@
#include <sys/syscall.h>
#include <time.h>
-#ifdef __NR_time
+#if defined(__NR_time) && !defined(__UCLIBC_USE_TIME64__)
_syscall_noerr1(time_t, time, time_t *, t)
#else
# include <sys/time.h>
diff --git a/libc/sysdeps/linux/common/timerfd.c b/libc/sysdeps/linux/common/timerfd.c
index f4854ac90..b4a9e1a93 100644
--- a/libc/sysdeps/linux/common/timerfd.c
+++ b/libc/sysdeps/linux/common/timerfd.c
@@ -9,6 +9,10 @@
#include <sys/syscall.h>
#include <sys/timerfd.h>
+#if defined(__UCLIBC_USE_TIME64__)
+#include "internal/time64_helpers.h"
+#endif
+
/*
* timerfd_create()
*/
@@ -19,13 +23,24 @@ _syscall2(int, timerfd_create, int, clockid, int, flags)
/*
* timerfd_settime()
*/
-#ifdef __NR_timerfd_settime
-_syscall4(int,timerfd_settime, int, ufd, int, flags, const struct itimerspec *, utmr, struct itimerspec *, otmr)
+#if defined(__NR_timerfd_settime) || defined(__NR_timerfd_settime64)
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_timerfd_settime64)
+int timerfd_settime(int ufd, int flags, const struct itimerspec *utmr, struct itimerspec *otmr)
+{
+ return INLINE_SYSCALL(timerfd_settime64, 4, ufd, flags, TO_ITS64_P(utmr), otmr);
+}
+#else
+_syscall4(int, timerfd_settime, int, ufd, int, flags, const struct itimerspec *, utmr, struct itimerspec *, otmr)
+#endif
#endif
/*
* timerfd_gettime()
*/
-#ifdef __NR_timerfd_gettime
+#if defined(__NR_timerfd_gettime) || defined(__NR_timerfd_gettime64)
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_timerfd_gettime64)
+_syscall2_64(int, timerfd_gettime, int, ufd, struct itimerspec *, otmr)
+#else
_syscall2(int, timerfd_gettime, int, ufd, struct itimerspec *, otmr)
#endif
+#endif
diff --git a/libc/sysdeps/linux/common/umount2.c b/libc/sysdeps/linux/common/umount2.c
index b39d8ef73..507171f24 100644
--- a/libc/sysdeps/linux/common/umount2.c
+++ b/libc/sysdeps/linux/common/umount2.c
@@ -14,7 +14,7 @@ _syscall2(int, umount2, const char *, special_file, int, flags)
libc_hidden_def(umount2)
#endif
-#if defined __UCLIBC_LINUX_SPECIFIC__ && defined __NR_oldumount
+#if defined __UCLIBC_LINUX_SPECIFIC__ && defined __NR_oldumount && !defined __NR_umount2
_syscall2(int, umount, const char *, special_file, int, flags)
strong_alias(umount,umount2)
#endif
diff --git a/libc/sysdeps/linux/common/utimensat.c b/libc/sysdeps/linux/common/utimensat.c
index 2cfb8247d..5816c7890 100644
--- a/libc/sysdeps/linux/common/utimensat.c
+++ b/libc/sysdeps/linux/common/utimensat.c
@@ -8,9 +8,32 @@
#include <sys/syscall.h>
#include <sys/stat.h>
+#include <stdint.h>
-#ifdef __NR_utimensat
+#if defined(__UCLIBC_USE_TIME64__)
+#include "internal/time64_helpers.h"
+#endif
+
+#if defined(__NR_utimensat) || defined(__NR_utimensat_time64)
+#if defined(__UCLIBC_USE_TIME64__) && defined(__NR_utimensat_time64)
+int utimensat(int fd, const char *path, const struct timespec times[2], int flags)
+{
+ struct __ts64_struct __times64[2] = {
+ {
+ .tv_sec = times ? times[0].tv_sec : 0,
+ .tv_nsec = times ? times[0].tv_nsec : 0
+ },
+ {
+ .tv_sec = times ? times[1].tv_sec : 0,
+ .tv_nsec = times ? times[1].tv_nsec : 0
+ }
+ };
+
+ return INLINE_SYSCALL(utimensat_time64, 4, fd, path, times ? (uintptr_t) &__times64 : 0, flags);
+}
+#else
_syscall4(int, utimensat, int, fd, const char *, path, const struct timespec *, times, int, flags)
+#endif
libc_hidden_def(utimensat)
#else
/* should add emulation with utimens() and /proc/self/fd/ ... */
diff --git a/libc/sysdeps/linux/common/utimes.c b/libc/sysdeps/linux/common/utimes.c
index e6fc578f3..a28594dfd 100644
--- a/libc/sysdeps/linux/common/utimes.c
+++ b/libc/sysdeps/linux/common/utimes.c
@@ -9,7 +9,7 @@
#include <sys/syscall.h>
#include <sys/time.h>
-#if defined __NR_utimensat && !defined __NR_utimes
+#if (defined (__NR_utimensat) || defined(__NR_utimensat_time64)) && !defined __NR_utimes
# include <fcntl.h>
# include <stddef.h>
int utimes(const char *file, const struct timeval tvp[2])
@@ -50,6 +50,6 @@ int utimes(const char *file, const struct timeval tvp[2])
}
#endif
-#if defined __NR_utimensat || defined __NR_utimes || defined __NR_utime
+#if defined __NR_utimensat || defined __NR_utimensat_time64 || defined __NR_utimes || defined __NR_utime
libc_hidden_def(utimes)
#endif
diff --git a/libc/sysdeps/linux/common/wait4.c b/libc/sysdeps/linux/common/wait4.c
index 19f02ae22..486ffaab8 100644
--- a/libc/sysdeps/linux/common/wait4.c
+++ b/libc/sysdeps/linux/common/wait4.c
@@ -8,15 +8,84 @@
#include <sys/syscall.h>
#include <sys/wait.h>
+#include <sys/resource.h>
+#if defined(__NR_wait4)
# define __NR___syscall_wait4 __NR_wait4
static __always_inline _syscall4(int, __syscall_wait4, __kernel_pid_t, pid,
int *, status, int, opts, struct rusage *, rusage)
pid_t __wait4_nocancel(pid_t pid, int *status, int opts, struct rusage *rusage)
{
+#if defined(__UCLIBC_USE_TIME64__)
+ char *arg_rusage = rusage ? (char *)&rusage->ru_maxrss - 4 * sizeof(__S32_TYPE) : 0;
+ int __ret = __syscall_wait4(pid, status, opts, (struct rusage *)arg_rusage);
+ if (__ret > 0 && rusage) {
+ __S32_TYPE __rusage[4];
+ memcpy(__rusage, arg_rusage, 4 * sizeof(__S32_TYPE));
+ struct timeval tv_utime = {.tv_sec = __rusage[0], .tv_usec = __rusage[1]};
+ struct timeval tv_stime = {.tv_sec = __rusage[2], .tv_usec = __rusage[2]};
+ rusage->ru_utime = tv_utime;
+ rusage->ru_stime = tv_stime;
+ }
+ return __ret;
+#else
return __syscall_wait4(pid, status, opts, rusage);
+#endif
}
+
+#else
+pid_t __wait4_nocancel(pid_t pid, int *status, int opts, struct rusage *rusage)
+{
+ idtype_t type;
+ int __res;
+ siginfo_t info;
+
+ info.si_pid = 0;
+
+ if (pid < -1) {
+ type = P_PGID;
+ pid = -pid;
+ } else if (pid == -1) {
+ type = P_ALL;
+ } else if (pid == 0) {
+ type = P_PGID;
+ } else {
+ type = P_PID;
+ }
+
+ __res = INLINE_SYSCALL(waitid, 5, type, pid, &info, opts|WEXITED, rusage);
+
+ if ( __res < 0 )
+ return __res;
+
+ if (info.si_pid && status) {
+ int sw = 0;
+ switch (info.si_code) {
+ case CLD_CONTINUED:
+ sw = 0xffff;
+ break;
+ case CLD_DUMPED:
+ sw = (info.si_status & 0x7f) | 0x80;
+ break;
+ case CLD_EXITED:
+ sw = (info.si_status & 0xff) << 8;
+ break;
+ case CLD_KILLED:
+ sw = info.si_status & 0x7f;
+ break;
+ case CLD_STOPPED:
+ case CLD_TRAPPED:
+ sw = (info.si_status << 8) + 0x7f;
+ break;
+ }
+ *status = sw;
+ }
+
+ return info.si_pid;
+}
+#endif
+
#ifdef __USE_BSD
strong_alias(__wait4_nocancel,wait4)
#endif
diff --git a/libc/sysdeps/linux/cris/bits/fcntl.h b/libc/sysdeps/linux/cris/bits/fcntl.h
index 27f1f8b91..e9bc90ea9 100644
--- a/libc/sysdeps/linux/cris/bits/fcntl.h
+++ b/libc/sysdeps/linux/cris/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/cris/bits/kernel_stat.h b/libc/sysdeps/linux/cris/bits/kernel_stat.h
index 619f35e9e..9038a5ab5 100644
--- a/libc/sysdeps/linux/cris/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/cris/bits/kernel_stat.h
@@ -19,8 +19,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
/* This matches struct kernel_stat64 in glibc2.1, hence the absolutely
diff --git a/libc/sysdeps/linux/cris/bits/uClibc_arch_features.h b/libc/sysdeps/linux/cris/bits/uClibc_arch_features.h
index 517f68cd6..96cada276 100644
--- a/libc/sysdeps/linux/cris/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/cris/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#undef __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/csky/Makefile.arch b/libc/sysdeps/linux/csky/Makefile.arch
index 704b36aff..a3157c265 100644
--- a/libc/sysdeps/linux/csky/Makefile.arch
+++ b/libc/sysdeps/linux/csky/Makefile.arch
@@ -1,6 +1,6 @@
CSRC-y := clone.c __syscall_error.c cacheflush.c
SSRC-y := __longjmp.S setjmp.S
-SSRC-y += libc-read_tp.S vfork.S csky_clone.S
+SSRC-y += libc-read_tp.S csky_clone.S
diff --git a/libc/sysdeps/linux/csky/__syscall_error.c b/libc/sysdeps/linux/csky/__syscall_error.c
index cc1fb5977..c6a4a14eb 100644
--- a/libc/sysdeps/linux/csky/__syscall_error.c
+++ b/libc/sysdeps/linux/csky/__syscall_error.c
@@ -8,7 +8,7 @@
#include <errno.h>
#include <features.h>
-int __syscall_error(int err_no)
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/csky/bits/fcntl.h b/libc/sysdeps/linux/csky/bits/fcntl.h
index b434badd6..b36f41569 100644
--- a/libc/sysdeps/linux/csky/bits/fcntl.h
+++ b/libc/sysdeps/linux/csky/bits/fcntl.h
@@ -33,15 +33,16 @@
#define O_ASYNC 020000
#ifdef __USE_XOPEN2K8
-# define O_DIRECTORY 040000 /* Must be a directory. */
-# define O_NOFOLLOW 0100000 /* Do not follow links. */
+# define O_DIRECTORY 00200000 /* must be a directory */
+# define O_NOFOLLOW 00400000 /* don't follow links */
# define O_CLOEXEC 02000000 /* Set close_on_exec. */
#endif
#ifdef __USE_GNU
-# define O_DIRECT 0200000 /* Direct disk access. */
+# define O_DIRECT 00040000 /* direct disk access hint */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -89,11 +90,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/csky/bits/kernel_stat.h b/libc/sysdeps/linux/csky/bits/kernel_stat.h
index dae77fd02..617632f48 100644
--- a/libc/sysdeps/linux/csky/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/csky/bits/kernel_stat.h
@@ -34,8 +34,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
diff --git a/libc/sysdeps/linux/csky/bits/shm.h b/libc/sysdeps/linux/csky/bits/shm.h
index dced1321e..d464318ec 100644
--- a/libc/sysdeps/linux/csky/bits/shm.h
+++ b/libc/sysdeps/linux/csky/bits/shm.h
@@ -40,16 +40,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -71,10 +71,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/csky/clone.c b/libc/sysdeps/linux/csky/clone.c
index 991cb8962..f0fcc257b 100644
--- a/libc/sysdeps/linux/csky/clone.c
+++ b/libc/sysdeps/linux/csky/clone.c
@@ -9,7 +9,7 @@
#include <sysdep.h>
#include <unistd.h>
-extern int __syscall_error(int err_no);
+extern long __syscall_error(int err_no);
extern int __csky_clone (
int flags,
diff --git a/libc/sysdeps/linux/frv/bits/fcntl.h b/libc/sysdeps/linux/frv/bits/fcntl.h
index b5fe0b588..02c8ac310 100644
--- a/libc/sysdeps/linux/frv/bits/fcntl.h
+++ b/libc/sysdeps/linux/frv/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* don't set atime */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/frv/bits/kernel_stat.h b/libc/sysdeps/linux/frv/bits/kernel_stat.h
index 1cf521044..cda016ce4 100644
--- a/libc/sysdeps/linux/frv/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/frv/bits/kernel_stat.h
@@ -38,7 +38,7 @@ struct kernel_stat {
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long long __unused4;
+ unsigned long long __uclibc_unused4;
};
struct kernel_stat64 {
@@ -68,7 +68,7 @@ struct kernel_stat64 {
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long long __unused4;
+ unsigned long long __uclibc_unused4;
};
#endif /* _BITS_STAT_STRUCT_H */
diff --git a/libc/sysdeps/linux/frv/bits/stat.h b/libc/sysdeps/linux/frv/bits/stat.h
index e6a1944bb..381d207f2 100644
--- a/libc/sysdeps/linux/frv/bits/stat.h
+++ b/libc/sysdeps/linux/frv/bits/stat.h
@@ -84,16 +84,16 @@ struct stat
# define st_mtime st_mtim.tv_sec
# define st_ctime st_ctim.tv_sec
#else
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t st_atime; /* Time of last access. */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t st_mtime; /* Time of last modification. */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__time_t st_ctime; /* Time of last status change. */
#endif
- unsigned long long __unused4;
+ unsigned long long __uclibc_unused4;
};
#ifdef __USE_LARGEFILE64
@@ -131,16 +131,16 @@ struct stat64
# define st_mtime st_mtim.tv_sec
# define st_ctime st_ctim.tv_sec
#else
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t st_atime; /* Time of last access. */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t st_mtime; /* Time of last modification. */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__time_t st_ctime; /* Time of last status change. */
#endif
- unsigned long long __unused4;
+ unsigned long long __uclibc_unused4;
};
#endif
diff --git a/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h b/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h
index f660fd223..916b1e28d 100644
--- a/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/frv/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#undef __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/frv/sysdep.c b/libc/sysdeps/linux/frv/sysdep.c
index bfae12100..28beb418f 100644
--- a/libc/sysdeps/linux/frv/sysdep.c
+++ b/libc/sysdeps/linux/frv/sysdep.c
@@ -19,7 +19,7 @@
/* This routine is jumped to by all the syscall handlers, to stash
an error number into errno. */
-int __syscall_error (int err_no)
+long __syscall_error (int err_no)
{
__set_errno (-err_no);
return -1;
diff --git a/libc/sysdeps/linux/h8300/bits/fcntl.h b/libc/sysdeps/linux/h8300/bits/fcntl.h
index 64ec08ff2..2062f7cda 100644
--- a/libc/sysdeps/linux/h8300/bits/fcntl.h
+++ b/libc/sysdeps/linux/h8300/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/h8300/bits/uClibc_arch_features.h b/libc/sysdeps/linux/h8300/bits/uClibc_arch_features.h
index 6047d1482..e2ac28bbf 100644
--- a/libc/sysdeps/linux/h8300/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/h8300/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/hppa/__syscall_error.c b/libc/sysdeps/linux/hppa/__syscall_error.c
index 5e109a83b..af26cf6ab 100644
--- a/libc/sysdeps/linux/hppa/__syscall_error.c
+++ b/libc/sysdeps/linux/hppa/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(err_no);
return -1;
diff --git a/libc/sysdeps/linux/hppa/bits/fcntl.h b/libc/sysdeps/linux/hppa/bits/fcntl.h
index 719955802..4ce76ce5f 100644
--- a/libc/sysdeps/linux/hppa/bits/fcntl.h
+++ b/libc/sysdeps/linux/hppa/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 00040000 /* Direct disk access. */
# define O_NOATIME 04000000 /* Do not set atime. */
# define O_PATH 020000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 040010000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -97,11 +98,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* for F_[GET|SET]FL */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/hppa/bits/ipc.h b/libc/sysdeps/linux/hppa/bits/ipc.h
index e634a74b3..fc71db409 100644
--- a/libc/sysdeps/linux/hppa/bits/ipc.h
+++ b/libc/sysdeps/linux/hppa/bits/ipc.h
@@ -57,6 +57,6 @@ struct ipc_perm
#endif
unsigned short int __seq; /* Sequence number. */
unsigned int __pad3;
- unsigned long long int __unused1;
- unsigned long long int __unused2;
+ unsigned long long int __uclibc_unused1;
+ unsigned long long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/hppa/bits/uClibc_arch_features.h b/libc/sysdeps/linux/hppa/bits/uClibc_arch_features.h
index 1c096bd17..30bfdef5d 100644
--- a/libc/sysdeps/linux/hppa/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/hppa/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/i386/__syscall_error.c b/libc/sysdeps/linux/i386/__syscall_error.c
index 36946bc6d..102ebbedb 100644
--- a/libc/sysdeps/linux/i386/__syscall_error.c
+++ b/libc/sysdeps/linux/i386/__syscall_error.c
@@ -25,8 +25,8 @@
#include <errno.h>
#include <features.h>
-int __syscall_error(void) attribute_hidden;
-int __syscall_error(void)
+long __syscall_error(void) attribute_hidden;
+long __syscall_error(void)
{
register int eax __asm__ ("%eax");
int _errno = -eax;
diff --git a/libc/sysdeps/linux/i386/bits/fcntl.h b/libc/sysdeps/linux/i386/bits/fcntl.h
index d03489ebf..f3c08bbe5 100644
--- a/libc/sysdeps/linux/i386/bits/fcntl.h
+++ b/libc/sysdeps/linux/i386/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/i386/bits/fenv.h b/libc/sysdeps/linux/i386/bits/fenv.h
index 9bd976fc1..2462b7477 100644
--- a/libc/sysdeps/linux/i386/bits/fenv.h
+++ b/libc/sysdeps/linux/i386/bits/fenv.h
@@ -65,18 +65,18 @@ typedef unsigned short int fexcept_t;
typedef struct
{
unsigned short int __control_word;
- unsigned short int __unused1;
+ unsigned short int __uclibc_unused1;
unsigned short int __status_word;
- unsigned short int __unused2;
+ unsigned short int __uclibc_unused2;
unsigned short int __tags;
- unsigned short int __unused3;
+ unsigned short int __uclibc_unused3;
unsigned int __eip;
unsigned short int __cs_selector;
unsigned int __opcode:11;
- unsigned int __unused4:5;
+ unsigned int __uclibc_unused4:5;
unsigned int __data_offset;
unsigned short int __data_selector;
- unsigned short int __unused5;
+ unsigned short int __uclibc_unused5;
}
fenv_t;
diff --git a/libc/sysdeps/linux/i386/bits/kernel_stat.h b/libc/sysdeps/linux/i386/bits/kernel_stat.h
index 231a984b4..ffe70cbf7 100644
--- a/libc/sysdeps/linux/i386/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/i386/bits/kernel_stat.h
@@ -20,8 +20,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
diff --git a/libc/sysdeps/linux/i386/crt1.S b/libc/sysdeps/linux/i386/crt1.S
index 35a6552e8..decc68967 100644
--- a/libc/sysdeps/linux/i386/crt1.S
+++ b/libc/sysdeps/linux/i386/crt1.S
@@ -67,6 +67,9 @@
#endif
.type main,%function
.type __uClibc_main,%function
+#ifdef L_rcrt1
+.type reloc_static_pie,%function
+#endif
_start:
/* Clear the frame pointer. The ABI suggests this be done, to mark
the outermost frame obviously. */
@@ -100,6 +103,23 @@ _start:
pop %ebx
addl $_GLOBAL_OFFSET_TABLE_+[.-.L0],%ebx
+#ifdef L_rcrt1
+ /* We cannot rely on _DYNAMIC being usable here due to RELRO.
+ Instead we calculate the load address based off a symbol
+ that we know will exist, _start. */
+ pushl %ecx /* Save ecx so it won't get clobbered */
+ pushl %ebx /* Save ebx so it won't get clobbered */
+ xorl %ecx, %ecx /* Clear ecx */
+ addl _start@GOT(%ebx), %ecx /* Get the offset of _start */
+ movl _start@GOT(%ebx), %eax /* Get the run time address of _start */
+ subl %ecx, %eax /* Subtract to find the load address */
+ pushl %eax /* Pass the load address */
+ call reloc_static_pie@PLT
+ popl %eax /* Clean up from function call */
+ popl %ebx /* Restore the GOT address */
+ popl %ecx /* restore ecx */
+#endif
+
/* Push address of our own entry points to .fini and .init. */
pushl _fini@GOT(%ebx)
pushl _init@GOT(%ebx)
diff --git a/libc/sysdeps/linux/i386/sigaction.c b/libc/sysdeps/linux/i386/sigaction.c
index cf6daa787..515ef99f2 100644
--- a/libc/sysdeps/linux/i386/sigaction.c
+++ b/libc/sysdeps/linux/i386/sigaction.c
@@ -31,15 +31,16 @@
extern void restore_rt(void) __asm__ ("__restore_rt") attribute_hidden;
extern void restore(void) __asm__ ("__restore") attribute_hidden;
-/* If ACT is not NULL, change the action for SIG to *ACT.
+/* If ACT is not NULL, change mask, handler and flags for SIG to ACT's
If OACT is not NULL, put the old action for SIG in *OACT. */
int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
{
struct sigaction kact;
if (act) {
- memcpy(&kact, act, sizeof(kact));
- kact.sa_flags |= SA_RESTORER;
+ memcpy(&kact.sa_mask, &act->sa_mask, sizeof(sigset_t));
+ kact.sa_handler = act->sa_handler;
+ kact.sa_flags = act->sa_flags;
kact.sa_restorer = (act->sa_flags & SA_SIGINFO) ? &restore_rt : &restore;
act = &kact;
}
diff --git a/libc/sysdeps/linux/ia64/__syscall_error.c b/libc/sysdeps/linux/ia64/__syscall_error.c
index 0727b2b53..cc2b13450 100644
--- a/libc/sysdeps/linux/ia64/__syscall_error.c
+++ b/libc/sysdeps/linux/ia64/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(void) attribute_hidden;
-int __syscall_error(void)
+long __syscall_error(void) attribute_hidden;
+long __syscall_error(void)
{
register int err_no __asm__("%r8");
__set_errno(err_no);
diff --git a/libc/sysdeps/linux/ia64/bits/fcntl.h b/libc/sysdeps/linux/ia64/bits/fcntl.h
index 66f4e9ceb..a20f44ff7 100644
--- a/libc/sysdeps/linux/ia64/bits/fcntl.h
+++ b/libc/sysdeps/linux/ia64/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -97,11 +98,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/ia64/bits/ipc.h b/libc/sysdeps/linux/ia64/bits/ipc.h
index eb014d7b9..6c93a1fa6 100644
--- a/libc/sysdeps/linux/ia64/bits/ipc.h
+++ b/libc/sysdeps/linux/ia64/bits/ipc.h
@@ -48,6 +48,6 @@ struct ipc_perm
__mode_t mode; /* Read/write permission. */
unsigned short int __seq; /* Sequence number. */
unsigned short int __pad1;
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/ia64/bits/msq.h b/libc/sysdeps/linux/ia64/bits/msq.h
index 2dea98627..fe2181da2 100644
--- a/libc/sysdeps/linux/ia64/bits/msq.h
+++ b/libc/sysdeps/linux/ia64/bits/msq.h
@@ -40,8 +40,8 @@ struct msqid_ds
unsigned long int msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/ia64/bits/sem.h b/libc/sysdeps/linux/ia64/bits/sem.h
index aa56e155d..b081cb038 100644
--- a/libc/sysdeps/linux/ia64/bits/sem.h
+++ b/libc/sysdeps/linux/ia64/bits/sem.h
@@ -43,8 +43,8 @@ struct semid_ds
__time_t sem_otime; /* last semop() time */
__time_t sem_ctime; /* last time changed by semctl() */
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/ia64/bits/shm.h b/libc/sysdeps/linux/ia64/bits/shm.h
index 0d0c96e6f..d91c90459 100644
--- a/libc/sysdeps/linux/ia64/bits/shm.h
+++ b/libc/sysdeps/linux/ia64/bits/shm.h
@@ -51,8 +51,8 @@ struct shmid_ds
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
@@ -74,10 +74,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/ia64/bits/stat.h b/libc/sysdeps/linux/ia64/bits/stat.h
index e868b0950..6723166e7 100644
--- a/libc/sysdeps/linux/ia64/bits/stat.h
+++ b/libc/sysdeps/linux/ia64/bits/stat.h
@@ -61,7 +61,7 @@ struct stat
#endif
__blksize_t st_blksize; /* Optimal block size for I/O. */
__blkcnt_t st_blocks; /* Nr. 512-byte blocks allocated. */
- long int __unused[3];
+ long int __uclibc_unused[3];
};
#ifdef __USE_LARGEFILE64
@@ -100,7 +100,7 @@ struct stat64
#endif
__blksize_t st_blksize; /* Optimal block size for I/O. */
__blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
- long int __unused[3];
+ long int __uclibc_unused[3];
};
#endif
diff --git a/libc/sysdeps/linux/ia64/bits/uClibc_arch_features.h b/libc/sysdeps/linux/ia64/bits/uClibc_arch_features.h
index 25c983206..a1e6419ba 100644
--- a/libc/sysdeps/linux/ia64/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/ia64/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/kvx/Makefile b/libc/sysdeps/linux/kvx/Makefile
new file mode 100644
index 000000000..633c91f3e
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/Makefile
@@ -0,0 +1,13 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+top_srcdir=../../../../
+top_builddir=../../../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.arch
+include $(top_srcdir)Makerules
diff --git a/libc/sysdeps/linux/kvx/Makefile.arch b/libc/sysdeps/linux/kvx/Makefile.arch
new file mode 100644
index 000000000..3ad290915
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/Makefile.arch
@@ -0,0 +1,10 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+CSRC-y := __syscall_error.c
+CSRC-$(UCLIBC_LINUX_SPECIFIC) += cachectl.c
+SSRC-y := setjmp.S bsd-setjmp.S bsd-_setjmp.S __longjmp.S clone.S vfork.S
diff --git a/libc/sysdeps/linux/kvx/__longjmp.S b/libc/sysdeps/linux/kvx/__longjmp.S
new file mode 100644
index 000000000..fbfefe81c
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/__longjmp.S
@@ -0,0 +1,53 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <sysdep.h>
+#define _SETJMP_H
+#define _ASM
+#include <bits/setjmp.h>
+#include <libc-symbols.h>
+
+/**
+ * void __longjmp(__jmp_buf __env, int __val)
+ */
+ENTRY(__longjmp)
+ /* Load $ra and $csinto r40r41 */
+ lq $r40r41 = JMPBUF_RA_CS_OFFSET[$r0]
+ ;;
+ /* Load $r36r37r38r39 with r12(sp) r14 r18 r19 */
+ lo $r36r37r38r39 = (JMPBUF_REGS_OFFSET)[$r0]
+ set $ra = $r40
+ ;;
+ /* Load $lc, $le and $ls */
+ lo $r32r33r34r35 = JMPBUF_LC_LE_LS_OFFSET[$r0]
+ copyd $sp = $r36
+ copyd $r14 = $r37
+ set $cs = $r41
+ ;;
+ /* Load r20r21r22r23 */
+ lo $r20r21r22r23 = (JMPBUF_REGS_OFFSET + QUAD_REG_SIZE)[$r0]
+ copyd $r18 = $r38
+ copyd $r19 = $r39
+ set $lc = $r32
+ ;;
+ /* Load r24r25r26r27 */
+ lo $r24r25r26r27 = (JMPBUF_REGS_OFFSET + 2 * QUAD_REG_SIZE)[$r0]
+ set $le = $r33
+ ;;
+ /* Load r28r29r30r31 */
+ lo $r28r29r30r31 = (JMPBUF_REGS_OFFSET + 3 * QUAD_REG_SIZE)[$r0]
+ set $ls = $r34
+ /* Copy retval */
+ copyd $r0 = $r1
+ ;;
+ /* According to man, if retval is equal to 0, then we should return 1 */
+ cmoved.deqz $r0? $r0 = 1
+ ret
+ ;;
+END(__longjmp)
+libc_hidden_def(__longjmp)
diff --git a/libc/sysdeps/linux/kvx/__syscall_error.c b/libc/sysdeps/linux/kvx/__syscall_error.c
new file mode 100644
index 000000000..d534ee7d4
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/__syscall_error.c
@@ -0,0 +1,19 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <errno.h>
+#include <features.h>
+
+/* This routine is jumped to by all the syscall handlers, to stash
+ * an error number into errno. */
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
+{
+ __set_errno(-err_no);
+ return -1;
+}
diff --git a/libc/sysdeps/linux/kvx/bits/atomic.h b/libc/sysdeps/linux/kvx/bits/atomic.h
new file mode 100644
index 000000000..6e81e6704
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/atomic.h
@@ -0,0 +1,195 @@
+/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
+ Copyright (C) 2023 Kalray Inc.
+
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Mostly copied from aarch64 atomic.h */
+
+#ifndef _KVX_BITS_ATOMIC_H
+#define _KVX_BITS_ATOMIC_H
+
+#define typeof __typeof__
+
+#include <stdint.h>
+#include <sysdep.h>
+
+typedef int8_t atomic8_t;
+typedef uint8_t uatomic8_t;
+typedef int_fast8_t atomic_fast8_t;
+typedef uint_fast8_t uatomic_fast8_t;
+
+typedef int16_t atomic16_t;
+typedef uint16_t uatomic16_t;
+typedef int_fast16_t atomic_fast16_t;
+typedef uint_fast16_t uatomic_fast16_t;
+
+typedef int32_t atomic32_t;
+typedef uint32_t uatomic32_t;
+typedef int_fast32_t atomic_fast32_t;
+typedef uint_fast32_t uatomic_fast32_t;
+
+typedef int64_t atomic64_t;
+typedef uint64_t uatomic64_t;
+typedef int_fast64_t atomic_fast64_t;
+typedef uint_fast64_t uatomic_fast64_t;
+
+typedef intptr_t atomicptr_t;
+typedef uintptr_t uatomicptr_t;
+typedef intmax_t atomic_max_t;
+typedef uintmax_t uatomic_max_t;
+
+
+#ifndef atomic_full_barrier
+# define atomic_full_barrier() do { atomic_read_barrier(); \
+ atomic_write_barrier(); } while(0)
+#endif
+
+#ifndef atomic_read_barrier
+# define atomic_read_barrier() __builtin_kvx_dinval()
+#endif
+
+#ifndef atomic_write_barrier
+# define atomic_write_barrier() __builtin_kvx_fence()
+#endif
+
+#define __HAVE_64B_ATOMICS 1
+#define USE_ATOMIC_COMPILER_BUILTINS 1
+
+/* Compare and exchange.
+ For all "bool" routines, we return FALSE if exchange succesful. */
+
+# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+
+/* Compare and exchange with "acquire" semantics, ie barrier after. */
+
+# define atomic_compare_and_exchange_bool_acq(mem, new, old) \
+ __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
+ mem, new, old, __ATOMIC_ACQUIRE)
+
+# define atomic_compare_and_exchange_val_acq(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old, __ATOMIC_ACQUIRE)
+
+/* Compare and exchange with "release" semantics, ie barrier before. */
+
+# define atomic_compare_and_exchange_val_rel(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old, __ATOMIC_RELEASE)
+
+
+/* Atomic exchange (without compare). */
+
+# define __arch_exchange_8_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_16_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_32_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_64_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define atomic_exchange_acq(mem, value) \
+ __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
+
+# define atomic_exchange_rel(mem, value) \
+ __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
+
+
+/* Atomically add value and return the previous (unincremented) value. */
+
+# define __arch_exchange_and_add_8_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_16_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_32_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_64_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define atomic_exchange_and_add_acq(mem, value) \
+ __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+ __ATOMIC_ACQUIRE)
+
+# define atomic_exchange_and_add_rel(mem, value) \
+ __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+
+#endif
diff --git a/libc/sysdeps/linux/kvx/bits/endian.h b/libc/sysdeps/linux/kvx/bits/endian.h
new file mode 100644
index 000000000..03a1b7f0c
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/endian.h
@@ -0,0 +1,13 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+#define __BYTE_ORDER __LITTLE_ENDIAN
diff --git a/libc/sysdeps/linux/kvx/bits/fcntl.h b/libc/sysdeps/linux/kvx/bits/fcntl.h
new file mode 100644
index 000000000..ea0c59d09
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/fcntl.h
@@ -0,0 +1,229 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_XOPEN2K8
+# define O_DIRECTORY 0200000 /* Must be a directory. */
+# define O_NOFOLLOW 0400000 /* Do not follow links. */
+# define O_CLOEXEC 02000000 /* Set close_on_exec. */
+#endif
+
+#ifdef __USE_GNU
+# define O_DIRECT 040000 /* Direct disk access. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define O_LARGEFILE 0100000
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+
+#define F_GETLK 5 /* Get record locking info. */
+#define F_SETLK 6 /* Set record locking info (non-blocking). */
+#define F_SETLKW 7 /* Set record locking info (blocking). */
+
+/* Same as standard, since we always have 64-bit offsets. */
+#define F_GETLK64 F_GETLK /* Get record locking info. */
+#define F_SETLK64 F_SETLK /* Set record locking info (non-blocking). */
+#define F_SETLKW64 F_SETLKW /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_XOPEN2K
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
+#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
+
+/* For F_[GET|SET]FL. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+/* Splice address range into a pipe. */
+extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
+ size_t __count, unsigned int __flags);
+
+/* Splice two files together. */
+extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
+ __off64_t *__offout, size_t __len,
+ unsigned int __flags);
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern ssize_t tee (int __fdin, int __fdout, size_t __len,
+ unsigned int __flags);
+
+#endif
+__END_DECLS
diff --git a/libc/sysdeps/linux/kvx/bits/fenv.h b/libc/sysdeps/linux/kvx/bits/fenv.h
new file mode 100644
index 000000000..445ec7aff
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/fenv.h
@@ -0,0 +1,106 @@
+/* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _FENV_H
+# error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
+#endif
+
+/* $cs register number for use in kvx builtins */
+#define KVX_SFR_CS 4
+
+/* Each core of the Coolidge processor has a coprocessor. They share
+ the CS register but have distinct bit-fields for their
+ floating-point environment. This implementation synchronizes them
+ in such a way that they cannot be managed separately. */
+
+/* Compute Status ($cs) register contains the following bit-fields for
+ floating-point execption flags.
+
+ Bit-field Condition of the IEEE 754 binary floating-point standard
+ --------- --------------------------------------------------------
+ IO Invalid Operation
+ DZ Divide by Zero
+ OV Overflow
+ UN Underflow
+ IN Inexact
+ XIO Invalid Operation (coprocessor)
+ XDZ Divide by Zero (coprocessor)
+ XOV Overflow (coprocessor)
+ XUN Underflow (coprocessor)
+ XIN Inexact (coprocessor) */
+
+#define _FE_INVALID 0x02
+#define _FE_DIVBYZERO 0x04
+#define _FE_OVERFLOW 0x08
+#define _FE_UNDERFLOW 0x10
+#define _FE_INEXACT 0x20
+
+#define _FE_X_INVALID 0x0200
+#define _FE_X_DIVBYZERO 0x0400
+#define _FE_X_OVERFLOW 0x0800
+#define _FE_X_UNDERFLOW 0x1000
+#define _FE_X_INEXACT 0x2000
+
+#define FE_INVALID (_FE_INVALID | _FE_X_INVALID)
+#define FE_DIVBYZERO (_FE_DIVBYZERO | _FE_X_DIVBYZERO)
+#define FE_OVERFLOW (_FE_OVERFLOW | _FE_X_OVERFLOW)
+#define FE_UNDERFLOW (_FE_UNDERFLOW | _FE_X_UNDERFLOW)
+#define FE_INEXACT (_FE_INEXACT | _FE_X_INEXACT)
+
+#define FE_ALL_EXCEPT (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT)
+
+/* Compute Status ($cs) register contains the following bit-fields for
+ floating-point rounding modes.
+
+ Following table describes both the RM and XRM (coproc) bit-fields.
+
+ Value Rounding Mode of the IEEE 754 binary floating-point standard
+ ----- ------------------------------------------------------------
+ 0b00 to nearest even
+ 0b01 toward +inf
+ 0b10 toward -inf
+ 0b11 toward zero */
+
+#define _FE_TONEAREST 0
+#define _FE_UPWARD 1
+#define _FE_DOWNWARD 2
+#define _FE_TOWARDZERO 3
+
+#define _FE_X_TONEAREST 0
+#define _FE_X_UPWARD 1
+#define _FE_X_DOWNWARD 2
+#define _FE_X_TOWARDZERO 3
+
+
+#define FE_TONEAREST ((_FE_TONEAREST << 16) | (_FE_X_TONEAREST << 20))
+#define FE_UPWARD ((_FE_UPWARD << 16) | (_FE_X_UPWARD << 20))
+#define FE_DOWNWARD ((_FE_DOWNWARD << 16) | (_FE_X_DOWNWARD << 20))
+#define FE_TOWARDZERO ((_FE_TOWARDZERO << 16) | (_FE_X_TOWARDZERO << 20))
+
+#define FE_RND_MASK FE_TOWARDZERO
+
+/* The type representing all floating-point status flags collectively.
+ The environment is simply a copy from the FPU related bits in the
+ CS register, but can be improved in the future. */
+typedef unsigned int fexcept_t;
+/* The type representing the entire floating-point environment. The
+ environment is simply a copy from the FPU related bits in the CS
+ register. */
+typedef unsigned int fenv_t;
+
+extern const fenv_t __fe_dfl_env;
+#define FE_DFL_ENV __fe_dfl_env
diff --git a/libc/sysdeps/linux/kvx/bits/kernel_types.h b/libc/sysdeps/linux/kvx/bits/kernel_types.h
new file mode 100644
index 000000000..8f6bda8e9
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/kernel_types.h
@@ -0,0 +1,44 @@
+/* Note that we use the exact same include guard #define names
+ * as asm/posix_types.h. This will avoid gratuitous conflicts
+ * with the posix_types.h kernel header, and will ensure that
+ * our private content, and not the kernel header, will win.
+ * -Erik
+ */
+#ifndef __ASM_GENERIC_POSIX_TYPES_H
+#define __ASM_GENERIC_POSIX_TYPES_H
+
+#include <asm/bitsperlong.h>
+
+typedef unsigned long __kernel_dev_t;
+typedef unsigned long __kernel_ino_t;
+typedef unsigned int __kernel_mode_t;
+typedef unsigned int __kernel_nlink_t;
+typedef long __kernel_off_t;
+typedef int __kernel_pid_t;
+typedef int __kernel_ipc_pid_t;
+typedef unsigned int __kernel_uid_t;
+typedef unsigned int __kernel_gid_t;
+typedef unsigned long __kernel_size_t;
+typedef long __kernel_ssize_t;
+typedef long __kernel_ptrdiff_t;
+typedef long __kernel_time_t;
+typedef long __kernel_suseconds_t;
+typedef long __kernel_clock_t;
+typedef int __kernel_daddr_t;
+typedef char * __kernel_caddr_t;
+typedef unsigned short __kernel_uid16_t;
+typedef unsigned short __kernel_gid16_t;
+typedef unsigned int __kernel_uid32_t;
+typedef unsigned int __kernel_gid32_t;
+typedef unsigned short __kernel_old_uid_t;
+typedef unsigned short __kernel_old_gid_t;
+typedef long long __kernel_loff_t;
+typedef unsigned int __kernel_old_dev_t;
+typedef long __kernel_long_t;
+typedef unsigned long __kernel_ulong_t;
+
+typedef struct {
+ int val[2];
+} __kernel_fsid_t;
+
+#endif /* __ASM_GENERIC_POSIX_TYPES_H */
diff --git a/libc/sysdeps/linux/kvx/bits/posix_types.h b/libc/sysdeps/linux/kvx/bits/posix_types.h
new file mode 100644
index 000000000..e556fda5d
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/posix_types.h
@@ -0,0 +1,14 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2017 Kalray Inc.
+ */
+
+#ifndef _UAPI_ASM_KVX_POSIX_TYPES_H
+#define _UAPI_ASM_KVX_POSIX_TYPES_H
+
+#include <asm-generic/posix_types.h>
+
+#endif /* _UAPI_ASM_KVX_POSIX_TYPES_H */
diff --git a/libc/sysdeps/linux/kvx/bits/sem.h b/libc/sysdeps/linux/kvx/bits/sem.h
new file mode 100644
index 000000000..4d412a2cb
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/sem.h
@@ -0,0 +1,84 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/sem.h> directly; use <sys/sem.h> instead."
+#endif
+
+#include <sys/types.h>
+
+/* Flags for `semop'. */
+#define SEM_UNDO 0x1000 /* undo the operation on exit */
+
+/* Commands for `semctl'. */
+#define GETPID 11 /* get sempid */
+#define GETVAL 12 /* get semval */
+#define GETALL 13 /* get all semval's */
+#define GETNCNT 14 /* get semncnt */
+#define GETZCNT 15 /* get semzcnt */
+#define SETVAL 16 /* set semval */
+#define SETALL 17 /* set all semval's */
+
+
+/* Data structure describing a set of semaphores. */
+struct semid_ds
+{
+ struct ipc_perm sem_perm; /* operation permission struct */
+ __time_t sem_otime; /* last semop() time */
+ __time_t sem_ctime; /* last time changed by semctl() */
+ unsigned long int sem_nsems; /* number of semaphores in set */
+ unsigned long int __unused1;
+ unsigned long int __unused2;
+};
+
+/* The user should define a union like the following to use it for arguments
+ for `semctl'.
+
+ union semun
+ {
+ int val; <= value for SETVAL
+ struct semid_ds *buf; <= buffer for IPC_STAT & IPC_SET
+ unsigned short int *array; <= array for GETALL & SETALL
+ struct seminfo *__buf; <= buffer for IPC_INFO
+ };
+
+ Previous versions of this file used to define this union but this is
+ incorrect. One can test the macro _SEM_SEMUN_UNDEFINED to see whether
+ one must define the union or not. */
+#define _SEM_SEMUN_UNDEFINED 1
+
+#ifdef __USE_MISC
+
+/* ipcs ctl cmds */
+# define SEM_STAT 18
+# define SEM_INFO 19
+
+struct seminfo
+{
+ int semmap;
+ int semmni;
+ int semmns;
+ int semmnu;
+ int semmsl;
+ int semopm;
+ int semume;
+ int semusz;
+ int semvmx;
+ int semaem;
+};
+
+#endif /* __USE_MISC */
diff --git a/libc/sysdeps/linux/kvx/bits/setjmp.h b/libc/sysdeps/linux/kvx/bits/setjmp.h
new file mode 100644
index 000000000..59faa7620
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/setjmp.h
@@ -0,0 +1,46 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#ifndef _BITS_SETJMP_H
+#define _BITS_SETJMP_H 1
+
+#if !defined _SETJMP_H && !defined _PTHREAD_H
+# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
+#endif
+
+#define SIZE_OF_REG 8
+
+/* Size of a quad reg (can't use sizeof(uint64_t) since it will be in asm */
+#define QUAD_REG_SIZE (4 * SIZE_OF_REG)
+
+
+#define JMPBUF_RA_CS_OFFSET 0
+#define JMPBUF_LC_LE_LS_OFFSET (2 * SIZE_OF_REG)
+/* Start offset of regs[] in __jmp_buf struct */
+#define JMPBUF_REGS_OFFSET (JMPBUF_LC_LE_LS_OFFSET + (4 * SIZE_OF_REG))
+
+#ifndef _ASM
+typedef struct
+ {
+ /* Return address */
+ unsigned long ra;
+ unsigned long cs;
+
+ /* Store lc, le, ls into this buf */
+ unsigned long lc_le_ls[4];
+
+ /* Callee-saved GPR registers:
+ * r12(sp) r14 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31
+ */
+ unsigned long regs[16];
+
+ } __jmp_buf[1] __attribute__((__aligned__ (8)));
+
+#endif
+
+#endif /* bits/setjmp.h */
diff --git a/libc/sysdeps/linux/i386/bits/wchar.h b/libc/sysdeps/linux/kvx/bits/stackinfo.h
index b94fc7a3f..0a17bff30 100644
--- a/libc/sysdeps/linux/i386/bits/wchar.h
+++ b/libc/sysdeps/linux/kvx/bits/stackinfo.h
@@ -1,5 +1,4 @@
-/* wchar_t type related definitions.
- Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -16,10 +15,15 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#ifndef _BITS_WCHAR_H
-#define _BITS_WCHAR_H 1
+/* This file contains a bit of information about the stack allocation
+ of the processor. Since there is no general truth we can't say
+ anything here. */
+
+#ifndef _STACKINFO_H
+#define _STACKINFO_H 1
+
+#define _STACK_GROWS_DOWN 1
+
+#endif /* stackinfo.h */
-#define __WCHAR_MIN (-2147483647l - 1l)
-#define __WCHAR_MAX (2147483647l)
-#endif /* bits/wchar.h */
diff --git a/libc/sysdeps/linux/kvx/bits/stat.h b/libc/sysdeps/linux/kvx/bits/stat.h
new file mode 100644
index 000000000..716d86150
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/stat.h
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#ifndef _SYS_STAT_H
+# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
+#endif
+
+#include <bits/align64bit.h>
+#include <bits/wordsize.h>
+#include <endian.h>
+
+/* Versions of the `struct stat' data structure. */
+#define _STAT_VER_LINUX_OLD 1
+#define _STAT_VER_KERNEL 1
+#define _STAT_VER_SVR4 2
+#define _STAT_VER_LINUX 3
+#define _STAT_VER _STAT_VER_LINUX /* The one defined below. */
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 1
+#define _MKNOD_VER_SVR4 2
+#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
+
+/*
+ * This struct is exactly the same with the stat64 one because kvx is 64 bit
+ */
+struct stat
+ {
+ unsigned long long st_dev; /* Device. */
+ unsigned long long st_ino; /* 32bit file serial number. */
+ unsigned int st_mode; /* File mode. */
+ unsigned int st_nlink; /* Link count. */
+ unsigned int st_uid; /* User ID of the file's owner. */
+ unsigned int st_gid; /* Group ID of the file's group.*/
+ unsigned long long st_rdev; /* Device number, if device. */
+ unsigned long long _pad1;
+ __off_t st_size; /* SIze of file, in bytes. */
+ int st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ long long st_blocks; /* Number 512-byte blocks allocated */
+#if defined(__USE_MISC) || defined(__USE_XOPEN2K8)
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the <sys/stat.h> header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+# define st_atime st_atim.tv_sec /* Backward compatibility. */
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+#else
+ long int st_atime; /* Time of last access. */
+ unsigned long int st_atime_nsec;
+ long int st_mtime; /* Time of last modification. */
+ unsigned long int st_mtime_nsec;
+ long int st_ctime; /* Time of last status change. */
+ unsigned long int st_ctime_nsec;
+#endif
+ unsigned int __uclibc_unused4;
+ unsigned int __uclibc_unused5;
+ } __ARCH_64BIT_ALIGNMENT__;
+
+
+#ifdef __USE_LARGEFILE64
+struct stat64
+ {
+ unsigned long long st_dev; /* Device. */
+ unsigned long long st_ino; /* 32bit file serial number. */
+ unsigned int st_mode; /* File mode. */
+ unsigned int st_nlink; /* Link count. */
+ unsigned int st_uid; /* User ID of the file's owner. */
+ unsigned int st_gid; /* Group ID of the file's group.*/
+ unsigned long long st_rdev; /* Device number, if device. */
+ unsigned long long __pad3;
+ long long st_size; /* Size of file, in bytes. */
+ int st_blksize; /* Optimal block size for I/O. */
+ int __pad4;
+ long long st_blocks; /* Number 512-byte blocks allocated */
+# if defined(__USE_MISC) || defined(__USE_XOPEN2K8)
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the <sys/stat.h> header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+# else
+ long int st_atime; /* Time of last access. */
+ unsigned long int st_atime_nsec;
+ long int st_mtime; /* Time of last modification. */
+ unsigned long int st_mtime_nsec;
+ long int st_ctime; /* Time of last status change. */
+ unsigned long int st_ctime_nsec;
+# endif
+ unsigned int __uclibc_unused4;
+ unsigned int __uclibc_unused5;
+};
+#endif
+
+/* Tell code we have these members. */
+#define _STATBUF_ST_BLKSIZE
+#define _STATBUF_ST_RDEV
+/* Nanosecond resolution time values are supported. */
+#define _STATBUF_ST_NSEC
+
+/* Encoding of the file mode. */
+
+#define __S_IFMT 0170000 /* These bits determine file type. */
+
+/* File types. */
+#define __S_IFDIR 0040000 /* Directory. */
+#define __S_IFCHR 0020000 /* Character device. */
+#define __S_IFBLK 0060000 /* Block device. */
+#define __S_IFREG 0100000 /* Regular file. */
+#define __S_IFIFO 0010000 /* FIFO. */
+#define __S_IFLNK 0120000 /* Symbolic link. */
+#define __S_IFSOCK 0140000 /* Socket. */
+
+/* POSIX.1b objects. Note that these macros always evaluate to zero. But
+ they do it by enforcing the correct use of the macros. */
+#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
+#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
+#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
+
+/* Protection bits. */
+
+#define __S_ISUID 04000 /* Set user ID on execution. */
+#define __S_ISGID 02000 /* Set group ID on execution. */
+#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
+#define __S_IREAD 0400 /* Read by owner. */
+#define __S_IWRITE 0200 /* Write by owner. */
+#define __S_IEXEC 0100 /* Execute by owner. */
+
+#ifdef __USE_ATFILE
+# define UTIME_NOW ((1l << 30) - 1l)
+# define UTIME_OMIT ((1l << 30) - 2l)
+#endif
diff --git a/libc/sysdeps/linux/kvx/bits/statfs.h b/libc/sysdeps/linux/kvx/bits/statfs.h
new file mode 100644
index 000000000..660ae8f5f
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/statfs.h
@@ -0,0 +1,64 @@
+/* Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_STATFS_H
+# error "Never include <bits/statfs.h> directly; use <sys/statfs.h> instead."
+#endif
+
+#include <bits/types.h> /* for __fsid_t and __fsblkcnt_t*/
+
+struct statfs
+ {
+ long int f_type;
+ long int f_bsize;
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+
+ /* Linux specials */
+ __fsid_t f_fsid;
+ long int f_namelen;
+ long int f_frsize;
+ long int f_flags;
+ long int f_spare[4];
+ };
+
+#ifdef __USE_LARGEFILE64
+struct statfs64
+ {
+ long int f_type;
+ long int f_bsize;
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+ __fsfilcnt64_t f_bavail;
+
+ /* Linux specials */
+ __fsid_t f_fsid;
+ long int f_namelen;
+ long int f_frsize;
+ long int f_flags;
+ long int f_spare[4];
+ };
+#endif
+
+/* Tell code we have these members. */
+#define _STATFS_F_NAMELEN
+#define _STATFS_F_FRSIZE
diff --git a/libc/sysdeps/linux/kvx/bits/syscalls.h b/libc/sysdeps/linux/kvx/bits/syscalls.h
new file mode 100644
index 000000000..71bd5e4fe
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/syscalls.h
@@ -0,0 +1,80 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#ifndef _BITS_SYSCALLS_H
+#define _BITS_SYSCALLS_H
+#ifndef _SYSCALL_H
+# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
+#endif
+
+#ifndef __ASSEMBLER__
+
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ \
+ register long _ret __asm__("r0"); \
+ register unsigned long _scno __asm__("r6") = name; \
+ LOAD_ARGS_##nr (args) \
+ __asm__ __volatile__("scall %[r_scno]" \
+ : "=r" (_ret) \
+ : [r_scno] "r" (_scno) ASM_ARGS_##nr \
+ : ASM_CLOBBER_##nr); \
+ _ret; \
+ })
+
+/* Mark all argument registers as per ABI in the range r1-r5 as
+ clobbered when they are not used for the invocation of the scall */
+#define ASM_CLOBBER_6 "cc", "memory", \
+ "r7", "r8", "r9", "r10", "r11", /* unused argument registers */ \
+ "r15", /* struct pointer */ \
+ "r16", "r17", /* veneer registers */ \
+ "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", /* 32->63 are caller-saved */ \
+ "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", \
+ "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", \
+ "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63"
+#define ASM_CLOBBER_5 "r5", ASM_CLOBBER_6
+#define ASM_CLOBBER_4 "r4", ASM_CLOBBER_5
+#define ASM_CLOBBER_3 "r3", ASM_CLOBBER_4
+#define ASM_CLOBBER_2 "r2", ASM_CLOBBER_3
+#define ASM_CLOBBER_1 "r1", ASM_CLOBBER_2
+#define ASM_CLOBBER_0 ASM_CLOBBER_1
+
+#define LOAD_ARGS_0()
+#define ASM_ARGS_0
+
+#define LOAD_ARGS_1(a1) \
+ LOAD_ARGS_0(); \
+ _ret = (long) a1;
+#define ASM_ARGS_1 ASM_ARGS_0, "r"(_ret)
+
+#define LOAD_ARGS_2(a1, a2) \
+ LOAD_ARGS_1(a1); \
+ register long _a2 __asm__("r1") = (long) a2;
+#define ASM_ARGS_2 ASM_ARGS_1, "r"(_a2)
+
+#define LOAD_ARGS_3(a1, a2, a3) \
+ LOAD_ARGS_2(a1, a2); \
+ register long _a3 __asm__("r2") = (long) a3;
+#define ASM_ARGS_3 ASM_ARGS_2, "r"(_a3)
+
+#define LOAD_ARGS_4(a1, a2, a3, a4) \
+ LOAD_ARGS_3(a1, a2, a3); \
+ register long _a4 __asm__("r3") = (long) a4;
+#define ASM_ARGS_4 ASM_ARGS_3, "r"(_a4)
+
+#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
+ LOAD_ARGS_4(a1, a2, a3, a4); \
+ register long _a5 __asm__("r4") = (long) a5;
+#define ASM_ARGS_5 ASM_ARGS_4, "r"(_a5)
+
+#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
+ LOAD_ARGS_5(a1, a2, a3, a4, a5); \
+ register long _a6 __asm__("r5") = (long) a6;
+#define ASM_ARGS_6 ASM_ARGS_5, "r"(_a6)
+
+#endif /* __ASSEMBLER__ */
+#endif /* _BITS_SYSCALLS_H */
diff --git a/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h b/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h
new file mode 100644
index 000000000..ecccdc7bb
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/uClibc_arch_features.h
@@ -0,0 +1,44 @@
+/*
+ * Track misc arch-specific features that aren't config options
+ */
+
+#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
+#define _BITS_UCLIBC_ARCH_FEATURES_H
+
+/* instruction used when calling abort() to kill yourself */
+#define __UCLIBC_ABORT_INSTRUCTION__ "errop\n\t;;\n"
+
+/* can your target use syscall6() for mmap ? */
+#define __UCLIBC_MMAP_HAS_6_ARGS__
+
+/* does your target use statx */
+#define __UCLIBC_HAVE_STATX__
+
+/* does your target align 64bit values in register pairs ? (32bit arches only) */
+#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
+
+/* does your target have a broken create_module() ? */
+#undef __UCLIBC_BROKEN_CREATE_MODULE__
+
+/* does your target have to worry about older [gs]etrlimit() ? */
+#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
+
+/* does your target have an asm .set ? */
+#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
+
+/* define if target supports .weak */
+#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
+
+/* define if target supports .weakext */
+#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
+
+/* define if target supports CFI pseudo ops */
+#undef __UCLIBC_HAVE_ASM_CFI_DIRECTIVES__
+
+/* define if target supports IEEE signed zero floats */
+#define __UCLIBC_HAVE_SIGNED_ZERO__
+
+/* only weird assemblers generally need this */
+#undef __UCLIBC_ASM_LINE_SEP__
+
+#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
diff --git a/libc/sysdeps/linux/kvx/bits/wordsize.h b/libc/sysdeps/linux/kvx/bits/wordsize.h
new file mode 100644
index 000000000..751c41ab7
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bits/wordsize.h
@@ -0,0 +1,9 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#define __WORDSIZE 64
diff --git a/libc/sysdeps/linux/kvx/bsd-_setjmp.S b/libc/sysdeps/linux/kvx/bsd-_setjmp.S
new file mode 100644
index 000000000..a4c4f87b0
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bsd-_setjmp.S
@@ -0,0 +1,18 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <sysdep.h>
+
+ENTRY(_setjmp)
+ /* Set second argument to 0 */
+ make $r1 = 0
+ ;;
+ goto HIDDEN_JUMPTARGET(__sigsetjmp)
+ ;;
+END(_setjmp)
+libc_hidden_def (_setjmp)
diff --git a/libc/sysdeps/linux/kvx/bsd-setjmp.S b/libc/sysdeps/linux/kvx/bsd-setjmp.S
new file mode 100644
index 000000000..d79f603d5
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/bsd-setjmp.S
@@ -0,0 +1,17 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <sysdep.h>
+
+ENTRY(setjmp)
+ /* Set second argument to 1 */
+ make $r1 = 1
+ ;;
+ goto HIDDEN_JUMPTARGET(__sigsetjmp)
+ ;;
+END(setjmp)
diff --git a/libc/sysdeps/linux/kvx/cachectl.c b/libc/sysdeps/linux/kvx/cachectl.c
new file mode 100644
index 000000000..9afeb44a1
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/cachectl.c
@@ -0,0 +1,15 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2020 Kalray Inc.
+ */
+
+#include <sys/syscall.h>
+
+#ifdef __NR_cachectl
+# include <sys/cachectl.h>
+_syscall4(int, cachectl, void *, addr, size_t, len,
+ unsigned long, cache, unsigned long, flags)
+#endif
diff --git a/libc/sysdeps/linux/kvx/clone.S b/libc/sysdeps/linux/kvx/clone.S
new file mode 100644
index 000000000..71553a4a9
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/clone.S
@@ -0,0 +1,100 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/**
+ * Clone system call implementation for kvx
+ * int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ * pid_t *ptid, struct user_desc *tls, pid_t *ctid);
+ * $r0 = fn
+ * $r1 = child_stack
+ * $r2 = flags
+ * $r3 = args
+ * $r4 = ptid
+ * $r5 = tls
+ * $r6 = ctid
+ *
+ * The kernel expects to find its arguments in the following order:
+ * sys_clone(unsigned long clone_flags, unsigned long newsp,
+ * int __user * parent_tidptr,
+ * int __user * child_tidptr,
+ * unsigned long tls)
+ *
+ * So we have to make a few modifications before calling
+ *
+ */
+
+ENTRY (__clone)
+ /* Check fn and stack to be non-null */
+ cb.deqz $r1? L(clone_einval_error)
+ /* Align child stack first */
+ andd $r1 = $r1, -32
+ ;;
+ cb.deqz $r0? L(clone_einval_error)
+ /* Prepare space for child arguments on stack and stay aligned */
+ addd $r1 = $r1, -32
+ ;;
+ /* Save fn ($r0) on child stack */
+ sd 0[$r1] = $r0
+ /* Set clone_flags */
+ copyd $r0 = $r2
+ ;;
+ /* Save args ($r3) on child stack */
+ sd 8[$r1] = $r3
+ /* Set parent_tidptr */
+ copyd $r2 = $r4
+ /* Set child_tidptr */
+ copyd $r3 = $r6
+ /* Set tls */
+ copyd $r4 = $r5
+ ;;
+ scall SYS_ify(clone)
+ ;;
+ /* If 0, then we are the child */
+ cb.deqz $r0? L(child_start)
+ ;;
+ /* Else we are the parent, and we need to check for errors */
+ cb.dltz $r0? L(clone_error)
+ ;;
+ /* No error ! Yeepa ! */
+ ret
+ ;;
+L(child_start):
+ /* get fn from stack */
+ ld $r1 = 0[$sp]
+ ;;
+ /* Get args from stack */
+ ld $r0 = 8[$sp]
+ addd $sp = $sp, 32
+ ;;
+ icall $r1
+ ;;
+ scall SYS_ify(exit)
+ ;;
+ /* We should never ever get here ! */
+ errop
+ ;;
+L(clone_einval_error):
+ make $r0 = -EINVAL
+ ;;
+L(clone_error):
+ /* goto __syscall_error but do not use call or $ra will be
+ * destroyed */
+ goto __syscall_error
+ ;;
+ /* We will not return here but to clone caller
+ * (stored in $ra) */
+ errop
+ ;;
+END(__clone)
+
+libc_hidden_def (__clone)
+weak_alias (__clone,clone)
diff --git a/libc/sysdeps/linux/kvx/crt1.S b/libc/sysdeps/linux/kvx/crt1.S
new file mode 100644
index 000000000..34501103e
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/crt1.S
@@ -0,0 +1,83 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+/* Startup code compliant to the ELF KVX ABI */
+
+#include <libc-symbols.h>
+#include <features.h>
+
+.type main,@function
+.type __uClibc_main,@function
+
+/*
+ * When we enter this piece of code, the program stack has been
+ * layed out by the kernel like this:
+ * argc argument counter (integer)
+ * argv[0] program name (pointer)
+ * argv[1...N] program args (pointers)
+ * argv[argc-1] end of args (integer)
+ * NULL
+ * env[0...N] environment variables (pointers)
+ * NULL
+ *
+ * Moreover, when using dynamic loader, $r0 contains the rtld_fini
+ * address
+ *
+ * And we need to call the following function:
+ * __uClibc_main (int (*main) (int, char **, char **), int argc,
+ * char **argv, void (*init) (void), void (*fini) (void),
+ * void (*rtld_fini) (void), void *stack_end)
+ */
+.text
+.globl _start
+.type _start,@function
+.align 8
+C_SYMBOL_NAME(_start):
+ /* Load argc from stack */
+ ld $r1 = 0[$sp]
+ /* Load argv addr from stack */
+ addd $r2 = $sp, 0x8
+#ifdef __PIC__
+ pcrel $r7 = @gotaddr()
+#endif
+ ;;
+ /* $r0 contains rtld_fini when run by dynamic loader */
+ copyd $r5 = $r0
+ /* prepare __uClibc_main arg */
+#ifndef __PIC__
+ make $r3 = _init
+ make $r4 = _fini
+#endif
+ ;;
+ /* Align stack to 32-byte boundary */
+ andd $sp = $sp, -32
+ make $r8 = 0
+ make $fp = 0
+ /* prepare __uClibc_main arg */
+#ifdef __PIC__
+ ld $r3 = @got(_init)[$r7]
+#endif
+ ;;
+ /* Setup stack_end for __uClibc_main */
+ copyd $r6 = $sp
+ /* Clear compute status */
+ set $cs = $r8
+#ifdef __PIC__
+ ld $r4 = @got(_fini)[$r7]
+#endif
+ ;;
+#ifdef __PIC__
+ ld $r0 = @got(main)[$r7]
+#else
+ make $r0 = main
+#endif
+ goto __uClibc_main
+ ;;
+ /* We should never return ! */
+ errop
+ ;;
diff --git a/libc/sysdeps/linux/kvx/crti.S b/libc/sysdeps/linux/kvx/crti.S
new file mode 100644
index 000000000..cf5fb2b42
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/crti.S
@@ -0,0 +1,31 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+ .section .init
+ .align 8
+ .global _init
+ .type _init,@function
+_init:
+ addd $sp = $sp, -32
+ get $r15 = $ra
+ ;;
+ sq 0[$sp] = $r14r15
+ copyd $fp = $sp
+ ;;
+
+ .section .fini
+ .align 8
+ .global _fini
+ .type _fini,@function
+_fini:
+ addd $sp = $sp, -32
+ get $r15 = $ra
+ ;;
+ sq 0[$sp] = $r14r15
+ copyd $fp = $sp
+ ;;
diff --git a/libc/sysdeps/linux/kvx/crtn.S b/libc/sysdeps/linux/kvx/crtn.S
new file mode 100644
index 000000000..c1ba48096
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/crtn.S
@@ -0,0 +1,33 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+ .section .init
+ .align 8
+ .global _init
+ .type _init,@function
+ # EPILOGUE
+ lq $r14r15 = 0[$sp]
+ ;;
+ set $ra = $r15
+ addd $sp = $sp, 32
+ ;;
+ ret
+ ;;
+
+ .section .fini
+ .align 8
+ .global _fini
+ .type _fini,@function
+ # EPILOGUE
+ lq $r14r15 = 0[$sp]
+ ;;
+ set $ra = $r15
+ addd $sp = $sp, 32
+ ;;
+ ret
+ ;;
diff --git a/libc/sysdeps/linux/kvx/jmpbuf-offsets.h b/libc/sysdeps/linux/kvx/jmpbuf-offsets.h
new file mode 100644
index 000000000..27636fa33
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/jmpbuf-offsets.h
@@ -0,0 +1,50 @@
+/*
+ * Private macros for accessing __jmp_buf contents. kvx version.
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2019 Kalray Inc.
+ */
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+
+/* We only need to save callee-saved registers plus stackpointer */
+# define JB_R12 0 /* stack pointer */
+# define JB_R14 1 /* frame pointer */
+# define JB_R18 2
+# define JB_R19 3
+# define JB_R20 4
+# define JB_R21 5
+# define JB_R22 6
+# define JB_R23 7
+# define JB_R24 8
+# define JB_R25 9
+# define JB_R26 10
+# define JB_R27 11
+# define JB_R28 12
+# define JB_R29 13
+# define JB_R30 14
+# define JB_R31 15
+
+#ifndef __ASSEMBLER__
+#include <setjmp.h>
+#include <stdint.h>
+#include <sysdep.h>
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf jmpbuf)
+{
+ uintptr_t sp = jmpbuf[0].regs[JB_R12];
+ return sp;
+}
+#endif
+
+
+#else
+
+#error unsupported 32 bit wordsize
+
+#endif
diff --git a/libc/sysdeps/linux/kvx/jmpbuf-unwind.h b/libc/sysdeps/linux/kvx/jmpbuf-unwind.h
new file mode 100644
index 000000000..544da7012
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/jmpbuf-unwind.h
@@ -0,0 +1,30 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2019 Kalray Inc.
+ */
+
+#include <setjmp.h>
+#include <jmpbuf-offsets.h>
+
+/* Test if longjmp to JMPBUF would unwind the frame
+ containing a local variable at ADDRESS. */
+#if __WORDSIZE == 64
+# define _JMPBUF_UNWINDS(jmpbuf, address) \
+ ((void *) (address) < (void *) (jmpbuf)[JB_R12])
+#else
+#error 32-bit unsupported
+#endif
+
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+#include <stdint.h>
+#include <unwind.h>
+
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
+ _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+
+#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
+ ((uintptr_t) (_address) - (_adj) < (uintptr_t) _jmpbuf_sp(_jmpbuf) - (_adj))
+#endif
diff --git a/libc/sysdeps/linux/kvx/setjmp.S b/libc/sysdeps/linux/kvx/setjmp.S
new file mode 100644
index 000000000..1a8fce3fd
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/setjmp.S
@@ -0,0 +1,59 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <sysdep.h>
+
+#define _SETJMP_H
+#define _ASM
+#include <bits/setjmp.h>
+#include <libc-symbols.h>
+
+/**
+ * Simply save the user context to $r0 (jmpbuf)
+ *
+ * This function has the following prototype:
+ * int __sigsetjmp (r0 = jmp_buf env, r1 = int savemask)
+ * At the end, we call sigjmp_save
+ * int __sigjmp_save (sigjmp_buf env, int savemask)
+ * which will save signal mask if needed (set by setjmp/_setjmp)
+ *
+ * NOTE: since r0 and r1 are used by __sigjmp_save, we must not
+ * clobber them during this function
+ */
+ENTRY(__sigsetjmp)
+ /* Save r20r21r22r23 */
+ so (JMPBUF_REGS_OFFSET + QUAD_REG_SIZE)[$r0] = $r20r21r22r23
+ get $r40 = $ra
+ ;;
+ /* Save r24r25r26r27 */
+ so (JMPBUF_REGS_OFFSET + 2 * QUAD_REG_SIZE) [$r0] = $r24r25r26r27
+ get $r41 = $cs
+ ;;
+ copyd $r36 = $sp
+ copyd $r37 = $r14
+ copyd $r38 = $r18
+ copyd $r39 = $r19
+ ;;
+ /* Save r12(sp) r14 r18 r19 stored in $r36r37r38r39 */
+ so (JMPBUF_REGS_OFFSET)[$r0] = $r36r37r38r39
+ get $r32 = $lc
+ ;;
+ /* Save r28r29r30r31 */
+ so (JMPBUF_REGS_OFFSET + 3 * QUAD_REG_SIZE) [$r0] = $r28r29r30r31
+ get $r33 = $le
+ ;;
+ /* Save $cs and $ra */
+ sq JMPBUF_RA_CS_OFFSET[$r0] = $r40r41
+ get $r34 = $ls
+ ;;
+ /* Save $lc, $le and $ls */
+ so JMPBUF_LC_LE_LS_OFFSET[$r0] = $r32r33r34r35
+ goto __sigjmp_save
+ ;;
+END(__sigsetjmp)
+libc_hidden_def(__sigsetjmp)
diff --git a/libc/sysdeps/linux/kvx/sys/cachectl.h b/libc/sysdeps/linux/kvx/sys/cachectl.h
new file mode 100644
index 000000000..707de263e
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/sys/cachectl.h
@@ -0,0 +1,21 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2020 Kalray Inc.
+ */
+
+#ifndef _SYS_CACHECTL_H
+#define _SYS_CACHECTL_H 1
+
+#include <asm/cachectl.h>
+
+__BEGIN_DECLS
+
+extern int cachectl(void *addr, size_t len, unsigned long cache,
+ unsigned long flags);
+
+__END_DECLS
+
+#endif
diff --git a/libc/sysdeps/linux/kvx/sys/procfs.h b/libc/sysdeps/linux/kvx/sys/procfs.h
new file mode 100644
index 000000000..b72322888
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/sys/procfs.h
@@ -0,0 +1,96 @@
+/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somewhat modelled after the file of the same name on SVR4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. It doesn't have anything to do with the /proc file
+ system, even though Linux has one.
+
+ Anyway, the whole purpose of this file is for GDB and GDB only.
+ Don't read too much into it. Don't use it for anything other than
+ GDB unless you know what you are doing. */
+
+#include <features.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <sys/ucontext.h>
+
+#define ELF_NGREG NGREG
+
+typedef unsigned long elf_greg_t;
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+typedef struct {} elf_fpregset_t;
+
+__BEGIN_DECLS
+
+/* Signal info. */
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with Linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ GDB doesn't really use excluded. */
+
+struct elf_prstatus
+ {
+ short int pr_cursig; /* Current signal. */
+ __pid_t pr_pid;
+ elf_gregset_t pr_reg; /* GP registers. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args. */
+
+struct elf_prpsinfo
+ {
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* The rest of this file provides the types for emulation of the
+ Solaris <proc_service.h> interfaces that should be implemented by
+ users of libthread_db. */
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore have only one PID type. */
+typedef __pid_t lwpid_t;
+
+/* Process status and info. In the end we do provide typedefs for them. */
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/linux/kvx/sys/ucontext.h b/libc/sysdeps/linux/kvx/sys/ucontext.h
new file mode 100644
index 000000000..a97b83cad
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/sys/ucontext.h
@@ -0,0 +1,28 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <signal.h>
+#include <bits/sigcontext.h>
+
+#define NGREG 70
+
+/* Type for general register. */
+typedef unsigned long greg_t;
+
+typedef struct ucontext {
+ unsigned long uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ struct sigcontext uc_mcontext;
+ sigset_t uc_sigmask; /* mask last for extensibility */
+} ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/linux/kvx/sys/user.h b/libc/sysdeps/linux/kvx/sys/user.h
new file mode 100644
index 000000000..c871f1a03
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/sys/user.h
@@ -0,0 +1 @@
+/* This file is not needed, but in practice gdb might try to include it. */
diff --git a/libc/sysdeps/linux/kvx/sysdep.h b/libc/sysdeps/linux/kvx/sysdep.h
new file mode 100644
index 000000000..944fedead
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/sysdep.h
@@ -0,0 +1,49 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#ifndef _LINUX_KVX_SYSDEP_H
+#define _LINUX_KVX_SYSDEP_H 1
+
+#include <common/sysdep.h>
+
+#define SYS_ify(syscall_name) (__NR_##syscall_name)
+
+#ifdef __ASSEMBLER__
+
+# define _ENTRY(name) \
+ .align 8; \
+ .globl C_SYMBOL_NAME(name); \
+ .func C_SYMBOL_NAME(name); \
+ .type C_SYMBOL_NAME(name), @function; \
+C_SYMBOL_NAME(name): \
+ cfi_startproc;
+
+/* Define an entry point visible from C. */
+# ifdef PIC
+# define ENTRY(name) \
+ .pic \
+ _ENTRY(name)
+
+# else
+# define ENTRY(name) _ENTRY(name)
+# endif
+
+#endif
+
+/* Local label name for asm code. */
+# ifndef L
+# define L(name) $L##name
+# endif
+
+#undef END
+#define END(name) \
+ cfi_endproc; \
+ .endfunc; \
+ .size C_SYMBOL_NAME(name), .-C_SYMBOL_NAME(name)
+
+#endif //_LINUX_KVX_SYSDEP_H
diff --git a/libc/sysdeps/linux/kvx/vfork.S b/libc/sysdeps/linux/kvx/vfork.S
new file mode 100644
index 000000000..7c6a17133
--- /dev/null
+++ b/libc/sysdeps/linux/kvx/vfork.S
@@ -0,0 +1,47 @@
+/*
+ * This file is subject to the terms and conditions of the LGPL V2.1
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2018 Kalray Inc.
+ */
+
+#include <sys/syscall.h>
+#include <sysdep.h>
+
+/* We do not want COMPAT to be enabled in our kernel, hence vfork
+ * is not available. Use clone to do the same job with appropriate flags */
+#define _SIGNAL_H
+#include <bits/signum.h> /* For SIGCHLD */
+
+#define CLONE_VM 0x00000100
+#define CLONE_VFORK 0x00004000
+#define CLONE_FLAGS_FOR_VFORK (CLONE_VM|CLONE_VFORK|SIGCHLD)
+
+ENTRY(__vfork)
+ make $r0 = CLONE_FLAGS_FOR_VFORK
+ /* Not sure if needed to zero-out other parameters but better
+ * be safe than sorry */
+ make $r1 = 0
+ make $r2 = 0
+ ;;
+ make $r3 = 0
+ make $r4 = 0
+ ;;
+ scall SYS_ify(clone)
+ ;;
+ /* If PID < 0 then it's an error, else, simply return */
+ cb.dltz $r0 ? err
+ ;;
+ ret
+ ;;
+L(err):
+ goto __syscall_error
+ ;;
+ /* Never return */
+ errop
+ ;;
+END(__vfork)
+
+weak_alias(__vfork,vfork)
+libc_hidden_def(vfork)
diff --git a/libc/sysdeps/linux/lm32/bits/fcntl.h b/libc/sysdeps/linux/lm32/bits/fcntl.h
index d1c6e31d7..0bfea6e7a 100644
--- a/libc/sysdeps/linux/lm32/bits/fcntl.h
+++ b/libc/sysdeps/linux/lm32/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set of pipe page size array */
# define F_GETPIPE_SZ 1032 /* Get of pipe page size array */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/lm32/bits/kernel_stat.h b/libc/sysdeps/linux/lm32/bits/kernel_stat.h
index c998b56c7..0dc589a5b 100644
--- a/libc/sysdeps/linux/lm32/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/lm32/bits/kernel_stat.h
@@ -22,8 +22,8 @@ struct kernel_stat
struct timespec st_atim; /* Time of last access. */
struct timespec st_mtim; /* Time of last modification. */
struct timespec st_ctim; /* Time of last status change. */
- unsigned int __unused4;
- unsigned int __unused5;
+ unsigned int __uclibc_unused4;
+ unsigned int __uclibc_unused5;
};
struct kernel_stat64
@@ -43,8 +43,8 @@ struct kernel_stat64
struct timespec st_atim; /* Time of last access. */
struct timespec st_mtim; /* Time of last modification. */
struct timespec st_ctim; /* Time of last status change. */
- unsigned int __unused4;
- unsigned int __unused5;
+ unsigned int __uclibc_unused4;
+ unsigned int __uclibc_unused5;
};
#endif /* _BITS_STAT_STRUCT_H */
diff --git a/libc/sysdeps/linux/lm32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/lm32/bits/uClibc_arch_features.h
index 03cb0ca8f..adcc8c043 100644
--- a/libc/sysdeps/linux/lm32/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/lm32/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target have a broken create_module() ? */
#undef __UCLIBC_BROKEN_CREATE_MODULE__
diff --git a/libc/sysdeps/linux/m68k/__syscall_error.c b/libc/sysdeps/linux/m68k/__syscall_error.c
index a29f6ffd6..2d2677521 100644
--- a/libc/sysdeps/linux/m68k/__syscall_error.c
+++ b/libc/sysdeps/linux/m68k/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(void) attribute_hidden;
-int __syscall_error(void)
+long __syscall_error(void) attribute_hidden;
+long __syscall_error(void)
{
register int err_no __asm__("%d0");
__set_errno(-err_no);
diff --git a/libc/sysdeps/linux/m68k/bits/fcntl.h b/libc/sysdeps/linux/m68k/bits/fcntl.h
index 684d8b88b..5a56c8781 100644
--- a/libc/sysdeps/linux/m68k/bits/fcntl.h
+++ b/libc/sysdeps/linux/m68k/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 0200000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020040000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/m68k/bits/kernel_stat.h b/libc/sysdeps/linux/m68k/bits/kernel_stat.h
index 3911c9bbf..f3b1bd645 100644
--- a/libc/sysdeps/linux/m68k/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/m68k/bits/kernel_stat.h
@@ -21,8 +21,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
diff --git a/libc/sysdeps/linux/m68k/bits/stat.h b/libc/sysdeps/linux/m68k/bits/stat.h
index d71670db8..7b9c3d144 100644
--- a/libc/sysdeps/linux/m68k/bits/stat.h
+++ b/libc/sysdeps/linux/m68k/bits/stat.h
@@ -82,8 +82,8 @@ struct stat
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
#ifndef __USE_FILE_OFFSET64
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
#else
__ino64_t st_ino; /* File serial number. */
#endif
diff --git a/libc/sysdeps/linux/m68k/crt1.S b/libc/sysdeps/linux/m68k/crt1.S
index 815a6076f..e7292682b 100644
--- a/libc/sysdeps/linux/m68k/crt1.S
+++ b/libc/sysdeps/linux/m68k/crt1.S
@@ -78,9 +78,13 @@ _start:
sub.l %fp, %fp
#if !defined __ARCH_USE_MMU__ && defined __PIC__
+#ifdef UCLIBC_FORMAT_ELF
+ move.l #_GLOBAL_OFFSET_TABLE_, %a5
+#else
/* Set up the global pointer. The GOT is at the beginning of the
data segment, whose address is in %d5. */
move.l %d5,%a5
+#endif
.equ have_current_got, 1
#endif
@@ -92,11 +96,11 @@ _start:
arguments for `main': argc, argv. envp will be determined
later in __libc_start_main. */
move.l (%sp)+, %d0 /* Pop the argument count. */
-#ifndef __ARCH_USE_MMU__
- move.l (%sp)+, %a0
-#else
+#if defined(__ARCH_USE_MMU__) || defined(__UCLIBC_FORMAT_ELF__)
move.l %sp, %a0 /* The argument vector starts just at the
current stack top. */
+#else
+ move.l (%sp)+, %a0
#endif
/* Provide the highest stack address to the user code (for stacks
diff --git a/libc/sysdeps/linux/metag/__syscall_error.c b/libc/sysdeps/linux/metag/__syscall_error.c
index f97cd0126..3e82abe0d 100644
--- a/libc/sysdeps/linux/metag/__syscall_error.c
+++ b/libc/sysdeps/linux/metag/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/metag/bits/fcntl.h b/libc/sysdeps/linux/metag/bits/fcntl.h
index 4130a5ba1..bdd697348 100644
--- a/libc/sysdeps/linux/metag/bits/fcntl.h
+++ b/libc/sysdeps/linux/metag/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/metag/bits/ipc.h b/libc/sysdeps/linux/metag/bits/ipc.h
index d50e39f6a..50d9514e9 100644
--- a/libc/sysdeps/linux/metag/bits/ipc.h
+++ b/libc/sysdeps/linux/metag/bits/ipc.h
@@ -49,6 +49,6 @@ struct ipc_perm
unsigned int mode; /* Read/write permission. */
unsigned short __seq; /* Sequence number. */
unsigned short __pad1;
- unsigned long __unused1;
- unsigned long __unused2;
+ unsigned long __uclibc_unused1;
+ unsigned long __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/metag/bits/uClibc_arch_features.h b/libc/sysdeps/linux/metag/bits/uClibc_arch_features.h
index 1433c588c..5d78b16b0 100644
--- a/libc/sysdeps/linux/metag/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/metag/bits/uClibc_arch_features.h
@@ -16,6 +16,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/microblaze/__syscall_error.c b/libc/sysdeps/linux/microblaze/__syscall_error.c
index 2b642e816..c682aae49 100644
--- a/libc/sysdeps/linux/microblaze/__syscall_error.c
+++ b/libc/sysdeps/linux/microblaze/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/microblaze/bits/fcntl.h b/libc/sysdeps/linux/microblaze/bits/fcntl.h
index 677858227..110927d95 100644
--- a/libc/sysdeps/linux/microblaze/bits/fcntl.h
+++ b/libc/sysdeps/linux/microblaze/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/mips/__syscall_error.c b/libc/sysdeps/linux/mips/__syscall_error.c
index 5e109a83b..af26cf6ab 100644
--- a/libc/sysdeps/linux/mips/__syscall_error.c
+++ b/libc/sysdeps/linux/mips/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(err_no);
return -1;
diff --git a/libc/sysdeps/linux/mips/bits/fcntl.h b/libc/sysdeps/linux/mips/bits/fcntl.h
index ac825a01f..33251c74d 100644
--- a/libc/sysdeps/linux/mips/bits/fcntl.h
+++ b/libc/sysdeps/linux/mips/bits/fcntl.h
@@ -55,6 +55,7 @@
# define O_DIRECT 0x8000 /* Direct disk access hint. */
# define O_NOATIME 0x40000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 0x410000 /* Atomically create nameless file. */
#endif
/* For now Linux has no synchronisity options for data and read operations.
@@ -113,11 +114,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/mips/bits/ipc.h b/libc/sysdeps/linux/mips/bits/ipc.h
index 97a8da032..b47c1e706 100644
--- a/libc/sysdeps/linux/mips/bits/ipc.h
+++ b/libc/sysdeps/linux/mips/bits/ipc.h
@@ -49,6 +49,6 @@ struct ipc_perm
unsigned int mode; /* Read/write permission. */
unsigned short int __seq; /* Sequence number. */
unsigned short int __pad1;
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/mips/bits/kernel_stat.h b/libc/sysdeps/linux/mips/bits/kernel_stat.h
index a2a6169a3..23a6ce61a 100644
--- a/libc/sysdeps/linux/mips/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/mips/bits/kernel_stat.h
@@ -14,7 +14,11 @@ typedef struct {
} __ktimespec_t;
#else
typedef struct {
+#if defined(__UCLIBC_USE_TIME64__)
+ __S32_TYPE tv_sec;
+#else
time_t tv_sec;
+#endif
unsigned long tv_nsec;
} __ktimespec_t;
#endif
diff --git a/libc/sysdeps/linux/mips/bits/msq.h b/libc/sysdeps/linux/mips/bits/msq.h
index fe09cfadf..bcf1073e8 100644
--- a/libc/sysdeps/linux/mips/bits/msq.h
+++ b/libc/sysdeps/linux/mips/bits/msq.h
@@ -64,8 +64,8 @@ struct msqid_ds
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/mips/bits/resource.h b/libc/sysdeps/linux/mips/bits/resource.h
index b204aefd6..97487d274 100644
--- a/libc/sysdeps/linux/mips/bits/resource.h
+++ b/libc/sysdeps/linux/mips/bits/resource.h
@@ -99,7 +99,13 @@ enum __rlimit_resource
__RLIMIT_RTPRIO = 14,
#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
- __RLIMIT_NLIMITS = 15,
+ /* Maximum CPU time in µs that a process scheduled under a real-time
+ scheduling policy may consume without making a blocking system
+ call before being forcibly descheduled. */
+ __RLIMIT_RTTIME = 15,
+#define RLIMIT_RTTIME __RLIMIT_RTTIME
+
+ __RLIMIT_NLIMITS = 16,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
@@ -117,10 +123,10 @@ enum __rlimit_resource
# ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((long int)(~0UL >> 1))
# else
-# define RLIM_INFINITY 0x7fffffffffffffffULL
+# define RLIM_INFINITY 0xffffffffffffffffULL
# endif
# ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffULL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
# endif
#endif
@@ -167,6 +173,15 @@ enum __rusage_who
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+
+#ifdef __USE_GNU
+ ,
+ /* The calling thread. */
+ RUSAGE_THREAD = 1
+# define RUSAGE_THREAD RUSAGE_THREAD
+ /* Name for the same functionality on Solaris. */
+# define RUSAGE_LWP RUSAGE_THREAD
+#endif
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/mips/bits/sem.h b/libc/sysdeps/linux/mips/bits/sem.h
index 4d412a2cb..35eaa05c3 100644
--- a/libc/sysdeps/linux/mips/bits/sem.h
+++ b/libc/sysdeps/linux/mips/bits/sem.h
@@ -38,11 +38,22 @@
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
- __time_t sem_otime; /* last semop() time */
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_otime_internal_1; /* last semop() time */
+ unsigned long int __sem_otime_internal_2;
+ unsigned long int __sem_ctime_internal_1; /* last time changed by semctl() */
+ unsigned long int __sem_ctime_internal_2;
+#else
+ __time_t sem_otime; /* last semop() time */
__time_t sem_ctime; /* last time changed by semctl() */
+#endif
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused1;
- unsigned long int __unused2;
+#if defined(__UCLIBC_USE_TIME64__)
+ __time_t sem_otime;
+ __time_t sem_ctime;
+#endif
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/mips/bits/shm.h b/libc/sysdeps/linux/mips/bits/shm.h
index 43869b3f4..bb87ba13d 100644
--- a/libc/sysdeps/linux/mips/bits/shm.h
+++ b/libc/sysdeps/linux/mips/bits/shm.h
@@ -52,8 +52,8 @@ struct shmid_ds
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
@@ -74,10 +74,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/mips/bits/syscalls.h b/libc/sysdeps/linux/mips/bits/syscalls.h
index b8f80597e..13728ac55 100644
--- a/libc/sysdeps/linux/mips/bits/syscalls.h
+++ b/libc/sysdeps/linux/mips/bits/syscalls.h
@@ -270,8 +270,13 @@
_sys_result; \
})
-#define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
- "$14", "$15", "$24", "$25", "hi", "lo", "memory"
+#if __mips_isa_rev >= 6
+# define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
+ "$14", "$15", "$24", "$25", "memory"
+#else
+# define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
+ "$14", "$15", "$24", "$25", "hi", "lo", "memory"
+#endif
#else /* N32 || N64 */
@@ -327,8 +332,13 @@
_sys_result; \
})
-#define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
- "$14", "$15", "$24", "$25", "hi", "lo", "memory"
+#if __mips_isa_rev >= 6
+# define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
+ "$14", "$15", "$24", "$25", "memory"
+#else
+# define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
+ "$14", "$15", "$24", "$25", "hi", "lo", "memory"
+#endif
#endif
diff --git a/libc/sysdeps/linux/mips/crt1.S b/libc/sysdeps/linux/mips/crt1.S
index 083615515..7c4db447c 100644
--- a/libc/sysdeps/linux/mips/crt1.S
+++ b/libc/sysdeps/linux/mips/crt1.S
@@ -78,6 +78,10 @@
.weak _init
.weak _fini
#endif
+#ifdef L_rcrt1
+ .type reloc_static_pie,@function
+ .hidden .L0
+#endif
.type main,@function
.type __uClibc_main,@function
.ent __start
@@ -90,6 +94,25 @@ __start:
PTR_LA $28, _gp /* Setup GP correctly if we're non-PIC. */
move $31, $0
#endif
+#ifdef L_rcrt1
+ PTR_LA $4, _DYNAMIC /* Place _DYNAMIC into the GOT */
+ REG_S $4, -0x7ff0($28) /* offset to GOT stolen from dl-startup */
+ jal .L0 /* Get the current $pc address */
+.L0:
+ PTR_SUBU $4, $31, $25 /* Calculate load addr */
+ move $31, $0 /* Clear ra */
+ and $29, -2 * SZREG /* Ensure stack is aligned */
+ PTR_ADDIU $29, (-2 * SZREG) /* Allocate 2 register spaces on stack */
+ REG_S $2, SZREG($29) /* Store atexit in case it exists */
+ PTR_LA $5, reloc_static_pie /* function calls before relocation
+ don't work unless we set $t9 manually */
+ PTR_ADDU $25, $4, $5 /* store reloc_static_pie in $t9 */
+ jalr $25 /* call reloc_static_pie */
+ nop /* delay slot, just in case */
+ REG_L $2, SZREG($29) /* cleanup stack */
+ PTR_ADDIU $29, $29, (2 * SZREG)
+
+#endif
PTR_LA $4, main /* main */
PTR_L $5, 0($29) /* argc */
diff --git a/libc/sysdeps/linux/nds32/Makefile.arch b/libc/sysdeps/linux/nds32/Makefile.arch
index caf163844..c7627b847 100644
--- a/libc/sysdeps/linux/nds32/Makefile.arch
+++ b/libc/sysdeps/linux/nds32/Makefile.arch
@@ -2,6 +2,6 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
CSRC-y := brk.c prctl.c mremap.c
-SSRC-y := setjmp.S __longjmp.S bsd-setjmp.S bsd-_setjmp.S clone.S vfork.S sysdep.S
+SSRC-y := setjmp.S __longjmp.S bsd-setjmp.S bsd-_setjmp.S clone.S sysdep.S
CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c swapcontext.c
SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += getcontext.S setcontext.S
diff --git a/libc/sysdeps/linux/nds32/__syscall_error.c b/libc/sysdeps/linux/nds32/__syscall_error.c
index 2aa6903e2..c8e6044a7 100644
--- a/libc/sysdeps/linux/nds32/__syscall_error.c
+++ b/libc/sysdeps/linux/nds32/__syscall_error.c
@@ -8,8 +8,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(err_no);
return -1;
diff --git a/libc/sysdeps/linux/nds32/bits/fcntl.h b/libc/sysdeps/linux/nds32/bits/fcntl.h
index fa9f039f5..2e6a95ec8 100644
--- a/libc/sysdeps/linux/nds32/bits/fcntl.h
+++ b/libc/sysdeps/linux/nds32/bits/fcntl.h
@@ -58,6 +58,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -105,11 +106,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/nds32/bits/kernel_stat.h b/libc/sysdeps/linux/nds32/bits/kernel_stat.h
index 9e5c40d15..3c0911c01 100644
--- a/libc/sysdeps/linux/nds32/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/nds32/bits/kernel_stat.h
@@ -30,8 +30,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
diff --git a/libc/sysdeps/linux/nds32/bits/kernel_types.h b/libc/sysdeps/linux/nds32/bits/kernel_types.h
index 1b6ae4d1b..6b142d2e5 100644
--- a/libc/sysdeps/linux/nds32/bits/kernel_types.h
+++ b/libc/sysdeps/linux/nds32/bits/kernel_types.h
@@ -14,13 +14,13 @@
typedef unsigned short __kernel_dev_t;
typedef unsigned long __kernel_ino_t;
-typedef unsigned short __kernel_mode_t;
+typedef unsigned int __kernel_mode_t;
typedef unsigned short __kernel_nlink_t;
typedef long __kernel_off_t;
typedef int __kernel_pid_t;
-typedef unsigned short __kernel_ipc_pid_t;
-typedef unsigned short __kernel_uid_t;
-typedef unsigned short __kernel_gid_t;
+typedef int __kernel_ipc_pid_t;
+typedef unsigned int __kernel_uid_t;
+typedef unsigned int __kernel_gid_t;
typedef unsigned int __kernel_size_t;
typedef int __kernel_ssize_t;
typedef int __kernel_ptrdiff_t;
@@ -34,19 +34,11 @@ typedef unsigned short __kernel_gid16_t;
typedef unsigned int __kernel_uid32_t;
typedef unsigned int __kernel_gid32_t;
-typedef unsigned short __kernel_old_uid_t;
-typedef unsigned short __kernel_old_gid_t;
-typedef __kernel_dev_t __kernel_old_dev_t;
+typedef __kernel_uid_t __kernel_old_uid_t;
+typedef __kernel_gid_t __kernel_old_gid_t;
+typedef unsigned int __kernel_old_dev_t;
typedef long __kernel_long_t;
typedef unsigned long __kernel_ulong_t;
__extension__ typedef long long __kernel_loff_t;
-typedef struct {
-#ifdef __USE_ALL
- int val[2];
-#else
- int __val[2];
-#endif
-} __kernel_fsid_t;
-
#endif /* __ARCH_NDS32_POSIX_TYPES_H */
diff --git a/libc/sysdeps/linux/nds32/bits/shm.h b/libc/sysdeps/linux/nds32/bits/shm.h
index 51e1ece7f..8904b6252 100644
--- a/libc/sysdeps/linux/nds32/bits/shm.h
+++ b/libc/sysdeps/linux/nds32/bits/shm.h
@@ -55,16 +55,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -85,10 +85,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/nds32/bits/stat.h b/libc/sysdeps/linux/nds32/bits/stat.h
index fe25292cb..c4e09e0f2 100644
--- a/libc/sysdeps/linux/nds32/bits/stat.h
+++ b/libc/sysdeps/linux/nds32/bits/stat.h
@@ -86,8 +86,8 @@ struct stat
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
#ifndef __USE_FILE_OFFSET64
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
#else
__ino64_t st_ino; /* File serial number. */
#endif
diff --git a/libc/sysdeps/linux/nds32/bits/syscalls.h b/libc/sysdeps/linux/nds32/bits/syscalls.h
index a5cdda18a..50e30db7d 100644
--- a/libc/sysdeps/linux/nds32/bits/syscalls.h
+++ b/libc/sysdeps/linux/nds32/bits/syscalls.h
@@ -37,8 +37,7 @@
#define Y(x) X(x)
#define LIB_SYSCALL __NR_syscall
-#define __issue_syscall(syscall_name) \
-" syscall " Y(syscall_name) "; \n"
+#define __issue_syscall(syscall_name) "syscall 0x0;\n"
#undef INTERNAL_SYSCALL_ERROR_P
#define INTERNAL_SYSCALL_ERROR_P(val, err) ((unsigned int) (val) >= 0xfffff001u)
diff --git a/libc/sysdeps/linux/nds32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/nds32/bits/uClibc_arch_features.h
index 5c4f634a0..275308701 100644
--- a/libc/sysdeps/linux/nds32/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/nds32/bits/uClibc_arch_features.h
@@ -13,6 +13,9 @@
/* instruction used when calling abort() to kill yourself */
#define __UCLIBC_ABORT_INSTRUCTION__ "bal abort"
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#define __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/nds32/sys/ucontext.h b/libc/sysdeps/linux/nds32/sys/ucontext.h
index 0d7422aab..ea86a3ad0 100644
--- a/libc/sysdeps/linux/nds32/sys/ucontext.h
+++ b/libc/sysdeps/linux/nds32/sys/ucontext.h
@@ -36,10 +36,10 @@ typedef struct sigcontext mcontext_t;
/* Userlevel context. */
-typedef struct ucontext
+typedef struct ucontext_t
{
- unsigned long int uc_flags;
- struct ucontext *uc_link;
+ unsigned long int __uc_flags;
+ struct ucontext_t *uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
__sigset_t uc_sigmask;
diff --git a/libc/sysdeps/linux/nds32/vfork.S b/libc/sysdeps/linux/nds32/vfork.S
deleted file mode 100644
index ab32135fc..000000000
--- a/libc/sysdeps/linux/nds32/vfork.S
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2016-2017 Andes Technology, Inc.
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
-
-/* Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
- Contributed by Philip Blundell <philb@gnu.org>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <sysdep.h>
-#define _ERRNO_H 1
-#include <bits/errno.h>
-
-/* Clone the calling process, but without copying the whole address space.
- The calling process is suspended until the new process exits or is
- replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
- and the process ID of the new process to the old process. */
-
-ENTRY (__vfork)
-#ifdef PIC
-.pic
-#endif
-
-#ifdef __NR_vfork
- syscall __NR_vfork
- bltz $r0, 2f
-1:
- ret
-2:
- sltsi $r1, $r0, -4096
- bnez $r1, 1b;
-
-# ifdef __ASSUME_VFORK_SYSCALL
-# ifdef PIC
- pushm $gp, $lp
- cfi_adjust_cfa_offset(8)
- cfi_rel_offset(gp, 0)
- cfi_rel_offset(lp, 4)
- mfusr $r15, $PC
- sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4)
- ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8)
- add $gp, $gp, $r15
-
- ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
- sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
- ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
- add $r15, $r15, $gp
-
- ! jump to SYSCALL_ERROR
- jral $r15
- popm $gp, $lp
- cfi_adjust_cfa_offset(-8)
- cfi_restore(lp)
- cfi_restore(gp)
- ret
-# else
- j C_SYMBOL_NAME(__syscall_error)
-# endif
-# else
- /* Check if vfork syscall is known at all. */
- li $r1, -ENOSYS
- beq $r0, $r1, 1f
-
-# ifdef PIC
-3:
- pushm $gp, $lp
- cfi_adjust_cfa_offset(8)
- cfi_rel_offset(gp, 0)
- cfi_rel_offset(lp, 4)
- mfusr $r15, $PC
- sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4)
- ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8)
- add $gp, $gp, $r15
-
- ! r15=C_SYMBOL_NAME(__syscall_error)@PLT
- sethi $r15, hi20(C_SYMBOL_NAME(__syscall_error)@PLT)
- ori $r15, $r15, lo12(C_SYMBOL_NAME(__syscall_error)@PLT)
- add $r15, $r15, $gp
-
- ! jump to SYSCALL_ERROR
- jral $r15
- popm $gp, $lp
- cfi_adjust_cfa_offset(-8)
- cfi_restore(lp)
- cfi_restore(gp)
- ret
-# else
- j C_SYMBOL_NAME(__syscall_error)
-# endif
-1:
-# endif
-#endif
-
-#ifndef __ASSUME_VFORK_SYSCALL
- /* If we don't have vfork, fork is close enough. */
- syscall __NR_fork
- bgez $r0, 1f
- sltsi $r1, $r0, -4096
- bnez $r1, 1f
-
-# ifdef PIC
- b 3b
-# else
- j C_SYMBOL_NAME(__syscall_error)
-# endif
-1:
- ret
-
-#elif !defined __NR_vfork
-# error "__NR_vfork not available and __ASSUME_VFORK_SYSCALL defined"
-#endif
-
-PSEUDO_END (__vfork)
-weak_alias (__vfork, vfork)
-libc_hidden_def (vfork)
diff --git a/libc/sysdeps/linux/nios2/__syscall_error.c b/libc/sysdeps/linux/nios2/__syscall_error.c
index 2b642e816..c682aae49 100644
--- a/libc/sysdeps/linux/nios2/__syscall_error.c
+++ b/libc/sysdeps/linux/nios2/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/nios2/bits/fcntl.h b/libc/sysdeps/linux/nios2/bits/fcntl.h
index 1ad086b8c..200a35443 100644
--- a/libc/sysdeps/linux/nios2/bits/fcntl.h
+++ b/libc/sysdeps/linux/nios2/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -100,11 +101,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/nios2/bits/uClibc_arch_features.h b/libc/sysdeps/linux/nios2/bits/uClibc_arch_features.h
index 293cc9b00..97d725048 100644
--- a/libc/sysdeps/linux/nios2/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/nios2/bits/uClibc_arch_features.h
@@ -12,6 +12,9 @@
/* can your target use syscall6() for mmap ? */
#undef __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/or1k/__syscall_error.c b/libc/sysdeps/linux/or1k/__syscall_error.c
index 1b7e8a394..7d1e09d91 100644
--- a/libc/sysdeps/linux/or1k/__syscall_error.c
+++ b/libc/sysdeps/linux/or1k/__syscall_error.c
@@ -17,11 +17,11 @@
#include <errno.h>
-int __syscall_error (int err_no);
+long __syscall_error (int err_no);
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error (int err_no)
+long __syscall_error (int err_no)
{
__set_errno (err_no);
return -1;
diff --git a/libc/sysdeps/linux/or1k/bits/fcntl.h b/libc/sysdeps/linux/or1k/bits/fcntl.h
index a82ede424..c9599ef3a 100644
--- a/libc/sysdeps/linux/or1k/bits/fcntl.h
+++ b/libc/sysdeps/linux/or1k/bits/fcntl.h
@@ -53,6 +53,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -102,11 +103,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/or1k/bits/kernel_stat.h b/libc/sysdeps/linux/or1k/bits/kernel_stat.h
new file mode 100644
index 000000000..2e5eab901
--- /dev/null
+++ b/libc/sysdeps/linux/or1k/bits/kernel_stat.h
@@ -0,0 +1,27 @@
+#ifndef _BITS_STAT_STRUCT_H
+#define _BITS_STAT_STRUCT_H
+
+struct kernel_stat {
+ unsigned long st_dev; /* Device. */
+ unsigned long st_ino; /* File serial number. */
+ unsigned int st_mode; /* File mode. */
+ unsigned int st_nlink; /* Link count. */
+ unsigned int st_uid; /* User ID of the file's owner. */
+ unsigned int st_gid; /* Group ID of the file's group. */
+ unsigned long st_rdev; /* Device number, if device. */
+ unsigned long __pad1;
+ long st_size; /* Size of file, in bytes. */
+ int st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ long st_blocks; /* Number 512-byte blocks allocated. */
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned int __unused4;
+ unsigned int __unused5;
+};
+
+#define kernel_stat64 kernel_stat
+
+#endif /* _BITS_STAT_STRUCT_H */
+
diff --git a/libc/sysdeps/linux/or1k/or1k_clone.S b/libc/sysdeps/linux/or1k/or1k_clone.S
index a2c16ac9e..2de873a02 100644
--- a/libc/sysdeps/linux/or1k/or1k_clone.S
+++ b/libc/sysdeps/linux/or1k/or1k_clone.S
@@ -71,7 +71,11 @@ L(oldpid):
l.ori r3, r11, 0
L(error):
- l.j SYSCALL_ERROR_NAME
+#ifdef __PIC__
+ l.j plt(__syscall_error)
+#else
+ l.j __syscall_error
+#endif
l.ori r3,r11,0
-PSEUDO_END (__or1k_clone)
+END (__or1k_clone)
diff --git a/libc/sysdeps/linux/or1k/sysdep.h b/libc/sysdeps/linux/or1k/sysdep.h
index 4dba3f2a0..782981c55 100644
--- a/libc/sysdeps/linux/or1k/sysdep.h
+++ b/libc/sysdeps/linux/or1k/sysdep.h
@@ -43,38 +43,6 @@ License along with the GNU C Library; if not, see
l.sys 1; \
l.nop
-#define PSEUDO(name, syscall_name, args) \
- ENTRY (name); \
- DO_CALL(syscall_name); \
- /* if -4096 < ret < 0 holds, it's an error */ \
- l.sfgeui r11, 0xf001; \
- l.bf L(pseudo_end); \
- l.nop
-
-#define PSEUDO_NOERRNO(name, syscall_name, args) \
- ENTRY (name); \
- DO_CALL(syscall_name)
-
-#define PSEUDO_END(name) \
-L(pseudo_end): \
- l.j SYSCALL_ERROR_NAME; \
- l.ori r3,r11,0; \
- END (name)
-
-#define PSEUDO_END_NOERRNO(name) \
- END (name)
-
-#ifndef PIC
-/* For static code, on error jump to __syscall_error directly. */
-# define SYSCALL_ERROR_NAME __syscall_error
-#elif NOT_IN_libc
-/* Use the internal name for libc/libpthread shared objects. */
-# define SYSCALL_ERROR_NAME __GI___syscall_error
-#else
-/* Otherwise, on error do a full PLT jump. */
-# define SYSCALL_ERROR_NAME plt(__syscall_error)
-#endif
-
/* Make use of .size directive. */
#define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
diff --git a/libc/sysdeps/linux/powerpc/__syscall_error.c b/libc/sysdeps/linux/powerpc/__syscall_error.c
index 5e109a83b..af26cf6ab 100644
--- a/libc/sysdeps/linux/powerpc/__syscall_error.c
+++ b/libc/sysdeps/linux/powerpc/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(err_no);
return -1;
diff --git a/libc/sysdeps/linux/powerpc/bits/fcntl.h b/libc/sysdeps/linux/powerpc/bits/fcntl.h
index 30f1e4e21..ef1beeca0 100644
--- a/libc/sysdeps/linux/powerpc/bits/fcntl.h
+++ b/libc/sysdeps/linux/powerpc/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 0400000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020040000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/powerpc/bits/ioctl-types.h b/libc/sysdeps/linux/powerpc/bits/ioctl-types.h
index 87b8265af..926061fa8 100644
--- a/libc/sysdeps/linux/powerpc/bits/ioctl-types.h
+++ b/libc/sysdeps/linux/powerpc/bits/ioctl-types.h
@@ -1,5 +1,77 @@
+/* Structure types for pre-termios terminal ioctls. Linux/powerpc version.
+ Copyright (C) 2014-2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
#ifndef _SYS_IOCTL_H
# error "Never use <bits/ioctl-types.h> directly; include <sys/ioctl.h> instead."
#endif
-#include <termios.h>
+/* Get definition of constants for use with `ioctl'. */
+#include <asm/ioctls.h>
+
+
+struct winsize
+ {
+ unsigned short int ws_row;
+ unsigned short int ws_col;
+ unsigned short int ws_xpixel;
+ unsigned short int ws_ypixel;
+ };
+
+#define NCC 10
+struct termio
+ {
+ unsigned short int c_iflag; /* input mode flags */
+ unsigned short int c_oflag; /* output mode flags */
+ unsigned short int c_cflag; /* control mode flags */
+ unsigned short int c_lflag; /* local mode flags */
+ unsigned char c_line; /* line discipline */
+ unsigned char c_cc[NCC]; /* control characters */
+};
+
+/* modem lines */
+#define TIOCM_LE 0x001
+#define TIOCM_DTR 0x002
+#define TIOCM_RTS 0x004
+#define TIOCM_ST 0x008
+#define TIOCM_SR 0x010
+#define TIOCM_CTS 0x020
+#define TIOCM_CAR 0x040
+#define TIOCM_RNG 0x080
+#define TIOCM_DSR 0x100
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RI TIOCM_RNG
+
+/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+
+/* line disciplines */
+#define N_TTY 0
+#define N_SLIP 1
+#define N_MOUSE 2
+#define N_PPP 3
+#define N_STRIP 4
+#define N_AX25 5
+#define N_X25 6 /* X.25 async */
+#define N_6PACK 7
+#define N_MASC 8 /* Mobitex module */
+#define N_R3964 9 /* Simatic R3964 module */
+#define N_PROFIBUS_FDL 10 /* Profibus */
+#define N_IRDA 11 /* Linux IR */
+#define N_SMSBLOCK 12 /* SMS block mode */
+#define N_HDLC 13 /* synchronous HDLC */
+#define N_SYNC_PPP 14 /* synchronous PPP */
+#define N_HCI 15 /* Bluetooth HCI UART */
diff --git a/libc/sysdeps/linux/powerpc/bits/ipc.h b/libc/sysdeps/linux/powerpc/bits/ipc.h
index e21debf5d..f40ffbc24 100644
--- a/libc/sysdeps/linux/powerpc/bits/ipc.h
+++ b/libc/sysdeps/linux/powerpc/bits/ipc.h
@@ -50,12 +50,12 @@ struct ipc_perm
#if 0
unsigned long __seq; /* Sequence number. */
unsigned int __pad2;
- unsigned long long int __unused1;
- unsigned long long int __unused2;
+ unsigned long long int __uclibc_unused1;
+ unsigned long long int __uclibc_unused2;
#else
__uint32_t __seq; /* Sequence number. */
__uint32_t __pad1;
- __uint64_t __unused1;
- __uint64_t __unused2;
+ __uint64_t __uclibc_unused1;
+ __uint64_t __uclibc_unused2;
#endif
};
diff --git a/libc/sysdeps/linux/powerpc/bits/kernel_stat.h b/libc/sysdeps/linux/powerpc/bits/kernel_stat.h
index 579b5b4e2..023eefeea 100644
--- a/libc/sysdeps/linux/powerpc/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/powerpc/bits/kernel_stat.h
@@ -39,11 +39,11 @@ struct kernel_stat64 {
long long st_size; /* Size of file, in bytes. */
long st_blksize; /* Optimal block size for I/O. */
long long st_blocks; /* Number 512-byte blocks allocated. */
- struct timespec st_atim; /* Time of last access. */
- struct timespec st_mtim; /* Time of last modification. */
- struct timespec st_ctim; /* Time of last status change. */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#endif /* _BITS_STAT_STRUCT_H */
diff --git a/libc/sysdeps/linux/powerpc/bits/msq.h b/libc/sysdeps/linux/powerpc/bits/msq.h
index 70d4f06e3..995f5157b 100644
--- a/libc/sysdeps/linux/powerpc/bits/msq.h
+++ b/libc/sysdeps/linux/powerpc/bits/msq.h
@@ -38,15 +38,15 @@ struct msqid_ds
{
struct ipc_perm msg_perm; /* structure describing operation permission */
#if __WORDSIZE == 32
- unsigned int __unused1;
+ unsigned int __uclibc_unused1;
#endif
__time_t msg_stime; /* time of last msgsnd command */
#if __WORDSIZE == 32
- unsigned int __unused2;
+ unsigned int __uclibc_unused2;
#endif
__time_t msg_rtime; /* time of last msgrcv command */
#if __WORDSIZE == 32
- unsigned int __unused3;
+ unsigned int __uclibc_unused3;
#endif
__time_t msg_ctime; /* time of last change */
unsigned long __msg_cbytes; /* current number of bytes on queue */
@@ -54,8 +54,8 @@ struct msqid_ds
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/powerpc/bits/sem.h b/libc/sysdeps/linux/powerpc/bits/sem.h
index 271a607ca..8d338eac0 100644
--- a/libc/sysdeps/linux/powerpc/bits/sem.h
+++ b/libc/sysdeps/linux/powerpc/bits/sem.h
@@ -35,23 +35,39 @@
#define SETALL 17 /* set all semval's */
+
/* Data structure describing a set of semaphores. */
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
#if __WORDSIZE == 32
- unsigned int __unused1;
+ unsigned int __uclibc_unused1;
#endif
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_otime_internal_1; /* last semop() time */
+ unsigned long int __sem_otime_internal_2;
+#else
__time_t sem_otime; /* last semop() time */
+#endif
#if __WORDSIZE == 32
- unsigned int __unused2;
+ unsigned int __uclibc_unused2;
#endif
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_ctime_internal_1; /* last time changed by semctl() */
+ unsigned long int __sem_ctime_internal_2;
+#else
__time_t sem_ctime; /* last time changed by semctl() */
+#endif
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long __unused3;
- unsigned long __unused4;
+#if defined(__UCLIBC_USE_TIME64__)
+ __time_t sem_otime;
+ __time_t sem_ctime;
+#endif
+ unsigned long __uclibc_unused3;
+ unsigned long __uclibc_unused4;
};
+
/* The user should define a union like the following to use it for arguments
for `semctl'.
diff --git a/libc/sysdeps/linux/powerpc/bits/shm.h b/libc/sysdeps/linux/powerpc/bits/shm.h
index 63e7f6ed1..7ba17f8ad 100644
--- a/libc/sysdeps/linux/powerpc/bits/shm.h
+++ b/libc/sysdeps/linux/powerpc/bits/shm.h
@@ -50,26 +50,26 @@ struct shmid_ds
{
struct ipc_perm shm_perm; /* operation permission struct */
#if __WORDSIZE == 32
- unsigned int __unused1;
+ unsigned int __uclibc_unused1;
#endif
__time_t shm_atime; /* time of last shmat() */
#if __WORDSIZE == 32
- unsigned int __unused2;
+ unsigned int __uclibc_unused2;
#endif
__time_t shm_dtime; /* time of last shmdt() */
#if __WORDSIZE == 32
- unsigned int __unused3;
+ unsigned int __uclibc_unused3;
#endif
__time_t shm_ctime; /* time of last change by shmctl() */
#if __WORDSIZE == 32
- unsigned int __unused4;
+ unsigned int __uclibc_unused4;
#endif
size_t shm_segsz; /* size of segment in bytes */
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long __unused5;
- unsigned long __unused6;
+ unsigned long __uclibc_unused5;
+ unsigned long __uclibc_unused6;
};
#ifdef __USE_MISC
@@ -91,10 +91,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/powerpc/bits/stat.h b/libc/sysdeps/linux/powerpc/bits/stat.h
index a90043f8a..7494586b5 100644
--- a/libc/sysdeps/linux/powerpc/bits/stat.h
+++ b/libc/sysdeps/linux/powerpc/bits/stat.h
@@ -80,8 +80,8 @@ struct stat
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
@@ -120,8 +120,8 @@ struct stat64
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
# endif /* __USE_LARGEFILE64 */
diff --git a/libc/sysdeps/linux/powerpc/bits/termios.h b/libc/sysdeps/linux/powerpc/bits/termios.h
index ffd99a5e2..83380685f 100644
--- a/libc/sysdeps/linux/powerpc/bits/termios.h
+++ b/libc/sysdeps/linux/powerpc/bits/termios.h
@@ -256,23 +256,6 @@ struct ltchars {
#define TIOCPKT_NOSTOP 16
#define TIOCPKT_DOSTOP 32
-struct winsize {
- unsigned short ws_row;
- unsigned short ws_col;
- unsigned short ws_xpixel;
- unsigned short ws_ypixel;
-};
-
-#define NCC 10
-struct termio {
- unsigned short c_iflag; /* input mode flags */
- unsigned short c_oflag; /* output mode flags */
- unsigned short c_cflag; /* control mode flags */
- unsigned short c_lflag; /* local mode flags */
- unsigned char c_line; /* line discipline */
- unsigned char c_cc[NCC]; /* control characters */
-};
-
/* c_cc characters */
#define _VINTR 0
#define _VQUIT 1
@@ -285,36 +268,5 @@ struct termio {
#define _VEOL2 8
#define _VSWTC 9
-/* modem lines */
-#define TIOCM_LE 0x001
-#define TIOCM_DTR 0x002
-#define TIOCM_RTS 0x004
-#define TIOCM_ST 0x008
-#define TIOCM_SR 0x010
-#define TIOCM_CTS 0x020
-#define TIOCM_CAR 0x040
-#define TIOCM_RNG 0x080
-#define TIOCM_DSR 0x100
-#define TIOCM_CD TIOCM_CAR
-#define TIOCM_RI TIOCM_RNG
-
/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
#define TIOCSER_TEMT 0x01 /* Transmitter physically empty */
-
-/* line disciplines */
-#define N_TTY 0
-#define N_SLIP 1
-#define N_MOUSE 2
-#define N_PPP 3
-#define N_STRIP 4
-#define N_AX25 5
-#define N_X25 6 /* X.25 async */
-#define N_6PACK 7
-#define N_MASC 8 /* Mobitex module */
-#define N_R3964 9 /* Simatic R3964 module */
-#define N_PROFIBUS_FDL 10 /* Profibus */
-#define N_IRDA 11 /* Linux IR */
-#define N_SMSBLOCK 12 /* SMS block mode */
-#define N_HDLC 13 /* synchronous HDLC */
-#define N_SYNC_PPP 14 /* synchronous PPP */
-#define N_HCI 15 /* Bluetooth HCI UART */
diff --git a/libc/sysdeps/linux/powerpc/crt1.S b/libc/sysdeps/linux/powerpc/crt1.S
index 27bfc5a5a..3ac32636c 100644
--- a/libc/sysdeps/linux/powerpc/crt1.S
+++ b/libc/sysdeps/linux/powerpc/crt1.S
@@ -41,6 +41,9 @@
.weak _init
.weak _fini
#endif
+#ifdef L_rcrt1
+ .type reloc_static_pie,%function
+#endif
.type main,%function
.type __uClibc_main,%function
@@ -57,6 +60,26 @@ _start:
bl _GLOBAL_OFFSET_TABLE_-4@local
mflr r31
# endif
+ /* in PIC/PIE, plt stubs need r30 to point to the GOT if using secure-plt */
+# ifdef PPC_HAS_SECUREPLT
+ mr 30,31
+# endif
+#ifdef L_rcrt1
+ stwu r3, -4(r1) /* Save r3 */
+ stwu r9, -16(r1) /* Save r9 */
+ bcl 20,31,2f /* Jump to label 2 */
+2: mflr r3 /* Load lr into r3 */
+ addis r3, r3, _DYNAMIC-2b@ha /* Add high half of _DYNAMIC to r3 */
+ addi r3,r3,_DYNAMIC-2b@l /* Add low half of _DYNAMIC */
+ lwz r4, 0(r31) /* load _DYNAMIC from the GOT */
+ subf r3, r4, r3 /* sub _DYNAMIC@got and it's actual address */
+ bl reloc_static_pie /* Call reloc_static_pie */
+ lwzu r9, 0(r1) /* restore r9 */
+ addi r1, r1, 16 /* update stack pointer */
+ lwzu r3, 0(r1) /* restore r3 */
+ addi r1, r1, 4 /* update stack pointer */
+ li r5, 0 /* zero r5 */
+#endif
#endif
/* Set up the small data pointer in r13. */
#ifdef __PIC__
diff --git a/libc/sysdeps/linux/powerpc/sys/procfs.h b/libc/sysdeps/linux/powerpc/sys/procfs.h
index 7ae12e3cc..9e6ec191c 100644
--- a/libc/sysdeps/linux/powerpc/sys/procfs.h
+++ b/libc/sysdeps/linux/powerpc/sys/procfs.h
@@ -34,7 +34,7 @@ __BEGIN_DECLS
/* These definitions are normally provided by ucontext.h via
asm/sigcontext.h, asm/ptrace.h, and asm/elf.h. Otherwise we define
them here. */
-#ifndef __PPC64_ELF_H
+#if !defined __PPC64_ELF_H && !defined _ASM_POWERPC_ELF_H
#define ELF_NGREG 48 /* includes nip, msr, lr, etc. */
#define ELF_NFPREG 33 /* includes fpscr */
#if __WORDSIZE == 32
diff --git a/libc/sysdeps/linux/riscv32/Makefile b/libc/sysdeps/linux/riscv32/Makefile
new file mode 100644
index 000000000..43dc60a42
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/Makefile
@@ -0,0 +1,6 @@
+top_srcdir=../../../../
+top_builddir=../../../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.arch
+include $(top_srcdir)Makerules
diff --git a/libc/sysdeps/linux/riscv32/Makefile.arch b/libc/sysdeps/linux/riscv32/Makefile.arch
new file mode 100644
index 000000000..21ecaa65b
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/Makefile.arch
@@ -0,0 +1,2 @@
+CSRC-y := __syscall_error.c cache.c
+SSRC-y := __longjmp.S setjmp.S vfork.S clone.S
diff --git a/libc/sysdeps/linux/riscv32/__longjmp.S b/libc/sysdeps/linux/riscv32/__longjmp.S
new file mode 100644
index 000000000..6079f98c1
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/__longjmp.S
@@ -0,0 +1,57 @@
+/* longjmp, RISC-V version.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+ENTRY (__longjmp)
+ REG_L ra, 0*SZREG(a0)
+ REG_L s0, 1*SZREG(a0)
+ REG_L s1, 2*SZREG(a0)
+ REG_L s2, 3*SZREG(a0)
+ REG_L s3, 4*SZREG(a0)
+ REG_L s4, 5*SZREG(a0)
+ REG_L s5, 6*SZREG(a0)
+ REG_L s6, 7*SZREG(a0)
+ REG_L s7, 8*SZREG(a0)
+ REG_L s8, 9*SZREG(a0)
+ REG_L s9, 10*SZREG(a0)
+ REG_L s10,11*SZREG(a0)
+ REG_L s11,12*SZREG(a0)
+ REG_L sp, 13*SZREG(a0)
+
+#ifndef __riscv_float_abi_soft
+ FREG_L fs0, 14*SZREG+ 0*SZFREG(a0)
+ FREG_L fs1, 14*SZREG+ 1*SZFREG(a0)
+ FREG_L fs2, 14*SZREG+ 2*SZFREG(a0)
+ FREG_L fs3, 14*SZREG+ 3*SZFREG(a0)
+ FREG_L fs4, 14*SZREG+ 4*SZFREG(a0)
+ FREG_L fs5, 14*SZREG+ 5*SZFREG(a0)
+ FREG_L fs6, 14*SZREG+ 6*SZFREG(a0)
+ FREG_L fs7, 14*SZREG+ 7*SZFREG(a0)
+ FREG_L fs8, 14*SZREG+ 8*SZFREG(a0)
+ FREG_L fs9, 14*SZREG+ 9*SZFREG(a0)
+ FREG_L fs10,14*SZREG+10*SZFREG(a0)
+ FREG_L fs11,14*SZREG+11*SZFREG(a0)
+#endif
+
+ seqz a0, a1
+ add a0, a0, a1 # a0 = (a1 == 0) ? 1 : a1
+ ret
+
+END (__longjmp)
+libc_hidden_def(__longjmp)
diff --git a/libc/sysdeps/linux/riscv32/__syscall_error.c b/libc/sysdeps/linux/riscv32/__syscall_error.c
new file mode 100644
index 000000000..c682aae49
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/__syscall_error.c
@@ -0,0 +1,18 @@
+/* Wrapper for setting errno.
+ *
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <errno.h>
+#include <features.h>
+
+/* This routine is jumped to by all the syscall handlers, to stash
+ * an error number into errno. */
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
+{
+ __set_errno(-err_no);
+ return -1;
+}
diff --git a/libc/sysdeps/linux/riscv32/bits/atomic.h b/libc/sysdeps/linux/riscv32/bits/atomic.h
new file mode 100644
index 000000000..555a73dec
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/atomic.h
@@ -0,0 +1,170 @@
+/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _RISCV32_ATOMIC_MACHINE_H
+#define _RISCV32_ATOMIC_MACHINE_H 1
+
+#define typeof __typeof__
+
+#include <stdint.h>
+#include <sysdep.h>
+
+typedef int8_t atomic8_t;
+typedef int16_t atomic16_t;
+typedef int32_t atomic32_t;
+typedef int64_t atomic64_t;
+
+typedef uint8_t uatomic8_t;
+typedef uint16_t uatomic16_t;
+typedef uint32_t uatomic32_t;
+typedef uint64_t uatomic64_t;
+
+typedef intptr_t atomicptr_t;
+typedef uintptr_t uatomicptr_t;
+typedef intmax_t atomic_max_t;
+typedef uintmax_t uatomic_max_t;
+
+#define __HAVE_64B_ATOMICS 1
+#define USE_ATOMIC_COMPILER_BUILTINS 1
+
+/* Compare and exchange.
+ For all "bool" routines, we return FALSE if exchange succesful. */
+
+# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+
+/* Compare and exchange with "acquire" semantics, ie barrier after. */
+
+# define atomic_compare_and_exchange_bool_acq(mem, new, old) \
+ __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
+ mem, new, old, __ATOMIC_ACQUIRE)
+
+# define atomic_compare_and_exchange_val_acq(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old, __ATOMIC_ACQUIRE)
+
+/* Compare and exchange with "release" semantics, ie barrier before. */
+
+# define atomic_compare_and_exchange_val_rel(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old, __ATOMIC_RELEASE)
+
+
+/* Atomic exchange (without compare). */
+
+# define __arch_exchange_8_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_16_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_32_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_64_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define atomic_exchange_acq(mem, value) \
+ __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
+
+# define atomic_exchange_rel(mem, value) \
+ __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
+
+
+/* Atomically add value and return the previous (unincremented) value. */
+
+# define __arch_exchange_and_add_8_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_16_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_32_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_64_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define atomic_exchange_and_add_acq(mem, value) \
+ __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+ __ATOMIC_ACQUIRE)
+
+# define atomic_exchange_and_add_rel(mem, value) \
+ __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+ __ATOMIC_RELEASE)
+
+/* Barrier macro. */
+#define atomic_full_barrier() __sync_synchronize()
+
+#endif
diff --git a/libc/sysdeps/linux/riscv32/bits/endian.h b/libc/sysdeps/linux/riscv32/bits/endian.h
new file mode 100644
index 000000000..4aaf559d4
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/endian.h
@@ -0,0 +1,5 @@
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+#define __BYTE_ORDER __LITTLE_ENDIAN
diff --git a/libc/sysdeps/linux/riscv32/bits/fcntl.h b/libc/sysdeps/linux/riscv32/bits/fcntl.h
new file mode 100644
index 000000000..a9d7c84e0
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/fcntl.h
@@ -0,0 +1,231 @@
+/* O_*, F_*, FD_* bit values for Linux.
+ *
+ * Licensed under the LGPL v2.1 or later, see the file
+ * COPYING.LIB in this tarball.
+ */
+
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 00000003
+#define O_RDONLY 00000000
+#define O_WRONLY 00000001
+#define O_RDWR 00000002
+#define O_CREAT 00000100 /* not fcntl */
+#define O_EXCL 00000200 /* not fcntl */
+#define O_NOCTTY 00000400 /* not fcntl */
+#define O_TRUNC 00001000 /* not fcntl */
+#define O_APPEND 00002000
+#define O_NONBLOCK 00004000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 00010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 00020000
+
+#ifdef __USE_XOPEN2K8
+# define O_DIRECTORY 00200000 /* Must be a directory. */
+# define O_NOFOLLOW 00400000 /* Do not follow links. */
+# define O_CLOEXEC 02000000 /* Set close_on_exec. */
+#endif
+
+#ifdef __USE_GNU
+# define O_DIRECT 00040000 /* Direct disk access. */
+# define O_NOATIME 01000000 /* Do not set atime. */
+# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define O_LARGEFILE 00100000
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+
+#ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+#else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+#endif
+#define F_GETLK64 12 /* Get record locking info. */
+#define F_SETLK64 13 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 14 /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_XOPEN2K
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
+#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
+
+/* For F_[GET|SET]FL. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#endif
+
+struct flock
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+#ifndef __USE_FILE_OFFSET64
+ __off_t l_start; /* Offset where the lock begins. */
+ __off_t l_len; /* Size of the locked area; zero means until EOF. */
+#else
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+#endif
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+ {
+ short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */
+ short int l_whence; /* Where `l_start' is relative to (like `lseek'). */
+ __off64_t l_start; /* Offset where the lock begins. */
+ __off64_t l_len; /* Size of the locked area; zero means until EOF. */
+ __pid_t l_pid; /* Process holding the lock. */
+ };
+#endif
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
+/* Flags for SYNC_FILE_RANGE. */
+# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
+ in the range before performing the
+ write. */
+# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
+ dirty pages in the range which are
+ not presently under writeback. */
+# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
+ the range after performing the
+ write. */
+
+/* Flags for SPLICE and VMSPLICE. */
+# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
+# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
+ (but we may still block on the fd
+ we splice from/to). */
+# define SPLICE_F_MORE 4 /* Expect more data. */
+# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
+#endif
+
+__BEGIN_DECLS
+
+#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+/* Splice address range into a pipe. */
+extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
+ size_t __count, unsigned int __flags);
+
+/* Splice two files together. */
+extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
+ __off64_t *__offout, size_t __len,
+ unsigned int __flags);
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern ssize_t tee (int __fdin, int __fdout, size_t __len,
+ unsigned int __flags);
+
+#endif
+__END_DECLS
diff --git a/libc/sysdeps/linux/riscv32/bits/fenv.h b/libc/sysdeps/linux/riscv32/bits/fenv.h
new file mode 100644
index 000000000..a3f8031af
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/fenv.h
@@ -0,0 +1,73 @@
+/* Floating point environment, RISC-V version.
+ Copyright (C) 1998-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _FENV_H
+# error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
+#endif
+
+enum
+ {
+ FE_INEXACT =
+#define FE_INEXACT (0x01)
+ FE_INEXACT,
+ FE_UNDERFLOW =
+#define FE_UNDERFLOW (0x02)
+ FE_UNDERFLOW,
+ FE_OVERFLOW =
+#define FE_OVERFLOW (0x04)
+ FE_OVERFLOW,
+ FE_DIVBYZERO =
+#define FE_DIVBYZERO (0x08)
+ FE_DIVBYZERO,
+ FE_INVALID =
+#define FE_INVALID (0x10)
+ FE_INVALID
+ };
+
+#define FE_ALL_EXCEPT \
+ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
+
+enum
+ {
+ FE_TONEAREST =
+#define FE_TONEAREST (0x0)
+ FE_TONEAREST,
+ FE_TOWARDZERO =
+#define FE_TOWARDZERO (0x1)
+ FE_TOWARDZERO,
+ FE_DOWNWARD =
+#define FE_DOWNWARD (0x2)
+ FE_DOWNWARD,
+ FE_UPWARD =
+#define FE_UPWARD (0x3)
+ FE_UPWARD
+ };
+
+
+typedef unsigned int fexcept_t;
+typedef unsigned int fenv_t;
+
+/* If the default argument is used we use this value. */
+#define FE_DFL_ENV ((__const fenv_t *) -1)
+
+#if __GLIBC_USE (IEC_60559_BFP_EXT)
+/* Type representing floating-point control modes. */
+typedef unsigned int femode_t;
+
+/* Default floating-point control modes. */
+# define FE_DFL_MODE ((const femode_t *) -1L)
+#endif
diff --git a/libc/sysdeps/linux/riscv32/bits/kernel_types.h b/libc/sysdeps/linux/riscv32/bits/kernel_types.h
new file mode 100644
index 000000000..832b17674
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/kernel_types.h
@@ -0,0 +1,42 @@
+/* Note that we use the exact same include guard #define names
+ * as asm/posix_types.h. This will avoid gratuitous conflicts
+ * with the posix_types.h kernel header, and will ensure that
+ * our private content, and not the kernel header, will win.
+ * -Erik
+ */
+#ifndef __ASM_GENERIC_POSIX_TYPES_H
+#define __ASM_GENERIC_POSIX_TYPES_H
+
+typedef unsigned long __kernel_dev_t;
+typedef unsigned long __kernel_ino_t;
+typedef unsigned int __kernel_mode_t;
+typedef unsigned int __kernel_nlink_t;
+typedef long __kernel_off_t;
+typedef int __kernel_pid_t;
+typedef int __kernel_ipc_pid_t;
+typedef unsigned int __kernel_uid_t;
+typedef unsigned int __kernel_gid_t;
+typedef unsigned long __kernel_size_t;
+typedef long __kernel_ssize_t;
+typedef long __kernel_ptrdiff_t;
+typedef long __kernel_time_t;
+typedef long __kernel_suseconds_t;
+typedef long __kernel_clock_t;
+typedef int __kernel_daddr_t;
+typedef char * __kernel_caddr_t;
+typedef unsigned short __kernel_uid16_t;
+typedef unsigned short __kernel_gid16_t;
+typedef unsigned int __kernel_uid32_t;
+typedef unsigned int __kernel_gid32_t;
+typedef unsigned short __kernel_old_uid_t;
+typedef unsigned short __kernel_old_gid_t;
+typedef long long __kernel_loff_t;
+typedef unsigned int __kernel_old_dev_t;
+typedef long __kernel_long_t;
+typedef unsigned long __kernel_ulong_t;
+
+typedef struct {
+ int val[2];
+} __kernel_fsid_t;
+
+#endif /* __ASM_GENERIC_POSIX_TYPES_H */
diff --git a/libc/sysdeps/linux/riscv32/bits/mman.h b/libc/sysdeps/linux/riscv32/bits/mman.h
new file mode 100644
index 000000000..fa6f8e6a0
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/mman.h
@@ -0,0 +1,38 @@
+/* Definitions for POSIX memory map interface. Linux/RISC-V version.
+ Copyright (C) 1997-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */
+# define MAP_DENYWRITE 0x00800 /* ETXTBSY. */
+# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */
+# define MAP_LOCKED 0x02000 /* Lock the mapping. */
+# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
+# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
+# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+# define MAP_STACK 0x20000 /* Allocation is for a stack. */
+# define MAP_HUGETLB 0x40000 /* Create huge page mapping. */
+# define MAP_SYNC 0x80000 /* Perform synchronous page
+ faults for the mapping. */
+# define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could - be uninitialized. */
+#endif
+
+/* Include generic Linux declarations. */
+#include <bits/mman-linux.h>
diff --git a/libc/sysdeps/linux/riscv32/bits/setjmp.h b/libc/sysdeps/linux/riscv32/bits/setjmp.h
new file mode 100644
index 000000000..c45f93957
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/setjmp.h
@@ -0,0 +1,38 @@
+/* Define the machine-dependent type `jmp_buf'. RISC-V version.
+ Copyright (C) 2011-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _RISCV_BITS_SETJMP_H
+#define _RISCV_BITS_SETJMP_H
+
+typedef struct __jmp_buf_internal_tag
+ {
+ /* Program counter. */
+ long int __pc;
+ /* Callee-saved registers. */
+ long int __regs[12];
+ /* Stack pointer. */
+ long int __sp;
+
+ /* Callee-saved floating point registers. */
+#if defined __riscv_float_abi_double
+ double __fpregs[12];
+#elif !defined __riscv_float_abi_soft
+# error unsupported FLEN
+#endif
+ } __jmp_buf[1];
+
+#endif /* _RISCV_BITS_SETJMP_H */
diff --git a/libc/sysdeps/linux/riscv32/bits/shm.h b/libc/sysdeps/linux/riscv32/bits/shm.h
new file mode 100644
index 000000000..8a11c7050
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/shm.h
@@ -0,0 +1,90 @@
+/*
+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
+ * in this tarball.
+ */
+
+#ifndef _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Permission flag for shmget. */
+#define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */
+#define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */
+
+/* Flags for `shmat'. */
+#define SHM_RDONLY 010000 /* attach read-only else read-write */
+#define SHM_RND 020000 /* round attach address to SHMLBA */
+#define SHM_REMAP 040000 /* take-over region on attach */
+
+/* Commands for `shmctl'. */
+#define SHM_LOCK 11 /* lock segment (root only) */
+#define SHM_UNLOCK 12 /* unlock segment (root only) */
+
+__BEGIN_DECLS
+
+/* Segment low boundary address multiple. */
+#define SHMLBA (__getpagesize () << 2)
+extern int __getpagesize (void) __THROW __attribute__ ((__const__));
+
+
+/* Type to count number of attaches. */
+typedef unsigned long int shmatt_t;
+
+/* Data structure describing a set of semaphores. */
+struct shmid_ds
+ {
+ struct ipc_perm shm_perm; /* operation permission struct */
+ size_t shm_segsz; /* size of segment in bytes */
+ __time_t shm_atime; /* time of last shmat() */
+ unsigned long int __uclibc_unused1;
+ __time_t shm_dtime; /* time of last shmdt() */
+ unsigned long int __uclibc_unused2;
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ unsigned long int __uclibc_unused3;
+ __pid_t shm_cpid; /* pid of creator */
+ __pid_t shm_lpid; /* pid of last shmop */
+ shmatt_t shm_nattch; /* number of current attaches */
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
+ };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 13
+# define SHM_INFO 14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST 01000 /* segment will be destroyed on last detach */
+# define SHM_LOCKED 02000 /* segment will not be swapped */
+# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */
+# define SHM_NORESERVE 010000 /* don't check for reservations */
+
+struct shminfo
+ {
+ unsigned long int shmmax;
+ unsigned long int shmmin;
+ unsigned long int shmmni;
+ unsigned long int shmseg;
+ unsigned long int shmall;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
+ };
+
+struct shm_info
+ {
+ int used_ids;
+ unsigned long int shm_tot; /* total allocated shm */
+ unsigned long int shm_rss; /* total resident shm */
+ unsigned long int shm_swp; /* total swapped shm */
+ unsigned long int swap_attempts;
+ unsigned long int swap_successes;
+ };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/libc/sysdeps/linux/riscv32/bits/sigcontext.h b/libc/sysdeps/linux/riscv32/bits/sigcontext.h
new file mode 100644
index 000000000..9b896a626
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/sigcontext.h
@@ -0,0 +1,32 @@
+/* Machine-dependent signal context structure for Linux. RISC-V version.
+ Copyright (C) 1996-2018 Free Software
+ Foundation, Inc. This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _BITS_SIGCONTEXT_H
+#define _BITS_SIGCONTEXT_H 1
+
+#if !defined _SIGNAL_H && !defined _SYS_UCONTEXT_H
+# error "Never use <bits/sigcontext.h> directly; include <signal.h> instead."
+#endif
+
+struct sigcontext {
+ /* gregs[0] holds the program counter. */
+ unsigned long int gregs[32];
+ unsigned long long int fpregs[66] __attribute__ ((__aligned__ (16)));
+};
+
+#endif
diff --git a/libc/sysdeps/linux/riscv32/bits/stackinfo.h b/libc/sysdeps/linux/riscv32/bits/stackinfo.h
new file mode 100644
index 000000000..a9fd8173b
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/stackinfo.h
@@ -0,0 +1,11 @@
+/*
+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB
+ * in this tarball.
+ */
+
+#ifndef _STACKINFO_H
+#define _STACKINFO_H 1
+
+#define _STACK_GROWS_DOWN 1
+
+#endif
diff --git a/libc/sysdeps/linux/riscv32/bits/syscalls.h b/libc/sysdeps/linux/riscv32/bits/syscalls.h
new file mode 100644
index 000000000..d1f1d9170
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/syscalls.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2018 by Waldemar Brodkorb <wbx@uclibc-ng.org>
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ * ported from GNU C Library
+ */
+
+#ifndef _BITS_SYSCALLS_H
+#define _BITS_SYSCALLS_H
+#ifndef _SYSCALL_H
+# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
+#endif
+
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({ long _sys_result; \
+ { \
+ register long int _a7 __asm__ ("a7"); \
+ LOAD_ARGS_##nr (args) \
+ _a7 = (name); \
+ \
+ __asm__ volatile ( \
+ "scall\n\t" \
+ : "=r" (_a0) \
+ : "r"(_a7) ASM_ARGS_##nr \
+ : "memory"); \
+ _sys_result = _a0; \
+ } \
+ _sys_result; \
+ })
+
+/* Macros for setting up inline __asm__ input regs */
+# define ASM_ARGS_0
+# define ASM_ARGS_1 , "r" (_a0)
+# define ASM_ARGS_2 ASM_ARGS_1, "r" (_a1)
+# define ASM_ARGS_3 ASM_ARGS_2, "r" (_a2)
+# define ASM_ARGS_4 ASM_ARGS_3, "r" (_a3)
+# define ASM_ARGS_5 ASM_ARGS_4, "r" (_a4)
+# define ASM_ARGS_6 ASM_ARGS_5, "r" (_a5)
+# define ASM_ARGS_7 ASM_ARGS_6, "r" (_a6)
+
+/* Macros for converting sys-call wrapper args into sys call args */
+# define LOAD_ARGS_0() \
+ register long _a0 __asm__ ("a0");
+# define LOAD_ARGS_1(a0) \
+ long _a0tmp; \
+ LOAD_ARGS_0 () \
+ _a0tmp = (long) (a0); \
+ _a0 = _a0tmp;
+# define LOAD_ARGS_2(a0, a1) \
+ register long _a1 __asm__ ("a1"); \
+ long _a1tmp; \
+ LOAD_ARGS_1 (a0) \
+ _a1tmp = (long) (a1); \
+ _a1 = _a1tmp;
+# define LOAD_ARGS_3(a0, a1, a2) \
+ register long _a2 __asm__ ("a2"); \
+ long _a2tmp; \
+ LOAD_ARGS_2 (a0, a1) \
+ _a2tmp = (long) (a2); \
+ _a2 = _a2tmp;
+# define LOAD_ARGS_4(a0, a1, a2, a3) \
+ register long _a3 __asm__ ("a3"); \
+ long _a3tmp; \
+ LOAD_ARGS_3 (a0, a1, a2) \
+ _a3tmp = (long) (a3); \
+ _a3 = _a3tmp;
+# define LOAD_ARGS_5(a0, a1, a2, a3, a4) \
+ register long _a4 __asm__ ("a4"); \
+ long _a4tmp; \
+ LOAD_ARGS_4 (a0, a1, a2, a3) \
+ _a4tmp = (long) (a4); \
+ _a4 = _a4tmp;
+# define LOAD_ARGS_6(a0, a1, a2, a3, a4, a5) \
+ register long _a5 __asm__ ("a5"); \
+ long _a5tmp; \
+ LOAD_ARGS_5 (a0, a1, a2, a3, a4) \
+ _a5tmp = (long) (a5); \
+ _a5 = _a5tmp;
+# define LOAD_ARGS_7(a0, a1, a2, a3, a4, a5, a6)\
+ register long _a6 __asm__ ("a6"); \
+ long _a6tmp; \
+ LOAD_ARGS_6 (a0, a1, a2, a3, a4, a5) \
+ _a6tmp = (long) (a6); \
+ _a6 = _a6tmp;
+
+#endif
diff --git a/libc/sysdeps/linux/riscv32/bits/uClibc_arch_features.h b/libc/sysdeps/linux/riscv32/bits/uClibc_arch_features.h
new file mode 100644
index 000000000..b53c47278
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/uClibc_arch_features.h
@@ -0,0 +1,36 @@
+/*
+ * Track misc arch-specific features that aren't config options
+ */
+
+#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
+#define _BITS_UCLIBC_ARCH_FEATURES_H
+
+#define __UCLIBC_ABORT_INSTRUCTION__ "unimp"
+
+#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
+
+/* does your target have a broken create_module() ? */
+#define __UCLIBC_BROKEN_CREATE_MODULE__
+
+/* does your target have to worry about older [gs]etrlimit() ? */
+#define __UCLIBC_HANDLE_OLDER_RLIMIT__
+
+/* does your target have an asm .set ? */
+#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
+
+/* define if target doesn't like .global */
+#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
+
+/* define if target supports .weak */
+#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
+
+/* define if target supports .weakext */
+#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
+
+/* define if target supports IEEE signed zero floats */
+#define __UCLIBC_HAVE_SIGNED_ZERO__
+
+/* define if target supports CFI pseudo ops */
+#define __UCLIBC_HAVE_ASM_CFI_DIRECTIVES__
+
+#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
diff --git a/libc/sysdeps/linux/riscv32/bits/uClibc_page.h b/libc/sysdeps/linux/riscv32/bits/uClibc_page.h
new file mode 100644
index 000000000..d1f9262fd
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/uClibc_page.h
@@ -0,0 +1,28 @@
+/* Copyright (C) 2004 Erik Andersen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * The GNU C Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; see the file COPYING.LIB. If
+ * not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Supply an architecture specific value for PAGE_SIZE and friends. */
+
+#ifndef _UCLIBC_PAGE_H
+#define _UCLIBC_PAGE_H
+
+/* PAGE_SHIFT determines the page size -- in this case 4096 */
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+
+#endif /* _UCLIBC_PAGE_H */
diff --git a/libc/sysdeps/linux/riscv32/bits/wordsize.h b/libc/sysdeps/linux/riscv32/bits/wordsize.h
new file mode 100644
index 000000000..1fc649aad
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bits/wordsize.h
@@ -0,0 +1,30 @@
+/* Determine the wordsize from the preprocessor defines. RISC-V version.
+ Copyright (C) 2002-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#if __riscv_xlen == (__SIZEOF_POINTER__ * 8)
+# define __WORDSIZE __riscv_xlen
+#else
+# error unsupported ABI
+#endif
+
+#if __riscv_xlen == 64
+# define __WORDSIZE_TIME64_COMPAT32 1
+#else
+# define __WORDSIZE_TIME64_COMPAT32 1
+// # warning "rv32i-based targets are experimental"
+#endif
diff --git a/libc/sysdeps/linux/riscv32/bsd-_setjmp.c b/libc/sysdeps/linux/riscv32/bsd-_setjmp.c
new file mode 100644
index 000000000..0d413101c
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bsd-_setjmp.c
@@ -0,0 +1 @@
+/* _setjmp is implemented in setjmp.S */
diff --git a/libc/sysdeps/linux/riscv32/bsd-setjmp.c b/libc/sysdeps/linux/riscv32/bsd-setjmp.c
new file mode 100644
index 000000000..0d413101c
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/bsd-setjmp.c
@@ -0,0 +1 @@
+/* _setjmp is implemented in setjmp.S */
diff --git a/libc/sysdeps/linux/riscv32/cache.c b/libc/sysdeps/linux/riscv32/cache.c
new file mode 100644
index 000000000..aa99a2a0d
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/cache.c
@@ -0,0 +1,55 @@
+/* RISC-V instruction cache flushing VDSO calls
+ Copyright (C) 2017-2020 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <atomic.h>
+#include <sys/syscall.h>
+
+#ifndef __NR_riscv_flush_icache
+#define __NR_riscv_flush_icache 259
+#endif
+
+typedef int (*func_type) (void *, void *, unsigned long int);
+
+static int
+__riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags)
+{
+ return INLINE_SYSCALL (riscv_flush_icache, 3, start, end, flags);
+}
+
+static func_type
+__lookup_riscv_flush_icache (void)
+{
+ /* always call the system call directly.*/
+ return &__riscv_flush_icache_syscall;
+}
+
+int
+__riscv_flush_icache (void *start, void *end, unsigned long int flags)
+{
+ static volatile func_type cached_func;
+
+ func_type func = atomic_load_relaxed (&cached_func);
+
+ if (!func)
+ {
+ func = __lookup_riscv_flush_icache ();
+ atomic_store_relaxed (&cached_func, func);
+ }
+
+ return func (start, end, flags);
+}
diff --git a/libc/sysdeps/linux/riscv32/clone.S b/libc/sysdeps/linux/riscv32/clone.S
new file mode 100644
index 000000000..315de2ac8
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/clone.S
@@ -0,0 +1,86 @@
+/* Wrapper around clone system call. RISC-V version.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* clone() is even more special than fork() as it mucks with stacks
+ and invokes a function in the right context after its all over. */
+
+#include <sys/asm.h>
+#include <sysdep.h>
+#define _ERRNO_H 1
+#include <bits/errno.h>
+
+/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
+ void *parent_tidptr, void *tls, void *child_tidptr) */
+
+ .text
+LEAF (clone)
+
+ /* Align stack to a 128-bit boundary as per RISC-V ABI. */
+ andi a1,a1,ALMASK
+
+ /* Sanity check arguments. */
+ beqz a0,L (invalid) /* No NULL function pointers. */
+ beqz a1,L (invalid) /* No NULL stack pointers. */
+
+ addi a1,a1,-16 /* Reserve argument save space. */
+ REG_S a0,0(a1) /* Save function pointer. */
+ REG_S a3,SZREG(a1) /* Save argument pointer. */
+
+ /* The syscall expects the args to be in different slots. */
+ mv a0,a2
+ mv a2,a4
+ mv a3,a5
+ mv a4,a6
+
+ /* Do the system call. */
+ li a7,__NR_clone
+ scall
+
+ bltz a0,L (error)
+ beqz a0,L (thread_start)
+
+ /* Successful return from the parent. */
+ ret
+
+L (invalid):
+ li a0, -EINVAL
+ /* Something bad happened -- no child created. */
+L (error):
+ tail __syscall_error
+ END (clone)
+
+/* Load up the arguments to the function. Put this block of code in
+ its own function so that we can terminate the stack trace with our
+ debug info. */
+
+ENTRY (__thread_start)
+L (thread_start):
+ .cfi_label .Ldummy
+ cfi_undefined (ra)
+
+ /* Restore the arg for user's function. */
+ REG_L a1,0(sp) /* Function pointer. */
+ REG_L a0,SZREG(sp) /* Argument pointer. */
+
+ /* Call the user's function. */
+ jalr a1
+
+ /* Call exit with the function's return value. */
+ li a7, __NR_exit
+ scall
+
+ END (__thread_start)
diff --git a/libc/sysdeps/linux/riscv32/crt1.S b/libc/sysdeps/linux/riscv32/crt1.S
new file mode 100644
index 000000000..5e33046d4
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/crt1.S
@@ -0,0 +1,85 @@
+/* Startup code compliant to the ELF RISC-V ABI.
+ Copyright (C) 1995-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ In addition to the permissions in the GNU Lesser General Public
+ License, the Free Software Foundation gives you unlimited
+ permission to link the compiled version of this file with other
+ programs, and to distribute those programs without any restriction
+ coming from the use of this file. (The GNU Lesser General Public
+ License restrictions do apply in other respects; for example, they
+ cover modification of the file, and distribution when not linked
+ into another program.)
+
+ Note that people who make modified versions of this file are not
+ obligated to grant this special exception for their modified
+ versions; it is their choice whether to do so. The GNU Lesser
+ General Public License gives permission to release a modified
+ version without this exception; this exception also makes it
+ possible to release a modified version which carries forward this
+ exception.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#define __ASSEMBLY__ 1
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+/* The entry point's job is to call __uClibc_main. Per the ABI,
+ a0 contains the address of a function to be passed to atexit.
+ __uClibc_main wants this in a5. */
+
+.text
+ .globl _start
+ .type _start,%function
+
+_start:
+ call .Lload_gp
+ mv a5, a0 /* rtld_fini. */
+ /* main may be in a shared library. */
+ la a0, main
+ REG_L a1, 0(sp) /* argc. */
+ addi a2, sp, SZREG /* argv. */
+ mv a3, zero
+ mv a4, zero
+ andi sp, sp, ALMASK /* Align stack. */
+ mv a6, sp /* stack_end. */
+
+ tail __uClibc_main@plt
+
+ .size _start,.-_start
+
+/* Dynamic links need the global pointer to be initialized prior to calling
+ any shared library's initializers, so we use preinit_array to load it.
+ This doesn't cut it for static links, though, since the global pointer
+ needs to be initialized before calling __libc_start_main in that case.
+ So we redundantly initialize it at the beginning of _start. */
+
+.Lload_gp:
+.option push
+.option norelax
+ lla gp, __global_pointer$
+.option pop
+ ret
+
+ .section .preinit_array,"aw"
+ .dc.a .Lload_gp
+
+/* Define a symbol for the first piece of initialized data. */
+ .data
+ .globl __data_start
+__data_start:
+ .weak data_start
+ data_start = __data_start
diff --git a/libc/sysdeps/linux/riscv32/crti.S b/libc/sysdeps/linux/riscv32/crti.S
new file mode 100644
index 000000000..176de9199
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/crti.S
@@ -0,0 +1,17 @@
+/* dummy _init and _fini */
+
+ .section .init
+ .globl _init
+ .align 2
+ .type _init,@function
+
+_init:
+
+
+ .section .fini
+ .global _fini
+ .align 2
+ .type _fini,@function
+
+_fini:
+
diff --git a/libc/sysdeps/linux/riscv32/crtn.S b/libc/sysdeps/linux/riscv32/crtn.S
new file mode 100644
index 000000000..6f70e7716
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/crtn.S
@@ -0,0 +1,13 @@
+/* Dummy crtn file.
+
+ In this configuration, crti.o and crtn.o are both empty because the
+ .init_array/.fini_array sections are used exclusively.
+
+ Older ports cannot use this because even if the linker used to
+ build libc itself has .init_array support, we don't want to produce
+ a crt[in].o that presume a linker that new will be used to link
+ other things later.
+
+ But new configurations without compatibility concerns for
+ toolchains without .init_array support can use this to avoid the
+ superfluous .init and .fini boilerplate code. */
diff --git a/libc/sysdeps/linux/riscv32/getcontext.S b/libc/sysdeps/linux/riscv32/getcontext.S
new file mode 100644
index 000000000..0b9e7c2d3
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/getcontext.S
@@ -0,0 +1,74 @@
+/* Save current context.
+ Copyright (C) 2009-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "ucontext-macros.h"
+
+/* int getcontext (ucontext_t *ucp) */
+
+ .text
+LEAF (getcontext)
+ SAVE_INT_REG (ra, 0, a0)
+ SAVE_INT_REG (ra, 1, a0)
+ SAVE_INT_REG (sp, 2, a0)
+ SAVE_INT_REG (s0, 8, a0)
+ SAVE_INT_REG (s1, 9, a0)
+ SAVE_INT_REG (x0, 10, a0) /* return 0 by overwriting a0. */
+ SAVE_INT_REG (s2, 18, a0)
+ SAVE_INT_REG (s3, 19, a0)
+ SAVE_INT_REG (s4, 20, a0)
+ SAVE_INT_REG (s5, 21, a0)
+ SAVE_INT_REG (s6, 22, a0)
+ SAVE_INT_REG (s7, 23, a0)
+ SAVE_INT_REG (s8, 24, a0)
+ SAVE_INT_REG (s9, 25, a0)
+ SAVE_INT_REG (s10, 26, a0)
+ SAVE_INT_REG (s11, 27, a0)
+
+#ifndef __riscv_float_abi_soft
+ frsr a1
+
+ SAVE_FP_REG (fs0, 8, a0)
+ SAVE_FP_REG (fs1, 9, a0)
+ SAVE_FP_REG (fs2, 18, a0)
+ SAVE_FP_REG (fs3, 19, a0)
+ SAVE_FP_REG (fs4, 20, a0)
+ SAVE_FP_REG (fs5, 21, a0)
+ SAVE_FP_REG (fs6, 22, a0)
+ SAVE_FP_REG (fs7, 23, a0)
+ SAVE_FP_REG (fs8, 24, a0)
+ SAVE_FP_REG (fs9, 25, a0)
+ SAVE_FP_REG (fs10, 26, a0)
+ SAVE_FP_REG (fs11, 27, a0)
+
+ sw a1, MCONTEXT_FSR(a0)
+#endif /* __riscv_float_abi_soft */
+
+/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */
+ li a3, _NSIG8
+ add a2, a0, UCONTEXT_SIGMASK
+ mv a1, zero
+ li a0, SIG_BLOCK
+
+ li a7, SYS_ify (rt_sigprocmask)
+ scall
+ bltz a0, 99f
+
+ ret
+
+99: j __syscall_error
+
+PSEUDO_END (getcontext)
diff --git a/libc/sysdeps/linux/riscv32/jmpbuf-offsets.h b/libc/sysdeps/linux/riscv32/jmpbuf-offsets.h
new file mode 100644
index 000000000..fff4d0d9c
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/jmpbuf-offsets.h
@@ -0,0 +1,23 @@
+/* Private macros for accessing __jmp_buf contents. RISC-V version.
+ Copyright (C) 2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <jmpbuf-unwind.h>
+
+/* Helper for generic ____longjmp_chk(). */
+#define JB_FRAME_ADDRESS(buf) \
+ ((void *) _jmpbuf_sp (buf))
diff --git a/libc/sysdeps/linux/riscv32/jmpbuf-unwind.h b/libc/sysdeps/linux/riscv32/jmpbuf-unwind.h
new file mode 100644
index 000000000..fb5d65ddd
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/jmpbuf-unwind.h
@@ -0,0 +1,43 @@
+/* Examine __jmp_buf for unwinding frames. RISC-V version.
+ Copyright (C) 2003-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <setjmp.h>
+#include <stdint.h>
+#include <unwind.h>
+#include <sysdep.h>
+
+/* Test if longjmp to JMPBUF would unwind the frame
+ containing a local variable at ADDRESS. */
+#define _JMPBUF_UNWINDS(jmpbuf, address) \
+ ((void *) (address) < (void *) ((jmpbuf)[0].__sp))
+
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
+ _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf regs)
+{
+ uintptr_t sp = regs[0].__sp;
+ return sp;
+}
+
+#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
+ ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
+
+/* We use the normal longjmp for unwinding. */
+#define __libc_unwind_longjmp(buf, val) __libc_longjmp (buf, val)
diff --git a/libc/sysdeps/linux/riscv32/setcontext.S b/libc/sysdeps/linux/riscv32/setcontext.S
new file mode 100644
index 000000000..15cc17bd8
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/setcontext.S
@@ -0,0 +1,112 @@
+/* Set current context.
+ Copyright (C) 2009-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "ucontext-macros.h"
+
+/* int __setcontext (const ucontext_t *ucp)
+
+ Restores the machine context in UCP and thereby resumes execution
+ in that context.
+
+ This implementation is intended to be used for *synchronous* context
+ switches only. Therefore, it does not have to restore anything
+ other than the PRESERVED state. */
+
+ .text
+LEAF (setcontext)
+
+ mv t0, a0 /* Save ucp into t0. */
+
+/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
+ li a3, _NSIG8
+ mv a2, zero
+ add a1, a0, UCONTEXT_SIGMASK
+ li a0, SIG_SETMASK
+
+ li a7, SYS_ify (rt_sigprocmask)
+ scall
+
+ bltz a0, 99f
+
+ cfi_def_cfa (t0, 0)
+
+#ifndef __riscv_float_abi_soft
+ lw t1, MCONTEXT_FSR(t0)
+
+ RESTORE_FP_REG_CFI (fs0, 8, t0)
+ RESTORE_FP_REG_CFI (fs1, 9, t0)
+ RESTORE_FP_REG_CFI (fs2, 18, t0)
+ RESTORE_FP_REG_CFI (fs3, 19, t0)
+ RESTORE_FP_REG_CFI (fs4, 20, t0)
+ RESTORE_FP_REG_CFI (fs5, 21, t0)
+ RESTORE_FP_REG_CFI (fs6, 22, t0)
+ RESTORE_FP_REG_CFI (fs7, 23, t0)
+ RESTORE_FP_REG_CFI (fs8, 24, t0)
+ RESTORE_FP_REG_CFI (fs9, 25, t0)
+ RESTORE_FP_REG_CFI (fs10, 26, t0)
+ RESTORE_FP_REG_CFI (fs11, 27, t0)
+
+ fssr t1
+#endif /* __riscv_float_abi_soft */
+
+ /* Note the contents of argument registers will be random
+ unless makecontext() has been called. */
+ RESTORE_INT_REG (t1, 0, t0)
+ RESTORE_INT_REG_CFI (ra, 1, t0)
+ RESTORE_INT_REG (sp, 2, t0)
+ RESTORE_INT_REG_CFI (s0, 8, t0)
+ RESTORE_INT_REG_CFI (s1, 9, t0)
+ RESTORE_INT_REG (a0, 10, t0)
+ RESTORE_INT_REG (a1, 11, t0)
+ RESTORE_INT_REG (a2, 12, t0)
+ RESTORE_INT_REG (a3, 13, t0)
+ RESTORE_INT_REG (a4, 14, t0)
+ RESTORE_INT_REG (a5, 15, t0)
+ RESTORE_INT_REG (a6, 16, t0)
+ RESTORE_INT_REG (a7, 17, t0)
+ RESTORE_INT_REG_CFI (s2, 18, t0)
+ RESTORE_INT_REG_CFI (s3, 19, t0)
+ RESTORE_INT_REG_CFI (s4, 20, t0)
+ RESTORE_INT_REG_CFI (s5, 21, t0)
+ RESTORE_INT_REG_CFI (s6, 22, t0)
+ RESTORE_INT_REG_CFI (s7, 23, t0)
+ RESTORE_INT_REG_CFI (s8, 24, t0)
+ RESTORE_INT_REG_CFI (s9, 25, t0)
+ RESTORE_INT_REG_CFI (s10, 26, t0)
+ RESTORE_INT_REG_CFI (s11, 27, t0)
+
+ jr t1
+
+99: j __syscall_error
+
+PSEUDO_END (setcontext)
+
+LEAF (start_context)
+
+ /* Terminate call stack by noting ra == 0. Happily, s0 == 0 here. */
+ cfi_register (ra, s0)
+
+ /* Call the function passed to makecontext. */
+ jalr s1
+
+ /* Invoke subsequent context if present, else exit(0). */
+ mv a0, s2
+ beqz s2, 1f
+ jal setcontext
+1: j exit
+
+PSEUDO_END (start_context)
diff --git a/libc/sysdeps/linux/riscv32/setjmp.S b/libc/sysdeps/linux/riscv32/setjmp.S
new file mode 100644
index 000000000..100a0bd78
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/setjmp.S
@@ -0,0 +1,73 @@
+/* setjmp for RISC-V.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+ENTRY (_setjmp)
+ li a1, 0
+ j HIDDEN_JUMPTARGET (__sigsetjmp)
+END (_setjmp)
+ENTRY (setjmp)
+ li a1, 1
+ /* Fallthrough */
+END (setjmp)
+ENTRY (__sigsetjmp)
+ REG_S ra, 0*SZREG(a0)
+ REG_S s0, 1*SZREG(a0)
+ REG_S s1, 2*SZREG(a0)
+ REG_S s2, 3*SZREG(a0)
+ REG_S s3, 4*SZREG(a0)
+ REG_S s4, 5*SZREG(a0)
+ REG_S s5, 6*SZREG(a0)
+ REG_S s6, 7*SZREG(a0)
+ REG_S s7, 8*SZREG(a0)
+ REG_S s8, 9*SZREG(a0)
+ REG_S s9, 10*SZREG(a0)
+ REG_S s10,11*SZREG(a0)
+ REG_S s11,12*SZREG(a0)
+ REG_S sp, 13*SZREG(a0)
+
+#ifndef __riscv_float_abi_soft
+ FREG_S fs0, 14*SZREG+ 0*SZFREG(a0)
+ FREG_S fs1, 14*SZREG+ 1*SZFREG(a0)
+ FREG_S fs2, 14*SZREG+ 2*SZFREG(a0)
+ FREG_S fs3, 14*SZREG+ 3*SZFREG(a0)
+ FREG_S fs4, 14*SZREG+ 4*SZFREG(a0)
+ FREG_S fs5, 14*SZREG+ 5*SZFREG(a0)
+ FREG_S fs6, 14*SZREG+ 6*SZFREG(a0)
+ FREG_S fs7, 14*SZREG+ 7*SZFREG(a0)
+ FREG_S fs8, 14*SZREG+ 8*SZFREG(a0)
+ FREG_S fs9, 14*SZREG+ 9*SZFREG(a0)
+ FREG_S fs10,14*SZREG+10*SZFREG(a0)
+ FREG_S fs11,14*SZREG+11*SZFREG(a0)
+#endif
+
+#if !IS_IN_libc && IS_IN_rtld
+ /* In ld.so we never save the signal mask. */
+ li a0, 0
+ ret
+#else
+ /* Make a tail call to __sigjmp_save; it takes the same args. */
+ j __sigjmp_save
+#endif
+
+
+END (__sigsetjmp)
+
+hidden_def (__sigsetjmp)
+weak_alias (_setjmp, __GI__setjmp)
diff --git a/libc/sysdeps/linux/riscv32/swapcontext.S b/libc/sysdeps/linux/riscv32/swapcontext.S
new file mode 100644
index 000000000..f5e12b2db
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/swapcontext.S
@@ -0,0 +1,122 @@
+/* Save and set current context.
+ Copyright (C) 2009-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include "ucontext-macros.h"
+
+/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
+
+LEAF (swapcontext)
+ mv t0, a1 /* Save ucp into t0. */
+
+ SAVE_INT_REG (ra, 0, a0)
+ SAVE_INT_REG (ra, 1, a0)
+ SAVE_INT_REG (sp, 2, a0)
+ SAVE_INT_REG (s0, 8, a0)
+ SAVE_INT_REG (s1, 9, a0)
+ SAVE_INT_REG (x0, 10, a0) /* return 0 by overwriting a0. */
+ SAVE_INT_REG (s2, 18, a0)
+ SAVE_INT_REG (s3, 19, a0)
+ SAVE_INT_REG (s4, 20, a0)
+ SAVE_INT_REG (s5, 21, a0)
+ SAVE_INT_REG (s6, 22, a0)
+ SAVE_INT_REG (s7, 23, a0)
+ SAVE_INT_REG (s8, 24, a0)
+ SAVE_INT_REG (s9, 25, a0)
+ SAVE_INT_REG (s10, 26, a0)
+ SAVE_INT_REG (s11, 27, a0)
+
+#ifndef __riscv_float_abi_soft
+ frsr a1
+
+ SAVE_FP_REG (fs0, 8, a0)
+ SAVE_FP_REG (fs1, 9, a0)
+ SAVE_FP_REG (fs2, 18, a0)
+ SAVE_FP_REG (fs3, 19, a0)
+ SAVE_FP_REG (fs4, 20, a0)
+ SAVE_FP_REG (fs5, 21, a0)
+ SAVE_FP_REG (fs6, 22, a0)
+ SAVE_FP_REG (fs7, 23, a0)
+ SAVE_FP_REG (fs8, 24, a0)
+ SAVE_FP_REG (fs9, 25, a0)
+ SAVE_FP_REG (fs10, 26, a0)
+ SAVE_FP_REG (fs11, 27, a0)
+
+ sw a1, MCONTEXT_FSR(a0)
+#endif /* __riscv_float_abi_soft */
+
+/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8) */
+ li a3, _NSIG8
+ add a2, a0, UCONTEXT_SIGMASK
+ add a1, t0, UCONTEXT_SIGMASK
+ li a0, SIG_SETMASK
+
+ li a7, SYS_ify (rt_sigprocmask)
+ scall
+
+ bltz a0, 99f
+
+#ifndef __riscv_float_abi_soft
+ lw t1, MCONTEXT_FSR(t0)
+
+ RESTORE_FP_REG (fs0, 8, t0)
+ RESTORE_FP_REG (fs1, 9, t0)
+ RESTORE_FP_REG (fs2, 18, t0)
+ RESTORE_FP_REG (fs3, 19, t0)
+ RESTORE_FP_REG (fs4, 20, t0)
+ RESTORE_FP_REG (fs5, 21, t0)
+ RESTORE_FP_REG (fs6, 22, t0)
+ RESTORE_FP_REG (fs7, 23, t0)
+ RESTORE_FP_REG (fs8, 24, t0)
+ RESTORE_FP_REG (fs9, 25, t0)
+ RESTORE_FP_REG (fs10, 26, t0)
+ RESTORE_FP_REG (fs11, 27, t0)
+
+ fssr t1
+#endif /* __riscv_float_abi_soft */
+
+ /* Note the contents of argument registers will be random
+ unless makecontext() has been called. */
+ RESTORE_INT_REG (t1, 0, t0)
+ RESTORE_INT_REG (ra, 1, t0)
+ RESTORE_INT_REG (sp, 2, t0)
+ RESTORE_INT_REG (s0, 8, t0)
+ RESTORE_INT_REG (s1, 9, t0)
+ RESTORE_INT_REG (a0, 10, t0)
+ RESTORE_INT_REG (a1, 11, t0)
+ RESTORE_INT_REG (a2, 12, t0)
+ RESTORE_INT_REG (a3, 13, t0)
+ RESTORE_INT_REG (a4, 14, t0)
+ RESTORE_INT_REG (a5, 15, t0)
+ RESTORE_INT_REG (a6, 16, t0)
+ RESTORE_INT_REG (a7, 17, t0)
+ RESTORE_INT_REG (s2, 18, t0)
+ RESTORE_INT_REG (s3, 19, t0)
+ RESTORE_INT_REG (s4, 20, t0)
+ RESTORE_INT_REG (s5, 21, t0)
+ RESTORE_INT_REG (s6, 22, t0)
+ RESTORE_INT_REG (s7, 23, t0)
+ RESTORE_INT_REG (s8, 24, t0)
+ RESTORE_INT_REG (s9, 25, t0)
+ RESTORE_INT_REG (s10, 26, t0)
+ RESTORE_INT_REG (s11, 27, t0)
+
+ jr t1
+
+
+99: j __syscall_error
+
+PSEUDO_END (swapcontext)
diff --git a/libc/sysdeps/linux/riscv32/sys/asm.h b/libc/sysdeps/linux/riscv32/sys/asm.h
new file mode 100644
index 000000000..3c94c9a70
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/sys/asm.h
@@ -0,0 +1,67 @@
+/* Miscellaneous macros.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_ASM_H
+#define _SYS_ASM_H
+
+/* Macros to handle different pointer/register sizes for 32/64-bit code. */
+#if __riscv_xlen == 64
+# define PTRLOG 3
+# define SZREG 8
+# define REG_S sd
+# define REG_L ld
+#elif __riscv_xlen == 32
+# define PTRLOG 2
+# define SZREG 4
+# define REG_S sw
+# define REG_L lw
+// # warning "rv32i-based targets are experimental"
+#else
+# error __riscv_xlen must equal 32 or 64
+#endif
+
+#if !defined __riscv_float_abi_soft
+/* For ABI uniformity, reserve 8 bytes for floats, even if double-precision
+ floating-point is not supported in hardware. */
+# if defined __riscv_float_abi_double
+# define FREG_L fld
+# define FREG_S fsd
+# define SZFREG 8
+# else
+# error unsupported FLEN
+# endif
+#endif
+
+/* Declare leaf routine. */
+#define LEAF(symbol) \
+ .globl symbol; \
+ .align 2; \
+ .type symbol,@function; \
+symbol: \
+ cfi_startproc;
+
+/* Mark end of function. */
+#undef END
+#define END(function) \
+ cfi_endproc; \
+ .size function,.-function
+
+/* Stack alignment. */
+#define ALMASK ~15
+
+#endif /* sys/asm.h */
diff --git a/libc/sysdeps/linux/riscv32/sys/procfs.h b/libc/sysdeps/linux/riscv32/sys/procfs.h
new file mode 100644
index 000000000..518de5674
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/sys/procfs.h
@@ -0,0 +1,114 @@
+/* Core image file related definitions, RISC-V version.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_PROCFS_H
+#define _SYS_PROCFS_H 1
+
+/* This is somehow modelled after the file of the same name on SysVr4
+ systems. It provides a definition of the core file format for ELF
+ used on Linux. */
+
+#include <features.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+#include <sys/ucontext.h>
+
+/* ELF register definitions */
+#define ELF_NGREG NGREG
+#define ELF_NFPREG NFPREG
+
+typedef unsigned long int elf_greg_t;
+typedef unsigned long int elf_gregset_t[32];
+typedef union __riscv_mc_fp_state elf_fpregset_t;
+
+__BEGIN_DECLS
+
+struct elf_siginfo
+ {
+ int si_signo; /* Signal number. */
+ int si_code; /* Extra code. */
+ int si_errno; /* Errno. */
+ };
+
+
+/* Definitions to generate Intel SVR4-like core files. These mostly
+ have the same names as the SVR4 types with "elf_" tacked on the
+ front to prevent clashes with linux definitions, and the typedef
+ forms have been avoided. This is mostly like the SVR4 structure,
+ but more Linuxy, with things that Linux does not support and which
+ gdb doesn't really use excluded. Fields present but not used are
+ marked with "XXX". */
+struct elf_prstatus
+ {
+ struct elf_siginfo pr_info; /* Info associated with signal. */
+ short int pr_cursig; /* Current signal. */
+ unsigned long int pr_sigpend; /* Set of pending signals. */
+ unsigned long int pr_sighold; /* Set of held signals. */
+ __pid_t pr_pid;
+ __pid_t pr_ppid;
+ __pid_t pr_pgrp;
+ __pid_t pr_sid;
+ struct timeval pr_utime; /* User time. */
+ struct timeval pr_stime; /* System time. */
+ struct timeval pr_cutime; /* Cumulative user time. */
+ struct timeval pr_cstime; /* Cumulative system time. */
+ elf_gregset_t pr_reg; /* GP registers. */
+ int pr_fpvalid; /* True if math copro being used. */
+ };
+
+
+#define ELF_PRARGSZ (80) /* Number of chars for args */
+
+struct elf_prpsinfo
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ unsigned long int pr_flag; /* Flags. */
+ long int pr_uid;
+ long int pr_gid;
+ int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+ /* Lots missing */
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */
+ };
+
+/* The rest of this file provides the types for emulation of the
+ Solaris <proc_service.h> interfaces that should be implemented by
+ users of libthread_db. */
+
+/* Addresses. */
+typedef void *psaddr_t;
+
+/* Register sets. Linux has different names. */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+ therefore habe only ine PID type. */
+typedef __pid_t lwpid_t;
+
+/* Process status and info. In the end we do provide typedefs for them. */
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif /* sys/procfs.h */
diff --git a/libc/sysdeps/linux/riscv32/sys/ucontext.h b/libc/sysdeps/linux/riscv32/sys/ucontext.h
new file mode 100644
index 000000000..2893ff359
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/sys/ucontext.h
@@ -0,0 +1,108 @@
+/* struct ucontext definition, RISC-V version.
+ Copyright (C) 1997-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Don't rely on this, the interface is currently messed up and may need to
+ be broken to be fixed. */
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H 1
+
+#include <features.h>
+#include <signal.h>
+#include <bits/sigcontext.h>
+
+typedef unsigned long int __riscv_mc_gp_state[32];
+
+#ifdef __USE_MISC
+# define NGREG 32
+
+# define REG_PC 0
+# define REG_RA 1
+# define REG_SP 2
+# define REG_TP 4
+# define REG_S0 8
+# define REG_S1 9
+# define REG_A0 10
+# define REG_S2 18
+# define REG_NARGS 8
+
+typedef unsigned long int greg_t;
+
+/* Container for all general registers. */
+typedef __riscv_mc_gp_state gregset_t;
+
+/* Container for floating-point state. */
+typedef union __riscv_mc_fp_state fpregset_t;
+#endif
+
+struct __riscv_mc_f_ext_state
+ {
+ unsigned int __f[32];
+ unsigned int __fcsr;
+ };
+
+struct __riscv_mc_d_ext_state
+ {
+ unsigned long long int __f[32];
+ unsigned int __fcsr;
+ };
+
+struct __riscv_mc_q_ext_state
+ {
+ unsigned long long int __f[64] __attribute__ ((__aligned__ (16)));
+ unsigned int __fcsr;
+ /* Reserved for expansion of sigcontext structure. Currently zeroed
+ upon signal, and must be zero upon sigreturn. */
+ unsigned int __glibc_reserved[3];
+ };
+
+union __riscv_mc_fp_state
+ {
+ struct __riscv_mc_f_ext_state __f;
+ struct __riscv_mc_d_ext_state __d;
+ struct __riscv_mc_q_ext_state __q;
+ };
+
+typedef struct mcontext_t
+ {
+ __riscv_mc_gp_state __gregs;
+ union __riscv_mc_fp_state __fpregs;
+ } mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext_t
+ {
+ unsigned long int __uc_flags;
+ struct ucontext_t *uc_link;
+ stack_t uc_stack;
+ sigset_t uc_sigmask;
+ /* There's some padding here to allow sigset_t to be expanded in the
+ future. Though this is unlikely, other architectures put uc_sigmask
+ at the end of this structure and explicitly state it can be
+ expanded, so we didn't want to box ourselves in here. */
+ char __glibc_reserved[1024 / 8 - sizeof (sigset_t)];
+ /* We can't put uc_sigmask at the end of this structure because we need
+ to be able to expand sigcontext in the future. For example, the
+ vector ISA extension will almost certainly add ISA state. We want
+ to ensure all user-visible ISA state can be saved and restored via a
+ ucontext, so we're putting this at the end in order to allow for
+ infinite extensibility. Since we know this will be extended and we
+ assume sigset_t won't be extended an extreme amount, we're
+ prioritizing this. */
+ mcontext_t uc_mcontext;
+ } ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/libc/sysdeps/linux/riscv32/sys/user.h b/libc/sysdeps/linux/riscv32/sys/user.h
new file mode 100644
index 000000000..c871f1a03
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/sys/user.h
@@ -0,0 +1 @@
+/* This file is not needed, but in practice gdb might try to include it. */
diff --git a/libc/sysdeps/linux/riscv32/sysdep.h b/libc/sysdeps/linux/riscv32/sysdep.h
new file mode 100644
index 000000000..3fa04bb57
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/sysdep.h
@@ -0,0 +1,126 @@
+/* Assembly macros for RISC-V.
+ Copyright (C) 2011-2018
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LINUX_RISCV_SYSDEP_H
+#define _LINUX_RISCV_SYSDEP_H 1
+
+#include <common/sysdep.h>
+#include <sys/syscall.h>
+
+#ifdef __ASSEMBLER__
+
+# include <sys/asm.h>
+
+# define ENTRY(name) LEAF(name)
+
+# define L(label) .L ## label
+
+/* Performs a system call, handling errors by setting errno. Linux indicates
+ errors by setting a0 to a value between -1 and -4095. */
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+ .text; \
+ .align 2; \
+ ENTRY (name); \
+ li a7, SYS_ify (syscall_name); \
+ scall; \
+ li a7, -4096; \
+ bgtu a0, a7, .Lsyscall_error ## name;
+
+# undef PSEUDO_END
+# define PSEUDO_END(sym) \
+ SYSCALL_ERROR_HANDLER (sym) \
+ ret; \
+ END (sym)
+
+# if !IS_IN_libc
+# if defined (__PIC__)
+# define SYSCALL_ERROR_HANDLER(name) \
+.Lsyscall_error ## name: \
+ la.tls.ie t1, errno; \
+ add t1, t1, tp; \
+ neg a0, a0; \
+ sw a0, 0(t1); \
+ li a0, -1;
+# else
+# define SYSCALL_ERROR_HANDLER(name) \
+.Lsyscall_error ## name: \
+ lui t1, %tprel_hi(errno); \
+ add t1, t1, tp, %tprel_add(errno); \
+ neg a0, a0; \
+ sw a0, %tprel_lo(errno)(t1); \
+ li a0, -1;
+# endif
+# else
+# define SYSCALL_ERROR_HANDLER(name) \
+.Lsyscall_error ## name: \
+ j __syscall_error;
+# endif
+
+/* Performs a system call, not setting errno. */
+# undef PSEUDO_NEORRNO
+# define PSEUDO_NOERRNO(name, syscall_name, args) \
+ .align 2; \
+ ENTRY (name); \
+ li a7, SYS_ify (syscall_name); \
+ scall;
+
+# undef PSEUDO_END_NOERRNO
+# define PSEUDO_END_NOERRNO(name) \
+ END (name)
+
+# undef ret_NOERRNO
+# define ret_NOERRNO ret
+
+/* Perfroms a system call, returning the error code. */
+# undef PSEUDO_ERRVAL
+# define PSEUDO_ERRVAL(name, syscall_name, args) \
+ PSEUDO_NOERRNO (name, syscall_name, args) \
+ neg a0, a0;
+
+# undef PSEUDO_END_ERRVAL
+# define PSEUDO_END_ERRVAL(name) \
+ END (name)
+
+# undef ret_ERRVAL
+# define ret_ERRVAL ret
+
+#endif /* __ASSEMBLER__ */
+
+/* In order to get __set_errno() definition in INLINE_SYSCALL. */
+#ifndef __ASSEMBLER__
+# include <errno.h>
+#endif
+
+#undef SYS_ify
+#define SYS_ify(syscall_name) __NR_##syscall_name
+
+#ifndef __ASSEMBLER__
+
+/* List of system calls which are supported as vsyscalls. */
+# define HAVE_CLOCK_GETRES_VSYSCALL 1
+# define HAVE_CLOCK_GETTIME_VSYSCALL 1
+# define HAVE_GETTIMEOFDAY_VSYSCALL 1
+# define HAVE_GETCPU_VSYSCALL 1
+
+
+extern long int __syscall_error (long int neg_errno);
+
+#endif /* ! __ASSEMBLER__ */
+
+#endif /* linux/riscv/sysdep.h */
diff --git a/libc/sysdeps/linux/riscv32/vfork.S b/libc/sysdeps/linux/riscv32/vfork.S
new file mode 100644
index 000000000..a624f2a7c
--- /dev/null
+++ b/libc/sysdeps/linux/riscv32/vfork.S
@@ -0,0 +1,42 @@
+/* vfork for Linux, RISC-V version.
+ Copyright (C) 2005-2018 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* vfork() is just a special case of clone(). */
+
+#include <sys/asm.h>
+#include <sysdep.h>
+#define __ASSEMBLY__
+#include <linux/sched.h>
+#include <asm/signal.h>
+
+ .text
+LEAF (__vfork)
+
+ li a0, (CLONE_VFORK | CLONE_VM | SIGCHLD)
+ mv a1, sp
+
+ li a7, __NR_clone
+ scall
+
+ bltz a0, 1f
+ ret
+
+1: j __syscall_error
+END (__vfork)
+libc_hidden_def(vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/libc/sysdeps/linux/riscv64/Makefile.arch b/libc/sysdeps/linux/riscv64/Makefile.arch
index 74c074852..21ecaa65b 100644
--- a/libc/sysdeps/linux/riscv64/Makefile.arch
+++ b/libc/sysdeps/linux/riscv64/Makefile.arch
@@ -1,2 +1,2 @@
-CSRC-y := __syscall_error.c
+CSRC-y := __syscall_error.c cache.c
SSRC-y := __longjmp.S setjmp.S vfork.S clone.S
diff --git a/libc/sysdeps/linux/riscv64/__syscall_error.c b/libc/sysdeps/linux/riscv64/__syscall_error.c
index 2b642e816..c682aae49 100644
--- a/libc/sysdeps/linux/riscv64/__syscall_error.c
+++ b/libc/sysdeps/linux/riscv64/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/riscv64/bits/atomic.h b/libc/sysdeps/linux/riscv64/bits/atomic.h
new file mode 100644
index 000000000..8bf6abfac
--- /dev/null
+++ b/libc/sysdeps/linux/riscv64/bits/atomic.h
@@ -0,0 +1,170 @@
+/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _RISCV64_ATOMIC_MACHINE_H
+#define _RISCV64_ATOMIC_MACHINE_H 1
+
+#define typeof __typeof__
+
+#include <stdint.h>
+#include <sysdep.h>
+
+typedef int8_t atomic8_t;
+typedef int16_t atomic16_t;
+typedef int32_t atomic32_t;
+typedef int64_t atomic64_t;
+
+typedef uint8_t uatomic8_t;
+typedef uint16_t uatomic16_t;
+typedef uint32_t uatomic32_t;
+typedef uint64_t uatomic64_t;
+
+typedef intptr_t atomicptr_t;
+typedef uintptr_t uatomicptr_t;
+typedef intmax_t atomic_max_t;
+typedef uintmax_t uatomic_max_t;
+
+#define __HAVE_64B_ATOMICS 1
+#define USE_ATOMIC_COMPILER_BUILTINS 1
+
+/* Compare and exchange.
+ For all "bool" routines, we return FALSE if exchange succesful. */
+
+# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ })
+
+# define __arch_compare_and_exchange_val_8_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_16_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_32_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+# define __arch_compare_and_exchange_val_64_int(mem, newval, oldval, model) \
+ ({ \
+ typeof (*mem) __oldval = (oldval); \
+ __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \
+ model, __ATOMIC_RELAXED); \
+ __oldval; \
+ })
+
+
+/* Compare and exchange with "acquire" semantics, ie barrier after. */
+
+# define atomic_compare_and_exchange_bool_acq(mem, new, old) \
+ __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
+ mem, new, old, __ATOMIC_ACQUIRE)
+
+# define atomic_compare_and_exchange_val_acq(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old, __ATOMIC_ACQUIRE)
+
+/* Compare and exchange with "release" semantics, ie barrier before. */
+
+# define atomic_compare_and_exchange_val_rel(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old, __ATOMIC_RELEASE)
+
+
+/* Atomic exchange (without compare). */
+
+# define __arch_exchange_8_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_16_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_32_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define __arch_exchange_64_int(mem, newval, model) \
+ __atomic_exchange_n (mem, newval, model)
+
+# define atomic_exchange_acq(mem, value) \
+ __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_ACQUIRE)
+
+# define atomic_exchange_rel(mem, value) \
+ __atomic_val_bysize (__arch_exchange, int, mem, value, __ATOMIC_RELEASE)
+
+
+/* Atomically add value and return the previous (unincremented) value. */
+
+# define __arch_exchange_and_add_8_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_16_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_32_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define __arch_exchange_and_add_64_int(mem, value, model) \
+ __atomic_fetch_add (mem, value, model)
+
+# define atomic_exchange_and_add_acq(mem, value) \
+ __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+ __ATOMIC_ACQUIRE)
+
+# define atomic_exchange_and_add_rel(mem, value) \
+ __atomic_val_bysize (__arch_exchange_and_add, int, mem, value, \
+ __ATOMIC_RELEASE)
+
+/* Barrier macro. */
+#define atomic_full_barrier() __sync_synchronize()
+
+#endif
diff --git a/libc/sysdeps/linux/riscv64/bits/fcntl.h b/libc/sysdeps/linux/riscv64/bits/fcntl.h
index a08bbf5b5..a9d7c84e0 100644
--- a/libc/sysdeps/linux/riscv64/bits/fcntl.h
+++ b/libc/sysdeps/linux/riscv64/bits/fcntl.h
@@ -40,6 +40,7 @@
# define O_DIRECT 00040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -88,11 +89,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/riscv64/bits/shm.h b/libc/sysdeps/linux/riscv64/bits/shm.h
index dbe4851f9..8a11c7050 100644
--- a/libc/sysdeps/linux/riscv64/bits/shm.h
+++ b/libc/sysdeps/linux/riscv64/bits/shm.h
@@ -38,16 +38,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -69,10 +69,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/riscv64/bits/uClibc_arch_features.h b/libc/sysdeps/linux/riscv64/bits/uClibc_arch_features.h
index b754f3227..63b17770d 100644
--- a/libc/sysdeps/linux/riscv64/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/riscv64/bits/uClibc_arch_features.h
@@ -5,12 +5,15 @@
#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
#define _BITS_UCLIBC_ARCH_FEATURES_H
-#undef __UCLIBC_ABORT_INSTRUCTION__
+#define __UCLIBC_ABORT_INSTRUCTION__ "unimp"
/* can your target use syscall6() for mmap ? */
-#undef __UCLIBC_MMAP_HAS_6_ARGS__
+#define __UCLIBC_MMAP_HAS_6_ARGS__
-#define __UCLIBC_SYSCALL_ALIGN_64BIT__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
+#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
/* does your target have a broken create_module() ? */
#define __UCLIBC_BROKEN_CREATE_MODULE__
diff --git a/libc/sysdeps/linux/riscv64/bits/uClibc_page.h b/libc/sysdeps/linux/riscv64/bits/uClibc_page.h
new file mode 100644
index 000000000..7282638ba
--- /dev/null
+++ b/libc/sysdeps/linux/riscv64/bits/uClibc_page.h
@@ -0,0 +1,34 @@
+/* Copyright (C) 2004 Erik Andersen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * The GNU C Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; see the file COPYING.LIB. If
+ * not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Supply an architecture specific value for PAGE_SIZE and friends. */
+
+#ifndef _UCLIBC_PAGE_H
+#define _UCLIBC_PAGE_H
+
+/* PAGE_SHIFT determines the page size -- in this case 4096 */
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+
+/* Some architectures always use 12 as page shift for mmap2() eventhough the
+ * real PAGE_SHIFT != 12. Other architectures use the same value as
+ * PAGE_SHIFT...
+ */
+#define MMAP2_PAGE_SHIFT PAGE_SHIFT
+
+#endif /* _UCLIBC_PAGE_H */
diff --git a/libc/sysdeps/linux/riscv64/bits/wordsize.h b/libc/sysdeps/linux/riscv64/bits/wordsize.h
index 67a16ba62..1fc649aad 100644
--- a/libc/sysdeps/linux/riscv64/bits/wordsize.h
+++ b/libc/sysdeps/linux/riscv64/bits/wordsize.h
@@ -25,5 +25,6 @@
#if __riscv_xlen == 64
# define __WORDSIZE_TIME64_COMPAT32 1
#else
-# error "rv32i-based targets are not supported"
+# define __WORDSIZE_TIME64_COMPAT32 1
+// # warning "rv32i-based targets are experimental"
#endif
diff --git a/libc/sysdeps/linux/riscv64/cache.c b/libc/sysdeps/linux/riscv64/cache.c
new file mode 100644
index 000000000..aa99a2a0d
--- /dev/null
+++ b/libc/sysdeps/linux/riscv64/cache.c
@@ -0,0 +1,55 @@
+/* RISC-V instruction cache flushing VDSO calls
+ Copyright (C) 2017-2020 Free Software Foundation, Inc.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <atomic.h>
+#include <sys/syscall.h>
+
+#ifndef __NR_riscv_flush_icache
+#define __NR_riscv_flush_icache 259
+#endif
+
+typedef int (*func_type) (void *, void *, unsigned long int);
+
+static int
+__riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags)
+{
+ return INLINE_SYSCALL (riscv_flush_icache, 3, start, end, flags);
+}
+
+static func_type
+__lookup_riscv_flush_icache (void)
+{
+ /* always call the system call directly.*/
+ return &__riscv_flush_icache_syscall;
+}
+
+int
+__riscv_flush_icache (void *start, void *end, unsigned long int flags)
+{
+ static volatile func_type cached_func;
+
+ func_type func = atomic_load_relaxed (&cached_func);
+
+ if (!func)
+ {
+ func = __lookup_riscv_flush_icache ();
+ atomic_store_relaxed (&cached_func, func);
+ }
+
+ return func (start, end, flags);
+}
diff --git a/libc/sysdeps/linux/riscv64/clone.S b/libc/sysdeps/linux/riscv64/clone.S
index f7684c88d..315de2ac8 100644
--- a/libc/sysdeps/linux/riscv64/clone.S
+++ b/libc/sysdeps/linux/riscv64/clone.S
@@ -29,6 +29,9 @@
.text
LEAF (clone)
+ /* Align stack to a 128-bit boundary as per RISC-V ABI. */
+ andi a1,a1,ALMASK
+
/* Sanity check arguments. */
beqz a0,L (invalid) /* No NULL function pointers. */
beqz a1,L (invalid) /* No NULL stack pointers. */
@@ -57,7 +60,7 @@ L (invalid):
li a0, -EINVAL
/* Something bad happened -- no child created. */
L (error):
- j __syscall_error
+ tail __syscall_error
END (clone)
/* Load up the arguments to the function. Put this block of code in
@@ -66,6 +69,9 @@ L (error):
ENTRY (__thread_start)
L (thread_start):
+ .cfi_label .Ldummy
+ cfi_undefined (ra)
+
/* Restore the arg for user's function. */
REG_L a1,0(sp) /* Function pointer. */
REG_L a0,SZREG(sp) /* Argument pointer. */
diff --git a/libc/sysdeps/linux/riscv64/crt1.S b/libc/sysdeps/linux/riscv64/crt1.S
index 1e8403d26..5e33046d4 100644
--- a/libc/sysdeps/linux/riscv64/crt1.S
+++ b/libc/sysdeps/linux/riscv64/crt1.S
@@ -52,9 +52,6 @@ _start:
la a0, main
REG_L a1, 0(sp) /* argc. */
addi a2, sp, SZREG /* argv. */
- /*
- * No support fo app_init/app_fini as we don't support shared libraries.
- */
mv a3, zero
mv a4, zero
andi sp, sp, ALMASK /* Align stack. */
diff --git a/libc/sysdeps/linux/riscv64/jmpbuf-unwind.h b/libc/sysdeps/linux/riscv64/jmpbuf-unwind.h
index 2e5f37f10..fb5d65ddd 100644
--- a/libc/sysdeps/linux/riscv64/jmpbuf-unwind.h
+++ b/libc/sysdeps/linux/riscv64/jmpbuf-unwind.h
@@ -23,8 +23,8 @@
/* Test if longjmp to JMPBUF would unwind the frame
containing a local variable at ADDRESS. */
-#define _JMPBUF_UNWINDS(jmpbuf, address, demangle) \
- ((void *) (address) < (void *) demangle ((jmpbuf)[0].__sp))
+#define _JMPBUF_UNWINDS(jmpbuf, address) \
+ ((void *) (address) < (void *) ((jmpbuf)[0].__sp))
#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
_JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
@@ -33,9 +33,6 @@ static inline uintptr_t __attribute__ ((unused))
_jmpbuf_sp (__jmp_buf regs)
{
uintptr_t sp = regs[0].__sp;
-#ifdef PTR_DEMANGLE
- PTR_DEMANGLE (sp);
-#endif
return sp;
}
diff --git a/libc/sysdeps/linux/riscv64/setjmp.S b/libc/sysdeps/linux/riscv64/setjmp.S
index 4cdb8e9c3..100a0bd78 100644
--- a/libc/sysdeps/linux/riscv64/setjmp.S
+++ b/libc/sysdeps/linux/riscv64/setjmp.S
@@ -20,7 +20,7 @@
ENTRY (_setjmp)
li a1, 0
- j __sigsetjmp
+ j HIDDEN_JUMPTARGET (__sigsetjmp)
END (_setjmp)
ENTRY (setjmp)
li a1, 1
diff --git a/libc/sysdeps/linux/riscv64/sys/asm.h b/libc/sysdeps/linux/riscv64/sys/asm.h
index ddb84b683..3c94c9a70 100644
--- a/libc/sysdeps/linux/riscv64/sys/asm.h
+++ b/libc/sysdeps/linux/riscv64/sys/asm.h
@@ -26,7 +26,11 @@
# define REG_S sd
# define REG_L ld
#elif __riscv_xlen == 32
-# error "rv32i-based targets are not supported"
+# define PTRLOG 2
+# define SZREG 4
+# define REG_S sw
+# define REG_L lw
+// # warning "rv32i-based targets are experimental"
#else
# error __riscv_xlen must equal 32 or 64
#endif
diff --git a/libc/sysdeps/linux/riscv64/sys/ucontext.h b/libc/sysdeps/linux/riscv64/sys/ucontext.h
index 2a80a853c..2893ff359 100644
--- a/libc/sysdeps/linux/riscv64/sys/ucontext.h
+++ b/libc/sysdeps/linux/riscv64/sys/ucontext.h
@@ -21,6 +21,8 @@
#define _SYS_UCONTEXT_H 1
#include <features.h>
+#include <signal.h>
+#include <bits/sigcontext.h>
typedef unsigned long int __riscv_mc_gp_state[32];
diff --git a/libc/sysdeps/linux/riscv64/sysdep.h b/libc/sysdeps/linux/riscv64/sysdep.h
index b12329332..3fa04bb57 100644
--- a/libc/sysdeps/linux/riscv64/sysdep.h
+++ b/libc/sysdeps/linux/riscv64/sysdep.h
@@ -20,6 +20,7 @@
#define _LINUX_RISCV_SYSDEP_H 1
#include <common/sysdep.h>
+#include <sys/syscall.h>
#ifdef __ASSEMBLER__
diff --git a/libc/sysdeps/linux/sh/bits/fcntl.h b/libc/sysdeps/linux/sh/bits/fcntl.h
index 58fd316eb..0d687f04f 100644
--- a/libc/sysdeps/linux/sh/bits/fcntl.h
+++ b/libc/sysdeps/linux/sh/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/sh/bits/kernel_stat.h b/libc/sysdeps/linux/sh/bits/kernel_stat.h
index 5b51b3cd3..c32b700ae 100644
--- a/libc/sysdeps/linux/sh/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/sh/bits/kernel_stat.h
@@ -22,8 +22,8 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
struct kernel_stat64 {
diff --git a/libc/sysdeps/linux/sh/bits/kernel_types.h b/libc/sysdeps/linux/sh/bits/kernel_types.h
index ac97261e6..90b2e66b6 100644
--- a/libc/sysdeps/linux/sh/bits/kernel_types.h
+++ b/libc/sysdeps/linux/sh/bits/kernel_types.h
@@ -21,6 +21,7 @@ typedef unsigned int __kernel_size_t;
typedef int __kernel_ssize_t;
typedef int __kernel_ptrdiff_t;
typedef long __kernel_time_t;
+typedef long long __kernel_time64_t;
typedef long __kernel_suseconds_t;
typedef long __kernel_clock_t;
typedef int __kernel_daddr_t;
@@ -33,6 +34,7 @@ typedef unsigned short __kernel_old_uid_t;
typedef unsigned short __kernel_old_gid_t;
typedef __kernel_dev_t __kernel_old_dev_t;
typedef long __kernel_long_t;
+typedef __kernel_long_t __kernel_old_time_t;
typedef unsigned long __kernel_ulong_t;
typedef long long __kernel_loff_t;
diff --git a/libc/sysdeps/linux/sh/bits/shm.h b/libc/sysdeps/linux/sh/bits/shm.h
index 646e5badc..f5e8f6fd5 100644
--- a/libc/sysdeps/linux/sh/bits/shm.h
+++ b/libc/sysdeps/linux/sh/bits/shm.h
@@ -56,16 +56,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -87,10 +87,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/sparc/Makefile.arch b/libc/sysdeps/linux/sparc/Makefile.arch
index d34624f36..c9529b344 100644
--- a/libc/sysdeps/linux/sparc/Makefile.arch
+++ b/libc/sysdeps/linux/sparc/Makefile.arch
@@ -6,7 +6,7 @@
#
CSRC-y := brk.c __syscall_error.c sigaction.c
-SSRC-y := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S \
+SSRC-y := __longjmp.S setjmp.S sigreturn_stub.S bsd-setjmp.S bsd-_setjmp.S \
syscall.S urem.S udiv.S umul.S sdiv.S rem.S pipe.S fork.S vfork.S clone.S
CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c
diff --git a/libc/sysdeps/linux/sparc/__syscall_error.c b/libc/sysdeps/linux/sparc/__syscall_error.c
index 5e109a83b..af26cf6ab 100644
--- a/libc/sysdeps/linux/sparc/__syscall_error.c
+++ b/libc/sysdeps/linux/sparc/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(err_no);
return -1;
diff --git a/libc/sysdeps/linux/sparc/bits/fcntl.h b/libc/sysdeps/linux/sparc/bits/fcntl.h
index 9ccc5946d..935495937 100644
--- a/libc/sysdeps/linux/sparc/bits/fcntl.h
+++ b/libc/sysdeps/linux/sparc/bits/fcntl.h
@@ -51,6 +51,7 @@
# define O_DIRECT 0x100000 /* direct disk access hint */
# define O_NOATIME 0x200000 /* Do not set atime. */
# define O_PATH 0x1000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 0x2010000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -102,11 +103,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
#define F_GETLK64 12 /* Get record locking info. */
#define F_SETLK64 13 /* Set record locking info (non-blocking). */
@@ -163,7 +166,7 @@ struct flock
__off64_t l_len; /* Size of the locked area; zero means until EOF. */
#endif
__pid_t l_pid; /* Process holding the lock. */
- short int __unused;
+ short int __uclibc_unused;
};
#ifdef __USE_LARGEFILE64
@@ -174,7 +177,7 @@ struct flock64
__off64_t l_start; /* Offset where the lock begins. */
__off64_t l_len; /* Size of the locked area; zero means until EOF. */
__pid_t l_pid; /* Process holding the lock. */
- short int __unused;
+ short int __uclibc_unused;
};
#endif
diff --git a/libc/sysdeps/linux/sparc/bits/ipc.h b/libc/sysdeps/linux/sparc/bits/ipc.h
index 017d0e1bc..193097ff8 100644
--- a/libc/sysdeps/linux/sparc/bits/ipc.h
+++ b/libc/sysdeps/linux/sparc/bits/ipc.h
@@ -49,6 +49,6 @@ struct ipc_perm
unsigned short int mode; /* Read/write permission. */
unsigned short int __pad2;
unsigned short int __seq; /* Sequence number. */
- unsigned long long int __unused1;
- unsigned long long int __unused2;
+ unsigned long long int __uclibc_unused1;
+ unsigned long long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/sparc/bits/msq.h b/libc/sysdeps/linux/sparc/bits/msq.h
index b8bcf31bf..2558a7bcb 100644
--- a/libc/sysdeps/linux/sparc/bits/msq.h
+++ b/libc/sysdeps/linux/sparc/bits/msq.h
@@ -47,8 +47,8 @@ struct msqid_ds
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/sparc/bits/resource.h b/libc/sysdeps/linux/sparc/bits/resource.h
index 1005aeced..48e1049f4 100644
--- a/libc/sysdeps/linux/sparc/bits/resource.h
+++ b/libc/sysdeps/linux/sparc/bits/resource.h
@@ -98,7 +98,13 @@ enum __rlimit_resource
__RLIMIT_RTPRIO = 14,
#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
- __RLIMIT_NLIMITS = 15,
+ /* Maximum CPU time in µs that a process scheduled under a real-time
+ scheduling policy may consume without making a blocking system
+ call before being forcibly descheduled. */
+ __RLIMIT_RTTIME = 15,
+#define RLIMIT_RTTIME __RLIMIT_RTTIME
+
+ __RLIMIT_NLIMITS = 16,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
@@ -108,11 +114,11 @@ enum __rlimit_resource
#ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((long int)(~0UL >> 1))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
#endif
/* We can represent all limits. */
@@ -158,6 +164,15 @@ enum __rusage_who
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+
+#ifdef __USE_GNU
+ ,
+ /* The calling thread. */
+ RUSAGE_THREAD = 1
+# define RUSAGE_THREAD RUSAGE_THREAD
+ /* Name for the same functionality on Solaris. */
+# define RUSAGE_LWP RUSAGE_THREAD
+#endif
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/sparc/bits/sem.h b/libc/sysdeps/linux/sparc/bits/sem.h
index 3faaadd96..23fd7c2eb 100644
--- a/libc/sysdeps/linux/sparc/bits/sem.h
+++ b/libc/sysdeps/linux/sparc/bits/sem.h
@@ -38,12 +38,26 @@ struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
unsigned int __pad1;
- __time_t sem_otime; /* last semop() time */
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_otime_internal_1; /* last semop() time */
+ unsigned long int __sem_otime_internal_2;
+#else
+ __time_t sem_otime; /* last semop() time */
+#endif
unsigned int __pad2;
- __time_t sem_ctime; /* last time changed by semctl() */
+#if defined(__UCLIBC_USE_TIME64__)
+ unsigned long int __sem_ctime_internal_1; /* last time changed by semctl() */
+ unsigned long int __sem_ctime_internal_2;
+#else
+ __time_t sem_ctime; /* last time changed by semctl() */
+#endif
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused1;
- unsigned long int __unused2;
+#if defined(__UCLIBC_USE_TIME64__)
+ __time_t sem_otime;
+ __time_t sem_ctime;
+#endif
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/sparc/bits/shm.h b/libc/sysdeps/linux/sparc/bits/shm.h
index 7ef10fc76..3f519ce8e 100644
--- a/libc/sysdeps/linux/sparc/bits/shm.h
+++ b/libc/sysdeps/linux/sparc/bits/shm.h
@@ -58,8 +58,8 @@ struct shmid_ds
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
@@ -81,10 +81,10 @@ struct shminfo
unsigned long shmmni;
unsigned long shmseg;
unsigned long shmall;
- unsigned long __unused1;
- unsigned long __unused2;
- unsigned long __unused3;
- unsigned long __unused4;
+ unsigned long __uclibc_unused1;
+ unsigned long __uclibc_unused2;
+ unsigned long __uclibc_unused3;
+ unsigned long __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/sparc/bits/stat.h b/libc/sysdeps/linux/sparc/bits/stat.h
index 7ec7d9b23..b88885fe2 100644
--- a/libc/sysdeps/linux/sparc/bits/stat.h
+++ b/libc/sysdeps/linux/sparc/bits/stat.h
@@ -74,8 +74,8 @@ struct stat
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_LARGEFILE64
@@ -114,8 +114,8 @@ struct stat64
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#endif
diff --git a/libc/sysdeps/linux/sparc/bits/typesizes.h b/libc/sysdeps/linux/sparc/bits/typesizes.h
index 37b7656aa..c7b7f5576 100644
--- a/libc/sysdeps/linux/sparc/bits/typesizes.h
+++ b/libc/sysdeps/linux/sparc/bits/typesizes.h
@@ -46,9 +46,21 @@
#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
#define __ID_T_TYPE __U32_TYPE
#define __CLOCK_T_TYPE __SLONGWORD_TYPE
+
+#ifdef __UCLIBC_USE_TIME64__
+#define __TIME_T_TYPE __S64_TYPE
+#else
#define __TIME_T_TYPE __SLONGWORD_TYPE
+#endif
+
#define __USECONDS_T_TYPE __U32_TYPE
+
+#ifdef __UCLIBC_USE_TIME64__
+#define __SUSECONDS_T_TYPE __S64_TYPE
+#else
#define __SUSECONDS_T_TYPE __S32_TYPE
+#endif
+
#define __DADDR_T_TYPE __S32_TYPE
#define __SWBLK_T_TYPE __SLONGWORD_TYPE
#define __KEY_T_TYPE __S32_TYPE
diff --git a/libc/sysdeps/linux/sparc/sigaction.c b/libc/sysdeps/linux/sparc/sigaction.c
index 7895e3acd..447943e3a 100644
--- a/libc/sysdeps/linux/sparc/sigaction.c
+++ b/libc/sysdeps/linux/sparc/sigaction.c
@@ -30,8 +30,8 @@
_syscall5(int, rt_sigaction, int, a, int, b, int, c, int, d, int, e)
-static void __rt_sigreturn_stub(void);
-static void __sigreturn_stub(void);
+void __rt_sigreturn_stub(void);
+void __sigreturn_stub(void);
int __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
{
@@ -75,24 +75,3 @@ libc_hidden_weak(sigaction)
# endif
#endif
-
-static void
-__rt_sigreturn_stub(void)
-{
- __asm__(
- "mov %0, %%g1\n\t"
- "ta 0x10\n\t"
- : /* no outputs */
- : "i" (__NR_rt_sigreturn)
- );
-}
-static void
-__sigreturn_stub(void)
-{
- __asm__(
- "mov %0, %%g1\n\t"
- "ta 0x10\n\t"
- : /* no outputs */
- : "i" (__NR_sigreturn)
- );
-}
diff --git a/libc/sysdeps/linux/sparc/sigreturn_stub.S b/libc/sysdeps/linux/sparc/sigreturn_stub.S
new file mode 100644
index 000000000..33f51409b
--- /dev/null
+++ b/libc/sysdeps/linux/sparc/sigreturn_stub.S
@@ -0,0 +1,14 @@
+#include <sysdep.h>
+
+ nop
+ nop
+
+ENTRY_NOCFI (__rt_sigreturn_stub)
+ mov __NR_rt_sigreturn, %g1
+ ta 0x10
+END_NOCFI (__rt_sigreturn_stub)
+
+ENTRY_NOCFI (__sigreturn_stub)
+ mov __NR_sigreturn, %g1
+ ta 0x10
+END_NOCFI (__sigreturn_stub)
diff --git a/libc/sysdeps/linux/sparc/sysdep.h b/libc/sysdeps/linux/sparc/sysdep.h
index c3897ec08..761d21454 100644
--- a/libc/sysdeps/linux/sparc/sysdep.h
+++ b/libc/sysdeps/linux/sparc/sysdep.h
@@ -17,6 +17,15 @@
C_LABEL(name) \
cfi_startproc;
+#define ENTRY_NOCFI(name) \
+ .align 4; \
+ .global C_SYMBOL_NAME(name); \
+ .type name, @function; \
+C_LABEL(name)
+
+#define END_NOCFI(name) \
+ .size name, . - name
+
#define END(name) \
cfi_endproc; \
.size name, . - name
diff --git a/libc/sysdeps/linux/sparc64/Makefile.arch b/libc/sysdeps/linux/sparc64/Makefile.arch
index 37b539b3b..cc4000b78 100644
--- a/libc/sysdeps/linux/sparc64/Makefile.arch
+++ b/libc/sysdeps/linux/sparc64/Makefile.arch
@@ -5,7 +5,7 @@
CSRC-y := __syscall_error.c sigaction.c
SSRC-y := __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S brk.S fork.S \
- syscall.S pipe.S vfork.S clone.S
+ syscall.S pipe.S vfork.S clone.S sigreturn_stub.S
CSRC-y += $(addprefix soft-fp/, \
qp_add.c qp_cmp.c qp_cmpe.c qp_div.c qp_dtoq.c qp_feq.c qp_fge.c \
diff --git a/libc/sysdeps/linux/sparc64/__longjmp.S b/libc/sysdeps/linux/sparc64/__longjmp.S
index 79cefcc9d..49cef2351 100644
--- a/libc/sysdeps/linux/sparc64/__longjmp.S
+++ b/libc/sysdeps/linux/sparc64/__longjmp.S
@@ -16,12 +16,7 @@
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
-
-/* Offsets into the jmp_buf structure. */
-
-#define O_mask_was_saved 512
-#define O_gregs 32
-#define O_g1 (O_gregs + 4*8)
+#include <jmpbuf-offsets.h>
ENTRY(__longjmp)
diff --git a/libc/sysdeps/linux/sparc64/__syscall_error.c b/libc/sysdeps/linux/sparc64/__syscall_error.c
index 5e109a83b..af26cf6ab 100644
--- a/libc/sysdeps/linux/sparc64/__syscall_error.c
+++ b/libc/sysdeps/linux/sparc64/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(err_no);
return -1;
diff --git a/libc/sysdeps/linux/sparc64/bits/fcntl.h b/libc/sysdeps/linux/sparc64/bits/fcntl.h
index dad3470b8..395c95baf 100644
--- a/libc/sysdeps/linux/sparc64/bits/fcntl.h
+++ b/libc/sysdeps/linux/sparc64/bits/fcntl.h
@@ -47,6 +47,7 @@
# define O_NOATIME 0x200000 /* Do not set atime. */
# define O_CLOEXEC 0x400000 /* Set close_on_exit. */
# define O_PATH 0x1000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 0x2010000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -98,11 +99,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
#define F_GETLK64 7 /* Get record locking info. */
#define F_SETLK64 8 /* Set record locking info (non-blocking). */
@@ -159,7 +162,7 @@ struct flock
__off64_t l_len; /* Size of the locked area; zero means until EOF. */
#endif
__pid_t l_pid; /* Process holding the lock. */
- short int __unused;
+ short int __uclibc_unused;
};
#ifdef __USE_LARGEFILE64
@@ -170,7 +173,7 @@ struct flock64
__off64_t l_start; /* Offset where the lock begins. */
__off64_t l_len; /* Size of the locked area; zero means until EOF. */
__pid_t l_pid; /* Process holding the lock. */
- short int __unused;
+ short int __uclibc_unused;
};
#endif
diff --git a/libc/sysdeps/linux/sparc64/bits/ipc.h b/libc/sysdeps/linux/sparc64/bits/ipc.h
index 7fedafa61..56247ab4e 100644
--- a/libc/sysdeps/linux/sparc64/bits/ipc.h
+++ b/libc/sysdeps/linux/sparc64/bits/ipc.h
@@ -48,6 +48,6 @@ struct ipc_perm
__mode_t mode; /* Read/write permission. */
unsigned short int __pad1;
unsigned short int __seq; /* Sequence number. */
- unsigned long long int __unused1;
- unsigned long long int __unused2;
+ unsigned long long int __uclibc_unused1;
+ unsigned long long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/sparc64/bits/msq.h b/libc/sysdeps/linux/sparc64/bits/msq.h
index f514e442c..f31caf2f7 100644
--- a/libc/sysdeps/linux/sparc64/bits/msq.h
+++ b/libc/sysdeps/linux/sparc64/bits/msq.h
@@ -44,8 +44,8 @@ struct msqid_ds
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/sparc64/bits/resource.h b/libc/sysdeps/linux/sparc64/bits/resource.h
index 366e5c2d9..84c768785 100644
--- a/libc/sysdeps/linux/sparc64/bits/resource.h
+++ b/libc/sysdeps/linux/sparc64/bits/resource.h
@@ -98,7 +98,13 @@ enum __rlimit_resource
__RLIMIT_RTPRIO = 14,
#define RLIMIT_RTPRIO __RLIMIT_RTPRIO
- __RLIMIT_NLIMITS = 15,
+ /* Maximum CPU time in µs that a process scheduled under a real-time
+ scheduling policy may consume without making a blocking system
+ call before being forcibly descheduled. */
+ __RLIMIT_RTTIME = 15,
+#define RLIMIT_RTTIME __RLIMIT_RTTIME
+
+ __RLIMIT_NLIMITS = 16,
__RLIM_NLIMITS = __RLIMIT_NLIMITS
#define RLIMIT_NLIMITS __RLIMIT_NLIMITS
#define RLIM_NLIMITS __RLIM_NLIMITS
@@ -122,11 +128,11 @@ enum __rlimit_resource
#ifndef __USE_FILE_OFFSET64
# define RLIM_INFINITY ((long int)(~0UL >> 1))
#else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
#endif
#ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
#endif
#endif
@@ -174,6 +180,15 @@ enum __rusage_who
/* All of its terminated child processes. */
RUSAGE_CHILDREN = -1
#define RUSAGE_CHILDREN RUSAGE_CHILDREN
+
+#ifdef __USE_GNU
+ ,
+ /* The calling thread. */
+ RUSAGE_THREAD = 1
+# define RUSAGE_THREAD RUSAGE_THREAD
+ /* Name for the same functionality on Solaris. */
+# define RUSAGE_LWP RUSAGE_THREAD
+#endif
};
#define __need_timeval
diff --git a/libc/sysdeps/linux/sparc64/bits/sem.h b/libc/sysdeps/linux/sparc64/bits/sem.h
index acc21742d..9e88db2e2 100644
--- a/libc/sysdeps/linux/sparc64/bits/sem.h
+++ b/libc/sysdeps/linux/sparc64/bits/sem.h
@@ -40,8 +40,8 @@ struct semid_ds
__time_t sem_otime; /* last semop() time */
__time_t sem_ctime; /* last time changed by semctl() */
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/sparc64/bits/setjmp.h b/libc/sysdeps/linux/sparc64/bits/setjmp.h
index 7cca64f82..5c03710d6 100644
--- a/libc/sysdeps/linux/sparc64/bits/setjmp.h
+++ b/libc/sysdeps/linux/sparc64/bits/setjmp.h
@@ -40,6 +40,7 @@ typedef struct __sparc64_jmp_buf
unsigned long __dregs[32];
long double __qregs[16];
} __mcfpu_fpregs;
+ unsigned long __mcfpu_fsr;
unsigned long __mcfpu_fprs;
unsigned long __mcfpu_gsr;
void *__mcfpu_fq;
diff --git a/libc/sysdeps/linux/sparc64/bits/shm.h b/libc/sysdeps/linux/sparc64/bits/shm.h
index a5d8c3464..b76c4c32b 100644
--- a/libc/sysdeps/linux/sparc64/bits/shm.h
+++ b/libc/sysdeps/linux/sparc64/bits/shm.h
@@ -55,8 +55,8 @@ struct shmid_ds
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
#ifdef __USE_MISC
@@ -78,10 +78,10 @@ struct shminfo
unsigned long shmmni;
unsigned long shmseg;
unsigned long shmall;
- unsigned long __unused1;
- unsigned long __unused2;
- unsigned long __unused3;
- unsigned long __unused4;
+ unsigned long __uclibc_unused1;
+ unsigned long __uclibc_unused2;
+ unsigned long __uclibc_unused3;
+ unsigned long __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/sparc64/bits/stat.h b/libc/sysdeps/linux/sparc64/bits/stat.h
index cae973b4e..8516b159c 100644
--- a/libc/sysdeps/linux/sparc64/bits/stat.h
+++ b/libc/sysdeps/linux/sparc64/bits/stat.h
@@ -79,8 +79,8 @@ struct stat
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_LARGEFILE64
@@ -122,8 +122,8 @@ struct stat64
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#endif
diff --git a/libc/sysdeps/linux/sparc64/bits/uClibc_arch_features.h b/libc/sysdeps/linux/sparc64/bits/uClibc_arch_features.h
index 283a250bb..76f5084ff 100644
--- a/libc/sysdeps/linux/sparc64/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/sparc64/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/sparc64/jmpbuf-offsets.h b/libc/sysdeps/linux/sparc64/jmpbuf-offsets.h
index e273f5561..f433365a2 100644
--- a/libc/sysdeps/linux/sparc64/jmpbuf-offsets.h
+++ b/libc/sysdeps/linux/sparc64/jmpbuf-offsets.h
@@ -15,6 +15,6 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#define O_mask_was_saved 512
+#define O_mask_was_saved 496
#define O_gregs 32
#define O_g1 (O_gregs + 4*8)
diff --git a/libc/sysdeps/linux/sparc64/setjmp.S b/libc/sysdeps/linux/sparc64/setjmp.S
index b30c7d744..a329bb7c1 100644
--- a/libc/sysdeps/linux/sparc64/setjmp.S
+++ b/libc/sysdeps/linux/sparc64/setjmp.S
@@ -19,12 +19,7 @@
Linux/Sparc64. */
#include <sysdep.h>
-
-/* Offsets into the jmp_buf structure. */
-
-#define O_mask_was_saved 512
-#define O_gregs 32
-#define O_g1 (O_gregs + 4*8)
+#include <jmpbuf-offsets.h>
/* int _setjmp(jmp_buf) */
diff --git a/libc/sysdeps/linux/sparc64/sigaction.c b/libc/sysdeps/linux/sparc64/sigaction.c
index d8aaad0fb..b28fa659a 100644
--- a/libc/sysdeps/linux/sparc64/sigaction.c
+++ b/libc/sysdeps/linux/sparc64/sigaction.c
@@ -26,7 +26,7 @@
/* SPARC 64bit userland requires a kernel that has rt signals anyway. */
-static void __rt_sigreturn_stub (void);
+void __rt_sigreturn_stub (void);
int __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
{
@@ -67,11 +67,3 @@ libc_hidden_weak(sigaction)
# endif
#endif
-static void
-__rt_sigreturn_stub (void)
-{
- __asm__ ("mov %0, %%g1\n\t"
- "ta 0x6d\n\t"
- : /* no outputs */
- : "i" (__NR_rt_sigreturn));
-}
diff --git a/libc/sysdeps/linux/sparc64/sigreturn_stub.S b/libc/sysdeps/linux/sparc64/sigreturn_stub.S
new file mode 100644
index 000000000..a5c9bb47f
--- /dev/null
+++ b/libc/sysdeps/linux/sparc64/sigreturn_stub.S
@@ -0,0 +1,10 @@
+#include <sysdep.h>
+
+ nop
+ nop
+
+ENTRY_NOCFI (__rt_sigreturn_stub)
+ mov __NR_rt_sigreturn, %g1
+ ta 0x6d
+END_NOCFI (__rt_sigreturn_stub)
+
diff --git a/libc/sysdeps/linux/sparc64/sysdep.h b/libc/sysdeps/linux/sparc64/sysdep.h
index 31008c34b..5a4c36348 100644
--- a/libc/sysdeps/linux/sparc64/sysdep.h
+++ b/libc/sysdeps/linux/sparc64/sysdep.h
@@ -83,6 +83,15 @@ C_LABEL(name) \
cfi_endproc; \
.size name, . - name
+#define ENTRY_NOCFI(name) \
+ .align 4; \
+ .global C_SYMBOL_NAME(name); \
+ .type name, @function; \
+C_LABEL(name)
+
+#define END_NOCFI(name) \
+ .size name, . - name
+
#define LOC(name) .L##name
#undef PSEUDO
diff --git a/libc/sysdeps/linux/tile/__syscall_error.c b/libc/sysdeps/linux/tile/__syscall_error.c
index a91fdff3a..31cab3799 100644
--- a/libc/sysdeps/linux/tile/__syscall_error.c
+++ b/libc/sysdeps/linux/tile/__syscall_error.c
@@ -6,7 +6,7 @@
#include <errno.h>
#include <features.h>
-int __syscall_error(int err_no)
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/tile/bits/fcntl.h b/libc/sysdeps/linux/tile/bits/fcntl.h
index 3cb4d2caf..818da5c4a 100644
--- a/libc/sysdeps/linux/tile/bits/fcntl.h
+++ b/libc/sysdeps/linux/tile/bits/fcntl.h
@@ -40,6 +40,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
#ifdef __USE_LARGEFILE64
@@ -88,11 +89,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FL. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/tile/bits/shm.h b/libc/sysdeps/linux/tile/bits/shm.h
index dbe4851f9..8a11c7050 100644
--- a/libc/sysdeps/linux/tile/bits/shm.h
+++ b/libc/sysdeps/linux/tile/bits/shm.h
@@ -38,16 +38,16 @@ struct shmid_ds
struct ipc_perm shm_perm; /* operation permission struct */
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -69,10 +69,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/tile/bits/uClibc_arch_features.h b/libc/sysdeps/linux/tile/bits/uClibc_arch_features.h
index 1472b18ab..ec7e4111f 100644
--- a/libc/sysdeps/linux/tile/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/tile/bits/uClibc_arch_features.h
@@ -10,6 +10,9 @@
/* can your target use syscall6() for mmap ? */
#undef __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
#define __UCLIBC_SYSCALL_ALIGN_64BIT__
/* does your target have a broken create_module() ? */
diff --git a/libc/sysdeps/linux/x86_64/__syscall_error.c b/libc/sysdeps/linux/x86_64/__syscall_error.c
index 448f50983..7f0f388c4 100644
--- a/libc/sysdeps/linux/x86_64/__syscall_error.c
+++ b/libc/sysdeps/linux/x86_64/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(void) attribute_hidden;
-int __syscall_error(void)
+long __syscall_error(void) attribute_hidden;
+long __syscall_error(void)
{
register int err_no __asm__ ("%rcx");
__asm__ ("mov %rax, %rcx\n\t"
diff --git a/libc/sysdeps/linux/x86_64/bits/fcntl.h b/libc/sysdeps/linux/x86_64/bits/fcntl.h
index bb75b76e0..3547a2046 100644
--- a/libc/sysdeps/linux/x86_64/bits/fcntl.h
+++ b/libc/sysdeps/linux/x86_64/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -115,11 +116,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/x86_64/bits/fenv.h b/libc/sysdeps/linux/x86_64/bits/fenv.h
index 8e38c16ec..f16b64ad3 100644
--- a/libc/sysdeps/linux/x86_64/bits/fenv.h
+++ b/libc/sysdeps/linux/x86_64/bits/fenv.h
@@ -69,18 +69,18 @@ typedef unsigned short int fexcept_t;
typedef struct
{
unsigned short int __control_word;
- unsigned short int __unused1;
+ unsigned short int __uclibc_unused1;
unsigned short int __status_word;
- unsigned short int __unused2;
+ unsigned short int __uclibc_unused2;
unsigned short int __tags;
- unsigned short int __unused3;
+ unsigned short int __uclibc_unused3;
unsigned int __eip;
unsigned short int __cs_selector;
unsigned int __opcode:11;
- unsigned int __unused4:5;
+ unsigned int __uclibc_unused4:5;
unsigned int __data_offset;
unsigned short int __data_selector;
- unsigned short int __unused5;
+ unsigned short int __uclibc_unused5;
#if __WORDSIZE == 64
unsigned int __mxcsr;
#endif
diff --git a/libc/sysdeps/linux/x86_64/bits/kernel_stat.h b/libc/sysdeps/linux/x86_64/bits/kernel_stat.h
index e194a7f76..d01d81d69 100644
--- a/libc/sysdeps/linux/x86_64/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/x86_64/bits/kernel_stat.h
@@ -21,7 +21,7 @@ struct kernel_stat {
struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
- long __unused[3];
+ long __uclibc_unused[3];
};
/* x86-64 stat64 is same as stat */
diff --git a/libc/sysdeps/linux/x86_64/bits/msq.h b/libc/sysdeps/linux/x86_64/bits/msq.h
index 838910713..3141266bc 100644
--- a/libc/sysdeps/linux/x86_64/bits/msq.h
+++ b/libc/sysdeps/linux/x86_64/bits/msq.h
@@ -39,23 +39,23 @@ struct msqid_ds
struct ipc_perm msg_perm; /* structure describing operation permission */
__time_t msg_stime; /* time of last msgsnd command */
#if __WORDSIZE == 32
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
#endif
__time_t msg_rtime; /* time of last msgrcv command */
#if __WORDSIZE == 32
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
#endif
__time_t msg_ctime; /* time of last change */
#if __WORDSIZE == 32
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
#endif
unsigned long int __msg_cbytes; /* current number of bytes on queue */
msgqnum_t msg_qnum; /* number of messages currently on queue */
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/x86_64/bits/sem.h b/libc/sysdeps/linux/x86_64/bits/sem.h
index 8c09031c7..9dfab87cb 100644
--- a/libc/sysdeps/linux/x86_64/bits/sem.h
+++ b/libc/sysdeps/linux/x86_64/bits/sem.h
@@ -39,12 +39,12 @@ struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
__time_t sem_otime; /* last semop() time */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t sem_ctime; /* last time changed by semctl() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
unsigned long int sem_nsems; /* number of semaphores in set */
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
/* The user should define a union like the following to use it for arguments
diff --git a/libc/sysdeps/linux/x86_64/bits/shm.h b/libc/sysdeps/linux/x86_64/bits/shm.h
index 3a25de562..316895853 100644
--- a/libc/sysdeps/linux/x86_64/bits/shm.h
+++ b/libc/sysdeps/linux/x86_64/bits/shm.h
@@ -52,21 +52,21 @@ struct shmid_ds
size_t shm_segsz; /* size of segment in bytes */
__time_t shm_atime; /* time of last shmat() */
#if __WORDSIZE == 32
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
#endif
__time_t shm_dtime; /* time of last shmdt() */
#if __WORDSIZE == 32
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
#endif
__time_t shm_ctime; /* time of last change by shmctl() */
#if __WORDSIZE == 32
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
#endif
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -88,10 +88,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/x86_64/bits/stat.h b/libc/sysdeps/linux/x86_64/bits/stat.h
index e25f01521..a7412c8f9 100644
--- a/libc/sysdeps/linux/x86_64/bits/stat.h
+++ b/libc/sysdeps/linux/x86_64/bits/stat.h
@@ -99,11 +99,11 @@ struct stat
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
#if __WORDSIZE == 64
- long int __unused[3];
+ long int __uclibc_unused[3];
#else
# ifndef __USE_FILE_OFFSET64
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
# else
__ino64_t st_ino; /* File serial number. */
# endif
@@ -160,7 +160,7 @@ struct stat64
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
#if __WORDSIZE == 64
- long int __unused[3];
+ long int __uclibc_unused[3];
#else
__ino64_t st_ino; /* File serial number. */
#endif
diff --git a/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h b/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h
index 43801699e..400cfe3b9 100644
--- a/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h
+++ b/libc/sysdeps/linux/x86_64/bits/uClibc_arch_features.h
@@ -11,6 +11,9 @@
/* can your target use syscall6() for mmap ? */
#define __UCLIBC_MMAP_HAS_6_ARGS__
+/* does your target use statx */
+#undef __UCLIBC_HAVE_STATX__
+
/* does your target align 64bit values in register pairs ? (32bit arches only) */
#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
diff --git a/libc/sysdeps/linux/x86_64/crt1.S b/libc/sysdeps/linux/x86_64/crt1.S
index 87777dd5d..701cbf2f6 100644
--- a/libc/sysdeps/linux/x86_64/crt1.S
+++ b/libc/sysdeps/linux/x86_64/crt1.S
@@ -80,6 +80,20 @@ _start:
the outermost frame obviously. */
xorl %ebp, %ebp
+#ifdef L_rcrt1
+ pushq %rdi /* save rdi (but should be 0...) */
+ pushq %rdx /* store rdx (rtld_fini) */
+ xorq %rcx, %rcx /* ensure rcx is 0 */
+ addq _start@GOTPCREL(%rip), %rcx /* get offset of _start from beginning of file */
+ movq _start@GOTPCREL(%rip), %rax /* get run time address of _start */
+ subq %rcx, %rax /* calculate run time load offset */
+ movq %rax, %rdi /* load offset -> param 1 */
+ call reloc_static_pie /* relocate dynamic addrs */
+ xorq %rax, %rax /* cleanup */
+ popq %rdx
+ popq %rdi
+#endif
+
/* Extract the arguments as encoded on the stack and set up
the arguments for __libc_start_main (int (*main) (int, char **, char **),
int argc, char *argv,
@@ -107,7 +121,7 @@ _start:
which grow downwards). */
pushq %rsp
-#if defined(L_Scrt1)
+#if defined(L_Scrt1) || defined(L_rcrt1)
/* Give address for main() */
movq main@GOTPCREL(%rip), %rdi
diff --git a/libc/sysdeps/linux/xtensa/Makefile.arch b/libc/sysdeps/linux/xtensa/Makefile.arch
index 23cd08ee5..f3a93caaa 100644
--- a/libc/sysdeps/linux/xtensa/Makefile.arch
+++ b/libc/sysdeps/linux/xtensa/Makefile.arch
@@ -10,3 +10,6 @@ SSRC-y := bsd-_setjmp.S bsd-setjmp.S setjmp.S clone.S \
sigrestorer.S syscall.S mmap.S windowspill.S __longjmp.S vfork.S
CSRC-$(if $(UCLIBC_HAS_THREADS_NATIVE),,y) += fork.c
+
+CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c
+SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += setcontext.S getcontext.S swapcontext.S __start_context.S
diff --git a/libc/sysdeps/linux/xtensa/__start_context.S b/libc/sysdeps/linux/xtensa/__start_context.S
new file mode 100644
index 000000000..a30d7b618
--- /dev/null
+++ b/libc/sysdeps/linux/xtensa/__start_context.S
@@ -0,0 +1,100 @@
+/* Copyright (C) 2018 - 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+
+#if defined(__XTENSA_CALL0_ABI__)
+/*
+ * There's no entry instruction, makecontext sets up ucontext_t as if
+ * getcontext was called above and is about to return here.
+ * Registers on entry to this function:
+ * a12: func to call
+ * a13: ucp->uc_link, next context to activate if func returns
+ * a14: func argc
+ */
+ .literal_position
+
+ENTRY_PREFIX(__start_context)
+
+ beqz a14, 1f
+
+ /* load func arguments 0..1 from stack and free that space */
+ l32i a2, a1, 8
+ l32i a3, a1, 12
+ addi a1, a1, 16
+ bltui a14, 3, 1f
+
+ /* load func arguments 2..5 from stack and free that space */
+ l32i a4, a1, 0
+ l32i a5, a1, 4
+ l32i a6, a1, 8
+ l32i a7, a1, 12
+ addi a1, a1, 16
+ /* func arguments 6..argc - 1 are now at the top of the stack */
+1:
+ callx0 a12
+ beqz a13, 1f
+ mov a2, a13
+ movi a4, JUMPTARGET (setcontext)
+ callx0 a4
+1:
+ movi a4, JUMPTARGET (_exit)
+ movi a2, 0
+ callx0 a4
+ ill
+END(__start_context)
+#elif defined(__XTENSA_WINDOWED_ABI__)
+/*
+ * There's no entry instruction, makecontext sets up ucontext_t as if
+ * getcontext was called above and is about to return here.
+ * Registers on entry to this function:
+ * a2: func to call
+ * a3: ucp->uc_link, next context to activate if func returns
+ * a4: func argc
+ * a5..a7: func arguments 0..2
+ */
+ .literal_position
+
+ENTRY_PREFIX(__start_context)
+
+ mov a10, a5
+ mov a11, a6
+ mov a12, a7
+ bltui a4, 4, 1f
+
+ /* load func arguments 3..5 from stack and free that space */
+ l32i a13, a1, 4
+ l32i a14, a1, 8
+ l32i a15, a1, 12
+ addi a5, a1, 16
+ movsp a1, a5
+ /* func arguments 6..argc - 1 are now at the top of the stack */
+1:
+ callx8 a2
+ beqz a3, 1f
+ mov a6, a3
+ movi a4, JUMPTARGET (setcontext)
+ callx4 a4
+1:
+ movi a4, JUMPTARGET (_exit)
+ movi a6, 0
+ callx4 a4
+ ill
+END(__start_context)
+#else
+#error Unsupported Xtensa ABI
+#endif
diff --git a/libc/sysdeps/linux/xtensa/__syscall_error.c b/libc/sysdeps/linux/xtensa/__syscall_error.c
index 2b642e816..c682aae49 100644
--- a/libc/sysdeps/linux/xtensa/__syscall_error.c
+++ b/libc/sysdeps/linux/xtensa/__syscall_error.c
@@ -10,8 +10,8 @@
/* This routine is jumped to by all the syscall handlers, to stash
* an error number into errno. */
-int __syscall_error(int err_no) attribute_hidden;
-int __syscall_error(int err_no)
+long __syscall_error(int err_no) attribute_hidden;
+long __syscall_error(int err_no)
{
__set_errno(-err_no);
return -1;
diff --git a/libc/sysdeps/linux/xtensa/bits/atomic.h b/libc/sysdeps/linux/xtensa/bits/atomic.h
index b2be547f0..18b809998 100644
--- a/libc/sysdeps/linux/xtensa/bits/atomic.h
+++ b/libc/sysdeps/linux/xtensa/bits/atomic.h
@@ -18,6 +18,7 @@
#ifndef _BITS_ATOMIC_H
#define _BITS_ATOMIC_H 1
+#include <bits/xtensa-config.h>
#include <inttypes.h>
typedef int32_t atomic32_t;
@@ -50,22 +51,144 @@ typedef uintmax_t uatomic_max_t;
#define __arch_compare_and_exchange_bool_16_rel(mem, newval, oldval) \
(abort (), 0)
+#if XCHAL_HAVE_EXCLUSIVE
+
+/* Atomically store NEWVAL in *MEM if *MEM is equal to OLDVAL.
+ Return the old *MEM value. */
+
+#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
+ ({__typeof__(*(mem)) __tmp, __value; \
+ __asm__ __volatile__( \
+ " memw \n" \
+ "1: l32ex %0, %2 \n" \
+ " bne %0, %4, 2f \n" \
+ " mov %1, %3 \n" \
+ " s32ex %1, %2 \n" \
+ " getex %1 \n" \
+ " beqz %1, 1b \n" \
+ " memw \n" \
+ "2: \n" \
+ : "=&a" (__value), "=&a" (__tmp) \
+ : "a" (mem), "a" (newval), "a" (oldval) \
+ : "memory" ); \
+ __value; \
+ })
+
+/* Atomically store NEWVAL in *MEM if *MEM is equal to OLDVAL.
+ Return zero if *MEM was changed or non-zero if no exchange happened. */
+
+#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
+ ({__typeof__(*(mem)) __tmp, __value; \
+ __asm__ __volatile__( \
+ " memw \n" \
+ "1: l32ex %0, %2 \n" \
+ " sub %0, %4, %0 \n" \
+ " bnez %0, 2f \n" \
+ " mov %1, %3 \n" \
+ " s32ex %1, %2 \n" \
+ " getex %1 \n" \
+ " beqz %1, 1b \n" \
+ " movi %0, 0 \n" \
+ " memw \n" \
+ "2: \n" \
+ : "=&a" (__value), "=&a" (__tmp) \
+ : "a" (mem), "a" (newval), "a" (oldval) \
+ : "memory" ); \
+ __value != 0; \
+ })
+
+/* Store NEWVALUE in *MEM and return the old value. */
+
+#define __arch_exchange_32_acq(mem, newval) \
+ ({__typeof__(*(mem)) __tmp, __value; \
+ __asm__ __volatile__( \
+ " memw \n" \
+ "1: l32ex %0, %2 \n" \
+ " mov %1, %3 \n" \
+ " s32ex %1, %2 \n" \
+ " getex %1 \n" \
+ " beqz %1, 1b \n" \
+ " memw \n" \
+ : "=&a" (__value), "=&a" (__tmp) \
+ : "a" (mem), "a" (newval) \
+ : "memory" ); \
+ __value; \
+ })
+
+/* Add VALUE to *MEM and return the old value of *MEM. */
+
+#define __arch_atomic_exchange_and_add_32(mem, value) \
+ ({__typeof__(*(mem)) __tmp, __value; \
+ __asm__ __volatile__( \
+ " memw \n" \
+ "1: l32ex %0, %2 \n" \
+ " add %1, %0, %3 \n" \
+ " s32ex %1, %2 \n" \
+ " getex %1 \n" \
+ " beqz %1, 1b \n" \
+ " memw \n" \
+ : "=&a" (__value), "=&a" (__tmp) \
+ : "a" (mem), "a" (value) \
+ : "memory" ); \
+ __value; \
+ })
+
+/* Subtract VALUE from *MEM and return the old value of *MEM. */
+
+#define __arch_atomic_exchange_and_sub_32(mem, value) \
+ ({__typeof__(*(mem)) __tmp, __value; \
+ __asm__ __volatile__( \
+ " memw \n" \
+ "1: l32ex %0, %2 \n" \
+ " sub %1, %0, %3 \n" \
+ " s32ex %1, %2 \n" \
+ " getex %1 \n" \
+ " beqz %1, 1b \n" \
+ " memw \n" \
+ : "=&a" (__value), "=&a" (__tmp) \
+ : "a" (mem), "a" (value) \
+ : "memory" ); \
+ __tmp; \
+ })
+
+/* Decrement *MEM if it is > 0, and return the old value. */
+
+#define __arch_atomic_decrement_if_positive_32(mem) \
+ ({__typeof__(*(mem)) __tmp, __value; \
+ __asm__ __volatile__( \
+ " memw \n" \
+ "1: l32ex %0, %2 \n" \
+ " blti %0, 1, 2f \n" \
+ " addi %1, %0, -1 \n" \
+ " s32ex %1, %2 \n" \
+ " getex %1 \n" \
+ " beqz %1, 1b \n" \
+ " memw \n" \
+ "2: \n" \
+ : "=&a" (__value), "=&a" (__tmp) \
+ : "a" (mem) \
+ : "memory" ); \
+ __value; \
+ })
+
+#elif XCHAL_HAVE_S32C1I
+
/* Atomically store NEWVAL in *MEM if *MEM is equal to OLDVAL.
Return the old *MEM value. */
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
({__typeof__(*(mem)) __tmp, __value; \
__asm__ __volatile__( \
- "1: l32i %1, %2, 0 \n" \
+ "1: l32i %1, %2 \n" \
" bne %1, %4, 2f \n" \
" wsr %1, SCOMPARE1 \n" \
" mov %0, %1 \n" \
" mov %1, %3 \n" \
- " s32c1i %1, %2, 0 \n" \
+ " s32c1i %1, %2 \n" \
" bne %0, %1, 1b \n" \
"2: \n" \
- : "=&a" (__value), "=&a" (__tmp) \
- : "a" (mem), "a" (newval), "a" (oldval) \
+ : "=&a" (__value), "=&a" (__tmp), "+m" (*(mem)) \
+ : "a" (newval), "a" (oldval) \
: "memory" ); \
__tmp; \
})
@@ -76,17 +199,17 @@ typedef uintmax_t uatomic_max_t;
#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \
({__typeof__(*(mem)) __tmp, __value; \
__asm__ __volatile__( \
- "1: l32i %0, %2, 0 \n" \
+ "1: l32i %0, %2 \n" \
" sub %1, %4, %0 \n" \
" bnez %1, 2f \n" \
" wsr %0, SCOMPARE1 \n" \
" mov %1, %3 \n" \
- " s32c1i %1, %2, 0 \n" \
+ " s32c1i %1, %2 \n" \
" bne %0, %1, 1b \n" \
" movi %1, 0 \n" \
"2: \n" \
- : "=&a" (__value), "=&a" (__tmp) \
- : "a" (mem), "a" (newval), "a" (oldval) \
+ : "=&a" (__value), "=&a" (__tmp), "+m" (*(mem)) \
+ : "a" (newval), "a" (oldval) \
: "memory" ); \
__tmp != 0; \
})
@@ -96,13 +219,13 @@ typedef uintmax_t uatomic_max_t;
#define __arch_exchange_32_acq(mem, newval) \
({__typeof__(*(mem)) __tmp, __value; \
__asm__ __volatile__( \
- "1: l32i %0, %2, 0 \n" \
+ "1: l32i %0, %2 \n" \
" wsr %0, SCOMPARE1 \n" \
" mov %1, %3 \n" \
- " s32c1i %1, %2, 0 \n" \
+ " s32c1i %1, %2 \n" \
" bne %0, %1, 1b \n" \
- : "=&a" (__value), "=&a" (__tmp) \
- : "a" (mem), "a" (newval) \
+ : "=&a" (__value), "=&a" (__tmp), "+m" (*(mem)) \
+ : "a" (newval) \
: "memory" ); \
__tmp; \
})
@@ -112,13 +235,13 @@ typedef uintmax_t uatomic_max_t;
#define __arch_atomic_exchange_and_add_32(mem, value) \
({__typeof__(*(mem)) __tmp, __value; \
__asm__ __volatile__( \
- "1: l32i %0, %2, 0 \n" \
+ "1: l32i %0, %2 \n" \
" wsr %0, SCOMPARE1 \n" \
" add %1, %0, %3 \n" \
- " s32c1i %1, %2, 0 \n" \
+ " s32c1i %1, %2 \n" \
" bne %0, %1, 1b \n" \
- : "=&a" (__value), "=&a" (__tmp) \
- : "a" (mem), "a" (value) \
+ : "=&a" (__value), "=&a" (__tmp), "+m" (*(mem)) \
+ : "a" (value) \
: "memory" ); \
__tmp; \
})
@@ -128,13 +251,13 @@ typedef uintmax_t uatomic_max_t;
#define __arch_atomic_exchange_and_sub_32(mem, value) \
({__typeof__(*(mem)) __tmp, __value; \
__asm__ __volatile__( \
- "1: l32i %0, %2, 0 \n" \
+ "1: l32i %0, %2 \n" \
" wsr %0, SCOMPARE1 \n" \
" sub %1, %0, %3 \n" \
- " s32c1i %1, %2, 0 \n" \
+ " s32c1i %1, %2 \n" \
" bne %0, %1, 1b \n" \
- : "=&a" (__value), "=&a" (__tmp) \
- : "a" (mem), "a" (value) \
+ : "=&a" (__value), "=&a" (__tmp), "+m" (*(mem)) \
+ : "a" (value) \
: "memory" ); \
__tmp; \
})
@@ -144,19 +267,23 @@ typedef uintmax_t uatomic_max_t;
#define __arch_atomic_decrement_if_positive_32(mem) \
({__typeof__(*(mem)) __tmp, __value; \
__asm__ __volatile__( \
- "1: l32i %0, %2, 0 \n" \
+ "1: l32i %0, %2 \n" \
" blti %0, 1, 2f \n" \
" wsr %0, SCOMPARE1 \n" \
" addi %1, %0, -1 \n" \
- " s32c1i %1, %2, 0 \n" \
+ " s32c1i %1, %2 \n" \
" bne %0, %1, 1b \n" \
"2: \n" \
- : "=&a" (__value), "=&a" (__tmp) \
- : "a" (mem) \
- : "memory" ); \
+ : "=&a" (__value), "=&a" (__tmp), "+m" (*(mem)) \
+ :: "memory" ); \
__value; \
})
+#else
+
+#error No hardware atomic operations
+
+#endif
/* These are the preferred public interfaces: */
diff --git a/libc/sysdeps/linux/xtensa/bits/fcntl.h b/libc/sysdeps/linux/xtensa/bits/fcntl.h
index f8ae40ca7..5af9d2124 100644
--- a/libc/sysdeps/linux/xtensa/bits/fcntl.h
+++ b/libc/sysdeps/linux/xtensa/bits/fcntl.h
@@ -54,6 +54,7 @@
# define O_DIRECT 040000 /* Direct disk access. */
# define O_NOATIME 01000000 /* Do not set atime. */
# define O_PATH 010000000 /* Resolve pathname but do not open file. */
+# define O_TMPFILE 020200000 /* Atomically create nameless file. */
#endif
/* For now Linux has synchronisity options for data and read operations.
@@ -101,11 +102,13 @@
# define F_SETLEASE 1024 /* Set a lease. */
# define F_GETLEASE 1025 /* Enquire what lease is active. */
# define F_NOTIFY 1026 /* Request notfications on a directory. */
-# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
- close-on-exit set on new fd. */
# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
#endif
+#if defined __USE_XOPEN2K8 || defined __USE_GNU
+# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
+ close-on-exit set on new fd. */
+#endif
/* For F_[GET|SET]FD. */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
diff --git a/libc/sysdeps/linux/xtensa/bits/ipc.h b/libc/sysdeps/linux/xtensa/bits/ipc.h
index 2ad5fc0a2..f4222de8c 100644
--- a/libc/sysdeps/linux/xtensa/bits/ipc.h
+++ b/libc/sysdeps/linux/xtensa/bits/ipc.h
@@ -48,6 +48,6 @@ struct ipc_perm
__gid_t cgid; /* Creator's group ID. */
unsigned int mode; /* Read/write permission. */
unsigned int __seq; /* Sequence number. */
- unsigned long int __unused1;
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
};
diff --git a/libc/sysdeps/linux/xtensa/bits/kernel_stat.h b/libc/sysdeps/linux/xtensa/bits/kernel_stat.h
index 5e4f5c4e5..d884344d3 100644
--- a/libc/sysdeps/linux/xtensa/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/xtensa/bits/kernel_stat.h
@@ -33,13 +33,13 @@ struct kernel_stat64 {
unsigned long long st_rdev; /* Device number, if device. */
long long st_size; /* Size of file, in bytes. */
unsigned long st_blksize; /* Optimal block size for I/O. */
- unsigned long __unused2;
+ unsigned long __uclibc_unused2;
unsigned long long st_blocks; /* Number 512-byte blocks allocated. */
struct timespec st_atim; /* Time of last access. */
struct timespec st_mtim; /* Time of last modification. */
struct timespec st_ctim; /* Time of last status change. */
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
#endif /* _BITS_STAT_STRUCT_H */
diff --git a/libc/sysdeps/linux/xtensa/bits/msq.h b/libc/sysdeps/linux/xtensa/bits/msq.h
index e4f3fa317..0f65b4274 100644
--- a/libc/sysdeps/linux/xtensa/bits/msq.h
+++ b/libc/sysdeps/linux/xtensa/bits/msq.h
@@ -38,19 +38,19 @@ struct msqid_ds
{
struct ipc_perm msg_perm; /* structure describing operation permission */
#if defined (__XTENSA_EB__)
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t msg_stime; /* time of last msgsnd command */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t msg_rtime; /* time of last msgrcv command */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__time_t msg_ctime; /* time of last change */
#elif defined (__XTENSA_EL__)
__time_t msg_stime; /* time of last msgsnd command */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t msg_rtime; /* time of last msgrcv command */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t msg_ctime; /* time of last change */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
#else
# error endian order not defined
#endif
@@ -59,8 +59,8 @@ struct msqid_ds
msglen_t msg_qbytes; /* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
diff --git a/libc/sysdeps/linux/xtensa/bits/shm.h b/libc/sysdeps/linux/xtensa/bits/shm.h
index d288a1cca..d1e13cb49 100644
--- a/libc/sysdeps/linux/xtensa/bits/shm.h
+++ b/libc/sysdeps/linux/xtensa/bits/shm.h
@@ -52,17 +52,17 @@ struct shmid_ds
size_t shm_segsz; /* size of segment in bytes */
#if defined (__XTENSA_EL__)
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_ctime; /* time of last change by shmctl() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
#elif defined (__XTENSA_EB__)
- unsigned long int __unused1;
+ unsigned long int __uclibc_unused1;
__time_t shm_atime; /* time of last shmat() */
- unsigned long int __unused2;
+ unsigned long int __uclibc_unused2;
__time_t shm_dtime; /* time of last shmdt() */
- unsigned long int __unused3;
+ unsigned long int __uclibc_unused3;
__time_t shm_ctime; /* time of last change by shmctl() */
#else
# error endian order not defined
@@ -70,8 +70,8 @@ struct shmid_ds
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
shmatt_t shm_nattch; /* number of current attaches */
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_MISC
@@ -93,10 +93,10 @@ struct shminfo
unsigned long int shmmni;
unsigned long int shmseg;
unsigned long int shmall;
- unsigned long int __unused1;
- unsigned long int __unused2;
- unsigned long int __unused3;
- unsigned long int __unused4;
+ unsigned long int __uclibc_unused1;
+ unsigned long int __uclibc_unused2;
+ unsigned long int __uclibc_unused3;
+ unsigned long int __uclibc_unused4;
};
struct shm_info
diff --git a/libc/sysdeps/linux/xtensa/bits/stat.h b/libc/sysdeps/linux/xtensa/bits/stat.h
index c61b188b7..045a017fd 100644
--- a/libc/sysdeps/linux/xtensa/bits/stat.h
+++ b/libc/sysdeps/linux/xtensa/bits/stat.h
@@ -75,8 +75,8 @@ struct stat
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long int __unused4;
- unsigned long int __unused5;
+ unsigned long int __uclibc_unused4;
+ unsigned long int __uclibc_unused5;
};
#ifdef __USE_LARGEFILE64
@@ -112,8 +112,8 @@ struct stat64
__time_t st_ctime; /* Time of last status change. */
unsigned long int st_ctimensec; /* Nsecs of last status change. */
#endif
- unsigned long __unused4;
- unsigned long __unused5;
+ unsigned long __uclibc_unused4;
+ unsigned long __uclibc_unused5;
};
#endif
diff --git a/libc/sysdeps/linux/xtensa/bits/xtensa-config.h b/libc/sysdeps/linux/xtensa/bits/xtensa-config.h
index 2e60af936..b99928b1e 100644
--- a/libc/sysdeps/linux/xtensa/bits/xtensa-config.h
+++ b/libc/sysdeps/linux/xtensa/bits/xtensa-config.h
@@ -43,4 +43,10 @@
#undef XCHAL_NUM_AREGS
#define XCHAL_NUM_AREGS 64
+#undef XCHAL_HAVE_S32C1I
+#define XCHAL_HAVE_S32C1I 1
+
+#undef XCHAL_HAVE_EXCLUSIVE
+#define XCHAL_HAVE_EXCLUSIVE 0
+
#endif /* !XTENSA_CONFIG_H */
diff --git a/libc/sysdeps/linux/xtensa/crt1.S b/libc/sysdeps/linux/xtensa/crt1.S
index efbe264c0..3fa14ae58 100644
--- a/libc/sysdeps/linux/xtensa/crt1.S
+++ b/libc/sysdeps/linux/xtensa/crt1.S
@@ -76,9 +76,26 @@
.global _start
.type _start, @function
_start:
+#ifdef L_rcrt1
+ .begin no-transform
+ call0 1f
+.Lret_addr:
+ .end no-transform
+ .align 4
+1:
+#endif
#if defined(__XTENSA_WINDOWED_ABI__)
+#ifdef L_rcrt1
+ movi a6, .Lret_addr
+ sub a6, a0, a6
+ movi a0, 0
+ movi a4, reloc_static_pie
+ add a4, a4, a6
+ callx4 a4
+#else
/* Clear a0 to obviously mark the outermost frame. */
movi a0, 0
+#endif
/* Load up the user's main function. */
movi a6, main
@@ -106,8 +123,18 @@ _start:
movi a4, __uClibc_main
callx4 a4
#elif defined(__XTENSA_CALL0_ABI__)
+#ifdef L_rcrt1
+ mov a12, a2
+ movi a2, .Lret_addr
+ sub a2, a0, a2
+ movi a0, reloc_static_pie
+ add a0, a0, a2
+ callx0 a0
+ mov a7, a12
+#else
/* Setup the shared library termination function. */
mov a7, a2
+#endif
/* Load up the user's main function. */
movi a2, main
diff --git a/libc/sysdeps/linux/xtensa/getcontext.S b/libc/sysdeps/linux/xtensa/getcontext.S
new file mode 100644
index 000000000..7588a91b3
--- /dev/null
+++ b/libc/sysdeps/linux/xtensa/getcontext.S
@@ -0,0 +1,99 @@
+/* Copyright (C) 2018 - 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include "ucontext_i.h"
+
+#if defined(__XTENSA_CALL0_ABI__)
+ENTRY(__getcontext)
+ s32i a0, a2, MCONTEXT_SC_PC
+ s32i a1, a2, MCONTEXT_SC_A_0 + 4
+
+ /* save callee-saved registers in the context */
+ s32i a12, a2, MCONTEXT_SC_A_0 + 48
+ s32i a13, a2, MCONTEXT_SC_A_0 + 52
+ s32i a14, a2, MCONTEXT_SC_A_0 + 56
+ s32i a15, a2, MCONTEXT_SC_A_0 + 60
+
+ movi a3, 0
+ addi a4, a2, UCONTEXT_SIGMASK
+ movi a2, SIG_BLOCK
+ movi a5, JUMPTARGET (sigprocmask)
+ jx a5
+END(__getcontext)
+#elif defined(__XTENSA_WINDOWED_ABI__)
+ENTRY(__getcontext)
+ movi a4, __window_spill
+ callx4 a4
+ s32i a0, a2, MCONTEXT_SC_PC
+
+ /* copy registers a0..a3 from spill area */
+ addi a3, a1, -16
+ l32i a4, a3, 0
+ l32i a5, a3, 4
+ l32i a6, a3, 8
+ l32i a7, a3, 12
+ s32i a4, a2, MCONTEXT_SC_A_0 + 0
+ s32i a5, a2, MCONTEXT_SC_A_0 + 4
+ s32i a6, a2, MCONTEXT_SC_A_0 + 8
+ s32i a7, a2, MCONTEXT_SC_A_0 + 12
+
+ /* if it was call4 then register saving is done */
+ extui a4, a0, 30, 2
+ bltui a4, 2, 1f
+
+ /* otherwise load spill overflow area address into a3 */
+ addi a3, a5, -16
+ l32i a3, a3, 4
+ addi a3, a3, -32
+ beqi a4, 2, 2f
+
+ /* copy registers a8..a11 from spill overflow area */
+ addi a3, a3, -16
+ l32i a4, a3, 16
+ l32i a5, a3, 20
+ l32i a6, a3, 24
+ l32i a7, a3, 28
+ s32i a4, a2, MCONTEXT_SC_A_0 + 32
+ s32i a5, a2, MCONTEXT_SC_A_0 + 36
+ s32i a6, a2, MCONTEXT_SC_A_0 + 40
+ s32i a7, a2, MCONTEXT_SC_A_0 + 44
+
+ /* copy registers a4..a7 from spill overflow area */
+2:
+ l32i a4, a3, 0
+ l32i a5, a3, 4
+ l32i a6, a3, 8
+ l32i a7, a3, 12
+ s32i a4, a2, MCONTEXT_SC_A_0 + 16
+ s32i a5, a2, MCONTEXT_SC_A_0 + 20
+ s32i a6, a2, MCONTEXT_SC_A_0 + 24
+ s32i a7, a2, MCONTEXT_SC_A_0 + 28
+1:
+ movi a6, SIG_BLOCK
+ movi a7, 0
+ addi a8, a2, UCONTEXT_SIGMASK
+ movi a4, JUMPTARGET (sigprocmask)
+ callx4 a4
+ mov a2, a6
+ retw
+END(__getcontext)
+#else
+#error Unsupported Xtensa ABI
+#endif
+
+weak_alias (__getcontext, getcontext)
diff --git a/libc/sysdeps/linux/xtensa/makecontext.c b/libc/sysdeps/linux/xtensa/makecontext.c
new file mode 100644
index 000000000..da26a0130
--- /dev/null
+++ b/libc/sysdeps/linux/xtensa/makecontext.c
@@ -0,0 +1,179 @@
+/* Copyright (C) 2018 - 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <string.h>
+#include <ucontext.h>
+
+extern void __start_context (void);
+
+#if defined(__XTENSA_CALL0_ABI__)
+/*
+ * makecontext sets up new stack like this:
+ *
+ * +------------------ stack top (uc_stack.ss_sp + uc_stack.ss_size)
+ * | optional alignment
+ * +------------------ CFA of __start_context, initial sp points here
+ * | optional padding
+ * +------------------ Optional arguments 6..argc - 1
+ * | func arg argc - 1
+ * | func arg argc - 2
+ * | ...
+ * | func arg 6
+ * +------------------ Optional arguments 2..5
+ * | func arg 5
+ * 16 | func arg 4
+ * | func arg 3
+ * | func arg 2
+ * +------------------ Optional arguments 0..1
+ * | func arg 1
+ * 16 | func arg 0
+ * | padding
+ * | padding
+ * +------------------ CFA of pseudo getcontext
+ * |
+ * +------------------ stack bottom (uc_stack.ss_sp)
+ *
+ * When argc is 0 arguments areas are not allocated,
+ * when 1 <= argc < 3 only area for arguments 0..1 is allocated,
+ * when 3 <= argc < 7 areas for arguments 0..1 and 2..5 is allocated,
+ * when argc >= 7 all three arguments areas are allocated.
+ * Arguments 0..5 area is deallocated by the __start_context after
+ * arguments are loaded into registers.
+ * uc_mcontext registers are set as if __start_context made call0
+ * to getcontext, sp points to that pseudo getcontext CFA.
+ * setcontext/swapcontext will arrange for restoring regiters
+ * a1, a12..a15 of __start_context.
+ */
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ unsigned long sp = ((unsigned long) ucp->uc_stack.ss_sp
+ + ucp->uc_stack.ss_size) & -16;
+ int i;
+
+ if (argc > 0)
+ sp -= 4 * (argc + 2);
+ sp &= -16;
+
+ ucp->uc_mcontext.sc_pc = (unsigned long) __start_context;
+ ucp->uc_mcontext.sc_a[1] = sp;
+ ucp->uc_mcontext.sc_a[12] = (unsigned long) func;
+ ucp->uc_mcontext.sc_a[13] = (unsigned long) ucp->uc_link;
+ ucp->uc_mcontext.sc_a[14] = argc;
+
+ if (argc)
+ {
+ va_list ap;
+
+ va_start (ap, argc);
+ for (i = 0; i < argc; ++i)
+ ((int *) sp)[i + 2] = va_arg (ap, int);
+ va_end (ap);
+ }
+}
+#elif defined(__XTENSA_WINDOWED_ABI__)
+/*
+ * makecontext sets up new stack like this:
+ *
+ * +------------------ stack top (uc_stack.ss_sp + uc_stack.ss_size)
+ * | optional alignment
+ * +------------------ CFA of __start_context
+ * 16 | Outermost caller spill area
+ * +------------------
+ * 16 | __start_context overflow area
+ * +------------------ initial sp points here
+ * | optional padding
+ * +------------------ Optional arguments 6..argc - 1
+ * | func arg argc - 1
+ * | func arg argc - 2
+ * | ...
+ * | func arg 6
+ * +------------------ Optional arguments 3..5
+ * | func arg 5
+ * 16 | func arg 4
+ * | func arg 3
+ * | padding
+ * +------------------ CFA of pseudo getcontext
+ * 16 | __start_context caller spill area
+ * +------------------
+ * |
+ * +------------------ stack bottom (uc_stack.ss_sp)
+ *
+ * When argc < 4 both arguments areas are not allocated,
+ * when 4 <= argc < 7 only area for arguments 3..5 is allocated,
+ * when argc >= 7 both arguments areas are allocated.
+ * Arguments 3..5 area is deallocated by the __start_context after
+ * arguments are loaded into registers.
+ * uc_mcontext registers are set as if __start_context made call8
+ * to getcontext, sp points to that pseudo getcontext CFA, spill
+ * area under that sp has a1 pointing to the __start_context CFA
+ * at the top of the stack. setcontext/swapcontext will arrange for
+ * restoring regiters a0..a7 of __start_context.
+ */
+
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+ unsigned long sp = ((unsigned long) ucp->uc_stack.ss_sp
+ + ucp->uc_stack.ss_size - 32) & -16;
+ unsigned long spill0[4] =
+ {
+ 0, sp + 32, 0, 0,
+ };
+ int i;
+
+ memset ((void *) sp, 0, 32);
+
+ if (argc > 2)
+ sp -= 4 * (argc - 2);
+ sp &= -16;
+
+ ucp->uc_mcontext.sc_pc =
+ ((unsigned long) __start_context & 0x3fffffff) + 0x80000000;
+ ucp->uc_mcontext.sc_a[0] = 0;
+ ucp->uc_mcontext.sc_a[1] = sp;
+ ucp->uc_mcontext.sc_a[2] = (unsigned long) func;
+ ucp->uc_mcontext.sc_a[3] = (unsigned long) ucp->uc_link;
+ ucp->uc_mcontext.sc_a[4] = argc;
+
+ if (argc)
+ {
+ va_list ap;
+
+ va_start (ap, argc);
+ for (i = 0; i < argc; ++i)
+ {
+ if (i < 3)
+ ucp->uc_mcontext.sc_a[5 + i] = va_arg (ap, int);
+ else
+ ((int *) sp)[i - 2] = va_arg (ap, int);
+ }
+ va_end (ap);
+ }
+
+ sp -= 16;
+ memcpy ((void *) sp, spill0, sizeof (spill0));
+}
+#else
+#error Unsupported Xtensa ABI
+#endif
+
+weak_alias (__makecontext, makecontext)
diff --git a/libc/sysdeps/linux/xtensa/setcontext.S b/libc/sysdeps/linux/xtensa/setcontext.S
new file mode 100644
index 000000000..4df7cc049
--- /dev/null
+++ b/libc/sysdeps/linux/xtensa/setcontext.S
@@ -0,0 +1,116 @@
+/* Copyright (C) 2018 - 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include "ucontext_i.h"
+
+#if defined(__XTENSA_CALL0_ABI__)
+ENTRY(__setcontext)
+ addi sp, sp, -16
+ s32i a0, sp, 0
+ s32i a2, sp, 4
+
+ addi a3, a2, UCONTEXT_SIGMASK
+ movi a4, 0
+ movi a2, SIG_SETMASK
+ movi a5, JUMPTARGET (sigprocmask)
+ callx0 a5
+ bnez a2, .Lerror
+
+ l32i a2, sp, 4
+ l32i a0, a2, MCONTEXT_SC_PC
+ l32i a1, a2, MCONTEXT_SC_A_0 + 4
+
+ /* load callee-saved registers from the context */
+ l32i a12, a2, MCONTEXT_SC_A_0 + 48
+ l32i a13, a2, MCONTEXT_SC_A_0 + 52
+ l32i a14, a2, MCONTEXT_SC_A_0 + 56
+ l32i a15, a2, MCONTEXT_SC_A_0 + 60
+ movi a2, 0
+ ret
+.Lerror:
+ l32i a0, sp, 0
+ addi sp, sp, 16
+ ret
+END(__setcontext)
+#elif defined(__XTENSA_WINDOWED_ABI__)
+ENTRY(__setcontext)
+ movi a6, SIG_SETMASK
+ addi a7, a2, UCONTEXT_SIGMASK
+ movi a8, 0
+ movi a4, JUMPTARGET (sigprocmask)
+ callx4 a4
+ bnez a6, .Lerror
+ movi a4, __window_spill
+ callx4 a4
+
+ l32i a0, a2, MCONTEXT_SC_PC
+
+ /* copy registers a0..a3 to spill area */
+ addi a3, a1, -16
+ l32i a4, a2, MCONTEXT_SC_A_0 + 0
+ l32i a5, a2, MCONTEXT_SC_A_0 + 4
+ l32i a6, a2, MCONTEXT_SC_A_0 + 8
+ l32i a7, a2, MCONTEXT_SC_A_0 + 12
+ s32i a4, a3, 0
+ s32i a5, a3, 4
+ s32i a6, a3, 8
+ s32i a7, a3, 12
+
+ /* if it was call4 then register setup is done */
+ extui a4, a0, 30, 2
+ bltui a4, 2, 1f
+
+ /* otherwise load spill overflow area address into a3 */
+ addi a3, a5, -16
+ l32i a3, a3, 4
+ addi a3, a3, -32
+ beqi a4, 2, 2f
+
+ /* copy registers a8..a11 to spill overflow area */
+ addi a3, a3, -16
+ l32i a4, a2, MCONTEXT_SC_A_0 + 32
+ l32i a5, a2, MCONTEXT_SC_A_0 + 36
+ l32i a6, a2, MCONTEXT_SC_A_0 + 40
+ l32i a7, a2, MCONTEXT_SC_A_0 + 44
+ s32i a4, a3, 16
+ s32i a5, a3, 20
+ s32i a6, a3, 24
+ s32i a7, a3, 28
+
+ /* copy registers a4..a7 to spill overflow area */
+2:
+ l32i a4, a2, MCONTEXT_SC_A_0 + 16
+ l32i a5, a2, MCONTEXT_SC_A_0 + 20
+ l32i a6, a2, MCONTEXT_SC_A_0 + 24
+ l32i a7, a2, MCONTEXT_SC_A_0 + 28
+ s32i a4, a3, 0
+ s32i a5, a3, 4
+ s32i a6, a3, 8
+ s32i a7, a3, 12
+1:
+ movi a2, 0
+ retw
+.Lerror:
+ mov a2, a6
+ retw
+END(__setcontext)
+#else
+#error Unsupported Xtensa ABI
+#endif
+
+weak_alias (__setcontext, setcontext)
diff --git a/libc/sysdeps/linux/xtensa/swapcontext.S b/libc/sysdeps/linux/xtensa/swapcontext.S
new file mode 100644
index 000000000..a215edc6d
--- /dev/null
+++ b/libc/sysdeps/linux/xtensa/swapcontext.S
@@ -0,0 +1,173 @@
+/* Copyright (C) 2018 - 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include "ucontext_i.h"
+
+#if defined(__XTENSA_CALL0_ABI__)
+ENTRY(__swapcontext)
+ s32i a0, a2, MCONTEXT_SC_PC
+ s32i a1, a2, MCONTEXT_SC_A_0 + 4
+
+ /* save callee-saved registers in the context */
+ s32i a12, a2, MCONTEXT_SC_A_0 + 48
+ s32i a13, a2, MCONTEXT_SC_A_0 + 52
+ s32i a14, a2, MCONTEXT_SC_A_0 + 56
+ s32i a15, a2, MCONTEXT_SC_A_0 + 60
+
+ mov a12, a3
+ mov a13, a2
+
+ addi a3, a3, UCONTEXT_SIGMASK
+ addi a4, a2, UCONTEXT_SIGMASK
+ movi a2, SIG_SETMASK
+ movi a5, JUMPTARGET (sigprocmask)
+ callx0 a5
+ bnez a2, .Lerror
+
+ mov a2, a12
+ l32i a0, a2, MCONTEXT_SC_PC
+ l32i a1, a2, MCONTEXT_SC_A_0 + 4
+
+ /* load callee-saved registers from the context */
+ l32i a12, a2, MCONTEXT_SC_A_0 + 48
+ l32i a13, a2, MCONTEXT_SC_A_0 + 52
+ l32i a14, a2, MCONTEXT_SC_A_0 + 56
+ l32i a15, a2, MCONTEXT_SC_A_0 + 60
+
+ movi a2, 0
+ ret
+.Lerror:
+ l32i a0, a13, MCONTEXT_SC_PC
+ l32i a12, a13, MCONTEXT_SC_A_0 + 48
+ l32i a13, a13, MCONTEXT_SC_A_0 + 52
+ ret
+END(__swapcontext)
+#elif defined(__XTENSA_WINDOWED_ABI__)
+ENTRY(__swapcontext)
+ movi a4, __window_spill
+ callx4 a4
+ mov a9, a3
+ s32i a0, a2, MCONTEXT_SC_PC
+
+ /* copy registers a0..a3 from spill area */
+ addi a3, a1, -16
+ l32i a4, a3, 0
+ l32i a5, a3, 4
+ l32i a6, a3, 8
+ l32i a7, a3, 12
+ s32i a4, a2, MCONTEXT_SC_A_0 + 0
+ s32i a5, a2, MCONTEXT_SC_A_0 + 4
+ s32i a6, a2, MCONTEXT_SC_A_0 + 8
+ s32i a7, a2, MCONTEXT_SC_A_0 + 12
+
+ /* if it was call4 then register saving is done */
+ extui a4, a0, 30, 2
+ bltui a4, 2, 1f
+
+ /* otherwise load spill overflow area address into a3 */
+ addi a3, a5, -16
+ l32i a3, a3, 4
+ addi a3, a3, -32
+ beqi a4, 2, 2f
+
+ /* copy registers a8..a11 from spill overflow area */
+ addi a3, a3, -16
+ l32i a4, a3, 16
+ l32i a5, a3, 20
+ l32i a6, a3, 24
+ l32i a7, a3, 28
+ s32i a4, a2, MCONTEXT_SC_A_0 + 32
+ s32i a5, a2, MCONTEXT_SC_A_0 + 36
+ s32i a6, a2, MCONTEXT_SC_A_0 + 40
+ s32i a7, a2, MCONTEXT_SC_A_0 + 44
+
+ /* copy registers a4..a7 from spill overflow area */
+2:
+ l32i a4, a3, 0
+ l32i a5, a3, 4
+ l32i a6, a3, 8
+ l32i a7, a3, 12
+ s32i a4, a2, MCONTEXT_SC_A_0 + 16
+ s32i a5, a2, MCONTEXT_SC_A_0 + 20
+ s32i a6, a2, MCONTEXT_SC_A_0 + 24
+ s32i a7, a2, MCONTEXT_SC_A_0 + 28
+1:
+ movi a6, SIG_SETMASK
+ addi a7, a9, UCONTEXT_SIGMASK
+ addi a8, a2, UCONTEXT_SIGMASK
+ mov a2, a9
+ movi a4, JUMPTARGET (sigprocmask)
+ callx4 a4
+ bnez a6, .Lerror
+
+ l32i a0, a2, MCONTEXT_SC_PC
+
+ /* copy registers a0..a3 to spill area */
+ addi a3, a1, -16
+ l32i a4, a2, MCONTEXT_SC_A_0 + 0
+ l32i a5, a2, MCONTEXT_SC_A_0 + 4
+ l32i a6, a2, MCONTEXT_SC_A_0 + 8
+ l32i a7, a2, MCONTEXT_SC_A_0 + 12
+ s32i a4, a3, 0
+ s32i a5, a3, 4
+ s32i a6, a3, 8
+ s32i a7, a3, 12
+
+ /* if it was call4 then register setup is done */
+ extui a4, a0, 30, 2
+ bltui a4, 2, 1f
+
+ /* otherwise load spill overflow area address into a3 */
+ addi a3, a5, -16
+ l32i a3, a3, 4
+ addi a3, a3, -32
+ beqi a4, 2, 2f
+
+ /* copy registers a8..a11 to spill overflow area */
+ addi a3, a3, -16
+ l32i a4, a2, MCONTEXT_SC_A_0 + 32
+ l32i a5, a2, MCONTEXT_SC_A_0 + 36
+ l32i a6, a2, MCONTEXT_SC_A_0 + 40
+ l32i a7, a2, MCONTEXT_SC_A_0 + 44
+ s32i a4, a3, 16
+ s32i a5, a3, 20
+ s32i a6, a3, 24
+ s32i a7, a3, 28
+
+ /* copy registers a4..a7 to spill overflow area */
+2:
+ l32i a4, a2, MCONTEXT_SC_A_0 + 16
+ l32i a5, a2, MCONTEXT_SC_A_0 + 20
+ l32i a6, a2, MCONTEXT_SC_A_0 + 24
+ l32i a7, a2, MCONTEXT_SC_A_0 + 28
+ s32i a4, a3, 0
+ s32i a5, a3, 4
+ s32i a6, a3, 8
+ s32i a7, a3, 12
+1:
+ movi a2, 0
+ retw
+.Lerror:
+ mov a2, a6
+ retw
+END(__swapcontext)
+#else
+#error Unsupported Xtensa ABI
+#endif
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/libc/sysdeps/linux/xtensa/sysdep.h b/libc/sysdeps/linux/xtensa/sysdep.h
index 0671f0783..80b3f30fc 100644
--- a/libc/sysdeps/linux/xtensa/sysdep.h
+++ b/libc/sysdeps/linux/xtensa/sysdep.h
@@ -39,12 +39,15 @@
#endif
-#define ENTRY(name) \
+#define ENTRY_PREFIX(name) \
.globl C_SYMBOL_NAME(name); \
ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
.align ALIGNARG(2); \
LITERAL_POSITION; \
- C_LABEL(name) \
+ C_LABEL(name)
+
+#define ENTRY(name) \
+ ENTRY_PREFIX(name) \
abi_entry(sp, FRAMESIZE);
#define HIDDEN_ENTRY(name) \
diff --git a/libc/sysdeps/linux/xtensa/ucontext_i.sym b/libc/sysdeps/linux/xtensa/ucontext_i.sym
new file mode 100644
index 000000000..4770c36c9
--- /dev/null
+++ b/libc/sysdeps/linux/xtensa/ucontext_i.sym
@@ -0,0 +1,15 @@
+#include <inttypes.h>
+#include <signal.h>
+#include <stddef.h>
+#include <sys/ucontext.h>
+
+SIG_BLOCK
+SIG_SETMASK
+
+-- Offsets of the fields in the ucontext_t structure.
+#define ucontext(member) offsetof (ucontext_t, member)
+#define mcontext(member) ucontext (uc_mcontext.member)
+
+UCONTEXT_SIGMASK ucontext (uc_sigmask)
+MCONTEXT_SC_A_0 mcontext (sc_a[0])
+MCONTEXT_SC_PC mcontext (sc_pc)