Commit Graph

6702 Commits

Author SHA1 Message Date
Adhemerval Zanella a2b0ff98a0 include/sys/cdefs.h: Add __attribute_optimization_barrier__
Add __attribute_optimization_barrier__ to disable inlining and cloning on a
function.  For Clang, expand it to

__attribute__ ((optnone))

Otherwise, expand it to

__attribute__ ((noinline, clone))

Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-23 06:28:55 +08:00
John David Anglin 325db5ab7f hppa: Simplify handling of sanity check errors in clone.S.
This simplifies the handling of sanity check errors in clone.S.
Adjusted a couple of comments to reflect current code.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
2024-12-22 09:58:02 -05:00
John David Anglin 9bdb1487c5 hppa: add cacheflush() syscall wrapper
The hppa Linux kernel supports the cacheflush() syscall
since version 6.5. This adds the glibc syscall wrapper.

Signed-off-by: Helge Deller <deller@gmx.de>

---
v2: This patch was too late in release cycle for GLIBC_2.40,
    so update now to GLIBC_2.41 instead.
2024-12-22 09:51:54 -05:00
Adhemerval Zanella 799e686c88 dirent: Remove variable length array structure for tst-getdents64.c
Clang emits the following warnings:

  ../sysdeps/unix/sysv/linux/tst-getdents64.c:111:18: error: fields must
  have a constant size: 'variable length array in structure' extension
  will never be supported
              char buffer[buffer_size];
                   ^

Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-22 13:06:02 +08:00
Joseph Myers 322e9d4e44 Add F_CREATED_QUERY from Linux 6.12 to bits/fcntl-linux.h
Linux 6.12 adds a new constant F_CREATED_QUERY.  Add it to glibc's
bits/fcntl-linux.h.

Tested for x86_64.
2024-12-20 11:47:33 +00:00
Joseph Myers 37d9618492 Add HWCAP_LOONGARCH_LSPW from Linux 6.12 to bits/hwcap.h
Add the new Linux 6.12 HWCAP_LOONGARCH_LSPW to the corresponding
bits/hwcap.h.

Tested with build-many-glibcs.py for loongarch64-linux-gnu-lp64d.
2024-12-20 11:47:03 +00:00
Joseph Myers fbdd8b3fa8 Add MSG_SOCK_DEVMEM from Linux 6.12 to bits/socket.h
Linux 6.12 adds a constant MSG_SOCK_DEVMEM (recall that various
constants such as this one are defined in the non-uapi linux/socket.h
but still form part of the kernel/userspace interface, so that
non-uapi header is one that needs checking each release for new such
constants).  Add it to glibc's bits/socket.h.

Tested for x86_64.
2024-12-20 11:46:06 +00:00
Florian Weimer 70d0836305 Linux: Accept null arguments for utimensat pathname
This matches kernel behavior.  With this change, it is possible
to use utimensat as a replacement for the futimens interface,
similar to what glibc does internally.

Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
2024-12-19 21:21:30 +01:00
Joseph Myers 29ae632e76 Add SCHED_EXT from Linux 6.12 to bits/sched.h
Linux 6.12 adds the SCHED_EXT constant.  Add it to glibc's
bits/sched.h and update the kernel version in tst-sched-consts.py.

Tested for x86_64.
2024-12-19 17:08:38 +00:00
John David Anglin 57256971b0 hppa: Fix strace detach-vfork test
This change implements vfork.S for direct support of the vfork
syscall.  clone.S is revised to correct child support for the
vfork case.

The main bug was creating a frame prior to the clone syscall.
This was done to allow the rp and r4 registers to be saved and
restored from the stack frame.  r4 was used to save and restore
the PIC register, r19, across the system call and the call to
set errno.  But in the vfork case, it is undefined behavior
for the child to return from the function in which vfork was
called.  It is surprising that this usually worked.

Syscalls on hppa save and restore rp and r19, so we don't need
to create a frame prior to the clone syscall.  We only need a
frame when __syscall_error is called.  We also don't need to
save and restore r19 around the call to $$dyncall as r19 is not
used in the code after $$dyncall.

