]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Amend the recent update to VG_(getrlimit) and VG_(setrlimit)
authorPetar Jovanovic <mips32r2@gmail.com>
Thu, 23 Apr 2020 16:42:26 +0000 (16:42 +0000)
committerPetar Jovanovic <mips32r2@gmail.com>
Thu, 23 Apr 2020 16:42:26 +0000 (16:42 +0000)
[get|set]rlimit system calls are becoming deprecated.
Coregrind should use prlimit64 as the first candidate in order to
achieve "rlimit" functionality.

There are also systems that do not even support older "rlimits".

Modify the previously added support VG_(getrlimit) and VG_(setrlimit)
using __NR_prlimit64 by making it similar to the glibc implementation.

It fixes none/tests/stackgrowth and none/tests/sigstackgrowth
tests on nanoMIPS.

Patch by: Stefan Maksimovic and Aleksandar Rikalo

This patch resolves KDE #416285.

NEWS
coregrind/m_libcproc.c
include/vki/vki-linux.h
include/vki/vki-mips32-linux.h
include/vki/vki-nanomips-linux.h

diff --git a/NEWS b/NEWS
index 27e79f6f5d928e88ab925f4c98d1926f55e372c7..a71e581281ba556afb5dc3a52d279ab2fbde9c64 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -116,6 +116,7 @@ where XXXXXX is the bug number as listed below.
 415136  ARMv8.1 Compare-and-Swap instructions are not supported
 415757  vex x86->IR: 0x66 0xF 0xCE 0x4F (bswapw)
 416239  valgrind crashes when handling clock_adjtime
+416285  Use prlimit64 in VG_(getrlimit) and VG_(setrlimit)
 416286  DRD reports "conflicting load" error on std::mutex::lock()
 416301  s390x: "compare and signal" not supported
 416387  finit_module and bpf syscalls are unhandled on arm64
index e7aef7fe66e94a21e4ddd6d2e531aea1bd2f7d3a..ae3804f99039088da2278f922d0e6e05f41cb70d 100644 (file)
@@ -600,44 +600,60 @@ Int VG_(sysctl)(Int *name, UInt namelen, void *oldp, SizeT *oldlenp, void *newp,
 /* Support for getrlimit. */
 Int VG_(getrlimit) (Int resource, struct vki_rlimit *rlim)
 {
-   SysRes res = VG_(mk_SysRes_Error)(VKI_ENOSYS);
+   SysRes res;
    /* res = getrlimit( resource, rlim ); */
+
+#  if defined(__NR_prlimit64) && defined(VKI_RLIM_INFINITY) && defined(VKI_RLIM64_INFINITY)
+   struct vki_rlimit64 new_rlimit;
+   res = VG_(do_syscall4)(__NR_prlimit64, 0, resource, 0, (UWord)&new_rlimit);
+   if (!sr_isError(res)) {
+      if (new_rlimit.rlim_cur == VKI_RLIM_INFINITY)
+         new_rlimit.rlim_cur = VKI_RLIM64_INFINITY;
+      if (new_rlimit.rlim_max == VKI_RLIM_INFINITY)
+         new_rlimit.rlim_max = VKI_RLIM64_INFINITY;
+      rlim->rlim_cur = new_rlimit.rlim_cur;
+      rlim->rlim_max = new_rlimit.rlim_max;
+      return sr_Res(res);
+   }
+   if (sr_Err(res) != VKI_ENOSYS) return -1;
+#  endif
+
 #  ifdef __NR_ugetrlimit
    res = VG_(do_syscall2)(__NR_ugetrlimit, resource, (UWord)rlim);
+   if (!sr_isError(res)) return sr_Res(res);
+   if (sr_Err(res) != VKI_ENOSYS) return -1;
 #  endif
-   if (sr_isError(res) && sr_Err(res) == VKI_ENOSYS)
-#  if defined(VGP_nanomips_linux)
-   {
-      struct vki_rlimit64 new_rlimit;
-      res = VG_(do_syscall4)(__NR_prlimit64, 0, resource, 0, (UWord)&new_rlimit);
-      if (new_rlimit.rlim_cur > 2147483647 || new_rlimit.rlim_max > 2147483647)
-         res = VG_(mk_SysRes_Error)(VKI_ENOSYS);
-      else {
-         rlim->rlim_cur = new_rlimit.rlim_cur;
-         rlim->rlim_max = new_rlimit.rlim_max;
-      }
-   }
-#  else
-      res = VG_(do_syscall2)(__NR_getrlimit, resource, (UWord)rlim);
+
+#  ifdef __NR_getrlimit
+   res = VG_(do_syscall2)(__NR_getrlimit, resource, (UWord)rlim);
+   if (!sr_isError(res)) return sr_Res(res);
 #  endif
-   return sr_isError(res) ? -1 : sr_Res(res);
-}
 
+   return -1;
+}
 
 /* Support for setrlimit. */
 Int VG_(setrlimit) (Int resource, const struct vki_rlimit *rlim)
 {
    SysRes res;
    /* res = setrlimit( resource, rlim ); */
-#  if defined(VGP_nanomips_linux)
+
+#  ifdef __NR_prlimit64
    struct vki_rlimit64 new_rlimit;
    new_rlimit.rlim_cur = rlim->rlim_cur;
    new_rlimit.rlim_max = rlim->rlim_max;
    res = VG_(do_syscall4)(__NR_prlimit64, 0, resource, (UWord)&new_rlimit, 0);
-#  else
+   if (!sr_isError(res)) return sr_Res(res);
+   if (sr_Err(res) != VKI_ENOSYS) return -1;
+#  endif
+
+#  ifdef __NR_setrlimit
    res = VG_(do_syscall2)(__NR_setrlimit, resource, (UWord)rlim);
+   if (!sr_isError(res)) return sr_Res(res);
+   if (sr_Err(res) != VKI_ENOSYS) return -1;
 #  endif
-   return sr_isError(res) ? -1 : sr_Res(res);
+
+   return -1;
 }
 
 /* Support for prctl. */
index 6f1100fe06a57171d5977a4d02467e6bdb8b00c1..ffda18f1833fb3767a6cb2b567f47310dc5948ea 100644 (file)
@@ -5339,6 +5339,12 @@ struct vki_itimerspec64 {
    struct vki_timespec it_value;
 };
 
+#ifndef VKI_RLIM_INFINITY
+#define VKI_RLIM_INFINITY (~0UL)
+#endif
+
+#define VKI_RLIM64_INFINITY (~0ULL)
+
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
index 94e453ed4692fccfef5d06593b86d44be4dea1ff..38f60b7749af38fc56d4f22b382e42d6c73244ff 100644 (file)
@@ -367,6 +367,7 @@ struct vki_f_owner_ex {
 #define VKI_RLIMIT_STACK       3   /* max stack size */
 #define VKI_RLIMIT_CORE                4   /* max core file size */
 #define VKI_RLIMIT_NOFILE      5   /* max number of open files */
+#define VKI_RLIM_INFINITY 0x7fffffffUL
 
 //----------------------------------------------------------------------
 // From linux-2.6.35.5/include/asm-mips/socket.h
index 7f42c25912b159a06e5b2d458eb414e69450a746..e1427f1d668c03f6522549b71db04dd7e44b3c48 100644 (file)
 #define ARCH_HAS_SOCKET_TYPES 1
 #define HAVE_ARCH_SIGINFO_T   1
 
-#define VKI_RLIM64_INFINITY 0x7fffffffUL
+#define VKI_RLIM_INFINITY 0x7fffffffUL
 
 typedef __signed__ char __vki_s8;
 typedef unsigned   char __vki_u8;