public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines
@ 2018-01-05 13:24 Aurelien Jarno
  2018-01-05 13:24 ` [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Aurelien Jarno
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-05 13:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: Aurelien Jarno

Since commit 045c13d185 ("Consolidate Linux setrlimit and getrlimit
implementation") which is in glibc 2.25, the getrlimit and setrlimit
functions are broken when used with RLIM_INFINITY on alpha. The commit
changed the syscalls behind these functions from getrlimit/setrlimit to
prlimit64. RLIM_INFINITY is not represented the same way in these
syscalls on alpha. The getrlimit/setrlimit syscalls use the same
definition than the GNU libc, that is 0x7fffffffffffffff while prlimit64
uses a standard value across all architectures which is 0xffffffffffffffff.

The commit therefore broke the getrlimit/setrlimit functions on alpha,
and is the reason why dozens of the glibc tests abort with:

  allocatestack.c:480: allocate_stack: Assertion `size != 0' failed.

This patch series fixes that in two steps, the first patch adds a
wrapper to fix the value before/after the syscall and can be backported
to stable branches. The second add a new symbol so that the
RLIM_INFINITY value can be changed to the same value as in the kernel
and other architectures.

The third patch fixes an issue with prlimit and RLIM_INFINITY on 32-bit
machines found while writing a test. The last patch add a test to detect
such issueS.

