Made INSTR_EmulateInstruction return the exception code.
[wine.git] / include / wine / port.h
blob8039a8732e7aec9099c660963b3f9c43b0356816
1 /*
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
26 #endif
28 #define _GNU_SOURCE /* for pread/pwrite */
29 #include <fcntl.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #ifdef HAVE_DIRECT_H
33 # include <direct.h>
34 #endif
35 #ifdef HAVE_IO_H
36 # include <io.h>
37 #endif
38 #include <string.h>
39 #ifdef HAVE_UNISTD_H
40 # include <unistd.h>
41 #endif
44 /****************************************************************
45 * Type definitions
48 #ifndef HAVE_MODE_T
49 typedef int mode_t;
50 #endif
51 #ifndef HAVE_OFF_T
52 typedef long off_t;
53 #endif
54 #ifndef HAVE_PID_T
55 typedef int pid_t;
56 #endif
57 #ifndef HAVE_SIZE_T
58 typedef unsigned int size_t;
59 #endif
60 #ifndef HAVE_SSIZE_T
61 typedef int ssize_t;
62 #endif
64 #ifndef HAVE_STATFS
65 # ifdef __BEOS__
66 # define HAVE_STRUCT_STATFS_F_BFREE
67 struct statfs {
68 long f_bsize; /* block_size */
69 long f_blocks; /* total_blocks */
70 long f_bfree; /* free_blocks */
72 # else /* defined(__BEOS__) */
73 struct statfs;
74 # endif /* defined(__BEOS__) */
75 #endif /* !defined(HAVE_STATFS) */
78 /****************************************************************
79 * Macro definitions
82 #ifdef HAVE_DLFCN_H
83 #include <dlfcn.h>
84 #else
85 #define RTLD_LAZY 0x001
86 #define RTLD_NOW 0x002
87 #define RTLD_GLOBAL 0x100
88 #endif
90 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
91 #define ftruncate chsize
92 #endif
94 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
95 #define popen _popen
96 #endif
98 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
99 #define pclose _pclose
100 #endif
102 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
103 #define snprintf _snprintf
104 #endif
106 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
107 #define vsnprintf _vsnprintf
108 #endif
110 #ifndef S_ISLNK
111 # define S_ISLNK(mod) (0)
112 #endif /* S_ISLNK */
114 /* So we open files in 64 bit access mode on Linux */
115 #ifndef O_LARGEFILE
116 # define O_LARGEFILE 0
117 #endif
119 /* Macros to define assembler functions somewhat portably */
121 #ifdef __GNUC__
122 # define __ASM_GLOBAL_FUNC(name,code) \
123 __asm__( ".align 4\n\t" \
124 ".globl " __ASM_NAME(#name) "\n\t" \
125 __ASM_FUNC(#name) "\n" \
126 __ASM_NAME(#name) ":\n\t" \
127 code );
128 #else /* __GNUC__ */
129 # define __ASM_GLOBAL_FUNC(name,code) \
130 void __asm_dummy_##name(void) { \
131 asm( ".align 4\n\t" \
132 ".globl " __ASM_NAME(#name) "\n\t" \
133 __ASM_FUNC(#name) "\n" \
134 __ASM_NAME(#name) ":\n\t" \
135 code ); \
137 #endif /* __GNUC__ */
140 /* Constructor functions */
142 #ifdef __GNUC__
143 # define DECL_GLOBAL_CONSTRUCTOR(func) \
144 static void func(void) __attribute__((constructor)); \
145 static void func(void)
146 #elif defined(__i386__)
147 # define DECL_GLOBAL_CONSTRUCTOR(func) \
148 static void __dummy_init_##func(void) { \
149 asm(".section .init,\"ax\"\n\t" \
150 "call " #func "\n\t" \
151 ".previous"); } \
152 static void func(void)
153 #elif defined(__sparc__)
154 # define DECL_GLOBAL_CONSTRUCTOR(func) \
155 static void __dummy_init_##func(void) { \
156 asm("\t.section \".init\",#alloc,#execinstr\n" \
157 "\tcall " #func "\n" \
158 "\tnop\n" \
159 "\t.section \".text\",#alloc,#execinstr\n" ); } \
160 static void func(void)
161 #else
162 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
163 #endif
166 /****************************************************************
167 * Function definitions (only when using libwine_port)
170 #ifndef NO_LIBWINE_PORT
172 #ifndef HAVE_GETOPT_LONG
173 extern char *optarg;
174 extern int optind;
175 extern int opterr;
176 extern int optopt;
177 struct option;
179 #ifndef HAVE_STRUCT_OPTION_NAME
180 struct option
182 const char *name;
183 int has_arg;
184 int *flag;
185 int val;
187 #endif
189 extern int getopt_long (int ___argc, char *const *___argv,
190 const char *__shortopts,
191 const struct option *__longopts, int *__longind);
192 extern int getopt_long_only (int ___argc, char *const *___argv,
193 const char *__shortopts,
194 const struct option *__longopts, int *__longind);
195 #endif /* HAVE_GETOPT_LONG */
197 #ifndef HAVE_GETPAGESIZE
198 size_t getpagesize(void);
199 #endif /* HAVE_GETPAGESIZE */
201 #ifndef HAVE_LSTAT
202 int lstat(const char *file_name, struct stat *buf);
203 #endif /* HAVE_LSTAT */
205 #ifndef HAVE_MEMMOVE
206 void *memmove(void *dest, const void *src, size_t len);
207 #endif /* !defined(HAVE_MEMMOVE) */
209 #ifndef HAVE_PREAD
210 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
211 #endif /* HAVE_PREAD */
213 #ifndef HAVE_PWRITE
214 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
215 #endif /* HAVE_PWRITE */
217 #ifndef HAVE_STATFS
218 int statfs(const char *name, struct statfs *info);
219 #endif /* !defined(HAVE_STATFS) */
221 #ifndef HAVE_STRNCASECMP
222 # ifndef HAVE__STRNICMP
223 int strncasecmp(const char *str1, const char *str2, size_t n);
224 # else
225 # define strncasecmp _strnicmp
226 # endif
227 #endif /* !defined(HAVE_STRNCASECMP) */
229 #ifndef HAVE_STRERROR
230 const char *strerror(int err);
231 #endif /* !defined(HAVE_STRERROR) */
233 #ifndef HAVE_STRCASECMP
234 # ifndef HAVE__STRICMP
235 int strcasecmp(const char *str1, const char *str2);
236 # else
237 # define strcasecmp _stricmp
238 # endif
239 #endif /* !defined(HAVE_STRCASECMP) */
241 #ifndef HAVE_USLEEP
242 int usleep (unsigned int useconds);
243 #endif /* !defined(HAVE_USLEEP) */
245 #ifdef __i386__
246 extern inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
248 return memcpy( dst, src, size );
250 #else
251 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
252 #endif /* __i386__ */
254 extern int mkstemps(char *template, int suffix_len);
256 /* Process creation flags */
257 #ifndef _P_WAIT
258 # define _P_WAIT 0
259 # define _P_NOWAIT 1
260 # define _P_OVERLAY 2
261 # define _P_NOWAITO 3
262 # define _P_DETACH 4
263 #endif
264 extern int spawnvp(int mode, const char *cmdname, char *const argv[]);
266 /* Interlocked functions */
268 #if defined(__i386__) && defined(__GNUC__)
270 extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare )
272 long ret;
273 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
274 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
275 return ret;
278 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
280 void *ret;
281 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
282 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
283 return ret;
286 extern inline long interlocked_xchg( long *dest, long val )
288 long ret;
289 __asm__ __volatile__( "lock; xchgl %0,(%1)"
290 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
291 return ret;
294 extern inline void *interlocked_xchg_ptr( void **dest, void *val )
296 void *ret;
297 __asm__ __volatile__( "lock; xchgl %0,(%1)"
298 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
299 return ret;
302 extern inline long interlocked_xchg_add( long *dest, long incr )
304 long ret;
305 __asm__ __volatile__( "lock; xaddl %0,(%1)"
306 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
307 return ret;
310 #else /* __i386___ && __GNUC__ */
312 extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
313 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
314 extern long interlocked_xchg( long *dest, long val );
315 extern void *interlocked_xchg_ptr( void **dest, void *val );
316 extern long interlocked_xchg_add( long *dest, long incr );
318 #endif /* __i386___ && __GNUC__ */
320 #else /* NO_LIBWINE_PORT */
322 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
324 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
325 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
326 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
327 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
328 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
329 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
330 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
331 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
332 #define lstat __WINE_NOT_PORTABLE(lstat)
333 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
334 #define memmove __WINE_NOT_PORTABLE(memmove)
335 #define pread __WINE_NOT_PORTABLE(pread)
336 #define pwrite __WINE_NOT_PORTABLE(pwrite)
337 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
338 #define statfs __WINE_NOT_PORTABLE(statfs)
339 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
340 #define strerror __WINE_NOT_PORTABLE(strerror)
341 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
342 #define usleep __WINE_NOT_PORTABLE(usleep)
344 #endif /* NO_LIBWINE_PORT */
346 #endif /* !defined(__WINE_WINE_PORT_H) */