Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Jul 2001 10:50:01 -0400 (EDT)
From:      Daniel Eischen <eischen@vigrid.com>
To:        Arun Sharma <arun@sharmas.dhs.org>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: libc_r, signals and modifying sigcontext
Message-ID:  <Pine.SUN.3.91.1010722104801.559A-100000@pcnet1.pcnet.com>
In-Reply-To: <20010721191747.A32529@sharmas.dhs.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.1010722104801.559A-100000>