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