1998-12-30 13:06:45 +01:00
|
|
|
/*
|
|
|
|
* Server-side console management
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* FIXME: all this stuff is a hack to avoid breaking
|
|
|
|
* the client-side console support.
|
|
|
|
*/
|
|
|
|
|
1999-10-25 00:13:47 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-12-30 13:06:45 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
1999-01-19 18:48:23 +01:00
|
|
|
#include <signal.h>
|
1999-01-03 12:55:56 +01:00
|
|
|
#include <string.h>
|
1998-12-30 13:06:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "winnt.h"
|
2000-05-03 19:48:21 +02:00
|
|
|
#include "winbase.h"
|
1999-01-19 18:48:23 +01:00
|
|
|
#include "wincon.h"
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
#include "handle.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "thread.h"
|
1999-06-22 19:26:53 +02:00
|
|
|
#include "request.h"
|
1998-12-30 13:06:45 +01:00
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
struct screen_buffer;
|
|
|
|
|
|
|
|
struct console_input
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
int mode; /* input mode */
|
|
|
|
struct screen_buffer *output; /* associated screen buffer */
|
1999-01-31 20:04:30 +01:00
|
|
|
int recnum; /* number of input records */
|
|
|
|
INPUT_RECORD *records; /* input records */
|
1999-01-19 18:48:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct screen_buffer
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-01-19 18:48:23 +01:00
|
|
|
struct object obj; /* object header */
|
|
|
|
int mode; /* output mode */
|
|
|
|
struct console_input *input; /* associated console input */
|
|
|
|
int cursor_size; /* size of cursor (percentage filled) */
|
|
|
|
int cursor_visible;/* cursor visibility flag */
|
|
|
|
int pid; /* xterm pid (hack) */
|
|
|
|
char *title; /* console title */
|
1998-12-30 13:06:45 +01:00
|
|
|
};
|
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
|
|
|
|
static void console_input_dump( struct object *obj, int verbose );
|
2000-01-01 01:56:27 +01:00
|
|
|
static int console_input_get_poll_events( struct object *obj );
|
2000-12-19 03:12:45 +01:00
|
|
|
static int console_input_get_fd( struct object *obj );
|
1999-01-19 18:48:23 +01:00
|
|
|
static void console_input_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static void screen_buffer_dump( struct object *obj, int verbose );
|
2000-01-01 01:56:27 +01:00
|
|
|
static int screen_buffer_get_poll_events( struct object *obj );
|
2000-12-19 03:12:45 +01:00
|
|
|
static int screen_buffer_get_fd( struct object *obj );
|
1999-01-19 18:48:23 +01:00
|
|
|
static void screen_buffer_destroy( struct object *obj );
|
|
|
|
|
|
|
|
/* common routine */
|
1999-06-26 10:43:26 +02:00
|
|
|
static int console_get_info( struct object *obj, struct get_file_info_request *req );
|
1998-12-30 13:06:45 +01:00
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
static const struct object_ops console_input_ops =
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
sizeof(struct console_input), /* size */
|
|
|
|
console_input_dump, /* dump */
|
|
|
|
default_poll_add_queue, /* add_queue */
|
|
|
|
default_poll_remove_queue, /* remove_queue */
|
|
|
|
default_poll_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
console_input_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
2000-12-19 03:12:45 +01:00
|
|
|
console_input_get_fd, /* get_fd */
|
2000-01-01 01:56:27 +01:00
|
|
|
no_flush, /* flush */
|
|
|
|
console_get_info, /* get_file_info */
|
|
|
|
console_input_destroy /* destroy */
|
1999-01-19 18:48:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct object_ops screen_buffer_ops =
|
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
sizeof(struct screen_buffer), /* size */
|
|
|
|
screen_buffer_dump, /* dump */
|
|
|
|
default_poll_add_queue, /* add_queue */
|
|
|
|
default_poll_remove_queue, /* remove_queue */
|
|
|
|
default_poll_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
screen_buffer_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
2000-12-19 03:12:45 +01:00
|
|
|
screen_buffer_get_fd, /* get_fd */
|
2000-01-01 01:56:27 +01:00
|
|
|
no_flush, /* flush */
|
|
|
|
console_get_info, /* get_file_info */
|
|
|
|
screen_buffer_destroy /* destroy */
|
1998-12-30 13:06:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-06-22 19:26:53 +02:00
|
|
|
static struct object *create_console_input( int fd )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-01-19 18:48:23 +01:00
|
|
|
struct console_input *console_input;
|
1998-12-30 13:06:45 +01:00
|
|
|
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((fd = (fd != -1) ? dup(fd) : dup(0)) == -1)
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
|
|
|
file_set_error();
|
1999-06-22 19:26:53 +02:00
|
|
|
return NULL;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
2000-01-01 01:56:27 +01:00
|
|
|
if (!(console_input = alloc_object( &console_input_ops, fd ))) return NULL;
|
|
|
|
console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
|
|
|
|
ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
|
|
|
|
console_input->output = NULL;
|
|
|
|
console_input->recnum = 0;
|
|
|
|
console_input->records = NULL;
|
|
|
|
return &console_input->obj;
|
1999-06-22 19:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct object *create_console_output( int fd, struct object *input )
|
|
|
|
{
|
|
|
|
struct console_input *console_input = (struct console_input *)input;
|
|
|
|
struct screen_buffer *screen_buffer;
|
|
|
|
|
|
|
|
if ((fd = (fd != -1) ? dup(fd) : dup(1)) == -1)
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
file_set_error();
|
|
|
|
return NULL;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
2000-01-01 01:56:27 +01:00
|
|
|
if (!(screen_buffer = alloc_object( &screen_buffer_ops, fd ))) return NULL;
|
|
|
|
screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
|
|
|
screen_buffer->input = console_input;
|
|
|
|
screen_buffer->cursor_size = 100;
|
|
|
|
screen_buffer->cursor_visible = 1;
|
|
|
|
screen_buffer->pid = 0;
|
|
|
|
screen_buffer->title = strdup( "Wine console" );
|
|
|
|
console_input->output = screen_buffer;
|
|
|
|
return &screen_buffer->obj;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
1999-06-11 20:31:22 +02:00
|
|
|
/* allocate a console for this process */
|
|
|
|
int alloc_console( struct process *process )
|
|
|
|
{
|
|
|
|
if (process->console_in || process->console_out)
|
|
|
|
{
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
1999-06-11 20:31:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((process->console_in = create_console_input( -1 )))
|
|
|
|
{
|
|
|
|
if ((process->console_out = create_console_output( -1, process->console_in )))
|
|
|
|
return 1;
|
|
|
|
release_object( process->console_in );
|
|
|
|
}
|
|
|
|
return 0;
|
1999-06-11 20:31:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free the console for this process */
|
|
|
|
int free_console( struct process *process )
|
|
|
|
{
|
|
|
|
if (process->console_in) release_object( process->console_in );
|
|
|
|
if (process->console_out) release_object( process->console_out );
|
|
|
|
process->console_in = process->console_out = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-01-05 05:08:07 +01:00
|
|
|
static int set_console_fd( handle_t handle, int fd_in, int fd_out, int pid )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-01-19 18:48:23 +01:00
|
|
|
struct console_input *input;
|
|
|
|
struct screen_buffer *output;
|
|
|
|
struct object *obj;
|
|
|
|
|
|
|
|
if (!(obj = get_handle_obj( current->process, handle, 0, NULL )))
|
|
|
|
return 0;
|
|
|
|
if (obj->ops == &console_input_ops)
|
|
|
|
{
|
|
|
|
input = (struct console_input *)obj;
|
|
|
|
output = input->output;
|
|
|
|
grab_object( output );
|
|
|
|
}
|
|
|
|
else if (obj->ops == &screen_buffer_ops)
|
|
|
|
{
|
|
|
|
output = (struct screen_buffer *)obj;
|
|
|
|
input = output->input;
|
|
|
|
grab_object( input );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
1999-01-19 18:48:23 +01:00
|
|
|
release_object( obj );
|
|
|
|
return 0;
|
|
|
|
}
|
1998-12-30 13:06:45 +01:00
|
|
|
|
1999-05-16 18:59:38 +02:00
|
|
|
/* can't change the fd if someone is waiting on it */
|
|
|
|
assert( !input->obj.head );
|
|
|
|
assert( !output->obj.head );
|
|
|
|
|
2000-01-01 01:56:27 +01:00
|
|
|
change_select_fd( &input->obj, fd_in );
|
|
|
|
change_select_fd( &output->obj, fd_out );
|
1999-12-13 01:16:44 +01:00
|
|
|
output->pid = pid;
|
1999-01-19 18:48:23 +01:00
|
|
|
release_object( input );
|
|
|
|
release_object( output );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-01-05 05:08:07 +01:00
|
|
|
static int get_console_mode( handle_t handle )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
|
|
|
struct object *obj;
|
|
|
|
int ret = 0;
|
|
|
|
|
1999-06-26 10:43:26 +02:00
|
|
|
if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
if (obj->ops == &console_input_ops)
|
|
|
|
ret = ((struct console_input *)obj)->mode;
|
|
|
|
else if (obj->ops == &screen_buffer_ops)
|
|
|
|
ret = ((struct screen_buffer *)obj)->mode;
|
|
|
|
else
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
1999-06-26 10:43:26 +02:00
|
|
|
release_object( obj );
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-05 05:08:07 +01:00
|
|
|
static int set_console_mode( handle_t handle, int mode )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
|
|
|
struct object *obj;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!(obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
|
|
|
|
return 0;
|
|
|
|
if (obj->ops == &console_input_ops)
|
|
|
|
{
|
|
|
|
((struct console_input *)obj)->mode = mode;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
else if (obj->ops == &screen_buffer_ops)
|
|
|
|
{
|
|
|
|
((struct screen_buffer *)obj)->mode = mode;
|
|
|
|
ret = 1;
|
|
|
|
}
|
2000-01-24 22:58:06 +01:00
|
|
|
else set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
1999-01-19 18:48:23 +01:00
|
|
|
release_object( obj );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set misc console information (output handle only) */
|
2001-01-05 05:08:07 +01:00
|
|
|
static int set_console_info( handle_t handle, struct set_console_info_request *req,
|
1999-06-22 19:26:53 +02:00
|
|
|
const char *title, size_t len )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
|
|
|
struct screen_buffer *console;
|
|
|
|
if (!(console = (struct screen_buffer *)get_handle_obj( current->process, handle,
|
|
|
|
GENERIC_WRITE, &screen_buffer_ops )))
|
|
|
|
return 0;
|
|
|
|
if (req->mask & SET_CONSOLE_INFO_CURSOR)
|
|
|
|
{
|
|
|
|
console->cursor_size = req->cursor_size;
|
|
|
|
console->cursor_visible = req->cursor_visible;
|
|
|
|
}
|
|
|
|
if (req->mask & SET_CONSOLE_INFO_TITLE)
|
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
char *new_title = mem_alloc( len + 1 );
|
|
|
|
if (new_title)
|
|
|
|
{
|
|
|
|
memcpy( new_title, title, len );
|
|
|
|
new_title[len] = 0;
|
|
|
|
if (console->title) free( console->title );
|
|
|
|
console->title = new_title;
|
|
|
|
}
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
release_object( console );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-01-31 20:04:30 +01:00
|
|
|
/* add input events to a console input queue */
|
2001-01-05 05:08:07 +01:00
|
|
|
static int write_console_input( handle_t handle, int count, INPUT_RECORD *records )
|
1999-01-31 20:04:30 +01:00
|
|
|
{
|
|
|
|
INPUT_RECORD *new_rec;
|
|
|
|
struct console_input *console;
|
|
|
|
|
|
|
|
if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
|
|
|
|
GENERIC_WRITE, &console_input_ops )))
|
|
|
|
return -1;
|
|
|
|
if (!(new_rec = realloc( console->records,
|
|
|
|
(console->recnum + count) * sizeof(INPUT_RECORD) )))
|
|
|
|
{
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_NO_MEMORY );
|
1999-01-31 20:04:30 +01:00
|
|
|
release_object( console );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
console->records = new_rec;
|
|
|
|
memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
|
|
|
|
console->recnum += count;
|
|
|
|
release_object( console );
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve a pointer to the console input records */
|
2001-01-05 05:08:07 +01:00
|
|
|
static int read_console_input( handle_t handle, int count, INPUT_RECORD *rec, int flush )
|
1999-01-31 20:04:30 +01:00
|
|
|
{
|
|
|
|
struct console_input *console;
|
|
|
|
|
|
|
|
if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
|
|
|
|
GENERIC_READ, &console_input_ops )))
|
|
|
|
return -1;
|
2000-08-31 03:59:51 +02:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
/* special case: do not retrieve anything, but return
|
|
|
|
* the total number of records available */
|
|
|
|
count = console->recnum;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (count > console->recnum) count = console->recnum;
|
|
|
|
memcpy( rec, console->records, count * sizeof(INPUT_RECORD) );
|
|
|
|
}
|
1999-01-31 20:04:30 +01:00
|
|
|
if (flush)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = count; i < console->recnum; i++)
|
|
|
|
console->records[i-count] = console->records[i];
|
|
|
|
if ((console->recnum -= count) > 0)
|
|
|
|
{
|
|
|
|
INPUT_RECORD *new_rec = realloc( console->records,
|
|
|
|
console->recnum * sizeof(INPUT_RECORD) );
|
|
|
|
if (new_rec) console->records = new_rec;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free( console->records );
|
|
|
|
console->records = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
release_object( console );
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
static void console_input_dump( struct object *obj, int verbose )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-01-19 18:48:23 +01:00
|
|
|
struct console_input *console = (struct console_input *)obj;
|
|
|
|
assert( obj->ops == &console_input_ops );
|
2000-01-01 01:56:27 +01:00
|
|
|
fprintf( stderr, "Console input fd=%d\n", console->obj.fd );
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
2000-01-01 01:56:27 +01:00
|
|
|
static int console_input_get_poll_events( struct object *obj )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
return POLLIN;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
2000-12-19 03:12:45 +01:00
|
|
|
static int console_input_get_fd( struct object *obj )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-01-19 18:48:23 +01:00
|
|
|
struct console_input *console = (struct console_input *)obj;
|
|
|
|
assert( obj->ops == &console_input_ops );
|
2000-12-22 22:12:36 +01:00
|
|
|
return console->obj.fd;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
1999-06-26 10:43:26 +02:00
|
|
|
static int console_get_info( struct object *obj, struct get_file_info_request *req )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
2001-10-04 18:18:15 +02:00
|
|
|
if (req)
|
|
|
|
{
|
|
|
|
req->type = FILE_TYPE_CHAR;
|
|
|
|
req->attr = 0;
|
|
|
|
req->access_time = 0;
|
|
|
|
req->write_time = 0;
|
|
|
|
req->size_high = 0;
|
|
|
|
req->size_low = 0;
|
|
|
|
req->links = 0;
|
|
|
|
req->index_high = 0;
|
|
|
|
req->index_low = 0;
|
|
|
|
req->serial = 0;
|
|
|
|
}
|
|
|
|
return FD_TYPE_CONSOLE;
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void console_input_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct console_input *console = (struct console_input *)obj;
|
|
|
|
assert( obj->ops == &console_input_ops );
|
|
|
|
if (console->output) console->output->input = NULL;
|
|
|
|
}
|
1998-12-30 13:06:45 +01:00
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
static void screen_buffer_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct screen_buffer *console = (struct screen_buffer *)obj;
|
|
|
|
assert( obj->ops == &screen_buffer_ops );
|
2000-01-01 01:56:27 +01:00
|
|
|
fprintf( stderr, "Console screen buffer fd=%d\n", console->obj.fd );
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
|
2000-01-01 01:56:27 +01:00
|
|
|
static int screen_buffer_get_poll_events( struct object *obj )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
return POLLOUT;
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
|
2000-12-19 03:12:45 +01:00
|
|
|
static int screen_buffer_get_fd( struct object *obj )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
|
|
|
struct screen_buffer *console = (struct screen_buffer *)obj;
|
|
|
|
assert( obj->ops == &screen_buffer_ops );
|
2000-12-22 22:12:36 +01:00
|
|
|
return console->obj.fd;
|
1999-01-03 12:55:56 +01:00
|
|
|
}
|
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
static void screen_buffer_destroy( struct object *obj )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-01-19 18:48:23 +01:00
|
|
|
struct screen_buffer *console = (struct screen_buffer *)obj;
|
|
|
|
assert( obj->ops == &screen_buffer_ops );
|
|
|
|
if (console->input) console->input->output = NULL;
|
|
|
|
if (console->title) free( console->title );
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
/* allocate a console for the current process */
|
|
|
|
DECL_HANDLER(alloc_console)
|
|
|
|
{
|
2001-01-05 05:08:07 +01:00
|
|
|
handle_t in = 0, out = 0;
|
1999-06-11 20:31:22 +02:00
|
|
|
|
|
|
|
if (!alloc_console( current->process )) goto done;
|
|
|
|
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((in = alloc_handle( current->process, current->process->console_in,
|
2001-01-05 05:08:07 +01:00
|
|
|
req->access, req->inherit )))
|
1999-06-11 20:31:22 +02:00
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((out = alloc_handle( current->process, current->process->console_out,
|
2001-01-05 05:08:07 +01:00
|
|
|
req->access, req->inherit )))
|
1999-06-11 20:31:22 +02:00
|
|
|
goto done; /* everything is fine */
|
2000-12-22 03:04:15 +01:00
|
|
|
close_handle( current->process, in, NULL );
|
2001-01-05 05:08:07 +01:00
|
|
|
in = 0;
|
1999-06-11 20:31:22 +02:00
|
|
|
}
|
|
|
|
free_console( current->process );
|
|
|
|
|
|
|
|
done:
|
1999-06-26 10:43:26 +02:00
|
|
|
req->handle_in = in;
|
|
|
|
req->handle_out = out;
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free the console of the current process */
|
|
|
|
DECL_HANDLER(free_console)
|
|
|
|
{
|
|
|
|
free_console( current->process );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a handle to the process console */
|
|
|
|
DECL_HANDLER(open_console)
|
|
|
|
{
|
1999-06-11 20:31:22 +02:00
|
|
|
struct object *obj= req->output ? current->process->console_out : current->process->console_in;
|
|
|
|
|
2001-01-05 05:08:07 +01:00
|
|
|
req->handle = 0;
|
1999-06-26 10:43:26 +02:00
|
|
|
if (obj) req->handle = alloc_handle( current->process, obj, req->access, req->inherit );
|
2000-01-24 22:58:06 +01:00
|
|
|
else set_error( STATUS_ACCESS_DENIED );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set info about a console (output only) */
|
|
|
|
DECL_HANDLER(set_console_info)
|
|
|
|
{
|
2000-08-31 03:59:51 +02:00
|
|
|
set_console_info( req->handle, req, get_req_data(req), get_req_data_size(req) );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get info about a console (output only) */
|
|
|
|
DECL_HANDLER(get_console_info)
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
struct screen_buffer *console;
|
2000-08-31 03:59:51 +02:00
|
|
|
size_t len = 0;
|
|
|
|
|
1999-06-26 10:43:26 +02:00
|
|
|
if ((console = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
|
|
|
|
GENERIC_READ, &screen_buffer_ops )))
|
|
|
|
{
|
|
|
|
req->cursor_size = console->cursor_size;
|
|
|
|
req->cursor_visible = console->cursor_visible;
|
|
|
|
req->pid = console->pid;
|
2000-08-31 03:59:51 +02:00
|
|
|
if (console->title)
|
|
|
|
{
|
|
|
|
len = strlen( console->title );
|
|
|
|
if (len > get_req_data_size(req)) len = get_req_data_size(req);
|
|
|
|
memcpy( get_req_data(req), console->title, len );
|
|
|
|
}
|
1999-06-26 10:43:26 +02:00
|
|
|
release_object( console );
|
|
|
|
}
|
2000-08-31 03:59:51 +02:00
|
|
|
set_req_data_size( req, len );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set a console fd */
|
|
|
|
DECL_HANDLER(set_console_fd)
|
|
|
|
{
|
2001-03-22 20:35:27 +01:00
|
|
|
int fd_out, fd_in = thread_get_inflight_fd( current, req->fd_in );
|
1999-06-26 10:43:26 +02:00
|
|
|
|
2001-03-22 20:35:27 +01:00
|
|
|
if (req->fd_out == req->fd_in) fd_out = dup( fd_in );
|
|
|
|
else fd_out = thread_get_inflight_fd( current, req->fd_out );
|
2001-02-16 20:08:19 +01:00
|
|
|
|
2001-03-22 20:35:27 +01:00
|
|
|
if (fd_in == -1 || fd_out == -1) set_error( STATUS_INVALID_HANDLE );
|
|
|
|
else if (set_console_fd( req->handle, fd_in, fd_out, req->pid )) return;
|
2001-02-16 20:08:19 +01:00
|
|
|
|
2001-03-22 20:35:27 +01:00
|
|
|
if (fd_in != -1) close( fd_in );
|
|
|
|
if (fd_out != -1) close( fd_out );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get a console mode (input or output) */
|
|
|
|
DECL_HANDLER(get_console_mode)
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
req->mode = get_console_mode( req->handle );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set a console mode (input or output) */
|
|
|
|
DECL_HANDLER(set_console_mode)
|
|
|
|
{
|
|
|
|
set_console_mode( req->handle, req->mode );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add input records to a console input queue */
|
|
|
|
DECL_HANDLER(write_console_input)
|
|
|
|
{
|
2000-08-31 03:59:51 +02:00
|
|
|
req->written = write_console_input( req->handle, get_req_data_size(req) / sizeof(INPUT_RECORD),
|
|
|
|
get_req_data(req) );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fetch input records from a console input queue */
|
|
|
|
DECL_HANDLER(read_console_input)
|
|
|
|
{
|
2000-08-31 03:59:51 +02:00
|
|
|
size_t size = get_req_data_size(req) / sizeof(INPUT_RECORD);
|
|
|
|
int res = read_console_input( req->handle, size, get_req_data(req), req->flush );
|
|
|
|
/* if size was 0 we didn't fetch anything */
|
|
|
|
if (size) set_req_data_size( req, res * sizeof(INPUT_RECORD) );
|
|
|
|
req->read = res;
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|