Commit Graph

1866 Commits

Author SHA1 Message Date
Joseph Myers 096fcdc0a5 Rename uimaxabs to umaxabs (bug 33325)
The C2y function uimaxabs has been renamed to umaxabs.  Implement this
change in glibc, keeping a compat symbol under the old name, copying
the test to test the new name and changing the old test to test the
compat symbol.  Jakub has done the corresponding change to the
built-in function in GCC.

Tested for x86_64 and x86.
2025-10-28 12:15:02 +00:00
Adhemerval Zanella 917425ca6d posix: Defined _POSIX_VDISABLE as integer literal
The constant should be used with c_cc, which for all supported ABIs
is defined as unsigned char.  By using it as literar char constant,
clang triggers an error when compared with signal literal on ABIs that
define 'char' as unsigned.

On aarch64, clang shows:

  ../sysdeps/posix/fpathconf.c:118:21: error: right side of operator
  converted from negative value to unsigned: -1 to 18446744073709551615
  [-Werror]
  #if _POSIX_VDISABLE == -1
    ~~~~~~~~~~~~~~~ ^  ~~

Reviewed-by: Collin Funk <collin.funk1@gmail.com>
2025-10-20 11:33:54 -03:00
Joseph Myers ea18d5a4c2 Implement C23 memalignment
Add the C23 memalignment function (query the alignment of a pointer)
to glibc.

Given how simple this operation is, it would make sense for compilers
to inline calls to this function, but I'm treating that as a compiler
matter (compilers should add it as a built-in function) rather than
adding an inline version to glibc headers (although such an inline
version would be reasonable as well).  I've filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122117 for this feature
in GCC.

Tested for x86_64 and x86.
2025-10-17 16:56:59 +00:00
Joseph Myers 0f201f4a81 Implement C23 memset_explicit (bug 32378)
Add the C23 memset_explicit function to glibc.  Everything here is
closely based on the approach taken for explicit_bzero.  This includes
the bits that relate to internal uses of explicit_bzero within glibc
(although we don't currently have any such internal uses of
memset_explicit), and also includes the nonnull attribute (when we
move to nonnull_if_nonzero for various functions following C2y, this
function should be included in that change).

The function is declared both for __USE_MISC and for __GLIBC_USE (ISOC23)
(so by default not just for compilers defaulting to C23 mode).

Tested for x86_64 and x86.
2025-10-01 15:14:09 +00:00
Samuel Thibault 81a6e97791 hurd: Note BZ #30166 as fixed
802b0eba51 ("hurd: implement RLIMIT_AS against Mach RPCs") brought the
needed RLIMIT_AS support for memory-crunchy tests.
2025-09-22 02:17:50 +02:00
Diego Nieto Cid 802b0eba51 hurd: implement RLIMIT_AS against Mach RPCs
Check for VM limit RPCs

  * config.h.in: add #undef for HAVE_MACH_VM_GET_SIZE_LIMIT and
    HAVE_MACH_VM_SET_SIZE_LIMIT.
  * sysdeps/mach/configure.ac: use mach_RPC_CHECK to check for
    vm_set_size_limit and vm_get_size_limit RPCs in gnumach.defs.
  * sysdeps/mach/configure: regenerate file.

Use vm_get_size_limit to initialize RLIMIT_AS

  * hurd/hurdrlimit.c(init_rlimit): use vm_get_size_limit to initialize
    RLIMIT_AS entry of the _hurd_rlimits array.

Notify the kernel of the new VM size limits

  * sysdeps/mach/hurd/setrlimit.c: use the vm_set_size_limit RPC,
    if available, to notify the kernel of the new limits. Retry RPC
    calls if they were interrupted by a signal.
