summaryrefslogtreecommitdiffhomepage
path: root/src/tty/ntapi_tty_query_information_server.c
blob: 1aecdfa4bce42c0e4212ef3b3443fab697988237 (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
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_tty.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"

#define __MSGBUF_ELEMENTS (NT_LPC_MAX_MSG_DATA_SIZE/sizeof(uintptr_t)) + 1

int32_t	__stdcall __ntapi_tty_query_information_server(
	__in	void *			hport,
	__out	nt_io_status_block *	iosb,
	__out	void *			tty_info,
	__in	uint32_t		tty_info_length,
	__in	int			tty_info_class)
{
	int32_t			status;
	nt_tty_server_msg *	msg;
	uintptr_t		msgbuf[__MSGBUF_ELEMENTS];

	__ntapi->tt_aligned_block_memset(
		msgbuf,0,
		sizeof(msgbuf));

	msg				= (nt_tty_server_msg *)msgbuf;
	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_QUERY_INFORMATION_SERVER;
	msg->data.srvinfo.info_class	= tty_info_class;

	if (!hport)
		hport = __ntapi_internals()->hport_tty_session;

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

	if (tty_info_length < msg->data.srvinfo.info_length)
		return NT_STATUS_BUFFER_TOO_SMALL;

	__ntapi->tt_generic_memcpy(
		tty_info,
		msg->data.srvinfo.info_buffer,
		msg->data.srvinfo.info_length);

	iosb->status = NT_STATUS_SUCCESS;
	iosb->info   = msg->data.srvinfo.info_length;

	return NT_STATUS_SUCCESS;
}