Rich Felker [Fri, 24 Apr 2020 14:35:01 +0000 (10:35 -0400)]
fix undefined behavior in wcsto[ld] family functions
analogous to commit
b287cd745c2243f8e5114331763a5a9813b5f6ee but for
the custom FILE stream type the wcstol and wcstod family use. __toread
could be used here as well, but there's a simple direct fix to make
the buffer pointers initially valid for subtraction, so just do that
to avoid pulling in stdio exit code in programs that don't use stdio.
Rich Felker [Sat, 18 Apr 2020 07:23:40 +0000 (03:23 -0400)]
fix sh fesetround failure to clear old mode
the sh version of fesetround or'd the new rounding mode onto the
control register without clearing the old rounding mode bits, making
changes sticky. this was the root cause of multiple test failures.
Rich Felker [Fri, 17 Apr 2020 20:18:07 +0000 (16:18 -0400)]
move __string_read into vsscanf source file
apparently this function was intended at some point to be used by
strto* family as well, and thus was put in its own file; however, as
far as I can tell, it's only ever been used by vsscanf. move it to the
same file to reduce the number of source files and external symbols.
Rich Felker [Fri, 17 Apr 2020 20:11:43 +0000 (16:11 -0400)]
remove spurious repeated semicolon in fmemopen
Rich Felker [Fri, 17 Apr 2020 20:10:28 +0000 (16:10 -0400)]
combine two calls to memset in fmemopen
this idea came up when I thought we might need to zero the UNGET
portion of buf as well, but it seems like a useful improvement even
when that turned out not to be necessary.
Rich Felker [Fri, 17 Apr 2020 19:31:16 +0000 (15:31 -0400)]
fix possible access to uninitialized memory in shgetc (via scanf)
shgetc sets up to be able to perform an "unget" operation without the
caller having to remember and pass back the character value, and for
this purpose used a conditional store idiom:
if (f->rpos[-1] != c) f->rpos[-1] = c
to make it safe to use with non-writable buffers (setup by the
sh_fromstring macro or __string_read with sscanf).
however, validity of this depends on the buffer space at rpos[-1]
being initialized, which is not the case under some conditions
(including at least unbuffered files and fmemopen ones).
whenever data was read "through the buffer", the desired character
value is already in place and does not need to be written. thus,
rather than testing for the absence of the value, we can test for
rpos<=buf, indicating that the last character read could not have come
from the buffer, and thereby that we have a "real" buffer (possibly of
zero length) with writable pushback (UNGET bytes) below it.
Rich Felker [Fri, 17 Apr 2020 17:46:57 +0000 (13:46 -0400)]
fix undefined behavior in scanf core
as reported/analyzed by Pascal Cuoq, the shlim and shcnt
macros/functions are called by the scanf core (vfscanf) with f->rpos
potentially null (if the FILE is not yet activated for reading at the
time of the call). in this case, they compute differences between a
null pointer (f->rpos) and a non-null one (f->buf), resulting in
undefined behavior.
it's unlikely that any observably wrong behavior occurred in practice,
at least without LTO, due to limits on what's visible to the compiler
from translation unit boundaries, but this has not been checked.
fix is simply ensuring that the FILE is activated for read mode before
entering the main scanf loop, and erroring out early if it can't be.
Alexander Monakov [Thu, 16 Jan 2020 20:58:13 +0000 (23:58 +0300)]
math: add x86_64 remquol
Alexander Monakov [Wed, 15 Jan 2020 15:42:46 +0000 (18:42 +0300)]
math: move x87-family fmod functions to C with inline asm
Alexander Monakov [Tue, 14 Jan 2020 20:36:44 +0000 (23:36 +0300)]
math: move x87-family remainder functions to C with inline asm
Alexander Monakov [Tue, 14 Jan 2020 11:53:38 +0000 (14:53 +0300)]
math: move x87-family rint functions to C with inline asm
Alexander Monakov [Sat, 11 Jan 2020 15:14:24 +0000 (18:14 +0300)]
math: move x87-family lrint functions to C with inline asm
Alexander Monakov [Fri, 10 Jan 2020 20:06:36 +0000 (23:06 +0300)]
math: move x86_64 (l)lrint(f) functions to C with inline asm
Alexander Monakov [Tue, 7 Jan 2020 12:53:03 +0000 (15:53 +0300)]
math: move i386 sqrt to C with inline asm
Alexander Monakov [Mon, 6 Jan 2020 17:31:47 +0000 (20:31 +0300)]
math: move i386 sqrtf to C with inline asm
Alexander Monakov [Mon, 6 Jan 2020 16:35:57 +0000 (19:35 +0300)]
math: move trivial x86-family sqrt functions to C with inline asm
Alexander Monakov [Mon, 6 Jan 2020 08:36:18 +0000 (11:36 +0300)]
math: move x87-family fabs functions to C with inline asm
Alexander Monakov [Sun, 5 Jan 2020 15:47:02 +0000 (18:47 +0300)]
math: move x86_64 fabs, fabsf to C with inline asm
Samuel Holland [Sat, 22 Feb 2020 22:01:13 +0000 (16:01 -0600)]
fix parsing offsets after long timezone names
TZ containg a timezone name with >TZNAME_MAX characters currently
breaks musl's timezone parsing. getname() stops after TZNAME_MAX
characters. getoff() will consume no characters (because the next
character is not a digit) and incorrectly return 0. Then, because
there are remaining alphabetic characters, __daylight == 1, and
dst_off == -3600.
getname() must consume the entire timezone name, even if it will not
fit in d/__tzname, so when it returns, s points to the offset digits.
Samuel Holland [Sat, 22 Feb 2020 22:01:12 +0000 (16:01 -0600)]
avoid out-of-bounds read for invalid quoted timezone
Parsing the timezone name must stop when reaching the null terminator.
In that case, there is no '>' to skip.
Alexander Monakov [Mon, 9 Mar 2020 18:32:16 +0000 (21:32 +0300)]
remove redundant condition in memccpy
Commit
d9bdfd164 ("fix memccpy to not access buffer past given size")
correctly added a check for 'n' nonzero, but made the pre-existing test
'*s==c' redundant: n!=0 implies *s==c. Remove the unnecessary check.
Reported by Alexey Izbyshev.
Fangrui Song [Sun, 8 Mar 2020 18:10:32 +0000 (11:10 -0700)]
ldso: remove redundant switch case for REL_NONE
as a result of commit
b6a6cd703ffefa6352249fb01f4da28d85d17306,
the REL_NONE case is now redundant.
Samuel Holland [Sat, 14 Mar 2020 05:31:40 +0000 (00:31 -0500)]
define MAP_SYNC on powerpc/powerpc64
Linux defines MAP_SYNC on powerpc and powerpc64 as of commit
22fcea6f85f2 ("mm: move MAP_SYNC to asm-generic/mman-common.h"),
so we can stop undefining it on those architectures.
Timo Teräs [Wed, 4 Mar 2020 09:27:01 +0000 (11:27 +0200)]
improve strerror speed
change the current O(n) lookup to O(1) based on the machinery
described in "How To Write Shared Libraries" (Appendix B).
Rich Felker [Fri, 13 Mar 2020 20:27:10 +0000 (16:27 -0400)]
fix corrupt sysvipc timestamps on 32-bit archs with old kernels
kernel commit
4693916846269d633a3664586650dbfac2c5562f (first included
in release v4.14) silently fixed a bug whereby the reserved space
(which was later used for high bits of time) in IPC_STAT structures
was left untouched rather than zeroed. this means that a caller that
wants to read the high bits needs to pre-zero the memory.
since it's not clear that these operations are permitted to modify the
destination buffer on failure, use a temp buffer and copy back to the
caller's buffer on success.
Rich Felker [Wed, 11 Mar 2020 23:02:52 +0000 (19:02 -0400)]
work around negated error code bug on some mips kernels
on all mips variants, Linux did (and maybe still does) have some
syscall return paths that wrongly return both the error flag in r7 and
a negated error code in r2. in particular this happened for at least
some causes of ENOSYS.
add an extra check to only negate the error code if it's positive to
begin with.
bug report and concept for patch by Andreas Dröscher.
Rich Felker [Wed, 11 Mar 2020 22:58:38 +0000 (18:58 -0400)]
remove useless mips syscall asm constraint, align style with mips64/n32
commit
4221f154ff29ab0d6be1e7beaa5ea2d1731bc58e added the r7
constraint apparently out of a misunderstanding of the breakage it was
addressing, and did so because the asm was in a shared macro used by
all the __syscallN inline functions. now "+r" is used in the output
section for the forms 4-argument and up, so having it in input is
redundant, and the forms with 0-3 arguments don't need it as an input
at all.
the r2 constraint is kept because without it most gcc versions (seems
to be all prior to 9.x) fail to honor the output register binding for
r2. this seems to be a variant of gcc bug #87733.
both the r7 and r2 input constraints look useless, but the r2 one was
a quiet workaround for gcc bug 87733, which affects all modern
versions prior to 9.x, so it's kept and documented.
Rich Felker [Wed, 11 Mar 2020 22:50:21 +0000 (18:50 -0400)]
revert mips (32-bit, o32) syscall asm clean-up due to regressions
exactly revert commit
604f8d3d8b08ee4f548de193050ef93a7753c2e0 which
was wrong; it caused a major regression on Linux versions prior to
2.6.36. old kernels did not properly preserve r2 across syscall
restart, and instead restarted with the instruction right before
syscall, imposing a contract that the previous instruction must load
r2 from an immediate or a register (or memory) not clobbered by the
syscall.
Rich Felker [Wed, 11 Mar 2020 22:43:11 +0000 (18:43 -0400)]
revert mips64/n32 syscall asm clean-up due to regressions
effectivly revert commit
ddc7c4f936c7a90781072f10dbaa122007e939d0
which was wrong; it caused a major regression on Linux versions prior
to 2.6.36. old kernels did not properly preserve r2 across syscall
restart, and instead restarted with the instruction right before
syscall, imposing a contract that the previous instruction must load
r2 from an immediate or a register (or memory) not clobbered by the
syscall.
since other changes were made since, including removal of the struct
stat conversion that was replaced by separate struct kstat, this is
not a direct revert, only a functional one.
the "0"(r2) input constraint added back seems useless/erroneous, but
without it most gcc versions (seems to be all prior to 9.x) fail to
honor the output register binding for r2. this seems to be a variant
of gcc bug #87733. further changes should be made later if a better
workaround is found, but this one has been working since 2012. it
seems this issue was encountered but misidentified then, when it
inspired commit
4221f154ff29ab0d6be1e7beaa5ea2d1731bc58e.
Rich Felker [Wed, 4 Mar 2020 17:33:35 +0000 (12:33 -0500)]
remove duplicate definitions of INET[6]_ADDRSTRLEN
these were leftover from early beginnings when arpa/inet.h was not
including netinet/in.h.
Rich Felker [Wed, 26 Feb 2020 15:09:32 +0000 (10:09 -0500)]
add PTHREAD_NULL
this is added for POSIX-future as the outcome of Austin Group issue
599. since it's in the reserved namespace for pthread.h, there are no
namespace considerations for adding it early.
Rich Felker [Sat, 22 Feb 2020 16:07:14 +0000 (11:07 -0500)]
use __socketcall to simplify socket()
commit
59324c8b0950ee94db846a50554183c845ede160 added __socketcall
analogous to __syscall, returning the negated error rather than
setting errno. use it to simplify the fallback path of socket(),
avoiding extern calls and access to errno.
Author: Rich Felker <dalias@aerifal.cx>
Date: Tue Jul 30 17:51:16 2019 -0400
make __socketcall analogous to __syscall, error-returning
Rich Felker [Sat, 22 Feb 2020 04:44:20 +0000 (23:44 -0500)]
remove wrap_write helper from vdprintf
this reverts commit
4ee039f3545976f9e3e25a7e5d7b58f1f2316dc3, which
added the helper as a hack to make vdprintf usable before relocation,
contingent on strong assumptions about the arch and tooling, back when
the dynamic linker did not have a real staged model for
self-relocation. since commit
f3ddd173806fd5c60b3f034528ca24542aecc5b9
this has been unnecessary and the function was just wasting size and
execution time.
Szabolcs Nagy [Mon, 20 Jan 2020 20:38:45 +0000 (20:38 +0000)]
math: fix sinh overflows in non-nearest rounding
The final rounding operation should be done with the correct sign
otherwise huge results may incorrectly get rounded to or away from
infinity in upward or downward rounding modes.
This affected sinh and sinhf which set the sign on the result after
a potentially overflowing mul. There may be other non-nearest rounding
issues, but this was a known long standing issue with large ulp error
(depending on how ulp is defined near infinity).
The fix should have no effect on sinh and sinhf performance but may
have a tiny effect on cosh and coshf.
Szabolcs Nagy [Sat, 18 Jan 2020 17:55:25 +0000 (17:55 +0000)]
math: fix __rem_pio2 in non-nearest rounding modes
Handle when after reduction |y| > pi/4+tiny. This happens in directed
rounding modes because the fast round to int code does not give the
nearest integer. In such cases the reduction may not be symmetric
between x and -x so e.g. cos(x)==cos(-x) may not hold (but polynomial
evaluation is not symmetric either with directed rounding so fixing
that would require more changes with bigger performance impact).
The fix only adds two predictable branches in nearest rounding mode,
simple ubenchmark does not show relevant performance regression in
nearest rounding mode.
The code could be improved: e.g reducing the medium size threshold
such that two step reduction is enough instead of three, and the
single precision case can avoid the issue by doing the round to int
differently, but this fix was kept minimal.
Rich Felker [Fri, 21 Feb 2020 00:37:02 +0000 (19:37 -0500)]
release 1.2.0
Rich Felker [Wed, 12 Feb 2020 22:23:29 +0000 (17:23 -0500)]
fix remaining direct use of stat syscalls outside fstatat.c
because struct stat is no longer assumed to correspond to the
structure used by the stat-family syscalls, it's not valid to make any
of these syscalls directly using a buffer of type struct stat.
commit
9493892021eac4edf1776d945bcdd3f7a96f6978 moved all logic around
this change for stat-family functions into fstatat.c, making the
others wrappers for it. but a few other direct uses of the syscall
were overlooked. the ones in tmpnam/tempnam are harmless since the
syscalls are just used to test for file existence. however, the uses
in fchmodat and __map_file depend on getting accurate file properties,
and these functions may actually have been broken one or more mips
variants due to removal of conversion hacks from syscall_arch.h.
as a low-risk fix, simply use struct kstat in place of struct stat in
the affected places.
Rich Felker [Thu, 6 Feb 2020 21:29:49 +0000 (16:29 -0500)]
remove i386 asm for single and double precision exp-family functions
these did not truncate excess precision in the return value. fixing
them looks like considerable work, and the current C code seems to
outperform them significantly anyway.
long double functions are left in place because they are not subject
to excess precision issues and probably better than the C code.
Rich Felker [Thu, 6 Feb 2020 21:24:03 +0000 (16:24 -0500)]
rename i386 exp.s to exp_ld.s
this commit is for the sake of reviewable history.
Rich Felker [Thu, 6 Feb 2020 18:29:45 +0000 (13:29 -0500)]
fix excess precision in return value of i386 log-family functions
Rich Felker [Thu, 6 Feb 2020 17:06:30 +0000 (12:06 -0500)]
fix excess precision in return value of i386 acos[f] and asin[f]
analogous to commit
1c9afd69051a64cf085c6fb3674a444ff9a43857 for
atan[2][f].
Rich Felker [Thu, 6 Feb 2020 16:34:54 +0000 (11:34 -0500)]
fix excess precision in return value of i386 atan[2][f]
for functions implemented in C, this is a requirement of C11 (F.6);
strictly speaking that text does not apply to standard library
functions, but it seems to be intended to apply to them, and C2x is
expected to make it a requirement.
failure to drop excess precision is particularly bad for inverse trig
functions, where a value with excess precision can be outside the
range of the function (entire range, or range for a particular
subdomain), breaking reasonable invariants a caller may expect.
Rich Felker [Wed, 5 Feb 2020 14:55:02 +0000 (09:55 -0500)]
remove legacy time32 timer[fd] syscalls from public syscall.h
this extends commit
5a105f19b5aae79dd302899e634b6b18b3dcd0d6, removing
timer[fd]_settime and timer[fd]_gettime. the timerfd ones are likely
to have been used in software that started using them before it could
rely on libc exposing functions.
Rich Felker [Wed, 5 Feb 2020 14:51:09 +0000 (09:51 -0500)]
remove further legacy time32 clock syscalls from public syscall.h
this extends commit
5a105f19b5aae79dd302899e634b6b18b3dcd0d6, removing
clock_settime, clock_getres, clock_nanosleep, and settimeofday.
Rich Felker [Wed, 5 Feb 2020 14:40:11 +0000 (09:40 -0500)]
fix incorrect results for catanf and catanl with some inputs
catan was fixed in
10e4bd3780050e75b72aac5d85c31816419bb17d but the
same bug in catanf and catanl was overlooked. the patch is completely
analogous.
Rich Felker [Tue, 4 Feb 2020 14:29:13 +0000 (09:29 -0500)]
move riscv64 register index constants to signal.h
under _GNU_SOURCE for namespace cleanliness, analogous to other archs.
the original placement in sys/reg.h seems not to have been motivated;
such a header isn't even present on other implementations.
Rich Felker [Thu, 30 Jan 2020 16:25:07 +0000 (11:25 -0500)]
remove legacy clock_gettime and gettimeofday from public syscall.h
some nontrivial number of applications have historically performed
direct syscalls for these operations rather than using the public
functions. such usage is invalid now that time_t is 64-bit and these
syscalls no longer match the types they are used with, and it was
already harmful before (by suppressing use of vdso).
since syscall() has no type safety, incorrect usage of these syscalls
can't be caught at compile-time. so, without manually inspecting or
running additional tools to check sources, the risk of such errors
slipping through is high.
this patch renames the syscalls on 32-bit archs to clock_gettime32 and
gettimeofday_time32, so that applications using the original names
will fail to build without being fixed.
note that there are a number of other syscalls that may also be unsafe
to use directly after the time64 switchover, but (1) these are the
main two that seem to be in widespread use, and (2) most of the others
continue to have valid usage with a null timeval/timespec argument, as
the argument is an optional timeout or similar.
Rich Felker [Wed, 29 Jan 2020 15:47:48 +0000 (10:47 -0500)]
fix misleading use of _POSIX_VDISABLE in sys/ttydefaults.h
_POSIX_VDISABLE is only visible if unistd.h has already been included,
so conditional use of it here makes no sense. the value is always 0
anyway; it does not vary.
Rich Felker [Wed, 29 Jan 2020 15:47:19 +0000 (10:47 -0500)]
fix unprotected macro argument in sys/ttydefaults.h
Alexander Monakov [Sat, 18 Jan 2020 16:15:16 +0000 (19:15 +0300)]
math/x32: correct lrintl.s for 32-bit long
Rich Felker [Sun, 26 Jan 2020 04:08:55 +0000 (23:08 -0500)]
move struct dirent to bits header, allow NAME_MAX to vary
this is not necessary for linux but is a simple, inexpensive change to
make that facilitates ports to systems where NAME_MAX needs to be
longer.
Luís Marques [Wed, 15 Jan 2020 13:24:41 +0000 (13:24 +0000)]
fix riscv64 a_cas inline asm operand sign extension
This patch adds an explicit cast to the int arguments passed to the
inline asm used in the RISC-V's implementation of `a_cas`, to ensure
that they are properly sign extended to 64 bits. They aren't
automatically sign extended by Clang, and GCC technically also doesn't
guarantee that they will be sign extended.
Will Dietz [Wed, 8 Jan 2020 19:20:44 +0000 (13:20 -0600)]
fix incorrect escaping in add-cfi.*.awk scripts
gawk 5 complains.
Andre McCurdy [Fri, 13 Sep 2019 18:44:31 +0000 (11:44 -0700)]
add thumb2 support to arm assembler memcpy
For Thumb2 compatibility, replace two instances of a single
instruction "orr with a variable shift" with the two instruction
equivalent. Neither of the replacements are in a performance critical
loop.
Rich Felker [Wed, 15 Jan 2020 21:15:49 +0000 (16:15 -0500)]
fix incorrect __hwcap seen in dynamic-linked __set_thread_area
the bug fixed in commit
b82cd6c78d812d38c31febba5a9e57dbaa7919c4 was
mostly masked on arm because __hwcap was zero at the point of the call
from the dynamic linker to __set_thread_area, causing the access to
libc.auxv to be skipped and kuser_helper versions of TLS access and
atomics to be used instead of the armv6 or v7 versions. however, on
kernels with kuser_helper removed for hardening it would crash.
since __set_thread_area potentially uses __hwcap, it must be
initialized before the function is called. move the AT_HWCAP lookup
from stage 3 to stage 2b.
Leah Neukirchen [Sat, 11 Jan 2020 19:16:59 +0000 (20:16 +0100)]
define RLIMIT_RTTIME, bump RLIMIT_NLIMITS
This macro exists since Linux 2.6.25 and is defined in glibc since 2011.
Rich Felker [Thu, 2 Jan 2020 01:02:51 +0000 (20:02 -0500)]
fix wcwidth wrongly returning 0 for most of planes 4 and up
commit
1b0ce9af6d2aa7b92edaf3e9c631cb635bae22bd introduced this bug
back in 2012 and it was never noticed, presumably since the affected
planes are essentially unused in Unicode.
Michael Forney [Tue, 19 Nov 2019 09:56:34 +0000 (01:56 -0800)]
unconditonally define alloca as __builtin_alloca
This enables alternative compilers, which may not define __GNUC__,
to implement alloca, which is still fairly widely used.
This is similar to how stdarg.h already works in musl; compilers must
implement __builtin_va_arg, there is no fallback definition.
Rich Felker [Wed, 1 Jan 2020 16:13:51 +0000 (11:13 -0500)]
update COPYRIGHT year
Rich Felker [Wed, 1 Jan 2020 16:10:07 +0000 (11:10 -0500)]
remove gratuitous aligned attribute from __ptrace_syscall_info
this change was discussed on the mailing list thread for the linux
uapi v5.3 patches, and submitted as a v2 patch, but overlooked when I
applied the patches much later.
revert commit
f291c09ec90e2514c954020e9b9bdb30e2adfc7f and apply the
v2 as submitted; the net change is just padding.
notes by Szabolcs Nagy follow:
compared to the linux uapi (and glibc) a padding is used instead of
aligned attribute for keeping the layout the same across targets, this
means the alignment of the struct may be different on some targets
(e.g. m68k where uint64_t is 2 byte aligned) but that should not affect
syscalls and this way the abi does not depend on nonstandard extensions.
Rich Felker [Wed, 1 Jan 2020 05:15:04 +0000 (00:15 -0500)]
fix fdpic regression in dynamic linker with overly smart compilers
at least gcc 9 broke execution of DT_INIT/DT_FINI for fdpic archs
(presently only sh) by recognizing that the stores to the
compound-literal function descriptor constructed to call them were
dead stores. there's no way to make a "may_alias function", so instead
launder the descriptor through an asm-statement barrier. in practice
just making the compound literal volatile seemed to have worked too,
but this should be less of a hack and more accurately convey the
semantics of what transformations are not valid.
Rich Felker [Wed, 1 Jan 2020 02:59:07 +0000 (21:59 -0500)]
fix crashing ldso on archs where __set_thread_area examines auxv
commit
1c84c99913bf1cd47b866ed31e665848a0da84a2 moved the call to
__init_tp above the initialization of libc.auxv, inadvertently
breaking archs where __set_thread_area examines auxv for the sake of
determining the TLS/atomic model needed at runtime. this broke armv6
and sh2.
Rich Felker [Wed, 1 Jan 2020 02:51:07 +0000 (21:51 -0500)]
move stage3_func typedef out of shared internal dynlink.h header
this interface contract is entirely internal to dynlink.c.
Szabolcs Nagy [Sun, 22 Dec 2019 12:31:44 +0000 (12:31 +0000)]
mips: add clone3 syscall numbers from linux v5.4
the syscall numbers were reserved in v5.3 but not wired up on mips, see
linux commit
0671c5b84e9e0a6d42d22da9b5d093787ac1c5f3
MIPS: Wire up clone3 syscall
Szabolcs Nagy [Sun, 22 Dec 2019 12:19:16 +0000 (12:19 +0000)]
mips: add hwcap bits from linux v5.4
mips application specific isa extensions were previously not exported
in hwcaps so userspace could not apply optimized code at runtime.
linux commit
38dffe1e4dde1d3174fdce09d67370412843ebb5
MIPS: elf_hwcap: Export userspace ASEs
Szabolcs Nagy [Sun, 22 Dec 2019 12:11:30 +0000 (12:11 +0000)]
sys/wait.h: add P_PIDFD from linux v5.4
allows waiting on a pidfd, in the future it might allow retrieving the
exit status by a non-parent process, see
linux commit
3695eae5fee0605f316fbaad0b9e3de791d7dfaf
pidfd: add P_PIDFD to waitid()
Szabolcs Nagy [Sun, 22 Dec 2019 12:02:52 +0000 (12:02 +0000)]
netinet/tcp.h: add new tcp_info fields from linux v5.4
tcpi_rcv_ooopack for tracking connection quality:
linux commit
f9af2dbbfe01def62765a58af7fbc488351893c3
tcp: Add TCP_INFO counter for packets received out-of-order
tcpi_snd_wnd peer window size for diagnosing tcp performance problems:
linux commit
8f7baad7f03543451af27f5380fc816b008aa1f2
tcp: Add snd_wnd to TCP_INFO
Szabolcs Nagy [Sun, 22 Dec 2019 10:51:37 +0000 (10:51 +0000)]
sys/prctl.h: add PR_*_TAGGED_ADDR_* from linux v5.4
per thread prctl commands to relax the syscall abi such that top bits
of user pointers are ignored in the kernel. this allows the use of
those bits by hwasan or by mte to color pointers and memory on aarch64:
linux commit
63f0c60379650d82250f22e4cf4137ef3dc4f43d
arm64: Introduce prctl() options to control the tagged user addresses ABI
Szabolcs Nagy [Sun, 22 Dec 2019 10:26:20 +0000 (10:26 +0000)]
sys/mman.h: add MADV_COLD and MADV_PAGEOUT from linux v5.4
These were mainly introduced so android can optimize the memory usage
of unused apps.
MADV_COLD hints that the memory range is currently not needed (unlike
with MADV_FREE the content is not garbage, it needs to be swapped):
linux commit
9c276cc65a58faf98be8e56962745ec99ab87636
mm: introduce MADV_COLD
MADV_PAGEOUT hints that the memory range is not needed for a long time
so it can be reclaimed immediately independently of memory pressure
(unlike with MADV_DONTNEED the content is not garbage):
linux commit
1a4e58cce84ee88129d5d49c064bd2852b481357
mm: introduce MADV_PAGEOUT
Szabolcs Nagy [Sun, 3 Nov 2019 23:27:31 +0000 (23:27 +0000)]
add clone3 syscall number from linux v5.3
the syscall number is reserved on all targets, but it is not wired up
on all targets, see
linux commit
8f6ccf6159aed1f04c6d179f61f6fb2691261e84
Merge tag 'clone3-v5.3' of ... brauner/linux
linux commit
8f3220a806545442f6f26195bc491520f5276e7c
arch: wire-up clone3() syscall
linux commit
7f192e3cd316ba58c88dfa26796cf77789dd9872
fork: add clone3
Szabolcs Nagy [Sun, 3 Nov 2019 23:16:53 +0000 (23:16 +0000)]
add pidfd_open syscall number from linux v5.3
see
linux commit
7615d9e1780e26e0178c93c55b73309a5dc093d7
arch: wire-up pidfd_open()
linux commit
32fcb426ec001cb6d5a4a195091a8486ea77e2df
pid: add pidfd_open()
Szabolcs Nagy [Sun, 3 Nov 2019 22:45:05 +0000 (22:45 +0000)]
sys/ptrace.h: add PTRACE_GET_SYSCALL_INFO from linux v5.3
ptrace API to get details of the syscall the tracee is blocked in, see
linux commit
201766a20e30f982ccfe36bebfad9602c3ff574a
ptrace: add PTRACE_GET_SYSCALL_INFO request
the align attribute was used to keep the layout the same across targets
e.g. on m68k uint32_t is 2 byte aligned, this helps with compat ptrace.
Szabolcs Nagy [Sun, 3 Nov 2019 22:27:13 +0000 (22:27 +0000)]
sys/socket.h: add SO_DETACH_REUSEPORT_BPF from linux v5.3
see
linux commit
99f3a064bc2e4bd5fe50218646c5be342f2ad18c
bpf: net: Add SO_DETACH_REUSEPORT_BPF
Szabolcs Nagy [Sun, 3 Nov 2019 22:22:32 +0000 (22:22 +0000)]
netinet/if_ether.h: add ETH_P_LLDP from linux v5.3
see
linux commit
c54c2c72b2b90a3ba61b8cad032a578ce2bf5b35
net: Add a define for LLDP ethertype
Szabolcs Nagy [Thu, 31 Oct 2019 21:15:43 +0000 (21:15 +0000)]
netinet/tcp.h: add TCP_TX_DELAY from linux v5.3
see
linux commit
a842fe1425cb20f457abd3f8ef98b468f83ca98b
tcp: add optional per socket transmit delay
Khem Raj [Wed, 18 Dec 2019 22:02:37 +0000 (14:02 -0800)]
fix types for mips sigcontext/mcontext_t regset members
Rich Felker [Sun, 22 Dec 2019 18:25:17 +0000 (13:25 -0500)]
spare archs without time32 legacy the cost of ioctl fallback conversions
adding this condition makes the entire convert_ioctl_struct function
and compat_map table statically unreachable, and thereby optimized out
by dead code elimination, on archs where they are not needed.
Rich Felker [Sun, 22 Dec 2019 18:18:47 +0000 (13:18 -0500)]
add further ioctl time64 fallback conversion for device-specific command
VIDIOC_OMAP3ISP_STAT_REQ is a device-specific command for the omap3isp
video device. the command number is in a device-private range and
therefore could theoretically be used by other devices too in the
future, but problematic clashes should not be able to arise without
intentional misuse.
A. Wilcox [Sun, 22 Dec 2019 06:06:47 +0000 (00:06 -0600)]
add uapi guards for new netinet/ip.h conflict with struct iphdr
This ensures that the musl definition of 'struct iphdr' does not conflict
with the Linux kernel UAPI definition of it.
Some software, i.e. net-tools, will not compile against 5.4 kernel headers
without this patch and the corresponding Linux kernel patch.
Rich Felker [Sun, 22 Dec 2019 17:37:16 +0000 (12:37 -0500)]
adjust utmpx struct layout for time64, 32-/64-bit arch compat
since time64 switchover has changed the size and layout of the struct
anyway, take the opportunity to fix it up so that it can be shared
between 32- and 64-bit ABIs on the same system as long as byte order
matches.
the ut_type member is explicitly padded to make up for m68k having
only 2-byte alignment; explicit padding has no effect on other archs.
ut_session is changed from long to int, with endian-matched padding.
this affects 64-bit archs as well, but brings the type into alignment
with glibc's x86_64 struct, so it should not break software, and does
not break on-disk format. the semantic type is int (pid-like) anyway.
the padding produces correct alignment for the ut_tv member on 32-bit
archs that don't naturally align it, so that ABI matches 64-bit.
this type is presently not used anywhere in the ABI between libc and
libc consumers; it's only used between pairs of consumers if a
third-party utmp library using the system utmpx.h is in use.
Rich Felker [Sun, 22 Dec 2019 16:20:44 +0000 (11:20 -0500)]
fix elf_prstatus regression on time64, existing wrong definition on x32
the elf_prstatus structure is used in core dumps, and the timeval
structures in it are longs matching the elf class, *not* the kernel
"old timeval" for the arch. this means using timeval here for x32 was
always wrong, despite kernel uapi headers and glibc also exposing it
this way, and of course it's wrong for any arch with 64-bit time_t.
rather than just changing the type on affected archs, use a tagless
struct containing long tv_sec and tv_usec members in place of the
timevals. this intentionally breaks use of them as timevals (e.g.
assignment, passing address, etc.) on 64-bit archs as well so that any
usage unsafe for 32-bit archs is caught even in software that only
gets tested on 64-bit archs. from what I could gather, there is not
any software using these members anyway. the only reason they need to
be fixed to begin with is that the only members which are commonly
used, the saved registers, follow the time members and have the wrong
offset if the time members are sized incorrectly.
Rich Felker [Sat, 21 Dec 2019 17:21:04 +0000 (12:21 -0500)]
don't continue looping through ioctl compat_map after finding match
there's only one matching entry for any given command so this had no
functional distinction, but additional loops are pointless and
wasteful.
Rich Felker [Sat, 21 Dec 2019 02:27:39 +0000 (21:27 -0500)]
revert unwanted and inadvertent change that slipped into mmap.c
commit
ae388becb529428ac926da102f1d025b3c3968da accidentally
introduced #define SYSCALL_NO_TLS 1 in mmap.c, which was probably a
stale change left around from unrelated syscall timing measurements.
reverse it.
Rich Felker [Fri, 20 Dec 2019 00:50:31 +0000 (19:50 -0500)]
add further ioctl time64 fallback conversions
this commit covers all remaining ioctls I'm aware of that use
time_t-derived types in their interfaces. it may still be incomplete,
and has undergone only minimal testing for a few commands used in
audio playback.
the SNDRV_PCM_IOCTL_SYNC_PTR command is special-cased because, rather
than the whole structure expanding, it has two substructures each
padded to 64 bytes that expand within their own 64-byte reserved zone.
as long as it's the only one of its type, it doesn't really make sense
to make a general framework for it, but the existing table framework
is still used for the substructures in the special-case. one of the
substructures, snd_pcm_mmap_status, has a snd_pcm_uframes_t member
which is not a timestamp but is expanded just like one, to match the
64-bit-arch version of the structure. this is handled just like a
timestamp at offset 8, and is the motivation for the conversions table
holding offsets of individual values to be expanded rather than
timespec/timeval type pairs.
for some of the types, the size to which they expand is dependent on
whether the arch's ABI aligns 8-byte types on 8-byte boundaries.
new_req entries in the table need to reflect this size to get the
right ioctl request number that will match what callers pass, but we
don't have access to the actual structure type definitions here and
duplicating them would be cumbersome. instead, the new_misaligned
macro introduced here constructs an artificial object whose size is
the result of expanding a misaligned timespec/timeval to 64-bit and
imposing the arch's alignment on the result, which can be passed to
the _IO{R,W,WR} macros.
Rich Felker [Thu, 19 Dec 2019 15:47:10 +0000 (10:47 -0500)]
improve ioctl time64 conversion fallback framework
record offsets of individual slots that expand from 32- to 64-bit,
rather than timespec/timeval pairs. this flexibility will be needed
for some ioctls. reduce size of types in table. adjust representation
of offsets to include a count rather than needing -1 padding so that
the table is less ugly and doesn't need large diffs if we increase max
number of slots.
Rich Felker [Thu, 19 Dec 2019 01:48:58 +0000 (20:48 -0500)]
convert ioctl time64 fallbacks to table-driven framework
with the current set of supported ioctls, this conversion is hardly an
improvement, but it sets the stage for being able to do alsa, v4l2,
ppp, and other ioctls with timespec/timeval-derived types. without
this capability, a lot of functionality users depend on would stop
working with the time64 switchover.
Rich Felker [Wed, 18 Dec 2019 23:03:43 +0000 (18:03 -0500)]
fix regression in ioctl definitions provided by arch/generic bits
commit
b60fdf133c033d4ad6b04a8237f253563fae5928 broke the
SIOCGSTAMP[NS] ioctl fallbacks introduced in commit
2e554617e5a6a41bf3f6c6306c753cd53abf728c, as well as use of these
ioctls, by creating a situation where bits/ioctl.h could be included
without __LONG_MAX being visible.
Rich Felker [Wed, 18 Dec 2019 04:00:24 +0000 (23:00 -0500)]
hook recvmmsg up to SO_TIMESTAMP[NS] fallback for pre-time64 kernels
always try the time64 syscall first since we can use its success to
conclude that no conversion is needed (any setsockopt for the
timestamp options would have succeeded without need for fallbacks).
otherwise, we have to remember the original controllen for each
msghdr, requiring O(vlen) space, so vlen must be bounded. linux clamps
it to IOV_MAX for sendmmsg only (not recvmmsg), but doing the same for
recvmmsg is not unreasonable, especially since the limitation will
only apply to old kernels.
we could optimize to avoid trying SYS_recvmmsg_time64 first if all
msghdrs have controllen zero, or support unlimited vlen by looping and
emulating the timeout logic, but I'm not inclined to do complex and
error-prone optimizations on a function that has so many underlying
problems it should really never be used.
Rich Felker [Wed, 18 Dec 2019 01:12:03 +0000 (20:12 -0500)]
implement SO_TIMESTAMP[NS] fallback for kernels without time64 versions
the definitions of SO_TIMESTAMP* changed on 32-bit archs in commit
38143339646a4ccce8afe298c34467767c899f51 to the new versions that
provide 64-bit versions of timeval/timespec structure in control
message payload. socket options, being state attached to the socket
rather than function calls, are not trivial to implement as fallbacks
on ENOSYS, and support for them was initially omitted on the
assumption that the ioctl-based polling alternatives (SIOCGSTAMP*)
could be used instead by applications if setsockopt fails.
unfortunately, it turns out that SO_TIMESTAMP is sufficiently old and
widely supported that a number of applications assume it's available
and treat errors as fatal.
this patch introduces emulation of SO_TIMESTAMP[NS] on pre-time64
kernels by falling back to setting the "_OLD" (time32) versions of the
options if the time64 ones are not recognized, and performing
translation of the SCM_TIMESTAMP[NS] control messages in recvmsg.
since recvmsg does not know whether its caller is legacy time32 code
or time64, it performs translation for any SCM_TIMESTAMP[NS]_OLD
control messages it sees, leaving the original time32 timestamp as-is
(it can't be rewritten in-place anyway, and memmove would be mildly
expensive) and appending the converted time64 control message at the
end of the buffer. legacy time32 callers will see the converted one as
a spurious control message of unknown type; time64 callers running on
pre-time64 kernels will see the original one as a spurious control
message of unknown type. a time64 caller running on a kernel with
native time64 support will only see the time64 version of the control
message.
emulation of SO_TIMESTAMPING is not included at this time since (1)
applications which use it seem to be prepared for the possibility that
it's not present or working, and (2) it can also be used in sendmsg
control messages, in a manner that looks complex to emulate
completely, and costly even when running on a time64-supporting
kernel.
corresponding changes in recvmmsg are not made at this time; they will
be done separately.
Rich Felker [Tue, 17 Dec 2019 23:19:05 +0000 (18:19 -0500)]
signal to kernel headers that time_t is 64-bit
linux/input.h and perhaps others use this macro to determine whether
the userspace time_t is 64-bit when potentially defining types in
terms of time_t and derived structures. the name __USE_TIME_BITS64 is
unfortunate; it really should have been in the __UAPI namespace. but
this is what was chosen back in v4.16 when first preparing input.h for
time64 userspace, presumably based on expectations about what the
glibc-internal features.h macro for time64 would be, and changing it
now would just put a new minimum version requirement on kernel
headers.
the __USE_TIME_BITS64 macro is not intended as a public interface. it
is purely an internal contract between libc and Linux uapi headers.
Rich Felker [Sun, 8 Dec 2019 15:35:04 +0000 (10:35 -0500)]
fix null pointer dereference in setitimer time32 compat shim
this interface permits a null pointer for where to store the old
itimerval being replaced. an early version of the time32 compat shim
code had corresponding bugs for lots of functions; apparently
setitimer was overlooked when fixing them.
Andre McCurdy [Wed, 18 Sep 2019 06:04:05 +0000 (23:04 -0700)]
arm: avoid conditional branch to PLT in sigsetjmp
The R_ARM_THM_JUMP19 relocation type generated for the original code
when targeting Thumb 2 is not supported by the gold linker.
Ruinland ChuanTzu Tsai [Mon, 2 Dec 2019 11:06:52 +0000 (19:06 +0800)]
riscv64: fix fesetenv(FE_DFL_ENV) crash
When FE_DFL_ENV is passed to fesetenv(), the very first instruction
lw t1, 0(a0) will fail since a0 is -1.
Ada Worcester [Sun, 24 Nov 2019 00:15:38 +0000 (17:15 -0700)]
update contributor name
This changes my name in the COPYRIGHT file, and adds a .mailmap entry
for my new name.
rofl0r [Tue, 5 Nov 2019 21:01:42 +0000 (21:01 +0000)]
ppc: add configure check for older compilers erroring on 'd' constraint
Rich Felker [Tue, 5 Nov 2019 15:15:11 +0000 (10:15 -0500)]
fix build regression on mips64 due to endian.h removal
commit
4d3a162d001a93edd285fb6603a883c30ae553ba overlooked that the
mips64 reloc.h dependent on endian.h not only for setting the ABI ldso
name to match the byte order, but also for use of the byte swapping
macros. they are needed to override R_TYPE, R_SYM, and R_INFO, to
compensate for a mips "quirk" of always using big endian order for
symbol references in relocations.
part of that commit canot be reverted because the original code was
wrong: it's invalid to define _GNU_SOURCE or any feature test macro
in reloc.h, or anywhere except at the top of a source file. however,
thanks to commit
316730cdc7a330cddf288b4e5c1de5daa64e19f4, the feature
test macro is no longer needed to access the endian-swapping macros,
so simply bringing back the #include directive suffices.
Rich Felker [Mon, 4 Nov 2019 06:47:38 +0000 (01:47 -0500)]
fix failure to build time32 compat shims with out-of-tree builds
commit
de90f38e3b105802655d19d965d66335d25d59ef omitted $(srcdir) from
the makefile include pathname it added. since the include directive
was prefixed with - to make it optional (for archs that don't use it),
the failure to find arch/$(ARCH)/arch.mak was silent.
Rich Felker [Sun, 3 Nov 2019 06:19:01 +0000 (01:19 -0500)]
fix time64 link regression of dlsym stub for static-linked programs
in commit
22daaea39f1cc5f7391f0a5cd84576ffb58c2860, the
__dlsym_redir_time64 function providing the backend for __dlsym_time64
was defined only in the dynamic linker, and thus was undefined when
static linking a program referencing dlsym. use the same stub_dlsym
definition that provides __dlsym (the non-redirecting backend) for
static linked programs to provide it, conditional on _REDIR_TIME64.
Rich Felker [Tue, 22 Oct 2019 21:08:56 +0000 (17:08 -0400)]
move time_t and suseconds_t definitions to common alltypes.h.in
now that all 32-bit archs have 64-bit time_t (and suseconds_t), the
arch-provided _Int64 macro (long or long long, as appropriate) can be
used to define them, and arch-specific definitions are no longer
needed.
Rich Felker [Sat, 2 Nov 2019 00:22:41 +0000 (20:22 -0400)]
move time64 ioctl numbers to generic bits/ioctl.h
now that all 32-bit archs have 64-bit time types, the values for the
time-related ioctls can be shared. the mechanism for this is an
arch/generic version of the bits header. archs which don't use the
generic header still need to duplicate the definitions.
x32, which does not use the new time64 values of the macros, already
has its own overrides, so this commit does not affect it.