oweals/musl.git
3 years agofix broken time64 clock_adjtime
Rich Felker [Wed, 3 Jun 2020 00:07:39 +0000 (20:07 -0400)]
fix broken time64 clock_adjtime

the 64-bit time code path used the wrong (time32) syscall. fortunately
this code path is not yet taken unless attempting to set a post-Y2038
time.

3 years agofix unbounded heap expansion race in malloc
Rich Felker [Tue, 2 Jun 2020 21:37:14 +0000 (17:37 -0400)]
fix unbounded heap expansion race in malloc

this has been a longstanding issue reported many times over the years,
with it becoming increasingly clear that it could be hit in practice.
under concurrent malloc and free from multiple threads, it's possible
to hit usage patterns where unbounded amounts of new memory are
obtained via brk/mmap despite the total nominal usage being small and
bounded.

the underlying cause is that, as a fundamental consequence of keeping
locking as fine-grained as possible, the state where free has unbinned
an already-free chunk to merge it with a newly-freed one, but has not
yet re-binned the combined chunk, is exposed to other threads. this is
bad even with small chunks, and leads to suboptimal use of memory, but
where it really blows up is where the already-freed chunk in question
is the large free region "at the top of the heap". in this situation,
other threads momentarily see a state of having almost no free memory,
and conclude that they need to obtain more.

as far as I can tell there is no fix for this that does not harm
performance. the fix made here forces all split/merge of free chunks
to take place under a single lock, which also takes the place of the
old free_lock, being held at least momentarily at the time of free to
determine whether there are neighboring free chunks that need merging.

as a consequence, the pretrim, alloc_fwd, and alloc_rev operations no
longer make sense and are deleted. simplified merging now takes place
inline in free (__bin_chunk) and realloc.

as commented in the source, holding the split_merge_lock precludes any
chunk transition from in-use to free state. for the most part, it also
precludes change to chunk header sizes. however, __memalign may still
modify the sizes of an in-use chunk to split it into two in-use
chunks. arguably this should require holding the split_merge_lock, but
that would necessitate refactoring to expose it externally, which is a
mess. and it turns out not to be necessary, at least assuming the
existing sloppy memory model malloc has been using, because if free
(__bin_chunk) or realloc sees any unsynchronized change to the size,
it will also see the in-use bit being set, and thereby can't do
anything with the neighboring chunk that changed size.

3 years agosuppress unwanted warnings when configuring with clang
Rich Felker [Tue, 2 Jun 2020 00:53:42 +0000 (20:53 -0400)]
suppress unwanted warnings when configuring with clang

coding style warnings enabled by default in clang have long been a
source of spurious questions/bug-reports. since clang provides a -w
that behaves differently from gcc's, and that lets us enable any
warnings we may actually want after turning them all off to start with
a clean slate, use it at configure time if clang is detected.

3 years agorestore lock-skipping for processes that return to single-threaded state
Rich Felker [Fri, 22 May 2020 21:45:47 +0000 (17:45 -0400)]
restore lock-skipping for processes that return to single-threaded state

the design used here relies on the barrier provided by the first lock
operation after the process returns to single-threaded state to
synchronize with actions by the last thread that exited. by storing
the intent to change modes in the same object used to detect whether
locking is needed, it's possible to avoid an extra (possibly costly)
memory load after the lock is taken.

3 years agocut down size of some libc struct members
Rich Felker [Fri, 22 May 2020 21:25:38 +0000 (17:25 -0400)]
cut down size of some libc struct members

these are all flags that can be single-byte values.

3 years agodon't use libc.threads_minus_1 as relaxed atomic for skipping locks
Rich Felker [Fri, 22 May 2020 03:32:45 +0000 (23:32 -0400)]
don't use libc.threads_minus_1 as relaxed atomic for skipping locks

after all but the last thread exits, the next thread to observe
libc.threads_minus_1==0 and conclude that it can skip locking fails to
synchronize with any changes to memory that were made by the
last-exiting thread. this can produce data races.

on some archs, at least x86, memory synchronization is unlikely to be
a problem; however, with the inline locks in malloc, skipping the lock
also eliminated the compiler barrier, and caused code that needed to
re-check chunk in-use bits after obtaining the lock to reuse a stale
value, possibly from before the process became single-threaded. this
in turn produced corruption of the heap state.

some uses of libc.threads_minus_1 remain, especially for allocation of
new TLS in the dynamic linker; otherwise, it could be removed
entirely. it's made non-volatile to reflect that the remaining
accesses are only made under lock on the thread list.

instead of libc.threads_minus_1, libc.threaded is now used for
skipping locks. the difference is that libc.threaded is permanently
true once an additional thread has been created. this will produce
some performance regression in processes that are mostly
single-threaded but occasionally creating threads. in the future it
may be possible to bring back the full lock-skipping, but more care
needs to be taken to produce a safe design.

3 years agoreorder thread list unlink in pthread_exit after all locks
Rich Felker [Fri, 22 May 2020 21:35:14 +0000 (17:35 -0400)]
reorder thread list unlink in pthread_exit after all locks

since the backend for LOCK() skips locking if single-threaded, it's
unsafe to make the process appear single-threaded before the last use
of lock.

this fixes potential unsynchronized access to a linked list via
__dl_thread_cleanup.

3 years agofix incorrect SIGSTKFLT on all mips archs
Rich Felker [Thu, 21 May 2020 17:06:21 +0000 (13:06 -0400)]
fix incorrect SIGSTKFLT on all mips archs

signal 7 is SIGEMT on Linux mips* ABI according to the man pages and
kernel. it's not clear where the wrong name came from but it dates
back to original mips commit.

3 years agohandle possibility that SIGEMT replaces SIGSTKFLT in strsignal
Rich Felker [Thu, 21 May 2020 17:14:40 +0000 (13:14 -0400)]
handle possibility that SIGEMT replaces SIGSTKFLT in strsignal

presently all archs define SIGSTKFLT but this is not correct. change
strsignal as a prerequisite for fixing that.

3 years agofix return value of res_send, res_query on errors from nameserver
Rich Felker [Tue, 19 May 2020 23:25:42 +0000 (19:25 -0400)]
fix return value of res_send, res_query on errors from nameserver

the internal __res_msend returns 0 on timeout without having obtained
any conclusive answer, but in this case has not filled in meaningful
anslen. res_send wrongly treated that as success, but returned a zero
answer length. any reasonable caller would eventually end up treating
that as an error when attempting to parse/validate it, but it should
just be reported as an error.

alternatively we could return the last-received inconclusive answer
(typically servfail), but doing so would require internal changes in
__res_msend. this may be considered later.

3 years agofix handling of errors resolving one of paired A+AAAA query
Rich Felker [Tue, 19 May 2020 23:11:16 +0000 (19:11 -0400)]
fix handling of errors resolving one of paired A+AAAA query

the old logic here likely dates back, at least in inspiration, to
before it was recognized that transient errors must not be allowed to
reflect the contents of successful results and must be reported to the
application.

here, the dns backend for getaddrinfo, when performing a paired query
for v4 and v6 addresses, accepted results for one address family even
if the other timed out. (the __res_msend backend does not propagate
error rcodes back to the caller, but continues to retry until timeout,
so other error conditions were not actually possible.)

this patch moves the checks to take place before answer parsing, and
performs them for each answer rather than only the answer to the first
query. if nxdomain is seen it's assumed to apply to both queries since
that's how dns semantics work.

3 years agoset AD bit in dns queries, suppress for internal use
Rich Felker [Tue, 19 May 2020 01:17:34 +0000 (21:17 -0400)]
set AD bit in dns queries, suppress for internal use

the AD (authenticated data) bit in outgoing dns queries is defined by
rfc3655 to request that the nameserver report (via the same bit in the
response) whether the result is authenticated by DNSSEC. while all
results returned by a DNSSEC conforming nameserver will be either
authenticated or cryptographically proven to lack DNSSEC protection,
for some applications it's necessary to be able to distinguish these
two cases. in particular, conforming and compatible handling of DANE
(TLSA) records requires enforcing them only in signed zones.

when the AD bit was first defined for queries, there were reports of
compatibility problems with broken firewalls and nameservers dropping
queries with it set. these problems are probably a thing of the past,
and broken nameservers are already unsupported. however, since there
is no use in the AD bit with the netdb.h interfaces, explicitly clear
it in the queries they make. this ensures that, even with broken
setups, the standard functions will work, and at most the res_*
functions break.

3 years agofix undefined behavior from signed overflow in strstr and memmem
Rich Felker [Fri, 1 May 2020 01:36:43 +0000 (21:36 -0400)]
fix undefined behavior from signed overflow in strstr and memmem

unsigned char promotes to int, which can overflow when shifted left by
24 bits or more. this has been reported multiple times but then
forgotten. it's expected to be benign UB, but can trap when built with
explicit overflow catching (ubsan or similar). fix it now.

