--- IO-AIO/AIO.xs 2018/02/20 05:23:47 1.254 +++ IO-AIO/AIO.xs 2018/08/12 06:03:20 1.263 @@ -6,12 +6,15 @@ #include "perl.h" #include "XSUB.h" -#include "schmorp.h" +#if !defined mg_findext +# define mg_findext(sv,type,vtbl) mg_find (sv, type) +#endif #include #include #include #include +#include #include #include #include @@ -106,7 +109,23 @@ /*****************************************************************************/ -#include "libeio/config.h" +#include "config.h" + +#if HAVE_ST_XTIMENSEC +# define ATIMENSEC PL_statcache.st_atimensec +# define MTIMENSEC PL_statcache.st_mtimensec +# define CTIMENSEC PL_statcache.st_ctimensec +#elif HAVE_ST_XTIMESPEC +# define ATIMENSEC PL_statcache.st_atim.tv_nsec +# define MTIMENSEC PL_statcache.st_mtim.tv_nsec +# define CTIMENSEC PL_statcache.st_ctim.tv_nsec +#else +# define ATIMENSEC 0 +# define MTIMENSEC 0 +# define CTIMENSEC 0 +#endif + +#include "schmorp.h" #if HAVE_EVENTFD # include @@ -161,10 +180,6 @@ # endif #endif -/* defines all sorts of constants to 0 unless they are already defined */ -/* also provides const_iv_ and const_niv_ macros for them */ -#include "def0.h" - #ifndef makedev # define makedev(maj,min) (((maj) << 8) | (min)) #endif @@ -182,7 +197,7 @@ /*****************************************************************************/ #if !_POSIX_MAPPED_FILES -# define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () +# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) # define munmap(addr,length) EIO_ENOSYS () #endif @@ -190,6 +205,10 @@ # define mprotect(addr,len,prot) EIO_ENOSYS () #endif +#if !MREMAP_MAYMOVE +# define mremap(old_address,old_size,new_size,flags,new_address) (errno = ENOSYS, (void *)-1) +#endif + #define FOREIGN_MAGIC PERL_MAGIC_ext static int ecb_cold @@ -272,6 +291,12 @@ /*****************************************************************************/ +/* defines all sorts of constants to 0 unless they are already defined */ +/* also provides const_iv_ and const_niv_ macros for them */ +#include "def0.h" + +/*****************************************************************************/ + static void fiemap (eio_req *req) { @@ -1036,6 +1061,8 @@ const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) /* the second block will be 0 when missing */ + const_iv (O_ACCMODE) + const_iv (O_RDONLY) const_iv (O_WRONLY) const_iv (O_RDWR) @@ -1105,8 +1132,14 @@ const_iv (MAP_HUGETLB) const_iv (MAP_STACK) + const_iv (MREMAP_MAYMOVE) + const_iv (MREMAP_FIXED) + const_iv (F_DUPFD_CLOEXEC) + const_iv (MSG_CMSG_CLOEXEC) + const_iv (SOCK_CLOEXEC) + const_iv (F_OFD_GETLK) const_iv (F_OFD_SETLK) const_iv (F_OFD_GETLKW) @@ -1596,6 +1629,32 @@ REQ_SEND; } +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)); + +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)); + UV major (UV dev) ALIAS: @@ -2059,6 +2118,36 @@ CODE: sv_clear_foreign (scalar); +SV * +mremap (SV *scalar, STRLEN new_length, int flags = MREMAP_MAYMOVE, IV new_address = 0) + CODE: +{ + MAGIC *mg = mg_findext (scalar, FOREIGN_MAGIC, &mmap_vtbl); + void *new; + + if (!mg || SvPVX (scalar) != mg->mg_ptr) + croak ("IO::AIO::mremap: scalar not mapped by IO::AIO::mmap or improperly modified"); + + new = mremap (mg->mg_ptr, (size_t)mg->mg_obj, new_length, flags, (void *)new_address); + + RETVAL = &PL_sv_no; + + if (new != (void *)-1) + { + RETVAL = new == (void *)mg->mg_ptr + ? newSVpvn ("0 but true", 10) + : &PL_sv_yes; + + mg->mg_ptr = (char *)new; + mg->mg_obj = (SV *)new_length; + + SvPVX (scalar) = mg->mg_ptr; + SvCUR_set (scalar, new_length); + } +} + OUTPUT: + RETVAL + int madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) ALIAS: @@ -2232,16 +2321,13 @@ PPCODE: { int fd = s_fileno_croak (fh, 0); +#if HAVE_TIMERFD int res; struct itimerspec its, ots; ts_set (&its.it_interval, interval); ts_set (&its.it_value , value); -#if HAVE_TIMERFD res = timerfd_settime (fd, flags, &its, &ots); -#else - res = (errno = ENOSYS, -1); -#endif if (!res) { @@ -2249,6 +2335,9 @@ PUSHs (newSVnv (ts_get (&ots.it_interval))); PUSHs (newSVnv (ts_get (&ots.it_value))); } +#else + errno = ENOSYS; +#endif } void @@ -2256,13 +2345,10 @@ PPCODE: { int fd = s_fileno_croak (fh, 0); +#if HAVE_TIMERFD int res; struct itimerspec ots; -#if HAVE_TIMERFD res = timerfd_gettime (fd, &ots); -#else - res = (errno = ENOSYS, -1); -#endif if (!res) { @@ -2270,6 +2356,9 @@ PUSHs (newSVnv (ts_get (&ots.it_interval))); PUSHs (newSVnv (ts_get (&ots.it_value))); } +#else + errno = ENOSYS; +#endif } UV