1998-12-30 13:06:45 +01:00
|
|
|
/*
|
|
|
|
* Server-side console management
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Alexandre Julliard
|
2001-11-24 00:04:58 +01:00
|
|
|
* 2001 Eric Pouech
|
2020-10-15 18:19:43 +02:00
|
|
|
* Copyright 2020 Jacek Caban for CodeWeavers
|
1998-12-30 13:06:45 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1998-12-30 13:06:45 +01:00
|
|
|
*/
|
|
|
|
|
1999-10-25 00:13:47 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-12-30 13:06:45 +01:00
|
|
|
#include <assert.h>
|
1999-01-03 12:55:56 +01:00
|
|
|
#include <string.h>
|
1998-12-30 13:06:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2002-06-02 23:22:22 +02:00
|
|
|
#include <signal.h>
|
2020-09-21 17:06:26 +02:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <termios.h>
|
1998-12-30 13:06:45 +01:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
1999-05-15 12:48:19 +02:00
|
|
|
#include "handle.h"
|
|
|
|
#include "process.h"
|
1999-06-22 19:26:53 +02:00
|
|
|
#include "request.h"
|
2010-08-28 13:14:43 +02:00
|
|
|
#include "file.h"
|
2001-11-24 00:04:58 +01:00
|
|
|
#include "unicode.h"
|
2007-05-11 12:46:32 +02:00
|
|
|
#include "wincon.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "winternl.h"
|
2020-07-06 19:26:56 +02:00
|
|
|
#include "wine/condrv.h"
|
1998-12-30 13:06:45 +01:00
|
|
|
|
2007-05-11 12:46:32 +02:00
|
|
|
struct screen_buffer;
|
|
|
|
|
2020-03-21 11:57:39 +01:00
|
|
|
struct history_line
|
|
|
|
{
|
|
|
|
data_size_t len;
|
|
|
|
WCHAR text[1];
|
|
|
|
};
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console
|
2007-05-11 12:46:32 +02:00
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
2020-11-10 16:31:43 +01:00
|
|
|
int signaled; /* is console signaled */
|
2007-05-11 12:46:32 +02:00
|
|
|
struct thread *renderer; /* console renderer thread */
|
|
|
|
struct screen_buffer *active; /* active screen buffer */
|
2020-08-20 23:48:21 +02:00
|
|
|
struct console_server *server; /* console server object */
|
2020-08-27 15:04:27 +02:00
|
|
|
unsigned int last_id; /* id of last created console buffer */
|
2010-08-30 22:18:44 +02:00
|
|
|
struct fd *fd; /* for bare console, attached input fd */
|
2020-08-20 23:50:20 +02:00
|
|
|
struct async_queue ioctl_q; /* ioctl queue */
|
2020-07-06 19:28:40 +02:00
|
|
|
struct async_queue read_q; /* read queue */
|
2007-05-11 12:46:32 +02:00
|
|
|
};
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static void console_dump( struct object *obj, int verbose );
|
|
|
|
static void console_destroy( struct object *obj );
|
|
|
|
static int console_signaled( struct object *obj, struct wait_queue_entry *entry );
|
|
|
|
static struct fd *console_get_fd( struct object *obj );
|
|
|
|
static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root );
|
|
|
|
static struct object *console_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2021-12-17 17:18:51 +01:00
|
|
|
static int console_add_queue( struct object *obj, struct wait_queue_entry *entry );
|
1999-01-19 18:48:23 +01:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static const struct object_ops console_ops =
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
sizeof(struct console), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&file_type, /* type */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_dump, /* dump */
|
2021-12-17 17:18:51 +01:00
|
|
|
console_add_queue, /* add_queue */
|
2020-11-10 16:31:43 +01:00
|
|
|
remove_queue, /* remove_queue */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_signaled, /* signaled */
|
2000-01-01 01:56:27 +01:00
|
|
|
no_satisfied, /* satisfied */
|
2005-04-24 19:35:52 +02:00
|
|
|
no_signal, /* signal */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
no_get_full_name, /* get_full_name */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_lookup_name, /* lookup_name */
|
2016-02-04 13:07:19 +01:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_open_file, /* open_file */
|
2019-03-25 14:37:09 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-06-09 17:39:52 +02:00
|
|
|
no_close_handle, /* close_handle */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_destroy /* destroy */
|
1999-01-19 18:48:23 +01:00
|
|
|
};
|
|
|
|
|
2020-07-09 19:28:07 +02:00
|
|
|
static enum server_fd_type console_get_fd_type( struct fd *fd );
|
2020-11-20 15:39:44 +01:00
|
|
|
static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
|
2021-09-03 02:08:50 +02:00
|
|
|
static void console_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class );
|
2021-09-03 02:08:51 +02:00
|
|
|
static void console_read( struct fd *fd, struct async *async, file_pos_t pos );
|
2021-09-03 02:08:53 +02:00
|
|
|
static void console_flush( struct fd *fd, struct async *async );
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2020-07-09 19:28:07 +02:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static const struct fd_ops console_fd_ops =
|
2020-07-09 19:28:07 +02:00
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
console_get_fd_type, /* get_fd_type */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_read, /* read */
|
2020-07-09 19:28:07 +02:00
|
|
|
no_fd_write, /* write */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_flush, /* flush */
|
2020-11-20 15:39:44 +01:00
|
|
|
console_get_file_info, /* get_file_info */
|
2020-11-20 15:40:19 +01:00
|
|
|
console_get_volume_info, /* get_volume_info */
|
2020-11-27 18:13:30 +01:00
|
|
|
console_ioctl, /* ioctl */
|
2021-09-04 06:11:38 +02:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2020-07-09 19:28:07 +02:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
|
|
|
};
|
|
|
|
|
2020-08-20 23:50:20 +02:00
|
|
|
struct console_host_ioctl
|
|
|
|
{
|
|
|
|
unsigned int code; /* ioctl code */
|
2020-08-27 15:04:27 +02:00
|
|
|
int output; /* output id for screen buffer ioctls */
|
2020-08-20 23:50:20 +02:00
|
|
|
struct async *async; /* ioctl async */
|
|
|
|
struct list entry; /* list entry */
|
|
|
|
};
|
|
|
|
|
2020-08-20 23:48:08 +02:00
|
|
|
struct console_server
|
|
|
|
{
|
2021-12-17 17:18:51 +01:00
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pseudo-fd for ioctls */
|
|
|
|
struct console *console; /* attached console */
|
|
|
|
struct list queue; /* ioctl queue */
|
|
|
|
struct list read_queue; /* blocking read queue */
|
|
|
|
unsigned int busy : 1; /* flag if server processing an ioctl */
|
|
|
|
unsigned int once_input : 1; /* flag if input thread has already been requested */
|
|
|
|
int term_fd; /* UNIX terminal fd */
|
|
|
|
struct termios termios; /* original termios */
|
2020-08-20 23:48:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void console_server_dump( struct object *obj, int verbose );
|
|
|
|
static void console_server_destroy( struct object *obj );
|
|
|
|
static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry );
|
2020-09-01 15:36:23 +02:00
|
|
|
static struct fd *console_server_get_fd( struct object *obj );
|
2020-11-25 19:42:42 +01:00
|
|
|
static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root );
|
2020-08-20 23:48:08 +02:00
|
|
|
static struct object *console_server_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
|
|
|
|
|
|
|
static const struct object_ops console_server_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct console_server), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&file_type, /* type */
|
2020-08-20 23:48:08 +02:00
|
|
|
console_server_dump, /* dump */
|
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
|
|
|
console_server_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2020-09-01 15:36:23 +02:00
|
|
|
console_server_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2020-08-20 23:48:08 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
no_get_full_name, /* get_full_name */
|
2020-08-20 23:48:21 +02:00
|
|
|
console_server_lookup_name, /* lookup_name */
|
2020-08-20 23:48:08 +02:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
|
|
|
console_server_open_file, /* open_file */
|
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2021-03-23 05:04:30 +01:00
|
|
|
no_close_handle, /* close_handle */
|
2020-08-20 23:48:08 +02:00
|
|
|
console_server_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2020-09-01 15:36:23 +02:00
|
|
|
|
|
|
|
static const struct fd_ops console_server_fd_ops =
|
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
console_get_fd_type, /* get_fd_type */
|
|
|
|
no_fd_read, /* read */
|
|
|
|
no_fd_write, /* write */
|
|
|
|
no_fd_flush, /* flush */
|
|
|
|
no_fd_get_file_info, /* get_file_info */
|
|
|
|
no_fd_get_volume_info, /* get_volume_info */
|
|
|
|
console_server_ioctl, /* ioctl */
|
2021-09-04 06:11:38 +02:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2020-09-01 15:36:23 +02:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
|
|
|
};
|
|
|
|
|
2015-10-29 13:17:18 +01:00
|
|
|
struct font_info
|
|
|
|
{
|
|
|
|
short int width;
|
|
|
|
short int height;
|
2019-11-20 11:45:28 +01:00
|
|
|
short int weight;
|
|
|
|
short int pitch_family;
|
|
|
|
WCHAR *face_name;
|
|
|
|
data_size_t face_len;
|
2015-10-29 13:17:18 +01:00
|
|
|
};
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
struct screen_buffer
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
2005-02-25 22:06:11 +01:00
|
|
|
struct list entry; /* entry in list of all screen buffers */
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *input; /* associated console input */
|
2020-08-27 15:04:27 +02:00
|
|
|
unsigned int id; /* buffer id */
|
2010-08-30 22:18:52 +02:00
|
|
|
struct fd *fd; /* for bare console, attached output fd */
|
2020-08-27 15:05:09 +02:00
|
|
|
struct async_queue ioctl_q; /* ioctl queue */
|
2001-11-24 00:04:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void screen_buffer_dump( struct object *obj, int verbose );
|
|
|
|
static void screen_buffer_destroy( struct object *obj );
|
2020-11-10 16:31:53 +01:00
|
|
|
static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry );
|
2010-08-30 22:18:52 +02:00
|
|
|
static struct fd *screen_buffer_get_fd( struct object *obj );
|
2020-06-25 22:26:54 +02:00
|
|
|
static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2001-11-24 00:04:58 +01:00
|
|
|
|
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 */
|
2021-02-04 13:44:18 +01:00
|
|
|
&file_type, /* type */
|
2000-01-01 01:56:27 +01:00
|
|
|
screen_buffer_dump, /* dump */
|
2020-11-10 16:31:53 +01:00
|
|
|
screen_buffer_add_queue, /* add_queue */
|
2001-11-24 00:04:58 +01:00
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
2005-04-24 19:35:52 +02:00
|
|
|
no_signal, /* signal */
|
2010-08-30 22:18:52 +02:00
|
|
|
screen_buffer_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
no_get_full_name, /* get_full_name */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 13:07:19 +01:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2020-06-25 22:26:54 +02:00
|
|
|
screen_buffer_open_file, /* open_file */
|
2019-03-25 14:37:09 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-06-09 17:39:52 +02:00
|
|
|
no_close_handle, /* close_handle */
|
2000-01-01 01:56:27 +01:00
|
|
|
screen_buffer_destroy /* destroy */
|
1998-12-30 13:06:45 +01:00
|
|
|
};
|
|
|
|
|
2021-09-03 02:08:52 +02:00
|
|
|
static void screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos );
|
2021-09-03 02:08:54 +02:00
|
|
|
static void screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2010-08-30 22:18:44 +02:00
|
|
|
|
2020-07-09 19:28:07 +02:00
|
|
|
static const struct fd_ops screen_buffer_fd_ops =
|
2010-08-30 22:18:44 +02:00
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
console_get_fd_type, /* get_fd_type */
|
2015-05-05 05:17:45 +02:00
|
|
|
no_fd_read, /* read */
|
2020-11-17 18:58:16 +01:00
|
|
|
screen_buffer_write, /* write */
|
2015-05-05 05:17:45 +02:00
|
|
|
no_fd_flush, /* flush */
|
2020-11-20 15:39:44 +01:00
|
|
|
console_get_file_info, /* get_file_info */
|
2020-11-20 15:40:19 +01:00
|
|
|
console_get_volume_info, /* get_volume_info */
|
2020-07-09 19:28:07 +02:00
|
|
|
screen_buffer_ioctl, /* ioctl */
|
2021-09-04 06:11:38 +02:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2010-08-30 22:18:44 +02:00
|
|
|
default_fd_queue_async, /* queue_async */
|
2016-12-01 12:10:34 +01:00
|
|
|
default_fd_reselect_async /* reselect_async */
|
2010-08-30 22:18:44 +02:00
|
|
|
};
|
|
|
|
|
2020-06-25 22:26:35 +02:00
|
|
|
static void console_device_dump( struct object *obj, int verbose );
|
2020-11-25 19:42:42 +01:00
|
|
|
static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root );
|
2020-06-25 22:26:35 +02:00
|
|
|
static struct object *console_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
|
|
|
|
|
|
|
static const struct object_ops console_device_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct object), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&device_type, /* type */
|
2020-06-25 22:26:35 +02:00
|
|
|
console_device_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2020-06-25 22:26:35 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
default_get_full_name, /* get_full_name */
|
2020-06-25 22:26:35 +02:00
|
|
|
console_device_lookup_name, /* lookup_name */
|
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
|
|
|
console_device_open_file, /* open_file */
|
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
no_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2020-11-27 18:13:59 +01:00
|
|
|
struct console_input
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pseudo-fd */
|
|
|
|
};
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static void console_input_dump( struct object *obj, int verbose );
|
|
|
|
static struct object *console_input_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
|
|
|
static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry );
|
|
|
|
static struct fd *console_input_get_fd( struct object *obj );
|
2020-11-27 18:13:59 +01:00
|
|
|
static void console_input_destroy( struct object *obj );
|
2020-11-12 19:56:18 +01:00
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static const struct object_ops console_input_ops =
|
2020-11-12 19:56:18 +01:00
|
|
|
{
|
2020-11-27 18:13:59 +01:00
|
|
|
sizeof(struct console_input), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&device_type, /* type */
|
2020-11-27 18:13:51 +01:00
|
|
|
console_input_dump, /* dump */
|
|
|
|
console_input_add_queue, /* add_queue */
|
2020-11-12 19:56:18 +01:00
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2020-11-27 18:13:51 +01:00
|
|
|
console_input_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2020-11-12 19:56:18 +01:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
|
|
|
no_get_full_name, /* get_full_name */
|
|
|
|
no_lookup_name, /* lookup_name */
|
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2020-11-27 18:13:51 +01:00
|
|
|
console_input_open_file, /* open_file */
|
2020-11-12 19:56:18 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
|
|
|
no_close_handle, /* close_handle */
|
2020-11-27 18:13:59 +01:00
|
|
|
console_input_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2021-09-03 02:08:51 +02:00
|
|
|
static void console_input_read( struct fd *fd, struct async *async, file_pos_t pos );
|
2021-09-03 02:08:53 +02:00
|
|
|
static void console_input_flush( struct fd *fd, struct async *async );
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2020-11-27 18:13:59 +01:00
|
|
|
|
|
|
|
static const struct fd_ops console_input_fd_ops =
|
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
console_get_fd_type, /* get_fd_type */
|
|
|
|
console_input_read, /* read */
|
|
|
|
no_fd_write, /* write */
|
|
|
|
console_input_flush, /* flush */
|
|
|
|
console_get_file_info, /* get_file_info */
|
|
|
|
console_get_volume_info, /* get_volume_info */
|
|
|
|
console_input_ioctl, /* ioctl */
|
2021-09-04 06:11:38 +02:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2020-11-27 18:13:59 +01:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
2020-11-12 19:56:18 +01:00
|
|
|
};
|
|
|
|
|
2020-11-27 18:14:12 +01:00
|
|
|
struct console_output
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct fd *fd; /* pseudo-fd */
|
|
|
|
};
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static void console_output_dump( struct object *obj, int verbose );
|
|
|
|
static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry );
|
|
|
|
static struct fd *console_output_get_fd( struct object *obj );
|
|
|
|
static struct object *console_output_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
2020-11-27 18:14:12 +01:00
|
|
|
static void console_output_destroy( struct object *obj );
|
2020-11-12 19:56:23 +01:00
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static const struct object_ops console_output_ops =
|
2020-11-12 19:56:23 +01:00
|
|
|
{
|
2020-11-27 18:14:12 +01:00
|
|
|
sizeof(struct console_output), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&device_type, /* type */
|
2020-11-27 18:13:51 +01:00
|
|
|
console_output_dump, /* dump */
|
|
|
|
console_output_add_queue, /* add_queue */
|
2020-11-12 19:56:23 +01:00
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2020-11-27 18:13:51 +01:00
|
|
|
console_output_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2020-11-12 19:56:23 +01:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
|
|
|
no_get_full_name, /* get_full_name */
|
|
|
|
no_lookup_name, /* lookup_name */
|
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2020-11-27 18:13:51 +01:00
|
|
|
console_output_open_file, /* open_file */
|
2020-11-12 19:56:23 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
|
|
|
no_close_handle, /* close_handle */
|
2020-11-27 18:14:12 +01:00
|
|
|
console_output_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2021-09-03 02:08:52 +02:00
|
|
|
static void console_output_write( struct fd *fd, struct async *async, file_pos_t pos );
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2020-11-27 18:14:12 +01:00
|
|
|
|
|
|
|
static const struct fd_ops console_output_fd_ops =
|
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
console_get_fd_type, /* get_fd_type */
|
|
|
|
no_fd_read, /* read */
|
|
|
|
console_output_write, /* write */
|
|
|
|
no_fd_flush, /* flush */
|
|
|
|
console_get_file_info, /* get_file_info */
|
|
|
|
console_get_volume_info, /* get_volume_info */
|
|
|
|
console_output_ioctl, /* ioctl */
|
2021-09-04 06:11:38 +02:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2020-11-27 18:14:12 +01:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
2020-11-12 19:56:23 +01:00
|
|
|
};
|
|
|
|
|
2020-09-16 20:38:37 +02:00
|
|
|
struct console_connection
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
2020-09-16 20:39:26 +02:00
|
|
|
struct fd *fd; /* pseudo-fd for ioctls */
|
2020-09-16 20:38:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void console_connection_dump( struct object *obj, int verbose );
|
2020-09-16 20:39:26 +02:00
|
|
|
static struct fd *console_connection_get_fd( struct object *obj );
|
2020-11-25 19:42:42 +01:00
|
|
|
static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root );
|
2020-09-16 20:38:37 +02:00
|
|
|
static struct object *console_connection_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
|
|
|
static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
|
2020-09-16 20:39:26 +02:00
|
|
|
static void console_connection_destroy( struct object *obj );
|
2020-09-16 20:38:37 +02:00
|
|
|
|
|
|
|
static const struct object_ops console_connection_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct console_connection),/* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&device_type, /* type */
|
2020-09-16 20:38:37 +02:00
|
|
|
console_connection_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2020-09-16 20:39:26 +02:00
|
|
|
console_connection_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2020-09-16 20:38:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
no_get_full_name, /* get_full_name */
|
2020-09-16 20:39:35 +02:00
|
|
|
console_connection_lookup_name, /* lookup_name */
|
2020-09-16 20:38:37 +02:00
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
|
|
|
console_connection_open_file, /* open_file */
|
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
|
|
|
console_connection_close_handle, /* close_handle */
|
2020-09-16 20:39:26 +02:00
|
|
|
console_connection_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2020-09-16 20:39:26 +02:00
|
|
|
|
|
|
|
static const struct fd_ops console_connection_fd_ops =
|
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
console_get_fd_type, /* get_fd_type */
|
|
|
|
no_fd_read, /* read */
|
|
|
|
no_fd_write, /* write */
|
|
|
|
no_fd_flush, /* flush */
|
|
|
|
no_fd_get_file_info, /* get_file_info */
|
|
|
|
no_fd_get_volume_info, /* get_volume_info */
|
|
|
|
console_connection_ioctl, /* ioctl */
|
2021-09-04 06:11:38 +02:00
|
|
|
default_fd_cancel_async, /* cancel_async */
|
2020-09-16 20:39:26 +02:00
|
|
|
default_fd_queue_async, /* queue_async */
|
|
|
|
default_fd_reselect_async /* reselect_async */
|
2020-09-16 20:38:37 +02:00
|
|
|
};
|
|
|
|
|
2005-02-25 22:06:11 +01:00
|
|
|
static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2021-12-17 17:18:51 +01:00
|
|
|
static int queue_host_ioctl( struct console_server *server, unsigned int code, unsigned int output,
|
|
|
|
struct async *async, struct async_queue *queue );
|
|
|
|
|
|
|
|
static int console_add_queue( struct object *obj, struct wait_queue_entry *entry )
|
|
|
|
{
|
|
|
|
struct console *console = (struct console*)obj;
|
|
|
|
assert( obj->ops == &console_ops );
|
|
|
|
/* before waiting, ensure conhost's input thread has been started */
|
|
|
|
if (console->server && !console->server->once_input)
|
|
|
|
{
|
|
|
|
console->server->once_input = 1;
|
|
|
|
if (console->server->term_fd == -1)
|
|
|
|
queue_host_ioctl( console->server, IOCTL_CONDRV_PEEK, 0, NULL, NULL );
|
|
|
|
}
|
|
|
|
return add_queue( &console->obj, entry );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static int console_signaled( struct object *obj, struct wait_queue_entry *entry )
|
2020-11-10 16:31:43 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = (struct console*)obj;
|
2020-11-10 16:31:43 +01:00
|
|
|
return console->signaled;
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static struct fd *console_get_fd( struct object *obj )
|
2010-08-30 22:18:44 +02:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = (struct console *)obj;
|
|
|
|
assert( obj->ops == &console_ops );
|
|
|
|
return (struct fd *)grab_object( console->fd );
|
2010-08-30 22:18:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum server_fd_type console_get_fd_type( struct fd *fd )
|
|
|
|
{
|
|
|
|
return FD_TYPE_CHAR;
|
|
|
|
}
|
|
|
|
|
2020-11-20 15:39:44 +01:00
|
|
|
static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_DEVICE_REQUEST );
|
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:50 +02:00
|
|
|
static void console_get_volume_info( struct fd *fd, struct async *async, unsigned int info_class )
|
2020-11-20 15:40:19 +01:00
|
|
|
{
|
|
|
|
switch (info_class)
|
|
|
|
{
|
|
|
|
case FileFsDeviceInformation:
|
|
|
|
{
|
|
|
|
static const FILE_FS_DEVICE_INFORMATION device_info =
|
|
|
|
{
|
|
|
|
FILE_DEVICE_CONSOLE,
|
|
|
|
FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
|
|
|
|
};
|
|
|
|
if (get_reply_max_size() >= sizeof(device_info))
|
|
|
|
set_reply_data( &device_info, sizeof(device_info) );
|
|
|
|
else
|
|
|
|
set_error( STATUS_BUFFER_TOO_SMALL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
set_error( STATUS_NOT_IMPLEMENTED );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static struct object *create_console(void)
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console;
|
1998-12-30 13:06:45 +01:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
if (!(console = alloc_object( &console_ops )))
|
2014-11-17 19:15:20 +01:00
|
|
|
return NULL;
|
2020-09-22 16:47:10 +02:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
console->renderer = NULL;
|
|
|
|
console->signaled = 0;
|
|
|
|
console->active = NULL;
|
|
|
|
console->server = NULL;
|
|
|
|
console->fd = NULL;
|
|
|
|
console->last_id = 0;
|
|
|
|
init_async_queue( &console->ioctl_q );
|
|
|
|
init_async_queue( &console->read_q );
|
|
|
|
|
|
|
|
console->fd = alloc_pseudo_fd( &console_fd_ops, &console->obj, FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
if (!console->fd)
|
2020-07-06 19:25:50 +02:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
release_object( console );
|
2020-07-06 19:25:50 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-11-27 18:13:30 +01:00
|
|
|
allow_fd_caching( console->fd );
|
|
|
|
return &console->obj;
|
1999-06-22 19:26:53 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 23:50:20 +02:00
|
|
|
static void console_host_ioctl_terminate( struct console_host_ioctl *call, unsigned int status )
|
|
|
|
{
|
|
|
|
if (call->async)
|
|
|
|
{
|
|
|
|
async_terminate( call->async, status );
|
|
|
|
release_object( call->async );
|
|
|
|
}
|
|
|
|
free( call );
|
|
|
|
}
|
|
|
|
|
2020-08-27 15:04:27 +02:00
|
|
|
static int queue_host_ioctl( struct console_server *server, unsigned int code, unsigned int output,
|
2020-08-20 23:50:20 +02:00
|
|
|
struct async *async, struct async_queue *queue )
|
|
|
|
{
|
|
|
|
struct console_host_ioctl *ioctl;
|
|
|
|
|
|
|
|
if (!(ioctl = mem_alloc( sizeof(*ioctl) ))) return 0;
|
2020-08-27 15:04:27 +02:00
|
|
|
ioctl->code = code;
|
|
|
|
ioctl->output = output;
|
|
|
|
ioctl->async = NULL;
|
2020-08-20 23:50:20 +02:00
|
|
|
if (async)
|
|
|
|
{
|
|
|
|
ioctl->async = (struct async *)grab_object( async );
|
|
|
|
queue_async( queue, async );
|
|
|
|
}
|
|
|
|
list_add_tail( &server->queue, &ioctl->entry );
|
|
|
|
wake_up( &server->obj, 0 );
|
|
|
|
if (async) set_error( STATUS_PENDING );
|
2020-10-15 18:19:43 +02:00
|
|
|
return 1;
|
2020-08-20 23:50:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void disconnect_console_server( struct console_server *server )
|
|
|
|
{
|
|
|
|
while (!list_empty( &server->queue ))
|
|
|
|
{
|
|
|
|
struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
|
|
|
|
list_remove( &call->entry );
|
|
|
|
console_host_ioctl_terminate( call, STATUS_CANCELLED );
|
|
|
|
}
|
2020-08-25 14:52:48 +02:00
|
|
|
while (!list_empty( &server->read_queue ))
|
|
|
|
{
|
|
|
|
struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
|
|
|
|
list_remove( &call->entry );
|
|
|
|
console_host_ioctl_terminate( call, STATUS_CANCELLED );
|
|
|
|
}
|
2020-08-20 23:50:20 +02:00
|
|
|
|
2020-09-21 17:06:26 +02:00
|
|
|
if (server->term_fd != -1)
|
|
|
|
{
|
|
|
|
tcsetattr( server->term_fd, TCSANOW, &server->termios );
|
|
|
|
close( server->term_fd );
|
|
|
|
server->term_fd = -1;
|
|
|
|
}
|
|
|
|
|
2020-08-20 23:50:20 +02:00
|
|
|
if (server->console)
|
|
|
|
{
|
|
|
|
assert( server->console->server == server );
|
|
|
|
server->console->server = NULL;
|
|
|
|
server->console = NULL;
|
|
|
|
wake_up( &server->obj, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static void set_active_screen_buffer( struct console *console, struct screen_buffer *screen_buffer )
|
2007-12-18 01:03:11 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
if (console->active == screen_buffer) return;
|
|
|
|
if (console->active) release_object( console->active );
|
|
|
|
console->active = (struct screen_buffer *)grab_object( screen_buffer );
|
2020-08-27 15:03:43 +02:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_ACTIVATE,
|
|
|
|
screen_buffer->id, NULL, NULL );
|
2007-12-18 01:03:11 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:37 +01:00
|
|
|
static struct object *create_screen_buffer( struct console *console )
|
1999-06-22 19:26:53 +02:00
|
|
|
{
|
|
|
|
struct screen_buffer *screen_buffer;
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
if (console->last_id == ~0)
|
2020-08-27 15:04:27 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_NO_MEMORY );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-19 12:27:12 +02:00
|
|
|
if (!(screen_buffer = alloc_object( &screen_buffer_ops )))
|
|
|
|
return NULL;
|
2020-09-22 16:47:10 +02:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
screen_buffer->id = ++console->last_id;
|
|
|
|
screen_buffer->input = console;
|
2020-08-27 15:05:09 +02:00
|
|
|
init_async_queue( &screen_buffer->ioctl_q );
|
2015-08-19 12:15:01 +02:00
|
|
|
list_add_head( &screen_buffer_list, &screen_buffer->entry );
|
|
|
|
|
2020-09-22 16:47:10 +02:00
|
|
|
screen_buffer->fd = alloc_pseudo_fd( &screen_buffer_fd_ops, &screen_buffer->obj,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT );
|
2020-07-09 19:28:13 +02:00
|
|
|
if (!screen_buffer->fd)
|
2010-08-30 22:18:52 +02:00
|
|
|
{
|
2020-07-09 19:28:13 +02:00
|
|
|
release_object( screen_buffer );
|
|
|
|
return NULL;
|
2010-08-30 22:18:52 +02:00
|
|
|
}
|
2020-07-09 19:28:13 +02:00
|
|
|
allow_fd_caching(screen_buffer->fd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_INIT_OUTPUT,
|
|
|
|
screen_buffer->id, NULL, NULL );
|
|
|
|
if (!console->active) set_active_screen_buffer( console, screen_buffer );
|
2020-07-21 14:56:57 +02:00
|
|
|
return &screen_buffer->obj;
|
1999-06-11 20:31:22 +02:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
struct thread *console_get_renderer( struct console *console )
|
2007-05-11 12:46:32 +02:00
|
|
|
{
|
|
|
|
return console->renderer;
|
|
|
|
}
|
|
|
|
|
2004-09-08 03:25:05 +02:00
|
|
|
struct console_signal_info
|
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console;
|
|
|
|
process_id_t group;
|
|
|
|
int signal;
|
2002-06-02 23:22:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int propagate_console_signal_cb(struct process *process, void *user)
|
|
|
|
{
|
|
|
|
struct console_signal_info* csi = (struct console_signal_info*)user;
|
|
|
|
|
2021-03-11 18:09:42 +01:00
|
|
|
if (process->console == csi->console && (!csi->group || process->group_id == csi->group))
|
2002-06-02 23:22:22 +02:00
|
|
|
{
|
2004-09-08 03:25:05 +02:00
|
|
|
/* find a suitable thread to signal */
|
|
|
|
struct thread *thread;
|
2005-03-01 11:56:18 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
|
2002-06-02 23:22:22 +02:00
|
|
|
{
|
2004-09-08 03:25:05 +02:00
|
|
|
if (send_thread_signal( thread, csi->signal )) break;
|
2002-06-02 23:22:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static void propagate_console_signal( struct console *console,
|
2002-10-03 21:54:57 +02:00
|
|
|
int sig, process_id_t group_id )
|
2002-06-02 23:22:22 +02:00
|
|
|
{
|
|
|
|
struct console_signal_info csi;
|
|
|
|
|
|
|
|
if (!console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* FIXME: should support the other events (like CTRL_BREAK) */
|
|
|
|
if (sig != CTRL_C_EVENT)
|
|
|
|
{
|
|
|
|
set_error( STATUS_NOT_IMPLEMENTED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
csi.console = console;
|
|
|
|
csi.signal = SIGINT;
|
|
|
|
csi.group = group_id;
|
|
|
|
|
|
|
|
enum_processes(propagate_console_signal_cb, &csi);
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/* dumb dump */
|
2020-11-27 18:13:30 +01:00
|
|
|
static void console_dump( struct object *obj, int verbose )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = (struct console *)obj;
|
|
|
|
assert( obj->ops == &console_ops );
|
2020-10-14 19:57:24 +02:00
|
|
|
fprintf( stderr, "Console input active=%p server=%p\n",
|
|
|
|
console->active, console->server );
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static void console_destroy( struct object *obj )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = (struct console *)obj;
|
2020-10-13 16:30:16 +02:00
|
|
|
struct screen_buffer *curr;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
assert( obj->ops == &console_ops );
|
2020-08-20 23:48:21 +02:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
if (console->server)
|
2020-08-20 23:48:21 +02:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
assert( console->server->console == console );
|
|
|
|
disconnect_console_server( console->server );
|
2020-08-20 23:48:21 +02:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
if (console->active) release_object( console->active );
|
|
|
|
console->active = NULL;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2005-02-25 22:06:11 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
if (curr->input == console) curr->input = NULL;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
free_async_queue( &console->ioctl_q );
|
|
|
|
free_async_queue( &console->read_q );
|
|
|
|
if (console->fd)
|
|
|
|
release_object( console->fd );
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
1998-12-30 13:06:45 +01:00
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static struct object *create_console_connection( struct console *console )
|
2020-09-16 20:38:37 +02:00
|
|
|
{
|
|
|
|
struct console_connection *connection;
|
|
|
|
|
|
|
|
if (current->process->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(connection = alloc_object( &console_connection_ops ))) return NULL;
|
2020-09-16 20:39:26 +02:00
|
|
|
if (!(connection->fd = alloc_pseudo_fd( &console_connection_fd_ops, &connection->obj, 0 )))
|
|
|
|
{
|
|
|
|
release_object( connection );
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-09-16 20:38:37 +02:00
|
|
|
|
2020-09-16 20:39:10 +02:00
|
|
|
if (console)
|
2020-11-27 18:13:30 +01:00
|
|
|
current->process->console = (struct console *)grab_object( console );
|
2020-09-16 20:38:37 +02:00
|
|
|
|
|
|
|
return &connection->obj;
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root )
|
2020-09-16 20:38:37 +02:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = (struct console *)obj;
|
2020-09-16 20:38:37 +02:00
|
|
|
static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
|
2020-11-27 18:13:30 +01:00
|
|
|
assert( obj->ops == &console_ops );
|
2020-09-16 20:38:37 +02:00
|
|
|
|
|
|
|
if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
|
|
|
|
{
|
|
|
|
name->len = 0;
|
|
|
|
return create_console_connection( console );
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:30 +01:00
|
|
|
static struct object *console_open_file( struct object *obj, unsigned int access,
|
2020-06-25 22:26:45 +02:00
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
1999-01-19 18:48:23 +01:00
|
|
|
static void screen_buffer_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2001-11-24 00:04:58 +01:00
|
|
|
struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
|
1999-01-19 18:48:23 +01:00
|
|
|
assert( obj->ops == &screen_buffer_ops );
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
static void screen_buffer_destroy( struct object *obj )
|
1999-01-19 18:48:23 +01:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
assert( obj->ops == &screen_buffer_ops );
|
|
|
|
|
2005-02-25 22:06:11 +01:00
|
|
|
list_remove( &screen_buffer->entry );
|
2020-08-27 15:04:27 +02:00
|
|
|
if (screen_buffer->input && screen_buffer->input->server)
|
|
|
|
queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_CLOSE_OUTPUT,
|
|
|
|
screen_buffer->id, NULL, NULL );
|
2010-08-30 22:18:52 +02:00
|
|
|
if (screen_buffer->fd) release_object( screen_buffer->fd );
|
2020-08-27 15:05:09 +02:00
|
|
|
free_async_queue( &screen_buffer->ioctl_q );
|
1999-01-19 18:48:23 +01:00
|
|
|
}
|
|
|
|
|
2020-06-25 22:26:54 +02:00
|
|
|
static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
2020-11-10 16:31:53 +01:00
|
|
|
static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry )
|
|
|
|
{
|
|
|
|
struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
|
|
|
|
if (!screen_buffer->input)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return add_queue( &screen_buffer->input->obj, entry );
|
|
|
|
}
|
|
|
|
|
2010-08-30 22:18:52 +02:00
|
|
|
static struct fd *screen_buffer_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
|
|
|
|
assert( obj->ops == &screen_buffer_ops );
|
2010-09-16 21:05:26 +02:00
|
|
|
if (screen_buffer->fd)
|
|
|
|
return (struct fd*)grab_object( screen_buffer->fd );
|
|
|
|
set_error( STATUS_OBJECT_TYPE_MISMATCH );
|
|
|
|
return NULL;
|
2010-08-30 22:18:52 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 23:48:08 +02:00
|
|
|
static void console_server_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
assert( obj->ops == &console_server_ops );
|
|
|
|
fprintf( stderr, "Console server\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void console_server_destroy( struct object *obj )
|
|
|
|
{
|
2020-08-20 23:48:21 +02:00
|
|
|
struct console_server *server = (struct console_server *)obj;
|
|
|
|
assert( obj->ops == &console_server_ops );
|
2020-08-20 23:50:20 +02:00
|
|
|
disconnect_console_server( server );
|
2020-09-01 15:36:23 +02:00
|
|
|
if (server->fd) release_object( server->fd );
|
2020-08-20 23:48:21 +02:00
|
|
|
}
|
|
|
|
|
2020-11-25 19:42:42 +01:00
|
|
|
static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root )
|
2020-08-20 23:48:21 +02:00
|
|
|
{
|
|
|
|
struct console_server *server = (struct console_server*)obj;
|
|
|
|
static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
|
2020-08-20 23:48:08 +02:00
|
|
|
assert( obj->ops == &console_server_ops );
|
2020-08-20 23:48:21 +02:00
|
|
|
|
|
|
|
if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
|
|
|
|
{
|
|
|
|
struct screen_buffer *screen_buffer;
|
|
|
|
name->len = 0;
|
|
|
|
if (server->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return 0;
|
|
|
|
}
|
2020-11-27 18:13:30 +01:00
|
|
|
if (!(server->console = (struct console *)create_console())) return NULL;
|
2020-11-27 18:13:37 +01:00
|
|
|
if (!(screen_buffer = (struct screen_buffer *)create_screen_buffer( server->console )))
|
2020-08-20 23:48:21 +02:00
|
|
|
{
|
|
|
|
release_object( server->console );
|
|
|
|
server->console = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
release_object( screen_buffer );
|
|
|
|
server->console->server = server;
|
|
|
|
|
|
|
|
return &server->console->obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2020-08-20 23:48:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry )
|
|
|
|
{
|
2020-08-20 23:48:21 +02:00
|
|
|
struct console_server *server = (struct console_server*)obj;
|
2020-08-20 23:48:08 +02:00
|
|
|
assert( obj->ops == &console_server_ops );
|
2020-08-20 23:50:20 +02:00
|
|
|
return !server->console || !list_empty( &server->queue );
|
2020-08-20 23:48:08 +02:00
|
|
|
}
|
|
|
|
|
2020-09-01 15:36:23 +02:00
|
|
|
static struct fd *console_server_get_fd( struct object* obj )
|
|
|
|
{
|
|
|
|
struct console_server *server = (struct console_server*)obj;
|
|
|
|
assert( obj->ops == &console_server_ops );
|
|
|
|
return (struct fd *)grab_object( server->fd );
|
|
|
|
}
|
|
|
|
|
2020-08-20 23:48:08 +02:00
|
|
|
static struct object *console_server_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct object *create_console_server( void )
|
|
|
|
{
|
|
|
|
struct console_server *server;
|
|
|
|
|
|
|
|
if (!(server = alloc_object( &console_server_ops ))) return NULL;
|
2021-12-17 17:18:51 +01:00
|
|
|
server->console = NULL;
|
|
|
|
server->busy = 0;
|
|
|
|
server->once_input = 0;
|
|
|
|
server->term_fd = -1;
|
2020-08-20 23:50:20 +02:00
|
|
|
list_init( &server->queue );
|
2020-08-25 14:52:48 +02:00
|
|
|
list_init( &server->read_queue );
|
2020-09-01 15:36:23 +02:00
|
|
|
server->fd = alloc_pseudo_fd( &console_server_fd_ops, &server->obj, FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
if (!server->fd)
|
|
|
|
{
|
|
|
|
release_object( server );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
allow_fd_caching(server->fd);
|
2020-08-20 23:48:08 +02:00
|
|
|
|
|
|
|
return &server->obj;
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:52:48 +02:00
|
|
|
static int is_blocking_read_ioctl( unsigned int code )
|
|
|
|
{
|
2020-11-19 17:59:16 +01:00
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case IOCTL_CONDRV_READ_INPUT:
|
|
|
|
case IOCTL_CONDRV_READ_CONSOLE:
|
|
|
|
case IOCTL_CONDRV_READ_FILE:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2020-08-25 14:52:48 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2020-07-06 19:26:56 +02:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = get_fd_user( fd );
|
2020-07-06 19:26:56 +02:00
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
2020-09-01 15:35:51 +02:00
|
|
|
case IOCTL_CONDRV_CTRL_EVENT:
|
|
|
|
{
|
|
|
|
const struct condrv_ctrl_event *event = get_req_data();
|
|
|
|
process_id_t group;
|
|
|
|
if (get_req_data_size() != sizeof(*event))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:35:51 +02:00
|
|
|
}
|
|
|
|
group = event->group_id ? event->group_id : current->process->group_id;
|
|
|
|
if (!group)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:35:51 +02:00
|
|
|
}
|
|
|
|
propagate_console_signal( console, event->event, group );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:35:51 +02:00
|
|
|
}
|
|
|
|
|
2020-07-06 19:26:56 +02:00
|
|
|
default:
|
2020-09-14 18:46:48 +02:00
|
|
|
if (!console->server || code >> 16 != FILE_DEVICE_CONSOLE)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-14 18:46:48 +02:00
|
|
|
}
|
2021-09-03 02:08:54 +02:00
|
|
|
queue_host_ioctl( console->server, code, 0, async, &console->ioctl_q );
|
2020-07-06 19:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:51 +02:00
|
|
|
static void console_read( struct fd *fd, struct async *async, file_pos_t pos )
|
2020-11-19 17:59:30 +01:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = get_fd_user( fd );
|
2020-11-19 17:59:30 +01:00
|
|
|
|
|
|
|
if (!console->server)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:51 +02:00
|
|
|
return;
|
2020-11-19 17:59:30 +01:00
|
|
|
}
|
2021-09-03 02:08:51 +02:00
|
|
|
queue_host_ioctl( console->server, IOCTL_CONDRV_READ_FILE, 0, async, &console->ioctl_q );
|
2020-11-19 17:59:30 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:53 +02:00
|
|
|
static void console_flush( struct fd *fd, struct async *async )
|
2020-10-15 18:19:43 +02:00
|
|
|
{
|
2020-11-27 18:13:30 +01:00
|
|
|
struct console *console = get_fd_user( fd );
|
2020-10-15 18:19:43 +02:00
|
|
|
|
|
|
|
if (!console->server)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:53 +02:00
|
|
|
return;
|
2020-10-15 18:19:43 +02:00
|
|
|
}
|
2021-09-03 02:08:53 +02:00
|
|
|
queue_host_ioctl( console->server, IOCTL_CONDRV_FLUSH, 0, NULL, NULL );
|
2020-10-15 18:19:43 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:52 +02:00
|
|
|
static void screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos )
|
2020-11-17 18:58:16 +01:00
|
|
|
{
|
|
|
|
struct screen_buffer *screen_buffer = get_fd_user( fd );
|
|
|
|
|
|
|
|
if (!screen_buffer->input || !screen_buffer->input->server)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:52 +02:00
|
|
|
return;
|
2020-11-17 18:58:16 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:52 +02:00
|
|
|
queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_WRITE_FILE,
|
|
|
|
screen_buffer->id, async, &screen_buffer->ioctl_q );
|
2020-11-17 18:58:16 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2020-07-09 19:28:07 +02:00
|
|
|
{
|
2020-07-09 19:28:13 +02:00
|
|
|
struct screen_buffer *screen_buffer = get_fd_user( fd );
|
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
2020-07-17 13:55:40 +02:00
|
|
|
case IOCTL_CONDRV_ACTIVATE:
|
|
|
|
if (!screen_buffer->input)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-07-17 13:55:40 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 15:03:43 +02:00
|
|
|
set_active_screen_buffer( screen_buffer->input, screen_buffer );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-07-17 13:55:40 +02:00
|
|
|
|
2020-07-09 19:28:13 +02:00
|
|
|
default:
|
2020-10-14 19:57:51 +02:00
|
|
|
if (!screen_buffer->input || !screen_buffer->input->server || code >> 16 != FILE_DEVICE_CONSOLE ||
|
|
|
|
is_blocking_read_ioctl( code ))
|
2020-09-11 14:31:07 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-11 14:31:07 +02:00
|
|
|
}
|
2021-09-03 02:08:54 +02:00
|
|
|
queue_host_ioctl( screen_buffer->input->server, code, screen_buffer->id,
|
|
|
|
async, &screen_buffer->ioctl_q );
|
2020-07-09 19:28:13 +02:00
|
|
|
}
|
2020-07-09 19:28:07 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2020-09-16 20:39:26 +02:00
|
|
|
{
|
|
|
|
struct console_connection *console_connection = get_fd_user( fd );
|
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case IOCTL_CONDRV_BIND_PID:
|
|
|
|
{
|
|
|
|
struct process *process;
|
|
|
|
unsigned int pid;
|
|
|
|
if (get_req_data_size() != sizeof(unsigned int))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-16 20:39:26 +02:00
|
|
|
}
|
|
|
|
if (current->process->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-16 20:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pid = *(unsigned int *)get_req_data();
|
|
|
|
if (pid == ATTACH_PARENT_PROCESS) pid = current->process->parent_id;
|
2021-09-03 02:08:54 +02:00
|
|
|
if (!(process = get_process_from_id( pid ))) return;
|
2020-09-16 20:39:26 +02:00
|
|
|
|
|
|
|
if (process->console)
|
2020-11-27 18:13:30 +01:00
|
|
|
current->process->console = (struct console *)grab_object( process->console );
|
2020-09-16 20:39:26 +02:00
|
|
|
else set_error( STATUS_ACCESS_DENIED );
|
|
|
|
release_object( process );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-16 20:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2021-09-03 02:08:54 +02:00
|
|
|
default_fd_ioctl( console_connection->fd, code, async );
|
2020-09-16 20:39:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2020-09-01 15:36:23 +02:00
|
|
|
{
|
|
|
|
struct console_server *server = get_fd_user( fd );
|
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case IOCTL_CONDRV_CTRL_EVENT:
|
|
|
|
{
|
|
|
|
const struct condrv_ctrl_event *event = get_req_data();
|
|
|
|
if (get_req_data_size() != sizeof(*event))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:36:23 +02:00
|
|
|
}
|
|
|
|
if (!server->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:36:23 +02:00
|
|
|
}
|
|
|
|
propagate_console_signal( server->console, event->event, event->group_id );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:36:23 +02:00
|
|
|
}
|
|
|
|
|
2020-09-21 17:06:26 +02:00
|
|
|
case IOCTL_CONDRV_SETUP_INPUT:
|
|
|
|
{
|
|
|
|
struct termios term;
|
|
|
|
obj_handle_t handle;
|
|
|
|
struct file *file;
|
|
|
|
int unix_fd;
|
|
|
|
|
|
|
|
if (get_req_data_size() != sizeof(unsigned int) || get_reply_max_size())
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-21 17:06:26 +02:00
|
|
|
}
|
|
|
|
if (server->term_fd != -1)
|
|
|
|
{
|
|
|
|
tcsetattr( server->term_fd, TCSANOW, &server->termios );
|
|
|
|
close( server->term_fd );
|
|
|
|
server->term_fd = -1;
|
|
|
|
}
|
|
|
|
handle = *(unsigned int *)get_req_data();
|
2021-09-03 02:08:54 +02:00
|
|
|
if (!handle) return;
|
2020-09-21 17:06:26 +02:00
|
|
|
if (!(file = get_file_obj( current->process, handle, FILE_READ_DATA )))
|
|
|
|
{
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-21 17:06:26 +02:00
|
|
|
}
|
|
|
|
unix_fd = get_file_unix_fd( file );
|
|
|
|
release_object( file );
|
|
|
|
|
|
|
|
if (tcgetattr( unix_fd, &server->termios ))
|
|
|
|
{
|
|
|
|
file_set_error();
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-21 17:06:26 +02:00
|
|
|
}
|
|
|
|
term = server->termios;
|
|
|
|
term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
|
|
|
|
term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
|
|
|
term.c_cflag &= ~(CSIZE | PARENB);
|
|
|
|
term.c_cflag |= CS8;
|
|
|
|
term.c_cc[VMIN] = 1;
|
|
|
|
term.c_cc[VTIME] = 0;
|
|
|
|
if (tcsetattr( unix_fd, TCSANOW, &term ) || (server->term_fd = dup( unix_fd )) == -1)
|
|
|
|
file_set_error();
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-21 17:06:26 +02:00
|
|
|
}
|
|
|
|
|
2020-09-01 15:36:23 +02:00
|
|
|
default:
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-09-01 15:36:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-16 20:38:37 +02:00
|
|
|
static void console_connection_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
fputs( "console connection\n", stderr );
|
|
|
|
}
|
|
|
|
|
2020-09-16 20:39:26 +02:00
|
|
|
static struct fd *console_connection_get_fd( struct object *obj )
|
|
|
|
{
|
|
|
|
struct console_connection *connection = (struct console_connection *)obj;
|
|
|
|
return (struct fd *)grab_object( connection->fd );
|
|
|
|
}
|
|
|
|
|
2020-11-25 19:42:42 +01:00
|
|
|
static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root )
|
2020-09-16 20:39:35 +02:00
|
|
|
{
|
|
|
|
static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
|
|
|
|
|
|
|
|
if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
|
|
|
|
{
|
|
|
|
if (!current->process->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
name->len = 0;
|
|
|
|
return grab_object( current->process->console );
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-09-16 20:38:37 +02:00
|
|
|
static struct object *console_connection_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
|
|
|
|
{
|
2020-11-30 18:42:02 +01:00
|
|
|
struct console *console = process->console;
|
|
|
|
|
|
|
|
if (console)
|
|
|
|
{
|
|
|
|
process->console = NULL;
|
|
|
|
release_object( console );
|
|
|
|
}
|
2020-09-16 20:38:37 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-09-16 20:39:26 +02:00
|
|
|
static void console_connection_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct console_connection *connection = (struct console_connection *)obj;
|
|
|
|
if (connection->fd) release_object( connection->fd );
|
|
|
|
}
|
|
|
|
|
2020-06-25 22:26:35 +02:00
|
|
|
static void console_device_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
fputs( "Console device\n", stderr );
|
|
|
|
}
|
|
|
|
|
2020-11-25 19:42:42 +01:00
|
|
|
static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
|
|
|
|
unsigned int attr, struct object *root )
|
2020-06-25 22:26:35 +02:00
|
|
|
{
|
2020-09-16 20:39:10 +02:00
|
|
|
static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
|
2020-07-21 14:56:57 +02:00
|
|
|
static const WCHAR consoleW[] = {'C','o','n','s','o','l','e'};
|
|
|
|
static const WCHAR current_inW[] = {'C','u','r','r','e','n','t','I','n'};
|
|
|
|
static const WCHAR current_outW[] = {'C','u','r','r','e','n','t','O','u','t'};
|
2020-11-12 19:56:18 +01:00
|
|
|
static const WCHAR inputW[] = {'I','n','p','u','t'};
|
2020-11-12 19:56:23 +01:00
|
|
|
static const WCHAR outputW[] = {'O','u','t','p','u','t'};
|
2020-07-21 14:56:57 +02:00
|
|
|
static const WCHAR screen_bufferW[] = {'S','c','r','e','e','n','B','u','f','f','e','r'};
|
2020-08-20 23:48:08 +02:00
|
|
|
static const WCHAR serverW[] = {'S','e','r','v','e','r'};
|
2020-06-25 22:26:45 +02:00
|
|
|
|
|
|
|
if (name->len == sizeof(current_inW) && !memcmp( name->str, current_inW, name->len ))
|
|
|
|
{
|
|
|
|
if (!current->process->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
name->len = 0;
|
|
|
|
return grab_object( current->process->console );
|
|
|
|
}
|
2020-06-25 22:26:35 +02:00
|
|
|
|
2020-06-25 22:26:54 +02:00
|
|
|
if (name->len == sizeof(current_outW) && !memcmp( name->str, current_outW, name->len ))
|
|
|
|
{
|
|
|
|
if (!current->process->console || !current->process->console->active)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
name->len = 0;
|
|
|
|
return grab_object( current->process->console->active );
|
|
|
|
}
|
|
|
|
|
2020-06-25 22:26:35 +02:00
|
|
|
if (name->len == sizeof(consoleW) && !memcmp( name->str, consoleW, name->len ))
|
|
|
|
{
|
|
|
|
name->len = 0;
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
2020-11-12 19:56:18 +01:00
|
|
|
if (name->len == sizeof(inputW) && !memcmp( name->str, inputW, name->len ))
|
|
|
|
{
|
2020-11-27 18:13:59 +01:00
|
|
|
struct console_input *console_input;
|
2020-11-12 19:56:18 +01:00
|
|
|
name->len = 0;
|
2020-11-27 18:13:59 +01:00
|
|
|
if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
|
|
|
|
console_input->fd = alloc_pseudo_fd( &console_input_fd_ops, &console_input->obj,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
if (!console_input->fd)
|
|
|
|
{
|
|
|
|
release_object( console_input );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &console_input->obj;
|
2020-11-12 19:56:18 +01:00
|
|
|
}
|
|
|
|
|
2020-11-12 19:56:23 +01:00
|
|
|
if (name->len == sizeof(outputW) && !memcmp( name->str, outputW, name->len ))
|
|
|
|
{
|
2020-11-27 18:14:12 +01:00
|
|
|
struct console_output *console_output;
|
2020-11-12 19:56:23 +01:00
|
|
|
name->len = 0;
|
2020-11-27 18:14:12 +01:00
|
|
|
if (!(console_output = alloc_object( &console_output_ops ))) return NULL;
|
|
|
|
console_output->fd = alloc_pseudo_fd( &console_output_fd_ops, &console_output->obj,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT );
|
|
|
|
if (!console_output->fd)
|
|
|
|
{
|
|
|
|
release_object( console_output );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &console_output->obj;
|
2020-11-12 19:56:23 +01:00
|
|
|
}
|
|
|
|
|
2020-07-21 14:56:57 +02:00
|
|
|
if (name->len == sizeof(screen_bufferW) && !memcmp( name->str, screen_bufferW, name->len ))
|
|
|
|
{
|
|
|
|
if (!current->process->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
name->len = 0;
|
2020-11-27 18:13:37 +01:00
|
|
|
return create_screen_buffer( current->process->console );
|
2020-07-21 14:56:57 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 23:48:08 +02:00
|
|
|
if (name->len == sizeof(serverW) && !memcmp( name->str, serverW, name->len ))
|
|
|
|
{
|
|
|
|
name->len = 0;
|
|
|
|
return create_console_server();
|
|
|
|
}
|
|
|
|
|
2020-09-16 20:39:10 +02:00
|
|
|
if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
|
|
|
|
{
|
|
|
|
name->len = 0;
|
|
|
|
return create_console_connection( NULL );
|
|
|
|
}
|
|
|
|
|
2020-06-25 22:26:35 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct object *console_device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
|
|
|
{
|
|
|
|
int is_output;
|
2021-02-05 12:10:44 +01:00
|
|
|
access = default_map_access( obj, access );
|
2020-06-25 22:26:35 +02:00
|
|
|
is_output = access & FILE_WRITE_DATA;
|
|
|
|
if (!current->process->console || (is_output && !current->process->console))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (is_output && (access & FILE_READ_DATA))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return is_output ? grab_object( current->process->console->active ) : grab_object( current->process->console );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static void console_input_dump( struct object *obj, int verbose )
|
2020-11-12 19:56:18 +01:00
|
|
|
{
|
|
|
|
fputs( "console Input device\n", stderr );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry )
|
2020-11-12 19:56:18 +01:00
|
|
|
{
|
|
|
|
if (!current->process->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return 0;
|
|
|
|
}
|
2021-12-17 17:18:51 +01:00
|
|
|
return console_add_queue( ¤t->process->console->obj, entry );
|
2020-11-12 19:56:18 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static struct fd *console_input_get_fd( struct object *obj )
|
2020-11-12 19:56:18 +01:00
|
|
|
{
|
2020-11-27 18:13:59 +01:00
|
|
|
struct console_input *console_input = (struct console_input *)obj;
|
|
|
|
assert( obj->ops == &console_input_ops );
|
|
|
|
return (struct fd *)grab_object( console_input->fd );
|
2020-11-12 19:56:18 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static struct object *console_input_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
2020-11-12 19:56:18 +01:00
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:59 +01:00
|
|
|
static void console_input_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct console_input *console_input = (struct console_input *)obj;
|
|
|
|
|
|
|
|
assert( obj->ops == &console_input_ops );
|
|
|
|
if (console_input->fd) release_object( console_input->fd );
|
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2020-11-27 18:13:59 +01:00
|
|
|
{
|
|
|
|
struct console *console = current->process->console;
|
|
|
|
|
|
|
|
if (!console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-11-27 18:13:59 +01:00
|
|
|
}
|
2021-09-03 02:08:54 +02:00
|
|
|
console_ioctl( console->fd, code, async );
|
2020-11-27 18:13:59 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:51 +02:00
|
|
|
static void console_input_read( struct fd *fd, struct async *async, file_pos_t pos )
|
2020-11-27 18:13:59 +01:00
|
|
|
{
|
|
|
|
struct console *console = current->process->console;
|
|
|
|
|
|
|
|
if (!console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:51 +02:00
|
|
|
return;
|
2020-11-27 18:13:59 +01:00
|
|
|
}
|
2021-09-03 02:08:51 +02:00
|
|
|
console_read( console->fd, async, pos );
|
2020-11-27 18:13:59 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:53 +02:00
|
|
|
static void console_input_flush( struct fd *fd, struct async *async )
|
2020-11-27 18:13:59 +01:00
|
|
|
{
|
|
|
|
struct console *console = current->process->console;
|
|
|
|
|
|
|
|
if (!console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:53 +02:00
|
|
|
return;
|
2020-11-27 18:13:59 +01:00
|
|
|
}
|
2021-09-03 02:08:53 +02:00
|
|
|
console_flush( console->fd, async );
|
2020-11-27 18:13:59 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static void console_output_dump( struct object *obj, int verbose )
|
2020-11-12 19:56:23 +01:00
|
|
|
{
|
|
|
|
fputs( "console Output device\n", stderr );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry )
|
2020-11-12 19:56:23 +01:00
|
|
|
{
|
|
|
|
if (!current->process->console || !current->process->console->active)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return add_queue( ¤t->process->console->obj, entry );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static struct fd *console_output_get_fd( struct object *obj )
|
2020-11-12 19:56:23 +01:00
|
|
|
{
|
2020-11-27 18:14:12 +01:00
|
|
|
struct console_output *console_output = (struct console_output *)obj;
|
|
|
|
assert( obj->ops == &console_output_ops );
|
|
|
|
return (struct fd *)grab_object( console_output->fd );
|
2020-11-12 19:56:23 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:13:51 +01:00
|
|
|
static struct object *console_output_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
2020-11-12 19:56:23 +01:00
|
|
|
{
|
|
|
|
return grab_object( obj );
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:14:12 +01:00
|
|
|
static void console_output_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct console_output *console_output = (struct console_output *)obj;
|
|
|
|
|
|
|
|
assert( obj->ops == &console_output_ops );
|
|
|
|
if (console_output->fd) release_object( console_output->fd );
|
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:54 +02:00
|
|
|
static void console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2020-11-27 18:14:12 +01:00
|
|
|
{
|
|
|
|
struct console *console = current->process->console;
|
|
|
|
|
|
|
|
if (!console || !console->active)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:54 +02:00
|
|
|
return;
|
2020-11-27 18:14:12 +01:00
|
|
|
}
|
2021-09-03 02:08:54 +02:00
|
|
|
screen_buffer_ioctl( console->active->fd, code, async );
|
2020-11-27 18:14:12 +01:00
|
|
|
}
|
|
|
|
|
2021-09-03 02:08:52 +02:00
|
|
|
static void console_output_write( struct fd *fd, struct async *async, file_pos_t pos )
|
2020-11-27 18:14:12 +01:00
|
|
|
{
|
|
|
|
struct console *console = current->process->console;
|
|
|
|
|
|
|
|
if (!console || !console->active)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
2021-09-03 02:08:52 +02:00
|
|
|
return;
|
2020-11-27 18:14:12 +01:00
|
|
|
}
|
2021-09-03 02:08:52 +02:00
|
|
|
screen_buffer_write( console->active->fd, async, pos );
|
2020-11-27 18:14:12 +01:00
|
|
|
}
|
|
|
|
|
2020-09-23 11:32:47 +02:00
|
|
|
struct object *create_console_device( struct object *root, const struct unicode_str *name,
|
|
|
|
unsigned int attr, const struct security_descriptor *sd )
|
2020-06-25 22:26:35 +02:00
|
|
|
{
|
2020-09-23 11:32:47 +02:00
|
|
|
return create_named_object( root, &console_device_ops, name, attr, sd );
|
2020-06-25 22:26:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 23:50:47 +02:00
|
|
|
/* retrieve the next pending console ioctl request */
|
|
|
|
DECL_HANDLER(get_next_console_request)
|
|
|
|
{
|
2020-08-25 14:52:48 +02:00
|
|
|
struct console_host_ioctl *ioctl = NULL, *next;
|
2020-08-20 23:50:47 +02:00
|
|
|
struct console_server *server;
|
|
|
|
struct iosb *iosb = NULL;
|
|
|
|
|
|
|
|
server = (struct console_server *)get_handle_obj( current->process, req->handle, 0, &console_server_ops );
|
|
|
|
if (!server) return;
|
|
|
|
|
|
|
|
if (!server->console)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
release_object( server );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-30 18:42:09 +01:00
|
|
|
if (!server->console->renderer) server->console->renderer = current;
|
|
|
|
|
2020-11-10 16:31:43 +01:00
|
|
|
if (!req->signal) server->console->signaled = 0;
|
|
|
|
else if (!server->console->signaled)
|
|
|
|
{
|
|
|
|
server->console->signaled = 1;
|
|
|
|
wake_up( &server->console->obj, 0 );
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:52:48 +02:00
|
|
|
if (req->read)
|
2020-08-20 23:50:47 +02:00
|
|
|
{
|
2020-08-25 14:52:48 +02:00
|
|
|
/* set result of current pending ioctl */
|
|
|
|
if (list_empty( &server->read_queue ))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_HANDLE );
|
|
|
|
release_object( server );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioctl = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
|
|
|
|
list_remove( &ioctl->entry );
|
|
|
|
list_move_tail( &server->queue, &server->read_queue );
|
|
|
|
}
|
|
|
|
else if (server->busy)
|
|
|
|
{
|
|
|
|
/* set result of previous ioctl */
|
2020-08-20 23:50:47 +02:00
|
|
|
ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
|
|
|
|
list_remove( &ioctl->entry );
|
2020-08-25 14:52:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl)
|
|
|
|
{
|
2021-09-02 00:28:38 +02:00
|
|
|
struct async *async = ioctl->async;
|
2020-08-25 14:52:48 +02:00
|
|
|
unsigned int status = req->status;
|
2021-09-02 00:28:38 +02:00
|
|
|
|
2020-10-01 15:10:09 +02:00
|
|
|
if (status == STATUS_PENDING) status = STATUS_INVALID_PARAMETER;
|
2021-09-02 00:28:38 +02:00
|
|
|
if (async)
|
2020-08-20 23:50:47 +02:00
|
|
|
{
|
2021-09-02 00:28:38 +02:00
|
|
|
iosb = async_get_iosb( async );
|
2020-11-17 18:58:16 +01:00
|
|
|
if (iosb->status == STATUS_PENDING)
|
2020-08-20 23:50:47 +02:00
|
|
|
{
|
2021-09-02 00:28:38 +02:00
|
|
|
data_size_t out_size = min( iosb->out_size, get_req_data_size() );
|
|
|
|
data_size_t result = ioctl->code == IOCTL_CONDRV_WRITE_FILE ? iosb->in_size : out_size;
|
2021-09-02 00:28:39 +02:00
|
|
|
async_request_complete_alloc( async, status, result, out_size, get_req_data() );
|
2020-11-17 18:58:16 +01:00
|
|
|
}
|
2021-09-02 00:28:38 +02:00
|
|
|
|
|
|
|
release_object( async );
|
2020-08-20 23:50:47 +02:00
|
|
|
}
|
2021-09-02 00:28:38 +02:00
|
|
|
free( ioctl );
|
2020-08-20 23:50:47 +02:00
|
|
|
if (iosb) release_object( iosb );
|
2020-08-25 14:52:48 +02:00
|
|
|
|
|
|
|
if (req->read)
|
|
|
|
{
|
|
|
|
release_object( server );
|
|
|
|
return;
|
|
|
|
}
|
2020-08-20 23:50:47 +02:00
|
|
|
server->busy = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:52:48 +02:00
|
|
|
/* if we have a blocking read ioctl in queue head and previous blocking read is still waiting,
|
|
|
|
* move it to read queue for execution after current read is complete. move all blocking
|
|
|
|
* ioctl at the same time to preserve their order. */
|
|
|
|
if (!list_empty( &server->queue ) && !list_empty( &server->read_queue ))
|
|
|
|
{
|
|
|
|
ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
|
|
|
|
if (is_blocking_read_ioctl( ioctl->code ))
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( ioctl, next, &server->queue, struct console_host_ioctl, entry )
|
|
|
|
{
|
|
|
|
if (!is_blocking_read_ioctl( ioctl->code )) continue;
|
|
|
|
list_remove( &ioctl->entry );
|
|
|
|
list_add_tail( &server->read_queue, &ioctl->entry );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 23:50:47 +02:00
|
|
|
/* return the next ioctl */
|
|
|
|
if (!list_empty( &server->queue ))
|
|
|
|
{
|
|
|
|
ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
|
|
|
|
iosb = ioctl->async ? async_get_iosb( ioctl->async ) : NULL;
|
|
|
|
|
|
|
|
if (!iosb || get_reply_max_size() >= iosb->in_size)
|
|
|
|
{
|
2020-08-27 15:04:27 +02:00
|
|
|
reply->code = ioctl->code;
|
|
|
|
reply->output = ioctl->output;
|
2020-08-20 23:50:47 +02:00
|
|
|
|
|
|
|
if (iosb)
|
|
|
|
{
|
|
|
|
reply->out_size = iosb->out_size;
|
|
|
|
set_reply_data_ptr( iosb->in_data, iosb->in_size );
|
|
|
|
iosb->in_data = NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:52:48 +02:00
|
|
|
if (is_blocking_read_ioctl( ioctl->code ))
|
|
|
|
{
|
|
|
|
list_remove( &ioctl->entry );
|
|
|
|
assert( list_empty( &server->read_queue ));
|
|
|
|
list_add_tail( &server->read_queue, &ioctl->entry );
|
|
|
|
}
|
|
|
|
else server->busy = 1;
|
2020-08-20 23:50:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reply->out_size = iosb->in_size;
|
|
|
|
set_error( STATUS_BUFFER_OVERFLOW );
|
|
|
|
}
|
|
|
|
if (iosb) release_object( iosb );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_error( STATUS_PENDING );
|
|
|
|
}
|
|
|
|
|
|
|
|
release_object( server );
|
|
|
|
}
|