ASIO to JACK driver for WINE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

457 lines
12KB

  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. #ifndef __WINE_WINE_PORT_H
  21. #define __WINE_WINE_PORT_H
  22. #ifndef __WINE_CONFIG_H
  23. # error You must include config.h to use this header
  24. #endif
  25. #define _FILE_OFFSET_BITS 64
  26. #define _GNU_SOURCE /* for pread/pwrite */
  27. #include <fcntl.h>
  28. #include <math.h>
  29. #include <sys/types.h>
  30. #include <sys/stat.h>
  31. #ifdef HAVE_DIRECT_H
  32. # include <direct.h>
  33. #endif
  34. #ifdef HAVE_IO_H
  35. # include <io.h>
  36. #endif
  37. #ifdef HAVE_PROCESS_H
  38. # include <process.h>
  39. #endif
  40. #include <string.h>
  41. #ifdef HAVE_UNISTD_H
  42. # include <unistd.h>
  43. #endif
  44. /****************************************************************
  45. * Type definitions
  46. */
  47. #if !defined(_MSC_VER) && !defined(__int64)
  48. # if defined(__x86_64__) || defined(_WIN64)
  49. # define __int64 long
  50. # else
  51. # define __int64 long long
  52. # endif
  53. #endif
  54. #ifndef HAVE_MODE_T
  55. typedef int mode_t;
  56. #endif
  57. #ifndef HAVE_OFF_T
  58. typedef long off_t;
  59. #endif
  60. #ifndef HAVE_PID_T
  61. typedef int pid_t;
  62. #endif
  63. #ifndef HAVE_SIZE_T
  64. typedef unsigned int size_t;
  65. #endif
  66. #ifndef HAVE_SSIZE_T
  67. typedef int ssize_t;
  68. #endif
  69. #ifndef HAVE_FSBLKCNT_T
  70. typedef unsigned long fsblkcnt_t;
  71. #endif
  72. #ifndef HAVE_FSFILCNT_T
  73. typedef unsigned long fsfilcnt_t;
  74. #endif
  75. #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
  76. struct statvfs
  77. {
  78. unsigned long f_bsize;
  79. unsigned long f_frsize;
  80. fsblkcnt_t f_blocks;
  81. fsblkcnt_t f_bfree;
  82. fsblkcnt_t f_bavail;
  83. fsfilcnt_t f_files;
  84. fsfilcnt_t f_ffree;
  85. fsfilcnt_t f_favail;
  86. unsigned long f_fsid;
  87. unsigned long f_flag;
  88. unsigned long f_namemax;
  89. };
  90. #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
  91. /****************************************************************
  92. * Macro definitions
  93. */
  94. #ifdef HAVE_DLFCN_H
  95. #include <dlfcn.h>
  96. #else
  97. #define RTLD_LAZY 0x001
  98. #define RTLD_NOW 0x002
  99. #define RTLD_GLOBAL 0x100
  100. #endif
  101. #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
  102. #define ftruncate chsize
  103. #endif
  104. #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
  105. #define popen _popen
  106. #endif
  107. #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
  108. #define pclose _pclose
  109. #endif
  110. #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
  111. #define snprintf _snprintf
  112. #endif
  113. #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
  114. #define vsnprintf _vsnprintf
  115. #endif
  116. #ifndef S_ISLNK
  117. # define S_ISLNK(mod) (0)
  118. #endif
  119. #ifndef S_ISSOCK
  120. # define S_ISSOCK(mod) (0)
  121. #endif
  122. #ifndef S_ISDIR
  123. # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
  124. #endif
  125. #ifndef S_ISCHR
  126. # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
  127. #endif
  128. #ifndef S_ISFIFO
  129. # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
  130. #endif
  131. #ifndef S_ISREG
  132. # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
  133. #endif
  134. #ifndef S_IWUSR
  135. # define S_IWUSR 0
  136. #endif
  137. /* So we open files in 64 bit access mode on Linux */
  138. #ifndef O_LARGEFILE
  139. # define O_LARGEFILE 0
  140. #endif
  141. #ifndef O_NONBLOCK
  142. # define O_NONBLOCK 0
  143. #endif
  144. #ifndef O_BINARY
  145. # define O_BINARY 0
  146. #endif
  147. #if !defined(S_IXUSR) && defined(S_IEXEC)
  148. # define S_IXUSR S_IEXEC
  149. #endif
  150. #if !defined(S_IXGRP) && defined(S_IEXEC)
  151. # define S_IXGRP S_IEXEC
  152. #endif
  153. #if !defined(S_IXOTH) && defined(S_IEXEC)
  154. # define S_IXOTH S_IEXEC
  155. #endif
  156. /****************************************************************
  157. * Constants
  158. */
  159. #ifndef M_PI
  160. #define M_PI 3.14159265358979323846
  161. #endif
  162. #ifndef M_PI_2
  163. #define M_PI_2 1.570796326794896619
  164. #endif
  165. /* Macros to define assembler functions somewhat portably */
  166. #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
  167. # define __ASM_GLOBAL_FUNC(name,code) \
  168. __asm__( ".text\n\t" \
  169. ".align 4\n\t" \
  170. ".globl " __ASM_NAME(#name) "\n\t" \
  171. __ASM_FUNC(#name) "\n" \
  172. __ASM_NAME(#name) ":\n\t" \
  173. code \
  174. "\n\t.previous" );
  175. #else /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__) */
  176. # define __ASM_GLOBAL_FUNC(name,code) \
  177. void __asm_dummy_##name(void) { \
  178. asm( ".align 4\n\t" \
  179. ".globl " __ASM_NAME(#name) "\n\t" \
  180. __ASM_FUNC(#name) "\n" \
  181. __ASM_NAME(#name) ":\n\t" \
  182. code ); \
  183. }
  184. #endif /* __GNUC__ */
  185. /* Register functions */
  186. #ifdef __i386__
  187. #define DEFINE_REGS_ENTRYPOINT( name, args, pop_args ) \
  188. __ASM_GLOBAL_FUNC( name, \
  189. "pushl %eax\n\t" \
  190. "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
  191. ".long " __ASM_NAME("__regs_") #name "-.\n\t" \
  192. ".byte " #args "," #pop_args )
  193. /* FIXME: add support for other CPUs */
  194. #endif /* __i386__ */
  195. /****************************************************************
  196. * Function definitions (only when using libwine_port)
  197. */
  198. #ifndef NO_LIBWINE_PORT
  199. #ifndef HAVE_FSTATVFS
  200. int fstatvfs( int fd, struct statvfs *buf );
  201. #endif
  202. #ifndef HAVE_GETOPT_LONG
  203. extern char *optarg;
  204. extern int optind;
  205. extern int opterr;
  206. extern int optopt;
  207. struct option;
  208. #ifndef HAVE_STRUCT_OPTION_NAME
  209. struct option
  210. {
  211. const char *name;
  212. int has_arg;
  213. int *flag;
  214. int val;
  215. };
  216. #endif
  217. extern int getopt_long (int ___argc, char *const *___argv,
  218. const char *__shortopts,
  219. const struct option *__longopts, int *__longind);
  220. extern int getopt_long_only (int ___argc, char *const *___argv,
  221. const char *__shortopts,
  222. const struct option *__longopts, int *__longind);
  223. #endif /* HAVE_GETOPT_LONG */
  224. #ifndef HAVE_FFS
  225. int ffs( int x );
  226. #endif
  227. #ifndef HAVE_FUTIMES
  228. struct timeval;
  229. int futimes(int fd, const struct timeval tv[2]);
  230. #endif
  231. #ifndef HAVE_GETPAGESIZE
  232. size_t getpagesize(void);
  233. #endif /* HAVE_GETPAGESIZE */
  234. #ifndef HAVE_GETTID
  235. pid_t gettid(void);
  236. #endif /* HAVE_GETTID */
  237. #ifndef HAVE_LSTAT
  238. int lstat(const char *file_name, struct stat *buf);
  239. #endif /* HAVE_LSTAT */
  240. #ifndef HAVE_MEMMOVE
  241. void *memmove(void *dest, const void *src, size_t len);
  242. #endif /* !defined(HAVE_MEMMOVE) */
  243. #ifndef HAVE_PREAD
  244. ssize_t pread( int fd, void *buf, size_t count, off_t offset );
  245. #endif /* HAVE_PREAD */
  246. #ifndef HAVE_PWRITE
  247. ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
  248. #endif /* HAVE_PWRITE */
  249. #ifndef HAVE_READLINK
  250. int readlink( const char *path, char *buf, size_t size );
  251. #endif /* HAVE_READLINK */
  252. #ifndef HAVE_SIGSETJMP
  253. # include <setjmp.h>
  254. typedef jmp_buf sigjmp_buf;
  255. int sigsetjmp( sigjmp_buf buf, int savesigs );
  256. void siglongjmp( sigjmp_buf buf, int val );
  257. #endif /* HAVE_SIGSETJMP */
  258. #ifndef HAVE_STATVFS
  259. int statvfs( const char *path, struct statvfs *buf );
  260. #endif
  261. #ifndef HAVE_STRNCASECMP
  262. # ifndef HAVE__STRNICMP
  263. int strncasecmp(const char *str1, const char *str2, size_t n);
  264. # else
  265. # define strncasecmp _strnicmp
  266. # endif
  267. #endif /* !defined(HAVE_STRNCASECMP) */
  268. #ifndef HAVE_STRERROR
  269. const char *strerror(int err);
  270. #endif /* !defined(HAVE_STRERROR) */
  271. #ifndef HAVE_STRCASECMP
  272. # ifndef HAVE__STRICMP
  273. int strcasecmp(const char *str1, const char *str2);
  274. # else
  275. # define strcasecmp _stricmp
  276. # endif
  277. #endif /* !defined(HAVE_STRCASECMP) */
  278. #ifndef HAVE_USLEEP
  279. int usleep (unsigned int useconds);
  280. #endif /* !defined(HAVE_USLEEP) */
  281. #ifdef __i386__
  282. static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
  283. {
  284. return memcpy( dst, src, size );
  285. }
  286. #else
  287. extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
  288. #endif /* __i386__ */
  289. extern int mkstemps(char *template, int suffix_len);
  290. /* Process creation flags */
  291. #ifndef _P_WAIT
  292. # define _P_WAIT 0
  293. # define _P_NOWAIT 1
  294. # define _P_OVERLAY 2
  295. # define _P_NOWAITO 3
  296. # define _P_DETACH 4
  297. #endif
  298. #ifndef HAVE_SPAWNVP
  299. extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
  300. #endif
  301. /* Interlocked functions */
  302. #if defined(__i386__) && defined(__GNUC__)
  303. extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
  304. extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
  305. extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
  306. extern inline int interlocked_xchg( int *dest, int val );
  307. extern inline void *interlocked_xchg_ptr( void **dest, void *val );
  308. extern inline int interlocked_xchg_add( int *dest, int incr );
  309. extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
  310. {
  311. int ret;
  312. __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
  313. : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
  314. return ret;
  315. }
  316. extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
  317. {
  318. void *ret;
  319. __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
  320. : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
  321. return ret;
  322. }
  323. extern inline int interlocked_xchg( int *dest, int val )
  324. {
  325. int ret;
  326. __asm__ __volatile__( "lock; xchgl %0,(%1)"
  327. : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
  328. return ret;
  329. }
  330. extern inline void *interlocked_xchg_ptr( void **dest, void *val )
  331. {
  332. void *ret;
  333. __asm__ __volatile__( "lock; xchgl %0,(%1)"
  334. : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
  335. return ret;
  336. }
  337. extern inline int interlocked_xchg_add( int *dest, int incr )
  338. {
  339. int ret;
  340. __asm__ __volatile__( "lock; xaddl %0,(%1)"
  341. : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
  342. return ret;
  343. }
  344. #else /* __i386___ && __GNUC__ */
  345. extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
  346. extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
  347. extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
  348. extern int interlocked_xchg( int *dest, int val );
  349. extern void *interlocked_xchg_ptr( void **dest, void *val );
  350. extern int interlocked_xchg_add( int *dest, int incr );
  351. #endif /* __i386___ && __GNUC__ */
  352. #else /* NO_LIBWINE_PORT */
  353. #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
  354. #define ffs __WINE_NOT_PORTABLE(ffs)
  355. #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
  356. #define futimes __WINE_NOT_PORTABLE(futimes)
  357. #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
  358. #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
  359. #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
  360. #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
  361. #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
  362. #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
  363. #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
  364. #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
  365. #define lstat __WINE_NOT_PORTABLE(lstat)
  366. #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
  367. #undef memmove
  368. #define memmove __WINE_NOT_PORTABLE(memmove)
  369. #define pread __WINE_NOT_PORTABLE(pread)
  370. #define pwrite __WINE_NOT_PORTABLE(pwrite)
  371. #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
  372. #define statvfs __WINE_NOT_PORTABLE(statvfs)
  373. #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
  374. #define strerror __WINE_NOT_PORTABLE(strerror)
  375. #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
  376. #define usleep __WINE_NOT_PORTABLE(usleep)
  377. #endif /* NO_LIBWINE_PORT */
  378. #endif /* !defined(__WINE_WINE_PORT_H) */