summaryrefslogtreecommitdiffhomepage
path: root/src/process
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-01-24 00:58:24 +0000
committermidipix <writeonce@midipix.org>2024-01-24 02:11:15 +0000
commita88bfbe7ee71556de2ff764d9527af37ab995d87 (patch)
tree872baae3b2d78fb05d6e40ebd7f08ca63c7d4b5a /src/process
parentb862c7314cd69af6b09e4a02b7868fbbe157e220 (diff)
downloadntapi-a88bfbe7ee71556de2ff764d9527af37ab995d87.tar.bz2
ntapi-a88bfbe7ee71556de2ff764d9527af37ab995d87.tar.xz
__ntapi_tt_spawn_native_process(): refactor __tt_spawn_return().
Diffstat (limited to 'src/process')
-rw-r--r--src/process/ntapi_tt_spawn_native_process.c68
1 files changed, 47 insertions, 21 deletions
diff --git a/src/process/ntapi_tt_spawn_native_process.c b/src/process/ntapi_tt_spawn_native_process.c
index 76bbbc4..6472dd7 100644
--- a/src/process/ntapi_tt_spawn_native_process.c
+++ b/src/process/ntapi_tt_spawn_native_process.c
@@ -23,6 +23,7 @@
static int32_t __stdcall __tt_spawn_return(
nt_runtime_data_block * rtblock,
+ void * himgfile,
void * hprocess,
void * hthread,
int32_t status)
@@ -43,6 +44,9 @@ static int32_t __stdcall __tt_spawn_return(
__ntapi->zw_close(
rtdata->hready);
+ if (himgfile)
+ __ntapi->zw_close(himgfile);
+
__ntapi->zw_free_virtual_memory(
NT_CURRENT_PROCESS_HANDLE,
&rtblock->addr,
@@ -66,6 +70,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
char * patharg;
void * hat;
void * hfile;
+ void * himgfile;
char * src;
char * dst;
int envc;
@@ -157,12 +162,19 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
imgbuf -= __SPAWN_NATIVE_PROCESS_RUNTIME_BLOCK_IMGBUF_SIZE / sizeof(*imgbuf);
/* hfile */
- if (sparams->himage)
- hfile = sparams->himage;
- else if ((status = __ntapi_tt_open_file_utf8(
+ if (sparams->himage) {
+ hfile = sparams->himage;
+ himgfile = 0;
+
+ } else if ((status = __ntapi_tt_open_file_utf8(
&hfile,hat,patharg,1,
- imgbuf,__SPAWN_NATIVE_PROCESS_RUNTIME_BLOCK_IMGBUF_SIZE)))
- return status;
+ imgbuf,__SPAWN_NATIVE_PROCESS_RUNTIME_BLOCK_IMGBUF_SIZE))) {
+ return __tt_spawn_return(
+ &rtblock,0,0,0,
+ status);
+
+ himgfile = hfile;
+ }
/* imgname */
if ((status = __ntapi->zw_query_object(
@@ -171,7 +183,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
imgbuf,__SPAWN_NATIVE_PROCESS_RUNTIME_BLOCK_IMGBUF_SIZE,
&(uint32_t){0})))
return __tt_spawn_return(
- &rtblock,0,0,status);
+ &rtblock,himgfile,0,0,
+ status);
imgname = (nt_unicode_string *)imgbuf;
@@ -190,7 +203,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
rdata->buffer,
buflen,&written)))
return __tt_spawn_return(
- &rtblock,0,0,status);
+ &rtblock,himgfile,0,0,
+ status);
rdata->argv = (char **)&((nt_runtime_data *)0)->buffer;
rdata->envp = rdata->argv + rdata->argc + 1;
@@ -210,7 +224,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
if ((written = (uintptr_t)wch - (uintptr_t)rdata) > rtblock.size)
return __tt_spawn_return(
- &rtblock,0,0,NT_STATUS_BUFFER_TOO_SMALL);
+ &rtblock,himgfile,0,0,
+ NT_STATUS_BUFFER_TOO_SMALL);
buflen = rtblock.size;
buflen -= written;
@@ -221,7 +236,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
rdata,wch,
buflen,&written)))
return __tt_spawn_return(
- &rtblock,0,0,status);
+ &rtblock,himgfile,0,0,
+ status);
wch += written/sizeof(wchar16_t);
buflen -= written;
@@ -232,7 +248,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
rdata,wch,
buflen,&written)))
return __tt_spawn_return(
- &rtblock,0,0,status);
+ &rtblock,himgfile,0,0,
+ status);
rdata->wargv -= (uintptr_t)rtblock.addr / sizeof(wchar16_t *);
rdata->wenvp -= (uintptr_t)rtblock.addr / sizeof(wchar16_t *);
@@ -263,7 +280,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
if (buflen < needed)
return __tt_spawn_return(
- &rtblock,0,0,NT_STATUS_BUFFER_TOO_SMALL);
+ &rtblock,himgfile,0,0,
+ NT_STATUS_BUFFER_TOO_SMALL);
rdata->w32_envp = (char **)(addr - (uintptr_t)rtblock.addr);
@@ -286,7 +304,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
if (buflen < __SPAWN_NATIVE_PROCESS_RUNTIME_BLOCK_IMGBUF_SIZE)
return __tt_spawn_return(
- &rtblock,0,0,NT_STATUS_BUFFER_TOO_SMALL);
+ &rtblock,himgfile,0,0,
+ NT_STATUS_BUFFER_TOO_SMALL);
/* session */
if (sparams->hready) {
@@ -298,14 +317,16 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
0,0,
NT_DUPLICATE_SAME_ACCESS|NT_DUPLICATE_SAME_ATTRIBUTES)))
return __tt_spawn_return(
- &rtblock,0,0,status);
+ &rtblock,himgfile,0,0,
+ status);
} else {
if ((status = __ntapi->tt_create_inheritable_event(
&rdata->hready,
NT_NOTIFICATION_EVENT,
NT_EVENT_NOT_SIGNALED)))
return __tt_spawn_return(
- &rtblock,0,0,status);
+ &rtblock,himgfile,0,0,
+ status);
}
/* process flags */
@@ -342,11 +363,8 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
/* hoppla */
if ((status = __ntapi->tt_create_native_process(&cparams)))
return __tt_spawn_return(
- &rtblock,0,0,status);
-
- /* tidy up */
- if (!sparams->himage)
- __ntapi->zw_close(hfile);
+ &rtblock,himgfile,0,0,
+ status);
/* debug */
if (sparams->spawnflags & NT_PROCESS_SPAWN_FLAG_DEBUG_MASK)
@@ -356,6 +374,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
NT_DEBUG_KILL_ON_EXIT)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -377,6 +396,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
NT_PAGE_READWRITE)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -389,6 +409,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
&rdata->ctx_size)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -405,6 +426,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
rsize,&rsize)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -418,6 +440,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
0,NT_TTY_INHERIT_HANDLES,0)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -432,6 +455,7 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
&session)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -453,12 +477,13 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
/* create suspended? */
if (fsuspended)
return __tt_spawn_return(
- &rtblock,0,0,NT_STATUS_SUCCESS);
+ &rtblock,himgfile,0,0,NT_STATUS_SUCCESS);
/* tada */
if ((status = __ntapi->zw_resume_thread(cparams.hthread,0)))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
@@ -481,11 +506,12 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
&(size_t){0})))
return __tt_spawn_return(
&rtblock,
+ himgfile,
cparams.hprocess,
cparams.hthread,
status);
/* all done */
return __tt_spawn_return(
- &rtblock,0,0,NT_STATUS_SUCCESS);
+ &rtblock,himgfile,0,0,NT_STATUS_SUCCESS);
}