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.275 by root, Mon Mar 18 23:52:09 2019 UTC vs.
Revision 1.286 by root, Tue Dec 29 15:25:26 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
1284 const_iv (SPLICE_F_GIFT) 1297 const_iv (SPLICE_F_GIFT)
1285 1298
1286 const_iv (EFD_CLOEXEC) 1299 const_iv (EFD_CLOEXEC)
1287 const_iv (EFD_NONBLOCK) 1300 const_iv (EFD_NONBLOCK)
1288 const_iv (EFD_SEMAPHORE) 1301 const_iv (EFD_SEMAPHORE)
1302
1303 const_iv (MFD_CLOEXEC)
1304 const_iv (MFD_ALLOW_SEALING)
1305 const_iv (MFD_HUGETLB)
1289 1306
1290 const_iv (CLOCK_REALTIME) 1307 const_iv (CLOCK_REALTIME)
1291 const_iv (CLOCK_MONOTONIC) 1308 const_iv (CLOCK_MONOTONIC)
1292 const_iv (CLOCK_BOOTTIME) 1309 const_iv (CLOCK_BOOTTIME)
1293 const_iv (CLOCK_REALTIME_ALARM) 1310 const_iv (CLOCK_REALTIME_ALARM)
1318 const_iv (STATX_ATTR_APPEND) 1335 const_iv (STATX_ATTR_APPEND)
1319 const_iv (STATX_ATTR_NODUMP) 1336 const_iv (STATX_ATTR_NODUMP)
1320 const_iv (STATX_ATTR_ENCRYPTED) 1337 const_iv (STATX_ATTR_ENCRYPTED)
1321 const_iv (STATX_ATTR_AUTOMOUNT) 1338 const_iv (STATX_ATTR_AUTOMOUNT)
1322 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 (FSOPEN_CLOEXEC)
1356
1357 const_iv (FSPICK_CLOEXEC)
1358 const_iv (FSPICK_SYMLINK_NOFOLLOW)
1359 const_iv (FSPICK_NO_AUTOMOUNT)
1360 const_iv (FSPICK_EMPTY_PATH)
1361
1362 const_iv (MOVE_MOUNT_F_SYMLINKS)
1363 const_iv (MOVE_MOUNT_F_AUTOMOUNTS)
1364 const_iv (MOVE_MOUNT_F_EMPTY_PATH)
1365 const_iv (MOVE_MOUNT_T_SYMLINKS)
1366 const_iv (MOVE_MOUNT_T_AUTOMOUNTS)
1367 const_iv (MOVE_MOUNT_T_EMPTY_PATH)
1368
1323 /* these are libeio constants, and are independent of gendef0 */ 1369 /* these are libeio constants, and are independent of gendef0 */
1324 const_eio (SEEK_SET) 1370 const_eio (SEEK_SET)
1325 const_eio (SEEK_CUR) 1371 const_eio (SEEK_CUR)
1326 const_eio (SEEK_END) 1372 const_eio (SEEK_END)
1327 1373
2484 RETVAL = 0; 2530 RETVAL = 0;
2485#endif 2531#endif
2486 OUTPUT: 2532 OUTPUT:
2487 RETVAL 2533 RETVAL
2488 2534
2489int 2535void
2536accept4 (aio_rfd rfh, SV *sockaddr, int salen, int flags)
2537 PPCODE:
2538{
2539 SV *retval;
2540#if HAVE_ACCEPT4
2541 socklen_t salen_ = salen ? salen + 1 : 0;
2542
2543 if (salen)
2544 {
2545 sv_upgrade (sockaddr, SVt_PV);
2546 sv_grow (sockaddr, salen_);
2547 }
2548
2549 int res = accept4 (rfh, salen ? (struct sockaddr *)SvPVX (sockaddr) : 0, salen ? &salen_ : 0, flags);
2550
2551 retval = newmortalFH (res, O_RDWR);
2552
2553 if (res >= 0 && salen > 0)
2554 {
2555 if (salen_ > salen + 1)
2556 salen_ = salen + 1;
2557
2558 SvPOK_only (sockaddr);
2559 SvCUR_set (sockaddr, salen_);
2560 }
2561#else
2562 errno = ENOSYS;
2563 retval = &PL_sv_undef;
2564#endif
2565 XPUSHs (retval);
2566}
2567
2568ssize_t
2490splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) 2569splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
2491 CODE: 2570 CODE:
2492{ 2571{
2493#if HAVE_LINUX_SPLICE 2572#if HAVE_LINUX_SPLICE
2494 loff_t off_in_, off_out_; 2573 loff_t off_in_, off_out_;
2502#endif 2581#endif
2503} 2582}
2504 OUTPUT: 2583 OUTPUT:
2505 RETVAL 2584 RETVAL
2506 2585
2507int 2586ssize_t
2508tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) 2587tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
2509 CODE: 2588 CODE:
2510#if HAVE_LINUX_SPLICE 2589#if HAVE_LINUX_SPLICE
2511 RETVAL = tee (rfh, wfh, length, flags); 2590 RETVAL = tee (rfh, wfh, length, flags);
2512#else 2591#else
2555 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2634 PUSHs (newmortalFH (fd[1], O_WRONLY));
2556 } 2635 }
2557} 2636}
2558 2637
2559void 2638void
2639pidfd_open (int pid, unsigned int flags = 0)
2640 PPCODE:
2641{
2642 /*GENDEF0_SYSCALL(pidfd_open,434)*/
2643 int fd = syscall (SYS_pidfd_open, pid, flags);
2644 XPUSHs (newmortalFH (fd, O_RDWR));
2645}
2646
2647int
2648pidfd_send_signal (SV *pidfh, int sig, SV *siginfo = &PL_sv_undef, unsigned int flags = 0)
2649 PPCODE:
2650{
2651 int res;
2652 siginfo_t si = { 0 };
2653
2654 if (SvOK (siginfo))
2655 {
2656 HV *hv;
2657 SV **svp;
2658
2659 if (!SvROK (siginfo) || SvTYPE (SvRV (siginfo)) != SVt_PVHV)
2660 croak ("siginfo argument must be a hashref code, pid, uid and value_int or value_ptr members, caught");
2661
2662 hv = (HV *)SvRV (siginfo);
2663
2664 if ((svp = hv_fetchs (hv, "code" , 0))) si.si_code = SvIV (*svp);
2665 if ((svp = hv_fetchs (hv, "pid" , 0))) si.si_pid = SvIV (*svp);
2666 if ((svp = hv_fetchs (hv, "uid" , 0))) si.si_uid = SvIV (*svp);
2667 if ((svp = hv_fetchs (hv, "value_int", 0))) si.si_value.sival_int = SvIV (*svp);
2668 if ((svp = hv_fetchs (hv, "value_ptr", 0))) si.si_value.sival_ptr = (void *)SvIV (*svp);
2669 }
2670
2671 /*GENDEF0_SYSCALL(pidfd_send_signal,424)*/
2672 res = syscall (SYS_pidfd_send_signal, s_fileno_croak (pidfh, 0), sig, SvOK (siginfo) ? &si : 0, flags);
2673
2674 XPUSHs (sv_2mortal (newSViv (res)));
2675}
2676
2677void
2678pidfd_getfd (SV *pidfh, int targetfd, unsigned int flags = 0)
2679 PPCODE:
2680{
2681 /*GENDEF0_SYSCALL(pidfd_getfd,438)*/
2682 int fd = syscall (SYS_pidfd_getfd, s_fileno_croak (pidfh, 0), targetfd, flags);
2683 XPUSHs (newmortalFH (fd, O_RDWR));
2684}
2685
2686void
2560eventfd (unsigned int initval = 0, int flags = 0) 2687eventfd (unsigned int initval = 0, int flags = 0)
2561 PPCODE: 2688 PPCODE:
2562{ 2689{
2563 int fd; 2690 int fd;
2564#if HAVE_EVENTFD 2691#if HAVE_EVENTFD
2627#else 2754#else
2628 errno = ENOSYS; 2755 errno = ENOSYS;
2629#endif 2756#endif
2630} 2757}
2631 2758
2759void
2760memfd_create (SV8 *pathname, int flags = 0)
2761 PPCODE:
2762{
2763 int fd;
2764#if HAVE_MEMFD_CREATE
2765 fd = memfd_create (SvPVbyte_nolen (pathname), flags);
2766#else
2767 fd = (errno = ENOSYS, -1);
2768#endif
2769
2770 XPUSHs (newmortalFH (fd, O_RDWR));
2771}
2772
2632UV 2773UV
2633get_fdlimit () 2774get_fdlimit ()
2634 CODE: 2775 CODE:
2635#if HAVE_RLIMITS 2776#if HAVE_RLIMITS
2636 struct rlimit rl; 2777 struct rlimit rl;
2669 if (0 == setrlimit (RLIMIT_NOFILE, &rl)) 2810 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2670 XSRETURN_YES; 2811 XSRETURN_YES;
2671 2812
2672 if (errno == EPERM) 2813 if (errno == EPERM)
2673 { 2814 {
2674 /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ 2815 /* setrlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */
2675 /* our limit overflows a system-wide limit */ 2816 /* our limit overflows a system-wide limit */
2676 /* try an adaptive algorithm, but do not lower the hardlimit */ 2817 /* try an adaptive algorithm, but do not lower the hardlimit */
2677 rl.rlim_max = 0; 2818 rl.rlim_max = 0;
2678 for (bit = 0x40000000U; bit; bit >>= 1) 2819 for (bit = 0x40000000U; bit; bit >>= 1)
2679 { 2820 {
2680 rl.rlim_max |= bit; 2821 rl.rlim_max |= bit;
2681 rl.rlim_cur = rl.rlim_max; 2822 rl.rlim_cur = rl.rlim_max;
2682 2823
2683 /* nevr decrease the hard limit */ 2824 /* never decrease the hard limit */
2684 if (rl.rlim_max < orig_rlim_max) 2825 if (rl.rlim_max < orig_rlim_max)
2685 break; 2826 break;
2686 2827
2687 if (0 != setrlimit (RLIMIT_NOFILE, &rl)) 2828 if (0 != setrlimit (RLIMIT_NOFILE, &rl))
2688 rl.rlim_max &= ~bit; /* too high, remove bit again */ 2829 rl.rlim_max &= ~bit; /* too high, remove bit again */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines