ab112c8e96148e75ddf54e9adff371ac3170bde0
4 /* This tests the ability of the target win32 to create an anonymous file
5 * mapping, create a mapping view with MapViewOfFile, and then realize the
6 * pages with VirtualAlloc.
9 int main( int argc
, char **argv
) {
14 fprintf( stderr
, "%d: Starting\n", GetCurrentProcessId() );
17 file_map
= atoi(argv
[1]);
19 file_map
= CreateFileMapping( INVALID_HANDLE_VALUE
,
21 PAGE_READWRITE
| SEC_RESERVE
,
23 if( !SetHandleInformation( file_map
,
25 HANDLE_FLAG_INHERIT
) ) {
26 fprintf( stderr
, "%d: Could not make handle inheritable.\n",
27 GetCurrentProcessId() );
33 fprintf( stderr
, "%d: Could not create anonymous file map.\n",
34 GetCurrentProcessId() );
38 file_view
= MapViewOfFile( file_map
,
45 fprintf( stderr
, "%d: Could not map view of file.\n",
46 GetCurrentProcessId() );
50 if( !VirtualAlloc( file_view
, 0x1000, MEM_COMMIT
, PAGE_READWRITE
) ) {
51 fprintf( stderr
, "%d: VirtualAlloc failed to realize the page.\n",
52 GetCurrentProcessId() );
59 if( x
[0] != 0x12345678 ) {
60 fprintf( stderr
, "%d: Can't write to the memory (%08x != 0x12345678)\n",
61 GetCurrentProcessId() );
67 PROCESS_INFORMATION pi
;
70 memset( &si
, 0, sizeof( si
) );
71 memset( &pi
, 0, sizeof( pi
) );
73 sprintf(cmdline
,"%s %d", argv
[0], (int)file_map
);
74 if( !CreateProcess(NULL
, cmdline
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
,
76 fprintf( stderr
, "%d: Could not create child process.\n",
77 GetCurrentProcessId() );
81 if( WaitForSingleObject( pi
.hThread
, INFINITE
) != WAIT_OBJECT_0
) {
82 fprintf( stderr
, "%d: Failed to wait for child process to terminate.\n",
83 GetCurrentProcessId() );