/*********************************************************/
/* ptycon: a pty-console bridge */
/* Copyright (C) 2016 Z. Gilboa */
/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */
/*********************************************************/
#include <psxtypes/psxtypes.h>
#include <ntcon/ntcon.h>
#include <ntapi/ntapi.h>
#include <gdi/gdi.h>
#include <ptycon/ptycon.h>
#include "ptycon_driver_impl.h"
int __stdcall ptyc_dbg_oven(struct ptyc_driver_ctx_impl * ictx)
{
int32_t status;
void * hwait;
char * ch;
nt_iosb iosb;
size_t nread;
uintptr_t buffer[4196/sizeof(uintptr_t)];
if ((status = ntapi->tt_create_private_event(
&hwait,
NT_NOTIFICATION_EVENT,
NT_EVENT_NOT_SIGNALED)))
return status;
do {
status = ntapi->pty_read(
ictx->cctx.hpts,
hwait,0,0,
&iosb,
buffer,sizeof(buffer),
0,0);
if (status == NT_STATUS_PENDING)
status = ntapi->zw_wait_for_single_object(
hwait,NT_SYNC_ALERTABLE,0);
if (status || iosb.status) {
ntapi->zw_close(hwait);
return status ? status : iosb.status;
}
ch = (char *)buffer;
nread = iosb.info;
for ( ; nread; ) {
status = ntapi->pty_write(
ictx->cctx.hpts,
hwait,0,0,&iosb,
ch,(uint32_t)nread,
0,0);
if (status == NT_STATUS_PENDING)
status = ntapi->zw_wait_for_single_object(
hwait,NT_SYNC_ALERTABLE,0);
if (status || iosb.status) {
ntapi->zw_close(hwait);
return status ? status : iosb.status;
}
ch += iosb.info;
nread -= iosb.info;
}
} while (1);
}