2 * Wine porting definitions
4 * Copyright 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_WINE_PORT_H
22 #define __WINE_WINE_PORT_H
24 #ifndef __WINE_CONFIG_H
25 # error You must include config.h to use this header
28 #define _FILE_OFFSET_BITS 64
29 #define _GNU_SOURCE /* for pread/pwrite */
32 #include <sys/types.h>
49 /****************************************************************
63 typedef unsigned int size_t;
68 #ifndef HAVE_FSBLKCNT_T
69 typedef unsigned long fsblkcnt_t;
71 #ifndef HAVE_FSFILCNT_T
72 typedef unsigned long fsfilcnt_t;
75 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
78 unsigned long f_bsize;
79 unsigned long f_frsize;
88 unsigned long f_namemax;
90 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
93 /****************************************************************
100 #define RTLD_LAZY 0x001
101 #define RTLD_NOW 0x002
102 #define RTLD_GLOBAL 0x100
105 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
106 #define ftruncate chsize
109 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
113 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
114 #define pclose _pclose
117 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
118 #define snprintf _snprintf
121 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
122 #define vsnprintf _vsnprintf
126 # define S_ISLNK(mod) (0)
130 # define S_ISSOCK(mod) (0)
134 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
138 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
142 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
146 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
153 /* So we open files in 64 bit access mode on Linux */
155 # define O_LARGEFILE 0
159 # define O_NONBLOCK 0
166 #if !defined(S_IXUSR) && defined(S_IEXEC)
167 # define S_IXUSR S_IEXEC
169 #if !defined(S_IXGRP) && defined(S_IEXEC)
170 # define S_IXGRP S_IEXEC
172 #if !defined(S_IXOTH) && defined(S_IEXEC)
173 # define S_IXOTH S_IEXEC
177 /****************************************************************
182 #define M_PI 3.14159265358979323846
186 #define M_PI_2 1.570796326794896619
190 /* Macros to define assembler functions somewhat portably */
192 #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
193 # define __ASM_GLOBAL_FUNC(name,code) \
194 __asm__( ".text\n\t" \
196 ".globl " __ASM_NAME(#name) "\n\t" \
197 __ASM_FUNC(#name) "\n" \
198 __ASM_NAME(#name) ":\n\t" \
201 #else /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__) */
202 # define __ASM_GLOBAL_FUNC(name,code) \
203 void __asm_dummy_##name(void) { \
204 asm( ".align 4\n\t" \
205 ".globl " __ASM_NAME(#name) "\n\t" \
206 __ASM_FUNC(#name) "\n" \
207 __ASM_NAME(#name) ":\n\t" \
210 #endif /* __GNUC__ */
213 /* Constructor functions */
216 # define DECL_GLOBAL_CONSTRUCTOR(func) \
217 static void func(void) __attribute__((constructor)); \
218 static void func(void)
219 #elif defined(__i386__)
220 # define DECL_GLOBAL_CONSTRUCTOR(func) \
221 static void __dummy_init_##func(void) { \
222 asm(".section .init,\"ax\"\n\t" \
223 "call " #func "\n\t" \
225 static void func(void)
226 #elif defined(__sparc__)
227 # define DECL_GLOBAL_CONSTRUCTOR(func) \
228 static void __dummy_init_##func(void) { \
229 asm("\t.section \".init\",#alloc,#execinstr\n" \
230 "\tcall " #func "\n" \
232 "\t.section \".text\",#alloc,#execinstr\n" ); } \
233 static void func(void)
235 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
239 /* Register functions */
242 #define DEFINE_REGS_ENTRYPOINT( name, args, pop_args ) \
243 __ASM_GLOBAL_FUNC( name, \
245 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
246 ".long " __ASM_NAME("__regs_") #name "-.\n\t" \
247 ".byte " #args "," #pop_args )
248 /* FIXME: add support for other CPUs */
249 #endif /* __i386__ */
252 /****************************************************************
253 * Function definitions (only when using libwine_port)
256 #ifndef NO_LIBWINE_PORT
258 #ifndef HAVE_FSTATVFS
259 int fstatvfs( int fd, struct statvfs *buf );
262 #ifndef HAVE_GETOPT_LONG
269 #ifndef HAVE_STRUCT_OPTION_NAME
279 extern int getopt_long (int ___argc, char *const *___argv,
280 const char *__shortopts,
281 const struct option *__longopts, int *__longind);
282 extern int getopt_long_only (int ___argc, char *const *___argv,
283 const char *__shortopts,
284 const struct option *__longopts, int *__longind);
285 #endif /* HAVE_GETOPT_LONG */
293 int futimes(int fd, const struct timeval tv[2]);
296 #ifndef HAVE_GETPAGESIZE
297 size_t getpagesize(void);
298 #endif /* HAVE_GETPAGESIZE */
302 #endif /* HAVE_GETTID */
305 int lstat(const char *file_name, struct stat *buf);
306 #endif /* HAVE_LSTAT */
309 void *memmove(void *dest, const void *src, size_t len);
310 #endif /* !defined(HAVE_MEMMOVE) */
313 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
314 #endif /* HAVE_PREAD */
317 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
318 #endif /* HAVE_PWRITE */
320 #ifndef HAVE_READLINK
321 int readlink( const char *path, char *buf, size_t size );
322 #endif /* HAVE_READLINK */
324 #ifndef HAVE_SIGSETJMP
326 typedef jmp_buf sigjmp_buf;
327 int sigsetjmp( sigjmp_buf buf, int savesigs );
328 void siglongjmp( sigjmp_buf buf, int val );
329 #endif /* HAVE_SIGSETJMP */
332 int statvfs( const char *path, struct statvfs *buf );
335 #ifndef HAVE_STRNCASECMP
336 # ifndef HAVE__STRNICMP
337 int strncasecmp(const char *str1, const char *str2, size_t n);
339 # define strncasecmp _strnicmp
341 #endif /* !defined(HAVE_STRNCASECMP) */
343 #ifndef HAVE_STRERROR
344 const char *strerror(int err);
345 #endif /* !defined(HAVE_STRERROR) */
347 #ifndef HAVE_STRCASECMP
348 # ifndef HAVE__STRICMP
349 int strcasecmp(const char *str1, const char *str2);
351 # define strcasecmp _stricmp
353 #endif /* !defined(HAVE_STRCASECMP) */
356 int usleep (unsigned int useconds);
357 #endif /* !defined(HAVE_USLEEP) */
360 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
362 return memcpy( dst, src, size );
365 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
366 #endif /* __i386__ */
368 extern int mkstemps(char *template, int suffix_len);
370 /* Process creation flags */
374 # define _P_OVERLAY 2
375 # define _P_NOWAITO 3
379 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
382 /* Interlocked functions */
384 #if defined(__i386__) && defined(__GNUC__)
386 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
387 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
388 extern inline int interlocked_xchg( int *dest, int val );
389 extern inline void *interlocked_xchg_ptr( void **dest, void *val );
390 extern inline int interlocked_xchg_add( int *dest, int incr );
392 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
395 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
396 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
400 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
403 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
404 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
408 extern inline int interlocked_xchg( int *dest, int val )
411 __asm__ __volatile__( "lock; xchgl %0,(%1)"
412 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
416 extern inline void *interlocked_xchg_ptr( void **dest, void *val )
419 __asm__ __volatile__( "lock; xchgl %0,(%1)"
420 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
424 extern inline int interlocked_xchg_add( int *dest, int incr )
427 __asm__ __volatile__( "lock; xaddl %0,(%1)"
428 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
432 #else /* __i386___ && __GNUC__ */
434 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
435 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
436 extern int interlocked_xchg( int *dest, int val );
437 extern void *interlocked_xchg_ptr( void **dest, void *val );
438 extern int interlocked_xchg_add( int *dest, int incr );
440 #endif /* __i386___ && __GNUC__ */
442 #else /* NO_LIBWINE_PORT */
444 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
446 #define ffs __WINE_NOT_PORTABLE(ffs)
447 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
448 #define futimes __WINE_NOT_PORTABLE(futimes)
449 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
450 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
451 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
452 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
453 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
454 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
455 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
456 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
457 #define lstat __WINE_NOT_PORTABLE(lstat)
458 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
460 #define memmove __WINE_NOT_PORTABLE(memmove)
461 #define pread __WINE_NOT_PORTABLE(pread)
462 #define pwrite __WINE_NOT_PORTABLE(pwrite)
463 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
464 #define statvfs __WINE_NOT_PORTABLE(statvfs)
465 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
466 #define strerror __WINE_NOT_PORTABLE(strerror)
467 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
468 #define usleep __WINE_NOT_PORTABLE(usleep)
470 #endif /* NO_LIBWINE_PORT */
472 #endif /* !defined(__WINE_WINE_PORT_H) */