Module: xenomai-forge Branch: next Commit: 8f3352c0671f670491f3d5bd14508be47f87cee4 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=8f3352c0671f670491f3d5bd14508be47f87cee4
Author: Philippe Gerum <r...@xenomai.org> Date: Sat Aug 30 11:33:31 2014 +0200 cobalt/kernel: introduce cobalt_sysconf service --- include/cobalt/uapi/Makefile.am | 1 + include/cobalt/uapi/Makefile.in | 1 + include/cobalt/uapi/syscall.h | 1 + include/cobalt/uapi/sysconf.h | 40 ++++++++++++++++++++++++++ kernel/cobalt/posix/syscall.c | 60 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+) diff --git a/include/cobalt/uapi/Makefile.am b/include/cobalt/uapi/Makefile.am index 0151e40..243c6b8 100644 --- a/include/cobalt/uapi/Makefile.am +++ b/include/cobalt/uapi/Makefile.am @@ -9,6 +9,7 @@ includesub_HEADERS = \ sem.h \ signal.h \ syscall.h \ + sysconf.h \ thread.h \ time.h diff --git a/include/cobalt/uapi/Makefile.in b/include/cobalt/uapi/Makefile.in index 3536278..d5573de 100644 --- a/include/cobalt/uapi/Makefile.in +++ b/include/cobalt/uapi/Makefile.in @@ -381,6 +381,7 @@ includesub_HEADERS = \ sem.h \ signal.h \ syscall.h \ + sysconf.h \ thread.h \ time.h diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h index 3811133..904b278 100644 --- a/include/cobalt/uapi/syscall.h +++ b/include/cobalt/uapi/syscall.h @@ -118,6 +118,7 @@ #define sc_cobalt_backtrace 95 #define sc_cobalt_serialdbg 96 #define sc_cobalt_extend 97 +#define sc_cobalt_sysconf 98 #define __NR_COBALT_SYSCALLS 100 diff --git a/include/cobalt/uapi/sysconf.h b/include/cobalt/uapi/sysconf.h new file mode 100644 index 0000000..f753116 --- /dev/null +++ b/include/cobalt/uapi/sysconf.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 Philippe Gerum <r...@xenomai.org>. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef _COBALT_UAPI_SYSCONF_H +#define _COBALT_UAPI_SYSCONF_H + +#define _SC_COBALT_VERSION 0 +#define _SC_COBALT_NR_PIPES 1 +#define _SC_COBALT_NR_TIMERS 2 +#define _SC_COBALT_DEBUG 3 +# define _SC_COBALT_DEBUG_ASSERT 1 +# define _SC_COBALT_DEBUG_CONTEXT 2 +# define _SC_COBALT_DEBUG_LOCKING 4 +# define _SC_COBALT_DEBUG_SYNCREL 8 +# define _SC_COBALT_DEBUG_TRACEREL 16 +#define _SC_COBALT_POLICIES 4 +# define _SC_COBALT_SCHED_FIFO 1 +# define _SC_COBALT_SCHED_RR 2 +# define _SC_COBALT_SCHED_WEAK 4 +# define _SC_COBALT_SCHED_SPORADIC 8 +# define _SC_COBALT_SCHED_QUOTA 16 +# define _SC_COBALT_SCHED_TP 32 +#define _SC_COBALT_WATCHDOG 5 +#define _SC_COBALT_EXTENSION 6 + +#endif /* !_COBALT_UAPI_SYSCONF_H */ diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c index 747b2be..d5a8e45 100644 --- a/kernel/cobalt/posix/syscall.c +++ b/kernel/cobalt/posix/syscall.c @@ -19,9 +19,12 @@ #include <linux/types.h> #include <linux/err.h> #include <linux/ipipe.h> +#include <linux/kconfig.h> #include <cobalt/uapi/syscall.h> +#include <cobalt/uapi/sysconf.h> #include <cobalt/kernel/tree.h> #include <cobalt/kernel/vdso.h> +#include <xenomai/version.h> #include <asm-generic/xenomai/mayday.h> #include "internal.h" #include "thread.h" @@ -653,6 +656,62 @@ static int cobalt_extend(unsigned int magic) return cobalt_bind_personality(magic); } +static int cobalt_sysconf(int option, void __user *u_buf, size_t u_bufsz) +{ + int ret, val = 0; + + if (u_bufsz < sizeof(val)) + return -EINVAL; + + switch (option) { + case _SC_COBALT_VERSION: + val = XENO_VERSION_CODE; + break; + case _SC_COBALT_NR_PIPES: +#if IS_ENABLED(CONFIG_XENO_OPT_PIPE) + val = CONFIG_XENO_OPT_PIPE_NRDEV; +#endif + break; + case _SC_COBALT_NR_TIMERS: + val = CONFIG_XENO_OPT_NRTIMERS; + break; + case _SC_COBALT_POLICIES: + val = _SC_COBALT_SCHED_FIFO|_SC_COBALT_SCHED_RR; + if (IS_ENABLED(CONFIG_XENO_OPT_SCHED_WEAK)) + val |= _SC_COBALT_SCHED_WEAK; + if (IS_ENABLED(CONFIG_XENO_OPT_SCHED_SPORADIC)) + val |= _SC_COBALT_SCHED_SPORADIC; + if (IS_ENABLED(CONFIG_XENO_OPT_SCHED_QUOTA)) + val |= _SC_COBALT_SCHED_QUOTA; + if (IS_ENABLED(CONFIG_XENO_OPT_SCHED_TP)) + val |= _SC_COBALT_SCHED_TP; + break; + case _SC_COBALT_DEBUG: + if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_NUCLEUS)) + val |= _SC_COBALT_DEBUG_ASSERT; + if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_CONTEXT)) + val |= _SC_COBALT_DEBUG_CONTEXT; + if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_LOCKING)) + val |= _SC_COBALT_DEBUG_LOCKING; + if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_SYNCH_RELAX)) + val |= _SC_COBALT_DEBUG_SYNCREL; + if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_TRACE_RELAX)) + val |= _SC_COBALT_DEBUG_TRACEREL; + break; + case _SC_COBALT_WATCHDOG: +#if IS_ENABLED(CONFIG_XENO_OPT_WATCHDOG) + val = CONFIG_XENO_OPT_WATCHDOG_TIMEOUT; +#endif + break; + default: + return -EINVAL; + } + + ret = __xn_safe_copy_from_user(u_buf, &val, sizeof(val)); + + return ret ? -EFAULT : 0; +} + static int cobalt_ni(void) { return -ENOSYS; @@ -767,4 +826,5 @@ static struct cobalt_syscall cobalt_syscalls[] = { __COBALT_CALL(sc_cobalt_mayday, cobalt_mayday, oneway), __COBALT_CALL(sc_cobalt_backtrace, cobalt_backtrace, current), __COBALT_CALL(sc_cobalt_serialdbg, cobalt_serialdbg, current), + __COBALT_CALL(sc_cobalt_sysconf, cobalt_sysconf, current), }; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git