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.291 by root, Tue Jul 27 07:58:35 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 }
1191 const_iv (MAP_NONBLOCK) 1203 const_iv (MAP_NONBLOCK)
1192 const_iv (MAP_GROWSDOWN) 1204 const_iv (MAP_GROWSDOWN)
1193 const_iv (MAP_32BIT) 1205 const_iv (MAP_32BIT)
1194 const_iv (MAP_HUGETLB) 1206 const_iv (MAP_HUGETLB)
1195 const_iv (MAP_STACK) 1207 const_iv (MAP_STACK)
1208 const_iv (MAP_FIXED_NOREPLACE)
1209 const_iv (MAP_SHARED_VALIDATE)
1210 const_iv (MAP_SYNC)
1211 const_iv (MAP_UNINITIALIZED)
1196 1212
1197 const_iv (MREMAP_MAYMOVE) 1213 const_iv (MREMAP_MAYMOVE)
1198 const_iv (MREMAP_FIXED) 1214 const_iv (MREMAP_FIXED)
1199 1215
1200 const_iv (F_DUPFD_CLOEXEC)
1201
1202 const_iv (MSG_CMSG_CLOEXEC) 1216 const_iv (MSG_CMSG_CLOEXEC)
1203 const_iv (SOCK_CLOEXEC) 1217 const_iv (SOCK_CLOEXEC)
1218
1219 const_iv (F_DUPFD_CLOEXEC)
1220
1221 const_iv (F_ADD_SEALS)
1222 const_iv (F_GET_SEALS)
1223 const_iv (F_SEAL_SEAL)
1224 const_iv (F_SEAL_SHRINK)
1225 const_iv (F_SEAL_GROW)
1226 const_iv (F_SEAL_WRITE)
1204 1227
1205 const_iv (F_OFD_GETLK) 1228 const_iv (F_OFD_GETLK)
1206 const_iv (F_OFD_SETLK) 1229 const_iv (F_OFD_SETLK)
1207 const_iv (F_OFD_GETLKW) 1230 const_iv (F_OFD_GETLKW)
1208 1231
1284 const_iv (SPLICE_F_GIFT) 1307 const_iv (SPLICE_F_GIFT)
1285 1308
1286 const_iv (EFD_CLOEXEC) 1309 const_iv (EFD_CLOEXEC)
1287 const_iv (EFD_NONBLOCK) 1310 const_iv (EFD_NONBLOCK)
1288 const_iv (EFD_SEMAPHORE) 1311 const_iv (EFD_SEMAPHORE)
1312
1313 const_iv (MFD_CLOEXEC)
1314 const_iv (MFD_ALLOW_SEALING)
1315 const_iv (MFD_HUGETLB)
1289 1316
1290 const_iv (CLOCK_REALTIME) 1317 const_iv (CLOCK_REALTIME)
1291 const_iv (CLOCK_MONOTONIC) 1318 const_iv (CLOCK_MONOTONIC)
1292 const_iv (CLOCK_BOOTTIME) 1319 const_iv (CLOCK_BOOTTIME)
1293 const_iv (CLOCK_REALTIME_ALARM) 1320 const_iv (CLOCK_REALTIME_ALARM)
1318 const_iv (STATX_ATTR_APPEND) 1345 const_iv (STATX_ATTR_APPEND)
1319 const_iv (STATX_ATTR_NODUMP) 1346 const_iv (STATX_ATTR_NODUMP)
1320 const_iv (STATX_ATTR_ENCRYPTED) 1347 const_iv (STATX_ATTR_ENCRYPTED)
1321 const_iv (STATX_ATTR_AUTOMOUNT) 1348 const_iv (STATX_ATTR_AUTOMOUNT)
1322 1349
1350 const_iv (AT_FDCWD)
1351 const_iv (AT_SYMLINK_NOFOLLOW)
1352 const_iv (AT_EACCESS)
1353 const_iv (AT_REMOVEDIR)
1354 const_iv (AT_SYMLINK_FOLLOW)
1355 const_iv (AT_NO_AUTOMOUNT)
1356 const_iv (AT_EMPTY_PATH)
1357 const_iv (AT_STATX_SYNC_TYPE)
1358 const_iv (AT_STATX_AS_STAT)
1359 const_iv (AT_STATX_FORCE_SYNC)
1360 const_iv (AT_STATX_DONT_SYNC)
1361 const_iv (AT_RECURSIVE)
1362
1363 const_iv (OPEN_TREE_CLONE)
1364
1365 const_iv (FSOPEN_CLOEXEC)
1366
1367 const_iv (FSPICK_CLOEXEC)
1368 const_iv (FSPICK_SYMLINK_NOFOLLOW)
1369 const_iv (FSPICK_NO_AUTOMOUNT)
1370 const_iv (FSPICK_EMPTY_PATH)
1371
1372 const_iv (MOVE_MOUNT_F_SYMLINKS)
1373 const_iv (MOVE_MOUNT_F_AUTOMOUNTS)
1374 const_iv (MOVE_MOUNT_F_EMPTY_PATH)
1375 const_iv (MOVE_MOUNT_T_SYMLINKS)
1376 const_iv (MOVE_MOUNT_T_AUTOMOUNTS)
1377 const_iv (MOVE_MOUNT_T_EMPTY_PATH)
1378
1379 /* waitid */
1380 const_iv (P_PID)
1381 const_iv (P_PIDFD)
1382 const_iv (P_PGID)
1383 const_iv (P_ALL)
1384
1385 const_iv (FSCONFIG_SET_FLAG)
1386 const_iv (FSCONFIG_SET_STRING)
1387 const_iv (FSCONFIG_SET_BINARY)
1388 const_iv (FSCONFIG_SET_PATH)
1389 const_iv (FSCONFIG_SET_PATH_EMPTY)
1390 const_iv (FSCONFIG_SET_FD)
1391 const_iv (FSCONFIG_CMD_CREATE)
1392 const_iv (FSCONFIG_CMD_RECONFIGURE)
1393
1394 const_iv (MOUNT_ATTR_RDONLY)
1395 const_iv (MOUNT_ATTR_NOSUID)
1396 const_iv (MOUNT_ATTR_NODEV)
1397 const_iv (MOUNT_ATTR_NOEXEC)
1398 const_iv (MOUNT_ATTR__ATIME)
1399 const_iv (MOUNT_ATTR_RELATIME)
1400 const_iv (MOUNT_ATTR_NOATIME)
1401 const_iv (MOUNT_ATTR_STRICTATIME)
1402 const_iv (MOUNT_ATTR_NODIRATIME)
1403
1323 /* these are libeio constants, and are independent of gendef0 */ 1404 /* these are libeio constants, and are independent of gendef0 */
1324 const_eio (SEEK_SET) 1405 const_eio (SEEK_SET)
1325 const_eio (SEEK_CUR) 1406 const_eio (SEEK_CUR)
1326 const_eio (SEEK_END) 1407 const_eio (SEEK_END)
1327 1408
2484 RETVAL = 0; 2565 RETVAL = 0;
2485#endif 2566#endif
2486 OUTPUT: 2567 OUTPUT:
2487 RETVAL 2568 RETVAL
2488 2569
2489int 2570void
2571accept4 (aio_rfd rfh, SV *sockaddr, int salen, int flags)
2572 PPCODE:
2573{
2574 SV *retval;
2575#if HAVE_ACCEPT4
2576 socklen_t salen_ = salen ? salen + 1 : 0;
2577
2578 if (salen)
2579 {
2580 sv_upgrade (sockaddr, SVt_PV);
2581 sv_grow (sockaddr, salen_);
2582 }
2583
2584 int res = accept4 (rfh, salen ? (struct sockaddr *)SvPVX (sockaddr) : 0, salen ? &salen_ : 0, flags);
2585
2586 retval = newmortalFH (res, O_RDWR);
2587
2588 if (res >= 0 && salen > 0)
2589 {
2590 if (salen_ > salen + 1)
2591 salen_ = salen + 1;
2592
2593 SvPOK_only (sockaddr);
2594 SvCUR_set (sockaddr, salen_);
2595 }
2596#else
2597 errno = ENOSYS;
2598 retval = &PL_sv_undef;
2599#endif
2600 XPUSHs (retval);
2601}
2602
2603ssize_t
2490splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) 2604splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
2491 CODE: 2605 CODE:
2492{ 2606{
2493#if HAVE_LINUX_SPLICE 2607#if HAVE_LINUX_SPLICE
2494 loff_t off_in_, off_out_; 2608 loff_t off_in_, off_out_;
2502#endif 2616#endif
2503} 2617}
2504 OUTPUT: 2618 OUTPUT:
2505 RETVAL 2619 RETVAL
2506 2620
2507int 2621ssize_t
2508tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) 2622tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
2509 CODE: 2623 CODE:
2510#if HAVE_LINUX_SPLICE 2624#if HAVE_LINUX_SPLICE
2511 RETVAL = tee (rfh, wfh, length, flags); 2625 RETVAL = tee (rfh, wfh, length, flags);
2512#else 2626#else
2555 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2669 PUSHs (newmortalFH (fd[1], O_WRONLY));
2556 } 2670 }
2557} 2671}
2558 2672
2559void 2673void
2674pidfd_open (int pid, unsigned int flags = 0)
2675 PPCODE:
2676{
2677 /*GENDEF0_SYSCALL(pidfd_open,434)*/
2678 int fd = syscall (SYS_pidfd_open, pid, flags);
2679 XPUSHs (newmortalFH (fd, O_RDWR));
2680}
2681
2682int
2683pidfd_send_signal (SV *pidfh, int sig, SV *siginfo = &PL_sv_undef, unsigned int flags = 0)
2684 PPCODE:
2685{
2686 #if HAVE_SIGINFO_T
2687 int res;
2688 siginfo_t si = { 0 };
2689
2690 if (SvOK (siginfo))
2691 {
2692 HV *hv;
2693 SV **svp;
2694
2695 if (!SvROK (siginfo) || SvTYPE (SvRV (siginfo)) != SVt_PVHV)
2696 croak ("siginfo argument must be a hashref code, pid, uid and value_int or value_ptr members, caught");
2697
2698 hv = (HV *)SvRV (siginfo);
2699
2700 if ((svp = hv_fetchs (hv, "code" , 0))) si.si_code = SvIV (*svp);
2701 if ((svp = hv_fetchs (hv, "pid" , 0))) si.si_pid = SvIV (*svp);
2702 if ((svp = hv_fetchs (hv, "uid" , 0))) si.si_uid = SvIV (*svp);
2703 if ((svp = hv_fetchs (hv, "value_int", 0))) si.si_value.sival_int = SvIV (*svp);
2704 if ((svp = hv_fetchs (hv, "value_ptr", 0))) si.si_value.sival_ptr = (void *)SvIV (*svp);
2705 }
2706
2707 /*GENDEF0_SYSCALL(pidfd_send_signal,424)*/
2708 res = syscall (SYS_pidfd_send_signal, s_fileno_croak (pidfh, 0), sig, SvOK (siginfo) ? &si : 0, flags);
2709 #else
2710 res = (errno = ENOSYS, -1);
2711 #endif
2712
2713 XPUSHs (sv_2mortal (newSViv (res)));
2714}
2715
2716void
2717pidfd_getfd (SV *pidfh, int targetfd, unsigned int flags = 0)
2718 PPCODE:
2719{
2720 /*GENDEF0_SYSCALL(pidfd_getfd,438)*/
2721 int fd = syscall (SYS_pidfd_getfd, s_fileno_croak (pidfh, 0), targetfd, flags);
2722 XPUSHs (newmortalFH (fd, O_RDWR));
2723}
2724
2725void
2560eventfd (unsigned int initval = 0, int flags = 0) 2726eventfd (unsigned int initval = 0, int flags = 0)
2561 PPCODE: 2727 PPCODE:
2562{ 2728{
2563 int fd; 2729 int fd;
2564#if HAVE_EVENTFD 2730#if HAVE_EVENTFD
2627#else 2793#else
2628 errno = ENOSYS; 2794 errno = ENOSYS;
2629#endif 2795#endif
2630} 2796}
2631 2797
2798void
2799memfd_create (SV8 *pathname, int flags = 0)
2800 PPCODE:
2801{
2802 int fd;
2803#if HAVE_MEMFD_CREATE
2804 fd = memfd_create (SvPVbyte_nolen (pathname), flags);
2805#else
2806 fd = (errno = ENOSYS, -1);
2807#endif
2808
2809 XPUSHs (newmortalFH (fd, O_RDWR));
2810}
2811
2632UV 2812UV
2633get_fdlimit () 2813get_fdlimit ()
2634 CODE: 2814 CODE:
2635#if HAVE_RLIMITS 2815#if HAVE_RLIMITS
2636 struct rlimit rl; 2816 struct rlimit rl;
2669 if (0 == setrlimit (RLIMIT_NOFILE, &rl)) 2849 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2670 XSRETURN_YES; 2850 XSRETURN_YES;
2671 2851
2672 if (errno == EPERM) 2852 if (errno == EPERM)
2673 { 2853 {
2674 /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ 2854 /* setrlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */
2675 /* our limit overflows a system-wide limit */ 2855 /* our limit overflows a system-wide limit */
2676 /* try an adaptive algorithm, but do not lower the hardlimit */ 2856 /* try an adaptive algorithm, but do not lower the hardlimit */
2677 rl.rlim_max = 0; 2857 rl.rlim_max = 0;
2678 for (bit = 0x40000000U; bit; bit >>= 1) 2858 for (bit = 0x40000000U; bit; bit >>= 1)
2679 { 2859 {
2680 rl.rlim_max |= bit; 2860 rl.rlim_max |= bit;
2681 rl.rlim_cur = rl.rlim_max; 2861 rl.rlim_cur = rl.rlim_max;
2682 2862
2683 /* nevr decrease the hard limit */ 2863 /* never decrease the hard limit */
2684 if (rl.rlim_max < orig_rlim_max) 2864 if (rl.rlim_max < orig_rlim_max)
2685 break; 2865 break;
2686 2866
2687 if (0 != setrlimit (RLIMIT_NOFILE, &rl)) 2867 if (0 != setrlimit (RLIMIT_NOFILE, &rl))
2688 rl.rlim_max &= ~bit; /* too high, remove bit again */ 2868 rl.rlim_max &= ~bit; /* too high, remove bit again */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines