From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludovic.courtes@inria.fr (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: glibc fallback code when =?utf-8?B?4oCYcHJsaW1pdDY04oCZ?= is missing Date: Fri, 30 Mar 2018 11:26:02 +0200 Message-ID: <87370hq5hx.fsf_-_@gnu.org> References: <87h8p3jfke.fsf@fastmail.com> <87a7uuhejf.fsf@elephly.net> <87po3ph0t1.fsf@fastmail.com> <87bmf8fhqf.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1qIV-0001Us-5n for guix-devel@gnu.org; Fri, 30 Mar 2018 05:26:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1qIR-0002rD-0v for guix-devel@gnu.org; Fri, 30 Mar 2018 05:26:11 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:3831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f1qIQ-0002pR-HF for guix-devel@gnu.org; Fri, 30 Mar 2018 05:26:06 -0400 In-Reply-To: <87bmf8fhqf.fsf@elephly.net> (Ricardo Wurmus's message of "Wed, 28 Mar 2018 15:32:40 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ricardo Wurmus Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Ricardo Wurmus skribis: >> Here is the commit that removes the fallback code for missing prlimit64: >> https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommitdiff;h=3D695d7d138ed= a449678a1650a8b8b58181033353f The attached patch appears to do the trick. I checked the assembly with =E2=80=9Cobjdump -S libc-2.27.so=E2=80=9D and f= ound that getrlimit and setrlimit appear to include the fallback code (using =E2=80=9Cprintf '#include \n__NR_getrlimit' |gcc -E -=E2=80= =9D to check the syscall numbers.) That said it=E2=80=99d be even better if you could check on a system running that kernel. To do that, I think it=E2=80=99s enough to run: ./pre-inst-env guix build -e '(@@ (gnu packages commencement) static-bash= -for-glibc)' and then run the resulting bash with: =E2=80=A6/bin/sh -c ulimit =E2=80=A6/bin/sh -c 'ulimit -c 1000' On my system I see: --8<---------------cut here---------------start------------->8--- $ strace -e prlimit64,getrlimit,setrlimit sh -c ulimit prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=3D62722, rlim_max=3D62722}) =3D 0 prlimit64(0, RLIMIT_FSIZE, NULL, {rlim_cur=3DRLIM64_INFINITY, rlim_max=3DRL= IM64_INFINITY}) =3D 0 unlimited +++ exited with 0 +++ $ strace -e prlimit64,getrlimit,setrlimit sh -c 'ulimit -c 1000' prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=3D62722, rlim_max=3D62722}) =3D 0 prlimit64(0, RLIMIT_CORE, NULL, {rlim_cur=3D0, rlim_max=3DRLIM64_INFINITY})= =3D 0 prlimit64(0, RLIMIT_CORE, NULL, {rlim_cur=3D0, rlim_max=3DRLIM64_INFINITY})= =3D 0 prlimit64(0, RLIMIT_CORE, {rlim_cur=3D500*1024, rlim_max=3D500*1024}, NULL)= =3D 0 --8<---------------cut here---------------end--------------->8--- On 2.6.32, you should see ENOSYS followed by =E2=80=98setrlimit=E2=80=99 or= =E2=80=98getrlimit=E2=80=99. Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-gnu-glibc-Reinstate-fallback-code-for-systems-lackin.patch Content-Description: the patch >From d33a6558a095debd806cf48e56ee41e5dae1c12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 30 Mar 2018 11:18:47 +0200 Subject: [PATCH] gnu: glibc: Reinstate fallback code for systems lacking 'prlimit64'. * gnu/packages/patches/glibc-reinstate-prlimit64-fallback.patch: New file. * gnu/packages/base.scm (glibc/linux)[source]: Use it. * gnu/local.mk (dist_patch_DATA): Add it. --- gnu/local.mk | 1 + gnu/packages/base.scm | 3 +- .../glibc-reinstate-prlimit64-fallback.patch | 127 +++++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/glibc-reinstate-prlimit64-fallback.patch diff --git a/gnu/local.mk b/gnu/local.mk index 7bb09fc7a..b99b40353 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -723,6 +723,7 @@ dist_patch_DATA = \ %D%/packages/patches/glibc-locales.patch \ %D%/packages/patches/glibc-memchr-overflow-i686.patch \ %D%/packages/patches/glibc-o-largefile.patch \ + %D%/packages/patches/glibc-reinstate-prlimit64-fallback.patch \ %D%/packages/patches/glibc-vectorized-strcspn-guards.patch \ %D%/packages/patches/glibc-versioned-locpath.patch \ %D%/packages/patches/glibc-2.27-git-fixes.patch \ diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm index e09af515d..1cbb7ae0e 100644 --- a/gnu/packages/base.scm +++ b/gnu/packages/base.scm @@ -568,7 +568,8 @@ store.") "glibc-2.27-git-fixes.patch" "glibc-hidden-visibility-ldconfig.patch" "glibc-versioned-locpath.patch" - "glibc-allow-kernel-2.6.32.patch")))) + "glibc-allow-kernel-2.6.32.patch" + "glibc-reinstate-prlimit64-fallback.patch")))) (build-system gnu-build-system) ;; Glibc's refers to , for instance, so glibc diff --git a/gnu/packages/patches/glibc-reinstate-prlimit64-fallback.patch b/gnu/packages/patches/glibc-reinstate-prlimit64-fallback.patch new file mode 100644 index 000000000..ccc153c12 --- /dev/null +++ b/gnu/packages/patches/glibc-reinstate-prlimit64-fallback.patch @@ -0,0 +1,127 @@ +This patch reinstates fallback code when the 'prlimit64' system call is +missing by reverting the relevant part of this upstream commit: + + commit 695d7d138eda449678a1650a8b8b58181033353f + Author: Joseph Myers + Date: Tue May 9 14:05:09 2017 +0000 + + Assume prlimit64 is available. + +The fallback code is useful on systems that lack 'prlimit64', such as the +2.6.32-on-steroid kernel found on RHEL 6: + + + +diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c +index 37c173286f..56af3c0646 100644 +--- b/sysdeps/unix/sysv/linux/getrlimit64.c ++++ a/sysdeps/unix/sysv/linux/getrlimit64.c +@@ -35,7 +35,40 @@ + int + __getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits) + { +- return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits); ++#ifdef __NR_prlimit64 ++ int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits); ++ if (res == 0 || errno != ENOSYS) ++ return res; ++#endif ++ ++/* The fallback code only makes sense if the platform supports either ++ __NR_ugetrlimit and/or __NR_getrlimit. */ ++#if defined (__NR_ugetrlimit) || defined (__NR_getrlimit) ++# ifndef __NR_ugetrlimit ++# define __NR_ugetrlimit __NR_getrlimit ++# endif ++# if __RLIM_T_MATCHES_RLIM64_T ++# define rlimits32 (*rlimits) ++# else ++ struct rlimit rlimits32; ++# endif ++ ++ if (INLINE_SYSCALL_CALL (ugetrlimit, resource, &rlimits32) < 0) ++ return -1; ++ ++# if !__RLIM_T_MATCHES_RLIM64_T ++ if (rlimits32.rlim_cur == RLIM_INFINITY) ++ rlimits->rlim_cur = RLIM64_INFINITY; ++ else ++ rlimits->rlim_cur = rlimits32.rlim_cur; ++ if (rlimits32.rlim_max == RLIM_INFINITY) ++ rlimits->rlim_max = RLIM64_INFINITY; ++ else ++ rlimits->rlim_max = rlimits32.rlim_max; ++# endif /* !__RLIM_T_MATCHES_RLIM64_T */ ++#endif /* defined (__NR_ugetrlimit) || defined (__NR_getrlimit) */ ++ ++ return 0; + } + libc_hidden_def (__getrlimit64) + +diff --git a/sysdeps/unix/sysv/linux/setrlimit.c b/sysdeps/unix/sysv/linux/setrlimit.c +index 01812ac355..8773c78236 100644 +--- b/sysdeps/unix/sysv/linux/setrlimit.c ++++ a/sysdeps/unix/sysv/linux/setrlimit.c +@@ -34,6 +34,7 @@ + int + __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlim) + { ++# ifdef __NR_prlimit64 + struct rlimit64 rlim64; + + if (rlim->rlim_cur == RLIM_INFINITY) +@@ -45,7 +46,11 @@ + else + rlim64.rlim_max = rlim->rlim_max; + +- return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL); ++ int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL); ++ if (res == 0 || errno != ENOSYS) ++ return res; ++# endif ++ return INLINE_SYSCALL_CALL (setrlimit, resource, rlim); + } + + # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) +diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c +index 2dd129d99e..db1960fc18 100644 +--- b/sysdeps/unix/sysv/linux/setrlimit64.c ++++ a/sysdeps/unix/sysv/linux/setrlimit64.c +@@ -36,7 +36,36 @@ + int + __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits) + { +- return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL); ++ int res; ++ ++#ifdef __NR_prlimit64 ++ res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL); ++ if (res == 0 || errno != ENOSYS) ++ return res; ++#endif ++ ++/* The fallback code only makes sense if the platform supports ++ __NR_setrlimit. */ ++#ifdef __NR_setrlimit ++# if !__RLIM_T_MATCHES_RLIM64_T ++ struct rlimit rlimits32; ++ ++ if (rlimits->rlim_cur >= RLIM_INFINITY) ++ rlimits32.rlim_cur = RLIM_INFINITY; ++ else ++ rlimits32.rlim_cur = rlimits->rlim_cur; ++ if (rlimits->rlim_max >= RLIM_INFINITY) ++ rlimits32.rlim_max = RLIM_INFINITY; ++ else ++ rlimits32.rlim_max = rlimits->rlim_max; ++# else ++# define rlimits32 (*rlimits) ++# endif ++ ++ res = INLINE_SYSCALL_CALL (setrlimit, resource, &rlimits32); ++#endif ++ ++ return res; + } + weak_alias (__setrlimit64, setrlimit64) + -- 2.16.2 --=-=-=--