]> Sergey Matveev's repositories - public-inbox.git/commitdiff
syscall: support Linux x32 ABI
authorEric Wong <e@yhbt.net>
Thu, 6 Feb 2020 08:49:36 +0000 (08:49 +0000)
committerEric Wong <e@yhbt.net>
Fri, 7 Feb 2020 07:19:59 +0000 (01:19 -0600)
The x32 ABI allows users to take advantage of the extra
registers on x86-64 without the bloat of 64-bit pointers and
longs.

This ought to be significant since Perl was designed when 32-bit
was prevalent; and the common structs for ops, hashes, scalars,
and arrays use longs (SSize_t/Size_t) for things which should
never need 64-bits when processing emails.

Debian's x32 port seems to work quite nicely under a chroot
on an amd64 Linux system.  All tests pass under x32, now.

MANIFEST
lib/PublicInbox/Syscall.pm
t/epoll.t [new file with mode: 0644]

index 6de45ebf76583f8fc081ab55078958a87a4a3578..f7568c25027bef834214c199e00df6b4f68d0b84 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -219,6 +219,7 @@ t/ds-leak.t
 t/ds-poll.t
 t/edit.t
 t/emergency.t
 t/ds-poll.t
 t/edit.t
 t/emergency.t
+t/epoll.t
 t/fail-bin/spamc
 t/feed.t
 t/filter_base.t
 t/fail-bin/spamc
 t/feed.t
 t/filter_base.t
index ca7aa1c8a957ff7ecb13af576c847ae6311fe684..ce6b0f3afd5f832669614d3c13c5e08e9c5b1805 100644 (file)
@@ -78,9 +78,9 @@ if ($^O eq "linux") {
     my $u64_mod_8 = 0;
 
     # if we're running on an x86_64 kernel, but a 32-bit process,
     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) {
     if ($machine eq "x86_64" && $Config{ptrsize} == 4) {
-        $machine = "i386";
+        $machine = $Config{cppsymbols} =~ /\b__ILP32__=1\b/ ? 'x32' : 'i386';
     }
 
     # Similarly for mips64 vs mips
     }
 
     # Similarly for mips64 vs mips
@@ -98,6 +98,11 @@ if ($^O eq "linux") {
         $SYS_epoll_ctl    = 233;
         $SYS_epoll_wait   = 232;
         $SYS_signalfd4 = 289;
         $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 =~ m/^parisc/) {
         $SYS_epoll_create = 224;
         $SYS_epoll_ctl    = 225;
     } elsif ($machine =~ m/^parisc/) {
         $SYS_epoll_create = 224;
         $SYS_epoll_ctl    = 225;
diff --git a/t/epoll.t b/t/epoll.t
new file mode 100644 (file)
index 0000000..56ade67
--- /dev/null
+++ b/t/epoll.t
@@ -0,0 +1,20 @@
+use strict;
+use Test::More;
+use IO::Handle;
+use PublicInbox::Syscall qw(:epoll);
+plan skip_all => 'not Linux' if $^O ne 'linux';
+my $epfd = epoll_create();
+ok($epfd >= 0, 'epoll_create');
+my $hnd = IO::Handle->new_from_fd($epfd, 'r+'); # close on exit
+
+pipe(my ($r, $w)) or die "pipe: $!";
+is(epoll_ctl($epfd, EPOLL_CTL_ADD, fileno($w), EPOLLOUT), 0,
+    'epoll_ctl socket EPOLLOUT');
+
+my @events;
+is(epoll_wait($epfd, 100, 10000, \@events), 1, 'epoll_wait returns');
+is_deeply(\@events, [ [ fileno($w), EPOLLOUT ] ], 'got expected events');
+close $w;
+is(epoll_wait($epfd, 100, 0, \@events), 0, 'epoll_wait timeout');
+
+done_testing;