Module: xenomai-2.6
Branch: master
Commit: 6a8730c0270a39ad9b0c5402e275f71df545c7f5
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=6a8730c0270a39ad9b0c5402e275f71df545c7f5

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Apr 23 14:04:16 2013 +0200

Invoke mlockall on every skin library initialization

The nucleus refuses to create threads if userspace didn't lock its
memory, that's the rule since day #1 basically. So far we require
userspace to do this explicitly, but there is actually nothing to lose
by doing it automatically during the initialization of a skin library.
In special scenarios, userspace could still temporarily unlock the
memory again.

As we lock unconditionally, there is no more need to lock/unlock around
POSIX, PSOS+ and uITRON auto-shadowing.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 configure.in            |   45 ---------------------------------------------
 src/skins/common/bind.c |    6 ++++++
 src/skins/posix/init.c  |   17 -----------------
 src/skins/psos+/init.c  |   15 +--------------
 src/skins/uitron/init.c |   15 +--------------
 5 files changed, 8 insertions(+), 90 deletions(-)

diff --git a/configure.in b/configure.in
index 7ed16d5..53495f1 100644
--- a/configure.in
+++ b/configure.in
@@ -576,51 +576,6 @@ LD_FILE_OPTION=$ac_cv_ld_file_option
 AC_SUBST(LD_FILE_OPTION)
 AM_CONDITIONAL(CONFIG_XENO_FAST_WRAP,[test "$LD_FILE_OPTION" = "yes"])
 
-AC_MSG_CHECKING(whether the POSIX skin library automatically calls mlockall)
-AC_ARG_ENABLE(posix-auto-mlockall,
-       AS_HELP_STRING([--enable-posix-auto-mlockall], [Enable Xenomai POSIX
-skin library to automatically call mlockall at startup. This option is mainly
-useful for running third-parties programs such as the Open Posix Testsuite
-unmodified with Xenomai POSIX skin [default=no]]),
-       [case "$enableval" in
-       y | yes) CONFIG_XENO_POSIX_AUTO_MLOCKALL=y ;;
-       *) unset CONFIG_XENO_POSIX_AUTO_MLOCKALL ;;
-       esac])
-AC_MSG_RESULT(${CONFIG_XENO_POSIX_AUTO_MLOCKALL:-no})
-if test x$CONFIG_XENO_POSIX_AUTO_MLOCKALL = xy; then
-       AC_DEFINE(CONFIG_XENO_POSIX_AUTO_MLOCKALL,1,[config])
-fi
-
-AC_MSG_CHECKING(whether the pSOS skin library automatically calls mlockall)
-AC_ARG_ENABLE(psos-auto-mlockall,
-       AS_HELP_STRING([--enable-psos-auto-mlockall], [Enable the
-Xenomai pSOS skin library to automatically call mlockall at
-process startup. Unless this option is switched on, the application
-will have to lock its memory explicitly while initializing. [default=no]]),
-       [case "$enableval" in
-       y | yes) CONFIG_XENO_PSOS_AUTO_MLOCKALL=y ;;
-       *) unset CONFIG_XENO_PSOS_AUTO_MLOCKALL ;;
-       esac])
-AC_MSG_RESULT(${CONFIG_XENO_PSOS_AUTO_MLOCKALL:-no})
-if test x$CONFIG_XENO_POSIX_PSOS_MLOCKALL = xy; then
-       AC_DEFINE(CONFIG_XENO_PSOS_AUTO_MLOCKALL,1,[config])
-fi
-
-AC_MSG_CHECKING(whether the uITRON skin library automatically calls mlockall)
-AC_ARG_ENABLE(uitron-auto-mlockall,
-       AS_HELP_STRING([--enable-uitron-auto-mlockall], [Enable the
-Xenomai uITRON skin library to automatically call mlockall at
-process startup. Unless this option is switched on, the application
-will have to lock its memory explicitly while initializing. [default=no]]),
-       [case "$enableval" in
-       y | yes) CONFIG_XENO_UITRON_AUTO_MLOCKALL=y ;;
-       *) unset CONFIG_XENO_UITRON_AUTO_MLOCKALL ;;
-       esac])
-AC_MSG_RESULT(${CONFIG_XENO_UITRON_AUTO_MLOCKALL:-no})
-if test x$CONFIG_XENO_POSIX_UITRON_MLOCKALL = xy; then
-       AC_DEFINE(CONFIG_XENO_UITRON_AUTO_MLOCKALL,1,[config])
-fi
-
 AC_MSG_CHECKING(whether to enable dlopen support for skin libraries)
 AC_ARG_ENABLE(dlopen-skins,
        AC_HELP_STRING([--enable-dlopen-skins], [Disable TLS features and
diff --git a/src/skins/common/bind.c b/src/skins/common/bind.c
index c869795..aeef861 100644
--- a/src/skins/common/bind.c
+++ b/src/skins/common/bind.c
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/mman.h>
 
 #include <nucleus/heap.h>
 #include <asm/xenomai/syscall.h>
@@ -92,6 +93,11 @@ xeno_bind_skin_opt(unsigned skin_magic, const char *skin, 
const char *module)
                exit(EXIT_FAILURE);
        }
 
+       if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
+               perror("Xenomai: mlockall");
+               exit(EXIT_FAILURE);
+       }
+
        xeno_featinfo = finfo;
        xeno_init_arch_features();
 
diff --git a/src/skins/posix/init.c b/src/skins/posix/init.c
index 710abfb..36ef397 100644
--- a/src/skins/posix/init.c
+++ b/src/skins/posix/init.c
@@ -68,16 +68,6 @@ void __init_posix_interface(void)
                                                                 
__rtdm_fdcount);
        }
 
-       /* If not dlopening, we are going to shadow the main thread, so mlock
-          the whole memory for the time of the syscall, in order to avoid the
-          SIGXCPU signal. */
-#if defined(CONFIG_XENO_POSIX_AUTO_MLOCKALL) || 
!defined(CONFIG_XENO_LIBS_DLOPEN)
-       if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
-               perror("Xenomai Posix skin init: mlockall");
-               exit(EXIT_FAILURE);
-       }
-#endif /* auto mlockall || !dlopen */
-
        /* Don't use auto-shadowing if we are likely invoked from dlopen. */
 #ifndef CONFIG_XENO_LIBS_DLOPEN
        err = __real_pthread_getschedparam(pthread_self(), &policy, &parm);
@@ -93,13 +83,6 @@ void __init_posix_interface(void)
                        "pthread_setschedparam: %s\n", strerror(err));
                exit(EXIT_FAILURE);
        }
-
-#ifndef CONFIG_XENO_POSIX_AUTO_MLOCKALL
-       if (munlockall()) {
-               perror("Xenomai Posix skin init: munlockall");
-               exit(EXIT_FAILURE);
-       }
-#endif /* !CONFIG_XENO_POSIX_AUTO_MLOCKALL */
 #endif /* !CONFIG_XENO_LIBS_DLOPEN */
 
        if (fork_handler_registered)
diff --git a/src/skins/psos+/init.c b/src/skins/psos+/init.c
index 35a3efa..5af37f8 100644
--- a/src/skins/psos+/init.c
+++ b/src/skins/psos+/init.c
@@ -44,26 +44,13 @@ void __init_xeno_interface(void)
 
        __psos_muxid = __xn_mux_shifted_id(__psos_muxid);
 
-       /* Shadow the main thread. mlock the whole memory for the time
-          of the syscall, in order to avoid the SIGXCPU signal. */
-       if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
-               perror("Xenomai pSOS skin init: mlockall() failed");
-               exit(EXIT_FAILURE);
-       }
-
+       /* Shadow the main thread. */
        err = t_shadow("MAIN", 0, 0, &tid);
 
        if (err) {
                fprintf(stderr, "Xenomai pSOS skin init: t_shadow() failed, 
status %ld", err);
                exit(EXIT_FAILURE);
        }
-
-#ifndef CONFIG_XENO_PSOS_AUTO_MLOCKALL
-       if (munlockall()) {
-               perror("Xenomai pSOS skin init: munlockall");
-               exit(EXIT_FAILURE);
-       }
-#endif /* !CONFIG_XENO_PSOS_AUTO_MLOCKALL */
 }
 
 void k_fatal(u_long err_code, u_long flags)
diff --git a/src/skins/uitron/init.c b/src/skins/uitron/init.c
index dc0dce5..5253729 100644
--- a/src/skins/uitron/init.c
+++ b/src/skins/uitron/init.c
@@ -33,13 +33,7 @@ void __init_xeno_interface(void)
        __uitron_muxid = xeno_bind_skin(uITRON_SKIN_MAGIC, "uitron", 
"xeno_uitron");
        __uitron_muxid = __xn_mux_shifted_id(__uitron_muxid);
 
-       /* Shadow the main thread. mlock the whole memory for the time
-          of the syscall, in order to avoid the SIGXCPU signal. */
-       if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
-               perror("Xenomai uITRON skin init: mlockall() failed");
-               exit(EXIT_FAILURE);
-       }
-
+       /* Shadow the main thread. */
        pk_ctsk.stksz = 0;
        pk_ctsk.itskpri = 0;    /* non-RT shadow. */
        err = shd_tsk(1, &pk_ctsk);
@@ -48,11 +42,4 @@ void __init_xeno_interface(void)
                fprintf(stderr, "Xenomai uITRON skin init: shd_tsk() failed, 
status %d", err);
                exit(EXIT_FAILURE);
        }
-
-#ifndef CONFIG_XENO_UITRON_AUTO_MLOCKALL
-       if (munlockall()) {
-               perror("Xenomai uITRON skin init: munlockall");
-               exit(EXIT_FAILURE);
-       }
-#endif /* !CONFIG_XENO_UITRON_AUTO_MLOCKALL */
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to