Commit Graph

4208 Commits

Author SHA1 Message Date
Rich Felker
dfc81828f7 implement fstatat with SYS_statx, conditional on undersized kstat time
this commit adds a new backend for fstatat (and thereby the whole stat
family) using the SYS_statx syscall, but conditions the new code on
the kernel stat structure's time fields being smaller than time_t. in
principle that should make it all dead code at present, but mips64 has
a broken stat structure with 32-bit time fields despite having 64-bit
time_t elsewhere, so on mips64 it is a functional change that makes
post-Y2038 filesystem timestamps accessible.

whenever the 32-bit archs end up getting 64-bit time_t, regardless of
how that happens, the changes in this commit will automatically take
effect for them too.
2019-07-18 21:46:33 -04:00
Rich Felker
67bf602f14 cleanup includes now that stat, lstat no longer make direct syscalls 2019-07-18 19:47:46 -04:00
Rich Felker
eeff60608c restore property that fstat(AT_FDCWD) fails with EBADF
AT_FDCWD is not a valid file descriptor, so POSIX requires fstat to
fail with EBADF. if passed to fstatat, the call would spuriously
succeed and return results for the working directory.
2019-07-18 19:47:46 -04:00
Rich Felker
fa7d4218c7 remove mips/n32/64 stat struct hacks from syscall machinery
now that we have a kstat structure decoupled from the public struct
stat, we can just use the broken kernel structures directly and let
the code in fstatat do the translation.
2019-07-18 19:38:37 -04:00
Rich Felker
01ae3fc6d4 decouple struct stat from kernel type
presently, all archs/ABIs have struct stat matching the kernel
stat[64] type, except mips/mipsn32/mips64 which do conversion hacks in
syscall_arch.h to work around bugs in the kernel type. this patch
completely decouples them and adds a translation step to the success
path of fstatat. at present, this is just a gratuitous copying, but it
opens up multiple possibilities for future support for 64-bit time_t
on 32-bit archs and for cleaned-up/unified ABIs.

for clarity, the mips hacks are not yet removed in this commit, so the
mips kstat structs still correspond to the output of the hacks in
their syscall_arch.h files, not the raw kernel type. a subsequent
commit will fix this.
2019-07-18 19:38:12 -04:00
Rich Felker
9493892021 refactor all stat functions in terms of fstatat
equivalent logic for fstat+O_PATH fallback and direct use of
stat/lstat syscalls where appropriate is kept, now in the fstatat
function. this change both improves functionality (now, fstatat forms
equivalent to fstat/lstat/stat will work even on kernels too old to
have the at functions) and localizes direct interfacing with the
kernel stat structure to one file.
2019-07-18 19:36:23 -04:00
Rich Felker
62a73d9649 remove utterly wrong includes from mips64/n32 bits/stat.h
these were overlooked during review. bits headers are not allowed to
pull in additional headers (note: that rule is currently broken in
other places but just for endian.h). string.h has no place here
anyway, and including bits/alltypes.h without defining macros to
request types from it is a nop.
2019-07-18 19:30:14 -04:00
Rich Felker
f0eb2e77b2 use register constraint instead of memory operand for riscv64 atomics
the "A" constraint is simply for an address expression that's a single
register, but it's not yet supported by clang, and has no advantage
here over just using a register operand for the address. the latter is
actually preferable in the a_cas_p case because it avoids aliasing an
lvalue onto the memory.
2019-07-17 19:07:57 -04:00
Rich Felker
2dcbeabd91 fix riscv64 atomic asm constraints
most egregious problem was the lack of memory clobber and lack of
volatile asm; this made the atomics memory barriers but not compiler
barriers. use of "+r" rather than "=r" for a clobbered temp was also
wrong, since the initial value is indeterminate.
2019-07-17 18:53:26 -04:00
Rich Felker
8eb49e0485 fix riscv64 syscall asm constraint
having "+r"(a0) is redundant with "0"(a0) in syscalls with at least 1
arg, which is arguably a constraint violation (clang treats it as
such), and an invalid input with indeterminate value in the 0-arg
case. use the "=r"(a0) form instead.
2019-07-17 18:50:15 -04:00
Rich Felker
1a28c6eade fix broken lseek on x32 (x86_64/ILP32) with offsets larger than LONG_MAX
this is analogous to commit 918c5fa0fc
which fixed the corresponding issue for mips n32.
2019-07-16 23:07:49 -04:00
Rich Felker
918c5fa0fc fix broken lseek on mipsn32 with offsets larger than LONG_MAX
mips n32 has 32-bit long, and generally uses long syscall arguments
and return values, but provides only SYS_lseek, not SYS_llseek. we
have some framework (syscall_arg_t, added for x32) to make syscall
arguments 64-bit in such a setting, but it's not clear whether this
could match the sign-extension semantics needed for 32-bit args to all
the other syscalls, and we don't have any existing mechanism to allow
the return value of syscalls to be something other than long.

