Commit 401288a7 authored by Alexandre Julliard's avatar Alexandre Julliard

make_specfiles: Generate a list of syscalls from the corresponding spec files.

parent a7ec901e
......@@ -163,6 +163,21 @@ sub update_file($$)
print "$file updated\n";
}
# update a file if changed
sub output_file($$)
{
my $file = shift;
my $new = shift;
my $old = "";
if (open FILE, "<$file")
{
local $/ = undef;
$old .= <FILE>;
close FILE;
}
update_file( $file, $new ) if $old ne $new;
}
# parse a spec file line
sub parse_line($$$)
{
......@@ -298,6 +313,65 @@ sub update_spec_file($)
update_file( $file, $new ) if $old ne $new;
}
sub get_args_size($)
{
my $args = shift;
my $ret32 = 0;
my $ret64 = 0;
if ($args =~ /^\((.*)\)$/)
{
my @args = split /\s+/, $1;
$ret64 += 8 * scalar @args;
map { $ret32 += ($_ eq "int64") ? 8 : 4; } @args;
}
return ($ret32, $ret64);
}
sub get_syscalls_str(@)
{
my @syscalls = sort { $a->[0] cmp $b->[0] } @_;
my $ret = "";
for (my $i = 0; $i < @syscalls; $i++)
{
my ($name, $args) = @{$syscalls[$i]};
$ret .= sprintf " \\\n SYSCALL_ENTRY( 0x%04x, %s, %u )", $i, $name, $args;
}
return $ret . "\n";
}
sub read_syscalls($)
{
my $spec = shift;
my @syscalls32 = ();
my @syscalls64 = ();
%funcs = ();
read_spec_file( $spec );
foreach my $func (keys %funcs)
{
my $descr = $funcs{$func};
next unless $descr->{flags} =~ /-syscall/;
next if $descr->{target} ne $func && defined $funcs{$descr->{target}};
my ($args32, $args64) = get_args_size( $funcs{$func}->{args} );
push @syscalls32, [ $func, $args32 ] unless $descr->{flags} =~ /-arch=win64/;
push @syscalls64, [ $func, $args64 ] unless $descr->{flags} =~ /-arch=win32/;
}
return (\@syscalls32, \@syscalls64);
}
sub update_syscalls($$)
{
my ($spec, $file) = @_;
my ($syscalls32, $syscalls64) = read_syscalls( $spec );
output_file( $file,
"/* Automatically generated by tools/make_specfiles */\n" .
"\n#define ALL_SYSCALLS32" . get_syscalls_str( @{$syscalls32} ) .
"\n#define ALL_SYSCALLS64" . get_syscalls_str( @{$syscalls64} ));
}
sub sync_spec_files(@)
{
%funcs = ();
......@@ -310,3 +384,6 @@ foreach my $group (@dll_groups)
{
sync_spec_files( @{$group} );
}
update_syscalls( "ntdll", "dlls/ntdll/ntsyscalls.h" );
update_syscalls( "win32u", "dlls/win32u/win32syscalls.h" );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment