|
|
538c8a |
#ifndef PTYCON_IOCTL_IMPL_H
|
|
|
538c8a |
#define PTYCON_IOCTL_IMPL_H
|
|
|
538c8a |
|
|
|
538c8a |
#include <ntapi/ntapi.h>
|
|
|
538c8a |
|
|
|
538c8a |
static int32_t ptyc_grant(nt_pty * hptm)
|
|
|
538c8a |
{
|
|
|
538c8a |
nt_tty_sigctl_info ctlinfo;
|
|
|
538c8a |
nt_iosb iosb;
|
|
|
538c8a |
|
|
|
538c8a |
ntapi->tt_aligned_block_memset(
|
|
|
538c8a |
&ctlinfo,0,sizeof(ctlinfo));
|
|
|
538c8a |
|
|
|
538c8a |
return ntapi->pty_ioctl(
|
|
|
538c8a |
hptm,
|
|
|
538c8a |
0,0,0,
|
|
|
538c8a |
&iosb,TTY_TIOCSPTLCK,
|
|
|
538c8a |
&ctlinfo,sizeof(ctlinfo),
|
|
|
538c8a |
&ctlinfo,sizeof(ctlinfo));
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
d918be |
static int32_t ptyc_set_client_info(
|
|
|
d918be |
nt_pty * hpty,
|
|
|
d918be |
nt_pty_client_info * clinfo)
|
|
|
d918be |
{
|
|
|
d918be |
int32_t status;
|
|
|
d918be |
nt_iosb iosb;
|
|
|
d918be |
nt_large_integer ticks;
|
|
|
d918be |
nt_large_integer freq;
|
|
|
d918be |
nt_pty_client_info ptyinfo;
|
|
|
d918be |
|
|
|
d918be |
if ((status = ntapi->zw_query_performance_counter(
|
|
|
d918be |
&ticks,&freq)))
|
|
|
d918be |
return status;
|
|
|
d918be |
|
|
|
d918be |
ptyinfo.any[0] = (ticks.ulow << 19) | (ticks.ulow >> 13);
|
|
|
d918be |
|
|
|
d918be |
if ((status = ntapi->zw_query_performance_counter(
|
|
|
d918be |
&ticks,&freq)))
|
|
|
d918be |
return status;
|
|
|
d918be |
|
|
|
d918be |
ptyinfo.any[1] = (ticks.ulow << 15) | (ticks.ulow >> 17);
|
|
|
d918be |
|
|
|
d918be |
if ((status = ntapi->zw_query_performance_counter(
|
|
|
d918be |
&ticks,&freq)))
|
|
|
d918be |
return status;
|
|
|
d918be |
|
|
|
d918be |
ptyinfo.any[1] = (ticks.ulow << 11) | (ticks.ulow >> 21);
|
|
|
d918be |
|
|
|
d918be |
if ((status = ntapi->zw_query_performance_counter(
|
|
|
d918be |
&ticks,&freq)))
|
|
|
d918be |
return status;
|
|
|
d918be |
|
|
|
d918be |
ptyinfo.any[1] = (ticks.ulow << 17) | (ticks.ulow >> 15);
|
|
|
d918be |
|
|
|
d918be |
if ((status = ntapi->pty_set(
|
|
|
d918be |
hpty,&iosb,
|
|
|
d918be |
&ptyinfo,sizeof(ptyinfo),
|
|
|
d918be |
NT_PTY_CLIENT_INFORMATION)))
|
|
|
d918be |
return status;
|
|
|
d918be |
|
|
|
d918be |
clinfo->any[0] = ptyinfo.any[0];
|
|
|
d918be |
clinfo->any[1] = ptyinfo.any[1];
|
|
|
d918be |
clinfo->any[2] = ptyinfo.any[2];
|
|
|
d918be |
clinfo->any[3] = ptyinfo.any[3];
|
|
|
d918be |
|
|
|
d918be |
return NT_STATUS_SUCCESS;
|
|
|
d918be |
}
|
|
|
d918be |
|
|
|
48271e |
static int32_t ptyc_pty_own(
|
|
|
48271e |
nt_pty * hpty,
|
|
|
48271e |
nt_runtime_data * rtdata)
|
|
|
48271e |
{
|
|
|
48271e |
int32_t status;
|
|
|
48271e |
nt_tty_session_info sessioninfo;
|
|
|
48271e |
nt_tty_sigctl_info ctlinfo;
|
|
|
48271e |
nt_pty_client_info ptyinfo;
|
|
|
48271e |
nt_iosb iosb;
|
|
|
48271e |
|
|
|
48271e |
/* inherited session info */
|
|
|
48271e |
if ((status = ntapi->tty_client_session_query(
|
|
|
48271e |
rtdata->hsession,
|
|
|
48271e |
&sessioninfo)))
|
|
|
48271e |
return status;
|
|
|
48271e |
|
|
|
48271e |
/* simulated fork */
|
|
|
48271e |
sessioninfo.pid = rtdata->cid_self.process_id;
|
|
|
48271e |
sessioninfo.pgid = sessioninfo.pgid ? sessioninfo.pgid : -1;
|
|
|
48271e |
sessioninfo.sid = 0;
|
|
|
48271e |
sessioninfo.syspid = 0;
|
|
|
48271e |
|
|
|
48271e |
if ((status = ntapi->tty_client_session_set(
|
|
|
48271e |
rtdata->hsession,
|
|
|
48271e |
&sessioninfo)))
|
|
|
48271e |
return status;
|
|
|
48271e |
|
|
|
48271e |
/* setsid() */
|
|
|
48271e |
sessioninfo.pid = rtdata->cid_self.process_id;
|
|
|
48271e |
sessioninfo.pgid = rtdata->cid_self.process_id;
|
|
|
48271e |
sessioninfo.sid = rtdata->cid_self.process_id;
|
|
|
48271e |
sessioninfo.syspid = 0;
|
|
|
48271e |
|
|
|
48271e |
if ((status = ntapi->tty_client_session_set(
|
|
|
48271e |
rtdata->hsession,
|
|
|
48271e |
&sessioninfo)))
|
|
|
48271e |
return status;
|
|
|
48271e |
|
|
|
48271e |
/* ctty */
|
|
|
48271e |
ntapi->tt_aligned_block_memset(
|
|
|
48271e |
&ctlinfo,0,sizeof(ctlinfo));
|
|
|
48271e |
|
|
|
48271e |
if ((status = ntapi->pty_ioctl(
|
|
|
48271e |
hpty,
|
|
|
48271e |
0,0,0,
|
|
|
48271e |
&iosb,
|
|
|
48271e |
TTY_TIOCSCTTY,
|
|
|
48271e |
&ctlinfo,sizeof(ctlinfo),
|
|
|
48271e |
&ctlinfo,sizeof(ctlinfo))))
|
|
|
48271e |
return status;
|
|
|
48271e |
|
|
|
48271e |
/* tcsetpgrp */
|
|
|
48271e |
ntapi->tt_aligned_block_memset(
|
|
|
48271e |
&ctlinfo,0,sizeof(ctlinfo));
|
|
|
48271e |
|
|
|
48271e |
ctlinfo.ctxarg[0] = rtdata->cid_self.process_id;
|
|
|
48271e |
|
|
|
48271e |
if ((status = ntapi->pty_ioctl(
|
|
|
48271e |
hpty,
|
|
|
48271e |
0,0,0,
|
|
|
48271e |
&iosb,
|
|
|
48271e |
TTY_TIOCSPGRP,
|
|
|
48271e |
&ctlinfo,sizeof(ctlinfo),
|
|
|
48271e |
&ctlinfo,sizeof(ctlinfo))))
|
|
|
48271e |
return status;
|
|
|
48271e |
|
|
|
48271e |
/* [ptycon daemon loop]: ctty signals */
|
|
|
48271e |
ntapi->tt_aligned_block_memset(
|
|
|
48271e |
&ptyinfo,0,sizeof(ptyinfo));
|
|
|
48271e |
|
|
|
48271e |
if ((status = ntapi->pty_set(
|
|
|
48271e |
hpty,&iosb,
|
|
|
48271e |
&ptyinfo,sizeof(ptyinfo),
|
|
|
48271e |
NT_PTY_CLIENT_INFORMATION)))
|
|
|
48271e |
return status;
|
|
|
48271e |
|
|
|
48271e |
return NT_STATUS_SUCCESS;
|
|
|
48271e |
}
|
|
|
48271e |
|
|
|
538c8a |
#endif
|