Message-ID: <03fb90a795b354a366ee73f56f73e6ad22a86cda.1755220108.git.dnietoc@gmail.com>
2025-09-22 00:52:37 +02:00
Samuel Thibault c9cc047e9f hurd: catch SIGSEGV on returning from signal handler
On stack overflow typically, we may not actually have room on the stack to
trampoline back from the signal handler.  We have to detect this before
locking the ss, otherwise the signal thread will be stuck on taking the
ss lock while trying to post SIGSEGV.
2025-09-21 23:45:40 +02:00
Cupertino Miranda 3b2b88ccee elf: early conversion of elf p_flags to mprotect flags
This patch replaces _dl_stack_flags global variable by
_dl_stack_prot_flags.
The advantage is that any convertion from p_flags to final used mprotect
flags occurs at loading of p_flags. It avoids repeated spurious
convertions of _dl_stack_flags, for example in allocate_thread_stack.

This modification was suggested in:
  https://sourceware.org/pipermail/libc-alpha/2025-March/165537.html

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-08-27 10:45:45 -03:00
gfleury 098e449df0 htl: move sem_unlink into libc.
Message-ID: <20250817104023.91919-8-gfleury@disroot.org>
2025-08-18 01:06:41 +02:00
gfleury f5a43420e2 htl: move sem_{clockwait, timedwait, wait, trywait} into libc.
Message-ID: <20250817104023.91919-7-gfleury@disroot.org>
2025-08-18 01:06:38 +02:00
gfleury 795f5f2a8b htl: move sem_post into libc.
Message-ID: <20250817104023.91919-6-gfleury@disroot.org>
2025-08-18 00:55:33 +02:00
gfleury 50f5ddc20a htl: move sem_open, sem_close into libc.
Message-ID: <20250817104023.91919-5-gfleury@disroot.org>
2025-08-18 00:55:18 +02:00
gfleury b2b6d32f11 htl: move sem_init into libc.
Message-ID: <20250817104023.91919-4-gfleury@disroot.org>
2025-08-18 00:23:11 +02:00
gfleury 11c07af422 htl: move sem_getvalue into libc.
Message-ID: <20250817104023.91919-3-gfleury@disroot.org>
2025-08-18 00:22:53 +02:00
gfleury c2560a0c56 htl: move sem_destroy into libc.
Message-ID: <20250817104023.91919-2-gfleury@disroot.org>
2025-08-18 00:22:43 +02:00
gfleury 80412aee3e htl: move __pthread_setup into libc.
Message-ID: <20250815181500.107433-19-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury b6616efe8c htl: move pthread_{join, clockjoin_np, timedjoin_np, tryjoin_np} into libc.
Message-ID: <20250815181500.107433-18-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 36982b0fdb htl: move pthread_exit into libc.
Message-ID: <20250815181500.107433-17-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury a901f2599e htl: move pthread_detach into libc.
Message-ID: <20250815181500.107433-16-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury d0667a77de htl: move __pthread_sigstate_init into libc.
Message-ID: <20250815181500.107433-15-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury f6a47e2d61 htl: move pthread_mutex_transfer_np into libc.
Message-ID: <20250815181500.107433-14-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 1e6588e777 htl: move pthread_getattr_np into libc.
Message-ID: <20250815181500.107433-13-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 6541288cb5 htl: move pthread_testcancel into libc.
Message-ID: <20250815181500.107433-12-gfleury@disroot.org>
2025-08-16 01:44:50 +02:00
gfleury edcc9ca48c htl: move pthread_kill into libc.
Message-ID: <20250815181500.107433-11-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury de8351f4de htl: move pthread_cancel, __pthread_do_cancel into libc.
Message-ID: <20250815181500.107433-10-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury e0b765d9ba htl: move __thread_set_pcsptp into libc.
Message-ID: <20250815181500.107433-9-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury 2dcb8fb8e7 htl: move pthread_yield into libc.
Message-ID: <20250815181500.107433-8-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury fa35ccbba8 htl: move pthread_getcpuclockid into libc.
Message-ID: <20250815181500.107433-7-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury c3abc99cb0 htl: move __pthread_thread_{alloc, start, terminate} into libc.
Message-ID: <20250815181500.107433-6-gfleury@disroot.org>
2025-08-16 01:44:26 +02:00
gfleury 450912d5db htl: move __pthread_stack_alloc into libc.
Message-ID: <20250815181500.107433-5-gfleury@disroot.org>
2025-08-16 01:15:37 +02:00
gfleury b586357e2a htl: move pthread_get/setconcurrency into libc.
Message-ID: <20250815181500.107433-3-gfleury@disroot.org>
2025-08-16 01:12:21 +02:00
gfleury d479e71498 htl: move pthread_setschedprio into libc.
Message-ID: <20250815181500.107433-2-gfleury@disroot.org>
2025-08-16 01:11:21 +02:00
Samuel Thibault 6afece738c htl: move __pthread_get_cleanup_stack to libc
This fixes the cleanup call from __qsort_r
2025-07-06 19:56:15 +00:00
Samuel Thibault 21cbe4a588 hurd: Mark more xfails for missing RLIMIT_AS support 2025-07-05 11:13:46 +02:00
Collin Funk b3b0d0308c hurd: Remove a duplicate entry from 'tests-unsupported'.
When building on GNU/Hurd the following warnings repeat themselves:

    ../Rules:400: target '/home/collin/obj/glibc/io/test-lfs.out' given more than once in the same rule
    ../Rules:400: target '/home/collin/obj/glibc/io/test-lfs.out' given more than once in the same rule

