Blame src/afl/ntapi_afl_query.c

6a4793
/********************************************************/
6a4793
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
6a4793
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
6a4793
/********************************************************/
6a4793
6a4793
#include <psxtypes/psxtypes.h>
6a4793
#include <ntapi/nt_file.h>
6a4793
#include <ntapi/nt_string.h>
6a4793
#include <ntapi/nt_atomic.h>
6a4793
#include <ntapi/nt_port.h>
6a4793
#include <ntapi/nt_ipc.h>
6a4793
#include <ntapi/nt_afl.h>
6a4793
#include <ntapi/ntapi.h>
6a4793
#include "ntapi_impl.h"
6a4793
6a4793
int32_t	__stdcall __ntapi_afl_query(
6a4793
	__in	nt_afl_info *		afl,
6a4793
	__out	nt_io_status_block *	iosb,
6a4793
	__out	void *			afl_info,
6a4793
	__in	uint32_t		afl_info_length,
6a4793
	__in	int32_t			afl_info_class)
6a4793
{
6a4793
	int32_t			status;
6a4793
	nt_afl_info_msg		msg;
6a4793
6a4793
	/* validate */
6a4793
	if (!iosb)
6a4793
		return NT_STATUS_INVALID_PARAMETER;
6a4793
6a4793
	else if (!afl_info)
6a4793
		return NT_STATUS_INVALID_PARAMETER;
6a4793
6a4793
	else if (afl_info_length < sizeof(msg.data.aflinfo))
6a4793
		return NT_STATUS_BUFFER_TOO_SMALL;
6a4793
6a4793
	else if (afl_info_class)
6a4793
		return NT_STATUS_INVALID_INFO_CLASS;
6a4793
6a4793
	/* msg */
6a4793
	__ntapi->tt_aligned_block_memset(
6a4793
		&msg,0,sizeof(msg));
6a4793
6a4793
	msg.header.msg_type		= NT_LPC_NEW_MESSAGE;
6a4793
	msg.header.data_size		= sizeof(msg.data);
6a4793
	msg.header.msg_size		= sizeof(msg);
6a4793
	msg.data.ttyinfo.opcode		= NT_TTY_AFL_QUERY;
6a4793
6a4793
	if ((status = __ntapi->zw_request_wait_reply_port(afl->hport,&msg,&msg)))
6a4793
		return status;
6a4793
	else if (msg.data.ttyinfo.status)
6a4793
		return msg.data.ttyinfo.status;
6a4793
6a4793
	/* reply */
6a4793
	if (msg.header.data_size != sizeof(msg.data))
6a4793
		return NT_STATUS_UNEXPECTED_IO_ERROR;
6a4793
6a4793
	__ntapi->tt_generic_memcpy(
6a4793
		afl_info,
6a4793
		&msg.data.aflinfo,
6a4793
		sizeof(msg.data.aflinfo));
6a4793
6a4793
	iosb->status = NT_STATUS_SUCCESS;
6a4793
	iosb->info   = sizeof(msg.data.aflinfo);
6a4793
6a4793
	return NT_STATUS_SUCCESS;
6a4793
}