--- IO-AIO/AIO.xs 2010/08/04 16:06:54 1.169 +++ IO-AIO/AIO.xs 2010/08/04 17:16:19 1.171 @@ -142,6 +142,10 @@ # 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 @@ -159,6 +163,23 @@ # 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 PROT_NONE +# define PROT_NONE 0 +#endif +#ifndef PROT_READ +# define PROT_READ 0 +#endif +#ifndef PROT_WRITE +# define PROT_READ 0 +#endif +#ifndef PROT_EXEC +# define PROT_EXEC 0 +#endif + #ifndef ST_NODEV # define ST_NODEV 0 #endif @@ -625,6 +646,7 @@ #if !_POSIX_MAPPED_FILES # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) # define munmap(addr,length) (errno = ENOSYS, -1) +# define mprotect(addr,len,prot) (errno = ENOSYS, -1) #endif #define MMAP_MAGIC PERL_MAGIC_ext @@ -737,8 +759,8 @@ const_iv (ST_NODIRATIME) const_iv (ST_RELATIME) - const_iv (PROT_EXEC) const_iv (PROT_NONE) + const_iv (PROT_EXEC) const_iv (PROT_READ) const_iv (PROT_WRITE) @@ -1387,11 +1409,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 @@ -1443,23 +1461,31 @@ sv_unmagic (scalar, MMAP_MAGIC); int -madvise (SV *scalar, off_t offset, off_t length, IV advice) +madvise (SV *scalar, off_t offset, off_t length, IV advice_or_prot) + ALIAS: + mprotect = 1 PROTOTYPE: $$$$ CODE: { - char *addr = SvPV_nolen (scalar) + offset; - - if (!SvOK (ST (2))) - length = SvCUR (scalar) - offset; + STRLEN cur; + char *addr = SvPVbyte (scalar, cur); - if (addr >= SvEND (scalar) || length <= 0) - XSRETURN_EMPTY; + if (offset > cur) + RETVAL = errno = EFAULT; + else + { + if (!SvOK (ST (2))) + length = cur - offset; - #if _XOPEN_SOURCE >= 600 && !NO_MADVISE - RETVAL = posix_madvise (addr, length, advice); - #else - RETVAL = errno = ENOSYS; /* yes, this is actually correct */ - #endif + if (offset + length > cur) + RETVAL = errno = EFAULT; + else + switch (ix) + { + case 0: RETVAL = posix_madvise (addr + offset, length, advice_or_prot); break; + case 1: RETVAL = mprotect (addr + offset, length, advice_or_prot); break; + } + } } OUTPUT: RETVAL