2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
33 #define WIN32_NO_STATUS
43 struct console_input_events;
47 struct object obj; /* object header */
48 int num_proc; /* number of processes attached to this console */
49 struct thread *renderer; /* console renderer thread */
50 int mode; /* input mode */
51 struct screen_buffer *active; /* active screen buffer */
52 int recnum; /* number of input records */
53 INPUT_RECORD *records; /* input records */
54 struct console_input_events *evt; /* synchronization event with renderer */
55 WCHAR *title; /* console title */
56 WCHAR **history; /* lines history */
57 int history_size; /* number of entries in history array */
58 int history_index; /* number of used entries in history array */
59 int history_mode; /* mode of history (non zero means remove doubled strings */
60 int edition_mode; /* index to edition mode flavors */
61 int input_cp; /* console input codepage */
62 int output_cp; /* console output codepage */
63 user_handle_t win; /* window handle if backend supports it */
64 struct event *event; /* event to wait on for input queue */
67 static void console_input_dump( struct object *obj, int verbose );
68 static void console_input_destroy( struct object *obj );
70 static const struct object_ops console_input_ops =
72 sizeof(struct console_input), /* size */
73 console_input_dump, /* dump */
74 no_get_type, /* get_type */
75 no_add_queue, /* add_queue */
76 NULL, /* remove_queue */
78 no_satisfied, /* satisfied */
79 no_signal, /* signal */
80 no_get_fd, /* get_fd */
81 default_fd_map_access, /* map_access */
82 default_get_sd, /* get_sd */
83 default_set_sd, /* set_sd */
84 no_lookup_name, /* lookup_name */
85 no_open_file, /* open_file */
86 no_close_handle, /* close_handle */
87 console_input_destroy /* destroy */
90 static void console_input_events_dump( struct object *obj, int verbose );
91 static void console_input_events_destroy( struct object *obj );
92 static int console_input_events_signaled( struct object *obj, struct thread *thread );
94 struct console_input_events
96 struct object obj; /* object header */
97 int num_alloc; /* number of allocated events */
98 int num_used; /* number of actually used events */
99 struct console_renderer_event* events;
102 static const struct object_ops console_input_events_ops =
104 sizeof(struct console_input_events), /* size */
105 console_input_events_dump, /* dump */
106 no_get_type, /* get_type */
107 add_queue, /* add_queue */
108 remove_queue, /* remove_queue */
109 console_input_events_signaled, /* signaled */
110 no_satisfied, /* satisfied */
111 no_signal, /* signal */
112 no_get_fd, /* get_fd */
113 default_fd_map_access, /* map_access */
114 default_get_sd, /* get_sd */
115 default_set_sd, /* set_sd */
116 no_lookup_name, /* lookup_name */
117 no_open_file, /* open_file */
118 no_close_handle, /* close_handle */
119 console_input_events_destroy /* destroy */
124 struct object obj; /* object header */
125 struct list entry; /* entry in list of all screen buffers */
126 struct console_input *input; /* associated console input */
127 int mode; /* output mode */
128 int cursor_size; /* size of cursor (percentage filled) */
129 int cursor_visible;/* cursor visibility flag */
130 int cursor_x; /* position of cursor */
131 int cursor_y; /* position of cursor */
132 int width; /* size (w-h) of the screen buffer */
134 int max_width; /* size (w-h) of the window given font size */
136 char_info_t *data; /* the data for each cell - a width x height matrix */
137 unsigned short attr; /* default attribute for screen buffer */
138 rectangle_t win; /* current visible window on the screen buffer *
139 * as seen in wineconsole */
142 static void screen_buffer_dump( struct object *obj, int verbose );
143 static void screen_buffer_destroy( struct object *obj );
145 static const struct object_ops screen_buffer_ops =
147 sizeof(struct screen_buffer), /* size */
148 screen_buffer_dump, /* dump */
149 no_get_type, /* get_type */
150 no_add_queue, /* add_queue */
151 NULL, /* remove_queue */
153 NULL, /* satisfied */
154 no_signal, /* signal */
155 no_get_fd, /* get_fd */
156 default_fd_map_access, /* map_access */
157 default_get_sd, /* get_sd */
158 default_set_sd, /* set_sd */
159 no_lookup_name, /* lookup_name */
160 no_open_file, /* open_file */
161 no_close_handle, /* close_handle */
162 screen_buffer_destroy /* destroy */
165 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
167 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
169 /* dumps the renderer events of a console */
170 static void console_input_events_dump( struct object *obj, int verbose )
172 struct console_input_events *evts = (struct console_input_events *)obj;
173 assert( obj->ops == &console_input_events_ops );
174 fprintf( stderr, "Console input events: %d/%d events\n",
175 evts->num_used, evts->num_alloc );
178 /* destroys the renderer events of a console */
179 static void console_input_events_destroy( struct object *obj )
181 struct console_input_events *evts = (struct console_input_events *)obj;
182 assert( obj->ops == &console_input_events_ops );
183 free( evts->events );
186 /* the renderer events list is signaled when it's not empty */
187 static int console_input_events_signaled( struct object *obj, struct thread *thread )
189 struct console_input_events *evts = (struct console_input_events *)obj;
190 assert( obj->ops == &console_input_events_ops );
191 return (evts->num_used != 0);
194 /* add an event to the console's renderer events list */
195 static void console_input_events_append( struct console_input_events* evts,
196 struct console_renderer_event* evt)
198 int collapsed = FALSE;
200 /* to be done even when evt has been generated by the rendere ? */
202 /* try to collapse evt into current queue's events */
205 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
207 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
208 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
210 /* if two update events overlap, collapse them into a single one */
211 if (last->u.update.bottom + 1 >= evt->u.update.top &&
212 evt->u.update.bottom + 1 >= last->u.update.top)
214 last->u.update.top = min(last->u.update.top, evt->u.update.top);
215 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
222 if (evts->num_used == evts->num_alloc)
224 evts->num_alloc += 16;
225 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
226 assert(evts->events);
228 evts->events[evts->num_used++] = *evt;
230 wake_up( &evts->obj, 0 );
233 /* retrieves events from the console's renderer events list */
234 static void console_input_events_get( struct console_input_events* evts )
236 data_size_t num = get_reply_max_size() / sizeof(evts->events[0]);
238 if (num > evts->num_used) num = evts->num_used;
239 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
240 if (num < evts->num_used)
242 memmove( &evts->events[0], &evts->events[num],
243 (evts->num_used - num) * sizeof(evts->events[0]) );
245 evts->num_used -= num;
248 static struct console_input_events *create_console_input_events(void)
250 struct console_input_events* evt;
252 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
253 evt->num_alloc = evt->num_used = 0;
258 static struct object *create_console_input( struct thread* renderer )
260 struct console_input *console_input;
262 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
263 console_input->renderer = renderer;
264 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
265 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
266 console_input->num_proc = 0;
267 console_input->active = NULL;
268 console_input->recnum = 0;
269 console_input->records = NULL;
270 console_input->evt = create_console_input_events();
271 console_input->title = NULL;
272 console_input->history_size = 50;
273 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
274 console_input->history_index = 0;
275 console_input->history_mode = 0;
276 console_input->edition_mode = 0;
277 console_input->input_cp = 0;
278 console_input->output_cp = 0;
279 console_input->win = 0;
280 console_input->event = create_event( NULL, NULL, 0, 1, 0, NULL );
282 if (!console_input->history || !console_input->evt || !console_input->event)
284 release_object( console_input );
287 return &console_input->obj;
290 static void generate_sb_initial_events( struct console_input *console_input )
292 struct screen_buffer *screen_buffer = console_input->active;
293 struct console_renderer_event evt;
295 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
296 memset(&evt.u, 0, sizeof(evt.u));
297 console_input_events_append( console_input->evt, &evt );
299 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
300 evt.u.resize.width = screen_buffer->width;
301 evt.u.resize.height = screen_buffer->height;
302 console_input_events_append( console_input->evt, &evt );
304 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
305 evt.u.display.left = screen_buffer->win.left;
306 evt.u.display.top = screen_buffer->win.top;
307 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
308 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
309 console_input_events_append( console_input->evt, &evt );
311 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
312 evt.u.update.top = 0;
313 evt.u.update.bottom = screen_buffer->height - 1;
314 console_input_events_append( console_input->evt, &evt );
316 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
317 evt.u.cursor_geom.size = screen_buffer->cursor_size;
318 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
319 console_input_events_append( console_input->evt, &evt );
321 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
322 evt.u.cursor_pos.x = screen_buffer->cursor_x;
323 evt.u.cursor_pos.y = screen_buffer->cursor_y;
324 console_input_events_append( console_input->evt, &evt );
327 static struct screen_buffer *create_console_output( struct console_input *console_input )
329 struct screen_buffer *screen_buffer;
332 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
333 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
334 screen_buffer->input = console_input;
335 screen_buffer->cursor_size = 100;
336 screen_buffer->cursor_visible = 1;
337 screen_buffer->width = 80;
338 screen_buffer->height = 150;
339 screen_buffer->max_width = 80;
340 screen_buffer->max_height = 25;
341 screen_buffer->cursor_x = 0;
342 screen_buffer->cursor_y = 0;
343 screen_buffer->attr = 0x0F;
344 screen_buffer->win.left = 0;
345 screen_buffer->win.right = screen_buffer->max_width - 1;
346 screen_buffer->win.top = 0;
347 screen_buffer->win.bottom = screen_buffer->max_height - 1;
349 list_add_head( &screen_buffer_list, &screen_buffer->entry );
351 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
352 sizeof(*screen_buffer->data) )))
354 release_object( screen_buffer );
357 /* clear the first row */
358 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
359 /* and copy it to all other rows */
360 for (i = 1; i < screen_buffer->height; i++)
361 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
362 screen_buffer->width * sizeof(char_info_t) );
364 if (!console_input->active)
366 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
367 generate_sb_initial_events( console_input );
369 return screen_buffer;
372 /* free the console for this process */
373 int free_console( struct process *process )
375 struct console_input* console = process->console;
377 if (!console || !console->renderer) return 0;
379 process->console = NULL;
380 if (--console->num_proc == 0)
382 /* all processes have terminated... tell the renderer to terminate too */
383 struct console_renderer_event evt;
384 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
385 memset(&evt.u, 0, sizeof(evt.u));
386 console_input_events_append( console->evt, &evt );
388 release_object( console );
393 /* let process inherit the console from parent... this handle two cases :
394 * 1/ generic console inheritance
395 * 2/ parent is a renderer which launches process, and process should attach to the console
396 * renderered by parent
398 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
401 struct process* parent = parent_thread->process;
403 /* if parent is a renderer, then attach current process to its console
408 struct console_input* console;
410 /* FIXME: should we check some access rights ? */
411 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
412 0, &console_input_ops )))
414 if (console->renderer == parent_thread)
416 process->console = (struct console_input*)grab_object( console );
417 process->console->num_proc++;
420 release_object( console );
422 else clear_error(); /* ignore error */
424 /* otherwise, if parent has a console, attach child to this console */
425 if (!done && parent->console)
427 assert(parent->console->renderer);
428 process->console = (struct console_input*)grab_object( parent->console );
429 process->console->num_proc++;
433 struct thread *console_get_renderer( struct console_input *console )
435 return console->renderer;
438 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
440 struct console_input* console = NULL;
443 console = (struct console_input *)get_handle_obj( current->process, handle,
444 access, &console_input_ops );
445 else if (current->process->console)
447 assert( current->process->console->renderer );
448 console = (struct console_input *)grab_object( current->process->console );
451 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
455 struct console_signal_info
457 struct console_input *console;
462 static int propagate_console_signal_cb(struct process *process, void *user)
464 struct console_signal_info* csi = (struct console_signal_info*)user;
466 if (process->console == csi->console && process->running_threads &&
467 (!csi->group || process->group_id == csi->group))
469 /* find a suitable thread to signal */
470 struct thread *thread;
471 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
473 if (send_thread_signal( thread, csi->signal )) break;
479 static void propagate_console_signal( struct console_input *console,
480 int sig, process_id_t group_id )
482 struct console_signal_info csi;
486 set_error( STATUS_INVALID_PARAMETER );
489 /* FIXME: should support the other events (like CTRL_BREAK) */
490 if (sig != CTRL_C_EVENT)
492 set_error( STATUS_NOT_IMPLEMENTED );
495 csi.console = console;
497 csi.group = group_id;
499 enum_processes(propagate_console_signal_cb, &csi);
502 static int get_console_mode( obj_handle_t handle )
507 if ((obj = get_handle_obj( current->process, handle, FILE_READ_PROPERTIES, NULL )))
509 if (obj->ops == &console_input_ops)
510 ret = ((struct console_input *)obj)->mode;
511 else if (obj->ops == &screen_buffer_ops)
512 ret = ((struct screen_buffer *)obj)->mode;
514 set_error( STATUS_OBJECT_TYPE_MISMATCH );
515 release_object( obj );
520 /* changes the mode of either a console input or a screen buffer */
521 static int set_console_mode( obj_handle_t handle, int mode )
526 if (!(obj = get_handle_obj( current->process, handle, FILE_WRITE_PROPERTIES, NULL )))
528 if (obj->ops == &console_input_ops)
530 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
531 ((struct console_input *)obj)->mode = mode;
534 else if (obj->ops == &screen_buffer_ops)
536 ((struct screen_buffer *)obj)->mode = mode;
539 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
540 release_object( obj );
544 /* add input events to a console input queue */
545 static int write_console_input( struct console_input* console, int count,
546 const INPUT_RECORD *records )
548 INPUT_RECORD *new_rec;
550 if (!count) return 0;
551 if (!(new_rec = realloc( console->records,
552 (console->recnum + count) * sizeof(INPUT_RECORD) )))
554 set_error( STATUS_NO_MEMORY );
555 release_object( console );
558 console->records = new_rec;
559 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
561 if (console->mode & ENABLE_PROCESSED_INPUT)
566 if (records[i].EventType == KEY_EVENT &&
567 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
568 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
571 memcpy( &console->records[console->recnum + i],
572 &console->records[console->recnum + i + 1],
573 (count - i - 1) * sizeof(INPUT_RECORD) );
575 if (records[i].Event.KeyEvent.bKeyDown)
577 /* send SIGINT to all processes attached to this console */
578 propagate_console_signal( console, CTRL_C_EVENT, 0 );
584 if (!console->recnum && count) set_event( console->event );
585 console->recnum += count;
589 /* retrieve a pointer to the console input records */
590 static int read_console_input( obj_handle_t handle, int count, int flush )
592 struct console_input *console;
594 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
595 FILE_READ_DATA, &console_input_ops )))
600 /* special case: do not retrieve anything, but return
601 * the total number of records available */
602 count = console->recnum;
606 if (count > console->recnum) count = console->recnum;
607 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
612 for (i = count; i < console->recnum; i++)
613 console->records[i-count] = console->records[i];
614 if ((console->recnum -= count) > 0)
616 INPUT_RECORD *new_rec = realloc( console->records,
617 console->recnum * sizeof(INPUT_RECORD) );
618 if (new_rec) console->records = new_rec;
622 free( console->records );
623 console->records = NULL;
624 reset_event( console->event );
627 release_object( console );
631 /* set misc console input information */
632 static int set_console_input_info( const struct set_console_input_info_request *req,
633 const WCHAR *title, data_size_t len )
635 struct console_input *console;
636 struct console_renderer_event evt;
638 if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) goto error;
640 memset(&evt.u, 0, sizeof(evt.u));
641 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
643 struct screen_buffer *screen_buffer;
645 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
646 FILE_WRITE_PROPERTIES, &screen_buffer_ops );
647 if (!screen_buffer || screen_buffer->input != console)
649 set_error( STATUS_INVALID_HANDLE );
650 if (screen_buffer) release_object( screen_buffer );
654 if (screen_buffer != console->active)
656 if (console->active) release_object( console->active );
657 console->active = screen_buffer;
658 generate_sb_initial_events( console );
661 release_object( screen_buffer );
663 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
665 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
668 memcpy( new_title, title, len );
669 new_title[len / sizeof(WCHAR)] = 0;
670 free( console->title );
671 console->title = new_title;
672 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
673 console_input_events_append( console->evt, &evt );
676 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
678 console->history_mode = req->history_mode;
680 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
681 console->history_size != req->history_size)
687 if (req->history_size)
689 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
690 if (!mem) goto error;
691 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
694 delta = (console->history_index > req->history_size) ?
695 (console->history_index - req->history_size) : 0;
697 for (i = delta; i < console->history_index; i++)
699 mem[i - delta] = console->history[i];
700 console->history[i] = NULL;
702 console->history_index -= delta;
704 for (i = 0; i < console->history_size; i++)
705 free( console->history[i] );
706 free( console->history );
707 console->history = mem;
708 console->history_size = req->history_size;
710 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
712 console->edition_mode = req->edition_mode;
714 if (req->mask & SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE)
716 console->input_cp = req->input_cp;
718 if (req->mask & SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE)
720 console->output_cp = req->output_cp;
722 if (req->mask & SET_CONSOLE_INPUT_INFO_WIN)
724 console->win = req->win;
726 release_object( console );
729 if (console) release_object( console );
733 /* resize a screen buffer */
734 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
735 int new_width, int new_height )
737 int i, old_width, old_height, copy_width, copy_height;
738 char_info_t *new_data;
740 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
742 set_error( STATUS_NO_MEMORY );
745 old_width = screen_buffer->width;
746 old_height = screen_buffer->height;
747 copy_width = min( old_width, new_width );
748 copy_height = min( old_height, new_height );
750 /* copy all the rows */
751 for (i = 0; i < copy_height; i++)
753 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
754 copy_width * sizeof(char_info_t) );
757 /* clear the end of each row */
758 if (new_width > old_width)
761 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
762 /* and blast it to the other rows */
763 for (i = 1; i < copy_height; i++)
764 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
765 (new_width - old_width) * sizeof(char_info_t) );
768 /* clear remaining rows */
769 if (new_height > old_height)
772 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
773 /* and blast it to the other rows */
774 for (i = old_height+1; i < new_height; i++)
775 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
776 new_width * sizeof(char_info_t) );
778 free( screen_buffer->data );
779 screen_buffer->data = new_data;
780 screen_buffer->width = new_width;
781 screen_buffer->height = new_height;
785 /* set misc screen buffer information */
786 static int set_console_output_info( struct screen_buffer *screen_buffer,
787 const struct set_console_output_info_request *req )
789 struct console_renderer_event evt;
791 memset(&evt.u, 0, sizeof(evt.u));
792 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
794 if (req->cursor_size < 1 || req->cursor_size > 100)
796 set_error( STATUS_INVALID_PARAMETER );
799 if (screen_buffer->cursor_size != req->cursor_size ||
800 screen_buffer->cursor_visible != req->cursor_visible)
802 screen_buffer->cursor_size = req->cursor_size;
803 screen_buffer->cursor_visible = req->cursor_visible;
804 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
805 evt.u.cursor_geom.size = req->cursor_size;
806 evt.u.cursor_geom.visible = req->cursor_visible;
807 console_input_events_append( screen_buffer->input->evt, &evt );
810 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
812 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
813 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
815 set_error( STATUS_INVALID_PARAMETER );
818 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
820 screen_buffer->cursor_x = req->cursor_x;
821 screen_buffer->cursor_y = req->cursor_y;
822 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
823 evt.u.cursor_pos.x = req->cursor_x;
824 evt.u.cursor_pos.y = req->cursor_y;
825 console_input_events_append( screen_buffer->input->evt, &evt );
828 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
832 /* new screen-buffer cannot be smaller than actual window */
833 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
834 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
836 set_error( STATUS_INVALID_PARAMETER );
839 /* FIXME: there are also some basic minimum and max size to deal with */
840 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
842 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
843 evt.u.resize.width = req->width;
844 evt.u.resize.height = req->height;
845 console_input_events_append( screen_buffer->input->evt, &evt );
847 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
848 evt.u.update.top = 0;
849 evt.u.update.bottom = screen_buffer->height - 1;
850 console_input_events_append( screen_buffer->input->evt, &evt );
852 /* scroll window to display sb */
853 if (screen_buffer->win.right >= req->width)
855 screen_buffer->win.right -= screen_buffer->win.left;
856 screen_buffer->win.left = 0;
858 if (screen_buffer->win.bottom >= req->height)
860 screen_buffer->win.bottom -= screen_buffer->win.top;
861 screen_buffer->win.top = 0;
863 /* reset cursor if needed (normally, if cursor was outside of new sb, the
864 * window has been shifted so that the new position of the cursor will be
867 if (screen_buffer->cursor_x >= req->width)
869 screen_buffer->cursor_x = req->width - 1;
872 if (screen_buffer->cursor_y >= req->height)
874 screen_buffer->cursor_y = req->height - 1;
879 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
880 evt.u.cursor_pos.x = req->cursor_x;
881 evt.u.cursor_pos.y = req->cursor_y;
882 console_input_events_append( screen_buffer->input->evt, &evt );
885 if (screen_buffer == screen_buffer->input->active &&
886 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
889 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
890 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
891 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
892 write_console_input( screen_buffer->input, 1, &ir );
895 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
897 screen_buffer->attr = req->attr;
899 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
901 if (req->win_left < 0 || req->win_left > req->win_right ||
902 req->win_right >= screen_buffer->width ||
903 req->win_top < 0 || req->win_top > req->win_bottom ||
904 req->win_bottom >= screen_buffer->height)
906 set_error( STATUS_INVALID_PARAMETER );
909 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
910 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
912 screen_buffer->win.left = req->win_left;
913 screen_buffer->win.top = req->win_top;
914 screen_buffer->win.right = req->win_right;
915 screen_buffer->win.bottom = req->win_bottom;
916 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
917 evt.u.display.left = req->win_left;
918 evt.u.display.top = req->win_top;
919 evt.u.display.width = req->win_right - req->win_left + 1;
920 evt.u.display.height = req->win_bottom - req->win_top + 1;
921 console_input_events_append( screen_buffer->input->evt, &evt );
924 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
926 /* can only be done by renderer */
927 if (current->process->console != screen_buffer->input)
929 set_error( STATUS_INVALID_PARAMETER );
933 screen_buffer->max_width = req->max_width;
934 screen_buffer->max_height = req->max_height;
940 /* appends a new line to history (history is a fixed size array) */
941 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, data_size_t len )
943 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
948 if (!console || !console->history_size)
950 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
955 memcpy( ptr, buf, len * sizeof(WCHAR) );
958 if (console->history_mode && console->history_index &&
959 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
961 /* ok, mode ask us to not use twice the same string...
962 * so just free mem and returns
964 set_error( STATUS_ALIAS_EXISTS );
969 if (console->history_index < console->history_size)
971 console->history[console->history_index++] = ptr;
975 free( console->history[0]) ;
976 memmove( &console->history[0], &console->history[1],
977 (console->history_size - 1) * sizeof(WCHAR*) );
978 console->history[console->history_size - 1] = ptr;
982 /* returns a line from the cache */
983 static data_size_t console_input_get_hist( struct console_input *console, int index )
987 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
990 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
991 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
997 static void console_input_dump( struct object *obj, int verbose )
999 struct console_input *console = (struct console_input *)obj;
1000 assert( obj->ops == &console_input_ops );
1001 fprintf( stderr, "Console input active=%p evt=%p\n",
1002 console->active, console->evt );
1005 static void console_input_destroy( struct object *obj )
1007 struct console_input* console_in = (struct console_input *)obj;
1008 struct screen_buffer* curr;
1011 assert( obj->ops == &console_input_ops );
1012 free( console_in->title );
1013 free( console_in->records );
1015 if (console_in->active) release_object( console_in->active );
1016 console_in->active = NULL;
1018 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
1020 if (curr->input == console_in) curr->input = NULL;
1023 release_object( console_in->evt );
1024 console_in->evt = NULL;
1025 release_object( console_in->event );
1027 for (i = 0; i < console_in->history_size; i++)
1028 free( console_in->history[i] );
1029 free( console_in->history );
1032 static void screen_buffer_dump( struct object *obj, int verbose )
1034 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
1035 assert( obj->ops == &screen_buffer_ops );
1037 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
1040 static void screen_buffer_destroy( struct object *obj )
1042 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
1044 assert( obj->ops == &screen_buffer_ops );
1046 list_remove( &screen_buffer->entry );
1048 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
1050 struct screen_buffer *sb;
1052 screen_buffer->input->active = NULL;
1053 LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry )
1055 if (sb->input == screen_buffer->input)
1057 sb->input->active = sb;
1062 free( screen_buffer->data );
1065 /* write data into a screen buffer */
1066 static int write_console_output( struct screen_buffer *screen_buffer, data_size_t size,
1067 const void* data, enum char_info_mode mode,
1068 int x, int y, int wrap )
1071 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1073 if (y >= screen_buffer->height) return 0;
1076 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1078 end = screen_buffer->data + (y+1) * screen_buffer->width;
1082 case CHAR_INFO_MODE_TEXT:
1084 const WCHAR *ptr = data;
1085 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1088 case CHAR_INFO_MODE_ATTR:
1090 const unsigned short *ptr = data;
1091 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1094 case CHAR_INFO_MODE_TEXTATTR:
1096 const char_info_t *ptr = data;
1097 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1100 case CHAR_INFO_MODE_TEXTSTDATTR:
1102 const WCHAR *ptr = data;
1103 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1106 dest->attr = screen_buffer->attr;
1111 set_error( STATUS_INVALID_PARAMETER );
1115 if (i && screen_buffer == screen_buffer->input->active)
1117 struct console_renderer_event evt;
1118 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1119 memset(&evt.u, 0, sizeof(evt.u));
1120 evt.u.update.top = y + x / screen_buffer->width;
1121 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1122 console_input_events_append( screen_buffer->input->evt, &evt );
1127 /* fill a screen buffer with uniform data */
1128 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1129 enum char_info_mode mode, int x, int y, int count, int wrap )
1132 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1134 if (y >= screen_buffer->height) return 0;
1137 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1139 end = screen_buffer->data + (y+1) * screen_buffer->width;
1141 if (count > end - dest) count = end - dest;
1145 case CHAR_INFO_MODE_TEXT:
1146 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1148 case CHAR_INFO_MODE_ATTR:
1149 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1151 case CHAR_INFO_MODE_TEXTATTR:
1152 for (i = 0; i < count; i++) dest[i] = data;
1154 case CHAR_INFO_MODE_TEXTSTDATTR:
1155 for (i = 0; i < count; i++)
1157 dest[i].ch = data.ch;
1158 dest[i].attr = screen_buffer->attr;
1162 set_error( STATUS_INVALID_PARAMETER );
1166 if (count && screen_buffer == screen_buffer->input->active)
1168 struct console_renderer_event evt;
1169 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1170 memset(&evt.u, 0, sizeof(evt.u));
1171 evt.u.update.top = y;
1172 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1173 console_input_events_append( screen_buffer->input->evt, &evt );
1178 /* read data from a screen buffer */
1179 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1180 enum char_info_mode mode, int wrap )
1183 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1185 if (y >= screen_buffer->height) return;
1188 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1190 end = screen_buffer->data + (y+1) * screen_buffer->width;
1194 case CHAR_INFO_MODE_TEXT:
1197 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1198 if ((data = set_reply_data_size( count * sizeof(*data) )))
1200 for (i = 0; i < count; i++) data[i] = src[i].ch;
1204 case CHAR_INFO_MODE_ATTR:
1206 unsigned short *data;
1207 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1208 if ((data = set_reply_data_size( count * sizeof(*data) )))
1210 for (i = 0; i < count; i++) data[i] = src[i].attr;
1214 case CHAR_INFO_MODE_TEXTATTR:
1217 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1218 if ((data = set_reply_data_size( count * sizeof(*data) )))
1220 for (i = 0; i < count; i++) data[i] = src[i];
1225 set_error( STATUS_INVALID_PARAMETER );
1230 /* scroll parts of a screen buffer */
1231 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1234 struct screen_buffer *screen_buffer;
1236 char_info_t *psrc, *pdst;
1237 struct console_renderer_event evt;
1239 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1240 FILE_WRITE_DATA, &screen_buffer_ops )))
1242 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1243 xsrc + w > screen_buffer->width ||
1244 xdst + w > screen_buffer->width ||
1245 ysrc + h > screen_buffer->height ||
1246 ydst + h > screen_buffer->height ||
1249 set_error( STATUS_INVALID_PARAMETER );
1250 release_object( screen_buffer );
1256 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1257 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1259 for (j = h; j > 0; j--)
1261 memcpy(pdst, psrc, w * sizeof(*pdst) );
1262 pdst -= screen_buffer->width;
1263 psrc -= screen_buffer->width;
1268 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1269 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1271 for (j = 0; j < h; j++)
1273 /* we use memmove here because when psrc and pdst are the same,
1274 * copies are done on the same row, so the dst and src blocks
1276 memmove( pdst, psrc, w * sizeof(*pdst) );
1277 pdst += screen_buffer->width;
1278 psrc += screen_buffer->width;
1282 /* FIXME: this could be enhanced, by signalling scroll */
1283 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1284 memset(&evt.u, 0, sizeof(evt.u));
1285 evt.u.update.top = min(ysrc, ydst);
1286 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1287 console_input_events_append( screen_buffer->input->evt, &evt );
1289 release_object( screen_buffer );
1292 /* allocate a console for the renderer */
1293 DECL_HANDLER(alloc_console)
1295 obj_handle_t in = 0;
1296 obj_handle_t evt = 0;
1297 struct process *process;
1298 struct console_input *console;
1302 if (!(process = get_process_from_id( req->pid ))) return;
1306 if (!(process = current->process->parent))
1308 set_error( STATUS_ACCESS_DENIED );
1311 grab_object( process );
1314 if (process != current->process && process->console)
1315 set_error( STATUS_ACCESS_DENIED );
1316 else if ((console = (struct console_input*)create_console_input( current )))
1318 if ((in = alloc_handle( current->process, console, req->access, req->attributes )))
1320 if ((evt = alloc_handle( current->process, console->evt, SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, 0 )))
1322 if (process != current->process)
1324 process->console = (struct console_input*)grab_object( console );
1325 console->num_proc++;
1327 reply->handle_in = in;
1329 release_object( console );
1332 close_handle( current->process, in );
1334 free_console( process );
1337 release_object( process );
1340 /* free the console of the current process */
1341 DECL_HANDLER(free_console)
1343 free_console( current->process );
1346 /* let the renderer peek the events it's waiting on */
1347 DECL_HANDLER(get_console_renderer_events)
1349 struct console_input_events *evt;
1351 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1352 FILE_READ_PROPERTIES, &console_input_events_ops );
1354 console_input_events_get( evt );
1355 release_object( evt );
1358 /* open a handle to the process console */
1359 DECL_HANDLER(open_console)
1361 struct object *obj = NULL;
1366 if (current->process->console && current->process->console->renderer)
1367 obj = grab_object( (struct object*)current->process->console );
1369 else if (req->from == (obj_handle_t)1)
1371 if (current->process->console && current->process->console->renderer &&
1372 current->process->console->active)
1373 obj = grab_object( (struct object*)current->process->console->active );
1375 else if ((obj = get_handle_obj( current->process, req->from,
1376 FILE_READ_PROPERTIES|FILE_WRITE_PROPERTIES, &console_input_ops )))
1378 struct console_input *console = (struct console_input *)obj;
1379 obj = (console->active) ? grab_object( console->active ) : NULL;
1380 release_object( console );
1383 /* FIXME: req->share is not used (as in screen buffer creation) */
1386 reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
1387 release_object( obj );
1389 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1392 /* set info about a console input */
1393 DECL_HANDLER(set_console_input_info)
1395 set_console_input_info( req, get_req_data(), get_req_data_size() );
1398 /* get info about a console (output only) */
1399 DECL_HANDLER(get_console_input_info)
1401 struct console_input *console;
1403 if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
1406 data_size_t len = strlenW( console->title ) * sizeof(WCHAR);
1407 if (len > get_reply_max_size()) len = get_reply_max_size();
1408 set_reply_data( console->title, len );
1410 reply->history_mode = console->history_mode;
1411 reply->history_size = console->history_size;
1412 reply->history_index = console->history_index;
1413 reply->edition_mode = console->edition_mode;
1414 reply->input_cp = console->input_cp;
1415 reply->output_cp = console->output_cp;
1416 reply->win = console->win;
1418 release_object( console );
1421 /* get a console mode (input or output) */
1422 DECL_HANDLER(get_console_mode)
1424 reply->mode = get_console_mode( req->handle );
1427 /* set a console mode (input or output) */
1428 DECL_HANDLER(set_console_mode)
1430 set_console_mode( req->handle, req->mode );
1433 /* add input records to a console input queue */
1434 DECL_HANDLER(write_console_input)
1436 struct console_input *console;
1439 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1440 FILE_WRITE_PROPERTIES, &console_input_ops )))
1442 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1444 release_object( console );
1447 /* fetch input records from a console input queue */
1448 DECL_HANDLER(read_console_input)
1450 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1451 reply->read = read_console_input( req->handle, count, req->flush );
1454 /* appends a string to console's history */
1455 DECL_HANDLER(append_console_input_history)
1457 struct console_input *console;
1459 if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) return;
1460 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1461 release_object( console );
1464 /* appends a string to console's history */
1465 DECL_HANDLER(get_console_input_history)
1467 struct console_input *console;
1469 if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
1470 reply->total = console_input_get_hist( console, req->index );
1471 release_object( console );
1474 /* creates a screen buffer */
1475 DECL_HANDLER(create_console_output)
1477 struct console_input* console;
1478 struct screen_buffer* screen_buffer;
1480 if (!(console = console_input_get( req->handle_in, FILE_WRITE_PROPERTIES ))) return;
1482 screen_buffer = create_console_output( console );
1485 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1486 * see file.c on how this could be done */
1487 reply->handle_out = alloc_handle( current->process, screen_buffer, req->access, req->attributes );
1488 release_object( screen_buffer );
1490 release_object( console );
1493 /* set info about a console screen buffer */
1494 DECL_HANDLER(set_console_output_info)
1496 struct screen_buffer *screen_buffer;
1498 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1499 FILE_WRITE_PROPERTIES, &screen_buffer_ops)))
1501 set_console_output_info( screen_buffer, req );
1502 release_object( screen_buffer );
1506 /* get info about a console screen buffer */
1507 DECL_HANDLER(get_console_output_info)
1509 struct screen_buffer *screen_buffer;
1511 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1512 FILE_READ_PROPERTIES, &screen_buffer_ops)))
1514 reply->cursor_size = screen_buffer->cursor_size;
1515 reply->cursor_visible = screen_buffer->cursor_visible;
1516 reply->cursor_x = screen_buffer->cursor_x;
1517 reply->cursor_y = screen_buffer->cursor_y;
1518 reply->width = screen_buffer->width;
1519 reply->height = screen_buffer->height;
1520 reply->attr = screen_buffer->attr;
1521 reply->win_left = screen_buffer->win.left;
1522 reply->win_top = screen_buffer->win.top;
1523 reply->win_right = screen_buffer->win.right;
1524 reply->win_bottom = screen_buffer->win.bottom;
1525 reply->max_width = screen_buffer->max_width;
1526 reply->max_height = screen_buffer->max_height;
1527 release_object( screen_buffer );
1531 /* read data (chars & attrs) from a screen buffer */
1532 DECL_HANDLER(read_console_output)
1534 struct screen_buffer *screen_buffer;
1536 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1537 FILE_READ_DATA, &screen_buffer_ops )))
1539 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1540 reply->width = screen_buffer->width;
1541 reply->height = screen_buffer->height;
1542 release_object( screen_buffer );
1546 /* write data (char and/or attrs) to a screen buffer */
1547 DECL_HANDLER(write_console_output)
1549 struct screen_buffer *screen_buffer;
1551 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1552 FILE_WRITE_DATA, &screen_buffer_ops)))
1554 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1555 req->mode, req->x, req->y, req->wrap );
1556 reply->width = screen_buffer->width;
1557 reply->height = screen_buffer->height;
1558 release_object( screen_buffer );
1562 /* fill a screen buffer with constant data (chars and/or attributes) */
1563 DECL_HANDLER(fill_console_output)
1565 struct screen_buffer *screen_buffer;
1567 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1568 FILE_WRITE_DATA, &screen_buffer_ops)))
1570 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1571 req->x, req->y, req->count, req->wrap );
1572 release_object( screen_buffer );
1576 /* move a rect of data in a screen buffer */
1577 DECL_HANDLER(move_console_output)
1579 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1583 /* sends a signal to a console (process, group...) */
1584 DECL_HANDLER(send_console_signal)
1588 group = req->group_id ? req->group_id : current->process->group_id;
1591 set_error( STATUS_INVALID_PARAMETER );
1593 propagate_console_signal( current->process->console, req->signal, group );
1596 /* get console which renderer is 'current' */
1597 static int cgwe_enum( struct process* process, void* user)
1599 if (process->console && process->console->renderer == current)
1601 *(struct console_input**)user = process->console;
1607 DECL_HANDLER(get_console_wait_event)
1609 struct console_input* console = NULL;
1611 if (current->process->console && current->process->console->renderer)
1612 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1613 else enum_processes(cgwe_enum, &console);
1617 reply->handle = alloc_handle( current->process, console->event, EVENT_ALL_ACCESS, 0 );
1618 release_object( console );
1620 else set_error( STATUS_INVALID_PARAMETER );