Module: xenomai-forge
Branch: master
Commit: 959ff0be726613ab500983566dcb27c9bf9acb7d
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=959ff0be726613ab500983566dcb27c9bf9acb7d

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Dec 10 19:27:42 2011 +0100

lib/cobalt: cleanup init code

We don't need to expose any general-purpose skin binding interface
anymore, so we may group all relevant code into the lib/cobalt/init.c,
getting rid of lib/cobalt/bind.c in the same move.

At this chance, xeno_handle_mlock_alert() was renamed
cobalt_handle_sigdebug() for consistency with the general naming
scheme.

---

 include/asm-generic/bits/bind.h |   30 +--------
 lib/cobalt/Makefile.am          |    1 -
 lib/cobalt/Makefile.in          |   27 +++-----
 lib/cobalt/bind.c               |  137 ---------------------------------------
 lib/cobalt/init.c               |  116 ++++++++++++++++++++++++++++++++-
 lib/cobalt/internal.c           |   23 +++++++
 6 files changed, 147 insertions(+), 187 deletions(-)

diff --git a/include/asm-generic/bits/bind.h b/include/asm-generic/bits/bind.h
index 2480206..87ddca9 100644
--- a/include/asm-generic/bits/bind.h
+++ b/include/asm-generic/bits/bind.h
@@ -1,36 +1,8 @@
 #ifndef _XENO_ASM_GENERIC_BITS_BIND_H
 #define _XENO_ASM_GENERIC_BITS_BIND_H
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <signal.h>
 
-void xeno_handle_mlock_alert(int sig, siginfo_t *si, void *context);
-
-int xeno_bind_skin_opt(unsigned int skin_magic, const char *skin,
-                      const char *module);
-
-static inline
-int xeno_bind_skin(unsigned int skin_magic, const char *skin,
-                  const char *module)
-{
-       struct sigaction sa;
-       int muxid;
-
-       muxid = xeno_bind_skin_opt(skin_magic, skin, module);
-       if (muxid < 0) {
-               fprintf(stderr,
-                       "Xenomai: %s skin disabled (modprobe %s?)\n",
-                       skin, module);
-               exit(EXIT_FAILURE);
-       }
-
-       sa.sa_sigaction = xeno_handle_mlock_alert;
-       sigemptyset(&sa.sa_mask);
-       sa.sa_flags = SA_SIGINFO;
-       sigaction(SIGXCPU, &sa, NULL);
-
-       return muxid;
-}
+void cobalt_handle_sigdebug(int sig, siginfo_t *si, void *context);
 
 #endif /* _XENO_ASM_GENERIC_BITS_BIND_H */
diff --git a/lib/cobalt/Makefile.am b/lib/cobalt/Makefile.am
index 7ce76ba..be556e6 100644
--- a/lib/cobalt/Makefile.am
+++ b/lib/cobalt/Makefile.am
@@ -13,7 +13,6 @@ libcobalt_la_LDFLAGS = @XENO_LIB_LDFLAGS@ -version-info 2:0:0 
-lpthread -lrt
 libcobalt_la_SOURCES = \
        assert_context.c \
        attr.c \
-       bind.c \
        current.c \
        sem_heap.c \
        sigshadow.c \
diff --git a/lib/cobalt/Makefile.in b/lib/cobalt/Makefile.in
index f6c9241..de37910 100644
--- a/lib/cobalt/Makefile.in
+++ b/lib/cobalt/Makefile.in
@@ -79,15 +79,15 @@ am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
 libcobalt_la_LIBADD =
 am_libcobalt_la_OBJECTS = libcobalt_la-assert_context.lo \
-       libcobalt_la-attr.lo libcobalt_la-bind.lo \
-       libcobalt_la-current.lo libcobalt_la-sem_heap.lo \
-       libcobalt_la-sigshadow.lo libcobalt_la-timeconv.lo \
-       libcobalt_la-init.lo libcobalt_la-internal.lo \
-       libcobalt_la-thread.lo libcobalt_la-timer.lo \
-       libcobalt_la-semaphore.lo libcobalt_la-clock.lo \
-       libcobalt_la-cond.lo libcobalt_la-mq.lo libcobalt_la-mutex.lo \
-       libcobalt_la-select.lo libcobalt_la-rtdm.lo \
-       libcobalt_la-printf.lo libcobalt_la-wrappers.lo
+       libcobalt_la-attr.lo libcobalt_la-current.lo \
+       libcobalt_la-sem_heap.lo libcobalt_la-sigshadow.lo \
+       libcobalt_la-timeconv.lo libcobalt_la-init.lo \
+       libcobalt_la-internal.lo libcobalt_la-thread.lo \
+       libcobalt_la-timer.lo libcobalt_la-semaphore.lo \
+       libcobalt_la-clock.lo libcobalt_la-cond.lo libcobalt_la-mq.lo \
+       libcobalt_la-mutex.lo libcobalt_la-select.lo \
+       libcobalt_la-rtdm.lo libcobalt_la-printf.lo \
+       libcobalt_la-wrappers.lo
 libcobalt_la_OBJECTS = $(am_libcobalt_la_OBJECTS)
 libcobalt_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@@ -280,7 +280,6 @@ libcobalt_la_LDFLAGS = @XENO_LIB_LDFLAGS@ -version-info 
