… | |
… | |
140 | #endif |
140 | #endif |
141 | #ifndef POSIX_FADV_DONTNEED |
141 | #ifndef POSIX_FADV_DONTNEED |
142 | # define POSIX_FADV_DONTNEED 0 |
142 | # define POSIX_FADV_DONTNEED 0 |
143 | #endif |
143 | #endif |
144 | |
144 | |
|
|
145 | #if _XOPEN_SOURCE < 600 || NO_FADVISE |
|
|
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
147 | #endif |
|
|
148 | |
|
|
149 | #ifndef POSIX_MADV_NORMAL |
|
|
150 | # define POSIX_MADV_NORMAL 0 |
|
|
151 | # define NO_MADVISE 1 |
|
|
152 | #endif |
|
|
153 | #ifndef POSIX_MADV_SEQUENTIAL |
|
|
154 | # define POSIX_MADV_SEQUENTIAL 0 |
|
|
155 | #endif |
|
|
156 | #ifndef POSIX_MADV_RANDOM |
|
|
157 | # define POSIX_MADV_RANDOM 0 |
|
|
158 | #endif |
|
|
159 | #ifndef POSIX_MADV_WILLNEED |
|
|
160 | # define POSIX_MADV_WILLNEED 0 |
|
|
161 | #endif |
|
|
162 | #ifndef POSIX_MADV_DONTNEED |
|
|
163 | # define POSIX_MADV_DONTNEED 0 |
|
|
164 | #endif |
|
|
165 | |
|
|
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
|
|
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
168 | #endif |
|
|
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 | |
145 | #ifndef ST_NODEV |
183 | #ifndef ST_NODEV |
146 | # define ST_NODEV 0 |
184 | # define ST_NODEV 0 |
147 | #endif |
185 | #endif |
148 | #ifndef ST_NOEXEC |
186 | #ifndef ST_NOEXEC |
149 | # define ST_NOEXEC 0 |
187 | # define ST_NOEXEC 0 |
… | |
… | |
304 | } |
342 | } |
305 | } |
343 | } |
306 | |
344 | |
307 | static int req_invoke (eio_req *req) |
345 | static int req_invoke (eio_req *req) |
308 | { |
346 | { |
309 | dSP; |
|
|
310 | |
|
|
311 | if (req->flags & FLAG_SV2_RO_OFF) |
347 | if (req->flags & FLAG_SV2_RO_OFF) |
312 | SvREADONLY_off (req->sv2); |
348 | SvREADONLY_off (req->sv2); |
313 | |
349 | |
314 | if (!EIO_CANCELLED (req) && req->callback) |
350 | if (!EIO_CANCELLED (req) && req->callback) |
315 | { |
351 | { |
|
|
352 | dSP; |
|
|
353 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
354 | SV *sv_result; |
|
|
355 | |
316 | ENTER; |
356 | ENTER; |
317 | SAVETMPS; |
357 | SAVETMPS; |
318 | PUSHMARK (SP); |
358 | PUSHMARK (SP); |
319 | EXTEND (SP, 1); |
359 | EXTEND (SP, 1); |
|
|
360 | |
|
|
361 | /* do not recreate the result IV from scratch each time */ |
|
|
362 | if (expect_true (sv_result_cache)) |
|
|
363 | { |
|
|
364 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
365 | SvIV_set (sv_result, req->result); |
|
|
366 | } |
|
|
367 | else |
|
|
368 | { |
|
|
369 | sv_result = newSViv (req->result); |
|
|
370 | SvREADONLY_on (sv_result); |
|
|
371 | } |
320 | |
372 | |
321 | switch (req->type) |
373 | switch (req->type) |
322 | { |
374 | { |
323 | case EIO_READDIR: |
375 | case EIO_READDIR: |
324 | { |
376 | { |
… | |
… | |
469 | case EIO_LSTAT: |
521 | case EIO_LSTAT: |
470 | case EIO_FSTAT: |
522 | case EIO_FSTAT: |
471 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
523 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
472 | PL_laststatval = req->result; |
524 | PL_laststatval = req->result; |
473 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
525 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
474 | PUSHs (sv_2mortal (newSViv (req->result))); |
526 | PUSHs (sv_result); |
475 | break; |
527 | break; |
476 | |
528 | |
477 | case EIO_READ: |
529 | case EIO_READ: |
478 | { |
530 | { |
479 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
531 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
480 | *SvEND (req->sv2) = 0; |
532 | *SvEND (req->sv2) = 0; |
481 | SvPOK_only (req->sv2); |
533 | SvPOK_only (req->sv2); |
482 | SvSETMAGIC (req->sv2); |
534 | SvSETMAGIC (req->sv2); |
483 | PUSHs (sv_2mortal (newSViv (req->result))); |
535 | PUSHs (sv_result); |
484 | } |
536 | } |
485 | break; |
537 | break; |
486 | |
538 | |
487 | case EIO_DUP2: |
539 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
488 | if (req->result > 0) |
540 | if (req->result > 0) |
489 | req->result = 0; |
541 | SvIV_set (sv_result, 0); |
490 | /* FALLTHROUGH */ |
542 | /* FALLTHROUGH */ |
491 | |
543 | |
492 | default: |
544 | default: |
493 | PUSHs (sv_2mortal (newSViv (req->result))); |
545 | PUSHs (sv_result); |
494 | break; |
546 | break; |
495 | } |
547 | } |
496 | |
548 | |
497 | errno = req->errorno; |
549 | errno = req->errorno; |
498 | |
550 | |
499 | PUTBACK; |
551 | PUTBACK; |
500 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
552 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
501 | SPAGAIN; |
553 | SPAGAIN; |
|
|
554 | |
|
|
555 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
556 | SvREFCNT_dec (sv_result); |
|
|
557 | else |
|
|
558 | sv_result_cache = sv_result; |
502 | |
559 | |
503 | FREETMPS; |
560 | FREETMPS; |
504 | LEAVE; |
561 | LEAVE; |
505 | |
562 | |
506 | PUTBACK; |
563 | PUTBACK; |
… | |
… | |
587 | /*****************************************************************************/ |
644 | /*****************************************************************************/ |
588 | |
645 | |
589 | #if !_POSIX_MAPPED_FILES |
646 | #if !_POSIX_MAPPED_FILES |
590 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
647 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
591 | # define munmap(addr,length) (errno = ENOSYS, -1) |
648 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
649 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
592 | #endif |
650 | #endif |
593 | |
651 | |
594 | #define MMAP_MAGIC PERL_MAGIC_ext |
652 | #define MMAP_MAGIC PERL_MAGIC_ext |
595 | |
653 | |
596 | static int |
654 | static int |
… | |
… | |
601 | errno = old_errno; |
659 | errno = old_errno; |
602 | |
660 | |
603 | mg->mg_obj = 0; /* just in case */ |
661 | mg->mg_obj = 0; /* just in case */ |
604 | |
662 | |
605 | SvREADONLY_off (sv); |
663 | SvREADONLY_off (sv); |
|
|
664 | |
|
|
665 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
666 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
667 | |
606 | SvCUR_set (sv, 0); |
668 | SvCUR_set (sv, 0); |
607 | SvLEN_set (sv, 0); |
|
|
608 | SvPVX (sv) = 0; |
669 | SvPVX (sv) = 0; |
609 | SvOK_off (sv); |
670 | SvOK_off (sv); |
610 | |
671 | |
611 | return 0; |
672 | return 0; |
612 | } |
673 | } |
… | |
… | |
662 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
723 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
663 | const_iv (EXDEV) |
724 | const_iv (EXDEV) |
664 | const_iv (ENOSYS) |
725 | const_iv (ENOSYS) |
665 | const_iv (O_RDONLY) |
726 | const_iv (O_RDONLY) |
666 | const_iv (O_WRONLY) |
727 | const_iv (O_WRONLY) |
|
|
728 | const_iv (O_RDWR) |
667 | const_iv (O_CREAT) |
729 | const_iv (O_CREAT) |
668 | const_iv (O_TRUNC) |
730 | const_iv (O_TRUNC) |
|
|
731 | const_iv (O_EXCL) |
|
|
732 | const_iv (O_APPEND) |
669 | #ifndef _WIN32 |
733 | #ifndef _WIN32 |
670 | const_iv (S_IFIFO) |
734 | const_iv (S_IFIFO) |
671 | #endif |
735 | #endif |
672 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
736 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
673 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
737 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
674 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
738 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
675 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
739 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
676 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
740 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
677 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
741 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
742 | |
|
|
743 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
744 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
745 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
746 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
747 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
678 | |
748 | |
679 | const_iv (ST_RDONLY) |
749 | const_iv (ST_RDONLY) |
680 | const_iv (ST_NOSUID) |
750 | const_iv (ST_NOSUID) |
681 | const_iv (ST_NODEV) |
751 | const_iv (ST_NODEV) |
682 | const_iv (ST_NOEXEC) |
752 | const_iv (ST_NOEXEC) |
… | |
… | |
687 | const_iv (ST_IMMUTABLE) |
757 | const_iv (ST_IMMUTABLE) |
688 | const_iv (ST_NOATIME) |
758 | const_iv (ST_NOATIME) |
689 | const_iv (ST_NODIRATIME) |
759 | const_iv (ST_NODIRATIME) |
690 | const_iv (ST_RELATIME) |
760 | const_iv (ST_RELATIME) |
691 | |
761 | |
|
|
762 | const_iv (PROT_NONE) |
692 | const_iv (PROT_EXEC) |
763 | const_iv (PROT_EXEC) |
693 | const_iv (PROT_NONE) |
|
|
694 | const_iv (PROT_READ) |
764 | const_iv (PROT_READ) |
695 | const_iv (PROT_WRITE) |
765 | const_iv (PROT_WRITE) |
696 | |
766 | |
697 | /*const_iv (MAP_FIXED)*/ |
767 | /*const_iv (MAP_FIXED)*/ |
698 | const_iv (MAP_PRIVATE) |
768 | const_iv (MAP_PRIVATE) |
… | |
… | |
1337 | |
1407 | |
1338 | int |
1408 | int |
1339 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1409 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1340 | PROTOTYPE: $$$$ |
1410 | PROTOTYPE: $$$$ |
1341 | CODE: |
1411 | CODE: |
1342 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1343 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1412 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1344 | #else |
|
|
1345 | RETVAL = errno = ENOSYS; /* yes, this is actually correct */ |
|
|
1346 | #endif |
|
|
1347 | OUTPUT: |
1413 | OUTPUT: |
1348 | RETVAL |
1414 | RETVAL |
1349 | |
1415 | |
1350 | ssize_t |
1416 | ssize_t |
1351 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1417 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
… | |
… | |
1364 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1430 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1365 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1431 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1366 | if (addr == (void *)-1) |
1432 | if (addr == (void *)-1) |
1367 | XSRETURN_NO; |
1433 | XSRETURN_NO; |
1368 | |
1434 | |
|
|
1435 | sv_force_normal (scalar); |
|
|
1436 | |
1369 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1437 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1370 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1438 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1371 | ->mg_obj = (SV *)length; |
1439 | ->mg_obj = (SV *)length; |
1372 | |
1440 | |
1373 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
1441 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1442 | |
1374 | if (!(prot & PROT_WRITE)) |
1443 | if (!(prot & PROT_WRITE)) |
1375 | SvREADONLY_on (scalar); |
1444 | SvREADONLY_on (scalar); |
|
|
1445 | |
|
|
1446 | if (SvLEN (scalar)) |
|
|
1447 | Safefree (SvPVX (scalar)); |
1376 | |
1448 | |
1377 | SvPVX (scalar) = (char *)addr; |
1449 | SvPVX (scalar) = (char *)addr; |
1378 | SvCUR_set (scalar, length); |
1450 | SvCUR_set (scalar, length); |
1379 | SvLEN_set (scalar, 0); |
1451 | SvLEN_set (scalar, 0); |
1380 | SvPOK_only (scalar); |
1452 | SvPOK_only (scalar); |
… | |
… | |
1385 | void |
1457 | void |
1386 | munmap (SV *scalar) |
1458 | munmap (SV *scalar) |
1387 | PROTOTYPE: $ |
1459 | PROTOTYPE: $ |
1388 | CODE: |
1460 | CODE: |
1389 | sv_unmagic (scalar, MMAP_MAGIC); |
1461 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1462 | |
|
|
1463 | int |
|
|
1464 | madvise (SV *scalar, off_t offset, off_t length, IV advice_or_prot) |
|
|
1465 | ALIAS: |
|
|
1466 | mprotect = 1 |
|
|
1467 | PROTOTYPE: $$$$ |
|
|
1468 | CODE: |
|
|
1469 | { |
|
|
1470 | STRLEN cur; |
|
|
1471 | char *addr = SvPVbyte (scalar, cur); |
|
|
1472 | |
|
|
1473 | if (offset > cur) |
|
|
1474 | RETVAL = errno = EFAULT; |
|
|
1475 | else |
|
|
1476 | { |
|
|
1477 | if (!SvOK (ST (2))) |
|
|
1478 | length = cur - offset; |
|
|
1479 | |
|
|
1480 | if (offset + length > cur) |
|
|
1481 | RETVAL = errno = EFAULT; |
|
|
1482 | else |
|
|
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 | } |
|
|
1489 | } |
|
|
1490 | OUTPUT: |
|
|
1491 | RETVAL |
1390 | |
1492 | |
1391 | int |
1493 | int |
1392 | mlockall (int flags) |
1494 | mlockall (int flags) |
1393 | PROTOTYPE: $ |
1495 | PROTOTYPE: $ |
1394 | CODE: |
1496 | CODE: |