From 21972b61ec0572395c5684eebc6cc7b3a4c9e3be Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 28 Jul 2014 12:24:22 -0700 Subject: [PATCH] syscall(3)'s return type should be long. This doesn't require us to change any of the syscall implementations because (a) the LP32 ones have sizeof(int) == sizeof(long) anyway, which is how we never noticed this bug before and (b) the LP64 ones all use a 64-bit register for the result (and for the syscall number too). Bug: https://code.google.com/p/android/issues/detail?id=73952 Change-Id: I9866c3579a7a94de27bfbe80ad7a822c3183c7fb --- libc/include/sys/syscall.h | 2 +- tests/unistd_test.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h index a44b2e5ba..34a29df3f 100644 --- a/libc/include/sys/syscall.h +++ b/libc/include/sys/syscall.h @@ -37,7 +37,7 @@ __BEGIN_DECLS -int syscall(int number, ...); +long syscall(long number, ...); __END_DECLS diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 58c9ad94f..2a656574c 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -212,6 +213,14 @@ TEST(unistd, read_EBADF) { ASSERT_EQ(EBADF, errno); } +TEST(unistd, syscall_long) { + // Check that syscall(3) correctly returns long results. + // https://code.google.com/p/android/issues/detail?id=73952 + // We assume that the break is > 4GiB, but this is potentially flaky. + uintptr_t p = reinterpret_cast(sbrk(0)); + ASSERT_EQ(p, static_cast(syscall(__NR_brk, 0))); +} + TEST(unistd, alarm) { ASSERT_EQ(0U, alarm(0)); }