about summary refs log tree commit homepage
path: root/devel/sysdefs-list
diff options
context:
space:
mode:
Diffstat (limited to 'devel/sysdefs-list')
-rwxr-xr-xdevel/sysdefs-list74
1 files changed, 74 insertions, 0 deletions
diff --git a/devel/sysdefs-list b/devel/sysdefs-list
new file mode 100755
index 00000000..9764cc29
--- /dev/null
+++ b/devel/sysdefs-list
@@ -0,0 +1,74 @@
+# Copyright all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
+# Dump system-specific constant numbers this is to maintain
+# PublicInbox::Syscall and any other system-specific pieces.
+# DO NOT USE syscall numbers for *BSDs, none of the current BSD kernels
+# we know about promise stable syscall numbers (unlike Linux).
+# However, sysconf(3) constants are stable ABI on all safe to dump.
+eval 'exec perl -S $0 ${1+"$@"}' # no shebang
+        if 0; # running under some shell
+use v5.12;
+use File::Temp 0.19;
+use POSIX qw(uname);
+use Config;
+say '$machine='.(POSIX::uname())[-1];
+my $cc = $ENV{CC} // $Config{cc} // 'cc';
+my @cflags = split(/\s+/, $ENV{CFLAGS} // $Config{ccflags} // '-Wall');
+my $str = do { local $/; <DATA> };
+$str =~ s/^\s*MAYBE\s*(\w+)\s*$/
+#ifdef $1
+        D($1);
+#endif
+/sgxm;
+my $tmp = File::Temp->newdir('sysdefs-list-XXXX', TMPDIR => 1);
+my $f = "$tmp/sysdefs.c";
+my $x = "$tmp/sysdefs";
+open my $fh, '>', $f or die "open $f $!";
+print $fh $str or die "print $f $!";
+close $fh or die "close $f $!";
+system($cc, '-o', $x, $f, @cflags) == 0 or die "$cc failed \$?=$?";
+exec($x);
+__DATA__
+#ifndef _GNU_SOURCE
+#  define _GNU_SOURCE
+#endif
+#include <signal.h>
+#include <sys/syscall.h>
+#include <sys/ioctl.h>
+#ifdef __linux__
+#include <linux/fs.h>
+#endif
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#define D(x) printf("$" #x " = %ld;\n", (long)x)
+
+int main(void)
+{
+#ifdef __linux__
+        D(SYS_epoll_create1);
+        D(SYS_epoll_ctl);
+        MAYBE SYS_epoll_wait
+        D(SYS_epoll_pwait);
+        D(SYS_signalfd4);
+        D(SYS_inotify_init1);
+        D(SYS_inotify_add_watch);
+        D(SYS_inotify_rm_watch);
+        D(SYS_prctl);
+        D(SYS_fstatfs);
+        D(SYS_sendmsg);
+        D(SYS_recvmsg);
+#ifdef FS_IOC_GETFLAGS
+        printf("FS_IOC_GETFLAGS=%#lx\nFS_IOC_SETFLAGS=%#lx\n",
+                (unsigned long)FS_IOC_GETFLAGS, (unsigned long)FS_IOC_SETFLAGS);
+#endif
+        MAYBE SYS_renameat2
+#endif /* Linux, any other OSes with stable syscalls? */
+        printf("size_t=%zu off_t=%zu pid_t=%zu\n",
+                 sizeof(size_t), sizeof(off_t), sizeof(pid_t));
+        D(SIGWINCH);
+        MAYBE _SC_NPROCESSORS_ONLN
+
+        return 0;
+}