kernel_defines.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef KERNEL_DEFINES_H
20 #define KERNEL_DEFINES_H
21 
22 #include <stddef.h>
23 
24 #ifdef __cplusplus
25  extern "C" {
26 #endif
27 
41 #if __STDC_VERSION__ >= 201112L
42 # define container_of(PTR, TYPE, MEMBER) \
43  (_Generic((PTR), \
44  const __typeof__ (((TYPE *) 0)->MEMBER) *: \
45  ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))), \
46  __typeof__ (((TYPE *) 0)->MEMBER) *: \
47  ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) \
48  ))
49 #elif defined __GNUC__
50 # define container_of(PTR, TYPE, MEMBER) \
51  (__extension__ ({ \
52  __extension__ const __typeof__ (((TYPE *) 0)->MEMBER) *__m____ = (PTR); \
53  ((TYPE *) ((char *) __m____ - offsetof(TYPE, MEMBER))); \
54  }))
55 #else
56 # define container_of(PTR, TYPE, MEMBER) \
57  ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER)))
58 #endif
59 
65 #ifdef __GNUC__
66 #define NORETURN __attribute__((noreturn))
67 #else
68 #define NORETURN
69 #endif
70 
77 #ifdef __GNUC__
78 #define CONST __attribute__((const))
79 #else
80 #define CONST
81 #endif
82 
90 #ifdef __GNUC__
91 #define PURE __attribute__((pure))
92 #else
93 #define PURE
94 #endif
95 
103 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 5)
104 #define UNREACHABLE() __builtin_unreachable()
105 #else
106 #define UNREACHABLE() do { /* nothing */ } while (1)
107 #endif
108 
115 #define ALIGN_OF(T) (offsetof(struct { char c; T t; }, t))
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif /* KERNEL_DEFINES_H */
122