--- IO-AIO/AIO.xs 2018/02/20 05:23:47 1.254 +++ IO-AIO/AIO.xs 2018/07/24 19:32:20 1.261 @@ -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 @@ -108,6 +111,8 @@ #include "libeio/config.h" +#include "schmorp.h" + #if HAVE_EVENTFD # include #endif @@ -161,10 +166,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 +183,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 +191,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 +277,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 +1047,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 +1118,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) @@ -2059,6 +2078,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 +2281,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 +2295,9 @@ PUSHs (newSVnv (ts_get (&ots.it_interval))); PUSHs (newSVnv (ts_get (&ots.it_value))); } +#else + errno = ENOSYS; +#endif } void @@ -2256,13 +2305,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 +2316,9 @@ PUSHs (newSVnv (ts_get (&ots.it_interval))); PUSHs (newSVnv (ts_get (&ots.it_value))); } +#else + errno = ENOSYS; +#endif } UV