@@ -22,6 +22,12 @@ Major new features:
* The ISO C2Y family of unsigned abs functions, i.e.
uabs, ulabs, ullabs and uimaxabs, are now supported.
+* The functions posix_spawnattr_getrlimit_np and
+ posix_spawnattr_setrlimit_np have been added, along with the
+ POSIX_SPAWN_SETRLIMIT flag. They allow posix_spawn, posix_spawnp,
+ pidfd_spawn, and pidfd_spawnp to set a process resource limit in the new
+ process, similiar to setrlimit or prlimit.
+
Deprecated and removed features, and other changes affecting compatibility:
* The glibc.rtld.execstack now supports a compatibility mode to allow
@@ -16,7 +16,10 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#ifndef _SYS_RESOURCE_H
+#ifndef _BITS_RESOURCE_H
+#define _BITS_RESOURCE_H
+
+#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H
# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
#endif
@@ -151,3 +154,5 @@ enum __priority_which
PRIO_USER = 2 /* WHO is a user ID. */
#define PRIO_USER PRIO_USER
};
+
+#endif
@@ -135,6 +135,9 @@ extern int __setrlimit (enum __rlimit_resource __resource,
const struct rlimit *__rlimits) __nonnull ((2));
libc_hidden_proto (__setrlimit);
+extern __typeof (setrlimit64) __setrlimit64;
+libc_hidden_proto (__setrlimit64);
+
#if __TIMESIZE == 64
# define __getrusage64 __getrusage
# define __wait4_time64 __wait4
@@ -161,6 +161,7 @@ routines := \
spawnattr_getdefault \
spawnattr_getflags \
spawnattr_getpgroup \
+ spawnattr_getrlimit_np \
spawnattr_getschedparam \
spawnattr_getschedpolicy \
spawnattr_getsigmask \
@@ -168,6 +169,7 @@ routines := \
spawnattr_setdefault \
spawnattr_setflags \
spawnattr_setpgroup \
+ spawnattr_setrlimit_np \
spawnattr_setschedparam \
spawnattr_setschedpolicy \
spawnattr_setsigmask \
@@ -317,6 +319,7 @@ tests := \
tst-spawn5 \
tst-spawn6 \
tst-spawn7 \
+ tst-spawn8 \
tst-sysconf \
tst-sysconf-empty-chroot \
tst-truncate \
@@ -601,6 +604,8 @@ CFLAGS-fork.c = $(libio-mtsafe) $(config-cflags-wno-ignored-attributes)
tstgetopt-ARGS = -a -b -cfoobar --required foobar --optional=bazbug \
--none random --col --color --colour
+CFLAGS-tst-spawn8.c += -D_FILE_OFFSET_BITS=64
+
tst-exec-ARGS = -- $(host-test-program-cmd)
tst-exec-static-ARGS = $(tst-exec-ARGS)
tst-execvpe5-ARGS = -- $(host-test-program-cmd)
@@ -609,6 +614,7 @@ tst-spawn-static-ARGS = $(tst-spawn-ARGS)
tst-spawn5-ARGS = -- $(host-test-program-cmd)
tst-spawn6-ARGS = -- $(host-test-program-cmd)
tst-spawn7-ARGS = -- $(host-test-program-cmd)
+tst-spawn8-ARGS = -- $(host-test-program-cmd)
tst-posix_spawn-setsid-ARGS = -- $(host-test-program-cmd)
tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir
tst-chmod-ARGS = $(objdir)
@@ -159,6 +159,10 @@ libc {
GLIBC_2.35 {
posix_spawn_file_actions_addtcsetpgrp_np;
}
+ GLIBC_2.42 {
+ posix_spawnattr_setrlimit_np;
+ posix_spawnattr_getrlimit_np;
+ }
GLIBC_PRIVATE {
__libc_fork; __libc_pread; __libc_pwrite;
__nanosleep_nocancel; __pause_nocancel;
@@ -59,6 +59,7 @@ typedef struct
# define POSIX_SPAWN_USEVFORK 0x40
# define POSIX_SPAWN_SETSID 0x80
# define POSIX_SPAWN_SETCGROUP 0x100
+# define POSIX_SPAWN_SETRLIMIT 0x200
#endif
@@ -199,6 +200,21 @@ extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
__THROW __nonnull ((1));
#ifdef __USE_MISC
+
+#include <bits/resource.h>
+
+#if __RLIM_T_MATCHES_RLIM64_T || defined __USE_FILE_OFFSET64
+extern int posix_spawnattr_setrlimit_np (posix_spawnattr_t *__restrict __attr,
+ int __resource,
+ const struct rlimit *__rlim)
+ __THROW __nonnull ((1, 3));
+
+extern int posix_spawnattr_getrlimit_np (posix_spawnattr_t *__restrict __attr,
+ int __resource,
+ struct rlimit *__rlim)
+ __THROW __nonnull ((1, 3));
+#endif
+
/* Add an action changing the directory to PATH during spawn. This
affects the subsequent file actions. */
extern int posix_spawn_file_actions_addchdir_np (posix_spawn_file_actions_t *
@@ -22,6 +22,7 @@
#include <spawn.h>
#include <spawn_int_def.h>
#include <stdbool.h>
+#include <sys/resource.h>
struct __spawn_attr
{
@@ -36,6 +37,8 @@ struct __spawn_attr
struct sched_param __sp;
int __policy;
int __cgroup;
+ uint32_t __rlimitset;
+ struct rlimit64 *__rlimits;
};
char __size[__SIZEOF_POSIX_SPAWNATTR_T];
};
@@ -16,12 +16,16 @@
<https://www.gnu.org/licenses/>. */
#include <spawn.h>
+#include <spawn_int.h>
+#include <stdlib.h>
/* Initialize data structure for file attribute for `spawn' call. */
int
__posix_spawnattr_destroy (posix_spawnattr_t *attr)
{
- /* Nothing to do in the moment. */
+ struct __spawn_attr *at = (struct __spawn_attr *) attr;
+ free (at->__rlimits);
+
return 0;
}
weak_alias (__posix_spawnattr_destroy, posix_spawnattr_destroy)
new file mode 100644
@@ -0,0 +1,46 @@
+/* Implement posix_spawn extension to setup resource limits.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <spawn.h>
+#include <spawn_int.h>
+#include <stdlib.h>
+
+int
+__posix_spawnattr_getrlimit_np (posix_spawnattr_t *__restrict attr,
+ int resource,
+#if __RLIM_T_MATCHES_RLIM64_T
+ struct rlimit *rlim
+#else
+ struct rlimit64 *rlim
+#endif
+ )
+{
+ if (resource < 0 || resource >= RLIM_NLIMITS)
+ return EINVAL;
+
+ struct __spawn_attr *at = (struct __spawn_attr *) attr;
+ if (!(at->__rlimitset & (1u << resource)))
+ return ENOENT;
+
+ rlim->rlim_cur = at->__rlimits[resource].rlim_cur;
+ rlim->rlim_max = at->__rlimits[resource].rlim_max;
+
+ return 0;
+}
+weak_alias (__posix_spawnattr_getrlimit_np, posix_spawnattr_getrlimit_np)
@@ -28,7 +28,8 @@
| POSIX_SPAWN_SETSCHEDULER \
| POSIX_SPAWN_SETSID \
| POSIX_SPAWN_USEVFORK \
- | POSIX_SPAWN_SETCGROUP)
+ | POSIX_SPAWN_SETCGROUP \
+ | POSIX_SPAWN_SETRLIMIT)
/* Store flags in the attribute structure. */
int
new file mode 100644
@@ -0,0 +1,54 @@
+/* Implement posix_spawn extension to setup resource limits.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <spawn.h>
+#include <spawn_int.h>
+#include <stdlib.h>
+
+/* Initialize data structure for file attribute for `spawn' call. */
+int
+__posix_spawnattr_setrlimit_np (posix_spawnattr_t *__restrict attr,
+ int resource,
+#if __RLIM_T_MATCHES_RLIM64_T
+ const struct rlimit *rlim
+#else
+ const struct rlimit64 *rlim
+#endif
+ )
+{
+ if (resource < 0 || resource >= RLIM_NLIMITS)
+ return EINVAL;
+
+ struct __spawn_attr *at = (struct __spawn_attr *) attr;
+
+ if (at->__rlimits == NULL)
+ {
+ at->__rlimits = __libc_reallocarray (at->__rlimits, RLIM_NLIMITS,
+ sizeof (struct rlimit64));
+ if (at->__rlimits == NULL)
+ return ENOMEM;
+ }
+
+ at->__rlimitset |= 1u << resource;
+ at->__rlimits[resource].rlim_cur = rlim->rlim_cur;
+ at->__rlimits[resource].rlim_max = rlim->rlim_max;
+
+ return 0;
+}
+weak_alias (__posix_spawnattr_setrlimit_np, posix_spawnattr_setrlimit_np)
new file mode 100644
@@ -0,0 +1,226 @@
+/* Tests for posix_spawn resource limit set.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <getopt.h>
+#include <intprops.h>
+#include <inttypes.h>
+#include <spawn.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <support/check.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <tst-spawn.h>
+#include <unistd.h>
+
+#define CMDLINE_OPTIONS \
+ { "restart", no_argument, &restart, 1 },
+static int restart;
+
+#pragma GCC optimize ("O0")
+
+static char *spargs[4 /* The four initial arguments. */
+ + 1 /* The extra --direct. */
+ + 1 /* The extra --restart. */
+ + RLIM_NLIMITS /* The resources to check. */
+ + RLIM_NLIMITS /* The soft limit. */
+ + RLIM_NLIMITS /* The maximum limit. */
+ + 1 /* The final NULL. */];
+static int start_args;
+
+_Noreturn static void
+handle_restart (int argc, char *argv[])
+{
+ TEST_VERIFY_EXIT (argc % 3 == 0);
+
+ for (int i = 0; i < argc; i += 3)
+ {
+ int resource;
+ {
+ char *endp;
+ resource = strtol (argv[0], &endp, 10);
+ TEST_VERIFY (endp != argv[0]);
+ }
+ TEST_VERIFY_EXIT (resource < RLIM_NLIMITS);
+ rlim64_t cur;
+ {
+ char *endp;
+ cur = strtoumax (argv[1], &endp, 10);
+ TEST_VERIFY (endp != argv[1]);
+ }
+ rlim64_t max;
+ {
+ char *endp;
+ max = strtoumax (argv[2], &endp, 10);
+ TEST_VERIFY (endp != argv[2]);
+ }
+
+ struct rlimit rlimit;
+ TEST_VERIFY_EXIT (getrlimit (resource, &rlimit) == 0);
+ TEST_COMPARE (rlimit.rlim_cur, cur);
+ TEST_COMPARE (rlimit.rlim_max, max);
+ }
+
+ exit (EXIT_SUCCESS);
+}
+
+static int
+do_basic_test (void)
+{
+ {
+ posix_spawnattr_t attr;
+ TEST_COMPARE (posix_spawnattr_init (&attr), 0);
+ TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, -1,
+ &(struct rlimit) {}),
+ EINVAL);
+ TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, RLIM_NLIMITS,
+ &(struct rlimit) {}),
+ EINVAL);
+ TEST_COMPARE (posix_spawnattr_destroy (&attr), 0);
+ }
+
+ for (int i = 0; i < RLIM_NLIMITS; i++)
+ {
+ posix_spawnattr_t attr;
+
+ TEST_COMPARE (posix_spawnattr_init (&attr), 0);
+
+ /* Query a non initialized resource. */
+ TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i,
+ &(struct rlimit) {}),
+ ENOENT);
+
+ /* Set the value. */
+ TEST_COMPARE (posix_spawnattr_setrlimit_np (&attr, i,
+ &(const struct rlimit)
+ { 0, RLIM_INFINITY }), 0);
+ {
+ struct rlimit rlim;
+ TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i, &rlim),
+ 0);
+ TEST_COMPARE (rlim.rlim_cur, 0);
+ TEST_COMPARE (rlim.rlim_max, RLIM_INFINITY);
+ }
+
+ /* Query a valid, but not already set value. */
+ if (i != RLIM_NLIMITS - 1)
+ TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i + 1,
+ &(struct rlimit) {}),
+ ENOENT);
+
+ /* Overwrite the resource value. */
+ TEST_COMPARE (posix_spawnattr_setrlimit_np (&attr, i,
+ &(const struct rlimit)
+ { RLIM_INFINITY, 0 }), 0);
+ {
+ struct rlimit rlim;
+ TEST_COMPARE (posix_spawnattr_getrlimit_np (&attr, i, &rlim),
+ 0);
+ TEST_COMPARE (rlim.rlim_cur, RLIM_INFINITY);
+ TEST_COMPARE (rlim.rlim_max, 0);
+ }
+
+ TEST_COMPARE (posix_spawnattr_destroy (&attr), 0);
+ }
+
+ return 0;
+}
+
+static int
+do_test_spawn (void)
+{
+ struct rlimit rlimits[RLIM_NLIMITS];
+ for (int i = 0; i < RLIM_NLIMITS; i++)
+ TEST_VERIFY_EXIT (getrlimit (i, &rlimits[i]) == 0);
+
+ char resource_str[RLIM_NLIMITS][INT_STRLEN_BOUND (int)];
+ char cur_limit_str[RLIM_NLIMITS][INT_STRLEN_BOUND (uintmax_t)];
+ char max_limit_str[RLIM_NLIMITS][INT_STRLEN_BOUND (uintmax_t)];
+
+ posix_spawnattr_t attr;
+ TEST_COMPARE (posix_spawnattr_init (&attr), 0);
+
+ int argc = start_args;
+ for (int i = 0; i < RLIM_NLIMITS; i++)
+ {
+ if (rlimits[i].rlim_max == 0)
+ continue;
+
+ rlimits[i].rlim_cur /= 2;
+ rlimits[i].rlim_max /= 2;
+
+ TEST_COMPARE (posix_spawnattr_setrlimit_np (&attr, i, &rlimits[i]), 0);
+
+ snprintf (resource_str[i], sizeof resource_str[i], "%d", i);
+ snprintf (cur_limit_str[i], sizeof cur_limit_str[i], "%ju",
+ (uintmax_t) rlimits[i].rlim_cur);
+ snprintf (max_limit_str[i], sizeof max_limit_str[i], "%ju",
+ (uintmax_t) rlimits[i].rlim_max);
+
+ spargs[argc++] = resource_str[i];
+ spargs[argc++] = cur_limit_str[i];
+ spargs[argc++] = max_limit_str[i];
+ }
+ spargs[argc] = NULL;
+
+ TEST_COMPARE (posix_spawnattr_setflags (&attr, POSIX_SPAWN_SETRLIMIT), 0);
+
+ PID_T_TYPE pid;
+ TEST_COMPARE (POSIX_SPAWN (&pid, spargs[0], NULL, &attr, spargs, environ),
+ 0);
+
+ TEST_COMPARE (posix_spawnattr_destroy (&attr), 0);
+
+ siginfo_t sinfo;
+ TEST_COMPARE (WAITID (P_ALL, 0, &sinfo, WEXITED), 0);
+ TEST_COMPARE (sinfo.si_code, CLD_EXITED);
+ TEST_COMPARE (sinfo.si_status, 0);
+
+ return 0;
+}
+
+static int
+do_test (int argc, char *argv[])
+{
+ if (restart)
+ handle_restart (argc - 1, &argv[1]);
+ TEST_VERIFY_EXIT (argc == 2 || argc == 5);
+
+ do_basic_test ();
+
+ {
+ int i;
+ for (i = 0; i < argc - 1; i++)
+ spargs[i] = argv[i + 1];
+ spargs[i++] = (char *) "--direct";
+ spargs[i++] = (char *) "--restart";
+ start_args = i;
+ }
+
+ do_test_spawn ();
+
+ return 0;
+}
+
+
+#define TEST_FUNCTION_ARGV do_test
+#include <support/test-driver.c>
@@ -23,7 +23,7 @@
Only the super-user can increase hard limits.
Return 0 if successful, -1 if not (and sets errno). */
int
-setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
+__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
{
struct rlimit rlimits32;
@@ -38,3 +38,5 @@ setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
return __setrlimit (resource, &rlimits32);
}
+libc_hidden_def (__setrlimit64)
+weak_alias (__setrlimit64, setrlimit64)
@@ -69,5 +69,10 @@
fsfilcnt64_t are not the same type for all ABI purposes. */
# define __STATFS_MATCHES_STATFS64 0
+#ifdef __LP64__
+# define __RLIM_T_MATCHES_RLIM64_T 1
+#else
+# define __RLIM_T_MATCHES_RLIM64_T 0
+#endif
#endif /* bits/typesizes.h */
@@ -2586,6 +2586,8 @@ GLIBC_2.41 pthread_mutexattr_settype F
GLIBC_2.41 pthread_sigmask F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_barrier_destroy F
GLIBC_2.42 pthread_barrier_init F
GLIBC_2.42 pthread_barrier_wait F
@@ -32,6 +32,7 @@
#include <hurd/resource.h>
#include <assert.h>
#include <argz.h>
+#include <stdbit.h>
#include "spawn_int.h"
/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
@@ -478,6 +479,19 @@ retry:
}
__mutex_unlock (&_hurd_dtable_lock);
+ /* Set the process resource limits. */
+ if ((attrp->__flags & POSIX_SPAWN_SETRLIMIT) != 0)
+ {
+ uint32_t rlimitset = attrp->__rlimitset;
+ while (rlimitset != 0)
+ {
+ int resource = stdc_trailing_zeros (rlimitset);
+ if (__setrlimit64 (resource, &attrp->__rlimits[resource]) == -1)
+ goto out;
+ rlimitset &= ~(1u << resource);
+ }
+ }
+
/* Safe to let signals happen now. */
_hurd_critical_section_unlock (ss);
@@ -607,7 +607,7 @@ GLIBC_2.38 _libc_intl_domainname D 0x5
GLIBC_2.38 _longjmp F
GLIBC_2.38 _mcleanup F
GLIBC_2.38 _mcount F
-GLIBC_2.38 _nl_default_dirname D 0xe
+GLIBC_2.38 _nl_default_dirname D 0x12
GLIBC_2.38 _nl_domain_bindings D 0x8
GLIBC_2.38 _nl_msg_cat_cntr D 0x4
GLIBC_2.38 _obstack_allocated_p F
@@ -2269,6 +2269,8 @@ GLIBC_2.41 pthread_mutexattr_settype F
GLIBC_2.41 pthread_sigmask F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_barrier_destroy F
GLIBC_2.42 pthread_barrier_init F
GLIBC_2.42 pthread_barrier_wait F
@@ -536,6 +536,7 @@ tests += \
tst-spawn5-pidfd \
tst-spawn6-pidfd \
tst-spawn7-pidfd \
+ tst-spawn8-pidfd \
# tests
tests-static += \
@@ -551,11 +552,14 @@ CFLAGS-getpid.o = -fomit-frame-pointer
CFLAGS-getpid.os = -fomit-frame-pointer
CFLAGS-tst-spawn3-pidfd.c += -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-spawn8-pidfd.c += -D_FILE_OFFSET_BITS=64
+
tst-spawn-cgroup-ARGS = -- $(host-test-program-cmd)
tst-spawn-pidfd-ARGS = -- $(host-test-program-cmd)
tst-spawn5-pidfd-ARGS = -- $(host-test-program-cmd)
tst-spawn6-pidfd-ARGS = -- $(host-test-program-cmd)
tst-spawn7-pidfd-ARGS = -- $(host-test-program-cmd)
+tst-spawn8-pidfd-ARGS = -- $(host-test-program-cmd)
tst-posix_spawn-setsid-pidfd-ARGS = -- $(host-test-program-cmd)
endif
@@ -2752,6 +2752,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -16,7 +16,10 @@
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */
-#ifndef _SYS_RESOURCE_H
+#ifndef _BITS_RESOURCE_H
+#define _BITS_RESOURCE_H
+
+#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H
# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
#endif
@@ -221,3 +224,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource,
#endif
__END_DECLS
+
+#endif
@@ -3099,6 +3099,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -17,7 +17,7 @@
#define USE_VERSIONED_RLIMIT
#include <sysdeps/unix/sysv/linux/setrlimit64.c>
-versioned_symbol (libc, __setrlimit, setrlimit, GLIBC_2_27);
+versioned_symbol (libc, __setrlimit64, setrlimit, GLIBC_2_27);
versioned_symbol (libc, __setrlimit64, setrlimit64, GLIBC_2_27);
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
@@ -2513,6 +2513,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2805,6 +2805,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2802,6 +2802,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -16,7 +16,10 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#ifndef _SYS_RESOURCE_H
+#ifndef _BITS_RESOURCE_H
+#define _BITS_RESOURCE_H
+
+#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H
# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
#endif
@@ -221,3 +224,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource,
#endif
__END_DECLS
+
+#endif
@@ -2789,6 +2789,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2826,6 +2826,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -3009,6 +3009,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2273,6 +2273,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2785,6 +2785,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2952,6 +2952,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2838,6 +2838,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2835,6 +2835,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -16,7 +16,10 @@
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */
-#ifndef _SYS_RESOURCE_H
+#ifndef _BITS_RESOURCE_H
+#define _BITS_RESOURCE_H
+
+#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H
# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
#endif
@@ -229,3 +232,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource,
#endif
__END_DECLS
+
+#endif
@@ -2913,6 +2913,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2919,6 +2919,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2821,6 +2821,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2263,6 +2263,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -3142,6 +3142,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -3187,6 +3187,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2896,6 +2896,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2972,6 +2972,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2516,6 +2516,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2716,6 +2716,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -3140,6 +3140,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2933,6 +2933,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -24,12 +24,9 @@
/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
linking setrlimit64 to {__}setrlimit does not throw a type error. */
#undef setrlimit
-#undef __setrlimit
#define setrlimit setrlimit_redirect
-#define __setrlimit __setrlimit_redirect
#include <sys/resource.h>
#undef setrlimit
-#undef __setrlimit
/* Set the soft and hard limits for RESOURCE to *RLIMITS.
Only the super-user can increase hard limits.
@@ -39,17 +36,17 @@ __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
{
return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
}
+libc_hidden_def (__setrlimit64)
/* Alpha defines a versioned setrlimit{64}. */
#ifndef USE_VERSIONED_RLIMIT
weak_alias (__setrlimit64, setrlimit64)
#endif
#if __RLIM_T_MATCHES_RLIM64_T
-strong_alias (__setrlimit64, __setrlimit)
# ifndef USE_VERSIONED_RLIMIT
weak_alias (__setrlimit64, setrlimit)
# endif
# ifdef SHARED
-__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64);
+strong_alias (__setrlimit64, __GI___setrlimit)
# endif
#endif
@@ -2832,6 +2832,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2829,6 +2829,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -16,7 +16,10 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#ifndef _SYS_RESOURCE_H
+#ifndef _BITS_RESOURCE_H
+#define _BITS_RESOURCE_H
+
+#if !defined _SYS_RESOURCE_H && !defined _SPAWN_H
# error "Never use <bits/resource.h> directly; include <sys/resource.h> instead."
#endif
@@ -236,3 +239,5 @@ extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource,
#endif
__END_DECLS
+
+#endif
@@ -3161,6 +3161,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2797,6 +2797,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -27,6 +27,7 @@
#include <sysdep.h>
#include <sys/resource.h>
#include <clone_internal.h>
+#include <stdbit.h>
/* The Linux implementation of posix_spawn{p} uses the clone syscall directly
with CLONE_VM and CLONE_VFORK flags and an allocated stack. The new stack
@@ -171,6 +172,19 @@ __spawni_child (void *arguments)
|| local_setegid (__getgid ()) != 0))
goto fail;
+ /* Set the process resource limits. */
+ if ((attr->__flags & POSIX_SPAWN_SETRLIMIT) != 0)
+ {
+ uint32_t rlimitset = attr->__rlimitset;
+ while (rlimitset != 0)
+ {
+ int resource = stdc_trailing_zeros (rlimitset);
+ if (__setrlimit64 (resource, &attr->__rlimits[resource]) == -1)
+ goto fail;
+ rlimitset &= ~(1u << resource);
+ }
+ }
+
/* Execute the file actions. */
if (file_actions != NULL)
{
new file mode 100644
@@ -0,0 +1,20 @@
+/* Tests for spawn pidfd extension.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <tst-spawn-pidfd.h>
+#include <posix/tst-spawn8.c>
@@ -2748,6 +2748,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F
@@ -2767,6 +2767,8 @@ GLIBC_2.41 sched_getattr F
GLIBC_2.41 sched_setattr F
GLIBC_2.42 __inet_ntop_chk F
GLIBC_2.42 __inet_pton_chk F
+GLIBC_2.42 posix_spawnattr_getrlimit_np F
+GLIBC_2.42 posix_spawnattr_setrlimit_np F
GLIBC_2.42 pthread_gettid_np F
GLIBC_2.42 uabs F
GLIBC_2.42 uimaxabs F