Return console handles in alloc_console request.

Fixed read_console_input parameters to conform to the reply structure
declaration.
oldstable
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 */
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_visible;/* cursor visibility flag */
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 screen_buffer *screen_buffer;
@ -156,6 +156,30 @@ int create_console( int fd, struct object *obj[2] )
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 )
{
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 )
{
struct console_input *console;
struct read_console_input_reply reply;
if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
GENERIC_READ, &console_input_ops )))
return -1;
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)
{
int i;
@ -491,8 +517,23 @@ static void screen_buffer_destroy( struct object *obj )
/* allocate a console for the current process */
DECL_HANDLER(alloc_console)
{
alloc_console( current->process );
send_reply( current, -1, 0 );
struct alloc_console_reply reply = { -1, -1 };
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 */
@ -505,13 +546,10 @@ DECL_HANDLER(free_console)
/* open a handle to the process console */
DECL_HANDLER(open_console)
{
struct object *obj;
struct open_console_reply reply = { -1 };
if ((obj = get_console( current->process, req->output )))
{
reply.handle = alloc_handle( current->process, obj, req->access, req->inherit );
release_object( obj );
}
struct object *obj= req->output ? current->process->console_out : current->process->console_in;
if (obj) reply.handle = alloc_handle( current->process, obj, req->access, req->inherit );
send_reply( current, -1, 1, &reply, sizeof(reply) );
}

View File

@ -161,7 +161,8 @@ extern void file_set_error(void);
/* 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 */

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 */
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 resume_process( struct process *process );
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 );
#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 )
{
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);
}
@ -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_visible=%d,", req->cursor_visible );
fprintf( stderr, " pid=%d", req->pid );
return (int)sizeof(*req);
fprintf( stderr, " pid=%d,", req->pid );
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 )
@ -870,7 +879,7 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
(dump_func)0,
(dump_func)0,
(dump_func)dump_create_pipe_reply,
(dump_func)0,
(dump_func)dump_alloc_console_reply,
(dump_func)0,
(dump_func)dump_open_console_reply,
(dump_func)0,
@ -988,14 +997,14 @@ void trace_kill( int exit_code )
void trace_reply( struct thread *thread, int type, int pass_fd,
struct iovec *vec, int veclen )
{
static char buffer[MAX_MSG_LENGTH];
static unsigned char buffer[MAX_MSG_LENGTH];
if (!thread) return;
fprintf( stderr, "%08x: %s() = %d",
(unsigned int)thread, req_names[thread->last_req], type );
if (veclen)
{
char *p = buffer;
unsigned char *p = buffer;
int len;
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,
struct iovec *vec, int veclen )
{
static char buffer[MAX_MSG_LENGTH];
static unsigned char buffer[MAX_MSG_LENGTH];
if (!thread) return;
fprintf( stderr, "%08x: %s() = %d",
(unsigned int)thread, req_names[thread->last_req], type );
if (veclen)
{
char *p = buffer;
unsigned char *p = buffer;
int len;
for (; veclen; veclen--, vec++)
{

View File

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