]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Syscall.pm
wwwstream: show relative coderepo URLs correctly
[public-inbox.git] / lib / PublicInbox / Syscall.pm
index c66ea51b4c6a8180810a01538e9a8e3945f69766..e4f00a2a2f736a995072dbac0db320ea49cb925e 100644 (file)
@@ -5,7 +5,7 @@
 # This license differs from the rest of public-inbox
 #
 # This module is Copyright (c) 2005 Six Apart, Ltd.
-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
 #
 # All rights reserved.
 #
@@ -14,7 +14,7 @@
 package PublicInbox::Syscall;
 use strict;
 use parent qw(Exporter);
-use POSIX qw(ENOSYS SEEK_CUR);
+use POSIX qw(ENOSYS O_NONBLOCK);
 use Config;
 
 # $VERSION = '0.25'; # Sys::Syscall version
@@ -22,7 +22,7 @@ our @EXPORT_OK = qw(epoll_ctl epoll_create epoll_wait
                   EPOLLIN EPOLLOUT EPOLLET
                   EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
                   EPOLLONESHOT EPOLLEXCLUSIVE
-                  signalfd SFD_NONBLOCK);
+                  signalfd $SFD_NONBLOCK);
 our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
                              EPOLLIN EPOLLOUT
                              EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
@@ -41,9 +41,6 @@ use constant {
        EPOLL_CTL_ADD => 1,
        EPOLL_CTL_DEL => 2,
        EPOLL_CTL_MOD => 3,
-
-       SFD_CLOEXEC => 02000000,
-       SFD_NONBLOCK => 00004000,
 };
 
 our $loaded_syscall = 0;
@@ -69,6 +66,8 @@ our (
      $SYS_signalfd4,
      );
 
+my $SFD_CLOEXEC = 02000000; # Perl does not expose O_CLOEXEC
+our $SFD_NONBLOCK = O_NONBLOCK;
 our $no_deprecated = 0;
 
 if ($^O eq "linux") {
@@ -78,9 +77,9 @@ if ($^O eq "linux") {
     my $u64_mod_8 = 0;
 
     # if we're running on an x86_64 kernel, but a 32-bit process,
-    # we need to use the i386 syscall numbers.
+    # we need to use the x32 or i386 syscall numbers.
     if ($machine eq "x86_64" && $Config{ptrsize} == 4) {
-        $machine = "i386";
+        $machine = $Config{cppsymbols} =~ /\b__ILP32__=1\b/ ? 'x32' : 'i386';
     }
 
     # Similarly for mips64 vs mips
@@ -98,6 +97,18 @@ if ($^O eq "linux") {
         $SYS_epoll_ctl    = 233;
         $SYS_epoll_wait   = 232;
         $SYS_signalfd4 = 289;
+    } elsif ($machine eq 'x32') {
+        $SYS_epoll_create = 1073742037;
+        $SYS_epoll_ctl = 1073742057;
+        $SYS_epoll_wait = 1073742056;
+        $SYS_signalfd4 = 1073742113;
+    } elsif ($machine eq 'sparc64') {
+       $SYS_epoll_create = 193;
+       $SYS_epoll_ctl = 194;
+       $SYS_epoll_wait = 195;
+       $u64_mod_8 = 1;
+       $SYS_signalfd4 = 317;
+       $SFD_CLOEXEC = 020000000;
     } elsif ($machine =~ m/^parisc/) {
         $SYS_epoll_create = 224;
         $SYS_epoll_ctl    = 225;
@@ -135,6 +146,7 @@ if ($^O eq "linux") {
         $SYS_epoll_wait   = 409;
         $u64_mod_8        = 1;
         $SYS_signalfd4 = 484;
+       $SFD_CLOEXEC = 010000000;
     } elsif ($machine eq "aarch64") {
         $SYS_epoll_create = 20;  # (sys_epoll_create1)
         $SYS_epoll_ctl    = 21;
@@ -252,13 +264,11 @@ sub epoll_wait_mod8 {
 sub signalfd ($$$) {
        my ($fd, $signos, $flags) = @_;
        if ($SYS_signalfd4) {
-               # Not sure if there's a way to get pack/unpack to get the
-               # contents of POSIX::SigSet to a buffer, but prepping the
-               # bitmap like one would for select() works:
-               my $buf = "\0" x 8;
-               vec($buf, $_ - 1, 1) = 1 for @$signos;
-
-               syscall($SYS_signalfd4, $fd, $buf, 8, $flags|SFD_CLOEXEC);
+               my $set = POSIX::SigSet->new(@$signos);
+               syscall($SYS_signalfd4, $fd, "$$set",
+                       # $Config{sig_count} is NSIG, so this is NSIG/8:
+                       int($Config{sig_count}/8),
+                       $flags|$SFD_CLOEXEC);
        } else {
                $! = ENOSYS;
                undef;