Эх сурвалжийг харах

sysctl: avoid inline initialization

Assign each field one by one rather than stack initialization as gcc will
call memset() to zero out the rest of the structure -- which we don't care
about as the field is unused and not seen outside of the libc.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Mike Frysinger 15 жил өмнө
parent
commit
3b96fc2ea7

+ 9 - 17
libc/sysdeps/linux/common/sysctl.c

@@ -10,10 +10,6 @@
 #include <sys/syscall.h>
 #include <sys/syscall.h>
 #if defined __NR__sysctl && (defined __USE_GNU || defined __USE_BSD)
 #if defined __NR__sysctl && (defined __USE_GNU || defined __USE_BSD)
 
 
-/* psm: including sys/sysctl.h would depend on kernel headers */
-extern int sysctl (int *__name, int __nlen, void *__oldval,
-		   size_t *__oldlenp, void *__newval, size_t __newlen) __THROW;
-
 struct __sysctl_args {
 struct __sysctl_args {
 	int *name;
 	int *name;
 	int nlen;
 	int nlen;
@@ -24,21 +20,17 @@ struct __sysctl_args {
 	unsigned long __unused[4];
 	unsigned long __unused[4];
 };
 };
 
 
-static __always_inline
-_syscall1(int, _sysctl, struct __sysctl_args *, args)
-
 int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
 int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
 		   void *newval, size_t newlen)
 		   void *newval, size_t newlen)
 {
 {
-	struct __sysctl_args args = {
+	/* avoid initializing on the stack as gcc will call memset() */
-	  .name = name,
+	struct __sysctl_args args;
-	  .nlen = nlen,
+	args.name = name;
-	  .oldval = oldval,
+	args.nlen = nlen;
-	  .oldlenp = oldlenp,
+	args.oldval = oldval;
-	  .newval = newval,
+	args.oldlenp = oldlenp;
-	  .newlen = newlen
+	args.newval = newval;
-	};
+	args.newlen = newlen;
-
+	return INLINE_SYSCALL(_sysctl, 1, &args);
-	return _sysctl(&args);
 }
 }
 #endif
 #endif