Commit 86113530 authored by Alexandre Julliard's avatar Alexandre Julliard

Added the data structures and macros that will be needed to support

reentrant server requests.
parent 5e7fa021
......@@ -15,6 +15,7 @@ struct _PDB;
struct __EXCEPTION_FRAME;
struct _SECURITY_ATTRIBUTES;
struct tagSYSLEVEL;
struct server_buffer_info;
/* Thread exception block
......@@ -89,17 +90,16 @@ typedef struct _TEB
DWORD unknown6[5]; /* --n 1e8 Unknown */
/* The following are Wine-specific fields (NT: GDI stuff) */
struct _TEB *next; /* --3 1fc Global thread list */
DWORD cleanup; /* --3 200 Cleanup service handle */
int socket; /* --3 204 Socket for server communication */
void *buffer; /* --3 208 Buffer shared with server */
int buffer_size; /* --3 20c Size of server buffer */
void *debug_info; /* --3 210 Info for debugstr functions */
void *pthread_data; /* --3 214 Data for pthread emulation */
DWORD cleanup; /* --3 1fc Cleanup service handle */
int socket; /* --3 200 Socket for server communication */
void *buffer; /* --3 204 Buffer shared with server */
struct server_buffer_info *buffer_info; /* --3 208 Buffer information */
void *debug_info; /* --3 20c Info for debugstr functions */
void *pthread_data; /* --3 210 Data for pthread emulation */
/* here is plenty space for wine specific fields (don't forget to change pad6!!) */
/* the following are nt specific fields */
DWORD pad6[632]; /* --n 218 */
DWORD pad6[633]; /* --n 214 */
UNICODE_STRING StaticUnicodeString; /* -2- bf8 used by advapi32 */
USHORT StaticUnicodeBuffer[261]; /* -2- c00 used by advapi32 */
DWORD pad7; /* --n e0c */
......
......@@ -105,7 +105,8 @@ static void CALLBACK THREAD_FreeTEB( TEB *teb )
if (teb->socket != -1) close( teb->socket );
if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 );
SELECTOR_FreeBlock( teb->teb_sel, 1 );
if (teb->buffer) munmap( teb->buffer, teb->buffer_size );
if (teb->buffer) munmap( (void *)teb->buffer,
(char *)(teb->buffer_info+1) - (char *)teb->buffer );
if (teb->debug_info) HeapFree( GetProcessHeap(), 0, teb->debug_info );
VirtualFree( teb->stack_base, 0, MEM_RELEASE );
}
......
......@@ -129,11 +129,14 @@ void fatal_perror( const char *err, ... )
}
/* call a request handler */
static inline void call_req_handler( struct thread *thread, enum request req )
static inline void call_req_handler( struct thread *thread )
{
enum request req;
current = thread;
clear_error();
req = ((struct request_header *)current->buffer)->req;
if (debug_level) trace_request( req );
if (req < REQ_NB_REQUESTS)
......@@ -165,7 +168,7 @@ void send_reply( struct thread *thread )
void read_request( struct thread *thread )
{
int ret;
enum request req;
char dummy[1];
#ifdef HAVE_MSGHDR_ACCRIGHTS
msghdr.msg_accrightslen = sizeof(int);
......@@ -178,43 +181,42 @@ void read_request( struct thread *thread )
assert( thread->pass_fd == -1 );
myiovec.iov_base = (void *)&req;
myiovec.iov_len = sizeof(req);
myiovec.iov_base = dummy;
myiovec.iov_len = 1;
ret = recvmsg( thread->obj.fd, &msghdr, 0 );
#ifndef HAVE_MSGHDR_ACCRIGHTS
thread->pass_fd = cmsg.fd;
#endif
if (ret == sizeof(req))
if (ret > 0)
{
call_req_handler( thread, req );
call_req_handler( thread );
thread->pass_fd = -1;
return;
}
if (ret == -1)
{
perror("recvmsg");
thread->exit_code = 1;
kill_thread( thread, 1 );
return;
}
if (!ret) /* closed pipe */
{
kill_thread( thread, 0 );
return;
}
fatal_protocol_error( thread, "partial message received %d/%d\n", ret, sizeof(req) );
perror("recvmsg");
thread->exit_code = 1;
kill_thread( thread, 1 );
}
/* send a message to a client that is ready to receive something */
int write_request( struct thread *thread )
{
int ret;
struct request_header *header = thread->buffer;
header->error = thread->error;
if (thread->pass_fd == -1)
{
ret = write( thread->obj.fd, &thread->error, sizeof(thread->error) );
/* write a single byte; the value is ignored anyway */
ret = write( thread->obj.fd, header, 1 );
}
else /* we have an fd to send */
{
......@@ -227,37 +229,28 @@ int write_request( struct thread *thread )
cmsg.fd = thread->pass_fd;
#endif /* HAVE_MSGHDR_ACCRIGHTS */
myiovec.iov_base = (void *)&thread->error;
myiovec.iov_len = sizeof(thread->error);
myiovec.iov_base = (void *)header;
myiovec.iov_len = 1;
ret = sendmsg( thread->obj.fd, &msghdr, 0 );
close( thread->pass_fd );
thread->pass_fd = -1;
}
if (ret == sizeof(thread->error))
if (ret > 0)
{
set_select_events( &thread->obj, POLLIN );
return 1;
}
if (ret == -1)
if (errno == EWOULDBLOCK) return 0; /* not a fatal error */
if (errno == EPIPE)
{
if (errno == EWOULDBLOCK) return 0; /* not a fatal error */
if (errno == EPIPE)
{
kill_thread( thread, 0 ); /* normal death */
}
else
{
perror("sendmsg");
thread->exit_code = 1;
kill_thread( thread, 1 );
}
kill_thread( thread, 0 ); /* normal death */
}
else
{
perror("sendmsg");
thread->exit_code = 1;
kill_thread( thread, 1 );
fprintf( stderr, "Partial message sent %d/%d\n", ret, sizeof(thread->error) );
}
return -1;
}
......
......@@ -48,17 +48,26 @@ static inline void *get_req_ptr( struct thread *thread )
return thread->buffer;
}
/* get the request vararg data */
inline static void *get_req_data( const void *req )
{
return ((union generic_request *)req + 1);
}
#define REQUEST_END(req) ((char *)(req) + MAX_REQUEST_LENGTH - sizeof(struct server_buffer_info))
/* get the remaining size in the request buffer for object of a given size */
static inline int get_req_size( const void *req, const void *ptr, size_t typesize )
{
return ((char *)req + MAX_REQUEST_LENGTH - (char *)ptr) / typesize;
return (REQUEST_END(req) - (char *)ptr) / typesize;
}
/* get the length of a request string, without going past the end of the request */
static inline size_t get_req_strlen( const void *req, const char *str )
{
const char *p = str;
while (*p && (p < (char *)req + MAX_REQUEST_LENGTH - 1)) p++;
while (*p && (p < REQUEST_END(req) - 1)) p++;
return p - str;
}
......@@ -66,7 +75,7 @@ static inline size_t get_req_strlen( const void *req, const char *str )
static inline size_t get_req_strlenW( const void *req, const WCHAR *str )
{
const WCHAR *p = str;
while (*p && (p < (WCHAR *)req + MAX_REQUEST_LENGTH/sizeof(WCHAR) - 1)) p++;
while (*p && (p < (WCHAR *)REQUEST_END(req) - 1)) p++;
return p - str;
}
......
......@@ -96,6 +96,7 @@ static int alloc_client_buffer( struct thread *thread )
if (ftruncate( fd, MAX_REQUEST_LENGTH ) == -1) goto error;
if ((thread->buffer = mmap( 0, MAX_REQUEST_LENGTH, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0 )) == (void*)-1) goto error;
thread->buffer_info = (struct server_buffer_info *)((char *)thread->buffer + MAX_REQUEST_LENGTH) - 1;
/* build the first request into the buffer and send it */
req = thread->buffer;
req->pid = get_process_id( thread->process );
......
......@@ -59,6 +59,7 @@ struct thread
int affinity; /* affinity mask */
int suspend; /* suspend count */
void *buffer; /* buffer for communication with the client */
struct server_buffer_info *buffer_info; /* buffer information structure */
enum request last_req; /* last request received (for debugging) */
};
......
......@@ -787,7 +787,6 @@ static void dump_alloc_console_reply( const struct alloc_console_request *req )
static void dump_free_console_request( const struct free_console_request *req )
{
fprintf( stderr, " dummy=%d", req->dummy );
}
static void dump_open_console_request( const struct open_console_request *req )
......
......@@ -9,7 +9,6 @@
%formats =
(
"int" => "%d",
"long" => "%ld",
"char" => "%c",
"unsigned char" => "%02x",
"unsigned int" => "%08x",
......@@ -70,8 +69,13 @@ my @server_lines = ();
push @server_lines, "enum request\n{\n";
foreach $req (@requests) { push @server_lines, " REQ_\U$req,\n"; }
push @server_lines, " REQ_NB_REQUESTS\n};\n";
push @server_lines, "\n#define SERVER_PROTOCOL_VERSION $protocol\n";
push @server_lines, " REQ_NB_REQUESTS\n};\n\n";
push @server_lines, "union generic_request\n{\n";
push @server_lines, " struct request_max_size max_size;\n";
push @server_lines, " struct request_header header;\n";
foreach $req (@requests) { push @server_lines, " struct ${req}_request $req;\n"; }
push @server_lines, "};\n\n";
push @server_lines, "#define SERVER_PROTOCOL_VERSION $protocol\n";
REPLACE_IN_FILE( "include/server.h", @server_lines );
......@@ -98,6 +102,7 @@ sub DO_REQUEST
my $name = shift;
my @in_struct = ();
my @out_struct = ();
my $got_header = 0;
while (<SERVER>)
{
my ($dir, $type, $var);
......@@ -105,14 +110,34 @@ sub DO_REQUEST
next if /^{$/;
s!/\*.*\*/!!g;
next if /^\s*$/;
/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/ or die "Unrecognized syntax $_";
$dir = $1;
$type = $2 . ($5 || "");
$var = $4;
die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
if (/REQUEST_HEADER/)
{
die "Duplicated header" if $got_header;
die "Header must be first" if ($#in_struct != -1 || $#out_struct != -1);
$got_header++;
next;
}
if (/^\s*(IN|OUT)\s*VARARG\((\w+),(\w+)\)/)
{
$dir = $1;
$var = $2;
$type = "&" . $3;
}
elsif (/^\s*(IN|OUT)\s*(\w+\**(\s+\w+\**)*)\s+(\w+)(\[[1]\])?;/)
{
$dir = $1;
$type = $2 . ($5 || "");
$var = $4;
die "Unrecognized type $type" unless (defined($formats{$type}) || $5);
}
else
{
die "Unrecognized syntax $_";
}
if ($dir =~ /IN/) { push @in_struct, $type, $var; }
if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
}
die "Missing header" unless $got_header;
push @requests, $name;
&DO_DUMP_FUNC( $name, "request", @in_struct);
if ($#out_struct >= 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment