6 /* This tests the ability of the target win32 to create an anonymous file
7 * mapping, create a mapping view with MapViewOfFile, and then realize the
8 * pages with VirtualAlloc.
11 int main( int argc
, char **argv
) {
16 fprintf( stderr
, "%lu: Starting\n", GetCurrentProcessId() );
20 file_map
= (void *)_atoi64(argv
[1]);
22 file_map
= (void *)UlongToPtr(atoi(argv
[1]));
25 file_map
= CreateFileMapping( INVALID_HANDLE_VALUE
,
27 PAGE_READWRITE
| SEC_RESERVE
,
29 if( !SetHandleInformation( file_map
,
31 HANDLE_FLAG_INHERIT
) ) {
32 fprintf( stderr
, "%lu: Could not make handle inheritable.\n",
33 GetCurrentProcessId() );
39 fprintf( stderr
, "%lu: Could not create anonymous file map.\n",
40 GetCurrentProcessId() );
44 file_view
= MapViewOfFile( file_map
,
51 fprintf( stderr
, "%lu: Could not map view of file.\n",
52 GetCurrentProcessId() );
53 if (file_map
!= INVALID_HANDLE_VALUE
)
54 CloseHandle(file_map
);
58 if( !VirtualAlloc( file_view
, 0x1000, MEM_COMMIT
, PAGE_READWRITE
) ) {
59 fprintf( stderr
, "%lu: VirtualAlloc failed to realize the page.\n",
60 GetCurrentProcessId() );
61 if (file_map
!= INVALID_HANDLE_VALUE
)
62 CloseHandle(file_map
);
69 if( x
[0] != 0x12345678 ) {
70 fprintf( stderr
, "%lu: Can't write to the memory (%08x != 0x12345678)\n",
71 GetCurrentProcessId(), x
[0] );
77 PROCESS_INFORMATION pi
;
80 memset( &si
, 0, sizeof( si
) );
81 memset( &pi
, 0, sizeof( pi
) );
83 sprintf(cmdline
,"%s %p", argv
[0], file_map
);
84 CloseHandle(file_map
);
86 if( !CreateProcess(NULL
, cmdline
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
,
88 fprintf( stderr
, "%lu: Could not create child process.\n",
89 GetCurrentProcessId() );
90 if (pi
.hProcess
!= INVALID_HANDLE_VALUE
)
91 CloseHandle(pi
.hProcess
);
96 if( WaitForSingleObject( pi
.hThread
, INFINITE
) != WAIT_OBJECT_0
) {
97 fprintf( stderr
, "%lu: Failed to wait for child process to terminate.\n",
98 GetCurrentProcessId() );
99 if (pi
.hProcess
!= INVALID_HANDLE_VALUE
)
100 CloseHandle(pi
.hProcess
);
104 if (pi
.hProcess
!= INVALID_HANDLE_VALUE
)
105 CloseHandle(pi
.hProcess
);