From 93ebdb3d34c8b9eb9ec107dd742f53188db47a04 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Wed, 2 Oct 2024 10:23:57 -0700 Subject: [PATCH 1/5] [libc][i386] syscall support Link: #93709 --- .../src/__support/OSUtil/linux/i386/syscall.h | 76 +++++++++++++++++++ libc/src/__support/OSUtil/linux/syscall.h | 4 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 libc/src/__support/OSUtil/linux/i386/syscall.h 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 0000000000000..ddc51c543077e --- /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 ad3f6947d0a06..24e0fca73c167 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" From 7da47561502ad9680aacb5dd6ceebbe1633c7116 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Wed, 30 Oct 2024 12:58:29 -0700 Subject: [PATCH 2/5] reformat with clang-format-17 --- .../src/__support/OSUtil/linux/i386/syscall.h | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h index ddc51c543077e..441998b6dbe2e 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; } From 593e1aa3f0a5de47e7117c1a6dace4b13f55a67c Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Thu, 31 Oct 2024 08:55:24 -0700 Subject: [PATCH 3/5] s/LIBC_NAMESPACE/LIBC_NAMESPACE_DECL/ --- libc/src/__support/OSUtil/linux/i386/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h index 441998b6dbe2e..43a6d9b1e3797 100644 --- a/libc/src/__support/OSUtil/linux/i386/syscall.h +++ b/libc/src/__support/OSUtil/linux/i386/syscall.h @@ -11,7 +11,7 @@ #include "src/__support/common.h" -namespace LIBC_NAMESPACE { +namespace LIBC_NAMESPACE_DECL { LIBC_INLINE long syscall_impl(long num) { long ret; From 66887be91563d737f46c1756febb0952831a3d0b Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Thu, 31 Oct 2024 09:04:52 -0700 Subject: [PATCH 4/5] reformat --- libc/src/__support/OSUtil/linux/i386/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h index 43a6d9b1e3797..a301d9e4587b5 100644 --- a/libc/src/__support/OSUtil/linux/i386/syscall.h +++ b/libc/src/__support/OSUtil/linux/i386/syscall.h @@ -82,6 +82,6 @@ LIBC_INLINE long syscall_impl(long num, long arg1, long arg2, long arg3, return ret; } -} // namespace LIBC_NAMESPACE +} // namespace LIBC_NAMESPACE_DECL #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H From 79305a00dd919acf89c5f48b23b95a34bee28735 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Thu, 31 Oct 2024 10:47:44 -0700 Subject: [PATCH 5/5] include config.h --- libc/src/__support/OSUtil/linux/i386/syscall.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/src/__support/OSUtil/linux/i386/syscall.h b/libc/src/__support/OSUtil/linux/i386/syscall.h index a301d9e4587b5..88d7f2fb2c49f 100644 --- a/libc/src/__support/OSUtil/linux/i386/syscall.h +++ b/libc/src/__support/OSUtil/linux/i386/syscall.h @@ -10,6 +10,7 @@ #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_I386_SYSCALL_H #include "src/__support/common.h" +#include "src/__support/macros/config.h" namespace LIBC_NAMESPACE_DECL {