This considerably simplifies clone.S.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
2024-12-19 11:30:09 -05:00
Joseph Myers 5fcee06dc7 Update kernel version to 6.12 in header constant tests
There are no new constants covered by tst-mman-consts.py,
tst-mount-consts.py or tst-pidfd-consts.py in Linux 6.12 that need any
header changes, so update the kernel version in those tests.
(tst-sched-consts.py will need updating separately along with adding
SCHED_EXT.)

Tested with build-many-glibcs.py.
2024-12-19 15:38:59 +00:00
Joseph Myers e0a0fd64b5 Update syscall lists for Linux 6.12
Linux 6.12 has no new syscalls.  Update the version number in
syscall-names.list to reflect that it is still current for 6.12.

Tested with build-many-glibcs.py.
2024-12-18 15:12:36 +00:00
H.J. Lu a194871b13 sys/platform/x86.h: Do not depend on _Bool definition in C++ mode
Clang does not define _Bool for -std=c++98:

/usr/include/bits/platform/features.h:31:19: error: unknown type name '_Bool'
   31 | static __inline__ _Bool
      |                   ^

Change _Bool to bool to silence clang++ error.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-12-18 02:32:27 +08:00
H.J. Lu d4ee46b0cd tst-clone3[-internal].c: Add _Atomic to silence Clang
Add _Atomic to futex_wait argument and ctid in tst-clone3[-internal].c to
silence Clang error:

../sysdeps/unix/sysv/linux/tst-clone3-internal.c:93:3: error: address argument to atomic operation must be a pointer to _Atomic type ('pid_t *' (aka 'int *') invalid)
   93 |   wait_tid (&ctid, CTID_INIT_VAL);
      |   ^         ~~~~~
