1999-11-13 23:23:35 +01:00
|
|
|
/*
|
|
|
|
* Wine porting definitions
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 1996 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-11-13 23:23:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __WINE_WINE_PORT_H
|
|
|
|
#define __WINE_WINE_PORT_H
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#ifndef __WINE_CONFIG_H
|
|
|
|
# error You must include config.h to use this header
|
|
|
|
#endif
|
2001-07-26 23:43:29 +02:00
|
|
|
|
2007-05-22 18:12:05 +02:00
|
|
|
#ifdef __WINE_BASETSD_H
|
|
|
|
# error You must include port.h before all other headers
|
|
|
|
#endif
|
|
|
|
|
2013-09-19 20:50:55 +02:00
|
|
|
#ifndef _GNU_SOURCE
|
2013-12-05 11:31:20 +01:00
|
|
|
# define _GNU_SOURCE /* for pread/pwrite, isfinite */
|
2013-09-19 20:50:55 +02:00
|
|
|
#endif
|
2001-05-16 21:45:34 +02:00
|
|
|
#include <fcntl.h>
|
2003-07-15 22:45:49 +02:00
|
|
|
#include <math.h>
|
1999-11-13 23:23:35 +01:00
|
|
|
#include <sys/types.h>
|
2000-12-06 21:20:11 +01:00
|
|
|
#include <sys/stat.h>
|
2002-03-11 06:08:38 +01:00
|
|
|
#include <string.h>
|
2013-01-08 22:06:25 +01:00
|
|
|
#include <stdlib.h>
|
2002-03-11 06:08:38 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1999-11-13 23:23:35 +01:00
|
|
|
|
|
|
|
|
2019-03-13 17:05:06 +01:00
|
|
|
/****************************************************************
|
|
|
|
* Hard-coded values for the Windows platform
|
|
|
|
*/
|
|
|
|
|
2019-12-16 11:59:46 +01:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2019-03-13 17:05:06 +01:00
|
|
|
|
|
|
|
#include <direct.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <process.h>
|
|
|
|
|
2019-03-13 17:14:48 +01:00
|
|
|
#define mkdir(path,mode) mkdir(path)
|
|
|
|
|
2019-03-13 17:12:36 +01:00
|
|
|
#ifdef _MSC_VER
|
2019-03-13 17:05:06 +01:00
|
|
|
|
2019-03-13 17:14:48 +01:00
|
|
|
#define ftruncate chsize
|
2019-11-17 13:43:13 +01:00
|
|
|
#ifndef isfinite
|
|
|
|
# define isfinite(x) _finite(x)
|
|
|
|
#endif
|
|
|
|
#ifndef isinf
|
|
|
|
# define isinf(x) (!(_finite(x) || _isnan(x)))
|
|
|
|
#endif
|
|
|
|
#ifndef isnan
|
|
|
|
# define isnan(x) _isnan(x)
|
|
|
|
#endif
|
2019-03-13 17:14:48 +01:00
|
|
|
#define popen _popen
|
|
|
|
#define pclose _pclose
|
2019-11-17 13:43:14 +01:00
|
|
|
/* The UCRT headers in the Windows SDK #error out if we #define snprintf.
|
|
|
|
* The C headers that came with previous Visual Studio versions do not have
|
|
|
|
* snprintf. Check for VS 2015, which appears to be the first version to
|
|
|
|
* use the UCRT headers by default. */
|
|
|
|
#if _MSC_VER < 1900
|
|
|
|
# define snprintf _snprintf
|
|
|
|
#endif
|
2019-03-13 17:14:48 +01:00
|
|
|
#define strtoll _strtoi64
|
|
|
|
#define strtoull _strtoui64
|
|
|
|
#define strncasecmp _strnicmp
|
|
|
|
#define strcasecmp _stricmp
|
|
|
|
|
2019-03-13 17:12:36 +01:00
|
|
|
typedef int mode_t;
|
|
|
|
typedef long off_t;
|
|
|
|
typedef int pid_t;
|
|
|
|
typedef int ssize_t;
|
|
|
|
|
|
|
|
#endif /* _MSC_VER */
|
|
|
|
|
|
|
|
#else /* _WIN32 */
|
2002-04-26 21:05:15 +02:00
|
|
|
|
2019-03-13 17:12:36 +01:00
|
|
|
#ifndef __int64
|
2013-01-18 17:51:46 +01:00
|
|
|
# if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64)
|
2007-02-02 15:35:15 +01:00
|
|
|
# define __int64 long
|
|
|
|
# else
|
|
|
|
# define __int64 long long
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 16:13:23 +01:00
|
|
|
#ifndef HAVE_ISFINITE
|
|
|
|
int isfinite(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ISINF
|
|
|
|
int isinf(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ISNAN
|
|
|
|
int isnan(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Process creation flags */
|
|
|
|
#ifndef _P_WAIT
|
|
|
|
# define _P_WAIT 0
|
|
|
|
# define _P_NOWAIT 1
|
|
|
|
# define _P_OVERLAY 2
|
|
|
|
# define _P_NOWAITO 3
|
|
|
|
# define _P_DETACH 4
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE__SPAWNVP
|
|
|
|
extern int _spawnvp(int mode, const char *cmdname, const char * const argv[]);
|
|
|
|
#endif
|
|
|
|
|
2019-03-13 17:12:36 +01:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Type definitions
|
|
|
|
*/
|
|
|
|
|
2004-03-05 22:03:46 +01:00
|
|
|
#ifndef HAVE_FSBLKCNT_T
|
|
|
|
typedef unsigned long fsblkcnt_t;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_FSFILCNT_T
|
|
|
|
typedef unsigned long fsfilcnt_t;
|
|
|
|
#endif
|
2000-12-01 21:47:11 +01:00
|
|
|
|
2004-03-05 22:03:46 +01:00
|
|
|
#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
|
|
|
|
struct statvfs
|
|
|
|
{
|
|
|
|
unsigned long f_bsize;
|
|
|
|
unsigned long f_frsize;
|
|
|
|
fsblkcnt_t f_blocks;
|
|
|
|
fsblkcnt_t f_bfree;
|
|
|
|
fsblkcnt_t f_bavail;
|
|
|
|
fsfilcnt_t f_files;
|
|
|
|
fsfilcnt_t f_ffree;
|
|
|
|
fsfilcnt_t f_favail;
|
|
|
|
unsigned long f_fsid;
|
|
|
|
unsigned long f_flag;
|
|
|
|
unsigned long f_namemax;
|
1999-11-13 23:23:35 +01:00
|
|
|
};
|
2004-03-05 22:03:46 +01:00
|
|
|
#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
|
1999-11-13 23:23:35 +01:00
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Macro definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DLFCN_H
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#else
|
|
|
|
#define RTLD_LAZY 0x001
|
|
|
|
#define RTLD_NOW 0x002
|
|
|
|
#define RTLD_GLOBAL 0x100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
# define S_ISLNK(mod) (0)
|
2004-04-23 01:45:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISSOCK
|
|
|
|
# define S_ISSOCK(mod) (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
# define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISCHR
|
|
|
|
# define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISFIFO
|
|
|
|
# define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISREG
|
|
|
|
# define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
/* So we open files in 64 bit access mode on Linux */
|
|
|
|
#ifndef O_LARGEFILE
|
|
|
|
# define O_LARGEFILE 0
|
|
|
|
#endif
|
|
|
|
|
2004-02-12 23:39:18 +01:00
|
|
|
#ifndef O_NONBLOCK
|
|
|
|
# define O_NONBLOCK 0
|
|
|
|
#endif
|
2003-07-15 22:45:49 +02:00
|
|
|
|
2004-04-23 01:45:47 +02:00
|
|
|
#ifndef O_BINARY
|
|
|
|
# define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2004-05-25 20:05:39 +02:00
|
|
|
|
2003-07-15 22:45:49 +02:00
|
|
|
/****************************************************************
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979323846
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef M_PI_2
|
|
|
|
#define M_PI_2 1.570796326794896619
|
|
|
|
#endif
|
|
|
|
|
2012-06-17 15:59:25 +02:00
|
|
|
#ifndef INFINITY
|
|
|
|
static inline float __port_infinity(void)
|
|
|
|
{
|
|
|
|
static const unsigned __inf_bytes = 0x7f800000;
|
|
|
|
return *(const float *)&__inf_bytes;
|
|
|
|
}
|
|
|
|
#define INFINITY __port_infinity()
|
|
|
|
#endif
|
|
|
|
|
2012-05-29 12:53:38 +02:00
|
|
|
#ifndef NAN
|
2012-06-05 11:35:34 +02:00
|
|
|
static inline float __port_nan(void)
|
2012-05-29 12:53:38 +02:00
|
|
|
{
|
|
|
|
static const unsigned __nan_bytes = 0x7fc00000;
|
|
|
|
return *(const float *)&__nan_bytes;
|
|
|
|
}
|
|
|
|
#define NAN __port_nan()
|
|
|
|
#endif
|
|
|
|
|
2003-07-15 22:45:49 +02:00
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
/****************************************************************
|
2003-03-20 23:06:16 +01:00
|
|
|
* Function definitions (only when using libwine_port)
|
2002-04-26 21:05:15 +02:00
|
|
|
*/
|
|
|
|
|
2003-03-20 22:07:49 +01:00
|
|
|
#ifndef NO_LIBWINE_PORT
|
1999-11-13 23:23:35 +01:00
|
|
|
|
2004-04-06 05:33:25 +02:00
|
|
|
#ifndef HAVE_FSTATVFS
|
|
|
|
int fstatvfs( int fd, struct statvfs *buf );
|
|
|
|
#endif
|
|
|
|
|
2013-06-16 17:07:55 +02:00
|
|
|
#ifndef HAVE_GETOPT_LONG_ONLY
|
2003-03-19 23:44:55 +01:00
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
extern int opterr;
|
|
|
|
extern int optopt;
|
2003-04-20 04:56:14 +02:00
|
|
|
struct option;
|
2003-03-19 23:44:55 +01:00
|
|
|
|
2003-04-20 04:56:14 +02:00
|
|
|
#ifndef HAVE_STRUCT_OPTION_NAME
|
2003-03-19 23:44:55 +01:00
|
|
|
struct option
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int has_arg;
|
|
|
|
int *flag;
|
|
|
|
int val;
|
|
|
|
};
|
2003-04-20 04:56:14 +02:00
|
|
|
#endif
|
2003-03-19 23:44:55 +01:00
|
|
|
|
|
|
|
extern int getopt_long (int ___argc, char *const *___argv,
|
|
|
|
const char *__shortopts,
|
|
|
|
const struct option *__longopts, int *__longind);
|
|
|
|
extern int getopt_long_only (int ___argc, char *const *___argv,
|
|
|
|
const char *__shortopts,
|
|
|
|
const struct option *__longopts, int *__longind);
|
2013-06-16 17:07:55 +02:00
|
|
|
#endif /* HAVE_GETOPT_LONG_ONLY */
|
2003-03-19 23:44:55 +01:00
|
|
|
|
2004-10-20 01:53:26 +02:00
|
|
|
#ifndef HAVE_FFS
|
|
|
|
int ffs( int x );
|
|
|
|
#endif
|
|
|
|
|
2017-11-07 03:01:13 +01:00
|
|
|
#ifndef HAVE_LLRINT
|
|
|
|
__int64 llrint(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_LLRINTF
|
|
|
|
__int64 llrintf(float x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_LRINT
|
|
|
|
long lrint(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_LRINTF
|
|
|
|
long lrintf(float x);
|
|
|
|
#endif
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#ifndef HAVE_LSTAT
|
|
|
|
int lstat(const char *file_name, struct stat *buf);
|
|
|
|
#endif /* HAVE_LSTAT */
|
|
|
|
|
2008-12-22 17:36:18 +01:00
|
|
|
#ifndef HAVE_POLL
|
|
|
|
struct pollfd
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
short events;
|
|
|
|
short revents;
|
|
|
|
};
|
|
|
|
#define POLLIN 0x01
|
|
|
|
#define POLLPRI 0x02
|
|
|
|
#define POLLOUT 0x04
|
|
|
|
#define POLLERR 0x08
|
|
|
|
#define POLLHUP 0x10
|
|
|
|
#define POLLNVAL 0x20
|
|
|
|
int poll( struct pollfd *fds, unsigned int count, int timeout );
|
|
|
|
#endif /* HAVE_POLL */
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#ifndef HAVE_PREAD
|
|
|
|
ssize_t pread( int fd, void *buf, size_t count, off_t offset );
|
|
|
|
#endif /* HAVE_PREAD */
|
2000-11-08 05:28:54 +01:00
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#ifndef HAVE_PWRITE
|
|
|
|
ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
|
|
|
|
#endif /* HAVE_PWRITE */
|
1999-11-13 23:23:35 +01:00
|
|
|
|
2004-01-08 06:07:05 +01:00
|
|
|
#ifndef HAVE_READLINK
|
|
|
|
int readlink( const char *path, char *buf, size_t size );
|
|
|
|
#endif /* HAVE_READLINK */
|
|
|
|
|
2017-11-07 03:01:13 +01:00
|
|
|
#ifndef HAVE_RINT
|
|
|
|
double rint(double x);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_RINTF
|
|
|
|
float rintf(float x);
|
|
|
|
#endif
|
|
|
|
|
2004-03-09 20:22:08 +01:00
|
|
|
#ifndef HAVE_STATVFS
|
|
|
|
int statvfs( const char *path, struct statvfs *buf );
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 10:48:48 +01:00
|
|
|
#ifndef HAVE_STRNLEN
|
|
|
|
size_t strnlen( const char *str, size_t maxlen );
|
|
|
|
#endif /* !defined(HAVE_STRNLEN) */
|
|
|
|
|
2008-12-22 10:47:16 +01:00
|
|
|
#ifndef HAVE_SYMLINK
|
|
|
|
int symlink(const char *from, const char *to);
|
|
|
|
#endif
|
|
|
|
|
1999-11-13 23:23:35 +01:00
|
|
|
#ifndef HAVE_USLEEP
|
|
|
|
int usleep (unsigned int useconds);
|
|
|
|
#endif /* !defined(HAVE_USLEEP) */
|
|
|
|
|
2003-03-20 22:07:49 +01:00
|
|
|
extern int mkstemps(char *template, int suffix_len);
|
|
|
|
|
2002-04-25 23:40:56 +02:00
|
|
|
/* Interlocked functions */
|
|
|
|
|
2008-12-08 19:25:25 +01:00
|
|
|
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
2002-04-25 23:40:56 +02:00
|
|
|
|
2010-04-15 11:56:32 +02:00
|
|
|
static inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
|
2002-04-25 23:40:56 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
int ret;
|
2002-04-25 23:40:56 +02:00
|
|
|
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
|
|
|
|
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-15 11:56:32 +02:00
|
|
|
static inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
|
2002-04-25 23:40:56 +02:00
|
|
|
{
|
|
|
|
void *ret;
|
2008-12-08 19:25:25 +01:00
|
|
|
#ifdef __x86_64__
|
|
|
|
__asm__ __volatile__( "lock; cmpxchgq %2,(%1)"
|
|
|
|
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
|
|
|
|
#else
|
2002-04-25 23:40:56 +02:00
|
|
|
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
|
|
|
|
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
|
2008-12-08 19:25:25 +01:00
|
|
|
#endif
|
2002-04-25 23:40:56 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-15 11:56:32 +02:00
|
|
|
static inline int interlocked_xchg( int *dest, int val )
|
2002-04-25 23:40:56 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
int ret;
|
2002-04-25 23:40:56 +02:00
|
|
|
__asm__ __volatile__( "lock; xchgl %0,(%1)"
|
|
|
|
: "=r" (ret) : "r" (dest), "0" (val) : "memory" );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-15 11:56:32 +02:00
|
|
|
static inline void *interlocked_xchg_ptr( void **dest, void *val )
|
2002-04-25 23:40:56 +02:00
|
|
|
{
|
|
|
|
void *ret;
|
2008-12-08 19:25:25 +01:00
|
|
|
#ifdef __x86_64__
|
|
|
|
__asm__ __volatile__( "lock; xchgq %0,(%1)"
|
|
|
|
: "=r" (ret) :"r" (dest), "0" (val) : "memory" );
|
|
|
|
#else
|
2002-04-25 23:40:56 +02:00
|
|
|
__asm__ __volatile__( "lock; xchgl %0,(%1)"
|
|
|
|
: "=r" (ret) : "r" (dest), "0" (val) : "memory" );
|
2008-12-08 19:25:25 +01:00
|
|
|
#endif
|
2002-04-25 23:40:56 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-04-15 11:56:32 +02:00
|
|
|
static inline int interlocked_xchg_add( int *dest, int incr )
|
2002-04-25 23:40:56 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
int ret;
|
2002-04-25 23:40:56 +02:00
|
|
|
__asm__ __volatile__( "lock; xaddl %0,(%1)"
|
|
|
|
: "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-01 12:39:17 +02:00
|
|
|
#ifdef __x86_64__
|
2010-04-15 11:56:32 +02:00
|
|
|
static inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
|
2009-09-01 12:39:17 +02:00
|
|
|
__int64 xchg_low, __int64 *compare )
|
|
|
|
{
|
|
|
|
unsigned char ret;
|
|
|
|
__asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
|
|
|
|
: "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
|
|
|
|
"=a" (compare[0]), "=d" (compare[1])
|
|
|
|
: "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
|
|
|
|
"c" (xchg_high), "b" (xchg_low) );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-08 19:25:25 +01:00
|
|
|
#else /* __GNUC__ */
|
2002-04-25 23:40:56 +02:00
|
|
|
|
2015-05-12 02:17:35 +02:00
|
|
|
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
|
|
|
|
static inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
|
|
|
|
{
|
|
|
|
return __sync_val_compare_and_swap( dest, compare, xchg );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int interlocked_xchg_add( int *dest, int incr )
|
|
|
|
{
|
|
|
|
return __sync_fetch_and_add( dest, incr );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int interlocked_xchg( int *dest, int val )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
do ret = *dest; while (!__sync_bool_compare_and_swap( dest, ret, val ));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
2005-09-26 15:51:58 +02:00
|
|
|
extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
|
2015-05-12 02:17:35 +02:00
|
|
|
extern int interlocked_xchg_add( int *dest, int incr );
|
|
|
|
extern int interlocked_xchg( int *dest, int val );
|
|
|
|
#endif
|
|
|
|
|
2015-05-12 02:17:37 +02:00
|
|
|
#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) && __SIZEOF_POINTER__ == 4) \
|
|
|
|
|| (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) && __SIZEOF_POINTER__ == 8)
|
|
|
|
static inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
|
|
|
|
{
|
|
|
|
return __sync_val_compare_and_swap( dest, compare, xchg );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *interlocked_xchg_ptr( void **dest, void *val )
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
do ret = *dest; while (!__sync_bool_compare_and_swap( dest, ret, val ));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
2002-04-25 23:40:56 +02:00
|
|
|
extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
|
|
|
|
extern void *interlocked_xchg_ptr( void **dest, void *val );
|
2015-05-12 02:17:37 +02:00
|
|
|
#endif
|
|
|
|
|
2013-01-18 18:05:42 +01:00
|
|
|
#if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64)
|
2009-09-01 12:39:17 +02:00
|
|
|
extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
|
|
|
|
__int64 xchg_low, __int64 *compare );
|
|
|
|
#endif
|
2002-04-25 23:40:56 +02:00
|
|
|
|
2008-12-08 19:25:25 +01:00
|
|
|
#endif /* __GNUC__ */
|
2002-04-25 23:40:56 +02:00
|
|
|
|
2015-05-12 02:17:36 +02:00
|
|
|
#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
|
|
|
|
static inline __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare )
|
|
|
|
{
|
|
|
|
return __sync_val_compare_and_swap( dest, compare, xchg );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
|
|
|
|
#endif
|
|
|
|
|
2003-03-20 22:07:49 +01:00
|
|
|
#else /* NO_LIBWINE_PORT */
|
2002-04-26 21:05:15 +02:00
|
|
|
|
|
|
|
#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
|
|
|
|
|
2004-10-20 01:53:26 +02:00
|
|
|
#define ffs __WINE_NOT_PORTABLE(ffs)
|
2004-04-06 05:33:25 +02:00
|
|
|
#define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
|
2003-03-20 23:06:16 +01:00
|
|
|
#define getopt_long __WINE_NOT_PORTABLE(getopt_long)
|
|
|
|
#define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
|
|
|
|
#define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
|
|
|
|
#define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
|
|
|
|
#define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
|
|
|
|
#define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
|
|
|
|
#define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
|
|
|
|
#define lstat __WINE_NOT_PORTABLE(lstat)
|
|
|
|
#define pread __WINE_NOT_PORTABLE(pread)
|
|
|
|
#define pwrite __WINE_NOT_PORTABLE(pwrite)
|
2004-03-09 20:22:08 +01:00
|
|
|
#define statvfs __WINE_NOT_PORTABLE(statvfs)
|
2017-12-15 10:48:48 +01:00
|
|
|
#define strnlen __WINE_NOT_PORTABLE(strnlen)
|
2003-03-20 23:06:16 +01:00
|
|
|
#define usleep __WINE_NOT_PORTABLE(usleep)
|
2002-04-26 21:05:15 +02:00
|
|
|
|
2003-03-20 22:07:49 +01:00
|
|
|
#endif /* NO_LIBWINE_PORT */
|
2000-12-27 05:18:26 +01:00
|
|
|
|
1999-11-13 23:23:35 +01:00
|
|
|
#endif /* !defined(__WINE_WINE_PORT_H) */
|