Commit 8081e5a1 authored by Alexandre Julliard's avatar Alexandre Julliard

Added handle_t type to server interface so that we can make handles

pointers later on. Always use 0 to signal invalid handle in server requests.
parent 980eeecf
......@@ -44,7 +44,6 @@ HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -84,7 +83,6 @@ HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -121,7 +119,6 @@ HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -149,7 +146,6 @@ HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -271,7 +267,6 @@ HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -300,7 +295,6 @@ HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -333,7 +327,6 @@ HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -361,7 +354,6 @@ HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -423,7 +415,6 @@ HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max,
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -464,7 +455,6 @@ HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -492,7 +482,6 @@ HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -519,7 +508,6 @@ HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......
......@@ -212,6 +212,7 @@ HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
ret = req->handle;
}
SERVER_END_REQ;
if (!ret) ret = INVALID_HANDLE_VALUE;
return ret;
}
......
......@@ -107,7 +107,6 @@ NTSTATUS WINAPI NtOpenKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTR
if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
if (!retkey) return STATUS_INVALID_PARAMETER;
*retkey = 0;
SERVER_START_REQ
{
......@@ -115,7 +114,8 @@ NTSTATUS WINAPI NtOpenKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTR
req->parent = attr->RootDirectory;
req->access = access;
memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len );
if (!(ret = server_call_noerr( REQ_OPEN_KEY ))) *retkey = req->hkey;
ret = server_call_noerr( REQ_OPEN_KEY );
*retkey = req->hkey;
}
SERVER_END_REQ;
return ret;
......
......@@ -36,8 +36,6 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
if ((MaximumCount <= 0) || (InitialCount < 0) || (InitialCount > MaximumCount))
return STATUS_INVALID_PARAMETER;
*SemaphoreHandle = 0;
SERVER_START_REQ
{
struct create_semaphore_request *req = server_alloc_req( sizeof(*req), len );
......@@ -45,8 +43,8 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT PHANDLE SemaphoreHandle,
req->max = MaximumCount;
req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len );
if (!(ret = server_call_noerr( REQ_CREATE_SEMAPHORE )))
*SemaphoreHandle = req->handle;
ret = server_call_noerr( REQ_CREATE_SEMAPHORE );
*SemaphoreHandle = req->handle;
}
SERVER_END_REQ;
return ret;
......@@ -62,16 +60,14 @@ NTSTATUS WINAPI NtOpenSemaphore( OUT PHANDLE SemaphoreHandle,
DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
NTSTATUS ret;
*SemaphoreHandle = 0;
SERVER_START_REQ
{
struct open_semaphore_request *req = server_alloc_req( sizeof(*req), len );
req->access = access;
req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len );
if (!(ret = server_call_noerr( REQ_OPEN_SEMAPHORE )))
*SemaphoreHandle = req->handle;
ret = server_call_noerr( REQ_OPEN_SEMAPHORE );
*SemaphoreHandle = req->handle;
}
SERVER_END_REQ;
return ret;
......@@ -129,8 +125,6 @@ NTSTATUS WINAPI NtCreateEvent(
DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
NTSTATUS ret;
*EventHandle = 0;
SERVER_START_REQ
{
struct create_event_request *req = server_alloc_req( sizeof(*req), len );
......@@ -138,7 +132,8 @@ NTSTATUS WINAPI NtCreateEvent(
req->initial_state = InitialState;
req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len );
if (!(ret = server_call_noerr( REQ_CREATE_EVENT ))) *EventHandle = req->handle;
ret = server_call_noerr( REQ_CREATE_EVENT );
*EventHandle = req->handle;
}
SERVER_END_REQ;
return ret;
......@@ -155,8 +150,6 @@ NTSTATUS WINAPI NtOpenEvent(
DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
NTSTATUS ret;
*EventHandle = 0;
SERVER_START_REQ
{
struct open_event_request *req = server_alloc_req( sizeof(*req), len );
......@@ -164,7 +157,8 @@ NTSTATUS WINAPI NtOpenEvent(
req->access = DesiredAccess;
req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
if (len) memcpy( server_data_ptr(req), attr->ObjectName->Buffer, len );
if (!(ret = server_call_noerr( REQ_OPEN_EVENT ))) *EventHandle = req->handle;
ret = server_call_noerr( REQ_OPEN_EVENT );
*EventHandle = req->handle;
}
SERVER_END_REQ;
return ret;
......
......@@ -818,10 +818,10 @@ SOCKET WINAPI WSOCK32_accept(SOCKET s, struct sockaddr *addr,
req->access = GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE;
req->inherit = TRUE;
sock_server_call( REQ_ACCEPT_SOCKET );
as = req->handle;
as = (SOCKET)req->handle;
}
SERVER_END_REQ;
if( ((int)as) >= 0 )
if (as)
{
unsigned omask = _get_sock_mask( s );
int fd = _get_sock_fd( as );
......@@ -2223,10 +2223,10 @@ SOCKET WINAPI WSOCK32_socket(INT af, INT type, INT protocol)
req->access = GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE;
req->inherit = TRUE;
sock_server_call( REQ_CREATE_SOCKET );
ret = req->handle;
ret = (SOCKET)req->handle;
}
SERVER_END_REQ;
if ( ((int) ret) >= 0)
if (ret)
{
TRACE("\tcreated %04x\n", ret );
return ret;
......
......@@ -697,7 +697,7 @@ const DOS_DEVICE *DOSFS_GetDeviceByHandle( HFILE hFile )
*/
static HANDLE DOSFS_CreateCommPort(LPCSTR name, DWORD access)
{
HANDLE ret = INVALID_HANDLE_VALUE;
HANDLE ret;
char devname[40];
TRACE("%s %lx\n", name, access);
......@@ -718,7 +718,8 @@ static HANDLE DOSFS_CreateCommPort(LPCSTR name, DWORD access)
req->sharing = FILE_SHARE_READ|FILE_SHARE_WRITE;
memcpy( server_data_ptr(req), devname, len );
SetLastError(0);
if (!(server_call( REQ_CREATE_SERIAL ))) ret = req->handle;
server_call( REQ_CREATE_SERIAL );
ret = req->handle;
}
SERVER_END_REQ;
......@@ -730,14 +731,14 @@ static HANDLE DOSFS_CreateCommPort(LPCSTR name, DWORD access)
* DOSFS_OpenDevice
*
* Open a DOS device. This might not map 1:1 into the UNIX device concept.
* Returns 0 on failure.
*/
HFILE DOSFS_OpenDevice( const char *name, DWORD access )
HANDLE DOSFS_OpenDevice( const char *name, DWORD access )
{
int i;
const char *p;
HFILE handle;
HANDLE handle;
if (!name) return (HFILE)NULL; /* if FILE_DupUnixHandle was used */
if (name[0] && (name[1] == ':')) name += 2;
if ((p = strrchr( name, '/' ))) name = p + 1;
if ((p = strrchr( name, '\\' ))) name = p + 1;
......@@ -752,9 +753,9 @@ HFILE DOSFS_OpenDevice( const char *name, DWORD access )
if (!strcmp(DOSFS_Devices[i].name,"NUL"))
return FILE_CreateFile( "/dev/null", access,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, -1, TRUE );
OPEN_EXISTING, 0, 0, TRUE );
if (!strcmp(DOSFS_Devices[i].name,"CON")) {
HFILE to_dup;
HANDLE to_dup;
switch (access & (GENERIC_READ|GENERIC_WRITE)) {
case GENERIC_READ:
to_dup = GetStdHandle( STD_INPUT_HANDLE );
......@@ -764,12 +765,11 @@ HFILE DOSFS_OpenDevice( const char *name, DWORD access )
break;
default:
FIXME("can't open CON read/write\n");
return HFILE_ERROR;
break;
return 0;
}
if (!DuplicateHandle( GetCurrentProcess(), to_dup, GetCurrentProcess(),
&handle, 0, FALSE, DUPLICATE_SAME_ACCESS ))
handle = HFILE_ERROR;
handle = 0;
return handle;
}
if (!strcmp(DOSFS_Devices[i].name,"SCSIMGR$") ||
......@@ -782,11 +782,11 @@ HFILE DOSFS_OpenDevice( const char *name, DWORD access )
return handle;
FIXME("device open %s not supported (yet)\n",DOSFS_Devices[i].name);
return HFILE_ERROR;
return 0;
}
}
}
return HFILE_ERROR;
return 0;
}
......
......@@ -181,7 +181,7 @@ void FILE_SetDosError(void)
*
* Duplicate a Unix handle into a task handle.
*/
HFILE FILE_DupUnixHandle( int fd, DWORD access )
HANDLE FILE_DupUnixHandle( int fd, DWORD access )
{
struct alloc_file_handle_request *req = get_req_buffer();
req->access = access;
......@@ -219,10 +219,11 @@ int FILE_GetUnixHandle( HANDLE handle, DWORD access )
* FILE_OpenConsole
*
* Open a handle to the current process console.
* Returns 0 on failure.
*/
static HANDLE FILE_OpenConsole( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES sa )
{
int ret = -1;
HANDLE ret;
SERVER_START_REQ
{
......@@ -232,7 +233,8 @@ static HANDLE FILE_OpenConsole( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES
req->access = access;
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
SetLastError(0);
if (!server_call( REQ_OPEN_CONSOLE )) ret = req->handle;
server_call( REQ_OPEN_CONSOLE );
ret = req->handle;
}
SERVER_END_REQ;
return ret;
......@@ -243,6 +245,7 @@ static HANDLE FILE_OpenConsole( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES
* FILE_CreateFile
*
* Implementation of CreateFile. Takes a Unix path name.
* Returns 0 on failure.
*/
HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
LPSECURITY_ATTRIBUTES sa, DWORD creation,
......@@ -256,7 +259,7 @@ HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
{
FIXME("filename '%s' too long\n", filename );
SetLastError( ERROR_INVALID_PARAMETER );
return -1;
return 0;
}
restart:
......@@ -277,7 +280,7 @@ HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
/* If write access failed, retry without GENERIC_WRITE */
if ((ret == -1) && !fail_read_only && (access & GENERIC_WRITE))
if (!ret && !fail_read_only && (access & GENERIC_WRITE))
{
if ((err == STATUS_MEDIA_WRITE_PROTECTED) || (err == STATUS_ACCESS_DENIED))
{
......@@ -288,7 +291,7 @@ HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
}
}
if (ret == -1)
if (!ret)
WARN("Unable to create file '%s' (GLE %ld)\n", filename,
GetLastError());
......@@ -300,10 +303,11 @@ HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
* FILE_CreateDevice
*
* Same as FILE_CreateFile but for a device
* Returns 0 on failure.
*/
HFILE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa )
HANDLE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa )
{
HFILE ret;
HANDLE ret;
SERVER_START_REQ
{
struct create_device_request *req = server_alloc_req( sizeof(*req), 0 );
......@@ -353,11 +357,12 @@ HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing,
DWORD attributes, HANDLE template )
{
DOS_FULL_NAME full_name;
HANDLE ret;
if (!filename)
{
SetLastError( ERROR_INVALID_PARAMETER );
return HFILE_ERROR;
return INVALID_HANDLE_VALUE;
}
TRACE("%s %s%s%s%s%s%s%s\n",filename,
((access & GENERIC_READ)==GENERIC_READ)?"GENERIC_READ ":"",
......@@ -380,13 +385,16 @@ HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing,
{
FIXME("UNC name (%s) not supported.\n", filename );
SetLastError( ERROR_PATH_NOT_FOUND );
return HFILE_ERROR;
return INVALID_HANDLE_VALUE;
}
}
if (!strncmp(filename, "\\\\.\\", 4)) {
if (!DOSFS_GetDevice( filename ))
return DEVICE_Open( filename+4, access, sa );
{
ret = DEVICE_Open( filename+4, access, sa );
goto done;
}
else
filename+=4; /* fall into DOSFS_Device case below */
}
......@@ -396,30 +404,36 @@ HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing,
{
FIXME("UNC name (%s) not supported.\n", filename );
SetLastError( ERROR_PATH_NOT_FOUND );
return HFILE_ERROR;
return INVALID_HANDLE_VALUE;
}
/* If the name contains a DOS wild card (* or ?), do no create a file */
if(strchr(filename,'*') || strchr(filename,'?'))
return HFILE_ERROR;
return INVALID_HANDLE_VALUE;
/* Open a console for CONIN$ or CONOUT$ */
if (!strcasecmp(filename, "CONIN$")) return FILE_OpenConsole( FALSE, access, sa );
if (!strcasecmp(filename, "CONOUT$")) return FILE_OpenConsole( TRUE, access, sa );
if (!strcasecmp(filename, "CONIN$"))
{
ret = FILE_OpenConsole( FALSE, access, sa );
goto done;
}
if (!strcasecmp(filename, "CONOUT$"))
{
ret = FILE_OpenConsole( TRUE, access, sa );
goto done;
}
if (DOSFS_GetDevice( filename ))
{
HFILE ret;
TRACE("opening device '%s'\n", filename );
if (HFILE_ERROR!=(ret=DOSFS_OpenDevice( filename, access )))
return ret;
/* Do not silence this please. It is a critical error. -MM */
ERR("Couldn't open device '%s'!\n",filename);
SetLastError( ERROR_FILE_NOT_FOUND );
return HFILE_ERROR;
if (!(ret = DOSFS_OpenDevice( filename, access )))
{
/* Do not silence this please. It is a critical error. -MM */
ERR("Couldn't open device '%s'!\n",filename);
SetLastError( ERROR_FILE_NOT_FOUND );
}
goto done;
}
/* check for filename, don't check for last entry if creating */
......@@ -429,12 +443,15 @@ HANDLE WINAPI CreateFileA( LPCSTR filename, DWORD access, DWORD sharing,
&full_name )) {
WARN("Unable to get full filename from '%s' (GLE %ld)\n",
filename, GetLastError());
return HFILE_ERROR;
return INVALID_HANDLE_VALUE;
}
return FILE_CreateFile( full_name.long_name, access, sharing,
sa, creation, attributes, template,
DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY );
ret = FILE_CreateFile( full_name.long_name, access, sharing,
sa, creation, attributes, template,
DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY );
done:
if (!ret) ret = INVALID_HANDLE_VALUE;
return ret;
}
......@@ -877,9 +894,9 @@ found:
}
hFileRet = FILE_CreateFile( full_name.long_name, access, sharing,
NULL, OPEN_EXISTING, 0, -1,
NULL, OPEN_EXISTING, 0, 0,
DRIVE_GetFlags(full_name.drive) & DRIVE_FAIL_READ_ONLY );
if (hFileRet == HFILE_ERROR) goto not_found;
if (!hFileRet) goto not_found;
GetFileTime( hFileRet, NULL, NULL, &filetime );
FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] );
......
......@@ -46,15 +46,14 @@ inline static char FILE_toupper( char c )
extern int FILE_strcasecmp( const char *str1, const char *str2 );
extern int FILE_strncasecmp( const char *str1, const char *str2, int len );
extern void FILE_SetDosError(void);
extern HFILE FILE_DupUnixHandle( int fd, DWORD access );
extern HANDLE FILE_DupUnixHandle( int fd, DWORD access );
extern int FILE_GetUnixHandle( HANDLE handle, DWORD access );
extern BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info );
extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 );
extern HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
LPSECURITY_ATTRIBUTES sa, DWORD creation,
DWORD attributes, HANDLE template, BOOL fail_read_only );
extern HFILE FILE_CreateDevice( int client_id, DWORD access,
LPSECURITY_ATTRIBUTES sa );
extern HANDLE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa );
extern LONG WINAPI WIN16_hread(HFILE16,SEGPTR,LONG);
......@@ -72,7 +71,7 @@ extern time_t DOSFS_FileTimeToUnixTime( const FILETIME *ft, DWORD *remainder );
extern BOOL DOSFS_ToDosFCBFormat( LPCSTR name, LPSTR buffer );
extern const DOS_DEVICE *DOSFS_GetDevice( const char *name );
extern const DOS_DEVICE *DOSFS_GetDeviceByHandle( HFILE hFile );
extern HFILE DOSFS_OpenDevice( const char *name, DWORD access );
extern HANDLE DOSFS_OpenDevice( const char *name, DWORD access );
extern BOOL DOSFS_FindUnixName( LPCSTR path, LPCSTR name, LPSTR long_buf,
INT long_len, LPSTR short_buf,
BOOL ignore_case );
......
......@@ -219,7 +219,7 @@ extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
extern WINE_MODREF *PE_LoadLibraryExA(LPCSTR, DWORD);
extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
DWORD flags, HFILE hFile, BOOL builtin );
DWORD flags, HANDLE hFile, BOOL builtin );
extern void PE_InitTls(void);
extern BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved );
......@@ -255,7 +255,7 @@ extern int BUILTIN32_dlclose( void *handle );
/* scheduler/process.c */
extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule );
extern BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
extern BOOL PROCESS_Create( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags,
STARTUPINFOA *startup, PROCESS_INFORMATION *info,
......
......@@ -164,7 +164,7 @@ WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags)
SNOOP_RegisterDLL(hmod,libname,STUBSIZE/sizeof(ELF_STDCALL_STUB));
wm = PE_CreateModule( hmod, libname, 0, -1, FALSE );
wm = PE_CreateModule( hmod, libname, 0, 0, FALSE );
wm->find_export = ELF_FindExportedFunction;
wm->dlhandle = dlhandle;
return wm;
......
......@@ -1089,7 +1089,7 @@ BOOL WINAPI CreateProcessA( LPCSTR lpApplicationName, LPSTR lpCommandLine,
if ( !MODULE_GetBinaryType( hFile, name, &type ) )
{
CloseHandle( hFile );
retv = PROCESS_Create( -1, name, tidy_cmdline, lpEnvironment,
retv = PROCESS_Create( 0, name, tidy_cmdline, lpEnvironment,
lpProcessAttributes, lpThreadAttributes,
bInheritHandles, dwCreationFlags,
lpStartupInfo, lpProcessInfo, lpCurrentDirectory );
......
......@@ -1019,7 +1019,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
TDB *pTask;
LPSTR cmdline;
WORD cmdShow;
HANDLE hThread = -1;
HANDLE hThread = 0;
int socket = -1;
/* Load module */
......@@ -1074,7 +1074,7 @@ HINSTANCE16 WINAPI LoadModule16( LPCSTR name, LPVOID paramBlock )
}
}
SERVER_END_REQ;
if (hThread == -1) return 0;
if (!hThread) return 0;
if (!(teb = THREAD_Create( socket, 0, FALSE ))) goto error;
teb->tibflags &= ~TEBF_WIN32;
......
......@@ -533,7 +533,7 @@ HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags )
* Note: Assumes that the process critical section is held
*/
WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags,
HFILE hFile, BOOL builtin )
HANDLE hFile, BOOL builtin )
{
DWORD load_addr = (DWORD)hModule; /* for RVA */
IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
......
......@@ -494,7 +494,7 @@ static LPVOID map_image( HANDLE hmapping, int fd, char *base, DWORD total_size,
{
if ((shared_fd = FILE_GetUnixHandle( shared_file, GENERIC_READ )) == -1) goto error;
CloseHandle( shared_file ); /* we no longer need it */
shared_file = INVALID_HANDLE_VALUE;
shared_file = 0;
}
/* map all the sections */
......@@ -571,7 +571,7 @@ static LPVOID map_image( HANDLE hmapping, int fd, char *base, DWORD total_size,
if (view) VIRTUAL_DeleteView( view );
close( fd );
if (shared_fd != -1) close( shared_fd );
if (shared_file != INVALID_HANDLE_VALUE) CloseHandle( shared_file );
if (shared_file) CloseHandle( shared_file );
return NULL;
}
......@@ -1295,6 +1295,7 @@ HANDLE WINAPI CreateFileMappingA(
/* Create the server object */
if (hFile == INVALID_HANDLE_VALUE) hFile = 0;
SERVER_START_REQ
{
struct create_mapping_request *req = server_alloc_req( sizeof(*req),
......@@ -1310,7 +1311,6 @@ HANDLE WINAPI CreateFileMappingA(
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -1353,6 +1353,7 @@ HANDLE WINAPI CreateFileMappingW( HANDLE hFile, LPSECURITY_ATTRIBUTES sa,
/* Create the server object */
if (hFile == INVALID_HANDLE_VALUE) hFile = 0;
SERVER_START_REQ
{
struct create_mapping_request *req = server_alloc_req( sizeof(*req),
......@@ -1368,7 +1369,6 @@ HANDLE WINAPI CreateFileMappingW( HANDLE hFile, LPSECURITY_ATTRIBUTES sa,
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -1404,7 +1404,6 @@ HANDLE WINAPI OpenFileMappingA(
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -1433,7 +1432,6 @@ HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name)
ret = req->handle;
}
SERVER_END_REQ;
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......
......@@ -1184,7 +1184,7 @@ static void load_wine_registry(HKEY hkey,LPCSTR fn)
case WINE_REG_VER_2: {
HANDLE file;
if ((file = FILE_CreateFile( fn, GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, -1, TRUE )) != INVALID_HANDLE_VALUE)
FILE_ATTRIBUTE_NORMAL, 0, TRUE )))
{
SERVER_START_REQ
{
......
......@@ -88,7 +88,7 @@ static void load_library( void *base, const char *filename )
MESSAGE( "Warning: loading builtin %s, but native version already present. Expect trouble.\n", filename );
/* Create 32-bit MODREF */
if (!(wm = PE_CreateModule( module, filename, 0, -1, TRUE )))
if (!(wm = PE_CreateModule( module, filename, 0, 0, TRUE )))
{
ERR( "can't load %s\n", filename );
SetLastError( ERROR_OUTOFMEMORY );
......
......@@ -602,15 +602,15 @@ int CLIENT_InitThread(void)
/* ignore SIGPIPE so that we get a EPIPE error instead */
signal( SIGPIPE, SIG_IGN );
teb->request_fd = wine_server_recv_fd( -1, 0 );
teb->request_fd = wine_server_recv_fd( 0, 0 );
if (teb->request_fd == -1) server_protocol_error( "no request fd passed on first request\n" );
fcntl( teb->request_fd, F_SETFD, 1 ); /* set close on exec flag */
teb->reply_fd = wine_server_recv_fd( -1, 0 );
teb->reply_fd = wine_server_recv_fd( 0, 0 );
if (teb->reply_fd == -1) server_protocol_error( "no reply fd passed on first request\n" );
fcntl( teb->reply_fd, F_SETFD, 1 ); /* set close on exec flag */
fd = wine_server_recv_fd( -1, 0 );
fd = wine_server_recv_fd( 0, 0 );
if (fd == -1) server_protocol_error( "no fd received for thread buffer\n" );
if ((size = lseek( fd, 0, SEEK_END )) == -1) server_perror( "lseek" );
......
......@@ -111,7 +111,7 @@ BOOL WINAPI DuplicateHandle( HANDLE source_process, HANDLE source,
HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
{
HANDLE ret = INVALID_HANDLE_VALUE;
DuplicateHandle( GetCurrentProcess(), hSrc, (HANDLE)-1, &ret, 0, FALSE,
DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
DUP_HANDLE_MAKE_GLOBAL | DUP_HANDLE_SAME_ACCESS | DUP_HANDLE_CLOSE_SOURCE );
return ret;
}
......
......@@ -95,7 +95,7 @@ PDB current_process;
static char **main_exe_argv;
static char main_exe_name[MAX_PATH];
static HANDLE main_exe_file = INVALID_HANDLE_VALUE;
static HANDLE main_exe_file;
unsigned int server_startticks;
......@@ -460,7 +460,7 @@ void PROCESS_InitWine( int argc, char *argv[] )
}
}
if (main_exe_file == INVALID_HANDLE_VALUE)
if (!main_exe_file)
{
if ((main_exe_file = CreateFileA( main_exe_name, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, -1 )) == INVALID_HANDLE_VALUE)
......@@ -484,7 +484,7 @@ void PROCESS_InitWine( int argc, char *argv[] )
current_process.flags |= PDB32_WIN16_PROC;
main_exe_name[0] = 0;
CloseHandle( main_exe_file );
main_exe_file = INVALID_HANDLE_VALUE;
main_exe_file = 0;
_EnterWin16Lock();
found:
......@@ -731,7 +731,7 @@ static int fork_and_exec( const char *filename, char *cmdline,
* file, and we exec a new copy of wine to load it; otherwise we
* simply exec the specified filename as a Unix process.
*/
BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
BOOL PROCESS_Create( HANDLE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
LPPROCESS_INFORMATION info, LPCSTR lpCurrentDirectory )
......@@ -741,9 +741,9 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
const char *unixfilename = NULL;
const char *unixdir = NULL;
DOS_FULL_NAME full_dir, full_name;
HANDLE load_done_evt = (HANDLE)-1;
HANDLE load_done_evt = 0;
info->hThread = info->hProcess = INVALID_HANDLE_VALUE;
info->hThread = info->hProcess = 0;
if (lpCurrentDirectory)
{
......@@ -783,7 +783,7 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
}
req->cmd_show = startup->wShowWindow;
if (hFile == -1) /* unix process */
if (!hFile) /* unix process */
{
unixfilename = filename;
if (DOSFS_GetFullName( filename, TRUE, &full_name ))
......@@ -824,7 +824,7 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
if (!ret || (pid == -1)) goto error;
/* Wait until process is initialized (or initialization failed) */
if (load_done_evt != (HANDLE)-1)
if (load_done_evt)
{
DWORD res;
HANDLE handles[2];
......@@ -845,9 +845,9 @@ BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
return TRUE;
error:
if (load_done_evt != (HANDLE)-1) CloseHandle( load_done_evt );
if (info->hThread != INVALID_HANDLE_VALUE) CloseHandle( info->hThread );
if (info->hProcess != INVALID_HANDLE_VALUE) CloseHandle( info->hProcess );
if (load_done_evt) CloseHandle( load_done_evt );
if (info->hThread) CloseHandle( info->hThread );
if (info->hProcess) CloseHandle( info->hProcess );
return FALSE;
}
......
......@@ -58,7 +58,7 @@ TEB *THREAD_IdToTEB( DWORD id )
SERVER_START_REQ
{
struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 );
req->handle = -1;
req->handle = 0;
req->tid_in = (void *)id;
if (!server_call_noerr( REQ_GET_THREAD_INFO )) ret = req->teb;
}
......@@ -284,7 +284,8 @@ HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
LPTHREAD_START_ROUTINE start, LPVOID param,
DWORD flags, LPDWORD id )
{
int socket = -1, handle = -1;
int socket = -1;
HANDLE handle = 0;
TEB *teb;
void *tid = 0;
......@@ -302,7 +303,7 @@ HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
}
}
SERVER_END_REQ;
if (handle == -1) return 0;
if (!handle) return 0;
if (!(teb = THREAD_Create( socket, stack, TRUE )))
{
......
......@@ -37,7 +37,6 @@ HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR
ret = req->handle;
}
SERVER_END_REQ;
if (ret == INVALID_HANDLE_VALUE) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -66,7 +65,6 @@ HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWST
ret = req->handle;
}
SERVER_END_REQ;
if (ret == INVALID_HANDLE_VALUE) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -94,7 +92,6 @@ HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == INVALID_HANDLE_VALUE) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......@@ -122,7 +119,6 @@ HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
ret = req->handle;
}
SERVER_END_REQ;
if (ret == INVALID_HANDLE_VALUE) ret = 0; /* must return 0 on failure, not -1 */
return ret;
}
......
......@@ -99,7 +99,7 @@ static void async_destroy( struct object *obj )
ov->timeout = NULL;
}
struct async *get_async_obj( struct process *process, int handle, unsigned int access )
struct async *get_async_obj( struct process *process, handle_t handle, unsigned int access )
{
return (struct async *)get_handle_obj( process, handle, access, &async_ops );
}
......@@ -162,7 +162,7 @@ DECL_HANDLER(create_async)
struct async *ov = NULL;
int fd;
req->ov_handle = -1;
req->ov_handle = 0;
if (!(obj = get_handle_obj( current->process, req->file_handle, 0, NULL)) )
return;
......
......@@ -72,7 +72,7 @@ DECL_HANDLER(create_change_notification)
{
struct change *change;
req->handle = -1;
req->handle = 0;
if ((change = create_change_notification( req->subtree, req->filter )))
{
req->handle = alloc_handle( current->process, change,
......
......@@ -167,7 +167,7 @@ int free_console( struct process *process )
return 1;
}
static int set_console_fd( int handle, int fd_in, int fd_out, int pid )
static int set_console_fd( handle_t handle, int fd_in, int fd_out, int pid )
{
struct console_input *input;
struct screen_buffer *output;
......@@ -206,7 +206,7 @@ static int set_console_fd( int handle, int fd_in, int fd_out, int pid )
return 1;
}
static int get_console_mode( int handle )
static int get_console_mode( handle_t handle )
{
struct object *obj;
int ret = 0;
......@@ -224,7 +224,7 @@ static int get_console_mode( int handle )
return ret;
}
static int set_console_mode( int handle, int mode )
static int set_console_mode( handle_t handle, int mode )
{
struct object *obj;
int ret = 0;
......@@ -247,7 +247,7 @@ static int set_console_mode( int handle, int mode )
}
/* set misc console information (output handle only) */
static int set_console_info( int handle, struct set_console_info_request *req,
static int set_console_info( handle_t handle, struct set_console_info_request *req,
const char *title, size_t len )
{
struct screen_buffer *console;
......@@ -275,7 +275,7 @@ static int set_console_info( int handle, struct set_console_info_request *req,
}
/* add input events to a console input queue */
static int write_console_input( int handle, int count, INPUT_RECORD *records )
static int write_console_input( handle_t handle, int count, INPUT_RECORD *records )
{
INPUT_RECORD *new_rec;
struct console_input *console;
......@@ -298,7 +298,7 @@ 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, INPUT_RECORD *rec, int flush )
static int read_console_input( handle_t handle, int count, INPUT_RECORD *rec, int flush )
{
struct console_input *console;
......@@ -409,18 +409,18 @@ static void screen_buffer_destroy( struct object *obj )
/* allocate a console for the current process */
DECL_HANDLER(alloc_console)
{
int in = -1, out = -1;
handle_t in = 0, out = 0;
if (!alloc_console( current->process )) goto done;
if ((in = alloc_handle( current->process, current->process->console_in,
req->access, req->inherit )) != -1)
req->access, req->inherit )))
{
if ((out = alloc_handle( current->process, current->process->console_out,
req->access, req->inherit )) != -1)
req->access, req->inherit )))
goto done; /* everything is fine */
close_handle( current->process, in, NULL );
in = -1;
in = 0;
}
free_console( current->process );
......@@ -440,6 +440,7 @@ DECL_HANDLER(open_console)
{
struct object *obj= req->output ? current->process->console_out : current->process->console_in;
req->handle = 0;
if (obj) req->handle = alloc_handle( current->process, obj, req->access, req->inherit );
else set_error( STATUS_ACCESS_DENIED );
}
......
......@@ -92,11 +92,10 @@ static int fill_create_thread_event( struct debug_event *event, void *arg )
{
struct process *debugger = event->debugger->process;
struct thread *thread = event->sender;
int handle;
handle_t handle;
/* documented: THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME */
if ((handle = alloc_handle( debugger, thread, THREAD_ALL_ACCESS, FALSE )) == -1)
return 0;
if (!(handle = alloc_handle( debugger, thread, THREAD_ALL_ACCESS, FALSE ))) return 0;
event->data.info.create_thread.handle = handle;
event->data.info.create_thread.teb = thread->teb;
event->data.info.create_thread.start = arg;
......@@ -108,25 +107,24 @@ static int fill_create_process_event( struct debug_event *event, void *arg )
struct process *debugger = event->debugger->process;
struct thread *thread = event->sender;
struct process *process = thread->process;
int handle;
handle_t handle;
/* documented: PROCESS_VM_READ | PROCESS_VM_WRITE */
if ((handle = alloc_handle( debugger, process, PROCESS_ALL_ACCESS, FALSE )) == -1)
return 0;
if (!(handle = alloc_handle( debugger, process, PROCESS_ALL_ACCESS, FALSE ))) return 0;
event->data.info.create_process.process = handle;
/* documented: THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME */
if ((handle = alloc_handle( debugger, thread, THREAD_ALL_ACCESS, FALSE )) == -1)
if (!(handle = alloc_handle( debugger, thread, THREAD_ALL_ACCESS, FALSE )))
{
close_handle( debugger, event->data.info.create_process.process, NULL );
return 0;
}
event->data.info.create_process.thread = handle;
handle = -1;
handle = 0;
if (process->exe.file &&
/* the doc says write access too, but this doesn't seem a good idea */
((handle = alloc_handle( debugger, process->exe.file, GENERIC_READ, FALSE )) == -1))
!(handle = alloc_handle( debugger, process->exe.file, GENERIC_READ, FALSE )))
{
close_handle( debugger, event->data.info.create_process.process, NULL );
close_handle( debugger, event->data.info.create_process.thread, NULL );
......@@ -161,9 +159,9 @@ static int fill_load_dll_event( struct debug_event *event, void *arg )
{
struct process *debugger = event->debugger->process;
struct process_dll *dll = arg;
int handle = -1;
handle_t handle = 0;
if (dll->file && (handle = alloc_handle( debugger, dll->file, GENERIC_READ, FALSE )) == -1)
if (dll->file && !(handle = alloc_handle( debugger, dll->file, GENERIC_READ, FALSE )))
return 0;
event->data.info.load_dll.handle = handle;
event->data.info.load_dll.base = dll->base;
......@@ -319,13 +317,13 @@ static void debug_event_destroy( struct object *obj )
close_handle( debugger, event->data.info.create_thread.handle, NULL );
break;
case CREATE_PROCESS_DEBUG_EVENT:
if (event->data.info.create_process.file != -1)
if (event->data.info.create_process.file)
close_handle( debugger, event->data.info.create_process.file, NULL );
close_handle( debugger, event->data.info.create_process.thread, NULL );
close_handle( debugger, event->data.info.create_process.process, NULL );
break;
case LOAD_DLL_DEBUG_EVENT:
if (event->data.info.load_dll.handle != -1)
if (event->data.info.load_dll.handle)
close_handle( debugger, event->data.info.load_dll.handle, NULL );
break;
}
......
......@@ -86,7 +86,7 @@ DECL_HANDLER(create_device)
{
struct device *dev;
req->handle = -1;
req->handle = 0;
if ((dev = create_device( req->id )))
{
req->handle = alloc_handle( current->process, dev, req->access, req->inherit );
......
......@@ -59,7 +59,7 @@ struct event *create_event( const WCHAR *name, size_t len,
return event;
}
struct event *get_event_obj( struct process *process, int handle, unsigned int access )
struct event *get_event_obj( struct process *process, handle_t handle, unsigned int access )
{
return (struct event *)get_handle_obj( process, handle, access, &event_ops );
}
......@@ -115,7 +115,7 @@ DECL_HANDLER(create_event)
{
struct event *event;
req->handle = -1;
req->handle = 0;
if ((event = create_event( get_req_data(req), get_req_data_size(req),
req->manual_reset, req->initial_state )))
{
......
......@@ -320,12 +320,12 @@ void file_set_error(void)
}
}
struct file *get_file_obj( struct process *process, int handle, unsigned int access )
struct file *get_file_obj( struct process *process, handle_t handle, unsigned int access )
{
return (struct file *)get_handle_obj( process, handle, access, &file_ops );
}
static int set_file_pointer( int handle, int *low, int *high, int whence )
static int set_file_pointer( handle_t handle, int *low, int *high, int whence )
{
struct file *file;
int result;
......@@ -354,7 +354,7 @@ static int set_file_pointer( int handle, int *low, int *high, int whence )
return 1;
}
static int truncate_file( int handle )
static int truncate_file( handle_t handle )
{
struct file *file;
int result;
......@@ -370,7 +370,6 @@ static int truncate_file( int handle )
}
release_object( file );
return 1;
}
/* try to grow the file to the specified size */
......@@ -394,7 +393,7 @@ int grow_file( struct file *file, int size_high, int size_low )
return 0;
}
static int set_file_time( int handle, time_t access_time, time_t write_time )
static int set_file_time( handle_t handle, time_t access_time, time_t write_time )
{
struct file *file;
struct utimbuf utimbuf;
......@@ -438,7 +437,7 @@ DECL_HANDLER(create_file)
{
struct file *file;
req->handle = -1;
req->handle = 0;
if ((file = create_file( get_req_data(req), get_req_data_size(req), req->access,
req->sharing, req->create, req->attrs )))
{
......@@ -452,7 +451,7 @@ DECL_HANDLER(alloc_file_handle)
{
struct file *file;
req->handle = -1;
req->handle = 0;
if (current->pass_fd != -1)
{
if ((file = create_file_for_fd( current->pass_fd, req->access,
......
......@@ -42,25 +42,37 @@ static struct handle_table *global_table;
#define RESERVED_CLOSE_PROTECT (HANDLE_FLAG_PROTECT_FROM_CLOSE << RESERVED_SHIFT)
#define RESERVED_ALL (RESERVED_INHERIT | RESERVED_CLOSE_PROTECT)
/* global handle macros */
#define HANDLE_OBFUSCATOR 0x544a4def
#define HANDLE_IS_GLOBAL(h) (((h) ^ HANDLE_OBFUSCATOR) < 0x10000)
#define HANDLE_LOCAL_TO_GLOBAL(h) ((h) ^ HANDLE_OBFUSCATOR)
#define HANDLE_GLOBAL_TO_LOCAL(h) ((h) ^ HANDLE_OBFUSCATOR)
#define MIN_HANDLE_ENTRIES 32
/* handle to table index conversion */
/* handles are a multiple of 4 under NT; handle 0 is not used */
inline static int index_to_handle( int index )
/* handles are a multiple of 4 under NT; handle 0 is not used */
inline static handle_t index_to_handle( int index )
{
return (handle_t)((index + 1) << 2);
}
inline static int handle_to_index( handle_t handle )
{
return ((unsigned int)handle >> 2) - 1;
}
/* global handle conversion */
#define HANDLE_OBFUSCATOR 0x544a4def
inline static int handle_is_global( handle_t handle)
{
return ((unsigned long)handle ^ HANDLE_OBFUSCATOR) < 0x10000;
}
inline static handle_t handle_local_to_global( handle_t handle )
{
return (index + 1) << 2;
if (!handle) return 0;
return (handle_t)((unsigned long)handle ^ HANDLE_OBFUSCATOR);
}
inline static int handle_to_index( int handle )
inline static handle_t handle_global_to_local( handle_t handle )
{
return (handle >> 2) - 1;
return (handle_t)((unsigned long)handle ^ HANDLE_OBFUSCATOR);
}
......@@ -99,7 +111,8 @@ static void handle_table_dump( struct object *obj, int verbose )
for (i = 0; i <= table->last; i++, entry++)
{
if (!entry->ptr) continue;
fprintf( stderr, "%9d: %p %08x ", index_to_handle(i), entry->ptr, entry->access );
fprintf( stderr, "%9u: %p %08x ",
(unsigned int)index_to_handle(i), entry->ptr, entry->access );
entry->ptr->ops->dump( entry->ptr, 0 );
}
}
......@@ -158,7 +171,7 @@ static int grow_handle_table( struct handle_table *table )
}
/* allocate the first free entry in the handle table */
static int alloc_entry( struct handle_table *table, void *obj, unsigned int access )
static handle_t alloc_entry( struct handle_table *table, void *obj, unsigned int access )
{
struct handle_entry *entry = table->entries + table->free;
int i;
......@@ -166,7 +179,7 @@ static int alloc_entry( struct handle_table *table, void *obj, unsigned int acce
for (i = table->free; i <= table->last; i++, entry++) if (!entry->ptr) goto found;
if (i >= table->count)
{
if (!grow_handle_table( table )) return -1;
if (!grow_handle_table( table )) return 0;
entry = table->entries + i; /* the entries may have moved */
}
table->last = i;
......@@ -179,8 +192,8 @@ static int alloc_entry( struct handle_table *table, void *obj, unsigned int acce
}
/* allocate a handle for an object, incrementing its refcount */
/* return the handle, or -1 on error */
int alloc_handle( struct process *process, void *obj, unsigned int access, int inherit )
/* return the handle, or 0 on error */
handle_t alloc_handle( struct process *process, void *obj, unsigned int access, int inherit )
{
struct handle_table *table = (struct handle_table *)process->handles;
......@@ -191,36 +204,34 @@ int alloc_handle( struct process *process, void *obj, unsigned int access, int i
}
/* allocate a global handle for an object, incrementing its refcount */
/* return the handle, or -1 on error */
static int alloc_global_handle( void *obj, unsigned int access )
/* return the handle, or 0 on error */
static handle_t alloc_global_handle( void *obj, unsigned int access )
{
int handle;
if (!global_table)
{
if (!(global_table = (struct handle_table *)alloc_handle_table( NULL, 0 ))) return -1;
if (!(global_table = (struct handle_table *)alloc_handle_table( NULL, 0 )))
return 0;
}
if ((handle = alloc_entry( global_table, obj, access )) != -1)
handle = HANDLE_LOCAL_TO_GLOBAL(handle);
return handle;
return handle_local_to_global( alloc_entry( global_table, obj, access ));
}
/* return a handle entry, or NULL if the handle is invalid */
static struct handle_entry *get_handle( struct process *process, int handle )
static struct handle_entry *get_handle( struct process *process, handle_t handle )
{
struct handle_table *table = (struct handle_table *)process->handles;
struct handle_entry *entry;
int index;
if (HANDLE_IS_GLOBAL(handle))
if (handle_is_global(handle))
{
handle = HANDLE_GLOBAL_TO_LOCAL(handle);
handle = handle_global_to_local(handle);
table = global_table;
}
if (!table) goto error;
handle = handle_to_index( handle );
if (handle < 0) goto error;
if (handle > table->last) goto error;
entry = table->entries + handle;
index = handle_to_index( handle );
if (index < 0) goto error;
if (index > table->last) goto error;
entry = table->entries + index;
if (!entry->ptr) goto error;
return entry;
......@@ -283,7 +294,7 @@ struct object *copy_handle_table( struct process *process, struct process *paren
/* close a handle and decrement the refcount of the associated object */
/* return 1 if OK, 0 on error */
int close_handle( struct process *process, int handle, int *fd )
int close_handle( struct process *process, handle_t handle, int *fd )
{
struct handle_table *table;
struct handle_entry *entry;
......@@ -300,7 +311,7 @@ int close_handle( struct process *process, int handle, int *fd )
if (fd) *fd = entry->fd;
else if (entry->fd != -1) return 1; /* silently ignore close attempt if we cannot close the fd */
entry->fd = -1;
table = HANDLE_IS_GLOBAL(handle) ? global_table : (struct handle_table *)process->handles;
table = handle_is_global(handle) ? global_table : (struct handle_table *)process->handles;
if (entry < table->entries + table->free) table->free = entry - table->entries;
if (entry == table->entries + table->last) shrink_handle_table( table );
release_object( obj );
......@@ -318,9 +329,9 @@ void close_global_handles(void)
}
/* retrieve the object corresponding to one of the magic pseudo-handles */
static inline struct object *get_magic_handle( int handle )
static inline struct object *get_magic_handle( handle_t handle )
{
switch(handle)
switch((unsigned long)handle)
{
case 0xfffffffe: /* current thread pseudo-handle */
return &current->obj;
......@@ -333,7 +344,7 @@ static inline struct object *get_magic_handle( int handle )
}
/* retrieve the object corresponding to a handle, incrementing its refcount */
struct object *get_handle_obj( struct process *process, int handle,
struct object *get_handle_obj( struct process *process, handle_t handle,
unsigned int access, const struct object_ops *ops )
{
struct handle_entry *entry;
......@@ -358,7 +369,7 @@ struct object *get_handle_obj( struct process *process, int handle,
}
/* retrieve the cached fd for a given handle */
int get_handle_fd( struct process *process, int handle, unsigned int access )
int get_handle_fd( struct process *process, handle_t handle, unsigned int access )
{
struct handle_entry *entry;
......@@ -373,7 +384,8 @@ int get_handle_fd( struct process *process, int handle, unsigned int access )
/* get/set the handle reserved flags */
/* return the old flags (or -1 on error) */
static int set_handle_info( struct process *process, int handle, int mask, int flags, int *fd )
static int set_handle_info( struct process *process, handle_t handle,
int mask, int flags, int *fd )
{
struct handle_entry *entry;
unsigned int old_access;
......@@ -396,13 +408,13 @@ static int set_handle_info( struct process *process, int handle, int mask, int f
}
/* duplicate a handle */
int duplicate_handle( struct process *src, int src_handle, struct process *dst,
unsigned int access, int inherit, int options )
handle_t duplicate_handle( struct process *src, handle_t src_handle, struct process *dst,
unsigned int access, int inherit, int options )
{
int res;
handle_t res;
struct object *obj = get_handle_obj( src, src_handle, 0, NULL );
if (!obj) return -1;
if (!obj) return 0;
if (options & DUP_HANDLE_SAME_ACCESS)
{
struct handle_entry *entry = get_handle( src, src_handle );
......@@ -424,10 +436,10 @@ int duplicate_handle( struct process *src, int src_handle, struct process *dst,
}
/* open a new handle to an existing object */
int open_object( const WCHAR *name, size_t len, const struct object_ops *ops,
unsigned int access, int inherit )
handle_t open_object( const WCHAR *name, size_t len, const struct object_ops *ops,
unsigned int access, int inherit )
{
int handle = -1;
handle_t handle = 0;
struct object *obj = find_object( name, len );
if (obj)
{
......@@ -453,7 +465,7 @@ DECL_HANDLER(set_handle_info)
{
int fd = req->fd;
if (HANDLE_IS_GLOBAL(req->handle)) fd = -1; /* no fd cache for global handles */
if (handle_is_global(req->handle)) fd = -1; /* no fd cache for global handles */
req->old_flags = set_handle_info( current->process, req->handle, req->mask, req->flags, &fd );
req->cur_fd = fd;
}
......@@ -463,7 +475,7 @@ DECL_HANDLER(dup_handle)
{
struct process *src, *dst;
req->handle = -1;
req->handle = 0;
req->fd = -1;
if ((src = get_process_from_handle( req->src_process, PROCESS_DUP_HANDLE )))
{
......
......@@ -13,6 +13,7 @@
#include <stdlib.h>
#include "windef.h"
#include "server.h"
struct process;
struct object_ops;
......@@ -21,16 +22,16 @@ struct object_ops;
/* alloc_handle takes a void *obj for convenience, but you better make sure */
/* that the thing pointed to starts with a struct object... */
extern int alloc_handle( struct process *process, void *obj,
unsigned int access, int inherit );
extern int close_handle( struct process *process, int handle, int *fd );
extern struct object *get_handle_obj( struct process *process, int handle,
extern handle_t alloc_handle( struct process *process, void *obj,
unsigned int access, int inherit );
extern int close_handle( struct process *process, handle_t handle, int *fd );
extern struct object *get_handle_obj( struct process *process, handle_t handle,
unsigned int access, const struct object_ops *ops );
extern int get_handle_fd( struct process *process, int handle, unsigned int access );
extern int duplicate_handle( struct process *src, int src_handle, struct process *dst,
unsigned int access, int inherit, int options );
extern int open_object( const WCHAR *name, size_t len, const struct object_ops *ops,
unsigned int access, int inherit );
extern int get_handle_fd( struct process *process, handle_t handle, unsigned int access );
extern handle_t duplicate_handle( struct process *src, handle_t src_handle, struct process *dst,
unsigned int access, int inherit, int options );
extern handle_t open_object( const WCHAR *name, size_t len, const struct object_ops *ops,
unsigned int access, int inherit );
extern struct object *alloc_handle_table( struct process *process, int count );
extern struct object *copy_handle_table( struct process *process, struct process *parent );
extern void close_global_handles(void);
......
......@@ -207,7 +207,7 @@ static int get_image_params( struct mapping *mapping )
static struct object *create_mapping( int size_high, int size_low, int protect,
int handle, const WCHAR *name, size_t len )
handle_t handle, const WCHAR *name, size_t len )
{
struct mapping *mapping;
int access = 0;
......@@ -227,7 +227,7 @@ static struct object *create_mapping( int size_high, int size_low, int protect,
if (protect & VPROT_READ) access |= GENERIC_READ;
if (protect & VPROT_WRITE) access |= GENERIC_WRITE;
if (handle != -1)
if (handle)
{
if (!(mapping->file = get_file_obj( current->process, handle, access ))) goto error;
if (protect & VPROT_IMAGE)
......@@ -304,7 +304,7 @@ DECL_HANDLER(create_mapping)
{
struct object *obj;
req->handle = -1;
req->handle = 0;
if ((obj = create_mapping( req->size_high, req->size_low,
req->protect, req->file_handle,
get_req_data(req), get_req_data_size(req) )))
......@@ -336,7 +336,7 @@ DECL_HANDLER(get_mapping_info)
req->protect = mapping->protect;
req->header_size = mapping->header_size;
req->base = mapping->base;
req->shared_file = -1;
req->shared_file = 0;
req->shared_size = mapping->shared_size;
req->anonymous = !mapping->file;
if (mapping->shared_file)
......
......@@ -140,7 +140,7 @@ DECL_HANDLER(create_mutex)
{
struct mutex *mutex;
req->handle = -1;
req->handle = 0;
if ((mutex = create_mutex( get_req_data(req), get_req_data_size(req), req->owned )))
{
req->handle = alloc_handle( current->process, mutex, MUTEX_ALL_ACCESS, req->inherit );
......
......@@ -135,7 +135,7 @@ struct event;
extern struct event *create_event( const WCHAR *name, size_t len,
int manual_reset, int initial_state );
extern struct event *get_event_obj( struct process *process, int handle, unsigned int access );
extern struct event *get_event_obj( struct process *process, handle_t handle, unsigned int access );
extern void pulse_event( struct event *event );
extern void set_event( struct event *event );
extern void reset_event( struct event *event );
......@@ -146,7 +146,7 @@ extern void abandon_mutexes( struct thread *thread );
/* file functions */
extern struct file *get_file_obj( struct process *process, int handle,
extern struct file *get_file_obj( struct process *process, handle_t handle,
unsigned int access );
extern int grow_file( struct file *file, int size_high, int size_low );
extern int create_anonymous_file(void);
......
......@@ -152,20 +152,19 @@ static void pipe_destroy( struct object *obj )
DECL_HANDLER(create_pipe)
{
struct object *obj[2];
int hread = -1, hwrite = -1;
handle_t hread = 0, hwrite = 0;
if (create_pipe( obj ))
{
hread = alloc_handle( current->process, obj[0],
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
req->inherit );
if (hread != -1)
if (hread)
{
hwrite = alloc_handle( current->process, obj[1],
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
req->inherit );
if (hwrite == -1)
close_handle( current->process, hread, NULL );
if (!hwrite) close_handle( current->process, hread, NULL );
}
release_object( obj[0] );
release_object( obj[1] );
......
......@@ -62,9 +62,9 @@ struct startup_info
int inherit_all; /* inherit all handles from parent */
int create_flags; /* creation flags */
int start_flags; /* flags from startup info */
int hstdin; /* handle for stdin */
int hstdout; /* handle for stdout */
int hstderr; /* handle for stderr */
handle_t hstdin; /* handle for stdin */
handle_t hstdout; /* handle for stdout */
handle_t hstderr; /* handle for stderr */
int cmd_show; /* main window show mode */
struct file *exe_file; /* file handle for main exe */
char *filename; /* file name for main exe */
......@@ -230,11 +230,11 @@ static void init_process( int ppid, struct init_process_request *req )
if (!process->handles) goto error;
/* retrieve the main exe file */
req->exe_file = -1;
req->exe_file = 0;
if (parent && info->exe_file)
{
process->exe.file = (struct file *)grab_object( info->exe_file );
if ((req->exe_file = alloc_handle( process, process->exe.file, GENERIC_READ, 0 )) == -1)
if (!(req->exe_file = alloc_handle( process, process->exe.file, GENERIC_READ, 0 )))
goto error;
}
......@@ -356,7 +356,7 @@ static void build_wait_process_reply( struct thread *thread, struct object *obj,
req->event = alloc_handle( thread->process, info->process->init_event,
EVENT_ALL_ACCESS, 0 );
else
req->event = -1;
req->event = 0;
/* FIXME: set_error */
}
......@@ -375,7 +375,7 @@ struct process *get_process_from_id( void *id )
}
/* get a process from a handle (and increment the refcount) */
struct process *get_process_from_handle( int handle, unsigned int access )
struct process *get_process_from_handle( handle_t handle, unsigned int access )
{
return (struct process *)get_handle_obj( current->process, handle,
access, &process_ops );
......@@ -734,7 +734,7 @@ DECL_HANDLER(new_process)
info->process = NULL;
info->thread = NULL;
if ((req->exe_file != -1) &&
if (req->exe_file &&
!(info->exe_file = get_file_obj( current->process, req->exe_file, GENERIC_READ )))
{
release_object( info );
......@@ -761,9 +761,9 @@ DECL_HANDLER(wait_process)
}
req->pid = 0;
req->tid = 0;
req->phandle = -1;
req->thandle = -1;
req->event = -1;
req->phandle = 0;
req->thandle = 0;
req->event = 0;
if (req->cancel)
{
release_object( current->info );
......@@ -812,7 +812,7 @@ DECL_HANDLER(init_process_done)
DECL_HANDLER(open_process)
{
struct process *process = get_process_from_id( req->pid );
req->handle = -1;
req->handle = 0;
if (process)
{
req->handle = alloc_handle( current->process, process, req->access, req->inherit );
......@@ -890,9 +890,9 @@ DECL_HANDLER(load_dll)
struct process_dll *dll;
struct file *file = NULL;
if ((req->handle != -1) &&
if (req->handle &&
!(file = get_file_obj( current->process, req->handle, GENERIC_READ ))) return;
if ((dll = process_load_dll( current->process, file, req->base )))
{
dll->dbg_offset = req->dbg_offset;
......@@ -917,7 +917,7 @@ DECL_HANDLER(wait_input_idle)
{
struct process *process;
req->event = -1;
req->event = 0;
if ((process = get_process_from_handle( req->handle, PROCESS_QUERY_INFORMATION )))
{
if (process->idle_event && process != current->process && process->queue != current->queue)
......
......@@ -74,7 +74,7 @@ struct module_snapshot
extern struct thread *create_process( int fd );
extern struct process *get_process_from_id( void *id );
extern struct process *get_process_from_handle( int handle, unsigned int access );
extern struct process *get_process_from_handle( handle_t handle, unsigned int access );
extern int process_set_debugger( struct process *process, struct thread *thread );
extern void add_process_thread( struct process *process,
struct thread *thread );
......
......@@ -110,7 +110,7 @@ DECL_HANDLER(get_msg_queue)
{
struct msg_queue *queue = current->queue;
req->handle = -1;
req->handle = 0;
if (!queue) queue = create_msg_queue( current );
if (queue) req->handle = alloc_handle( current->process, queue, SYNCHRONIZE, 0 );
}
......
......@@ -71,7 +71,9 @@ struct key_value
#define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
#define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
#define NB_SPECIAL_ROOT_KEYS (HKEY_SPECIAL_ROOT_LAST - HKEY_SPECIAL_ROOT_FIRST + 1)
#define IS_SPECIAL_ROOT_HKEY(h) (((h) >= HKEY_SPECIAL_ROOT_FIRST) && ((h) <= HKEY_SPECIAL_ROOT_LAST))
#define IS_SPECIAL_ROOT_HKEY(h) (((unsigned int)(h) >= HKEY_SPECIAL_ROOT_FIRST) && \
((unsigned int)(h) <= HKEY_SPECIAL_ROOT_LAST))
static struct key *special_root_keys[NB_SPECIAL_ROOT_KEYS];
/* the real root key */
......@@ -896,18 +898,18 @@ static void delete_value( struct key *key, const WCHAR *name )
}
}
static struct key *create_root_key( int hkey )
static struct key *create_root_key( handle_t hkey )
{
WCHAR keyname[80];
int i, dummy;
struct key *key;
const char *p;
p = special_root_names[hkey - HKEY_SPECIAL_ROOT_FIRST];
p = special_root_names[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST];
i = 0;
while (*p) keyname[i++] = *p++;
if (hkey == HKEY_CURRENT_USER) /* this one is special */
if (hkey == (handle_t)HKEY_CURRENT_USER) /* this one is special */
{
/* get the current user name */
char buffer[10];
......@@ -925,21 +927,21 @@ static struct key *create_root_key( int hkey )
if ((key = create_key( root_key, keyname, NULL, 0, time(NULL), &dummy )))
{
special_root_keys[hkey - HKEY_SPECIAL_ROOT_FIRST] = key;
special_root_keys[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST] = key;
key->flags |= KEY_ROOT;
}
return key;
}
/* get the registry key corresponding to an hkey handle */
static struct key *get_hkey_obj( int hkey, unsigned int access )
static struct key *get_hkey_obj( handle_t hkey, unsigned int access )
{
struct key *key;
if (!hkey) return (struct key *)grab_object( root_key );
if (IS_SPECIAL_ROOT_HKEY(hkey))
{
if (!(key = special_root_keys[hkey - HKEY_SPECIAL_ROOT_FIRST]))
if (!(key = special_root_keys[(unsigned int)hkey - HKEY_SPECIAL_ROOT_FIRST]))
key = create_root_key( hkey );
else
grab_object( key );
......@@ -1334,7 +1336,7 @@ static void load_keys( struct key *key, FILE *f )
}
/* load a part of the registry from a file */
static void load_registry( struct key *key, int handle )
static void load_registry( struct key *key, handle_t handle )
{
struct object *obj;
int fd;
......@@ -1424,7 +1426,7 @@ static void save_all_subkeys( struct key *key, FILE *f )
}
/* save a registry branch to a file handle */
static void save_registry( struct key *key, int handle )
static void save_registry( struct key *key, handle_t handle )
{
struct object *obj;
int fd;
......@@ -1583,7 +1585,7 @@ DECL_HANDLER(create_key)
size_t len;
if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
req->hkey = -1;
req->hkey = 0;
if (!(name = copy_req_path( req, &len ))) return;
if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
{
......@@ -1618,7 +1620,7 @@ DECL_HANDLER(open_key)
unsigned int access = req->access;
if (access & MAXIMUM_ALLOWED) access = KEY_ALL_ACCESS; /* FIXME: needs general solution */
req->hkey = -1;
req->hkey = 0;
if ((parent = get_hkey_obj( req->parent, 0 /*FIXME*/ )))
{
WCHAR *name = copy_path( get_req_data(req), get_req_data_size(req) );
......
......@@ -255,7 +255,7 @@ int write_request( struct thread *thread )
}
/* send an fd to a client */
int send_client_fd( struct thread *thread, int fd, int handle )
int send_client_fd( struct thread *thread, int fd, handle_t handle )
{
int ret;
......@@ -382,7 +382,7 @@ struct object *create_request_socket( struct thread *thread )
return NULL;
}
sock->thread = thread;
send_client_fd( thread, fd[1], -1 );
send_client_fd( thread, fd[1], 0 );
close( fd[1] );
set_select_events( &sock->obj, POLLIN );
return &sock->obj;
......
......@@ -33,7 +33,7 @@ extern void fatal_perror( const char *err, ... ) WINE_NORETURN;
extern const char *get_config_dir(void);
extern void read_request( struct thread *thread );
extern int write_request( struct thread *thread );
extern int send_client_fd( struct thread *thread, int fd, int handle );
extern int send_client_fd( struct thread *thread, int fd, handle_t handle );
extern void send_reply( struct thread *thread );
extern void open_master_socket(void);
extern void close_master_socket(void);
......
......@@ -64,7 +64,7 @@ static struct semaphore *create_semaphore( const WCHAR *name, size_t len,
return sem;
}
static unsigned int release_semaphore( int handle, unsigned int count )
static unsigned int release_semaphore( handle_t handle, unsigned int count )
{
struct semaphore *sem;
unsigned int prev = 0;
......@@ -123,7 +123,7 @@ DECL_HANDLER(create_semaphore)
{
struct semaphore *sem;
req->handle = -1;
req->handle = 0;
if ((sem = create_semaphore( get_req_data(req), get_req_data_size(req),
req->initial, req->max )))
{
......
......@@ -135,7 +135,7 @@ static void serial_dump( struct object *obj, int verbose )
fprintf( stderr, "Port fd=%d mask=%x\n", serial->obj.fd, serial->eventmask );
}
struct serial *get_serial_obj( struct process *process, int handle, unsigned int access )
struct serial *get_serial_obj( struct process *process, handle_t handle, unsigned int access )
{
return (struct serial *)get_handle_obj( process, handle, access, &serial_ops );
}
......@@ -249,7 +249,7 @@ DECL_HANDLER(create_serial)
{
struct serial *serial;
req->handle = -1;
req->handle = 0;
if ((serial = create_serial( get_req_data(req), get_req_data_size(req), req->access )))
{
req->handle = alloc_handle( current->process, serial, req->access, req->inherit );
......
......@@ -198,7 +198,7 @@ DECL_HANDLER(create_snapshot)
{
struct snapshot *snapshot;
req->handle = -1;
req->handle = 0;
if ((snapshot = create_snapshot( req->pid, req->flags )))
{
req->handle = alloc_handle( current->process, snapshot, 0, req->inherit );
......
......@@ -304,7 +304,7 @@ static struct object *create_socket( int family, int type, int protocol )
}
/* accept a socket (creates a new fd) */
static struct object *accept_socket( int handle )
static struct object *accept_socket( handle_t handle )
{
struct sock *acceptsock;
struct sock *sock;
......@@ -429,28 +429,26 @@ static void sock_set_error(void)
DECL_HANDLER(create_socket)
{
struct object *obj;
int s = -1;
req->handle = 0;
if ((obj = create_socket( req->family, req->type, req->protocol )) != NULL)
{
s = alloc_handle( current->process, obj, req->access, req->inherit );
req->handle = alloc_handle( current->process, obj, req->access, req->inherit );
release_object( obj );
}
req->handle = s;
}
/* accept a socket */
DECL_HANDLER(accept_socket)
{
struct object *obj;
int s = -1;
req->handle = 0;
if ((obj = accept_socket( req->lhandle )) != NULL)
{
s = alloc_handle( current->process, obj, req->access, req->inherit );
req->handle = alloc_handle( current->process, obj, req->access, req->inherit );
release_object( obj );
}
req->handle = s;
}
/* set socket event parameters */
......
......@@ -113,8 +113,8 @@ static int alloc_client_buffer( struct thread *thread )
/* add it here since send_client_fd may call kill_thread */
add_process_thread( thread->process, thread );
send_client_fd( thread, fd_pipe[0], -1 );
send_client_fd( thread, fd, -1 );
send_client_fd( thread, fd_pipe[0], 0 );
send_client_fd( thread, fd, 0 );
send_reply( thread );
close( fd_pipe[0] );
close( fd );
......@@ -246,7 +246,7 @@ struct thread *get_thread_from_id( void *id )
}
/* get a thread from a handle (and increment the refcount) */
struct thread *get_thread_from_handle( int handle, unsigned int access )
struct thread *get_thread_from_handle( handle_t handle, unsigned int access )
{
return (struct thread *)get_handle_obj( current->process, handle,
access, &thread_ops );
......@@ -488,7 +488,7 @@ int sleep_on( int count, struct object *objects[], int flags, int timeout, sleep
}
/* select on a list of handles */
static int select_on( int count, int *handles, int flags, int timeout )
static int select_on( int count, handle_t *handles, int flags, int timeout )
{
int ret = 0;
int i;
......@@ -697,7 +697,7 @@ DECL_HANDLER(new_thread)
if (req->suspend) thread->suspend++;
req->tid = thread;
if ((req->handle = alloc_handle( current->process, thread,
THREAD_ALL_ACCESS, req->inherit )) != -1)
THREAD_ALL_ACCESS, req->inherit )))
{
send_client_fd( current, sock[1], req->handle );
close( sock[1] );
......@@ -756,9 +756,9 @@ DECL_HANDLER(terminate_thread)
DECL_HANDLER(get_thread_info)
{
struct thread *thread;
int handle = req->handle;
handle_t handle = req->handle;
if (handle == -1) thread = get_thread_from_id( req->tid_in );
if (!handle) thread = get_thread_from_id( req->tid_in );
else thread = get_thread_from_handle( req->handle, THREAD_QUERY_INFORMATION );
if (thread)
......
......@@ -81,7 +81,7 @@ extern struct thread *current;
extern struct thread *create_thread( int fd, struct process *process );
extern struct thread *get_thread_from_id( void *id );
extern struct thread *get_thread_from_handle( int handle, unsigned int access );
extern struct thread *get_thread_from_handle( handle_t handle, unsigned int access );
extern struct thread *get_thread_from_pid( int pid );
extern int suspend_thread( struct thread *thread, int check_limit );
extern int resume_thread( struct thread *thread );
......
......@@ -174,7 +174,7 @@ DECL_HANDLER(create_timer)
{
struct timer *timer;
req->handle = -1;
req->handle = 0;
if ((timer = create_timer( get_req_data(req), get_req_data_size(req), req->manual )))
{
req->handle = alloc_handle( current->process, timer, TIMER_ALL_ACCESS, req->inherit );
......
......@@ -89,6 +89,21 @@ static size_t dump_varargs_ints( const void *req )
return get_size(req);
}
static size_t dump_varargs_handles( const void *req )
{
const handle_t *data = get_data(req);
size_t len = get_size(req) / sizeof(*data);
fputc( '{', stderr );
while (len > 0)
{
fprintf( stderr, "%d", *data++ );
if (--len) fputc( ',', stderr );
}
fputc( '}', stderr );
return get_size(req);
}
static size_t dump_varargs_ptrs( const void *req )
{
void * const *data = get_data(req);
......@@ -523,7 +538,7 @@ static void dump_select_request( const struct select_request *req )
fprintf( stderr, " flags=%d,", req->flags );
fprintf( stderr, " timeout=%d,", req->timeout );
fprintf( stderr, " handles=" );
cur_pos += dump_varargs_ints( req );
cur_pos += dump_varargs_handles( req );
}
static void dump_select_reply( const struct select_request *req )
......
......@@ -14,7 +14,7 @@
"unsigned int" => "%08x",
"void*" => "%p",
"time_t" => "%ld",
"path_t" => "&dump_path_t",
"handle_t" => "%d",
);
my @requests = ();
......
......@@ -611,7 +611,7 @@ static BOOL CONSOLE_make_complex(HANDLE handle)
pty_handle = FILE_DupUnixHandle( slave, GENERIC_READ | GENERIC_WRITE );
close( master );
close( slave );
if (pty_handle == -1) return FALSE;
if (!pty_handle) return FALSE;
/* most xterms like to print their window ID when used with -S;
* read it and continue before the user has a chance...
......
......@@ -331,7 +331,7 @@ HANDLE DEVICE_Open( LPCSTR filename, DWORD access,
FIXME( "Unknown VxD %s. Try --winver nt40 !\n", filename);
SetLastError( ERROR_FILE_NOT_FOUND );
return HFILE_ERROR;
return 0;
}
static const struct VxDInfo *DEVICE_GetInfo( HANDLE handle )
......
......@@ -438,7 +438,7 @@ void QUEUE_SetExitingQueue( HQUEUE16 hQueue )
static HQUEUE16 QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData )
{
HQUEUE16 hQueue;
HANDLE handle = -1;
HANDLE handle;
MESSAGEQUEUE * msgQueue;
TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
......@@ -455,10 +455,11 @@ static HQUEUE16 QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData )
SERVER_START_REQ
{
struct get_msg_queue_request *req = server_alloc_req( sizeof(*req), 0 );
if (!server_call( REQ_GET_MSG_QUEUE )) handle = req->handle;
server_call( REQ_GET_MSG_QUEUE );
handle = req->handle;
}
SERVER_END_REQ;
if (handle == -1)
if (!handle)
{
ERR_(msg)("Cannot get thread queue");
GlobalFree16( hQueue );
......@@ -1518,7 +1519,7 @@ DWORD WINAPI WaitForInputIdle (HANDLE hProcess, DWORD dwTimeOut)
}
SERVER_END_REQ;
if (ret) return 0xffffffff; /* error */
if (idle_event == -1) return 0; /* no event to wait on */
if (!idle_event) return 0; /* no event to wait on */
cur_time = GetTickCount();
......
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