Commit Graph

4945 Commits

Author SHA1 Message Date
Rich Felker dd1e63c363 syslog: revert LOG_FAC/LOG_FACMASK changes
commit 895736d49b made these changes
along with fixing a real bug in LOG_MAKEPRI. based on further
information, they do not seem to be well-motivated or in line with
policy.

the result of LOG_FAC is not a meaningful facility value if we shift
it down like before, but apparently the way it is used by applications
is as an index into an array of facility names. moreover, all
historical systems which define it do so with the shift. as it is a
nonstandard interface, there is no justification for providing a macro
by the same name that is incompatible with historical practice.

the value of LOG_FACMASK likewise is 0x3f8 on all historical systems
checked. while only 5 bits are used for existing facility codes, the
convention seems to be that all 7 bits belong to the facility field
and theoretically could be used to expand to having more facilities.
that seems unlikely to happen, but there is no reason to make a
gratuitously incompatible change here.
2024-07-05 13:22:25 -04:00
Rich Felker 008f737ddf siglongjmp: document why this function just calls longjmp 2024-06-23 20:52:53 -04:00
Jakub Stasiak 947b4574fa inet_ntop: fix the IPv6 leading zero sequence compression
Per RFC 5952, ties for longest sequence of zero fields must be broken
by choosing the earliest, but the implementation put the leading
sequence of zeros at a disadvantage. That's because for example when
compressing "0:0:0:10:0:0:0:10" the strspn(buf+i, ":0") call returns 6
for the first sequence and 7 for the second one – the second sequence
has the benefit of a leading colon.

Changing the condition to require beating the leading sequence by not
one but two characters resolves the issue.
2024-06-22 17:01:00 -04:00
Rich Felker 50ab830633 dynlink: avoid copying to temp buffer in get_lfs64
while commit 53ac44ff4c fixed the temp
buffer being undersized, the use of a temp buffer to begin with was a
mistake. instead, compare the requested symbol name in-place and use
the already-null-terminated copy of the name without "64" present in
lfs64_list[] to look up the real symbol.
2024-06-22 16:54:11 -04:00
Joe Damato 1b97d0060b sys/epoll.h: add epoll ioctls
add two ioctls to get and set struct epoll_params to allow users to
control epoll based busy polling of network sockets.

added to uapi in commit 18e2bf0edf4dd88d9656ec92395aa47392e85b61 (Linux
kernel 6.9 and newer).
2024-06-22 16:53:06 -04:00
Rich Felker ab31e9d6a0 getusershell: skip blank lines and comments
this interface does not have a lot of historical consensus on how it
handles the contents of the /etc/shells file in regard to whitespace
and comments, but the commonality between all checked is that they
ignore lines that are blank or that begin with '#', so that is the
behavior we adopt.
2024-06-21 20:54:30 -04:00
Florian Ziesche 53ac44ff4c dynlink: fix get_lfs64() with posix_fallocate64
"posix_fallocate64" is 17 characters long, so 16 is one too short.
2024-06-20 22:44:35 -04:00
Rich Felker 895736d49b syslog: fix incorrect LOG_MAKEPRI and LOG_FAC[MASK] macros
these are nonstandard and unnecessary for using the associated
functionality, but resulted in applications that used them
malfunctioning.

patch based on proposed fix by erny hombre.
2024-06-13 11:48:40 -04:00
Tony Ambardar 05ce67fea9 add renameat2 linux syscall wrapper
This syscall is available since Linux 3.15 and also implemented in
glibc from version 2.28. It is commonly used in filesystem or security
contexts.

