public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/4] Fix typos in getrlimit64.c and setrlimit64.c
  2017-12-30 18:44 [PATCH 0/4] Alpha: Fix getrlimit/setrlimit with RLIM_INFINITY Aurelien Jarno
  2017-12-30 18:44 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
  2017-12-30 18:44 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
@ 2017-12-30 18:44 ` Aurelien Jarno
  2017-12-31 19:34   ` Adhemerval Zanella
  2017-12-30 19:27 ` [PATCH 4/4] Simplify getrlimit64.c Aurelien Jarno
  3 siblings, 1 reply; 16+ messages in thread
From: Aurelien Jarno @ 2017-12-30 18:44 UTC (permalink / raw)
  To: libc-alpha; +Cc: Richard Henderson, Aurelien Jarno

Changelog:
	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Fix a typo in the
	comment.
	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Fix a typo in the
	comment.
	(settrlimit): Rename into setrlimit.
	(__sttrlimit): Rename into __setrlimit.
---
 ChangeLog                             | 9 +++++++++
 sysdeps/unix/sysv/linux/getrlimit64.c | 2 +-
 sysdeps/unix/sysv/linux/setrlimit64.c | 6 +++---
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1e8740530d..663a9186e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
+
+	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Fix a typo in the
+	comment.
+	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Fix a typo in the
+	comment.
+	(settrlimit): Rename into setrlimit.
+	(__sttrlimit): Rename into __setrlimit.
+
 2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
 
 	* sysdeps/unix/sysv/linux/alpha/bits/resource.h (RLIM_INFINITY,
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 37827e5f42..53cb4bb4d8 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -21,7 +21,7 @@
 #include <shlib-compat.h>
 
 /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
-   linking getlimit64 to {__}getrlimit does not throw a type error.  */
+   linking getrlimit64 to {__}getrlimit does not throw a type error.  */
 #undef getrlimit
 #undef __getrlimit
 #define getrlimit getrlimit_redirect
diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
index ff835c8733..2b1d3d172e 100644
--- a/sysdeps/unix/sysv/linux/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/setrlimit64.c
@@ -21,9 +21,9 @@
 #include <shlib-compat.h>
 
 /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
-   linking setlimit64 to {__}setrlimit does not throw a type error.  */
-#undef settrlimit
-#undef __sttrlimit
+   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>
-- 
2.15.1

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

* [PATCH 0/4] Alpha: Fix getrlimit/setrlimit with RLIM_INFINITY
@ 2017-12-30 18:44 Aurelien Jarno
  2017-12-30 18:44 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Aurelien Jarno @ 2017-12-30 18:44 UTC (permalink / raw)
  To: libc-alpha; +Cc: Richard Henderson, 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 two later patches are just some cleanup
that I have seen possible while writing the two first patches.

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
  Fix typos in getrlimit64.c and setrlimit64.c
  Simplify getrlimit64.c

 ChangeLog                                     | 36 +++++++++++
 sysdeps/unix/sysv/linux/alpha/Versions        |  3 +
 sysdeps/unix/sysv/linux/alpha/bits/resource.h |  6 +-
 sysdeps/unix/sysv/linux/alpha/getrlimit64.c   | 88 +++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |  4 ++
 sysdeps/unix/sysv/linux/alpha/setrlimit64.c   | 83 +++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/getrlimit64.c         |  6 +-
 sysdeps/unix/sysv/linux/setrlimit64.c         |  6 +-
 8 files changed, 221 insertions(+), 11 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/getrlimit64.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/setrlimit64.c

-- 
2.15.1

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

* [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2017-12-30 18:44 [PATCH 0/4] Alpha: Fix getrlimit/setrlimit with RLIM_INFINITY Aurelien Jarno
  2017-12-30 18:44 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
@ 2017-12-30 18:44 ` Aurelien Jarno
  2017-12-31 19:33   ` Adhemerval Zanella
  2018-01-01 23:01   ` Richard Henderson
  2017-12-30 18:44 ` [PATCH 3/4] Fix typos in getrlimit64.c and setrlimit64.c Aurelien Jarno
  2017-12-30 19:27 ` [PATCH 4/4] Simplify getrlimit64.c Aurelien Jarno
  3 siblings, 2 replies; 16+ messages in thread