This is because commit 73b854e955 (hurd: Mark more memory-hungry tests
as unsupported, 2025-01-12) added it to 'tests-unsupported' even though
it was already added by decf02d382 (hurd: Mark two tests as unsupported,
2023-04-13).
Message-ID: <54dc6bf7e0dbedb1b19356f41fec843c1c523b11.1750130025.git.collin.funk1@gmail.com>
2025-06-21 14:46:53 +02:00
Collin Funk 5071149e89 hurd: Fix redefinition of 'P2ALIGN'.
When building on GNU/Hurd warnings like the following occur:

    ../sysdeps/x86_64/multiarch/strnlen-evex-base.S:53:10: warning: "P2ALIGN" redefined
       53 | # define P2ALIGN(...)   .p2align 4,, 6
          |          ^~~~~~~
    In file included from /usr/include/x86_64-gnu/mach/x86_64/syscall_sw.h:30,
                     from ../sysdeps/mach/sysdep.h:21,
                     from ../sysdeps/mach/x86/sysdep.h:31,
                     from ../sysdeps/x86_64/multiarch/strnlen-evex-base.S:24:
    /usr/include/x86_64-gnu/mach/x86_64/asm.h:78:9: note: this is the location of the previous definition
       78 | #define P2ALIGN(p2)     .p2align p2     /* gas-specific */
          |         ^~~~~~~

The fix is to undefine the macro from system headers in sysdep.h so that
it can be properly defined in assembly files where its definition
depends on whether string functions are being compiled for
wide-characters or not.
Message-ID: <721cd3a1bae1a553857db1dd69761a175f611364.1750131904.git.collin.funk1@gmail.com>
2025-06-21 14:39:36 +02:00
H. Peter Anvin (Intel) 5f138519eb termios: add new baud_t interface, defined to be explicitly numeric
Add an explicitly numeric interface for baudrate setting. For glibc,
this only announces what is a fair accompli, but this is a plausible
way forward for standardization, and may be possible to infill on
non-compliant systems. The POSIX committee has stated:

