6 /* This tests the ability of the target win32 to duplicate a process handle,
7 * spawn a child, and have the child dup it's own handle back into the parent
8 * using the duplicated handle.
11 int main( int argc
, char **argv
) {
13 HANDLE h_process_in_parent
;
15 fprintf( stderr
, "%lu: Starting\n", GetCurrentProcessId() );
18 h_process
= (HANDLE
)atoi(argv
[1]);
20 if( !DuplicateHandle( GetCurrentProcess(),
26 DUPLICATE_SAME_ACCESS
) ) {
27 fprintf( stderr
, "%lu: Could not duplicate my own process handle.\n",
28 GetCurrentProcessId() );
35 PROCESS_INFORMATION pi
;
38 memset( &si
, 0, sizeof( si
) );
39 memset( &pi
, 0, sizeof( pi
) );
41 sprintf( cmdline
, "%s %lu", argv
[0], (DWORD
)h_process
);
42 if( !CreateProcess(NULL
, cmdline
, NULL
, NULL
, TRUE
, 0, NULL
, NULL
,
44 fprintf( stderr
, "%lu: Could not create child process.\n",
45 GetCurrentProcessId() );
49 if( WaitForSingleObject( pi
.hThread
, INFINITE
) != WAIT_OBJECT_0
) {
50 fprintf( stderr
, "%lu: Failed to wait for child process to terminate.\n",
51 GetCurrentProcessId() );
55 if( !DuplicateHandle( GetCurrentProcess(),
61 DUPLICATE_SAME_ACCESS
) ) {
62 fprintf( stderr
, "%lu: Could not duplicate my handle into the parent.\n",
63 GetCurrentProcessId() );