summaryrefslogtreecommitdiff
path: root/scripts/codegen/gen_linux_syscalls.pl
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-05-07 01:17:41 -0400
committerNick Mathewson <nickm@torproject.org>2014-05-07 01:17:41 -0400
commitde3bbc4f53c2a1905a713c66bf8f375b646cd2a2 (patch)
tree224a3c32c79a712844fae33f40bd1696b21de148 /scripts/codegen/gen_linux_syscalls.pl
parent81144b2bd28b8c0e3d7919c04f1a8190b75c07e9 (diff)
downloadtor-de3bbc4f53c2a1905a713c66bf8f375b646cd2a2.tar.gz
tor-de3bbc4f53c2a1905a713c66bf8f375b646cd2a2.zip
Move code-generation scripts to scripts/codegen
Now that we have a scripts/* directory, let's put the scripts we use for generating C there.
Diffstat (limited to 'scripts/codegen/gen_linux_syscalls.pl')
-rwxr-xr-xscripts/codegen/gen_linux_syscalls.pl37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/codegen/gen_linux_syscalls.pl b/scripts/codegen/gen_linux_syscalls.pl
new file mode 100755
index 0000000000..f985bad6c9
--- /dev/null
+++ b/scripts/codegen/gen_linux_syscalls.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+use strict;
+my %syscalls = ();
+
+while (<>) {
+ if (/^#define (__NR_\w+) /) {
+ $syscalls{$1} = 1;
+ }
+}
+
+print <<EOL;
+/* Automatically generated with
+ gen_linux_syscalls.pl /usr/include/asm/unistd*.h
+ Do not edit.
+ */
+static const struct {
+ int syscall_num; const char *syscall_name;
+} SYSCALLS_BY_NUMBER[] = {
+EOL
+
+for my $k (sort keys %syscalls) {
+ my $name = $k;
+ $name =~ s/^__NR_//;
+ print <<EOL;
+#ifdef $k
+ { $k, "$name" },
+#endif
+EOL
+
+}
+
+print <<EOL
+ {0, NULL}
+};
+
+EOL