Commit ebe29ef3 authored by Alexandre Julliard's avatar Alexandre Julliard

Further server optimizations:

- merged request and reply structures - build requests directly into the buffer to avoid a copy
parent f26c89e8
......@@ -19,20 +19,17 @@
/****************************************************************************
* FindFirstChangeNotification32A (KERNEL32.248)
* FindFirstChangeNotificationA (KERNEL32.248)
*/
HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName,
BOOL bWatchSubtree,
DWORD dwNotifyFilter )
HANDLE WINAPI FindFirstChangeNotificationA( LPCSTR lpPathName, BOOL bWatchSubtree,
DWORD dwNotifyFilter )
{
struct create_change_notification_request req;
struct create_change_notification_reply reply;
struct create_change_notification_request *req = get_req_buffer();
req.subtree = bWatchSubtree;
req.filter = dwNotifyFilter;
CLIENT_SendRequest( REQ_CREATE_CHANGE_NOTIFICATION, -1, 1, &req, sizeof(req) );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
return reply.handle;
req->subtree = bWatchSubtree;
req->filter = dwNotifyFilter;
server_call( REQ_CREATE_CHANGE_NOTIFICATION );
return req->handle;
}
/****************************************************************************
......
......@@ -613,17 +613,14 @@ const DOS_DEVICE *DOSFS_GetDevice( const char *name )
*/
const DOS_DEVICE *DOSFS_GetDeviceByHandle( HFILE hFile )
{
struct get_file_info_request req;
struct get_file_info_reply reply;
struct get_file_info_request *req = get_req_buffer();
req.handle = hFile;
CLIENT_SendRequest( REQ_GET_FILE_INFO, -1, 1, &req, sizeof(req) );
if (!CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) &&
(reply.type == FILE_TYPE_UNKNOWN))
req->handle = hFile;
if (!server_call( REQ_GET_FILE_INFO ) && (req->type == FILE_TYPE_UNKNOWN))
{
if ((reply.attr >= 0) &&
(reply.attr < sizeof(DOSFS_Devices)/sizeof(DOSFS_Devices[0])))
return &DOSFS_Devices[reply.attr];
if ((req->attr >= 0) &&
(req->attr < sizeof(DOSFS_Devices)/sizeof(DOSFS_Devices[0])))
return &DOSFS_Devices[req->attr];
}
return NULL;
}
......
......@@ -39,8 +39,8 @@ typedef struct _TEB
WORD teb_sel; /* 3c Selector to TEB */
WORD emu_sel; /* 3e 80387 emulator selector */
void *buffer; /* 40 Buffer shared with server */
void *buffer_args; /* 44 Current position of arguments in server buffer */
int buffer_size; /* 48 Size of server buffer */
int buffer_size; /* 44 Size of server buffer */
void (*startup)(void); /* 48 Thread startup routine */
int thread_errno; /* 4c Per-thread errno (was: ring0_thread) */
int thread_h_errno; /* 50 Per-thread h_errno (was: ptr to tdbx structure) */
void *stack_base; /* 54 Base of the stack */
......@@ -69,8 +69,6 @@ typedef struct _TEB
SYSLEVEL *sys_mutex[4]; /* 1d8 Syslevel mutex pointers */
DWORD unknown6[2]; /* 1e8 Unknown */
/* The following are Wine-specific fields */
unsigned int seq; /* Server sequence number */
void (*startup)(void); /* Thread startup routine */
struct _TEB *next; /* Global thread list */
DWORD cleanup; /* Cleanup service handle */
} TEB;
......
......@@ -344,8 +344,8 @@ BOOL MZ_InitTask( LPDOSTASK lpDosTask )
pid_t child;
char *fname,*farg,arg[16],fproc[64],path[256],*fpath;
SECURITY_ATTRIBUTES attr={sizeof(attr),NULL,TRUE};
struct get_read_fd_request r_req;
struct get_write_fd_request w_req;
struct get_read_fd_request *r_req = get_req_buffer();
struct get_write_fd_request *w_req = get_req_buffer();
if (!lpDosTask) return FALSE;
/* create pipes */
......@@ -357,12 +357,10 @@ BOOL MZ_InitTask( LPDOSTASK lpDosTask )
CloseHandle(lpDosTask->hXPipe);
return FALSE;
}
r_req.handle = lpDosTask->hReadPipe;
CLIENT_SendRequest( REQ_GET_READ_FD, -1, 1, &r_req, sizeof(r_req) );
CLIENT_WaitReply( NULL, &(lpDosTask->read_pipe), 0 );
w_req.handle = lpDosTask->hXPipe;
CLIENT_SendRequest( REQ_GET_WRITE_FD, -1, 1, &w_req, sizeof(w_req) );
CLIENT_WaitReply( NULL, &x_fd, 0 );
r_req->handle = lpDosTask->hReadPipe;
server_call_fd( REQ_GET_READ_FD, -1, &lpDosTask->read_pipe );
w_req->handle = lpDosTask->hXPipe;
server_call_fd( REQ_GET_WRITE_FD, -1, &x_fd );
TRACE("win32 pipe: read=%d, write=%d, unix pipe: read=%d, write=%d\n",
lpDosTask->hReadPipe,lpDosTask->hXPipe,lpDosTask->read_pipe,x_fd);
......
......@@ -1051,8 +1051,7 @@ HANDLE WINAPI CreateFileMappingA(
DWORD size_low, /* [in] Low-order 32 bits of object size */
LPCSTR name /* [in] Name of file-mapping object */ )
{
struct create_mapping_request req;
struct create_mapping_reply reply;
struct create_mapping_request *req = get_req_buffer();
BYTE vprot;
/* Check parameters */
......@@ -1074,19 +1073,16 @@ HANDLE WINAPI CreateFileMappingA(
/* Create the server object */
if (!name) name = "";
req.handle = hFile;
req.size_high = size_high;
req.size_low = size_low;
req.protect = vprot;
req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
CLIENT_SendRequest( REQ_CREATE_MAPPING, -1, 2,
&req, sizeof(req),
name, strlen(name) + 1 );
req->file_handle = hFile;
req->size_high = size_high;
req->size_low = size_low;
req->protect = vprot;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
SetLastError(0);
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0;
return reply.handle;
server_call( REQ_CREATE_MAPPING );
if (req->handle == -1) return 0;
return req->handle;
}
......@@ -1119,16 +1115,14 @@ HANDLE WINAPI OpenFileMappingA(
BOOL inherit, /* [in] Inherit flag */
LPCSTR name ) /* [in] Name of file-mapping object */
{
struct open_mapping_request req;
struct open_mapping_reply reply;
int len = name ? strlen(name) + 1 : 0;
req.access = access;
req.inherit = inherit;
CLIENT_SendRequest( REQ_OPEN_MAPPING, -1, 2, &req, sizeof(req), name, len );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */
return reply.handle;
struct open_mapping_request *req = get_req_buffer();
req->access = access;
req->inherit = inherit;
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
server_call( REQ_OPEN_MAPPING );
if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
return req->handle;
}
......@@ -1185,8 +1179,8 @@ LPVOID WINAPI MapViewOfFileEx(
UINT ptr = (UINT)-1, size = 0;
int flags = MAP_PRIVATE;
int unix_handle = -1;
struct get_mapping_info_request req;
struct get_mapping_info_reply info;
int prot;
struct get_mapping_info_request *req = get_req_buffer();
/* Check parameters */
......@@ -1197,29 +1191,28 @@ LPVOID WINAPI MapViewOfFileEx(
return NULL;
}
req.handle = handle;
CLIENT_SendRequest( REQ_GET_MAPPING_INFO, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &info, sizeof(info), &unix_handle ))
goto error;
req->handle = handle;
if (server_call_fd( REQ_GET_MAPPING_INFO, -1, &unix_handle )) goto error;
if (info.size_high || offset_high)
if (req->size_high || offset_high)
ERR("Offsets larger than 4Gb not supported\n");
if ((offset_low >= info.size_low) ||
(count > info.size_low - offset_low))
if ((offset_low >= req->size_low) ||
(count > req->size_low - offset_low))
{
SetLastError( ERROR_INVALID_PARAMETER );
goto error;
}
if (count) size = ROUND_SIZE( offset_low, count );
else size = info.size_low - offset_low;
else size = req->size_low - offset_low;
prot = req->protect;
switch(access)
{
case FILE_MAP_ALL_ACCESS:
case FILE_MAP_WRITE:
case FILE_MAP_WRITE | FILE_MAP_READ:
if (!(info.protect & VPROT_WRITE))
if (!(prot & VPROT_WRITE))
{
SetLastError( ERROR_INVALID_PARAMETER );
goto error;
......@@ -1229,7 +1222,7 @@ LPVOID WINAPI MapViewOfFileEx(
case FILE_MAP_READ:
case FILE_MAP_COPY:
case FILE_MAP_COPY | FILE_MAP_READ:
if (info.protect & VPROT_READ) break;
if (prot & VPROT_READ) break;
/* fall through */
default:
SetLastError( ERROR_INVALID_PARAMETER );
......@@ -1238,13 +1231,10 @@ LPVOID WINAPI MapViewOfFileEx(
/* Map the file */
TRACE("handle=%x size=%x offset=%lx\n",
handle, size, offset_low );
TRACE("handle=%x size=%x offset=%lx\n", handle, size, offset_low );
ptr = (UINT)FILE_dommap( unix_handle,
addr, 0, size, 0, offset_low,
VIRTUAL_GetUnixProt( info.protect ),
flags );
ptr = (UINT)FILE_dommap( unix_handle, addr, 0, size, 0, offset_low,
VIRTUAL_GetUnixProt( prot ), flags );
if (ptr == (UINT)-1) {
/* KB: Q125713, 25-SEP-1995, "Common File Mapping Problems and
* Platform Differences":
......@@ -1259,8 +1249,7 @@ LPVOID WINAPI MapViewOfFileEx(
goto error;
}
if (!(view = VIRTUAL_CreateView( ptr, size, offset_low, 0,
info.protect, handle )))
if (!(view = VIRTUAL_CreateView( ptr, size, offset_low, 0, prot, handle )))
{
SetLastError( ERROR_OUTOFMEMORY );
goto error;
......
......@@ -1476,31 +1476,30 @@ BOOL WINAPI BuildCommDCBW(LPCWSTR devid,LPDCB lpdcb)
}
/*****************************************************************************
* COMM_Handle2fd
* returns a file descriptor for reading from or writing to
* mode is GENERIC_READ or GENERIC_WRITE. Make sure to close
* the handle afterwards!
* COMM_GetReadFd
* Returns a file descriptor for reading.
* Make sure to close the handle afterwards!
*/
int COMM_Handle2fd(HANDLE handle, int mode) {
struct get_read_fd_request r_req;
struct get_write_fd_request w_req;
static int COMM_GetReadFd( HANDLE handle)
{
int fd;
struct get_read_fd_request *req = get_req_buffer();
req->handle = handle;
server_call_fd( REQ_GET_READ_FD, -1, &fd );
return fd;
}
w_req.handle = r_req.handle = handle;
switch(mode) {
case GENERIC_WRITE:
CLIENT_SendRequest( REQ_GET_WRITE_FD, -1, 1, &w_req, sizeof(w_req) );
break;
case GENERIC_READ:
CLIENT_SendRequest( REQ_GET_READ_FD, -1, 1, &r_req, sizeof(r_req) );
break;
default:
ERR(comm,"COMM_Handle2fd: Don't know what type of fd is required.\n");
return -1;
}
CLIENT_WaitReply( NULL, &fd, 0 );
/*****************************************************************************
* COMM_GetWriteFd
* Returns a file descriptor for writing.
* Make sure to close the handle afterwards!
*/
static int COMM_GetWriteFd( HANDLE handle)
{
int fd;
struct get_write_fd_request *req = get_req_buffer();
req->handle = handle;
server_call_fd( REQ_GET_WRITE_FD, -1, &fd );
return fd;
}
......@@ -1534,7 +1533,7 @@ BOOL WINAPI EscapeCommFunction(HANDLE handle,UINT nFunction)
struct termios port;
TRACE(comm,"handle %d, function=%d\n", handle, nFunction);
fd = COMM_Handle2fd(handle, GENERIC_WRITE);
fd = COMM_GetWriteFd(handle);
if(fd<0)
return FALSE;
......@@ -1611,7 +1610,7 @@ BOOL WINAPI PurgeComm( HANDLE handle, DWORD flags)
TRACE(comm,"handle %d, flags %lx\n", handle, flags);
fd = COMM_Handle2fd(handle, GENERIC_WRITE);
fd = COMM_GetWriteFd(handle);
if(fd<0)
return FALSE;
......@@ -1648,7 +1647,7 @@ BOOL WINAPI ClearCommError(INT handle,LPDWORD errors,LPCOMSTAT lpStat)
{
int fd;
fd=COMM_Handle2fd(handle,GENERIC_READ);
fd=COMM_GetReadFd(handle);
if(0>fd)
{
return FALSE;
......@@ -1693,7 +1692,7 @@ BOOL WINAPI SetupComm( HANDLE handle, DWORD insize, DWORD outsize)
int fd;
FIXME(comm, "insize %ld outsize %ld unimplemented stub\n", insize, outsize);
fd=COMM_Handle2fd(handle,GENERIC_WRITE);
fd=COMM_GetWriteFd(handle);
if(0>fd)
{
return FALSE;
......@@ -1710,7 +1709,7 @@ BOOL WINAPI GetCommMask(HANDLE handle,LPDWORD evtmask)
int fd;
TRACE(comm, "handle %d, mask %p\n", handle, evtmask);
if(0>(fd=COMM_Handle2fd(handle,GENERIC_READ)))
if(0>(fd=COMM_GetReadFd(handle)))
{
return FALSE;
}
......@@ -1727,7 +1726,7 @@ BOOL WINAPI SetCommMask(INT handle,DWORD evtmask)
int fd;
TRACE(comm, "handle %d, mask %lx\n", handle, evtmask);
if(0>(fd=COMM_Handle2fd(handle,GENERIC_WRITE))) {
if(0>(fd=COMM_GetWriteFd(handle))) {
return FALSE;
}
close(fd);
......@@ -1742,19 +1741,14 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
{
struct termios port;
int fd;
struct get_write_fd_request req;
TRACE(comm,"handle %d, ptr %p\n", handle, lpdcb);
req.handle = handle;
CLIENT_SendRequest( REQ_GET_WRITE_FD, -1, 1, &req, sizeof(req) );
CLIENT_WaitReply( NULL, &fd, 0 );
if(fd<0)
return FALSE;
if ((fd = COMM_GetWriteFd(handle)) < 0) return FALSE;
if (tcgetattr(fd,&port) == -1) {
commerror = WinError();
commerror = WinError();
close( fd );
return FALSE;
}
......@@ -1821,6 +1815,7 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
break;
default:
commerror = IE_BAUDRATE;
close( fd );
return FALSE;
}
#elif !defined(__EMX__)
......@@ -1863,6 +1858,7 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
break;
default:
commerror = IE_BAUDRATE;
close( fd );
return FALSE;
}
port.c_ispeed = port.c_ospeed;
......@@ -1884,6 +1880,7 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
break;
default:
commerror = IE_BYTESIZE;
close( fd );
return FALSE;
}
......@@ -1904,6 +1901,7 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
break;
default:
commerror = IE_BYTESIZE;
close( fd );
return FALSE;
}
......@@ -1918,6 +1916,7 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
break;
default:
commerror = IE_BYTESIZE;
close( fd );
return FALSE;
}
#ifdef CRTSCTS
......@@ -1941,9 +1940,11 @@ BOOL WINAPI SetCommState(INT handle,LPDCB lpdcb)
if (tcsetattr(fd,TCSADRAIN,&port)==-1) {
commerror = WinError();
close( fd );
return FALSE;
} else {
commerror = 0;
close( fd );
return TRUE;
}
}
......@@ -1956,21 +1957,18 @@ BOOL WINAPI GetCommState(INT handle, LPDCB lpdcb)
{
struct termios port;
int fd;
struct get_read_fd_request req;
TRACE(comm,"handle %d, ptr %p\n", handle, lpdcb);
req.handle = handle;
CLIENT_SendRequest( REQ_GET_READ_FD, -1, 1, &req, sizeof(req) );
CLIENT_WaitReply( NULL, &fd, 0 );
if(fd<0)
return FALSE;
if ((fd = COMM_GetReadFd(handle)) < 0) return FALSE;
if (tcgetattr(fd, &port) == -1) {
TRACE(comm,"tcgetattr(%d, ...) returned -1",fd);
commerror = WinError();
close( fd );
return FALSE;
}
close( fd );
#ifndef __EMX__
#ifdef CBAUD
switch (port.c_cflag & CBAUD) {
......
......@@ -116,8 +116,7 @@ FARPROC16 tmp;
*/
HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
{
struct create_snapshot_request req;
struct create_snapshot_reply reply;
struct create_snapshot_request *req = get_req_buffer();
TRACE( toolhelp, "%lx,%lx\n", flags, process );
if (flags & (TH32CS_SNAPHEAPLIST|TH32CS_SNAPMODULE|TH32CS_SNAPTHREAD))
......@@ -127,13 +126,12 @@ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
return INVALID_HANDLE_VALUE;
}
/* Now do the snapshot */
req.flags = flags & ~TH32CS_INHERIT;
req.inherit = (flags & TH32CS_INHERIT) != 0;
CLIENT_SendRequest( REQ_CREATE_SNAPSHOT, -1, 1, &req, sizeof(req) );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
return reply.handle;
req->flags = flags & ~TH32CS_INHERIT;
req->inherit = (flags & TH32CS_INHERIT) != 0;
server_call( REQ_CREATE_SNAPSHOT );
return req->handle;
}
......@@ -144,8 +142,7 @@ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
*/
static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY lppe, BOOL first )
{
struct next_process_request req;
struct next_process_reply reply;
struct next_process_request *req = get_req_buffer();
if (lppe->dwSize < sizeof (PROCESSENTRY))
{
......@@ -153,17 +150,16 @@ static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY lppe, BOOL fir
ERR (toolhelp, "Result buffer too small\n");
return FALSE;
}
req.handle = handle;
req.reset = first;
CLIENT_SendRequest( REQ_NEXT_PROCESS, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
req->handle = handle;
req->reset = first;
if (server_call( REQ_NEXT_PROCESS )) return FALSE;
lppe->cntUsage = 1;
lppe->th32ProcessID = (DWORD)reply.pid;
lppe->th32ProcessID = (DWORD)req->pid;
lppe->th32DefaultHeapID = 0; /* FIXME */
lppe->th32ModuleID = 0; /* FIXME */
lppe->cntThreads = reply.threads;
lppe->cntThreads = req->threads;
lppe->th32ParentProcessID = 0; /* FIXME */
lppe->pcPriClassBase = reply.priority;
lppe->pcPriClassBase = req->priority;
lppe->dwFlags = -1; /* FIXME */
lppe->szExeFile[0] = 0; /* FIXME */
return TRUE;
......
......@@ -18,18 +18,16 @@
HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
BOOL initial_state, LPCSTR name )
{
struct create_event_request req;
struct create_event_reply reply;
if (!name) name = "";
req.manual_reset = manual_reset;
req.initial_state = initial_state;
req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
CLIENT_SendRequest( REQ_CREATE_EVENT, -1, 2, &req, sizeof(req), name, strlen(name)+1 );
struct create_event_request *req = get_req_buffer();
req->manual_reset = manual_reset;
req->initial_state = initial_state;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
SetLastError(0);
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0;
return reply.handle;
server_call( REQ_CREATE_EVENT );
if (req->handle == -1) return 0;
return req->handle;
}
......@@ -59,16 +57,14 @@ HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
*/
HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
{
struct open_event_request req;
struct open_event_reply reply;
int len = name ? strlen(name) + 1 : 0;
req.access = access;
req.inherit = inherit;
CLIENT_SendRequest( REQ_OPEN_EVENT, -1, 2, &req, sizeof(req), name, len );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */
return (HANDLE)reply.handle;
struct open_event_request *req = get_req_buffer();
req->access = access;
req->inherit = inherit;
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
server_call( REQ_OPEN_EVENT );
if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
return req->handle;
}
......@@ -91,12 +87,10 @@ HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
*/
static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
{
struct event_op_request req;
req.handle = handle;
req.op = op;
CLIENT_SendRequest( REQ_EVENT_OP, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct event_op_request *req = get_req_buffer();
req->handle = handle;
req->op = op;
return !server_call( REQ_EVENT_OP );
}
......
......@@ -18,11 +18,9 @@ DEFAULT_DEBUG_CHANNEL(win32)
*/
BOOL WINAPI CloseHandle( HANDLE handle )
{
struct close_handle_request req;
req.handle = handle;
CLIENT_SendRequest( REQ_CLOSE_HANDLE, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct close_handle_request *req = get_req_buffer();
req->handle = handle;
return !server_call( REQ_CLOSE_HANDLE );
}
......@@ -31,13 +29,10 @@ BOOL WINAPI CloseHandle( HANDLE handle )
*/
BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
{
struct get_handle_info_request req;
struct get_handle_info_reply reply;
req.handle = handle;
CLIENT_SendRequest( REQ_GET_HANDLE_INFO, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
if (flags) *flags = reply.flags;
struct get_handle_info_request *req = get_req_buffer();
req->handle = handle;
if (server_call( REQ_GET_HANDLE_INFO )) return FALSE;
if (flags) *flags = req->flags;
return TRUE;
}
......@@ -47,13 +42,11 @@ BOOL WINAPI GetHandleInformation( HANDLE handle, LPDWORD flags )
*/
BOOL WINAPI SetHandleInformation( HANDLE handle, DWORD mask, DWORD flags )
{
struct set_handle_info_request req;
req.handle = handle;
req.flags = flags;
req.mask = mask;
CLIENT_SendRequest( REQ_SET_HANDLE_INFO, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct set_handle_info_request *req = get_req_buffer();
req->handle = handle;
req->flags = flags;
req->mask = mask;
return !server_call( REQ_SET_HANDLE_INFO );
}
......@@ -64,19 +57,17 @@ BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
HANDLE dest_process, HANDLE *dest,
DWORD access, BOOL inherit, DWORD options )
{
struct dup_handle_request req;
struct dup_handle_reply reply;
req.src_process = source_process;
req.src_handle = source;
req.dst_process = dest_process;
req.access = access;
req.inherit = inherit;
req.options = options;
CLIENT_SendRequest( REQ_DUP_HANDLE, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
if (dest) *dest = reply.handle;
struct dup_handle_request *req = get_req_buffer();
req->src_process = source_process;
req->src_handle = source;
req->dst_process = dest_process;
req->access = access;
req->inherit = inherit;
req->options = options;
if (server_call( REQ_DUP_HANDLE )) return FALSE;
if (dest) *dest = req->handle;
return TRUE;
}
......@@ -86,19 +77,17 @@ BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
*/
HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
{
struct dup_handle_request req;
struct dup_handle_reply reply;
req.src_process = GetCurrentProcess();
req.src_handle = hSrc;
req.dst_process = -1;
req.access = 0;
req.inherit = FALSE;
req.options = DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS;
CLIENT_SendRequest( REQ_DUP_HANDLE, -1, 1, &req, sizeof(req) );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
return reply.handle;
struct dup_handle_request *req = get_req_buffer();
req->src_process = GetCurrentProcess();
req->src_handle = hSrc;
req->dst_process = -1;
req->access = 0;
req->inherit = FALSE;
req->options = DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS;
server_call( REQ_DUP_HANDLE );
return req->handle;
}
/***********************************************************************
......
......@@ -16,17 +16,15 @@
*/
HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
{
struct create_mutex_request req;
struct create_mutex_reply reply;
struct create_mutex_request *req = get_req_buffer();
if (!name) name = "";
req.owned = owner;
req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
CLIENT_SendRequest( REQ_CREATE_MUTEX, -1, 2, &req, sizeof(req), name, strlen(name)+1 );
req->owned = owner;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
SetLastError(0);
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0;
return reply.handle;
server_call( REQ_CREATE_MUTEX );
if (req->handle == -1) return 0;
return req->handle;
}
......@@ -48,16 +46,14 @@ HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner,
*/
HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
{
struct open_mutex_request req;
struct open_mutex_reply reply;
int len = name ? strlen(name) + 1 : 0;
struct open_mutex_request *req = get_req_buffer();
req.access = access;
req.inherit = inherit;
CLIENT_SendRequest( REQ_OPEN_MUTEX, -1, 2, &req, sizeof(req), name, len );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */
return reply.handle;
req->access = access;
req->inherit = inherit;
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
server_call( REQ_OPEN_MUTEX );
if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
return req->handle;
}
......@@ -78,9 +74,7 @@ HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
*/
BOOL WINAPI ReleaseMutex( HANDLE handle )
{
struct release_mutex_request req;
req.handle = handle;
CLIENT_SendRequest( REQ_RELEASE_MUTEX, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct release_mutex_request *req = get_req_buffer();
req->handle = handle;
return !server_call( REQ_RELEASE_MUTEX );
}
......@@ -16,15 +16,11 @@
BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
LPSECURITY_ATTRIBUTES sa, DWORD size )
{
struct create_pipe_request req;
struct create_pipe_reply reply;
int len;
struct create_pipe_request *req = get_req_buffer();
req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
CLIENT_SendRequest( REQ_CREATE_PIPE, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) ) != ERROR_SUCCESS)
return FALSE;
*hReadPipe = reply.handle_read;
*hWritePipe = reply.handle_write;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
if (server_call( REQ_CREATE_PIPE )) return FALSE;
*hReadPipe = req->handle_read;
*hWritePipe = req->handle_write;
return TRUE;
}
......@@ -16,8 +16,7 @@
*/
HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
{
struct create_semaphore_request req;
struct create_semaphore_reply reply;
struct create_semaphore_request *req = get_req_buffer();
/* Check parameters */
......@@ -27,16 +26,14 @@ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max,
return 0;
}
if (!name) name = "";
req.initial = (unsigned int)initial;
req.max = (unsigned int)max;
req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
CLIENT_SendRequest( REQ_CREATE_SEMAPHORE, -1, 2, &req, sizeof(req), name, strlen(name)+1 );
req->initial = (unsigned int)initial;
req->max = (unsigned int)max;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
SetLastError(0);
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0;
return reply.handle;
server_call( REQ_CREATE_SEMAPHORE );
if (req->handle == -1) return 0;
return req->handle;
}
......@@ -58,16 +55,14 @@ HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
*/
HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
{
struct open_semaphore_request req;
struct open_semaphore_reply reply;
int len = name ? strlen(name) + 1 : 0;
req.access = access;
req.inherit = inherit;
CLIENT_SendRequest( REQ_OPEN_SEMAPHORE, -1, 2, &req, sizeof(req), name, len );
CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
if (reply.handle == -1) return 0; /* must return 0 on failure, not -1 */
return reply.handle;
struct open_semaphore_request *req = get_req_buffer();
req->access = access;
req->inherit = inherit;
lstrcpynA( req->name, name ? name : "", server_remaining(req->name) );
server_call( REQ_OPEN_SEMAPHORE );
if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
return req->handle;
}
......@@ -88,18 +83,16 @@ HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
*/
BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
{
struct release_semaphore_request req;
struct release_semaphore_reply reply;
struct release_semaphore_request *req = get_req_buffer();
if (count < 0)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
req.handle = handle;
req.count = (unsigned int)count;
CLIENT_SendRequest( REQ_RELEASE_SEMAPHORE, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
if (previous) *previous = reply.prev_count;
req->handle = handle;
req->count = (unsigned int)count;
if (server_call( REQ_RELEASE_SEMAPHORE )) return FALSE;
if (previous) *previous = req->prev_count;
return TRUE;
}
......@@ -17,6 +17,27 @@
#include "x11drv.h"
#include "server.h"
/***********************************************************************
* call_apcs
*
* Call outstanding APCs.
*/
static void call_apcs(void)
{
#define MAX_APCS 16
int i;
void *buffer[MAX_APCS * 2];
struct get_apcs_request *req = get_req_buffer();
if (server_call( REQ_GET_APCS ) || !req->count) return;
assert( req->count <= MAX_APCS );
memcpy( buffer, req->apcs, req->count * 2 * sizeof(req->apcs[0]) );
for (i = 0; i < req->count * 2; i += 2)
{
PAPCFUNC func = (PAPCFUNC)req->apcs[i];
if (func) func( (ULONG_PTR)req->apcs[i+1] );
}
}
/***********************************************************************
* Sleep (KERNEL32.679)
......@@ -73,11 +94,8 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
BOOL wait_all, DWORD timeout,
BOOL alertable )
{
struct select_request req;
struct select_reply reply;
int server_handle[MAXIMUM_WAIT_OBJECTS];
void *apc[32];
int i, len;
struct select_request *req = get_req_buffer();
int i, ret;
if (count > MAXIMUM_WAIT_OBJECTS)
{
......@@ -99,32 +117,18 @@ DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
EVENT_Synchronize( FALSE );
}
for (i = 0; i < count; i++) server_handle[i] = handles[i];
req.count = count;
req.flags = 0;
req.timeout = timeout;
req->count = count;
req->flags = 0;
req->timeout = timeout;
for (i = 0; i < count; i++) req->handles[i] = handles[i];
if (wait_all) req.flags |= SELECT_ALL;
if (alertable) req.flags |= SELECT_ALERTABLE;
if (timeout != INFINITE) req.flags |= SELECT_TIMEOUT;
if (wait_all) req->flags |= SELECT_ALL;
if (alertable) req->flags |= SELECT_ALERTABLE;
if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT;
CLIENT_SendRequest( REQ_SELECT, -1, 2,
&req, sizeof(req),
server_handle, count * sizeof(int) );
CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply),
apc, sizeof(apc) );
if ((reply.signaled == STATUS_USER_APC) && (len > sizeof(reply)))
{
int i;
len -= sizeof(reply);
for (i = 0; i < len / sizeof(void*); i += 2)
{
PAPCFUNC func = (PAPCFUNC)apc[i];
if ( func ) func( (ULONG_PTR)apc[i+1] );
}
}
return reply.signaled;
server_call( REQ_SELECT );
if ((ret = req->signaled) == STATUS_USER_APC) call_apcs();
return ret;
}
......
......@@ -199,8 +199,7 @@ TEB *THREAD_CreateInitialThread( PDB *pdb, int server_fd )
TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
LPSECURITY_ATTRIBUTES sa, int *server_handle )
{
struct new_thread_request request;
struct new_thread_reply reply = { NULL, -1 };
struct new_thread_request *req = get_req_buffer();
int fd[2];
HANDLE cleanup_object;
......@@ -217,6 +216,7 @@ TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
/* Allocate the TEB selector (%fs register) */
*server_handle = -1;
teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, SEGMENT_DATA, TRUE, FALSE );
if (!teb->teb_sel) goto error;
......@@ -232,13 +232,12 @@ TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
/* Create the thread on the server side */
request.pid = teb->process->server_pid;
request.suspend = ((flags & CREATE_SUSPENDED) != 0);
request.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
CLIENT_SendRequest( REQ_NEW_THREAD, fd[1], 1, &request, sizeof(request) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) goto error;
teb->tid = reply.tid;
*server_handle = reply.handle;
req->pid = teb->process->server_pid;
req->suspend = ((flags & CREATE_SUSPENDED) != 0);
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
if (server_call_fd( REQ_NEW_THREAD, fd[1], NULL )) goto error;
teb->tid = req->tid;
*server_handle = req->handle;
/* Do the rest of the initialization */
......@@ -255,7 +254,7 @@ TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
return teb;
error:
if (reply.handle != -1) CloseHandle( reply.handle );
if (*server_handle != -1) CloseHandle( *server_handle );
if (teb->teb_sel) SELECTOR_FreeBlock( teb->teb_sel, 1 );
if (teb->socket != -1) close( teb->socket );
HeapFree( SystemHeap, 0, teb );
......@@ -532,13 +531,11 @@ BOOL WINAPI GetThreadContext(
INT WINAPI GetThreadPriority(
HANDLE hthread) /* [in] Handle to thread */
{
struct get_thread_info_request req;
struct get_thread_info_reply reply;
req.handle = hthread;
CLIENT_SendRequest( REQ_GET_THREAD_INFO, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ))
return THREAD_PRIORITY_ERROR_RETURN;
return reply.priority;
INT ret = THREAD_PRIORITY_ERROR_RETURN;
struct get_thread_info_request *req = get_req_buffer();
req->handle = hthread;
if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority;
return ret;
}
......@@ -553,12 +550,11 @@ BOOL WINAPI SetThreadPriority(
HANDLE hthread, /* [in] Handle to thread */
INT priority) /* [in] Thread priority level */
{
struct set_thread_info_request req;
req.handle = hthread;
req.priority = priority;
req.mask = SET_THREAD_INFO_PRIORITY;
CLIENT_SendRequest( REQ_SET_THREAD_INFO, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct set_thread_info_request *req = get_req_buffer();
req->handle = hthread;
req->priority = priority;
req->mask = SET_THREAD_INFO_PRIORITY;
return !server_call( REQ_SET_THREAD_INFO );
}
......@@ -567,12 +563,11 @@ BOOL WINAPI SetThreadPriority(
*/
DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
{
struct set_thread_info_request req;
req.handle = hThread;
req.affinity = dwThreadAffinityMask;
req.mask = SET_THREAD_INFO_AFFINITY;
CLIENT_SendRequest( REQ_SET_THREAD_INFO, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitReply( NULL, NULL, 0 )) return 0;
struct set_thread_info_request *req = get_req_buffer();
req->handle = hThread;
req->affinity = dwThreadAffinityMask;
req->mask = SET_THREAD_INFO_AFFINITY;
if (server_call( REQ_SET_THREAD_INFO )) return 0;
return 1; /* FIXME: should return previous value */
}
......@@ -588,11 +583,10 @@ BOOL WINAPI TerminateThread(
HANDLE handle, /* [in] Handle to thread */
DWORD exitcode) /* [in] Exit code for thread */
{
struct terminate_thread_request req;
req.handle = handle;
req.exit_code = exitcode;
CLIENT_SendRequest( REQ_TERMINATE_THREAD, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct terminate_thread_request *req = get_req_buffer();
req->handle = handle;
req->exit_code = exitcode;
return !server_call( REQ_TERMINATE_THREAD );
}
......@@ -607,13 +601,15 @@ BOOL WINAPI GetExitCodeThread(
HANDLE hthread, /* [in] Handle to thread */
LPDWORD exitcode) /* [out] Address to receive termination status */
{
struct get_thread_info_request req;
struct get_thread_info_reply reply;
req.handle = hthread;
CLIENT_SendRequest( REQ_GET_THREAD_INFO, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
if (exitcode) *exitcode = reply.exit_code;
return TRUE;
BOOL ret = FALSE;
struct get_thread_info_request *req = get_req_buffer();
req->handle = hthread;
if (!server_call( REQ_GET_THREAD_INFO ))
{
if (exitcode) *exitcode = req->exit_code;
ret = TRUE;
}
return ret;
}
......@@ -631,12 +627,11 @@ BOOL WINAPI GetExitCodeThread(
DWORD WINAPI ResumeThread(
HANDLE hthread) /* [in] Identifies thread to restart */
{
struct resume_thread_request req;
struct resume_thread_reply reply;
req.handle = hthread;
CLIENT_SendRequest( REQ_RESUME_THREAD, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return 0xffffffff;
return reply.count;
DWORD ret = 0xffffffff;
struct resume_thread_request *req = get_req_buffer();
req->handle = hthread;
if (!server_call( REQ_RESUME_THREAD )) ret = req->count;
return ret;
}
......@@ -650,12 +645,11 @@ DWORD WINAPI ResumeThread(
DWORD WINAPI SuspendThread(
HANDLE hthread) /* [in] Handle to the thread */
{
struct suspend_thread_request req;
struct suspend_thread_reply reply;
req.handle = hthread;
CLIENT_SendRequest( REQ_SUSPEND_THREAD, -1, 1, &req, sizeof(req) );
if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return 0xffffffff;
return reply.count;
DWORD ret = 0xffffffff;
struct suspend_thread_request *req = get_req_buffer();
req->handle = hthread;
if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count;
return ret;
}
......@@ -664,12 +658,11 @@ DWORD WINAPI SuspendThread(
*/
DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
{
struct queue_apc_request req;
req.handle = hthread;
req.func = func;
req.param = (void *)data;
CLIENT_SendRequest( REQ_QUEUE_APC, -1, 1, &req, sizeof(req) );
return !CLIENT_WaitReply( NULL, NULL, 0 );
struct queue_apc_request *req = get_req_buffer();
req->handle = hthread;
req->func = func;
req->param = (void *)data;
return !server_call( REQ_QUEUE_APC );
}
......
......@@ -41,13 +41,15 @@ static const struct object_ops change_ops =
};
static struct object *create_change_notification( int subtree, int filter )
static struct change *create_change_notification( int subtree, int filter )
{
struct change *change;
if (!(change = alloc_object( &change_ops ))) return NULL;
change->subtree = subtree;
change->filter = filter;
return &change->obj;
if ((change = alloc_object( &change_ops )))
{
change->subtree = subtree;
change->filter = filter;
}
return change;
}
static void change_dump( struct object *obj, int verbose )
......@@ -68,13 +70,13 @@ static int change_signaled( struct object *obj, struct thread *thread )
/* create a change notification */
DECL_HANDLER(create_change_notification)
{
struct object *obj;
struct create_change_notification_reply *reply = push_reply_data( current, sizeof(*reply) );
struct change *change;
if ((obj = create_change_notification( req->subtree, req->filter )))
req->handle = -1;
if ((change = create_change_notification( req->subtree, req->filter )))
{
reply->handle = alloc_handle( current->process, obj,
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE, 0 );
release_object( obj );
req->handle = alloc_handle( current->process, change,
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE, 0 );
release_object( change );
}
}
......@@ -69,7 +69,7 @@ static int screen_buffer_get_write_fd( struct object *obj );
static void screen_buffer_destroy( struct object *obj );
/* common routine */
static int console_get_info( struct object *obj, struct get_file_info_reply *reply );
static int console_get_info( struct object *obj, struct get_file_info_request *req );
static const struct object_ops console_input_ops =
{
......@@ -183,12 +183,11 @@ int free_console( struct process *process )
return 1;
}
static int set_console_fd( int handle, int fd, int pid )
static int set_console_fd( int handle, int fd_in, int fd_out, int pid )
{
struct console_input *input;
struct screen_buffer *output;
struct object *obj;
int fd_in, fd_out;
if (!(obj = get_handle_obj( current->process, handle, 0, NULL )))
return 0;
......@@ -215,21 +214,6 @@ static int set_console_fd( int handle, int fd, int pid )
assert( !input->obj.head );
assert( !output->obj.head );
if ((fd_in = dup(fd)) == -1)
{
file_set_error();
release_object( input );
release_object( output );
return 0;
}
if ((fd_out = dup(fd)) == -1)
{
file_set_error();
close( fd_in );
release_object( input );
release_object( output );
return 0;
}
unregister_select_user( &input->select );
unregister_select_user( &output->select );
close( input->select.fd );
......@@ -244,25 +228,21 @@ static int set_console_fd( int handle, int fd, int pid )
return 1;
}
static int get_console_mode( int handle, int *mode )
static int get_console_mode( int handle )
{
struct object *obj;
int ret = 0;
if (!(obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
return 0;
if (obj->ops == &console_input_ops)
{
*mode = ((struct console_input *)obj)->mode;
ret = 1;
}
else if (obj->ops == &screen_buffer_ops)
if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
{
*mode = ((struct screen_buffer *)obj)->mode;
ret = 1;
if (obj->ops == &console_input_ops)
ret = ((struct console_input *)obj)->mode;
else if (obj->ops == &screen_buffer_ops)
ret = ((struct screen_buffer *)obj)->mode;
else
set_error( ERROR_INVALID_HANDLE );
release_object( obj );
}
else set_error( ERROR_INVALID_HANDLE );
release_object( obj );
return ret;
}
......@@ -316,21 +296,6 @@ static int set_console_info( int handle, struct set_console_info_request *req,
return 1;
}
/* get misc console information (output handle only) */
static int get_console_info( int handle, struct get_console_info_reply *reply, const char **title )
{
struct screen_buffer *console;
if (!(console = (struct screen_buffer *)get_handle_obj( current->process, handle,
GENERIC_READ, &screen_buffer_ops )))
return 0;
reply->cursor_size = console->cursor_size;
reply->cursor_visible = console->cursor_visible;
reply->pid = console->pid;
*title = console->title;
release_object( console );
return 1;
}
/* add input events to a console input queue */
static int write_console_input( int handle, int count, INPUT_RECORD *records )
{
......@@ -355,16 +320,16 @@ static int write_console_input( int handle, int count, INPUT_RECORD *records )
}
/* retrieve a pointer to the console input records */
static int read_console_input( int handle, int count, int flush )
static int read_console_input( int handle, int count, INPUT_RECORD *rec, int max, int flush )
{
struct console_input *console;
struct read_console_input_reply *reply = push_reply_data( current, sizeof(*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;
add_reply_data( current, console->records, count * sizeof(INPUT_RECORD) );
if (count > max) count = max;
memcpy( rec, console->records, count * sizeof(INPUT_RECORD) );
if (flush)
{
int i;
......@@ -440,10 +405,18 @@ static int console_input_get_read_fd( struct object *obj )
return dup( console->select.fd );
}
static int console_get_info( struct object *obj, struct get_file_info_reply *reply )
static int console_get_info( struct object *obj, struct get_file_info_request *req )
{
memset( reply, 0, sizeof(*reply) );
reply->type = FILE_TYPE_CHAR;
req->type = FILE_TYPE_CHAR;
req->attr = 0;
req->access_time = 0;
req->write_time = 0;
req->size_high = 0;
req->size_low = 0;
req->links = 0;
req->index_high = 0;
req->index_low = 0;
req->serial = 0;
return 1;
}
......@@ -517,14 +490,12 @@ static void screen_buffer_destroy( struct object *obj )
unregister_select_user( &console->select );
close( console->select.fd );
if (console->input) console->input->output = NULL;
if (console->pid) kill( console->pid, SIGTERM );
if (console->title) free( console->title );
}
/* allocate a console for the current process */
DECL_HANDLER(alloc_console)
{
struct alloc_console_reply *reply = push_reply_data( current, sizeof(*reply) );
int in = -1, out = -1;
if (!alloc_console( current->process )) goto done;
......@@ -541,8 +512,8 @@ DECL_HANDLER(alloc_console)
free_console( current->process );
done:
reply->handle_in = in;
reply->handle_out = out;
req->handle_in = in;
req->handle_out = out;
}
/* free the console of the current process */
......@@ -554,40 +525,61 @@ DECL_HANDLER(free_console)
/* open a handle to the process console */
DECL_HANDLER(open_console)
{
struct open_console_reply *reply = push_reply_data( current, sizeof(*reply) );
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 );
if (obj) req->handle = alloc_handle( current->process, obj, req->access, req->inherit );
else set_error( ERROR_ACCESS_DENIED );
}
/* set info about a console (output only) */
DECL_HANDLER(set_console_info)
{
size_t len = get_req_strlen();
set_console_info( req->handle, req, get_req_data( len + 1 ), len );
size_t len = get_req_strlen( req->title );
set_console_info( req->handle, req, req->title, len );
}
/* get info about a console (output only) */
DECL_HANDLER(get_console_info)
{
struct get_console_info_reply *reply = push_reply_data( current, sizeof(*reply) );
const char *title;
get_console_info( req->handle, reply, &title );
if (title) add_reply_data( current, title, strlen(title) + 1 );
struct screen_buffer *console;
if ((console = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
GENERIC_READ, &screen_buffer_ops )))
{
req->cursor_size = console->cursor_size;
req->cursor_visible = console->cursor_visible;
req->pid = console->pid;
strcpy( req->title, console->title ? console->title : "" );
release_object( console );
}
}
/* set a console fd */
DECL_HANDLER(set_console_fd)
{
set_console_fd( req->handle, fd, req->pid );
struct object *obj;
int fd_in, fd_out;
if (!(obj = get_handle_obj( current->process, req->file_handle,
GENERIC_READ | GENERIC_WRITE, NULL ))) return;
if ((fd_in = obj->ops->get_read_fd( obj )) == -1)
{
release_object( obj );
return;
}
fd_out = obj->ops->get_write_fd( obj );
release_object( obj );
if (fd_out != -1)
{
if (set_console_fd( req->handle, fd_in, fd_out, req->pid )) return;
close( fd_out );
}
close( fd_in );
}
/* get a console mode (input or output) */
DECL_HANDLER(get_console_mode)
{
struct get_console_mode_reply *reply = push_reply_data( current, sizeof(*reply) );
get_console_mode( req->handle, &reply->mode );
req->mode = get_console_mode( req->handle );
}
/* set a console mode (input or output) */
......@@ -599,18 +591,17 @@ DECL_HANDLER(set_console_mode)
/* add input records to a console input queue */
DECL_HANDLER(write_console_input)
{
struct write_console_input_reply *reply = push_reply_data( current, sizeof(*reply) );
int max = get_req_size( req + 1, sizeof(INPUT_RECORD) );
int count = req->count;
if (check_req_data( req->count * sizeof(INPUT_RECORD)))
{
INPUT_RECORD *records = get_req_data( req->count * sizeof(INPUT_RECORD) );
reply->written = write_console_input( req->handle, req->count, records );
}
else fatal_protocol_error( "write_console_input: bad length" );
if (count > max) count = max;
req->written = write_console_input( req->handle, count, (INPUT_RECORD *)(req + 1) );
}
/* fetch input records from a console input queue */
DECL_HANDLER(read_console_input)
{
read_console_input( req->handle, req->count, req->flush );
int max = get_req_size( req + 1, sizeof(INPUT_RECORD) );
req->read = read_console_input( req->handle, req->count, (INPUT_RECORD *)(req + 1),
max, req->flush );
}
......@@ -146,16 +146,16 @@ static void build_event_reply( struct debug_ctx *debug_ctx )
{
struct debug_event *event = debug_ctx->event_head;
struct thread *thread = event->thread;
struct wait_debug_event_reply *reply = push_reply_data( debug_ctx->owner, sizeof(*reply) );
struct wait_debug_event_request *req = get_req_ptr( debug_ctx->owner );
assert( event );
assert( debug_ctx->waiting );
unlink_event( debug_ctx, event );
event->sent = 1;
reply->code = event->code;
reply->pid = thread->process;
reply->tid = thread;
req->code = event->code;
req->pid = thread->process;
req->tid = thread;
debug_ctx->waiting = 0;
if (debug_ctx->timeout)
{
......@@ -163,20 +163,20 @@ static void build_event_reply( struct debug_ctx *debug_ctx )
debug_ctx->timeout = NULL;
}
debug_ctx->owner->error = 0;
add_reply_data( debug_ctx->owner, &event->data, event_sizes[event->code] );
memcpy( req + 1, &event->data, event_sizes[event->code] );
}
/* timeout callback while waiting for a debug event */
static void wait_event_timeout( void *ctx )
{
struct debug_ctx *debug_ctx = (struct debug_ctx *)ctx;
struct wait_debug_event_reply *reply = push_reply_data( debug_ctx->owner, sizeof(*reply) );
struct wait_debug_event_request *req = get_req_ptr( debug_ctx->owner );
assert( debug_ctx->waiting );
reply->code = 0;
reply->pid = 0;
reply->tid = 0;
req->code = 0;
req->pid = 0;
req->tid = 0;
debug_ctx->waiting = 0;
debug_ctx->timeout = NULL;
debug_ctx->owner->error = WAIT_TIMEOUT;
......@@ -232,8 +232,8 @@ static int continue_debug_event( struct process *process, struct thread *thread,
{
/* only send a reply if the thread is still there */
/* (we can get a continue on an exit thread/process event) */
struct send_debug_event_reply *reply = push_reply_data( thread, sizeof(*reply) );
reply->status = status;
struct send_debug_event_request *req = get_req_ptr( thread );
req->status = status;
send_reply( thread );
}
free_event( event );
......@@ -380,10 +380,9 @@ DECL_HANDLER(wait_debug_event)
{
if (!wait_for_debug_event( req->timeout ))
{
struct wait_debug_event_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->code = 0;
reply->pid = NULL;
reply->tid = NULL;
req->code = 0;
req->pid = NULL;
req->tid = NULL;
}
}
......@@ -423,23 +422,13 @@ DECL_HANDLER(send_debug_event)
assert( !current->debug_event );
if ((req->code <= 0) || (req->code > RIP_EVENT))
{
fatal_protocol_error( "send_debug_event: bad event code" );
fatal_protocol_error( current, "send_debug_event: bad code %d\n", req->code );
return;
}
if (!check_req_data( event_sizes[req->code] ))
{
fatal_protocol_error( "send_debug_event: bad length" );
return;
}
if (debugger && queue_debug_event( debugger, current, req->code,
get_req_data( event_sizes[req->code] )))
req->status = 0;
if (debugger && queue_debug_event( debugger, current, req->code, req + 1 ))
{
/* wait for continue_debug_event */
current->state = SLEEPING;
}
else
{
struct send_debug_event_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->status = 0;
}
}
......@@ -30,7 +30,7 @@ struct device
};
static void device_dump( struct object *obj, int verbose );
static int device_get_info( struct object *obj, struct get_file_info_reply *reply );
static int device_get_info( struct object *obj, struct get_file_info_request *req );
static const struct object_ops device_ops =
{
......@@ -64,13 +64,20 @@ static void device_dump( struct object *obj, int verbose )
fprintf( stderr, "Device id=%08x\n", dev->id );
}
static int device_get_info( struct object *obj, struct get_file_info_reply *reply )
static int device_get_info( struct object *obj, struct get_file_info_request *req )
{
struct device *dev = (struct device *)obj;
assert( obj->ops == &device_ops );
memset( reply, 0, sizeof(*reply) );
reply->type = FILE_TYPE_UNKNOWN;
reply->attr = dev->id; /* hack! */
req->type = FILE_TYPE_UNKNOWN;
req->attr = dev->id; /* hack! */
req->access_time = 0;
req->write_time = 0;
req->size_high = 0;
req->size_low = 0;
req->links = 0;
req->index_high = 0;
req->index_low = 0;
req->serial = 0;
return 1;
}
......@@ -78,12 +85,11 @@ static int device_get_info( struct object *obj, struct get_file_info_reply *repl
DECL_HANDLER(create_device)
{
struct device *dev;
struct create_device_reply *reply = push_reply_data( current, sizeof(*reply) );
req->handle = -1;
if ((dev = create_device( req->id )))
{
reply->handle = alloc_handle( current->process, dev, req->access, req->inherit );
req->handle = alloc_handle( current->process, dev, req->access, req->inherit );
release_object( dev );
}
else reply->handle = -1;
}
......@@ -128,25 +128,22 @@ static int event_satisfied( struct object *obj, struct thread *thread )
/* create an event */
DECL_HANDLER(create_event)
{
size_t len = get_req_strlen();
struct create_event_reply *reply = push_reply_data( current, sizeof(*reply) );
size_t len = get_req_strlen( req->name );
struct event *event;
if ((event = create_event( get_req_data(len+1), len, req->manual_reset, req->initial_state )))
req->handle = -1;
if ((event = create_event( req->name, len, req->manual_reset, req->initial_state )))
{
reply->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
req->handle = alloc_handle( current->process, event, EVENT_ALL_ACCESS, req->inherit );
release_object( event );
}
else reply->handle = -1;
}
/* open a handle to an event */
DECL_HANDLER(open_event)
{
size_t len = get_req_strlen();
struct open_event_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->handle = open_object( get_req_data( len + 1 ), len, &event_ops,
req->access, req->inherit );
size_t len = get_req_strlen( req->name );
req->handle = open_object( req->name, len, &event_ops, req->access, req->inherit );
}
/* do an event operation */
......@@ -164,6 +161,6 @@ DECL_HANDLER(event_op)
reset_event( req->handle );
break;
default:
fatal_protocol_error( "event_op: invalid operation" );
fatal_protocol_error( current, "event_op: invalid operation %d\n", req->op );
}
}
......@@ -47,7 +47,7 @@ static int file_signaled( struct object *obj, struct thread *thread );
static int file_get_read_fd( struct object *obj );
static int file_get_write_fd( struct object *obj );
static int file_flush( struct object *obj );
static int file_get_info( struct object *obj, struct get_file_info_reply *reply );
static int file_get_info( struct object *obj, struct get_file_info_request *req );
static void file_destroy( struct object *obj );
static const struct object_ops file_ops =
......@@ -208,7 +208,7 @@ struct file *create_temp_file( int access )
struct file *file;
int fd;
if ((fd = create_anonymous_file()) != -1) return NULL;
if ((fd = create_anonymous_file()) == -1) return NULL;
if (!(file = create_file_for_fd( fd, access, 0, 0 ))) close( fd );
return file;
}
......@@ -295,7 +295,7 @@ static int file_flush( struct object *obj )
return ret;
}
static int file_get_info( struct object *obj, struct get_file_info_reply *reply )
static int file_get_info( struct object *obj, struct get_file_info_request *req )
{
struct stat st;
struct file *file = (struct file *)obj;
......@@ -307,19 +307,19 @@ static int file_get_info( struct object *obj, struct get_file_info_reply *reply
return 0;
}
if (S_ISCHR(st.st_mode) || S_ISFIFO(st.st_mode) ||
S_ISSOCK(st.st_mode) || isatty(file->select.fd)) reply->type = FILE_TYPE_CHAR;
else reply->type = FILE_TYPE_DISK;
if (S_ISDIR(st.st_mode)) reply->attr = FILE_ATTRIBUTE_DIRECTORY;
else reply->attr = FILE_ATTRIBUTE_ARCHIVE;
if (!(st.st_mode & S_IWUSR)) reply->attr |= FILE_ATTRIBUTE_READONLY;
reply->access_time = st.st_atime;
reply->write_time = st.st_mtime;
reply->size_high = 0;
reply->size_low = S_ISDIR(st.st_mode) ? 0 : st.st_size;
reply->links = st.st_nlink;
reply->index_high = st.st_dev;
reply->index_low = st.st_ino;
reply->serial = 0; /* FIXME */
S_ISSOCK(st.st_mode) || isatty(file->select.fd)) req->type = FILE_TYPE_CHAR;
else req->type = FILE_TYPE_DISK;
if (S_ISDIR(st.st_mode)) req->attr = FILE_ATTRIBUTE_DIRECTORY;
else req->attr = FILE_ATTRIBUTE_ARCHIVE;
if (!(st.st_mode & S_IWUSR)) req->attr |= FILE_ATTRIBUTE_READONLY;
req->access_time = st.st_atime;
req->write_time = st.st_mtime;
req->size_high = 0;
req->size_low = S_ISDIR(st.st_mode) ? 0 : st.st_size;
req->links = st.st_nlink;
req->index_high = st.st_dev;
req->index_low = st.st_ino;
req->serial = 0; /* FIXME */
return 1;
}
......@@ -485,71 +485,72 @@ static int file_unlock( struct file *file, int offset_high, int offset_low,
/* FIXME: implement this */
return 1;
}
/* create a file */
DECL_HANDLER(create_file)
{
struct create_file_reply *reply = push_reply_data( current, sizeof(*reply) );
struct file *file = NULL;
size_t len = get_req_strlen( req->name );
struct file *file;
if (fd == -1)
req->handle = -1;
if ((file = create_file( req->name, len, req->access,
req->sharing, req->create, req->attrs )))
{
size_t len = get_req_strlen();
file = create_file( get_req_data( len + 1), len, req->access,
req->sharing, req->create, req->attrs );
}
else
{
if ((fd = dup(fd)) == -1)
file_set_error();
else
file = create_file_for_fd( fd, req->access, req->sharing, req->attrs );
req->handle = alloc_handle( current->process, file, req->access, req->inherit );
release_object( file );
}
if (file)
}
/* allocate a file handle for a Unix fd */
DECL_HANDLER(alloc_file_handle)
{
struct file *file;
req->handle = -1;
if ((fd = dup(fd)) != -1)
{
reply->handle = alloc_handle( current->process, file, req->access, req->inherit );
release_object( file );
if ((file = create_file_for_fd( fd, req->access, FILE_SHARE_READ | FILE_SHARE_WRITE, 0 )))
{
req->handle = alloc_handle( current->process, file, req->access, 0 );
release_object( file );
}
else close( fd );
}
else reply->handle = -1;
else file_set_error();
}
/* get a Unix fd to read from a file */
DECL_HANDLER(get_read_fd)
{
struct object *obj;
int read_fd;
if ((obj = get_handle_obj( current->process, req->handle, GENERIC_READ, NULL )))
{
read_fd = obj->ops->get_read_fd( obj );
set_reply_fd( current, obj->ops->get_read_fd( obj ) );
release_object( obj );
}
else read_fd = -1;
set_reply_fd( current, read_fd );
}
/* get a Unix fd to write to a file */
DECL_HANDLER(get_write_fd)
{
struct object *obj;
int write_fd;
if ((obj = get_handle_obj( current->process, req->handle, GENERIC_WRITE, NULL )))
{
write_fd = obj->ops->get_write_fd( obj );
set_reply_fd( current, obj->ops->get_write_fd( obj ) );
release_object( obj );
}
else write_fd = -1;
set_reply_fd( current, write_fd );
}
/* set a file current position */
DECL_HANDLER(set_file_pointer)
{
struct set_file_pointer_reply reply;
reply.low = req->low;
reply.high = req->high;
set_file_pointer( req->handle, &reply.low, &reply.high, req->whence );
add_reply_data( current, &reply, sizeof(reply) );
int high = req->high;
int low = req->low;
set_file_pointer( req->handle, &low, &high, req->whence );
req->new_low = low;
req->new_high = high;
}
/* truncate (or extend) a file */
......@@ -580,11 +581,10 @@ DECL_HANDLER(set_file_time)
DECL_HANDLER(get_file_info)
{
struct object *obj;
struct get_file_info_reply *reply = push_reply_data( current, sizeof(*reply) );
if ((obj = get_handle_obj( current->process, req->handle, 0, NULL )))
{
obj->ops->get_file_info( obj, reply );
obj->ops->get_file_info( obj, req );
release_object( obj );
}
}
......
......@@ -403,8 +403,7 @@ DECL_HANDLER(close_handle)
/* get information about a handle */
DECL_HANDLER(get_handle_info)
{
struct get_handle_info_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->flags = set_handle_info( current->process, req->handle, 0, 0 );
req->flags = set_handle_info( current->process, req->handle, 0, 0 );
}
/* set a handle information */
......@@ -416,20 +415,20 @@ DECL_HANDLER(set_handle_info)
/* duplicate a handle */
DECL_HANDLER(dup_handle)
{
struct dup_handle_reply reply = { -1 };
struct process *src, *dst;
req->handle = -1;
if ((src = get_process_from_handle( req->src_process, PROCESS_DUP_HANDLE )))
{
if (req->options & DUP_HANDLE_MAKE_GLOBAL)
{
reply.handle = duplicate_handle( src, req->src_handle, NULL,
req->access, req->inherit, req->options );
req->handle = duplicate_handle( src, req->src_handle, NULL,
req->access, req->inherit, req->options );
}
else if ((dst = get_process_from_handle( req->dst_process, PROCESS_DUP_HANDLE )))
{
reply.handle = duplicate_handle( src, req->src_handle, dst,
req->access, req->inherit, req->options );
req->handle = duplicate_handle( src, req->src_handle, dst,
req->access, req->inherit, req->options );
release_object( dst );
}
/* close the handle no matter what happened */
......@@ -437,5 +436,4 @@ DECL_HANDLER(dup_handle)
close_handle( src, req->src_handle );
release_object( src );
}
add_reply_data( current, &reply, sizeof(reply) );
}
......@@ -104,11 +104,11 @@ static struct object *create_mapping( int size_high, int size_low, int protect,
if (!(mapping->file = get_file_obj( current->process, handle, access ))) goto error;
if (!size_high && !size_low)
{
struct get_file_info_reply reply;
struct get_file_info_request req;
struct object *obj = (struct object *)mapping->file;
obj->ops->get_file_info( obj, &reply );
size_high = reply.size_high;
size_low = ROUND_SIZE( 0, reply.size_low );
obj->ops->get_file_info( obj, &req );
size_high = req.size_high;
size_low = ROUND_SIZE( 0, req.size_low );
}
else if (!grow_file( mapping->file, size_high, size_low )) goto error;
}
......@@ -133,23 +133,6 @@ static struct object *create_mapping( int size_high, int size_low, int protect,
return NULL;
}
static int get_mapping_info( int handle, struct get_mapping_info_reply *reply )
{
struct mapping *mapping;
int fd;
if (!(mapping = (struct mapping *)get_handle_obj( current->process, handle,
0, &mapping_ops )))
return -1;
reply->size_high = mapping->size_high;
reply->size_low = mapping->size_low;
reply->protect = mapping->protect;
if (mapping->file) fd = file_get_mmap_fd( mapping->file );
else fd = -1;
release_object( mapping );
return fd;
}
static void mapping_dump( struct object *obj, int verbose )
{
struct mapping *mapping = (struct mapping *)obj;
......@@ -169,34 +152,40 @@ static void mapping_destroy( struct object *obj )
/* create a file mapping */
DECL_HANDLER(create_mapping)
{
size_t len = get_req_strlen();
struct create_mapping_reply *reply = push_reply_data( current, sizeof(*reply) );
size_t len = get_req_strlen( req->name );
struct object *obj;
req->handle = -1;
if ((obj = create_mapping( req->size_high, req->size_low,
req->protect, req->handle, get_req_data( len + 1 ), len )))
req->protect, req->file_handle, req->name, len )))
{
int access = FILE_MAP_ALL_ACCESS;
if (!(req->protect & VPROT_WRITE)) access &= ~FILE_MAP_WRITE;
reply->handle = alloc_handle( current->process, obj, access, req->inherit );
req->handle = alloc_handle( current->process, obj, access, req->inherit );
release_object( obj );
}
else reply->handle = -1;
}
/* open a handle to a mapping */
DECL_HANDLER(open_mapping)
{
size_t len = get_req_strlen();
struct open_mapping_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->handle = open_object( get_req_data( len + 1 ), len, &mapping_ops,
req->access, req->inherit );
size_t len = get_req_strlen( req->name );
req->handle = open_object( req->name, len, &mapping_ops, req->access, req->inherit );
}
/* get a mapping information */
DECL_HANDLER(get_mapping_info)
{
struct get_mapping_info_reply *reply = push_reply_data( current, sizeof(*reply) );
int map_fd = get_mapping_info( req->handle, reply );
set_reply_fd( current, map_fd );
struct mapping *mapping;
if ((mapping = (struct mapping *)get_handle_obj( current->process, req->handle,
0, &mapping_ops )))
{
req->size_high = mapping->size_high;
req->size_low = mapping->size_low;
req->protect = mapping->protect;
if (mapping->file) set_reply_fd( current, file_get_mmap_fd( mapping->file ) );
release_object( mapping );
}
}
......@@ -126,25 +126,22 @@ static int mutex_satisfied( struct object *obj, struct thread *thread )
/* create a mutex */
DECL_HANDLER(create_mutex)
{
size_t len = get_req_strlen();
struct create_mutex_reply *reply = push_reply_data( current, sizeof(*reply) );
size_t len = get_req_strlen( req->name );
struct mutex *mutex;
if ((mutex = create_mutex( get_req_data( len + 1 ), len, req->owned )))
req->handle = -1;
if ((mutex = create_mutex( req->name, len, req->owned )))
{
reply->handle = alloc_handle( current->process, mutex, MUTEX_ALL_ACCESS, req->inherit );
req->handle = alloc_handle( current->process, mutex, MUTEX_ALL_ACCESS, req->inherit );
release_object( mutex );
}
else reply->handle = -1;
}
/* open a handle to a mutex */
DECL_HANDLER(open_mutex)
{
size_t len = get_req_strlen();
struct open_mutex_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->handle = open_object( get_req_data( len + 1 ), len, &mutex_ops,
req->access, req->inherit );
size_t len = get_req_strlen( req->name );
req->handle = open_object( req->name, len, &mutex_ops, req->access, req->inherit );
}
/* release a mutex */
......
......@@ -240,7 +240,7 @@ int no_flush( struct object *obj )
return 0;
}
int no_get_file_info( struct object *obj, struct get_file_info_reply *info )
int no_get_file_info( struct object *obj, struct get_file_info_request *info )
{
set_error( ERROR_INVALID_HANDLE );
return 0;
......
......@@ -47,7 +47,7 @@ struct object_ops
/* flush the object buffers */
int (*flush)(struct object *);
/* get file information */
int (*get_file_info)(struct object *,struct get_file_info_reply *);
int (*get_file_info)(struct object *,struct get_file_info_request *);
/* destroy on refcount == 0 */
void (*destroy)(struct object *);
};
......@@ -80,7 +80,7 @@ extern int no_satisfied( struct object *obj, struct thread *thread );
extern int no_read_fd( struct object *obj );
extern int no_write_fd( struct object *obj );
extern int no_flush( struct object *obj );
extern int no_get_file_info( struct object *obj, struct get_file_info_reply *info );
extern int no_get_file_info( struct object *obj, struct get_file_info_request *info );
extern void no_destroy( struct object *obj );
extern void default_select_event( int event, void *private );
#ifdef DEBUG_OBJECTS
......@@ -123,7 +123,7 @@ struct client;
extern struct client *add_client( int client_fd, struct thread *self );
extern void remove_client( struct client *client, int exit_code );
extern void client_pass_fd( struct client *client, int pass_fd );
extern void client_reply( struct client *client );
extern void client_reply( struct client *client, unsigned int res );
/* mutex functions */
......
......@@ -39,7 +39,7 @@ static void pipe_remove_queue( struct object *obj, struct wait_queue_entry *entr
static int pipe_signaled( struct object *obj, struct thread *thread );
static int pipe_get_read_fd( struct object *obj );
static int pipe_get_write_fd( struct object *obj );
static int pipe_get_info( struct object *obj, struct get_file_info_reply *reply );
static int pipe_get_info( struct object *obj, struct get_file_info_request *req );
static void pipe_destroy( struct object *obj );
static const struct object_ops pipe_ops =
......@@ -189,10 +189,18 @@ static int pipe_get_write_fd( struct object *obj )
return dup( pipe->select.fd );
}
static int pipe_get_info( struct object *obj, struct get_file_info_reply *reply )
static int pipe_get_info( struct object *obj, struct get_file_info_request *req )
{
memset( reply, 0, sizeof(*reply) );
reply->type = FILE_TYPE_PIPE;
req->type = FILE_TYPE_PIPE;
req->attr = 0;
req->access_time = 0;
req->write_time = 0;
req->size_high = 0;
req->size_low = 0;
req->links = 0;
req->index_high = 0;
req->index_low = 0;
req->serial = 0;
return 1;
}
......@@ -209,23 +217,25 @@ static void pipe_destroy( struct object *obj )
/* create an anonymous pipe */
DECL_HANDLER(create_pipe)
{
struct create_pipe_reply reply = { -1, -1 };
struct object *obj[2];
int hread = -1, hwrite = -1;
if (create_pipe( obj ))
{
reply.handle_read = alloc_handle( current->process, obj[0],
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
req->inherit );
if (reply.handle_read != -1)
hread = alloc_handle( current->process, obj[0],
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
req->inherit );
if (hread != -1)
{
reply.handle_write = alloc_handle( current->process, obj[1],
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
req->inherit );
if (reply.handle_write == -1)
close_handle( current->process, reply.handle_read );
hwrite = alloc_handle( current->process, obj[1],
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
req->inherit );
if (hwrite == -1)
close_handle( current->process, hread );
}
release_object( obj[0] );
release_object( obj[1] );
}
add_reply_data( current, &reply, sizeof(reply) );
req->handle_read = hread;
req->handle_write = hwrite;
}
......@@ -82,10 +82,10 @@ static struct process *create_process( struct process *parent, struct new_proces
/* alloc a handle for the process itself */
alloc_handle( process, process, PROCESS_ALL_ACCESS, 0 );
if (!(process->info = mem_alloc( sizeof(*process->info) + len + 1 ))) goto error;
if (!(process->info = mem_alloc( sizeof(*process->info) + len ))) goto error;
memcpy( process->info, req, sizeof(*req) );
memcpy( process->info->cmd_line, cmd_line, len );
process->info->cmd_line[len] = 0;
memcpy( process->info->cmdline, cmd_line, len );
process->info->cmdline[len] = 0;
/* set the process console */
if (req->create_flags & CREATE_NEW_CONSOLE)
......@@ -285,14 +285,13 @@ void kill_process( struct process *process, int exit_code )
}
/* get all information about a process */
static void get_process_info( struct process *process,
struct get_process_info_reply *reply )
static void get_process_info( struct process *process, struct get_process_info_request *req )
{
reply->pid = process;
reply->exit_code = process->exit_code;
reply->priority = process->priority;
reply->process_affinity = process->affinity;
reply->system_affinity = 1;
req->pid = process;
req->exit_code = process->exit_code;
req->priority = process->priority;
req->process_affinity = process->affinity;
req->system_affinity = 1;
}
/* set all information about a process */
......@@ -333,62 +332,55 @@ struct process_snapshot *process_snap( int *count )
/* create a new process */
DECL_HANDLER(new_process)
{
struct new_process_reply *reply = push_reply_data( current, sizeof(*reply) );
size_t len = get_req_strlen();
size_t len = get_req_strlen( req->cmdline );
struct process *process;
if ((process = create_process( current->process, req, get_req_data( len + 1 ), len )))
req->handle = -1;
req->pid = NULL;
if ((process = create_process( current->process, req, req->cmdline, len )))
{
reply->handle = alloc_handle( current->process, process,
PROCESS_ALL_ACCESS, req->inherit );
reply->pid = process;
req->handle = alloc_handle( current->process, process, PROCESS_ALL_ACCESS, req->inherit );
req->pid = process;
release_object( process );
}
else
{
reply->handle = -1;
reply->pid = NULL;
}
}
/* initialize a new process */
DECL_HANDLER(init_process)
{
struct init_process_reply *reply = push_reply_data( current, sizeof(*reply) );
struct new_process_request *info;
if (current->state == STARTING)
{
fatal_protocol_error( "init_process: init_thread not called yet\n" );
fatal_protocol_error( current, "init_process: init_thread not called yet\n" );
return;
}
if (!(info = current->process->info))
{
fatal_protocol_error( "init_process: called twice\n" );
fatal_protocol_error( current, "init_process: called twice\n" );
return;
}
current->process->info = NULL;
reply->start_flags = info->start_flags;
reply->hstdin = info->hstdin;
reply->hstdout = info->hstdout;
reply->hstderr = info->hstderr;
reply->cmd_show = info->cmd_show;
reply->env_ptr = info->env_ptr;
add_reply_data( current, info->cmd_line, strlen(info->cmd_line) + 1 );
req->start_flags = info->start_flags;
req->hstdin = info->hstdin;
req->hstdout = info->hstdout;
req->hstderr = info->hstderr;
req->cmd_show = info->cmd_show;
req->env_ptr = info->env_ptr;
strcpy( req->cmdline, info->cmdline );
free( info );
}
/* open a handle to a process */
DECL_HANDLER(open_process)
{
struct open_process_reply *reply = push_reply_data( current, sizeof(*reply) );
struct process *process = get_process_from_id( req->pid );
req->handle = -1;
if (process)
{
reply->handle = alloc_handle( current->process, process, req->access, req->inherit );
req->handle = alloc_handle( current->process, process, req->access, req->inherit );
release_object( process );
}
else reply->handle = -1;
}
/* terminate a process */
......@@ -407,11 +399,10 @@ DECL_HANDLER(terminate_process)
DECL_HANDLER(get_process_info)
{
struct process *process;
struct get_process_info_reply *reply = push_reply_data( current, sizeof(*reply) );
if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
{
get_process_info( process, reply );
get_process_info( process, req );
release_object( process );
}
}
......
......@@ -26,55 +26,33 @@
struct thread *current = NULL; /* thread handling the current request */
/* complain about a protocol error and terminate the client connection */
void fatal_protocol_error( const char *err )
void fatal_protocol_error( struct thread *thread, const char *err, ... )
{
unsigned char *p;
va_list args;
fprintf( stderr, "Protocol error:%p: %s\n request:", current, err );
for (p = (unsigned char *)current->buffer; p < (unsigned char *)current->req_end; p++)
fprintf( stderr, " %02x", *p );
fprintf( stderr, "\n" );
remove_client( current->client, -2 );
va_start( args, err );
fprintf( stderr, "Protocol error:%p: ", thread );
vfprintf( stderr, err, args );
va_end( args );
remove_client( thread->client, PROTOCOL_ERROR );
}
/* call a request handler */
void call_req_handler( struct thread *thread, int fd )
void call_req_handler( struct thread *thread, enum request req, int fd )
{
const struct handler *handler;
struct header *head;
unsigned int req, len;
current = thread;
assert (current);
head = (struct header *)current->buffer;
req = head->type;
len = head->len;
/* set the buffer pointers */
current->req_pos = current->reply_pos = (char *)current->buffer + sizeof(struct header);
current->req_end = (char *)current->buffer + len;
clear_error();
if ((len < sizeof(struct header)) || (len > MAX_MSG_LENGTH)) goto bad_header;
if (req >= REQ_NB_REQUESTS) goto bad_header;
if (debug_level) trace_request( req, fd );
/* now call the handler */
handler = &req_handlers[req];
if (!check_req_data( handler->min_size )) goto bad_request;
handler->handler( get_req_data( handler->min_size ), fd );
if (current && current->state != SLEEPING) send_reply( current );
current = NULL;
return;
bad_header:
/* dump only the header */
current->req_end = (char *)current->buffer + sizeof(struct header);
bad_request:
fatal_protocol_error( "bad request" );
if (req < REQ_NB_REQUESTS)
{
req_handlers[req].handler( current->buffer, fd );
if (current && current->state != SLEEPING) send_reply( current );
current = NULL;
return;
}
fatal_protocol_error( current, "bad request %d\n", req );
}
/* handle a client timeout */
......@@ -110,15 +88,8 @@ void set_reply_fd( struct thread *thread, int pass_fd )
/* send a reply to a thread */
void send_reply( struct thread *thread )
{
struct header *head = thread->buffer;
int len = (char *)thread->reply_pos - (char *)thread->buffer;
assert( len < MAX_MSG_LENGTH );
head->len = len;
head->type = thread->error;
if (thread->state == SLEEPING) thread->state = RUNNING;
client_reply( thread->client );
client_reply( thread->client, thread->error );
}
/* set the debug level */
......
......@@ -13,14 +13,21 @@
#include "thread.h"
/* request handler definition */
/* max request length */
#define MAX_REQUEST_LENGTH 8192
/* exit code passed to remove_client on communication error */
#define OUT_OF_MEMORY -1
#define BROKEN_PIPE -2
#define PROTOCOL_ERROR -3
/* request handler definition */
#define DECL_HANDLER(name) void req_##name( struct name##_request *req, int fd )
/* request functions */
extern void fatal_protocol_error( const char *err );
extern void call_req_handler( struct thread *thread, int fd );
extern void fatal_protocol_error( struct thread *thread, const char *err, ... );
extern void call_req_handler( struct thread *thread, enum request req, int fd );
extern void call_timeout_handler( void *thread );
extern void call_kill_handler( struct thread *thread, int exit_code );
extern void set_reply_fd( struct thread *thread, int pass_fd );
......@@ -29,48 +36,26 @@ extern void send_reply( struct thread *thread );
extern void trace_request( enum request req, int fd );
extern void trace_timeout(void);
extern void trace_kill( int exit_code );
extern void trace_reply( struct thread *thread, int pass_fd );
/* Warning: the buffer is shared between request and reply,
* so make sure you are finished using the request before starting
* to add data for the reply.
*/
extern void trace_reply( struct thread *thread, unsigned int res, int pass_fd );
/* remove some data from the current request */
static inline void *get_req_data( size_t len )
/* get the request buffer */
static inline void *get_req_ptr( struct thread *thread )
{
void *old = current->req_pos;
current->req_pos = (char *)old + len;
return old;
return thread->buffer;
}
/* check that there is enough data available in the current request */
static inline int check_req_data( size_t len )
/* get the remaining size in the request buffer for object of a given size */
static inline int get_req_size( const void *ptr, size_t typesize )
{
return (char *)current->req_pos + len <= (char *)current->req_end;
return ((char *)current->buffer + MAX_REQUEST_LENGTH - (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(void)
{
char *p = current->req_pos;
while (*p && (p < (char *)current->req_end - 1)) p++;
return p - (char *)current->req_pos;
}
/* make space for some data in the current reply */
static inline void *push_reply_data( struct thread *thread, size_t len )
{
void *old = thread->reply_pos;
thread->reply_pos = (char *)old + len;
return old;
}
/* add some data to the current reply */
static inline void add_reply_data( struct thread *thread, const void *data, size_t len )
static inline size_t get_req_strlen( const char *str )
{
memcpy( push_reply_data( thread, len ), data, len );
const char *p = str;
while (*p && (p < (char *)current->buffer + MAX_REQUEST_LENGTH - 1)) p++;
return p - str;
}
/* Everything below this line is generated automatically by tools/make_requests */
......@@ -81,6 +66,7 @@ DECL_HANDLER(new_thread);
DECL_HANDLER(set_debug);
DECL_HANDLER(init_process);
DECL_HANDLER(init_thread);
DECL_HANDLER(get_thread_buffer);
DECL_HANDLER(terminate_process);
DECL_HANDLER(terminate_thread);
DECL_HANDLER(get_process_info);
......@@ -91,6 +77,7 @@ DECL_HANDLER(suspend_thread);
DECL_HANDLER(resume_thread);
DECL_HANDLER(debugger);
DECL_HANDLER(queue_apc);
DECL_HANDLER(get_apcs);
DECL_HANDLER(close_handle);
DECL_HANDLER(get_handle_info);
DECL_HANDLER(set_handle_info);
......@@ -107,6 +94,7 @@ DECL_HANDLER(create_semaphore);
DECL_HANDLER(release_semaphore);
DECL_HANDLER(open_semaphore);
DECL_HANDLER(create_file);
DECL_HANDLER(alloc_file_handle);
DECL_HANDLER(get_read_fd);
DECL_HANDLER(get_write_fd);
DECL_HANDLER(set_file_pointer);
......@@ -150,6 +138,7 @@ static const struct handler {
{ (void(*)())req_set_debug, sizeof(struct set_debug_request) },
{ (void(*)())req_init_process, sizeof(struct init_process_request) },
{ (void(*)())req_init_thread, sizeof(struct init_thread_request) },
{ (void(*)())req_get_thread_buffer, sizeof(struct get_thread_buffer_request) },
{ (void(*)())req_terminate_process, sizeof(struct terminate_process_request) },
{ (void(*)())req_terminate_thread, sizeof(struct terminate_thread_request) },
{ (void(*)())req_get_process_info, sizeof(struct get_process_info_request) },
......@@ -160,6 +149,7 @@ static const struct handler {
{ (void(*)())req_resume_thread, sizeof(struct resume_thread_request) },
{ (void(*)())req_debugger, sizeof(struct debugger_request) },
{ (void(*)())req_queue_apc, sizeof(struct queue_apc_request) },
{ (void(*)())req_get_apcs, sizeof(struct get_apcs_request) },
{ (void(*)())req_close_handle, sizeof(struct close_handle_request) },
{ (void(*)())req_get_handle_info, sizeof(struct get_handle_info_request) },
{ (void(*)())req_set_handle_info, sizeof(struct set_handle_info_request) },
......@@ -176,6 +166,7 @@ static const struct handler {
{ (void(*)())req_release_semaphore, sizeof(struct release_semaphore_request) },
{ (void(*)())req_open_semaphore, sizeof(struct open_semaphore_request) },
{ (void(*)())req_create_file, sizeof(struct create_file_request) },
{ (void(*)())req_alloc_file_handle, sizeof(struct alloc_file_handle_request) },
{ (void(*)())req_get_read_fd, sizeof(struct get_read_fd_request) },
{ (void(*)())req_get_write_fd, sizeof(struct get_write_fd_request) },
{ (void(*)())req_set_file_pointer, sizeof(struct set_file_pointer_request) },
......
......@@ -64,31 +64,33 @@ static struct semaphore *create_semaphore( const char *name, size_t len,
return sem;
}
static void release_semaphore( int handle, unsigned int count, unsigned int *prev_count )
static unsigned int release_semaphore( int handle, unsigned int count )
{
struct semaphore *sem;
unsigned int prev = 0;
if (!(sem = (struct semaphore *)get_handle_obj( current->process, handle,
SEMAPHORE_MODIFY_STATE, &semaphore_ops )))
return;
*prev_count = sem->count;
if (sem->count + count < sem->count || sem->count + count > sem->max)
{
set_error( ERROR_TOO_MANY_POSTS );
}
else if (sem->count)
if ((sem = (struct semaphore *)get_handle_obj( current->process, handle,
SEMAPHORE_MODIFY_STATE, &semaphore_ops )))
{
/* there cannot be any thread waiting if the count is != 0 */
assert( !sem->obj.head );
sem->count += count;
}
else
{
sem->count = count;
wake_up( &sem->obj, count );
prev = sem->count;
if (sem->count + count < sem->count || sem->count + count > sem->max)
{
set_error( ERROR_TOO_MANY_POSTS );
}
else if (sem->count)
{
/* there cannot be any thread waiting if the count is != 0 */
assert( !sem->obj.head );
sem->count += count;
}
else
{
sem->count = count;
wake_up( &sem->obj, count );
}
release_object( sem );
}
release_object( sem );
return prev;
}
static void semaphore_dump( struct object *obj, int verbose )
......@@ -118,30 +120,26 @@ static int semaphore_satisfied( struct object *obj, struct thread *thread )
/* create a semaphore */
DECL_HANDLER(create_semaphore)
{
size_t len = get_req_strlen();
struct create_semaphore_reply *reply = push_reply_data( current, sizeof(*reply) );
size_t len = get_req_strlen( req->name );
struct semaphore *sem;
if ((sem = create_semaphore( get_req_data( len + 1 ), len, req->initial, req->max )))
req->handle = -1;
if ((sem = create_semaphore( req->name, len, req->initial, req->max )))
{
reply->handle = alloc_handle( current->process, sem, SEMAPHORE_ALL_ACCESS, req->inherit );
req->handle = alloc_handle( current->process, sem, SEMAPHORE_ALL_ACCESS, req->inherit );
release_object( sem );
}
else reply->handle = -1;
}
/* open a handle to a semaphore */
DECL_HANDLER(open_semaphore)
{
size_t len = get_req_strlen();
struct open_semaphore_reply *reply = push_reply_data( current, sizeof(*reply) );
reply->handle = open_object( get_req_data( len + 1 ), len, &semaphore_ops,
req->access, req->inherit );
size_t len = get_req_strlen( req->name );
req->handle = open_object( req->name, len, &semaphore_ops, req->access, req->inherit );
}
/* release a semaphore */
DECL_HANDLER(release_semaphore)
{
struct release_semaphore_reply *reply = push_reply_data( current, sizeof(*reply) );
release_semaphore( req->handle, req->count, &reply->prev_count );
req->prev_count = release_semaphore( req->handle, req->count );
}
......@@ -64,31 +64,25 @@ static struct snapshot *create_snapshot( int flags )
}
/* get the next process in the snapshot */
static int snapshot_next_process( int handle, int reset, struct next_process_reply *reply )
static int snapshot_next_process( struct snapshot *snapshot, struct next_process_request *req )
{
struct snapshot *snapshot;
struct process_snapshot *ptr;
if (!(snapshot = (struct snapshot *)get_handle_obj( current->process, handle,
0, &snapshot_ops )))
return 0;
if (!snapshot->process_count)
{
set_error( ERROR_INVALID_PARAMETER ); /* FIXME */
release_object( snapshot );
return 0;
}
if (reset) snapshot->process_pos = 0;
if (req->reset) snapshot->process_pos = 0;
else if (snapshot->process_pos >= snapshot->process_count)
{
set_error( ERROR_NO_MORE_FILES );
release_object( snapshot );
return 0;
}
ptr = &snapshot->process[snapshot->process_pos++];
reply->pid = ptr->process;
reply->threads = ptr->threads;
reply->priority = ptr->priority;
release_object( snapshot );
req->pid = ptr->process;
req->threads = ptr->threads;
req->priority = ptr->priority;
return 1;
}
......@@ -117,19 +111,24 @@ static void snapshot_destroy( struct object *obj )
DECL_HANDLER(create_snapshot)
{
struct snapshot *snapshot;
struct create_snapshot_reply *reply = push_reply_data( current, sizeof(*reply) );
req->handle = -1;
if ((snapshot = create_snapshot( req->flags )))
{
reply->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
req->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
release_object( snapshot );
}
else reply->handle = -1;
}
/* get the next process from a snapshot */
DECL_HANDLER(next_process)
{
struct next_process_reply *reply = push_reply_data( current, sizeof(*reply) );
snapshot_next_process( req->handle, req->reset, reply );
struct snapshot *snapshot;
if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
0, &snapshot_ops )))
{
snapshot_next_process( snapshot, req );
release_object( snapshot );
}
}
......@@ -30,139 +30,102 @@
struct client
{
struct select_user select; /* select user */
unsigned int seq; /* current sequence number */
unsigned int res; /* current result to send */
int pass_fd; /* fd to pass to and from the client */
struct thread *self; /* client thread (opaque pointer) */
struct timeout_user *timeout; /* current timeout (opaque pointer) */
};
/* exit code passed to remove_client */
#define OUT_OF_MEMORY -1
#define BROKEN_PIPE -2
#define PROTOCOL_ERROR -3
/* signal a client protocol error */
static void protocol_error( struct client *client, const char *err, ... )
/* socket communication static structures */
static struct iovec iovec;
static struct msghdr msghdr = { NULL, 0, &iovec, 1, };
#ifndef HAVE_MSGHDR_ACCRIGHTS
struct cmsg_fd
{
va_list args;
int len; /* sizeof structure */
int level; /* SOL_SOCKET */
int type; /* SCM_RIGHTS */
int fd; /* fd to pass */
};
static struct cmsg_fd cmsg = { sizeof(cmsg), SOL_SOCKET, SCM_RIGHTS, -1 };
#endif /* HAVE_MSGHDR_ACCRIGHTS */
va_start( args, err );
fprintf( stderr, "Protocol error:%p: ", client->self );
vfprintf( stderr, err, args );
va_end( args );
remove_client( client, PROTOCOL_ERROR );
}
/* send a message to a client that is ready to receive something */
static void do_write( struct client *client )
static int do_write( struct client *client )
{
int ret;
if (client->pass_fd == -1)
{
ret = write( client->select.fd, &client->seq, sizeof(client->seq) );
ret = write( client->select.fd, &client->res, sizeof(client->res) );
if (ret == sizeof(client->res)) goto ok;
}
else /* we have an fd to send */
{
struct iovec vec;
struct msghdr msghdr;
#ifdef HAVE_MSGHDR_ACCRIGHTS
msghdr.msg_accrightslen = sizeof(int);
msghdr.msg_accrights = (void *)&client->pass_fd;
msghdr.msg_accrightslen = sizeof(client->pass_fd);
#else /* HAVE_MSGHDR_ACCRIGHTS */
struct cmsg_fd cmsg;
cmsg.len = sizeof(cmsg);
cmsg.level = SOL_SOCKET;
cmsg.type = SCM_RIGHTS;
cmsg.fd = client->pass_fd;
msghdr.msg_control = &cmsg;
msghdr.msg_controllen = sizeof(cmsg);
msghdr.msg_flags = 0;
cmsg.fd = client->pass_fd;
#endif /* HAVE_MSGHDR_ACCRIGHTS */
msghdr.msg_name = NULL;
msghdr.msg_namelen = 0;
msghdr.msg_iov = &vec;
msghdr.msg_iovlen = 1;
vec.iov_base = (char *)&client->seq;
vec.iov_len = sizeof(client->seq);
iovec.iov_base = (char *)&client->res;
iovec.iov_len = sizeof(client->res);
ret = sendmsg( client->select.fd, &msghdr, 0 );
close( client->pass_fd );
client->pass_fd = -1;
}
if (ret == sizeof(client->seq))
{
/* everything OK */
client->seq++;
set_select_events( &client->select, READ_EVENT );
return;
if (ret == sizeof(client->res)) goto ok;
}
if (ret == -1)
{
if (errno == EWOULDBLOCK) return 0; /* not a fatal error */
if (errno != EPIPE) perror("sendmsg");
remove_client( client, BROKEN_PIPE );
return;
}
fprintf( stderr, "Partial sequence sent (%d)\n", ret );
else fprintf( stderr, "Partial message sent %d/%d\n", ret, sizeof(client->res) );
remove_client( client, BROKEN_PIPE );
return 0;
ok:
set_select_events( &client->select, READ_EVENT );
return 1;
}
/* read a message from a client that has something to say */
static void do_read( struct client *client )
{
struct iovec vec;
int ret, seq;
int ret;
enum request req;
#ifdef HAVE_MSGHDR_ACCRIGHTS
struct msghdr msghdr;
msghdr.msg_accrights = (void *)&client->pass_fd;
msghdr.msg_accrightslen = sizeof(client->pass_fd);
msghdr.msg_accrightslen = sizeof(int);
msghdr.msg_accrights = (void *)&client->pass_fd;
#else /* HAVE_MSGHDR_ACCRIGHTS */
struct msghdr msghdr;
struct cmsg_fd cmsg;
cmsg.len = sizeof(cmsg);
cmsg.level = SOL_SOCKET;
cmsg.type = SCM_RIGHTS;
cmsg.fd = -1;
msghdr.msg_control = &cmsg;
msghdr.msg_controllen = sizeof(cmsg);
msghdr.msg_flags = 0;
cmsg.fd = -1;
#endif /* HAVE_MSGHDR_ACCRIGHTS */
assert( client->pass_fd == -1 );
msghdr.msg_name = NULL;
msghdr.msg_namelen = 0;
msghdr.msg_iov = &vec;
msghdr.msg_iovlen = 1;
vec.iov_base = &seq;
vec.iov_len = sizeof(seq);
iovec.iov_base = &req;
iovec.iov_len = sizeof(req);
ret = recvmsg( client->select.fd, &msghdr, 0 );
#ifndef HAVE_MSGHDR_ACCRIGHTS
client->pass_fd = cmsg.fd;
#endif
if (ret == sizeof(seq))
if (ret == sizeof(req))
{
int pass_fd = client->pass_fd;
if (seq != client->seq++)
{
protocol_error( client, "bad sequence %08x instead of %08x\n",
seq, client->seq - 1 );
return;
}
client->pass_fd = -1;
call_req_handler( client->self, pass_fd );
call_req_handler( client->self, req, pass_fd );
if (pass_fd != -1) close( pass_fd );
return;
}
......@@ -177,7 +140,7 @@ static void do_read( struct client *client )
remove_client( client, BROKEN_PIPE );
return;
}
protocol_error( client, "partial sequence received %d/%d\n", ret, sizeof(seq) );
fatal_protocol_error( client->self, "partial message received %d/%d\n", ret, sizeof(req) );
}
/* handle a client event */
......@@ -204,7 +167,6 @@ struct client *add_client( int fd, struct thread *self )
client->select.fd = fd;
client->select.func = client_event;
client->select.private = client;
client->seq = 0;
client->self = self;
client->timeout = NULL;
client->pass_fd = -1;
......@@ -237,8 +199,9 @@ void client_pass_fd( struct client *client, int pass_fd )
}
/* send a reply to a client */
void client_reply( struct client *client )
void client_reply( struct client *client, unsigned int res )
{
if (debug_level) trace_reply( client->self, client->pass_fd );
set_select_events( &client->select, WRITE_EVENT );
if (debug_level) trace_reply( client->self, res, client->pass_fd );
client->res = res;
if (!do_write( client )) set_select_events( &client->select, WRITE_EVENT );
}
......@@ -84,10 +84,9 @@ static int alloc_client_buffer( struct thread *thread )
int fd;
if ((fd = create_anonymous_file()) == -1) return -1;
if (ftruncate( fd, MAX_MSG_LENGTH ) == -1) goto error;
if ((thread->buffer = mmap( 0, MAX_MSG_LENGTH, PROT_READ | PROT_WRITE,
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->req_pos = thread->reply_pos = thread->buffer;
return fd;
error:
......@@ -123,7 +122,7 @@ static struct thread *create_thread( int fd, struct process *process, int suspen
thread->affinity = 1;
thread->suspend = (suspend != 0);
thread->buffer = (void *)-1;
thread->last_req = 0;
thread->last_req = REQ_GET_THREAD_BUFFER;
if (!first_thread) /* creating the first thread */
{
......@@ -143,7 +142,6 @@ static struct thread *create_thread( int fd, struct process *process, int suspen
close( buf_fd );
goto error;
}
push_reply_data( thread, sizeof(struct header) );
set_reply_fd( thread, buf_fd ); /* send the fd to the client */
send_reply( thread );
return thread;
......@@ -173,7 +171,7 @@ static void destroy_thread( struct object *obj )
if (thread->prev) thread->prev->next = thread->next;
else first_thread = thread->next;
if (thread->apc) free( thread->apc );
if (thread->buffer != (void *)-1) munmap( thread->buffer, MAX_MSG_LENGTH );
if (thread->buffer != (void *)-1) munmap( thread->buffer, MAX_REQUEST_LENGTH );
}
/* dump a thread on stdout for debugging purposes */
......@@ -378,7 +376,7 @@ static int check_wait( struct thread *thread, int *signaled )
/* Wait satisfied: tell it to the object */
*signaled = i;
if (entry->obj->ops->satisfied( entry->obj, thread ))
*signaled += STATUS_ABANDONED_WAIT_0;
*signaled = i + STATUS_ABANDONED_WAIT_0;
return 1;
}
}
......@@ -404,62 +402,48 @@ static int check_wait( struct thread *thread, int *signaled )
return 0;
}
/* build a select reply to wake up the client */
static void build_select_reply( struct thread *thread, int signaled )
{
struct select_reply *reply = push_reply_data( thread, sizeof(*reply) );
reply->signaled = signaled;
if ((signaled == STATUS_USER_APC) && thread->apc)
{
add_reply_data( thread, thread->apc, thread->apc_count * sizeof(*thread->apc) );
free( thread->apc );
thread->apc = NULL;
thread->apc_count = 0;
}
}
/* attempt to wake up a thread */
/* return 1 if OK, 0 if the wait condition is still not satisfied */
static int wake_thread( struct thread *thread )
{
int signaled;
struct select_request *req = get_req_ptr( thread );
if (!check_wait( thread, &signaled )) return 0;
if (!check_wait( thread, &req->signaled )) return 0;
end_wait( thread );
build_select_reply( thread, signaled );
return 1;
}
/* sleep on a list of objects */
static void sleep_on( struct thread *thread, int count, int *handles, int flags, int timeout )
{
struct select_request *req;
assert( !thread->wait );
if (!wait_on( thread, count, handles, flags, timeout ))
{
build_select_reply( thread, -1 );
return;
}
if (!wait_on( thread, count, handles, flags, timeout )) goto error;
if (wake_thread( thread )) return;
/* now we need to wait */
if (flags & SELECT_TIMEOUT)
{
if (!(thread->wait->user = add_timeout_user( &thread->wait->timeout,
call_timeout_handler, thread )))
{
build_select_reply( thread, -1 );
return;
}
goto error;
}
thread->state = SLEEPING;
return;
error:
req = get_req_ptr( thread );
req->signaled = -1;
}
/* timeout for the current thread */
void thread_timeout(void)
{
struct select_request *req = get_req_ptr( current );
assert( current->wait );
current->wait->user = NULL;
end_wait( current );
build_select_reply( current, STATUS_TIMEOUT );
req->signaled = STATUS_TIMEOUT;
send_reply( current );
}
......@@ -525,39 +509,40 @@ void thread_killed( struct thread *thread, int exit_code )
/* create a new thread */
DECL_HANDLER(new_thread)
{
struct new_thread_reply reply;
struct thread *thread;
struct process *process;
int new_fd;
if ((process = get_process_from_id( req->pid )))
{
if ((new_fd = dup(fd)) != -1)
if ((fd = dup(fd)) != -1)
{
if ((thread = create_thread( new_fd, process, req->suspend )))
if ((thread = create_thread( fd, process, req->suspend )))
{
reply.tid = thread;
reply.handle = alloc_handle( current->process, thread,
THREAD_ALL_ACCESS, req->inherit );
if (reply.handle == -1) release_object( thread );
req->tid = thread;
if ((req->handle = alloc_handle( current->process, thread,
THREAD_ALL_ACCESS, req->inherit )) == -1)
release_object( thread );
/* else will be released when the thread gets killed */
}
else close( new_fd );
else close( fd );
}
else set_error( ERROR_TOO_MANY_OPEN_FILES );
else file_set_error();
release_object( process );
}
add_reply_data( current, &reply, sizeof(reply) );
}
/* retrieve the thread buffer file descriptor */
DECL_HANDLER(get_thread_buffer)
{
fatal_protocol_error( current, "get_thread_buffer: should never get called directly\n" );
}
/* initialize a new thread */
DECL_HANDLER(init_thread)
{
struct init_thread_reply *reply = push_reply_data( current, sizeof(*reply) );
if (current->state != STARTING)
{
fatal_protocol_error( "init_thread: already running\n" );
fatal_protocol_error( current, "init_thread: already running\n" );
return;
}
current->state = RUNNING;
......@@ -565,8 +550,8 @@ DECL_HANDLER(init_thread)
current->teb = req->teb;
if (current->suspend + current->process->suspend > 0)
kill( current->unix_pid, SIGSTOP );
reply->pid = current->process;
reply->tid = current;
req->pid = current->process;
req->tid = current;
}
/* terminate a thread */
......@@ -585,13 +570,12 @@ DECL_HANDLER(terminate_thread)
DECL_HANDLER(get_thread_info)
{
struct thread *thread;
struct get_thread_info_reply *reply = push_reply_data( current, sizeof(*reply) );
if ((thread = get_thread_from_handle( req->handle, THREAD_QUERY_INFORMATION )))
{
reply->tid = thread;
reply->exit_code = thread->exit_code;
reply->priority = thread->priority;
req->tid = thread;
req->exit_code = thread->exit_code;
req->priority = thread->priority;
release_object( thread );
}
}
......@@ -612,10 +596,10 @@ DECL_HANDLER(set_thread_info)
DECL_HANDLER(suspend_thread)
{
struct thread *thread;
struct suspend_thread_reply *reply = push_reply_data( current, sizeof(*reply) );
if ((thread = get_thread_from_handle( req->handle, THREAD_SUSPEND_RESUME )))
{
reply->count = suspend_thread( thread );
req->count = suspend_thread( thread );
release_object( thread );
}
}
......@@ -624,10 +608,10 @@ DECL_HANDLER(suspend_thread)
DECL_HANDLER(resume_thread)
{
struct thread *thread;
struct resume_thread_reply *reply = push_reply_data( current, sizeof(*reply) );
if ((thread = get_thread_from_handle( req->handle, THREAD_SUSPEND_RESUME )))
{
reply->count = resume_thread( thread );
req->count = resume_thread( thread );
release_object( thread );
}
}
......@@ -635,12 +619,7 @@ DECL_HANDLER(resume_thread)
/* select on a handle list */
DECL_HANDLER(select)
{
if (check_req_data( req->count * sizeof(int) ))
{
sleep_on( current, req->count, get_req_data( req->count * sizeof(int) ),
req->flags, req->timeout );
}
else fatal_protocol_error( "select: bad length" );
sleep_on( current, req->count, req->handles, req->flags, req->timeout );
}
/* queue an APC for a thread */
......@@ -653,3 +632,15 @@ DECL_HANDLER(queue_apc)
release_object( thread );
}
}
/* get list of APC to call */
DECL_HANDLER(get_apcs)
{
if ((req->count = current->apc_count))
{
memcpy( req->apcs, current->apc, current->apc_count * sizeof(*current->apc) );
free( current->apc );
current->apc = NULL;
current->apc_count = 0;
}
}
......@@ -49,9 +49,6 @@ struct thread
int affinity; /* affinity mask */
int suspend; /* suspend count */
void *buffer; /* buffer for communication with the client */
void *req_pos; /* current request position in buffer */
void *req_end; /* ptr to end of current request */
void *reply_pos; /* current reply position in buffer */
enum request last_req; /* last request received (for debugging) */
};
......
......@@ -14,9 +14,7 @@
"unsigned int" => "%08x",
"void*" => "%p",
"time_t" => "%ld",
"char[0]" => "dump_chars",
"int[0]" => "dump_ints",
"void*[0]" => "dump_ptrs"
"char[1]" => "\\\"%s\\\""
);
my @requests = ();
......@@ -31,7 +29,6 @@ my @trace_lines = ();
while (<SERVER>)
{
if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
if (/^struct +(\w+)_reply/) { &DO_REPLY($1); }
}
### Output the dumping function tables
......@@ -92,71 +89,56 @@ REPLACE_IN_FILE( "server/request.h", @request_lines );
sub DO_REQUEST
{
my $name = shift;
my @struct = ();
my @in_struct = ();
my @out_struct = ();
while (<SERVER>)
{
my ($dir, $type, $var);
last if /^};$/;
next if /^{$/;
s!/\*.*\*/!!g;
next if /^\s*$/;
/ *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
my $type = $1 . ($4 || "");
my $var = $3;
die "Unrecognized type $type" unless defined($formats{$type});
push @struct, $type, $var;
/^\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 ($dir =~ /IN/) { push @in_struct, $type, $var; }
if ($dir =~ /OUT/) { push @out_struct, $type, $var; }
}
push @requests, $name;
&DO_DUMP_FUNC( $name . "_request",@struct);
}
### Handle a reply structure definition
sub DO_REPLY
{
my $name = shift;
my @struct = ();
while (<SERVER>)
&DO_DUMP_FUNC( $name, "request", @in_struct);
if ($#out_struct >= 0)
{
last if /^};$/;
next if /^{$/;
s!/\*.*\*/!!g;
next if /^\s*$/;
/ *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
my $type = $1 . ($4 || "");
my $var = $3;
die "Unrecognized type $type" unless defined($formats{$type});
push @struct, $type, $var;
$replies{$name} = 1;
&DO_DUMP_FUNC( $name, "reply", @out_struct);
}
$replies{$name} = 1;
&DO_DUMP_FUNC( $name . "_reply" ,@struct);
}
### Generate a dumping function
sub DO_DUMP_FUNC
{
my $vararg = 0;
my $name = shift;
push @trace_lines, "static int dump_$name( struct $name *req, int len )\n{\n";
my $req = shift;
push @trace_lines, "static void dump_${name}_$req( struct ${name}_request *req )\n{\n";
while ($#_ >= 0)
{
my $type = shift;
my $var = shift;
if ($type =~ /\[0\]$/) # vararg type?
{
$vararg = 1;
push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
push @trace_lines, " return $formats{$type}( req+1, len - (int)sizeof(*req) ) + sizeof(*req);\n";
}
else
if (defined($formats{$type}))
{
push @trace_lines, " fprintf( stderr, \" $var=$formats{$type}";
push @trace_lines, "," if ($#_ > 0);
push @trace_lines, "\", ";
push @trace_lines, "req->$var );\n";
}
else # must be some varargs format
{
push @trace_lines, " fprintf( stderr, \" $var=\" );\n";
push @trace_lines, " dump_varargs_${name}( req );\n";
}
}
push @trace_lines, " return (int)sizeof(*req);\n" unless $vararg;
push @trace_lines, "}\n\n";
}
......
......@@ -285,20 +285,16 @@ HANDLE DEVICE_Open( LPCSTR filename, DWORD access,
static const struct VxDInfo *DEVICE_GetInfo( HANDLE handle )
{
struct get_file_info_request req;
struct get_file_info_reply reply;
req.handle = handle;
CLIENT_SendRequest( REQ_GET_FILE_INFO, -1, 1, &req, sizeof(req) );
if (!CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) &&
(reply.type == FILE_TYPE_UNKNOWN) &&
(reply.attr & 0x10000))
struct get_file_info_request *req = get_req_buffer();
req->handle = handle;
if (!server_call( REQ_GET_FILE_INFO ) &&
(req->type == FILE_TYPE_UNKNOWN) &&
(req->attr & 0x10000))
{
const struct VxDInfo *info;
for (info = VxDList; info->name; info++)
if (info->id == LOWORD(reply.attr)) break;
return info;
if (info->id == LOWORD(req->attr)) return info;
}
return NULL;
}
......
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