L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
compiler.h
Go to the documentation of this file.
1/*****************************************************************************/
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>,
10 * Frank Mehnert <fm3@os.inf.tu-dresden.de>,
11 * Jork Löser <jork@os.inf.tu-dresden.de>,
12 * Ronald Aigner <ra3@os.inf.tu-dresden.de>
13 * economic rights: Technische Universität Dresden (Germany)
14 *
15 * License: see LICENSE.spdx (in this directory or the directories above)
16 */
17/*****************************************************************************/
18#ifndef __L4_COMPILER_H__
19#define __L4_COMPILER_H__
20
21#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
22
29
34#ifndef L4_INLINE
35#ifndef __cplusplus
36# ifdef __OPTIMIZE__
37# define L4_INLINE_STATIC static __inline__
38# define L4_INLINE_EXTERN extern __inline__
39# ifdef __GNUC_STDC_INLINE__
40# define L4_INLINE L4_INLINE_STATIC
41# else
42# define L4_INLINE L4_INLINE_EXTERN
43# endif
44# else /* ! __OPTIMIZE__ */
45# define L4_INLINE static
46# endif /* ! __OPTIMIZE__ */
47#else /* __cplusplus */
48# define L4_INLINE inline
49#endif /* __cplusplus */
50#elif defined DOXYGEN
51# define L4_INLINE inline
52#endif /* L4_INLINE */
53
58#ifdef __OPTIMIZE__
59#define L4_ALWAYS_INLINE L4_INLINE __attribute__((__always_inline__))
60#elif defined(__cplusplus)
61#define L4_ALWAYS_INLINE inline __attribute__((__always_inline__))
62#else
63#define L4_ALWAYS_INLINE static inline __attribute__((__always_inline__))
64#endif
65
66
67#define L4_DECLARE_CONSTRUCTOR(func, prio) \
68 static inline __attribute__((constructor(prio))) void func ## _ctor_func(void) { func(); }
69
70
81
104
130
153#ifndef __cplusplus
154# define L4_NOTHROW__A __attribute__((nothrow))
155# define L4_NOTHROW
156# ifndef __BEGIN_DECLS
157# define __BEGIN_DECLS
158# endif
159# ifndef __END_DECLS
160# define __END_DECLS
161# endif
162# define L4_BEGIN_DECLS
163# define L4_END_DECLS
164# define L4_DEFAULT_PARAM(x)
165#else /* __cplusplus */
166# if __cplusplus >= 201103L
167# define L4_NOTHROW noexcept
168# else /* C++ < 11 */
169# define L4_NOTHROW throw()
170# endif
171# define L4_BEGIN_DECLS extern "C" {
172# define L4_END_DECLS }
173# if !defined __BEGIN_DECLS || defined DOXYGEN
174# define __BEGIN_DECLS extern "C" {
175# endif
176# if !defined __END_DECLS || defined DOXYGEN
177# define __END_DECLS }
178# endif
179# define L4_DEFAULT_PARAM(x) = x
180#endif /* __cplusplus */
181
182/* Deprecation hints during compile -- remove later (2025+) */
183#ifndef EXTERN_C
184#define EXTERN_C DO_NOT_USE_EXTERN_C_ANY_MORE
185#endif
186#ifndef EXTERN_C_BEGIN
187#define EXTERN_C_BEGIN DO_NOT_USE_EXTERN_C_BEGIN_ANY_MORE__USE_L4_BEGIN_DECLS
188#endif
189#ifndef EXTERN_C_END
190#define EXTERN_C_END DO_NOT_USE_EXTERN_C_END_ANY_MORE__USE_L4_END_DECLS
191#endif
192
197#if defined __cplusplus && __cplusplus >= 201402L
198# define L4_CONSTEXPR constexpr
199#else
200# define L4_CONSTEXPR
201#endif
202
207#define L4_NORETURN __attribute__((noreturn))
208
209#define L4_PURE __attribute__((pure))
210
215#define L4_NOINSTRUMENT __attribute__((no_instrument_function))
216#ifndef L4_HIDDEN
217# define L4_HIDDEN __attribute__((visibility("hidden")))
218#endif
219#if !defined L4_EXPORT || defined DOXYGEN
220# define L4_EXPORT __attribute__((visibility("default")))
221#endif
222#ifndef L4_EXPORT_TYPE
223# ifdef __cplusplus
224# define L4_EXPORT_TYPE __attribute__((visibility("default")))
225# else
226# define L4_EXPORT_TYPE
227# endif
228#endif
229#define L4_STRONG_ALIAS(name, aliasname) L4__STRONG_ALIAS(name, aliasname)
230#define L4_WEAK_ALIAS(name, aliasname) L4__WEAK_ALIAS(name, aliasname)
231#ifdef __clang__
232#define L4__STRONG_ALIAS(name, aliasname) \
233 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
234#define L4__WEAK_ALIAS(name, aliasname) \
235 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
236#else
237#define L4__STRONG_ALIAS(name, aliasname) \
238 extern __typeof (name) aliasname __attribute__ ((alias (#name), copy(name)));
239#define L4__WEAK_ALIAS(name, aliasname) \
240 extern __typeof (name) aliasname __attribute__ ((weak, alias (#name), copy(name)));
241#endif
242
250#if defined(__i386__) || defined(__amd64__) || \
251 defined(__arm__) || defined(__aarch64__) || \
252 defined(__mips__) || defined(__riscv) || \
253 defined(__powerpc__) || defined(__sparc__)
254# define L4_STACK_ALIGN __BIGGEST_ALIGNMENT__
255#else
256# error Define L4_STACK_ALIGN for this target!
257#endif
258
276#if defined(__i386__) || defined(__amd64__)
277L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
278{
279 if ((stack & (L4_STACK_ALIGN - 1)) == (L4_STACK_ALIGN - sizeof(unsigned long)))
280 return stack;
281 return (stack & ~(L4_STACK_ALIGN)) - sizeof(unsigned long);
282}
283#else
284L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
285{
286 return stack & ~(L4_STACK_ALIGN);
287}
288#endif
289
290#endif /* !__ASSEMBLY__ */
291
292#include <l4/sys/linkage.h>
293
294#define L4_LIKELY(x) __builtin_expect((x),1)
295#define L4_UNLIKELY(x) __builtin_expect((x),0)
296
297/* Make sure that the function is not removed by optimization. Without the
298 * "used" attribute, unreferenced static functions are removed. */
299#define L4_STICKY(x) __attribute__((used)) x
300#define L4_DEPRECATED(s) __attribute__((deprecated(s)))
301
302#ifndef static_assert
303# if !defined(__cplusplus)
304# define static_assert _Static_assert
305# elif __cplusplus < 201103L
306# define static_assert(x, y) \
307 extern int l4_static_assert[-(!(x))] __attribute__((unused))
308# endif
309#endif
310
311#define L4_stringify_helper(x) #x
312#define L4_stringify(x) L4_stringify_helper(x)
313
314#ifdef __has_builtin
315#define L4_HAS_BUILTIN(def) __has_builtin(def)
316#else
317#define L4_HAS_BUILTIN(def) 0
318#endif
319
320#ifndef __ASSEMBLER__
324L4_INLINE void l4_barrier(void);
325
329L4_INLINE void l4_mb(void);
330
334L4_INLINE void l4_wmb(void);
335
340
341
342/* Implementations */
344{
345 __asm__ __volatile__ ("" : : : "memory");
346}
347
348L4_INLINE void l4_mb(void)
349{
350 __asm__ __volatile__ ("" : : : "memory");
351}
352
354{
355 __asm__ __volatile__ ("" : : : "memory");
356}
357
359{
360 while (1)
361 l4_barrier();
362}
363#endif
364
366
367#endif /* !__L4_COMPILER_H__ */
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:353
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
void l4_barrier(void)
Memory barrier.
Definition compiler.h:343
void l4_mb(void)
Memory barrier.
Definition compiler.h:348
unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
Specify the desired alignment of the stack pointer.
Definition compiler.h:284
L4_NORETURN void l4_infinite_loop(void)
Infinite loop.
Definition compiler.h:358
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:207