mksysnum_linux.pl 1.1 KB

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