xref: /aoo42x/main/sal/osl/unx/system.h (revision 9eab2a37)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __OSL_SYSTEM_H__
25 #define __OSL_SYSTEM_H__
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <limits.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <stdarg.h>
33 
34 #include <unistd.h>
35 #include <fcntl.h>
36 #include <dirent.h>
37 #include <signal.h>
38 #include <utime.h>
39 
40 #include <pwd.h>
41 
42 #include <netdb.h>
43 
44 #include <sys/stat.h>
45 #include <sys/wait.h>
46 
47 #include <sys/types.h>
48 
49 /* Make sockets of type AF_UNIX use underlying FS rights */
50 #ifdef SOLARIS
51 #	define _XOPEN_SOURCE 500
52 #	include <sys/socket.h>
53 #	undef _XOPEN_SOURCE
54 #else
55 #	include <sys/socket.h>
56 #endif
57 
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
60 
61 #ifdef SYSV
62 #   include <sys/utsname.h>
63 #endif
64 
65 #ifdef LINUX
66 #   ifndef __USE_GNU
67 #   define __USE_GNU
68 #   endif
69 
70 #if GLIBC >= 2
71 #   include <shadow.h>
72 #   include <pthread.h>
73 #   include <sys/file.h>
74 #   include <sys/ioctl.h>
75 #	include <sys/uio.h>
76 #	include <sys/un.h>
77 #   include <netinet/tcp.h>
78 #   include <dlfcn.h>
79 #	include <endian.h>
80 #	include <sys/time.h>
81 #	include <semaphore.h>
82 #	if __BYTE_ORDER == __LITTLE_ENDIAN
83 #		define _LITTLE_ENDIAN
84 #	elif __BYTE_ORDER == __BIG_ENDIAN
85 #               ifndef _BIG_ENDIAN
86 #               define _BIG_ENDIAN
87 #               endif
88 #	elif __BYTE_ORDER == __PDP_ENDIAN
89 #		define _PDP_ENDIAN
90 #	endif
91 #	define 	IORESOURCE_TRANSFER_BSD
92 #	define 	IOCHANNEL_TRANSFER_BSD_RENO
93 #	define	pthread_testcancel()
94 #	define  NO_PTHREAD_PRIORITY
95 #	define  PTHREAD_SIGACTION 			pthread_sigaction
96 #else
97 #   include <shadow.h>
98 #   include <asm/sigcontext.h>
99 #   include <pthread.h>
100 #   include <sys/file.h>
101 #   include <sys/ioctl.h>
102 #   include <linux/net.h>
103 #	include <sys/un.h>
104 #   include <netinet/tcp.h>
105 #   include <linux/elfcore.h>
106 #   include <dlfcn.h>
107 #	include <endian.h>
108 #	if __BYTE_ORDER == __LITTLE_ENDIAN
109 #		define _LITTLE_ENDIAN
110 #	elif __BYTE_ORDER == __BIG_ENDIAN
111 #		define _BIG_ENDIAN
112 #	elif __BYTE_ORDER == __PDP_ENDIAN
113 #		define _PDP_ENDIAN
114 #	endif
115 #	define 	IORESOURCE_TRANSFER_BSD
116 #	define 	IOCHANNEL_TRANSFER_BSD_RENO
117 #	define	pthread_testcancel()
118 #	define  NO_PTHREAD_RTL
119 #	define  NO_PTHREAD_PRIORITY
120 #	define  PTHREAD_SIGACTION 			pthread_sigaction
121 #endif
122 
123 #   ifndef ETIME
124 #       define ETIME ETIMEDOUT
125 #   endif
126 
127 #endif
128 
129 #ifdef NETBSD
130 #	define  ETIME ETIMEDOUT
131 #	define _POSIX_THREAD_SYSCALL_SOFT 1
132 #	include <pthread.h>
133 #	include <netdb.h>
134 #	include <sys/sem.h>
135 #	include <sys/exec.h>
136 #	include <sys/filio.h>
137 #	include <sys/ioctl.h>
138 #	include <sys/time.h>
139 #	include <sys/un.h>
140 #	include <netinet/tcp.h>
141 #	include <dlfcn.h>
142 #   include <machine/endian.h>
143 #   if BYTE_ORDER == LITTLE_ENDIAN
144 #   	define _LITTLE_ENDIAN_OO
145 #   elif BYTE_ORDER == BIG_ENDIAN
146 #   	define _BIG_ENDIAN_OO
147 #   elif BYTE_ORDER == PDP_ENDIAN
148 #   	define _PDP_ENDIAN_OO
149 #   endif
150 #	define 	IORESOURCE_TRANSFER_BSD
151 #	define 	IOCHANNEL_TRANSFER_BSD_RENO
152 #	define	pthread_testcancel()
153 #	define  NO_PTHREAD_PRIORITY
154 #     define  NO_PTHREAD_SEMAPHORES
155 #	define  NO_PTHREAD_RTL
156 #	define  PTHREAD_SIGACTION 			pthread_sigaction
157 #endif
158 
159 #ifdef FREEBSD
160 #   define  ETIME ETIMEDOUT
161 #   include <pthread.h>
162 #   include <sys/sem.h>
163 #   include <semaphore.h>
164 #   include <dlfcn.h>
165 #   include <sys/filio.h>
166 #   include <sys/ioctl.h>
167 #   include <sys/param.h>
168 #   include <sys/time.h>
169 #   include <sys/uio.h>
170 #   include <sys/exec.h>
171 #   include <vm/vm.h>
172 #   include <vm/vm_param.h>
173 #   include <vm/pmap.h>
174 #   include <vm/swap_pager.h>
175 #	include <sys/un.h>
176 #   include <netinet/tcp.h>
177 #	define 	IORESOURCE_TRANSFER_BSD
178 #   include <machine/endian.h>
179 #if __FreeBSD_version < 500000
180 #   if BYTE_ORDER == LITTLE_ENDIAN
181 #   	define _LITTLE_ENDIAN
182 #   elif BYTE_ORDER == BIG_ENDIAN
183 #   	define _BIG_ENDIAN
184 #   elif BYTE_ORDER == PDP_ENDIAN
185 #   	define _PDP_ENDIAN
186 #   endif
187 #endif
188 #	define  NO_PTHREAD_RTL
189 #endif
190 
191 #ifdef SCO
192 #   define AF_IPX -1
193 #	include <strings.h>
194 #	include <pthread.h>
195 #	include <shadow.h>
196 #	include <netdb.h>
197 #	include <sys/un.h>
198 #	include <sys/netinet/tcp.h>
199 #   include <sys/types.h>
200 #   include <sys/byteorder.h>
201 #   include <dlfcn.h>
202 #   if BYTE_ORDER == LITTLE_ENDIAN
203 #   	define _LITTLE_ENDIAN
204 #   elif BYTE_ORDER == BIG_ENDIAN
205 #   	define _BIG_ENDIAN
206 #   elif BYTE_ORDER == PDP_ENDIAN
207 #   	define _PDP_ENDIAN
208 #   endif
209 #	define  sched_yield() 				pthread_yield()
210 #	define	pthread_testcancel()
211 #	define  NO_PTHREAD_RTL
212 #	define  NO_PTHREAD_PRIORITY
213 extern int pthread_cancel(pthread_t);
214 extern unsigned int nanosleep(unsigned int);
215 #	define  SLEEP_TIMESPEC(timespec)  	(timespec .tv_sec > 0) ? sleep(timespec .tv_sec), nanosleep(timespec .tv_nsec) : nanosleep(timespec .tv_nsec)
216 #	define  PATH_MAX 					_POSIX_PATH_MAX
217 #	define	S_ISSOCK					S_ISFIFO
218 #	define	PTHREAD_SIGACTION 			pthread_sigaction
219 #	define	STAT_PARENT					stat
220 #endif
221 
222 #ifdef AIX
223 #   define AF_IPX -1
224 #	include <strings.h>
225 #	include <pthread.h>
226 #	include <sys/time.h>
227 #	include <sys/un.h>
228 #	include <netinet/tcp.h>
229 #	include <sys/machine.h>
230 #   if BYTE_ORDER == LITTLE_ENDIAN
231 #   	define _LITTLE_ENDIAN
232 #   elif BYTE_ORDER == BIG_ENDIAN
233 #   	define _BIG_ENDIAN
234 #   elif BYTE_ORDER == PDP_ENDIAN
235 #   	define _PDP_ENDIAN
236 #   endif
237 #	define  sched_yield() 				pthread_yield()
238 #	define  SLEEP_TIMESPEC(timespec)  	nsleep(&timespec, 0)
239 #	define  LIBPATH "LIBPATH"
240 #	define  NO_PTHREAD_SEMAPHORES
241 #   define  NO_DL_FUNCTIONS
242 #endif
243 
244 #ifdef HPUX
245 #   define  AF_IPX -1
246 #   undef	howmany
247 #   undef	MAXINT
248 #	include <pthread.h>
249 #	include <sys/un.h>
250 #	include <sys/sched.h>
251 #	include <sys/xti.h>
252 #	include <sys/pstat.h>
253 #	include <shadow.h>
254 #	include <crypt.h>
255 #	include <machine/param.h>
256 #	define  LIBPATH "SHLIB_PATH"
257 #	define  PTR_FD_SET(s)				((int *)&(s))
258 #	define  PTHREAD_VALUE(t)			((t).field2)
259 # 	define  PTHREAD_NONE_INIT			{ 0, -1 }
260 #	define  PTHREAD_ATTR_DEFAULT		pthread_attr_default
261 #	define  PTHREAD_MUTEXATTR_DEFAULT	pthread_mutexattr_default
262 #	define  PTHREAD_CONDATTR_DEFAULT	pthread_condattr_default
263 #	define  pthread_detach(t)			pthread_detach(&(t))
264 #	define  NO_PTHREAD_PRIORITY
265 #	define  NO_PTHREAD_SEMAPHORES
266 #   define  NO_DL_FUNCTIONS
267 #	undef	sigaction
268 #	define  PTHREAD_SIGACTION 			cma_sigaction
269 #endif
270 
271 #ifdef SOLARIS
272 #	include <shadow.h>
273 #	include <sys/un.h>
274 #	include <stropts.h>
275 #	include <pthread.h>
276 #	include <semaphore.h>
277 #	include <netinet/tcp.h>
278 #	include <sys/filio.h>
279 #	include <dlfcn.h>
280 #	include <sys/isa_defs.h>
281 #	define 	IORESOURCE_TRANSFER_SYSV
282 #	define 	IOCHANNEL_TRANSFER_BSD
283 #	define  LIBPATH "LD_LIBRARY_PATH"
284 #endif
285 
286 #ifdef MACOSX
287 #define __OPENTRANSPORTPROVIDERS__ // these are already defined
288 #define TimeValue CFTimeValue      // Do not conflict with TimeValue in sal/inc/osl/time.h
289 #include <Carbon/Carbon.h>
290 #undef TimeValue
291 #	ifndef ETIME
292 #		define  ETIME ETIMEDOUT
293 #	endif
294 #	include <dlfcn.h>
295 #	include <pthread.h>
296 #	include <sys/file.h>
297 #	include <sys/ioctl.h>
298 #	include <sys/uio.h>
299 #	include <sys/un.h>
300 #	include <netinet/tcp.h>
301 #	include <machine/endian.h>
302 #	include <sys/time.h>
303 #	include <sys/semaphore.h>
304 /* fixme are premac and postmac still needed here? */
305 #	include <premac.h>
306 #	include <mach-o/dyld.h>
307 #	include <postmac.h>
308 #	if BYTE_ORDER == LITTLE_ENDIAN
309 #		ifndef _LITTLE_ENDIAN
310 #		define _LITTLE_ENDIAN
311 #		endif
312 #	elif BYTE_ORDER == BIG_ENDIAN
313 #		ifndef _BIG_ENDIAN
314 #		define _BIG_ENDIAN
315 #		endif
316 #	elif BYTE_ORDER == PDP_ENDIAN
317 #		ifndef _PDP_ENDIAN
318 #		define _PDP_ENDIAN
319 #		endif
320 #	endif
321 #	define 	IOCHANNEL_TRANSFER_BSD_RENO
322 #	define  NO_PTHREAD_RTL
323 /* for NSGetArgc/Argv/Environ */
324 #       include <crt_externs.h>
325 #ifdef __cplusplus
326 extern "C" {
327 #endif
328 int macxp_resolveAlias(char *path, int buflen);
329 #ifdef __cplusplus
330 }
331 #endif
332 #endif
333 
334 #if !defined(_WIN32)  && !defined(_WIN16) && !defined(OS2)  && \
335     !defined(LINUX)   && !defined(NETBSD) && !defined(FREEBSD) && !defined(SCO)  && \
336 	!defined(AIX)     && !defined(HPUX)   && \
337 	!defined(SOLARIS) && !defined(MACOSX)
338 #	error "Target platform not specified!"
339 #endif
340 
341 #if defined(NETBSD)
342 #if defined _LITTLE_ENDIAN_OO
343 #	define _OSL_BIGENDIAN
344 #elif defined _BIG_ENDIAN_OO
345 #	define _OSL_LITENDIAN
346 #else
347 #	error undetermined endianess
348 #endif
349 #else
350 #if defined _LITTLE_ENDIAN
351 #	define _OSL_BIGENDIAN
352 #elif defined _BIG_ENDIAN
353 #	define _OSL_LITENDIAN
354 #else
355 #	error undetermined endianess
356 #endif
357 #endif
358 
359 #ifndef PTR_FD_SET
360 #	define PTR_FD_SET(s)				(&(s))
361 #endif
362 
363 #ifndef NORMALIZE_TIMESPEC
364 #	define NORMALIZE_TIMESPEC(timespec) \
365   		timespec . tv_sec  += timespec . tv_nsec / 1000000000; \
366   		timespec . tv_nsec %= 1000000000;
367 #endif
368 
369 #ifndef SET_TIMESPEC
370 #	define SET_TIMESPEC(timespec, sec, nsec) \
371   		timespec . tv_sec  = (sec);  \
372   		timespec . tv_nsec = (nsec); \
373 		NORMALIZE_TIMESPEC(timespec);
374 #endif
375 
376 #ifndef SLEEP_TIMESPEC
377 #	define SLEEP_TIMESPEC(timespec) nanosleep(&timespec, 0)
378 #endif
379 
380 #ifndef INIT_GROUPS
381 #	define  INIT_GROUPS(name, gid)	((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
382 #endif
383 
384 #ifndef PTHREAD_VALUE
385 #	define PTHREAD_VALUE(t) 			(t)
386 #endif
387 #ifndef PTHREAD_NONE
388 # if (__GNUC__ < 4) && !defined(MACOSX)
389 extern pthread_t _pthread_none_;
390 # endif
391 #	define PTHREAD_NONE					_pthread_none_
392 #   ifndef PTHREAD_NONE_INIT
393 #		define PTHREAD_NONE_INIT		((pthread_t)-1)
394 #	endif
395 #endif
396 
397 #ifndef PTHREAD_ATTR_DEFAULT
398 #	define PTHREAD_ATTR_DEFAULT 		NULL
399 #endif
400 #ifndef PTHREAD_MUTEXATTR_DEFAULT
401 #	define PTHREAD_MUTEXATTR_DEFAULT 	NULL
402 #endif
403 #ifndef PTHREAD_CONDATTR_DEFAULT
404 #	define PTHREAD_CONDATTR_DEFAULT 	NULL
405 #endif
406 
407 #ifndef PTHREAD_SIGACTION
408 #	define PTHREAD_SIGACTION sigaction
409 #endif
410 
411 #ifndef STAT_PARENT
412 #	define STAT_PARENT					lstat
413 #endif
414 
415 /* socket options which might not be defined on all unx flavors */
416 #ifndef SO_ACCEPTCONN
417 #	define SO_ACCEPTCONN 	0
418 #endif
419 #ifndef SO_SNDLOWAT
420 #	define SO_SNDLOWAT 		0
421 #endif
422 #ifndef SO_RCVLOWAT
423 #	define SO_RCVLOWAT 		0
424 #endif
425 #ifndef SO_SNDTIMEO
426 #	define	SO_SNDTIMEO 	0
427 #endif
428 #ifndef SO_RCVTIMEO
429 #	define SO_RCVTIMEO 		0
430 #endif
431 #ifndef SO_USELOOPBACK
432 #	define SO_USELOOPBACK 	0
433 #endif
434 #ifndef MSG_MAXIOVLEN
435 #	define MSG_MAXIOVLEN 	0
436 #endif
437 
438 /* BEGIN HACK */
439 /* dummy define and declarations for IPX should be replaced by */
440 /* original ipx headers when these are available for this platform */
441 
442 #ifndef SA_FAMILY_DECL
443 #	define SA_FAMILY_DECL short sa_family
444 #endif
445 
446 typedef struct sockaddr_ipx {
447     SA_FAMILY_DECL;
448     char  sa_netnum[4];
449     char  sa_nodenum[6];
450     unsigned short sa_socket;
451 } SOCKADDR_IPX;
452 
453 #define NSPROTO_IPX      1000
454 #define NSPROTO_SPX      1256
455 #define NSPROTO_SPXII    1257
456 
457 /* END HACK */
458 
459 #ifdef NO_PTHREAD_SEMAPHORES
460 
461 typedef struct
462 {
463 	pthread_mutex_t	mutex;
464 	pthread_cond_t	increased;
465 	int			    value;
466 } sem_t;
467 extern int sem_init(sem_t* sem, int pshared, unsigned int value);
468 extern int sem_destroy(sem_t* sem);
469 extern int sem_wait(sem_t* sem);
470 extern int sem_trywait(sem_t* sem);
471 extern int sem_post(sem_t* sem);
472 
473 #endif
474 
475 #ifdef NO_PTHREAD_RTL
476 #if !defined FREEBSD || (__FreeBSD_version < 500112)
477 struct passwd *getpwent_r(struct passwd *pwd, char *buffer,  int buflen);
478 extern struct spwd *getspnam_r(const char *name, struct spwd *result,
479 							   char *buffer, int buflen);
480 
481 struct tm *localtime_r(const time_t *timep, struct tm *buffer);
482 struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
483 #endif /* !defined FREEBSD || (__FreeBSD_version < 500112) */
484 #if !defined(FREEBSD) || (__FreeBSD_version < 601103)
485 struct hostent *gethostbyname_r(const char *name, struct hostent *result,
486 								char *buffer, int buflen, int *h_errnop);
487 #endif /* !defined(FREEBSD) || (__FreeBSD_version < 601103) */
488 #endif
489 
490 #endif /* __OSL_SYSTEM_H__ */
491 
492