VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/shaderlib/libWineStub/include/wine/port.h

Last change on this file was 66828, checked in by vboxsync, 8 years ago

Devices: Adjustments for Visual C++ v12 / Visual Studio 2013. New warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.2 KB
Line 
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21/*
22 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
23 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
24 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
25 * a choice of LGPL license versions is made available with the language indicating
26 * that LGPLv2 or any later version may be used, or where a choice of which version
27 * of the LGPL is applied is otherwise unspecified.
28 */
29
30#ifndef __WINE_WINE_PORT_H
31#define __WINE_WINE_PORT_H
32
33#ifndef __WINE_CONFIG_H
34# error You must include config.h to use this header
35#endif
36
37#ifdef __WINE_BASETSD_H
38# error You must include port.h before all other headers
39#endif
40
41#define _GNU_SOURCE /* for pread/pwrite */
42#include <fcntl.h>
43#include <math.h>
44#include <sys/types.h>
45#include <sys/stat.h>
46#ifdef HAVE_DIRECT_H
47# include <direct.h>
48#endif
49#ifdef HAVE_IO_H
50# include <io.h>
51#endif
52#ifdef HAVE_PROCESS_H
53# include <process.h>
54#endif
55#include <string.h>
56#ifdef HAVE_UNISTD_H
57# include <unistd.h>
58#endif
59
60/* Can't use windef.h here, cause it'd cause problems with NONAMELESSUNION/STRUCT later */
61#ifndef inline
62#define inline
63#endif
64
65/****************************************************************
66 * Type definitions
67 */
68
69#if !defined(_MSC_VER) && !defined(__int64)
70# if defined(__x86_64__) || defined(_WIN64)
71# define __int64 long
72# else
73# define __int64 long long
74# endif
75#endif
76
77#ifndef HAVE_MODE_T
78typedef int mode_t;
79#endif
80#ifndef HAVE_OFF_T
81typedef long off_t;
82#endif
83#ifndef HAVE_PID_T
84typedef int pid_t;
85#endif
86#ifndef HAVE_SIZE_T
87typedef unsigned int size_t;
88#endif
89#ifndef HAVE_SSIZE_T
90typedef int ssize_t;
91#endif
92#ifndef HAVE_FSBLKCNT_T
93typedef unsigned long fsblkcnt_t;
94#endif
95#ifndef HAVE_FSFILCNT_T
96typedef unsigned long fsfilcnt_t;
97#endif
98
99#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
100struct statvfs
101{
102 unsigned long f_bsize;
103 unsigned long f_frsize;
104 fsblkcnt_t f_blocks;
105 fsblkcnt_t f_bfree;
106 fsblkcnt_t f_bavail;
107 fsfilcnt_t f_files;
108 fsfilcnt_t f_ffree;
109 fsfilcnt_t f_favail;
110 unsigned long f_fsid;
111 unsigned long f_flag;
112 unsigned long f_namemax;
113};
114#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
115
116
117/****************************************************************
118 * Macro definitions
119 */
120
121#ifdef HAVE_DLFCN_H
122#include <dlfcn.h>
123#else
124#define RTLD_LAZY 0x001
125#define RTLD_NOW 0x002
126#define RTLD_GLOBAL 0x100
127#endif
128
129#ifdef HAVE_ONE_ARG_MKDIR
130#define mkdir(path,mode) mkdir(path)
131#endif
132
133#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
134#define ftruncate chsize
135#endif
136
137#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
138#define popen _popen
139#endif
140
141#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
142#define pclose _pclose
143#endif
144
145#if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
146#define strdup _strdup
147#endif
148
149#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
150#define snprintf _snprintf
151#endif
152
153#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
154#define vsnprintf _vsnprintf
155#endif
156
157#if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
158#define strtoll _strtoi64
159#endif
160
161#if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
162#define strtoull _strtoui64
163#endif
164
165#ifndef S_ISLNK
166# define S_ISLNK(mod) (0)
167#endif
168
169#ifndef S_ISSOCK
170# define S_ISSOCK(mod) (0)
171#endif
172
173#ifndef S_ISDIR
174# define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
175#endif
176
177#ifndef S_ISCHR
178# define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
179#endif
180
181#ifndef S_ISFIFO
182# define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
183#endif
184
185#ifndef S_ISREG
186# define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
187#endif
188
189/* So we open files in 64 bit access mode on Linux */
190#ifndef O_LARGEFILE
191# define O_LARGEFILE 0
192#endif
193
194#ifndef O_NONBLOCK
195# define O_NONBLOCK 0
196#endif
197
198#ifndef O_BINARY
199# define O_BINARY 0
200#endif
201
202
203/****************************************************************
204 * Constants
205 */
206
207#ifndef M_PI
208#define M_PI 3.14159265358979323846
209#endif
210
211#ifndef M_PI_2
212#define M_PI_2 1.570796326794896619
213#endif
214
215
216/****************************************************************
217 * Function definitions (only when using libwine_port)
218 */
219
220#ifndef NO_LIBWINE_PORT
221
222#ifndef HAVE_FSTATVFS
223int fstatvfs( int fd, struct statvfs *buf );
224#endif
225
226#ifndef HAVE_GETOPT_LONG
227extern char *optarg;
228extern int optind;
229extern int opterr;
230extern int optopt;
231struct option;
232
233#ifndef HAVE_STRUCT_OPTION_NAME
234struct option
235{
236 const char *name;
237 int has_arg;
238 int *flag;
239 int val;
240};
241#endif
242
243extern int getopt_long (int ___argc, char *const *___argv,
244 const char *__shortopts,
245 const struct option *__longopts, int *__longind);
246extern int getopt_long_only (int ___argc, char *const *___argv,
247 const char *__shortopts,
248 const struct option *__longopts, int *__longind);
249#endif /* HAVE_GETOPT_LONG */
250
251#ifndef HAVE_FFS
252int ffs( int x );
253#endif
254
255#ifndef HAVE_FUTIMES
256struct timeval;
257int futimes(int fd, const struct timeval *tv);
258#endif
259
260#ifndef HAVE_GETPAGESIZE
261size_t getpagesize(void);
262#endif /* HAVE_GETPAGESIZE */
263
264#ifndef HAVE_GETTID
265pid_t gettid(void);
266#endif /* HAVE_GETTID */
267
268#ifndef HAVE_ISINF
269# undef isinf /* VBox: _MSC_VER >= RT_MSC_VER_VC120 has complicated macro implementation in math.h */
270int isinf(double x);
271#endif
272
273#ifndef HAVE_ISNAN
274# undef isnan /* VBox: _MSC_VER >= RT_MSC_VER_VC120 has complicated macro implementation in math.h */
275int isnan(double x);
276#endif
277
278#ifndef HAVE_LSTAT
279int lstat(const char *file_name, struct stat *buf);
280#endif /* HAVE_LSTAT */
281
282#ifndef HAVE_MEMMOVE
283void *memmove(void *dest, const void *src, size_t len);
284#endif /* !defined(HAVE_MEMMOVE) */
285
286#ifndef HAVE_POLL
287struct pollfd
288{
289 int fd;
290 short events;
291 short revents;
292};
293#define POLLIN 0x01
294#define POLLPRI 0x02
295#define POLLOUT 0x04
296#define POLLERR 0x08
297#define POLLHUP 0x10
298#define POLLNVAL 0x20
299int poll( struct pollfd *fds, unsigned int count, int timeout );
300#endif /* HAVE_POLL */
301
302#ifndef HAVE_PREAD
303ssize_t pread( int fd, void *buf, size_t count, off_t offset );
304#endif /* HAVE_PREAD */
305
306#ifndef HAVE_PWRITE
307ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
308#endif /* HAVE_PWRITE */
309
310#ifndef HAVE_READLINK
311int readlink( const char *path, char *buf, size_t size );
312#endif /* HAVE_READLINK */
313
314#ifndef HAVE_STATVFS
315int statvfs( const char *path, struct statvfs *buf );
316#endif
317
318#ifndef HAVE_STRNCASECMP
319# ifndef HAVE__STRNICMP
320int strncasecmp(const char *str1, const char *str2, size_t n);
321# else
322# define strncasecmp _strnicmp
323# endif
324#endif /* !defined(HAVE_STRNCASECMP) */
325
326#ifndef HAVE_STRERROR
327const char *strerror(int err);
328#endif /* !defined(HAVE_STRERROR) */
329
330#ifndef HAVE_STRCASECMP
331# ifndef HAVE__STRICMP
332int strcasecmp(const char *str1, const char *str2);
333# else
334# define strcasecmp _stricmp
335# endif
336#endif /* !defined(HAVE_STRCASECMP) */
337
338#ifndef HAVE_SYMLINK
339int symlink(const char *from, const char *to);
340#endif
341
342#ifndef HAVE_USLEEP
343int usleep (unsigned int useconds);
344#endif /* !defined(HAVE_USLEEP) */
345
346#ifdef __i386__
347static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
348{
349 return memcpy( dst, src, size );
350}
351#else
352extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
353#endif /* __i386__ */
354
355extern int mkstemps(char *template, int suffix_len);
356
357/* Process creation flags */
358#ifndef _P_WAIT
359# define _P_WAIT 0
360# define _P_NOWAIT 1
361# define _P_OVERLAY 2
362# define _P_NOWAITO 3
363# define _P_DETACH 4
364#endif
365#ifndef HAVE_SPAWNVP
366extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
367#endif
368
369/* Interlocked functions */
370
371#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
372
373extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
374extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
375extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
376extern inline int interlocked_xchg( int *dest, int val );
377extern inline void *interlocked_xchg_ptr( void **dest, void *val );
378extern inline int interlocked_xchg_add( int *dest, int incr );
379
380extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
381{
382 int ret;
383 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
384 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
385 return ret;
386}
387
388extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
389{
390 void *ret;
391#ifdef __x86_64__
392 __asm__ __volatile__( "lock; cmpxchgq %2,(%1)"
393 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
394#else
395 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
396 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
397#endif
398 return ret;
399}
400
401extern inline int interlocked_xchg( int *dest, int val )
402{
403 int ret;
404 __asm__ __volatile__( "lock; xchgl %0,(%1)"
405 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
406 return ret;
407}
408
409extern inline void *interlocked_xchg_ptr( void **dest, void *val )
410{
411 void *ret;
412#ifdef __x86_64__
413 __asm__ __volatile__( "lock; xchgq %0,(%1)"
414 : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
415#else
416 __asm__ __volatile__( "lock; xchgl %0,(%1)"
417 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
418#endif
419 return ret;
420}
421
422extern inline int interlocked_xchg_add( int *dest, int incr )
423{
424 int ret;
425 __asm__ __volatile__( "lock; xaddl %0,(%1)"
426 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
427 return ret;
428}
429
430#ifdef __x86_64__
431extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
432 __int64 xchg_low, __int64 *compare );
433extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
434 __int64 xchg_low, __int64 *compare )
435{
436 unsigned char ret;
437 __asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
438 : "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
439 "=a" (compare[0]), "=d" (compare[1])
440 : "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
441 "c" (xchg_high), "b" (xchg_low) );
442 return ret;
443}
444#endif
445
446#else /* __GNUC__ */
447
448extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
449extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
450extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
451extern int interlocked_xchg( int *dest, int val );
452extern void *interlocked_xchg_ptr( void **dest, void *val );
453extern int interlocked_xchg_add( int *dest, int incr );
454#ifdef _WIN64
455extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
456 __int64 xchg_low, __int64 *compare );
457#endif
458
459#endif /* __GNUC__ */
460
461#else /* NO_LIBWINE_PORT */
462
463#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
464
465#define ffs __WINE_NOT_PORTABLE(ffs)
466#define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
467#define futimes __WINE_NOT_PORTABLE(futimes)
468#define getopt_long __WINE_NOT_PORTABLE(getopt_long)
469#define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
470#define getpagesize __WINE_NOT_PORTABLE(getpagesize)
471#define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
472#define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
473#define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
474#define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
475#define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
476#define lstat __WINE_NOT_PORTABLE(lstat)
477#define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
478#undef memmove
479#define memmove __WINE_NOT_PORTABLE(memmove)
480#define pread __WINE_NOT_PORTABLE(pread)
481#define pwrite __WINE_NOT_PORTABLE(pwrite)
482#define spawnvp __WINE_NOT_PORTABLE(spawnvp)
483#define statvfs __WINE_NOT_PORTABLE(statvfs)
484#define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
485#define strerror __WINE_NOT_PORTABLE(strerror)
486#define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
487#define usleep __WINE_NOT_PORTABLE(usleep)
488
489#endif /* NO_LIBWINE_PORT */
490
491#endif /* !defined(__WINE_WINE_PORT_H) */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette