Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kApiCfg.h
Go to the documentation of this file.
1
10 #ifndef K_API_API_CFG_H
11 #define K_API_API_CFG_H
12
13 /* Detect the compiler family; fall back to GCC as default. */
14 #if defined(_MSC_VER)
15 # define K_MSVC
16 #elif defined(__TI_COMPILER_VERSION__)
17 # define K_TI_CCS
18 #else
19 # define K_GCC
20 #endif
21
22 /* Detect the OS; fall back to non-specific POSIX as default. */
23 #if defined(_WIN32) || defined(_WIN64)
24 # define K_WINDOWS
25 #elif defined(K_TI_CCS)
26 # define K_DSP_BIOS
27 #elif defined(_WRS_KERNEL)
28 # define K_VX_KERNEL
29 #else
30 # define K_POSIX
31 # if defined(__linux__)
32 # define K_LINUX
33 # endif
34 # if defined(__APPLE__)
35 # define K_DARWIN
36 # endif
37 # if defined(__QNXNTO__)
38 # define K_QNX
39 # endif
40 #endif
41
42 #if defined(K_DEBUG)
43 # define K_DEBUG_ENABLED (1)
44 #else
45 # define K_DEBUG_ENABLED (0)
46 #endif
47
48 #if defined(K_PROFILE)
49 # define K_PROFILE_ENABLED (1)
50 #else
51 # define K_PROFILE_ENABLED (0)
52 #endif
53
54 /*
55 * Include some C standard headers that we heavily rely on. This list is subject to change;
56 * dependent code should not assume that these headers will always be included here.
57 */
58 #if defined(K_MSVC) && defined(K_DEBUG)
59 # define _CRTDBG_MAP_ALLOC
60 # include <stdlib.h>
61 # include <crtdbg.h>
62 #else
63 # include <stdlib.h>
64 #endif
65
66 #include <stdarg.h>
67 #include <stddef.h>
68 #include <string.h>
69 #include <assert.h>
70
71 /*
72 * Detect pointer size; raise an eror if the pointer size cannot be detected. The behaviour
73 * can be overridden by defining K_POINTER_SIZE as a compiler flag.
74 */
75 #if !defined(K_POINTER_SIZE)
76 # if defined(_WIN64) || defined(WIN64)
77 # define K_POINTER_SIZE (8)
78 # elif defined(_WIN32) || defined(WIN32)
79 # define K_POINTER_SIZE (4)
80 # elif defined(__SIZEOF_POINTER__)
81 # define K_POINTER_SIZE (__SIZEOF_POINTER__)
82 # elif defined(__LP64__) || defined(__LLP64__) || defined(__SILP64__)
83 # define K_POINTER_SIZE (8)
84 # elif defined(__LP32__) || defined(__ILP32__)
85 # define K_POINTER_SIZE (4)
86 # elif defined(_TMS320C6X)
87 # define K_POINTER_SIZE (4)
88 # else
89 # error "Pointer size not detected; define K_POINTER_SIZE as compiler flag."
90 # endif
91 #endif
92
93 /*
94 * Detect endianness; fall back to little endian as default. The behaviour can be overridden
95 * by defining K_ENDIANNESS as a compiler flag.
96 */
97 #if !defined(K_ENDIANNESS)
98 # if defined(K_GCC) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
99 # define K_ENDIANNESS (kENDIANNESS_BIG)
100 # else
101 # define K_ENDIANNESS (kENDIANNESS_LITTLE)
102 # endif
103 #endif
104
105 /* Define primative data types and calling conventions. */
106 #if defined(K_MSVC)
107
108 # define kxCall __stdcall
109 # define kxDlCall __cdecl
110
111 # define kExportFx(TYPE) __declspec(dllexport) TYPE kCall
112 # define kImportFx(TYPE) __declspec(dllimport) TYPE kCall
113
114 # define kExportCx(TYPE) __declspec(dllexport) TYPE kxDlCall
115 # define kImportCx(TYPE) __declspec(dllimport) TYPE kxDlCall
116
117 # define kInFx(TYPE) TYPE kCall
118 # define kInCx(TYPE) TYPE kCall
119
120 # define kExportDx(TYPE) __declspec(dllexport) TYPE
121 # define kImportDx(TYPE) __declspec(dllimport) TYPE
122
123 # define kInDx(TYPE) TYPE
124
125 typedef unsigned __int8 kx8u;
126 typedef unsigned __int16 kx16u;
127 typedef unsigned __int32 kx32u;
128 typedef unsigned __int64 kx64u;
129 typedef __int8 kx8s;
130 typedef __int16 kx16s;
131 typedef __int32 kx32s;
132 typedef __int64 kx64s;
133 typedef float kx32f;
134 typedef double kx64f;
135 typedef char kxChar;
136 typedef unsigned char kxByte;
137
138 # define kx64U(CONSTANT) (CONSTANT##ui64)
139 # define kx64S(CONSTANT) (CONSTANT##i64)
140
141 #elif defined(K_TI_CCS)
142
143 # define kxCall
144 # define kxDlCall
145
146 # define kExportFx(TYPE) TYPE kCall
147 # define kImportFx(TYPE) TYPE kCall
148
149 # define kExportCx(TYPE) TYPE kDlCall
150 # define kImportCx(TYPE) TYPE kDlCall
151
152 # define kInFx(TYPE) TYPE kCall
153 # define kInCx(TYPE) TYPE kCall
154
155 # define kExportDx(TYPE) TYPE
156 # define kImportDx(TYPE) TYPE
157
158 # define kInDx(TYPE) TYPE
159
160 typedef unsigned char kx8u;
161 typedef unsigned short kx16u;
162 typedef unsigned int kx32u;
163 typedef unsigned long long kx64u;
164 typedef signed char kx8s;
165 typedef signed short kx16s;
166 typedef signed int kx32s;
167 typedef signed long long kx64s;
168 typedef float kx32f;
169 typedef double kx64f;
170 typedef char kxChar;
171 typedef unsigned char kxByte;
172
173 # define kx64U(CONSTANT) (CONSTANT##LLU)
174 # define kx64S(CONSTANT) (CONSTANT##LL)
175
176 #else
177
178 # define kxCall
179 # define kxDlCall
180
181 # define kExportFx(TYPE) TYPE kCall
182 # define kImportFx(TYPE) TYPE kCall
183
184 # define kExportCx(TYPE) TYPE kDlCall
185 # define kImportCx(TYPE) TYPE kDlCall
186
187 # define kInFx(TYPE) TYPE kCall
188 # define kInCx(TYPE) TYPE kCall
189
190 # define kExportDx(TYPE) TYPE
191 # define kImportDx(TYPE) TYPE
192
193 # define kInDx(TYPE) TYPE
194
195 typedef unsigned char kx8u;
196 typedef unsigned short kx16u;
197 typedef unsigned int kx32u;
198 typedef unsigned long long kx64u;
199 typedef signed char kx8s;
200 typedef signed short kx16s;
201 typedef signed int kx32s;
202 typedef signed long long kx64s;
203 typedef float kx32f;
204 typedef double kx64f;
205 typedef char kxChar;
206 typedef unsigned char kxByte;
207
208 # define kx64U(CONSTANT) (CONSTANT##LLU)
209 # define kx64S(CONSTANT) (CONSTANT##LL)
210
211 #endif
212
213 #if (K_POINTER_SIZE == 4)
214
215 typedef kx32u kxSize;
216 # define kxSIZE_MAX k32U_MAX
217
218 typedef kx32s kxSSize;
219 # define kxSSIZE_MIN k32S_MIN
220 # define kxSSIZE_MAX k32S_MAX
221
222 #elif (K_POINTER_SIZE == 8)
223
224 typedef kx64u kxSize;
225 # define kxSIZE_MAX k64U_MAX
226
227 typedef kx64s kxSSize;
228 # define kxSSIZE_MIN k64S_MIN
229 # define kxSSIZE_MAX k64S_MAX
230
231 #endif
232
233 #define kALIGN_ANY (3)
234 #define kALIGN_ANY_SIZE (1 << kALIGN_ANY)
235
236 #define kVarArgList va_list
237
238 #if defined(K_MSVC) || defined(K_TI_CCS)
239 # define kVarArgList_Start_(ARG_PTR, PREV_PARAM) va_start(ARG_PTR, PREV_PARAM)
240 # define kVarArgList_End_(ARG_PTR) va_end(ARG_PTR)
241 # define kVarArgList_Copy_(ARG_PTR, SOURCE) ((ARG_PTR) = (SOURCE))
242 # define kVarArgList_Next_(ARG_PTR, TYPE) va_arg(ARG_PTR, TYPE)
243 #else
244 # define kVarArgList_Start_(ARG_PTR, PREV_PARAM) va_start(ARG_PTR, PREV_PARAM)
245 # define kVarArgList_End_(ARG_PTR) va_end(ARG_PTR)
246 # define kVarArgList_Copy_(ARG_PTR, SOURCE) va_copy(ARG_PTR, SOURCE)
247 # define kVarArgList_Next_(ARG_PTR, TYPE) va_arg(ARG_PTR, TYPE)
248 #endif
249
250 /*
251 * The kBeginHeader/kEndHeader macros are used to wrap header files. This enables any required
252 * definitions, pragmas, etc., to be pushed/popped as part of header processing.
253 */
254 #if defined (__cplusplus)
255 # define kBeginHeader() extern "C" {
256 # define kEndHeader() }
257 #else
258 # define kBeginHeader()
259 # define kEndHeader()
260 #endif
261
262 /*
263 * Some source files require platform library headers to be included. And, at least
264 * for Windows, there can sometimes exist complicated rules about the particular order
265 * in which headers have to be included. The K_PLATFORM symbol helps to deal with
266 * these issues.
267 *
268 * Any kApi source file that requires platform headers should have #define K_PLATFORM as the
269 * first line in the source file. This ensures that the most common platform headers are
270 * included here, in the correct order.
271 */
272 #if defined(K_PLATFORM)
273 # if defined(K_WINDOWS)
274 # include <winsock2.h>
275 # include <ws2tcpip.h>
276 # include <iphlpapi.h>
277 # include <windows.h>
278 # include <process.h>
279 # endif
280 # if defined(K_DSP_BIOS)
281 # include <std.h>
282 # include <gbl.h>
283 # include <clk.h>
284 # include <tsk.h>
285 # include <lck.h>
286 # include <sem.h>
287 # include <prd.h>
288 # include <netmain.h>
289 # include <nettools/nettools.h>
290 # include <nettools/inc/inet.h>
291 # endif
292 # if defined(K_VX_KERNEL)
293 # include <vxWorks.h>
294 # include <sysLib.h>
295 # include <kernelLib.h>
296 # include <intLib.h>
297 # include <taskLib.h>
298 # include <stdioLib.h>
299 # include <strLib.h>
300 # include <sockLib.h>
301 # include <inetLib.h>
302 # include <ioLib.h>
303 # include <fioLib.h>
304 # include <selectLib.h>
305 # include <netinet/in.h>
306 # include <netinet/tcp.h>
307 # include <wrapper/wrapperHostLib.h>
308 # include <netdb.h>
309 # include <sys/socket.h>
310 # include <net/if.h>
311 # include <ipnet/ipioctl.h>
312 # endif
313 # if defined(K_POSIX)
314 # include <errno.h>
315 # include <unistd.h>
316 # include <pthread.h>
317 # include <semaphore.h>
318 # include <sys/types.h>
319 # include <sys/stat.h>
320 # include <sys/fcntl.h>
321 # include <sys/socket.h>
322 # include <sys/select.h>
323 # include <sys/ioctl.h>
324 # include <sys/time.h>
325 # include <sys/timeb.h>
326 # include <netinet/in.h>
327 # include <netinet/tcp.h>
328 # include <dlfcn.h>
329 # include <dirent.h>
330 # include <net/if.h>
331 # include <netdb.h>
332 # endif
333 # if defined(K_DARWIN)
334 # include <ifaddrs.h>
335 # include <mach-o/dyld.h>
336 # include <libkern/OSAtomic.h>
337 # endif
338 #endif
339
340 #if defined(K_VX_KERNEL)
341 # include <base/b_atomic_t.h>
342
343 typedef atomic32Val_t kxAtomic32s;
344 typedef atomicVal_t kxAtomicPointer;
345 #else
346 typedef volatile kx32s kxAtomic32s;
347 typedef void* volatile kxAtomicPointer;
348 #endif
349
350 #if defined(K_PLATFORM)
351 # if defined(K_WINDOWS)
352 # define K_OS_INFINITE INFINITE
353 typedef DWORD kThreadId;
354 # elif defined(K_DSP_BIOS)
355 # define K_OS_INFINITE SYS_FOREVER
356 typedef TSK_Handle kThreadId;
357 # elif defined(K_VX_KERNEL)
358 # define K_OS_INFINITE WAIT_FOREVER
359 typedef TASK_ID kThreadId;
360 # elif defined(K_POSIX)
361 # define K_OS_INFINITE kINFINITE /* no special "infinite" value */
362 typedef pthread_t kThreadId;
363 # endif
364 #endif
365
366 #if defined(K_COMPAT_5)
367
368 /* Simple renaming (handled by porting script). */
369 # define KAPI_ALIGN_SHIFT kALIGN_ANY
370 # define KAPI_ALIGN kALIGN_ANY_SIZE
371
372 /*
373 * These flags probably shouldn't exist; but since they're going to be
374 * required for some time (FS 5 compatibility), we may as well use an
375 * up-to-date style.
376 */
377 # if defined(K_DSP)
378 # define KAPI_DSP
379 # elif defined(K_HOST)
380 # define KAPI_HOST
381 # elif defined(K_VIRTUAL)
382 # define KAPI_VIRTUAL
383 # endif
384
385 # if defined(K_WINDOWS)
386 # define KAPI_MS_WINDOWS
387 # elif defined(K_DSP_BIOS)
388 # define KAPI_TI_DSP_BIOS
389 # endif
390
391 #endif
392
393 #endif