From dfc0800de97a99f555fc6035987d49af3fe1f68e Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 8 Mar 2018 07:07:31 +0000 Subject: __ntapi_sem_query(): unmap the ad-hoc section as needed. --- src/sem/ntapi_sem_query.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/sem/ntapi_sem_query.c b/src/sem/ntapi_sem_query.c index f1e53a9..1a6b2e2 100644 --- a/src/sem/ntapi_sem_query.c +++ b/src/sem/ntapi_sem_query.c @@ -15,12 +15,18 @@ #include "ntapi_impl.h" static int32_t __sem_query_return( + void * mapaddr, intptr_t * hlock, int32_t status) { if (hlock) at_store(hlock,0); + if (mapaddr) + __ntapi->zw_unmap_view_of_section( + NT_CURRENT_PROCESS_HANDLE, + mapaddr); + return status; } @@ -32,6 +38,7 @@ int32_t __stdcall __ntapi_sem_query( __in int32_t sem_ipc_cmd) { int32_t status; + void * mapaddr; void * hsection; void * secaddr; size_t secsize; @@ -65,17 +72,23 @@ int32_t __stdcall __ntapi_sem_query( hsection = sem->section; secaddr = sem->section_addr; secsize = sem->section_size; + mapaddr = 0; } else if ((status = __ntapi->ipc_init_section_by_port( sem->hport,&hsection, &secaddr,&secsize))) return status; + else + mapaddr = secaddr; + /* lock */ hlock = &(__ntapi_internals()->hlock); if (at_locked_cas(hlock,0,1)) - return NT_STATUS_RESOURCE_NOT_OWNED; + return __sem_query_return( + mapaddr,0, + NT_STATUS_RESOURCE_NOT_OWNED); } /* msg */ @@ -95,15 +108,15 @@ int32_t __stdcall __ntapi_sem_query( msg.data.seminfo.section_size = secsize; if ((status = __ntapi->zw_request_wait_reply_port(sem->hport,&msg,&msg))) - return __sem_query_return(hlock,status); + return __sem_query_return(mapaddr,hlock,status); else if (msg.data.ttyinfo.status) - return __sem_query_return(hlock,msg.data.ttyinfo.status); + return __sem_query_return(mapaddr,hlock,msg.data.ttyinfo.status); /* reply */ if (sem_ipc_cmd == NT_SEM_CMD_GETALL) { if (msg.data.seminfo.section_size > sem_info_length) return __sem_query_return( - hlock, + mapaddr,hlock, NT_STATUS_BUFFER_TOO_SMALL); __ntapi->tt_generic_memcpy( @@ -114,6 +127,11 @@ int32_t __stdcall __ntapi_sem_query( iosb->status = NT_STATUS_SUCCESS; iosb->info = msg.data.seminfo.section_size; + + if (mapaddr) + __ntapi->zw_unmap_view_of_section( + NT_CURRENT_PROCESS_HANDLE, + mapaddr); } else { if (msg.header.data_size != sizeof(msg.data)) return NT_STATUS_UNEXPECTED_IO_ERROR; -- cgit v1.2.3