unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: ludovic.courtes@inria.fr (Ludovic Courtès)
To: Ricardo Wurmus <rekado@elephly.net>
Cc: guix-devel@gnu.org
Subject: glibc fallback code when ‘prlimit64’ is missing
Date: Fri, 30 Mar 2018 11:26:02 +0200	[thread overview]
Message-ID: <87370hq5hx.fsf_-_@gnu.org> (raw)
In-Reply-To: <87bmf8fhqf.fsf@elephly.net> (Ricardo Wurmus's message of "Wed, 28 Mar 2018 15:32:40 +0200")

[-- Attachment #1: Type: text/plain, Size: 1737 bytes --]

Hello,

Ricardo Wurmus <rekado@elephly.net> skribis:

>> Here is the commit that removes the fallback code for missing prlimit64:
>> https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=695d7d138eda449678a1650a8b8b58181033353f

The attached patch appears to do the trick.

I checked the assembly with “objdump -S libc-2.27.so” and found that
getrlimit and setrlimit appear to include the fallback code (using
“printf '#include <sys/syscall.h>\n__NR_getrlimit' |gcc -E -” to check
the syscall numbers.)

That said it’d be even better if you could check on a system running
that kernel.  To do that, I think it’s enough to run:

  ./pre-inst-env guix build -e '(@@ (gnu packages commencement) static-bash-for-glibc)'

and then run the resulting bash with:

  …/bin/sh -c ulimit
  …/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=62722, rlim_max=62722}) = 0
prlimit64(0, RLIMIT_FSIZE, NULL, {rlim_cur=RLIM64_INFINITY, rlim_max=RLIM64_INFINITY}) = 0
unlimited
+++ exited with 0 +++
$ strace -e prlimit64,getrlimit,setrlimit sh -c 'ulimit -c 1000'
prlimit64(0, RLIMIT_NPROC, NULL, {rlim_cur=62722, rlim_max=62722}) = 0
prlimit64(0, RLIMIT_CORE, NULL, {rlim_cur=0, rlim_max=RLIM64_INFINITY}) = 0
prlimit64(0, RLIMIT_CORE, NULL, {rlim_cur=0, rlim_max=RLIM64_INFINITY}) = 0
prlimit64(0, RLIMIT_CORE, {rlim_cur=500*1024, rlim_max=500*1024}, NULL) = 0
--8<---------------cut here---------------end--------------->8---

On 2.6.32, you should see ENOSYS followed by ‘setrlimit’ or ‘getrlimit’.

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: the patch --]
[-- Type: text/x-patch, Size: 6466 bytes --]

From d33a6558a095debd806cf48e56ee41e5dae1c12c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludovic.courtes@inria.fr>
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 <limits.h> refers to <linux/limit.h>, 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 <joseph@codesourcery.com>
+  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:
+
+  <https://lists.gnu.org/archive/html/guix-devel/2018-03/msg00349.html>
+
+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


  parent reply	other threads:[~2018-03-30  9:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-26 10:29 'core-updates' spring 2018 Marius Bakke
2018-03-26 14:09 ` Ludovic Courtès
2018-03-26 18:34 ` Ricardo Wurmus
2018-03-27 12:03   ` Gábor Boskovits
2018-03-28 19:46     ` Ricardo Wurmus
2018-03-27 17:43   ` Marius Bakke
2018-03-28 13:32     ` Ricardo Wurmus
2018-03-29 11:29       ` Ludovic Courtès
2018-03-30  9:26       ` Ludovic Courtès [this message]
2018-04-01 10:37         ` glibc fallback code when ‘prlimit64’ is missing Ludovic Courtès
2018-03-27 20:28 ` 'core-updates' spring 2018 Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87370hq5hx.fsf_-_@gnu.org \
    --to=ludovic.courtes@inria.fr \
    --cc=guix-devel@gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).