All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-core] Handle SIGILL when kernel compiled without Xenomai.
@ 2008-09-21 20:01 Gilles Chanteperdrix
  2008-09-22  8:25 ` Philippe Gerum
  2008-09-22  9:14 ` Jan Kiszka
  0 siblings, 2 replies; 11+ messages in thread
From: Gilles Chanteperdrix @ 2008-09-21 20:01 UTC (permalink / raw)
  To: xenomai-core


Hi,

on some (all ?) platforms, we get a SIGILL when trying to emit the first 
Xenomai syscall, instead of the -ENOSYS return value. This patches 
handles the SIGILL by printing an error message and exiting.

Index: include/asm-generic/bits/bind.h
===================================================================
--- include/asm-generic/bits/bind.h	(revision 4175)
+++ include/asm-generic/bits/bind.h	(working copy)
@@ -9,6 +9,7 @@
 #include <signal.h>
 #include <pthread.h>
 #include <fcntl.h>
+#include <setjmp.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <asm/xenomai/syscall.h>
@@ -17,6 +18,8 @@ __attribute__ ((weak))
 pthread_key_t xeno_current_key;
 __attribute__ ((weak))
 pthread_once_t xeno_init_current_key_once = PTHREAD_ONCE_INIT;
+__attribute__ ((weak))
+jmp_buf xeno_sigill_jmpbuf;
 
 __attribute__ ((weak))
 void xeno_set_current(void)
@@ -99,13 +102,28 @@ static void unmap_sem_heap(unsigned long
 }
 #endif /* CONFIG_XENO_FASTSEM */
 
+void __attribute__((weak)) xeno_sigill_handler(int sig)
+{
+	siglongjmp(xeno_sigill_jmpbuf, 1);
+}
+
 static inline int
 xeno_bind_skin(unsigned skin_magic, const char *skin, const char *module)
 {
+	sighandler_t old_sigill_handler;
 	struct sigaction sa;
 	xnfeatinfo_t finfo;
 	int muxid;
 
+	old_sigill_handler = signal(SIGILL, xeno_sigill_handler);
+	if (old_sigill_handler == SIG_ERR) {
+		perror("signal(SIGILL)");
+		exit(1);
+	}
+
+	if (sigsetjmp(xeno_sigill_jmpbuf, 1))
+		goto enosys;
+
 	muxid = XENOMAI_SYSBIND(skin_magic,
 				XENOMAI_FEAT_DEP, XENOMAI_ABI_REV, &finfo);
 	switch (muxid) {
@@ -126,7 +144,7 @@ xeno_bind_skin(unsigned skin_magic, cons
 
 	case -ENOSYS:
 	case -ESRCH:
-
+	enosys:
 		fprintf(stderr,
 			"Xenomai: %s skin or CONFIG_XENO_OPT_PERVASIVE disabled.\n"
 			"(modprobe %s?)\n", skin, module);
@@ -139,6 +157,8 @@ xeno_bind_skin(unsigned skin_magic, cons
 		exit(1);
 	}
 
+	signal(SIGILL, old_sigill_handler);
+
 #ifdef xeno_arch_features_check
 	xeno_arch_features_check();
 #endif /* xeno_arch_features_check */
@@ -180,9 +200,19 @@ xeno_bind_skin(unsigned skin_magic, cons
 static inline int
 xeno_bind_skin_opt(unsigned skin_magic, const char *skin, const char *module)
 {
+	sighandler_t old_sigill_handler;
 	xnfeatinfo_t finfo;
 	int muxid;
 
+	old_sigill_handler = signal(SIGILL, xeno_sigill_handler);
+	if (old_sigill_handler == SIG_ERR) {
+		perror("signal(SIGILL)");
+		exit(1);
+	}
+
+	if (sigsetjmp(xeno_sigill_jmpbuf, 1))
+		goto enosys;
+
 	muxid = XENOMAI_SYSBIND(skin_magic,
 				XENOMAI_FEAT_DEP, XENOMAI_ABI_REV, &finfo);
 	switch (muxid) {
@@ -203,7 +233,7 @@ xeno_bind_skin_opt(unsigned skin_magic, 
 
 	case -ENOSYS:
 	case -ESRCH:
-
+	enosys:
 		return -1;
 	}
 
@@ -213,6 +243,8 @@ xeno_bind_skin_opt(unsigned skin_magic, 
 		exit(1);
 	}
 
+	signal(SIGILL, old_sigill_handler);
+
 #ifdef xeno_arch_features_check
 	xeno_arch_features_check();
 #endif /* xeno_arch_features_check */



-- 
					    Gilles.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-09-28 14:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-21 20:01 [Xenomai-core] Handle SIGILL when kernel compiled without Xenomai Gilles Chanteperdrix
2008-09-22  8:25 ` Philippe Gerum
2008-09-22 15:32   ` Gilles Chanteperdrix
2008-09-22 18:18     ` Gilles Chanteperdrix
2008-09-28 14:31     ` Philippe Gerum
2008-09-28 14:39       ` Gilles Chanteperdrix
2008-09-28 14:49         ` Philippe Gerum
2008-09-22  9:14 ` Jan Kiszka
2008-09-22  9:21   ` Gilles Chanteperdrix
2008-09-22 10:43     ` Jan Kiszka
2008-09-22 12:03       ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.