xref: /aoo42x/main/sal/osl/unx/system.h (revision e15a4534)
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 #include <osl/endian.h>
130 
131 #ifdef NETBSD
132 #	define  ETIME ETIMEDOUT
133 #	define _POSIX_THREAD_SYSCALL_SOFT 1
134 #	include <pthread.h>
135 #	include <netdb.h>
136 #	include <sys/sem.h>
137 #	include <sys/exec.h>
138 #	include <sys/filio.h>
139 #	include <sys/ioctl.h>
140 #	include <sys/time.h>
141 #	include <sys/un.h>
142 #	include <netinet/tcp.h>
143 #	include <dlfcn.h>
144 #   include <machine/endian.h>
145 #   if BYTE_ORDER == LITTLE_ENDIAN
146 #   	define _LITTLE_ENDIAN_OO
147 #   elif BYTE_ORDER == BIG_ENDIAN
148 #   	define _BIG_ENDIAN_OO
149 #   elif BYTE_ORDER == PDP_ENDIAN
150 #   	define _PDP_ENDIAN_OO
151 #   endif
152 #	define 	IORESOURCE_TRANSFER_BSD
153 #	define 	IOCHANNEL_TRANSFER_BSD_RENO
154 #	define	pthread_testcancel()
155 #	define  NO_PTHREAD_PRIORITY
156 #     define  NO_PTHREAD_SEMAPHORES
157 #	define  NO_PTHREAD_RTL
158 #	define  PTHREAD_SIGACTION 			pthread_sigaction
159 #endif
160 
161 #ifdef FREEBSD
162 #   define  ETIME ETIMEDOUT
163 #   include <pthread.h>
164 #   include <sys/sem.h>
165 #   include <semaphore.h>
166 #   include <dlfcn.h>
167 #   include <sys/filio.h>
168 #   include <sys/ioctl.h>
169 #   include <sys/param.h>
170 #   include <sys/time.h>
171 #   include <sys/uio.h>
172 #   include <sys/exec.h>
173 #   include <vm/vm.h>
174 #   include <vm/vm_param.h>
175 #   include <vm/pmap.h>
176 #   include <vm/swap_pager.h>
177 #	include <sys/un.h>
178 #   include <netinet/tcp.h>
179 #	define 	IORESOURCE_TRANSFER_BSD
180 #   include <machine/endian.h>
181 #   if BYTE_ORDER == LITTLE_ENDIAN
182 #   	undef _BIG_ENDIAN
183 #   elif BYTE_ORDER == BIG_ENDIAN
184 #   	undef _LITTLE_ENDIAN
185 #   elif BYTE_ORDER == PDP_ENDIAN
186 #   	define _PDP_ENDIAN
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 #	define  OLD_SHADOW_API
285 #endif
286 
287 #ifdef MACOSX
288 #define __OPENTRANSPORTPROVIDERS__ // these are already defined
289 #define TimeValue CFTimeValue      // Do not conflict with TimeValue in sal/inc/osl/time.h
290 #include <Carbon/Carbon.h>
291 #undef TimeValue
292 #	ifndef ETIME
293 #		define  ETIME ETIMEDOUT
294 #	endif
295 #	include <dlfcn.h>
296 #	include <pthread.h>
297 #	include <sys/file.h>
298 #	include <sys/ioctl.h>
299 #	include <sys/uio.h>
300 #	include <sys/un.h>
301 #	include <netinet/tcp.h>
302 #	include <machine/endian.h>
303 #	include <sys/time.h>
304 #	include <sys/semaphore.h>
305 /* fixme are premac and postmac still needed here? */
306 #	include <premac.h>
307 #	include <mach-o/dyld.h>
308 #	include <postmac.h>
309 #	if BYTE_ORDER == LITTLE_ENDIAN
310 #		ifndef _LITTLE_ENDIAN
311 #		define _LITTLE_ENDIAN
312 #		endif
313 #	elif BYTE_ORDER == BIG_ENDIAN
314 #		ifndef _BIG_ENDIAN
315 #		define _BIG_ENDIAN
316 #		endif
317 #	elif BYTE_ORDER == PDP_ENDIAN
318 #		ifndef _PDP_ENDIAN
319 #		define _PDP_ENDIAN
320 #		endif
321 #	endif
322 #	define 	IOCHANNEL_TRANSFER_BSD_RENO
323 #	define  NO_PTHREAD_RTL
324 /* for NSGetArgc/Argv/Environ */
325 #       include <crt_externs.h>
326 #ifdef __cplusplus
327 extern "C" {
328 #endif
329 int macxp_resolveAlias(char *path, int buflen);
330 #ifdef __cplusplus
331 }
332 #endif
333 #endif
334 
335 #if !defined(_WIN32)  && !defined(_WIN16) && !defined(OS2)  && \
336     !defined(LINUX)   && !defined(NETBSD) && !defined(FREEBSD) && !defined(SCO)  && \
337 	!defined(AIX)     && !defined(HPUX)   && \
338 	!defined(SOLARIS) && !defined(MACOSX)
339 #	error "Target platform not specified!"
340 #endif
341 
342 #if defined(NETBSD)
343 #if defined _LITTLE_ENDIAN_OO
344 #	define _OSL_BIGENDIAN
345 #elif defined _BIG_ENDIAN_OO
346 #	define _OSL_LITENDIAN
347 #else
348 #	error undetermined endianness
349 #endif
350 #else
351 #if defined _LITTLE_ENDIAN
352 #	define _OSL_BIGENDIAN
353 #elif defined _BIG_ENDIAN
354 #	define _OSL_LITENDIAN
355 #else
356 #	error undetermined endianness
357 #endif
358 #endif
359 
360 #ifndef PTR_FD_SET
361 #	define PTR_FD_SET(s)				(&(s))
362 #endif
363 
364 #ifndef NORMALIZE_TIMESPEC
365 #	define NORMALIZE_TIMESPEC(timespec) \
366   		timespec . tv_sec  += timespec . tv_nsec / 1000000000; \
367   		timespec . tv_nsec %= 1000000000;
368 #endif
369 
370 #ifndef SET_TIMESPEC
371 #	define SET_TIMESPEC(timespec, sec, nsec) \
372   		timespec . tv_sec  = (sec);  \
373   		timespec . tv_nsec = (nsec); \
374 		NORMALIZE_TIMESPEC(timespec);
375 #endif
376 
377 #ifndef SLEEP_TIMESPEC
378 #	define SLEEP_TIMESPEC(timespec) nanosleep(&timespec, 0)
379 #endif
380 
381 #ifndef INIT_GROUPS
382 #	define  INIT_GROUPS(name, gid)	((setgid((gid)) == 0) && (initgroups((name), (gid)) == 0))
383 #endif
384 
385 #ifndef PTHREAD_VALUE
386 #	define PTHREAD_VALUE(t) 			(t)
387 #endif
388 #ifndef PTHREAD_NONE
389 # if (__GNUC__ < 4) && !defined(MACOSX)
390 extern pthread_t _pthread_none_;
391 # endif
392 #	define PTHREAD_NONE					_pthread_none_
393 #   ifndef PTHREAD_NONE_INIT
394 #		define PTHREAD_NONE_INIT		((pthread_t)-1)
395 #	endif
396 #endif
397 
398 #ifndef PTHREAD_ATTR_DEFAULT
399 #	define PTHREAD_ATTR_DEFAULT 		NULL
400 #endif
401 #ifndef PTHREAD_MUTEXATTR_DEFAULT
402 #	define PTHREAD_MUTEXATTR_DEFAULT 	NULL
403 #endif
404 #ifndef PTHREAD_CONDATTR_DEFAULT
405 #	define PTHREAD_CONDATTR_DEFAULT 	NULL
406 #endif
407 
408 #ifndef PTHREAD_SIGACTION
409 #	define PTHREAD_SIGACTION sigaction
410 #endif
411 
412 #ifndef STAT_PARENT
413 #	define STAT_PARENT					lstat
414 #endif
415 
416 /* socket options which might not be defined on all unx flavors */
417 #ifndef SO_ACCEPTCONN
418 #	define SO_ACCEPTCONN 	0
419 #endif
420 #ifndef SO_SNDLOWAT
421 #	define SO_SNDLOWAT 		0
422 #endif
423 #ifndef SO_RCVLOWAT
424 #	define SO_RCVLOWAT 		0
425 #endif
426 #ifndef SO_SNDTIMEO
427 #	define	SO_SNDTIMEO 	0
428 #endif
429 #ifndef SO_RCVTIMEO
430 #	define SO_RCVTIMEO 		0
431 #endif
432 #ifndef SO_USELOOPBACK
433 #	define SO_USELOOPBACK 	0
434 #endif
435 #ifndef MSG_MAXIOVLEN
436 #	define MSG_MAXIOVLEN 	0
437 #endif
438 
439 /* BEGIN HACK */
440 /* dummy define and declarations for IPX should be replaced by */
441 /* original ipx headers when these are available for this platform */
442 
443 #ifndef SA_FAMILY_DECL
444 #	define SA_FAMILY_DECL short sa_family
445 #endif
446 
447 typedef struct sockaddr_ipx {
448     SA_FAMILY_DECL;
449     char  sa_netnum[4];
450     char  sa_nodenum[6];
451     unsigned short sa_socket;
452 } SOCKADDR_IPX;
453 
454 #define NSPROTO_IPX      1000
455 #define NSPROTO_SPX      1256
456 #define NSPROTO_SPXII    1257
457 
458 /* END HACK */
459 
460 #ifdef NO_PTHREAD_SEMAPHORES
461 
462 typedef struct
463 {
464 	pthread_mutex_t	mutex;
465 	pthread_cond_t	increased;
466 	int			    value;
467 } sem_t;
468 extern int sem_init(sem_t* sem, int pshared, unsigned int value);
469 extern int sem_destroy(sem_t* sem);
470 extern int sem_wait(sem_t* sem);
471 extern int sem_trywait(sem_t* sem);
472 extern int sem_post(sem_t* sem);
473 
474 #endif
475 
476 #ifdef NO_PTHREAD_RTL
477 #if !defined FREEBSD || (__FreeBSD_version < 500112)
478 struct passwd *getpwent_r(struct passwd *pwd, char *buffer,  int buflen);
479 extern struct spwd *getspnam_r(const char *name, struct spwd *result,
480 							   char *buffer, int buflen);
481 
482 struct tm *localtime_r(const time_t *timep, struct tm *buffer);
483 struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
484 #endif /* !defined FREEBSD || (__FreeBSD_version < 500112) */
485 #if !defined(FREEBSD) || (__FreeBSD_version < 601103)
486 struct hostent *gethostbyname_r(const char *name, struct hostent *result,
487 								char *buffer, int buflen, int *h_errnop);
488 #endif /* !defined(FREEBSD) || (__FreeBSD_version < 601103) */
489 #endif
490 
491 #endif /* __OSL_SYSTEM_H__ */
492 
493