diff options
-rw-r--r-- | src/internal/ntapi.c | 16 | ||||
-rw-r--r-- | src/internal/ntapi_impl.h | 3 | ||||
-rw-r--r-- | src/ipc/ntapi_ipc_connect.c | 78 | ||||
-rw-r--r-- | src/process/ntapi_tt_fork.c | 14 |
4 files changed, 68 insertions, 43 deletions
diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index a808aa1..dfb614b 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -89,6 +89,18 @@ static union __ntapi_img_rdata __ntapi_rdata = {{ #define import_table __ntapi_rdata.img_sec_data.__ntapi_import_table +static int __ipc_memfn( + struct dalist_ex * dlist, + void ** addr, + size_t * alloc_size) +{ + (void)dlist; + (void)addr; + (void)alloc_size; + + return DALIST_EMEMFN; +} + static void __ntapi_init_adjust_privileges(void) { uintptr_t buffer[64]; @@ -181,7 +193,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) &internals->ipc_conns, sizeof(nt_ipc_conn), NT_ALLOCATION_GRANULARITY, - __ntapi_ipc_page_alloc, + __ipc_memfn, DALIST_MEMFN_CUSTOM))) return status; @@ -640,7 +652,7 @@ static int32_t __ntapi_init_solib_fork_child_finalize(void) &__internals->ipc_conns, sizeof(nt_ipc_conn), NT_ALLOCATION_GRANULARITY, - __ntapi_ipc_page_alloc, + __ipc_memfn, DALIST_MEMFN_CUSTOM))) return status; diff --git a/src/internal/ntapi_impl.h b/src/internal/ntapi_impl.h index f565fff..43511d4 100644 --- a/src/internal/ntapi_impl.h +++ b/src/internal/ntapi_impl.h @@ -149,9 +149,6 @@ __attr_protected__ int32_t __ntapi_tt_open_dir_utf8(void ** hfile, void * hat, c __attr_protected__ int32_t __ntapi_dsr_connect_internal_client(nt_daemon_params *); __attr_protected__ int32_t __ntapi_dsr_internal_client_connect(nt_daemon_params *); -/* ipc internals */ -__attr_protected__ int __ntapi_ipc_page_alloc(struct dalist_ex * dlist, void ** addr, size_t * alloc_size); - /* debug */ #define __ntidx(x) __offsetof(ntapi_vtbl,x) / sizeof(size_t) diff --git a/src/ipc/ntapi_ipc_connect.c b/src/ipc/ntapi_ipc_connect.c index eacbff2..fa2abca 100644 --- a/src/ipc/ntapi_ipc_connect.c +++ b/src/ipc/ntapi_ipc_connect.c @@ -285,6 +285,40 @@ static int32_t __ipc_set_client_keys( return NT_STATUS_SUCCESS; } + +static int __ipc_page_alloc(void) +{ + int32_t status; + size_t size; + struct dalist_ex * dlist; + void * addr; + ntapi_internals * __internals; + + __internals = __ntapi_internals(); + + addr = 0; + size = NT_ALLOCATION_GRANULARITY; + dlist = &__internals->ipc_conns; + + if (__internals->ipc_page == __NT_IPC_PAGES) + return NT_STATUS_QUOTA_EXCEEDED; + + if ((status = __ntapi->zw_allocate_virtual_memory( + NT_CURRENT_PROCESS_HANDLE, + &addr,0,&size, + NT_MEM_COMMIT, + NT_PAGE_READWRITE))) + return status; + + __internals->ipc_pages[__internals->ipc_page++] = addr; + + dalist_deposit_memory_block( + dlist,addr,size); + + return 0; +} + + static int32_t __ipc_connect_by_attr( void ** hport, const nt_port_attr * attr, @@ -351,10 +385,13 @@ static int32_t __ipc_connect_by_attr( return __ipc_connect_return(hlock,NT_STATUS_NOT_FOUND); /* allocate list node */ - if ((status = dalist_get_free_node( - &__internals->ipc_conns, - (void **)&node))) - return __ipc_connect_return(hlock,status); + if (!__internals->ipc_conns.free) + if ((status = __ipc_page_alloc())) + return __ipc_connect_return(hlock,status); + + dalist_get_free_node( + &__internals->ipc_conns, + (void **)&node); /* connect as needed */ if (!hconn) { @@ -578,39 +615,6 @@ int32_t __stdcall __ntapi_ipc_connect_by_port( } -int __ntapi_ipc_page_alloc( - struct dalist_ex * dlist, - void ** addr, - size_t * alloc_size) -{ - int32_t status; - size_t size; - ntapi_internals * __internals; - - __internals = __ntapi_internals(); - size = __NT_INTERNAL_PAGE_SIZE; - - if (__internals->ipc_page == __NT_IPC_PAGES) - return NT_STATUS_QUOTA_EXCEEDED; - - if ((status = __ntapi->zw_allocate_virtual_memory( - NT_CURRENT_PROCESS_HANDLE, - addr,0,&size, - NT_MEM_COMMIT, - NT_PAGE_READWRITE))) - return status; - - dalist_deposit_memory_block( - dlist,*addr,size); - - __internals->ipc_pages[__internals->ipc_page++] = *addr; - - *alloc_size = size; - - return 0; -} - - int32_t __stdcall __ntapi_ipc_get_port_by_attr( __out void ** hport, __in nt_port_attr * attr) diff --git a/src/process/ntapi_tt_fork.c b/src/process/ntapi_tt_fork.c index 5690164..dcd551f 100644 --- a/src/process/ntapi_tt_fork.c +++ b/src/process/ntapi_tt_fork.c @@ -17,6 +17,18 @@ static intptr_t __fork_retry_stats = 0; static intptr_t __fork_resume_stats = 0; +static int __ipc_memfn( + struct dalist_ex * dlist, + void ** addr, + size_t * alloc_size) +{ + (void)dlist; + (void)addr; + (void)alloc_size; + + return DALIST_EMEMFN; +} + static intptr_t __fastcall __ntapi_tt_fork_finalize(void ** hprocess) { int32_t status; @@ -46,7 +58,7 @@ static intptr_t __fastcall __ntapi_tt_fork_finalize(void ** hprocess) &__internals->ipc_conns, sizeof(nt_ipc_conn), NT_ALLOCATION_GRANULARITY, - __ntapi_ipc_page_alloc, + __ipc_memfn, DALIST_MEMFN_CUSTOM))) return status; |