Return console handles in alloc_console request.

Fixed read_console_input parameters to conform to the reply structure
declaration.
This commit is contained in:
Alexandre Julliard 1999-06-11 18:31:22 +00:00
parent 7990b7c011
commit 039aa42373
8 changed files with 110 additions and 115 deletions

View File

@ -532,7 +532,13 @@ struct create_pipe_reply
/* Allocate a console for the current process */ /* Allocate a console for the current process */
struct alloc_console_request struct alloc_console_request
{ {
int dummy; unsigned int access; /* wanted access rights */
int inherit; /* inherit flag */
};
struct alloc_console_reply
{
int handle_in; /* handle to console input */
int handle_out; /* handle to console output */
}; };
@ -605,7 +611,7 @@ struct get_console_info_reply
int cursor_size; /* size of cursor (percentage filled) */ int cursor_size; /* size of cursor (percentage filled) */
int cursor_visible;/* cursor visibility flag */ int cursor_visible;/* cursor visibility flag */
int pid; /* pid of xterm (hack) */ int pid; /* pid of xterm (hack) */
/* char title[0]; */ /* console title */ char title[0]; /* console title */
}; };

View File

@ -99,7 +99,7 @@ static const struct object_ops screen_buffer_ops =
}; };
int create_console( int fd, struct object *obj[2] ) static int create_console( int fd, struct object *obj[2] )
{ {
struct console_input *console_input; struct console_input *console_input;
struct screen_buffer *screen_buffer; struct screen_buffer *screen_buffer;
@ -156,6 +156,30 @@ int create_console( int fd, struct object *obj[2] )
return 1; return 1;
} }
/* allocate a console for this process */
int alloc_console( struct process *process )
{
struct object *obj[2];
if (process->console_in || process->console_out)
{
SET_ERROR( ERROR_ACCESS_DENIED );
return 0;
}
if (!create_console( -1, obj )) return 0;
process->console_in = obj[0];
process->console_out = obj[1];
return 1;
}
/* free the console for this process */
int free_console( struct process *process )
{
if (process->console_in) release_object( process->console_in );
if (process->console_out) release_object( process->console_out );
process->console_in = process->console_out = NULL;
return 1;
}
static int set_console_fd( int handle, int fd, int pid ) static int set_console_fd( int handle, int fd, int pid )
{ {
struct console_input *input; struct console_input *input;
@ -324,12 +348,14 @@ static int write_console_input( int handle, int count, INPUT_RECORD *records )
static int read_console_input( int handle, int count, int flush ) static int read_console_input( int handle, int count, int flush )
{ {
struct console_input *console; struct console_input *console;
struct read_console_input_reply reply;
if (!(console = (struct console_input *)get_handle_obj( current->process, handle, if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
GENERIC_READ, &console_input_ops ))) GENERIC_READ, &console_input_ops )))
return -1; return -1;
if ((count < 0) || (count > console->recnum)) count = console->recnum; if ((count < 0) || (count > console->recnum)) count = console->recnum;
send_reply( current, -1, 1, console->records, count * sizeof(INPUT_RECORD) ); send_reply( current, -1, 2, &reply, sizeof(reply),
console->records, count * sizeof(INPUT_RECORD) );
if (flush) if (flush)
{ {
int i; int i;
@ -491,8 +517,23 @@ static void screen_buffer_destroy( struct object *obj )
/* allocate a console for the current process */ /* allocate a console for the current process */
DECL_HANDLER(alloc_console) DECL_HANDLER(alloc_console)
{ {
alloc_console( current->process ); struct alloc_console_reply reply = { -1, -1 };
send_reply( current, -1, 0 );
if (!alloc_console( current->process )) goto done;
if ((reply.handle_in = alloc_handle( current->process, current->process->console_in,
req->access, req->inherit )) != -1)
{
if ((reply.handle_out = alloc_handle( current->process, current->process->console_out,
req->access, req->inherit )) != -1)
goto done; /* everything is fine */
close_handle( current->process, reply.handle_in );
reply.handle_in = -1;
}
free_console( current->process );
done:
send_reply( current, -1, 1, &reply, sizeof(reply) );
} }
/* free the console of the current process */ /* free the console of the current process */
@ -505,13 +546,10 @@ DECL_HANDLER(free_console)
/* open a handle to the process console */ /* open a handle to the process console */
DECL_HANDLER(open_console) DECL_HANDLER(open_console)
{ {
struct object *obj;
struct open_console_reply reply = { -1 }; struct open_console_reply reply = { -1 };
if ((obj = get_console( current->process, req->output ))) struct object *obj= req->output ? current->process->console_out : current->process->console_in;
{
reply.handle = alloc_handle( current->process, obj, req->access, req->inherit ); if (obj) reply.handle = alloc_handle( current->process, obj, req->access, req->inherit );
release_object( obj );
}
send_reply( current, -1, 1, &reply, sizeof(reply) ); send_reply( current, -1, 1, &reply, sizeof(reply) );
} }

View File

@ -161,7 +161,8 @@ extern void file_set_error(void);
/* console functions */ /* console functions */
extern int create_console( int fd, struct object *obj[2] ); extern int alloc_console( struct process *process );
extern int free_console( struct process *process );
/* debugger functions */ /* debugger functions */

View File

@ -308,39 +308,6 @@ static void set_process_info( struct process *process,
} }
} }
/* allocate a console for this process */
int alloc_console( struct process *process )
{
struct object *obj[2];
if (process->console_in || process->console_out)
{
SET_ERROR( ERROR_ACCESS_DENIED );
return 0;
}
if (!create_console( -1, obj )) return 0;
process->console_in = obj[0];
process->console_out = obj[1];
return 1;
}
/* free the console for this process */
int free_console( struct process *process )
{
if (process->console_in) release_object( process->console_in );
if (process->console_out) release_object( process->console_out );
process->console_in = process->console_out = NULL;
return 1;
}
/* get the process console */
struct object *get_console( struct process *process, int output )
{
struct object *obj;
if (!(obj = output ? process->console_out : process->console_in))
return NULL;
return grab_object( obj );
}
/* take a snapshot of currently running processes */ /* take a snapshot of currently running processes */
struct process_snapshot *process_snap( int *count ) struct process_snapshot *process_snap( int *count )
{ {

View File

@ -58,9 +58,6 @@ extern void remove_process_thread( struct process *process,
extern void suspend_process( struct process *process ); extern void suspend_process( struct process *process );
extern void resume_process( struct process *process ); extern void resume_process( struct process *process );
extern void kill_process( struct process *process, int exit_code ); extern void kill_process( struct process *process, int exit_code );
extern int alloc_console( struct process *process );
extern int free_console( struct process *process );
extern struct object *get_console( struct process *process, int output );
extern struct process_snapshot *process_snap( int *count ); extern struct process_snapshot *process_snap( int *count );
#endif /* __WINE_SERVER_PROCESS_H */ #endif /* __WINE_SERVER_PROCESS_H */

View File

@ -521,7 +521,15 @@ static int dump_create_pipe_reply( struct create_pipe_reply *req, int len )
static int dump_alloc_console_request( struct alloc_console_request *req, int len ) static int dump_alloc_console_request( struct alloc_console_request *req, int len )
{ {
fprintf( stderr, " dummy=%d", req->dummy ); fprintf( stderr, " access=%08x,", req->access );
fprintf( stderr, " inherit=%d", req->inherit );
return (int)sizeof(*req);
}
static int dump_alloc_console_reply( struct alloc_console_reply *req, int len )
{
fprintf( stderr, " handle_in=%d,", req->handle_in );
fprintf( stderr, " handle_out=%d", req->handle_out );
return (int)sizeof(*req); return (int)sizeof(*req);
} }
@ -591,8 +599,9 @@ static int dump_get_console_info_reply( struct get_console_info_reply *req, int
{ {
fprintf( stderr, " cursor_size=%d,", req->cursor_size ); fprintf( stderr, " cursor_size=%d,", req->cursor_size );
fprintf( stderr, " cursor_visible=%d,", req->cursor_visible ); fprintf( stderr, " cursor_visible=%d,", req->cursor_visible );
fprintf( stderr, " pid=%d", req->pid ); fprintf( stderr, " pid=%d,", req->pid );
return (int)sizeof(*req); fprintf( stderr, " title=" );
return dump_chars( req+1, len - (int)sizeof(*req) ) + sizeof(*req);
} }
static int dump_write_console_input_request( struct write_console_input_request *req, int len ) static int dump_write_console_input_request( struct write_console_input_request *req, int len )
@ -870,7 +879,7 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
(dump_func)0, (dump_func)0,
(dump_func)0, (dump_func)0,
(dump_func)dump_create_pipe_reply, (dump_func)dump_create_pipe_reply,
(dump_func)0, (dump_func)dump_alloc_console_reply,
(dump_func)0, (dump_func)0,
(dump_func)dump_open_console_reply, (dump_func)dump_open_console_reply,
(dump_func)0, (dump_func)0,
@ -988,14 +997,14 @@ void trace_kill( int exit_code )
void trace_reply( struct thread *thread, int type, int pass_fd, void trace_reply( struct thread *thread, int type, int pass_fd,
struct iovec *vec, int veclen ) struct iovec *vec, int veclen )
{ {
static char buffer[MAX_MSG_LENGTH]; static unsigned char buffer[MAX_MSG_LENGTH];
if (!thread) return; if (!thread) return;
fprintf( stderr, "%08x: %s() = %d", fprintf( stderr, "%08x: %s() = %d",
(unsigned int)thread, req_names[thread->last_req], type ); (unsigned int)thread, req_names[thread->last_req], type );
if (veclen) if (veclen)
{ {
char *p = buffer; unsigned char *p = buffer;
int len; int len;
for (; veclen; veclen--, vec++) for (; veclen; veclen--, vec++)
{ {

View File

@ -140,14 +140,14 @@ void trace_kill( int exit_code )
void trace_reply( struct thread *thread, int type, int pass_fd, void trace_reply( struct thread *thread, int type, int pass_fd,
struct iovec *vec, int veclen ) struct iovec *vec, int veclen )
{ {
static char buffer[MAX_MSG_LENGTH]; static unsigned char buffer[MAX_MSG_LENGTH];
if (!thread) return; if (!thread) return;
fprintf( stderr, "%08x: %s() = %d", fprintf( stderr, "%08x: %s() = %d",
(unsigned int)thread, req_names[thread->last_req], type ); (unsigned int)thread, req_names[thread->last_req], type );
if (veclen) if (veclen)
{ {
char *p = buffer; unsigned char *p = buffer;
int len; int len;
for (; veclen; veclen--, vec++) for (; veclen; veclen--, vec++)
{ {

View File

@ -546,65 +546,34 @@ static BOOL CONSOLE_make_complex(HANDLE handle)
*/ */
BOOL WINAPI AllocConsole(VOID) BOOL WINAPI AllocConsole(VOID)
{ {
struct open_console_request req; struct alloc_console_request req;
struct open_console_reply reply; struct alloc_console_reply reply;
HANDLE hIn, hOut, hErr; HANDLE hStderr;
DWORD ret;
TRACE("()\n"); TRACE("()\n");
CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 1, &req, sizeof(req) ); req.access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
ret = CLIENT_WaitReply( NULL, NULL, 0 ); req.inherit = FALSE;
if (ret != ERROR_SUCCESS) { CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 1, &req, sizeof(req) );
/* Hmm, error returned by server when we already have an if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS)
* opened console. however, we might have inherited it(?) return FALSE;
* and our handles are wrong? puzzling -MM 990330
*/
if (ret!=ERROR_ACCESS_DENIED) {
ERR(" failed to allocate console: %ld\n",ret);
return FALSE;
}
}
req.output = 0; if (!DuplicateHandle( GetCurrentProcess(), reply.handle_out, GetCurrentProcess(), &hStderr,
req.access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE; 0, TRUE, DUPLICATE_SAME_ACCESS ))
req.inherit = FALSE; {
CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); CloseHandle( reply.handle_in );
ret =CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); CloseHandle( reply.handle_out );
if (ret != ERROR_SUCCESS) FreeConsole();
{ return FALSE;
/* FIXME: free console */ }
ERR(" open console error %ld\n",ret);
return FALSE;
}
hIn = reply.handle;
req.output = 1; /* NT resets the STD_*_HANDLEs on console alloc */
CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); SetStdHandle( STD_INPUT_HANDLE, reply.handle_in );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS) SetStdHandle( STD_OUTPUT_HANDLE, reply.handle_out );
{ SetStdHandle( STD_ERROR_HANDLE, hStderr );
CloseHandle(hIn);
/* FIXME: free console */
return FALSE;
}
hOut = reply.handle;
if (!DuplicateHandle( GetCurrentProcess(), hOut, SetLastError(ERROR_SUCCESS);
GetCurrentProcess(), &hErr, SetConsoleTitleA("Wine Console");
0, TRUE, DUPLICATE_SAME_ACCESS )) return TRUE;
{
CloseHandle(hIn);
CloseHandle(hOut);
return FALSE;
}
/* NT resets the STD_*_HANDLEs on console alloc */
SetStdHandle(STD_INPUT_HANDLE, hIn);
SetStdHandle(STD_OUTPUT_HANDLE, hOut);
SetStdHandle(STD_ERROR_HANDLE, hErr);
SetLastError(ERROR_SUCCESS);
SetConsoleTitleA("Wine Console");
return TRUE;
} }
@ -824,6 +793,7 @@ BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
int charsread = 0; int charsread = 0;
LPSTR xbuf = (LPSTR)lpBuffer; LPSTR xbuf = (LPSTR)lpBuffer;
struct read_console_input_request req; struct read_console_input_request req;
struct read_console_input_reply reply;
INPUT_RECORD ir; INPUT_RECORD ir;
TRACE("(%d,%p,%ld,%p,%p)\n", TRACE("(%d,%p,%ld,%p,%p)\n",
@ -843,8 +813,9 @@ BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
int len; int len;
CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitReply( &len, NULL, 1, &ir, sizeof(ir) )) if (CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply), &ir, sizeof(ir) ))
return FALSE; return FALSE;
len -= sizeof(reply);
assert( !(len % sizeof(ir)) ); assert( !(len % sizeof(ir)) );
if (!len) break; if (!len) break;
if (!ir.Event.KeyEvent.bKeyDown) if (!ir.Event.KeyEvent.bKeyDown)
@ -903,6 +874,7 @@ BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput,
DWORD nLength, LPDWORD lpNumberOfEventsRead) DWORD nLength, LPDWORD lpNumberOfEventsRead)
{ {
struct read_console_input_request req; struct read_console_input_request req;
struct read_console_input_reply reply;
int len; int len;
req.handle = hConsoleInput; req.handle = hConsoleInput;
@ -913,8 +885,10 @@ BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput,
for (;;) for (;;)
{ {
CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitReply( &len, NULL, 1, lpBuffer, nLength * sizeof(*lpBuffer) )) if (CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply),
lpBuffer, nLength * sizeof(*lpBuffer) ))
return FALSE; return FALSE;
len -= sizeof(reply);
assert( !(len % sizeof(INPUT_RECORD)) ); assert( !(len % sizeof(INPUT_RECORD)) );
if (len) break; if (len) break;
CONSOLE_get_input(hConsoleInput,TRUE); CONSOLE_get_input(hConsoleInput,TRUE);
@ -963,6 +937,7 @@ BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer,
DWORD count, LPDWORD read ) DWORD count, LPDWORD read )
{ {
struct read_console_input_request req; struct read_console_input_request req;
struct read_console_input_reply reply;
int len; int len;
CONSOLE_get_input(handle,FALSE); CONSOLE_get_input(handle,FALSE);
@ -971,8 +946,10 @@ BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer,
req.flush = 0; req.flush = 0;
CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitReply( &len, NULL, 1, buffer, count * sizeof(*buffer) )) if (CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply),
buffer, count * sizeof(*buffer) ))
return FALSE; return FALSE;
len -= sizeof(reply);
assert( !(len % sizeof(INPUT_RECORD)) ); assert( !(len % sizeof(INPUT_RECORD)) );
if (read) *read = len / sizeof(INPUT_RECORD); if (read) *read = len / sizeof(INPUT_RECORD);
return TRUE; return TRUE;