NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-sh3/49597: swapcontext(3) stack pointer problem on NetBSD/sh3



The following reply was made to PR port-sh3/49597; it has been noted by GNATS.

From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: port-sh3/49597: swapcontext(3) stack pointer problem on NetBSD/sh3
Date: Sun, 25 Jan 2015 06:39:09 +0300

 Thanks, I have applied the patch.  But it's got me thinking... We are
 tweaking oucp to resume "returning" from swapcontext, but we have
 already clobbered r12 and pr before/by calling getcontext, so oucp
 will get resumed with wrong r12 and pr values.  It probably goes
 undetected since the caller saves and restores pr itself (since it
 calls swapcontext at least) and since r12 is not used because the test
 is not in a DSO.
 
 So what about something like:
 
 ENTRY(swapcontext)
 	PIC_PROLOGUE(.L_got)
 	sts.l	pr, @-sp
 
 	mov.l	.L__getcontext, r0
 	mov.l	r5, @-sp
 1:	CALL	r0			! _getcontext(oucp)
 	 mov.l	r4, @-sp
 	!! getcontext captures oucp resuming here with r12 (when PIC),
 	!! pr, r5 and r4 pushed onto the stack
 
 	tst	r0, r0
 	bf.s	3f			! return error from getcontext
 	 mov.l	@sp, r1			! saved oucp
 
 	!! adjust oucp to resume after setcontext below
 	mova	3f, r0
 	mov.l	r0, @(36 + 1 * 4, r1)	! _UC_MACHINE_SET_PC(oucp, pr)
 
 	mov.l	.L_setcontext, r2
 2:	CALL	r2			! setcontext(ucp)
 	 mov.l	@(4, sp), r4		! saved ucp
 
 	.align	2
 3:	!! we get here on errors and when resuming oucp
 	add	#8, sp			! skip r4 and r5
 	lds.l	@sp+, pr
 	rts
 	 PIC_EPILOGUE_SLOT
 
 though I haven't tested error legs.
 
 -uwe
 


Home | Main Index | Thread Index | Old Index