… | |
… | |
15 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
16 | #include <sys/statvfs.h> |
16 | #include <sys/statvfs.h> |
17 | #include <limits.h> |
17 | #include <limits.h> |
18 | #include <fcntl.h> |
18 | #include <fcntl.h> |
19 | #include <sched.h> |
19 | #include <sched.h> |
|
|
20 | |
|
|
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
|
|
22 | # include <sys/mman.h> |
|
|
23 | #endif |
20 | |
24 | |
21 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
22 | #undef VERSION |
26 | #undef VERSION |
23 | |
27 | |
24 | #ifdef _WIN32 |
28 | #ifdef _WIN32 |
… | |
… | |
120 | |
124 | |
121 | #ifndef POSIX_FADV_NORMAL |
125 | #ifndef POSIX_FADV_NORMAL |
122 | # define POSIX_FADV_NORMAL 0 |
126 | # define POSIX_FADV_NORMAL 0 |
123 | # define NO_FADVISE 1 |
127 | # define NO_FADVISE 1 |
124 | #endif |
128 | #endif |
125 | |
|
|
126 | #ifndef POSIX_FADV_SEQUENTIAL |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
127 | # define POSIX_FADV_SEQUENTIAL 0 |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
128 | #endif |
131 | #endif |
129 | |
|
|
130 | #ifndef POSIX_FADV_RANDOM |
132 | #ifndef POSIX_FADV_RANDOM |
131 | # define POSIX_FADV_RANDOM 0 |
133 | # define POSIX_FADV_RANDOM 0 |
132 | #endif |
134 | #endif |
133 | |
|
|
134 | #ifndef POSIX_FADV_NOREUSE |
135 | #ifndef POSIX_FADV_NOREUSE |
135 | # define POSIX_FADV_NOREUSE 0 |
136 | # define POSIX_FADV_NOREUSE 0 |
136 | #endif |
137 | #endif |
137 | |
|
|
138 | #ifndef POSIX_FADV_WILLNEED |
138 | #ifndef POSIX_FADV_WILLNEED |
139 | # define POSIX_FADV_WILLNEED 0 |
139 | # define POSIX_FADV_WILLNEED 0 |
140 | #endif |
140 | #endif |
141 | |
|
|
142 | #ifndef POSIX_FADV_DONTNEED |
141 | #ifndef POSIX_FADV_DONTNEED |
143 | # define POSIX_FADV_DONTNEED 0 |
142 | # define POSIX_FADV_DONTNEED 0 |
144 | #endif |
143 | #endif |
145 | |
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 | |
146 | #ifndef ST_NODEV |
170 | #ifndef ST_NODEV |
147 | # define ST_NODEV 0 |
171 | # define ST_NODEV 0 |
148 | #endif |
172 | #endif |
149 | |
|
|
150 | #ifndef ST_NOEXEC |
173 | #ifndef ST_NOEXEC |
151 | # define ST_NOEXEC 0 |
174 | # define ST_NOEXEC 0 |
152 | #endif |
175 | #endif |
153 | |
|
|
154 | #ifndef ST_SYNCHRONOUS |
176 | #ifndef ST_SYNCHRONOUS |
155 | # define ST_SYNCHRONOUS 0 |
177 | # define ST_SYNCHRONOUS 0 |
156 | #endif |
178 | #endif |
157 | |
|
|
158 | #ifndef ST_MANDLOCK |
179 | #ifndef ST_MANDLOCK |
159 | # define ST_MANDLOCK 0 |
180 | # define ST_MANDLOCK 0 |
160 | #endif |
181 | #endif |
161 | |
|
|
162 | #ifndef ST_WRITE |
182 | #ifndef ST_WRITE |
163 | # define ST_WRITE 0 |
183 | # define ST_WRITE 0 |
164 | #endif |
184 | #endif |
165 | |
|
|
166 | #ifndef ST_APPEND |
185 | #ifndef ST_APPEND |
167 | # define ST_APPEND 0 |
186 | # define ST_APPEND 0 |
168 | #endif |
187 | #endif |
169 | |
|
|
170 | #ifndef ST_IMMUTABLE |
188 | #ifndef ST_IMMUTABLE |
171 | # define ST_IMMUTABLE 0 |
189 | # define ST_IMMUTABLE 0 |
172 | #endif |
190 | #endif |
173 | |
|
|
174 | #ifndef ST_NOATIME |
191 | #ifndef ST_NOATIME |
175 | # define ST_NOATIME 0 |
192 | # define ST_NOATIME 0 |
176 | #endif |
193 | #endif |
177 | |
|
|
178 | #ifndef ST_NODIRATIME |
194 | #ifndef ST_NODIRATIME |
179 | # define ST_NODIRATIME 0 |
195 | # define ST_NODIRATIME 0 |
180 | #endif |
196 | #endif |
181 | |
|
|
182 | #ifndef ST_RELATIME |
197 | #ifndef ST_RELATIME |
183 | # define ST_RELATIME 0 |
198 | # define ST_RELATIME 0 |
|
|
199 | #endif |
|
|
200 | |
|
|
201 | #ifndef MCL_CURRENT |
|
|
202 | # define MCL_CURRENT 0 |
|
|
203 | #endif |
|
|
204 | #ifndef MCL_FUTURE |
|
|
205 | # define MCL_FUTURE 0 |
|
|
206 | #endif |
|
|
207 | |
|
|
208 | #ifndef MAP_ANONYMOUS |
|
|
209 | # ifdef MAP_ANON |
|
|
210 | # define MAP_ANONYMOUS MAP_ANON |
|
|
211 | # else |
|
|
212 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
213 | # endif |
|
|
214 | #endif |
|
|
215 | #ifndef MAP_HUGETLB |
|
|
216 | # define MAP_HUGETLB 0 |
|
|
217 | #endif |
|
|
218 | #ifndef MAP_LOCKED |
|
|
219 | # define MAP_LOCKED 0 |
|
|
220 | #endif |
|
|
221 | #ifndef MAP_NORESERVE |
|
|
222 | # define MAP_NORESERVE 0 |
|
|
223 | #endif |
|
|
224 | #ifndef MAP_POPULATE |
|
|
225 | # define MAP_POPULATE 0 |
|
|
226 | #endif |
|
|
227 | #ifndef MAP_NONBLOCK |
|
|
228 | # define MAP_NONBLOCK 0 |
|
|
229 | #endif |
|
|
230 | |
|
|
231 | #ifndef PAGESIZE |
|
|
232 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
184 | #endif |
233 | #endif |
185 | |
234 | |
186 | static int req_invoke (eio_req *req); |
235 | static int req_invoke (eio_req *req); |
187 | #define EIO_FINISH(req) req_invoke (req) |
236 | #define EIO_FINISH(req) req_invoke (req) |
188 | static void req_destroy (eio_req *grp); |
237 | static void req_destroy (eio_req *grp); |
… | |
… | |
280 | } |
329 | } |
281 | } |
330 | } |
282 | |
331 | |
283 | static int req_invoke (eio_req *req) |
332 | static int req_invoke (eio_req *req) |
284 | { |
333 | { |
285 | dSP; |
|
|
286 | |
|
|
287 | if (req->flags & FLAG_SV2_RO_OFF) |
334 | if (req->flags & FLAG_SV2_RO_OFF) |
288 | SvREADONLY_off (req->sv2); |
335 | SvREADONLY_off (req->sv2); |
289 | |
336 | |
290 | if (!EIO_CANCELLED (req) && req->callback) |
337 | if (!EIO_CANCELLED (req) && req->callback) |
291 | { |
338 | { |
|
|
339 | dSP; |
|
|
340 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
341 | SV *sv_result; |
|
|
342 | |
292 | ENTER; |
343 | ENTER; |
293 | SAVETMPS; |
344 | SAVETMPS; |
294 | PUSHMARK (SP); |
345 | PUSHMARK (SP); |
295 | EXTEND (SP, 1); |
346 | EXTEND (SP, 1); |
|
|
347 | |
|
|
348 | /* do not recreate the result IV from scratch each time */ |
|
|
349 | if (expect_true (sv_result_cache)) |
|
|
350 | { |
|
|
351 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
352 | SvIV_set (sv_result, req->result); |
|
|
353 | } |
|
|
354 | else |
|
|
355 | { |
|
|
356 | sv_result = newSViv (req->result); |
|
|
357 | SvREADONLY_on (sv_result); |
|
|
358 | } |
296 | |
359 | |
297 | switch (req->type) |
360 | switch (req->type) |
298 | { |
361 | { |
299 | case EIO_READDIR: |
362 | case EIO_READDIR: |
300 | { |
363 | { |
… | |
… | |
445 | case EIO_LSTAT: |
508 | case EIO_LSTAT: |
446 | case EIO_FSTAT: |
509 | case EIO_FSTAT: |
447 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
510 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
448 | PL_laststatval = req->result; |
511 | PL_laststatval = req->result; |
449 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
512 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
450 | PUSHs (sv_2mortal (newSViv (req->result))); |
513 | PUSHs (sv_result); |
451 | break; |
514 | break; |
452 | |
515 | |
453 | case EIO_READ: |
516 | case EIO_READ: |
454 | { |
517 | { |
455 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
518 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
456 | *SvEND (req->sv2) = 0; |
519 | *SvEND (req->sv2) = 0; |
457 | SvPOK_only (req->sv2); |
520 | SvPOK_only (req->sv2); |
458 | SvSETMAGIC (req->sv2); |
521 | SvSETMAGIC (req->sv2); |
459 | PUSHs (sv_2mortal (newSViv (req->result))); |
522 | PUSHs (sv_result); |
460 | } |
523 | } |
461 | break; |
524 | break; |
462 | |
525 | |
463 | case EIO_DUP2: |
526 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
464 | if (req->result > 0) |
527 | if (req->result > 0) |
465 | req->result = 0; |
528 | SvIV_set (sv_result, 0); |
466 | /* FALLTHROUGH */ |
529 | /* FALLTHROUGH */ |
467 | |
530 | |
468 | default: |
531 | default: |
469 | PUSHs (sv_2mortal (newSViv (req->result))); |
532 | PUSHs (sv_result); |
470 | break; |
533 | break; |
471 | } |
534 | } |
472 | |
535 | |
473 | errno = req->errorno; |
536 | errno = req->errorno; |
474 | |
537 | |
475 | PUTBACK; |
538 | PUTBACK; |
476 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
539 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
477 | SPAGAIN; |
540 | SPAGAIN; |
|
|
541 | |
|
|
542 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
543 | SvREFCNT_dec (sv_result); |
|
|
544 | else |
|
|
545 | sv_result_cache = sv_result; |
478 | |
546 | |
479 | FREETMPS; |
547 | FREETMPS; |
480 | LEAVE; |
548 | LEAVE; |
481 | |
549 | |
482 | PUTBACK; |
550 | PUTBACK; |
… | |
… | |
557 | |
625 | |
558 | static void atfork_child (void) |
626 | static void atfork_child (void) |
559 | { |
627 | { |
560 | create_respipe (); |
628 | create_respipe (); |
561 | } |
629 | } |
|
|
630 | |
|
|
631 | /*****************************************************************************/ |
|
|
632 | |
|
|
633 | #if !_POSIX_MAPPED_FILES |
|
|
634 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
635 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
636 | #endif |
|
|
637 | |
|
|
638 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
639 | |
|
|
640 | static int |
|
|
641 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
642 | { |
|
|
643 | int old_errno = errno; |
|
|
644 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
645 | errno = old_errno; |
|
|
646 | |
|
|
647 | mg->mg_obj = 0; /* just in case */ |
|
|
648 | |
|
|
649 | SvREADONLY_off (sv); |
|
|
650 | |
|
|
651 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
652 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
653 | |
|
|
654 | SvCUR_set (sv, 0); |
|
|
655 | SvPVX (sv) = 0; |
|
|
656 | SvOK_off (sv); |
|
|
657 | |
|
|
658 | return 0; |
|
|
659 | } |
|
|
660 | |
|
|
661 | static MGVTBL mmap_vtbl = { |
|
|
662 | 0, 0, 0, 0, mmap_free |
|
|
663 | }; |
|
|
664 | |
|
|
665 | /*****************************************************************************/ |
562 | |
666 | |
563 | static SV * |
667 | static SV * |
564 | get_cb (SV *cb_sv) |
668 | get_cb (SV *cb_sv) |
565 | { |
669 | { |
566 | SvGETMAGIC (cb_sv); |
670 | SvGETMAGIC (cb_sv); |
… | |
… | |
598 | { |
702 | { |
599 | static const struct { |
703 | static const struct { |
600 | const char *name; |
704 | const char *name; |
601 | IV iv; |
705 | IV iv; |
602 | } *civ, const_iv[] = { |
706 | } *civ, const_iv[] = { |
603 | # define const_iv(name, value) { # name, (IV) value }, |
707 | # define const_niv(name, value) { # name, (IV) value }, |
|
|
708 | # define const_iv(name) { # name, (IV) name }, |
604 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
709 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
605 | const_iv (EXDEV , EXDEV) |
710 | const_iv (EXDEV) |
606 | const_iv (ENOSYS , ENOSYS) |
711 | const_iv (ENOSYS) |
607 | const_iv (O_RDONLY, O_RDONLY) |
712 | const_iv (O_RDONLY) |
608 | const_iv (O_WRONLY, O_WRONLY) |
713 | const_iv (O_WRONLY) |
|
|
714 | const_iv (O_RDWR) |
609 | const_iv (O_CREAT , O_CREAT) |
715 | const_iv (O_CREAT) |
610 | const_iv (O_TRUNC , O_TRUNC) |
716 | const_iv (O_TRUNC) |
|
|
717 | const_iv (O_EXCL) |
|
|
718 | const_iv (O_APPEND) |
611 | #ifndef _WIN32 |
719 | #ifndef _WIN32 |
612 | const_iv (S_IFIFO , S_IFIFO) |
720 | const_iv (S_IFIFO) |
613 | #endif |
721 | #endif |
614 | const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) |
722 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
615 | const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
723 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
616 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
724 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
617 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
725 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
618 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
726 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
619 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
727 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
620 | |
728 | |
621 | const_iv (ST_RDONLY , ST_RDONLY) |
729 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
622 | const_iv (ST_NOSUID , ST_NOSUID) |
730 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
623 | const_iv (ST_NODEV , ST_NODEV) |
731 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
624 | const_iv (ST_NOEXEC , ST_NOEXEC) |
732 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
733 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
734 | |
|
|
735 | const_iv (ST_RDONLY) |
|
|
736 | const_iv (ST_NOSUID) |
|
|
737 | const_iv (ST_NODEV) |
|
|
738 | const_iv (ST_NOEXEC) |
625 | const_iv (ST_SYNCHRONOUS , ST_SYNCHRONOUS) |
739 | const_iv (ST_SYNCHRONOUS) |
626 | const_iv (ST_MANDLOCK , ST_MANDLOCK) |
740 | const_iv (ST_MANDLOCK) |
627 | const_iv (ST_WRITE , ST_WRITE) |
741 | const_iv (ST_WRITE) |
628 | const_iv (ST_APPEND , ST_APPEND) |
742 | const_iv (ST_APPEND) |
629 | const_iv (ST_IMMUTABLE , ST_IMMUTABLE) |
743 | const_iv (ST_IMMUTABLE) |
630 | const_iv (ST_NOATIME , ST_NOATIME) |
744 | const_iv (ST_NOATIME) |
631 | const_iv (ST_NODIRATIME , ST_NODIRATIME) |
745 | const_iv (ST_NODIRATIME) |
632 | const_iv (ST_RELATIME , ST_RELATIME) |
746 | const_iv (ST_RELATIME) |
|
|
747 | |
|
|
748 | const_iv (PROT_EXEC) |
|
|
749 | const_iv (PROT_NONE) |
|
|
750 | const_iv (PROT_READ) |
|
|
751 | const_iv (PROT_WRITE) |
|
|
752 | |
|
|
753 | /*const_iv (MAP_FIXED)*/ |
|
|
754 | const_iv (MAP_PRIVATE) |
|
|
755 | const_iv (MAP_SHARED) |
|
|
756 | const_iv (MAP_ANONYMOUS) |
|
|
757 | |
|
|
758 | /* linuxish */ |
|
|
759 | const_iv (MAP_HUGETLB) |
|
|
760 | const_iv (MAP_LOCKED) |
|
|
761 | const_iv (MAP_NORESERVE) |
|
|
762 | const_iv (MAP_POPULATE) |
|
|
763 | const_iv (MAP_NONBLOCK) |
|
|
764 | |
|
|
765 | const_iv (MCL_FUTURE) |
|
|
766 | const_iv (MCL_CURRENT) |
633 | |
767 | |
634 | const_eio (MS_ASYNC) |
768 | const_eio (MS_ASYNC) |
635 | const_eio (MS_INVALIDATE) |
769 | const_eio (MS_INVALIDATE) |
636 | const_eio (MS_SYNC) |
770 | const_eio (MS_SYNC) |
637 | |
771 | |
… | |
… | |
661 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
795 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
662 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
796 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
663 | |
797 | |
664 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
798 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
665 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
799 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
800 | |
|
|
801 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
666 | |
802 | |
667 | create_respipe (); |
803 | create_respipe (); |
668 | |
804 | |
669 | if (eio_init (want_poll, done_poll) < 0) |
805 | if (eio_init (want_poll, done_poll) < 0) |
670 | croak ("IO::AIO: unable to initialise eio library"); |
806 | croak ("IO::AIO: unable to initialise eio library"); |
… | |
… | |
1257 | |
1393 | |
1258 | int |
1394 | int |
1259 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1395 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1260 | PROTOTYPE: $$$$ |
1396 | PROTOTYPE: $$$$ |
1261 | CODE: |
1397 | CODE: |
1262 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1263 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1398 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1264 | #else |
|
|
1265 | RETVAL = errno = ENOSYS; |
|
|
1266 | #endif |
|
|
1267 | OUTPUT: |
1399 | OUTPUT: |
1268 | RETVAL |
1400 | RETVAL |
1269 | |
1401 | |
1270 | ssize_t |
1402 | ssize_t |
1271 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1403 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
… | |
… | |
1273 | CODE: |
1405 | CODE: |
1274 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1406 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1275 | OUTPUT: |
1407 | OUTPUT: |
1276 | RETVAL |
1408 | RETVAL |
1277 | |
1409 | |
|
|
1410 | void |
|
|
1411 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
|
|
1412 | PROTOTYPE: $$$$$;$ |
|
|
1413 | PPCODE: |
|
|
1414 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1415 | { |
|
|
1416 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1417 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1418 | if (addr == (void *)-1) |
|
|
1419 | XSRETURN_NO; |
|
|
1420 | |
|
|
1421 | sv_force_normal (scalar); |
|
|
1422 | |
|
|
1423 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1424 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1425 | ->mg_obj = (SV *)length; |
|
|
1426 | |
|
|
1427 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1428 | |
|
|
1429 | if (!(prot & PROT_WRITE)) |
|
|
1430 | SvREADONLY_on (scalar); |
|
|
1431 | |
|
|
1432 | if (SvLEN (scalar)) |
|
|
1433 | Safefree (SvPVX (scalar)); |
|
|
1434 | |
|
|
1435 | SvPVX (scalar) = (char *)addr; |
|
|
1436 | SvCUR_set (scalar, length); |
|
|
1437 | SvLEN_set (scalar, 0); |
|
|
1438 | SvPOK_only (scalar); |
|
|
1439 | |
|
|
1440 | XSRETURN_YES; |
|
|
1441 | } |
|
|
1442 | |
|
|
1443 | void |
|
|
1444 | munmap (SV *scalar) |
|
|
1445 | PROTOTYPE: $ |
|
|
1446 | CODE: |
|
|
1447 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1448 | |
|
|
1449 | int |
|
|
1450 | madvise (SV *scalar, off_t offset, off_t length, IV advice) |
|
|
1451 | PROTOTYPE: $$$$ |
|
|
1452 | CODE: |
|
|
1453 | { |
|
|
1454 | char *addr = SvPV_nolen (scalar) + offset; |
|
|
1455 | |
|
|
1456 | if (!SvOK (ST (2))) |
|
|
1457 | length = SvCUR (scalar) - offset; |
|
|
1458 | |
|
|
1459 | if (addr >= SvEND (scalar) || length <= 0) |
|
|
1460 | XSRETURN_EMPTY; |
|
|
1461 | |
|
|
1462 | RETVAL = posix_madvise (addr, length, advice); |
|
|
1463 | } |
|
|
1464 | OUTPUT: |
|
|
1465 | RETVAL |
|
|
1466 | |
|
|
1467 | int |
|
|
1468 | mlockall (int flags) |
|
|
1469 | PROTOTYPE: $ |
|
|
1470 | CODE: |
|
|
1471 | #if _POSIX_MEMLOCK |
|
|
1472 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
|
|
1473 | extern int mallopt (int, int); |
|
|
1474 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1475 | #endif |
|
|
1476 | mlockall (flags); |
|
|
1477 | #else |
|
|
1478 | RETVAL = -1; |
|
|
1479 | errno = ENOSYS; |
|
|
1480 | #endif |
|
|
1481 | OUTPUT: |
|
|
1482 | RETVAL |
|
|
1483 | |
|
|
1484 | int |
|
|
1485 | munlockall () |
|
|
1486 | PROTOTYPE: |
|
|
1487 | CODE: |
|
|
1488 | #if _POSIX_MEMLOCK |
|
|
1489 | munlockall (); |
|
|
1490 | #else |
|
|
1491 | RETVAL = -1; |
|
|
1492 | errno = ENOSYS; |
|
|
1493 | #endif |
|
|
1494 | OUTPUT: |
|
|
1495 | RETVAL |
|
|
1496 | |
1278 | void _on_next_submit (SV *cb) |
1497 | void _on_next_submit (SV *cb) |
1279 | CODE: |
1498 | CODE: |
1280 | SvREFCNT_dec (on_next_submit); |
1499 | SvREFCNT_dec (on_next_submit); |
1281 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1500 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1282 | |
1501 | |