From patchwork Fri Mar 24 06:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: caiyinyu X-Patchwork-Id: 66831 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4622C3881D34 for ; Fri, 24 Mar 2023 06:25:30 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 3A0E638708C6 for ; Fri, 24 Mar 2023 06:25:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A0E638708C6 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.5]) by gateway (Coremail) with SMTP id _____8AxYcxIQh1klZ0QAA--.25373S3; Fri, 24 Mar 2023 14:25:12 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx97xHQh1kdvcKAA--.2781S2; Fri, 24 Mar 2023 14:25:11 +0800 (CST) From: caiyinyu To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, xry111@xry111.site, caiyinyu Subject: [PATCH] LoongArch: Modify some member names in mcontext_t and ucontext_t structs to align them with the kernel. Date: Fri, 24 Mar 2023 14:25:10 +0800 Message-Id: <20230324062510.1812367-1-caiyinyu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cx97xHQh1kdvcKAA--.2781S2 X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Gr15WF4kur18XF13XF1DKFg_yoWxJr4xpF 4Y93W8AF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STATUS, SPF_HELO_PASS, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" During the construction of the LoongArch Alpine system, we found that there is an inconsistency in the member names of mcontext_t and ucontext_t between musl and glibc, which can cause compilation errors. After testing, we have decided to modify some member names. This patch will be backported to glibc versions 2.36 and 2.37. Reference: 4fa9b3bfe6759c82beb4b043a54a3598ca467289 --- .../unix/sysv/linux/loongarch/makecontext.c | 26 +++++++++---------- .../sysv/linux/loongarch/sigcontextinfo.h | 2 +- .../unix/sysv/linux/loongarch/sys/ucontext.h | 17 ++++++++---- .../unix/sysv/linux/loongarch/ucontext_i.sym | 6 ++--- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/sysdeps/unix/sysv/linux/loongarch/makecontext.c b/sysdeps/unix/sysv/linux/loongarch/makecontext.c index a17f6ccc51..153be5a680 100644 --- a/sysdeps/unix/sysv/linux/loongarch/makecontext.c +++ b/sysdeps/unix/sysv/linux/loongarch/makecontext.c @@ -41,19 +41,19 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int argc, long int a0, ra = s0 = 0, terminating the stack for backtracing purposes. s1 = the function we must call. s2 = the subsequent context to run. */ - ucp->uc_mcontext.__gregs[LARCH_REG_RA] = (uintptr_t) 0; - ucp->uc_mcontext.__gregs[LARCH_REG_S0] = (uintptr_t) 0; - ucp->uc_mcontext.__gregs[LARCH_REG_S1] = (uintptr_t) func; - ucp->uc_mcontext.__gregs[LARCH_REG_S2] = (uintptr_t) ucp->uc_link; - ucp->uc_mcontext.__gregs[LARCH_REG_SP] = (uintptr_t) sp; - ucp->uc_mcontext.__pc = (uintptr_t) &__start_context; + ucp->uc_mcontext.sc_regs[LARCH_REG_RA] = (uintptr_t) 0; + ucp->uc_mcontext.sc_regs[LARCH_REG_S0] = (uintptr_t) 0; + ucp->uc_mcontext.sc_regs[LARCH_REG_S1] = (uintptr_t) func; + ucp->uc_mcontext.sc_regs[LARCH_REG_S2] = (uintptr_t) ucp->uc_link; + ucp->uc_mcontext.sc_regs[LARCH_REG_SP] = (uintptr_t) sp; + ucp->uc_mcontext.sc_pc = (uintptr_t) &__start_context; /* Put args in a0-a7, then put any remaining args on the stack. */ - ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 0] = (uintptr_t) a0; - ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 1] = (uintptr_t) a1; - ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 2] = (uintptr_t) a2; - ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 3] = (uintptr_t) a3; - ucp->uc_mcontext.__gregs[LARCH_REG_A0 + 4] = (uintptr_t) a4; + ucp->uc_mcontext.sc_regs[LARCH_REG_A0 + 0] = (uintptr_t) a0; + ucp->uc_mcontext.sc_regs[LARCH_REG_A0 + 1] = (uintptr_t) a1; + ucp->uc_mcontext.sc_regs[LARCH_REG_A0 + 2] = (uintptr_t) a2; + ucp->uc_mcontext.sc_regs[LARCH_REG_A0 + 3] = (uintptr_t) a3; + ucp->uc_mcontext.sc_regs[LARCH_REG_A0 + 4] = (uintptr_t) a4; if (__glibc_unlikely (argc > 5)) { @@ -62,14 +62,14 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int argc, long int a0, long int reg_args = argc < LARCH_REG_NARGS ? argc : LARCH_REG_NARGS; for (long int i = 5; i < reg_args; i++) - ucp->uc_mcontext.__gregs[LARCH_REG_A0 + i] = va_arg (vl, unsigned long int); + ucp->uc_mcontext.sc_regs[LARCH_REG_A0 + i] = va_arg (vl, unsigned long int); long int stack_args = argc - reg_args; if (stack_args > 0) { sp = (unsigned long int *) (((uintptr_t) sp - stack_args * sizeof (long int)) & ALMASK); - ucp->uc_mcontext.__gregs[LARCH_REG_SP] = (uintptr_t) sp; + ucp->uc_mcontext.sc_regs[LARCH_REG_SP] = (uintptr_t) sp; for (long int i = 0; i < stack_args; i++) sp[i] = va_arg (vl, unsigned long int); } diff --git a/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h b/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h index 4cfb87da76..3d6fe08e57 100644 --- a/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h +++ b/sysdeps/unix/sysv/linux/loongarch/sigcontextinfo.h @@ -26,7 +26,7 @@ static inline uintptr_t sigcontext_get_pc (const ucontext_t *ctx) { - return ctx->uc_mcontext.__pc; + return ctx->uc_mcontext.sc_pc; } #endif diff --git a/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h b/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h index 8790265e74..f2af4f5abf 100644 --- a/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h +++ b/sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h @@ -43,18 +43,25 @@ typedef unsigned long int greg_t; typedef greg_t gregset_t[32]; #endif +#ifdef __USE_MISC +# define __ctx(fld) fld +#else +# define __ctx(fld) __ ## fld +#endif + + typedef struct mcontext_t { - unsigned long long __pc; - unsigned long long __gregs[32]; - unsigned int __flags; - unsigned long long __extcontext[0] __attribute__((__aligned__(16))); + unsigned long long __ctx(sc_pc); + unsigned long long __ctx(sc_regs)[32]; + unsigned int __ctx(sc_flags); + unsigned long long __ctx(sc_extcontext)[0] __attribute__((__aligned__(16))); } mcontext_t; /* Userlevel context. */ typedef struct ucontext_t { - unsigned long int __uc_flags; + unsigned long int __ctx(uc_flags); struct ucontext_t *uc_link; stack_t uc_stack; sigset_t uc_sigmask; diff --git a/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym b/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym index f27afad56f..dfe5199542 100644 --- a/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym +++ b/sysdeps/unix/sysv/linux/loongarch/ucontext_i.sym @@ -15,7 +15,7 @@ _NSIG8 (_NSIG / 8) #define stack(member) ucontext (uc_stack.member) #define mcontext(member) ucontext (uc_mcontext.member) -UCONTEXT_FLAGS ucontext (__uc_flags) +UCONTEXT_FLAGS ucontext (uc_flags) UCONTEXT_LINK ucontext (uc_link) UCONTEXT_STACK ucontext (uc_stack) UCONTEXT_MCONTEXT ucontext (uc_mcontext) @@ -25,7 +25,7 @@ STACK_SP stack (ss_sp) STACK_SIZE stack (ss_size) STACK_FLAGS stack (ss_flags) -MCONTEXT_PC mcontext (__pc) -MCONTEXT_GREGS mcontext (__gregs) +MCONTEXT_PC mcontext (sc_pc) +MCONTEXT_GREGS mcontext (sc_regs) UCONTEXT_SIZE sizeof (ucontext_t)