cmd: Inline some simple extern WCHAR strings.
[wine.git] / server / console.c
blob295db7767b2d246e87173aff409f97617cefb5f0
1 /*
2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
5 * 2001 Eric Pouech
6 * Copyright 2020 Jacek Caban for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <assert.h>
28 #include <string.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <signal.h>
32 #include <sys/ioctl.h>
33 #include <termios.h>
35 #include "ntstatus.h"
36 #define WIN32_NO_STATUS
37 #include "handle.h"
38 #include "process.h"
39 #include "request.h"
40 #include "file.h"
41 #include "unicode.h"
42 #include "wincon.h"
43 #include "winternl.h"
44 #include "wine/condrv.h"
46 struct screen_buffer;
48 struct history_line
50 data_size_t len;
51 WCHAR text[1];
54 struct console
56 struct object obj; /* object header */
57 int signaled; /* is console signaled */
58 int num_proc; /* number of processes attached to this console */
59 struct thread *renderer; /* console renderer thread */
60 struct screen_buffer *active; /* active screen buffer */
61 struct console_server *server; /* console server object */
62 unsigned int last_id; /* id of last created console buffer */
63 struct fd *fd; /* for bare console, attached input fd */
64 struct async_queue ioctl_q; /* ioctl queue */
65 struct async_queue read_q; /* read queue */
68 static void console_dump( struct object *obj, int verbose );
69 static void console_destroy( struct object *obj );
70 static int console_signaled( struct object *obj, struct wait_queue_entry *entry );
71 static struct fd *console_get_fd( struct object *obj );
72 static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
73 unsigned int attr, struct object *root );
74 static struct object *console_open_file( struct object *obj, unsigned int access,
75 unsigned int sharing, unsigned int options );
77 static const struct object_ops console_ops =
79 sizeof(struct console), /* size */
80 console_dump, /* dump */
81 no_get_type, /* get_type */
82 add_queue, /* add_queue */
83 remove_queue, /* remove_queue */
84 console_signaled, /* signaled */
85 no_satisfied, /* satisfied */
86 no_signal, /* signal */
87 console_get_fd, /* get_fd */
88 default_fd_map_access, /* map_access */
89 default_get_sd, /* get_sd */
90 default_set_sd, /* set_sd */
91 no_get_full_name, /* get_full_name */
92 console_lookup_name, /* lookup_name */
93 no_link_name, /* link_name */
94 NULL, /* unlink_name */
95 console_open_file, /* open_file */
96 no_kernel_obj_list, /* get_kernel_obj_list */
97 no_close_handle, /* close_handle */
98 console_destroy /* destroy */
101 static enum server_fd_type console_get_fd_type( struct fd *fd );
102 static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class );
103 static void console_get_volume_info( struct fd *fd, unsigned int info_class );
104 static int console_read( struct fd *fd, struct async *async, file_pos_t pos );
105 static int console_flush( struct fd *fd, struct async *async );
106 static int console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
108 static const struct fd_ops console_fd_ops =
110 default_fd_get_poll_events, /* get_poll_events */
111 default_poll_event, /* poll_event */
112 console_get_fd_type, /* get_fd_type */
113 console_read, /* read */
114 no_fd_write, /* write */
115 console_flush, /* flush */
116 console_get_file_info, /* get_file_info */
117 console_get_volume_info, /* get_volume_info */
118 console_ioctl, /* ioctl */
119 default_fd_queue_async, /* queue_async */
120 default_fd_reselect_async /* reselect_async */
123 struct console_host_ioctl
125 unsigned int code; /* ioctl code */
126 int output; /* output id for screen buffer ioctls */
127 struct async *async; /* ioctl async */
128 struct list entry; /* list entry */
131 struct console_server
133 struct object obj; /* object header */
134 struct fd *fd; /* pseudo-fd for ioctls */
135 struct console *console; /* attached console */
136 struct list queue; /* ioctl queue */
137 struct list read_queue; /* blocking read queue */
138 int busy; /* flag if server processing an ioctl */
139 int term_fd; /* UNIX terminal fd */
140 struct termios termios; /* original termios */
143 static void console_server_dump( struct object *obj, int verbose );
144 static void console_server_destroy( struct object *obj );
145 static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry );
146 static struct fd *console_server_get_fd( struct object *obj );
147 static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
148 unsigned int attr, struct object *root );
149 static struct object *console_server_open_file( struct object *obj, unsigned int access,
150 unsigned int sharing, unsigned int options );
152 static const struct object_ops console_server_ops =
154 sizeof(struct console_server), /* size */
155 console_server_dump, /* dump */
156 no_get_type, /* get_type */
157 add_queue, /* add_queue */
158 remove_queue, /* remove_queue */
159 console_server_signaled, /* signaled */
160 no_satisfied, /* satisfied */
161 no_signal, /* signal */
162 console_server_get_fd, /* get_fd */
163 default_fd_map_access, /* map_access */
164 default_get_sd, /* get_sd */
165 default_set_sd, /* set_sd */
166 no_get_full_name, /* get_full_name */
167 console_server_lookup_name, /* lookup_name */
168 no_link_name, /* link_name */
169 NULL, /* unlink_name */
170 console_server_open_file, /* open_file */
171 no_kernel_obj_list, /* get_kernel_obj_list */
172 fd_close_handle, /* close_handle */
173 console_server_destroy /* destroy */
176 static int console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
178 static const struct fd_ops console_server_fd_ops =
180 default_fd_get_poll_events, /* get_poll_events */
181 default_poll_event, /* poll_event */
182 console_get_fd_type, /* get_fd_type */
183 no_fd_read, /* read */
184 no_fd_write, /* write */
185 no_fd_flush, /* flush */
186 no_fd_get_file_info, /* get_file_info */
187 no_fd_get_volume_info, /* get_volume_info */
188 console_server_ioctl, /* ioctl */
189 default_fd_queue_async, /* queue_async */
190 default_fd_reselect_async /* reselect_async */
193 struct font_info
195 short int width;
196 short int height;
197 short int weight;
198 short int pitch_family;
199 WCHAR *face_name;
200 data_size_t face_len;
203 struct screen_buffer
205 struct object obj; /* object header */
206 struct list entry; /* entry in list of all screen buffers */
207 struct console *input; /* associated console input */
208 unsigned int id; /* buffer id */
209 struct fd *fd; /* for bare console, attached output fd */
210 struct async_queue ioctl_q; /* ioctl queue */
213 static void screen_buffer_dump( struct object *obj, int verbose );
214 static void screen_buffer_destroy( struct object *obj );
215 static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry );
216 static struct fd *screen_buffer_get_fd( struct object *obj );
217 static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
218 unsigned int sharing, unsigned int options );
220 static const struct object_ops screen_buffer_ops =
222 sizeof(struct screen_buffer), /* size */
223 screen_buffer_dump, /* dump */
224 no_get_type, /* get_type */
225 screen_buffer_add_queue, /* add_queue */
226 NULL, /* remove_queue */
227 NULL, /* signaled */
228 NULL, /* satisfied */
229 no_signal, /* signal */
230 screen_buffer_get_fd, /* get_fd */
231 default_fd_map_access, /* map_access */
232 default_get_sd, /* get_sd */
233 default_set_sd, /* set_sd */
234 no_get_full_name, /* get_full_name */
235 no_lookup_name, /* lookup_name */
236 no_link_name, /* link_name */
237 NULL, /* unlink_name */
238 screen_buffer_open_file, /* open_file */
239 no_kernel_obj_list, /* get_kernel_obj_list */
240 no_close_handle, /* close_handle */
241 screen_buffer_destroy /* destroy */
244 static int screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos );
245 static int screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
247 static const struct fd_ops screen_buffer_fd_ops =
249 default_fd_get_poll_events, /* get_poll_events */
250 default_poll_event, /* poll_event */
251 console_get_fd_type, /* get_fd_type */
252 no_fd_read, /* read */
253 screen_buffer_write, /* write */
254 no_fd_flush, /* flush */
255 console_get_file_info, /* get_file_info */
256 console_get_volume_info, /* get_volume_info */
257 screen_buffer_ioctl, /* ioctl */
258 default_fd_queue_async, /* queue_async */
259 default_fd_reselect_async /* reselect_async */
262 static struct object_type *console_device_get_type( struct object *obj );
263 static void console_device_dump( struct object *obj, int verbose );
264 static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
265 unsigned int attr, struct object *root );
266 static struct object *console_device_open_file( struct object *obj, unsigned int access,
267 unsigned int sharing, unsigned int options );
269 static const struct object_ops console_device_ops =
271 sizeof(struct object), /* size */
272 console_device_dump, /* dump */
273 console_device_get_type, /* get_type */
274 no_add_queue, /* add_queue */
275 NULL, /* remove_queue */
276 NULL, /* signaled */
277 no_satisfied, /* satisfied */
278 no_signal, /* signal */
279 no_get_fd, /* get_fd */
280 default_fd_map_access, /* map_access */
281 default_get_sd, /* get_sd */
282 default_set_sd, /* set_sd */
283 default_get_full_name, /* get_full_name */
284 console_device_lookup_name, /* lookup_name */
285 directory_link_name, /* link_name */
286 default_unlink_name, /* unlink_name */
287 console_device_open_file, /* open_file */
288 no_kernel_obj_list, /* get_kernel_obj_list */
289 no_close_handle, /* close_handle */
290 no_destroy /* destroy */
293 struct console_input
295 struct object obj; /* object header */
296 struct fd *fd; /* pseudo-fd */
299 static void console_input_dump( struct object *obj, int verbose );
300 static struct object *console_input_open_file( struct object *obj, unsigned int access,
301 unsigned int sharing, unsigned int options );
302 static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry );
303 static struct fd *console_input_get_fd( struct object *obj );
304 static void console_input_destroy( struct object *obj );
306 static const struct object_ops console_input_ops =
308 sizeof(struct console_input), /* size */
309 console_input_dump, /* dump */
310 console_device_get_type, /* get_type */
311 console_input_add_queue, /* add_queue */
312 NULL, /* remove_queue */
313 NULL, /* signaled */
314 no_satisfied, /* satisfied */
315 no_signal, /* signal */
316 console_input_get_fd, /* get_fd */
317 no_map_access, /* map_access */
318 default_get_sd, /* get_sd */
319 default_set_sd, /* set_sd */
320 no_get_full_name, /* get_full_name */
321 no_lookup_name, /* lookup_name */
322 directory_link_name, /* link_name */
323 default_unlink_name, /* unlink_name */
324 console_input_open_file, /* open_file */
325 no_kernel_obj_list, /* get_kernel_obj_list */
326 no_close_handle, /* close_handle */
327 console_input_destroy /* destroy */
330 static int console_input_read( struct fd *fd, struct async *async, file_pos_t pos );
331 static int console_input_flush( struct fd *fd, struct async *async );
332 static int console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
334 static const struct fd_ops console_input_fd_ops =
336 default_fd_get_poll_events, /* get_poll_events */
337 default_poll_event, /* poll_event */
338 console_get_fd_type, /* get_fd_type */
339 console_input_read, /* read */
340 no_fd_write, /* write */
341 console_input_flush, /* flush */
342 console_get_file_info, /* get_file_info */
343 console_get_volume_info, /* get_volume_info */
344 console_input_ioctl, /* ioctl */
345 default_fd_queue_async, /* queue_async */
346 default_fd_reselect_async /* reselect_async */
349 struct console_output
351 struct object obj; /* object header */
352 struct fd *fd; /* pseudo-fd */
355 static void console_output_dump( struct object *obj, int verbose );
356 static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry );
357 static struct fd *console_output_get_fd( struct object *obj );
358 static struct object *console_output_open_file( struct object *obj, unsigned int access,
359 unsigned int sharing, unsigned int options );
360 static void console_output_destroy( struct object *obj );
362 static const struct object_ops console_output_ops =
364 sizeof(struct console_output), /* size */
365 console_output_dump, /* dump */
366 console_device_get_type, /* get_type */
367 console_output_add_queue, /* add_queue */
368 NULL, /* remove_queue */
369 NULL, /* signaled */
370 no_satisfied, /* satisfied */
371 no_signal, /* signal */
372 console_output_get_fd, /* get_fd */
373 no_map_access, /* map_access */
374 default_get_sd, /* get_sd */
375 default_set_sd, /* set_sd */
376 no_get_full_name, /* get_full_name */
377 no_lookup_name, /* lookup_name */
378 directory_link_name, /* link_name */
379 default_unlink_name, /* unlink_name */
380 console_output_open_file, /* open_file */
381 no_kernel_obj_list, /* get_kernel_obj_list */
382 no_close_handle, /* close_handle */
383 console_output_destroy /* destroy */
386 static int console_output_write( struct fd *fd, struct async *async, file_pos_t pos );
387 static int console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
389 static const struct fd_ops console_output_fd_ops =
391 default_fd_get_poll_events, /* get_poll_events */
392 default_poll_event, /* poll_event */
393 console_get_fd_type, /* get_fd_type */
394 no_fd_read, /* read */
395 console_output_write, /* write */
396 no_fd_flush, /* flush */
397 console_get_file_info, /* get_file_info */
398 console_get_volume_info, /* get_volume_info */
399 console_output_ioctl, /* ioctl */
400 default_fd_queue_async, /* queue_async */
401 default_fd_reselect_async /* reselect_async */
404 struct console_connection
406 struct object obj; /* object header */
407 struct fd *fd; /* pseudo-fd for ioctls */
410 static void console_connection_dump( struct object *obj, int verbose );
411 static struct fd *console_connection_get_fd( struct object *obj );
412 static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
413 unsigned int attr, struct object *root );
414 static struct object *console_connection_open_file( struct object *obj, unsigned int access,
415 unsigned int sharing, unsigned int options );
416 static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
417 static void console_connection_destroy( struct object *obj );
419 static const struct object_ops console_connection_ops =
421 sizeof(struct console_connection),/* size */
422 console_connection_dump, /* dump */
423 console_device_get_type, /* get_type */
424 no_add_queue, /* add_queue */
425 NULL, /* remove_queue */
426 NULL, /* signaled */
427 no_satisfied, /* satisfied */
428 no_signal, /* signal */
429 console_connection_get_fd, /* get_fd */
430 no_map_access, /* map_access */
431 default_get_sd, /* get_sd */
432 default_set_sd, /* set_sd */
433 no_get_full_name, /* get_full_name */
434 console_connection_lookup_name, /* lookup_name */
435 directory_link_name, /* link_name */
436 default_unlink_name, /* unlink_name */
437 console_connection_open_file, /* open_file */
438 no_kernel_obj_list, /* get_kernel_obj_list */
439 console_connection_close_handle, /* close_handle */
440 console_connection_destroy /* destroy */
443 static int console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
445 static const struct fd_ops console_connection_fd_ops =
447 default_fd_get_poll_events, /* get_poll_events */
448 default_poll_event, /* poll_event */
449 console_get_fd_type, /* get_fd_type */
450 no_fd_read, /* read */
451 no_fd_write, /* write */
452 no_fd_flush, /* flush */
453 no_fd_get_file_info, /* get_file_info */
454 no_fd_get_volume_info, /* get_volume_info */
455 console_connection_ioctl, /* ioctl */
456 default_fd_queue_async, /* queue_async */
457 default_fd_reselect_async /* reselect_async */
460 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
462 static int console_signaled( struct object *obj, struct wait_queue_entry *entry )
464 struct console *console = (struct console*)obj;
465 return console->signaled;
468 static struct fd *console_get_fd( struct object *obj )
470 struct console *console = (struct console *)obj;
471 assert( obj->ops == &console_ops );
472 return (struct fd *)grab_object( console->fd );
475 static enum server_fd_type console_get_fd_type( struct fd *fd )
477 return FD_TYPE_CHAR;
480 static void console_get_file_info( struct fd *fd, obj_handle_t handle, unsigned int info_class )
482 set_error( STATUS_INVALID_DEVICE_REQUEST );
485 static void console_get_volume_info( struct fd *fd, unsigned int info_class )
487 switch (info_class)
489 case FileFsDeviceInformation:
491 static const FILE_FS_DEVICE_INFORMATION device_info =
493 FILE_DEVICE_CONSOLE,
494 FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
496 if (get_reply_max_size() >= sizeof(device_info))
497 set_reply_data( &device_info, sizeof(device_info) );
498 else
499 set_error( STATUS_BUFFER_TOO_SMALL );
500 break;
502 default:
503 set_error( STATUS_NOT_IMPLEMENTED );
507 static struct object *create_console(void)
509 struct console *console;
511 if (!(console = alloc_object( &console_ops )))
512 return NULL;
514 console->renderer = NULL;
515 console->signaled = 0;
516 console->num_proc = 0;
517 console->active = NULL;
518 console->server = NULL;
519 console->fd = NULL;
520 console->last_id = 0;
521 init_async_queue( &console->ioctl_q );
522 init_async_queue( &console->read_q );
524 console->fd = alloc_pseudo_fd( &console_fd_ops, &console->obj, FILE_SYNCHRONOUS_IO_NONALERT );
525 if (!console->fd)
527 release_object( console );
528 return NULL;
530 allow_fd_caching( console->fd );
531 return &console->obj;
534 static void console_host_ioctl_terminate( struct console_host_ioctl *call, unsigned int status )
536 if (call->async)
538 async_terminate( call->async, status );
539 release_object( call->async );
541 free( call );
544 static int queue_host_ioctl( struct console_server *server, unsigned int code, unsigned int output,
545 struct async *async, struct async_queue *queue )
547 struct console_host_ioctl *ioctl;
549 if (!(ioctl = mem_alloc( sizeof(*ioctl) ))) return 0;
550 ioctl->code = code;
551 ioctl->output = output;
552 ioctl->async = NULL;
553 if (async)
555 ioctl->async = (struct async *)grab_object( async );
556 queue_async( queue, async );
558 list_add_tail( &server->queue, &ioctl->entry );
559 wake_up( &server->obj, 0 );
560 if (async) set_error( STATUS_PENDING );
561 return 1;
564 static void disconnect_console_server( struct console_server *server )
566 while (!list_empty( &server->queue ))
568 struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
569 list_remove( &call->entry );
570 console_host_ioctl_terminate( call, STATUS_CANCELLED );
572 while (!list_empty( &server->read_queue ))
574 struct console_host_ioctl *call = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
575 list_remove( &call->entry );
576 console_host_ioctl_terminate( call, STATUS_CANCELLED );
579 if (server->term_fd != -1)
581 tcsetattr( server->term_fd, TCSANOW, &server->termios );
582 close( server->term_fd );
583 server->term_fd = -1;
586 if (server->console)
588 assert( server->console->server == server );
589 server->console->server = NULL;
590 server->console = NULL;
591 wake_up( &server->obj, 0 );
595 static void set_active_screen_buffer( struct console *console, struct screen_buffer *screen_buffer )
597 if (console->active == screen_buffer) return;
598 if (console->active) release_object( console->active );
599 console->active = (struct screen_buffer *)grab_object( screen_buffer );
601 if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_ACTIVATE,
602 screen_buffer->id, NULL, NULL );
605 static struct object *create_screen_buffer( struct console *console )
607 struct screen_buffer *screen_buffer;
609 if (console->last_id == ~0)
611 set_error( STATUS_NO_MEMORY );
612 return NULL;
615 if (!(screen_buffer = alloc_object( &screen_buffer_ops )))
616 return NULL;
618 screen_buffer->id = ++console->last_id;
619 screen_buffer->input = console;
620 init_async_queue( &screen_buffer->ioctl_q );
621 list_add_head( &screen_buffer_list, &screen_buffer->entry );
623 screen_buffer->fd = alloc_pseudo_fd( &screen_buffer_fd_ops, &screen_buffer->obj,
624 FILE_SYNCHRONOUS_IO_NONALERT );
625 if (!screen_buffer->fd)
627 release_object( screen_buffer );
628 return NULL;
630 allow_fd_caching(screen_buffer->fd);
632 if (console->server) queue_host_ioctl( console->server, IOCTL_CONDRV_INIT_OUTPUT,
633 screen_buffer->id, NULL, NULL );
634 if (!console->active) set_active_screen_buffer( console, screen_buffer );
635 return &screen_buffer->obj;
638 /* free the console for this process */
639 int free_console( struct process *process )
641 struct console *console = process->console;
643 if (!console) return 0;
645 process->console = NULL;
646 console->num_proc--;
647 release_object( console );
649 return 1;
652 struct thread *console_get_renderer( struct console *console )
654 return console->renderer;
657 struct console_signal_info
659 struct console *console;
660 process_id_t group;
661 int signal;
664 static int propagate_console_signal_cb(struct process *process, void *user)
666 struct console_signal_info* csi = (struct console_signal_info*)user;
668 if (process->console == csi->console && process->running_threads &&
669 (!csi->group || process->group_id == csi->group))
671 /* find a suitable thread to signal */
672 struct thread *thread;
673 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
675 if (send_thread_signal( thread, csi->signal )) break;
678 return FALSE;
681 static void propagate_console_signal( struct console *console,
682 int sig, process_id_t group_id )
684 struct console_signal_info csi;
686 if (!console)
688 set_error( STATUS_INVALID_PARAMETER );
689 return;
691 /* FIXME: should support the other events (like CTRL_BREAK) */
692 if (sig != CTRL_C_EVENT)
694 set_error( STATUS_NOT_IMPLEMENTED );
695 return;
697 csi.console = console;
698 csi.signal = SIGINT;
699 csi.group = group_id;
701 enum_processes(propagate_console_signal_cb, &csi);
704 /* dumb dump */
705 static void console_dump( struct object *obj, int verbose )
707 struct console *console = (struct console *)obj;
708 assert( obj->ops == &console_ops );
709 fprintf( stderr, "Console input active=%p server=%p\n",
710 console->active, console->server );
713 static void console_destroy( struct object *obj )
715 struct console *console = (struct console *)obj;
716 struct screen_buffer *curr;
718 assert( obj->ops == &console_ops );
720 if (console->server)
722 assert( console->server->console == console );
723 disconnect_console_server( console->server );
726 if (console->active) release_object( console->active );
727 console->active = NULL;
729 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
731 if (curr->input == console) curr->input = NULL;
734 free_async_queue( &console->ioctl_q );
735 free_async_queue( &console->read_q );
736 if (console->fd)
737 release_object( console->fd );
740 static struct object *create_console_connection( struct console *console )
742 struct console_connection *connection;
744 if (current->process->console)
746 set_error( STATUS_ACCESS_DENIED );
747 return NULL;
750 if (!(connection = alloc_object( &console_connection_ops ))) return NULL;
751 if (!(connection->fd = alloc_pseudo_fd( &console_connection_fd_ops, &connection->obj, 0 )))
753 release_object( connection );
754 return NULL;
757 if (console)
759 current->process->console = (struct console *)grab_object( console );
760 console->num_proc++;
763 return &connection->obj;
766 static struct object *console_lookup_name( struct object *obj, struct unicode_str *name,
767 unsigned int attr, struct object *root )
769 struct console *console = (struct console *)obj;
770 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
771 assert( obj->ops == &console_ops );
773 if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
775 name->len = 0;
776 return create_console_connection( console );
779 return NULL;
782 static struct object *console_open_file( struct object *obj, unsigned int access,
783 unsigned int sharing, unsigned int options )
785 return grab_object( obj );
788 static void screen_buffer_dump( struct object *obj, int verbose )
790 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
791 assert( obj->ops == &screen_buffer_ops );
793 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
796 static void screen_buffer_destroy( struct object *obj )
798 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
800 assert( obj->ops == &screen_buffer_ops );
802 list_remove( &screen_buffer->entry );
803 if (screen_buffer->input && screen_buffer->input->server)
804 queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_CLOSE_OUTPUT,
805 screen_buffer->id, NULL, NULL );
806 if (screen_buffer->fd) release_object( screen_buffer->fd );
807 free_async_queue( &screen_buffer->ioctl_q );
810 static struct object *screen_buffer_open_file( struct object *obj, unsigned int access,
811 unsigned int sharing, unsigned int options )
813 return grab_object( obj );
816 static int screen_buffer_add_queue( struct object *obj, struct wait_queue_entry *entry )
818 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
819 if (!screen_buffer->input)
821 set_error( STATUS_ACCESS_DENIED );
822 return 0;
824 return add_queue( &screen_buffer->input->obj, entry );
827 static struct fd *screen_buffer_get_fd( struct object *obj )
829 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
830 assert( obj->ops == &screen_buffer_ops );
831 if (screen_buffer->fd)
832 return (struct fd*)grab_object( screen_buffer->fd );
833 set_error( STATUS_OBJECT_TYPE_MISMATCH );
834 return NULL;
837 static void console_server_dump( struct object *obj, int verbose )
839 assert( obj->ops == &console_server_ops );
840 fprintf( stderr, "Console server\n" );
843 static void console_server_destroy( struct object *obj )
845 struct console_server *server = (struct console_server *)obj;
846 assert( obj->ops == &console_server_ops );
847 disconnect_console_server( server );
848 if (server->fd) release_object( server->fd );
851 static struct object *console_server_lookup_name( struct object *obj, struct unicode_str *name,
852 unsigned int attr, struct object *root )
854 struct console_server *server = (struct console_server*)obj;
855 static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
856 assert( obj->ops == &console_server_ops );
858 if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
860 struct screen_buffer *screen_buffer;
861 name->len = 0;
862 if (server->console)
864 set_error( STATUS_INVALID_HANDLE );
865 return 0;
867 if (!(server->console = (struct console *)create_console())) return NULL;
868 if (!(screen_buffer = (struct screen_buffer *)create_screen_buffer( server->console )))
870 release_object( server->console );
871 server->console = NULL;
872 return NULL;
874 release_object( screen_buffer );
875 server->console->server = server;
877 return &server->console->obj;
880 return NULL;
883 static int console_server_signaled( struct object *obj, struct wait_queue_entry *entry )
885 struct console_server *server = (struct console_server*)obj;
886 assert( obj->ops == &console_server_ops );
887 return !server->console || !list_empty( &server->queue );
890 static struct fd *console_server_get_fd( struct object* obj )
892 struct console_server *server = (struct console_server*)obj;
893 assert( obj->ops == &console_server_ops );
894 return (struct fd *)grab_object( server->fd );
897 static struct object *console_server_open_file( struct object *obj, unsigned int access,
898 unsigned int sharing, unsigned int options )
900 return grab_object( obj );
903 static struct object *create_console_server( void )
905 struct console_server *server;
907 if (!(server = alloc_object( &console_server_ops ))) return NULL;
908 server->console = NULL;
909 server->busy = 0;
910 server->term_fd = -1;
911 list_init( &server->queue );
912 list_init( &server->read_queue );
913 server->fd = alloc_pseudo_fd( &console_server_fd_ops, &server->obj, FILE_SYNCHRONOUS_IO_NONALERT );
914 if (!server->fd)
916 release_object( server );
917 return NULL;
919 allow_fd_caching(server->fd);
921 return &server->obj;
924 static int is_blocking_read_ioctl( unsigned int code )
926 switch (code)
928 case IOCTL_CONDRV_READ_INPUT:
929 case IOCTL_CONDRV_READ_CONSOLE:
930 case IOCTL_CONDRV_READ_FILE:
931 return 1;
932 default:
933 return 0;
937 static int console_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
939 struct console *console = get_fd_user( fd );
941 switch (code)
943 case IOCTL_CONDRV_CTRL_EVENT:
945 const struct condrv_ctrl_event *event = get_req_data();
946 process_id_t group;
947 if (get_req_data_size() != sizeof(*event))
949 set_error( STATUS_INVALID_PARAMETER );
950 return 0;
952 group = event->group_id ? event->group_id : current->process->group_id;
953 if (!group)
955 set_error( STATUS_INVALID_PARAMETER );
956 return 0;
958 propagate_console_signal( console, event->event, group );
959 return !get_error();
962 default:
963 if (!console->server || code >> 16 != FILE_DEVICE_CONSOLE)
965 set_error( STATUS_INVALID_HANDLE );
966 return 0;
968 return queue_host_ioctl( console->server, code, 0, async, &console->ioctl_q );
972 static int console_read( struct fd *fd, struct async *async, file_pos_t pos )
974 struct console *console = get_fd_user( fd );
976 if (!console->server)
978 set_error( STATUS_INVALID_HANDLE );
979 return 0;
981 return queue_host_ioctl( console->server, IOCTL_CONDRV_READ_FILE, 0, async, &console->ioctl_q );
984 static int console_flush( struct fd *fd, struct async *async )
986 struct console *console = get_fd_user( fd );
988 if (!console->server)
990 set_error( STATUS_INVALID_HANDLE );
991 return 0;
993 return queue_host_ioctl( console->server, IOCTL_CONDRV_FLUSH, 0, NULL, NULL );
996 static int screen_buffer_write( struct fd *fd, struct async *async, file_pos_t pos )
998 struct screen_buffer *screen_buffer = get_fd_user( fd );
999 struct iosb *iosb;
1001 if (!screen_buffer->input || !screen_buffer->input->server)
1003 set_error( STATUS_INVALID_HANDLE );
1004 return 0;
1007 if (!queue_host_ioctl( screen_buffer->input->server, IOCTL_CONDRV_WRITE_FILE,
1008 screen_buffer->id, async, &screen_buffer->ioctl_q ))
1009 return 0;
1011 /* we can't use default async handling, because write result is not
1012 * compatible with ioctl result */
1013 iosb = async_get_iosb( async );
1014 iosb->status = STATUS_SUCCESS;
1015 iosb->result = iosb->in_size;
1016 async_terminate( async, iosb->result ? STATUS_ALERTED : STATUS_SUCCESS );
1017 release_object( iosb );
1018 return 1;
1021 static int screen_buffer_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1023 struct screen_buffer *screen_buffer = get_fd_user( fd );
1025 switch (code)
1027 case IOCTL_CONDRV_ACTIVATE:
1028 if (!screen_buffer->input)
1030 set_error( STATUS_INVALID_HANDLE );
1031 return 0;
1034 set_active_screen_buffer( screen_buffer->input, screen_buffer );
1035 return 1;
1037 default:
1038 if (!screen_buffer->input || !screen_buffer->input->server || code >> 16 != FILE_DEVICE_CONSOLE ||
1039 is_blocking_read_ioctl( code ))
1041 set_error( STATUS_INVALID_HANDLE );
1042 return 0;
1044 return queue_host_ioctl( screen_buffer->input->server, code, screen_buffer->id,
1045 async, &screen_buffer->ioctl_q );
1049 static int console_connection_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1051 struct console_connection *console_connection = get_fd_user( fd );
1053 switch (code)
1055 case IOCTL_CONDRV_BIND_PID:
1057 struct process *process;
1058 unsigned int pid;
1059 if (get_req_data_size() != sizeof(unsigned int))
1061 set_error( STATUS_INVALID_PARAMETER );
1062 return 0;
1064 if (current->process->console)
1066 set_error( STATUS_INVALID_HANDLE );
1067 return 0;
1070 pid = *(unsigned int *)get_req_data();
1071 if (pid == ATTACH_PARENT_PROCESS) pid = current->process->parent_id;
1072 if (!(process = get_process_from_id( pid ))) return 0;
1074 if (process->console)
1076 current->process->console = (struct console *)grab_object( process->console );
1077 process->console->num_proc++;
1079 else set_error( STATUS_ACCESS_DENIED );
1080 release_object( process );
1081 return !get_error();
1084 default:
1085 return default_fd_ioctl( console_connection->fd, code, async );
1089 static int console_server_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1091 struct console_server *server = get_fd_user( fd );
1093 switch (code)
1095 case IOCTL_CONDRV_CTRL_EVENT:
1097 const struct condrv_ctrl_event *event = get_req_data();
1098 if (get_req_data_size() != sizeof(*event))
1100 set_error( STATUS_INVALID_PARAMETER );
1101 return 0;
1103 if (!server->console)
1105 set_error( STATUS_INVALID_HANDLE );
1106 return 0;
1108 propagate_console_signal( server->console, event->event, event->group_id );
1109 return !get_error();
1112 case IOCTL_CONDRV_SETUP_INPUT:
1114 struct termios term;
1115 obj_handle_t handle;
1116 struct file *file;
1117 int unix_fd;
1119 if (get_req_data_size() != sizeof(unsigned int) || get_reply_max_size())
1121 set_error( STATUS_INVALID_PARAMETER );
1122 return 0;
1124 if (server->term_fd != -1)
1126 tcsetattr( server->term_fd, TCSANOW, &server->termios );
1127 close( server->term_fd );
1128 server->term_fd = -1;
1130 handle = *(unsigned int *)get_req_data();
1131 if (!handle) return 1;
1132 if (!(file = get_file_obj( current->process, handle, FILE_READ_DATA )))
1134 return 0;
1136 unix_fd = get_file_unix_fd( file );
1137 release_object( file );
1139 if (tcgetattr( unix_fd, &server->termios ))
1141 file_set_error();
1142 return 0;
1144 term = server->termios;
1145 term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
1146 term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
1147 term.c_cflag &= ~(CSIZE | PARENB);
1148 term.c_cflag |= CS8;
1149 term.c_cc[VMIN] = 1;
1150 term.c_cc[VTIME] = 0;
1151 if (tcsetattr( unix_fd, TCSANOW, &term ) || (server->term_fd = dup( unix_fd )) == -1)
1153 file_set_error();
1154 return 0;
1156 return 1;
1159 default:
1160 set_error( STATUS_INVALID_HANDLE );
1161 return 0;
1165 static void console_connection_dump( struct object *obj, int verbose )
1167 fputs( "console connection\n", stderr );
1170 static struct fd *console_connection_get_fd( struct object *obj )
1172 struct console_connection *connection = (struct console_connection *)obj;
1173 return (struct fd *)grab_object( connection->fd );
1176 static struct object *console_connection_lookup_name( struct object *obj, struct unicode_str *name,
1177 unsigned int attr, struct object *root )
1179 static const WCHAR referenceW[] = {'R','e','f','e','r','e','n','c','e'};
1181 if (name->len == sizeof(referenceW) && !memcmp( name->str, referenceW, name->len ))
1183 if (!current->process->console)
1185 set_error( STATUS_INVALID_HANDLE );
1186 return NULL;
1188 name->len = 0;
1189 return grab_object( current->process->console );
1192 return NULL;
1195 static struct object *console_connection_open_file( struct object *obj, unsigned int access,
1196 unsigned int sharing, unsigned int options )
1198 return grab_object( obj );
1201 static int console_connection_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
1203 free_console( process );
1204 return 1;
1207 static void console_connection_destroy( struct object *obj )
1209 struct console_connection *connection = (struct console_connection *)obj;
1210 if (connection->fd) release_object( connection->fd );
1213 static struct object_type *console_device_get_type( struct object *obj )
1215 static const WCHAR name[] = {'D','e','v','i','c','e'};
1216 static const struct unicode_str str = { name, sizeof(name) };
1217 return get_object_type( &str );
1220 static void console_device_dump( struct object *obj, int verbose )
1222 fputs( "Console device\n", stderr );
1225 static struct object *console_device_lookup_name( struct object *obj, struct unicode_str *name,
1226 unsigned int attr, struct object *root )
1228 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n'};
1229 static const WCHAR consoleW[] = {'C','o','n','s','o','l','e'};
1230 static const WCHAR current_inW[] = {'C','u','r','r','e','n','t','I','n'};
1231 static const WCHAR current_outW[] = {'C','u','r','r','e','n','t','O','u','t'};
1232 static const WCHAR inputW[] = {'I','n','p','u','t'};
1233 static const WCHAR outputW[] = {'O','u','t','p','u','t'};
1234 static const WCHAR screen_bufferW[] = {'S','c','r','e','e','n','B','u','f','f','e','r'};
1235 static const WCHAR serverW[] = {'S','e','r','v','e','r'};
1237 if (name->len == sizeof(current_inW) && !memcmp( name->str, current_inW, name->len ))
1239 if (!current->process->console)
1241 set_error( STATUS_INVALID_HANDLE );
1242 return NULL;
1244 name->len = 0;
1245 return grab_object( current->process->console );
1248 if (name->len == sizeof(current_outW) && !memcmp( name->str, current_outW, name->len ))
1250 if (!current->process->console || !current->process->console->active)
1252 set_error( STATUS_INVALID_HANDLE );
1253 return NULL;
1255 name->len = 0;
1256 return grab_object( current->process->console->active );
1259 if (name->len == sizeof(consoleW) && !memcmp( name->str, consoleW, name->len ))
1261 name->len = 0;
1262 return grab_object( obj );
1265 if (name->len == sizeof(inputW) && !memcmp( name->str, inputW, name->len ))
1267 struct console_input *console_input;
1268 name->len = 0;
1269 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
1270 console_input->fd = alloc_pseudo_fd( &console_input_fd_ops, &console_input->obj,
1271 FILE_SYNCHRONOUS_IO_NONALERT );
1272 if (!console_input->fd)
1274 release_object( console_input );
1275 return NULL;
1277 return &console_input->obj;
1280 if (name->len == sizeof(outputW) && !memcmp( name->str, outputW, name->len ))
1282 struct console_output *console_output;
1283 name->len = 0;
1284 if (!(console_output = alloc_object( &console_output_ops ))) return NULL;
1285 console_output->fd = alloc_pseudo_fd( &console_output_fd_ops, &console_output->obj,
1286 FILE_SYNCHRONOUS_IO_NONALERT );
1287 if (!console_output->fd)
1289 release_object( console_output );
1290 return NULL;
1292 return &console_output->obj;
1295 if (name->len == sizeof(screen_bufferW) && !memcmp( name->str, screen_bufferW, name->len ))
1297 if (!current->process->console)
1299 set_error( STATUS_INVALID_HANDLE );
1300 return NULL;
1302 name->len = 0;
1303 return create_screen_buffer( current->process->console );
1306 if (name->len == sizeof(serverW) && !memcmp( name->str, serverW, name->len ))
1308 name->len = 0;
1309 return create_console_server();
1312 if (name->len == sizeof(connectionW) && !memcmp( name->str, connectionW, name->len ))
1314 name->len = 0;
1315 return create_console_connection( NULL );
1318 return NULL;
1321 static struct object *console_device_open_file( struct object *obj, unsigned int access,
1322 unsigned int sharing, unsigned int options )
1324 int is_output;
1325 access = default_fd_map_access( obj, access );
1326 is_output = access & FILE_WRITE_DATA;
1327 if (!current->process->console || (is_output && !current->process->console))
1329 set_error( STATUS_INVALID_HANDLE );
1330 return NULL;
1332 if (is_output && (access & FILE_READ_DATA))
1334 set_error( STATUS_INVALID_PARAMETER );
1335 return NULL;
1337 return is_output ? grab_object( current->process->console->active ) : grab_object( current->process->console );
1340 static void console_input_dump( struct object *obj, int verbose )
1342 fputs( "console Input device\n", stderr );
1345 static int console_input_add_queue( struct object *obj, struct wait_queue_entry *entry )
1347 if (!current->process->console)
1349 set_error( STATUS_ACCESS_DENIED );
1350 return 0;
1352 return add_queue( &current->process->console->obj, entry );
1355 static struct fd *console_input_get_fd( struct object *obj )
1357 struct console_input *console_input = (struct console_input *)obj;
1358 assert( obj->ops == &console_input_ops );
1359 return (struct fd *)grab_object( console_input->fd );
1362 static struct object *console_input_open_file( struct object *obj, unsigned int access,
1363 unsigned int sharing, unsigned int options )
1365 return grab_object( obj );
1368 static void console_input_destroy( struct object *obj )
1370 struct console_input *console_input = (struct console_input *)obj;
1372 assert( obj->ops == &console_input_ops );
1373 if (console_input->fd) release_object( console_input->fd );
1376 static int console_input_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1378 struct console *console = current->process->console;
1380 if (!console)
1382 set_error( STATUS_INVALID_HANDLE );
1383 return 0;
1385 return console_ioctl( console->fd, code, async );
1388 static int console_input_read( struct fd *fd, struct async *async, file_pos_t pos )
1390 struct console *console = current->process->console;
1392 if (!console)
1394 set_error( STATUS_INVALID_HANDLE );
1395 return 0;
1397 return console_read( console->fd, async, pos );
1400 static int console_input_flush( struct fd *fd, struct async *async )
1402 struct console *console = current->process->console;
1404 if (!console)
1406 set_error( STATUS_INVALID_HANDLE );
1407 return 0;
1409 return console_flush( console->fd, async );
1412 static void console_output_dump( struct object *obj, int verbose )
1414 fputs( "console Output device\n", stderr );
1417 static int console_output_add_queue( struct object *obj, struct wait_queue_entry *entry )
1419 if (!current->process->console || !current->process->console->active)
1421 set_error( STATUS_ACCESS_DENIED );
1422 return 0;
1424 return add_queue( &current->process->console->obj, entry );
1427 static struct fd *console_output_get_fd( struct object *obj )
1429 struct console_output *console_output = (struct console_output *)obj;
1430 assert( obj->ops == &console_output_ops );
1431 return (struct fd *)grab_object( console_output->fd );
1434 static struct object *console_output_open_file( struct object *obj, unsigned int access,
1435 unsigned int sharing, unsigned int options )
1437 return grab_object( obj );
1440 static void console_output_destroy( struct object *obj )
1442 struct console_output *console_output = (struct console_output *)obj;
1444 assert( obj->ops == &console_output_ops );
1445 if (console_output->fd) release_object( console_output->fd );
1448 static int console_output_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
1450 struct console *console = current->process->console;
1452 if (!console || !console->active)
1454 set_error( STATUS_INVALID_HANDLE );
1455 return 0;
1457 return screen_buffer_ioctl( console->active->fd, code, async );
1460 static int console_output_write( struct fd *fd, struct async *async, file_pos_t pos )
1462 struct console *console = current->process->console;
1464 if (!console || !console->active)
1466 set_error( STATUS_INVALID_HANDLE );
1467 return 0;
1469 return screen_buffer_write( console->active->fd, async, pos );
1472 struct object *create_console_device( struct object *root, const struct unicode_str *name,
1473 unsigned int attr, const struct security_descriptor *sd )
1475 return create_named_object( root, &console_device_ops, name, attr, sd );
1478 /* retrieve the next pending console ioctl request */
1479 DECL_HANDLER(get_next_console_request)
1481 struct console_host_ioctl *ioctl = NULL, *next;
1482 struct console_server *server;
1483 struct iosb *iosb = NULL;
1485 server = (struct console_server *)get_handle_obj( current->process, req->handle, 0, &console_server_ops );
1486 if (!server) return;
1488 if (!server->console)
1490 set_error( STATUS_INVALID_HANDLE );
1491 release_object( server );
1492 return;
1495 if (!req->signal) server->console->signaled = 0;
1496 else if (!server->console->signaled)
1498 server->console->signaled = 1;
1499 wake_up( &server->console->obj, 0 );
1502 if (req->read)
1504 /* set result of current pending ioctl */
1505 if (list_empty( &server->read_queue ))
1507 set_error( STATUS_INVALID_HANDLE );
1508 release_object( server );
1509 return;
1512 ioctl = LIST_ENTRY( list_head( &server->read_queue ), struct console_host_ioctl, entry );
1513 list_remove( &ioctl->entry );
1514 list_move_tail( &server->queue, &server->read_queue );
1516 else if (server->busy)
1518 /* set result of previous ioctl */
1519 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1520 list_remove( &ioctl->entry );
1523 if (ioctl)
1525 unsigned int status = req->status;
1526 if (status == STATUS_PENDING) status = STATUS_INVALID_PARAMETER;
1527 if (ioctl->async)
1529 iosb = async_get_iosb( ioctl->async );
1530 if (iosb->status == STATUS_PENDING)
1532 iosb->status = status;
1533 iosb->out_size = min( iosb->out_size, get_req_data_size() );
1534 if (iosb->out_size)
1536 if ((iosb->out_data = memdup( get_req_data(), iosb->out_size )))
1538 iosb->result = iosb->out_size;
1539 status = STATUS_ALERTED;
1541 else if (!status)
1543 iosb->status = STATUS_NO_MEMORY;
1544 iosb->out_size = 0;
1548 else
1550 release_object( ioctl->async );
1551 ioctl->async = NULL;
1554 console_host_ioctl_terminate( ioctl, status );
1555 if (iosb) release_object( iosb );
1557 if (req->read)
1559 release_object( server );
1560 return;
1562 server->busy = 0;
1565 /* if we have a blocking read ioctl in queue head and previous blocking read is still waiting,
1566 * move it to read queue for execution after current read is complete. move all blocking
1567 * ioctl at the same time to preserve their order. */
1568 if (!list_empty( &server->queue ) && !list_empty( &server->read_queue ))
1570 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1571 if (is_blocking_read_ioctl( ioctl->code ))
1573 LIST_FOR_EACH_ENTRY_SAFE( ioctl, next, &server->queue, struct console_host_ioctl, entry )
1575 if (!is_blocking_read_ioctl( ioctl->code )) continue;
1576 list_remove( &ioctl->entry );
1577 list_add_tail( &server->read_queue, &ioctl->entry );
1582 /* return the next ioctl */
1583 if (!list_empty( &server->queue ))
1585 ioctl = LIST_ENTRY( list_head( &server->queue ), struct console_host_ioctl, entry );
1586 iosb = ioctl->async ? async_get_iosb( ioctl->async ) : NULL;
1588 if (!iosb || get_reply_max_size() >= iosb->in_size)
1590 reply->code = ioctl->code;
1591 reply->output = ioctl->output;
1593 if (iosb)
1595 reply->out_size = iosb->out_size;
1596 set_reply_data_ptr( iosb->in_data, iosb->in_size );
1597 iosb->in_data = NULL;
1600 if (is_blocking_read_ioctl( ioctl->code ))
1602 list_remove( &ioctl->entry );
1603 assert( list_empty( &server->read_queue ));
1604 list_add_tail( &server->read_queue, &ioctl->entry );
1606 else server->busy = 1;
1608 else
1610 reply->out_size = iosb->in_size;
1611 set_error( STATUS_BUFFER_OVERFLOW );
1613 if (iosb) release_object( iosb );
1615 else
1617 set_error( STATUS_PENDING );
1620 release_object( server );