Debian Codegraph @

strace-4.6/linux/x86_64/gentab.pl

raw
1 #!/usr/bin/perl -w
2 #generate syscall table from a template file (usually the master i386 syscall
3 #ent.h) and the x86_64 unistd.h
4 %conv = (
5 "exit" => "_exit",
6 );
7
8 %known = (
9 "mmap" => "sys_mmap",
10 "sched_yield" => "printargs",
11 );
12
13 # only used when the template file has no entry
14 %args = (
15 "arch_prctl" => 2,
16 "tkill" => 2,
17 "gettid" => 0,
18 "readahead" => 3,
19 # should decode all these:
20 "setxattr" => 5,
21 "lsetxattr" => 5,
22 "fsetxattr" => 5,
23 "getxattr" => 4,
24 "lgetxattr" => 4,
25 "fgetxattr" => 4,
26 "listxattr" => 3,
27 "llistxattr" => 3,
28 "flistxattr" => 3,
29 "removexattr" => 2,
30 "lremovexattr" => 2,
31 "fremovexattr" => 2,
32 "mmap" => 6,
33 "sched_yield" => 0,
34 );
35
36 open(F,$ARGV[0]) || die "cannot open template file $ARGV[0]\n";
37
38 while (<F>) {
39 next unless /{/;
40 s/\/\*.*\*\///;
41 ($name) = /"([^"]+)"/;
42 chomp;
43 $call{$name} = $_;
44 }
45
46 open(SL, ">syscallnum.h") || die "cannot create syscallnum.h\n";
47
48
49
50 open(S,$ARGV[1]) || die "cannot open syscall file $ARGV[1]\n";
51 while (<S>) {
52 $name = "";
53 next unless (($name, $num) = /define\s+__NR_(\S+)\s+(\d+)/);
54 next if $name eq "";
55
56 $name = $conv{$name} if defined($conv{$name});
57
58 if (!defined($call{$name})) {
59 unless (defined($args{$name})) {
60 print STDERR "unknown call $name $num\n";
61 $na = 3;
62 } else {
63 $na = $args{$name};
64 }
65 if (defined($known{$name})) {
66 $func = $known{$name};
67 } else {
68 $func = "printargs";
69 }
70 print "\t{ $na,\t0,\t$func,\t\"$name\" }, /* $num */\n";
71 } else {
72 print "$call{$name} /* $num */\n";
73 }
74 print SL "#define SYS_$name $num\n"
75 }