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.276 by root, Wed Apr 3 03:03:53 2019 UTC vs.
Revision 1.285 by root, Tue Dec 29 15:16:28 2020 UTC

226 226
227#if PAGESIZE <= 0 227#if PAGESIZE <= 0
228# define PAGESIZE sysconf (_SC_PAGESIZE) 228# define PAGESIZE sysconf (_SC_PAGESIZE)
229#endif 229#endif
230 230
231#if HAVE_SYSCALL
232#include <sys/syscall.h>
233#else
234# define syscall(nr,...) (errno = ENOSYS, -1)
235#endif
236
231/*****************************************************************************/ 237/*****************************************************************************/
232 238
233#if !_POSIX_MAPPED_FILES 239#if !_POSIX_MAPPED_FILES
234# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) 240# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
235# define munmap(addr,length) EIO_ENOSYS () 241# define munmap(addr,length) EIO_ENOSYS ()
344 int count = req->int3; 350 int count = req->int3;
345 351
346 req->flags |= EIO_FLAG_PTR1_FREE; 352 req->flags |= EIO_FLAG_PTR1_FREE;
347 353
348 /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ 354 /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */
349 /* increase in 3.5kb steps */ 355 /* increase in fixed steps */
350 if (count < 0) 356 if (count < 0)
351 count = 8; 357 count = 8;
352 358
353 fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); 359 fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count);
354 errno = ENOMEM; 360 errno = ENOMEM;
407 413
408 for (count = 0; count < incmap->fm_mapped_extents; ++count) 414 for (count = 0; count < incmap->fm_mapped_extents; ++count)
409 { 415 {
410 struct fiemap_extent *e = incmap->fm_extents + count; 416 struct fiemap_extent *e = incmap->fm_extents + count;
411 417
418 fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e;
419
412 if (e->fe_logical + e->fe_length >= end_offset) 420 if (e->fe_logical >= end_offset)
413 goto done; 421 goto done;
414
415 fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e;
416 422
417 if (e->fe_flags & FIEMAP_EXTENT_LAST) 423 if (e->fe_flags & FIEMAP_EXTENT_LAST)
418 goto done; 424 goto done;
419 425
420 } 426 }
1195 const_iv (MAP_STACK) 1201 const_iv (MAP_STACK)
1196 1202
1197 const_iv (MREMAP_MAYMOVE) 1203 const_iv (MREMAP_MAYMOVE)
1198 const_iv (MREMAP_FIXED) 1204 const_iv (MREMAP_FIXED)
1199 1205
1200 const_iv (F_DUPFD_CLOEXEC)
1201
1202 const_iv (MSG_CMSG_CLOEXEC) 1206 const_iv (MSG_CMSG_CLOEXEC)
1203 const_iv (SOCK_CLOEXEC) 1207 const_iv (SOCK_CLOEXEC)
1208
1209 const_iv (F_DUPFD_CLOEXEC)
1210
1211 const_iv (F_ADD_SEALS)
1212 const_iv (F_GET_SEALS)
1213 const_iv (F_SEAL_SEAL)
1214 const_iv (F_SEAL_SHRINK)
1215 const_iv (F_SEAL_GROW)
1216 const_iv (F_SEAL_WRITE)
1204 1217
1205 const_iv (F_OFD_GETLK) 1218 const_iv (F_OFD_GETLK)
1206 const_iv (F_OFD_SETLK) 1219 const_iv (F_OFD_SETLK)
1207 const_iv (F_OFD_GETLKW) 1220 const_iv (F_OFD_GETLKW)
1208 1221
1322 const_iv (STATX_ATTR_APPEND) 1335 const_iv (STATX_ATTR_APPEND)
1323 const_iv (STATX_ATTR_NODUMP) 1336 const_iv (STATX_ATTR_NODUMP)
1324 const_iv (STATX_ATTR_ENCRYPTED) 1337 const_iv (STATX_ATTR_ENCRYPTED)
1325 const_iv (STATX_ATTR_AUTOMOUNT) 1338 const_iv (STATX_ATTR_AUTOMOUNT)
1326 1339
1340 const_iv (AT_FDCWD)
1341 const_iv (AT_SYMLINK_NOFOLLOW)
1342 const_iv (AT_EACCESS)
1343 const_iv (AT_REMOVEDIR)
1344 const_iv (AT_SYMLINK_FOLLOW)
1345 const_iv (AT_NO_AUTOMOUNT)
1346 const_iv (AT_EMPTY_PATH)
1347 const_iv (AT_STATX_SYNC_TYPE)
1348 const_iv (AT_STATX_AS_STAT)
1349 const_iv (AT_STATX_FORCE_SYNC)
1350 const_iv (AT_STATX_DONT_SYNC)
1351 const_iv (AT_RECURSIVE)
1352
1353 const_iv (OPEN_TREE_CLONE)
1354
1355 const_iv (MOVE_MOUNT_F_SYMLINKS)
1356 const_iv (MOVE_MOUNT_F_AUTOMOUNTS)
1357 const_iv (MOVE_MOUNT_F_EMPTY_PATH)
1358 const_iv (MOVE_MOUNT_T_SYMLINKS)
1359 const_iv (MOVE_MOUNT_T_AUTOMOUNTS)
1360 const_iv (MOVE_MOUNT_T_EMPTY_PATH)
1361
1327 /* these are libeio constants, and are independent of gendef0 */ 1362 /* these are libeio constants, and are independent of gendef0 */
1328 const_eio (SEEK_SET) 1363 const_eio (SEEK_SET)
1329 const_eio (SEEK_CUR) 1364 const_eio (SEEK_CUR)
1330 const_eio (SEEK_END) 1365 const_eio (SEEK_END)
1331 1366
2488 RETVAL = 0; 2523 RETVAL = 0;
2489#endif 2524#endif
2490 OUTPUT: 2525 OUTPUT:
2491 RETVAL 2526 RETVAL
2492 2527
2493int 2528void
2529accept4 (aio_rfd rfh, SV *sockaddr, int salen, int flags)
2530 PPCODE:
2531{
2532 SV *retval;
2533#if HAVE_ACCEPT4
2534 socklen_t salen_ = salen ? salen + 1 : 0;
2535
2536 if (salen)
2537 {
2538 sv_upgrade (sockaddr, SVt_PV);
2539 sv_grow (sockaddr, salen_);
2540 }
2541
2542 int res = accept4 (rfh, salen ? (struct sockaddr *)SvPVX (sockaddr) : 0, salen ? &salen_ : 0, flags);
2543
2544 retval = newmortalFH (res, O_RDWR);
2545
2546 if (res >= 0 && salen > 0)
2547 {
2548 if (salen_ > salen + 1)
2549 salen_ = salen + 1;
2550
2551 SvPOK_only (sockaddr);
2552 SvCUR_set (sockaddr, salen_);
2553 }
2554#else
2555 errno = ENOSYS;
2556 retval = &PL_sv_undef;
2557#endif
2558 XPUSHs (retval);
2559}
2560
2561ssize_t
2494splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) 2562splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
2495 CODE: 2563 CODE:
2496{ 2564{
2497#if HAVE_LINUX_SPLICE 2565#if HAVE_LINUX_SPLICE
2498 loff_t off_in_, off_out_; 2566 loff_t off_in_, off_out_;
2506#endif 2574#endif
2507} 2575}
2508 OUTPUT: 2576 OUTPUT:
2509 RETVAL 2577 RETVAL
2510 2578
2511int 2579ssize_t
2512tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) 2580tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
2513 CODE: 2581 CODE:
2514#if HAVE_LINUX_SPLICE 2582#if HAVE_LINUX_SPLICE
2515 RETVAL = tee (rfh, wfh, length, flags); 2583 RETVAL = tee (rfh, wfh, length, flags);
2516#else 2584#else
2559 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2627 PUSHs (newmortalFH (fd[1], O_WRONLY));
2560 } 2628 }
2561} 2629}
2562 2630
2563void 2631void
2632pidfd_open (int pid, unsigned int flags = 0)
2633 PPCODE:
2634{
2635 /*GENDEF0_SYSCALL(pidfd_open,434)*/
2636 int fd = syscall (SYS_pidfd_open, pid, flags);
2637 XPUSHs (newmortalFH (fd, O_RDWR));
2638}
2639
2640int
2641pidfd_send_signal (SV *pidfh, int sig, SV *siginfo = &PL_sv_undef, unsigned int flags = 0)
2642 PPCODE:
2643{
2644 int res;
2645 siginfo_t si = { 0 };
2646
2647 if (SvOK (siginfo))
2648 {
2649 HV *hv;
2650 SV **svp;
2651
2652 if (!SvROK (siginfo) || SvTYPE (SvRV (siginfo)) != SVt_PVHV)
2653 croak ("siginfo argument must be a hashref code, pid, uid and value_int or value_ptr members, caught");
2654
2655 hv = (HV *)SvRV (siginfo);
2656
2657 if ((svp = hv_fetchs (hv, "code" , 0))) si.si_code = SvIV (*svp);
2658 if ((svp = hv_fetchs (hv, "pid" , 0))) si.si_pid = SvIV (*svp);
2659 if ((svp = hv_fetchs (hv, "uid" , 0))) si.si_uid = SvIV (*svp);
2660 if ((svp = hv_fetchs (hv, "value_int", 0))) si.si_value.sival_int = SvIV (*svp);
2661 if ((svp = hv_fetchs (hv, "value_ptr", 0))) si.si_value.sival_ptr = (void *)SvIV (*svp);
2662 }
2663
2664 /*GENDEF0_SYSCALL(pidfd_send_signal,424)*/
2665 res = syscall (SYS_pidfd_send_signal, s_fileno_croak (pidfh, 0), sig, SvOK (siginfo) ? &si : 0, flags);
2666
2667 XPUSHs (sv_2mortal (newSViv (res)));
2668}
2669
2670void
2671pidfd_getfd (SV *pidfh, int targetfd, unsigned int flags = 0)
2672 PPCODE:
2673{
2674 /*GENDEF0_SYSCALL(pidfd_getfd,438)*/
2675 int fd = syscall (SYS_pidfd_getfd, s_fileno_croak (pidfh, 0), targetfd, flags);
2676 XPUSHs (newmortalFH (fd, O_RDWR));
2677}
2678
2679void
2564eventfd (unsigned int initval = 0, int flags = 0) 2680eventfd (unsigned int initval = 0, int flags = 0)
2565 PPCODE: 2681 PPCODE:
2566{ 2682{
2567 int fd; 2683 int fd;
2568#if HAVE_EVENTFD 2684#if HAVE_EVENTFD
2687 if (0 == setrlimit (RLIMIT_NOFILE, &rl)) 2803 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2688 XSRETURN_YES; 2804 XSRETURN_YES;
2689 2805
2690 if (errno == EPERM) 2806 if (errno == EPERM)
2691 { 2807 {
2692 /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ 2808 /* setrlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */
2693 /* our limit overflows a system-wide limit */ 2809 /* our limit overflows a system-wide limit */
2694 /* try an adaptive algorithm, but do not lower the hardlimit */ 2810 /* try an adaptive algorithm, but do not lower the hardlimit */
2695 rl.rlim_max = 0; 2811 rl.rlim_max = 0;
2696 for (bit = 0x40000000U; bit; bit >>= 1) 2812 for (bit = 0x40000000U; bit; bit >>= 1)
2697 { 2813 {
2698 rl.rlim_max |= bit; 2814 rl.rlim_max |= bit;
2699 rl.rlim_cur = rl.rlim_max; 2815 rl.rlim_cur = rl.rlim_max;
2700 2816
2701 /* nevr decrease the hard limit */ 2817 /* never decrease the hard limit */
2702 if (rl.rlim_max < orig_rlim_max) 2818 if (rl.rlim_max < orig_rlim_max)
2703 break; 2819 break;
2704 2820
2705 if (0 != setrlimit (RLIMIT_NOFILE, &rl)) 2821 if (0 != setrlimit (RLIMIT_NOFILE, &rl))
2706 rl.rlim_max &= ~bit; /* too high, remove bit again */ 2822 rl.rlim_max &= ~bit; /* too high, remove bit again */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines