--- IO-AIO/AIO.xs 2010/05/09 20:42:55 1.165 +++ IO-AIO/AIO.xs 2010/08/04 16:09:36 1.170 @@ -142,6 +142,31 @@ # define POSIX_FADV_DONTNEED 0 #endif +#if _XOPEN_SOURCE < 600 || NO_FADVISE +# define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ +#endif + +#ifndef POSIX_MADV_NORMAL +# define POSIX_MADV_NORMAL 0 +# define NO_MADVISE 1 +#endif +#ifndef POSIX_MADV_SEQUENTIAL +# define POSIX_MADV_SEQUENTIAL 0 +#endif +#ifndef POSIX_MADV_RANDOM +# define POSIX_MADV_RANDOM 0 +#endif +#ifndef POSIX_MADV_WILLNEED +# define POSIX_MADV_WILLNEED 0 +#endif +#ifndef POSIX_MADV_DONTNEED +# define POSIX_MADV_DONTNEED 0 +#endif + +#if _XOPEN_SOURCE < 600 || NO_MADVISE +# define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ +#endif + #ifndef ST_NODEV # define ST_NODEV 0 #endif @@ -306,13 +331,12 @@ static int req_invoke (eio_req *req) { - dSP; - if (req->flags & FLAG_SV2_RO_OFF) SvREADONLY_off (req->sv2); if (!EIO_CANCELLED (req) && req->callback) { + dSP; static SV *sv_result_cache; /* caches the result integer SV */ SV *sv_result; @@ -499,7 +523,7 @@ } break; - case EIO_DUP2: + case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ if (req->result > 0) SvIV_set (sv_result, 0); /* FALLTHROUGH */ @@ -623,8 +647,11 @@ mg->mg_obj = 0; /* just in case */ SvREADONLY_off (sv); + + if (SvPVX (sv) != mg->mg_ptr) + croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); + SvCUR_set (sv, 0); - SvLEN_set (sv, 0); SvPVX (sv) = 0; SvOK_off (sv); @@ -699,6 +726,12 @@ const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) + const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) + const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) + const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) + const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) + const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) + const_iv (ST_RDONLY) const_iv (ST_NOSUID) const_iv (ST_NODEV) @@ -1362,11 +1395,7 @@ fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) PROTOTYPE: $$$$ CODE: -#if _XOPEN_SOURCE >= 600 && !NO_FADVISE RETVAL = posix_fadvise (fh, offset, length, advice); -#else - RETVAL = errno = ENOSYS; /* yes, this is actually correct */ -#endif OUTPUT: RETVAL @@ -1389,14 +1418,20 @@ if (addr == (void *)-1) XSRETURN_NO; + sv_force_normal (scalar); + /* we store the length in mg_obj, as namlen is I32 :/ */ sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) ->mg_obj = (SV *)length; SvUPGRADE (scalar, SVt_PV); /* nop... */ + if (!(prot & PROT_WRITE)) SvREADONLY_on (scalar); + if (SvLEN (scalar)) + Safefree (SvPVX (scalar)); + SvPVX (scalar) = (char *)addr; SvCUR_set (scalar, length); SvLEN_set (scalar, 0); @@ -1412,6 +1447,24 @@ sv_unmagic (scalar, MMAP_MAGIC); int +madvise (SV *scalar, off_t offset, off_t length, IV advice) + PROTOTYPE: $$$$ + CODE: +{ + char *addr = SvPV_nolen (scalar) + offset; + + if (!SvOK (ST (2))) + length = SvCUR (scalar) - offset; + + if (addr >= SvEND (scalar) || length <= 0) + XSRETURN_EMPTY; + + RETVAL = posix_madvise (addr, length, advice); +} + OUTPUT: + RETVAL + +int mlockall (int flags) PROTOTYPE: $ CODE: