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.295 by root, Mon Sep 5 00:03:32 2022 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 }
1081 return ts->tv_sec + ts->tv_nsec * 1e-9; 1093 return ts->tv_sec + ts->tv_nsec * 1e-9;
1082} 1094}
1083 1095
1084/*****************************************************************************/ 1096/*****************************************************************************/
1085 1097
1098/* extract a ref-to-array of strings into a temporary c style string vector */
1099static char **
1100extract_stringvec (SV *sv, const char *croakmsg)
1101{
1102 if (!SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
1103 croak (croakmsg);
1104
1105 AV *av = (AV *)SvRV (sv);
1106 int i, nelem = av_len (av) + 1;
1107 char **vecp = (char **)SvPVX (sv_2mortal (newSV (sizeof (char *) * (nelem + 1))));
1108
1109 for (i = 0; i < nelem; ++i)
1110 {
1111 SV **e = av_fetch (av, i, 0);
1112
1113 if (e && *e)
1114 vecp[i] = SvPVbyte_nolen (*e);
1115 else
1116 vecp[i] = "";
1117 }
1118
1119 vecp[nelem] = 0;
1120
1121 return vecp;
1122}
1123
1124/*****************************************************************************/
1125
1086XS(boot_IO__AIO) ecb_cold; 1126XS(boot_IO__AIO) ecb_cold;
1087 1127
1088MODULE = IO::AIO PACKAGE = IO::AIO 1128MODULE = IO::AIO PACKAGE = IO::AIO
1089 1129
1090PROTOTYPES: ENABLE 1130PROTOTYPES: ENABLE
1191 const_iv (MAP_NONBLOCK) 1231 const_iv (MAP_NONBLOCK)
1192 const_iv (MAP_GROWSDOWN) 1232 const_iv (MAP_GROWSDOWN)
1193 const_iv (MAP_32BIT) 1233 const_iv (MAP_32BIT)
1194 const_iv (MAP_HUGETLB) 1234 const_iv (MAP_HUGETLB)
1195 const_iv (MAP_STACK) 1235 const_iv (MAP_STACK)
1236 const_iv (MAP_FIXED_NOREPLACE)
1237 const_iv (MAP_SHARED_VALIDATE)
1238 const_iv (MAP_SYNC)
1239 const_iv (MAP_UNINITIALIZED)
1196 1240
1197 const_iv (MREMAP_MAYMOVE) 1241 const_iv (MREMAP_MAYMOVE)
1198 const_iv (MREMAP_FIXED) 1242 const_iv (MREMAP_FIXED)
1199 1243
1200 const_iv (F_DUPFD_CLOEXEC)
1201
1202 const_iv (MSG_CMSG_CLOEXEC) 1244 const_iv (MSG_CMSG_CLOEXEC)
1203 const_iv (SOCK_CLOEXEC) 1245 const_iv (SOCK_CLOEXEC)
1246
1247 const_iv (F_DUPFD_CLOEXEC)
1248
1249 const_iv (F_ADD_SEALS)
1250 const_iv (F_GET_SEALS)
1251 const_iv (F_SEAL_SEAL)
1252 const_iv (F_SEAL_SHRINK)
1253 const_iv (F_SEAL_GROW)
1254 const_iv (F_SEAL_WRITE)
1204 1255
1205 const_iv (F_OFD_GETLK) 1256 const_iv (F_OFD_GETLK)
1206 const_iv (F_OFD_SETLK) 1257 const_iv (F_OFD_SETLK)
1207 const_iv (F_OFD_GETLKW) 1258 const_iv (F_OFD_GETLKW)
1208 1259
1288 const_iv (EFD_SEMAPHORE) 1339 const_iv (EFD_SEMAPHORE)
1289 1340
1290 const_iv (MFD_CLOEXEC) 1341 const_iv (MFD_CLOEXEC)
1291 const_iv (MFD_ALLOW_SEALING) 1342 const_iv (MFD_ALLOW_SEALING)
1292 const_iv (MFD_HUGETLB) 1343 const_iv (MFD_HUGETLB)
1344 const_iv (MFD_HUGETLB_2MB)
1345 const_iv (MFD_HUGETLB_1GB)
1293 1346
1294 const_iv (CLOCK_REALTIME) 1347 const_iv (CLOCK_REALTIME)
1295 const_iv (CLOCK_MONOTONIC) 1348 const_iv (CLOCK_MONOTONIC)
1296 const_iv (CLOCK_BOOTTIME) 1349 const_iv (CLOCK_BOOTTIME)
1297 const_iv (CLOCK_REALTIME_ALARM) 1350 const_iv (CLOCK_REALTIME_ALARM)
1322 const_iv (STATX_ATTR_APPEND) 1375 const_iv (STATX_ATTR_APPEND)
1323 const_iv (STATX_ATTR_NODUMP) 1376 const_iv (STATX_ATTR_NODUMP)
1324 const_iv (STATX_ATTR_ENCRYPTED) 1377 const_iv (STATX_ATTR_ENCRYPTED)
1325 const_iv (STATX_ATTR_AUTOMOUNT) 1378 const_iv (STATX_ATTR_AUTOMOUNT)
1326 1379
1380 const_iv (AT_FDCWD)
1381 const_iv (AT_SYMLINK_NOFOLLOW)
1382 const_iv (AT_EACCESS)
1383 const_iv (AT_REMOVEDIR)
1384 const_iv (AT_SYMLINK_FOLLOW)
1385 const_iv (AT_NO_AUTOMOUNT)
1386 const_iv (AT_EMPTY_PATH)
1387 const_iv (AT_STATX_SYNC_TYPE)
1388 const_iv (AT_STATX_AS_STAT)
1389 const_iv (AT_STATX_FORCE_SYNC)
1390 const_iv (AT_STATX_DONT_SYNC)
1391 const_iv (AT_RECURSIVE)
1392
1393 const_iv (OPEN_TREE_CLONE)
1394
1395 const_iv (FSOPEN_CLOEXEC)
1396
1397 const_iv (FSPICK_CLOEXEC)
1398 const_iv (FSPICK_SYMLINK_NOFOLLOW)
1399 const_iv (FSPICK_NO_AUTOMOUNT)
1400 const_iv (FSPICK_EMPTY_PATH)
1401
1402 const_iv (MOVE_MOUNT_F_SYMLINKS)
1403 const_iv (MOVE_MOUNT_F_AUTOMOUNTS)
1404 const_iv (MOVE_MOUNT_F_EMPTY_PATH)
1405 const_iv (MOVE_MOUNT_T_SYMLINKS)
1406 const_iv (MOVE_MOUNT_T_AUTOMOUNTS)
1407 const_iv (MOVE_MOUNT_T_EMPTY_PATH)
1408
1409 /* waitid */
1410 const_iv (P_PID)
1411 const_iv (P_PIDFD)
1412 const_iv (P_PGID)
1413 const_iv (P_ALL)
1414
1415 const_iv (FSCONFIG_SET_FLAG)
1416 const_iv (FSCONFIG_SET_STRING)
1417 const_iv (FSCONFIG_SET_BINARY)
1418 const_iv (FSCONFIG_SET_PATH)
1419 const_iv (FSCONFIG_SET_PATH_EMPTY)
1420 const_iv (FSCONFIG_SET_FD)
1421 const_iv (FSCONFIG_CMD_CREATE)
1422 const_iv (FSCONFIG_CMD_RECONFIGURE)
1423
1424 const_iv (MOUNT_ATTR_RDONLY)
1425 const_iv (MOUNT_ATTR_NOSUID)
1426 const_iv (MOUNT_ATTR_NODEV)
1427 const_iv (MOUNT_ATTR_NOEXEC)
1428 const_iv (MOUNT_ATTR__ATIME)
1429 const_iv (MOUNT_ATTR_RELATIME)
1430 const_iv (MOUNT_ATTR_NOATIME)
1431 const_iv (MOUNT_ATTR_STRICTATIME)
1432 const_iv (MOUNT_ATTR_NODIRATIME)
1433
1327 /* these are libeio constants, and are independent of gendef0 */ 1434 /* these are libeio constants, and are independent of gendef0 */
1328 const_eio (SEEK_SET) 1435 const_eio (SEEK_SET)
1329 const_eio (SEEK_CUR) 1436 const_eio (SEEK_CUR)
1330 const_eio (SEEK_END) 1437 const_eio (SEEK_END)
1331 1438
2488 RETVAL = 0; 2595 RETVAL = 0;
2489#endif 2596#endif
2490 OUTPUT: 2597 OUTPUT:
2491 RETVAL 2598 RETVAL
2492 2599
2493int 2600void
2601accept4 (aio_rfd rfh, SV *sockaddr, int salen, int flags)
2602 PPCODE:
2603{
2604 SV *retval;
2605#if HAVE_ACCEPT4
2606 socklen_t salen_ = salen ? salen + 1 : 0;
2607
2608 if (salen)
2609 {
2610 sv_upgrade (sockaddr, SVt_PV);
2611 sv_grow (sockaddr, salen_);
2612 }
2613
2614 int res = accept4 (rfh, salen ? (struct sockaddr *)SvPVX (sockaddr) : 0, salen ? &salen_ : 0, flags);
2615
2616 retval = newmortalFH (res, O_RDWR);
2617
2618 if (res >= 0 && salen > 0)
2619 {
2620 if (salen_ > salen + 1)
2621 salen_ = salen + 1;
2622
2623 SvPOK_only (sockaddr);
2624 SvCUR_set (sockaddr, salen_);
2625 }
2626#else
2627 errno = ENOSYS;
2628 retval = &PL_sv_undef;
2629#endif
2630 XPUSHs (retval);
2631}
2632
2633ssize_t
2494splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) 2634splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags)
2495 CODE: 2635 CODE:
2496{ 2636{
2497#if HAVE_LINUX_SPLICE 2637#if HAVE_LINUX_SPLICE
2498 loff_t off_in_, off_out_; 2638 loff_t off_in_, off_out_;
2506#endif 2646#endif
2507} 2647}
2508 OUTPUT: 2648 OUTPUT:
2509 RETVAL 2649 RETVAL
2510 2650
2511int 2651ssize_t
2512tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) 2652tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags)
2513 CODE: 2653 CODE:
2514#if HAVE_LINUX_SPLICE 2654#if HAVE_LINUX_SPLICE
2515 RETVAL = tee (rfh, wfh, length, flags); 2655 RETVAL = tee (rfh, wfh, length, flags);
2516#else 2656#else
2559 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2699 PUSHs (newmortalFH (fd[1], O_WRONLY));
2560 } 2700 }
2561} 2701}
2562 2702
2563void 2703void
2704pidfd_open (int pid, unsigned int flags = 0)
2705 PPCODE:
2706{
2707 /*GENDEF0_SYSCALL(pidfd_open,434)*/
2708 int fd = syscall (SYS_pidfd_open, pid, flags);
2709 XPUSHs (newmortalFH (fd, O_RDWR));
2710}
2711
2712int
2713pidfd_send_signal (SV *pidfh, int sig, SV *siginfo = &PL_sv_undef, unsigned int flags = 0)
2714 PPCODE:
2715{
2716 int res;
2717#if HAVE_SIGINFO_T
2718 siginfo_t si = { 0 };
2719
2720 if (SvOK (siginfo))
2721 {
2722 HV *hv;
2723 SV **svp;
2724
2725 if (!SvROK (siginfo) || SvTYPE (SvRV (siginfo)) != SVt_PVHV)
2726 croak ("siginfo argument must be a hashref with 'code', 'pid', 'uid' and 'value_int' or 'value_ptr' members, caught");
2727
2728 hv = (HV *)SvRV (siginfo);
2729
2730 if ((svp = hv_fetchs (hv, "code" , 0))) si.si_code = SvIV (*svp);
2731 if ((svp = hv_fetchs (hv, "pid" , 0))) si.si_pid = SvIV (*svp);
2732 if ((svp = hv_fetchs (hv, "uid" , 0))) si.si_uid = SvIV (*svp);
2733 if ((svp = hv_fetchs (hv, "value_int", 0))) si.si_value.sival_int = SvIV (*svp);
2734 if ((svp = hv_fetchs (hv, "value_ptr", 0))) si.si_value.sival_ptr = (void *)SvIV (*svp);
2735 }
2736
2737 /*GENDEF0_SYSCALL(pidfd_send_signal,424)*/
2738 res = syscall (SYS_pidfd_send_signal, s_fileno_croak (pidfh, 0), sig, SvOK (siginfo) ? &si : 0, flags);
2739#else
2740 res = (errno = ENOSYS, -1);
2741#endif
2742
2743 XPUSHs (sv_2mortal (newSViv (res)));
2744}
2745
2746void
2747pidfd_getfd (SV *pidfh, int targetfd, unsigned int flags = 0)
2748 PPCODE:
2749{
2750 /*GENDEF0_SYSCALL(pidfd_getfd,438)*/
2751 int fd = syscall (SYS_pidfd_getfd, s_fileno_croak (pidfh, 0), targetfd, flags);
2752 XPUSHs (newmortalFH (fd, O_RDWR));
2753}
2754
2755void
2564eventfd (unsigned int initval = 0, int flags = 0) 2756eventfd (unsigned int initval = 0, int flags = 0)
2565 PPCODE: 2757 PPCODE:
2566{ 2758{
2567 int fd; 2759 int fd;
2568#if HAVE_EVENTFD 2760#if HAVE_EVENTFD
2645#endif 2837#endif
2646 2838
2647 XPUSHs (newmortalFH (fd, O_RDWR)); 2839 XPUSHs (newmortalFH (fd, O_RDWR));
2648} 2840}
2649 2841
2842int
2843fexecve (SV *fh, SV *args, SV *envs = &PL_sv_undef)
2844 CODE:
2845{
2846 int fd = PerlIO_fileno (IoIFP (sv_2io (fh)));
2847 char **envp, **argv;
2848 argv = extract_stringvec (args, "IO::AIO::fexecve: args must be an array of strings");
2849 if (!SvOK (envs))
2850 {
2851 extern char **environ;
2852 envp = environ;
2853 }
2854 else
2855 envp = extract_stringvec (envs, "IO::AIO::fexecve: envs must be an array of strings");
2856#if _POSIX_VERSION >= 200809L
2857 RETVAL = fexecve (fd, argv, envp);
2858#else
2859 RETVAL = (errno = ENOSYS, -1);
2860#endif
2861}
2862 OUTPUT: RETVAL
2863
2650UV 2864UV
2651get_fdlimit () 2865get_fdlimit ()
2652 CODE: 2866 CODE:
2653#if HAVE_RLIMITS 2867#if HAVE_RLIMITS
2654 struct rlimit rl; 2868 struct rlimit rl;
2687 if (0 == setrlimit (RLIMIT_NOFILE, &rl)) 2901 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2688 XSRETURN_YES; 2902 XSRETURN_YES;
2689 2903
2690 if (errno == EPERM) 2904 if (errno == EPERM)
2691 { 2905 {
2692 /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ 2906 /* setrlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */
2693 /* our limit overflows a system-wide limit */ 2907 /* our limit overflows a system-wide limit */
2694 /* try an adaptive algorithm, but do not lower the hardlimit */ 2908 /* try an adaptive algorithm, but do not lower the hardlimit */
2695 rl.rlim_max = 0; 2909 rl.rlim_max = 0;
2696 for (bit = 0x40000000U; bit; bit >>= 1) 2910 for (bit = 0x40000000U; bit; bit >>= 1)
2697 { 2911 {
2698 rl.rlim_max |= bit; 2912 rl.rlim_max |= bit;
2699 rl.rlim_cur = rl.rlim_max; 2913 rl.rlim_cur = rl.rlim_max;
2700 2914
2701 /* nevr decrease the hard limit */ 2915 /* never decrease the hard limit */
2702 if (rl.rlim_max < orig_rlim_max) 2916 if (rl.rlim_max < orig_rlim_max)
2703 break; 2917 break;
2704 2918
2705 if (0 != setrlimit (RLIMIT_NOFILE, &rl)) 2919 if (0 != setrlimit (RLIMIT_NOFILE, &rl))
2706 rl.rlim_max &= ~bit; /* too high, remove bit again */ 2920 rl.rlim_max &= ~bit; /* too high, remove bit again */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines