@@ -391,154 +391,6 @@ fn test_interior_nul_in_env_value_is_error() {
391391 }
392392}
393393
394- /// Tests that process creation flags work by debugging a process.
395- /// Other creation flags make it hard or impossible to detect
396- /// behavioral changes in the process.
397- #[ test]
398- #[ cfg( windows) ]
399- fn test_creation_flags ( ) {
400- use crate :: os:: windows:: process:: CommandExt ;
401- use crate :: sys:: c:: { BOOL , INFINITE } ;
402- #[ repr( C ) ]
403- struct DEBUG_EVENT {
404- pub event_code : u32 ,
405- pub process_id : u32 ,
406- pub thread_id : u32 ,
407- // This is a union in the real struct, but we don't
408- // need this data for the purposes of this test.
409- pub _junk : [ u8 ; 164 ] ,
410- }
411-
412- extern "system" {
413- fn WaitForDebugEvent ( lpDebugEvent : * mut DEBUG_EVENT , dwMilliseconds : u32 ) -> BOOL ;
414- fn ContinueDebugEvent ( dwProcessId : u32 , dwThreadId : u32 , dwContinueStatus : u32 ) -> BOOL ;
415- }
416-
417- const DEBUG_PROCESS : u32 = 1 ;
418- const EXIT_PROCESS_DEBUG_EVENT : u32 = 5 ;
419- const DBG_EXCEPTION_NOT_HANDLED : u32 = 0x80010001 ;
420-
421- let mut child = Command :: new ( "cmd" )
422- . creation_flags ( DEBUG_PROCESS )
423- . stdin ( Stdio :: piped ( ) )
424- . stdout ( Stdio :: null ( ) )
425- . stderr ( Stdio :: null ( ) )
426- . spawn ( )
427- . unwrap ( ) ;
428- child. stdin . take ( ) . unwrap ( ) . write_all ( b"exit\r \n " ) . unwrap ( ) ;
429- let mut events = 0 ;
430- let mut event = DEBUG_EVENT { event_code : 0 , process_id : 0 , thread_id : 0 , _junk : [ 0 ; 164 ] } ;
431- loop {
432- if unsafe { WaitForDebugEvent ( & mut event as * mut DEBUG_EVENT , INFINITE ) } == 0 {
433- panic ! ( "WaitForDebugEvent failed!" ) ;
434- }
435- events += 1 ;
436-
437- if event. event_code == EXIT_PROCESS_DEBUG_EVENT {
438- break ;
439- }
440-
441- if unsafe {
442- ContinueDebugEvent ( event. process_id , event. thread_id , DBG_EXCEPTION_NOT_HANDLED )
443- } == 0
444- {
445- panic ! ( "ContinueDebugEvent failed!" ) ;
446- }
447- }
448- assert ! ( events > 0 ) ;
449- }
450-
451- /// Tests proc thread attributes by spawning a process with a custom parent process,
452- /// then comparing the parent process ID with the expected parent process ID.
453- #[ test]
454- #[ cfg( windows) ]
455- fn test_proc_thread_attributes ( ) {
456- use crate :: mem;
457- use crate :: os:: windows:: io:: AsRawHandle ;
458- use crate :: os:: windows:: process:: { CommandExt , ProcThreadAttributeList } ;
459- use crate :: sys:: c:: { BOOL , CloseHandle , HANDLE } ;
460- use crate :: sys:: cvt;
461-
462- #[ repr( C ) ]
463- #[ allow( non_snake_case) ]
464- struct PROCESSENTRY32W {
465- dwSize : u32 ,
466- cntUsage : u32 ,
467- th32ProcessID : u32 ,
468- th32DefaultHeapID : usize ,
469- th32ModuleID : u32 ,
470- cntThreads : u32 ,
471- th32ParentProcessID : u32 ,
472- pcPriClassBase : i32 ,
473- dwFlags : u32 ,
474- szExeFile : [ u16 ; 260 ] ,
475- }
476-
477- extern "system" {
478- fn CreateToolhelp32Snapshot ( dwflags : u32 , th32processid : u32 ) -> HANDLE ;
479- fn Process32First ( hsnapshot : HANDLE , lppe : * mut PROCESSENTRY32W ) -> BOOL ;
480- fn Process32Next ( hsnapshot : HANDLE , lppe : * mut PROCESSENTRY32W ) -> BOOL ;
481- }
482-
483- const PROC_THREAD_ATTRIBUTE_PARENT_PROCESS : usize = 0x00020000 ;
484- const TH32CS_SNAPPROCESS : u32 = 0x00000002 ;
485-
486- struct ProcessDropGuard ( crate :: process:: Child ) ;
487-
488- impl Drop for ProcessDropGuard {
489- fn drop ( & mut self ) {
490- let _ = self . 0 . kill ( ) ;
491- }
492- }
493-
494- let mut parent = Command :: new ( "cmd" ) ;
495- parent. stdout ( Stdio :: null ( ) ) . stderr ( Stdio :: null ( ) ) ;
496-
497- let parent = ProcessDropGuard ( parent. spawn ( ) . unwrap ( ) ) ;
498-
499- let mut child_cmd = Command :: new ( "cmd" ) ;
500- child_cmd. stdout ( Stdio :: null ( ) ) . stderr ( Stdio :: null ( ) ) ;
501-
502- let parent_process_handle = parent. 0 . as_raw_handle ( ) ;
503-
504- let mut attribute_list = ProcThreadAttributeList :: build ( )
505- . attribute ( PROC_THREAD_ATTRIBUTE_PARENT_PROCESS , & parent_process_handle)
506- . finish ( )
507- . unwrap ( ) ;
508-
509- let child = ProcessDropGuard ( child_cmd. spawn_with_attributes ( & mut attribute_list) . unwrap ( ) ) ;
510-
511- let h_snapshot = unsafe { CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS , 0 ) } ;
512-
513- let mut process_entry = PROCESSENTRY32W {
514- dwSize : mem:: size_of :: < PROCESSENTRY32W > ( ) as u32 ,
515- cntUsage : 0 ,
516- th32ProcessID : 0 ,
517- th32DefaultHeapID : 0 ,
518- th32ModuleID : 0 ,
519- cntThreads : 0 ,
520- th32ParentProcessID : 0 ,
521- pcPriClassBase : 0 ,
522- dwFlags : 0 ,
523- szExeFile : [ 0 ; 260 ] ,
524- } ;
525-
526- unsafe { cvt ( Process32First ( h_snapshot, & mut process_entry as * mut _ ) ) } . unwrap ( ) ;
527-
528- loop {
529- if child. 0 . id ( ) == process_entry. th32ProcessID {
530- break ;
531- }
532- unsafe { cvt ( Process32Next ( h_snapshot, & mut process_entry as * mut _ ) ) } . unwrap ( ) ;
533- }
534-
535- unsafe { cvt ( CloseHandle ( h_snapshot) ) } . unwrap ( ) ;
536-
537- assert_eq ! ( parent. 0 . id( ) , process_entry. th32ParentProcessID) ;
538-
539- drop ( child)
540- }
541-
542394#[ test]
543395fn test_command_implements_send_sync ( ) {
544396 fn take_send_sync_type < T : Send + Sync > ( _: T ) { }
0 commit comments