ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.257 by root, Tue Jul 17 23:20:09 2018 UTC vs.
Revision 1.269 by root, Thu Nov 29 21:48:44 2018 UTC

3#include <errno.h> 3#include <errno.h>
4 4
5#include "EXTERN.h" 5#include "EXTERN.h"
6#include "perl.h" 6#include "perl.h"
7#include "XSUB.h" 7#include "XSUB.h"
8
9#if !defined mg_findext
10# define mg_findext(sv,type,vtbl) mg_find (sv, type)
11#endif
8 12
9#include <stddef.h> 13#include <stddef.h>
10#include <stdlib.h> 14#include <stdlib.h>
11#include <errno.h> 15#include <errno.h>
12#include <sys/types.h> 16#include <sys/types.h>
17#include <sys/socket.h>
13#include <sys/stat.h> 18#include <sys/stat.h>
14#include <limits.h> 19#include <limits.h>
15#include <fcntl.h> 20#include <fcntl.h>
16#include <sched.h> 21#include <sched.h>
17
18#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
19# include <sys/mman.h>
20#endif
21 22
22/* the incompetent fool that created musl keeps __linux__, refuses 23/* the incompetent fool that created musl keeps __linux__, refuses
23 * to implement any linux standard apis, and also has no way to test 24 * to implement any linux standard apis, and also has no way to test
24 * for his broken iplementation. don't complain to me if this fails 25 * for his broken iplementation. don't complain to me if this fails
25 * for you. 26 * for you.
73 #undef fchmod 74 #undef fchmod
74 #undef dup 75 #undef dup
75 #undef dup2 76 #undef dup2
76 #undef abort 77 #undef abort
77 #undef pipe 78 #undef pipe
79 #undef utime
78 80
79 #define EIO_STRUCT_STAT struct _stati64 81 #define EIO_STRUCT_STAT struct _stati64
80 #define EIO_STRUCT_STATI64 82 #define EIO_STRUCT_STATI64
81 83
82#else 84#else
102#define expect_false(expr) expect ((expr) != 0, 0) 104#define expect_false(expr) expect ((expr) != 0, 0)
103#define expect_true(expr) expect ((expr) != 0, 1) 105#define expect_true(expr) expect ((expr) != 0, 1)
104 106
105/*****************************************************************************/ 107/*****************************************************************************/
106 108
107#include "libeio/config.h" 109#include "config.h"
110
111#if HAVE_SYS_MKDEV_H
112# include <sys/mkdev.h>
113#elif HAVE_SYS_SYSMACROS_H
114# include <sys/sysmacros.h>
115#endif
116
117#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
118# include <sys/mman.h>
119#endif
120
121#if HAVE_ST_XTIMENSEC
122# define ATIMENSEC PL_statcache.st_atimensec
123# define MTIMENSEC PL_statcache.st_mtimensec
124# define CTIMENSEC PL_statcache.st_ctimensec
125#elif HAVE_ST_XTIMESPEC
126# define ATIMENSEC PL_statcache.st_atim.tv_nsec
127# define MTIMENSEC PL_statcache.st_mtim.tv_nsec
128# define CTIMENSEC PL_statcache.st_ctim.tv_nsec
129#else
130# define ATIMENSEC 0
131# define MTIMENSEC 0
132# define CTIMENSEC 0
133#endif
134
135#if HAVE_ST_BIRTHTIMENSEC
136# define BTIMESEC PL_statcache.st_birthtime
137# define BTIMENSEC PL_statcache.st_birthtimensec
138#elif HAVE_ST_BIRTHTIMESPEC
139# define BTIMESEC PL_statcache.st_birthtim.tv_sec
140# define BTIMENSEC PL_statcache.st_birthtim.tv_nsec
141#else
142# define BTIMESEC 0
143# define BTIMENSEC 0
144#endif
145
146#if HAVE_ST_GEN
147# define ST_GEN PL_statcache.st_gen
148#else
149# define ST_GEN 0
150#endif
108 151
109#include "schmorp.h" 152#include "schmorp.h"
110 153
111#if HAVE_EVENTFD 154#if HAVE_EVENTFD
112# include <sys/eventfd.h> 155# include <sys/eventfd.h>
159# else 202# else
160# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ 203# define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */
161# endif 204# endif
162#endif 205#endif
163 206
164/* defines all sorts of constants to 0 unless they are already defined */
165/* also provides const_iv_ and const_niv_ macros for them */
166#include "def0.h"
167
168#ifndef makedev 207#ifndef makedev
169# define makedev(maj,min) (((maj) << 8) | (min)) 208# define makedev(maj,min) (((maj) << 8) | (min))
170#endif 209#endif
171#ifndef major 210#ifndef major
172# define major(dev) ((dev) >> 8) 211# define major(dev) ((dev) >> 8)
173#endif 212#endif
174#ifndef minor 213#ifndef minor
175# define minor(dev) ((dev) & 0xff) 214# define minor(dev) ((dev) & 0xff)
176#endif 215#endif
177 216
217/* solaris has a non-posix/unix compliant PAGESIZE that breaks compilation */
218#ifdef __sun
219# undef PAGESIZE
220#endif
221
178#if PAGESIZE <= 0 222#if PAGESIZE <= 0
179# define PAGESIZE sysconf (_SC_PAGESIZE) 223# define PAGESIZE sysconf (_SC_PAGESIZE)
180#endif 224#endif
181 225
182/*****************************************************************************/ 226/*****************************************************************************/
183 227
184#if !_POSIX_MAPPED_FILES 228#if !_POSIX_MAPPED_FILES
185# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () 229# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
186# define munmap(addr,length) EIO_ENOSYS () 230# define munmap(addr,length) EIO_ENOSYS ()
187#endif 231#endif
188 232
189#if !_POSIX_MEMORY_PROTECTION 233#if !_POSIX_MEMORY_PROTECTION
190# define mprotect(addr,len,prot) EIO_ENOSYS () 234# define mprotect(addr,len,prot) EIO_ENOSYS ()
271{ 315{
272 /* todo: iterate over magic and only free ours, but of course */ 316 /* todo: iterate over magic and only free ours, but of course */
273 /* the perl5porters will call that (correct) behaviour buggy */ 317 /* the perl5porters will call that (correct) behaviour buggy */
274 sv_unmagic (sv, FOREIGN_MAGIC); 318 sv_unmagic (sv, FOREIGN_MAGIC);
275} 319}
320
321/*****************************************************************************/
322
323/* defines all sorts of constants to 0 unless they are already defined */
324/* also provides const_iv_ and const_niv_ macros for them */
325#include "def0.h"
276 326
277/*****************************************************************************/ 327/*****************************************************************************/
278 328
279static void 329static void
280fiemap (eio_req *req) 330fiemap (eio_req *req)
371 errno = ENOSYS; 421 errno = ENOSYS;
372#endif 422#endif
373} 423}
374 424
375/*****************************************************************************/ 425/*****************************************************************************/
426
427static int close_fd; /* dummy fd to close fds via dup2 */
376 428
377enum { 429enum {
378 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ 430 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
379}; 431};
380 432
1038 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 1090 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
1039 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 1091 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
1040 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 1092 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
1041 1093
1042 /* the second block will be 0 when missing */ 1094 /* the second block will be 0 when missing */
1095 const_iv (O_ACCMODE)
1096
1043 const_iv (O_RDONLY) 1097 const_iv (O_RDONLY)
1044 const_iv (O_WRONLY) 1098 const_iv (O_WRONLY)
1045 const_iv (O_RDWR) 1099 const_iv (O_RDWR)
1046 const_iv (O_CREAT) 1100 const_iv (O_CREAT)
1047 const_iv (O_TRUNC) 1101 const_iv (O_TRUNC)
1111 1165
1112 const_iv (MREMAP_MAYMOVE) 1166 const_iv (MREMAP_MAYMOVE)
1113 const_iv (MREMAP_FIXED) 1167 const_iv (MREMAP_FIXED)
1114 1168
1115 const_iv (F_DUPFD_CLOEXEC) 1169 const_iv (F_DUPFD_CLOEXEC)
1170
1171 const_iv (MSG_CMSG_CLOEXEC)
1172 const_iv (SOCK_CLOEXEC)
1116 1173
1117 const_iv (F_OFD_GETLK) 1174 const_iv (F_OFD_GETLK)
1118 const_iv (F_OFD_SETLK) 1175 const_iv (F_OFD_SETLK)
1119 const_iv (F_OFD_GETLKW) 1176 const_iv (F_OFD_GETLKW)
1120 1177
1216 const_eio (SEEK_CUR) 1273 const_eio (SEEK_CUR)
1217 const_eio (SEEK_END) 1274 const_eio (SEEK_END)
1218 1275
1219 const_eio (MCL_FUTURE) 1276 const_eio (MCL_FUTURE)
1220 const_eio (MCL_CURRENT) 1277 const_eio (MCL_CURRENT)
1278 const_eio (MCL_ONFAULT)
1221 1279
1222 const_eio (MS_ASYNC) 1280 const_eio (MS_ASYNC)
1223 const_eio (MS_INVALIDATE) 1281 const_eio (MS_INVALIDATE)
1224 const_eio (MS_SYNC) 1282 const_eio (MS_SYNC)
1225 1283
1264 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 1322 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
1265 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 1323 newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
1266 1324
1267 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); 1325 newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE));
1268 1326
1327 /* allocate dummy pipe fd for aio_close */
1328 {
1329 int pipefd [2];
1330
1331 if (
1332#ifdef _WIN32
1333 _pipe (pipefd, 1, _O_BINARY) < 0
1334#else
1335 pipe (pipefd) < 0
1336 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1337#endif
1338 || close (pipefd [1]) < 0
1339 )
1340 croak ("IO::AIO: unable to create dummy pipe for aio_close");
1341
1342 close_fd = pipefd [0];
1343 }
1344
1269 reinit (); 1345 reinit ();
1270} 1346}
1271 1347
1272void 1348void
1273reinit () 1349reinit ()
1395 1471
1396void 1472void
1397aio_close (SV *fh, SV *callback = &PL_sv_undef) 1473aio_close (SV *fh, SV *callback = &PL_sv_undef)
1398 PPCODE: 1474 PPCODE:
1399{ 1475{
1400 static int close_fd = -1; /* dummy fd to close fds via dup2 */
1401 int fd = s_fileno_croak (fh, 0); 1476 int fd = s_fileno_croak (fh, 0);
1402 dREQ; 1477 dREQ;
1403
1404 if (expect_false (close_fd < 0))
1405 {
1406 int pipefd [2];
1407
1408 if (
1409#ifdef _WIN32
1410 _pipe (pipefd, 1, _O_BINARY) < 0
1411#else
1412 pipe (pipefd) < 0
1413 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0
1414#endif
1415 || close (pipefd [1]) < 0
1416 )
1417 abort (); /*D*/
1418
1419 close_fd = pipefd [0];
1420 }
1421 1478
1422 req->type = EIO_DUP2; 1479 req->type = EIO_DUP2;
1423 req->int1 = close_fd; 1480 req->int1 = close_fd;
1424 req->sv2 = newSVsv (fh); 1481 req->sv2 = newSVsv (fh);
1425 req->int2 = fd; 1482 req->int2 = fd;
1601 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); 1658 req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path);
1602 1659
1603 REQ_SEND; 1660 REQ_SEND;
1604} 1661}
1605 1662
1663void
1664st_xtime ()
1665 ALIAS:
1666 st_atime = 0x01
1667 st_mtime = 0x02
1668 st_ctime = 0x04
1669 st_btime = 0x08
1670 st_xtime = 0x0f
1671 PPCODE:
1672 EXTEND (SP, 4);
1673 if (ix & 0x01) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC));
1674 if (ix & 0x02) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC));
1675 if (ix & 0x04) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC));
1676 if (ix & 0x08) PUSHs (newSVnv (BTIMESEC + 1e-9 * BTIMENSEC));
1677
1678void
1679st_xtimensec ()
1680 ALIAS:
1681 st_atimensec = 0x01
1682 st_mtimensec = 0x02
1683 st_ctimensec = 0x04
1684 st_btimensec = 0x08
1685 st_xtimensec = 0x0f
1686 st_btimesec = 0x10
1687 st_gen = 0x20
1688 PPCODE:
1689 EXTEND (SP, 4);
1690 if (ix & 0x01) PUSHs (newSViv (ATIMENSEC));
1691 if (ix & 0x02) PUSHs (newSViv (MTIMENSEC));
1692 if (ix & 0x04) PUSHs (newSViv (CTIMENSEC));
1693 if (ix & 0x08) PUSHs (newSViv (BTIMENSEC));
1694 if (ix & 0x10) PUSHs (newSVuv (BTIMESEC));
1695 if (ix & 0x20) PUSHs (newSVuv (ST_GEN));
1696
1606UV 1697UV
1607major (UV dev) 1698major (UV dev)
1608 ALIAS: 1699 ALIAS:
1609 minor = 1 1700 minor = 1
1610 CODE: 1701 CODE:
2065munmap (SV *scalar) 2156munmap (SV *scalar)
2066 CODE: 2157 CODE:
2067 sv_clear_foreign (scalar); 2158 sv_clear_foreign (scalar);
2068 2159
2069SV * 2160SV *
2070mremap (SV *scalar, STRLEN new_length, int flags = 0, IV new_address = 0) 2161mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0)
2071 CODE: 2162 CODE:
2072{ 2163{
2073 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); 2164 MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl);
2074 void *new; 2165 void *new;
2075 2166
2095} 2186}
2096 OUTPUT: 2187 OUTPUT:
2097 RETVAL 2188 RETVAL
2098 2189
2099int 2190int
2100madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) 2191madvise (SV *scalar, IV offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot)
2101 ALIAS: 2192 ALIAS:
2102 mprotect = 1 2193 mprotect = 1
2103 CODE: 2194 CODE:
2104{ 2195{
2105 STRLEN svlen; 2196 STRLEN svlen;
2126} 2217}
2127 OUTPUT: 2218 OUTPUT:
2128 RETVAL 2219 RETVAL
2129 2220
2130int 2221int
2131munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef) 2222munlock (SV *scalar, IV offset = 0, SV *length = &PL_sv_undef)
2132 CODE: 2223 CODE:
2133{ 2224{
2134 STRLEN svlen; 2225 STRLEN svlen;
2135 void *addr = SvPVbyte (scalar, svlen); 2226 void *addr = SvPVbyte (scalar, svlen);
2136 size_t len = SvUV (length); 2227 size_t len = SvUV (length);
2151#else 2242#else
2152 RETVAL = EIO_ENOSYS (); 2243 RETVAL = EIO_ENOSYS ();
2153#endif 2244#endif
2154} 2245}
2155 OUTPUT: 2246 OUTPUT:
2247 RETVAL
2248
2249int
2250mlockall (int flags)
2251 CODE:
2252 RETVAL = eio_mlockall_sync (flags);
2253 OUTPUT:
2156 RETVAL 2254 RETVAL
2157 2255
2158int 2256int
2159munlockall () 2257munlockall ()
2160 CODE: 2258 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines