Skip to content

Commit

Permalink
Steve Hay's patch to detect fork capabilities
Browse files Browse the repository at this point in the history
Patch is 79f8362,
I slightly reworked it to include the fork detection
code in Win32::API::Test, which seemed appropriate to me.
  • Loading branch information
cosimo committed Oct 16, 2012
1 parent 79f8362 commit 59f21be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
12 changes: 8 additions & 4 deletions Callback/t/iat.t
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,18 @@ is($patch->GetOriginalFunctionPtr(),

SKIP: {
Win32::API::Type->typedef('PRTL_PROCESS_MODULES', 'char *');

my $LdrQueryProcessModuleInformation =
Win32::API::More->new("ntdll.dll",
"NTSTATUS NTAPI LdrQueryProcessModuleInformation(".
"PRTL_PROCESS_MODULES ModuleInformation,
ULONG Size, PULONG ReturnedSize)");
skip("This Perl doesn't have ithreads and/or this Windows OS doesn't have "
."LdrQueryProcessModuleInformation", 6) if ! $Config{'useithreads'}
|| ! $LdrQueryProcessModuleInformation; #Native API changed, thats ok

skip("This Perl doesn't have fork and/or this Windows OS "
. " doesn't have LdrQueryProcessModuleInformation", 6)
if ! Win32::API::Test::can_fork()
|| ! $LdrQueryProcessModuleInformation; #Native API changed, thats ok

is(GetAPITestDLLLoadCount($LdrQueryProcessModuleInformation), 1,
"DLL load count is 1 before fork");
my ($child, $parent);
Expand Down Expand Up @@ -213,4 +217,4 @@ sub GetAPITestDLLLoadCount{
return $_->{LoadCount};
}
}
}
}
22 changes: 13 additions & 9 deletions Callback/t/ithreads.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ use strict;
use warnings;

use Win32::API::Callback;
use Win32::API::Test;
use Test::More;
use Config;

plan tests => 1;
#this test was originally useless without the Windows debugging heap, by
#raising the alloc size to 50 MB, a call to the paging system is forced
#a double free will get access violation rather THAN no symptoms failure mode of
#VirtualAlloced but freed Heap memory

#HeapBlock class is not public API
# This test was originally useless without the Windows debugging heap, by
# raising the alloc size to 50 MB, a call to the paging system is forced
# a double free will get access violation rather THAN no symptoms failure mode of
# VirtualAlloced but freed Heap memory

SKIP: {
skip("This Perl doesn't have ithreads", 1) if ! $Config{'useithreads'};
#50 megs should be enough to force a VirtualAlloc and a VirtualFree
skip("This Perl doesn't have fork", 1) if ! Win32::API::Test::can_fork();

# HeapBlock class is not public API

# 50 megs should be enough to force a VirtualAlloc and a VirtualFree
my $ptrobj = new Win32::API::Callback::HeapBlock 5000000;
my $pid = fork();
if($pid) {
if ($pid) {
print "in parent\n";
{ #block to force destruction on scope leave
undef($ptrobj);
}
ok("didn't crash");
}
else{
else {
print "in child\n";
{ #block to force destruction on scope leave
undef($ptrobj);
Expand Down
10 changes: 10 additions & 0 deletions Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ sub is_perl_64bit () {
return;
}

sub can_fork () {
use Config;

my $native = $Config{d_fork} || $Config{d_pseudofork};
my $win32 = ($^O eq 'MSWin32' || $^O eq 'NetWare');
my $ithr = $Config{useithreads} and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/;

return $native || ($win32 and $ithr);
}

sub compiler_name () {
use Config;
my $cc = $Config{ccname};
Expand Down

0 comments on commit 59f21be

Please sign in to comment.