note that promotion to uint32_t is safe and portable even outside of
the assumptions usually made in musl, since either uint32_t has rank
at least unsigned int, so that no further default promotions happen,
or int is wide enough that the shift can't overflow. this is a
desirable property to have in case someone wants to reuse the code
elsewhere.

4 years agoremove arm (32-bit) support for vdso clock_gettime
Rich Felker [Sun, 26 Apr 2020 20:47:49 +0000 (16:47 -0400)]
remove arm (32-bit) support for vdso clock_gettime

it's been reported that the vdso clock_gettime64 function on (32-bit)
arm is broken, producing erratic results that grow at a rate far
greater than one reported second per actual elapsed second. the vdso
function seems to have been added sometime between linux 5.4 and 5.6,
so if there's ever been a working version, it was only present for a
very short window.

it's not clear what the eventual upstream kernel solution will be, but
something needs to be done on the libc side so as not to be producing
binaries that seem to work on older/existing/lts kernels (which lack
the function and thus lack the bug) but will break fantastically when
moving to newer kernels.

hopefully vdso support will be added back soon, but with a new symbol
name or version from the kernel to allow continued rejection of broken
ones.

4 years agofix undefined behavior in wcsto[ld] family functions
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.

4 years agofix sh fesetround failure to clear old mode
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.

4 years agomove __string_read into vsscanf source file
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.

4 years agoremove spurious repeated semicolon in fmemopen
Rich Felker [Fri, 17 Apr 2020 20:11:43 +0000 (16:11 -0400)]
remove spurious repeated semicolon in fmemopen

4 years agocombine two calls to memset 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.

4 years agofix possible access to uninitialized memory in shgetc (via scanf)
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.

4 years agofix undefined behavior in scanf core
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.

4 years agomath: add x86_64 remquol
Alexander Monakov [Thu, 16 Jan 2020 20:58:13 +0000 (23:58 +0300)]
math: add x86_64 remquol

4 years agomath: move x87-family fmod functions to C with inline asm
Alexander Monakov [Wed, 15 Jan 2020 15:42:46 +0000 (18:42 +0300)]
math: move x87-family fmod functions to C with inline asm

4 years agomath: move x87-family remainder 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

4 years agomath: move x87-family rint 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

4 years agomath: move x87-family lrint 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

4 years agomath: move x86_64 (l)lrint(f) 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

4 years agomath: move i386 sqrt 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

4 years agomath: move i386 sqrtf 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

4 years agomath: move trivial x86-family sqrt functions 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

4 years agomath: move x87-family fabs 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

4 years agomath: move x86_64 fabs, fabsf 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

4 years agofix parsing offsets after long timezone names
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.

4 years agoavoid out-of-bounds read for invalid quoted timezone
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.

4 years agoremove redundant condition in memccpy
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.

4 years agoldso: remove redundant switch case for REL_NONE
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.

4 years agodefine MAP_SYNC on powerpc/powerpc64
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.

4 years agoimprove strerror speed
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).

4 years agofix corrupt sysvipc timestamps on 32-bit archs with old kernels
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.

4 years agowork around negated error code bug on some mips kernels
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.

4 years agoremove useless mips syscall asm constraint, align style with mips64/n32
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.

4 years agorevert mips (32-bit, o32) syscall asm clean-up due to regressions
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.

4 years agorevert mips64/n32 syscall asm clean-up due to regressions
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.

4 years agoremove duplicate definitions of INET[6]_ADDRSTRLEN
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.

4 years agoadd PTHREAD_NULL
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.

4 years agouse __socketcall to simplify socket()
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

4 years agoremove wrap_write helper from vdprintf
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.

4 years agomath: fix sinh overflows in non-nearest rounding
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.

4 years agomath: fix __rem_pio2 in non-nearest rounding modes
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.

4 years agorelease 1.2.0 v1.2.0
Rich Felker [Fri, 21 Feb 2020 00:37:02 +0000 (19:37 -0500)]
release 1.2.0

4 years agofix remaining direct use of stat syscalls outside fstatat.c
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.

4 years agoremove i386 asm for single and double precision exp-family functions
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.

4 years agorename i386 exp.s to exp_ld.s
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.

4 years agofix excess precision in return value of i386 log-family functions
Rich Felker [Thu, 6 Feb 2020 18:29:45 +0000 (13:29 -0500)]
fix excess precision in return value of i386 log-family functions

