Loading...
Searching...
No Matches
compiler.h
Go to the documentation of this file.
/*****************************************************************************/
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>,
* Frank Mehnert <fm3@os.inf.tu-dresden.de>,
* Jork Löser <jork@os.inf.tu-dresden.de>,
* Ronald Aigner <ra3@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
/*****************************************************************************/
#ifndef __L4_COMPILER_H__
#define __L4_COMPILER_H__
#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
#ifndef L4_INLINE
#ifndef __cplusplus
# ifdef __OPTIMIZE__
# define L4_INLINE_STATIC static __inline__
# define L4_INLINE_EXTERN extern __inline__
# ifdef __GNUC_STDC_INLINE__
# define L4_INLINE L4_INLINE_STATIC
# else
# define L4_INLINE L4_INLINE_EXTERN
# endif
# else /* ! __OPTIMIZE__ */
# define L4_INLINE static
# endif /* ! __OPTIMIZE__ */
#else /* __cplusplus */
# define L4_INLINE inline
#endif /* __cplusplus */
#elif defined DOXYGEN
# define L4_INLINE inline
#endif /* L4_INLINE */
#define L4_ALWAYS_INLINE L4_INLINE __attribute__((__always_inline__))
#define L4_DECLARE_CONSTRUCTOR(func, prio) \
static inline __attribute__((constructor(prio))) void func ## _ctor_func(void) { func(); }
#ifndef __cplusplus
# define L4_NOTHROW__A __attribute__((nothrow))
# define L4_NOTHROW
# ifndef __BEGIN_DECLS
# define __BEGIN_DECLS
# endif
# ifndef __END_DECLS
# define __END_DECLS
# endif
# define L4_BEGIN_DECLS
# define L4_END_DECLS
# define L4_DEFAULT_PARAM(x)
#else /* __cplusplus */
# if __cplusplus >= 201103L
# define L4_NOTHROW noexcept
# else /* C++ < 11 */
# define L4_NOTHROW throw()
# endif
# define L4_BEGIN_DECLS extern "C" {
# define L4_END_DECLS }
# if !defined __BEGIN_DECLS || defined DOXYGEN
# define __BEGIN_DECLS extern "C" {
# endif
# if !defined __END_DECLS || defined DOXYGEN
# define __END_DECLS }
# endif
# define L4_DEFAULT_PARAM(x) = x
#endif /* __cplusplus */
/* Depration hints during compile -- remove later (2025+) */
#ifndef EXTERN_C
#define EXTERN_C DO_NOT_USE_EXTERN_C_ANY_MORE
#endif
#ifndef EXTERN_C_BEGIN
#define EXTERN_C_BEGIN DO_NOT_USE_EXTERN_C_BEGIN_ANY_MORE__USE_L4_BEGIN_DECLS
#endif
#ifndef EXTERN_C_END
#define EXTERN_C_END DO_NOT_USE_EXTERN_C_END_ANY_MORE__USE_L4_END_DECLS
#endif
#if defined __cplusplus && __cplusplus >= 201402L
# define L4_CONSTEXPR constexpr
#else
# define L4_CONSTEXPR
#endif
#define L4_NORETURN __attribute__((noreturn))
#define L4_PURE __attribute__((pure))
#define L4_NOINSTRUMENT __attribute__((no_instrument_function))
#ifndef L4_HIDDEN
# define L4_HIDDEN __attribute__((visibility("hidden")))
#endif
#if !defined L4_EXPORT || defined DOXYGEN
# define L4_EXPORT __attribute__((visibility("default")))
#endif
#ifndef L4_EXPORT_TYPE
# ifdef __cplusplus
# define L4_EXPORT_TYPE __attribute__((visibility("default")))
# else
# define L4_EXPORT_TYPE
# endif
#endif
#define L4_STRONG_ALIAS(name, aliasname) L4__STRONG_ALIAS(name, aliasname)
#ifdef __clang__
#define L4__STRONG_ALIAS(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((alias (#name)));
#else
#define L4__STRONG_ALIAS(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((alias (#name), copy(name)));
#endif
#if defined(__i386__) || defined(__amd64__) || \
defined(__arm__) || defined(__aarch64__) || \
defined(__mips__) || defined(__riscv) || \
defined(__powerpc__) || defined(__sparc__)
# define L4_STACK_ALIGN __BIGGEST_ALIGNMENT__
#else
# error Define L4_STACK_ALIGN for this target!
#endif
#if defined(__i386__) || defined(__amd64__)
L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
{
if ((stack & (L4_STACK_ALIGN - 1)) == (L4_STACK_ALIGN - sizeof(unsigned long)))
return stack;
return (stack & ~(L4_STACK_ALIGN)) - sizeof(unsigned long);
}
#else
L4_INLINE unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
{
return stack & ~(L4_STACK_ALIGN);
}
#endif
#endif /* !__ASSEMBLY__ */
#include <l4/sys/linkage.h>
#define L4_LIKELY(x) __builtin_expect((x),1)
#define L4_UNLIKELY(x) __builtin_expect((x),0)
/* Make sure that the function is not removed by optimization. Without the
* "used" attribute, unreferenced static functions are removed. */
#define L4_STICKY(x) __attribute__((used)) x
#define L4_DEPRECATED(s) __attribute__((deprecated(s)))
#ifndef static_assert
# if !defined(__cplusplus)
# define static_assert(x, y) _Static_assert(x, y)
# elif __cplusplus < 201103L
# define static_assert(x, y) \
extern int l4_static_assert[-(!(x))] __attribute__((unused))
# endif
#endif
#define L4_stringify_helper(x) #x
#define L4_stringify(x) L4_stringify_helper(x)
#ifdef __has_builtin
#define L4_HAS_BUILTIN(def) __has_builtin(def)
#else
#define L4_HAS_BUILTIN(def) 0
#endif
#ifndef __ASSEMBLER__
L4_INLINE void l4_barrier(void);
L4_INLINE void l4_mb(void);
L4_INLINE void l4_wmb(void);
L4_INLINE L4_NORETURN void l4_infinite_loop(void);
/* Implementations */
L4_INLINE void l4_barrier(void)
{
__asm__ __volatile__ ("" : : : "memory");
}
L4_INLINE void l4_mb(void)
{
__asm__ __volatile__ ("" : : : "memory");
}
L4_INLINE void l4_wmb(void)
{
__asm__ __volatile__ ("" : : : "memory");
}
L4_INLINE L4_NORETURN void l4_infinite_loop(void)
{
while (1)
l4_barrier();
}
#endif
#endif /* !__L4_COMPILER_H__ */
l4_wmb
void l4_wmb(void)
Write memory barrier.
Definition compiler.h:342
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
l4_barrier
void l4_barrier(void)
Memory barrier.
Definition compiler.h:332
l4_mb
void l4_mb(void)
Memory barrier.
Definition compiler.h:337
l4_align_stack_for_direct_fncall
unsigned long l4_align_stack_for_direct_fncall(unsigned long stack)
Specify the desired alignment of the stack pointer.
Definition compiler.h:273
l4_infinite_loop
L4_NORETURN void l4_infinite_loop(void)
Infinite loop.
Definition compiler.h:347
L4_NORETURN
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:201