mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
This test case test ROS' ability to duplicate a process handle, give the
handle to the child process, then have the child process give back its own handle. This is used by cygwin during fork and vfork. svn path=/trunk/; revision=6484
This commit is contained in:
parent
cef6a8899c
commit
0f8d274449
2 changed files with 88 additions and 0 deletions
21
reactos/apps/tests/p_dup_handle/makefile
Normal file
21
reactos/apps/tests/p_dup_handle/makefile
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# $Id: makefile,v 1.1 2003/10/31 21:41:32 arty Exp $
|
||||||
|
|
||||||
|
PATH_TO_TOP = ../../..
|
||||||
|
|
||||||
|
TARGET_NORC = yes
|
||||||
|
|
||||||
|
TARGET_TYPE = program
|
||||||
|
|
||||||
|
TARGET_APPTYPE = console
|
||||||
|
|
||||||
|
TARGET_NAME = p_dup_handle
|
||||||
|
|
||||||
|
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
|
67
reactos/apps/tests/p_dup_handle/p_dup_handle.c
Normal file
67
reactos/apps/tests/p_dup_handle/p_dup_handle.c
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
/* This tests the ability of the target win32 to duplicate a process handle,
|
||||||
|
* spawn a child, and have the child dup it's own handle back into the parent
|
||||||
|
* using the duplicated handle.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main( int argc, char **argv ) {
|
||||||
|
HANDLE h_process;
|
||||||
|
HANDLE h_process_in_parent;
|
||||||
|
|
||||||
|
fprintf( stderr, "%d: Starting\n", GetCurrentProcessId() );
|
||||||
|
|
||||||
|
if( argc == 2 ) {
|
||||||
|
h_process = atoi(argv[1]);
|
||||||
|
} else {
|
||||||
|
if( !DuplicateHandle( GetCurrentProcess(),
|
||||||
|
GetCurrentProcess(),
|
||||||
|
GetCurrentProcess(),
|
||||||
|
&h_process,
|
||||||
|
0,
|
||||||
|
TRUE,
|
||||||
|
DUPLICATE_SAME_ACCESS) ) {
|
||||||
|
fprintf( stderr, "%d: Could not duplicate my own process handle.\n",
|
||||||
|
GetCurrentProcessId() );
|
||||||
|
return 101;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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], h_process );
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if( !DuplicateHandle( GetCurrentProcess(),
|
||||||
|
GetCurrentProcess(),
|
||||||
|
h_process,
|
||||||
|
&h_process_in_parent,
|
||||||
|
0,
|
||||||
|
TRUE,
|
||||||
|
DUPLICATE_SAME_ACCESS) ) {
|
||||||
|
fprintf( stderr, "%d: Could not duplicate my handle into the parent.\n",
|
||||||
|
GetCurrentProcessId() );
|
||||||
|
return 102;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue