--- IO-AIO/AIO.xs 2018/08/14 11:50:43 1.265 +++ IO-AIO/AIO.xs 2018/12/28 12:43:00 1.271 @@ -5,6 +5,7 @@ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" +#include "perliol.h" #if !defined mg_findext # define mg_findext(sv,type,vtbl) mg_find (sv, type) @@ -20,16 +21,6 @@ #include #include -#if HAVE_SYS_MKDEV_H -# include -#elif HAVE_SYS_SYSMACROS_H -# include -#endif - -#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES -# include -#endif - /* the incompetent fool that created musl keeps __linux__, refuses * to implement any linux standard apis, and also has no way to test * for his broken iplementation. don't complain to me if this fails @@ -86,6 +77,7 @@ #undef dup2 #undef abort #undef pipe + #undef utime #define EIO_STRUCT_STAT struct _stati64 #define EIO_STRUCT_STATI64 @@ -117,6 +109,16 @@ #include "config.h" +#if HAVE_SYS_MKDEV_H +# include +#elif HAVE_SYS_SYSMACROS_H +# include +#endif + +#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES +# include +#endif + #if HAVE_ST_XTIMENSEC # define ATIMENSEC PL_statcache.st_atimensec # define MTIMENSEC PL_statcache.st_mtimensec @@ -131,6 +133,23 @@ # define CTIMENSEC 0 #endif +#if HAVE_ST_BIRTHTIMENSEC +# define BTIMESEC PL_statcache.st_birthtime +# define BTIMENSEC PL_statcache.st_birthtimensec +#elif HAVE_ST_BIRTHTIMESPEC +# define BTIMESEC PL_statcache.st_birthtim.tv_sec +# define BTIMENSEC PL_statcache.st_birthtim.tv_nsec +#else +# define BTIMESEC 0 +# define BTIMENSEC 0 +#endif + +#if HAVE_ST_GEN +# define ST_GEN PL_statcache.st_gen +#else +# define ST_GEN 0 +#endif + #include "schmorp.h" #if HAVE_EVENTFD @@ -196,6 +215,11 @@ # define minor(dev) ((dev) & 0xff) #endif +/* solaris has a non-posix/unix compliant PAGESIZE that breaks compilation */ +#ifdef __sun +# undef PAGESIZE +#endif + #if PAGESIZE <= 0 # define PAGESIZE sysconf (_SC_PAGESIZE) #endif @@ -401,6 +425,8 @@ /*****************************************************************************/ +static int close_fd; /* dummy fd to close fds via dup2 */ + enum { FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ }; @@ -1250,6 +1276,7 @@ const_eio (MCL_FUTURE) const_eio (MCL_CURRENT) + const_eio (MCL_ONFAULT) const_eio (MS_ASYNC) const_eio (MS_INVALIDATE) @@ -1298,6 +1325,24 @@ newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); + /* allocate dummy pipe fd for aio_close */ + { + int pipefd [2]; + + if ( +#ifdef _WIN32 + _pipe (pipefd, 1, _O_BINARY) < 0 +#else + pipe (pipefd) < 0 + || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 +#endif + || close (pipefd [1]) < 0 + ) + croak ("IO::AIO: unable to create dummy pipe for aio_close"); + + close_fd = pipefd [0]; + } + reinit (); } @@ -1429,32 +1474,36 @@ aio_close (SV *fh, SV *callback = &PL_sv_undef) PPCODE: { - static int close_fd = -1; /* dummy fd to close fds via dup2 */ - int fd = s_fileno_croak (fh, 0); dREQ; + int fd = s_fileno_croak (fh, 0); - if (expect_false (close_fd < 0)) - { - int pipefd [2]; + /* partially duplicate logic in s_fileno */ + SvGETMAGIC (fh); - if ( -#ifdef _WIN32 - _pipe (pipefd, 1, _O_BINARY) < 0 -#else - pipe (pipefd) < 0 - || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 -#endif - || close (pipefd [1]) < 0 - ) - abort (); /*D*/ + if (SvROK (fh)) + { + fh = SvRV (fh); + SvGETMAGIC (fh); + } - close_fd = pipefd [0]; + if (SvTYPE (fh) == SVt_PVGV) + { + /* perl filehandle */ + PerlIOUnix_refcnt_inc (fd); + do_close ((GV *)fh, 1); + + req->type = EIO_CLOSE; + req->int1 = fd; + req->sv2 = newSVsv (fh); + } + else + { + /* fd number */ + req->type = EIO_DUP2; + req->int1 = close_fd; + req->sv2 = newSVsv (fh); + req->int2 = fd; } - - req->type = EIO_DUP2; - req->int1 = close_fd; - req->sv2 = newSVsv (fh); - req->int2 = fd; REQ_SEND; } @@ -1638,28 +1687,36 @@ void st_xtime () ALIAS: - st_atime = 1 - st_mtime = 2 - st_ctime = 4 - st_xtime = 7 - PPCODE: - EXTEND (SP, 3); - if (ix & 1) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC)); - if (ix & 2) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC)); - if (ix & 4) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC)); + st_atime = 0x01 + st_mtime = 0x02 + st_ctime = 0x04 + st_btime = 0x08 + st_xtime = 0x0f + PPCODE: + EXTEND (SP, 4); + if (ix & 0x01) PUSHs (newSVnv (PL_statcache.st_atime + 1e-9 * ATIMENSEC)); + if (ix & 0x02) PUSHs (newSVnv (PL_statcache.st_mtime + 1e-9 * MTIMENSEC)); + if (ix & 0x04) PUSHs (newSVnv (PL_statcache.st_ctime + 1e-9 * CTIMENSEC)); + if (ix & 0x08) PUSHs (newSVnv (BTIMESEC + 1e-9 * BTIMENSEC)); void st_xtimensec () ALIAS: - st_atimensec = 1 - st_mtimensec = 2 - st_ctimensec = 4 - st_xtimensec = 7 - PPCODE: - EXTEND (SP, 3); - if (ix & 1) PUSHs (newSViv (ATIMENSEC)); - if (ix & 2) PUSHs (newSViv (MTIMENSEC)); - if (ix & 4) PUSHs (newSViv (CTIMENSEC)); + st_atimensec = 0x01 + st_mtimensec = 0x02 + st_ctimensec = 0x04 + st_btimensec = 0x08 + st_xtimensec = 0x0f + st_btimesec = 0x10 + st_gen = 0x20 + PPCODE: + EXTEND (SP, 4); + if (ix & 0x01) PUSHs (newSViv (ATIMENSEC)); + if (ix & 0x02) PUSHs (newSViv (MTIMENSEC)); + if (ix & 0x04) PUSHs (newSViv (CTIMENSEC)); + if (ix & 0x08) PUSHs (newSViv (BTIMENSEC)); + if (ix & 0x10) PUSHs (newSVuv (BTIMESEC)); + if (ix & 0x20) PUSHs (newSVuv (ST_GEN)); UV major (UV dev) @@ -2155,7 +2212,7 @@ RETVAL int -madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) +madvise (SV *scalar, IV offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) ALIAS: mprotect = 1 CODE: @@ -2186,7 +2243,7 @@ RETVAL int -munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef) +munlock (SV *scalar, IV offset = 0, SV *length = &PL_sv_undef) CODE: { STRLEN svlen; @@ -2214,6 +2271,14 @@ RETVAL int +mlockall (int flags) + PROTOTYPE: $; + CODE: + RETVAL = eio_mlockall_sync (flags); + OUTPUT: + RETVAL + +int munlockall () CODE: #if _POSIX_MEMLOCK