Module: xenomai-forge Branch: next Commit: 4e09e1bf51803b042a0505cb8d5e3e2c73d4b451 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4e09e1bf51803b042a0505cb8d5e3e2c73d4b451
Author: Philippe Gerum <r...@xenomai.org> Date: Tue Jul 16 15:42:58 2013 +0200 cobalt: introduce internal extension interface Drivers from the RTDM_COBALT class are specifically designed for extending the Cobalt/POSIX services. We need a way to expose extension-specific handlers in the latter, so that the former may change the default behavior at well-defined locations. This extension mechanism should not cause any overhead when disabled, which is the most common situation. For this reason, the extension mechanism is compiled out when CONFIG_XENO_OPT_COBALT_EXTENSION is disabled. This patch introduces the cobalt_extension abstraction, aimed at exposing a series of extension handlers as described previously, on a per-thread basis. Extension drivers should invoke the cobalt_thread_extend() and cobalt_thread_restrict() services to respectively enable and disable the handlers. At this chance, the private data field moved from the core thread object (xnthread) to the cobalt_thread structure, since this facility is intended for use by Cobalt extension code. Cobalt extension drivers should include <rtdm/cobalt.h>, which will read in the appropriate kernel headers, useful for implementing the add-on features, and interposing on the existing Cobalt services via the internal interface. Since these headers a not part of the public kernel API, drivers should mention "-Ikernel" in the ccflags-y variable from their Kbuild Makefile frag. --- include/cobalt/kernel/thread.h | 3 -- include/rtdm/Makefile.am | 13 ++++--- include/rtdm/Makefile.in | 11 +++--- include/rtdm/cobalt.h | 31 +++++++++++++++++ kernel/cobalt/Kconfig | 3 ++ kernel/cobalt/posix/clock.h | 67 +++++++++++++++++++++++++++++++++---- kernel/cobalt/posix/cond.c | 4 ++- kernel/cobalt/posix/cond.h | 11 ++++-- kernel/cobalt/posix/cond_attr.c | 3 +- kernel/cobalt/posix/event.c | 4 +- kernel/cobalt/posix/init.c | 4 +-- kernel/cobalt/posix/internal.h | 68 -------------------------------------- kernel/cobalt/posix/monitor.c | 4 +- kernel/cobalt/posix/mqueue.c | 12 +++--- kernel/cobalt/posix/mutex.c | 4 ++- kernel/cobalt/posix/mutex_attr.c | 3 +- kernel/cobalt/posix/registry.c | 6 ++-- kernel/cobalt/posix/sem.c | 44 ++++++++++++++---------- kernel/cobalt/posix/sem.h | 13 ++----- kernel/cobalt/posix/signal.c | 2 + kernel/cobalt/posix/syscall.c | 7 +++- kernel/cobalt/posix/thread.c | 28 +++++++++++++++ kernel/cobalt/posix/thread.h | 25 ++++++++++--- kernel/cobalt/posix/timer.c | 3 ++ kernel/cobalt/posix/timer.h | 1 + kernel/cobalt/thread.c | 1 - 26 files changed, 226 insertions(+), 149 deletions(-) diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h index 4f5f5f5..a9c8d8d 100644 --- a/include/cobalt/kernel/thread.h +++ b/include/cobalt/kernel/thread.h @@ -165,8 +165,6 @@ typedef struct xnthread { struct pt_regs *regs; /* Current register frame */ struct xnthread_user_window *u_window; /* Data visible from userland. */ - void *privdata; /* Private data for extension */ - struct xnpersonality *personality; /* Originating interface/personality */ #ifdef CONFIG_XENO_OPT_DEBUG @@ -232,7 +230,6 @@ static inline void xnthread_clear_info(struct xnthread *thread, int bits) #define xnthread_inc_rescnt(thread) ({ (thread)->hrescnt++; }) #define xnthread_dec_rescnt(thread) ({ --(thread)->hrescnt; }) #define xnthread_get_rescnt(thread) ((thread)->hrescnt) -#define xnthread_private(thread) ((thread)->privdata) #define xnthread_personality(thread) ((thread)->personality) #define xnthread_for_each_claimed(__pos, __thread) \ diff --git a/include/rtdm/Makefile.am b/include/rtdm/Makefile.am index 4e48be8..b271df9 100644 --- a/include/rtdm/Makefile.am +++ b/include/rtdm/Makefile.am @@ -1,9 +1,10 @@ includesubdir = $(includedir)/rtdm -includesub_HEADERS = \ - rtdm.h \ - rtdm_driver.h \ - rtserial.h \ - rttesting.h \ - rtcan.h \ +includesub_HEADERS = \ + cobalt.h \ + rtdm.h \ + rtdm_driver.h \ + rtserial.h \ + rttesting.h \ + rtcan.h \ rtipc.h diff --git a/include/rtdm/Makefile.in b/include/rtdm/Makefile.in index e4c3742..3e2eca4 100644 --- a/include/rtdm/Makefile.in +++ b/include/rtdm/Makefile.in @@ -275,11 +275,12 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ includesubdir = $(includedir)/rtdm includesub_HEADERS = \ - rtdm.h \ - rtdm_driver.h \ - rtserial.h \ - rttesting.h \ - rtcan.h \ + cobalt.h \ + rtdm.h \ + rtdm_driver.h \ + rtserial.h \ + rttesting.h \ + rtcan.h \ rtipc.h all: all-am diff --git a/include/rtdm/cobalt.h b/include/rtdm/cobalt.h new file mode 100644 index 0000000..977fdb6 --- /dev/null +++ b/include/rtdm/cobalt.h @@ -0,0 +1,31 @@ +/** + * @file + * This file is part of the Xenomai project. + * + * @note Copyright (C) 2013 Philippe Gerum <r...@xenomai.org> + * + * Xenomai is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#ifndef _RTDM_COBALT_H +#define _RTDM_COBALT_H + +#include <xenomai/posix/thread.h> +#include <xenomai/posix/signal.h> +#include <xenomai/posix/timer.h> +#include <xenomai/posix/clock.h> +#include <xenomai/posix/event.h> +#include <xenomai/posix/monitor.h> + +#endif /* !_RTDM_COBALT_H */ diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig index 241216a..d6764f1 100644 --- a/kernel/cobalt/Kconfig +++ b/kernel/cobalt/Kconfig @@ -208,6 +208,9 @@ config XENO_OPT_PIPE config XENO_OPT_MAP bool +config XENO_OPT_COBALT_EXTENSION + bool + config XENO_OPT_VFILE bool depends on PROC_FS diff --git a/kernel/cobalt/posix/clock.h b/kernel/cobalt/posix/clock.h index 9ceb90c..5c8d112 100644 --- a/kernel/cobalt/posix/clock.h +++ b/kernel/cobalt/posix/clock.h @@ -21,9 +21,66 @@ #include <linux/time.h> #include <cobalt/uapi/time.h> -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +#define ONE_BILLION 1000000000 + +static inline void ns2ts(struct timespec *ts, xnticks_t nsecs) +{ + ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec); +} + +static inline xnticks_t ts2ns(const struct timespec *ts) +{ + xntime_t nsecs = ts->tv_nsec; + + if (ts->tv_sec) + nsecs += (xntime_t)ts->tv_sec * ONE_BILLION; + + return nsecs; +} + +static inline xnticks_t tv2ns(const struct timeval *tv) +{ + xntime_t nsecs = tv->tv_usec * 1000; + + if (tv->tv_sec) + nsecs += (xntime_t)tv->tv_sec * ONE_BILLION; + + return nsecs; +} + +static inline void ticks2tv(struct timeval *tv, xnticks_t ticks) +{ + unsigned long nsecs; + + tv->tv_sec = xnclock_divrem_billion(ticks, &nsecs); + tv->tv_usec = nsecs / 1000; +} + +static inline xnticks_t clock_get_ticks(clockid_t clock_id) +{ + return clock_id == CLOCK_REALTIME ? + xnclock_read() : + xnclock_read_monotonic(); +} + +static inline int clock_flag(int flag, clockid_t clock_id) +{ + switch(flag & TIMER_ABSTIME) { + case 0: + return XN_RELATIVE; + + case TIMER_ABSTIME: + switch(clock_id) { + case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC_RAW: + return XN_ABSOLUTE; + + case CLOCK_REALTIME: + return XN_REALTIME; + } + } + return -EINVAL; +} int cobalt_clock_getres(clockid_t clock_id, struct timespec __user *u_ts); @@ -35,8 +92,4 @@ int cobalt_clock_nanosleep(clockid_t clock_id, int flags, const struct timespec __user *u_rqt, struct timespec __user *u_rmt); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* !_COBALT_POSIX_CLOCK_H */ diff --git a/kernel/cobalt/posix/cond.c b/kernel/cobalt/posix/cond.c index 8b3ace7..4b0cf03 100644 --- a/kernel/cobalt/posix/cond.c +++ b/kernel/cobalt/posix/cond.c @@ -47,9 +47,11 @@ * *@{*/ -#include <cobalt/kernel/ppd.h> +#include "thread.h" #include "mutex.h" #include "cond.h" +#include "clock.h" +#include "internal.h" static inline void cond_destroy_internal(struct cobalt_cond *cond, struct cobalt_kqueues *q) diff --git a/kernel/cobalt/posix/cond.h b/kernel/cobalt/posix/cond.h index cd0bf5f..26f5544 100644 --- a/kernel/cobalt/posix/cond.h +++ b/kernel/cobalt/posix/cond.h @@ -18,11 +18,16 @@ #ifndef _COBALT_POSIX_COND_H #define _COBALT_POSIX_COND_H -#include "thread.h" +#include <linux/time.h> +#include <linux/list.h> +#include <cobalt/kernel/synch.h> +#include <cobalt/uapi/thread.h> #include <cobalt/uapi/cond.h> -struct __shadow_mutex; -union cobalt_mutex_union; +struct cobalt_kqueues; +struct cobalt_mutex; + +typedef struct cobalt_condattr pthread_condattr_t; struct cobalt_cond { unsigned int magic; diff --git a/kernel/cobalt/posix/cond_attr.c b/kernel/cobalt/posix/cond_attr.c index d4081d3..d684d35 100644 --- a/kernel/cobalt/posix/cond_attr.c +++ b/kernel/cobalt/posix/cond_attr.c @@ -21,8 +21,9 @@ * *@{*/ -#include "internal.h" #include "thread.h" +#include "cond.h" +#include "internal.h" const pthread_condattr_t cobalt_default_cond_attr = { diff --git a/kernel/cobalt/posix/event.c b/kernel/cobalt/posix/event.c index 4c779af..ed7d688 100644 --- a/kernel/cobalt/posix/event.c +++ b/kernel/cobalt/posix/event.c @@ -38,10 +38,10 @@ * We expose this non-POSIX feature through the internal API, as a * fast IPC mechanism available to the Copperplate interface. */ -#include <cobalt/kernel/ppd.h> -#include "internal.h" #include "thread.h" +#include "clock.h" #include "event.h" +#include "internal.h" struct event_wait_context { struct xnthread_wait_context wc; diff --git a/kernel/cobalt/posix/init.c b/kernel/cobalt/posix/init.c index a9d0391..04e3a76 100644 --- a/kernel/cobalt/posix/init.c +++ b/kernel/cobalt/posix/init.c @@ -46,14 +46,12 @@ */ #include <linux/init.h> -#include "internal.h" +#include "thread.h" #include "cond.h" #include "mutex.h" #include "sem.h" -#include "thread.h" #include "mqueue.h" #include "timer.h" -#include "registry.h" #include "monitor.h" #include "event.h" #include "signal.h" diff --git a/kernel/cobalt/posix/internal.h b/kernel/cobalt/posix/internal.h index 4e536fb..37ad903 100644 --- a/kernel/cobalt/posix/internal.h +++ b/kernel/cobalt/posix/internal.h @@ -15,19 +15,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #ifndef _COBALT_POSIX_INTERNAL_H #define _COBALT_POSIX_INTERNAL_H #include <cobalt/kernel/pod.h> #include <cobalt/kernel/heap.h> #include <cobalt/kernel/ppd.h> -#include <cobalt/kernel/select.h> #include <cobalt/kernel/assert.h> #include <cobalt/kernel/list.h> #include <cobalt/kernel/arith.h> -#include <cobalt/uapi/syscall.h> -#include <asm/xenomai/syscall.h> #include "registry.h" #ifndef CONFIG_XENO_OPT_DEBUG_COBALT @@ -49,8 +45,6 @@ #define COBALT_EVENT_MAGIC COBALT_MAGIC(0F) #define COBALT_MONITOR_MAGIC COBALT_MAGIC(10) -#define ONE_BILLION 1000000000 - #define cobalt_obj_active(h,m,t) \ ((h) && ((t *)(h))->magic == (m)) @@ -102,68 +96,6 @@ static inline struct cobalt_kqueues *cobalt_kqueues(int pshared) return &container_of(ppd, struct cobalt_context, ppd)->kqueues; } -static inline void ns2ts(struct timespec *ts, xnticks_t nsecs) -{ - ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec); -} - -static inline xnticks_t ts2ns(const struct timespec *ts) -{ - xntime_t nsecs = ts->tv_nsec; - - if (ts->tv_sec) - nsecs += (xntime_t)ts->tv_sec * ONE_BILLION; - - return nsecs; -} - -static inline xnticks_t tv2ns(const struct timeval *tv) -{ - xntime_t nsecs = tv->tv_usec * 1000; - - if (tv->tv_sec) - nsecs += (xntime_t)tv->tv_sec * ONE_BILLION; - - return nsecs; -} - -static inline void ticks2tv(struct timeval *tv, xnticks_t ticks) -{ - unsigned long nsecs; - - tv->tv_sec = xnclock_divrem_billion(ticks, &nsecs); - tv->tv_usec = nsecs / 1000; -} - -static inline xnticks_t clock_get_ticks(clockid_t clock_id) -{ - return clock_id == CLOCK_REALTIME ? - xnclock_read() : - xnclock_read_monotonic(); -} - -static inline int clock_flag(int flag, clockid_t clock_id) -{ - switch(flag & TIMER_ABSTIME) { - case 0: - return XN_RELATIVE; - - case TIMER_ABSTIME: - switch(clock_id) { - case CLOCK_MONOTONIC: - case CLOCK_MONOTONIC_RAW: - return XN_ABSOLUTE; - - case CLOCK_REALTIME: - return XN_REALTIME; - } - } - return -EINVAL; -} - -int cobalt_mq_elect_bind(mqd_t fd, struct xnselector *selector, - unsigned type, unsigned index); - int cobalt_init(void); void cobalt_cleanup(void); diff --git a/kernel/cobalt/posix/monitor.c b/kernel/cobalt/posix/monitor.c index 79e26c6..0942929 100644 --- a/kernel/cobalt/posix/monitor.c +++ b/kernel/cobalt/posix/monitor.c @@ -49,10 +49,10 @@ * Implementation-wise, the monitor logic is shared with the Cobalt * thread object. */ -#include <cobalt/kernel/ppd.h> -#include "internal.h" #include "thread.h" +#include "clock.h" #include "monitor.h" +#include "internal.h" int cobalt_monitor_init(struct cobalt_monitor_shadow __user *u_monsh, int flags) diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c index f3bb488..dd87d3f 100644 --- a/kernel/cobalt/posix/mqueue.c +++ b/kernel/cobalt/posix/mqueue.c @@ -30,13 +30,13 @@ *@{*/ #include <stdarg.h> -#include <linux/fs.h> /* ERR_PTR */ -#include "registry.h" -#include "internal.h" /* Magics, time conversion */ -#include "thread.h" /* errno. */ +#include <linux/fs.h> +#include <cobalt/kernel/select.h> +#include "thread.h" #include "timer.h" #include "mqueue.h" #include "signal.h" +#include "clock.h" #include "internal.h" struct mq_attr { @@ -274,8 +274,8 @@ static mqd_t mq_open(const char *name, int oflags, ...) } /* Here, we know that we must create a message queue. */ - mq = (cobalt_mq_t *) xnmalloc(sizeof(*mq)); - if (!mq) { + mq = xnmalloc(sizeof(*mq)); + if (mq == NULL) { err = -ENOSPC; goto error; } diff --git a/kernel/cobalt/posix/mutex.c b/kernel/cobalt/posix/mutex.c index 9c91528..3b0ac5c 100644 --- a/kernel/cobalt/posix/mutex.c +++ b/kernel/cobalt/posix/mutex.c @@ -47,9 +47,11 @@ * *@{*/ -#include <cobalt/kernel/ppd.h> +#include "thread.h" #include "mutex.h" #include "cond.h" +#include "clock.h" +#include "internal.h" static int cobalt_mutex_init_inner(struct __shadow_mutex *shadow, struct cobalt_mutex *mutex, diff --git a/kernel/cobalt/posix/mutex_attr.c b/kernel/cobalt/posix/mutex_attr.c index c997e80..8ed2633 100644 --- a/kernel/cobalt/posix/mutex_attr.c +++ b/kernel/cobalt/posix/mutex_attr.c @@ -21,8 +21,9 @@ * *@{*/ -#include "internal.h" +#include "thread.h" #include "mutex.h" +#include "internal.h" const pthread_mutexattr_t cobalt_default_mutex_attr = { magic: COBALT_MUTEX_ATTR_MAGIC, diff --git a/kernel/cobalt/posix/registry.c b/kernel/cobalt/posix/registry.c index 62b18dd..3660df2 100644 --- a/kernel/cobalt/posix/registry.c +++ b/kernel/cobalt/posix/registry.c @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "registry.h" #include "thread.h" +#include "internal.h" #define BITS_PER_INT 32 @@ -218,8 +218,8 @@ int cobalt_desc_create(cobalt_desc_t ** descp, cobalt_node_t * node, long flags) spl_t s; int fd; - desc = (cobalt_desc_t *) xnmalloc(sizeof(*desc)); - if (!desc) + desc = xnmalloc(sizeof(*desc)); + if (desc == NULL) return ENOSPC; xnlock_get_irqsave(&nklock, s); diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c index e973bba..6aceffa 100644 --- a/kernel/cobalt/posix/sem.c +++ b/kernel/cobalt/posix/sem.c @@ -33,9 +33,9 @@ #include <stddef.h> #include <stdarg.h> -#include "registry.h" /* For named semaphores. */ #include "internal.h" #include "thread.h" +#include "clock.h" #include "sem.h" #define SEM_NAMED 0x80000000 @@ -51,20 +51,26 @@ struct cobalt_sem { struct cobalt_kqueues *owningq; }; +struct cobalt_usem { + unsigned long uaddr; + unsigned refcnt; + cobalt_assoc_t assoc; +}; + static inline struct cobalt_kqueues *sem_kqueue(struct cobalt_sem *sem) { int pshared = !!(sem->flags & SEM_PSHARED); return cobalt_kqueues(pshared); } -typedef struct cobalt_named_sem { +struct cobalt_named_sem { struct cobalt_sem sembase; /* Has to be the first member. */ cobalt_node_t nodebase; union cobalt_sem_union descriptor; -} nsem_t; +}; -#define sem2named_sem(saddr) ((nsem_t *)(saddr)) -#define node2sem(naddr) container_of(naddr, nsem_t, nodebase) +#define sem2named_sem(saddr) ((struct cobalt_named_sem *)(saddr)) +#define node2sem(naddr) container_of(naddr, struct cobalt_named_sem, nodebase) static int sem_destroy_inner(struct cobalt_sem *sem, struct cobalt_kqueues *q) { @@ -279,8 +285,8 @@ static int sem_destroy(struct __shadow_sem *sm) */ sem_t *sem_open(const char *name, int oflags, ...) { + struct cobalt_named_sem *named_sem; cobalt_node_t *node; - nsem_t *named_sem; unsigned value; mode_t mode; va_list ap; @@ -299,8 +305,8 @@ sem_t *sem_open(const char *name, int oflags, ...) goto got_sem; } - named_sem = (nsem_t *)xnmalloc(sizeof(*named_sem)); - if (!named_sem) { + named_sem = xnmalloc(sizeof(*named_sem)); + if (named_sem == NULL) { err = -ENOSPC; goto error; } @@ -375,7 +381,7 @@ sem_t *sem_open(const char *name, int oflags, ...) */ int sem_close(struct __shadow_sem *sm) { - nsem_t *named_sem; + struct cobalt_named_sem *named_sem; spl_t s; int err; @@ -442,8 +448,8 @@ int sem_close(struct __shadow_sem *sm) */ int sem_unlink(const char *name) { + struct cobalt_named_sem *named_sem; cobalt_node_t *node; - nsem_t *named_sem; spl_t s; int err; @@ -856,9 +862,9 @@ int cobalt_sem_open(unsigned long __user *u_addr, struct cobalt_context *cc; char name[COBALT_MAXNAME]; struct __shadow_sem *sm; + struct cobalt_usem *usm; cobalt_assoc_t *assoc; unsigned long uaddr; - cobalt_usem_t *usm; long len; int err; spl_t s; @@ -890,7 +896,7 @@ int cobalt_sem_open(unsigned long __user *u_addr, assoc = cobalt_assoc_lookup(&cc->usems, (u_long)sm->sem); if (assoc) { - usm = assoc2usem(assoc); + usm = container_of(assoc, struct cobalt_usem, assoc); ++usm->refcnt; xnlock_put_irqrestore(&nklock, s); goto got_usm; @@ -911,10 +917,10 @@ int cobalt_sem_open(unsigned long __user *u_addr, assoc = cobalt_assoc_lookup(&cc->usems, (u_long)sm->sem); if (assoc) { - assoc2usem(assoc)->refcnt++; + container_of(assoc, struct cobalt_usem, assoc)->refcnt++; xnlock_put_irqrestore(&nklock, s); xnfree(usm); - usm = assoc2usem(assoc); + usm = container_of(assoc, struct cobalt_usem, assoc); goto got_usm; } @@ -939,10 +945,10 @@ int cobalt_sem_open(unsigned long __user *u_addr, int cobalt_sem_close(unsigned long uaddr, int __user *u_closed) { struct cobalt_context *cc; + struct cobalt_usem *usm; struct __shadow_sem sm; cobalt_assoc_t *assoc; int closed = 0, err; - cobalt_usem_t *usm; spl_t s; cc = cobalt_process_context(); @@ -960,7 +966,7 @@ int cobalt_sem_close(unsigned long uaddr, int __user *u_closed) return -EINVAL; } - usm = assoc2usem(assoc); + usm = container_of(assoc, struct cobalt_usem, assoc); err = sem_close(&sm); @@ -1029,9 +1035,9 @@ int cobalt_sem_broadcast_np(struct __shadow_sem __user *u_sem) static void usem_cleanup(cobalt_assoc_t *assoc) { - struct cobalt_sem *sem = (struct cobalt_sem *) cobalt_assoc_key(assoc); - cobalt_usem_t *usem = assoc2usem(assoc); - nsem_t *nsem = sem2named_sem(sem); + struct cobalt_usem *usem = container_of(assoc, struct cobalt_usem, assoc); + struct cobalt_sem *sem = (struct cobalt_sem *)cobalt_assoc_key(assoc); + struct cobalt_named_sem *nsem = sem2named_sem(sem); #if XENO_DEBUG(COBALT) printk(XENO_INFO "closing Cobalt semaphore \"%s\"\n", diff --git a/kernel/cobalt/posix/sem.h b/kernel/cobalt/posix/sem.h index 2721424..18a8b5a 100644 --- a/kernel/cobalt/posix/sem.h +++ b/kernel/cobalt/posix/sem.h @@ -23,6 +23,9 @@ #include <cobalt/kernel/thread.h> #include <cobalt/kernel/registry.h> +struct cobalt_sem; +struct cobalt_context; + /* Copied from Linuxthreads semaphore.h. */ struct _sem_fastlock { @@ -42,18 +45,8 @@ typedef struct #define SEM_VALUE_MAX (INT_MAX) #define SEM_FAILED NULL -typedef struct { - u_long uaddr; - unsigned refcnt; - cobalt_assoc_t assoc; - -#define assoc2usem(laddr) container_of(laddr, cobalt_usem_t, assoc) -} cobalt_usem_t; - void cobalt_sem_usems_cleanup(struct cobalt_context *cc); -struct cobalt_sem; - int sem_getvalue(struct cobalt_sem *sem, int *value); int sem_post_inner(struct cobalt_sem *sem, diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c index c3be4bc..2df3528 100644 --- a/kernel/cobalt/posix/signal.c +++ b/kernel/cobalt/posix/signal.c @@ -18,6 +18,8 @@ #include <cobalt/kernel/assert.h> #include "thread.h" #include "timer.h" +#include "signal.h" +#include "clock.h" #include "internal.h" static void *sigev_mem; diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c index b5ac7cf..5e1de22 100644 --- a/kernel/cobalt/posix/syscall.c +++ b/kernel/cobalt/posix/syscall.c @@ -23,6 +23,8 @@ #include <linux/types.h> #include <linux/err.h> #include <cobalt/kernel/select.h> +#include <cobalt/uapi/syscall.h> +#include <asm/xenomai/syscall.h> #include <rtdm/rtdm_driver.h> #include "thread.h" #include "mutex.h" @@ -33,6 +35,8 @@ #include "monitor.h" #include "clock.h" #include "event.h" +#include "signal.h" +#include "internal.h" #define RTDM_FD_MAX CONFIG_XENO_OPT_RTDM_FILDES @@ -178,7 +182,8 @@ static int __select(int nfds, if (!first_fd_valid_p(in_fds, nfds)) return -EBADF; - if (!(selector = xnmalloc(sizeof(*thread->selector)))) + selector = xnmalloc(sizeof(*thread->selector)); + if (selector == NULL) return -ENOMEM; xnselector_init(selector); thread->selector = selector; diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c index 1b84181..aec4da3 100644 --- a/kernel/cobalt/posix/thread.c +++ b/kernel/cobalt/posix/thread.c @@ -35,6 +35,9 @@ #include <cobalt/uapi/signal.h> #include "thread.h" #include "timer.h" +#include "signal.h" +#include "clock.h" +#include "internal.h" xnticks_t cobalt_time_slice; @@ -1196,6 +1199,31 @@ int cobalt_thread_getschedparam_ex(unsigned long pth, return __xn_safe_copy_to_user(u_param, ¶m, sizeof(param)); } +#ifdef CONFIG_XENO_OPT_COBALT_EXTENSION + +void cobalt_thread_extend(struct cobalt_thread *thread, + struct cobalt_extension *ext, + void *priv) +{ + struct xnpersonality *prev; + + prev = xnshadow_push_personality(&thread->threadbase, &ext->core); + thread->extension = ext; + thread->private = priv; + XENO_BUGON(NUCLEUS, prev != &cobalt_personality); +} +EXPORT_SYMBOL_GPL(cobalt_thread_extend); + +void cobalt_thread_restrict(struct cobalt_thread *thread) +{ + xnshadow_pop_personality(&thread->threadbase, &cobalt_personality); + thread->extension = NULL; + thread->private = NULL; +} +EXPORT_SYMBOL_GPL(cobalt_thread_restrict); + +#endif /* !CONFIG_XENO_OPT_COBALT_EXTENSION */ + int cobalt_sched_min_prio(int policy) { switch (policy) { diff --git a/kernel/cobalt/posix/thread.h b/kernel/cobalt/posix/thread.h index d431b6c..1d0c267 100644 --- a/kernel/cobalt/posix/thread.h +++ b/kernel/cobalt/posix/thread.h @@ -21,9 +21,8 @@ #include <linux/types.h> #include <linux/time.h> #include <linux/signal.h> -#include "internal.h" -#include "signal.h" -#include <cobalt/kernel/synch.h> +#include <cobalt/kernel/thread.h> +#include <cobalt/kernel/shadow.h> #include <cobalt/uapi/thread.h> #include <cobalt/uapi/sched.h> @@ -43,8 +42,7 @@ struct cobalt_thread; struct cobalt_threadstat; - -typedef struct cobalt_condattr pthread_condattr_t; +struct cobalt_extension; typedef struct cobalt_threadattr { unsigned magic; @@ -99,9 +97,19 @@ struct cobalt_local_hkey { struct mm_struct *mm; }; +struct cobalt_extension { + struct xnpersonality core; + struct { + } ops; +}; + struct cobalt_thread { unsigned int magic; struct xnthread threadbase; +#ifdef CONFIG_XENO_OPT_COBALT_EXTENSION + struct cobalt_extension *extension; + void *private; +#endif /** cobalt_threadq */ struct list_head link; @@ -195,7 +203,12 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread *curr); struct xnpersonality *cobalt_thread_unmap(struct xnthread *zombie); -/* round-robin period. */ +void cobalt_thread_extend(struct cobalt_thread *thread, + struct cobalt_extension *ext, + void *priv); + +void cobalt_thread_restrict(struct cobalt_thread *thread); + extern xnticks_t cobalt_time_slice; extern struct xnpersonality cobalt_personality; diff --git a/kernel/cobalt/posix/timer.c b/kernel/cobalt/posix/timer.c index 7e79b50..6b7f584 100644 --- a/kernel/cobalt/posix/timer.c +++ b/kernel/cobalt/posix/timer.c @@ -24,6 +24,8 @@ #include <linux/cred.h> #include "thread.h" #include "timer.h" +#include "signal.h" +#include "clock.h" #include "internal.h" struct cobalt_timer { @@ -34,6 +36,7 @@ struct cobalt_timer { siginfo_t si; clockid_t clockid; pid_t target; + struct sigevent ev; struct cobalt_thread *owner; struct cobalt_kqueues *owningq; }; diff --git a/kernel/cobalt/posix/timer.h b/kernel/cobalt/posix/timer.h index d21cf02..fa63631 100644 --- a/kernel/cobalt/posix/timer.h +++ b/kernel/cobalt/posix/timer.h @@ -21,6 +21,7 @@ #include <linux/time.h> struct cobalt_thread; +struct cobalt_kqueues; int cobalt_timer_create(clockid_t clock, const struct sigevent __user *u_sev, diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index 2c5573d..0d43a8b 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -177,7 +177,6 @@ int xnthread_init(struct xnthread *thread, thread->selector = NULL; INIT_LIST_HEAD(&thread->claimq); - thread->privdata = NULL; thread->personality = attr->personality; thread->sched = sched; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git