… | |
… | |
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 | #if HAVE_SYSCALL |
|
|
233 | #include <sys/syscall.h> |
|
|
234 | #else |
|
|
235 | # define syscall(nr,...) (errno = ENOSYS, -1) |
|
|
236 | #endif |
|
|
237 | |
231 | /*****************************************************************************/ |
238 | /*****************************************************************************/ |
232 | |
239 | |
233 | #if !_POSIX_MAPPED_FILES |
240 | #if !_POSIX_MAPPED_FILES |
234 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) |
241 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, (void *)-1) |
235 | # define munmap(addr,length) EIO_ENOSYS () |
242 | # define munmap(addr,length) EIO_ENOSYS () |
… | |
… | |
344 | int count = req->int3; |
351 | int count = req->int3; |
345 | |
352 | |
346 | req->flags |= EIO_FLAG_PTR1_FREE; |
353 | req->flags |= EIO_FLAG_PTR1_FREE; |
347 | |
354 | |
348 | /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ |
355 | /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ |
349 | /* increase in 3.5kb steps */ |
356 | /* increase in fixed steps */ |
350 | if (count < 0) |
357 | if (count < 0) |
351 | count = 8; |
358 | count = 8; |
352 | |
359 | |
353 | fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
360 | fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
354 | errno = ENOMEM; |
361 | errno = ENOMEM; |
… | |
… | |
407 | |
414 | |
408 | for (count = 0; count < incmap->fm_mapped_extents; ++count) |
415 | for (count = 0; count < incmap->fm_mapped_extents; ++count) |
409 | { |
416 | { |
410 | struct fiemap_extent *e = incmap->fm_extents + count; |
417 | struct fiemap_extent *e = incmap->fm_extents + count; |
411 | |
418 | |
|
|
419 | fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e; |
|
|
420 | |
412 | if (e->fe_logical + e->fe_length >= end_offset) |
421 | if (e->fe_logical >= end_offset) |
413 | goto done; |
422 | goto done; |
414 | |
|
|
415 | fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e; |
|
|
416 | |
423 | |
417 | if (e->fe_flags & FIEMAP_EXTENT_LAST) |
424 | if (e->fe_flags & FIEMAP_EXTENT_LAST) |
418 | goto done; |
425 | goto done; |
419 | |
426 | |
420 | } |
427 | } |
… | |
… | |
1195 | const_iv (MAP_STACK) |
1202 | const_iv (MAP_STACK) |
1196 | |
1203 | |
1197 | const_iv (MREMAP_MAYMOVE) |
1204 | const_iv (MREMAP_MAYMOVE) |
1198 | const_iv (MREMAP_FIXED) |
1205 | const_iv (MREMAP_FIXED) |
1199 | |
1206 | |
1200 | const_iv (F_DUPFD_CLOEXEC) |
|
|
1201 | |
|
|
1202 | const_iv (MSG_CMSG_CLOEXEC) |
1207 | const_iv (MSG_CMSG_CLOEXEC) |
1203 | const_iv (SOCK_CLOEXEC) |
1208 | const_iv (SOCK_CLOEXEC) |
|
|
1209 | |
|
|
1210 | const_iv (F_DUPFD_CLOEXEC) |
|
|
1211 | |
|
|
1212 | const_iv (F_ADD_SEALS) |
|
|
1213 | const_iv (F_GET_SEALS) |
|
|
1214 | const_iv (F_SEAL_SEAL) |
|
|
1215 | const_iv (F_SEAL_SHRINK) |
|
|
1216 | const_iv (F_SEAL_GROW) |
|
|
1217 | const_iv (F_SEAL_WRITE) |
1204 | |
1218 | |
1205 | const_iv (F_OFD_GETLK) |
1219 | const_iv (F_OFD_GETLK) |
1206 | const_iv (F_OFD_SETLK) |
1220 | const_iv (F_OFD_SETLK) |
1207 | const_iv (F_OFD_GETLKW) |
1221 | const_iv (F_OFD_GETLKW) |
1208 | |
1222 | |
… | |
… | |
1284 | const_iv (SPLICE_F_GIFT) |
1298 | const_iv (SPLICE_F_GIFT) |
1285 | |
1299 | |
1286 | const_iv (EFD_CLOEXEC) |
1300 | const_iv (EFD_CLOEXEC) |
1287 | const_iv (EFD_NONBLOCK) |
1301 | const_iv (EFD_NONBLOCK) |
1288 | const_iv (EFD_SEMAPHORE) |
1302 | const_iv (EFD_SEMAPHORE) |
|
|
1303 | |
|
|
1304 | const_iv (MFD_CLOEXEC) |
|
|
1305 | const_iv (MFD_ALLOW_SEALING) |
|
|
1306 | const_iv (MFD_HUGETLB) |
1289 | |
1307 | |
1290 | const_iv (CLOCK_REALTIME) |
1308 | const_iv (CLOCK_REALTIME) |
1291 | const_iv (CLOCK_MONOTONIC) |
1309 | const_iv (CLOCK_MONOTONIC) |
1292 | const_iv (CLOCK_BOOTTIME) |
1310 | const_iv (CLOCK_BOOTTIME) |
1293 | const_iv (CLOCK_REALTIME_ALARM) |
1311 | const_iv (CLOCK_REALTIME_ALARM) |
… | |
… | |
1318 | const_iv (STATX_ATTR_APPEND) |
1336 | const_iv (STATX_ATTR_APPEND) |
1319 | const_iv (STATX_ATTR_NODUMP) |
1337 | const_iv (STATX_ATTR_NODUMP) |
1320 | const_iv (STATX_ATTR_ENCRYPTED) |
1338 | const_iv (STATX_ATTR_ENCRYPTED) |
1321 | const_iv (STATX_ATTR_AUTOMOUNT) |
1339 | const_iv (STATX_ATTR_AUTOMOUNT) |
1322 | |
1340 | |
|
|
1341 | const_iv (AT_FDCWD) |
|
|
1342 | const_iv (AT_SYMLINK_NOFOLLOW) |
|
|
1343 | const_iv (AT_EACCESS) |
|
|
1344 | const_iv (AT_REMOVEDIR) |
|
|
1345 | const_iv (AT_SYMLINK_FOLLOW) |
|
|
1346 | const_iv (AT_NO_AUTOMOUNT) |
|
|
1347 | const_iv (AT_EMPTY_PATH) |
|
|
1348 | const_iv (AT_STATX_SYNC_TYPE) |
|
|
1349 | const_iv (AT_STATX_AS_STAT) |
|
|
1350 | const_iv (AT_STATX_FORCE_SYNC) |
|
|
1351 | const_iv (AT_STATX_DONT_SYNC) |
|
|
1352 | const_iv (AT_RECURSIVE) |
|
|
1353 | |
|
|
1354 | const_iv (OPEN_TREE_CLONE) |
|
|
1355 | |
|
|
1356 | const_iv (FSOPEN_CLOEXEC) |
|
|
1357 | |
|
|
1358 | const_iv (FSPICK_CLOEXEC) |
|
|
1359 | const_iv (FSPICK_SYMLINK_NOFOLLOW) |
|
|
1360 | const_iv (FSPICK_NO_AUTOMOUNT) |
|
|
1361 | const_iv (FSPICK_EMPTY_PATH) |
|
|
1362 | |
|
|
1363 | const_iv (MOVE_MOUNT_F_SYMLINKS) |
|
|
1364 | const_iv (MOVE_MOUNT_F_AUTOMOUNTS) |
|
|
1365 | const_iv (MOVE_MOUNT_F_EMPTY_PATH) |
|
|
1366 | const_iv (MOVE_MOUNT_T_SYMLINKS) |
|
|
1367 | const_iv (MOVE_MOUNT_T_AUTOMOUNTS) |
|
|
1368 | const_iv (MOVE_MOUNT_T_EMPTY_PATH) |
|
|
1369 | |
|
|
1370 | /* waitid */ |
|
|
1371 | const_iv (P_PID) |
|
|
1372 | const_iv (P_PIDFD) |
|
|
1373 | const_iv (P_PGID) |
|
|
1374 | const_iv (P_ALL) |
|
|
1375 | |
|
|
1376 | const_iv (FSCONFIG_SET_FLAG) |
|
|
1377 | const_iv (FSCONFIG_SET_STRING) |
|
|
1378 | const_iv (FSCONFIG_SET_BINARY) |
|
|
1379 | const_iv (FSCONFIG_SET_PATH) |
|
|
1380 | const_iv (FSCONFIG_SET_PATH_EMPTY) |
|
|
1381 | const_iv (FSCONFIG_SET_FD) |
|
|
1382 | const_iv (FSCONFIG_CMD_CREATE) |
|
|
1383 | const_iv (FSCONFIG_CMD_RECONFIGURE) |
|
|
1384 | |
|
|
1385 | const_iv (MOUNT_ATTR_RDONLY) |
|
|
1386 | const_iv (MOUNT_ATTR_NOSUID) |
|
|
1387 | const_iv (MOUNT_ATTR_NODEV) |
|
|
1388 | const_iv (MOUNT_ATTR_NOEXEC) |
|
|
1389 | const_iv (MOUNT_ATTR__ATIME) |
|
|
1390 | const_iv (MOUNT_ATTR_RELATIME) |
|
|
1391 | const_iv (MOUNT_ATTR_NOATIME) |
|
|
1392 | const_iv (MOUNT_ATTR_STRICTATIME) |
|
|
1393 | const_iv (MOUNT_ATTR_NODIRATIME) |
|
|
1394 | |
1323 | /* these are libeio constants, and are independent of gendef0 */ |
1395 | /* these are libeio constants, and are independent of gendef0 */ |
1324 | const_eio (SEEK_SET) |
1396 | const_eio (SEEK_SET) |
1325 | const_eio (SEEK_CUR) |
1397 | const_eio (SEEK_CUR) |
1326 | const_eio (SEEK_END) |
1398 | const_eio (SEEK_END) |
1327 | |
1399 | |
… | |
… | |
2484 | RETVAL = 0; |
2556 | RETVAL = 0; |
2485 | #endif |
2557 | #endif |
2486 | OUTPUT: |
2558 | OUTPUT: |
2487 | RETVAL |
2559 | RETVAL |
2488 | |
2560 | |
2489 | int |
2561 | void |
|
|
2562 | accept4 (aio_rfd rfh, SV *sockaddr, int salen, int flags) |
|
|
2563 | PPCODE: |
|
|
2564 | { |
|
|
2565 | SV *retval; |
|
|
2566 | #if HAVE_ACCEPT4 |
|
|
2567 | socklen_t salen_ = salen ? salen + 1 : 0; |
|
|
2568 | |
|
|
2569 | if (salen) |
|
|
2570 | { |
|
|
2571 | sv_upgrade (sockaddr, SVt_PV); |
|
|
2572 | sv_grow (sockaddr, salen_); |
|
|
2573 | } |
|
|
2574 | |
|
|
2575 | int res = accept4 (rfh, salen ? (struct sockaddr *)SvPVX (sockaddr) : 0, salen ? &salen_ : 0, flags); |
|
|
2576 | |
|
|
2577 | retval = newmortalFH (res, O_RDWR); |
|
|
2578 | |
|
|
2579 | if (res >= 0 && salen > 0) |
|
|
2580 | { |
|
|
2581 | if (salen_ > salen + 1) |
|
|
2582 | salen_ = salen + 1; |
|
|
2583 | |
|
|
2584 | SvPOK_only (sockaddr); |
|
|
2585 | SvCUR_set (sockaddr, salen_); |
|
|
2586 | } |
|
|
2587 | #else |
|
|
2588 | errno = ENOSYS; |
|
|
2589 | retval = &PL_sv_undef; |
|
|
2590 | #endif |
|
|
2591 | XPUSHs (retval); |
|
|
2592 | } |
|
|
2593 | |
|
|
2594 | ssize_t |
2490 | splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) |
2595 | splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) |
2491 | CODE: |
2596 | CODE: |
2492 | { |
2597 | { |
2493 | #if HAVE_LINUX_SPLICE |
2598 | #if HAVE_LINUX_SPLICE |
2494 | loff_t off_in_, off_out_; |
2599 | loff_t off_in_, off_out_; |
… | |
… | |
2502 | #endif |
2607 | #endif |
2503 | } |
2608 | } |
2504 | OUTPUT: |
2609 | OUTPUT: |
2505 | RETVAL |
2610 | RETVAL |
2506 | |
2611 | |
2507 | int |
2612 | ssize_t |
2508 | tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) |
2613 | tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) |
2509 | CODE: |
2614 | CODE: |
2510 | #if HAVE_LINUX_SPLICE |
2615 | #if HAVE_LINUX_SPLICE |
2511 | RETVAL = tee (rfh, wfh, length, flags); |
2616 | RETVAL = tee (rfh, wfh, length, flags); |
2512 | #else |
2617 | #else |
… | |
… | |
2555 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2660 | PUSHs (newmortalFH (fd[1], O_WRONLY)); |
2556 | } |
2661 | } |
2557 | } |
2662 | } |
2558 | |
2663 | |
2559 | void |
2664 | void |
|
|
2665 | pidfd_open (int pid, unsigned int flags = 0) |
|
|
2666 | PPCODE: |
|
|
2667 | { |
|
|
2668 | /*GENDEF0_SYSCALL(pidfd_open,434)*/ |
|
|
2669 | int fd = syscall (SYS_pidfd_open, pid, flags); |
|
|
2670 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2671 | } |
|
|
2672 | |
|
|
2673 | int |
|
|
2674 | pidfd_send_signal (SV *pidfh, int sig, SV *siginfo = &PL_sv_undef, unsigned int flags = 0) |
|
|
2675 | PPCODE: |
|
|
2676 | { |
|
|
2677 | int res; |
|
|
2678 | siginfo_t si = { 0 }; |
|
|
2679 | |
|
|
2680 | if (SvOK (siginfo)) |
|
|
2681 | { |
|
|
2682 | HV *hv; |
|
|
2683 | SV **svp; |
|
|
2684 | |
|
|
2685 | if (!SvROK (siginfo) || SvTYPE (SvRV (siginfo)) != SVt_PVHV) |
|
|
2686 | croak ("siginfo argument must be a hashref code, pid, uid and value_int or value_ptr members, caught"); |
|
|
2687 | |
|
|
2688 | hv = (HV *)SvRV (siginfo); |
|
|
2689 | |
|
|
2690 | if ((svp = hv_fetchs (hv, "code" , 0))) si.si_code = SvIV (*svp); |
|
|
2691 | if ((svp = hv_fetchs (hv, "pid" , 0))) si.si_pid = SvIV (*svp); |
|
|
2692 | if ((svp = hv_fetchs (hv, "uid" , 0))) si.si_uid = SvIV (*svp); |
|
|
2693 | if ((svp = hv_fetchs (hv, "value_int", 0))) si.si_value.sival_int = SvIV (*svp); |
|
|
2694 | if ((svp = hv_fetchs (hv, "value_ptr", 0))) si.si_value.sival_ptr = (void *)SvIV (*svp); |
|
|
2695 | } |
|
|
2696 | |
|
|
2697 | /*GENDEF0_SYSCALL(pidfd_send_signal,424)*/ |
|
|
2698 | res = syscall (SYS_pidfd_send_signal, s_fileno_croak (pidfh, 0), sig, SvOK (siginfo) ? &si : 0, flags); |
|
|
2699 | |
|
|
2700 | XPUSHs (sv_2mortal (newSViv (res))); |
|
|
2701 | } |
|
|
2702 | |
|
|
2703 | void |
|
|
2704 | pidfd_getfd (SV *pidfh, int targetfd, unsigned int flags = 0) |
|
|
2705 | PPCODE: |
|
|
2706 | { |
|
|
2707 | /*GENDEF0_SYSCALL(pidfd_getfd,438)*/ |
|
|
2708 | int fd = syscall (SYS_pidfd_getfd, s_fileno_croak (pidfh, 0), targetfd, flags); |
|
|
2709 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2710 | } |
|
|
2711 | |
|
|
2712 | void |
2560 | eventfd (unsigned int initval = 0, int flags = 0) |
2713 | eventfd (unsigned int initval = 0, int flags = 0) |
2561 | PPCODE: |
2714 | PPCODE: |
2562 | { |
2715 | { |
2563 | int fd; |
2716 | int fd; |
2564 | #if HAVE_EVENTFD |
2717 | #if HAVE_EVENTFD |
… | |
… | |
2627 | #else |
2780 | #else |
2628 | errno = ENOSYS; |
2781 | errno = ENOSYS; |
2629 | #endif |
2782 | #endif |
2630 | } |
2783 | } |
2631 | |
2784 | |
|
|
2785 | void |
|
|
2786 | memfd_create (SV8 *pathname, int flags = 0) |
|
|
2787 | PPCODE: |
|
|
2788 | { |
|
|
2789 | int fd; |
|
|
2790 | #if HAVE_MEMFD_CREATE |
|
|
2791 | fd = memfd_create (SvPVbyte_nolen (pathname), flags); |
|
|
2792 | #else |
|
|
2793 | fd = (errno = ENOSYS, -1); |
|
|
2794 | #endif |
|
|
2795 | |
|
|
2796 | XPUSHs (newmortalFH (fd, O_RDWR)); |
|
|
2797 | } |
|
|
2798 | |
2632 | UV |
2799 | UV |
2633 | get_fdlimit () |
2800 | get_fdlimit () |
2634 | CODE: |
2801 | CODE: |
2635 | #if HAVE_RLIMITS |
2802 | #if HAVE_RLIMITS |
2636 | struct rlimit rl; |
2803 | struct rlimit rl; |
… | |
… | |
2669 | if (0 == setrlimit (RLIMIT_NOFILE, &rl)) |
2836 | if (0 == setrlimit (RLIMIT_NOFILE, &rl)) |
2670 | XSRETURN_YES; |
2837 | XSRETURN_YES; |
2671 | |
2838 | |
2672 | if (errno == EPERM) |
2839 | if (errno == EPERM) |
2673 | { |
2840 | { |
2674 | /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ |
2841 | /* setrlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */ |
2675 | /* our limit overflows a system-wide limit */ |
2842 | /* our limit overflows a system-wide limit */ |
2676 | /* try an adaptive algorithm, but do not lower the hardlimit */ |
2843 | /* try an adaptive algorithm, but do not lower the hardlimit */ |
2677 | rl.rlim_max = 0; |
2844 | rl.rlim_max = 0; |
2678 | for (bit = 0x40000000U; bit; bit >>= 1) |
2845 | for (bit = 0x40000000U; bit; bit >>= 1) |
2679 | { |
2846 | { |
2680 | rl.rlim_max |= bit; |
2847 | rl.rlim_max |= bit; |
2681 | rl.rlim_cur = rl.rlim_max; |
2848 | rl.rlim_cur = rl.rlim_max; |
2682 | |
2849 | |
2683 | /* nevr decrease the hard limit */ |
2850 | /* never decrease the hard limit */ |
2684 | if (rl.rlim_max < orig_rlim_max) |
2851 | if (rl.rlim_max < orig_rlim_max) |
2685 | break; |
2852 | break; |
2686 | |
2853 | |
2687 | if (0 != setrlimit (RLIMIT_NOFILE, &rl)) |
2854 | if (0 != setrlimit (RLIMIT_NOFILE, &rl)) |
2688 | rl.rlim_max &= ~bit; /* too high, remove bit again */ |
2855 | rl.rlim_max &= ~bit; /* too high, remove bit again */ |