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.
 
 
 

79 lines
1.7 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. my $offset = 0;
  19. sub fmt {
  20. my ($name, $num) = @_;
  21. if($num > 999){
  22. # ignore deprecated 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. $num = $num + $offset;
  28. print " SYS_$name = $num;\n";
  29. }
  30. my $prev;
  31. open(GCC, "gcc -E -dD @ARGV |") || die "can't run gcc";
  32. while(<GCC>){
  33. if(/^#define __NR_Linux\s+([0-9]+)/){
  34. # mips/mips64: extract offset
  35. $offset = $1;
  36. }
  37. elsif(/^#define __NR(\w*)_SYSCALL_BASE\s+([0-9]+)/){
  38. # arm: extract offset
  39. $offset = $1;
  40. }
  41. elsif(/^#define __NR_syscalls\s+/) {
  42. # ignore redefinitions of __NR_syscalls
  43. }
  44. elsif(/^#define __NR_(\w*)Linux_syscalls\s+/) {
  45. # mips/mips64: ignore definitions about the number of syscalls
  46. }
  47. elsif(/^#define __NR_(\w+)\s+([0-9]+)/){
  48. $prev = $2;
  49. fmt($1, $2);
  50. }
  51. elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){
  52. $prev = $2;
  53. fmt($1, $2);
  54. }
  55. elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
  56. fmt($1, $prev+$2)
  57. }
  58. elsif(/^#define __NR_(\w+)\s+\(__NR_Linux \+ ([0-9]+)/){
  59. fmt($1, $2);
  60. }
  61. elsif(/^#define __NR_(\w+)\s+\(__NR_SYSCALL_BASE \+ ([0-9]+)/){
  62. fmt($1, $2);
  63. }
  64. }
  65. print <<EOF;
  66. )
  67. EOF