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.

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