From: Ammar Faizi <[email protected]>
To: Willy Tarreau <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>,
Nugraha <[email protected]>,
Linux Kernel Mailing List <[email protected]>,
GNU/Weeb Mailing List <[email protected]>,
Ammar Faizi <[email protected]>,
[email protected], [email protected],
David Laight <[email protected]>
Subject: [PATCH v1 06/11] tools/nolibc: i386: Implement syscall with 6 arguments
Date: Thu, 24 Mar 2022 14:30:34 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On i386, the 6th argument of syscall goes in %ebp. However, both Clang
and GCC cannot use %ebp in the clobber list and in the "r" constraint
without using -fomit-frame-pointer. To make it always available for
any kind of compilation, the below workaround is implemented.
1) Push the 6-th argument.
2) Push %ebp.
3) Load the 6-th argument from 4(%esp) to %ebp.
4) Do the syscall (int $0x80).
5) Pop %ebp (restore the old value of %ebp).
6) Add %esp by 4 (undo the stack pointer).
Cc: [email protected]
Cc: [email protected]
Link: https://lore.kernel.org/lkml/[email protected]
Suggested-by: David Laight <[email protected]>
Signed-off-by: Ammar Faizi <[email protected]>
---
@@ Changelog:
Link RFC v2: https://lore.kernel.org/lkml/[email protected]
RFC v2 -> v1:
- Use the same pattern for syscall6, regardless using GCC or Clang
(comment from David).
- Use appropriate constraints for syscall6 instead of always using
register variables (comment from David).
Link RFC v1: https://lore.kernel.org/llvm/[email protected]
RFC v1 -> RFC v2:
- Fix %ebp saving method. Don't use redzone, i386 doesn't have a redzone
(comment from David and Alviro).
---
tools/include/nolibc/arch-i386.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h
index 6eb96ee8c4f7..cdffd99664ae 100644
--- a/tools/include/nolibc/arch-i386.h
+++ b/tools/include/nolibc/arch-i386.h
@@ -145,6 +145,29 @@ struct sys_stat_struct {
_ret; \
})
+#define my_syscall6(num, arg1, arg2, arg3, arg4, arg5, arg6) \
+({ \
+ long _eax = (long)(num); \
+ long _arg6 = (long)(arg6); /* Always in memory */ \
+ __asm__ volatile ( \
+ "pushl %[_arg6]\n\t" \
+ "pushl %%ebp\n\t" \
+ "movl 4(%%esp),%%ebp\n\t" \
+ "int $0x80\n\t" \
+ "popl %%ebp\n\t" \
+ "addl $4,%%esp\n\t" \
+ : "+a"(_eax) /* %eax */ \
+ : "b"(arg1), /* %ebx */ \
+ "c"(arg2), /* %ecx */ \
+ "d"(arg3), /* %edx */ \
+ "S"(arg4), /* %esi */ \
+ "D"(arg5), /* %edi */ \
+ [_arg6]"m"(_arg6) /* memory */ \
+ : "memory", "cc" \
+ ); \
+ _eax; \
+})
+
/* startup code */
/*
* i386 System V ABI mandates:
--
Ammar Faizi
next prev parent reply other threads:[~2022-03-24 7:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-24 7:30 [PATCH v1 00/11] Add dynamic memory allocator support for nolibc Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 01/11] tools/nolibc: x86-64: Update System V ABI document link Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 02/11] tools/nolibc: Remove .global _start from the entry point code Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 03/11] tools/nolibc: Replace `asm` with `__asm__` Ammar Faizi
2022-03-24 7:41 ` Willy Tarreau
2022-03-24 9:03 ` Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 04/11] tools/nolibc: x86-64: Use appropriate register constraints if exist Ammar Faizi
2022-03-24 7:57 ` Willy Tarreau
2022-03-24 8:33 ` Alviro Iskandar Setiawan
2022-03-24 9:00 ` Ammar Faizi
2022-03-24 15:42 ` Willy Tarreau
2022-03-24 7:30 ` [PATCH v1 05/11] tools/nolibc: i386: " Ammar Faizi
2022-03-24 7:30 ` Ammar Faizi [this message]
2022-03-24 7:30 ` [PATCH v1 07/11] tools/nolibc/sys: Implement `mmap()` and `munmap()` Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 08/11] tools/nolibc/types: Implement `offsetof()` and `container_of()` macro Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 09/11] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()` Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 10/11] tools/nolibc/string: Implement `strnlen()` Ammar Faizi
2022-03-24 7:30 ` [PATCH v1 11/11] tools/include/string: Implement `strdup()` and `strndup()` Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox