diff options
author | midipix <writeonce@midipix.org> | 2022-12-20 22:48:43 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2022-12-21 01:03:29 +0000 |
commit | a823bc7bd268975d035582e84d3d96149c9f231e (patch) | |
tree | c19eec97ccb36004888fd3be3ca3961ca81f0bbe /src/process/ntapi_tt_fork.c | |
parent | 1717a8ab178466bb73fd4c0a7fba1402df9deef0 (diff) | |
download | ntapi-a823bc7bd268975d035582e84d3d96149c9f231e.tar.bz2 ntapi-a823bc7bd268975d035582e84d3d96149c9f231e.tar.xz |
__ntapi_tt_fork(): changed signature: record cid, return native status code.
Diffstat (limited to 'src/process/ntapi_tt_fork.c')
-rw-r--r-- | src/process/ntapi_tt_fork.c | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/src/process/ntapi_tt_fork.c b/src/process/ntapi_tt_fork.c index e503508..20c7c25 100644 --- a/src/process/ntapi_tt_fork.c +++ b/src/process/ntapi_tt_fork.c @@ -1,3 +1,4 @@ + /********************************************************/ /* ntapi: Native API core library */ /* Copyright (C) 2013--2021 SysDeer Technologies, LLC */ @@ -29,7 +30,7 @@ static int __ipc_memfn( return DALIST_EMEMFN; } -static intptr_t __fastcall __ntapi_tt_fork_finalize(void ** hprocess) +static int32_t __fastcall __ntapi_tt_fork_finalize(void ** hprocess) { int32_t status; int page; @@ -89,7 +90,7 @@ static intptr_t __fastcall __ntapi_tt_fork_finalize(void ** hprocess) rtdata->ipc_keys[4] = 0; rtdata->ipc_keys[5] = 0; - return 0; + return NT_STATUS_SUCCESS; } static int32_t __stdcall __fork_thread(void * ctx) @@ -112,7 +113,7 @@ static int32_t __stdcall __fork_thread(void * ctx) hready,0)); } -static intptr_t __fastcall __ntapi_tt_fork_child( +static int32_t __fastcall __ntapi_tt_fork_child( void * hresumed, void * hready, void ** hthread) @@ -185,7 +186,7 @@ static intptr_t __fastcall __ntapi_tt_fork_child( __ntapi->zw_close(hresumed); __ntapi->zw_close(hready); __ntapi->zw_close(tparams.hthread); - return 0; + return NT_STATUS_SUCCESS; } timeout.quad = (-1) * 10 * 1000 * 250; @@ -199,7 +200,7 @@ static intptr_t __fastcall __ntapi_tt_fork_child( __ntapi->zw_close(hresumed); __ntapi->zw_close(hready); __ntapi->zw_close(tparams.hthread); - return 0; + return NT_STATUS_SUCCESS; } __ntapi->zw_terminate_thread( @@ -217,7 +218,7 @@ static intptr_t __fastcall __ntapi_tt_fork_child( __ntapi->zw_close(hresumed); __ntapi->zw_close(hready); __ntapi->zw_close(tparams.hthread); - return 0; + return NT_STATUS_SUCCESS; } return __ntapi->zw_terminate_process( @@ -248,11 +249,8 @@ static intptr_t __fastcall __ntapi_tt_fork_parent( NT_SYNC_NON_ALERTABLE, &timeout); - if (status == NT_STATUS_SUCCESS) { - __ntapi->zw_close(hresumed); - __ntapi->zw_close(hready); + if (status == NT_STATUS_SUCCESS) return NT_STATUS_SUCCESS; - } __ntapi->zw_suspend_thread( *hthread,&prev); @@ -271,8 +269,6 @@ static intptr_t __fastcall __ntapi_tt_fork_parent( __ntapi->zw_resume_thread( *hthread,0); - __ntapi->zw_close(hresumed); - __ntapi->zw_close(hready); return NT_STATUS_SUCCESS; } @@ -289,12 +285,12 @@ static intptr_t __fastcall __ntapi_tt_fork_parent( return status; } -intptr_t __fastcall __ntapi_tt_fork( +int32_t __fastcall __ntapi_tt_fork( __out void ** hprocess, - __out void ** hthread) + __out void ** hthread, + __out nt_cid * cid) { int32_t status; - intptr_t pid; void * hresumed; void * hready; int i; @@ -303,42 +299,47 @@ intptr_t __fastcall __ntapi_tt_fork( &hresumed, NT_NOTIFICATION_EVENT, NT_EVENT_NOT_SIGNALED))) - return -1; + return status; if ((status = __ntapi->tt_create_inheritable_event( &hready, NT_NOTIFICATION_EVENT, NT_EVENT_NOT_SIGNALED))) - return -1; + return status; for (i=0; i<32; i++) { if (__ntapi->zw_create_user_process) - pid = __ntapi_tt_fork_v2(hprocess,hthread); + status = __ntapi_tt_fork_v2(hprocess,hthread,cid); else - pid = __ntapi_tt_fork_v1(hprocess,hthread); + status = __ntapi_tt_fork_v1(hprocess,hthread,cid); - if (pid == 0) { + if (status) { + __ntapi->zw_close(hresumed); + __ntapi->zw_close(hready); + return status; + } + + if (cid->process_id == 0) { __ntapi_tt_fork_child( hresumed,hready,hthread); return __ntapi_tt_fork_finalize( hprocess); + } - } else if (pid > 0) { - if (!(__ntapi_tt_fork_parent( - hprocess,hthread, - hresumed,hready))) - return pid; + status = __ntapi_tt_fork_parent( + hprocess,hthread, + hresumed,hready); - } else { + if (status == NT_STATUS_SUCCESS) { __ntapi->zw_close(hresumed); __ntapi->zw_close(hready); - return -1; + return NT_STATUS_SUCCESS; } } __ntapi->zw_close(hresumed); __ntapi->zw_close(hready); - return -1; + return NT_STATUS_UNSUCCESSFUL; } |