diff --git a/src/sem/ntapi_sem_ioctl.c b/src/sem/ntapi_sem_ioctl.c index 9735dfc..5c6a0a1 100644 --- a/src/sem/ntapi_sem_ioctl.c +++ b/src/sem/ntapi_sem_ioctl.c @@ -15,10 +15,18 @@ #include "ntapi_impl.h" static int32_t __sem_ioctl_return( + void * mapaddr, intptr_t * hlock, int32_t status) { - at_store(hlock,0); + if (hlock) + at_store(hlock,0); + + if (mapaddr) + __ntapi->zw_unmap_view_of_section( + NT_CURRENT_PROCESS_HANDLE, + mapaddr); + return status; } @@ -36,6 +44,7 @@ int32_t __stdcall __ntapi_sem_ioctl( __in uint32_t output_buffer_length) { int32_t status; + void * mapaddr; void * hsection; void * secaddr; size_t secsize; @@ -63,20 +72,28 @@ int32_t __stdcall __ntapi_sem_ioctl( 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; + if (input_buffer_length > secsize) - return NT_STATUS_INFO_LENGTH_MISMATCH; + return __sem_ioctl_return( + mapaddr,0, + NT_STATUS_INFO_LENGTH_MISMATCH); /* lock */ hlock = &(__ntapi_internals()->hlock); if (at_locked_cas(hlock,0,1)) - return NT_STATUS_RESOURCE_NOT_OWNED; + return __sem_ioctl_return( + mapaddr,0, + NT_STATUS_RESOURCE_NOT_OWNED); /* semop array to section */ __ntapi->tt_generic_memcpy( @@ -104,12 +121,12 @@ int32_t __stdcall __ntapi_sem_ioctl( msg.data.seminfo.riosb = iosb; if ((status = __ntapi->zw_request_wait_reply_port(sem->hport,&msg,&msg))) - return __sem_ioctl_return(hlock,status); + return __sem_ioctl_return(mapaddr,hlock,status); else if (msg.data.ttyinfo.status) - return __sem_ioctl_return(hlock,msg.data.ttyinfo.status); + return __sem_ioctl_return(mapaddr,hlock,msg.data.ttyinfo.status); iosb->status = NT_STATUS_SUCCESS; iosb->info = 0; - return __sem_ioctl_return(hlock,NT_STATUS_SUCCESS); + return __sem_ioctl_return(mapaddr,hlock,NT_STATUS_SUCCESS); }