From 46ef072377bf995fcbd20191d6ea9b8e41e2499d Mon Sep 17 00:00:00 2001 From: skrll Date: Wed, 21 Sep 2016 06:49:39 +0000 Subject: [PATCH] Fix for [on]{32,64} /usr/tests/lib/libc/sys/t_getcontext /usr/tests/lib/libc/sys/t_swapcontext /usr/tests/lib/libc/sys/t_ucontext /usr/tests/lib/libpthread/t_swapcontext All pass now. Changes amount to - saving GP from caller in context for n{32,64} - performing (the equivalient of) PIC_PROLOGUE for swapcontext and __resumecontext - Call setcontext via the PLT in __resumecontext --- lib/libc/arch/mips/gen/_resumecontext.S | 27 +++++++++++++++++++++---- lib/libc/arch/mips/gen/swapcontext.S | 9 +++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/libc/arch/mips/gen/_resumecontext.S b/lib/libc/arch/mips/gen/_resumecontext.S index 7194deb57288..1eb92002f0ec 100644 --- a/lib/libc/arch/mips/gen/_resumecontext.S +++ b/lib/libc/arch/mips/gen/_resumecontext.S @@ -1,4 +1,4 @@ -/* $NetBSD: _resumecontext.S,v 1.10 2016/08/13 08:09:17 skrll Exp $ */ +/* $NetBSD: _resumecontext.S,v 1.11 2016/09/21 06:49:39 skrll Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include "assym.h" #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: _resumecontext.S,v 1.10 2016/08/13 08:09:17 skrll Exp $") + RCSID("$NetBSD: _resumecontext.S,v 1.11 2016/09/21 06:49:39 skrll Exp $") #endif /* SYSLIBC_SCCS && !lint */ .set reorder @@ -44,17 +44,36 @@ LEAF_NOPROFILE(__resumecontext) /* * We get here not by a call through $t9 but thru $ra after the - * function passed to makecontext returns. + * function passed to makecontext returns. Therefore, we need + * to recover gp from ra */ +#if defined(__mips_o32) || defined(__mips_o64) + .set push + .set noreorder + .cpload ra + .set pop +#endif +#if defined(__mips_n32) || defined(__mips_n64) + .cpsetup ra, t3, __resumecontext +#endif + PTR_SUBU sp, sp, UCONTEXT_SIZE # get space for ucontext move a0, sp # arg0 for getcontext PTR_S zero, _OFFSETOF_UC_LINK(a0) # make sure uc_link is 0 SYSTRAP(getcontext) # get context + +#if defined(__mips_n32) || defined(__mips_n64) + REG_PROLOGUE + /* We saved gp in t2 above */ + REG_S t3, _OFFSETOF_UC_GREGS_GP(a0) + REG_EPILOGUE +#endif + PTR_L a0, _OFFSETOF_UC_LINK(a0) # linked context? NOP_L beq a0, zero, 1f # nope, exit process nop - SYSTRAP(setcontext) # yes, become it. + PIC_TAILCALL(setcontext) # yes, become it. /* NOTREACHED (in theory) */ li a0, -1 # failure, 1: diff --git a/lib/libc/arch/mips/gen/swapcontext.S b/lib/libc/arch/mips/gen/swapcontext.S index 11d02e9e48e3..45abfec1063d 100644 --- a/lib/libc/arch/mips/gen/swapcontext.S +++ b/lib/libc/arch/mips/gen/swapcontext.S @@ -1,4 +1,4 @@ -/* $NetBSD: swapcontext.S,v 1.6 2016/09/21 06:41:42 skrll Exp $ */ +/* $NetBSD: swapcontext.S,v 1.7 2016/09/21 06:49:39 skrll Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -33,13 +33,14 @@ #include "assym.h" #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: swapcontext.S,v 1.6 2016/09/21 06:41:42 skrll Exp $") + RCSID("$NetBSD: swapcontext.S,v 1.7 2016/09/21 06:49:39 skrll Exp $") #endif /* SYSLIBC_SCCS && !lint */ .set reorder NESTED(swapcontext, CALLFRAME_SIZ, ra) .mask 0x80000030, (CALLFRAME_RA - CALLFRAME_SIZ) + PIC_PROLOGUE(swapcontext) PTR_SUBU sp, sp, CALLFRAME_SIZ PTR_S ra, CALLFRAME_RA(sp) # save ra PTR_S a0, 0(sp) # stash away oucp @@ -53,6 +54,10 @@ NESTED(swapcontext, CALLFRAME_SIZ, ra) PTR_ADDIU v0, sp, CALLFRAME_SIZ REG_PROLOGUE REG_S zero, _OFFSETOF_UC_GREGS_V0(v1) +#if defined(__mips_n32) || defined(__mips_n64) + /* PIC_PROLOGUE saved gp in t3 */ + REG_S t3, _OFFSETOF_UC_GREGS_GP(v1) +#endif REG_S ra, _OFFSETOF_UC_GREGS_EPC(v1) REG_S v0, _OFFSETOF_UC_GREGS_SP(v1) REG_EPILOGUE