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.
diff --git a/server/async.c b/server/async.c
index fb722bc..e740add 100644
--- a/server/async.c
+++ b/server/async.c
@@ -99,7 +99,7 @@
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 @@
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;
diff --git a/server/change.c b/server/change.c
index 338712e..4dd0dcb 100644
--- a/server/change.c
+++ b/server/change.c
@@ -72,7 +72,7 @@
{
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,
diff --git a/server/console.c b/server/console.c
index 7454c9a..f389e25 100644
--- a/server/console.c
+++ b/server/console.c
@@ -167,7 +167,7 @@
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 @@
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 @@
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 @@
}
/* 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 @@
}
/* 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 @@
}
/* 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 @@
/* 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 @@
{
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 );
}
diff --git a/server/debugger.c b/server/debugger.c
index 7f84410..202f0dd 100644
--- a/server/debugger.c
+++ b/server/debugger.c
@@ -92,11 +92,10 @@
{
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 @@
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 @@
{
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 @@
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;
}
diff --git a/server/device.c b/server/device.c
index 4183b75..5c19734 100644
--- a/server/device.c
+++ b/server/device.c
@@ -86,7 +86,7 @@
{
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 );
diff --git a/server/event.c b/server/event.c
index 18f6b41..b7652fb 100644
--- a/server/event.c
+++ b/server/event.c
@@ -59,7 +59,7 @@
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 @@
{
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 )))
{
diff --git a/server/file.c b/server/file.c
index 0c8aaae..c5b5ca3 100644
--- a/server/file.c
+++ b/server/file.c
@@ -320,12 +320,12 @@
}
}
-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 @@
return 1;
}
-static int truncate_file( int handle )
+static int truncate_file( handle_t handle )
{
struct file *file;
int result;
@@ -370,7 +370,6 @@
}
release_object( file );
return 1;
-
}
/* try to grow the file to the specified size */
@@ -394,7 +393,7 @@
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 @@
{
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 @@
{
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,
diff --git a/server/handle.c b/server/handle.c
index c3b8a05..50fef3e 100644
--- a/server/handle.c
+++ b/server/handle.c
@@ -42,25 +42,37 @@
#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 (index + 1) << 2;
+ return (handle_t)((index + 1) << 2);
}
-inline static int handle_to_index( int handle )
+inline static int handle_to_index( handle_t handle )
{
- return (handle >> 2) - 1;
+ 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 )
+{
+ if (!handle) return 0;
+ return (handle_t)((unsigned long)handle ^ HANDLE_OBFUSCATOR);
+}
+inline static handle_t handle_global_to_local( handle_t handle )
+{
+ return (handle_t)((unsigned long)handle ^ HANDLE_OBFUSCATOR);
}
@@ -99,7 +111,8 @@
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 @@
}
/* 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 @@
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 @@
}
/* 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 @@
}
/* 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 @@
/* 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 @@
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 @@
}
/* 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 ¤t->obj;
@@ -333,7 +344,7 @@
}
/* 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 @@
}
/* 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 @@
/* 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 @@
}
/* 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 @@
}
/* 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 @@
{
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 @@
{
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 )))
{
diff --git a/server/handle.h b/server/handle.h
index d648dd7..18d5d2a 100644
--- a/server/handle.h
+++ b/server/handle.h
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include "windef.h"
+#include "server.h"
struct process;
struct object_ops;
@@ -21,16 +22,16 @@
/* 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);
diff --git a/server/mapping.c b/server/mapping.c
index 43a67d8..8cd24b5 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -207,7 +207,7 @@
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 @@
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 @@
{
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 @@
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)
diff --git a/server/mutex.c b/server/mutex.c
index 1adf373..54f9052 100644
--- a/server/mutex.c
+++ b/server/mutex.c
@@ -140,7 +140,7 @@
{
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 );
diff --git a/server/object.h b/server/object.h
index deec306..089ab5b 100644
--- a/server/object.h
+++ b/server/object.h
@@ -135,7 +135,7 @@
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 @@
/* 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);
diff --git a/server/pipe.c b/server/pipe.c
index 47dfb61..789c201 100644
--- a/server/pipe.c
+++ b/server/pipe.c
@@ -152,20 +152,19 @@
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] );
diff --git a/server/process.c b/server/process.c
index 013dbc7..b52e15f 100644
--- a/server/process.c
+++ b/server/process.c
@@ -62,9 +62,9 @@
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 @@
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 @@
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 @@
}
/* 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 @@
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 @@
}
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(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 @@
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 @@
{
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)
diff --git a/server/process.h b/server/process.h
index 204fd04..f20d185 100644
--- a/server/process.h
+++ b/server/process.h
@@ -74,7 +74,7 @@
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 );
diff --git a/server/queue.c b/server/queue.c
index 8d63e7b..3067c0c 100644
--- a/server/queue.c
+++ b/server/queue.c
@@ -110,7 +110,7 @@
{
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 );
}
diff --git a/server/registry.c b/server/registry.c
index 4fa5a4e..5905aba 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -71,7 +71,9 @@
#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 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 @@
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 @@
}
/* 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 @@
}
/* 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 @@
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 @@
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) );
diff --git a/server/request.c b/server/request.c
index 7a8498b..fcaea8c 100644
--- a/server/request.c
+++ b/server/request.c
@@ -255,7 +255,7 @@
}
/* 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 @@
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;
diff --git a/server/request.h b/server/request.h
index c58d5fb..6383cb1 100644
--- a/server/request.h
+++ b/server/request.h
@@ -33,7 +33,7 @@
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);
diff --git a/server/semaphore.c b/server/semaphore.c
index 710f6ab..4844414 100644
--- a/server/semaphore.c
+++ b/server/semaphore.c
@@ -64,7 +64,7 @@
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 @@
{
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 )))
{
diff --git a/server/serial.c b/server/serial.c
index f32f8a3..3ba18ca 100644
--- a/server/serial.c
+++ b/server/serial.c
@@ -135,7 +135,7 @@
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 @@
{
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 );
diff --git a/server/snapshot.c b/server/snapshot.c
index ae4eb49..48654fa 100644
--- a/server/snapshot.c
+++ b/server/snapshot.c
@@ -198,7 +198,7 @@
{
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 );
diff --git a/server/sock.c b/server/sock.c
index ec7a067..1617fb3 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -304,7 +304,7 @@
}
/* 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 @@
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 */
diff --git a/server/thread.c b/server/thread.c
index 20250d1..fceca02 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -113,8 +113,8 @@
/* 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 @@
}
/* 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 @@
}
/* 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 @@
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(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)
diff --git a/server/thread.h b/server/thread.h
index 8e36569..0eea735 100644
--- a/server/thread.h
+++ b/server/thread.h
@@ -81,7 +81,7 @@
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 );
diff --git a/server/timer.c b/server/timer.c
index 198b0f5..f4b159f 100644
--- a/server/timer.c
+++ b/server/timer.c
@@ -174,7 +174,7 @@
{
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 );
diff --git a/server/trace.c b/server/trace.c
index 534f4d43..255a0ba 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -89,6 +89,21 @@
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 @@
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 )