Commit a2b6ce8e authored by Philippe Gerum's avatar Philippe Gerum
Browse files

cobalt/kernel, lib/cobalt: expose a single syscall table

Since all userland processes belong to the Cobalt personality, all
syscalls have been merged into the Cobalt table.

As a consequence, all process context information maintained by the
core has moved to the cobalt_process descriptor.
parent 06609e08
......@@ -26,7 +26,6 @@ noinst_HEADERS = \
sched-tp.h \
sched-weak.h \
select.h \
shadow.h \
stat.h \
synch.h \
thread.h \
......
......@@ -370,7 +370,6 @@ noinst_HEADERS = \
sched-tp.h \
sched-weak.h \
select.h \
shadow.h \
stat.h \
synch.h \
thread.h \
......
......@@ -19,18 +19,9 @@
#ifndef _COBALT_KERNEL_PPD_H
#define _COBALT_KERNEL_PPD_H
#include <cobalt/kernel/list.h>
#include <cobalt/kernel/shadow.h>
#include <cobalt/kernel/lock.h>
#include <linux/atomic.h>
#include <linux/rbtree.h>
#include <cobalt/kernel/heap.h>
#include <rtdm/fd.h>
#define NR_PERSONALITIES 4
#if BITS_PER_LONG < NR_PERSONALITIES
#error "NR_PERSONALITIES overflows internal bitmap"
#endif
void *xnshadow_get_context(unsigned int muxid);
struct xnsys_ppd {
struct xnheap sem_heap;
......@@ -40,24 +31,6 @@ struct xnsys_ppd {
struct rb_root fds;
};
struct xnshadow_process {
struct mm_struct *mm;
void *priv[NR_PERSONALITIES];
struct hlist_node hlink;
struct xnsys_ppd sys_ppd;
unsigned long permap;
};
extern struct xnsys_ppd __xnsys_global_ppd;
static inline struct xnsys_ppd *xnsys_ppd_get(int global)
{
struct xnshadow_process *ppd;
if (global || (ppd = xnshadow_get_context(0)) == NULL)
return &__xnsys_global_ppd;
return &ppd->sys_ppd;
}
#endif /* _COBALT_KERNEL_PPD_H */
......@@ -37,7 +37,6 @@
#include <cobalt/kernel/vfile.h>
#include <cobalt/kernel/clock.h>
#include <cobalt/kernel/apc.h>
#include <cobalt/kernel/shadow.h>
#include <cobalt/kernel/init.h>
#include <cobalt/kernel/ancillaries.h>
#include <cobalt/kernel/tree.h>
......@@ -50,6 +49,7 @@
#ifdef CONFIG_PCI
#include <asm-generic/xenomai/pci_ids.h>
#endif /* CONFIG_PCI */
#include <asm/xenomai/syscall.h>
struct rtdm_dev_context;
typedef struct xnselector rtdm_selector_t;
......@@ -947,7 +947,7 @@ static inline void rtdm_task_destroy(rtdm_task_t *task)
static inline int rtdm_task_should_stop(void)
{
return xnthread_test_info(xnshadow_current(), XNCANCELD);
return xnthread_test_info(xnthread_current(), XNCANCELD);
}
void rtdm_task_join(rtdm_task_t *task);
......@@ -984,7 +984,7 @@ static inline int rtdm_task_unblock(rtdm_task_t *task)
static inline rtdm_task_t *rtdm_task_current(void)
{
return xnshadow_current();
return xnthread_current();
}
static inline int rtdm_task_wait_period(void)
......@@ -1217,7 +1217,7 @@ static inline int rtdm_rt_capable(struct rtdm_fd *fd)
if (!rtdm_fd_is_user(fd))
return !xnsched_root_p();
return xnshadow_thread(current) != NULL;
return xnthread_current() != NULL;
}
static inline int rtdm_in_rt_context(void)
......
......@@ -26,6 +26,7 @@
#include <linux/sched.h>
#include <linux/socket.h>
#include <cobalt/kernel/ppd.h>
#include <rtdm/fd.h>
#define RTDM_FD_MAGIC 0x52544446
......
/*
* Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@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.
*
* Xenomai 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 Xenomai; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef _COBALT_KERNEL_SHADOW_H
#define _COBALT_KERNEL_SHADOW_H
#include <linux/signal.h>
#include <linux/sched.h>
#include <asm/xenomai/syscall.h>
#include <cobalt/uapi/kernel/types.h>
#include <cobalt/uapi/signal.h>
/**
* @addtogroup cobalt_core_shadow
* @{
*/
struct xnthread;
struct xnthread_user_window;
struct pt_regs;
struct timespec;
struct timeval;
struct completion;
struct module;
struct xnshadow_process;
struct xnpersonality {
const char *name;
unsigned int magic;
int muxid;
int nrcalls;
struct xnsyscall *syscalls;
atomic_t refcnt;
struct {
void *(*attach_process)(void);
void (*detach_process)(void *arg);
void (*map_thread)(struct xnthread *thread);
struct xnpersonality *(*relax_thread)(struct xnthread *thread);
struct xnpersonality *(*harden_thread)(struct xnthread *thread);
struct xnpersonality *(*move_thread)(struct xnthread *thread,
int dest_cpu);
struct xnpersonality *(*exit_thread)(struct xnthread *thread);
struct xnpersonality *(*finalize_thread)(struct xnthread *thread);
} ops;
struct module *module;
};
static inline struct xnthread *xnshadow_current(void)
{
return ipipe_current_threadinfo()->thread;
}
static inline struct xnthread *xnshadow_thread(struct task_struct *p)
{
return ipipe_task_threadinfo(p)->thread;
}
static inline struct xnshadow_process *xnshadow_current_process(void)
{
return ipipe_current_threadinfo()->process;
}
static inline struct xnshadow_process *
xnshadow_set_process(struct xnshadow_process *process)
{
struct ipipe_threadinfo *p = ipipe_current_threadinfo();
struct xnshadow_process *old;
old = p->process;
p->process = process;
return old;
}
int xnshadow_mount(void);
void xnshadow_cleanup(void);
void xnshadow_grab_events(void);
void xnshadow_release_events(void);
int xnshadow_map_user(struct xnthread *thread,
unsigned long __user *u_window_offset);
int xnshadow_map_kernel(struct xnthread *thread,
struct completion *done);
void xnshadow_finalize(struct xnthread *thread);
int xnshadow_harden(void);
void xnshadow_relax(int notify, int reason);
int xnshadow_register_personality(struct xnpersonality *personality);
int xnshadow_unregister_personality(int muxid);
void xnshadow_send_sig(struct xnthread *thread,
int sig,
int arg);
void xnshadow_call_mayday(struct xnthread *thread, int reason);
void __xnshadow_kick(struct xnthread *thread);
void xnshadow_kick(struct xnthread *thread);
void __xnshadow_demote(struct xnthread *thread);
void xnshadow_demote(struct xnthread *thread);
struct xnpersonality *
xnshadow_push_personality(int muxid);
void xnshadow_pop_personality(struct xnpersonality *prev);
int xnshadow_yield(xnticks_t min, xnticks_t max);
extern struct xnpersonality xenomai_personality;
/** @} */
#endif /* !_COBALT_KERNEL_SHADOW_H */
......@@ -27,7 +27,6 @@
#include <cobalt/kernel/registry.h>
#include <cobalt/kernel/schedparam.h>
#include <cobalt/kernel/trace.h>
#include <cobalt/kernel/shadow.h>
#include <cobalt/kernel/synch.h>
#include <cobalt/uapi/kernel/thread.h>
#include <asm/xenomai/machine.h>
......@@ -45,10 +44,11 @@ struct xnsched;
struct xnselector;
struct xnsched_class;
struct xnsched_tpslot;
struct xnpersonality;
struct xnthread_personality;
struct completion;
struct xnthread_init_attr {
struct xnpersonality *personality;
struct xnthread_personality *personality;
cpumask_t affinity;
int flags;
const char *name;
......@@ -64,6 +64,25 @@ struct xnthread_wait_context {
int posted;
};
struct xnthread_personality {
const char *name;
unsigned int magic;
int xid;
atomic_t refcnt;
struct {
void *(*attach_process)(void);
void (*detach_process)(void *arg);
void (*map_thread)(struct xnthread *thread);
struct xnthread_personality *(*relax_thread)(struct xnthread *thread);
struct xnthread_personality *(*harden_thread)(struct xnthread *thread);
struct xnthread_personality *(*move_thread)(struct xnthread *thread,
int dest_cpu);
struct xnthread_personality *(*exit_thread)(struct xnthread *thread);
struct xnthread_personality *(*finalize_thread)(struct xnthread *thread);
} ops;
struct module *module;
};
struct xnthread {
struct xnarchtcb tcb; /* Architecture-dependent block */
......@@ -170,7 +189,7 @@ struct xnthread {
struct pt_regs *regs; /* Current register frame */
struct xnthread_user_window *u_window; /* Data visible from userland. */
struct xnpersonality *personality; /* Originating interface/personality */
struct xnthread_personality *personality;
#ifdef CONFIG_XENO_OPT_DEBUG
const char *exe_path; /* Executable path */
......@@ -252,14 +271,14 @@ static inline struct xnarchtcb *xnthread_archtcb(struct xnthread *thread)
#define xnthread_run_handler(__t, __h, __a...) \
do { \
struct xnpersonality *__p__ = (__t)->personality; \
struct xnthread_personality *__p__ = (__t)->personality; \
if ((__p__)->ops.__h) \
(__p__)->ops.__h(__t, ##__a); \
} while (0)
#define xnthread_run_handler_stack(__t, __h, __a...) \
do { \
struct xnpersonality *__p__ = (__t)->personality; \
struct xnthread_personality *__p__ = (__t)->personality; \
do { \
if ((__p__)->ops.__h == NULL) \
break; \
......@@ -343,6 +362,42 @@ void __xnthread_test_cancel(struct xnthread *curr);
void __xnthread_cleanup(struct xnthread *curr);
/**
* @fn struct xnthread *xnthread_current(void)
* @brief Retrieve the current Cobalt core TCB.
*
* Returns the address of the current Cobalt core thread descriptor,
* or NULL if running over a regular Linux task. This call is not
* affected by the current runtime mode of the core thread.
*
* @caution The returned value may differ from
* xnsched_current_thread() called from the same context, since the
* latter returns the root thread descriptor for the current CPU if
* the caller is running in secondary mode.
*
* @coretags{unrestricted}
*/
static inline struct xnthread *xnthread_current(void)
{
return ipipe_current_threadinfo()->thread;
}
/**
* @fn struct xnthread *xnthread_from_task(struct task_struct *p)
* @brief Retrieve the Cobalt core TCB attached to a Linux task.
*
* Returns the address of the Cobalt core thread descriptor attached
* to the Linux task @a p, or NULL if @a p is a regular Linux
* task. This call is not affected by the current runtime mode of the
* core thread.
*
* @coretags{unrestricted}
*/
static inline struct xnthread *xnthread_from_task(struct task_struct *p)
{
return ipipe_task_threadinfo(p)->thread;
}
/**
* @fn void xnthread_test_cancel(void)
* @brief Introduce a thread cancellation point.
......@@ -350,12 +405,11 @@ void __xnthread_cleanup(struct xnthread *curr);
* Terminates the current thread if a cancellation request is pending
* for it, i.e. if xnthread_cancel() was called.
*
* Calling context: This service may be called from all runtime modes
* of kernel or user-space threads.
* @coretags{mode-unrestricted}
*/
static inline void xnthread_test_cancel(void)
{
struct xnthread *curr = xnshadow_current();
struct xnthread *curr = xnthread_current();
if (curr && xnthread_test_info(curr, XNCANCELD))
__xnthread_test_cancel(curr);
......@@ -431,6 +485,28 @@ void xnthread_cancel(struct xnthread *thread);
int xnthread_join(struct xnthread *thread, bool uninterruptible);
int xnthread_harden(void);
void xnthread_relax(int notify, int reason);
void __xnthread_kick(struct xnthread *thread);
void xnthread_kick(struct xnthread *thread);
void __xnthread_demote(struct xnthread *thread);
void xnthread_demote(struct xnthread *thread);
void xnthread_signal(struct xnthread *thread,
int sig, int arg);
void xnthread_pin_initial(struct xnthread *thread);
int xnthread_map(struct xnthread *thread,
struct completion *done);
void xnthread_call_mayday(struct xnthread *thread, int reason);
#ifdef CONFIG_SMP
int xnthread_migrate(int cpu);
......@@ -457,6 +533,8 @@ int xnthread_set_schedparam(struct xnthread *thread,
struct xnsched_class *sched_class,
const union xnsched_policy_param *sched_param);
extern struct xnthread_personality xenomai_personality;
/** @} */
#endif /* !_COBALT_KERNEL_THREAD_H */
......@@ -55,6 +55,8 @@ struct cobalt_tsd_hook {
extern "C" {
#endif
int cobalt_extend(unsigned int magic);
int cobalt_thread_stat(pid_t pid,
struct cobalt_threadstat *stat);
......
......@@ -20,7 +20,7 @@
#define XNFEAT_STRING_LEN 64
struct xnfeatinfo {
struct cobalt_featinfo {
unsigned long feat_all; /* Available feature set. */
char feat_all_s[XNFEAT_STRING_LEN];
unsigned long feat_man; /* Mandatory features (when requested). */
......@@ -29,7 +29,7 @@ struct xnfeatinfo {
char feat_req_s[XNFEAT_STRING_LEN];
unsigned long feat_mis; /* Missing features. */
char feat_mis_s[XNFEAT_STRING_LEN];
struct xnfeatinfo_archdep feat_arch; /* Arch-dep extension. */
struct cobalt_featinfo_archdep feat_arch; /* Arch-dep extension. */
unsigned long feat_abirev; /* ABI revision level. */
};
......
......@@ -21,36 +21,23 @@
#include <asm/xenomai/uapi/features.h>
#include <asm/xenomai/uapi/syscall.h>
/* Xenomai multiplexer syscall. */
#define sc_nucleus_mux 555 /* Must fit within 15bit */
/* Xenomai nucleus syscalls. */
#define sc_nucleus_bind 0 /* muxid = xnshadow_sys_bind(magic, &breq) */
#define sc_nucleus_migrate 1 /* switched = xnshadow_relax/harden() */
#define sc_nucleus_info 2 /* xnshadow_sys_info(&info) */
#define sc_nucleus_arch 3 /* r = xnarch_local_syscall(args) */
#define sc_nucleus_trace 4 /* r = xntrace_xxx(...) */
#define sc_nucleus_heap_info 5
#define sc_nucleus_current 6 /* threadh = xnthread_handle(cur) */
#define sc_nucleus_mayday 7 /* request mayday fixup */
#define sc_nucleus_backtrace 8 /* collect backtrace (relax tracing) */
#define sc_nucleus_serialdbg 9 /* output to serial console (__ipipe_serial_debug()) */
#define cobalt_syscall_tag 555 /* Must fit within 15bit */
struct xnbindreq {
int feat_req; /* Features userland requires. */
int abi_rev; /* ABI revision userland uses. */
struct xnfeatinfo feat_ret; /* Features kernel space provides. */
struct cobalt_bindreq {
/** Features userland requires. */
int feat_req;
/** ABI revision userland uses. */
int abi_rev;
/** Features the Cobalt core provides. */
struct cobalt_featinfo feat_ret;
};
#define XENOMAI_LINUX_DOMAIN 0
#define XENOMAI_XENO_DOMAIN 1
#define COBALT_SECONDARY 0
#define COBALT_PRIMARY 1
struct xnsysinfo {
struct cobalt_sysinfo {
unsigned long long clockfreq; /* Real-time clock frequency */
unsigned long vdso; /* Offset of nkvdso in the sem heap */
};
#define SIGSHADOW_ACTION_HARDEN 1
#define SIGSHADOW_ACTION_BACKTRACE 2
#define SIGSHADOW_BACKTRACE_DEPTH 16
#endif /* !_COBALT_UAPI_ASM_GENERIC_SYSCALL_H */
......@@ -21,12 +21,12 @@
#define XNHEAP_DEV_NAME "/dev/rtheap"
#define XNHEAP_DEV_MINOR 254
/* Possible arguments to the sys_heap_info syscall */
#define XNHEAP_PROC_PRIVATE_HEAP 0
#define XNHEAP_PROC_SHARED_HEAP 1
#define XNHEAP_SYS_HEAP 2
/* For sc_cobalt_heap_getstat. */
#define COBALT_PRIVATE_HEAP 0
#define COBALT_SHARED_HEAP 1
#define COBALT_GLOBAL_HEAP 2
struct xnheap_desc {
struct cobalt_heapstat {
unsigned long handle;
unsigned int size;
unsigned long area;
......
......@@ -44,6 +44,11 @@
#define sigshadow_arg(code) (((code) >> 8) & 0xff)
#define sigshadow_int(action, arg) ((action) | ((arg) << 8))
/* SIGSHADOW action codes. */
#define SIGSHADOW_ACTION_HARDEN 1
#define SIGSHADOW_ACTION_BACKTRACE 2
#define SIGSHADOW_BACKTRACE_DEPTH 16
#define SIGDEBUG SIGXCPU
#define sigdebug_code(si) ((si)->si_value.sival_int)
#define sigdebug_reason(si) (sigdebug_code(si) & 0xff)
......
......@@ -20,101 +20,105 @@
#include <cobalt/uapi/asm-generic/syscall.h>
#define COBALT_BINDING_MAGIC 0x50534531
#define sc_cobalt_bind 0
#define sc_cobalt_thread_create 1
#define sc_cobalt_thread_getpid 2
#define sc_cobalt_thread_setmode 3
#define sc_cobalt_thread_setname 4
#define sc_cobalt_thread_join 5
#define sc_cobalt_thread_kill 6
#define sc_cobalt_thread_setschedparam_ex 7
#define sc_cobalt_thread_getschedparam_ex 8
#define sc_cobalt_thread_getstat 9
/* 10 unimp */
#define sc_cobalt_sem_init 11
#define sc_cobalt_sem_destroy 12
#define sc_cobalt_sem_post 13
#define sc_cobalt_sem_wait 14
#define sc_cobalt_sem_trywait 15
#define sc_cobalt_sem_getvalue 16
#define sc_cobalt_sem_open 17
#define sc_cobalt_sem_close 18
#define sc_cobalt_sem_unlink 19
#define sc_cobalt_sem_timedwait 20
#define sc_cobalt_sem_inquire 21
#define sc_cobalt_sem_init_np 22
#define sc_cobalt_sem_broadcast_np 23
#define sc_cobalt_clock_getres 24
#define sc_cobalt_clock_gettime 25
#define sc_cobalt_clock_settime 26
#define sc_cobalt_clock_nanosleep 27
#define sc_cobalt_mutex_init 28
#define sc_cobalt_mutex_check_init 29
#define sc_cobalt_mutex_destroy 30
#define sc_cobalt_mutex_lock 31
#define sc_cobalt_mutex_timedlock 32
#define sc_cobalt_mutex_trylock 33
#define sc_cobalt_mutex_unlock 34
#define sc_cobalt_cond_init 35
#define sc_cobalt_cond_destroy 36
#define sc_cobalt_cond_wait_prologue 37
#define sc_cobalt_cond_wait_epilogue 38
#define sc_cobalt_mq_open 39
#define sc_cobalt_mq_close 40
#define sc_cobalt_mq_unlink 41
#define sc_cobalt_mq_getattr 42
#define sc_cobalt_mq_setattr 43
#define sc_cobalt_mq_timedsend 44
#define sc_cobalt_mq_timedreceive 45
#define sc_cobalt_mq_notify 46
#define sc_cobalt_sched_minprio 47
#define sc_cobalt_sched_maxprio 48
#define sc_cobalt_sched_weightprio 49
#define sc_cobalt_sched_yield 50
#define sc_cobalt_sched_setconfig_np 51
#define sc_cobalt_sched_getconfig_np 52
#define sc_cobalt_timer_create 53
#define sc_cobalt_timer_delete 54
#define sc_cobalt_timer_settime 55
#define sc_cobalt_timer_gettime 56
#define sc_cobalt_timer_getoverrun 57
#define sc_cobalt_timerfd_create 58
#define sc_cobalt_timerfd_settime 59
#define sc_cobalt_timerfd_gettime 60
#define sc_cobalt_sigwait 61
#define sc_cobalt_sigwaitinfo 62
#define sc_cobalt_sigtimedwait 63
#define sc_cobalt_sigpending 64
#define sc_cobalt_kill 65
#define sc_cobalt_sigqueue 66
#define sc_cobalt_monitor_init 67
#define sc_cobalt_monitor_destroy 68
#define sc_cobalt_monitor_enter 69
#define sc_cobalt_monitor_wait 70
#define sc_cobalt_monitor_sync 71
#define sc_cobalt_monitor_exit 72
#define sc_cobalt_event_init 73
#define sc_cobalt_event_wait 74
#define sc_cobalt_event_sync 75
#define sc_cobalt_event_destroy 76
#define sc_cobalt_event_inquire 77
#define sc_cobalt_open 78
#define sc_cobalt_socket 79
#define sc_cobalt_close 80
#define sc_cobalt_ioctl 81
#define sc_cobalt_read 82
#define sc_cobalt_write 83
#define sc_cobalt_recvmsg 84
#define sc_cobalt_sendmsg 85
#define sc_cobalt_mmap 86
#define sc_cobalt_select 87
#define sc_cobalt_migrate 88
#define sc_cobalt_arch 89
#define sc_cobalt_info 90
#define sc_cobalt_trace 91
#define sc_cobalt_heap_getstat 92
#define sc_cobalt_current 93
#define sc_cobalt_mayday 94
#define sc_cobalt_backtrace 95