diff --git a/reactos/apps/tests/map_dup_inherit/makefile b/reactos/apps/tests/map_dup_inherit/makefile new file mode 100644 index 00000000000..c7d945a3f6e --- /dev/null +++ b/reactos/apps/tests/map_dup_inherit/makefile @@ -0,0 +1,21 @@ +# $Id: makefile,v 1.1 2003/10/31 20:26:14 arty Exp $ + +PATH_TO_TOP = ../../.. + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = map_dup_inherit + +TARGET_SDKLIBS = kernel32.a gdi32.a ntdll.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/reactos/apps/tests/map_dup_inherit/map_dup_inherit.c b/reactos/apps/tests/map_dup_inherit/map_dup_inherit.c new file mode 100644 index 00000000000..ab112c8e961 --- /dev/null +++ b/reactos/apps/tests/map_dup_inherit/map_dup_inherit.c @@ -0,0 +1,89 @@ +#include +#include + +/* This tests the ability of the target win32 to create an anonymous file + * mapping, create a mapping view with MapViewOfFile, and then realize the + * pages with VirtualAlloc. + */ + +int main( int argc, char **argv ) { + HANDLE file_view; + void *file_map; + int *x; + + fprintf( stderr, "%d: Starting\n", GetCurrentProcessId() ); + + if( argc == 2 ) { + file_map = atoi(argv[1]); + } else { + file_map = CreateFileMapping( INVALID_HANDLE_VALUE, + NULL, + PAGE_READWRITE | SEC_RESERVE, + 0, 0x1000, NULL ); + if( !SetHandleInformation( file_map, + HANDLE_FLAG_INHERIT, + HANDLE_FLAG_INHERIT ) ) { + fprintf( stderr, "%d: Could not make handle inheritable.\n", + GetCurrentProcessId() ); + return 100; + } + } + + if( !file_map ) { + fprintf( stderr, "%d: Could not create anonymous file map.\n", + GetCurrentProcessId() ); + return 1; + } + + file_view = MapViewOfFile( file_map, + FILE_MAP_WRITE, + 0, + 0, + 0x1000 ); + + if( !file_view ) { + fprintf( stderr, "%d: Could not map view of file.\n", + GetCurrentProcessId() ); + return 2; + } + + if( !VirtualAlloc( file_view, 0x1000, MEM_COMMIT, PAGE_READWRITE ) ) { + fprintf( stderr, "%d: VirtualAlloc failed to realize the page.\n", + GetCurrentProcessId() ); + return 3; + } + + x = (int *)file_view; + x[0] = 0x12345678; + + if( x[0] != 0x12345678 ) { + fprintf( stderr, "%d: Can't write to the memory (%08x != 0x12345678)\n", + GetCurrentProcessId() ); + return 4; + } + + if( argc == 1 ) { + STARTUPINFO si; + PROCESS_INFORMATION pi; + char cmdline[1000]; + + memset( &si, 0, sizeof( si ) ); + memset( &pi, 0, sizeof( pi ) ); + + sprintf(cmdline,"%s %d", argv[0], (int)file_map); + if( !CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, + &si, &pi ) ) { + fprintf( stderr, "%d: Could not create child process.\n", + GetCurrentProcessId() ); + return 5; + } + + if( WaitForSingleObject( pi.hThread, INFINITE ) != WAIT_OBJECT_0 ) { + fprintf( stderr, "%d: Failed to wait for child process to terminate.\n", + GetCurrentProcessId() ); + return 6; + } + } + + return 0; +}