summaryrefslogtreecommitdiffhomepage
path: root/src/msq/ntapi_msq_query.c
blob: 6a7e06f9bff1dfd0f851d71ce861dbee65e70f7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_file.h>
#include <ntapi/nt_string.h>
#include <ntapi/nt_atomic.h>
#include <ntapi/nt_port.h>
#include <ntapi/nt_ipc.h>
#include <ntapi/nt_msq.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"

int32_t	__stdcall __ntapi_msq_query(
	__in	nt_msq_info *		msq,
	__out	nt_io_status_block *	iosb,
	__out	void *			msq_info,
	__in	uint32_t		msq_info_length,
	__in	int32_t			msq_info_class)
{
	int32_t			status;
	nt_msq_info_msg		msg;

	/* validate */
	if (!iosb)
		return NT_STATUS_INVALID_PARAMETER;

	else if (!msq_info)
		return NT_STATUS_INVALID_PARAMETER;

	else if (msq_info_length < sizeof(msg.data.msqinfo))
		return NT_STATUS_BUFFER_TOO_SMALL;

	else if (msq_info_class)
		return NT_STATUS_INVALID_INFO_CLASS;

	/* 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_QUERY;

	msg.data.msqinfo.msqkey		= msq->msqkey;
	msg.data.msqinfo.msqid		= msq->msqid;

	if ((status = __ntapi->zw_request_wait_reply_port(msq->hport,&msg,&msg)))
		return status;
	else if (msg.data.ttyinfo.status)
		return msg.data.ttyinfo.status;

	/* reply */
	if (msg.header.data_size != sizeof(msg.data))
		return NT_STATUS_UNEXPECTED_IO_ERROR;

	__ntapi->tt_generic_memcpy(
		msq_info,
		&msg.data.msqinfo,
		sizeof(msg.data.msqinfo));

	iosb->status = NT_STATUS_SUCCESS;
	iosb->info   = sizeof(msg.data.msqinfo);

	return NT_STATUS_SUCCESS;
}