From 47f21a54cf74e2ec0fc7aa7e3ee06ab5087600a6 Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 8 Sep 2017 22:22:22 +0000 Subject: integrated msgqueue client side interfaces. --- src/msq/ntapi_msq_recv.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/msq/ntapi_msq_recv.c (limited to 'src/msq/ntapi_msq_recv.c') diff --git a/src/msq/ntapi_msq_recv.c b/src/msq/ntapi_msq_recv.c new file mode 100644 index 0000000..4da7cbe --- /dev/null +++ b/src/msq/ntapi_msq_recv.c @@ -0,0 +1,109 @@ +/********************************************************/ +/* ntapi: Native API core library */ +/* Copyright (C) 2013--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */ +/********************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ntapi_impl.h" + +static int32_t __msq_recv_return( + intptr_t * hlock, + int32_t status) +{ + at_store(hlock,0); + return status; +} + + +int32_t __stdcall __ntapi_msq_recv( + __in nt_msq_info * msq, + __in void * hevent __optional, + __in nt_io_apc_routine * apc_routine __optional, + __in void * apc_context __optional, + __out void * buffer, + __in size_t len, + __in intptr_t rank, + __in uint32_t options, + __out nt_io_status_block * iosb) +{ + int32_t status; + void * hsection; + void * secaddr; + size_t secsize; + nt_msq_info_msg msg; + intptr_t * hlock; + + /* validate */ + if (!iosb) + return NT_STATUS_INVALID_PARAMETER; + + else if (!len) + return NT_STATUS_INVALID_PARAMETER; + + /* section */ + if (msq->section_addr) { + hsection = msq->section; + secaddr = msq->section_addr; + secsize = msq->section_size; + + } else if ((status = __ntapi->ipc_init_section_by_port( + msq->hport,&hsection, + &secaddr,&secsize))) + return status; + + /* len */ + if (len > secsize) + len = secsize; + + /* lock */ + hlock = &(__ntapi_internals()->hlock); + + if (at_locked_cas(hlock,0,1)) + return NT_STATUS_RESOURCE_NOT_OWNED; + + /* msg */ + __ntapi->tt_aligned_block_memset( + &msg,0,sizeof(msg)); + + msg.header.msg_type = NT_LPC_NEW_MESSAGE; + msg.header.data_size = sizeof(msg.data); + msg.header.msg_size = sizeof(msg); + msg.data.ttyinfo.opcode = NT_TTY_MSQ_RECV; + + msg.data.msqinfo.msqkey = msq->msqkey; + msg.data.msqinfo.msqid = msq->msqid; + msg.data.msqinfo.msqrpid = msq->msqrpid; + msg.data.msqinfo.msqrank = rank; + msg.data.msqinfo.section_addr = secaddr; + msg.data.msqinfo.section_size = len; + msg.data.msqinfo.ntoptions = options; + + msg.data.msqinfo.hevent = hevent; + msg.data.msqinfo.apc_routine = apc_routine; + msg.data.msqinfo.apc_context = apc_context; + msg.data.msqinfo.riosb = iosb; + + if ((status = __ntapi->zw_request_wait_reply_port(msq->hport,&msg,&msg))) + return __msq_recv_return(hlock,status); + else if (msg.data.ttyinfo.status) + return __msq_recv_return(hlock,msg.data.ttyinfo.status); + + /* msq data section to buffer */ + __ntapi->tt_generic_memcpy( + buffer,secaddr, + msg.data.msqinfo.ntiosb.info); + + /* all done */ + iosb->status = msg.data.msqinfo.ntiosb.status; + iosb->info = msg.data.msqinfo.ntiosb.info; + + return __msq_recv_return(hlock,NT_STATUS_SUCCESS); +} -- cgit v1.2.3