From: Aurelien Jarno @ 2017-12-30 18:44 UTC (permalink / raw)
  To: libc-alpha; +Cc: Richard Henderson, 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 26e5f96f5d..433b10145d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
+
+	[BZ #22648]
+	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: New file.
+	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto.
+
 2017-12-29  Dmitry V. Levin  <ldv@altlinux.org>
 
 	[BZ #22433]
diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
new file mode 100644
index 0000000000..ad398a136f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 2017 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..a5f7907afd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2013-2017 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] 16+ messages in thread

* [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants
  2017-12-30 18:44 [PATCH 0/4] Alpha: Fix getrlimit/setrlimit with RLIM_INFINITY Aurelien Jarno
@ 2017-12-30 18:44 ` Aurelien Jarno
  2017-12-31 19:33   ` Adhemerval Zanella
  2017-12-30 18:44 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Aurelien Jarno @ 2017-12-30 18:44 UTC (permalink / raw)
  To: libc-alpha; +Cc: Richard Henderson, 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.

Note that the alpha implementation does not include the generic
getrlimit64.c or setrlimit64.c as they:
- redefine SHLIB_COMPAT when __RLIM_T_MATCHES_RLIM64_T == 1
- redefine getrlimit or setrlimit, not allowing to rename them into
  __new_getrlimit or __new_setrlimit.

Changelog:
	* 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: 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                                     | 15 +++++++
 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   | 52 ++++++++++++++++++-------
 6 files changed, 102 insertions(+), 34 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 433b10145d..1e8740530d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
+
+	* 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: 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.
+
 2017-12-30  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 bd5142caa4..749703b716 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 ad398a136f..25cf4aa555 100644
--- a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
@@ -17,9 +17,10 @@
 
 #include <errno.h>
 #include <sys/types.h>
+#include <shlib-compat.h>
 
-/* Add this redirection so the strong_alias linking getrlimit64 to
-   {__}getrlimit does not throw a type error.  */
+/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
+   linking getrlimit64 to {__}getrlimit does not throw a type error.  */
 #undef getrlimit
 #undef __getrlimit
 #define getrlimit getrlimit_redirect
@@ -28,37 +29,60 @@
 #undef getrlimit
 #undef __getrlimit
 
+
+/* Put the soft and hard limits for RESOURCE in *RLIMITS.
+   Returns 0 if successful, -1 if not (and sets errno).  */
+int
+__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
+{
+  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
+}
+libc_hidden_def (__getrlimit64)
+
+strong_alias (__getrlimit64, __GI_getrlimit)
+strong_alias (__getrlimit64, __GI_getrlimit64)
+strong_alias (__getrlimit64, __GI___getrlimit)
+strong_alias (__getrlimit64, __getrlimit)
+
+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) \
+    || SHLIB_COMPAT (libc, GLIBC_2_1, 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)
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
+strong_alias (__old_getrlimit64, __old_getrlimit)
+compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0);
+# endif
+# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_27)
+compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+# endif
+#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 a5f7907afd..b8074d2df6 100644
--- a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
@@ -17,9 +17,10 @@
 
 #include <errno.h>
 #include <sys/types.h>
+#include <shlib-compat.h>
 
