2002-09-23 15:41:01 +00:00
#!/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" ,
2009-01-02 13:03:44 +00:00
) ;
2002-09-23 15:41:01 +00:00
% known = (
"mmap" = > "sys_mmap" ,
2009-01-02 13:03:44 +00:00
"sched_yield" = > "printargs" ,
) ;
2002-09-23 15:41:01 +00:00
# only used when the template file has no entry
% args = (
"arch_prctl" = > 2 ,
"tkill" = > 2 ,
"gettid" = > 0 ,
"readahead" = > 3 ,
# should decode all these:
2009-01-02 13:03:44 +00:00
"setxattr" = > 5 ,
2002-09-23 15:41:01 +00:00
"lsetxattr" = > 5 ,
"fsetxattr" = > 5 ,
"getxattr" = > 4 ,
"lgetxattr" = > 4 ,
"fgetxattr" = > 4 ,
"listxattr" = > 3 ,
"llistxattr" = > 3 ,
"flistxattr" = > 3 ,
"removexattr" = > 2 ,
"lremovexattr" = > 2 ,
"fremovexattr" = > 2 ,
"mmap" = > 6 ,
2009-01-02 13:03:44 +00:00
"sched_yield" = > 0 ,
) ;
2002-09-23 15:41:01 +00:00
2009-01-02 13:03:44 +00:00
open ( F , $ ARGV [ 0 ] ) || die "cannot open template file $ARGV[0]\n" ;
2002-09-23 15:41:01 +00:00
2009-01-02 13:03:44 +00:00
while ( <F> ) {
next unless /{/ ;
s/\/\*.*\*\/// ;
2002-09-23 15:41:01 +00:00
( $ name ) = /"([^"]+)"/ ;
2009-01-02 13:03:44 +00:00
chomp ;
$ call { $ name } = $ _ ;
}
2002-09-23 15:41:01 +00:00
2009-01-02 13:03:44 +00:00
open ( SL , ">syscallnum.h" ) || die "cannot create syscallnum.h\n" ;
2002-09-23 15:41:01 +00:00
2009-01-02 13:03:44 +00:00
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 "" ;
2002-09-23 15:41:01 +00:00
2009-01-02 13:03:44 +00:00
$ name = $ conv { $ name } if defined ( $ conv { $ name } ) ;
2002-09-23 15:41:01 +00:00
2009-01-02 13:03:44 +00:00
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" ;
}
2002-09-23 15:41:01 +00:00
print SL "#define SYS_$name $num\n"
2009-01-02 13:03:44 +00:00
}