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
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#define L4_ALWAYS_INLINE L4_INLINE __attribute__((__always_inline__))
59
60
61#define L4_DECLARE_CONSTRUCTOR(func, prio) \
62 static inline __attribute__((constructor(prio))) void func ## _ctor_func(void) { func(); }
63
64
147#ifndef __cplusplus
148# define L4_NOTHROW__A __attribute__((nothrow))
149# define L4_NOTHROW
150# ifndef __BEGIN_DECLS
151# define __BEGIN_DECLS
152# endif
153# ifndef __END_DECLS
154# define __END_DECLS
155# endif
156# define L4_DEFAULT_PARAM(x)
157#else /* __cplusplus */
158# if __cplusplus >= 201103L
159# define L4_NOTHROW noexcept
160# else /* C++ < 11 */
161# define L4_NOTHROW throw()
162# endif
163# if !defined __BEGIN_DECLS || defined DOXYGEN
164# define __BEGIN_DECLS extern "C" {
165# endif
166# if !defined __END_DECLS || defined DOXYGEN
167# define __END_DECLS }
168# endif
169# define L4_DEFAULT_PARAM(x) = x
170#endif /* __cplusplus */
171
172/* Depration hints during compile -- remove later (2025+) */
173#ifndef EXTERN_C
174#define EXTERN_C DO_NOT_USE_EXTERN_C_ANY_MORE
175#endif
176#ifndef EXTERN_C_BEGIN
177#define EXTERN_C_BEGIN DO_NOT_USE_EXTERN_C_BEGIN_ANY_MORE__USE__BEGIN_DECLS
178#endif
179#ifndef EXTERN_C_END
180#define EXTERN_C_END DO_NOT_USE_EXTERN_C_END_ANY_MORE__USE__END_DECLS
181#endif
182
187#if defined __cplusplus && __cplusplus >= 201402L
188# define L4_CONSTEXPR constexpr
189#else
190# define L4_CONSTEXPR
191#endif
192
197#define L4_NORETURN __attribute__((noreturn))
198
199#define L4_PURE __attribute__((pure))
200
205#define L4_NOINSTRUMENT __attribute__((no_instrument_function))
206#ifndef L4_HIDDEN
207# define L4_HIDDEN __attribute__((visibility("hidden")))
208#endif
209#if !defined L4_EXPORT || defined DOXYGEN
210# define L4_EXPORT __attribute__((visibility("default")))
211#endif
212#ifndef L4_EXPORT_TYPE
213# ifdef __cplusplus
214# define L4_EXPORT_TYPE __attribute__((visibility("default")))
215# else
216# define L4_EXPORT_TYPE
217# endif
218#endif
219#define L4_STRONG_ALIAS(name, aliasname) L4__STRONG_ALIAS(name, aliasname)
220#define L4__STRONG_ALIAS(name, aliasname) \
221 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
222
230#if defined(__i386__) || defined(__amd64__) || \
231 defined(__arm__) || defined(__aarch64__) || \
232 defined(__mips__) || defined(__riscv) || \
233 defined(__powerpc__) || defined(__sparc__)
234# define L4_STACK_ALIGN __BIGGEST_ALIGNMENT__
235#else
236# error Define L4_STACK_ALIGN for this target!
237#endif
238
256#if defined(__i386__) || defined(__amd64__)
257L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
258{
259 if ((stack & (L4_STACK_ALIGN - 1)) == (L4_STACK_ALIGN - sizeof(unsigned long)))
260 return stack;
261 return (stack & ~(L4_STACK_ALIGN)) - sizeof(unsigned long);
262}
263#else
264L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
265{
266 return stack & ~(L4_STACK_ALIGN);
267}
268#endif
269
270#endif /* !__ASSEMBLY__ */
271
272#include <l4/sys/linkage.h>
273
274#define L4_LIKELY(x) __builtin_expect((x),1)
275#define L4_UNLIKELY(x) __builtin_expect((x),0)
276
277/* Make sure that the function is not removed by optimization. Without the
278 * "used" attribute, unreferenced static functions are removed. */
279#define L4_STICKY(x) __attribute__((used)) x
280#define L4_DEPRECATED(s) __attribute__((deprecated(s)))
281
282#ifndef static_assert
283# if !defined(__cplusplus)
284# define static_assert(x, y) _Static_assert(x, y)
285# elif __cplusplus < 201103L
286# define static_assert(x, y) \
287 extern int l4_static_assert[-(!(x))] __attribute__((unused))
288# endif
289#endif
290
291#define L4_stringify_helper(x) #x
292#define L4_stringify(x) L4_stringify_helper(x)
293
294#ifdef __has_builtin
295#define L4_HAS_BUILTIN(def) __has_builtin(def)
296#else
297#define L4_HAS_BUILTIN(def) 0
298#endif
299
300#ifndef __ASSEMBLER__
304L4_INLINE void l4_barrier(void);
305
309L4_INLINE void l4_mb(void);
310
314L4_INLINE void l4_wmb(void);
315
320
321
322/* Implementations */
324{
325 __asm__ __volatile__ ("" : : : "memory");
326}
327
328L4_INLINE void l4_mb(void)
329{
330 __asm__ __volatile__ ("" : : : "memory");
331}
332
334{
335 __asm__ __volatile__ ("" : : : "memory");
336}
337
339{
340 while (1)
341 l4_barrier();
342}
343#endif
344
347#endif /* !__L4_COMPILER_H__ */
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:333
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
void l4_barrier(void)
Memory barrier.
Definition compiler.h:323
void l4_mb(void)
Memory barrier.
Definition compiler.h:328
unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
Specify the desired alignment of the stack pointer.
Definition compiler.h:264
L4_NORETURN void l4_infinite_loop(void)
Infinite loop.
Definition compiler.h:338
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:197