public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Stefan Liebler <stli@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] s390: Set psw addr field in getcontext and friends. Date: Tue, 19 Dec 2023 10:01:59 +0000 (GMT) [thread overview] Message-ID: <20231219100159.670523858417@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=664f565f9caa26bb128bad7d7050cf0f0b9c6322 commit 664f565f9caa26bb128bad7d7050cf0f0b9c6322 Author: Stefan Liebler <stli@linux.ibm.com> Date: Fri Dec 15 09:26:40 2023 +0100 s390: Set psw addr field in getcontext and friends. So far if the ucontext structure was obtained by getcontext and co, the return address was stored in general purpose register 14 as it is defined as return address in the ABI. In contrast, the context passed to a signal handler contains the address in psw.addr field. If somebody e.g. wants to dump the address of the context, the origin needs to be known. Now this patch adjusts getcontext and friends and stores the return address also in psw.addr field. Note that setcontext isn't adjusted and it is not supported to pass a ucontext structure from signal-handler to setcontext. We are not able to restore all registers and branching to psw.addr without clobbering one register. Diff: --- sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S | 6 ++++++ sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c | 5 +++++ sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S | 6 ++++++ sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S | 6 ++++++ sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c | 5 +++++ sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S | 6 ++++++ 6 files changed, 34 insertions(+) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S b/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S index 8bef183fed..de969dd990 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S @@ -71,6 +71,12 @@ ENTRY(__getcontext) /* Store general purpose registers. */ stm %r0,%r15,SC_GPRS(%r1) + /* Store psw mask to 0x0 and addr to return address. Then the address + can be retrieved from the ucontext structure in the same way as if it + is created by kernel and passed to a signal-handler. */ + st %r2,SC_PSW+0(%r1) + st %r14,SC_PSW+4(%r1) + /* Return. */ br %r14 END(__getcontext) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c b/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c index 1f35ffa5eb..6458ca5f3d 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c @@ -60,6 +60,11 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) /* Set the return address to trampoline. */ ucp->uc_mcontext.gregs[14] = (long int) __makecontext_ret; + /* Store psw mask to 0x0 and addr to trampoline. Then the address + can be retrieved from the ucontext structure in the same way as if it + is created by kernel and passed to a signal-handler. */ + ucp->uc_mcontext.psw.addr = (long int) __makecontext_ret; + ucp->uc_mcontext.psw.mask = 0; /* Set register parameters. */ va_start (ap, argc); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S b/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S index b3f2a8b344..ccf4d7a935 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S @@ -66,6 +66,12 @@ ENTRY(__swapcontext) /* Store general purpose registers. */ stm %r0,%r15,SC_GPRS(%r1) + /* Store psw mask to 0x0 and addr to return address. Then the address + can be retrieved from the ucontext structure in the same way as if it + is created by kernel and passed to a signal-handler. */ + st %r2,SC_PSW+0(%r1) + st %r14,SC_PSW+4(%r1) + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, sigsetsize). */ la %r2,SIG_SETMASK diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S b/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S index bda313cb23..683f8bb985 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S @@ -71,6 +71,12 @@ ENTRY(__getcontext) /* Store general purpose registers. */ stmg %r0,%r15,SC_GPRS(%r1) + /* Store psw mask to 0x0 and addr to return address. Then the address + can be retrieved from the ucontext structure in the same way as if it + is created by kernel and passed to a signal-handler. */ + stg %r2,SC_PSW+0(%r1) + stg %r14,SC_PSW+8(%r1) + /* Return. */ br %r14 END(__getcontext) diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c b/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c index 1dc1af8dc9..b69ff5a136 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c +++ b/sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c @@ -60,6 +60,11 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) /* Set the return address to trampoline. */ ucp->uc_mcontext.gregs[14] = (long int) __makecontext_ret; + /* Store psw mask to 0x0 and addr to trampoline. Then the address + can be retrieved from the ucontext structure in the same way as if it + is created by kernel and passed to a signal-handler. */ + ucp->uc_mcontext.psw.addr = (long int) __makecontext_ret; + ucp->uc_mcontext.psw.mask = 0; /* Set register parameters. */ va_start (ap, argc); diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S b/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S index eaa4f3ba19..4bf85c152c 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S @@ -66,6 +66,12 @@ ENTRY(__swapcontext) /* Store general purpose registers. */ stmg %r0,%r15,SC_GPRS(%r1) + /* Store psw mask to 0x0 and addr to return address. Then the address + can be retrieved from the ucontext structure in the same way as if it + is created by kernel and passed to a signal-handler. */ + stg %r2,SC_PSW+0(%r1) + stg %r14,SC_PSW+8(%r1) + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, sigsetsize). */ la %r2,SIG_SETMASK
reply other threads:[~2023-12-19 10:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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 \ --in-reply-to=20231219100159.670523858417@sourceware.org \ --to=stli@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /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: linkBe 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; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).