Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 May 2023 14:07:48 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 037b60fb0fbc - main - linux(4): Preserve %rcx (return address) like a Linux do
Message-ID:  <202305281407.34SE7mSc067238@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=037b60fb0fbcb2dd6b6cbb632b05a2939ff4ff29

commit 037b60fb0fbcb2dd6b6cbb632b05a2939ff4ff29
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-05-28 14:06:47 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-05-28 14:06:47 +0000

    linux(4): Preserve %rcx (return address) like a Linux do
    
    Perhaps, this does not makes much sense as destroyng %rcx declared by
    the x86_64 Linux syscall ABI. However,:
    a) if we get a signal while we are in the kernel, we should restore
       tf_rcx when preparing machine context for signal handlers.
    b) the Linux world is strange, someone can depend on %rcx value
       after syscall, something like go.
    
    Differential Revision:  https://reviews.freebsd.org/D40155
    MFC after:              1 month
---
 sys/amd64/linux/linux_sysvec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index 422cfbe7c5ba..05afcdfcd045 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -169,6 +169,8 @@ linux_fetch_syscall_args(struct thread *td)
 
 	/* Restore r10 earlier to avoid doing this multiply times. */
 	frame->tf_r10 = frame->tf_rcx;
+	/* Restore %rcx for machine context. */
+	frame->tf_rcx = frame->tf_rip;
 
 	td->td_retval[0] = 0;
 	return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202305281407.34SE7mSc067238>