… | |
… | |
165 | |
165 | |
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
168 | #endif |
168 | #endif |
169 | |
169 | |
|
|
170 | #ifndef PROT_NONE |
|
|
171 | # define PROT_NONE 0 |
|
|
172 | #endif |
|
|
173 | #ifndef PROT_READ |
|
|
174 | # define PROT_READ 0 |
|
|
175 | #endif |
|
|
176 | #ifndef PROT_WRITE |
|
|
177 | # define PROT_READ 0 |
|
|
178 | #endif |
|
|
179 | #ifndef PROT_EXEC |
|
|
180 | # define PROT_EXEC 0 |
|
|
181 | #endif |
|
|
182 | |
170 | #ifndef ST_NODEV |
183 | #ifndef ST_NODEV |
171 | # define ST_NODEV 0 |
184 | # define ST_NODEV 0 |
172 | #endif |
185 | #endif |
173 | #ifndef ST_NOEXEC |
186 | #ifndef ST_NOEXEC |
174 | # define ST_NOEXEC 0 |
187 | # define ST_NOEXEC 0 |
… | |
… | |
631 | /*****************************************************************************/ |
644 | /*****************************************************************************/ |
632 | |
645 | |
633 | #if !_POSIX_MAPPED_FILES |
646 | #if !_POSIX_MAPPED_FILES |
634 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
647 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
635 | # define munmap(addr,length) (errno = ENOSYS, -1) |
648 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
649 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
636 | #endif |
650 | #endif |
637 | |
651 | |
638 | #define MMAP_MAGIC PERL_MAGIC_ext |
652 | #define MMAP_MAGIC PERL_MAGIC_ext |
639 | |
653 | |
640 | static int |
654 | static int |
… | |
… | |
743 | const_iv (ST_IMMUTABLE) |
757 | const_iv (ST_IMMUTABLE) |
744 | const_iv (ST_NOATIME) |
758 | const_iv (ST_NOATIME) |
745 | const_iv (ST_NODIRATIME) |
759 | const_iv (ST_NODIRATIME) |
746 | const_iv (ST_RELATIME) |
760 | const_iv (ST_RELATIME) |
747 | |
761 | |
|
|
762 | const_iv (PROT_NONE) |
748 | const_iv (PROT_EXEC) |
763 | const_iv (PROT_EXEC) |
749 | const_iv (PROT_NONE) |
|
|
750 | const_iv (PROT_READ) |
764 | const_iv (PROT_READ) |
751 | const_iv (PROT_WRITE) |
765 | const_iv (PROT_WRITE) |
752 | |
766 | |
753 | /*const_iv (MAP_FIXED)*/ |
767 | /*const_iv (MAP_FIXED)*/ |
754 | const_iv (MAP_PRIVATE) |
768 | const_iv (MAP_PRIVATE) |
… | |
… | |
1445 | PROTOTYPE: $ |
1459 | PROTOTYPE: $ |
1446 | CODE: |
1460 | CODE: |
1447 | sv_unmagic (scalar, MMAP_MAGIC); |
1461 | sv_unmagic (scalar, MMAP_MAGIC); |
1448 | |
1462 | |
1449 | int |
1463 | int |
1450 | madvise (SV *scalar, off_t offset, off_t length, IV advice) |
1464 | madvise (SV *scalar, off_t offset, off_t length, IV advice_or_prot) |
|
|
1465 | ALIAS: |
|
|
1466 | mprotect = 1 |
1451 | PROTOTYPE: $$$$ |
1467 | PROTOTYPE: $$$$ |
1452 | CODE: |
1468 | CODE: |
1453 | { |
1469 | { |
1454 | char *addr = SvPV_nolen (scalar) + offset; |
1470 | STRLEN cur; |
|
|
1471 | char *addr = SvPVbyte (scalar, cur); |
1455 | |
1472 | |
|
|
1473 | if (offset > cur) |
|
|
1474 | RETVAL = errno = EFAULT; |
|
|
1475 | else |
|
|
1476 | { |
1456 | if (!SvOK (ST (2))) |
1477 | if (!SvOK (ST (2))) |
1457 | length = SvCUR (scalar) - offset; |
1478 | length = cur - offset; |
1458 | |
1479 | |
1459 | if (addr >= SvEND (scalar) || length <= 0) |
1480 | if (offset + length > cur) |
1460 | XSRETURN_EMPTY; |
1481 | RETVAL = errno = EFAULT; |
1461 | |
1482 | else |
1462 | RETVAL = posix_madvise (addr, length, advice); |
1483 | switch (ix) |
|
|
1484 | { |
|
|
1485 | case 0: RETVAL = posix_madvise (addr + offset, length, advice_or_prot); break; |
|
|
1486 | case 1: RETVAL = mprotect (addr + offset, length, advice_or_prot); break; |
|
|
1487 | } |
|
|
1488 | } |
1463 | } |
1489 | } |
1464 | OUTPUT: |
1490 | OUTPUT: |
1465 | RETVAL |
1491 | RETVAL |
1466 | |
1492 | |
1467 | int |
1493 | int |