Explorar el Código

only check for rlimit stuff if the target doesnt support the newer function call, and dont bother with 64bit versions on 64bit hosts as the regular one works fine (should fix the setrlimit ltp tests)

Mike Frysinger hace 18 años
padre
commit
ef25eef9a1

+ 3 - 0
libc/sysdeps/linux/common/bits/uClibc_arch_features.h

@@ -20,6 +20,9 @@
 /* does your target have a broken create_module() ? */
 #undef __UCLIBC_BROKEN_CREATE_MODULE__
 
+/* does your target have to worry about older [gs]etrlimit() ? */
+#undef __UCLIBC_HANDLE_OLDER_RLIMIT__
+
 /* does your target prefix all symbols with an _ ? */
 #define __UCLIBC_NO_UNDERSCORES__
 

+ 25 - 8
libc/sysdeps/linux/common/getrlimit.c

@@ -7,25 +7,37 @@
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
+#define getrlimit64 __hide_getrlimit64
 #include "syscalls.h"
 #include <unistd.h>
 #include <sys/resource.h>
+#undef getrlimit64
 
 libc_hidden_proto(getrlimit)
 
-#ifdef __NR_ugetrlimit
-# define __NR___ugetrlimit __NR_ugetrlimit
-static inline
-_syscall2(int, __ugetrlimit, enum __rlimit_resource, resource,
-		  struct rlimit *, rlim);
+/* Only wrap getrlimit if the new ugetrlimit is not present and getrlimit sucks */
+
+#if defined(__NR_ugetrlimit)
+
+/* just call ugetrlimit() */
+# define __NR___syscall_ugetrlimit __NR_ugetrlimit
+static always_inline
+_syscall2(int, __syscall_ugetrlimit, enum __rlimit_resource, resource,
+          struct rlimit *, rlim);
 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
 {
-	return (__ugetrlimit(resource, rlimits));
+	return (__syscall_ugetrlimit(resource, rlimits));
 }
 
-#else							/* __NR_ugetrlimit */
+#elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
+
+/* We don't need to wrap getrlimit() */
+_syscall2(int, getrlimit, __rlimit_resource_t, resource,
+		struct rlimit *, rlim);
 
-/* Only include the old getrlimit if the new one (ugetrlimit) is not around */
+#else
+
+/* we have to handle old style getrlimit() */
 # define __NR___syscall_getrlimit __NR_getrlimit
 static inline
 _syscall2(int, __syscall_getrlimit, int, resource, struct rlimit *, rlim);
@@ -48,4 +60,9 @@ int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
 	return result;
 }
 #endif
+
 libc_hidden_def(getrlimit)
+
+#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
+strong_alias(getrlimit, getrlimit64)
+#endif

+ 5 - 2
libc/sysdeps/linux/common/getrlimit64.c

@@ -33,10 +33,13 @@
 
 #include <sys/types.h>
 #include <sys/resource.h>
+#include <bits/wordsize.h>
 
-libc_hidden_proto(getrlimit)
+/* the regular getrlimit will work just fine for 64bit users */
+
+#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 32
 
-#if defined __UCLIBC_HAS_LFS__
+libc_hidden_proto(getrlimit)
 
 /* Put the soft and hard limits for RESOURCE in *RLIMITS.
    Returns 0 if successful, -1 if not (and sets errno).  */

+ 37 - 9
libc/sysdeps/linux/common/setrlimit.c

@@ -7,36 +7,64 @@
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
 
+#define setrlimit64 __hide_setrlimit64
 #include "syscalls.h"
 #include <unistd.h>
 #include <sys/resource.h>
+#undef setrlimit64
 
 libc_hidden_proto(setrlimit)
 
-#ifndef __NR_ugetrlimit
-/* Only wrap setrlimit if the new ugetrlimit is not present */
+/* Only wrap setrlimit if the new usetrlimit is not present and setrlimit sucks */
 
-#define __NR___syscall_setrlimit __NR_setrlimit
-#define RMIN(x, y) ((x) < (y) ? (x) : (y))
+#if defined(__NR_usetrlimit)
+
+/* just call usetrlimit() */
+# define __NR___syscall_usetrlimit __NR_usetrlimit
+static always_inline
+_syscall2(int, __syscall_usetrlimit, enum __rlimit_resource, resource,
+          const struct rlimit *, rlim);
+int setrlimit(__rlimit_resource_t resource, struct rlimit *rlimits)
+{
+	return (__syscall_usetrlimit(resource, rlimits));
+}
+
+#elif !defined(__UCLIBC_HANDLE_OLDER_RLIMIT__)
+
+/* We don't need to wrap setrlimit() */
+_syscall2(int, setrlimit, __rlimit_resource_t, resource,
+		const struct rlimit *, rlim);
+
+#else
+
+/* we have to handle old style setrlimit() */
+# define __NR___syscall_setrlimit __NR_setrlimit
 static inline
 _syscall2(int, __syscall_setrlimit, int, resource, const struct rlimit *, rlim);
+
 int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlimits)
 {
 	struct rlimit rlimits_small;
 
+	if (rlimits == NULL) {
+		__set_errno(EINVAL);
+		return -1;
+	}
+
 	/* We might have to correct the limits values.  Since the old values
 	 * were signed the new values might be too large.  */
+# define RMIN(x, y) ((x) < (y) ? (x) : (y))
 	rlimits_small.rlim_cur = RMIN((unsigned long int) rlimits->rlim_cur,
 								  RLIM_INFINITY >> 1);
 	rlimits_small.rlim_max = RMIN((unsigned long int) rlimits->rlim_max,
 								  RLIM_INFINITY >> 1);
+#undef RMIN
 	return (__syscall_setrlimit(resource, &rlimits_small));
 }
+#endif
 
-#undef RMIN
+libc_hidden_def(setrlimit)
 
-#else							/* We don't need to wrap setrlimit */
-_syscall2(int, setrlimit, __rlimit_resource_t, resource,
-		const struct rlimit *, rlim);
+#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
+strong_alias(setrlimit, setrlimit64)
 #endif
-libc_hidden_def(setrlimit)

+ 4 - 1
libc/sysdeps/linux/common/setrlimit64.c

@@ -33,8 +33,11 @@
 
 #include <sys/types.h>
 #include <sys/resource.h>
+#include <bits/wordsize.h>
 
-#if defined __UCLIBC_HAS_LFS__
+/* the regular setrlimit will work just fine for 64bit users */
+
+#if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 32
 
 libc_hidden_proto(setrlimit)
 

+ 3 - 0
libc/sysdeps/linux/i386/bits/uClibc_arch_features.h

@@ -17,6 +17,9 @@
 /* does your target have a broken create_module() ? */
 #define __UCLIBC_BROKEN_CREATE_MODULE__
 
+/* does your target have to worry about older [gs]etrlimit() ? */
+#define __UCLIBC_HANDLE_OLDER_RLIMIT__
+
 /* does your target prefix all symbols with an _ ? */
 #define __UCLIBC_NO_UNDERSCORES__
 

+ 3 - 0
libc/sysdeps/linux/m68k/bits/uClibc_arch_features.h

@@ -21,6 +21,9 @@
 /* does your target have a broken create_module() ? */
 #define __UCLIBC_BROKEN_CREATE_MODULE__
 
+/* does your target have to worry about older [gs]etrlimit() ? */
+#define __UCLIBC_HANDLE_OLDER_RLIMIT__
+
 /* does your target prefix all symbols with an _ ? */
 #define __UCLIBC_NO_UNDERSCORES__
 

+ 3 - 0
libc/sysdeps/linux/powerpc/bits/uClibc_arch_features.h

@@ -17,6 +17,9 @@
 /* does your target have a broken create_module() ? */
 #undef __UCLIBC_BROKEN_CREATE_MODULE__
 
+/* does your target have to worry about older [gs]etrlimit() ? */
+#define __UCLIBC_HANDLE_OLDER_RLIMIT__
+
 /* does your target prefix all symbols with an _ ? */
 #define __UCLIBC_NO_UNDERSCORES__
 

+ 3 - 0
libc/sysdeps/linux/sh/bits/uClibc_arch_features.h

@@ -21,6 +21,9 @@
 /* does your target have a broken create_module() ? */
 #undef __UCLIBC_BROKEN_CREATE_MODULE__
 
+/* does your target have to worry about older [gs]etrlimit() ? */
+#define __UCLIBC_HANDLE_OLDER_RLIMIT__
+
 /* does your target prefix all symbols with an _ ? */
 #define __UCLIBC_NO_UNDERSCORES__