github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/golang.org/x/sys/unix/mksysnum_linux.pl (about)

     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  if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") {
     9  	print STDERR "GOARCH or GOOS not defined in environment\n";
    10  	exit 1;
    11  }
    12  
    13  my $command = "mksysnum_linux.pl ". join(' ', @ARGV);
    14  
    15  print <<EOF;
    16  // $command
    17  // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
    18  
    19  // +build $ENV{'GOARCH'},$ENV{'GOOS'}
    20  
    21  package unix
    22  
    23  const(
    24  EOF
    25  
    26  my $offset = 0;
    27  
    28  sub fmt {
    29  	my ($name, $num) = @_;
    30  	if($num > 999){
    31  		# ignore deprecated syscalls that are no longer implemented
    32  		# https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716
    33  		return;
    34  	}
    35  	$name =~ y/a-z/A-Z/;
    36  	$num = $num + $offset;
    37  	print "	SYS_$name = $num;\n";
    38  }
    39  
    40  my $prev;
    41  open(GCC, "gcc -E -dD @ARGV |") || die "can't run gcc";
    42  while(<GCC>){
    43  	if(/^#define __NR_Linux\s+([0-9]+)/){
    44  		# mips/mips64: extract offset
    45  		$offset = $1;
    46  	}
    47  	elsif(/^#define __NR(\w*)_SYSCALL_BASE\s+([0-9]+)/){
    48  		# arm: extract offset
    49  		$offset = $1;
    50  	}
    51  	elsif(/^#define __NR_syscalls\s+/) {
    52  		# ignore redefinitions of __NR_syscalls
    53  	}
    54  	elsif(/^#define __NR_(\w*)Linux_syscalls\s+/) {
    55  		# mips/mips64: ignore definitions about the number of syscalls
    56  	}
    57  	elsif(/^#define __NR_(\w+)\s+([0-9]+)/){
    58  		$prev = $2;
    59  		fmt($1, $2);
    60  	}
    61  	elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){
    62  		$prev = $2;
    63  		fmt($1, $2);
    64  	}
    65  	elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
    66  		fmt($1, $prev+$2)
    67  	}
    68  	elsif(/^#define __NR_(\w+)\s+\(__NR_Linux \+ ([0-9]+)/){
    69  		fmt($1, $2);
    70  	}
    71  	elsif(/^#define __NR_(\w+)\s+\(__NR_SYSCALL_BASE \+ ([0-9]+)/){
    72  		fmt($1, $2);
    73  	}
    74  }
    75  
    76  print <<EOF;
    77  )
    78  EOF