From owner-freebsd-arch Sat Feb 16 12:20:23 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mail.pcnet.com (pcnet1.pcnet.com [204.213.232.3]) by hub.freebsd.org (Postfix) with ESMTP id 04A5F37B400 for ; Sat, 16 Feb 2002 12:20:14 -0800 (PST) Received: from vigrid.com (pm3-pt39.pcnet.net [206.105.29.113]) by mail.pcnet.com (8.12.1/8.12.1) with ESMTP id g1GKK7oS018962; Sat, 16 Feb 2002 15:20:08 -0500 (EST) Message-ID: <3C6EC0A2.419FDA74@vigrid.com> Date: Sat, 16 Feb 2002 15:27:14 -0500 From: Dan Eischen X-Mailer: Mozilla 4.74 [en] (X11; U; FreeBSD 5.0-CURRENT i386) X-Accept-Language: en MIME-Version: 1.0 To: Matthew Dillon Cc: Peter Wemm , arch@FreeBSD.ORG Subject: Re: MFC makecontext(), getcontext(), setcontext()?, also would be nice to have some cleanups References: <20020206195918.6350039F1@overcee.wemm.org> <200202161842.g1GIgFF89658@apollo.backplane.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Matthew Dillon wrote: > > It would be nice if getcontext() and setcontext() could be told > not to screw around with the signal mask, similar to what sigsetjmp() > and siglongjmp() do if the savemask is empty. Perhaps something like > this: > [...] > (make same change in both setcontext() and getcontext()) > > This way these calls could be used to replace the alternate signal > stack, sigsetjmp()/setlongjmp() junk that has to be done now in > roll-your-own threads systems. Yeah, I originally thought about also making _getcontext and _setcontext, similar to _setjmp/_longjmp which don't change the signal mask. The current implementation of these functions in libc will be replaced with a system call as soon as I incorporate bde's comments wrt FPU state handling. They simply become: .weak CNAME(getcontext) .set CNAME(getcontext),CNAME(__getcontext) ENTRY(__getcontext) popl %ecx /* save return address */ movl 0(%esp), %eax /* get ucp */ pushl $0 /* NULL */ pushl %eax /* ucp */ pushl $0 /* leave slot for return address */ movl $SYS_getsetcontext, %eax KERNCALL addl $8, %esp movl %ecx, 0(%esp) /* return to address saved in %ecx */ jb 1f xorl %eax, %eax /* always returns 0 upon success */ ret 1: PIC_PROLOGUE jmp PIC_PLT(HIDENAME(cerror)) and similar for setcontext and swapcontext. We do need the something similar to the current implementation for the threads library though. For KSE threads, we may actually need to know when XXX_setcontext() is done so we can clear an "in scheduler" or "context in use" flag. I was just going to add these functions to the threads library, but perhaps we can find something that isn't just useful for the threads library. I was thinking along the lines of: _thr_setcontext(const ucontext_t *ucp, long *done) We can do away with "done" in the threads library, but it would probably mean copying an interrupted context before resuming it (so the context doesn't get clobbered if the thread gets interrupted in the middle of resuming it). -- Dan Eischen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message