From a823bc7bd268975d035582e84d3d96149c9f231e Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 20 Dec 2022 22:48:43 +0000 Subject: __ntapi_tt_fork(): changed signature: record cid, return native status code. --- src/process/ntapi_tt_fork_v1.c | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src/process/ntapi_tt_fork_v1.c') diff --git a/src/process/ntapi_tt_fork_v1.c b/src/process/ntapi_tt_fork_v1.c index d017cf0..7662b72 100644 --- a/src/process/ntapi_tt_fork_v1.c +++ b/src/process/ntapi_tt_fork_v1.c @@ -40,7 +40,7 @@ static intptr_t __tt_fork_cancel(void * hprocess,int32_t status) { __ntapi->zw_terminate_process(hprocess, status); __ntapi->zw_close(hprocess); - return (intptr_t)(-1); + return status; } __attr_protected__ @@ -62,6 +62,9 @@ intptr_t __fastcall __tt_fork_impl_v1( nt_client_id cid; nt_large_integer timeout; + cid.process_id = 0; + cid.thread_id = 0; + hprocess = 0; hthread = 0; @@ -78,7 +81,7 @@ intptr_t __fastcall __tt_fork_impl_v1( &oa, NT_CURRENT_PROCESS_HANDLE, 1,0,0,0))) - return (intptr_t)(-1); + return status; if ((status = __ntapi->zw_query_information_process( hprocess, @@ -129,7 +132,6 @@ intptr_t __fastcall __tt_fork_impl_v1( 0, 0, &timeout))) return __tt_fork_cancel(hprocess,status); - if ((status = __ntapi->zw_create_thread( &hthread, NT_THREAD_ALL_ACCESS, @@ -141,21 +143,25 @@ intptr_t __fastcall __tt_fork_impl_v1( if (cid.process_id > 0) { __internals->hany[0] = hprocess; __internals->hany[1] = hthread; + __internals->hany[2] = (void *)cid.process_id; + __internals->hany[3] = (void *)cid.thread_id; } else { __internals->hany[0] = 0; __internals->hany[1] = 0; + __internals->hany[2] = 0; + __internals->hany[3] = 0; } /* hoppla */ - return (int32_t)cid.process_id; + return NT_STATUS_SUCCESS; } -intptr_t __fastcall __ntapi_tt_fork_v1( +int32_t __fastcall __ntapi_tt_fork_v1( __out void ** hprocess, - __out void ** hthread) + __out void ** hthread, + __out nt_cid * cid) { int32_t status; - intptr_t pid; nt_large_integer timeout; void ** hport_session; void * htty_connected; @@ -172,24 +178,32 @@ intptr_t __fastcall __ntapi_tt_fork_v1( &(nt_timeout){{0,0}}); if (hport_session && *hport_session) { - if (__ntapi_tt_create_inheritable_event( + status = __ntapi_tt_create_inheritable_event( &htty_connected, NT_NOTIFICATION_EVENT, - NT_EVENT_NOT_SIGNALED)) { + NT_EVENT_NOT_SIGNALED); + + if (status) { at_store(&__internals->hlock,0); - return (intptr_t)(-1); + return status; } } - pid = __tt_fork_v1(); + if ((status = __tt_fork_v1())) { + at_store(&__internals->hlock,0); + return status; + } *hprocess = __internals->hany[0]; *hthread = __internals->hany[1]; + cid->process_id = (uintptr_t)__internals->hany[2]; + cid->thread_id = (uintptr_t)__internals->hany[3]; + at_store(&__internals->hlock,0); if (hport_session && *hport_session) { - if (pid == 0) { + if (cid->process_id == 0) { if ((status = __ntapi->tty_connect( hport_session, __internals->subsystem->base_named_objects, @@ -205,7 +219,7 @@ intptr_t __fastcall __ntapi_tt_fork_v1( htty_connected, 0); - } else if (pid > 0) { + } else { status = __ntapi->zw_wait_for_single_object( htty_connected, NT_SYNC_NON_ALERTABLE, @@ -216,11 +230,11 @@ intptr_t __fastcall __ntapi_tt_fork_v1( htty_connected, NT_SYNC_NON_ALERTABLE, 0))) - pid = __tt_fork_cancel(*hprocess,status); + status = __tt_fork_cancel(*hprocess,status); } __ntapi->zw_close(htty_connected); } - return pid; + return status; } -- cgit v1.2.3