[libc-commits] [libc] 371779f - [libc] Add linux aarch64 syscall implementation.
Siva Chandra via libc-commits
libc-commits at lists.llvm.org
Mon Jan 10 15:53:27 PST 2022
Author: Siva Chandra
Date: 2022-01-10T15:53:17-08:00
New Revision: 371779fac193e8af3854941bff3b88da6597a200
URL: https://github.com/llvm/llvm-project/commit/371779fac193e8af3854941bff3b88da6597a200
DIFF: https://github.com/llvm/llvm-project/commit/371779fac193e8af3854941bff3b88da6597a200.diff
LOG: [libc] Add linux aarch64 syscall implementation.
Add mmap and munmap to the linux aarch64 entrypoint list as the first
user of these syscalls.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D116949
Added:
libc/src/__support/OSUtil/linux/aarch64/CMakeLists.txt
libc/src/__support/OSUtil/linux/aarch64/syscall.h
Modified:
libc/config/linux/aarch64/entrypoints.txt
libc/src/__support/OSUtil/linux/CMakeLists.txt
libc/src/__support/OSUtil/linux/syscall.h
libc/src/__support/OSUtil/linux/x86_64/syscall.h
Removed:
################################################################################
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 25dc646764541..c0072c6190750 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -171,6 +171,14 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.truncl
)
+if(LLVM_LIBC_FULL_BUILD)
+ list(APPEND TARGET_LIBC_ENTRYPOINTS
+ # sys/mman.h entrypoints
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ )
+endif()
+
set(TARGET_LLVMLIBC_ENTRYPOINTS
${TARGET_LIBC_ENTRYPOINTS}
${TARGET_LIBM_ENTRYPOINTS}
diff --git a/libc/src/__support/OSUtil/linux/CMakeLists.txt b/libc/src/__support/OSUtil/linux/CMakeLists.txt
index 4b0f5d70a0a24..b04237a808949 100644
--- a/libc/src/__support/OSUtil/linux/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/CMakeLists.txt
@@ -1,3 +1,4 @@
+add_subdirectory(aarch64)
add_subdirectory(x86_64)
add_header_library(
@@ -7,6 +8,7 @@ add_header_library(
quick_exit.h
syscall.h
DEPENDS
+ .aarch64.linux_aarch64_util
.x86_64.linux_x86_64_util
libc.src.__support.common
)
diff --git a/libc/src/__support/OSUtil/linux/aarch64/CMakeLists.txt b/libc/src/__support/OSUtil/linux/aarch64/CMakeLists.txt
new file mode 100644
index 0000000000000..eea9badc46cae
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/aarch64/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_header_library(
+ linux_aarch64_util
+ HDRS
+ syscall.h
+ DEPENDS
+ libc.src.__support.common
+)
diff --git a/libc/src/__support/OSUtil/linux/aarch64/syscall.h b/libc/src/__support/OSUtil/linux/aarch64/syscall.h
new file mode 100644
index 0000000000000..841f63e368453
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/aarch64/syscall.h
@@ -0,0 +1,114 @@
+//===--------- inline implementation of aarch64 syscalls ----------* C++ *-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
+#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
+
+#include "src/__support/common.h"
+
+#define REGISTER_DECL_0 \
+ register long x8 __asm__("x8") = number; \
+ register long x0 __asm__("x0");
+#define REGISTER_DECL_1 \
+ register long x8 __asm__("x8") = number; \
+ register long x0 __asm__("x0") = arg1;
+#define REGISTER_DECL_2 REGISTER_DECL_1 register long x1 __asm__("x1") = arg2;
+#define REGISTER_DECL_3 \
+ REGISTER_DECL_2 \
+ register long x2 __asm__("x2") = arg3;
+#define REGISTER_DECL_4 \
+ REGISTER_DECL_3 \
+ register long x3 __asm__("x3") = arg4;
+#define REGISTER_DECL_5 \
+ REGISTER_DECL_4 \
+ register long x4 __asm__("x4") = arg5;
+#define REGISTER_DECL_6 \
+ REGISTER_DECL_5 \
+ register long x5 __asm__("x5") = arg6;
+
+#define REGISTER_CONSTRAINT_0 "r"(x8)
+#define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(x0)
+#define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(x1)
+#define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(x2)
+#define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(x3)
+#define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(x4)
+#define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(x5)
+
+#define SYSCALL_INSTR(input_constraint) \
+ LIBC_INLINE_ASM("svc 0" : "=r"(x0) : input_constraint : "memory", "cc")
+
+namespace __llvm_libc {
+
+__attribute__((always_inline)) inline long syscall(long number) {
+ REGISTER_DECL_0;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_0);
+ return x0;
+}
+
+__attribute__((always_inline)) inline long syscall(long number, long arg1) {
+ REGISTER_DECL_1;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_1);
+ return x0;
+}
+
+__attribute__((always_inline)) inline long syscall(long number, long arg1,
+ long arg2) {
+ REGISTER_DECL_2;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_2);
+ return x0;
+}
+
+__attribute__((always_inline)) inline long syscall(long number, long arg1,
+ long arg2, long arg3) {
+ REGISTER_DECL_3;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_3);
+ return x0;
+}
+
+__attribute__((always_inline)) inline long
+syscall(long number, long arg1, long arg2, long arg3, long arg4) {
+ REGISTER_DECL_4;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_4);
+ return x0;
+}
+
+__attribute__((always_inline)) inline long
+syscall(long number, long arg1, long arg2, long arg3, long arg4, long arg5) {
+ REGISTER_DECL_5;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_5);
+ return x0;
+}
+
+__attribute__((always_inline)) inline long syscall(long number, long arg1,
+ long arg2, long arg3,
+ long arg4, long arg5,
+ long arg6) {
+ REGISTER_DECL_6;
+ SYSCALL_INSTR(REGISTER_CONSTRAINT_6);
+ return x0;
+}
+
+} // namespace __llvm_libc
+
+#undef REGISTER_DECL_0
+#undef REGISTER_DECL_1
+#undef REGISTER_DECL_2
+#undef REGISTER_DECL_3
+#undef REGISTER_DECL_4
+#undef REGISTER_DECL_5
+#undef REGISTER_DECL_6
+
+#undef REGISTER_CONSTRAINT_0
+#undef REGISTER_CONSTRAINT_1
+#undef REGISTER_CONSTRAINT_2
+#undef REGISTER_CONSTRAINT_3
+#undef REGISTER_CONSTRAINT_4
+#undef REGISTER_CONSTRAINT_5
+#undef REGISTER_CONSTRAINT_6
+
+#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
diff --git a/libc/src/__support/OSUtil/linux/syscall.h b/libc/src/__support/OSUtil/linux/syscall.h
index 754883e8a667f..5887a62902b96 100644
--- a/libc/src/__support/OSUtil/linux/syscall.h
+++ b/libc/src/__support/OSUtil/linux/syscall.h
@@ -13,6 +13,18 @@
#ifdef LLVM_LIBC_ARCH_X86_64
#include "x86_64/syscall.h"
+#elif defined(LLVM_LIBC_ARCH_AARCH64)
+#include "aarch64/syscall.h"
#endif
+namespace __llvm_libc {
+
+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...);
+}
+
+} // namespace __llvm_libc
+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H
diff --git a/libc/src/__support/OSUtil/linux/x86_64/syscall.h b/libc/src/__support/OSUtil/linux/x86_64/syscall.h
index 77d139806271f..c6f88a6ec853a 100644
--- a/libc/src/__support/OSUtil/linux/x86_64/syscall.h
+++ b/libc/src/__support/OSUtil/linux/x86_64/syscall.h
@@ -95,12 +95,6 @@ __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
More information about the libc-commits
mailing list