]> sourceware.org Git - glibc.git/commitdiff
s390: Set psw addr field in getcontext and friends.
authorStefan Liebler <stli@linux.ibm.com>
Fri, 15 Dec 2023 08:26:40 +0000 (09:26 +0100)
committerStefan Liebler <stli@linux.ibm.com>
Tue, 19 Dec 2023 10:00:19 +0000 (11:00 +0100)
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.

sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S
sysdeps/unix/sysv/linux/s390/s390-32/makecontext.c
sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S
sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S
sysdeps/unix/sysv/linux/s390/s390-64/makecontext.c
sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S

index 8bef183fede4bbbfd63d1b8db64d2061529d8440..de969dd9909ae642d1e825a397aa2a1fb642091c 100644 (file)
@@ -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)
index 1f35ffa5ebcf11ff65443a0b919c11a24959ae33..6458ca5f3d256550657fa57918ad9312ca9c3b66 100644 (file)
@@ -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);
index b3f2a8b3446da82e84c6783cf55d7ded75b9ef6f..ccf4d7a935c56b09e1332d83735d081291f06288 100644 (file)
@@ -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
index bda313cb230096e22d9d33dd8e8620c2fb333d05..683f8bb98579029a647c8295a6accb58b4af35e7 100644 (file)
@@ -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)
index 1dc1af8dc9074d072dce7a58b0cdece99e0589b5..b69ff5a136e3ddd829b794121eade43770df461a 100644 (file)
@@ -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);
index eaa4f3ba195832cf36ecf0ff151fa15bdb304188..4bf85c152c9be2b46ab5e48ab45801d7591b1c7b 100644 (file)
@@ -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
This page took 0.050668 seconds and 5 git commands to generate.