3 * @brief Include O/S headers and smooth out per-O/S differences
6 * Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
8 * This software is distributed under commercial and open source licenses.
9 * You may use the GPL open source license described below or you may acquire
10 * a commercial license from Mbedthis Software. You agree to be fully bound
11 * by the terms of either license. Consult the LICENSE.TXT distributed with
12 * this software for full details.
14 * This software is open source; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See the GNU General Public License for more
18 * details at: http://www.mbedthis.com/downloads/gplLicense.html
20 * This program is distributed WITHOUT ANY WARRANTY; without even the
21 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * This GPL license does NOT permit incorporating this software into
24 * proprietary programs. If you are unable to comply with the GPL, you must
25 * acquire a commercial license to use this software. Commercial licenses
26 * for this software and support services are available from Mbedthis
27 * Software at http://www.mbedthis.com
30 ******************************* Documentation *********************************
32 * This header is part of the Mbedthis Portable Runtime and aims to include
33 * all necessary O/S headers and to unify the constants and declarations
34 * required by Mbedthis products. It can be included by C or C++ programs.
36 ********************************************************************************/
42 #ifndef _h_MPR_OS_HDRS
43 #define _h_MPR_OS_HDRS 1
45 #include "lib/ejs/config.h"
47 /********************************* CPU Families *********************************/
49 * Porters, add your CPU families here and update configure code.
51 #define MPR_CPU_UNKNOWN 0
52 #define MPR_CPU_IX86 1
54 #define MPR_CPU_SPARC 3
55 #define MPR_CPU_XSCALE 4
57 #define MPR_CPU_MIPS 6
59 #define MPR_CPU_SIMNT 8 /* VxWorks NT simulator */
60 #define MPR_CPU_SIMSPARC 9 /* VxWorks sparc simulator */
62 /********************************* O/S Includes *********************************/
65 #include <sys/types.h>
67 #include <arpa/inet.h>
77 #include <netinet/in.h>
78 #include <netinet/tcp.h>
79 #include <netinet/ip.h>
89 #include <sys/ioctl.h>
91 #include <sys/param.h>
92 #include <sys/resource.h>
95 #include <sys/socket.h>
96 #include <sys/select.h>
98 #include <sys/times.h>
99 #include <sys/utsname.h>
100 #include <sys/wait.h>
108 #include <netinet/in_systm.h>
111 #if BLD_FEATURE_FLOATING_POINT
112 #define __USE_ISOC99 1
117 #endif /* LINUX || SOLARIS */
122 #include <sys/types.h>
124 #include <arpa/inet.h>
132 #include <netinet/tcp.h>
133 #include <netinet/in.h>
134 #include <netinet/ip.h>
140 #include <sysSymTbl.h>
141 #include <sys/fcntlcom.h>
142 #include <sys/ioctl.h>
143 #include <sys/stat.h>
144 #include <sys/socket.h>
145 #include <sys/times.h>
146 #include <sys/wait.h>
150 #if BLD_FEATURE_FLOATING_POINT
152 #define __USE_ISOC99 1
163 #include <taskHookLib.h>
169 #include <arpa/inet.h>
176 #include <mach-o/dyld.h>
179 #include <netinet/in_systm.h>
180 #include <netinet/in.h>
181 #include <netinet/tcp.h>
182 #include <netinet/ip.h>
193 #include <sys/ioctl.h>
194 #include <sys/types.h>
195 #include <sys/stat.h>
196 #include <sys/param.h>
197 #include <sys/resource.h>
200 #include <sys/socket.h>
201 #include <sys/select.h>
202 #include <sys/time.h>
203 #include <sys/times.h>
204 #include <sys/types.h>
205 #include <sys/utsname.h>
206 #include <sys/wait.h>
220 #include <sys/stat.h>
221 #include <sys/types.h>
228 #define WIN32_LEAN_AND_MEAN
229 #include <winsock2.h>
232 #if BLD_FEATURE_FLOATING_POINT
236 #include <shellapi.h>
237 #include <wincrypt.h>
244 /********************************************************************************/
245 /******************************* General Defines ********************************/
246 /********************************************************************************/
248 #define MAXINT INT_MAX
249 #define BITS(type) (BITSPERBYTE * (int) sizeof(type))
252 #define max(a,b) (((a) > (b)) ? (a) : (b))
256 #define min(a,b) (((a) < (b)) ? (a) : (b))
260 * Set FD_SETSIZE to the maximum number of files (sockets) that you want to
261 * support. It is used in select.cpp.
266 * #define FD_SETSIZE 128
269 typedef char *MprStr; /* Used for dynamic strings */
271 /********************************************************************************/
272 /*******************************/ Linux Defines *********************************/
273 /********************************************************************************/
276 typedef unsigned char uchar;
278 #if BLD_FEATURE_INT64
279 __extension__ typedef long long int int64;
280 __extension__ typedef unsigned long long int uint64;
281 #define INT64(x) (x##LL)
284 #define closesocket(x) close(x)
285 #define MPR_BINARY ""
289 #define SOCKET_ERROR -1
290 #define MPR_DLL_EXT ".so"
292 #if BLD_FEATURE_FLOATING_POINT
293 #define MAX_FLOAT MAXFLOAT
296 #if BLD_FEATURE_MALLOC
298 * PORTERS: You will need add assembler code for your architecture here
299 * only if you want to use the fast malloc (BLD_FEATURE_MALLOC)
302 #define MPR_GET_RETURN(ip) __builtin_return_address(0)
304 #if BLD_HOST_CPU_ARCH == MPR_CPU_IX86
305 #define MPR_GET_RETURN(ip) \
306 asm("movl 4(%%ebp),%%eax ; movl %%eax,%0" : \
311 #endif /* BLD_FEATURE_MALLOC */
314 /* #define mprGetHiResTime(x) __asm__ __volatile__ ("rdtsc" : "=A" (x)) */
315 /* extern char *inet_ntoa_r(const struct in_addr in, char *buffer, int buflen); */
318 /* Atomic functions */
320 typedef struct { volatile int counter; } mprAtomic_t;
322 #if BLD_FEATURE_MULTITHREAD
323 #define LOCK "lock ; "
328 static __inline__ void mprAtomicInc(mprAtomic_t* v) {
329 __asm__ __volatile__(
335 static __inline__ void mprAtomicDec(mprAtomic_t* v) {
336 __asm__ __volatile__(
345 /********************************************************************************/
346 /******************************* VxWorks Defines ********************************/
347 /********************************************************************************/
351 typedef unsigned char uchar;
352 typedef unsigned int uint;
353 typedef unsigned long ulong;
355 #define HAVE_SOCKLEN_T
356 typedef int socklen_t;
358 #if BLD_FEATURE_INT64
359 typedef long long int int64;
360 typedef unsigned long long int uint64;
361 #define INT64(x) (x##LL)
364 #define closesocket(x) close(x)
365 #define getpid() taskIdSelf()
366 #define MPR_BINARY ""
370 #define SOCKET_ERROR -1
371 #define MPR_DLL_EXT ".so"
373 #if BLD_FEATURE_FLOATING_POINT
374 #define MAX_FLOAT FLT_MAX
386 #define MSG_NOSIGNAL 0
388 extern int access(char *path, int mode);
389 extern int sysClkRateGet();
391 #if BLD_FEATURE_MALLOC
393 * PORTERS: You will need add assembler code for your architecture here
394 * only if you want to use the fast malloc (BLD_FEATURE_MALLOC)
397 #define MPR_GET_RETURN(ip) __builtin_return_address(0)
399 #if BLD_HOST_CPU_ARCH == MPR_CPU_IX86
400 #define MPR_GET_RETURN(ip) \
401 asm("movl 4(%%ebp),%%eax ; movl %%eax,%0" : \
406 #endif /* BLD_FEATURE_MALLOC */
409 /********************************************************************************/
410 /******************************** MacOsx Defines ********************************/
411 /********************************************************************************/
413 typedef unsigned long ulong;
414 typedef unsigned char uchar;
416 #if BLD_FEATURE_INT64
417 __extension__ typedef long long int int64;
418 __extension__ typedef unsigned long long int uint64;
419 #define INT64(x) (x##LL)
421 #define closesocket(x) close(x)
422 #define MPR_BINARY ""
426 #define SOCKET_ERROR -1
427 #define MPR_DLL_EXT ".dylib"
428 #define MSG_NOSIGNAL 0
429 #define __WALL 0x40000000
430 #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
432 #if BLD_FEATURE_FLOATING_POINT
433 #define MAX_FLOAT MAXFLOAT
436 #if MPR_FEATURE_MALLOC
438 * PORTERS: You will need add assembler code for your architecture here
439 * only if you want to use the fast malloc (MPR_FEATURE_MALLOC)
441 #define MPR_GET_RETURN(ip) __builtin_return_address
445 /* #define mprGetHiResTime(x) __asm__ __volatile__ ("rdtsc" : "=A" (x)) */
446 /* extern char *inet_ntoa_r(const struct in_addr in, char *buffer, int buflen); */
449 /* Atomic functions */
451 typedef struct { volatile int counter; } mprAtomic_t;
453 #if MPR_FEATURE_MULTITHREAD
454 #define LOCK "lock ; "
459 static __inline__ void mprAtomicInc(mprAtomic_t* v) {
460 __asm__ __volatile__(
466 static __inline__ void mprAtomicDec(mprAtomic_t* v) {
467 __asm__ __volatile__(
475 /********************************************************************************/
476 /******************************* Windows Defines ********************************/
477 /********************************************************************************/
480 typedef unsigned char uchar;
481 typedef unsigned int uint;
482 typedef unsigned long ulong;
483 typedef unsigned short ushort;
485 #if BLD_FEATURE_INT64
486 typedef __int64 int64;
487 typedef unsigned __int64 uint64;
488 #define INT64(x) (x##i64)
492 typedef void *handle;
493 typedef char *caddr_t;
496 typedef ushort mode_t;
497 typedef void *siginfo_t;
499 #define HAVE_SOCKLEN_T
500 typedef int socklen_t;
512 #define EADDRINUSE 46
515 #define EWOULDBLOCK EAGAIN
521 #define ECONNRESET 44
524 #define ECONNREFUSED 45
527 #define MSG_NOSIGNAL 0
528 #define MPR_BINARY "b"
531 #if BLD_FEATURE_FLOATING_POINT
532 #define MAX_FLOAT DBL_MAX
535 #ifndef FILE_FLAG_FIRST_PIPE_INSTANCE
536 #define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000
539 #define access _access
541 #define fileno _fileno
543 #define getpid _getpid
545 #define putenv _putenv
549 #define unlink _unlink
551 #define strdup _strdup
554 #define mkdir(a,b) _mkdir(a)
555 #define rmdir(a) _rmdir(a)
557 #if BLD_FEATURE_MALLOC
559 * PORTERS: You will need add assembler code for your architecture here
560 * only if you want to use the fast malloc (BLD_FEATURE_MALLOC)
563 #define MPR_GET_RETURN(ip) \
564 __asm { mov eax, 4[ebp] } \
565 __asm { mov ip, eax }
569 #define MPR_DLL_EXT ".dll"
571 extern void srand48(long);
572 extern long lrand48(void);
573 extern long ulimit(int, ...);
574 extern long nap(long);
575 extern uint sleep(unsigned int secs);
576 extern uid_t getuid(void);
577 extern uid_t geteuid(void);
581 /********************************************************************************/
582 /*****************************/ Solaris Defines *********************************/
583 /********************************************************************************/
586 typedef unsigned char uchar;
588 #if BLD_FEATURE_INT64
589 typedef long long int int64;
590 typedef unsigned long long int uint64;
591 #define INT64(x) (x##LL)
594 #define closesocket(x) close(x)
595 #define MPR_BINARY ""
599 #define SOCKET_ERROR -1
600 #define MPR_DLL_EXT ".so"
601 #define MSG_NOSIGNAL 0
602 #define INADDR_NONE ((in_addr_t) 0xffffffff)
604 #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
606 #if BLD_FEATURE_FLOATING_POINT
607 #define MAX_FLOAT MAXFLOAT
612 /********************************************************************************/
617 #endif /* _h_MPR_OS_HDRS */
625 * vim600: sw=4 ts=4 fdm=marker