From nobody Mon Dec 18 22:28:59 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SvDy36Klkz54BfN; Mon, 18 Dec 2023 22:28:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SvDy31twDz4cD8; Mon, 18 Dec 2023 22:28:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702938539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nL3ndP0Zlq8owU6FKQgVXXmgAO46lAbQrik2/qxexmw=; b=dR8EzIzXIUbJSerU/0TgRwDmQzBi9d0IakeJjB3woCRXwlOuIxarlAzp/v3aogYR9L8sLC NtVuKiv9DcTB3DCENzb4iKiAs9sbPjtvp1Q5PqhBBUT8ouXAj4tye6Mkbslj9h2kr/07rz 7l7Q1EwryhgR9cUq4sqU1dgrlohu8ZNjuYpjMtFQt1m9+1cv4VYjBQ9MYbLFXPiisFKG3o x15XaHa5od32npjuKBsnV2v7SSK0wk8Asqe5Qw1tLixWepyo3Iqm3ldpXqSTcFC/mxKO/3 aZVeNU4R2EDGjlKywR/IHO0NgMtcDa24x9xB6EZwmlyU5EW8e9AW3XiT7NgK4Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702938539; a=rsa-sha256; cv=none; b=oxxhZSz1MVcFUTcWzHUkLRvTcgSpVvZsH+xGDGCEjIXnIlQvnmp6ZCFxAM/U+VP1RdXKGc p+GNMLorxVuHA4BaK7cUmfhoZrEh5/CaUyJLqOftn+sdCGUWBhEB5RhPu2IVEDyQUiDED4 FuV5fLPawBJR1GXNKZl/SRlg6odiY3eFTe5B6M2kJkUQOrzoDKh7Tzu+8e1tAUt5QP19Tp u+r0HuzfPNoAamPbN7nPkzL+ub9D4lJEjQoamCCpfkg6ywRWYQorlaU1/xvC/Us5rGR1t9 LycHxAFoGShE2ic5X9lVJoScmLs7lEQSP3pkI5IHNZJPxI8H5wEv3lW4AjBV/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702938539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nL3ndP0Zlq8owU6FKQgVXXmgAO46lAbQrik2/qxexmw=; b=km5Ok5Ix9OpsH2hgLZESd6+EzoaNeDIcV0nv4PsJsbrV6bsmRvj9GBZiQkdwnWf6pi/Mla XWtb0v8RkaUKEAMwf/w+Xs4elAArD//C3aFAF7jClchUctbkaYzmsVcIaIw0ed82IAjMSf uqqBw5Ol/i6I+aDK1hdGdcmnae5+u93Jcm1xZuBf+vNZBD72gQTgs9EBck7Whu2jR417WB pCmH6AK0eg4ICcVvVm8J+QU6wYd/Y+3a+Ori4Eg+WOi9ioT8uulmDKBcx4FlPyrJuLyvTM Myo+HEr6zdwhZyg39NkAcwdupXBFwgVBPTDrHiZVFg9n7nC9If3BDse1mvGTIA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SvDy30xzKzdvr; Mon, 18 Dec 2023 22:28:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BIMSxig007890; Mon, 18 Dec 2023 22:28:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BIMSxHY007887; Mon, 18 Dec 2023 22:28:59 GMT (envelope-from git) Date: Mon, 18 Dec 2023 22:28:59 GMT Message-Id: <202312182228.3BIMSxHY007887@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 8f465f509bc1 - main - {amd64,i386}/SYS.h: add _SYSCALL and _SYSCALL_BODY List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8f465f509bc1b038806963f716263b56004871d3 Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=8f465f509bc1b038806963f716263b56004871d3 commit 8f465f509bc1b038806963f716263b56004871d3 Author: Brooks Davis AuthorDate: 2023-12-18 22:28:42 +0000 Commit: Brooks Davis 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 #include +#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 #include +#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: