1 This patch reinstates fallback code when the 'prlimit64' system call is
2 missing by reverting the relevant part of this upstream commit:
4 commit 695d7d138eda449678a1650a8b8b58181033353f
5 Author: Joseph Myers <joseph@codesourcery.com>
6 Date: Tue May 9 14:05:09 2017 +0000
8 Assume prlimit64 is available.
10 The fallback code is useful on systems that lack 'prlimit64', such as the
11 2.6.32-on-steroid kernel found on RHEL 6:
13 <https://lists.gnu.org/archive/html/guix-devel/2018-03/msg00349.html>
15 diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
16 index 37c173286f..56af3c0646 100644
17 --- b/sysdeps/unix/sysv/linux/getrlimit64.c
18 +++ a/sysdeps/unix/sysv/linux/getrlimit64.c
21 __getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
23 - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
24 +#ifdef __NR_prlimit64
25 + int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
26 + if (res == 0 || errno != ENOSYS)
30 +/* The fallback code only makes sense if the platform supports either
31 + __NR_ugetrlimit and/or __NR_getrlimit. */
32 +#if defined (__NR_ugetrlimit) || defined (__NR_getrlimit)
33 +# ifndef __NR_ugetrlimit
34 +# define __NR_ugetrlimit __NR_getrlimit
36 +# if __RLIM_T_MATCHES_RLIM64_T
37 +# define rlimits32 (*rlimits)
39 + struct rlimit rlimits32;
42 + if (INLINE_SYSCALL_CALL (ugetrlimit, resource, &rlimits32) < 0)
45 +# if !__RLIM_T_MATCHES_RLIM64_T
46 + if (rlimits32.rlim_cur == RLIM_INFINITY)
47 + rlimits->rlim_cur = RLIM64_INFINITY;
49 + rlimits->rlim_cur = rlimits32.rlim_cur;
50 + if (rlimits32.rlim_max == RLIM_INFINITY)
51 + rlimits->rlim_max = RLIM64_INFINITY;
53 + rlimits->rlim_max = rlimits32.rlim_max;
54 +# endif /* !__RLIM_T_MATCHES_RLIM64_T */
55 +#endif /* defined (__NR_ugetrlimit) || defined (__NR_getrlimit) */
59 libc_hidden_def (__getrlimit64)
61 diff --git a/sysdeps/unix/sysv/linux/setrlimit.c b/sysdeps/unix/sysv/linux/setrlimit.c
62 index 01812ac355..8773c78236 100644
63 --- b/sysdeps/unix/sysv/linux/setrlimit.c
64 +++ a/sysdeps/unix/sysv/linux/setrlimit.c
67 __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlim)
69 +# ifdef __NR_prlimit64
70 struct rlimit64 rlim64;
72 if (rlim->rlim_cur == RLIM_INFINITY)
75 rlim64.rlim_max = rlim->rlim_max;
77 - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL);
78 + int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL);
79 + if (res == 0 || errno != ENOSYS)
82 + return INLINE_SYSCALL_CALL (setrlimit, resource, rlim);
85 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
86 diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
87 index 2dd129d99e..db1960fc18 100644
88 --- b/sysdeps/unix/sysv/linux/setrlimit64.c
89 +++ a/sysdeps/unix/sysv/linux/setrlimit64.c
92 __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
94 - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
97 +#ifdef __NR_prlimit64
98 + res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
99 + if (res == 0 || errno != ENOSYS)
103 +/* The fallback code only makes sense if the platform supports
105 +#ifdef __NR_setrlimit
106 +# if !__RLIM_T_MATCHES_RLIM64_T
107 + struct rlimit rlimits32;
109 + if (rlimits->rlim_cur >= RLIM_INFINITY)
110 + rlimits32.rlim_cur = RLIM_INFINITY;
112 + rlimits32.rlim_cur = rlimits->rlim_cur;
113 + if (rlimits->rlim_max >= RLIM_INFINITY)
114 + rlimits32.rlim_max = RLIM_INFINITY;
116 + rlimits32.rlim_max = rlimits->rlim_max;
118 +# define rlimits32 (*rlimits)
121 + res = INLINE_SYSCALL_CALL (setrlimit, resource, &rlimits32);
126 weak_alias (__setrlimit64, setrlimit64)