Blame src/pty/ntapi_pty_query.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_port.h>
dd89bb
#include <ntapi/nt_tty.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
#include "ntapi_pty.h"
dd89bb
dd89bb
int32_t	__stdcall __ntapi_pty_query(
dd89bb
	nt_pty *		pty,
dd89bb
	nt_io_status_block *	iosb,
dd89bb
	void *			pty_info,
dd89bb
	uint32_t		pty_info_length,
dd89bb
	nt_pty_info_class	pty_info_class)
dd89bb
{
dd89bb
	int32_t			status;
efc01e
	void * 			hport;
dd89bb
	nt_pty_sigctl_msg	msg;
5b96cf
	nt_pty_client_info *	anyinfo;
c9195c
	nt_pty_fd_info *	ofdinfo;
dd89bb
858b95
	if (pty_info_class>=NT_PTY_INFORMATION_CAP)
dd89bb
		return NT_STATUS_INVALID_INFO_CLASS;
c4fe1e
e62c29
	if (pty_info_class == NT_PTY_INHERIT_INFORMATION)
e62c29
		return NT_STATUS_CONTEXT_MISMATCH;
e62c29
c4fe1e
	if (pty_info_class == NT_PTY_BASIC_INFORMATION)
dd89bb
		return NT_STATUS_NOT_IMPLEMENTED;
c4fe1e
c4fe1e
	if (pty_info_class == NT_PTY_CLIENT_INFORMATION)
c4fe1e
		if (pty_info_length < sizeof(nt_pty_client_info))
c4fe1e
			return NT_STATUS_INVALID_PARAMETER;
c4fe1e
dd89bb
	__ntapi->tt_aligned_block_memset(
dd89bb
		&msg,0,sizeof(msg));
dd89bb
dd89bb
	msg.header.msg_type		= NT_LPC_NEW_MESSAGE;
dd89bb
	msg.header.data_size		= sizeof(msg.data);
dd89bb
	msg.header.msg_size		= sizeof(msg);
dd89bb
	msg.data.ttyinfo.opcode		= NT_TTY_PTY_QUERY;
dd89bb
5b96cf
	switch (pty_info_class) {
5b96cf
		case NT_PTY_CLIENT_INFORMATION:
c9195c
		case NT_PTY_OFD_INFORMATION:
5b96cf
			hport 				= pty->hport;
5b96cf
			msg.data.ctlinfo.hpty		= pty->hpty;
5b96cf
			msg.data.ctlinfo.luid.high	= pty->luid.high;
5b96cf
			msg.data.ctlinfo.luid.low	= pty->luid.low;
5b96cf
			msg.data.ctlinfo.ctlcode	= pty_info_class;
5b96cf
5b96cf
			__ntapi->tt_guid_copy(
5b96cf
				&msg.data.ctlinfo.guid,
5b96cf
				&pty->guid);
5b96cf
			break;
5b96cf
5b96cf
		default:
5b96cf
			return NT_STATUS_INVALID_INFO_CLASS;
efc01e
	}
dd89bb
efc01e
	if ((status = __ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
dd89bb
		return status;
c4fe1e
dd89bb
	else if (msg.data.ttyinfo.status)
dd89bb
		return msg.data.ttyinfo.status;
dd89bb
efc01e
	if (pty_info_class == NT_PTY_CLIENT_INFORMATION) {
5b96cf
		anyinfo         = (nt_pty_client_info *)pty_info;
5b96cf
		anyinfo->any[0] = msg.data.ctlinfo.ctxarg[0];
5b96cf
		anyinfo->any[1] = msg.data.ctlinfo.ctxarg[1];
5b96cf
		anyinfo->any[2] = msg.data.ctlinfo.ctxarg[2];
5b96cf
		anyinfo->any[3] = msg.data.ctlinfo.ctxarg[3];
5b96cf
5b96cf
		iosb->status = NT_STATUS_SUCCESS;
5b96cf
		iosb->info   = sizeof(*anyinfo);
efc01e
c9195c
	} else if (pty_info_class == NT_PTY_OFD_INFORMATION) {
c9195c
		ofdinfo            = (nt_pty_fd_info *)pty_info;
c9195c
		ofdinfo->hpty      = msg.data.ctlinfo.hpty;
c9195c
		ofdinfo->luid.low  = msg.data.ctlinfo.luid.low;
c9195c
		ofdinfo->luid.high = msg.data.ctlinfo.luid.high;
c9195c
c9195c
		ofdinfo->access    = (uint32_t)msg.data.ctlinfo.ctxarg[0];
c9195c
		ofdinfo->flags     = (uint32_t)msg.data.ctlinfo.ctxarg[1];
c9195c
		ofdinfo->share     = (uint32_t)msg.data.ctlinfo.ctxarg[2];
c9195c
		ofdinfo->options   = (uint32_t)msg.data.ctlinfo.ctxarg[3];
c9195c
c9195c
		__ntapi->tt_guid_copy(
c9195c
			&ofdinfo->guid,
c9195c
			&msg.data.ctlinfo.guid);
c9195c
c9195c
		ofdinfo->section      = pty->section;
c9195c
		ofdinfo->section_addr = pty->section_addr;
c9195c
		ofdinfo->section_size = pty->section_size;
c9195c
		ofdinfo->state        = 0;
c9195c
		ofdinfo->hevent[0]    = 0;
c9195c
		ofdinfo->hevent[1]    = 0;
c9195c
c9195c
		iosb->status = NT_STATUS_SUCCESS;
c9195c
		iosb->info   = sizeof(*ofdinfo);
efc01e
	}
dd89bb
dd89bb
	return NT_STATUS_SUCCESS;
dd89bb
}