user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH] syscall: support Linux x32 ABI
Date: Thu,  6 Feb 2020 08:49:36 +0000	[thread overview]
Message-ID: <20200206084936.25616-1-e@yhbt.net> (raw)

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                   |  1 +
 lib/PublicInbox/Syscall.pm |  9 +++++++--
 t/epoll.t                  | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 t/epoll.t

diff --git a/MANIFEST b/MANIFEST
index 5eb5d53a..61747daa 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -217,6 +217,7 @@ t/ds-leak.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
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index c66ea51b..29d60ed1 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -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,
-    # 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 +98,11 @@ 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 =~ m/^parisc/) {
         $SYS_epoll_create = 224;
         $SYS_epoll_ctl    = 225;
diff --git a/t/epoll.t b/t/epoll.t
new file mode 100644
index 00000000..56ade672
--- /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;

                 reply	other threads:[~2020-02-06  8:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200206084936.25616-1-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).