Xenomai  3.1
process.h
1 /*
2  * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 #ifndef _COBALT_POSIX_PROCESS_H
19 #define _COBALT_POSIX_PROCESS_H
20 
21 #include <linux/list.h>
22 #include <linux/bitmap.h>
23 #include <cobalt/kernel/ppd.h>
24 
25 #define KEVENT_PROPAGATE 0
26 #define KEVENT_STOP 1
27 
28 #define NR_PERSONALITIES 4
29 #if BITS_PER_LONG < NR_PERSONALITIES
30 #error "NR_PERSONALITIES overflows internal bitmap"
31 #endif
32 
33 struct mm_struct;
34 struct xnthread_personality;
35 struct cobalt_timer;
36 
37 struct cobalt_resources {
38  struct list_head condq;
39  struct list_head mutexq;
40  struct list_head semq;
41  struct list_head monitorq;
42  struct list_head eventq;
43  struct list_head schedq;
44 };
45 
46 struct cobalt_process {
47  struct mm_struct *mm;
48  struct hlist_node hlink;
49  struct cobalt_ppd sys_ppd;
50  unsigned long permap;
51  struct rb_root usems;
52  struct list_head sigwaiters;
53  struct cobalt_resources resources;
54  struct list_head thread_list;
55  DECLARE_BITMAP(timers_map, CONFIG_XENO_OPT_NRTIMERS);
56  struct cobalt_timer *timers[CONFIG_XENO_OPT_NRTIMERS];
57  void *priv[NR_PERSONALITIES];
58  int ufeatures;
59  unsigned int debugged_threads;
60 };
61 
62 struct cobalt_resnode {
63  struct cobalt_resources *scope;
64  struct cobalt_process *owner;
65  struct list_head next;
66  xnhandle_t handle;
67 };
68 
69 int cobalt_register_personality(struct xnthread_personality *personality);
70 
71 int cobalt_unregister_personality(int xid);
72 
73 struct xnthread_personality *cobalt_push_personality(int xid);
74 
75 void cobalt_pop_personality(struct xnthread_personality *prev);
76 
77 int cobalt_bind_core(int ufeatures);
78 
79 int cobalt_bind_personality(unsigned int magic);
80 
81 struct cobalt_process *cobalt_search_process(struct mm_struct *mm);
82 
83 int cobalt_map_user(struct xnthread *thread, __u32 __user *u_winoff);
84 
85 void *cobalt_get_context(int xid);
86 
87 int cobalt_yield(xnticks_t min, xnticks_t max);
88 
89 int cobalt_process_init(void);
90 
91 extern struct list_head cobalt_global_thread_list;
92 
93 extern struct cobalt_resources cobalt_global_resources;
94 
95 static inline struct cobalt_process *cobalt_current_process(void)
96 {
97  return ipipe_current_threadinfo()->process;
98 }
99 
100 static inline struct cobalt_process *
101 cobalt_set_process(struct cobalt_process *process)
102 {
103  struct ipipe_threadinfo *p = ipipe_current_threadinfo();
104  struct cobalt_process *old;
105 
106  old = p->process;
107  p->process = process;
108 
109  return old;
110 }
111 
112 static inline struct cobalt_ppd *cobalt_ppd_get(int global)
113 {
114  struct cobalt_process *process;
115 
116  if (global || (process = cobalt_current_process()) == NULL)
117  return &cobalt_kernel_ppd;
118 
119  return &process->sys_ppd;
120 }
121 
122 static inline struct cobalt_resources *cobalt_current_resources(int pshared)
123 {
124  struct cobalt_process *process;
125 
126  if (pshared || (process = cobalt_current_process()) == NULL)
127  return &cobalt_global_resources;
128 
129  return &process->resources;
130 }
131 
132 static inline
133 void __cobalt_add_resource(struct cobalt_resnode *node, int pshared)
134 {
135  node->owner = cobalt_current_process();
136  node->scope = cobalt_current_resources(pshared);
137 }
138 
139 #define cobalt_add_resource(__node, __type, __pshared) \
140  do { \
141  __cobalt_add_resource(__node, __pshared); \
142  list_add_tail(&(__node)->next, \
143  &((__node)->scope)->__type ## q); \
144  } while (0)
145 
146 static inline
147 void cobalt_del_resource(struct cobalt_resnode *node)
148 {
149  list_del(&node->next);
150 }
151 
152 extern struct xnthread_personality *cobalt_personalities[];
153 
154 extern struct xnthread_personality cobalt_personality;
155 
156 #endif /* !_COBALT_POSIX_PROCESS_H */