summaryrefslogtreecommitdiffhomepage
path: root/src/afl/ntapi_afl_ioctl.c
blob: 07d07cf9d6d8e98985a0fb4e2ad52200271301c4 (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
/********************************************************/
/*  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_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_afl.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"

int32_t	__stdcall __ntapi_afl_ioctl(
	__in	nt_afl_info *		afl,
	__in	void *			hevent			__optional,
	__in	nt_io_apc_routine *	apc_routine		__optional,
	__in	void *			apc_context		__optional,
	__out	nt_iosb *		iosb,
	__in	uint32_t		io_control_code,
	__in	void *			input_buffer		__optional,
	__in	uint32_t		input_buffer_length,
	__out	void *			output_buffer		__optional,
	__in	uint32_t		output_buffer_length)
{
	int32_t			status;
	nt_afl_info_msg		msg;
	nt_afl_op *		aflop;

	/* validate */
	if (io_control_code)
		return NT_STATUS_NOT_SUPPORTED;

	else if (!iosb)
		return NT_STATUS_INVALID_PARAMETER;

	else if (!(aflop = (nt_afl_op *)input_buffer))
		return NT_STATUS_INVALID_PARAMETER;

	else if (input_buffer_length != sizeof(nt_afl_op))
		return NT_STATUS_INFO_LENGTH_MISMATCH;

	if (output_buffer)
		if (output_buffer_length < sizeof(nt_afl_op))
			return NT_STATUS_BUFFER_TOO_SMALL;

	/* msg */
	__ntapi->tt_aligned_block_memset(
		&msg,0,sizeof(msg));

	__ntapi->tt_guid_copy(
		&msg.data.aflinfo.afldev,
		&afl->afldev);

	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_AFL_IOCTL;

	msg.data.aflinfo.l_fileid	= aflop->l_fileid;
	msg.data.aflinfo.l_start	= aflop->l_start;
	msg.data.aflinfo.l_len		= aflop->l_len;
	msg.data.aflinfo.l_pid		= aflop->l_pid;
	msg.data.aflinfo.l_cmd		= aflop->l_cmd;

	msg.data.aflinfo.hevent		= hevent;
	msg.data.aflinfo.apc_routine	= apc_routine;
	msg.data.aflinfo.apc_context	= apc_context;
	msg.data.aflinfo.riosb		= iosb;

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

	iosb->status = NT_STATUS_SUCCESS;
	iosb->info   = msg.data.aflinfo.ntiosb.info;

	if (msg.data.aflinfo.ntiosb.info && output_buffer) {
		aflop = (nt_afl_op *)output_buffer;
		aflop->l_fileid = msg.data.aflinfo.l_fileid;
		aflop->l_start  = msg.data.aflinfo.l_start;
		aflop->l_len    = msg.data.aflinfo.l_len;
		aflop->l_pid    = msg.data.aflinfo.l_pid;
		aflop->l_cmd    = msg.data.aflinfo.l_cmd;
	}

	return NT_STATUS_SUCCESS;
}