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