ReactOS 0.4.15-dev-7660-g0086d05
port.h
Go to the documentation of this file.
1/*
2 * Wine porting definitions
3 *
4 * Copyright 1996 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef __WINE_WINE_PORT_H
22#define __WINE_WINE_PORT_H
23
24#ifndef __WINE_CONFIG_H
25# error You must include config.h to use this header
26#endif
27
28#define _GNU_SOURCE /* for pread/pwrite */
29#include <fcntl.h>
30#include <math.h>
31#include <sys/types.h>
32#include <sys/stat.h>
33#ifdef HAVE_DIRECT_H
34# include <direct.h>
35#endif
36#ifdef HAVE_IO_H
37# include <io.h>
38#endif
39#ifdef HAVE_PROCESS_H
40# include <process.h>
41#endif
42#include <string.h>
43#ifdef HAVE_UNISTD_H
44# include <unistd.h>
45#endif
46
47
48/****************************************************************
49 * Type definitions
50 */
51
52#ifndef HAVE_MODE_T
53typedef int mode_t;
54#endif
55#ifndef HAVE_OFF_T
56typedef long off_t;
57#endif
58#ifndef HAVE_PID_T
59typedef int pid_t;
60#endif
61#ifndef HAVE_SIZE_T
62typedef unsigned int size_t;
63#endif
64#ifndef HAVE_SSIZE_T
65typedef int ssize_t;
66#endif
67#ifndef HAVE_FSBLKCNT_T
68typedef unsigned long fsblkcnt_t;
69#endif
70#ifndef HAVE_FSFILCNT_T
71typedef unsigned long fsfilcnt_t;
72#endif
73
74#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
75struct statvfs
76{
77 unsigned long f_bsize;
78 unsigned long f_frsize;
85 unsigned long f_fsid;
86 unsigned long f_flag;
87 unsigned long f_namemax;
88};
89#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
90
91
92/****************************************************************
93 * Macro definitions
94 */
95
96#ifdef HAVE_DLFCN_H
97#include <dlfcn.h>
98#else
99#define RTLD_LAZY 0x001
100#define RTLD_NOW 0x002
101#define RTLD_GLOBAL 0x100
102#endif
103
104#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
105#define ftruncate chsize
106#endif
107
108#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
109#define popen _popen
110#endif
111
112#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
113#define pclose _pclose
114#endif
115
116#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
117#define snprintf _snprintf
118#endif
119
120#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
121#define vsnprintf _vsnprintf
122#endif
123
124#ifndef S_ISLNK
125# define S_ISLNK(mod) (0)
126#endif
127
128#ifndef S_ISSOCK
129# define S_ISSOCK(mod) (0)
130#endif
131
132#ifndef S_ISDIR
133# define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
134#endif
135
136#ifndef S_ISCHR
137# define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
138#endif
139
140#ifndef S_ISFIFO
141# define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
142#endif
143
144#ifndef S_ISREG
145# define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
146#endif
147
148#ifndef S_IWUSR
149# define S_IWUSR 0
150#endif
151
152/* So we open files in 64 bit access mode on Linux */
153#ifndef O_LARGEFILE
154# define O_LARGEFILE 0
155#endif
156
157#ifndef O_NONBLOCK
158# define O_NONBLOCK 0
159#endif
160
161#ifndef O_BINARY
162# define O_BINARY 0
163#endif
164
165#if !defined(S_IXUSR) && defined(S_IEXEC)
166# define S_IXUSR S_IEXEC
167#endif
168#if !defined(S_IXGRP) && defined(S_IEXEC)
169# define S_IXGRP S_IEXEC
170#endif
171#if !defined(S_IXOTH) && defined(S_IEXEC)
172# define S_IXOTH S_IEXEC
173#endif
174
175
176/****************************************************************
177 * Constants
178 */
179
180#ifndef M_PI
181#define M_PI 3.14159265358979323846
182#endif
183
184#ifndef M_PI_2
185#define M_PI_2 1.570796326794896619
186#endif
187
188
189/* Macros to define assembler functions somewhat portably */
190
191#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
192# define __ASM_GLOBAL_FUNC(name,code) \
193 __asm__( ".text\n\t" \
194 ".align 4\n\t" \
195 ".globl " __ASM_NAME(#name) "\n\t" \
196 __ASM_FUNC(#name) "\n" \
197 __ASM_NAME(#name) ":\n\t" \
198 code \
199 "\n\t.previous" );
200#else /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__) */
201# define __ASM_GLOBAL_FUNC(name,code) \
202 void __asm_dummy_##name(void) { \
203 asm( ".align 4\n\t" \
204 ".globl " __ASM_NAME(#name) "\n\t" \
205 __ASM_FUNC(#name) "\n" \
206 __ASM_NAME(#name) ":\n\t" \
207 code ); \
208 }
209#endif /* __GNUC__ */
210
211
212/* Constructor functions */
213
214#ifdef __GNUC__
215# define DECL_GLOBAL_CONSTRUCTOR(func) \
216 static void func(void) __attribute__((constructor)); \
217 static void func(void)
218#elif defined(__i386__)
219# define DECL_GLOBAL_CONSTRUCTOR(func) \
220 static void __dummy_init_##func(void) { \
221 asm(".section .init,\"ax\"\n\t" \
222 "call " #func "\n\t" \
223 ".previous"); } \
224 static void func(void)
225#elif defined(__sparc__)
226# define DECL_GLOBAL_CONSTRUCTOR(func) \
227 static void __dummy_init_##func(void) { \
228 asm("\t.section \".init\",#alloc,#execinstr\n" \
229 "\tcall " #func "\n" \
230 "\tnop\n" \
231 "\t.section \".text\",#alloc,#execinstr\n" ); } \
232 static void func(void)
233#else
234# error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
235#endif
236
237
238/* Register functions */
239
240#ifdef __i386__
241#define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
242 __ASM_GLOBAL_FUNC( name, \
243 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
244 ".long " __ASM_NAME(#fn) "\n\t" \
245 ".byte " #args "," #pop_args )
246/* FIXME: add support for other CPUs */
247#endif /* __i386__ */
248
249
250/****************************************************************
251 * Function definitions (only when using libwine_port)
252 */
253
254#ifndef NO_LIBWINE_PORT
255
256#ifndef HAVE_FSTATVFS
257int fstatvfs( int fd, struct statvfs *buf );
258#endif
259
260#ifndef HAVE_GETOPT_LONG
261extern char *optarg;
262extern int optind;
263extern int opterr;
264extern int optopt;
265struct option;
266
267#ifndef HAVE_STRUCT_OPTION_NAME
268struct option
269{
270 const char *name;
271 int has_arg;
272 int *flag;
273 int val;
274};
275#endif
276
277extern int getopt_long (int ___argc, char *const *___argv,
278 const char *__shortopts,
279 const struct option *__longopts, int *__longind);
280extern int getopt_long_only (int ___argc, char *const *___argv,
281 const char *__shortopts,
282 const struct option *__longopts, int *__longind);
283#endif /* HAVE_GETOPT_LONG */
284
285#ifndef HAVE_FFS
286int ffs( int x );
287#endif
288
289#ifndef HAVE_FUTIMES
290struct timeval;
291int futimes(int fd, const struct timeval tv[2]);
292#endif
293
294#ifndef HAVE_GETPAGESIZE
295size_t getpagesize(void);
296#endif /* HAVE_GETPAGESIZE */
297
298#ifndef HAVE_GETTID
300#endif /* HAVE_GETTID */
301
302#ifndef HAVE_LSTAT
303int lstat(const char *file_name, struct stat *buf);
304#endif /* HAVE_LSTAT */
305
306#ifndef HAVE_MEMMOVE
307void *memmove(void *dest, const void *src, size_t len);
308#endif /* !defined(HAVE_MEMMOVE) */
309
310#ifndef HAVE_PREAD
311ssize_t pread( int fd, void *buf, size_t count, off_t offset );
312#endif /* HAVE_PREAD */
313
314#ifndef HAVE_PWRITE
315ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
316#endif /* HAVE_PWRITE */
317
318#ifndef HAVE_READLINK
319int readlink( const char *path, char *buf, size_t size );
320#endif /* HAVE_READLINK */
321
322#ifndef HAVE_SIGSETJMP
323# include <setjmp.h>
325int sigsetjmp( sigjmp_buf buf, int savesigs );
327#endif /* HAVE_SIGSETJMP */
328
329#ifndef HAVE_STATVFS
330int statvfs( const char *path, struct statvfs *buf );
331#endif
332
333#ifndef HAVE_STRNCASECMP
334# ifndef HAVE__STRNICMP
335int strncasecmp(const char *str1, const char *str2, size_t n);
336# else
337# define strncasecmp _strnicmp
338# endif
339#endif /* !defined(HAVE_STRNCASECMP) */
340
341#ifndef HAVE_STRERROR
342const char *strerror(int err);
343#endif /* !defined(HAVE_STRERROR) */
344
345#ifndef HAVE_STRCASECMP
346# ifndef HAVE__STRICMP
347int strcasecmp(const char *str1, const char *str2);
348# else
349# define strcasecmp _stricmp
350# endif
351#endif /* !defined(HAVE_STRCASECMP) */
352
353#ifndef HAVE_USLEEP
354int usleep (unsigned int useconds);
355#endif /* !defined(HAVE_USLEEP) */
356
357#ifdef __i386__
358static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
359{
360 return memcpy( dst, src, size );
361}
362#else
363extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
364#endif /* __i386__ */
365
366extern int mkstemps(char *template, int suffix_len);
367
368/* Process creation flags */
369#ifndef _P_WAIT
370# define _P_WAIT 0
371# define _P_NOWAIT 1
372# define _P_OVERLAY 2
373# define _P_NOWAITO 3
374# define _P_DETACH 4
375#endif
376#ifndef HAVE_SPAWNVP
377extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
378#endif
379
380/* Interlocked functions */
381
382#if defined(__i386__) && defined(__GNUC__)
383
384extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare );
385extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
386extern inline long interlocked_xchg( long *dest, long val );
387extern inline void *interlocked_xchg_ptr( void **dest, void *val );
388extern inline long interlocked_xchg_add( long *dest, long incr );
389
390extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare )
391{
392 long ret;
393 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
394 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
395 return ret;
396}
397
398extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
399{
400 void *ret;
401 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
402 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
403 return ret;
404}
405
406extern inline long interlocked_xchg( long *dest, long val )
407{
408 long ret;
409 __asm__ __volatile__( "lock; xchgl %0,(%1)"
410 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
411 return ret;
412}
413
414extern inline void *interlocked_xchg_ptr( void **dest, void *val )
415{
416 void *ret;
417 __asm__ __volatile__( "lock; xchgl %0,(%1)"
418 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
419 return ret;
420}
421
422extern inline long interlocked_xchg_add( long *dest, long incr )
423{
424 long ret;
425 __asm__ __volatile__( "lock; xaddl %0,(%1)"
426 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
427 return ret;
428}
429
430#else /* __i386___ && __GNUC__ */
431
432extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
433extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
434extern long interlocked_xchg( long *dest, long val );
435extern void *interlocked_xchg_ptr( void **dest, void *val );
436extern long interlocked_xchg_add( long *dest, long incr );
437
438#endif /* __i386___ && __GNUC__ */
439
440#else /* NO_LIBWINE_PORT */
441
442#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
443
444#define ffs __WINE_NOT_PORTABLE(ffs)
445#define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
446#define futimes __WINE_NOT_PORTABLE(futimes)
447#define getopt_long __WINE_NOT_PORTABLE(getopt_long)
448#define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
449#define getpagesize __WINE_NOT_PORTABLE(getpagesize)
450#define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
451#define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
452#define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
453#define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
454#define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
455#define lstat __WINE_NOT_PORTABLE(lstat)
456#define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
457#define memmove __WINE_NOT_PORTABLE(memmove)
458#define pread __WINE_NOT_PORTABLE(pread)
459#define pwrite __WINE_NOT_PORTABLE(pwrite)
460#define spawnvp __WINE_NOT_PORTABLE(spawnvp)
461#define statvfs __WINE_NOT_PORTABLE(statvfs)
462#define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
463#define strerror __WINE_NOT_PORTABLE(strerror)
464#define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
465#define usleep __WINE_NOT_PORTABLE(usleep)
466
467#endif /* NO_LIBWINE_PORT */
468
469#endif /* !defined(__WINE_WINE_PORT_H) */
_JBTYPE jmp_buf[_JBLEN]
Definition: setjmp.h:186
DWORD pid_t
Definition: types.h:91
__kernel_off_t off_t
Definition: linux.h:201
#define strncasecmp
Definition: fake.h:10
#define strcasecmp
Definition: fake.h:9
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLenum src
Definition: glext.h:6340
GLenum mode
Definition: glext.h:6217
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum dst
Definition: glext.h:6340
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
#define lstat
Definition: syshdrs.h:49
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static char * dest
Definition: rtl.c:135
static LPCWSTR file_name
Definition: protocol.c:147
int futimes(int fd, const struct timeval tv[2])
unsigned long fsblkcnt_t
Definition: port.h:68
pid_t gettid(void)
int pid_t
Definition: port.h:59
int usleep(unsigned int useconds)
int optopt
Definition: getopt.c:48
int sigsetjmp(sigjmp_buf buf, int savesigs)
int mkstemps(char *template, int suffix_len)
Definition: mkstemps.c:73
int readlink(const char *path, char *buf, size_t size)
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
ssize_t pread(int fd, void *buf, size_t count, off_t offset)
const char * strerror(int err)
Definition: compat_str.c:23
unsigned int size_t
Definition: port.h:62
int mode_t
Definition: port.h:53
int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
Definition: getopt.c:283
unsigned long fsfilcnt_t
Definition: port.h:71
void siglongjmp(sigjmp_buf buf, int val)
size_t getpagesize(void)
int spawnvp(int mode, const char *cmdname, const char *const argv[])
jmp_buf sigjmp_buf
Definition: port.h:324
int optind
Definition: getopt.c:47
char * optarg
Definition: getopt.c:49
void * memcpy_unaligned(void *dst, const void *src, size_t size)
int opterr
Definition: getopt.c:46
int fstatvfs(int fd, struct statvfs *buf)
int ssize_t
Definition: port.h:65
int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
long off_t
Definition: port.h:56
#define argv
Definition: mplay32.c:18
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tmov %rdx, %rbp\n" "\tjmp *%rax\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
#define err(...)
int ssize_t
Definition: rosdhcp.h:48
#define interlocked_cmpxchg_ptr
Definition: port.h:344
#define interlocked_xchg
Definition: port.h:345
#define interlocked_cmpxchg
Definition: port.h:343
#define interlocked_xchg_ptr
Definition: port.h:346
#define interlocked_xchg_add
Definition: port.h:347
#define ffs
Definition: port.h:359
static int fd
Definition: io.c:51
Definition: bug.cpp:8
Definition: getopt.h:109
int val
Definition: getopt.h:115
int * flag
Definition: getopt.h:114
int has_arg
Definition: getopt.h:113
const char * name
Definition: port.h:270
Definition: stat.h:55
Definition: port.h:76
unsigned long f_namemax
Definition: port.h:87
unsigned long f_fsid
Definition: port.h:85
unsigned long f_bsize
Definition: port.h:77
fsblkcnt_t f_bavail
Definition: port.h:81
fsfilcnt_t f_files
Definition: port.h:82
fsfilcnt_t f_ffree
Definition: port.h:83
fsfilcnt_t f_favail
Definition: port.h:84
fsblkcnt_t f_blocks
Definition: port.h:79
fsblkcnt_t f_bfree
Definition: port.h:80
unsigned long f_flag
Definition: port.h:86
unsigned long f_frsize
Definition: port.h:78
int ret