[libc-commits] [libc] 2c73c26 - [libc] Add Convenience syscall Template Function
Alex Brachet via libc-commits
libc-commits at lists.llvm.org
Thu Feb 13 11:40:11 PST 2020
Author: Alex Brachet
Date: 2020-02-13T14:39:16-05:00
New Revision: 2c73c266665108ab84a27b11c7860db4bd839225
URL: https://github.com/llvm/llvm-project/commit/2c73c266665108ab84a27b11c7860db4bd839225
DIFF: https://github.com/llvm/llvm-project/commit/2c73c266665108ab84a27b11c7860db4bd839225.diff
LOG: [libc] Add Convenience syscall Template Function
Summary: This patch adds a convenience template function so we don't need to cast all types to `long` manually when calling `__llvm_libc::syscall`.
Reviewers: sivachandra, MaskRay, gchatelet
Reviewed By: sivachandra
Subscribers: libc-commits, tschuett
Differential Revision: https://reviews.llvm.org/D74530
Added:
Modified:
libc/config/linux/x86_64/syscall.h.inc
libc/test/config/linux/x86_64/syscall_test.cpp
Removed:
################################################################################
diff --git a/libc/config/linux/x86_64/syscall.h.inc b/libc/config/linux/x86_64/syscall.h.inc
index 4659aa09a480..ee3b5e5bfc0d 100644
--- a/libc/config/linux/x86_64/syscall.h.inc
+++ b/libc/config/linux/x86_64/syscall.h.inc
@@ -94,6 +94,13 @@ __attribute__((always_inline)) inline long syscall(long __number, long __arg1,
return retcode;
}
+template <typename... Ts>
+__attribute__((always_inline)) inline long syscall(long __number, Ts... ts) {
+ static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall");
+ return syscall(__number, (long)ts...);
+}
+
+
#undef SYSCALL_CLOBBER_LIST
} // namespace __llvm_libc
diff --git a/libc/test/config/linux/x86_64/syscall_test.cpp b/libc/test/config/linux/x86_64/syscall_test.cpp
index efab1444d35c..8db7a85256e7 100644
--- a/libc/test/config/linux/x86_64/syscall_test.cpp
+++ b/libc/test/config/linux/x86_64/syscall_test.cpp
@@ -36,4 +36,9 @@ TEST(X86_64_SyscallTest, APITest) {
[](long n, long a1, long a2, long a3, long a4, long a5, long a6) {
return __llvm_libc::syscall(n, a1, a2, a3, a4, a5, a6);
});
+
+ std::function<long(long, void *)> notLongType(
+ [](long n, void *a1) {
+ return __llvm_libc::syscall(n, a1);
+ });
}
More information about the libc-commits
mailing list