Пример #1
0
static __constructor__ void __init_posix_interface(void)
{
	struct sched_param parm;
	int policy;
	int muxid, err;
	const char *noshadow;

	rt_print_auto_init(1);

	muxid =
	    xeno_bind_skin(PSE51_SKIN_MAGIC, "POSIX", "xeno_posix");

#ifdef XNARCH_HAVE_NONPRIV_TSC
	pse51_clock_init(muxid);
#endif /* XNARCH_HAVE_NONPRIV_TSC */

	__pse51_muxid = __xn_mux_shifted_id(muxid);

	muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC,
				XENOMAI_FEAT_DEP, XENOMAI_ABI_REV, NULL);
	if (muxid > 0) {
		__pse51_rtdm_muxid = __xn_mux_shifted_id(muxid);
		__pse51_rtdm_fd_start = FD_SETSIZE - XENOMAI_SKINCALL0(__pse51_rtdm_muxid,
								 __rtdm_fdcount);
	}

	pse51_mutex_init();

	noshadow = getenv("XENO_NOSHADOW");
	if ((!noshadow || !*noshadow) && xeno_get_current() == XN_NO_HANDLE) {
		err = __real_pthread_getschedparam(pthread_self(), &policy,
						   &parm);
		if (err) {
			fprintf(stderr, "Xenomai Posix skin init: "
				"pthread_getschedparam: %s\n", strerror(err));
			exit(EXIT_FAILURE);
		}

		err = __wrap_pthread_setschedparam(pthread_self(), policy,
						   &parm);
		if (err) {
			fprintf(stderr, "Xenomai Posix skin init: "
				"pthread_setschedparam: %s\n", strerror(err));
			exit(EXIT_FAILURE);
		}
	}

	if (fork_handler_registered)
		return;

	err = pthread_atfork(NULL, NULL, &__init_posix_interface);
	if (err) {
		fprintf(stderr, "Xenomai Posix skin init: "
			"pthread_atfork: %s\n", strerror(err));
		exit(EXIT_FAILURE);
	}
	fork_handler_registered = 1;

	if (sizeof(struct __shadow_mutex) > sizeof(pthread_mutex_t)) {
		fprintf(stderr, "sizeof(pthread_mutex_t): %d <"
			" sizeof(shadow_mutex): %d !\n",
			(int) sizeof(pthread_mutex_t),
			(int) sizeof(struct __shadow_mutex));
		exit(EXIT_FAILURE);
	}
}
Пример #2
0
void __init_posix_interface(void)
{
	struct xnbindreq breq;
	
#ifndef CONFIG_XENO_LIBS_DLOPEN
	struct sched_param parm;
	int policy;
#endif /* !CONFIG_XENO_LIBS_DLOPEN */
	int muxid, err;

	rt_print_auto_init(1);

	muxid =
	    xeno_bind_skin(PSE51_SKIN_MAGIC, "POSIX", "xeno_posix");

	pse51_clock_init(muxid);

	__pse51_muxid = __xn_mux_shifted_id(muxid);

	breq.feat_req = XENOMAI_FEAT_DEP;
	breq.abi_rev = XENOMAI_ABI_REV;
	muxid = XENOMAI_SYSBIND(RTDM_SKIN_MAGIC, &breq);
	if (muxid > 0) {
		__rtdm_muxid = __xn_mux_shifted_id(muxid);
		__rtdm_fd_start = FD_SETSIZE - XENOMAI_SKINCALL0(__rtdm_muxid,
								 __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 = __STD(pthread_getschedparam(pthread_self(), &policy, &parm));
	if (err) {
		fprintf(stderr, "Xenomai Posix skin init: "
			"pthread_getschedparam: %s\n", strerror(err));
		exit(EXIT_FAILURE);
	}

	err = __wrap_pthread_setschedparam(pthread_self(), policy, &parm);
	if (err) {
		fprintf(stderr, "Xenomai Posix skin init: "
			"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)
		return;

	err = pthread_atfork(NULL, NULL, &__init_posix_interface);
	if (err) {
		fprintf(stderr, "Xenomai Posix skin init: "
			"pthread_atfork: %s\n", strerror(err));
		exit(EXIT_FAILURE);
	}
	fork_handler_registered = 1;

	if (sizeof(struct __shadow_mutex) > sizeof(pthread_mutex_t)) {
		fprintf(stderr, "sizeof(pthread_mutex_t): %d <"
			" sizeof(shadow_mutex): %d !\n",
			(int) sizeof(pthread_mutex_t),
			(int) sizeof(struct __shadow_mutex));
		exit(EXIT_FAILURE);
	}
}