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 language. */
14 #if defined __cplusplus
15 # define K_CPP
16 #endif
17
18 /* Detect the compiler family; fall back to GCC as default. */
19 #if defined(_MSC_VER)
20 # define K_MSVC
21 #elif defined(__TI_COMPILER_VERSION__)
22 # define K_TI_CCS
23 #else
24 # define K_GCC
25 #endif
26
27 /* Detect the OS; fall back to non-specific POSIX as default. */
28 #if defined(_WIN32) || defined(_WIN64)
29 # define K_WINDOWS
30 #elif defined(__TMS320C6X__)
31 # define K_TI_BIOS
32 # define K_DSP_BIOS /* old definition, provided for compatibility with FS<=6.1.33.x */
33 #elif defined(_WRS_KERNEL)
34 # define K_VX_KERNEL
35 #else
36 # define K_POSIX
37 # if defined(__linux__)
38 # define K_LINUX
39 # endif
40 # if defined(__APPLE__)
41 # define K_DARWIN
42 # endif
43 # if defined(__QNXNTO__)
44 # define K_QNX
45 # endif
46 #endif
47
48 /* Code profiling always enabled in debug builds. */
49 #if defined(K_DEBUG)
50 # define K_PROFILE
51 #endif
52
53 #if defined(K_DEBUG)
54 # define K_DEBUG_ENABLED (1)
55 #else
56 # define K_DEBUG_ENABLED (0)
57 #endif
58
59 #if defined(K_PROFILE)
60 # define K_PROFILE_ENABLED (1)
61 #else
62 # define K_PROFILE_ENABLED (0)
63 #endif
64
65 /*
66 * Include some C standard headers that we heavily rely on. This list is subject to change;
67 * dependent code should not assume that these headers will always be included here.
68 */
69 #if defined(K_MSVC) && defined(K_DEBUG)
70 # define _CRTDBG_MAP_ALLOC
71 # include <stdlib.h>
72 # include <crtdbg.h>
73 #else
74 # include <stdlib.h>
75 #endif
76
77 #include <stdarg.h>
78 #include <stddef.h>
79 #include <string.h>
80
81 /* Utilty macros for stringizing macro arguments. */
82 #define xkStringize(X) #X
83 #define xkStringizeDefine(X) xkStringize(X)
84
85 /*
86 * Detect pointer size; raise an eror if the pointer size cannot be detected. The behaviour
87 * can be overridden by defining K_POINTER_SIZE as a compiler flag.
88 */
89 #if !defined(K_POINTER_SIZE)
90 # if defined(_WIN64) || defined(WIN64)
91 # define K_POINTER_SIZE (8)
92 # elif defined(_WIN32) || defined(WIN32)
93 # define K_POINTER_SIZE (4)
94 # elif defined(__SIZEOF_POINTER__)
95 # define K_POINTER_SIZE (__SIZEOF_POINTER__)
96 # elif defined(__LP64__) || defined(__LLP64__) || defined(__SILP64__)
97 # define K_POINTER_SIZE (8)
98 # elif defined(__LP32__) || defined(__ILP32__)
99 # define K_POINTER_SIZE (4)
100 # elif defined(_TMS320C6X)
101 # define K_POINTER_SIZE (4)
102 # else
103 # error "Pointer size not detected; define K_POINTER_SIZE as compiler flag."
104 # endif
105 #endif
106
107 #if (K_POINTER_SIZE == 8)
108 # define K_POINTER_SHIFT (3)
109 #elif (K_POINTER_SIZE == 4)
110 # define K_POINTER_SHIFT (2)
111 #endif
112
113 /*
114 * Detect endianness; fall back to little endian as default. The behaviour can be overridden
115 * by defining K_ENDIANNESS as a compiler flag.
116 */
117 #if !defined(K_ENDIANNESS)
118 # if defined(K_GCC) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
119 # define K_ENDIANNESS (kENDIANNESS_BIG)
120 # else
121 # define K_ENDIANNESS (kENDIANNESS_LITTLE)
122 # endif
123 #endif
124
125 #if defined(K_CPP)
126 # define kExtern extern "C"
127 #else
128 # define kExtern extern
129 #endif
130
131 #if defined(K_GCC)
132 # define K_ATTRIBUTE_UNUSED __attribute__((unused))
133 #else
134 # define K_ATTRIBUTE_UNUSED
135 #endif
136
137 /* Define primitive data types and calling conventions. */
138 #if defined(K_MSVC)
139
140 # define xkCall __stdcall
141 # define xkDlCall __cdecl
142
143 # define kExportFx(TYPE) kExtern __declspec(dllexport) TYPE kCall
144 # define kImportFx(TYPE) kExtern __declspec(dllimport) TYPE kCall
145
146 # define kExportCx(TYPE) kExtern __declspec(dllexport) TYPE xkDlCall
147 # define kImportCx(TYPE) kExtern __declspec(dllimport) TYPE xkDlCall
148
149 # define kInFx(TYPE) kExtern TYPE kCall
150 # define kInCx(TYPE) kExtern TYPE kCall
151
152 # define kExportDx(TYPE) __declspec(dllexport) TYPE
153 # define kImportDx(TYPE) __declspec(dllimport) TYPE
154
155 # define kInDx(TYPE) TYPE
156
157 # if _MSC_VER >= 1500
158 # define kInline __inline
159 # else
160 # define kInline
161 # endif
162
163 typedef unsigned __int8 xk8u;
164 typedef unsigned __int16 xk16u;
165 typedef unsigned __int32 xk32u;
166 typedef unsigned __int64 xk64u;
167 typedef __int8 xk8s;
168 typedef __int16 xk16s;
169 typedef __int32 xk32s;
170 typedef __int64 xk64s;
171 typedef float xk32f;
172 typedef double xk64f;
173 typedef char xkChar;
174 typedef unsigned char xkByte;
175
176 # define xk64U(CONSTANT) (CONSTANT##ui64)
177 # define xk64S(CONSTANT) (CONSTANT##i64)
178
179 #elif defined(K_TI_CCS)
180
181 # define xkCall
182 # define xkDlCall
183
184 # define kExportFx(TYPE) kExtern TYPE kCall
185 # define kImportFx(TYPE) kExtern TYPE kCall
186
187 # define kExportCx(TYPE) kExtern TYPE kDlCall
188 # define kImportCx(TYPE) kExtern TYPE kDlCall
189
190 # define kInFx(TYPE) kExtern TYPE kCall
191 # define kInCx(TYPE) kExtern TYPE kCall
192
193 # define kExportDx(TYPE) TYPE
194 # define kImportDx(TYPE) TYPE
195
196 # define kInDx(TYPE) TYPE
197
198 # define kInline inline
199
200 typedef unsigned char xk8u;
201 typedef unsigned short xk16u;
202 typedef unsigned int xk32u;
203 typedef unsigned long long xk64u;
204 typedef signed char xk8s;
205 typedef signed short xk16s;
206 typedef signed int xk32s;
207 typedef signed long long xk64s;
208 typedef float xk32f;
209 typedef double xk64f;
210 typedef char xkChar;
211 typedef unsigned char xkByte;
212
213 # define xk64U(CONSTANT) (CONSTANT##LLU)
214 # define xk64S(CONSTANT) (CONSTANT##LL)
215
216 #else
217
218 # define xkCall
219 # define xkDlCall
220
221 # define kExportFx(TYPE) kExtern TYPE kCall
222 # define kImportFx(TYPE) kExtern TYPE kCall
223
224 # define kExportCx(TYPE) kExtern TYPE kDlCall
225 # define kImportCx(TYPE) kExtern TYPE kDlCall
226
227 # define kInFx(TYPE) kExtern TYPE kCall
228 # define kInCx(TYPE) kExtern TYPE kCall
229
230 # define kExportDx(TYPE) TYPE
231 # define kImportDx(TYPE) TYPE
232
233 # define kInDx(TYPE) TYPE
234
235 # define kInline inline
236
237 typedef unsigned char xk8u;
238 typedef unsigned short xk16u;
239 typedef unsigned int xk32u;
240 typedef unsigned long long xk64u;
241 typedef signed char xk8s;
242 typedef signed short xk16s;
243 typedef signed int xk32s;
244 typedef signed long long xk64s;
245 typedef float xk32f;
246 typedef double xk64f;
247 typedef char xkChar;
248 typedef unsigned char xkByte;
249
250 # define xk64U(CONSTANT) (CONSTANT##LLU)
251 # define xk64S(CONSTANT) (CONSTANT##LL)
252
253 #endif
254
255 #define xkInlineFx(TYPE) static kInline TYPE kCall
256
257 #if (K_POINTER_SIZE == 4)
258
259 typedef xk32u xkSize;
260 # define xkSIZE_MAX k32U_MAX
261
262 typedef xk32s xkSSize;
263 # define xkSSIZE_MIN k32S_MIN
264 # define xkSSIZE_MAX k32S_MAX
265
266 #elif (K_POINTER_SIZE == 8)
267
268 typedef xk64u xkSize;
269 # define xkSIZE_MAX k64U_MAX
270
271 typedef xk64s xkSSize;
272 # define xkSSIZE_MIN k64S_MIN
273 # define xkSSIZE_MAX k64S_MAX
274
275 #endif
276
277 #define kALIGN_ANY (3)
278 #define kALIGN_ANY_SIZE (1 << kALIGN_ANY)
279
280 #define kVarArgList va_list
281
282 #if defined(K_MSVC) || defined(K_TI_CCS)
283 # define kVarArgList_Start(ARG_PTR, PREV_PARAM) va_start(ARG_PTR, PREV_PARAM)
284 # define kVarArgList_End(ARG_PTR) va_end(ARG_PTR)
285 # define kVarArgList_Copy(ARG_PTR, SOURCE) ((ARG_PTR) = (SOURCE))
286 # define kVarArgList_Next(ARG_PTR, TYPE) va_arg(ARG_PTR, TYPE)
287 #else
288 # define kVarArgList_Start(ARG_PTR, PREV_PARAM) va_start(ARG_PTR, PREV_PARAM)
289 # define kVarArgList_End(ARG_PTR) va_end(ARG_PTR)
290 # define kVarArgList_Copy(ARG_PTR, SOURCE) va_copy(ARG_PTR, SOURCE)
291 # define kVarArgList_Next(ARG_PTR, TYPE) va_arg(ARG_PTR, TYPE)
292 #endif
293
294
295 /* Deprecation support. */
296 #if !defined(K_NO_DEPRECATION)
297 # if defined(K_MSVC)
298 # define xkDeprecate(SYMBOL) __pragma(deprecated(SYMBOL))
299 # else
300 # define xkDeprecate(SYMBOL)
301 # endif
302 #else
303 # define xkDeprecate(SYMBOL)
304 #endif
305
306 /* Warning support. */
307 #if defined(K_MSVC)
308
309 # define xkWarn(MESSAGE) __pragma(message(__FILE__ "(" xkStringizeDefine(__LINE__) "): warning: " MESSAGE))
310
311 #elif defined(K_GCC)
312
313 # define xkWarnHelper(x) _Pragma (#x)
314 # define xkWarn(MESSAGE) xkWarnHelper(GCC warning MESSAGE)
315
316 #else
317
318 # define xkWarn(MESSAGE)
319
320 #endif
321
322 /* Software breakpoint support. */
323 #if defined(K_DEBUG) && defined(K_MSVC)
324 # define xkDebugBreak() __debugbreak()
325 #else
326 # define xkDebugBreak()
327 #endif
328
329 #if defined (K_CPP)
330 # define kBeginCHeader() extern "C" {
331 # define kEndCHeader() }
332 #else
333 # define kBeginCHeader()
334 # define kEndCHeader()
335 #endif
336
337
338 /*
339 * Some source files require platform library headers to be included. And, at least
340 * for Windows, there can sometimes exist complicated rules about the particular order
341 * in which headers have to be included. The K_PLATFORM symbol helps to deal with
342 * these issues.
343 *
344 * Any kApi source file that requires platform headers should have #define K_PLATFORM as the
345 * first line in the source file. This ensures that the most common platform headers are
346 * included here, in the correct order.
347 */
348 #if defined(K_PLATFORM)
349
350 /*
351 * Common for all platforms.
352 */
353 # include <assert.h>
354
355 /*
356 * Platform specific includes.
357 */
358 # if defined(K_WINDOWS)
359 # include <winsock2.h>
360 # include <ws2tcpip.h>
361 # include <iphlpapi.h>
362 # include <windows.h>
363 # include <process.h>
364 # endif
365 # if defined(K_TI_BIOS)
366 # include <xdc/std.h>
367 # include <xdc/runtime/Types.h>
368 # include <xdc/runtime/Error.h>
369 # include <ti/sysbios/BIOS.h>
370 # include <ti/sysbios/knl/Clock.h>
371 # include <ti/sysbios/knl/Semaphore.h>
372 # include <ti/sysbios/knl/Task.h>
373 kBeginCHeader()
374 # include <netmain.h>
375 # include <nettools/nettools.h>
376 # include <nettools/inc/inet.h>
377 kEndCHeader()
378 # endif
379 # if defined(K_VX_KERNEL)
380 # include <vxWorks.h>
381 # include <sysLib.h>
382 # include <kernelLib.h>
383 # include <loadLib.h>
384 # include <intLib.h>
385 # include <symLib.h>
386 # include <sysSymTbl.h>
387 # include <taskLib.h>
388 # include <inline/semLibInline.h>
389 # include <unldLib.h>
390 # include <stdioLib.h>
391 # include <strLib.h>
392 # include <sockLib.h>
393 # include <inetLib.h>
394 # include <ioLib.h>
395 # include <fioLib.h>
396 # include <selectLib.h>
397 # include <netinet/in.h>
398 # include <netinet/tcp.h>
399 # include <wrapper/wrapperHostLib.h>
400 # include <netdb.h>
401 # include <sys/socket.h>
402 # include <net/if.h>
403 # include <net/if_ll.h>
404 # include <net/ethernet.h>
405 # include <ipnet/ipioctl.h>
406 # endif
407 # if defined(K_POSIX)
408 # include <errno.h>
409 # include <unistd.h>
410 # include <pthread.h>
411 # include <semaphore.h>
412 # include <sys/types.h>
413 # include <sys/stat.h>
414 # if defined(K_QNX)
415 # include <fcntl.h>
416 # else
417 # include <sys/fcntl.h>
418 # endif
419 # include <sys/socket.h>
420 # include <sys/select.h>
421 # include <sys/ioctl.h>
422 # include <sys/time.h>
423 # include <sys/timeb.h>
424 # include <netinet/in.h>
425 # include <netinet/tcp.h>
426 # include <dlfcn.h>
427 # include <dirent.h>
428 # include <net/if.h>
429 # include <netdb.h>
430 # endif
431 # if defined(K_DARWIN)
432 # include <ifaddrs.h>
433 # include <mach-o/dyld.h>
434 # include <libkern/OSAtomic.h>
435 # endif
436 # if defined (K_LINUX)
437 # include <signal.h>
438 # include <sys/prctl.h>
439 # include <sys/wait.h>
440 # include <linux/sockios.h>
441 # include <linux/ethtool.h>
442 # endif
443 #endif
444
445 #if defined(K_VX_KERNEL)
446 typedef xk32s xkAtomic32s;
447 typedef xkSSize xkAtomicPointer;
448 #else
449 typedef volatile xk32s xkAtomic32s;
450 typedef void* volatile xkAtomicPointer;
451 #endif
452
453 #if defined(K_PLATFORM)
454 # if defined(K_WINDOWS)
455 # define K_OS_INFINITE INFINITE
456 typedef DWORD kThreadId;
457 # elif defined(K_TI_BIOS)
458 # define K_OS_INFINITE ti_sysbios_BIOS_WAIT_FOREVER
459 typedef ti_sysbios_knl_Task_Handle kThreadId;
460 # elif defined(K_VX_KERNEL)
461 # define K_OS_INFINITE WAIT_FOREVER
462 typedef TASK_ID kThreadId;
463 # elif defined(K_POSIX)
464 # define K_OS_INFINITE kINFINITE /* no special "infinite" value */
465 typedef pthread_t kThreadId;
466 # endif
467 #endif
468
469 #if defined(K_VX_KERNEL)
470 # if defined(K_MAIN_DYNAMIC)
471 # undef kMain
472 # define kMain kMain_Dynamic
473 # else
474 # undef kMain
475 # define kMain kMain
476 # endif
477 # define kMAIN_DYNAMIC "kMain_Dynamic"
478 #else
479 # define kMAIN_DYNAMIC "kMain"
480 #endif
481
482
483 /*
484 * Deprecated (Stage 1): not recommended for further use, but not yet announced via kDeprecate
485 */
486
487 #if defined (K_CPP)
488
489 //[Deprecated] No longer required; provided that any C functions are properly annotated.
490 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
491 # define kBeginHeader() extern "C" {
492
493 //[Deprecated] No longer required; provided that any C functions are properly annotated.
494 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
495 # define kEndHeader() }
496
497 #else
498
499 //[Deprecated] No longer required; provided that any C functions are properly annotated.
500 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
501 # define kBeginHeader()
502
503 //[Deprecated] No longer required; provided that any C functions are properly annotated.
504 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
505 # define kEndHeader()
506
507 #endif
508
509 //[Deprecated] Replace with kVarArgList_Start
510 #define kVarArgList_Start_ kVarArgList_Start
511
512 //[Deprecated] Replace with kVarArgList_End
513 #define kVarArgList_End_ kVarArgList_End
514
515 //[Deprecated] Replace with kVarArgList_Copy
516 #define kVarArgList_Copy_ kVarArgList_Copy
517
518 //[Deprecated] Replace with kVarArgList_Next
519 #define kVarArgList_Next_ kVarArgList_Next
520
521 #endif