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 <ws2tcpip.h>
374 # include <iphlpapi.h>
375 # include <windows.h>
376 # include <process.h>
377 # endif
378 # if defined(K_TI_BIOS)
379 # include <xdc/std.h>
380 # include <xdc/runtime/Types.h>
381 # include <xdc/runtime/Error.h>
382 # include <ti/sysbios/BIOS.h>
383 # include <ti/sysbios/knl/Clock.h>
384 # include <ti/sysbios/knl/Semaphore.h>
385 # include <ti/sysbios/knl/Task.h>
386 kBeginCHeader()
387 # include <netmain.h>
388 # include <nettools/nettools.h>
389 # include <nettools/inc/inet.h>
390 kEndCHeader()
391 # endif
392 # if defined(K_VX_KERNEL)
393 # if defined(K_DEBUG)
394 # pragma GCC optimize ("O2")
395 # include <errno.h> /* work-around for error "ldarm: error in obj.o (.eh_frame); no .eh_frame_hdr table will be created." */
396 # pragma GCC reset_options
397 # endif
398 # include <vxWorks.h>
399 # include <sysLib.h>
400 # include <kernelLib.h>
401 # include <loadLib.h>
402 # include <intLib.h>
403 # include <symLib.h>
404 # include <sysSymTbl.h>
405 # include <taskLib.h>
406 # include <inline/semLibInline.h>
407 # include <unldLib.h>
408 # include <stdioLib.h>
409 # include <strLib.h>
410 # include <sockLib.h>
411 # include <inetLib.h>
412 # include <ioLib.h>
413 # include <fioLib.h>
414 # include <selectLib.h>
415 # include <netinet/in.h>
416 # include <netinet/tcp.h>
417 # include <wrapper/wrapperHostLib.h>
418 # include <netdb.h>
419 # include <sys/socket.h>
420 # include <net/if.h>
421 # include <net/if_ll.h>
422 # include <net/ethernet.h>
423 # include <ipnet/ipioctl.h>
424 # endif
425 # if defined(K_POSIX)
426 # include <errno.h>
427 # include <unistd.h>
428 # include <pthread.h>
429 # include <semaphore.h>
430 # include <sys/types.h>
431 # include <sys/stat.h>
432 # if defined(K_QNX)
433 # include <fcntl.h>
434 # else
435 # include <sys/fcntl.h>
436 # endif
437 # include <sys/socket.h>
438 # include <sys/select.h>
439 # include <sys/ioctl.h>
440 # include <sys/time.h>
441 # include <sys/timeb.h>
442 # include <netinet/in.h>
443 # include <netinet/tcp.h>
444 # include <dlfcn.h>
445 # include <dirent.h>
446 # include <net/if.h>
447 # include <netdb.h>
448 # endif
449 # if defined(K_DARWIN)
450 # include <ifaddrs.h>
451 # include <mach-o/dyld.h>
452 # endif
453 # if defined (K_LINUX)
454 # include <signal.h>
455 # include <sys/prctl.h>
456 # include <sys/wait.h>
457 # include <linux/sockios.h>
458 # include <linux/ethtool.h>
459 # endif
460 #endif
461
462 #if defined(K_VX_KERNEL)
463 typedef xk32s xkAtomic32s;
464 typedef xkSSize xkAtomicPointer;
465 #else
466 typedef volatile xk32s xkAtomic32s;
467 typedef void* volatile xkAtomicPointer;
468 #endif
469
470 #if defined(K_PLATFORM)
471 # if defined(K_WINDOWS)
472 # define kOS_INFINITE INFINITE
473 typedef DWORD kThreadId;
474 # elif defined(K_TI_BIOS)
475 # define kOS_INFINITE ti_sysbios_BIOS_WAIT_FOREVER
476 typedef ti_sysbios_knl_Task_Handle kThreadId;
477 # elif defined(K_VX_KERNEL)
478 # define kOS_INFINITE WAIT_FOREVER
479 typedef TASK_ID kThreadId;
480 # elif defined(K_POSIX)
481 # define kOS_INFINITE 0 /* no special "infinite" value */
482 typedef pthread_t kThreadId;
483 # endif
484 #endif
485
486 #if defined(K_VX_KERNEL)
487 # if defined(K_MAIN_DYNAMIC)
488 # undef kMain
489 # define kMain kMain_Dynamic
490 # else
491 # undef kMain
492 # define kMain kMain
493 # endif
494 # define kMAIN_DYNAMIC "kMain_Dynamic"
495 #else
496 # define kMAIN_DYNAMIC "kMain"
497 #endif
498
499
500 /*
501 * Deprecated (Stage 1): not recommended for further use, but not yet announced via kDeprecate
502 */
503
504 #if defined (K_CPP)
505
506 //[Deprecated] No longer required; provided that any C functions are properly annotated.
507 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
508 # define kBeginHeader() extern "C" {
509
510 //[Deprecated] No longer required; provided that any C functions are properly annotated.
511 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
512 # define kEndHeader() }
513
514 #else
515
516 //[Deprecated] No longer required; provided that any C functions are properly annotated.
517 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
518 # define kBeginHeader()
519
520 //[Deprecated] No longer required; provided that any C functions are properly annotated.
521 //Use kBeginCHeader/kEndCHeader to include a C header from C++ if the header was not desiged to support C++.
522 # define kEndHeader()
523
524 #endif
525
526 /*
527 * Deprecated (Stage 2): announced via kDeprecate
528 */
529
530 //kDeprecated not defined yet...
531 #define xkDeprecateSymbol(SYMBOL) xkDeprecate(#SYMBOL)
532
533 //[Deprecated] Replace with kVarArgList_Start
534 #define kVarArgList_Start_ kVarArgList_Start
535 xkDeprecateSymbol(kVarArgList_Start_)
536
537 //[Deprecated] Replace with kVarArgList_End
538 #define kVarArgList_End_ kVarArgList_End
539 xkDeprecateSymbol(kVarArgList_End_)
540
541 //[Deprecated] Replace with kVarArgList_Copy
542 #define kVarArgList_Copy_ kVarArgList_Copy
543 xkDeprecateSymbol(kVarArgList_Copy_)
544
545 //[Deprecated] Replace with kVarArgList_Next
546 #define kVarArgList_Next_ kVarArgList_Next
547 xkDeprecateSymbol(kVarArgList_Next_)
548
549 #endif