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
|
/********************************************************/
/* 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/nt_termios.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"
#include "ntapi_pty.h"
int32_t __stdcall __ntapi_pty_ioctl(
nt_pty * pty,
void * hevent __optional,
nt_io_apc_routine * apc_routine __optional,
void * apc_context __optional,
nt_iosb * iosb,
uint32_t ctlcode,
void * input_buffer __optional,
uint32_t input_buffer_length,
void * output_buffer __optional,
uint32_t output_buffer_length)
{
int32_t status;
nt_pty_sigctl_msg msg;
nt_tty_sigctl_info * input;
nt_tty_sigctl_info * output;
(void)hevent;
(void)apc_routine;
(void)apc_context;
if ((uintptr_t)input_buffer % sizeof(uintptr_t))
return NT_STATUS_DATATYPE_MISALIGNMENT_ERROR;
else if (input_buffer_length != sizeof(nt_tty_sigctl_info))
return NT_STATUS_INVALID_BUFFER_SIZE;
else if (!output_buffer)
return NT_STATUS_ACCESS_DENIED;
else if ((uintptr_t)output_buffer % sizeof(uintptr_t))
return NT_STATUS_DATATYPE_MISALIGNMENT_ERROR;
else if (output_buffer_length < sizeof(nt_tty_sigctl_info))
return NT_STATUS_BUFFER_TOO_SMALL;
input = (nt_tty_sigctl_info *)input_buffer;
output = (nt_tty_sigctl_info *)output_buffer;
__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_IOCTL;
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 = ctlcode;
__ntapi->tt_guid_copy(
&msg.data.ctlinfo.guid,
&pty->guid);
msg.data.ctlinfo.ctxarg[0] = input->ctxarg[0];
msg.data.ctlinfo.ctxarg[1] = input->ctxarg[1];
msg.data.ctlinfo.ctxarg[2] = input->ctxarg[2];
msg.data.ctlinfo.ctxarg[3] = input->ctxarg[3];
__ntapi->tt_generic_memcpy(
(char *)&msg.data.ctlinfo.terminfo,
(char *)&input->terminfo,
sizeof(input->terminfo));
__ntapi->tt_generic_memcpy(
(char *)&msg.data.ctlinfo.winsize,
(char *)&input->winsize,
sizeof(input->winsize));
if ((status = __ntapi->zw_request_wait_reply_port(pty->hport,&msg,&msg)))
return status;
else if (msg.data.ttyinfo.status)
return msg.data.ttyinfo.status;
__ntapi->tt_aligned_block_memcpy(
(uintptr_t *)output,
(uintptr_t *)&msg.data.ctlinfo,
sizeof(*output));
iosb->info = msg.data.ctlinfo.iosb.info;
iosb->status = msg.data.ctlinfo.iosb.status;
return NT_STATUS_SUCCESS;
}
|