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.277 by root, Wed Apr 3 03:09:04 2019 UTC vs.
Revision 1.289 by root, Mon Jan 4 22:19:06 2021 UTC

84 84
85#else 85#else
86 86
87 #include <sys/time.h> 87 #include <sys/time.h>
88 #include <sys/select.h> 88 #include <sys/select.h>
89 #include <sys/wait.h>
89 #include <unistd.h> 90 #include <unistd.h>
90 #include <utime.h> 91 #include <utime.h>
91 #include <signal.h> 92 #include <signal.h>
92 93
93 #define EIO_STRUCT_STAT Stat_t 94 #define EIO_STRUCT_STAT Stat_t
226 227
227#if PAGESIZE <= 0 228#if PAGESIZE <= 0
228# define PAGESIZE sysconf (_SC_PAGESIZE) 229# define PAGESIZE sysconf (_SC_PAGESIZE)
229#endif 230#endif
230 231
232/* solaris perl seems to declare a wrong syscall function that clashes with system includes */
233#ifdef __sun
234# undef HAVE_SYSCALL
235#endif
236
237#if HAVE_SYSCALL
238#include <sys/syscall.h>
239#else
240# define syscall(nr,...) (errno = ENOSYS, -1)
241#endif
242
231/*****************************************************************************/ 243/*****************************************************************************/
232 244
233#if !_POSIX_MAPPED_FILES 245#if !_POSIX_MAPPED_FILES
234# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) 246# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1)
235# define munmap(addr,length) EIO_ENOSYS () 247# define munmap(addr,length) EIO_ENOSYS ()
344 int count = req->int3; 356 int count = req->int3;
345 357
346 req->flags |= EIO_FLAG_PTR1_FREE; 358 req->flags |= EIO_FLAG_PTR1_FREE;
347 359
348 /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ 360 /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */
349 /* increase in 3.5kb steps */ 361 /* increase in fixed steps */
350 if (count < 0) 362 if (count < 0)
351 count = 8; 363 count = 8;
352 364
353 fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); 365 fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count);
354 errno = ENOMEM; 366 errno = ENOMEM;
407 419
408 for (count = 0; count < incmap->fm_mapped_extents; ++count) 420 for (count = 0; count < incmap->fm_mapped_extents; ++count)
409 { 421 {
410 struct fiemap_extent *e = incmap->fm_extents + count; 422 struct fiemap_extent *e = incmap->fm_extents + count;
411 423
424 fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e;
425
412 if (e->fe_logical + e->fe_length >= end_offset) 426 if (e->fe_logical >= end_offset)
413 goto done; 427 goto done;
414
415 fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e;
416 428
417 if (e->fe_flags & FIEMAP_EXTENT_LAST) 429 if (e->fe_flags & FIEMAP_EXTENT_LAST)
418 goto done; 430 goto done;
419 431
420 } 432 }
1329 const_iv (STATX_ATTR_APPEND) 1341 const_iv (STATX_ATTR_APPEND)
1330 const_iv (STATX_ATTR_NODUMP) 1342 const_iv (STATX_ATTR_NODUMP)
1331 const_iv (STATX_ATTR_ENCRYPTED) 1343 const_iv (STATX_ATTR_ENCRYPTED)
1332 const_iv (STATX_ATTR_AUTOMOUNT) 1344 const_iv (STATX_ATTR_AUTOMOUNT)
1333 1345
1346 const_iv (AT_FDCWD)
1347 const_iv (AT_SYMLINK_NOFOLLOW)
1348 const_iv (AT_EACCESS)
1349 const_iv (AT_REMOVEDIR)
1350 const_iv (AT_SYMLINK_FOLLOW)
1351 const_iv (AT_NO_AUTOMOUNT)
1352 const_iv (AT_EMPTY_PATH)
1353 const_iv (AT_STATX_SYNC_TYPE)
1354 const_iv (AT_STATX_AS_STAT)
1355 const_iv (AT_STATX_FORCE_SYNC)
1356 const_iv (AT_STATX_DONT_SYNC)
1357 const_iv (AT_RECURSIVE)
1358
1359 const_iv (OPEN_TREE_CLONE)
1360
1361 const_iv (FSOPEN_CLOEXEC)
1362
1363 const_iv (FSPICK_CLOEXEC)
1364 const_iv (FSPICK_SYMLINK_NOFOLLOW)
1365 const_iv (FSPICK_NO_AUTOMOUNT)
1366 const_iv (FSPICK_EMPTY_PATH)
1367
1368 const_iv (MOVE_MOUNT_F_SYMLINKS)
1369 const_iv (MOVE_MOUNT_F_AUTOMOUNTS)
1370 const_iv (MOVE_MOUNT_F_EMPTY_PATH)
1371 const_iv (MOVE_MOUNT_T_SYMLINKS)
1372 const_iv (MOVE_MOUNT_T_AUTOMOUNTS)
1373 const_iv (MOVE_MOUNT_T_EMPTY_PATH)
1374
1375 /* waitid */
1376 const_iv (P_PID)
1377 const_iv (P_PIDFD)
1378 const_iv (P_PGID)
1379 const_iv (P_ALL)
1380
1381 const_iv (FSCONFIG_SET_FLAG)
1382 const_iv (FSCONFIG_SET_STRING)
1383 const_iv (FSCONFIG_SET_BINARY)
1384 const_iv (FSCONFIG_SET_PATH)
1385 const_iv (FSCONFIG_SET_PATH_EMPTY)
1386 const_iv (FSCONFIG_SET_FD)
1387 const_iv (FSCONFIG_CMD_CREATE)
1388 const_iv (FSCONFIG_CMD_RECONFIGURE)
1389
1390 const_iv (MOUNT_ATTR_RDONLY)
1391 const_iv (MOUNT_ATTR_NOSUID)
1392 const_iv (MOUNT_ATTR_NODEV)
1393 const_iv (MOUNT_ATTR_NOEXEC)
1394 const_iv (MOUNT_ATTR__ATIME)
1395 const_iv (MOUNT_ATTR_RELATIME)
1396 const_iv (MOUNT_ATTR_NOATIME)
1397 const_iv (MOUNT_ATTR_STRICTATIME)
1398 const_iv (MOUNT_ATTR_NODIRATIME)
1399
1334 /* these are libeio constants, and are independent of gendef0 */ 1400 /* these are libeio constants, and are independent of gendef0 */
1335 const_eio (SEEK_SET) 1401 const_eio (SEEK_SET)
1336 const_eio (SEEK_CUR) 1402 const_eio (SEEK_CUR)
1337 const_eio (SEEK_END) 1403 const_eio (SEEK_END)
1338 1404
2495 RETVAL = 0; 2561 RETVAL = 0;
2496#endif 2562#endif
2497 OUTPUT: 2563 OUTPUT:
2498 RETVAL 2564 RETVAL
2499 2565
2500int 2566void
2567accept4 (aio_rfd rfh, SV *sockaddr, int salen, int flags)
2568 PPCODE:
2569{
2570 SV *retval;
2571#if HAVE_ACCEPT4
2572 socklen_t salen_ = salen ? salen + 1 : 0;
2573
2574 if (salen)
2575 {
2576 sv_upgrade (sockaddr, SVt_PV);
2577 sv_grow (sockaddr, salen_);
2578 }
2579
2580 int res = accept4 (rfh, salen ? (struct sockaddr *)SvPVX (sockaddr) : 0, salen ? &salen_ : 0, flags);
2581
2582 retval = newmortalFH (res, O_RDWR);
2583
2584 if (res >= 0 && salen > 0)
2585 {
2586 if (salen_ > salen + 1)
2587 salen_ = salen + 1;
2588
2589 SvPOK_only (sockaddr);
2590 SvCUR_set (sockaddr, salen_);
2591 }
2592#else
2593 errno = ENOSYS;
2594 retval = &PL_sv_undef;
2595#endif
2596 XPUSHs (retval);
2597}
2598
2599ssize_t
2501splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) 2600splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
2502 CODE: 2601 CODE:
2503{ 2602{
2504#if HAVE_LINUX_SPLICE 2603#if HAVE_LINUX_SPLICE
2505 loff_t off_in_, off_out_; 2604 loff_t off_in_, off_out_;
2513#endif 2612#endif
2514} 2613}
2515 OUTPUT: 2614 OUTPUT:
2516 RETVAL 2615 RETVAL
2517 2616
2518int 2617ssize_t
2519tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) 2618tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
2520 CODE: 2619 CODE:
2521#if HAVE_LINUX_SPLICE 2620#if HAVE_LINUX_SPLICE
2522 RETVAL = tee (rfh, wfh, length, flags); 2621 RETVAL = tee (rfh, wfh, length, flags);
2523#else 2622#else
2566 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2665 PUSHs (newmortalFH (fd[1], O_WRONLY));
2567 } 2666 }
2568} 2667}
2569 2668
2570void 2669void
2670pidfd_open (int pid, unsigned int flags = 0)
2671 PPCODE:
2672{
2673 /*GENDEF0_SYSCALL(pidfd_open,434)*/
2674 int fd = syscall (SYS_pidfd_open, pid, flags);
2675 XPUSHs (newmortalFH (fd, O_RDWR));
2676}
2677
2678int
2679pidfd_send_signal (SV *pidfh, int sig, SV *siginfo = &PL_sv_undef, unsigned int flags = 0)
2680 PPCODE:
2681{
2682 int res;
2683 siginfo_t si = { 0 };
2684
2685 if (SvOK (siginfo))
2686 {
2687 HV *hv;
2688 SV **svp;
2689
2690 if (!SvROK (siginfo) || SvTYPE (SvRV (siginfo)) != SVt_PVHV)
2691 croak ("siginfo argument must be a hashref code, pid, uid and value_int or value_ptr members, caught");
2692
2693 hv = (HV *)SvRV (siginfo);
2694
2695 if ((svp = hv_fetchs (hv, "code" , 0))) si.si_code = SvIV (*svp);
2696 if ((svp = hv_fetchs (hv, "pid" , 0))) si.si_pid = SvIV (*svp);
2697 if ((svp = hv_fetchs (hv, "uid" , 0))) si.si_uid = SvIV (*svp);
2698 if ((svp = hv_fetchs (hv, "value_int", 0))) si.si_value.sival_int = SvIV (*svp);
2699 if ((svp = hv_fetchs (hv, "value_ptr", 0))) si.si_value.sival_ptr = (void *)SvIV (*svp);
2700 }
2701
2702 /*GENDEF0_SYSCALL(pidfd_send_signal,424)*/
2703 res = syscall (SYS_pidfd_send_signal, s_fileno_croak (pidfh, 0), sig, SvOK (siginfo) ? &si : 0, flags);
2704
2705 XPUSHs (sv_2mortal (newSViv (res)));
2706}
2707
2708void
2709pidfd_getfd (SV *pidfh, int targetfd, unsigned int flags = 0)
2710 PPCODE:
2711{
2712 /*GENDEF0_SYSCALL(pidfd_getfd,438)*/
2713 int fd = syscall (SYS_pidfd_getfd, s_fileno_croak (pidfh, 0), targetfd, flags);
2714 XPUSHs (newmortalFH (fd, O_RDWR));
2715}
2716
2717void
2571eventfd (unsigned int initval = 0, int flags = 0) 2718eventfd (unsigned int initval = 0, int flags = 0)
2572 PPCODE: 2719 PPCODE:
2573{ 2720{
2574 int fd; 2721 int fd;
2575#if HAVE_EVENTFD 2722#if HAVE_EVENTFD
2694 if (0 == setrlimit (RLIMIT_NOFILE, &rl)) 2841 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2695 XSRETURN_YES; 2842 XSRETURN_YES;
2696 2843
2697 if (errno == EPERM) 2844 if (errno == EPERM)
2698 { 2845 {
2699 /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ 2846 /* setrlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */
2700 /* our limit overflows a system-wide limit */ 2847 /* our limit overflows a system-wide limit */
2701 /* try an adaptive algorithm, but do not lower the hardlimit */ 2848 /* try an adaptive algorithm, but do not lower the hardlimit */
2702 rl.rlim_max = 0; 2849 rl.rlim_max = 0;
2703 for (bit = 0x40000000U; bit; bit >>= 1) 2850 for (bit = 0x40000000U; bit; bit >>= 1)
2704 { 2851 {
2705 rl.rlim_max |= bit; 2852 rl.rlim_max |= bit;
2706 rl.rlim_cur = rl.rlim_max; 2853 rl.rlim_cur = rl.rlim_max;
2707 2854
2708 /* nevr decrease the hard limit */ 2855 /* never decrease the hard limit */
2709 if (rl.rlim_max < orig_rlim_max) 2856 if (rl.rlim_max < orig_rlim_max)
2710 break; 2857 break;
2711 2858
2712 if (0 != setrlimit (RLIMIT_NOFILE, &rl)) 2859 if (0 != setrlimit (RLIMIT_NOFILE, &rl))
2713 rl.rlim_max &= ~bit; /* too high, remove bit again */ 2860 rl.rlim_max &= ~bit; /* too high, remove bit again */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines