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() );
19 file_map
= (void *)atoi(argv
[1]);
21 file_map
= CreateFileMapping( INVALID_HANDLE_VALUE
,
23 PAGE_READWRITE
| SEC_RESERVE
,
25 if( !SetHandleInformation( file_map
,
27 HANDLE_FLAG_INHERIT
) ) {
28 fprintf( stderr
, "%lu: Could not make handle inheritable.\n",
29 GetCurrentProcessId() );
35 fprintf( stderr
, "%lu: Could not create anonymous file map.\n",
36 GetCurrentProcessId() );
40 file_view
= MapViewOfFile( file_map
,
47 fprintf( stderr
, "%lu: Could not map view of file.\n",
48 GetCurrentProcessId() );
52 if( !VirtualAlloc( file_view
, 0x1000, MEM_COMMIT
, PAGE_READWRITE
) ) {
53 fprintf( stderr
, "%lu: VirtualAlloc failed to realize the page.\n",
54 GetCurrentProcessId() );
61 if( x
[0] != 0x12345678 ) {
62 fprintf( stderr
, "%lu: Can't write to the memory (%08x != 0x12345678)\n",
63 GetCurrentProcessId(), x
[0] );
69 PROCESS_INFORMATION pi
;
72 memset( &si
, 0, sizeof( si
) );
73 memset( &pi
, 0, sizeof( pi
) );
75 sprintf(cmdline
,"%s %d", argv
[0], (int)file_map
);
76 if( !CreateProcess(NULL
, cmdline
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
,
78 fprintf( stderr
, "%lu: Could not create child process.\n",
79 GetCurrentProcessId() );
83 if( WaitForSingleObject( pi
.hThread
, INFINITE
) != WAIT_OBJECT_0
) {
84 fprintf( stderr
, "%lu: Failed to wait for child process to terminate.\n",
85 GetCurrentProcessId() );