Commit dbf9d71e authored by Alexandre Julliard's avatar Alexandre Julliard

server: Add support for keyed event objects.

parent bf3e23bb
...@@ -1249,8 +1249,36 @@ NTSTATUS WINAPI NtDelayExecution( BOOLEAN alertable, const LARGE_INTEGER *timeou ...@@ -1249,8 +1249,36 @@ NTSTATUS WINAPI NtDelayExecution( BOOLEAN alertable, const LARGE_INTEGER *timeou
NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access, NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access,
const OBJECT_ATTRIBUTES *attr, ULONG flags ) const OBJECT_ATTRIBUTES *attr, ULONG flags )
{ {
FIXME( "stub\n" ); DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
return STATUS_NOT_IMPLEMENTED; NTSTATUS ret;
struct security_descriptor *sd = NULL;
struct object_attributes objattr;
if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
objattr.rootdir = wine_server_obj_handle( attr ? attr->RootDirectory : 0 );
objattr.sd_len = 0;
objattr.name_len = len;
if (attr)
{
ret = NTDLL_create_struct_sd( attr->SecurityDescriptor, &sd, &objattr.sd_len );
if (ret != STATUS_SUCCESS) return ret;
}
SERVER_START_REQ( create_keyed_event )
{
req->access = access;
req->attributes = attr ? attr->Attributes : 0;
wine_server_add_data( req, &objattr, sizeof(objattr) );
if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
ret = wine_server_call( req );
*handle = wine_server_ptr_handle( reply->handle );
}
SERVER_END_REQ;
NTDLL_free_struct_sd( sd );
return ret;
} }
/****************************************************************************** /******************************************************************************
...@@ -1258,8 +1286,22 @@ NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access, ...@@ -1258,8 +1286,22 @@ NTSTATUS WINAPI NtCreateKeyedEvent( HANDLE *handle, ACCESS_MASK access,
*/ */
NTSTATUS WINAPI NtOpenKeyedEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr ) NTSTATUS WINAPI NtOpenKeyedEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
{ {
FIXME( "stub\n" ); DWORD len = attr && attr->ObjectName ? attr->ObjectName->Length : 0;
return STATUS_NOT_IMPLEMENTED; NTSTATUS ret;
if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
SERVER_START_REQ( open_event )
{
req->access = access;
req->attributes = attr ? attr->Attributes : 0;
req->rootdir = wine_server_obj_handle( attr ? attr->RootDirectory : 0 );
if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
ret = wine_server_call( req );
*handle = wine_server_ptr_handle( reply->handle );
}
SERVER_END_REQ;
return ret;
} }
/****************************************************************************** /******************************************************************************
......
...@@ -1122,6 +1122,39 @@ struct open_event_reply ...@@ -1122,6 +1122,39 @@ struct open_event_reply
struct create_keyed_event_request
{
struct request_header __header;
unsigned int access;
unsigned int attributes;
/* VARARG(objattr,object_attributes); */
char __pad_20[4];
};
struct create_keyed_event_reply
{
struct reply_header __header;
obj_handle_t handle;
char __pad_12[4];
};
struct open_keyed_event_request
{
struct request_header __header;
unsigned int access;
unsigned int attributes;
obj_handle_t rootdir;
/* VARARG(name,unicode_str); */
};
struct open_keyed_event_reply
{
struct reply_header __header;
obj_handle_t handle;
char __pad_12[4];
};
struct create_mutex_request struct create_mutex_request
{ {
struct request_header __header; struct request_header __header;
...@@ -4982,6 +5015,8 @@ enum request ...@@ -4982,6 +5015,8 @@ enum request
REQ_create_event, REQ_create_event,
REQ_event_op, REQ_event_op,
REQ_open_event, REQ_open_event,
REQ_create_keyed_event,
REQ_open_keyed_event,
REQ_create_mutex, REQ_create_mutex,
REQ_release_mutex, REQ_release_mutex,
REQ_open_mutex, REQ_open_mutex,
...@@ -5238,6 +5273,8 @@ union generic_request ...@@ -5238,6 +5273,8 @@ union generic_request
struct create_event_request create_event_request; struct create_event_request create_event_request;
struct event_op_request event_op_request; struct event_op_request event_op_request;
struct open_event_request open_event_request; struct open_event_request open_event_request;
struct create_keyed_event_request create_keyed_event_request;
struct open_keyed_event_request open_keyed_event_request;
struct create_mutex_request create_mutex_request; struct create_mutex_request create_mutex_request;
struct release_mutex_request release_mutex_request; struct release_mutex_request release_mutex_request;
struct open_mutex_request open_mutex_request; struct open_mutex_request open_mutex_request;
...@@ -5492,6 +5529,8 @@ union generic_reply ...@@ -5492,6 +5529,8 @@ union generic_reply
struct create_event_reply create_event_reply; struct create_event_reply create_event_reply;
struct event_op_reply event_op_reply; struct event_op_reply event_op_reply;
struct open_event_reply open_event_reply; struct open_event_reply open_event_reply;
struct create_keyed_event_reply create_keyed_event_reply;
struct open_keyed_event_reply open_keyed_event_reply;
struct create_mutex_reply create_mutex_reply; struct create_mutex_reply create_mutex_reply;
struct release_mutex_reply release_mutex_reply; struct release_mutex_reply release_mutex_reply;
struct open_mutex_reply open_mutex_reply; struct open_mutex_reply open_mutex_reply;
...@@ -5715,6 +5754,6 @@ union generic_reply ...@@ -5715,6 +5754,6 @@ union generic_reply
struct set_suspend_context_reply set_suspend_context_reply; struct set_suspend_context_reply set_suspend_context_reply;
}; };
#define SERVER_PROTOCOL_VERSION 440 #define SERVER_PROTOCOL_VERSION 441
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */ #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
...@@ -71,6 +71,41 @@ static const struct object_ops event_ops = ...@@ -71,6 +71,41 @@ static const struct object_ops event_ops =
}; };
struct keyed_event
{
struct object obj; /* object header */
};
static void keyed_event_dump( struct object *obj, int verbose );
static struct object_type *keyed_event_get_type( struct object *obj );
static int keyed_event_signaled( struct object *obj, struct thread *thread );
static unsigned int keyed_event_map_access( struct object *obj, unsigned int access );
static const struct object_ops keyed_event_ops =
{
sizeof(struct keyed_event), /* size */
keyed_event_dump, /* dump */
keyed_event_get_type, /* get_type */
add_queue, /* add_queue */
remove_queue, /* remove_queue */
keyed_event_signaled, /* signaled */
no_satisfied, /* satisfied */
no_signal, /* signal */
no_get_fd, /* get_fd */
keyed_event_map_access, /* map_access */
default_get_sd, /* get_sd */
default_set_sd, /* set_sd */
no_lookup_name, /* lookup_name */
no_open_file, /* open_file */
no_close_handle, /* close_handle */
no_destroy /* destroy */
};
#define KEYEDEVENT_WAIT 0x0001
#define KEYEDEVENT_WAKE 0x0002
#define KEYEDEVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x0003)
struct event *create_event( struct directory *root, const struct unicode_str *name, struct event *create_event( struct directory *root, const struct unicode_str *name,
unsigned int attr, int manual_reset, int initial_state, unsigned int attr, int manual_reset, int initial_state,
const struct security_descriptor *sd ) const struct security_descriptor *sd )
...@@ -174,6 +209,56 @@ static int event_signal( struct object *obj, unsigned int access ) ...@@ -174,6 +209,56 @@ static int event_signal( struct object *obj, unsigned int access )
return 1; return 1;
} }
struct keyed_event *create_keyed_event( struct directory *root, const struct unicode_str *name,
unsigned int attr, const struct security_descriptor *sd )
{
struct keyed_event *event;
if ((event = create_named_object_dir( root, name, attr, &keyed_event_ops )))
{
if (get_error() != STATUS_OBJECT_NAME_EXISTS)
{
/* initialize it if it didn't already exist */
if (sd) default_set_sd( &event->obj, sd, OWNER_SECURITY_INFORMATION|
GROUP_SECURITY_INFORMATION|
DACL_SECURITY_INFORMATION|
SACL_SECURITY_INFORMATION );
}
}
return event;
}
static void keyed_event_dump( struct object *obj, int verbose )
{
struct keyed_event *event = (struct keyed_event *)obj;
assert( obj->ops == &keyed_event_ops );
fprintf( stderr, "Keyed event " );
dump_object_name( &event->obj );
fputc( '\n', stderr );
}
static struct object_type *keyed_event_get_type( struct object *obj )
{
static const WCHAR name[] = {'K','e','y','e','d','E','v','e','n','t'};
static const struct unicode_str str = { name, sizeof(name) };
return get_object_type( &str );
}
static int keyed_event_signaled( struct object *obj, struct thread *thread )
{
assert( obj->ops == &keyed_event_ops );
return 1;
}
static unsigned int keyed_event_map_access( struct object *obj, unsigned int access )
{
if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ | SYNCHRONIZE | KEYEDEVENT_WAIT;
if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE | KEYEDEVENT_WAKE;
if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL | KEYEDEVENT_ALL_ACCESS;
return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
}
/* create an event */ /* create an event */
DECL_HANDLER(create_event) DECL_HANDLER(create_event)
{ {
...@@ -249,3 +334,48 @@ DECL_HANDLER(event_op) ...@@ -249,3 +334,48 @@ DECL_HANDLER(event_op)
} }
release_object( event ); release_object( event );
} }
/* create a keyed event */
DECL_HANDLER(create_keyed_event)
{
struct keyed_event *event;
struct unicode_str name;
struct directory *root = NULL;
const struct object_attributes *objattr = get_req_data();
const struct security_descriptor *sd;
if (!objattr_is_valid( objattr, get_req_data_size() )) return;
sd = objattr->sd_len ? (const struct security_descriptor *)(objattr + 1) : NULL;
objattr_get_name( objattr, &name );
if (objattr->rootdir && !(root = get_directory_obj( current->process, objattr->rootdir, 0 ))) return;
if ((event = create_keyed_event( root, &name, req->attributes, sd )))
{
if (get_error() == STATUS_OBJECT_NAME_EXISTS)
reply->handle = alloc_handle( current->process, event, req->access, req->attributes );
else
reply->handle = alloc_handle_no_access_check( current->process, event, req->access, req->attributes );
release_object( event );
}
if (root) release_object( root );
}
/* open a handle to a keyed event */
DECL_HANDLER(open_keyed_event)
{
struct unicode_str name;
struct directory *root = NULL;
struct keyed_event *event;
get_req_unicode_str( &name );
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 ))) return;
if ((event = open_object_dir( root, &name, req->attributes, &keyed_event_ops )))
{
reply->handle = alloc_handle( current->process, &event->obj, req->access, req->attributes );
release_object( event );
}
if (root) release_object( root );
}
...@@ -152,10 +152,13 @@ extern void close_objects(void); ...@@ -152,10 +152,13 @@ extern void close_objects(void);
/* event functions */ /* event functions */
struct event; struct event;
struct keyed_event;
extern struct event *create_event( struct directory *root, const struct unicode_str *name, extern struct event *create_event( struct directory *root, const struct unicode_str *name,
unsigned int attr, int manual_reset, int initial_state, unsigned int attr, int manual_reset, int initial_state,
const struct security_descriptor *sd ); const struct security_descriptor *sd );
extern struct keyed_event *create_keyed_event( struct directory *root, const struct unicode_str *name,
unsigned int attr, const struct security_descriptor *sd );
extern struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access ); extern struct event *get_event_obj( struct process *process, obj_handle_t handle, unsigned int access );
extern void pulse_event( struct event *event ); extern void pulse_event( struct event *event );
extern void set_event( struct event *event ); extern void set_event( struct event *event );
......
...@@ -965,6 +965,26 @@ enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT }; ...@@ -965,6 +965,26 @@ enum event_op { PULSE_EVENT, SET_EVENT, RESET_EVENT };
@END @END
/* Create a keyed event */
@REQ(create_keyed_event)
unsigned int access; /* wanted access rights */
unsigned int attributes; /* object attributes */
VARARG(objattr,object_attributes); /* object attributes */
@REPLY
obj_handle_t handle; /* handle to the event */
@END
/* Open a keyed event */
@REQ(open_keyed_event)
unsigned int access; /* wanted access rights */
unsigned int attributes; /* object attributes */
obj_handle_t rootdir; /* root directory */
VARARG(name,unicode_str); /* object name */
@REPLY
obj_handle_t handle; /* handle to the event */
@END
/* Create a mutex */ /* Create a mutex */
@REQ(create_mutex) @REQ(create_mutex)
unsigned int access; /* wanted access rights */ unsigned int access; /* wanted access rights */
......
...@@ -134,6 +134,8 @@ DECL_HANDLER(select); ...@@ -134,6 +134,8 @@ DECL_HANDLER(select);
DECL_HANDLER(create_event); DECL_HANDLER(create_event);
DECL_HANDLER(event_op); DECL_HANDLER(event_op);
DECL_HANDLER(open_event); DECL_HANDLER(open_event);
DECL_HANDLER(create_keyed_event);
DECL_HANDLER(open_keyed_event);
DECL_HANDLER(create_mutex); DECL_HANDLER(create_mutex);
DECL_HANDLER(release_mutex); DECL_HANDLER(release_mutex);
DECL_HANDLER(open_mutex); DECL_HANDLER(open_mutex);
...@@ -389,6 +391,8 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] = ...@@ -389,6 +391,8 @@ static const req_handler req_handlers[REQ_NB_REQUESTS] =
(req_handler)req_create_event, (req_handler)req_create_event,
(req_handler)req_event_op, (req_handler)req_event_op,
(req_handler)req_open_event, (req_handler)req_open_event,
(req_handler)req_create_keyed_event,
(req_handler)req_open_keyed_event,
(req_handler)req_create_mutex, (req_handler)req_create_mutex,
(req_handler)req_release_mutex, (req_handler)req_release_mutex,
(req_handler)req_open_mutex, (req_handler)req_open_mutex,
...@@ -834,6 +838,17 @@ C_ASSERT( FIELD_OFFSET(struct open_event_request, rootdir) == 20 ); ...@@ -834,6 +838,17 @@ C_ASSERT( FIELD_OFFSET(struct open_event_request, rootdir) == 20 );
C_ASSERT( sizeof(struct open_event_request) == 24 ); C_ASSERT( sizeof(struct open_event_request) == 24 );
C_ASSERT( FIELD_OFFSET(struct open_event_reply, handle) == 8 ); C_ASSERT( FIELD_OFFSET(struct open_event_reply, handle) == 8 );
C_ASSERT( sizeof(struct open_event_reply) == 16 ); C_ASSERT( sizeof(struct open_event_reply) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_keyed_event_request, access) == 12 );
C_ASSERT( FIELD_OFFSET(struct create_keyed_event_request, attributes) == 16 );
C_ASSERT( sizeof(struct create_keyed_event_request) == 24 );
C_ASSERT( FIELD_OFFSET(struct create_keyed_event_reply, handle) == 8 );
C_ASSERT( sizeof(struct create_keyed_event_reply) == 16 );
C_ASSERT( FIELD_OFFSET(struct open_keyed_event_request, access) == 12 );
C_ASSERT( FIELD_OFFSET(struct open_keyed_event_request, attributes) == 16 );
C_ASSERT( FIELD_OFFSET(struct open_keyed_event_request, rootdir) == 20 );
C_ASSERT( sizeof(struct open_keyed_event_request) == 24 );
C_ASSERT( FIELD_OFFSET(struct open_keyed_event_reply, handle) == 8 );
C_ASSERT( sizeof(struct open_keyed_event_reply) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_mutex_request, access) == 12 ); C_ASSERT( FIELD_OFFSET(struct create_mutex_request, access) == 12 );
C_ASSERT( FIELD_OFFSET(struct create_mutex_request, attributes) == 16 ); C_ASSERT( FIELD_OFFSET(struct create_mutex_request, attributes) == 16 );
C_ASSERT( FIELD_OFFSET(struct create_mutex_request, owned) == 20 ); C_ASSERT( FIELD_OFFSET(struct create_mutex_request, owned) == 20 );
......
...@@ -1404,6 +1404,31 @@ static void dump_open_event_reply( const struct open_event_reply *req ) ...@@ -1404,6 +1404,31 @@ static void dump_open_event_reply( const struct open_event_reply *req )
fprintf( stderr, " handle=%04x", req->handle ); fprintf( stderr, " handle=%04x", req->handle );
} }
static void dump_create_keyed_event_request( const struct create_keyed_event_request *req )
{
fprintf( stderr, " access=%08x", req->access );
fprintf( stderr, ", attributes=%08x", req->attributes );
dump_varargs_object_attributes( ", objattr=", cur_size );
}
static void dump_create_keyed_event_reply( const struct create_keyed_event_reply *req )
{
fprintf( stderr, " handle=%04x", req->handle );
}
static void dump_open_keyed_event_request( const struct open_keyed_event_request *req )
{
fprintf( stderr, " access=%08x", req->access );
fprintf( stderr, ", attributes=%08x", req->attributes );
fprintf( stderr, ", rootdir=%04x", req->rootdir );
dump_varargs_unicode_str( ", name=", cur_size );
}
static void dump_open_keyed_event_reply( const struct open_keyed_event_reply *req )
{
fprintf( stderr, " handle=%04x", req->handle );
}
static void dump_create_mutex_request( const struct create_mutex_request *req ) static void dump_create_mutex_request( const struct create_mutex_request *req )
{ {
fprintf( stderr, " access=%08x", req->access ); fprintf( stderr, " access=%08x", req->access );
...@@ -4008,6 +4033,8 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = { ...@@ -4008,6 +4033,8 @@ static const dump_func req_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_create_event_request, (dump_func)dump_create_event_request,
(dump_func)dump_event_op_request, (dump_func)dump_event_op_request,
(dump_func)dump_open_event_request, (dump_func)dump_open_event_request,
(dump_func)dump_create_keyed_event_request,
(dump_func)dump_open_keyed_event_request,
(dump_func)dump_create_mutex_request, (dump_func)dump_create_mutex_request,
(dump_func)dump_release_mutex_request, (dump_func)dump_release_mutex_request,
(dump_func)dump_open_mutex_request, (dump_func)dump_open_mutex_request,
...@@ -4260,6 +4287,8 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = { ...@@ -4260,6 +4287,8 @@ static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {
(dump_func)dump_create_event_reply, (dump_func)dump_create_event_reply,
NULL, NULL,
(dump_func)dump_open_event_reply, (dump_func)dump_open_event_reply,
(dump_func)dump_create_keyed_event_reply,
(dump_func)dump_open_keyed_event_reply,
(dump_func)dump_create_mutex_reply, (dump_func)dump_create_mutex_reply,
(dump_func)dump_release_mutex_reply, (dump_func)dump_release_mutex_reply,
(dump_func)dump_open_mutex_reply, (dump_func)dump_open_mutex_reply,
...@@ -4512,6 +4541,8 @@ static const char * const req_names[REQ_NB_REQUESTS] = { ...@@ -4512,6 +4541,8 @@ static const char * const req_names[REQ_NB_REQUESTS] = {
"create_event", "create_event",
"event_op", "event_op",
"open_event", "open_event",
"create_keyed_event",
"open_keyed_event",
"create_mutex", "create_mutex",
"release_mutex", "release_mutex",
"open_mutex", "open_mutex",
......
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