From patchwork Fri Dec 15 08:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 1876513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=cebv1eQ4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Ss2Px4gXvz23nF for ; Fri, 15 Dec 2023 19:27:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 791603847733 for ; Fri, 15 Dec 2023 08:26:58 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id B401A384DEC8 for ; Fri, 15 Dec 2023 08:26:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B401A384DEC8 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B401A384DEC8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702628809; cv=none; b=LXG0hNRNydKB14CNLrD4ew3Qh20CKaXrzgl7EsltlQjGEA73L0VKmIpR1JbKXCunPMRzpIG4Blx3iQ+o6o4jREZosutPvG4zXSYp2/P4YLZmsJLt5qyT63dVDC5whsHIQXCWdbrJMiQ5yFioIUVF5EdXBb1yDx7grlKlnbCXCqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702628809; c=relaxed/simple; bh=bLLYKqj6G4yo9WpSpadKX9kgLA4zm33ma6UuzdI0BRE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MpUvQJ65YybEuFcdOKBtq9V5hlPEFKEwy0qemWJ4RwnUmWWINrlUtxfozrJfiw2BAkENUEB1XSBSz7/430C2Mp5W3aTRfKAscQJBHGIUdxkMMLW9MI5XKRo5dZUT/IsJLKElz+9c/s41kL9RKE1Rna0xMl9RnO01vYsYp6TLmUk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BF8CWkx015863 for ; Fri, 15 Dec 2023 08:26:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=M8ZETPM38Z+PB56KlA3MVA6/VrvASm3+ypU3wxJXQok=; b=cebv1eQ4Q5FcjHhKhsaJtqZxzsi3sDuiwrv0Gze5VN1iGzL9xO4rG4644+OBPlJX3Za+ GsyLDZ85qCD0JgdlEEOtH6vNSaaQX4yk3UNZyxEfq6oCJZWxA/U5kWabv0yln9pdj7xB QfeL4HnCFMc5vp1NDJKVjGjFZRuBkcPSoHtF008spB9PGluSKEshidkGjmWCEWDcPjzi 22b/1YhzyPYr4U9IrllVtYTSK2k3dG7+XUq1hU2YXASM620MnWLYkNoe7yFqeKGRxSm3 folu9yEV8MAPI3mBxiqTBCCvd/zKA62+uNrROlPdi9/IZi4kHemBmh4jQ0TH9WBD34oP aw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3v0k32gbt7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 15 Dec 2023 08:26:46 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BF8Eghx012699 for ; Fri, 15 Dec 2023 08:26:45 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3uw3jperq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 15 Dec 2023 08:26:45 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BF8Qgme23855720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Dec 2023 08:26:42 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 10B4B20043; Fri, 15 Dec 2023 08:26:42 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC57820040; Fri, 15 Dec 2023 08:26:41 +0000 (GMT) Received: from a35lp68.lnxne.boe (unknown [9.152.108.100]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2023 08:26:41 +0000 (GMT) From: Stefan Liebler To: libc-alpha@sourceware.org Cc: Stefan Liebler Subject: [PATCH] s390: Set psw addr field in getcontext and friends. Date: Fri, 15 Dec 2023 09:26:40 +0100 Message-ID: <20231215082640.2088490-1-stli@linux.ibm.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: HCLresRJWk1pJH1HzVhOtZVF0R3dkwWl X-Proofpoint-ORIG-GUID: HCLresRJWk1pJH1HzVhOtZVF0R3dkwWl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-15_04,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=1 mlxscore=1 suspectscore=0 impostorscore=0 clxscore=1015 bulkscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 spamscore=1 malwarescore=0 mlxlogscore=225 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312150054 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org 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 | 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