4 years agofix excess precision in return value of i386 acos[f] and asin[f]
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].

4 years agofix excess precision in return value of i386 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.

4 years agoremove legacy time32 timer[fd] syscalls from public syscall.h
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.

4 years agoremove further legacy time32 clock syscalls from public syscall.h
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.

4 years agofix incorrect results for catanf and catanl with some inputs
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.

4 years agomove riscv64 register index constants to signal.h
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.

4 years agoremove legacy clock_gettime and gettimeofday from public syscall.h
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.

4 years agofix misleading use of _POSIX_VDISABLE in sys/ttydefaults.h
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.

4 years agofix unprotected macro argument in sys/ttydefaults.h
Rich Felker [Wed, 29 Jan 2020 15:47:19 +0000 (10:47 -0500)]
fix unprotected macro argument in sys/ttydefaults.h

4 years agomath/x32: correct lrintl.s for 32-bit long
Alexander Monakov [Sat, 18 Jan 2020 16:15:16 +0000 (19:15 +0300)]
math/x32: correct lrintl.s for 32-bit long

4 years agomove struct dirent to bits header, allow NAME_MAX to vary
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.

4 years agofix riscv64 a_cas inline asm operand sign extension
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.

4 years agofix incorrect escaping in add-cfi.*.awk scripts
Will Dietz [Wed, 8 Jan 2020 19:20:44 +0000 (13:20 -0600)]
fix incorrect escaping in add-cfi.*.awk scripts

gawk 5 complains.

4 years agoadd thumb2 support to arm assembler memcpy
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.

4 years agofix incorrect __hwcap seen in dynamic-linked __set_thread_area
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.

4 years agodefine RLIMIT_RTTIME, bump RLIMIT_NLIMITS
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.

4 years agofix wcwidth wrongly returning 0 for most of planes 4 and up
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.

4 years agounconditonally define alloca as __builtin_alloca
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.

4 years agoupdate COPYRIGHT year
Rich Felker [Wed, 1 Jan 2020 16:13:51 +0000 (11:13 -0500)]
update COPYRIGHT year

4 years agoremove gratuitous aligned attribute from __ptrace_syscall_info
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.

4 years agofix fdpic regression in dynamic linker with overly smart compilers
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.

4 years agofix crashing ldso on archs where __set_thread_area examines auxv
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.

4 years agomove stage3_func typedef out of shared internal dynlink.h header
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.

4 years agomips: add clone3 syscall numbers from linux v5.4
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

4 years agomips: add hwcap bits from linux v5.4
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

4 years agosys/wait.h: add P_PIDFD from linux v5.4
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()

4 years agonetinet/tcp.h: add new tcp_info fields from linux v5.4
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

4 years agosys/prctl.h: add PR_*_TAGGED_ADDR_* from linux v5.4
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

4 years agosys/mman.h: add MADV_COLD and MADV_PAGEOUT from linux v5.4
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

4 years agoadd clone3 syscall number from linux v5.3
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

4 years agoadd pidfd_open syscall number from linux v5.3
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()

4 years agosys/ptrace.h: add PTRACE_GET_SYSCALL_INFO from linux v5.3
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.

4 years agosys/socket.h: add SO_DETACH_REUSEPORT_BPF from linux v5.3
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

4 years agonetinet/if_ether.h: add ETH_P_LLDP from linux v5.3
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

4 years agonetinet/tcp.h: add TCP_TX_DELAY from linux v5.3
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

4 years agofix types for mips sigcontext/mcontext_t regset members
Khem Raj [Wed, 18 Dec 2019 22:02:37 +0000 (14:02 -0800)]
fix types for mips sigcontext/mcontext_t regset members

4 years agospare archs without time32 legacy the cost of ioctl fallback conversions
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.

4 years agoadd further ioctl time64 fallback conversion for device-specific command
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.

4 years agoadd uapi guards for new netinet/ip.h conflict with struct iphdr
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.

4 years agoadjust utmpx struct layout for time64, 32-/64-bit arch compat
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.

4 years agofix elf_prstatus regression on time64, existing wrong definition on x32
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.

4 years agodon't continue looping through ioctl compat_map after finding match
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.

4 years agorevert unwanted and inadvertent change that slipped into mmap.c
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.

4 years agoadd further ioctl time64 fallback conversions
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.

4 years agoimprove ioctl time64 conversion fallback framework
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.

4 years agoconvert ioctl time64 fallbacks to table-driven framework
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.