From owner-freebsd-hackers Sun Jul 22 7:50:50 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from pcnet1.pcnet.com (pcnet1.pcnet.com [204.213.232.3]) by hub.freebsd.org (Postfix) with ESMTP id 0722037B405 for ; Sun, 22 Jul 2001 07:50:47 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: (from eischen@localhost) by pcnet1.pcnet.com (8.8.7/PCNet) id KAA00828; Sun, 22 Jul 2001 10:50:02 -0400 (EDT) Date: Sun, 22 Jul 2001 10:50:01 -0400 (EDT) From: Daniel Eischen To: Arun Sharma Cc: hackers@FreeBSD.ORG Subject: Re: libc_r, signals and modifying sigcontext In-Reply-To: <20010721191747.A32529@sharmas.dhs.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sat, 21 Jul 2001, Arun Sharma wrote: > Greetings. I'm trying to port an application to FreeBSD. I have > a signal handler registered using signal(2). It modifies the > data pointed to by the third argument - of type sigcontext (specifically > sc_eip) - so that the execution would resume at a different point). > > However, when execution resumes, it resumes at the same point where > it was interrupted. A quick search of the archives brought up this > thread: > > http://groups.google.com/groups?hl=en&safe=off&th=6d5b8c3ead4a79ab,5&seekm=9fo8vq%241ma8%241%40FreeBSD.csie.NCTU.edu.tw#p > > I tried: > > _thread_sys_sigreturn(sc); > > as suggested, but truss shows that sigreturn is failing. So my question > is: what is the correct way to modify the sigcontext in FreeBSD ? Are > there other multi threaded apps (using pthreads, linked to libc_r), > which do this ? Try this patch: -- Dan Eischen Index: uthread/pthread_private.h =================================================================== RCS file: /opt/b/CVS/src/lib/libc_r/uthread/pthread_private.h,v retrieving revision 1.59 diff -u -r1.59 pthread_private.h --- uthread/pthread_private.h 2001/07/20 04:23:10 1.59 +++ uthread/pthread_private.h 2001/07/22 04:29:10 @@ -654,6 +654,7 @@ int sig_has_args; /* use signal args if true */ ucontext_t uc; siginfo_t siginfo; + int restore_context; }; /* Index: uthread/uthread_sig.c =================================================================== RCS file: /opt/b/CVS/src/lib/libc_r/uthread/uthread_sig.c,v retrieving revision 1.38 diff -u -r1.38 uthread_sig.c --- uthread/uthread_sig.c 2001/06/29 17:09:07 1.38 +++ uthread/uthread_sig.c 2001/07/22 04:28:02 @@ -1004,6 +1004,10 @@ else (*(sigfunc))(psf->signo, (siginfo_t *)psf->siginfo.si_code, &psf->uc); + if (psf->restore_context != 0) { + memcpy(&thread->ctx.uc, &psf->uc, sizeof(psf->uc)); + thread->ctxtype = CTX_UC; + } } /* * Call the kernel scheduler to safely restore the frame and @@ -1046,6 +1050,7 @@ stackp -= sizeof(struct pthread_signal_frame); psf = (struct pthread_signal_frame *) stackp; + psf->restore_context = 0; /* Save the current context in the signal frame: */ thread_sigframe_save(thread, psf); @@ -1059,6 +1064,8 @@ sizeof(psf->uc)); memcpy(&psf->siginfo, &_thread_sigq[psf->signo - 1].siginfo, sizeof(psf->siginfo)); + psf->restore_context = ((thread == _get_curthread()) && + (thread->ctxtype == CTX_UC)); } /* Setup the signal mask: */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message