-/* Add this redirection so the strong_alias linking setrlimit64 to
-   {__}setrlimit does not throw a type error.  */
+/* 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
@@ -28,34 +29,55 @@
 #undef setrlimit
 #undef __setrlimit
 
+/* Set the soft and hard limits for RESOURCE to *RLIMITS.
+   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)
+{
+  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
+}
+strong_alias (__setrlimit64, __setrlimit)
+# ifdef SHARED
+__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64);
+# endif
+
+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) \
+    || SHLIB_COMPAT (libc, GLIBC_2_1, 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);
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
+strong_alias (__old_setrlimit64, __old_setrlimit)
+compat_symbol (libc, __old_setrlimit, setrlimit, GLIBC_2_0);
+# endif
+# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_27)
+compat_symbol (libc, __old_setrlimit64, setrlimit64, GLIBC_2_1);
+# endif
 #endif
-- 
2.15.1

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

* [PATCH 4/4] Simplify getrlimit64.c
  2017-12-30 18:44 [PATCH 0/4] Alpha: Fix getrlimit/setrlimit with RLIM_INFINITY Aurelien Jarno
                   ` (2 preceding siblings ...)
  2017-12-30 18:44 ` [PATCH 3/4] Fix typos in getrlimit64.c and setrlimit64.c Aurelien Jarno
@ 2017-12-30 19:27 ` Aurelien Jarno
  2017-12-31 19:34   ` Adhemerval Zanella
  3 siblings, 1 reply; 16+ messages in thread
From: Aurelien Jarno @ 2017-12-30 19:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: Richard Henderson, Aurelien Jarno

Changelog:
	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c (__old_getrlimit64):
	Drop __RLIM_T_MATCHES_RLIM64_T conditional as __old_getrlimit64 is
	never defined in that case.
---
 ChangeLog                             | 6 ++++++
 sysdeps/unix/sysv/linux/getrlimit64.c | 4 ----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 663a9186e4..598499fd78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
+
+	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c (__old_getrlimit64):
+	Drop __RLIM_T_MATCHES_RLIM64_T conditional as __old_getrlimit64 is
+	never defined in that case.
+
 2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
 
 	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Fix a typo in the
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 53cb4bb4d8..1310d179d0 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -60,11 +60,7 @@ int
 attribute_compat_text_section
 __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 {
-# if __RLIM_T_MATCHES_RLIM64_T
-#  define rlimits32 (*rlimits)
-# else
   struct rlimit rlimits32;
-# endif
 
   if (__new_getrlimit (resource, &rlimits32) < 0)
     return -1;
-- 
2.15.1

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

* Re: [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants
  2017-12-30 18:44 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
@ 2017-12-31 19:33   ` Adhemerval Zanella
  2018-01-03 16:35     ` Aurelien Jarno
  0 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-12-31 19:33 UTC (permalink / raw)
  To: libc-alpha



On 30/12/2017 16:44, Aurelien Jarno wrote:
> 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.
> 
> Note that the alpha implementation does not include the generic
> getrlimit64.c or setrlimit64.c as they:
> - redefine SHLIB_COMPAT when __RLIM_T_MATCHES_RLIM64_T == 1
> - redefine getrlimit or setrlimit, not allowing to rename them into
>   __new_getrlimit or __new_setrlimit.

I think we can work this around to avoid code duplication with the following
patch (based on this one plus the previous one you posted). Basically:

  * it adds a new define, USE_VERSIONED_RLIMIT, which supress the alias to the 
    exported symbols on generic implementation (since alpha will add the
    versioned one instead).

  * it simplifies the SHLIB_COMPAT macros on alpha since there is no need to 
    check for both GLIBC_2_0 and GLIBC_2_1 (it is already an arch-specific
    file which assumes an already defined ABI, in this case GLIBC_2_0).

  * it adds a weak_alias alias between __getrlimit64 and __GI_getrlimit64
    for alpha case to follow generic case with libc_hidden_weak definition.

What do you think?

---
diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
index 25cf4aa..d8ac917 100644
--- a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
@@ -15,40 +15,12 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <sys/types.h>
-#include <shlib-compat.h>
-
-/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
-   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
-
-
-/* Put the soft and hard limits for RESOURCE in *RLIMITS.
-   Returns 0 if successful, -1 if not (and sets errno).  */
-int
-__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
-{
-  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
-}
-libc_hidden_def (__getrlimit64)
-
-strong_alias (__getrlimit64, __GI_getrlimit)
-strong_alias (__getrlimit64, __GI_getrlimit64)
-strong_alias (__getrlimit64, __GI___getrlimit)
-strong_alias (__getrlimit64, __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) \
-    || SHLIB_COMPAT (libc, GLIBC_2_1, 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
@@ -78,11 +50,7 @@ __old_getrlimit64 (enum __rlimit_resource resource,
   return 0;
 }
 
-# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
 strong_alias (__old_getrlimit64, __old_getrlimit)
 compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0);
-# endif
-# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_27)
 compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
-# endif
 #endif
diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
index b8074d2..1735f68 100644
--- a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
+++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
@@ -15,38 +15,12 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <sys/types.h>
-#include <shlib-compat.h>
-
-/* 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.
-   Return 0 if successful, -1 if not (and sets errno).  */
-int
-__setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
-{
-  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
-}
-strong_alias (__setrlimit64, __setrlimit)
-# ifdef SHARED
-__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64);
-# endif
-
+#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) \
-    || SHLIB_COMPAT (libc, GLIBC_2_1, 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
@@ -73,11 +47,7 @@ __old_setrlimit64 (enum __rlimit_resource resource,
   return __setrlimit64 (resource, &krlimits);
 }
 
-# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
 strong_alias (__old_setrlimit64, __old_setrlimit)
 compat_symbol (libc, __old_setrlimit, setrlimit, GLIBC_2_0);
-# endif
-# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_27)
 compat_symbol (libc, __old_setrlimit64, setrlimit64, GLIBC_2_1);
-# endif
 #endif
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 37827e5..d14fc63 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 if 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;
@@ -82,7 +85,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 ff835c8..0f5cc85 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
---

> 
> Changelog:
> 	* 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: 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                                     | 15 +++++++
>  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   | 52 ++++++++++++++++++-------
>  6 files changed, 102 insertions(+), 34 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 433b10145d..1e8740530d 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,18 @@
> +2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
> +
> +	* 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: 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.
> +
>  2017-12-30  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;
>    }

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/bits/resource.h b/sysdeps/unix/sysv/linux/alpha/bits/resource.h
> index bd5142caa4..749703b716 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.  */

Ok.  

> diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
> index ad398a136f..25cf4aa555 100644
> --- a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
> +++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
> @@ -17,9 +17,10 @@
>  
>  #include <errno.h>
>  #include <sys/types.h>
> +#include <shlib-compat.h>
>  
> -/* Add this redirection so the strong_alias linking getrlimit64 to
> -   {__}getrlimit does not throw a type error.  */
> +/* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
> +   linking getrlimit64 to {__}getrlimit does not throw a type error.  */
>  #undef getrlimit
>  #undef __getrlimit
>  #define getrlimit getrlimit_redirect
> @@ -28,37 +29,60 @@
>  #undef getrlimit
>  #undef __getrlimit
>  
> +
> +/* Put the soft and hard limits for RESOURCE in *RLIMITS.
> +   Returns 0 if successful, -1 if not (and sets errno).  */
> +int
> +__getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
> +{
> +  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
> +}
> +libc_hidden_def (__getrlimit64)
> +
> +strong_alias (__getrlimit64, __GI_getrlimit)
> +strong_alias (__getrlimit64, __GI_getrlimit64)
> +strong_alias (__getrlimit64, __GI___getrlimit)
> +strong_alias (__getrlimit64, __getrlimit)
> +
> +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) \
> +    || SHLIB_COMPAT (libc, GLIBC_2_1, 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)
> +# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
> +strong_alias (__old_getrlimit64, __old_getrlimit)
> +compat_symbol (libc, __old_getrlimit, getrlimit, GLIBC_2_0);
> +# endif
> +# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_27)
> +compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
> +# endif
> +#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

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
> index a5f7907afd..b8074d2df6 100644
> --- a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
> +++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
> @@ -17,9 +17,10 @@
>  
>  #include <errno.h>
>  #include <sys/types.h>
> +#include <shlib-compat.h>
>  
> -/* Add this redirection so the strong_alias linking setrlimit64 to
> -   {__}setrlimit does not throw a type error.  */
> +/* 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
> @@ -28,34 +29,55 @@
>  #undef setrlimit
>  #undef __setrlimit
>  
> +/* Set the soft and hard limits for RESOURCE to *RLIMITS.
> +   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)
> +{
> +  return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
> +}
> +strong_alias (__setrlimit64, __setrlimit)
> +# ifdef SHARED
> +__hidden_ver1 (__setrlimit64, __GI___setrlimit, __setrlimit64);
> +# endif
> +
> +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) \
> +    || SHLIB_COMPAT (libc, GLIBC_2_1, 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);
> +# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_27)
> +strong_alias (__old_setrlimit64, __old_setrlimit)
> +compat_symbol (libc, __old_setrlimit, setrlimit, GLIBC_2_0);
> +# endif
> +# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_27)
> +compat_symbol (libc, __old_setrlimit64, setrlimit64, GLIBC_2_1);
> +# endif
>  #endif
> 

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

* Re: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2017-12-30 18:44 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
@ 2017-12-31 19:33   ` Adhemerval Zanella
  2018-01-01  1:42     ` Joseph Myers
  2018-01-01 14:50     ` Aurelien Jarno
  2018-01-01 23:01   ` Richard Henderson
  1 sibling, 2 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2017-12-31 19:33 UTC (permalink / raw)
  To: libc-alpha

On 30/12/2017 16:44, Aurelien Jarno wrote:
> 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.

Sigh, at least seem only alpha still defines RLIMIT64_INFINITY as 
0x7ffffffffffffffful.  I did see some failures related to 'allocatestack.c:480' 
you pointed out (basically all the rt/* ones from 2.26 release info),
however the issue only triggers when the tests are ran from make with
either make check or make <folder>/tests.  If I ran the tests directly
using 'testrun.sh' the same one succeeds.

Anyway, do you think you can came up with a regression tests for this
issues? Otherwise change LGTM

[1] https://sourceware.org/glibc/wiki/Release/2.26

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

> 
> 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 26e5f96f5d..433b10145d 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
> +
> +	[BZ #22648]
> +	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: New file.
> +	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Ditto.
> +
>  2017-12-29  Dmitry V. Levin  <ldv@altlinux.org>
>  
>  	[BZ #22433]
> diff --git a/sysdeps/unix/sysv/linux/alpha/getrlimit64.c b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
> new file mode 100644
> index 0000000000..ad398a136f
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/getrlimit64.c
> @@ -0,0 +1,64 @@
> +/* Copyright (C) 2017 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)

Ok.

> diff --git a/sysdeps/unix/sysv/linux/alpha/setrlimit64.c b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
> new file mode 100644
> index 0000000000..a5f7907afd
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/alpha/setrlimit64.c
> @@ -0,0 +1,61 @@
> +/* Copyright (C) 2013-2017 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
> 

Ok.

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

* Re: [PATCH 4/4] Simplify getrlimit64.c
  2017-12-30 19:27 ` [PATCH 4/4] Simplify getrlimit64.c Aurelien Jarno
@ 2017-12-31 19:34   ` Adhemerval Zanella
  0 siblings, 0 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2017-12-31 19:34 UTC (permalink / raw)
  To: libc-alpha



On 30/12/2017 16:44, Aurelien Jarno wrote:
> Changelog:
> 	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c (__old_getrlimit64):
> 	Drop __RLIM_T_MATCHES_RLIM64_T conditional as __old_getrlimit64 is
> 	never defined in that case.

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

> ---
>  ChangeLog                             | 6 ++++++
>  sysdeps/unix/sysv/linux/getrlimit64.c | 4 ----
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 663a9186e4..598499fd78 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
> +
> +	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c (__old_getrlimit64):
> +	Drop __RLIM_T_MATCHES_RLIM64_T conditional as __old_getrlimit64 is
> +	never defined in that case.
> +
>  2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
>  
>  	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Fix a typo in the
> diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
> index 53cb4bb4d8..1310d179d0 100644
> --- a/sysdeps/unix/sysv/linux/getrlimit64.c
> +++ b/sysdeps/unix/sysv/linux/getrlimit64.c
> @@ -60,11 +60,7 @@ int
>  attribute_compat_text_section
>  __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
>  {
> -# if __RLIM_T_MATCHES_RLIM64_T
> -#  define rlimits32 (*rlimits)
> -# else
>    struct rlimit rlimits32;
> -# endif
>  
>    if (__new_getrlimit (resource, &rlimits32) < 0)
>      return -1;
> 

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

* Re: [PATCH 3/4] Fix typos in getrlimit64.c and setrlimit64.c
  2017-12-30 18:44 ` [PATCH 3/4] Fix typos in getrlimit64.c and setrlimit64.c Aurelien Jarno
@ 2017-12-31 19:34   ` Adhemerval Zanella
  0 siblings, 0 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2017-12-31 19:34 UTC (permalink / raw)
  To: libc-alpha



On 30/12/2017 16:44, Aurelien Jarno wrote:
> Changelog:
> 	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Fix a typo in the
> 	comment.
> 	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Fix a typo in the
> 	comment.
> 	(settrlimit): Rename into setrlimit.
> 	(__sttrlimit): Rename into __setrlimit.

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

> ---
>  ChangeLog                             | 9 +++++++++
>  sysdeps/unix/sysv/linux/getrlimit64.c | 2 +-
>  sysdeps/unix/sysv/linux/setrlimit64.c | 6 +++---
>  3 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 1e8740530d..663a9186e4 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,12 @@
> +2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
> +
> +	* sysdeps/unix/sysv/linux/alpha/getrlimit64.c: Fix a typo in the
> +	comment.
> +	* sysdeps/unix/sysv/linux/alpha/setrlimit64.c: Fix a typo in the
> +	comment.
> +	(settrlimit): Rename into setrlimit.
> +	(__sttrlimit): Rename into __setrlimit.
> +
>  2017-12-30  Aurelien Jarno <aurelien@aurel32.net>
>  
>  	* sysdeps/unix/sysv/linux/alpha/bits/resource.h (RLIM_INFINITY,
> diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
> index 37827e5f42..53cb4bb4d8 100644
> --- a/sysdeps/unix/sysv/linux/getrlimit64.c
> +++ b/sysdeps/unix/sysv/linux/getrlimit64.c
> @@ -21,7 +21,7 @@
>  #include <shlib-compat.h>
>  
>  /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
> -   linking getlimit64 to {__}getrlimit does not throw a type error.  */
> +   linking getrlimit64 to {__}getrlimit does not throw a type error.  */
>  #undef getrlimit
>  #undef __getrlimit
>  #define getrlimit getrlimit_redirect
> diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
> index ff835c8733..2b1d3d172e 100644
> --- a/sysdeps/unix/sysv/linux/setrlimit64.c
> +++ b/sysdeps/unix/sysv/linux/setrlimit64.c
> @@ -21,9 +21,9 @@
>  #include <shlib-compat.h>
>  
>  /* Add this redirection so the strong_alias for __RLIM_T_MATCHES_RLIM64_T
> -   linking setlimit64 to {__}setrlimit does not throw a type error.  */
> -#undef settrlimit
> -#undef __sttrlimit
> +   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>
> 

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

* Re: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2017-12-31 19:33   ` Adhemerval Zanella
@ 2018-01-01  1:42     ` Joseph Myers
  2018-01-01 14:50     ` Aurelien Jarno
  1 sibling, 0 replies; 16+ messages in thread
From: Joseph Myers @ 2018-01-01  1:42 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Sun, 31 Dec 2017, Adhemerval Zanella wrote:

> however the issue only triggers when the tests are ran from make with
> either make check or make <folder>/tests.  If I ran the tests directly
> using 'testrun.sh' the same one succeeds.

Maybe this is the issue with some versions of GNU make unlimiting the 
stack and applying that unlimited stack to subprocesses?  Any test that 
relies on properties of the stack limit needs to explicitly limit or 
unlimit the stack itself.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2017-12-31 19:33   ` Adhemerval Zanella
  2018-01-01  1:42     ` Joseph Myers
@ 2018-01-01 14:50     ` Aurelien Jarno
  1 sibling, 0 replies; 16+ messages in thread
From: Aurelien Jarno @ 2018-01-01 14:50 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2017-12-31 17:33, Adhemerval Zanella wrote:
> On 30/12/2017 16:44, Aurelien Jarno wrote:
> > 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.
> 
> Sigh, at least seem only alpha still defines RLIMIT64_INFINITY as 
> 0x7ffffffffffffffful.  I did see some failures related to 'allocatestack.c:480' 
> you pointed out (basically all the rt/* ones from 2.26 release info),
> however the issue only triggers when the tests are ran from make with
> either make check or make <folder>/tests.  If I ran the tests directly
> using 'testrun.sh' the same one succeeds.
> 
> Anyway, do you think you can came up with a regression tests for this
> issues? Otherwise change LGTM

As long as getrlimit and setrlimit behave the same way, it's difficult
to do so. I guess it's possible to call prlimit directly and compare the
values with getrlimit and setrlimit. Such a test will fail for
architectures which have a different representation of RLIM_INFINITY in
the kernel and the libc, so it is somehow dependent on patch 2 (assuming
that alpha is the last concerned architecture, which seems to be the
case).

Aurelien

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

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

* Re: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2017-12-30 18:44 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
  2017-12-31 19:33   ` Adhemerval Zanella
@ 2018-01-01 23:01   ` Richard Henderson
  2018-01-02  9:10     ` Aurelien Jarno
  1 sibling, 1 reply; 16+ messages in thread
From: Richard Henderson @ 2018-01-01 23:01 UTC (permalink / raw)
  To: Aurelien Jarno, libc-alpha

On 12/30/2017 10:44 AM, Aurelien Jarno wrote:
> 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

However, do_prlimit still uses RLIM_INFINITY, so I'm a bit confused about how
this change is supposed to make any difference.

Even if it did, surely the best solution is not to map __{old}_getrlimit64 to
the prlimit64 syscall, but to the original getrlimit syscall so that userland
need do no mapping at all of the return value structure.


r~

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

* Re: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2018-01-01 23:01   ` Richard Henderson
@ 2018-01-02  9:10     ` Aurelien Jarno
  2018-01-02 17:28       ` Richard Henderson
  0 siblings, 1 reply; 16+ messages in thread
From: Aurelien Jarno @ 2018-01-02  9:10 UTC (permalink / raw)
  To: Richard Henderson; +Cc: libc-alpha

On 2018-01-01 15:00, Richard Henderson wrote:
> On 12/30/2017 10:44 AM, Aurelien Jarno wrote:
> > 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
> 
> However, do_prlimit still uses RLIM_INFINITY, so I'm a bit confused about how
> this change is supposed to make any difference.

The prlimit64 syscall does the conversion between the two variants of
RLIM_INFINITY, through the rlim_to_rlim64 and rlim64_to_rlim functions.
Therefore depending if the getrlimit/setrlimit or the prlimit64 syscalls
are used, the RLIM_INFINITY value is different.

> Even if it did, surely the best solution is not to map __{old}_getrlimit64 to
> the prlimit64 syscall, but to the original getrlimit syscall so that userland
> need do no mapping at all of the return value structure.

This has two issues:
- The RLIM_INFINITY value defined on the glibc side is correct for the
  getrlimit/setrlimit functions, but not for the prlimit one which is
  also provided by the GNU libc. The goal of the second patch is
  actually to change this value to fix that issue.
- Using different syscalls depending on the architecture causes issues
  when seccomp is being used, and requires additional whitelisting for
  them. It's something that is usually not well done for non-mainstream
  architectures like alpha. This has caused issue for example in systemd
  (not sure about alpha in particular though).

Aurelien

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

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

* Re: [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648]
  2018-01-02  9:10     ` Aurelien Jarno
@ 2018-01-02 17:28       ` Richard Henderson
  0 siblings, 0 replies; 16+ messages in thread
From: Richard Henderson @ 2018-01-02 17:28 UTC (permalink / raw)
  To: libc-alpha

On 01/02/2018 01:09 AM, Aurelien Jarno wrote:
> - Using different syscalls depending on the architecture causes issues
>   when seccomp is being used, and requires additional whitelisting for
>   them. It's something that is usually not well done for non-mainstream
>   architectures like alpha. This has caused issue for example in systemd
>   (not sure about alpha in particular though).

Huh.  I hadn't considered that issue.
The patch series looks fine, then.


r~

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

* Re: [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants
  2017-12-31 19:33   ` Adhemerval Zanella
@ 2018-01-03 16:35     ` Aurelien Jarno
  0 siblings, 0 replies; 16+ messages in thread
From: Aurelien Jarno @ 2018-01-03 16:35 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2017-12-31 17:33, Adhemerval Zanella wrote:
> 
> 
> On 30/12/2017 16:44, Aurelien Jarno wrote:
> > 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.
> > 
> > Note that the alpha implementation does not include the generic
> > getrlimit64.c or setrlimit64.c as they:
> > - redefine SHLIB_COMPAT when __RLIM_T_MATCHES_RLIM64_T == 1
> > - redefine getrlimit or setrlimit, not allowing to rename them into
> >   __new_getrlimit or __new_setrlimit.
> 
> I think we can work this around to avoid code duplication with the following
> patch (based on this one plus the previous one you posted). Basically:
> 
>   * it adds a new define, USE_VERSIONED_RLIMIT, which supress the alias to the 
>     exported symbols on generic implementation (since alpha will add the
>     versioned one instead).
> 
>   * it simplifies the SHLIB_COMPAT macros on alpha since there is no need to 
>     check for both GLIBC_2_0 and GLIBC_2_1 (it is already an arch-specific
>     file which assumes an already defined ABI, in this case GLIBC_2_0).
> 
>   * it adds a weak_alias alias between __getrlimit64 and __GI_getrlimit64
>     for alpha case to follow generic case with libc_hidden_weak definition.
> 
> What do you think?

Thanks, this looks all good to me, and works as expected. I am currently
writing a test to catch this kind of issues. I'll send the new patches
when it's done. I have already committed the patches 3 & 4.

Aurelien

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

^ permalink raw reply	[flat|nested] 16+ 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
@ 2018-01-05 13:24 ` Aurelien Jarno
  0 siblings, 0 replies; 16+ 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] 16+ messages in thread

end of thread, other threads:[~2018-01-05 13:24 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-30 18:44 [PATCH 0/4] Alpha: Fix getrlimit/setrlimit with RLIM_INFINITY Aurelien Jarno
2017-12-30 18:44 ` [PATCH 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants Aurelien Jarno
2017-12-31 19:33   ` Adhemerval Zanella
2018-01-03 16:35     ` Aurelien Jarno
2017-12-30 18:44 ` [PATCH 1/4] Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant [BZ #22648] Aurelien Jarno
2017-12-31 19:33   ` Adhemerval Zanella
2018-01-01  1:42     ` Joseph Myers
2018-01-01 14:50     ` Aurelien Jarno
2018-01-01 23:01   ` Richard Henderson
2018-01-02  9:10     ` Aurelien Jarno
2018-01-02 17:28       ` Richard Henderson
2017-12-30 18:44 ` [PATCH 3/4] Fix typos in getrlimit64.c and setrlimit64.c Aurelien Jarno
2017-12-31 19:34   ` Adhemerval Zanella
2017-12-30 19:27 ` [PATCH 4/4] Simplify getrlimit64.c Aurelien Jarno
2017-12-31 19:34   ` Adhemerval Zanella
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 2/4] Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants 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).