Blame src/debug/ptyc_dbg_oven.c

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