git: 8f465f509bc1 - main - {amd64,i386}/SYS.h: add _SYSCALL and _SYSCALL_BODY
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 18 Dec 2023 22:28:59 UTC
The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=8f465f509bc1b038806963f716263b56004871d3 commit 8f465f509bc1b038806963f716263b56004871d3 Author: Brooks Davis <brooks@FreeBSD.org> AuthorDate: 2023-12-18 22:28:42 +0000 Commit: Brooks Davis <brooks@FreeBSD.org> CommitDate: 2023-12-18 22:28:42 +0000 {amd64,i386}/SYS.h: add _SYSCALL and _SYSCALL_BODY Add a _SYSCALL(name) which calls the SYS_name syscall. Use it to add a _SYSCALL_BODY() macro which invokes the syscall and calls cerror as required. Use the latter to implement PSEUDO() and RSYSCALL(). Reviewed by: imp, markj Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43059 --- lib/libc/amd64/SYS.h | 18 ++++++++++++------ lib/libc/amd64/gen/rfork_thread.S | 6 ++---- lib/libc/amd64/sys/getcontext.S | 3 +-- lib/libc/amd64/sys/vfork.S | 3 +-- lib/libc/i386/SYS.h | 19 ++++++++++++------- lib/libc/i386/gen/rfork_thread.S | 6 ++---- lib/libc/i386/sys/getcontext.S | 3 +-- lib/libc/i386/sys/syscall.S | 2 +- lib/libc/i386/sys/vfork.S | 3 +-- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/libc/amd64/SYS.h b/lib/libc/amd64/SYS.h index 23b4226d942f..2dfca1896fcd 100644 --- a/lib/libc/amd64/SYS.h +++ b/lib/libc/amd64/SYS.h @@ -35,17 +35,23 @@ #include <sys/syscall.h> #include <machine/asm.h> +#define _SYSCALL(name) \ + mov $SYS_##name, %eax; \ + movq %rcx, %r10; \ + syscall + +#define _SYSCALL_BODY(name) \ + _SYSCALL(name); \ + jb HIDENAME(cerror); \ + ret + #define RSYSCALL(name) ENTRY(__sys_##name); \ WEAK_REFERENCE(__sys_##name, name); \ WEAK_REFERENCE(__sys_##name, _##name); \ - mov $SYS_##name,%eax; KERNCALL; \ - jb HIDENAME(cerror); ret; \ + _SYSCALL_BODY(name); \ END(__sys_##name) #define PSEUDO(name) ENTRY(__sys_##name); \ WEAK_REFERENCE(__sys_##name, _##name); \ - mov $SYS_##name,%eax; KERNCALL; \ - jb HIDENAME(cerror); ret; \ + _SYSCALL_BODY(name); \ END(__sys_##name) - -#define KERNCALL movq %rcx, %r10; syscall diff --git a/lib/libc/amd64/gen/rfork_thread.S b/lib/libc/amd64/gen/rfork_thread.S index a3c64fad7994..a70551631f1b 100644 --- a/lib/libc/amd64/gen/rfork_thread.S +++ b/lib/libc/amd64/gen/rfork_thread.S @@ -51,8 +51,7 @@ ENTRY(rfork_thread) /* * Prepare and execute the thread creation syscall */ - movq $SYS_rfork, %rax - KERNCALL + _SYSCALL(rfork) jb 2f /* @@ -78,8 +77,7 @@ ENTRY(rfork_thread) /* * Exit system call */ - movq $SYS_exit, %rax - KERNCALL + _SYSCALL(exit) /* * Branch here if the thread creation fails: diff --git a/lib/libc/amd64/sys/getcontext.S b/lib/libc/amd64/sys/getcontext.S index 6860a3cf9bef..c3a856c879f8 100644 --- a/lib/libc/amd64/sys/getcontext.S +++ b/lib/libc/amd64/sys/getcontext.S @@ -36,8 +36,7 @@ WEAK_REFERENCE(__sys_getcontext, getcontext) ENTRY(__sys_getcontext) movq (%rsp),%rsi /* save getcontext return address */ - mov $SYS_getcontext,%rax - KERNCALL + _SYSCALL(getcontext) jb HIDENAME(cerror) addq $8,%rsp /* remove stale (setcontext) return address */ jmp *%rsi /* restore return address */ diff --git a/lib/libc/amd64/sys/vfork.S b/lib/libc/amd64/sys/vfork.S index 3714a742bc15..e3c5f701dcff 100644 --- a/lib/libc/amd64/sys/vfork.S +++ b/lib/libc/amd64/sys/vfork.S @@ -37,8 +37,7 @@ WEAK_REFERENCE(__sys_vfork, vfork) ENTRY(__sys_vfork) popq %rsi /* fetch return address (%rsi preserved) */ - mov $SYS_vfork,%rax - KERNCALL + _SYSCALL(vfork) jb 1f jmp *%rsi 1: diff --git a/lib/libc/i386/SYS.h b/lib/libc/i386/SYS.h index 24b0060372f8..292b705f80f2 100644 --- a/lib/libc/i386/SYS.h +++ b/lib/libc/i386/SYS.h @@ -35,17 +35,22 @@ #include <sys/syscall.h> #include <machine/asm.h> +#define _SYSCALL(name) \ + mov $SYS_##name, %eax; \ + int $0x80 + +#define _SYSCALL_BODY(name) \ + _SYSCALL(name); \ + jb HIDENAME(cerror); \ + ret + #define RSYSCALL(name) ENTRY(__sys_##name); \ WEAK_REFERENCE(__sys_##name, name); \ WEAK_REFERENCE(__sys_##name, _##name); \ - mov $SYS_##name,%eax; KERNCALL; \ - jb HIDENAME(cerror); \ - ret; END(__sys_##name) + _SYSCALL_BODY(name); \ + END(__sys_##name) #define PSEUDO(name) ENTRY(__sys_##name); \ WEAK_REFERENCE(__sys_##name, _##name); \ - mov $SYS_##name,%eax; KERNCALL; \ - jb HIDENAME(cerror); ret; \ + _SYSCALL_BODY(name); \ END(__sys_##name) - -#define KERNCALL int $0x80 diff --git a/lib/libc/i386/gen/rfork_thread.S b/lib/libc/i386/gen/rfork_thread.S index e4d3b904d523..b37f16c930e8 100644 --- a/lib/libc/i386/gen/rfork_thread.S +++ b/lib/libc/i386/gen/rfork_thread.S @@ -64,8 +64,7 @@ ENTRY(rfork_thread) */ pushl 8(%ebp) pushl $0 - movl $SYS_rfork, %eax - KERNCALL + _SYSCALL(rfork) jb 2f /* @@ -96,8 +95,7 @@ ENTRY(rfork_thread) */ pushl %eax pushl $0 - movl $SYS_exit, %eax - KERNCALL + _SYSCALL(exit) /* * Branch here if the thread creation fails: diff --git a/lib/libc/i386/sys/getcontext.S b/lib/libc/i386/sys/getcontext.S index 8baf0caf18fd..d6b5dcd58669 100644 --- a/lib/libc/i386/sys/getcontext.S +++ b/lib/libc/i386/sys/getcontext.S @@ -36,8 +36,7 @@ WEAK_REFERENCE(__sys_getcontext, getcontext) ENTRY(__sys_getcontext) movl (%esp),%ecx /* save getcontext return address */ - mov $SYS_getcontext,%eax - KERNCALL + _SYSCALL(getcontext) jb HIDENAME(cerror) addl $4,%esp /* remove stale (setcontext) return address */ jmp *%ecx /* restore return address */ diff --git a/lib/libc/i386/sys/syscall.S b/lib/libc/i386/sys/syscall.S index 6e9f8e587258..9eaf193c1d7a 100644 --- a/lib/libc/i386/sys/syscall.S +++ b/lib/libc/i386/sys/syscall.S @@ -37,7 +37,7 @@ ENTRY(syscall) pop %ecx /* rta */ pop %eax /* syscall number */ push %ecx - KERNCALL + int $0x80 push %ecx /* need to push a word to keep stack frame intact upon return; the word must be the return address. */ jb HIDENAME(cerror) diff --git a/lib/libc/i386/sys/vfork.S b/lib/libc/i386/sys/vfork.S index b96f3d18c950..3399b8b752de 100644 --- a/lib/libc/i386/sys/vfork.S +++ b/lib/libc/i386/sys/vfork.S @@ -37,8 +37,7 @@ WEAK_REFERENCE(__sys_vfork, vfork) ENTRY(__sys_vfork) popl %ecx /* my rta into ecx */ - mov $SYS_vfork,%eax - KERNCALL + _SYSCALL(vfork) jb 1f jmp *%ecx 1: