diff options
author | Brooks Davis <brooks@FreeBSD.org> | 2023-12-18 22:28:42 +0000 |
---|---|---|
committer | Brooks Davis <brooks@FreeBSD.org> | 2023-12-18 22:28:42 +0000 |
commit | 8f465f509bc1b038806963f716263b56004871d3 (patch) | |
tree | ea5a9d7dc22aa5cb775773241f0ba3906b597619 | |
parent | 300bbb3a43e3cc1337b827b72ff5a22c4321a317 (diff) | |
download | src-8f465f509bc1b038806963f716263b56004871d3.tar.gz src-8f465f509bc1b038806963f716263b56004871d3.zip |
{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
-rw-r--r-- | lib/libc/amd64/SYS.h | 18 | ||||
-rw-r--r-- | lib/libc/amd64/gen/rfork_thread.S | 6 | ||||
-rw-r--r-- | lib/libc/amd64/sys/getcontext.S | 3 | ||||
-rw-r--r-- | lib/libc/amd64/sys/vfork.S | 3 | ||||
-rw-r--r-- | lib/libc/i386/SYS.h | 19 | ||||
-rw-r--r-- | lib/libc/i386/gen/rfork_thread.S | 6 | ||||
-rw-r--r-- | lib/libc/i386/sys/getcontext.S | 3 | ||||
-rw-r--r-- | lib/libc/i386/sys/syscall.S | 2 | ||||
-rw-r--r-- | 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: |