Constants RENAME_NOREPLACE, RENAME_EXCHANGE, RENAME_WHITEOUT are
guarded by _GNU_SOURCE as with glibc.
2024-05-23 09:13:49 -04:00
Rich Felker 0079972992 fix mismatched type in posix_getdents definition
commit 1b0d48517f wrongly copied the
getdents return type of int rather than matching the ssize_t used by
posix_getdents. this was overlooked in testing on 32-bit archs but
obviously broke 64-bit archs.
2024-05-12 15:33:15 -04:00
mojyack cbf59dd662 aarch64 crti.o: fix alignment of _init/_fini
without explicit alignment directives, whether they end up at the
necessary alignment depends on linker/linking conditions. initially
reported as mold issue 1255.
2024-05-12 12:17:13 -04:00
Gonzalo Alvarez 84015cee17 fix typo that broke sys/reg.h and sys/user.h
commit 7019fbe103 and commit
e709a6f07a misspelled bits/alltypes.h.
2024-05-11 17:52:04 -04:00
Rich Felker 1b0d48517f implement posix_getdents adopted for next issue of POSIX
this interface was added as the outcome of Austin Group tracker issue
697. no error is specified for unsupported flags, which is probably an
oversight. for now, EOPNOTSUPP is used so as not to overload EINVAL.
2024-05-08 08:50:03 -04:00
Rich Felker 2c124e13bd stdint.h: derive limits from __LONG_MAX, use common fast16 types
the bits file is retained, but as a single generic version, to allow
for the unlikely future possibility of letting a new arch define
something differently.
2024-05-07 09:17:51 -04:00
Rich Felker 7019fbe103 sys/user.h: derive __WORDSIZE from __LONG_MAX
previously, only a few archs defined it here. this change makes the
presence consistent across all archs, and reduces the amount of header
duplication (and potential for future inconsistency) between archs.
2024-05-07 09:11:10 -04:00
Rich Felker e709a6f07a sys/reg.h: derive __WORDSIZE from __LONG_MAX
this removes an otherwise-unnecessary bits header from most archs,
replacing it with an empty generic version.
2024-05-07 09:08:31 -04:00
Rich Felker 29b216b2f2 unistd.h: derive ILP32/LP64 macros from __LONG_MAX instead of arch bits 2024-05-07 09:01:47 -04:00
Rich Felker 0dfa1d8caa unify bits/stat.h for all archs sharing a common definition
future archs should not define their own bits/stat.h but use this
generic one.
2024-05-07 08:58:45 -04:00
Rich Felker ef600888d2 align aarch64, riscv64, loongarch64 stat structure padding type
this change is purely to document that they are the same in
preparation to remove the arch-specific headers for these archs and
replace them with a generic version that matches riscv32 and can be
shared by these and all future archs.
2024-05-07 08:55:55 -04:00
Rich Felker 6f666231bf ldso: fix non-functional fix to early dynamic PAGE_SIZE access
commit f47a8cdd25 introduced an
alternate mechanism for access to runtime page size for compatibility
with early stages of dynamic linking, but because pthread_impl.h
indirectly includes libc.h, the condition #ifndef PAGE_SIZE was never
satisfied.

rather than depend on order of inclusion, use the (baseline POSIX)
macro PAGESIZE, not the (XSI) macro PAGE_SIZE, to determine whether
page size is dynamic. our internal libc.h only provides a dynamic
definition for PAGE_SIZE, not for PAGESIZE.
2024-05-07 08:32:11 -04:00
Rich Felker fced99e93d strptime: implement conversion specifiers adopted for next POSIX issue
the %s conversion is added as the outcome of Austin Group tracker
issue 169 and its unspecified behavior is clarified as the outcome of
issue 1727.

the %F, %g, %G, %u, %V, %z, and %Z conversions are added as the
outcome of Austin Group tracker issue 879 for alignment with strftime
and the behaviors of %u, %z, and %Z are defined as the outcome of
issue 1727.

at this time, the conversions with unspecified effects on struct tm
are all left as parse-only no-ops. this may be changed at a later
time, particularly for %s, if there is reasonable cross-implementation
consensus outside the standards process on what the behavior should
be.
2024-05-06 19:04:55 -04:00
Rich Felker 3f9d4224d8 printf decimal integer formatting: shave off one division
once the remaining value is less than 10, the modulo operation to
produce the final digit and division to prepare for next loop
iteration can be dropped. this may be a meaningful performance
distinction when formatting low-magnitude numbers in bulk, and should
never hurt.

based on patch by Viktor Reznov.
2024-05-06 17:13:23 -04:00
Michael Forney a23cf8f9c5 riscv mcontext_t/sigcontext: use __aligned__ instead of aligned
aligned may be defined by the application for its own use before
bits/signal.h is included.
2024-05-06 10:59:12 -04:00
Rich Felker cbf1c7b605 add missing STATX_ATTR_* macros omitted when statx was added
commit b817541f1c added statx and the
mask constant macros, but not the stx_attributes[_mask] ones.
2024-04-24 13:26:03 -04:00
Rich Felker 3f49203c55 initgroups: do not artificially limit number of supplementary groups
historically linux limited the number of supplementary groups a
process could be in to 32, but this limit was raised to 65536 in linux
2.6.4. proposals to support the new limit, change NGROUPS_MAX, or make
it dynamic have been stalled due to the impact it would have on
initgroups where the groups array exists in automatic storage.

the changes here decouple initgroups from the value of NGROUPS_MAX and
allow it to fall back to allocating a buffer in the case where
getgrouplist indicates the user has more supplementary groups than
could be reported in the buffer. getgrouplist already involves
allocation, so this does not pull in any new link dependency.
likewise, getgrouplist is already using the public malloc (vs internal
libc one), so initgroups does the same. if this turns out not to be
the best choice, both can be changed together later.

the initial buffer size is left at 32, but now as the literal value,
so that any potential future change to NGROUPS_MAX will not affect
initgroups.
2024-04-13 23:05:46 -04:00
Rich Felker 24ebbbdedc printf: fix edge case where hex float precision was not honored
commit cfa0a54c08 attempted to fix
rounding on archs where long double is not 80-bit (where LDBL_MANT_DIG
is not zero mod four), but failed to address the edge case where
rounding was skipped because LDBL_MANT_DIG/4 rounded down in the
comparison against the requested precision.

the rounding logic based on hex digit count is difficult to understand
and not well-motivated, so rather than try to fix it, replace it with
an explicit calculation in terms of number of bits to be kept, without
any truncating division operations. based on patch by Peter Ammon, but
with scalbn to apply the rounding exponent since the value will not
generally fit in any integer type. scalbn is used instead of scalbnl
to avoid pulling in the latter unnecessarily, since the value is an
exact power of two whose exponent range is bounded by LDBL_MANT_DIG, a
small integer.
2024-04-12 19:57:59 -04:00
Szabolcs Nagy e3b0ace505 complex: fix comment in cacosh
The principal expressions defining acosh and acos are such that

  acosh(z) = ±i acos(z)

where the + is only true on the Im(z)>0 half of the complex plane
(and partly on Im(z)==0 depending on number representation).

fix the comment without expanding on the details.
2024-03-14 10:06:15 -04:00
Szabolcs Nagy 9683bd6241 math: fix fma(x,y,0) when x*y rounds to -0
if x!=0, y!=0, z==0 then

  fma(x,y,z) == x*y

in all rounding modes, while adding z can ruin the sign of 0 if x*y
rounds to -0.
2024-03-14 10:04:42 -04:00
Rich Felker 5370070fde fix pwrite/pwritev handling of O_APPEND files
POSIX requires pwrite to honor the explicit file offset where the
write should take place even if the file was opened as O_APPEND.
however, linux historically defined the pwrite syscall family as
honoring O_APPEND. this cannot be changed on the kernel side due to
stability policy, but the addition of the pwritev2 syscall with a
flags argument opened the door to fixing it, and linux commit
73fa7547c70b32cc69685f79be31135797734eb6 adds the RWF_NOAPPEND flag
that lets us request a write honoring the file offset argument.

this patch changes the pwrite function to first attempt using the
pwritev2 syscall with RWF_NOAPPEND, falling back to using the old
pwrite syscall only after checking that O_APPEND is not set for the
open file. if O_APPEND is set, the operation fails with EOPNOTSUPP,
reflecting that the kernel does not support the correct behavior. this
is an extended error case needed to avoid the wrong behavior that
happened before (writing the data at the wrong location), and is
aligned with the spirit of the POSIX requirement that "An attempt to
perform a pwrite() on a file that is incapable of seeking shall result
in an error."

since the pwritev2 syscall interprets the offset of -1 as a request to
write at the current file offset, it is mapped to a different negative
value that will produce the expected error.

pwritev, though not governed by POSIX at this time, is adjusted to
match pwrite in honoring the offset.
2024-03-14 10:04:28 -04:00
Rich Felker bdc9a9ff6f uio.h: add RWF_NOAPPEND flag for pwritev2
added in linux kernel commit 73fa7547c70b32cc69685f79be31135797734eb6.

this is added now as a prerequisite for fixing pwrite/pwritev behavior
for O_APPEND files.
2024-03-13 10:39:37 -04:00
Rich Felker 7ada6dde6f iconv: fix missing bounds checking for shift_jis decoding
the jis0208 table we use is only 84x94 in size, but the shift_jis
encoding supports a 94x94 grid. attempts to convert sequences outside
of the supported zone resulted in out-of-bounds table reads,
misinterpreting adjacent rodata as part of the character table and
thereby converting these sequences to unexpected characters.
2024-03-02 22:17:49 -05:00
Rich Felker fd7d018521 add missing inline keyword on default a_barrier definition
this is not needed, but may act as a hint to the compiler, and also
serves to suppress unused function warnings if enabled (on by default
since commit 86ac0f7947).
2024-03-02 12:34:05 -05:00
Rich Felker b5121e2ed8 iconv: add aliases for GBK
these are taken from the IANA registry, restricted to those that match
the forms already used for other supported character encodings.
2024-03-01 16:04:48 -05:00
Rich Felker ca6f46aff1 iconv: add euro symbol to GBK as single byte 0x80
this is how it's defined in the cp936 document referenced by the IANA
charset registry as defining GBK, and of the mappings defined there,
was the only one missing.

it is not accepted for GB18030, as GB18030 is a UTF and has its own
unique mapping for the euro symbol.
2024-03-01 15:49:58 -05:00
Rich Felker 0784374d56 release 1.2.5 2024-02-29 21:07:33 -05:00
Rich Felker f5dba42f36 iconv: add cp932 as an alias for shift_jis 2024-02-29 20:40:03 -05:00
Rich Felker e5aa498451 update INSTALL file archs list with riscv32, loongarch64 additions 2024-02-29 19:23:03 -05:00
wanghongliang 8d9d266573 loongarch64: add new syscall numbers 2024-02-29 17:33:45 -05:00
Rich Felker 8d852cdacd loongarch64: remove getrlimit/setrlimit syscall numbers
these are not supported by the kernel for new archs; prlimit64
replaces them.
2024-02-29 17:32:27 -05:00
wanghongliang 13cd64af31 loongarch64: remove ptrace.h macros 2024-02-29 17:30:11 -05:00
Stefan O'Rear 377c363fb5 configure: enable riscv32 port 2024-02-29 16:59:06 -05:00
Khem Raj d25f0cccb9 riscv: define REG_S1 and REG_S2
These are used by applications to access members of mcontext, and are
also defined by other libcs on linux.
2024-02-29 16:36:55 -05:00
Khem Raj 8432d16a46 riscv32: add new syscall numbers
- add mount_setattr from linux v5.12
- add epoll_pwait2 from linux v5.11
- add process_madvise from linux v5.10
- add __NR_faccessat2 from linux v5.8
- add pidfd_getfd and openat2 syscall numbers from linux v5.6
- add clone3 syscall number from linux v5.3
- add process_mrelease from linux v5.15
- add futex_waitv from linux v5.16
- add set_mempolicy_home_node from linux v5.17
- add cachestat from linux v6.4
- add __NR_fchmodat2 from linux v6.6
2024-02-29 16:36:55 -05:00
Rich Felker 3ea3fcf78a riscv32: add sysvipc msg/sem/shm bits
despite riscv32 being natively time64, the IPC_TIME64 bit (0x100) is
set in IPC_STAT and derived command macros, differentiating their
values from the raw command values used to interface with the kernel.
this reflects that the kernel ipc structure types are not natively
time64, but have broken-down hi/lo fields that cannot be used in-place
and require translation, and that the userspace struct types differ
from the kernel types (relevant to things like strace).
2024-02-29 16:36:55 -05:00
Stefan O'Rear b28c44de8c riscv32: add thread support
Identical to riscv64 except for stack offsets in clone.
2024-02-29 16:36:55 -05:00
Stefan O'Rear c34a8eedff riscv32: add setjmp/longjmp and sigreturn
Largely copied from riscv64 but required recalculation of offsets.
2024-02-29 16:36:55 -05:00
Stefan O'Rear 11eee89e14 riscv32: add dlsym
Identical to riscv64.
2024-02-29 16:36:55 -05:00
Stefan O'Rear b4f7b2ca35 riscv32: add fenv and math
These are identical to riscv64.
2024-02-29 16:36:55 -05:00
Stefan O'Rear 01d9fe4d9f riscv32: add arch headers
These are mostly copied from riscv64. _Addr and _Reg had to become int
to match compiler-controlled parts of the ABI (result type of sizeof,
etc.). There is no kernel stat struct; the userspace stat matches
glibc in the sizes and offsets of all fields (including glibc's
__dev_t __pad1). The jump buffer is 12 words larger to account for 12
saved double-precision floats; additionally it should be 64-bit
aligned to save doubles.

The syscall list was significantly revised by deleting all time32 and
pre-statx syscalls, and renaming several syscalls that have different
names depending on __BITS_PER_LONG, notably mmap2 and _llseek.

futex was added as an alias to futex_time64 since it is widely used by
software which does not pass time arguments.
2024-02-29 16:35:30 -05:00
Alexey Izbyshev 5c653ccaa1 getnameinfo: fix calling __dns_parse with potentially too large rlen
__res_send returns the full answer length even if it didn't fit the
buffer, but __dns_parse expects the length of the filled part of the
buffer.

This is analogous to commit 77327ed064,
which fixed the only other __dns_parse call site.
2024-02-29 10:14:16 -05:00