ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.164 by root, Tue May 4 21:14:01 2010 UTC vs.
Revision 1.171 by root, Wed Aug 4 17:16:19 2010 UTC

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
307static int req_invoke (eio_req *req) 345static 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
596static int 654static 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}
677 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) 738 const_niv (FADV_RANDOM , POSIX_FADV_RANDOM)
678 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) 739 const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE)
679 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) 740 const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED)
680 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) 741 const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED)
681 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)
748
682 const_iv (ST_RDONLY) 749 const_iv (ST_RDONLY)
683 const_iv (ST_NOSUID) 750 const_iv (ST_NOSUID)
684 const_iv (ST_NODEV) 751 const_iv (ST_NODEV)
685 const_iv (ST_NOEXEC) 752 const_iv (ST_NOEXEC)
686 const_iv (ST_SYNCHRONOUS) 753 const_iv (ST_SYNCHRONOUS)
690 const_iv (ST_IMMUTABLE) 757 const_iv (ST_IMMUTABLE)
691 const_iv (ST_NOATIME) 758 const_iv (ST_NOATIME)
692 const_iv (ST_NODIRATIME) 759 const_iv (ST_NODIRATIME)
693 const_iv (ST_RELATIME) 760 const_iv (ST_RELATIME)
694 761
762 const_iv (PROT_NONE)
695 const_iv (PROT_EXEC) 763 const_iv (PROT_EXEC)
696 const_iv (PROT_NONE)
697 const_iv (PROT_READ) 764 const_iv (PROT_READ)
698 const_iv (PROT_WRITE) 765 const_iv (PROT_WRITE)
699 766
700 /*const_iv (MAP_FIXED)*/ 767 /*const_iv (MAP_FIXED)*/
701 const_iv (MAP_PRIVATE) 768 const_iv (MAP_PRIVATE)
1340 1407
1341int 1408int
1342fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) 1409fadvise (aio_rfd fh, off_t offset, off_t length, IV advice)
1343 PROTOTYPE: $$$$ 1410 PROTOTYPE: $$$$
1344 CODE: 1411 CODE:
1345#if _XOPEN_SOURCE >= 600 && !NO_FADVISE
1346 RETVAL = posix_fadvise (fh, offset, length, advice); 1412 RETVAL = posix_fadvise (fh, offset, length, advice);
1347#else
1348 RETVAL = errno = ENOSYS; /* yes, this is actually correct */
1349#endif
1350 OUTPUT: 1413 OUTPUT:
1351 RETVAL 1414 RETVAL
1352 1415
1353ssize_t 1416ssize_t
1354sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) 1417sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count)
1367 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;
1368 void *addr = (void *)mmap (0, length, prot, flags, fd, offset); 1431 void *addr = (void *)mmap (0, length, prot, flags, fd, offset);
1369 if (addr == (void *)-1) 1432 if (addr == (void *)-1)
1370 XSRETURN_NO; 1433 XSRETURN_NO;
1371 1434
1435 sv_force_normal (scalar);
1436
1372 /* we store the length in mg_obj, as namlen is I32 :/ */ 1437 /* we store the length in mg_obj, as namlen is I32 :/ */
1373 sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) 1438 sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0)
1374 ->mg_obj = (SV *)length; 1439 ->mg_obj = (SV *)length;
1375 1440
1376 SvUPGRADE (scalar, SVt_PV); /* nop... */ 1441 SvUPGRADE (scalar, SVt_PV); /* nop... */
1442
1377 if (!(prot & PROT_WRITE)) 1443 if (!(prot & PROT_WRITE))
1378 SvREADONLY_on (scalar); 1444 SvREADONLY_on (scalar);
1445
1446 if (SvLEN (scalar))
1447 Safefree (SvPVX (scalar));
1379 1448
1380 SvPVX (scalar) = (char *)addr; 1449 SvPVX (scalar) = (char *)addr;
1381 SvCUR_set (scalar, length); 1450 SvCUR_set (scalar, length);
1382 SvLEN_set (scalar, 0); 1451 SvLEN_set (scalar, 0);
1383 SvPOK_only (scalar); 1452 SvPOK_only (scalar);
1388void 1457void
1389munmap (SV *scalar) 1458munmap (SV *scalar)
1390 PROTOTYPE: $ 1459 PROTOTYPE: $
1391 CODE: 1460 CODE:
1392 sv_unmagic (scalar, MMAP_MAGIC); 1461 sv_unmagic (scalar, MMAP_MAGIC);
1462
1463int
1464madvise (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
1393 1492
1394int 1493int
1395mlockall (int flags) 1494mlockall (int flags)
1396 PROTOTYPE: $ 1495 PROTOTYPE: $
1397 CODE: 1496 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines