summaryrefslogtreecommitdiffhomepage
path: root/src/pty/ntapi_pty_query.c
blob: 77d7bb76244eaa736589a8b0101147d0d918363b (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/********************************************************/
/*  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_port.h>
#include <ntapi/nt_tty.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"
#include "ntapi_pty.h"

int32_t	__stdcall __ntapi_pty_query(
	nt_pty *		pty,
	nt_io_status_block *	iosb,
	void *			pty_info,
	uint32_t		pty_info_length,
	nt_pty_info_class	pty_info_class)
{
	int32_t			status;
	void * 			hport;
	nt_pty_sigctl_msg	msg;
	nt_pty_client_info *	anyinfo;
	nt_pty_fd_info *	ofdinfo;

	if (pty_info_class>=NT_PTY_INFORMATION_CAP)
		return NT_STATUS_INVALID_INFO_CLASS;

	if (pty_info_class == NT_PTY_INHERIT_INFORMATION)
		return NT_STATUS_CONTEXT_MISMATCH;

	if (pty_info_class == NT_PTY_BASIC_INFORMATION)
		return NT_STATUS_NOT_IMPLEMENTED;

	if (pty_info_class == NT_PTY_CLIENT_INFORMATION)
		if (pty_info_length < sizeof(nt_pty_client_info))
			return NT_STATUS_INVALID_PARAMETER;

	__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_PTY_QUERY;

	switch (pty_info_class) {
		case NT_PTY_CLIENT_INFORMATION:
		case NT_PTY_OFD_INFORMATION:
			hport 				= pty->hport;
			msg.data.ctlinfo.hpty		= pty->hpty;
			msg.data.ctlinfo.luid.high	= pty->luid.high;
			msg.data.ctlinfo.luid.low	= pty->luid.low;
			msg.data.ctlinfo.ctlcode	= pty_info_class;

			__ntapi->tt_guid_copy(
				&msg.data.ctlinfo.guid,
				&pty->guid);
			break;

		default:
			return NT_STATUS_INVALID_INFO_CLASS;
	}

	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 (pty_info_class == NT_PTY_CLIENT_INFORMATION) {
		anyinfo         = (nt_pty_client_info *)pty_info;
		anyinfo->any[0] = msg.data.ctlinfo.ctxarg[0];
		anyinfo->any[1] = msg.data.ctlinfo.ctxarg[1];
		anyinfo->any[2] = msg.data.ctlinfo.ctxarg[2];
		anyinfo->any[3] = msg.data.ctlinfo.ctxarg[3];

		iosb->status = NT_STATUS_SUCCESS;
		iosb->info   = sizeof(*anyinfo);

	} else if (pty_info_class == NT_PTY_OFD_INFORMATION) {
		ofdinfo            = (nt_pty_fd_info *)pty_info;
		ofdinfo->hpty      = msg.data.ctlinfo.hpty;
		ofdinfo->luid.low  = msg.data.ctlinfo.luid.low;
		ofdinfo->luid.high = msg.data.ctlinfo.luid.high;

		ofdinfo->access    = (uint32_t)msg.data.ctlinfo.ctxarg[0];
		ofdinfo->flags     = (uint32_t)msg.data.ctlinfo.ctxarg[1];
		ofdinfo->share     = (uint32_t)msg.data.ctlinfo.ctxarg[2];
		ofdinfo->options   = (uint32_t)msg.data.ctlinfo.ctxarg[3];

		__ntapi->tt_guid_copy(
			&ofdinfo->guid,
			&msg.data.ctlinfo.guid);

		ofdinfo->section      = pty->section;
		ofdinfo->section_addr = pty->section_addr;
		ofdinfo->section_size = pty->section_size;
		ofdinfo->state        = 0;
		ofdinfo->hevent[0]    = 0;
		ofdinfo->hevent[1]    = 0;

		iosb->status = NT_STATUS_SUCCESS;
		iosb->info   = sizeof(*ofdinfo);
	}

	return NT_STATUS_SUCCESS;
}