Skip to content

Commit 371779f

Browse files
author
Siva Chandra
committed
[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
1 parent b191c1f commit 371779f

File tree

6 files changed

+143
-6
lines changed

6 files changed

+143
-6
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ set(TARGET_LIBM_ENTRYPOINTS
171171
libc.src.math.truncl
172172
)
173173

174+
if(LLVM_LIBC_FULL_BUILD)
175+
list(APPEND TARGET_LIBC_ENTRYPOINTS
176+
# sys/mman.h entrypoints
177+
libc.src.sys.mman.mmap
178+
libc.src.sys.mman.munmap
179+
)
180+
endif()
181+
174182
set(TARGET_LLVMLIBC_ENTRYPOINTS
175183
${TARGET_LIBC_ENTRYPOINTS}
176184
${TARGET_LIBM_ENTRYPOINTS}

libc/src/__support/OSUtil/linux/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_subdirectory(aarch64)
12
add_subdirectory(x86_64)
23

34
add_header_library(
@@ -7,6 +8,7 @@ add_header_library(
78
quick_exit.h
89
syscall.h
910
DEPENDS
11+
.aarch64.linux_aarch64_util
1012
.x86_64.linux_x86_64_util
1113
libc.src.__support.common
1214
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_header_library(
2+
linux_aarch64_util
3+
HDRS
4+
syscall.h
5+
DEPENDS
6+
libc.src.__support.common
7+
)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//===--------- inline implementation of aarch64 syscalls ----------* C++ *-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
10+
#define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
11+
12+
#include "src/__support/common.h"
13+
14+
#define REGISTER_DECL_0 \
15+
register long x8 __asm__("x8") = number; \
16+
register long x0 __asm__("x0");
17+
#define REGISTER_DECL_1 \
18+
register long x8 __asm__("x8") = number; \
19+
register long x0 __asm__("x0") = arg1;
20+
#define REGISTER_DECL_2 REGISTER_DECL_1 register long x1 __asm__("x1") = arg2;
21+
#define REGISTER_DECL_3 \
22+
REGISTER_DECL_2 \
23+
register long x2 __asm__("x2") = arg3;
24+
#define REGISTER_DECL_4 \
25+
REGISTER_DECL_3 \
26+
register long x3 __asm__("x3") = arg4;
27+
#define REGISTER_DECL_5 \
28+
REGISTER_DECL_4 \
29+
register long x4 __asm__("x4") = arg5;
30+
#define REGISTER_DECL_6 \
31+
REGISTER_DECL_5 \
32+
register long x5 __asm__("x5") = arg6;
33+
34+
#define REGISTER_CONSTRAINT_0 "r"(x8)
35+
#define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(x0)
36+
#define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(x1)
37+
#define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(x2)
38+
#define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(x3)
39+
#define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(x4)
40+
#define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(x5)
41+
42+
#define SYSCALL_INSTR(input_constraint) \
43+
LIBC_INLINE_ASM("svc 0" : "=r"(x0) : input_constraint : "memory", "cc")
44+
45+
namespace __llvm_libc {
46+
47+
__attribute__((always_inline)) inline long syscall(long number) {
48+
REGISTER_DECL_0;
49+
SYSCALL_INSTR(REGISTER_CONSTRAINT_0);
50+
return x0;
51+
}
52+
53+
__attribute__((always_inline)) inline long syscall(long number, long arg1) {
54+
REGISTER_DECL_1;
55+
SYSCALL_INSTR(REGISTER_CONSTRAINT_1);
56+
return x0;
57+
}
58+
59+
__attribute__((always_inline)) inline long syscall(long number, long arg1,
60+
long arg2) {
61+
REGISTER_DECL_2;
62+
SYSCALL_INSTR(REGISTER_CONSTRAINT_2);
63+
return x0;
64+
}
65+
66+
__attribute__((always_inline)) inline long syscall(long number, long arg1,
67+
long arg2, long arg3) {
68+
REGISTER_DECL_3;
69+
SYSCALL_INSTR(REGISTER_CONSTRAINT_3);
70+
return x0;
71+
}
72+
73+
__attribute__((always_inline)) inline long
74+
syscall(long number, long arg1, long arg2, long arg3, long arg4) {
75+
REGISTER_DECL_4;
76+
SYSCALL_INSTR(REGISTER_CONSTRAINT_4);
77+
return x0;
78+
}
79+
80+
__attribute__((always_inline)) inline long
81+
syscall(long number, long arg1, long arg2, long arg3, long arg4, long arg5) {
82+
REGISTER_DECL_5;
83+
SYSCALL_INSTR(REGISTER_CONSTRAINT_5);
84+
return x0;
85+
}
86+
87+
__attribute__((always_inline)) inline long syscall(long number, long arg1,
88+
long arg2, long arg3,
89+
long arg4, long arg5,
90+
long arg6) {
91+
REGISTER_DECL_6;
92+
SYSCALL_INSTR(REGISTER_CONSTRAINT_6);
93+
return x0;
94+
}
95+
96+
} // namespace __llvm_libc
97+
98+
#undef REGISTER_DECL_0
99+
#undef REGISTER_DECL_1
100+
#undef REGISTER_DECL_2
101+
#undef REGISTER_DECL_3
102+
#undef REGISTER_DECL_4
103+
#undef REGISTER_DECL_5
104+
#undef REGISTER_DECL_6
105+
106+
#undef REGISTER_CONSTRAINT_0
107+
#undef REGISTER_CONSTRAINT_1
108+
#undef REGISTER_CONSTRAINT_2
109+
#undef REGISTER_CONSTRAINT_3
110+
#undef REGISTER_CONSTRAINT_4
111+
#undef REGISTER_CONSTRAINT_5
112+
#undef REGISTER_CONSTRAINT_6
113+
114+
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H

libc/src/__support/OSUtil/linux/syscall.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313

1414
#ifdef LLVM_LIBC_ARCH_X86_64
1515
#include "x86_64/syscall.h"
16+
#elif defined(LLVM_LIBC_ARCH_AARCH64)
17+
#include "aarch64/syscall.h"
1618
#endif
1719

20+
namespace __llvm_libc {
21+
22+
template <typename... Ts>
23+
__attribute__((always_inline)) inline long syscall(long __number, Ts... ts) {
24+
static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall");
25+
return syscall(__number, (long)ts...);
26+
}
27+
28+
} // namespace __llvm_libc
29+
1830
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H

libc/src/__support/OSUtil/linux/x86_64/syscall.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ __attribute__((always_inline)) inline long syscall(long __number, long __arg1,
9595
return retcode;
9696
}
9797

98-
template <typename... Ts>
99-
__attribute__((always_inline)) inline long syscall(long __number, Ts... ts) {
100-
static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall");
101-
return syscall(__number, (long)ts...);
102-
}
103-
10498
#undef SYSCALL_CLOBBER_LIST
10599

106100
} // namespace __llvm_libc

0 commit comments

Comments
 (0)