[https://www.austingroupbugs.net/view.php?id=1916#c7135]

	A future version of this standard is expected to add at least
	the following symbolic constants for use as values of objects
	of type speed_t: B57600, B115200, B230400, B460800, and
	B921600.

	Implementations are encouraged to propose additional
	interfaces which will make it possible to set and query a
	wider range of speeds than just those enumerated by the
	constants beginning with B. If a set of common interfaces
	emerges between several implementations, a future version of
	this standard will likely add those interfaces.

This is exactly that interface.

The use of the term "baud" is due to the need to have a term
contrasting "speed", and it is already well established as a legacy
term -- including in the names of the legacy Bxxx
constants. Futhermore, it *is* valid from the point of view that the
termios interface fundamentally emulates an RS-232 serial port as far
as the application software is concerned.

The documentation states that for the current version of glibc,
speed_t == baud_t, but explicitly declares that this may not be the
case in the future.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2025-06-17 09:11:38 -03:00
H. Peter Anvin (Intel) bff11c2fa9 hurd/termios: remove USE_OLD_TTY
Hurd with USE_OLD_TTY was the only remaining platform with speed_t not
containing a proper baud rate. From the looks of it, that code has
long since bitrotted.

Remove the vestiges of USE_OLD_TTY.

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-06-17 09:11:38 -03:00
gfleury 27360ab9ea htl: move pthread_key_*, pthread_get/setspecific
Signed-off-by: gfleury <gfleury@disroot.org>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Message-ID: <20250613184440.1660335-1-gfleury@disroot.org>
2025-06-15 21:21:12 +02:00
Samuel Thibault 5fdc693d95 hurd: Make __getrandom_early_init call __mach_init
25d37948c9 ("malloc: Improve malloc initialization") moved calling malloc
initialization earlier, within _dl_sysdep_start's call to dl_main, before
__mach_init is called by _dl_init_first. But malloc initialization uses
getrandom, which needs to make RPCs.

This adds __getrandom_early_init on hurd to express that getrandom needs
__mach_init too. This also adds a guard to avoid making it create several task
and host ports.

Fixes: 25d37948c9 ("malloc: Improve malloc initialization")
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2025-06-09 08:34:06 +00:00
Joseph Myers 06caf53adf Implement C23 rootn.
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the rootn functions, which compute the Yth root of X for
integer Y (with a domain error if Y is 0, even if X is a NaN).  The
integer exponent has type long long int in C23; it was intmax_t in TS
18661-4, and as with other interfaces changed after their initial
appearance in the TS, I don't think we need to support the original
version of the interface.

As with pown and compoundn, I strongly encourage searching for worst
cases for ulps error for these implementations (necessarily
non-exhaustively, given the size of the input space).  I also expect a
custom implementation for a given format could be much faster as well
as more accurate, although the implementation is simpler than those
for pown and compoundn.

This completes adding to glibc those TS 18661-4 functions (ignoring
DFP) that are included in C23.  See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118592 regarding the C23
mathematical functions (not just the TS 18661-4 ones) missing built-in
functions in GCC, where such functions might usefully be added.

Tested for x86_64 and x86, and with build-many-glibcs.py.
2025-05-14 10:51:46 +00:00
Samuel Thibault 2ae4ec56c2 hurd: Make rename refuse trailing slashes [BZ #32570]
As tested by Gnulib's renameatu module.

Reported by Collin Funk on
https://sourceware.org/bugzilla/show_bug.cgi?id=32570
2025-05-12 01:54:34 +02:00
Joseph Myers ae31254432 Implement C23 compoundn
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the compoundn functions, which compute (1+X) to the
power Y for integer Y (and X at least -1).  The integer exponent has
type long long int in C23; it was intmax_t in TS 18661-4, and as with
other interfaces changed after their initial appearance in the TS, I
don't think we need to support the original version of the interface.

Note that these functions are "compoundn" with a trailing "n", *not*
"compound" (CORE-MATH has the wrong name, for example).

As with pown, I strongly encourage searching for worst cases for ulps
error for these implementations (necessarily non-exhaustively, given
the size of the input space).  I also expect a custom implementation
for a given format could be much faster as well as more accurate (I
haven't tested or benchmarked the CORE-MATH implementation for
binary32); this is one of the more complicated and less efficient
functions to implement in a type-generic way.

As with exp2m1 and exp10m1, this showed up places where the
powerpc64le IFUNC setup is not as self-contained as one might hope (in
this case, without the changes specific to powerpc64le, there were
undefined references to __GI___expf128).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2025-05-09 15:17:27 +00:00
Adhemerval Zanella 0c34259423 nptl: Fix pthread_getattr_np when modules with execstack are allowed (BZ 32897)
The BZ 32653 fix (12a497c716) kept the
stack pointer zeroing from make_main_stack_executable on
_dl_make_stack_executable.  However, previously the 'stack_endp'
pointed to temporary variable created before the call of
_dl_map_object_from_fd; while now we use the __libc_stack_end
directly.

Since pthread_getattr_np relies on correct __libc_stack_end, if
_dl_make_stack_executable is called (for instance, when
glibc.rtld.execstack=2 is set) __libc_stack_end will be set to zero,
and the call will always fail.

The __libc_stack_end zero was used a mitigation hardening, but since
52a01100ad it is used solely on
pthread_getattr_np code.  So there is no point in zeroing anymore.

Checked on x86_64-linux-gnu and i686-linux-gnu.
Reviewed-by: Sam James <sam@gentoo.org>
2025-04-28 10:13:46 -03:00
Samuel Thibault 39183b953c hurd: Make symlink return EEXIST on existing target directory
8ef1791950 ("hurd: Fix EINVAL error on linking to a slash-trailing path
[BZ #32569]) made symlink return ENOTDIR, but the gnulib testsuite does
not recognize it for such a situation, and EEXIST is indeed more
comprehensible to users.
2025-04-21 23:08:17 +02:00
Samuel Thibault 0d99714680 hurd: Clear FP exceptions before calling signal handler
This avoids SIGFPE handlers (or code longjmp-ed to) getting disturbed by the
exception that generated it.

Note: gcc's unwinding depends on the rpc_wait_trampoline/trampoline exact
code, so we here avoid breaking it.
2025-04-21 20:01:37 +02:00
Samuel Thibault 0f2df19d95 hurd: Do not check for xstate level if it was not initialized
If __thread_get_state failed, there is no xstate level to check.
ok is 0 already and the memory exists, but better not read uninitialized
memory.
2025-04-21 19:46:24 +02:00
Samuel Thibault 8d54b428cf hurd: Do not restore xstate when it is not initialized
If the process has never used fp before getting a signal, xstate is set
(and thus the x87 state is not initialized) but xstate->initialized is still
0, and we should not restore anything.
2025-04-21 19:43:36 +02:00
Samuel Thibault d58ebf51bc hurd: Make *utime*s catch invalid times [BZ #32802, BZ #32803] 2025-04-20 00:24:56 +02:00
Luca Dariz 6d6a6e2dd2 hurd: save xstate during signal handling
* hurd/Makefile: add new tests
* hurd/test-sig-rpc-interrupted.c: check xstate save and restore in
  the case where a signal is delivered to a thread which is waiting
  for an rpc. This test implements the rpc interruption protocol used
  by the hurd servers. It was so far passing on Debian thanks to the
  local-intr-msg-clobber.diff patch, which is now obsolete.
* hurd/test-sig-xstate.c: check xstate save and restore in the case
  where a signal is delivered to a running thread, making sure that
  the xstate is modified in the signal handler.
* hurd/test-xstate.h: add helpers to test xstate
* sysdeps/mach/hurd/i386/bits/sigcontext.h: add xstate to the
  sigcontext structure.
+ sysdeps/mach/hurd/i386/sigreturn.c: restore xstate from the saved
  context
* sysdeps/mach/hurd/x86/trampoline.c: save xstate if
  supported. Otherwise we fall back to the previous behaviour of
  ignoring xstate.
* sysdeps/mach/hurd/x86_64/bits/sigcontext.h: add xstate to the
  sigcontext structure.
* sysdeps/mach/hurd/x86_64/sigreturn.c: restore xstate from the saved
  context

Signed-off-by: Luca Dariz <luca@orpolo.org>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Message-ID: <20250319171118.142163-1-luca@orpolo.org>
2025-04-18 02:42:36 +02:00