• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
36open(F,$ARGV[0]) || die "cannot open template file $ARGV[0]\n";
37
38while (<F>) {
39	next unless /{/;
40	s/\/\*.*\*\///;
41	($name) = /"([^"]+)"/;
42	chomp;
43	$call{$name} = $_;
44}
45
46open(SL, ">syscallnum.h") || die "cannot create syscallnum.h\n";
47
48open(S,$ARGV[1]) || die "cannot open syscall file $ARGV[1]\n";
49while (<S>) {
50	$name = "";
51	next unless  (($name, $num) = /define\s+__NR_(\S+)\s+(\d+)/);
52	next if $name eq "";
53
54	$name = $conv{$name} if defined($conv{$name});
55
56	if (!defined($call{$name})) {
57		unless (defined($args{$name})) {
58			print STDERR "unknown call $name $num\n";
59			$na = 3;
60		} else {
61			$na = $args{$name};
62		}
63		if (defined($known{$name})) {
64			$func = $known{$name};
65		} else {
66			$func = "printargs";
67		}
68		print "\t{ $na,\t0,\t$func,\t\"$name\" }, /* $num */\n";
69	} else {
70		print "$call{$name} /* $num */\n";
71	}
72	print SL "#define SYS_$name $num\n"
73}
74