]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/include/_/cdefs.h
Update README and add CI-tests for minimal supported LLVM-version (10) (#302)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / include / _ / cdefs.h
1 // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions
5 // are met:
6 // 1. Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 //
12 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 // SUCH DAMAGE.
23
24 #ifndef ___CDEFS_H_
25 #define ___CDEFS_H_
26
27 // Version information.
28 #define __cloudlibc__ 1
29 #define __cloudlibc_major__ 0
30 #define __cloudlibc_minor__ 102
31
32 #ifdef __cplusplus
33 #define __BEGIN_DECLS extern "C" {
34 #define __END_DECLS }
35 #else
36 #define __BEGIN_DECLS
37 #define __END_DECLS
38 #endif
39
40 // Whether we should provide inline versions of functions. Due to C++'s
41 // support for namespaces, it is generally a bad idea to declare
42 // function macros.
43 #ifdef __cplusplus
44 #define _CLOUDLIBC_INLINE_FUNCTIONS 0
45 #else
46 #define _CLOUDLIBC_INLINE_FUNCTIONS 1
47 #endif
48
49 // Compiler-independent annotations.
50
51 #ifndef __has_builtin
52 #define __has_builtin(x) 0
53 #endif
54 #ifndef __has_extension
55 #define __has_extension(x) __has_feature(x)
56 #endif
57 #ifndef __has_feature
58 #define __has_feature(x) 0
59 #endif
60
61 #define __offsetof(type, member) __builtin_offsetof(type, member)
62 #define __containerof(ptr, type, member) \
63 ((type *)((char *)(ptr)-__offsetof(type, member)))
64
65 #define __extname(x) __asm__(x)
66 #define __malloc_like __attribute__((__malloc__))
67 #define __pure2 __attribute__((__const__))
68 #define __pure __attribute__((__pure__))
69 #define __section(x) __attribute__((__section__(x)))
70 #define __unused __attribute__((__unused__))
71 #define __used __attribute__((__used__))
72 #define __weak_symbol __attribute__((__weak__))
73
74 // Format string argument type checking.
75 #define __printflike(format, va) \
76 __attribute__((__format__(__printf__, format, va)))
77 #define __scanflike(format, va) \
78 __attribute__((__format__(__scanf__, format, va)))
79 // TODO(ed): Enable this once supported by LLVM:
80 // https://llvm.org/bugs/show_bug.cgi?id=16810
81 #define __wprintflike(format, va)
82 #define __wscanflike(format, va)
83
84 #define __strong_reference(oldsym, newsym) \
85 extern __typeof__(oldsym) newsym __attribute__((__alias__(#oldsym)))
86
87 // Convenience macros.
88
89 #define __arraycount(x) (sizeof(x) / sizeof((x)[0]))
90 #define __howmany(x, y) (((x) + (y)-1) / (y))
91 #define __rounddown(x, y) (((x) / (y)) * (y))
92 #define __roundup(x, y) ((((x) + (y)-1) / (y)) * (y))
93
94 // Lock annotations.
95
96 #if __has_extension(c_thread_safety_attributes)
97 #define __lock_annotate(x) __attribute__((x))
98 #else
99 #define __lock_annotate(x)
100 #endif
101
102 #define __lockable __lock_annotate(lockable)
103
104 #define __locks_exclusive(...) \
105 __lock_annotate(exclusive_lock_function(__VA_ARGS__))
106 #define __locks_shared(...) __lock_annotate(shared_lock_function(__VA_ARGS__))
107
108 #define __trylocks_exclusive(...) \
109 __lock_annotate(exclusive_trylock_function(__VA_ARGS__))
110 #define __trylocks_shared(...) \
111 __lock_annotate(shared_trylock_function(__VA_ARGS__))
112
113 #define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__))
114
115 #define __asserts_exclusive(...) \
116 __lock_annotate(assert_exclusive_lock(__VA_ARGS__))
117 #define __asserts_shared(...) __lock_annotate(assert_shared_lock(__VA_ARGS__))
118
119 #define __requires_exclusive(...) \
120 __lock_annotate(exclusive_locks_required(__VA_ARGS__))
121 #define __requires_shared(...) \
122 __lock_annotate(shared_locks_required(__VA_ARGS__))
123 #define __requires_unlocked(...) __lock_annotate(locks_excluded(__VA_ARGS__))
124
125 #define __no_lock_analysis __lock_annotate(no_thread_safety_analysis)
126
127 #define __guarded_by(x) __lock_annotate(guarded_by(x))
128 #define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x))
129
130 // Const preservation.
131 //
132 // Functions like strchr() allow you to silently discard a const
133 // qualifier from a string. This macro can be used to wrap such
134 // functions to propagate the const keyword where possible.
135 //
136 // This macro has many limitations, such as only being able to detect
137 // constness for void, char and wchar_t. For Clang, it also doesn't seem
138 // to work on string literals.
139
140 #define __preserve_const(type, name, arg, ...) \
141 _Generic(arg, \
142 const void *: (const type *)name(__VA_ARGS__), \
143 const char *: (const type *)name(__VA_ARGS__), \
144 const signed char *: (const type *)name(__VA_ARGS__), \
145 const unsigned char *: (const type *)name(__VA_ARGS__), \
146 const __wchar_t *: (const type *)name(__VA_ARGS__), \
147 default: name(__VA_ARGS__))
148
149 #endif