summaryrefslogtreecommitdiff
path: root/linux/x86_64/gentab.pl
blob: 3251b4309532841f2634bdf3b9e9ac17e299b6f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl -w
#generate syscall table from a template file (usually the master i386 syscall
#ent.h) and the x86_64 unistd.h
%conv =  (
	"exit" => "_exit",
); 	

%known = (
	"mmap" => "sys_mmap",
	"sched_yield" => "printargs",	
); 	

# only used when the template file has no entry
%args = (
	"arch_prctl" => 2,
	"tkill" => 2,
	"gettid" => 0,
	"readahead" => 3,
	# should decode all these:
	"setxattr" => 5, 
	"lsetxattr" => 5,
	"fsetxattr" => 5,
	"getxattr" => 4,
	"lgetxattr" => 4,
	"fgetxattr" => 4,
	"listxattr" => 3,
	"llistxattr" => 3,
	"flistxattr" => 3,
	"removexattr" => 2,
	"lremovexattr" => 2,
	"fremovexattr" => 2,
	"mmap" => 6,
	"sched_yield" => 0, 
); 	

open(F,$ARGV[0]) || die "cannot open template file $ARGV[0]\n"; 

while (<F>) { 
	next unless /{/; 
	s/\/\*.*\*\///; 
	($name) = /"([^"]+)"/;
	chomp; 
	$call{$name} = $_; 
} 

open(SL, ">syscallnum.h") || die "cannot create syscallnum.h\n"; 



open(S,$ARGV[1]) || die "cannot open syscall file $ARGV[1]\n";  
while (<S>) { 
	$name = ""; 
	next unless  (($name, $num) = /define\s+__NR_(\S+)\s+(\d+)/); 
	next if $name eq ""; 

	$name = $conv{$name} if defined($conv{$name}); 

	if (!defined($call{$name})) { 
		unless (defined($args{$name})) { 
			print STDERR "unknown call $name $num\n"; 
			$na = 3; 
		} else { 
			$na = $args{$name}; 
		} 	
		if (defined($known{$name})) { 
			$func = $known{$name}; 
		} else { 
			$func = "printargs"; 
		} 	
		print "\t{ $na,\t0,\t$func,\t\"$name\" }, /* $num */\n"; 
	} else { 
		print "$call{$name} /* $num */\n"; 
	} 
	print SL "#define SYS_$name $num\n"
}