Aurelien Jarno (4):
  Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant
    [BZ #22648]
  Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants
  prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY
    [BZ #22678]
  Add test for getrlimit/setrlimit/prlimit with infinity value

 ChangeLog                                     |  41 +++++++
 sysdeps/unix/sysv/linux/Makefile              |   3 +-
 sysdeps/unix/sysv/linux/alpha/Versions        |   3 +
 sysdeps/unix/sysv/linux/alpha/bits/resource.h |   6 +-
 sysdeps/unix/sysv/linux/alpha/getrlimit64.c   |  56 +++++++++
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   4 +
 sysdeps/unix/sysv/linux/alpha/setrlimit64.c   |  53 +++++++++
 sysdeps/unix/sysv/linux/getrlimit64.c         |  18 +--
 sysdeps/unix/sysv/linux/prlimit.c             |  15 ++-
 sysdeps/unix/sysv/linux/setrlimit64.c         |   5 +
 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c | 157 ++++++++++++++++++++++++++
 11 files changed, 342 insertions(+), 19 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/getrlimit64.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/setrlimit64.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c

-- 
2.15.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2018-01-05 13:24 [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Aurelien Jarno
  2018-01-05 13:24 ` [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Aurelien Jarno
@ 2018-01-05 13:24 ` Aurelien Jarno
  2018-01-05 13:24 ` [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678] Aurelien Jarno
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-05 13:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: Aurelien Jarno

RLIM64_INFINITY was supposed to be a glibc convention rather than
anything seen by the kernel, but it ended being passed to the kernel
through the prlimit64 syscall.

* On the kernel side, the value is defined for the prlimit64 syscall for
  all architectures in include/uapi/linux/resource.h:

  #define RLIM64_INFINITY           (~0ULL)

* On the kernel side, the value is defined for getrlimit and setrlimit
  in arch/alpha/include/uapi/asm/resource.h

  #define RLIM_INFINITY            0x7ffffffffffffffful

* On the GNU libc side, the value is defined in
  sysdeps/unix/sysv/linux/alpha/bits/resource.h:

  # define RLIM64_INFINITY 0x7fffffffffffffffLL

This was not an issue until the getrlimit and setrlimit glibc functions
have been changed in commit 045c13d185 ("Consolidate Linux setrlimit and
getrlimit implementation") to use the prlimit64 syscall instead of the
getrlimit and setrlimit ones.

This patch fixes that by adding a wrapper to fix the value passed to or
received from the kernel, before or after calling the prlimit64 syscall.

Changelog:
	[BZ #22648]
	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: New file.
	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto.
---
 ChangeLog                                   |  6 +++
 sysdeps/unix/sysv/linux/alpha/getrlimit64.c | 64 +++++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/alpha/setrlimit64.c | 61 +++++++++++++++++++++++++++
 3 files changed, 131 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/getrlimit64.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/setrlimit64.c

diff --git a/ChangeLog b/ChangeLog
index ddd49200ed..489cd1fd84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
+
+	[BZ #22648]
+	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: New file.
+	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto.
+
 2018-01-04  Joseph Myers  <joseph@codesourcery.com>
 
 	* malloc/tst-malloc-tcache-leak.c (TIMEOUT): Define to 50.
diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
new file mode 100644
index 0000000000..908be53180
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 2018 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 <errno.h>
+#include <sys/types.h>
+
+/* Add this redirection so the strong_alias linking getrlimit64 to
+   {__}getrlimit does not throw a type error.  */
+#undef getrlimit
+#undef __getrlimit
+#define getrlimit getrlimit_redirect
+#define __getrlimit __getrlimit_redirect
+#include <sys/resource.h>
+#undef getrlimit
+#undef __getrlimit
+
+/* RLIM64_INFINITY was supposed to be a glibc convention rather than
+   anything seen by the kernel, but it ended being passed to the kernel
+   through the prlimit64 syscall.  Given that a lot of binaries with
+   the wrong constant value are in the wild, provide a wrapper function
+   fixing the value after the syscall.  */
+#define KERNEL_RLIM64_INFINITY		0xffffffffffffffffULL
+
+int
+__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
+{
+  struct rlimit64 krlimits;
+
+  if (INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, &krlimits) < 0)
+    return -1;
+
+  if (krlimits.rlim_cur == KERNEL_RLIM64_INFINITY)
+    rlimits->rlim_cur = RLIM64_INFINITY;
+  else
+    rlimits->rlim_cur = krlimits.rlim_cur;
+  if (krlimits.rlim_max == KERNEL_RLIM64_INFINITY)
+    rlimits->rlim_max = RLIM64_INFINITY;
+  else
+    rlimits->rlim_max = krlimits.rlim_max;
+
+  return 0;
+}
+libc_hidden_def (__getrlimit64)
+strong_alias (__getrlimit64, __GI_getrlimit)
+strong_alias (__getrlimit64, __GI___getrlimit)
+strong_alias (__getrlimit64, __getrlimit)
+weak_alias (__getrlimit64, getrlimit)
+
+weak_alias (__getrlimit64, getrlimit64)
+libc_hidden_weak (getrlimit64)
diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
new file mode 100644
index 0000000000..1b8a95b9e9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2018 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 <errno.h>
+#include <sys/types.h>
+
+/* Add this redirection so the strong_alias 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
+
+/* RLIM64_INFINITY was supposed to be a glibc convention rather than
+   anything seen by the kernel, but it ended being passed to the kernel
+   through the prlimit64 syscall.  Given that a lot of binaries with
+   the wrong constant value are in the wild, provide a wrapper function
+   fixing the value before the syscall.  */
+#define KERNEL_RLIM64_INFINITY		0xffffffffffffffffULL
+
+int
+__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
+{
+  struct rlimit64 krlimits;
+
+  if (rlimits->rlim_cur == RLIM64_INFINITY)
+    krlimits.rlim_cur = KERNEL_RLIM64_INFINITY;
+  else
+    krlimits.rlim_cur = rlimits->rlim_cur;
+  if (rlimits->rlim_max == RLIM64_INFINITY)
+    krlimits.rlim_max = KERNEL_RLIM64_INFINITY;
+  else
+    krlimits.rlim_max = rlimits->rlim_max;
+
+  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &krlimits, NULL);
+}
+
+weak_alias (__setrlimit64, setrlimit64)
+
+strong_alias (__setrlimit64, __setrlimit)
+weak_alias (__setrlimit64, setrlimit)
+#ifdef SHARED
+__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64);
+#endif
-- 
2.15.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants
  2018-01-05 13:24 [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Aurelien Jarno
                   ` (2 preceding siblings ...)
  2018-01-05 13:24 ` [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678] Aurelien Jarno
@ 2018-01-05 13:24 ` Aurelien Jarno
  2018-01-05 23:55 ` [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Joseph Myers
  4 siblings, 0 replies; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-05 13:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: Aurelien Jarno

Fix the RLIM_INFINITY and RLIM64_INFINITY constants on alpha to match
the kernel one and all other architectures. Change the getrlimit,
getrlimit64, setrlimit, setrlimit64 into old compat symbols, and provide
the Linux generic functions as GLIBC_2_27 version.

Changelog:
	* sysdeps/unix/sysv/linux/getrlimit64.c [USE_VERSIONED_RLIMIT]: Do not
	define getrlimit and getrlimit64 as weak aliases of __getrlimit64.
	Define __GI_getrlimit64 as weak alias of __getrlimit64.
	[__RLIM_T_MATCHES_RLIM64_T]: Do not redefine SHLIB_COMPAT, use #elif
	instead.
	* sysdeps/unix/sysv/linux/setrlimit64.c [USE_VERSIONED_RLIMIT]: Do not
	define setrlimit and setrlimit64 as weak aliases of __setrlimit64.
	* sysdeps/unix/sysv/linux/alpha/bits/resource.h (RLIM_INFINITY,
	RLIM64_INFINITY): Fix values to match the kernel ones.
	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Define
	USE_VERSIONED_RLIMIT.  Rename __getrlimit64 into __old_getrlimit64 and
	provide it as getrlimit@@GLIBC_2_0 and getrlimit64@@GLIBC_2_1.  Add a
	__getrlimit64 function and provide it as getrlimit@@GLIBC_2_27 and
	getrlimit64@@GLIBC_2_27.
	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto with setrlimit
	and setrlimit64.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.27): Add
	getrlimit, setrlimit, getrlimit64 and setrlimit64.
	* sysdeps/unix/sysv/linux/alpha/Versions (libc): Add getrlimit,
	setrlimit, getrlimit64 and setrlimit64.
---
 ChangeLog                                     | 24 +++++++++++++++
 sysdeps/unix/sysv/linux/alpha/Versions        |  3 ++
 sysdeps/unix/sysv/linux/alpha/bits/resource.h |  6 ++--
 sysdeps/unix/sysv/linux/alpha/getrlimit64.c   | 44 +++++++++++----------------
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  4 +++
 sysdeps/unix/sysv/linux/alpha/setrlimit64.c   | 42 +++++++++++--------------
 sysdeps/unix/sysv/linux/getrlimit64.c         | 18 +++++------
 sysdeps/unix/sysv/linux/setrlimit64.c         |  5 +++
 8 files changed, 83 insertions(+), 63 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 489cd1fd84..fd0fc0bc71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
+	    Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* sysdeps/unix/sysv/linux/getrlimit64.c [USE_VERSIONED_RLIMIT]: Do not
+	define getrlimit and getrlimit64 as weak aliases of __getrlimit64.
+	Define __GI_getrlimit64 as weak alias of __getrlimit64.
+	[__RLIM_T_MATCHES_RLIM64_T]: Do not redefine SHLIB_COMPAT, use #elif
+	instead.
+	* sysdeps/unix/sysv/linux/setrlimit64.c [USE_VERSIONED_RLIMIT]: Do not
+	define setrlimit and setrlimit64 as weak aliases of __setrlimit64.
+	* sysdeps/unix/sysv/linux/alpha/bits/resource.h (RLIM_INFINITY,
+	RLIM64_INFINITY): Fix values to match the kernel ones.
+	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Define
+	USE_VERSIONED_RLIMIT.  Rename __getrlimit64 into __old_getrlimit64 and
+	provide it as getrlimit@@GLIBC_2_0 and getrlimit64@@GLIBC_2_1.  Add a
+	__getrlimit64 function and provide it as getrlimit@@GLIBC_2_27 and
+	getrlimit64@@GLIBC_2_27.
+	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto with setrlimit
+	and setrlimit64.
+	* sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.27): Add
+	getrlimit, setrlimit, getrlimit64 and setrlimit64.
+	* sysdeps/unix/sysv/linux/alpha/Versions (libc): Add getrlimit,
+	setrlimit, getrlimit64 and setrlimit64.
+
 2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
 
 	[BZ #22648]
diff --git a/sysdeps/unix/sysv/linux/alpha/Versions b/sysdeps/unix/sysv/linux/alpha/Versions
index 29b82f999b..3b7971c2a3 100644
--- a/sysdeps/unix/sysv/linux/alpha/Versions
+++ b/sysdeps/unix/sysv/linux/alpha/Versions
@@ -85,6 +85,9 @@ libc {
     #errlist-compat	140
     _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
   }
+  GLIBC_2.27 {
+    getrlimit; setrlimit; getrlimit64; setrlimit64;
+  }
   GLIBC_PRIVATE {
     __libc_alpha_cache_shape;
   }
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/resource.h b/sysdeps/unix/sysv/linux/alpha/bits/resource.h
index ac05cbb803..dddcb0f049 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/resource.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/resource.h
@@ -112,13 +112,13 @@ enum __rlimit_resource
 
 /* Value to indicate that there is no limit.  */
 #ifndef __USE_FILE_OFFSET64
-# define RLIM_INFINITY ((long int)(~0UL >> 1))
+# define RLIM_INFINITY ((__rlim_t) -1)
 #else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffuLL
 #endif
 
 #ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffuLL
 #endif
 
 /* We can represent all limits.  */
diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
index 908be53180..5502586462 100644
--- a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
@@ -15,50 +15,42 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <sys/types.h>
-
-/* Add this redirection so the strong_alias linking getrlimit64 to
-   {__}getrlimit does not throw a type error.  */
-#undef getrlimit
-#undef __getrlimit
-#define getrlimit getrlimit_redirect
-#define __getrlimit __getrlimit_redirect
-#include <sys/resource.h>
-#undef getrlimit
-#undef __getrlimit
+#define USE_VERSIONED_RLIMIT
+#include <sysdeps/unix/sysv/linux/getrlimit64.c>
+versioned_symbol (libc, __getrlimit, getrlimit, GLIBC_2_27);
+versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_27);
 
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
 /* RLIM64_INFINITY was supposed to be a glibc convention rather than
    anything seen by the kernel, but it ended being passed to the kernel
    through the prlimit64 syscall.  Given that a lot of binaries with
    the wrong constant value are in the wild, provide a wrapper function
    fixing the value after the syscall.  */
-#define KERNEL_RLIM64_INFINITY		0xffffffffffffffffULL
+# define OLD_RLIM64_INFINITY           0x7fffffffffffffffULL
 
 int
-__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
+attribute_compat_text_section
+__old_getrlimit64 (enum __rlimit_resource resource,
+		   struct rlimit64 *rlimits)
 {
   struct rlimit64 krlimits;
 
-  if (INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, &krlimits) < 0)
+  if (__getrlimit64 (resource, &krlimits) < 0)
     return -1;
 
-  if (krlimits.rlim_cur == KERNEL_RLIM64_INFINITY)
-    rlimits->rlim_cur = RLIM64_INFINITY;
+  if (krlimits.rlim_cur == RLIM64_INFINITY)
+    rlimits->rlim_cur = OLD_RLIM64_INFINITY;
   else
     rlimits->rlim_cur = krlimits.rlim_cur;
-  if (krlimits.rlim_max == KERNEL_RLIM64_INFINITY)
-    rlimits->rlim_max = RLIM64_INFINITY;
+  if (krlimits.rlim_max == RLIM64_INFINITY)
+    rlimits->rlim_max = OLD_RLIM64_INFINITY;
   else
     rlimits->rlim_max = krlimits.rlim_max;
 
   return 0;
 }
-libc_hidden_def (__getrlimit64)
-strong_alias (__getrlimit64, __GI_getrlimit)
-strong_alias (__getrlimit64, __GI___getrlimit)
-strong_alias (__getrlimit64, __getrlimit)
-weak_alias (__getrlimit64, getrlimit)
 
-weak_alias (__getrlimit64, getrlimit64)
-libc_hidden_weak (getrlimit64)
+strong_alias (__old_getrlimit64, __old_getrlimit)
+compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0);
+compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist
index fd2d81fb68..8674a874b4 100644
--- a/sysdeps/unix/sysv/linux/alpha/libc.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist
@@ -2016,6 +2016,8 @@ GLIBC_2.26 pwritev64v2 F
 GLIBC_2.26 reallocarray F
 GLIBC_2.27 GLIBC_2.27 A
 GLIBC_2.27 copy_file_range F
+GLIBC_2.27 getrlimit F
+GLIBC_2.27 getrlimit64 F
 GLIBC_2.27 glob F
 GLIBC_2.27 glob64 F
 GLIBC_2.27 memfd_create F
@@ -2025,6 +2027,8 @@ GLIBC_2.27 pkey_free F
 GLIBC_2.27 pkey_get F
 GLIBC_2.27 pkey_mprotect F
 GLIBC_2.27 pkey_set F
+GLIBC_2.27 setrlimit F
+GLIBC_2.27 setrlimit64 F
 GLIBC_2.27 strfromf128 F
 GLIBC_2.27 strfromf32 F
 GLIBC_2.27 strfromf32x F
diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
index 1b8a95b9e9..871c878b7e 100644
--- a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
@@ -15,47 +15,39 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <sys/types.h>
-
-/* Add this redirection so the strong_alias 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
+#define USE_VERSIONED_RLIMIT
+#include <sysdeps/unix/sysv/linux/setrlimit64.c>
+versioned_symbol (libc, __setrlimit, setrlimit, GLIBC_2_27);
+versioned_symbol (libc, __setrlimit64, setrlimit64, GLIBC_2_27);
 
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
 /* RLIM64_INFINITY was supposed to be a glibc convention rather than
    anything seen by the kernel, but it ended being passed to the kernel
    through the prlimit64 syscall.  Given that a lot of binaries with
    the wrong constant value are in the wild, provide a wrapper function
    fixing the value before the syscall.  */
-#define KERNEL_RLIM64_INFINITY		0xffffffffffffffffULL
+# define OLD_RLIM64_INFINITY           0x7fffffffffffffffULL
 
 int
-__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
+attribute_compat_text_section
+__old_setrlimit64 (enum __rlimit_resource resource,
+		   const struct rlimit64 *rlimits)
 {
   struct rlimit64 krlimits;
 
-  if (rlimits->rlim_cur == RLIM64_INFINITY)
-    krlimits.rlim_cur = KERNEL_RLIM64_INFINITY;
+  if (rlimits->rlim_cur == OLD_RLIM64_INFINITY)
+    krlimits.rlim_cur = RLIM64_INFINITY;
   else
     krlimits.rlim_cur = rlimits->rlim_cur;
-  if (rlimits->rlim_max == RLIM64_INFINITY)
-    krlimits.rlim_max = KERNEL_RLIM64_INFINITY;
+  if (rlimits->rlim_max == OLD_RLIM64_INFINITY)
+    krlimits.rlim_max = RLIM64_INFINITY;
   else
     krlimits.rlim_max = rlimits->rlim_max;
 
-  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &krlimits, NULL);
+  return __setrlimit64 (resource, &krlimits);
 }
 
-weak_alias (__setrlimit64, setrlimit64)
-
-strong_alias (__setrlimit64, __setrlimit)
-weak_alias (__setrlimit64, setrlimit)
-#ifdef SHARED
-__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64);
+strong_alias (__old_setrlimit64, __old_setrlimit)
+compat_symbol (libc, __old_setrlimit, setrlimit, GLIBC_2_0);
+compat_symbol (libc, __old_setrlimit64, setrlimit64, GLIBC_2_1);
 #endif
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 3750cf22fa..1cc82e364d 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -45,13 +45,16 @@ libc_hidden_def (__getrlimit64)
 strong_alias (__getrlimit64, __GI_getrlimit)
 strong_alias (__getrlimit64, __GI___getrlimit)
 strong_alias (__getrlimit64, __getrlimit)
+/* Alpha defines a versioned getrlimit{64}.  */
+# ifndef USE_VERSIONED_RLIMIT
 weak_alias (__getrlimit64, getrlimit)
-/* And there is no need for compat symbols.  */
-# undef SHLIB_COMPAT
-# define SHLIB_COMPAT(a, b, c) 0
-#endif
+weak_alias (__getrlimit64, getrlimit64)
+libc_hidden_weak (getrlimit64)
+# else
+weak_alias (__getrlimit64, __GI_getrlimit64)
+# endif
 
-#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
+#elif SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)
 /* Back compatible 2GiB limited rlimit.  */
 extern int __new_getrlimit (enum __rlimit_resource, struct rlimit *)
   attribute_hidden;
@@ -78,7 +81,4 @@ __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 }
 versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
 compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
-#else
-weak_alias (__getrlimit64, getrlimit64)
-libc_hidden_weak (getrlimit64)
-#endif
+#endif /* __RLIM_T_MATCHES_RLIM64_T  */
diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
index 3ec831fb4d..860fccb548 100644
--- a/sysdeps/unix/sysv/linux/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/setrlimit64.c
@@ -38,11 +38,16 @@ __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
 {
   return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
 }
+/* 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);
 # endif
-- 
2.15.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678]
  2018-01-05 13:24 [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Aurelien Jarno
  2018-01-05 13:24 ` [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Aurelien Jarno
  2018-01-05 13:24 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
@ 2018-01-05 13:24 ` Aurelien Jarno
  2018-01-05 13:54   ` Adhemerval Zanella
  2018-01-05 13:24 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
  2018-01-05 23:55 ` [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Joseph Myers
  4 siblings, 1 reply; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-05 13:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: Aurelien Jarno

prlimit called without a new value fails on 32-bit machines if any of
the soft or hard limits are infinity. This is because prlimit does not
translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY, but checks
that the value returned by the prlimit64 syscall fits into a 32-bit
value, like it is done for example in getrlimit. Note that on the
other hand new_rlimit is correctly translated from RLIM_INFINITY to
RLIM64_INFINITY before calling the syscall.

This patch fixes that.

Changelog:
	[BZ #22678]
	* sysdeps/unix/sysv/linux/prlimit.c (prlimit): Translate
	old_rlimit from RLIM64_INFINITY to RLIM_INFINITY.
---
 ChangeLog                         |  6 ++++++
 sysdeps/unix/sysv/linux/prlimit.c | 15 +++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fd0fc0bc71..53c3d62b2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
+
+	[BZ #22678]
+	* sysdeps/unix/sysv/linux/prlimit.c (prlimit): Translate
+	old_rlimit from RLIM64_INFINITY to RLIM_INFINITY.
+
 2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
 	    Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
diff --git a/sysdeps/unix/sysv/linux/prlimit.c b/sysdeps/unix/sysv/linux/prlimit.c
index 9db8e821b3..2fa0642c76 100644
--- a/sysdeps/unix/sysv/linux/prlimit.c
+++ b/sysdeps/unix/sysv/linux/prlimit.c
@@ -50,21 +50,24 @@ prlimit (__pid_t pid, enum __rlimit_resource resource,
     {
       /* The prlimit64 syscall is ill-designed for 32-bit machines.
 	 We have to provide a 32-bit variant since otherwise the LFS
-	 system would not work.  But what shall we do if the syscall
-	 succeeds but the old values do not fit into a rlimit
-	 structure?  We cannot return an error because the operation
-	 itself worked.  Best is perhaps to return RLIM_INFINITY.  */
+	 system would not work.  The infinity value can be translated,
+	 but otherwise what shall we do if the syscall succeeds but the
+	 old values do not fit into a rlimit structure?  We cannot return
+	 an error because the operation itself worked.  Best is perhaps
+	 to return RLIM_INFINITY.  */
       old_rlimit->rlim_cur = old_rlimit64_mem.rlim_cur;
       if (old_rlimit->rlim_cur != old_rlimit64_mem.rlim_cur)
 	{
-	  if (new_rlimit == NULL)
+	  if ((new_rlimit == NULL)
+	      && (old_rlimit64_mem.rlim_cur != RLIM64_INFINITY))
 	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
 	  old_rlimit->rlim_cur = RLIM_INFINITY;
 	}
       old_rlimit->rlim_max = old_rlimit64_mem.rlim_max;
       if (old_rlimit->rlim_max != old_rlimit64_mem.rlim_max)
 	{
-	  if (new_rlimit == NULL)
+	  if ((new_rlimit == NULL)
+	      && (old_rlimit64_mem.rlim_max != RLIM64_INFINITY))
 	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
 	  old_rlimit->rlim_max = RLIM_INFINITY;
 	}
-- 
2.15.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value
  2018-01-05 13:24 [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Aurelien Jarno
@ 2018-01-05 13:24 ` Aurelien Jarno
  2018-01-05 13:47   ` Joseph Myers
  2018-01-05 13:58   ` Adhemerval Zanella
  2018-01-05 13:24 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-05 13:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: Aurelien Jarno

Add a test to check that the getrlimit, setrlimit and prlimit functions
and their 64-bit equivalent behave correctly with RLIM_INFINITY and
RLIM64_INFINITY. For that it assumes that the prlimit64 function calls
the syscall directly without translating the value and that the kernel
uses the -1 value to represent infinity.

It first finds a resource with the hard limit set to infinity so the
soft limit can be manipulated easily and check for the consistency
between the value set or get by the prlimit64 and the other functions.

It is Linux specific add it uses the prlimit and prlimit64 functions.

Changelog:
	* sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file.
	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity.
---
 ChangeLog                                     |   5 +
 sysdeps/unix/sysv/linux/Makefile              |   3 +-
 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c | 157 ++++++++++++++++++++++++++
 3 files changed, 164 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c

diff --git a/ChangeLog b/ChangeLog
index 53c3d62b2e..81ce7f3dfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
+
+	* sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file.
+	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity.
+
 2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
 
 	[BZ #22678]
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 4af9c5661d..8f19e0efc3 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -44,7 +44,8 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
 
 tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
 	 tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
-	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey
+	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \
+	 tst-rlimit-infinity
 
 # Generate the list of SYS_* macros for the system calls (__NR_*
 # macros).  The file syscall-names.list contains all possible system
diff --git a/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c b/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c
new file mode 100644
index 0000000000..58aace625a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c
@@ -0,0 +1,157 @@
+#include <errno.h>
+#include <stdio.h>
+#include <sys/resource.h>
+#include <support/check.h>
+
+static int resources[] = {
+  /* The following 7 limits are part of POSIX and must exist.  */
+  RLIMIT_CORE,
+  RLIMIT_CPU,
+  RLIMIT_DATA,
+  RLIMIT_FSIZE,
+  RLIMIT_NOFILE,
+  RLIMIT_STACK,
+  RLIMIT_AS
+};
+
+#define nresources (sizeof (resources) / sizeof (resources[0]))
+
+/* Assume that the prlimit64 function calls the prlimit64 syscall without
+   mangling the arguments.  */
+#define PRLIMIT64_INFINITY	((rlim64_t) -1)
+
+/* As we don't know which limit will be modified, use a sufficiently high
+   value to not shoot ourself in the foot.  Use a 32-bit value to test
+   both the 32- and 64-bit versions, and keep the highest bit clear to
+   avoid sign extension.  */
+#define PRLIMIT64_TESTVAL	((rlim64_t) 0x42420000)
+
+static void
+test_getrlimit (int resource, rlim_t exp_cur, rlim_t exp_max)
+{
+  struct rlimit r;
+  TEST_VERIFY_EXIT (getrlimit (resource, &r) == 0);
+  TEST_COMPARE (r.rlim_cur, exp_cur);
+  TEST_COMPARE (r.rlim_max, exp_max);
+}
+
+static void
+test_getrlimit64 (int resource, rlim64_t exp_cur, rlim64_t exp_max)
+{
+  struct rlimit64 r;
+  TEST_VERIFY_EXIT (getrlimit64 (resource, &r) == 0);
+  TEST_COMPARE (r.rlim_cur, exp_cur);
+  TEST_COMPARE (r.rlim_max, exp_max);
+}
+
+static void
+test_prlimit_get (int resource, rlim_t exp_cur, rlim_t exp_max)
+{
+  struct rlimit r;
+  TEST_VERIFY_EXIT (prlimit (0, resource, NULL, &r) == 0);
+  TEST_COMPARE (r.rlim_cur, exp_cur);
+  TEST_COMPARE (r.rlim_max, exp_max);
+}
+
+static void
+test_prlimit64_get (int resource, rlim64_t exp_cur, rlim64_t exp_max)
+{
+  struct rlimit64 r;
+  TEST_COMPARE (prlimit64 (0, resource, NULL, &r), 0);
+  TEST_COMPARE (r.rlim_cur, exp_cur);
+  TEST_COMPARE (r.rlim_max, exp_max);
+}
+
+static void
+test_setrlimit (int resource, rlim_t new_cur, rlim_t new_max)
+{
+  struct rlimit r = { new_cur, new_max };
+  TEST_COMPARE (setrlimit (resource, &r), 0);
+}
+
+static void
+test_setrlimit64 (int resource, rlim64_t new_cur, rlim64_t new_max)
+{
+  struct rlimit64 r = { new_cur, new_max };
+  TEST_COMPARE (setrlimit64 (resource, &r), 0);
+}
+
+static void
+test_prlimit_set (int resource, rlim_t new_cur, rlim_t new_max)
+{
+  struct rlimit r = { new_cur, new_max };
+  TEST_COMPARE (prlimit (0, resource, &r, NULL), 0);
+}
+
+static void
+test_prlimit64_set (int resource, rlim64_t new_cur, rlim64_t new_max)
+{
+  struct rlimit64 r = { new_cur, new_max };
+  TEST_COMPARE (prlimit64 (0, resource, &r, NULL), 0);
+}
+
+static int
+do_test (void)
+{
+  int resource = -1;
+
+  /* Find a resource with hard limit set to infinity, so that the soft limit
+     can be manipulated to any value.  */
+  for (int i = 0; i < nresources; ++i)
+    {
+      struct rlimit64 r64;
+      int res = prlimit64 (0, resources[i], NULL, &r64);
+      if ((res == 0) && (r64.rlim_max == PRLIMIT64_INFINITY))
+	{
+	  resource = resources[i];
+	  break;
+	}
+    }
+
+  if (resource == -1)
+    FAIL_UNSUPPORTED
+      ("Could not find and limit with hard limit set to infinity.");
+
+  /* First check that the get functions work correctly with the test value.  */
+  test_prlimit64_set (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
+  test_getrlimit (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
+  test_getrlimit64 (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY);
+  test_prlimit_get (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY);
+
+  /* Then check that the get functions work correctly with infinity.  */
+  test_prlimit64_set (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
+  test_getrlimit (resource, RLIM_INFINITY, RLIM_INFINITY);
+  test_getrlimit64 (resource, RLIM64_INFINITY, RLIM64_INFINITY);
+  test_prlimit_get (resource, RLIM_INFINITY, RLIM_INFINITY);
+  test_prlimit64_get (resource, RLIM64_INFINITY, RLIM64_INFINITY);
+
+  /* Then check that setrlimit works correctly with the test value.  */
+  test_setrlimit (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
+
+  /* Then check that setrlimit works correctly with infinity.  */
+  test_setrlimit (resource, RLIM_INFINITY, RLIM_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
+
+  /* Then check that setrlimit64 works correctly with the test value.  */
+  test_setrlimit64 (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
+
+  /* Then check that setrlimit64 works correctly with infinity.  */
+  test_setrlimit64 (resource, RLIM64_INFINITY, RLIM64_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
+
+  /* Then check that prlimit works correctly with the test value.  */
+  test_prlimit_set (resource, RLIM_INFINITY, RLIM_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
+
+  /* Finally check that prlimit works correctly with infinity.  */
+  test_prlimit_set (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
+  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
-- 
2.15.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value
  2018-01-05 13:24 ` [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Aurelien Jarno
@ 2018-01-05 13:47   ` Joseph Myers
  2018-01-05 13:58   ` Adhemerval Zanella
  1 sibling, 0 replies; 13+ messages in thread
From: Joseph Myers @ 2018-01-05 13:47 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: libc-alpha

The new test is missing copyright / license notices.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678]
  2018-01-05 13:24 ` [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678] Aurelien Jarno
@ 2018-01-05 13:54   ` Adhemerval Zanella
  0 siblings, 0 replies; 13+ messages in thread
From: Adhemerval Zanella @ 2018-01-05 13:54 UTC (permalink / raw)
  To: libc-alpha



On 05/01/2018 11:24, Aurelien Jarno wrote:
> prlimit called without a new value fails on 32-bit machines if any of
> the soft or hard limits are infinity. This is because prlimit does not
> translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY, but checks
> that the value returned by the prlimit64 syscall fits into a 32-bit
> value, like it is done for example in getrlimit. Note that on the
> other hand new_rlimit is correctly translated from RLIM_INFINITY to
> RLIM64_INFINITY before calling the syscall.
> 
> This patch fixes that.

At least it affects only old interface in 32-bits.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> 
> Changelog:
> 	[BZ #22678]
> 	* sysdeps/unix/sysv/linux/prlimit.c (prlimit): Translate
> 	old_rlimit from RLIM64_INFINITY to RLIM_INFINITY.
> ---
>  ChangeLog                         |  6 ++++++
>  sysdeps/unix/sysv/linux/prlimit.c | 15 +++++++++------
>  2 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index fd0fc0bc71..53c3d62b2e 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
> +
> +	[BZ #22678]
> +	* sysdeps/unix/sysv/linux/prlimit.c (prlimit): Translate
> +	old_rlimit from RLIM64_INFINITY to RLIM_INFINITY.
> +
>  2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
>  	    Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>  
> diff --git a/sysdeps/unix/sysv/linux/prlimit.c b/sysdeps/unix/sysv/linux/prlimit.c
> index 9db8e821b3..2fa0642c76 100644
> --- a/sysdeps/unix/sysv/linux/prlimit.c
> +++ b/sysdeps/unix/sysv/linux/prlimit.c
> @@ -50,21 +50,24 @@ prlimit (__pid_t pid, enum __rlimit_resource resource,
>      {
>        /* The prlimit64 syscall is ill-designed for 32-bit machines.
>  	 We have to provide a 32-bit variant since otherwise the LFS
> -	 system would not work.  But what shall we do if the syscall
> -	 succeeds but the old values do not fit into a rlimit
> -	 structure?  We cannot return an error because the operation
> -	 itself worked.  Best is perhaps to return RLIM_INFINITY.  */
> +	 system would not work.  The infinity value can be translated,
> +	 but otherwise what shall we do if the syscall succeeds but the
> +	 old values do not fit into a rlimit structure?  We cannot return
> +	 an error because the operation itself worked.  Best is perhaps
> +	 to return RLIM_INFINITY.  */
>        old_rlimit->rlim_cur = old_rlimit64_mem.rlim_cur;
>        if (old_rlimit->rlim_cur != old_rlimit64_mem.rlim_cur)
>  	{
> -	  if (new_rlimit == NULL)
> +	  if ((new_rlimit == NULL)
> +	      && (old_rlimit64_mem.rlim_cur != RLIM64_INFINITY))
>  	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
>  	  old_rlimit->rlim_cur = RLIM_INFINITY;
>  	}
>        old_rlimit->rlim_max = old_rlimit64_mem.rlim_max;
>        if (old_rlimit->rlim_max != old_rlimit64_mem.rlim_max)
>  	{
> -	  if (new_rlimit == NULL)
> +	  if ((new_rlimit == NULL)
> +	      && (old_rlimit64_mem.rlim_max != RLIM64_INFINITY))
>  	    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
>  	  old_rlimit->rlim_max = RLIM_INFINITY;
>  	}
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value
  2018-01-05 13:24 ` [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Aurelien Jarno
  2018-01-05 13:47   ` Joseph Myers
@ 2018-01-05 13:58   ` Adhemerval Zanella
  2018-01-05 17:51     ` Aurelien Jarno
  1 sibling, 1 reply; 13+ messages in thread
From: Adhemerval Zanella @ 2018-01-05 13:58 UTC (permalink / raw)
  To: libc-alpha



On 05/01/2018 11:24, Aurelien Jarno wrote:
> Add a test to check that the getrlimit, setrlimit and prlimit functions
> and their 64-bit equivalent behave correctly with RLIM_INFINITY and
> RLIM64_INFINITY. For that it assumes that the prlimit64 function calls
> the syscall directly without translating the value and that the kernel
> uses the -1 value to represent infinity.
> 
> It first finds a resource with the hard limit set to infinity so the
> soft limit can be manipulated easily and check for the consistency
> between the value set or get by the prlimit64 and the other functions.
> 
> It is Linux specific add it uses the prlimit and prlimit64 functions.
> 
> Changelog:
> 	* sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file.
> 	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity.

LGTM with two remarks below.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  ChangeLog                                     |   5 +
>  sysdeps/unix/sysv/linux/Makefile              |   3 +-
>  sysdeps/unix/sysv/linux/tst-rlimit-infinity.c | 157 ++++++++++++++++++++++++++
>  3 files changed, 164 insertions(+), 1 deletion(-)
>  create mode 100644 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c
> 
> diff --git a/ChangeLog b/ChangeLog
> index 53c3d62b2e..81ce7f3dfc 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
> +
> +	* sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file.
> +	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity.
> +
>  2018-01-05  Aurelien Jarno  <aurelien@aurel32.net>
>  
>  	[BZ #22678]
> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index 4af9c5661d..8f19e0efc3 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -44,7 +44,8 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \
>  
>  tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
>  	 tst-quota tst-sync_file_range tst-sysconf-iov_max tst-ttyname \
> -	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey
> +	 test-errno-linux tst-memfd_create tst-mlock2 tst-pkey \
> +	 tst-rlimit-infinity
>  
>  # Generate the list of SYS_* macros for the system calls (__NR_*
>  # macros).  The file syscall-names.list contains all possible system
> diff --git a/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c b/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c
> new file mode 100644
> index 0000000000..58aace625a
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-rlimit-infinity.c

Missing Copyright header.

> @@ -0,0 +1,157 @@
> +#include <errno.h>
> +#include <stdio.h>
> +#include <sys/resource.h>
> +#include <support/check.h>
> +
> +static int resources[] = {
> +  /* The following 7 limits are part of POSIX and must exist.  */
> +  RLIMIT_CORE,
> +  RLIMIT_CPU,
> +  RLIMIT_DATA,
> +  RLIMIT_FSIZE,
> +  RLIMIT_NOFILE,
> +  RLIMIT_STACK,
> +  RLIMIT_AS
> +};
> +
> +#define nresources (sizeof (resources) / sizeof (resources[0]))
> +
> +/* Assume that the prlimit64 function calls the prlimit64 syscall without
> +   mangling the arguments.  */
> +#define PRLIMIT64_INFINITY	((rlim64_t) -1)
> +
> +/* As we don't know which limit will be modified, use a sufficiently high
> +   value to not shoot ourself in the foot.  Use a 32-bit value to test
> +   both the 32- and 64-bit versions, and keep the highest bit clear to
> +   avoid sign extension.  */
> +#define PRLIMIT64_TESTVAL	((rlim64_t) 0x42420000)
> +
> +static void
> +test_getrlimit (int resource, rlim_t exp_cur, rlim_t exp_max)
> +{
> +  struct rlimit r;
> +  TEST_VERIFY_EXIT (getrlimit (resource, &r) == 0);
> +  TEST_COMPARE (r.rlim_cur, exp_cur);
> +  TEST_COMPARE (r.rlim_max, exp_max);
> +}
> +
> +static void
> +test_getrlimit64 (int resource, rlim64_t exp_cur, rlim64_t exp_max)
> +{
> +  struct rlimit64 r;
> +  TEST_VERIFY_EXIT (getrlimit64 (resource, &r) == 0);
> +  TEST_COMPARE (r.rlim_cur, exp_cur);
> +  TEST_COMPARE (r.rlim_max, exp_max);
> +}
> +
> +static void
> +test_prlimit_get (int resource, rlim_t exp_cur, rlim_t exp_max)
> +{
> +  struct rlimit r;
> +  TEST_VERIFY_EXIT (prlimit (0, resource, NULL, &r) == 0);
> +  TEST_COMPARE (r.rlim_cur, exp_cur);
> +  TEST_COMPARE (r.rlim_max, exp_max);
> +}
> +
> +static void
> +test_prlimit64_get (int resource, rlim64_t exp_cur, rlim64_t exp_max)
> +{
> +  struct rlimit64 r;
> +  TEST_COMPARE (prlimit64 (0, resource, NULL, &r), 0);
> +  TEST_COMPARE (r.rlim_cur, exp_cur);
> +  TEST_COMPARE (r.rlim_max, exp_max);
> +}
> +
> +static void
> +test_setrlimit (int resource, rlim_t new_cur, rlim_t new_max)
> +{
> +  struct rlimit r = { new_cur, new_max };
> +  TEST_COMPARE (setrlimit (resource, &r), 0);
> +}
> +
> +static void
> +test_setrlimit64 (int resource, rlim64_t new_cur, rlim64_t new_max)
> +{
> +  struct rlimit64 r = { new_cur, new_max };
> +  TEST_COMPARE (setrlimit64 (resource, &r), 0);
> +}
> +
> +static void
> +test_prlimit_set (int resource, rlim_t new_cur, rlim_t new_max)
> +{
> +  struct rlimit r = { new_cur, new_max };
> +  TEST_COMPARE (prlimit (0, resource, &r, NULL), 0);
> +}
> +
> +static void
> +test_prlimit64_set (int resource, rlim64_t new_cur, rlim64_t new_max)
> +{
> +  struct rlimit64 r = { new_cur, new_max };
> +  TEST_COMPARE (prlimit64 (0, resource, &r, NULL), 0);
> +}
> +
> +static int
> +do_test (void)
> +{
> +  int resource = -1;
> +
> +  /* Find a resource with hard limit set to infinity, so that the soft limit
> +     can be manipulated to any value.  */
> +  for (int i = 0; i < nresources; ++i)
> +    {
> +      struct rlimit64 r64;
> +      int res = prlimit64 (0, resources[i], NULL, &r64);
> +      if ((res == 0) && (r64.rlim_max == PRLIMIT64_INFINITY))
> +	{
> +	  resource = resources[i];
> +	  break;
> +	}
> +    }
> +
> +  if (resource == -1)
> +    FAIL_UNSUPPORTED
> +      ("Could not find and limit with hard limit set to infinity.");
> +
> +  /* First check that the get functions work correctly with the test value.  */
> +  test_prlimit64_set (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
> +  test_getrlimit (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
> +  test_getrlimit64 (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY);
> +  test_prlimit_get (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY);
> +
> +  /* Then check that the get functions work correctly with infinity.  */
> +  test_prlimit64_set (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
> +  test_getrlimit (resource, RLIM_INFINITY, RLIM_INFINITY);
> +  test_getrlimit64 (resource, RLIM64_INFINITY, RLIM64_INFINITY);
> +  test_prlimit_get (resource, RLIM_INFINITY, RLIM_INFINITY);
> +  test_prlimit64_get (resource, RLIM64_INFINITY, RLIM64_INFINITY);
> +
> +  /* Then check that setrlimit works correctly with the test value.  */
> +  test_setrlimit (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
> +
> +  /* Then check that setrlimit works correctly with infinity.  */
> +  test_setrlimit (resource, RLIM_INFINITY, RLIM_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
> +
> +  /* Then check that setrlimit64 works correctly with the test value.  */
> +  test_setrlimit64 (resource, PRLIMIT64_TESTVAL, RLIM64_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
> +
> +  /* Then check that setrlimit64 works correctly with infinity.  */
> +  test_setrlimit64 (resource, RLIM64_INFINITY, RLIM64_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
> +
> +  /* Then check that prlimit works correctly with the test value.  */
> +  test_prlimit_set (resource, RLIM_INFINITY, RLIM_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_INFINITY, PRLIMIT64_INFINITY);
> +
> +  /* Finally check that prlimit works correctly with infinity.  */
> +  test_prlimit_set (resource, PRLIMIT64_TESTVAL, RLIM_INFINITY);
> +  test_prlimit64_get (resource, PRLIMIT64_TESTVAL, PRLIMIT64_INFINITY);
> +
> +  return 0;
> +}
> +
> +#define TEST_FUNCTION do_test ()
> +#include "../test-skeleton.c"

Correct to use libsupport is to include <support/test-driver.c> instead
(and you do not need to define TEST_FUNCTION if you have a do_test function
already).

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value
  2018-01-05 13:58   ` Adhemerval Zanella
@ 2018-01-05 17:51     ` Aurelien Jarno
  0 siblings, 0 replies; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-05 17:51 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2018-01-05 11:58, Adhemerval Zanella wrote:
> 
> 
> On 05/01/2018 11:24, Aurelien Jarno wrote:
> > Add a test to check that the getrlimit, setrlimit and prlimit functions
> > and their 64-bit equivalent behave correctly with RLIM_INFINITY and
> > RLIM64_INFINITY. For that it assumes that the prlimit64 function calls
> > the syscall directly without translating the value and that the kernel
> > uses the -1 value to represent infinity.
> > 
> > It first finds a resource with the hard limit set to infinity so the
> > soft limit can be manipulated easily and check for the consistency
> > between the value set or get by the prlimit64 and the other functions.
> > 
> > It is Linux specific add it uses the prlimit and prlimit64 functions.
> > 
> > Changelog:
> > 	* sysdeps/unix/sysv/linux/tst-rlimit-infinity.c: New file.
> > 	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-rlimit-infinity.
> 
> LGTM with two remarks below.
> 
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

Thanks for the review, I'll the two issues that before committing.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines
  2018-01-05 13:24 [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Aurelien Jarno
                   ` (3 preceding siblings ...)
  2018-01-05 13:24 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
@ 2018-01-05 23:55 ` Joseph Myers
  2018-01-06 10:00   ` Aurelien Jarno
  4 siblings, 1 reply; 13+ messages in thread
From: Joseph Myers @ 2018-01-05 23:55 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: libc-alpha

One of these patches breaks the testsuite build for various (but not all) 
32-bit configurations.

https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html

The failures are all of the form:

/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
collect2: error: ld returned 1 exit status
../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines
  2018-01-05 23:55 ` [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Joseph Myers
@ 2018-01-06 10:00   ` Aurelien Jarno
  2018-01-06 11:02     ` Aurelien Jarno
  0 siblings, 1 reply; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-06 10:00 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha

On 2018-01-05 23:55, Joseph Myers wrote:
> One of these patches breaks the testsuite build for various (but not all) 
> 32-bit configurations.
> 
> https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html
> 
> The failures are all of the form:
> 
> /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
> /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
> collect2: error: ld returned 1 exit status
> ../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
> make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1

Sorry about that. The issue happens on 32-bit configurations which have
a minimum version >= 2.2, and thus which don't need the 2GiB limited
compat getrlimit64. I wrongly moved one case under the #ifdef
__RLIM_T_MATCHES_RLIM64_T case, while it should have been copied
instead.

I am currently testing the following patch:

diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 1cc82e364d..a14ca58096 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -81,4 +81,7 @@ __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 }
 versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
 compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+#else
+weak_alias (__getrlimit64, getrlimit64)
+libc_hidden_weak (getrlimit64)
 #endif /* __RLIM_T_MATCHES_RLIM64_T  */

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines
  2018-01-06 10:00   ` Aurelien Jarno
@ 2018-01-06 11:02     ` Aurelien Jarno
  2018-01-07 21:45       ` Aurelien Jarno
  0 siblings, 1 reply; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-06 11:02 UTC (permalink / raw)
  To: Joseph Myers, libc-alpha

On 2018-01-06 11:00, Aurelien Jarno wrote:
> On 2018-01-05 23:55, Joseph Myers wrote:
> > One of these patches breaks the testsuite build for various (but not all) 
> > 32-bit configurations.
> > 
> > https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html
> > 
> > The failures are all of the form:
> > 
> > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
> > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
> > collect2: error: ld returned 1 exit status
> > ../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
> > make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1
> 
> Sorry about that. The issue happens on 32-bit configurations which have
> a minimum version >= 2.2, and thus which don't need the 2GiB limited
> compat getrlimit64. I wrongly moved one case under the #ifdef
> __RLIM_T_MATCHES_RLIM64_T case, while it should have been copied
> instead.
> 
> I am currently testing the following patch:

It worked fine on arm-linux-gnueabihf with no regression. Here is the
full patch.


From 5551e9755c3bbcd0c6682a1626eb869596d201c6 Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <aurelien@aurel32.net>
Date: Sat, 6 Jan 2018 11:48:16 +0100
Subject: [PATCH] getrlimit64: fix for 32-bit configurations with default
 version >= 2.2

Commit 24731685 ("prlimit: Translate old_rlimit from RLIM64_INFINITY to
RLIM_INFINITY") broken the getrlimit64 for 32-bit configurations which
do no need the 2GiB limited compat getrlimit (default version >= 2.2).

This patch fixes that by restoring the weak alias in that case.

Changelog:
	* sysdeps/unix/sysv/linux/getrlimit64 (getrlimit64)
	[!__RLIM_T_MATCHES_RLIM64_T]
	[!SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)]: Define as weak alias of
	__getrlimit64. Add libc_hidden_weak.
---
 ChangeLog                             | 7 +++++++
 sysdeps/unix/sysv/linux/getrlimit64.c | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 8833b1da33..303ded4877 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-01-06  Aurelien Jarno  <aurelien@aurel32.net>
+
+	* sysdeps/unix/sysv/linux/getrlimit64 (getrlimit64)
+	[!__RLIM_T_MATCHES_RLIM64_T]
+	[!SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)]: Define as weak alias of
+	__getrlimit64. Add libc_hidden_weak.
+
 2018-01-06  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
 	* sysdeps/mach/hurd/i386/jmp_buf-macros.h: New file.
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 1cc82e364d..a14ca58096 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -81,4 +81,7 @@ __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 }
 versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
 compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+#else
+weak_alias (__getrlimit64, getrlimit64)
+libc_hidden_weak (getrlimit64)
 #endif /* __RLIM_T_MATCHES_RLIM64_T  */
-- 
2.15.1


-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines
  2018-01-06 11:02     ` Aurelien Jarno
@ 2018-01-07 21:45       ` Aurelien Jarno
  0 siblings, 0 replies; 13+ messages in thread
From: Aurelien Jarno @ 2018-01-07 21:45 UTC (permalink / raw)
  To: Joseph Myers, libc-alpha

On 2018-01-06 12:01, Aurelien Jarno wrote:
> On 2018-01-06 11:00, Aurelien Jarno wrote:
> > On 2018-01-05 23:55, Joseph Myers wrote:
> > > One of these patches breaks the testsuite build for various (but not all) 
> > > 32-bit configurations.
> > > 
> > > https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html
> > > 
> > > The failures are all of the form:
> > > 
> > > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
> > > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
> > > collect2: error: ld returned 1 exit status
> > > ../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
> > > make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1
> > 
> > Sorry about that. The issue happens on 32-bit configurations which have
> > a minimum version >= 2.2, and thus which don't need the 2GiB limited
> > compat getrlimit64. I wrongly moved one case under the #ifdef
> > __RLIM_T_MATCHES_RLIM64_T case, while it should have been copied
> > instead.
> > 
> > I am currently testing the following patch:
> 
> It worked fine on arm-linux-gnueabihf with no regression. Here is the
> full patch.

I have now committed it, as I don't want to leave things broken for too
long.

Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-01-07 21:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-05 13:24 [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Aurelien Jarno
2018-01-05 13:24 ` [PATCH 4/4] Add test for getrlimit/setrlimit/prlimit with infinity value Aurelien Jarno
2018-01-05 13:47   ` Joseph Myers
2018-01-05 13:58   ` Adhemerval Zanella
2018-01-05 17:51     ` Aurelien Jarno
2018-01-05 13:24 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
2018-01-05 13:24 ` [PATCH 3/4] prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY [BZ #22678] Aurelien Jarno
2018-01-05 13:54   ` Adhemerval Zanella
2018-01-05 13:24 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
2018-01-05 23:55 ` [PATCH 0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines Joseph Myers
2018-01-06 10:00   ` Aurelien Jarno
2018-01-06 11:02     ` Aurelien Jarno
2018-01-07 21:45       ` Aurelien Jarno

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).