../sysdeps/unix/sysv/linux/tst-clone3-internal.c:51:21: note: expanded from macro 'wait_tid'
   51 |     while ((__tid = atomic_load_explicit (ctid_ptr,                     \
      |                     ^                     ~~~~~~~~
/usr/bin/../lib/clang/19/include/stdatomic.h:145:30: note: expanded from macro 'atomic_load_explicit'
  145 | #define atomic_load_explicit __c11_atomic_load
      |                              ^

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-18 01:54:26 +08:00
H.J. Lu 07e3eb1774 Use empty initializer to silence GCC 4.9 or older
Use empty initializer to silence GCC 4.9 or older:

getaddrinfo.c: In function ‘gaih_inet’:
getaddrinfo.c:1135:24: error: missing braces around initializer [-Werror=missing-braces]
       / sizeof (struct gaih_typeproto)] = {0};
                        ^

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-16 04:06:30 +08:00
Florian Weimer b933e5cef6 Linux: Check for 0 return value from vDSO getrandom probe
As of Linux 6.13, there is no code in the vDSO that declines this
initialization request with the special ~0UL state size.  If the vDSO
has the function, the call succeeds and returns 0.  It's expected
that the code would follow the “a negative value indicating an error”
convention, as indicated in the __cvdso_getrandom_data function
comment, so that INTERNAL_SYSCALL_ERROR_P on glibc's side would return
true.  This commit changes the commit to check for zero to indicate
success instead, which covers potential future non-zero success
return values and error returns.

Fixes commit 4f5704ea34 ("powerpc: Use
correct procedure call standard for getrandom vDSO call (bug 32440)").
2024-12-15 17:05:25 +01:00
H.J. Lu 20f8c5df56 Revert "Add braces in initializers for GCC 4.9 or older"
This reverts commit 8aa2a9e033.

as not all targets need braces.
2024-12-15 18:49:52 +08:00
H.J. Lu 335ba9b6c1 Return EXIT_UNSUPPORTED if __builtin_add_overflow unavailable
Since GCC 4.9 doesn't have __builtin_add_overflow:

In file included from tst-stringtable.c:180:0:
stringtable.c: In function ‘stringtable_finalize’:
stringtable.c:185:7: error: implicit declaration of function ‘__builtin_add_overflow’ [-Werror=implicit-function-declaration]
       else if (__builtin_add_overflow (previous->offset,
       ^

return EXIT_UNSUPPORTED for GCC 4.9 or older.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-15 05:24:19 +08:00
H.J. Lu 8aa2a9e033 Add braces in initializers for GCC 4.9 or older
Add braces to silence GCC 4.9 or older:

getaddrinfo.c: In function ‘gaih_inet’:
getaddrinfo.c:1135:24: error: missing braces around initializer [-Werror=missing-braces]
       / sizeof (struct gaih_typeproto)] = {0};
                        ^

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-14 19:26:45 +08:00
Joseph Myers 3374de9038 Implement C23 atan2pi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the atan2pi functions (atan2(y,x)/pi).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-12 20:57:44 +00:00
Joseph Myers ffe79c446c Implement C23 atanpi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the atanpi functions (atan(x)/pi).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-11 21:51:49 +00:00
Florian Weimer 4f5704ea34 powerpc: Use correct procedure call standard for getrandom vDSO call (bug 32440)
A plain indirect function call does not work on POWER because
success and failure are signaled through a flag register, and
not via the usual Linux negative return value convention.

This has potential security impact, in two ways: the return value
could be out of bounds (EAGAIN is 11 on powerpc6le), and no
random bytes have been written despite the non-error return value.

Fixes commit 461cab1de7 ("linux: Add
support for getrandom vDSO").

Reported-by: Ján Stanček <jstancek@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-12-11 17:49:04 +01:00
Joseph Myers f962932206 Implement C23 asinpi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the asinpi functions (asin(x)/pi).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-10 20:42:20 +00:00
Joseph Myers 28d102d15c Implement C23 acospi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the acospi functions (acos(x)/pi).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-09 23:01:29 +00:00
Sachin Monga be13e46764 powerpc64le: ROP changes for the *context and setjmp functions
Add ROP protection for the getcontext, setcontext, makecontext, swapcontext
and __sigsetjmp_symbol functions.

Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
2024-12-09 16:49:54 -05:00
Michael Jeanson d3b3a12258 nptl: add RSEQ_SIG for RISC-V
Enable RSEQ for RISC-V, support was added in Linux 5.18.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-12-09 13:26:55 -05:00
Joseph Myers f9e90e4b4c Implement C23 tanpi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the tanpi functions (tan(pi*x)).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-05 21:42:10 +00:00
Joseph Myers 776938e8b8 Implement C23 sinpi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the sinpi functions (sin(pi*x)).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-04 20:04:04 +00:00
Joseph Myers 0ae0af68d8 Implement C23 cospi
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the cospi functions (cos(pi*x)).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2024-12-04 10:20:44 +00:00
Adhemerval Zanella 82a3991a84 Remove nios2-linux-gnu
GCC 15 (e876acab6cdd84bb2b32c98fc69fb0ba29c81153) and binutils
(e7a16d9fd65098045ef5959bf98d990f12314111) both removed all Nios II
support, and the architecture has been EOL'ed by the vendor.  The
kernel still has support, but without a proper compiler there
is no much sense in keep it on glibc.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-11-28 14:03:25 -03:00
Alejandro Colomar 53fcdf5f74 Silence most -Wzero-as-null-pointer-constant diagnostics
Replace 0 by NULL and {0} by {}.

Omit a few cases that aren't so trivial to fix.

Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
Link: <https://software.codidact.com/posts/292718/292759#answer-292759>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-25 16:45:59 -03:00
Yannick Le Pennec 83d4b42ded sysdeps: linux: Fix output of LD_SHOW_AUXV=1 for AT_RSEQ_*
The constants themselves were added to elf.h back in 8754a4133e but the
array in _dl_show_auxv wasn't modified accordingly, resulting in the
following output when running LD_SHOW_AUXV=1 /bin/true on recent Linux:

    AT_??? (0x1b): 0x1c
    AT_??? (0x1c): 0x20

With this patch:

    AT_RSEQ_FEATURE_SIZE: 28
    AT_RSEQ_ALIGN:        32

Tested on Linux 6.11 x86_64

Signed-off-by: Yannick Le Pennec <yannick.lepennec@live.fr>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2024-11-25 16:45:59 -03:00
Michael Jeanson d9f40387d3 nptl: initialize cpu_id_start prior to rseq registration
When adding explicit initialization of rseq fields prior to
registration, I glossed over the fact that 'cpu_id_start' is also
documented as initialized by user-space.

While current kernels don't validate the content of this field on
registration, future ones could.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2024-11-25 19:42:14 +01:00
Joseph Myers 99671e72bb Add multithreaded test of sem_getvalue
Test coverage of sem_getvalue is fairly limited.  Add a test that runs
it on threads on each CPU.  For this purpose I adapted
tst-skeleton-thread-affinity.c; it didn't seem very suitable to use
as-is or include directly in a different test doing things per-CPU,
but did seem a suitable starting point (thus sharing
tst-skeleton-affinity.c) for such testing.

Tested for x86_64.
2024-11-22 16:58:51 +00:00
Yury Khrustalev f4d00dd60d AArch64: Add support for memory protection keys
This patch adds support for memory protection keys on AArch64 systems with
enabled Stage 1 permission overlays feature introduced in Armv8.9 / 9.4
(FEAT_S1POE) [1].

 1. Internal functions "pkey_read" and "pkey_write" to access data
    associated with memory protection keys.
 2. Implementation of API functions "pkey_get" and "pkey_set" for
    the AArch64 target.
 3. AArch64-specific PKEY flags for READ and EXECUTE (see below).
 4. New target-specific test that checks behaviour of pkeys on
    AArch64 targets.
 5. This patch also extends existing generic test for pkeys.
 6. HWCAP constant for Permission Overlay Extension feature.

To support more accurate mapping of underlying permissions to the
PKEY flags, we introduce additional AArch64-specific flags. The full
list of flags is:

 - PKEY_UNRESTRICTED: 0x0 (for completeness)
 - PKEY_DISABLE_ACCESS: 0x1 (existing flag)
 - PKEY_DISABLE_WRITE: 0x2 (existing flag)
 - PKEY_DISABLE_EXECUTE: 0x4 (new flag, AArch64 specific)
 - PKEY_DISABLE_READ: 0x8 (new flag, AArch64 specific)

The problem here is that PKEY_DISABLE_ACCESS has unusual semantics as
it overlaps with existing PKEY_DISABLE_WRITE and new PKEY_DISABLE_READ.
For this reason mapping between permission bits RWX and "restrictions"
bits awxr (a for disable access, etc) becomes complicated:

 - PKEY_DISABLE_ACCESS disables both R and W
 - PKEY_DISABLE_{WRITE,READ} disables W and R respectively
 - PKEY_DISABLE_EXECUTE disables X

Combinations like the one below are accepted although they are redundant:

 - PKEY_DISABLE_ACCESS | PKEY_DISABLE_READ | PKEY_DISABLE_WRITE

Reverse mapping tries to retain backward compatibility and ORs
PKEY_DISABLE_ACCESS whenever both flags PKEY_DISABLE_READ and
PKEY_DISABLE_WRITE would be present.

This will break code that compares pkey_get output with == instead
of using bitwise operations. The latter is more correct since PKEY_*
constants are essentially bit flags.

It should be noted that PKEY_DISABLE_ACCESS does not prevent execution.

[1] https://developer.arm.com/documentation/ddi0487/ka/ section D8.4.1.4

Co-authored-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2024-11-20 11:30:58 +00:00
Peter Bergner 229265cc2c powerpc: Improve the inline asm for syscall wrappers
Update the inline asm syscall wrappers to match the newer register constraint
usage in INTERNAL_VSYSCALL_CALL_TYPE.  Use the faster mfocrf instruction when
available, rather than the slower mfcr microcoded instruction.
2024-11-19 12:43:57 -05:00
Adhemerval Zanella 461cab1de7 linux: Add support for getrandom vDSO
Linux 6.11 has getrandom() in vDSO. It operates on a thread-local opaque
state allocated with mmap using flags specified by the vDSO.

Multiple states are allocated at once, as many as fit into a page, and
these are held in an array of available states to be doled out to each
thread upon first use, and recycled when a thread terminates. As these
states run low, more are allocated.

To make this procedure async-signal-safe, a simple guard is used in the
LSB of the opaque state address, falling back to the syscall if there's
reentrancy contention.

Also, _Fork() is handled by blocking signals on opaque state allocation
(so _Fork() always sees a consistent state even if it interrupts a
getrandom() call) and by iterating over the thread stack cache on
reclaim_stack. Each opaque state will be in the free states list
(grnd_alloc.states) or allocated to a running thread.

The cancellation is handled by always using GRND_NONBLOCK flags while
calling the vDSO, and falling back to the cancellable syscall if the
kernel returns EAGAIN (would block). Since getrandom is not defined by
POSIX and cancellation is supported as an extension, the cancellation is
handled as 'may occur' instead of 'shall occur' [1], meaning that if
vDSO does not block (the expected behavior) getrandom will not act as a
cancellation entrypoint. It avoids a pthread_testcancel call on the fast
path (different than 'shall occur' functions, like sem_wait()).

It is currently enabled for x86_64, which is available in Linux 6.11,
and aarch64, powerpc32, powerpc64, loongarch64, and s390x, which are
available in Linux 6.12.

Link: https://pubs.opengroup.org/onlinepubs/9799919799/nframe.html [1]
Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Tested-by: Jason A. Donenfeld <Jason@zx2c4.com> # x86_64
Tested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> # x86_64, aarch64
Tested-by: Xi Ruoyao <xry111@xry111.site> # x86_64, aarch64, loongarch64
Tested-by: Stefan Liebler <stli@linux.ibm.com> # s390x
2024-11-12 14:42:12 -03:00
Michael Jeanson 97f60abd25 nptl: initialize rseq area prior to registration
Per the rseq syscall documentation, 3 fields are required to be
initialized by userspace prior to registration, they are 'cpu_id',
'rseq_cs' and 'flags'. Since we have no guarantee that 'struct pthread'
is cleared on all architectures, explicitly set those 3 fields prior to
registration.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-11-07 22:23:49 +01:00
Yury Khrustalev ff254cabd6 misc: Align argument name for pkey_*() functions with the manual
Change name of the access_rights argument to access_restrictions
of the following functions:

 - pkey_alloc()
 - pkey_set()

as this argument refers to access restrictions rather than access
rights and previous name might have been misleading.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2024-11-06 13:11:33 +00:00
Aurelien Jarno 273694cd78 Add Arm HWCAP2_* constants from Linux 3.15 and 6.2 to <bits/hwcap.h>
Linux 3.15 and 6.2 added HWCAP2_* values for Arm. These bits have
already been added to dl-procinfo.{c,h} in commits 9aea0cb842 and
8ebe9c0b38. Also add them to <bits/hwcap.h> so that they can be used
in user code. For example, for checking bits in the value returned by
getauxval(AT_HWCAP2).

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Yury Khrustalev <yury.khrustalev@arm.com>
2024-11-05 21:03:37 +01:00
caiyinyu 93ced0e1b8 LoongArch: Add RSEQ_SIG in rseq.h.
Signed-off-by: caiyinyu <caiyinyu@loongson.cn>
2024-11-01 10:41:20 +08:00
Sachin Monga 383e4f53cb powerpc64: Obviate the need for ROP protection in clone/clone3
Save lr in a non-volatile register before scv in clone/clone3.
For clone, the non-volatile register was unused and already
saved/restored.  Remove the dead code from clone.

Signed-off-by: Sachin Monga <smonga@linux.ibm.com>
Reviewed-by: Peter Bergner <bergner@linux.ibm.com>
2024-10-30 16:50:04 -04:00
Florian Weimer 4f5f8343c3 Linux: Match kernel text for SCHED_ macros
This avoids -Werror build issues in strace, which bundles UAPI
headers, but does not include them as system headers.

Fixes commit c444cc1d83
("Linux: Add missing scheduler constants to <sched.h>").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2024-10-25 16:46:30 +02:00
DJ Delorie 81439a116c configure: default to --prefix=/usr on GNU/Linux
I'm getting tired of always typing --prefix=/usr
so making it the default.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-22 18:11:49 -04:00
Adhemerval Zanella ab564362d0 linux: Fix tst-syscall-restart.c on old gcc (BZ 32283)
To avoid a parameter name omitted error.
2024-10-18 08:48:22 -03:00
Adhemerval Zanella 2c1903cbba sparc: Fix restartable syscalls (BZ 32173)
The commit 'sparc: Use Linux kABI for syscall return'
(86c5d2cf0c) did not take into account
a subtle sparc syscall kABI constraint.  For syscalls that might block
indefinitely, on an interrupt (like SIGCONT) the kernel will set the
instruction pointer to just before the syscall:

arch/sparc/kernel/signal_64.c
476 static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
477 {
[...]
525                 if (restart_syscall) {
526                         switch (regs->u_regs[UREG_I0]) {
527                         case ERESTARTNOHAND:
528                         case ERESTARTSYS:
529                         case ERESTARTNOINTR:
530                                 /* replay the system call when we are done */
531                                 regs->u_regs[UREG_I0] = orig_i0;
532                                 regs->tpc -= 4;
533                                 regs->tnpc -= 4;
534                                 pt_regs_clear_syscall(regs);
535                                 fallthrough;
536                         case ERESTART_RESTARTBLOCK:
537                                 regs->u_regs[UREG_G1] = __NR_restart_syscall;
538                                 regs->tpc -= 4;
539                                 regs->tnpc -= 4;
540                                 pt_regs_clear_syscall(regs);
541                         }

However, on a SIGCONT it seems that 'g1' register is being clobbered after the
syscall returns.  Before 86c5d2cf0c, the 'g1' was always placed jus
before the 'ta' instruction which then reloads the syscall number and restarts
the syscall.

On master, where 'g1' might be placed before 'ta':

  $ cat test.c
  #include <unistd.h>

  int main ()
  {
    pause ();
  }
  $ gcc test.c -o test
  $ strace -f ./t
  [...]
  ppoll(NULL, 0, NULL, NULL, 0

On another terminal

  $ kill -STOP 2262828

  $ strace -f ./t
  [...]
  --- SIGSTOP {si_signo=SIGSTOP, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  --- stopped by SIGSTOP ---

And then

  $ kill -CONT 2262828

Results in:

  --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  restart_syscall(<... resuming interrupted ppoll ...>) = -1 EINTR (Interrupted system call)

Where the expected behaviour would be:

  $ strace -f ./t
  [...]
  ppoll(NULL, 0, NULL, NULL, 0)           = ? ERESTARTNOHAND (To be restarted if no handler)
  --- SIGSTOP {si_signo=SIGSTOP, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  --- stopped by SIGSTOP ---
  --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=2521813, si_uid=8289} ---
  ppoll(NULL, 0, NULL, NULL, 0

Just moving the 'g1' setting near the syscall asm is not suffice,
the compiler might optimize it away (as I saw on cancellation.c by
trying this fix).  Instead, I have change the inline asm to put the
'g1' setup in ithe asm block.  This would require to change the asm
constraint for INTERNAL_SYSCALL_NCS, since the syscall number is not
constant.

Checked on sparc64-linux-gnu.

Reported-by: René Rebe <rene@exactcode.de>
Tested-by: Sam James <sam@gentoo.org>
Reviewed-by: Sam James <sam@gentoo.org>
2024-10-16 14:54:24 -03:00
caiyinyu 2fffaffde8 LoongArch: Regenerate loongarch/arch-syscall.h by build-many-glibcs.py update-syscalls. 2024-10-12 15:50:11 +08:00
Adhemerval Zanella 5ffc903216 misc: Add support for Linux uio.h RWF_ATOMIC flag
Linux 6.11 adds the new flag for pwritev2 (commit
c34fc6f26ab86d03a2d47446f42b6cd492dfdc56).

Checked on x86_64-linux-gnu on 6.11 kernel.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-10 10:28:01 -03:00
Adhemerval Zanella 934d0bf426 Update kernel version to 6.11 in header constant tests
This patch updates the kernel version in the tests tst-mount-consts.py,
and tst-sched-consts.py to 6.11.

There are no new constants covered by these tests in 6.11.

Tested with build-many-glibcs.py.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-10 10:27:55 -03:00
Adhemerval Zanella f6e849fd7c linux: Add MAP_DROPPABLE from Linux 6.11
This request the page to be never written out to swap, it will be zeroed
under memory pressure (so kernel can just drop the page), it is inherited
by fork, it is not counted against @code{mlock} budget, and if there is
no enough memory to service a page faults there is no fatal error (so not
signal is sent).

Tested with build-many-glibcs.py.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-10 10:27:53 -03:00