2:0:0 -lpthread -lrt
 libcobalt_la_SOURCES = \
        assert_context.c \
        attr.c \
-       bind.c \
        current.c \
        sem_heap.c \
        sigshadow.c \
@@ -381,7 +380,6 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcobalt_la-assert_context.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcobalt_la-attr.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcobalt_la-bind.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcobalt_la-clock.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcobalt_la-cond.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libcobalt_la-current.Plo@am__quote@
@@ -435,13 +433,6 @@ libcobalt_la-attr.lo: attr.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcobalt_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o 
libcobalt_la-attr.lo `test -f 'attr.c' || echo '$(srcdir)/'`attr.c
 
-libcobalt_la-bind.lo: bind.c
-@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcobalt_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT 
libcobalt_la-bind.lo -MD -MP -MF $(DEPDIR)/libcobalt_la-bind.Tpo -c -o 
libcobalt_la-bind.lo `test -f 'bind.c' || echo '$(srcdir)/'`bind.c
-@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libcobalt_la-bind.Tpo 
$(DEPDIR)/libcobalt_la-bind.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='bind.c' 
object='libcobalt_la-bind.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcobalt_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o 
libcobalt_la-bind.lo `test -f 'bind.c' || echo '$(srcdir)/'`bind.c
-
 libcobalt_la-current.lo: current.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) 
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(libcobalt_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT 
libcobalt_la-current.lo -MD -MP -MF $(DEPDIR)/libcobalt_la-current.Tpo -c -o 
libcobalt_la-current.lo `test -f 'current.c' || echo '$(srcdir)/'`current.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libcobalt_la-current.Tpo 
$(DEPDIR)/libcobalt_la-current.Plo
diff --git a/lib/cobalt/bind.c b/lib/cobalt/bind.c
deleted file mode 100644
index 45aeba9..0000000
--- a/lib/cobalt/bind.c
+++ /dev/null
@@ -1,137 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include <nucleus/heap.h>
-#include <asm/xenomai/syscall.h>
-#include <asm-generic/xenomai/bits/current.h>
-#include <asm-generic/xenomai/timeconv.h>
-#include <asm-generic/xenomai/stack.h>
-#include <asm-generic/xenomai/sem_heap.h>
-#include <asm/xenomai/bits/bind.h>
-
-int xeno_sigxcpu_no_mlock = 1;
-static pthread_t xeno_main_tid;
-
-static void xeno_sigill_handler(int sig)
-{
-       fprintf(stderr, "Xenomai disabled (modprobe xeno_nucleus?)\n");
-       exit(EXIT_FAILURE);
-}
-
-struct xnfeatinfo xeno_featinfo;
-
-#ifdef xeno_arch_features_check
-static void do_init_arch_features(void)
-{
-       xeno_arch_features_check(&xeno_featinfo);
-}
-static void xeno_init_arch_features(void)
-{
-       static pthread_once_t init_archfeat_once = PTHREAD_ONCE_INIT;
-       pthread_once(&init_archfeat_once, do_init_arch_features);
-}
-#else  /* !xeno_init_arch_features */
-#define xeno_init_arch_features()      do { } while (0)
-#endif /* !xeno_arch_features_check */
-
-int xeno_bind_skin_opt(unsigned int skin_magic, const char *skin,
-                      const char *module)
-{
-       sighandler_t old_sigill_handler;
-       struct xnbindreq breq;
-       struct xnfeatinfo *f;
-       int muxid;
-
-       /* Some sanity checks first. */
-       if (access(XNHEAP_DEV_NAME, 0)) {
-               fprintf(stderr, "Xenomai: %s is missing\n(chardev, major=10 
minor=%d)\n",
-                       XNHEAP_DEV_NAME, XNHEAP_DEV_MINOR);
-               exit(EXIT_FAILURE);
-       }
-
-       old_sigill_handler = signal(SIGILL, xeno_sigill_handler);
-       if (old_sigill_handler == SIG_ERR) {
-               perror("signal(SIGILL)");
-               exit(EXIT_FAILURE);
-       }
-
-       f = &breq.feat_ret;
-       breq.feat_req = XENOMAI_FEAT_DEP;
-       breq.abi_rev = XENOMAI_ABI_REV;
-       muxid = XENOMAI_SYSBIND(skin_magic, &breq);
-
-       signal(SIGILL, old_sigill_handler);
-
-       switch (muxid) {
-       case -EINVAL:
-               fprintf(stderr, "Xenomai: incompatible feature set\n");
-               fprintf(stderr,
-                       "(userland requires \"%s\", kernel provides \"%s\", 
missing=\"%s\").\n",
-                       f->feat_man_s, f->feat_all_s, f->feat_mis_s);
-               exit(EXIT_FAILURE);
-
-       case -ENOEXEC:
-               fprintf(stderr, "Xenomai: incompatible ABI revision level\n");
-               fprintf(stderr, "(user-space requires '%lu', kernel provides 
'%lu').\n",
-                       XENOMAI_ABI_REV, f->feat_abirev);
-               exit(EXIT_FAILURE);
-
-       case -ENOSYS:
-       case -ESRCH:
-               return -1;
-       }
-
-       if (muxid < 0) {
-               fprintf(stderr, "Xenomai: binding failed: %s.\n",
-                       strerror(-muxid));
-               exit(EXIT_FAILURE);
-       }
-
-       xeno_featinfo = *f;
-       xeno_init_arch_features();
-
-       xeno_init_sem_heaps();
-
-       xeno_init_current_keys();
-
-       xeno_main_tid = pthread_self();
-
-       xeno_init_timeconv(muxid);
-
-       return muxid;
-}
-
-void xeno_fault_stack(void)
-{
-       if (pthread_self() == xeno_main_tid) {
-               char stk[xeno_stacksize(1)];
-
-               stk[0] = stk[sizeof(stk) - 1] = 0xA5;
-       }
-}
-
-void xeno_handle_mlock_alert(int sig, siginfo_t *si, void *context)
-{
-       struct sigaction sa;
-
-       if (si->si_value.sival_int == SIGDEBUG_NOMLOCK) {
-               fprintf(stderr, "Xenomai: process memory not locked "
-                       "(missing mlockall?)\n");
-               fflush(stderr);
-               exit(4);
-       }
-
-       /* XNTRAPSW was set for the thread but no user-defined handler
-          has been set to override our internal handler, so let's
-          invoke the default signal action. */
-
-       sa.sa_handler = SIG_DFL;
-       sigemptyset(&sa.sa_mask);
-       sa.sa_flags = 0;
-       sigaction(SIGXCPU, &sa, NULL);
-       pthread_kill(pthread_self(), SIGXCPU);
-}
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 9a2cfc2..037a5ce 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -20,36 +20,148 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <signal.h>
 #include <limits.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <nucleus/heap.h>
 #include <cobalt/posix.h>
 #include <cobalt/syscall.h>
 #include <rtdm/syscall.h>
 #include <kernel/cobalt/mutex.h>
 #include <rtdk.h>
 #include <asm/xenomai/bits/bind.h>
+#include <asm-generic/xenomai/timeconv.h>
+#include <asm-generic/xenomai/stack.h>
+#include <asm-generic/xenomai/sem_heap.h>
+#include "internal.h"
 
 int __cobalt_muxid = -1;
 int __rtdm_muxid = -1;
 int __rtdm_fd_start = INT_MAX;
 static int fork_handler_registered;
+static pthread_t xeno_main_tid;
+struct xnfeatinfo xeno_featinfo;
 
 int __wrap_pthread_setschedparam(pthread_t, int, const struct sched_param *);
 void cobalt_clock_init(int);
 
+static void sigill_handler(int sig)
+{
+       fprintf(stderr, "Xenomai disabled in kernel?\n");
+       exit(EXIT_FAILURE);
+}
+
+#ifdef xeno_arch_features_check
+static void do_init_arch_features(void)
+{
+       xeno_arch_features_check(&xeno_featinfo);
+}
+static void init_arch_features(void)
+{
+       static pthread_once_t init_archfeat_once = PTHREAD_ONCE_INIT;
+       pthread_once(&init_archfeat_once, do_init_arch_features);
+}
+#else  /* !xeno_init_arch_features */
+#define init_arch_features()   do { } while (0)
+#endif /* !xeno_arch_features_check */
+
+void xeno_fault_stack(void)
+{
+       if (pthread_self() == xeno_main_tid) {
+               char stk[xeno_stacksize(1)];
+               stk[0] = stk[sizeof(stk) - 1] = 0xA5;
+       }
+}
+
+static int bind_interface(void)
+{
+       sighandler_t old_sigill_handler;
+       struct xnbindreq breq;
+       struct xnfeatinfo *f;
+       int muxid;
+
+       /* Some sanity checks first. */
+       if (access(XNHEAP_DEV_NAME, 0)) {
+               fprintf(stderr, "Xenomai: %s is missing\n(chardev, major=10 
minor=%d)\n",
+                       XNHEAP_DEV_NAME, XNHEAP_DEV_MINOR);
+               exit(EXIT_FAILURE);
+       }
+
+       old_sigill_handler = signal(SIGILL, sigill_handler);
+       if (old_sigill_handler == SIG_ERR) {
+               perror("signal(SIGILL)");
+               exit(EXIT_FAILURE);
+       }
+
+       f = &breq.feat_ret;
+       breq.feat_req = XENOMAI_FEAT_DEP;
+       breq.abi_rev = XENOMAI_ABI_REV;
+       muxid = XENOMAI_SYSBIND(COBALT_SKIN_MAGIC, &breq);
+
+       signal(SIGILL, old_sigill_handler);
+
+       switch (muxid) {
+       case -EINVAL:
+               fprintf(stderr, "Xenomai: incompatible feature set\n");
+               fprintf(stderr,
+                       "(userland requires \"%s\", kernel provides \"%s\", 
missing=\"%s\").\n",
+                       f->feat_man_s, f->feat_all_s, f->feat_mis_s);
+               exit(EXIT_FAILURE);
+
+       case -ENOEXEC:
+               fprintf(stderr, "Xenomai: incompatible ABI revision level\n");
+               fprintf(stderr, "(user-space requires '%lu', kernel provides 
'%lu').\n",
+                       XENOMAI_ABI_REV, f->feat_abirev);
+               exit(EXIT_FAILURE);
+
+       case -ENOSYS:
+       case -ESRCH:
+               return -1;
+       }
+
+       if (muxid < 0) {
+               fprintf(stderr, "Xenomai: binding failed: %s.\n",
+                       strerror(-muxid));
+               exit(EXIT_FAILURE);
+       }
+
+       xeno_featinfo = *f;
+       init_arch_features();
+
+       xeno_init_sem_heaps();
+
+       xeno_init_current_keys();
+
+       xeno_main_tid = pthread_self();
+
+       xeno_init_timeconv(muxid);
+
+       return muxid;
+}
+
 static __attribute__ ((constructor))
 void __init_cobalt_interface(void)
 {
        struct sched_param parm;
        struct xnbindreq breq;
        int policy, muxid, ret;
+       struct sigaction sa;
        const char *p;
 
        rt_print_auto_init(1);
 
-       muxid =
-           xeno_bind_skin(COBALT_SKIN_MAGIC, "POSIX", "xeno_posix");
+       muxid = bind_interface();
+       if (muxid < 0) {
+               fprintf(stderr,
+                       "Xenomai: Cobalt interface unavailable\n");
+               exit(EXIT_FAILURE);
+       }
+
+       sa.sa_sigaction = cobalt_handle_sigdebug;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = SA_SIGINFO;
+       sigaction(SIGXCPU, &sa, NULL);
 
        cobalt_clock_init(muxid);
 
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index d04bfd0..0b87f6a 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -294,3 +294,26 @@ int cobalt_monitor_drain_all_sync(cobalt_monitor_t *mon)
 
        return ret;
 }
+
+void cobalt_handle_sigdebug(int sig, siginfo_t *si, void *context)
+{
+       struct sigaction sa;
+
+       if (si->si_value.sival_int == SIGDEBUG_NOMLOCK) {
+               fprintf(stderr, "Xenomai: process memory not locked "
+                       "(missing mlockall?)\n");
+               fflush(stderr);
+               exit(4);
+       }
+
+       /*
+        * XNTRAPSW was set for the thread but no user-defined handler
+        * has been set to override our internal handler, so let's
+        * invoke the default signal action.
+        */
+       sa.sa_handler = SIG_DFL;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = 0;
+       sigaction(SIGXCPU, &sa, NULL);
+       pthread_kill(pthread_self(), SIGXCPU);
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to