instead, just provide a custom mipsn32 version of the lseek function
doing its own syscall asm with 64-bit arguments. as a result of commit
03919b26ed, stdio will also get the new
code, fixing fseeko/ftello too.
2019-07-16 21:05:24 -04:00
Rich Felker
ddc7c4f936 clean up mips64/n32 syscall asm constraints
ever since inline syscalls were added for (o32) mips in commit
328810d325, the asm has nonsensically
loaded the syscall number, rather than taking $2 as an input
constraint to let the compiler load it. commit
cfc09b1ecf improved on this somewhat by
allowing a constant syscall number to propagate into an immediate, but
missed that the whole operation made no sense.

now, only $4, $5, $6, $8, and $9 are potential input-only registers.
$2 is always input and output, and $7 is both when it's an argument,
otherwise output-only. previously, $7 was treated as an input (with a
"1" constraint matching its output position) even when it was not an
input, which was arguably undefined behavior (asm input from
indeterminate value). this is corrected.
2019-07-16 20:49:02 -04:00
Rich Felker
db2a148d9d deduplicate mips64/n32 syscall clobbered register lists
this patch is not purely non-functional changes, since before, $8 and
$9 were wrongly in the clobberlist for syscalls with fewer than 5 or 6
arguments. of course it's impossible for syscalls to have different
clobbers depending on their number of arguments. the clobberlist for
the recently-added 5- and 6-argument forms was correct, and for the 0-
to 4-argument forms was erroneously copied from the mips o32 ABI where
the additional arguments had to be passed on the stack.

in making this change, I reviewed the kernel sources, and $8 and $9
are always saved for 64-bit kernels since they're part of the syscall
argument list for n32 and n64 ABIs.
2019-07-16 20:31:38 -04:00
Rich Felker
03919b26ed use namespace-safe __lseek for __stdio_seek instead of direct syscall
this probably saves a few bytes, avoids duplicating the clunky
lseek/_llseek syscall convention in two places, and sets the stage for
fixing broken seeks on x32 and mipsn32.
2019-07-16 18:31:33 -04:00
Rich Felker
b07d45eb01 release 1.1.23 2019-07-16 15:30:39 -04:00
Rich Felker
d6dcd4185b update year in COPYRIGHT file 2019-07-15 18:28:43 -04:00
Rich Felker
7a6c8a0df1 update authors/contributors list
these additions were made by scanning git log since the last major
update in commit 1366b3c5e6.

as before my aim was adding everyone with either substantial code
contributions or a pattern of ongoing simple patch submission; any
omissions are unintentional.
2019-07-15 18:26:30 -04:00
Rich Felker
980f80f792 fix build failure on arm building C code in thumb1 mode
a fully thumb1 build is not supported because some asm files are
incompatible with thumb1, but apparently it works to compile the C
code as thumb1

commit 06fbefd100 caused this regression
but introducing use of the clz instruction, which is not supported in
arm mode prior to v5, and not supported in thumb prior to thumb2
(v6t2). commit 1b9406b03c fixed the
issue only for arm mode pre-v5 but left thumb1 broken.
2019-07-15 15:33:12 -04:00
James Y Knight
7829f42a2c fix sigaltstack to ignore ss_size with SS_DISABLE, per POSIX 2019-07-13 11:22:37 -04:00
Samuel Holland
c225e6c1a4 use the correct attributes for ___errno_location
In the public header, __errno_location is declared with the "const"
attribute, conditional on __GNUC__. Ensure that its internal alias has
the same attributes.

Maintainer's note: This change also fixes a regression in quality of
code generation -- multiple references to errno in a single function
started generating multiple calls again -- introduced by commit
e13063aad7.
2019-07-10 17:10:59 -04:00
Samuel Holland
05eb8ea060 fix conflicting mips and powerpc definitions for TIOCSER_TEMT macro
Commit 3517d74a5e changed the token in
sys/ioctl.h from 0x01 to 1, so bits/termios.h no longer matches. Revert
the bits/termios.h change to keep the headers in sync.

