1999-09-23 17:14:20 +02:00
|
|
|
package winapi_local;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
1999-10-31 03:08:38 +01:00
|
|
|
sub check_function {
|
1999-09-23 17:14:20 +02:00
|
|
|
my $options = shift;
|
|
|
|
my $output = shift;
|
|
|
|
my $return_type = shift;
|
|
|
|
my $calling_convention = shift;
|
2000-04-24 20:02:32 +02:00
|
|
|
my $external_name = shift;
|
|
|
|
my $internal_name = shift;
|
1999-09-23 17:14:20 +02:00
|
|
|
my $refargument_types = shift;
|
|
|
|
my @argument_types = @$refargument_types;
|
|
|
|
my $winapi = shift;
|
|
|
|
|
2000-04-24 20:02:32 +02:00
|
|
|
my $module = $winapi->function_module($external_name);
|
1999-12-12 00:01:45 +01:00
|
|
|
|
1999-10-24 23:45:39 +02:00
|
|
|
if($winapi->name eq "win16") {
|
2000-04-24 20:02:32 +02:00
|
|
|
my $name16 = $external_name;
|
1999-12-12 00:01:45 +01:00
|
|
|
$name16 =~ s/16$//;
|
2000-04-24 20:02:32 +02:00
|
|
|
if($name16 ne $external_name && $winapi->function_stub($name16)) {
|
1999-10-24 23:45:39 +02:00
|
|
|
if($options->implemented) {
|
|
|
|
&$output("function implemented but declared as stub in .spec file");
|
|
|
|
}
|
|
|
|
return;
|
2000-04-24 20:02:32 +02:00
|
|
|
} elsif($winapi->function_stub($external_name)) {
|
1999-10-24 23:45:39 +02:00
|
|
|
if($options->implemented_win32) {
|
|
|
|
&$output("32-bit variant of function implemented but declared as stub in .spec file");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2000-04-24 20:02:32 +02:00
|
|
|
} elsif($winapi->function_stub($external_name)) {
|
1999-10-24 23:45:39 +02:00
|
|
|
if($options->implemented) {
|
|
|
|
&$output("function implemented but declared as stub in .spec file");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
my $forbidden_return_type = 0;
|
|
|
|
my $implemented_return_kind;
|
1999-10-24 23:45:39 +02:00
|
|
|
$winapi->type_used_in_module($return_type,$module);
|
1999-09-23 17:14:20 +02:00
|
|
|
if(!defined($implemented_return_kind = $winapi->translate_argument($return_type))) {
|
|
|
|
if($return_type ne "") {
|
|
|
|
&$output("no translation defined: " . $return_type);
|
|
|
|
}
|
|
|
|
} elsif(!$winapi->is_allowed_kind($implemented_return_kind) || !$winapi->allowed_type_in_module($return_type,$module)) {
|
|
|
|
$forbidden_return_type = 1;
|
|
|
|
if($options->report_argument_forbidden($return_type)) {
|
|
|
|
&$output("forbidden return type: $return_type ($implemented_return_kind)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $segmented = 0;
|
|
|
|
if($implemented_return_kind =~ /^segptr|segstr$/) {
|
|
|
|
$segmented = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $implemented_calling_convention;
|
|
|
|
if($winapi->name eq "win16") {
|
|
|
|
if($calling_convention =~ /^__cdecl$/) {
|
|
|
|
$implemented_calling_convention = "cdecl";
|
2000-01-08 23:20:32 +01:00
|
|
|
} elsif($calling_convention =~ /^VFWAPIV|WINAPIV$/) {
|
|
|
|
$implemented_calling_convention = "varargs";
|
2000-04-15 22:39:55 +02:00
|
|
|
} elsif($calling_convention = ~ /^__stdcall|VFWAPI|WINAPI|CALLBACK$/) {
|
1999-09-23 17:14:20 +02:00
|
|
|
if($implemented_return_kind =~ /^s_word|word|void$/) {
|
|
|
|
$implemented_calling_convention = "pascal16";
|
|
|
|
} else {
|
|
|
|
$implemented_calling_convention = "pascal";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elsif($winapi->name eq "win32") {
|
|
|
|
if($calling_convention =~ /^__cdecl$/) {
|
|
|
|
$implemented_calling_convention = "cdecl";
|
|
|
|
} elsif($calling_convention =~ /^VFWAPIV|WINAPIV$/) {
|
|
|
|
$implemented_calling_convention = "varargs";
|
2000-04-15 22:39:55 +02:00
|
|
|
} elsif($calling_convention =~ /^__stdcall|VFWAPI|WINAPI|CALLBACK$/) {
|
1999-09-23 17:14:20 +02:00
|
|
|
$implemented_calling_convention = "stdcall";
|
1999-10-24 23:45:39 +02:00
|
|
|
} else {
|
|
|
|
$implemented_calling_convention = "<default>";
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:02:32 +02:00
|
|
|
my $declared_calling_convention = $winapi->function_calling_convention($external_name);
|
|
|
|
my @declared_argument_kinds = split(/\s+/, $winapi->function_arguments($external_name));
|
1999-09-23 17:14:20 +02:00
|
|
|
|
|
|
|
if($declared_calling_convention =~ /^register|interrupt$/) {
|
|
|
|
push @declared_argument_kinds, "ptr";
|
|
|
|
}
|
|
|
|
|
|
|
|
if($declared_calling_convention =~ /^register|interupt$/ &&
|
|
|
|
(($winapi->name eq "win32" && $implemented_calling_convention eq "stdcall") ||
|
|
|
|
(($winapi->name eq "win16" && $implemented_calling_convention =~ /^pascal/))))
|
|
|
|
{
|
|
|
|
# correct
|
|
|
|
} elsif($implemented_calling_convention ne $declared_calling_convention &&
|
2000-01-08 23:20:32 +01:00
|
|
|
!($declared_calling_convention =~ /^pascal/ && $forbidden_return_type) &&
|
|
|
|
!($implemented_calling_convention =~ /^cdecl|varargs$/ && $declared_calling_convention =~ /^cdecl|varargs$/))
|
1999-09-23 17:14:20 +02:00
|
|
|
{
|
|
|
|
if($options->calling_convention) {
|
|
|
|
&$output("calling convention mismatch: $implemented_calling_convention != $declared_calling_convention");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($declared_calling_convention eq "varargs") {
|
|
|
|
if($#argument_types != -1 && $argument_types[$#argument_types] eq "...") {
|
|
|
|
pop @argument_types;
|
|
|
|
} else {
|
|
|
|
&$output("function not implemented as vararg");
|
|
|
|
}
|
|
|
|
} elsif($#argument_types != -1 && $argument_types[$#argument_types] eq "...") {
|
|
|
|
&$output("function not declared as vararg");
|
|
|
|
}
|
1999-12-12 00:01:45 +01:00
|
|
|
|
|
|
|
if($#argument_types != -1 && $argument_types[$#argument_types] eq "CONTEXT *" &&
|
2000-04-24 20:02:32 +02:00
|
|
|
$external_name !~ /^(Get|Set)ThreadContext$/) # FIXME: Kludge
|
1999-12-12 00:01:45 +01:00
|
|
|
{
|
|
|
|
$#argument_types--;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:02:32 +02:00
|
|
|
if($internal_name =~ /^CRTDLL__ftol|CRTDLL__CIpow$/) { # FIXME: Kludge
|
1999-09-23 17:14:20 +02:00
|
|
|
# ignore
|
|
|
|
} else {
|
|
|
|
my $n = 0;
|
|
|
|
my @argument_kinds = map {
|
|
|
|
my $type = $_;
|
|
|
|
my $kind = "unknown";
|
1999-10-24 23:45:39 +02:00
|
|
|
$winapi->type_used_in_module($type,$module);
|
1999-09-23 17:14:20 +02:00
|
|
|
if(!defined($kind = $winapi->translate_argument($type))) {
|
|
|
|
&$output("no translation defined: " . $type);
|
|
|
|
} elsif(!$winapi->is_allowed_kind($kind) ||
|
|
|
|
!$winapi->allowed_type_in_module($type, $module)) {
|
|
|
|
if($options->report_argument_forbidden($type)) {
|
2000-02-29 22:59:09 +01:00
|
|
|
&$output("forbidden argument " . ($n + 1) . " type " . $type . " (" . $kind . ")");
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
|
|
|
}
|
1999-10-24 23:45:39 +02:00
|
|
|
if(defined($kind) && $kind eq "longlong") {
|
|
|
|
$n+=2;
|
|
|
|
("long", "long");
|
|
|
|
} else {
|
|
|
|
$n++;
|
|
|
|
$kind;
|
|
|
|
}
|
1999-09-23 17:14:20 +02:00
|
|
|
} @argument_types;
|
|
|
|
|
|
|
|
for my $n (0..$#argument_kinds) {
|
|
|
|
if(!defined($argument_kinds[$n]) || !defined($declared_argument_kinds[$n])) { next; }
|
|
|
|
|
|
|
|
if($argument_kinds[$n] =~ /^segptr|segstr$/ ||
|
|
|
|
$declared_argument_kinds[$n] =~ /^segptr|segstr$/)
|
|
|
|
{
|
|
|
|
$segmented = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($argument_kinds[$n] ne $declared_argument_kinds[$n]) {
|
|
|
|
if($options->report_argument_kind($argument_kinds[$n]) ||
|
|
|
|
$options->report_argument_kind($declared_argument_kinds[$n]))
|
|
|
|
{
|
|
|
|
&$output("argument " . ($n + 1) . " type mismatch: " .
|
|
|
|
$argument_types[$n] . " ($argument_kinds[$n]) != " . $declared_argument_kinds[$n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-24 23:45:39 +02:00
|
|
|
if($#argument_kinds != $#declared_argument_kinds) {
|
|
|
|
if($options->argument_count) {
|
|
|
|
&$output("argument count differs: " . ($#argument_types + 1) . " != " . ($#declared_argument_kinds + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:02:32 +02:00
|
|
|
if($segmented && $options->shared_segmented && $winapi->is_shared_function($internal_name)) {
|
1999-09-23 17:14:20 +02:00
|
|
|
&$output("function using segmented pointers shared between Win16 och Win32");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-31 03:08:38 +01:00
|
|
|
sub check_file {
|
|
|
|
my $options = shift;
|
|
|
|
my $output = shift;
|
|
|
|
my $file = shift;
|
|
|
|
my $functions = shift;
|
|
|
|
|
|
|
|
if($options->cross_call) {
|
|
|
|
my @names = sort(keys(%$functions));
|
|
|
|
for my $name (@names) {
|
|
|
|
my @called_names = $$functions{$name}->called_function_names;
|
|
|
|
my @called_by_names = $$functions{$name}->called_by_function_names;
|
|
|
|
my $module = $$functions{$name}->module;
|
2000-04-29 16:24:11 +02:00
|
|
|
|
|
|
|
if($options->cross_call_win32_win16) {
|
|
|
|
my $module16 = $$functions{$name}->module16;
|
|
|
|
my $module32 = $$functions{$name}->module32;
|
|
|
|
|
|
|
|
if($#called_names >= 0 && (defined($module16) || defined($module32)) ) {
|
|
|
|
for my $called_name (@called_names) {
|
|
|
|
my $called_module16 = $$functions{$called_name}->module16;
|
|
|
|
my $called_module32 = $$functions{$called_name}->module32;
|
|
|
|
if(defined($module32) &&
|
|
|
|
defined($called_module16) && !defined($called_module32) &&
|
|
|
|
$name ne $called_name)
|
|
|
|
{
|
|
|
|
$output->write("$file: $module: $name: illegal call to $called_name (Win32 -> Win16)\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($options->cross_call_unicode_ascii) {
|
|
|
|
if($name =~ /W$/) {
|
|
|
|
for my $called_name (@called_names) {
|
|
|
|
if($called_name =~ /A$/) {
|
|
|
|
$output->write("$file: $module: $name: illegal call to $called_name (Unicode -> ASCII)\n");
|
|
|
|
}
|
1999-10-31 03:08:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
1;
|
|
|
|
|