1 #!/usr/bin/env perl 2 # Copyright 2009 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 use strict; 7 8 my $command = "mksysnum_linux.pl ". join(' ', @ARGV); 9 10 print <<EOF; 11 // $command 12 // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT 13 14 package syscall 15 16 const( 17 EOF 18 19 sub fmt { 20 my ($name, $num) = @_; 21 if($num > 999){ 22 # ignore depricated syscalls that are no longer implemented 23 # https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716 24 return; 25 } 26 $name =~ y/a-z/A-Z/; 27 print " SYS_$name = $num;\n"; 28 } 29 30 my $prev; 31 open(GCC, "gcc -E -dD $ARGV[0] |") || die "can't run gcc"; 32 while(<GCC>){ 33 if(/^#define __NR_syscalls\s+/) { 34 # ignore redefinitions of __NR_syscalls 35 } 36 elsif(/^#define __NR_(\w+)\s+([0-9]+)/){ 37 $prev = $2; 38 fmt($1, $2); 39 } 40 elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){ 41 $prev = $2; 42 fmt($1, $2); 43 } 44 elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){ 45 fmt($1, $prev+$2) 46 } 47 } 48 49 print <<EOF; 50 ) 51 EOF 52