This reverts commit 9eda4dc69c.
2019-07-10 17:09:49 -04:00
Samuel Holland
e0eee3ceef fix restrict violations in internal use of several functions
The old/new parameters to pthread_sigmask, sigprocmask, and setitimer
are marked restrict, so passing the same address to both is
prohibited. Modify callers of these functions to use a separate object
for each argument.
2019-07-10 17:06:00 -04:00
Rich Felker
a730639273 mention mips64 n32 ABI support in INSTALL doc 2019-07-09 18:40:50 -04:00
Rich Felker
0f72228208 document riscv64 support in INSTALL document 2019-07-09 18:40:07 -04:00
Rich Felker
759900403d prevent dup2 action for posix_spawn internal pipe fd
as reported by Tavian Barnes, a dup2 file action for the internal pipe
fd used by posix_spawn could cause it to remain open after execve and
allow the child to write an artificial error into it, confusing the
parent. POSIX allows internal use of file descriptors by the
implementation, with undefined behavior for poking at them, so this is
not a conformance problem, but it seems preferable to diagnose and
prevent the error when we can do so easily.

catch attempts to apply a dup2 action to the internal pipe fd and
emulate EBADF for it instead.
2019-07-08 23:47:15 -04:00
Rich Felker
9b83182069 fix inadvertent use of uninitialized variable in dladdr
commit c8b49b2fbc introduced code that
checked bestsym to determine whether a matching symbol was found, but
bestsym is uninitialized if not. instead use best, consistent with use
in the rest of the function.

simplified from bug report and patch by Cheng Liu.
2019-07-06 17:47:43 -04:00
Rich Felker
524e76f17b remove spurious MAP_32BIT definition from riscv64 arch
this was apparently copied from x86_64; it's not part of the kernel
API for riscv64. this change eliminates the need for a
riscv64-specific bits header and lets it use the generic one.
2019-07-04 12:28:29 -04:00
Fangrui Song
4b5ba07650 configure: make AR and RANLIB customizable 2019-07-04 12:03:18 -04:00
Fangrui Song
94751d8ee4 remove stray .end directives from powerpc[64] asm
maintainer's note: these are not meaningful/correct/needed and the
clang integrated assembler errors out upon seeing them.
2019-07-02 17:01:39 -04:00
Szabolcs Nagy
f3f96f2daa add new syscall numbers from linux v5.1
syscall numbers are now synced up across targets (starting from 403 the
numbers are the same on all targets other than an arch specific offset)

IPC syscalls sem*, shm*, msg* got added where they were missing (except
for semop: only semtimedop got added), the new semctl, shmctl, msgctl
imply IPC_64, see

  linux commit 0d6040d4681735dfc47565de288525de405a5c99
  arch: add split IPC system calls where needed

new 64bit time_t syscall variants got added on 32bit targets, see

  linux commit 48166e6ea47d23984f0b481ca199250e1ce0730a
  y2038: add 64-bit time_t syscalls to all 32-bit architectures

new async io syscalls got added, see

  linux commit 2b188cc1bb857a9d4701ae59aa7768b5124e262e
  Add io_uring IO interface

  linux commit edafccee56ff31678a091ddb7219aba9b28bc3cb
  io_uring: add support for pre-mapped user IO buffers

a new syscall got added that uses the fd of /proc/<pid> as a stable
handle for processes: allows sending signals without pid reuse issues,
intended to eventually replace rt_sigqueueinfo, kill, tgkill and
rt_tgsigqueueinfo, see

  linux commit 3eb39f47934f9d5a3027fe00d906a45fe3a15fad
  signal: add pidfd_send_signal() syscall

on some targets (arm, m68k, s390x, sh) some previously missing syscall
numbers got added as well.
2019-07-01 14:20:58 -04:00
Szabolcs Nagy
4acfc287d8 ipc: prefer SYS_ipc when it is defined
Linux v5.1 introduced ipc syscalls on targets where previously only
SYS_ipc was available, change the logic such that the ipc code keeps
using SYS_ipc which works backward compatibly on older kernels.

This changes behaviour on microblaze which had both mechanisms, now
SYS_ipc will be used instead of separate syscalls.
2019-07-01 14:17:59 -04:00
Szabolcs Nagy
b574de5bf3 mips64: fix syscall numbers of io_pgetevents and rseq
the numbers added in

  commit d149e69c02
  add io_pgetevents and rseq syscall numbers from linux v4.18

were incorrect.
2019-07-01 14:17:02 -04:00
Szabolcs Nagy
47bc7f0afe elf.h: add NT_ARM_PAC{A,G}_KEYS from linux v5.1
to request or change pointer auth keys for criu via ptrace, new in

  linux commit d0a060be573bfbf8753a15dca35497db5e968bb0
  arm64: add ptrace regsets for ptrauth key management
2019-07-01 14:16:49 -04:00
Szabolcs Nagy
eea841e653 netinet/in.h: add INADDR_ALLSNOOPERS_GROUP from linux v5.1
RFC 4286: "The IPv4 multicast address for All-Snoopers is 224.0.0.106."
from

  linux commit 4effd28c1245303dce7fd290c501ac2c11052114
  bridge: join all-snoopers multicast address
2019-07-01 14:16:41 -04:00
Szabolcs Nagy
5b2b682ddc sys/socket.h: add SO_BINDTOIFINDEX from linux v5.1
SO_BINDTOIFINDEX behaves similar to SO_BINDTODEVICE, but takes a
network interface index as argument, rather than the network
interface name. see

  linux commit f5dd3d0c9638a9d9a02b5964c4ad636f06cf7e2c
  net: introduce SO_BINDTOIFINDEX sockopt
2019-07-01 14:12:36 -04:00
Szabolcs Nagy
4523505114 s390x: drop SO_ definitions from bits/socket.h
the s390x definitions matched the generic ones in sys/socket.h.
2019-07-01 14:12:25 -04:00
Szabolcs Nagy
93b5f6c843 netinet/in.h: add IPV6_ROUTER_ALERT_ISOLATE from linux v5.1
restricts router alert packets received by the socket to the
socket's namespace only. see

  linux commit 9036b2fe092a107856edd1a3bad48b83f2b45000
  net: ipv6: add socket option IPV6_ROUTER_ALERT_ISOLATE
2019-07-01 14:12:14 -04:00
Szabolcs Nagy
c7081edcf8 sys/prctl.h: add PR_SPEC_DISABLE_NOEXEC from linux v5.1
allows specifying that the speculative store bypass disable bit should
be cleared on exec. see

  linux commit 71368af9027f18fe5d1c6f372cfdff7e4bde8b48
  x86/speculation: Add PR_SPEC_DISABLE_NOEXEC
2019-07-01 14:12:06 -04:00
Szabolcs Nagy
9e8dd1c7f1 fcntl.h: add F_SEAL_FUTURE_WRITE from linux v5.1
needed for android so it can migrate from its ashmem to memfd.
allows making the memfd readonly for future users while keeping
a writable mmap of it. see

  linux commit ab3948f58ff841e51feb845720624665ef5b7ef3
  mm/memfd: add an F_SEAL_FUTURE_WRITE seal to memfd
2019-07-01 14:11:56 -04:00
Szabolcs Nagy
f67b3c1799 sys/fanotify.h: update for linux v5.1
includes changes from linux v5.1

  linux commit 235328d1fa4251c6dcb32351219bb553a58838d2
  fanotify: add support for create/attrib/move/delete events

  linux commit 5e469c830fdb5a1ebaa69b375b87f583326fd296
  fanotify: copy event fid info to user

  linux commit e9e0c8903009477b630e37a8b6364b26a00720da
  fanotify: encode file identifier for FAN_REPORT_FID

as well as earlier changes that were missed.

sys/statfs.h is included for fsid_t.
2019-07-01 14:11:42 -04:00
Samuel Holland
84ebec6cee fix deadlock in synccall after threaded fork
synccall may be called by AS-safe functions such as setuid/setgid after
fork. although fork() resets libc.threads_minus_one, causing synccall to
take the single-threaded path, synccall still takes the thread list
lock. This lock may be held by another thread if for example fork()
races with pthread_create(). After fork(), the value of the lock is
meaningless, so clear it.

maintainer's note: commit 8f11e6127f and
e4235d7067 introduced this regression.
the state protected by this lock is the linked list, which is entirely
replaced in the child path of fork (next=prev=self), so resetting it
is semantically sound.
2019-07-01 10:10:52 -04:00
Rich Felker
3d178a7e2b cap getdents length argument to INT_MAX
the linux syscall treats this argument as having type int, so passing
extremely long buffer sizes would be misinterpreted by the kernel.
since "short reads" are always acceptable, just cap it down.

patch based on report and suggested change by Florian Weimer.
2019-06-28 17:58:03 -04:00
Rich Felker
54b7564b72 remove unnecessary and problematic _Noreturn from crt/ldso startup
after commit a48ccc159a removed the use
of _Noreturn on the stage3_func type (which only worked due to it
being defined to the "GNU C" attribute in C99 mode), GCC could no
longer assume that the ends of __dls2 and __dls2b are unreachable, and
produced a warning that a function marked _Noreturn returns.

also, since commit 4390383b32, the
_Noreturn declaration for __libc_start_main in crt1/rcrt1 has been not
only inconsistent with the definition, but wrong. formally,
__libc_start_main does return, via a (hopefully) tail call to a helper
function after the barrier. incorrect usage of _Noreturn in the
declaration was probably formal UB.

the _Noreturn specifiers were not useful in any of these places, so
remove them all. now, the only remaining usage of _Noreturn is in
public interfaces where _Noreturn is part of their contract.
2019-06-25 19:05:40 -04:00
Rich Felker
95dfa3dd12 allow fmemopen with zero size
previously, POSIX erroneously required this to fail with EINVAL
despite the traditional glibc implementation, on which the POSIX
interface was based, allowing it. the resolution of Austin Group issue
818 removes the requirement to fail.
2019-06-25 17:47:12 -04:00
Matthew Maurer
a48ccc159a do not use _Noreturn for a function pointer in dynamic linker
_Noreturn is a C11 construct, and may only be used at the site of a
function definition.
2019-06-21 16:26:40 -04:00
Rich Felker
a31a30a007 remove implicit include of sys/sysmacros.h from sys/types.h
this reverts commit f552c792c7, which
exposed the sysmacros.h macros (device major/minor calculations) for
BSD and GNU profiles to mimic an unintentional glibc behavior some
code depended on. glibc has deprecated and since removed them as the
resolution to bug #19239, so it makes no sense for us to keep this
behavior. affected code should all have been fixed by now, and if it's
not yet fixed it needs to be for use with modern glibc anyway.
2019-06-21 15:49:38 -04:00
Rich Felker
0a48860c27 add riscv64 architecture support
Author: Alex Suykov <alex.suykov@gmail.com>
Author: Aric Belsito <lluixhi@gmail.com>
Author: Drew DeVault <sir@cmpwn.com>
Author: Michael Clark <mjc@sifive.com>
Author: Michael Forney <mforney@mforney.org>
Author: Stefan O'Rear <sorear2@gmail.com>

This port has involved the work of many people over several years. I
have tried to ensure that everyone with substantial contributions has
been credited above; if any omissions are found they will be noted
later in an update to the authors/contributors list in the COPYRIGHT
file.

The version committed here comes from the riscv/riscv-musl repo's
commit 3fe7e2c75df78eef42dcdc352a55757729f451e2, with minor changes by
me for issues found during final review:

- a_ll/a_sc atomics are removed (according to the ISA spec, lr/sc
  are not safe to use in separate inline asm fragments)

- a_cas[_p] is fixed to be a memory barrier

- the call from the _start assembly into the C part of crt1/ldso is
  changed to allow for the possibility that the linker does not place
  them nearby each other.

- DTP_OFFSET is defined correctly so that local-dynamic TLS works

- reloc.h LDSO_ARCH logic is simplified and made explicit.

- unused, non-functional crti/n asm files are removed.

- an empty .sdata section is added to crt1 so that the
  __global_pointer reference is resolvable.

- indentation style errors in some asm files are fixed.
2019-06-14 17:13:05 -04:00
Rich Felker
5fc4379825 optimize aarch64 dynamic tlsdesc function to spill fewer registers
with the glibc generation counter model for reusing dynamic tls slots
after dlclose, it's really not possible to get away with fewer than 4
working registers. for us however it's always been possible, but
tricky, and only became apparent after the switch to installing new
dynamic tls at dlopen time. by merging the negated thread pointer into
the addend early, the register holding the thread pointer can
immediately be reused, bringing the working register count down to
three. this allows saving/restoring via a single stp/ldp pair, since
the return register x0 does not need to be saved.

net reduction of 3 instructions, 2 of which were push/pop.
2019-05-26 19:27:20 -04:00
Rich Felker
ac304227bb make powerpc64 vrregset_t logical layout match expected API
between v2 and v3 of the powerpc64 port patch, the change was made
from a 32x4 array of 32-bit unsigned ints for vrregs[] to a 32-element
array of __int128. this mismatches the API applications working with
mcontext_t expect from glibc, and seems to have been motivated by a
misinterpretation of a comment on how aarch64 did things as a
suggestion to do the same on powerpc64.
2019-05-22 23:27:48 -04:00