You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  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. use strict;
  6. if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") {
  7. print STDERR "GOARCH or GOOS not defined in environment\n";
  8. exit 1;
  9. }
  10. my $command = "mksysnum_linux.pl ". join(' ', @ARGV);
  11. print <<EOF;
  12. // $command
  13. // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
  14. // +build $ENV{'GOARCH'},$ENV{'GOOS'}
  15. package unix
  16. const(
  17. EOF
  18. sub fmt {
  19. my ($name, $num) = @_;
  20. if($num > 999){
  21. # ignore deprecated syscalls that are no longer implemented
  22. # https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716
  23. return;
  24. }
  25. $name =~ y/a-z/A-Z/;
  26. print " SYS_$name = $num;\n";
  27. }
  28. my $prev;
  29. open(GCC, "gcc -E -dD $ARGV[0] |") || die "can't run gcc";
  30. while(<GCC>){
  31. if(/^#define __NR_syscalls\s+/) {
  32. # ignore redefinitions of __NR_syscalls
  33. }
  34. elsif(/^#define __NR_(\w+)\s+([0-9]+)/){
  35. $prev = $2;
  36. fmt($1, $2);
  37. }
  38. elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){
  39. $prev = $2;
  40. fmt($1, $2);
  41. }
  42. elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
  43. fmt($1, $prev+$2)
  44. }
  45. }
  46. print <<EOF;
  47. )
  48. EOF