-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc][i386] syscall support #114264
Open
nickdesaulniers
wants to merge
1
commit into
llvm:main
Choose a base branch
from
nickdesaulniers:i386_syscalls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[libc][i386] syscall support #114264
+79
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libc Author: Nick Desaulniers (nickdesaulniers) ChangesLink: #93709 Full diff: https://github.com/llvm/llvm-project/pull/114264.diff 2 Files Affected:
diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h
new file mode 100644
index 00000000000000..ddc51c543077ed
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/i386/syscall.h
@@ -0,0 +1,76 @@
+//===---------- inline implementation of i386 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_I386_SYSCALL_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
+
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LIBC_INLINE long syscall_impl(long num) {
+ long ret;
+ LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num) : "memory");
+ return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1) {
+ long ret;
+ LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1) : "memory");
+ return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2) {
+ long ret;
+ LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1),
+ "c"(arg2) : "memory");
+ return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3) {
+ long ret;
+ LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
+ "d"(arg3) : "memory");
+ return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
+ long arg4) {
+ long ret;
+ LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
+ "d"(arg3), "S"(arg4) : "memory");
+ return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
+ long arg4, long arg5) {
+ long ret;
+ LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
+ "d"(arg3), "S"(arg4), "D"(arg5) : "memory");
+ return ret;
+}
+
+LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
+ long arg4, long arg5, long arg6) {
+ long ret;
+ LIBC_INLINE_ASM(R"(
+ push %[arg6]
+ push %%ebp
+ mov 4(%%esp), %%ebp
+ int $128
+ pop %%ebp
+ add $4, %%esp
+ )" : "=a"(ret) : "a"(num),
+ "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
+ "D"(arg5), [arg6] "m"(arg6) : "memory");
+ return ret;
+}
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H
diff --git a/libc/src/__support/OSUtil/linux/syscall.h b/libc/src/__support/OSUtil/linux/syscall.h
index ad3f6947d0a06a..24e0fca73c1678 100644
--- a/libc/src/__support/OSUtil/linux/syscall.h
+++ b/libc/src/__support/OSUtil/linux/syscall.h
@@ -14,7 +14,9 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
-#ifdef LIBC_TARGET_ARCH_IS_X86_64
+#ifdef LIBC_TARGET_ARCH_IS_X86_32
+#include "i386/syscall.h"
+#elif defined(LIBC_TARGET_ARCH_IS_X86_64)
#include "x86_64/syscall.h"
#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
#include "aarch64/syscall.h"
|
You can test this locally with the following command:git-clang-format --diff f405c683ba929fcd0bcaa435ca2fbe4bb221d04b 93ebdb3d34c8b9eb9ec107dd742f53188db47a04 --extensions h -- libc/src/__support/OSUtil/linux/i386/syscall.h libc/src/__support/OSUtil/linux/syscall.h View the diff from clang-format here.diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h
index ddc51c5430..441998b6db 100644
--- a/libc/src/__support/OSUtil/linux/i386/syscall.h
+++ b/libc/src/__support/OSUtil/linux/i386/syscall.h
@@ -27,31 +27,40 @@ LIBC_INLINE long syscall_impl(long num, long arg1) {
LIBC_INLINE long syscall_impl(long num, long arg1, long arg2) {
long ret;
- LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1),
- "c"(arg2) : "memory");
+ LIBC_INLINE_ASM("int $128"
+ : "=a"(ret)
+ : "a"(num), "b"(arg1), "c"(arg2)
+ : "memory");
return ret;
}
LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3) {
long ret;
- LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
- "d"(arg3) : "memory");
+ LIBC_INLINE_ASM("int $128"
+ : "=a"(ret)
+ : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3)
+ : "memory");
return ret;
}
LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
long arg4) {
long ret;
- LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
- "d"(arg3), "S"(arg4) : "memory");
+ LIBC_INLINE_ASM("int $128"
+ : "=a"(ret)
+ : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4)
+ : "memory");
return ret;
}
LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
long arg4, long arg5) {
long ret;
- LIBC_INLINE_ASM("int $128" : "=a"(ret) : "a"(num), "b"(arg1), "c"(arg2),
- "d"(arg3), "S"(arg4), "D"(arg5) : "memory");
+ LIBC_INLINE_ASM("int $128"
+ : "=a"(ret)
+ : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
+ "D"(arg5)
+ : "memory");
return ret;
}
@@ -65,9 +74,11 @@ LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3,
int $128
pop %%ebp
add $4, %%esp
- )" : "=a"(ret) : "a"(num),
- "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
- "D"(arg5), [arg6] "m"(arg6) : "memory");
+ )"
+ : "=a"(ret)
+ : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3), "S"(arg4),
+ "D"(arg5), [arg6] "m"(arg6)
+ : "memory");
return ret;
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Link: #93709