[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
This commit is contained in:
Alex Brachet 2020-02-13 14:39:16 -05:00
parent 22d63b6318
commit 2c73c26666
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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);
});
}