Text file src/syscall/mksysnum_linux.pl

     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  // Code generated by the command above; DO NOT EDIT.
    13  
    14  package syscall
    15  
    16  const(
    17  EOF
    18  
    19  my $offset = 0;
    20  
    21  sub fmt {
    22  	my ($name, $num) = @_;
    23  	if($num > 999){
    24  		# ignore deprecated syscalls that are no longer implemented
    25  		# https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716
    26  		return;
    27  	}
    28  	$name =~ y/a-z/A-Z/;
    29  	$num = $num + $offset;
    30  	print "	SYS_$name = $num;\n";
    31  }
    32  
    33  my $prev;
    34  open(GCC, "gcc -E -dD $ARGV[0] |") || die "can't run gcc";
    35  while(<GCC>){
    36  	if(/^#define __NR_Linux\s+([0-9]+)/){
    37  		# mips/mips64: extract offset
    38  		$offset = $1;
    39  	}
    40  	elsif(/^#define __NR_syscalls\s+/) {
    41  		# ignore redefinitions of __NR_syscalls
    42  	}
    43  	elsif(/^#define __NR_(\w+)\s+([0-9]+)/){
    44  		$prev = $2;
    45  		fmt($1, $2);
    46  	}
    47  	elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){
    48  		$prev = $2;
    49  		fmt($1, $2);
    50  	}
    51  	elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
    52  		fmt($1, $prev+$2)
    53  	}
    54  	elsif(/^#define __NR_(\w+)\s+\(__NR_Linux \+ ([0-9]+)/){
    55  		fmt($1, $2);
    56  	}
    57  }
    58  
    59  print <<EOF;
    60  )
    61  EOF
    62  

View as plain text