[RFC 1/1] Fix varargs in prctl syscall

Hans-Christian Egtvedt hans-christian.egtvedt at atmel.com
Fri Sep 12 13:34:14 UTC 2008


prctl is defined to use varargs in the header file, but implemented to use
varargs in the source. This patch properly handles the variodic argument before
the syscall is passed to the kernel.

Signed-off-by: Hans-Christian Egtvedt <hans-christian.egtvedt at atmel.com>
---
I am considering applying the patch above, but I would like some feedback on
the solution I chose.

 libc/sysdeps/linux/common/prctl.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/libc/sysdeps/linux/common/prctl.c b/libc/sysdeps/linux/common/prctl.c
index 4853867..ac7ea6e 100644
--- a/libc/sysdeps/linux/common/prctl.c
+++ b/libc/sysdeps/linux/common/prctl.c
@@ -8,10 +8,26 @@
  */
 
 #include <sys/syscall.h>
+#include <sys/prctl.h>
 #include <stdarg.h>
-/* psm: including sys/prctl.h would depend on kernel headers */
 
 #ifdef __NR_prctl
-extern int prctl (int, long, long, long, long);
-_syscall5(int, prctl, int, option, long, arg2, long, arg3, long, arg4, long, arg5);
+#define __NR___syscall_prctl __NR_prctl
+static inline _syscall5(int, __syscall_prctl, int, option, long, arg2, long,
+		arg3, long, arg4, long, arg5);
+
+int prctl(int option, ...) {
+	long arg2 = 0;
+	va_list ap;
+
+	va_start(ap, option);
+
+	if (option != PR_GET_KEEPCAPS && option != PR_GET_TIMING &&
+			option != PR_GET_ENDIAN)
+		arg2 = va_arg(ap, long);
+
+	va_end(ap);
+
+	return __syscall_prctl(option, arg2, 0, 0, 0);
+}
 #endif
-- 
1.5.4.3




More information about the uClibc mailing list