Blame src/msq/ntapi_msq_fdio.c

47f21a
/********************************************************/
47f21a
/*  ntapi: Native API core library                      */
47f21a
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
47f21a
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
47f21a
/********************************************************/
47f21a
47f21a
#include <psxtypes/psxtypes.h>
47f21a
#include <ntapi/nt_file.h>
47f21a
#include <ntapi/nt_string.h>
47f21a
#include <ntapi/nt_atomic.h>
47f21a
#include <ntapi/nt_port.h>
47f21a
#include <ntapi/nt_ipc.h>
47f21a
#include <ntapi/nt_msq.h>
47f21a
#include <ntapi/ntapi.h>
47f21a
#include "ntapi_impl.h"
47f21a
47f21a
static int32_t __msq_fdio(
47f21a
	nt_msq_info *		msq,
47f21a
	nt_iosb *		iosb,
47f21a
	uint32_t		opcode)
47f21a
{
47f21a
	int32_t			status;
47f21a
	nt_msq_info_msg		msg;
47f21a
47f21a
	/* validate */
47f21a
	if (!iosb)
47f21a
		return NT_STATUS_INVALID_PARAMETER;
47f21a
47f21a
	/* msg */
47f21a
	__ntapi->tt_aligned_block_memset(
47f21a
		&msg,0,sizeof(msg));
47f21a
47f21a
	msg.header.msg_type		= NT_LPC_NEW_MESSAGE;
47f21a
	msg.header.data_size		= sizeof(msg.data);
47f21a
	msg.header.msg_size		= sizeof(msg);
47f21a
	msg.data.ttyinfo.opcode		= opcode;
47f21a
47f21a
	msg.data.msqinfo.msqkey		= msq->msqkey;
47f21a
	msg.data.msqinfo.msqid		= msq->msqid;
47f21a
47f21a
	if ((status = __ntapi->zw_request_wait_reply_port(msq->hport,&msg,&msg)))
47f21a
		return status;
47f21a
	else if (msg.data.ttyinfo.status)
47f21a
		return msg.data.ttyinfo.status;
47f21a
47f21a
	iosb->status = NT_STATUS_SUCCESS;
47f21a
	iosb->info   = 0;
47f21a
47f21a
	return NT_STATUS_SUCCESS;
47f21a
}
47f21a
47f21a
int32_t	__stdcall __ntapi_msq_cancel(
47f21a
	__in	nt_msq_info *		msq,
47f21a
	__out	nt_iosb *		iosb)
47f21a
{
47f21a
	return __msq_fdio(msq,iosb,NT_TTY_MSQ_CANCEL);
47f21a
}
47f21a
47f21a
int32_t	__stdcall __ntapi_msq_free(
47f21a
	__in	nt_msq_info *		msq,
47f21a
	__out	nt_iosb *		iosb)
47f21a
{
47f21a
	return __msq_fdio(msq,iosb,NT_TTY_MSQ_FREE);
47f21a
}