Xenomai  3.0.5
internal.h
1 /*
2  * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _COPPERPLATE_INTERNAL_H
19 #define _COPPERPLATE_INTERNAL_H
20 
21 #include <sys/types.h>
22 #include <stdarg.h>
23 #include <time.h>
24 #include <pthread.h>
25 #include <semaphore.h>
26 #include <xeno_config.h>
27 #include <boilerplate/list.h>
28 #include <boilerplate/ancillaries.h>
29 #include <boilerplate/limits.h>
30 #include <boilerplate/sched.h>
31 #include <boilerplate/setup.h>
32 #include <copperplate/heapobj.h>
33 #include <copperplate/tunables.h>
34 
35 #ifdef CONFIG_XENO_REGISTRY
36 #define DEFAULT_REGISTRY_ROOT CONFIG_XENO_REGISTRY_ROOT
37 #else
38 #define DEFAULT_REGISTRY_ROOT NULL
39 #endif
40 
41 #define HOBJ_PAGE_SHIFT 9 /* 2^9 => 512 bytes */
42 #if HOBJ_PAGE_SHIFT > 21
43 #error "page size is too large"
44 #endif
45 
46 #define HOBJ_PAGE_SIZE (1UL << HOBJ_PAGE_SHIFT)
47 #define HOBJ_PAGE_MASK (~(HOBJ_PAGE_SIZE-1))
48 
49 #define HOBJ_MINLOG2 4 /* 16 bytes */
50 /* +1 for holding HOBJ_PAGE_SIZE < x <= HOBJ_PAGE_SIZE * 2 */
51 #define HOBJ_MAXLOG2 (HOBJ_PAGE_SHIFT + 1)
52 #define HOBJ_NBUCKETS (HOBJ_MAXLOG2 - HOBJ_MINLOG2 + 1)
53 #define HOBJ_MINALIGNSZ (1U << HOBJ_MINLOG2)
54 
55 #define HOBJ_MAXEXTSZ (1U << 31) /* 2Gb */
56 
57 /*
58  * The struct below has to live in shared memory; no direct reference
59  * to process local memory in there.
60  */
61 struct shared_heap {
62  char name[XNOBJECT_NAME_LEN];
63  pthread_mutex_t lock;
64  struct listobj extents;
65  size_t ubytes;
66  size_t total;
67  size_t maxcont;
68  struct sysgroup_memspec memspec;
69  struct {
70  memoff_t freelist;
71  int fcount;
72  } buckets[HOBJ_NBUCKETS];
73 };
74 
75 struct corethread_attributes {
76  size_t stacksize;
77  int detachstate;
78  int policy;
79  struct sched_param_ex param_ex;
80  int (*prologue)(void *arg);
81  void *(*run)(void *arg);
82  void *arg;
83  struct {
84  int status;
85  sem_t warm;
86  sem_t *released;
87  } __reserved;
88 };
89 
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93 
94 void copperplate_set_current_name(const char *name);
95 
96 int copperplate_get_current_name(char *name, size_t maxlen);
97 
98 int copperplate_kill_tid(pid_t tid, int sig);
99 
100 int copperplate_probe_tid(pid_t tid);
101 
102 int copperplate_create_thread(struct corethread_attributes *cta,
103  pthread_t *ptid);
104 
105 int copperplate_renice_local_thread(pthread_t ptid, int policy,
106  const struct sched_param_ex *param_ex);
107 
108 void copperplate_bootstrap_internal(const char *arg0,
109  char *mountpt, int regflags);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* _COPPERPLATE_INTERNAL_H */