Xenomai  3.1
signal.h
1 /*
2  * Copyright (C) 2006 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3  * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18  */
19 #ifndef _COBALT_UAPI_SIGNAL_H
20 #define _COBALT_UAPI_SIGNAL_H
21 
22 /*
23  * Those are pseudo-signals only available with pthread_kill() to
24  * suspend/resume/unblock threads synchronously, force them out of
25  * primary mode or even demote them to the SCHED_OTHER class via the
26  * low-level nucleus interface. Can't block those signals, queue them,
27  * or even set them in a sigset. Those are nasty, strictly anti-POSIX
28  * things; we do provide them nevertheless only because we are mean
29  * people doing harmful code for no valid reason. Can't go against
30  * your nature, right? Nah... (this said, don't blame us for POSIX,
31  * we are not _that_ mean).
32  */
33 #define SIGSUSP (SIGRTMAX + 1)
34 #define SIGRESM (SIGRTMAX + 2)
35 #define SIGRELS (SIGRTMAX + 3)
36 #define SIGKICK (SIGRTMAX + 4)
37 #define SIGDEMT (SIGRTMAX + 5)
38 
39 /*
40  * Regular POSIX signals with specific handling by Xenomai.
41  */
42 #define SIGSHADOW SIGWINCH
43 #define sigshadow_action(code) ((code) & 0xff)
44 #define sigshadow_arg(code) (((code) >> 8) & 0xff)
45 #define sigshadow_int(action, arg) ((action) | ((arg) << 8))
46 
47 /* SIGSHADOW action codes. */
48 #define SIGSHADOW_ACTION_HARDEN 1
49 #define SIGSHADOW_ACTION_BACKTRACE 2
50 #define SIGSHADOW_ACTION_HOME 3
51 #define SIGSHADOW_BACKTRACE_DEPTH 16
52 
53 #define SIGDEBUG SIGXCPU
54 #define sigdebug_code(si) ((si)->si_value.sival_int)
55 #define sigdebug_reason(si) (sigdebug_code(si) & 0xff)
56 #define sigdebug_marker 0xfccf0000
57 #define sigdebug_marked(si) \
58  ((sigdebug_code(si) & 0xffff0000) == sigdebug_marker)
59 
60 /* Possible values of sigdebug_reason() */
61 #define SIGDEBUG_UNDEFINED 0
62 #define SIGDEBUG_MIGRATE_SIGNAL 1
63 #define SIGDEBUG_MIGRATE_SYSCALL 2
64 #define SIGDEBUG_MIGRATE_FAULT 3
65 #define SIGDEBUG_MIGRATE_PRIOINV 4
66 #define SIGDEBUG_NOMLOCK 5
67 #define SIGDEBUG_WATCHDOG 6
68 #define SIGDEBUG_RESCNT_IMBALANCE 7
69 #define SIGDEBUG_LOCK_BREAK 8
70 #define SIGDEBUG_MUTEX_SLEEP 9
71 
72 #define COBALT_DELAYMAX 2147483647U
73 
74 /*
75  * Internal accessors to extra siginfo/sigevent fields, extending some
76  * existing base field. The extra data should be grouped in a
77  * dedicated struct type. The extra space is taken from the padding
78  * area available from the original structure definitions.
79  *
80  * e.g. getting the address of the following extension to
81  * _sifields._rt from siginfo_t,
82  *
83  * struct bar {
84  * int foo;
85  * };
86  *
87  * would be noted as:
88  *
89  * siginfo_t si;
90  * struct bar *p = __cobalt_si_extra(&si, _rt, struct bar);
91  *
92  * This code is shared between kernel and user space. Proper
93  * definitions of siginfo_t and sigevent_t should have been read prior
94  * to including this file.
95  *
96  * CAUTION: this macro does not handle alignment issues for the extra
97  * data. The extra type definition should take care of this.
98  */
99 #ifdef __OPTIMIZE__
100 extern void *__siginfo_overflow(void);
101 static inline
102 const void *__check_si_overflow(size_t fldsz, size_t extrasz, const void *p)
103 {
104  siginfo_t *si __attribute__((unused));
105 
106  if (fldsz + extrasz <= sizeof(si->_sifields))
107  return p;
108 
109  return __siginfo_overflow();
110 }
111 #define __cobalt_si_extra(__si, __basefield, __type) \
112  ((__type *)__check_si_overflow(sizeof(__si->_sifields.__basefield), \
113  sizeof(__type), &(__si->_sifields.__basefield) + 1))
114 #else
115 #define __cobalt_si_extra(__si, __basefield, __type) \
116  ((__type *)((&__si->_sifields.__basefield) + 1))
117 #endif
118 
119 /* Same approach, this time for extending sigevent_t. */
120 
121 #ifdef __OPTIMIZE__
122 extern void *__sigevent_overflow(void);
123 static inline
124 const void *__check_sev_overflow(size_t fldsz, size_t extrasz, const void *p)
125 {
126  sigevent_t *sev __attribute__((unused));
127 
128  if (fldsz + extrasz <= sizeof(sev->_sigev_un))
129  return p;
130 
131  return __sigevent_overflow();
132 }
133 #define __cobalt_sev_extra(__sev, __basefield, __type) \
134  ((__type *)__check_sev_overflow(sizeof(__sev->_sigev_un.__basefield), \
135  sizeof(__type), &(__sev->_sigev_un.__basefield) + 1))
136 #else
137 #define __cobalt_sev_extra(__sev, __basefield, __type) \
138  ((__type *)((&__sev->_sigev_un.__basefield) + 1))
139 #endif
140 
141 #endif /* !_COBALT_UAPI_SIGNAL_H */
static int __attribute__((cold))
Test if a mutex structure contains a valid autoinitializer.
Definition: mutex.c:177