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