--- IO-AIO/AIO.xs 2018/02/20 06:05:19 1.255 +++ IO-AIO/AIO.xs 2018/07/22 20:39:19 1.259 @@ -6,6 +6,10 @@ #include "perl.h" #include "XSUB.h" +#if !defined mg_findext +# define mg_findext(sv,type,vtbl) mg_find (sv, type) +#endif + #include #include #include @@ -190,6 +194,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 @@ -1036,6 +1044,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,6 +1115,9 @@ const_iv (MAP_HUGETLB) const_iv (MAP_STACK) + const_iv (MREMAP_MAYMOVE) + const_iv (MREMAP_FIXED) + const_iv (F_DUPFD_CLOEXEC) const_iv (F_OFD_GETLK) @@ -2059,6 +2072,36 @@ CODE: sv_clear_foreign (scalar); +SV * +mremap (SV *scalar, STRLEN new_length, int flags = 0, 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 +2275,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 +2289,9 @@ PUSHs (newSVnv (ts_get (&ots.it_interval))); PUSHs (newSVnv (ts_get (&ots.it_value))); } +#else + errno = ENOSYS; +#endif } void @@ -2256,13 +2299,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 +2310,9 @@ PUSHs (newSVnv (ts_get (&ots.it_interval))); PUSHs (newSVnv (ts_get (&ots.it_value))); } +#else + errno = ENOSYS; +#endif } UV