2007-05-08 18:28:37 +00:00
|
|
|
/*
|
|
|
|
* Server-side device support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2015-05-21 08:18:08 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
2019-03-25 13:37:09 +00:00
|
|
|
#include "wine/rbtree.h"
|
2015-05-21 08:18:08 +00:00
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
#include <assert.h>
|
2015-05-21 08:18:08 +00:00
|
|
|
#include <fcntl.h>
|
2007-05-08 18:28:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winternl.h"
|
2015-05-05 02:34:15 +00:00
|
|
|
#include "ddk/wdm.h"
|
2007-05-08 18:28:37 +00:00
|
|
|
|
|
|
|
#include "object.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "handle.h"
|
|
|
|
#include "request.h"
|
2011-10-27 12:20:19 +00:00
|
|
|
#include "process.h"
|
2007-05-08 18:28:37 +00:00
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
/* IRP object */
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct list dev_entry; /* entry in device queue */
|
|
|
|
struct list mgr_entry; /* entry in manager queue */
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file; /* file containing this irp */
|
2015-05-05 02:34:15 +00:00
|
|
|
struct thread *thread; /* thread that queued the irp */
|
2007-05-08 18:37:21 +00:00
|
|
|
struct async *async; /* pending async op */
|
2015-05-06 02:21:40 +00:00
|
|
|
irp_params_t params; /* irp parameters */
|
2016-12-04 20:21:25 +00:00
|
|
|
struct iosb *iosb; /* I/O status block */
|
2007-05-08 18:37:21 +00:00
|
|
|
};
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
static void irp_call_dump( struct object *obj, int verbose );
|
|
|
|
static int irp_call_signaled( struct object *obj, struct wait_queue_entry *entry );
|
|
|
|
static void irp_call_destroy( struct object *obj );
|
2007-05-08 18:37:21 +00:00
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
static const struct object_ops irp_call_ops =
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
sizeof(struct irp_call), /* size */
|
|
|
|
irp_call_dump, /* dump */
|
2007-12-05 17:16:42 +00:00
|
|
|
no_get_type, /* get_type */
|
2007-05-08 18:37:21 +00:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
2015-05-05 02:34:15 +00:00
|
|
|
irp_call_signaled, /* signaled */
|
2007-05-08 18:37:21 +00:00
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
|
|
|
no_map_access, /* map_access */
|
2007-10-03 12:10:37 +00:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2007-05-08 18:37:21 +00:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 12:07:19 +00:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-05-08 18:37:21 +00:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 13:37:09 +00:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2007-05-08 18:37:21 +00:00
|
|
|
no_close_handle, /* close_handle */
|
2015-05-05 02:34:15 +00:00
|
|
|
irp_call_destroy /* destroy */
|
2007-05-08 18:37:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
/* device manager (a list of devices managed by the same client process) */
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
struct device_manager
|
|
|
|
{
|
2019-03-25 13:37:09 +00:00
|
|
|
struct object obj; /* object header */
|
|
|
|
struct list devices; /* list of devices */
|
|
|
|
struct list requests; /* list of pending irps across all devices */
|
|
|
|
struct wine_rb_tree kernel_objects; /* map of objects that have client side pointer associated */
|
2007-05-08 18:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void device_manager_dump( struct object *obj, int verbose );
|
2013-08-26 09:55:04 +00:00
|
|
|
static int device_manager_signaled( struct object *obj, struct wait_queue_entry *entry );
|
2007-05-08 18:28:37 +00:00
|
|
|
static void device_manager_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops device_manager_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct device_manager), /* size */
|
|
|
|
device_manager_dump, /* dump */
|
2007-12-05 17:16:42 +00:00
|
|
|
no_get_type, /* get_type */
|
2007-05-08 18:37:21 +00:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
|
|
|
device_manager_signaled, /* signaled */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
|
|
|
no_map_access, /* map_access */
|
2007-10-03 12:10:37 +00:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 12:07:19 +00:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 13:37:09 +00:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
device_manager_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
/* device (a single device object) */
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
struct device
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct device_manager *manager; /* manager for this device (or NULL if deleted) */
|
2015-05-21 08:18:08 +00:00
|
|
|
char *unix_path; /* path to unix device if any */
|
2008-12-29 16:28:40 +00:00
|
|
|
client_ptr_t user_ptr; /* opaque ptr for client side */
|
2007-05-08 18:28:37 +00:00
|
|
|
struct list entry; /* entry in device manager list */
|
2015-05-18 07:42:03 +00:00
|
|
|
struct list files; /* list of open files */
|
2007-05-08 18:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void device_dump( struct object *obj, int verbose );
|
2007-12-05 17:16:42 +00:00
|
|
|
static struct object_type *device_get_type( struct object *obj );
|
2007-05-08 18:28:37 +00:00
|
|
|
static void device_destroy( struct object *obj );
|
|
|
|
static struct object *device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options );
|
|
|
|
|
|
|
|
static const struct object_ops device_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct device), /* size */
|
|
|
|
device_dump, /* dump */
|
2007-12-05 17:16:42 +00:00
|
|
|
device_get_type, /* get_type */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
2015-05-18 07:42:03 +00:00
|
|
|
no_get_fd, /* get_fd */
|
2007-10-02 12:20:15 +00:00
|
|
|
default_fd_map_access, /* map_access */
|
2007-10-03 12:10:37 +00:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 12:08:02 +00:00
|
|
|
directory_link_name, /* link_name */
|
|
|
|
default_unlink_name, /* unlink_name */
|
2007-05-08 18:28:37 +00:00
|
|
|
device_open_file, /* open_file */
|
2019-03-25 13:37:09 +00:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2007-05-08 18:28:37 +00:00
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
device_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
|
|
|
|
/* device file (an open file handle to a device) */
|
|
|
|
|
|
|
|
struct device_file
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct device *device; /* device for this file */
|
|
|
|
struct fd *fd; /* file descriptor for irp */
|
2015-07-08 09:56:01 +00:00
|
|
|
client_ptr_t user_ptr; /* opaque ptr for client side */
|
2015-05-18 07:42:03 +00:00
|
|
|
struct list entry; /* entry in device list */
|
|
|
|
struct list requests; /* list of pending irp requests */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void device_file_dump( struct object *obj, int verbose );
|
|
|
|
static struct fd *device_file_get_fd( struct object *obj );
|
2015-07-08 09:05:04 +00:00
|
|
|
static int device_file_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
|
2015-05-18 07:42:03 +00:00
|
|
|
static void device_file_destroy( struct object *obj );
|
|
|
|
static enum server_fd_type device_file_get_fd_type( struct fd *fd );
|
2017-06-26 10:17:36 +00:00
|
|
|
static int device_file_read( struct fd *fd, struct async *async, file_pos_t pos );
|
2017-06-26 10:18:23 +00:00
|
|
|
static int device_file_write( struct fd *fd, struct async *async, file_pos_t pos );
|
2017-06-26 10:20:20 +00:00
|
|
|
static int device_file_flush( struct fd *fd, struct async *async );
|
2017-06-26 10:20:10 +00:00
|
|
|
static int device_file_ioctl( struct fd *fd, ioctl_code_t code, struct async *async );
|
2015-05-18 07:42:03 +00:00
|
|
|
|
|
|
|
static const struct object_ops device_file_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct device_file), /* size */
|
|
|
|
device_file_dump, /* dump */
|
2019-02-22 12:14:34 +00:00
|
|
|
file_get_type, /* get_type */
|
2015-05-18 07:42:03 +00:00
|
|
|
add_queue, /* add_queue */
|
|
|
|
remove_queue, /* remove_queue */
|
|
|
|
default_fd_signaled, /* signaled */
|
|
|
|
no_satisfied, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
device_file_get_fd, /* get_fd */
|
|
|
|
default_fd_map_access, /* map_access */
|
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 12:07:19 +00:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2015-05-18 07:42:03 +00:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 13:37:09 +00:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2015-07-08 09:05:04 +00:00
|
|
|
device_file_close_handle, /* close_handle */
|
2015-05-18 07:42:03 +00:00
|
|
|
device_file_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct fd_ops device_file_fd_ops =
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
|
|
|
default_fd_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
2015-05-18 07:42:03 +00:00
|
|
|
device_file_get_fd_type, /* get_fd_type */
|
|
|
|
device_file_read, /* read */
|
|
|
|
device_file_write, /* write */
|
|
|
|
device_file_flush, /* flush */
|
2018-10-23 15:45:06 +00:00
|
|
|
default_fd_get_file_info, /* get_file_info */
|
2017-10-02 14:42:16 +00:00
|
|
|
no_fd_get_volume_info, /* get_volume_info */
|
2015-05-18 07:42:03 +00:00
|
|
|
device_file_ioctl, /* ioctl */
|
2007-05-08 18:28:37 +00:00
|
|
|
default_fd_queue_async, /* queue_async */
|
2016-12-01 11:10:34 +00:00
|
|
|
default_fd_reselect_async /* reselect_async */
|
2007-05-08 18:28:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-25 13:37:09 +00:00
|
|
|
struct list *no_kernel_obj_list( struct object *obj )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct kernel_object
|
|
|
|
{
|
|
|
|
struct device_manager *manager;
|
|
|
|
client_ptr_t user_ptr;
|
|
|
|
struct object *object;
|
|
|
|
struct list list_entry;
|
|
|
|
struct wine_rb_entry rb_entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int compare_kernel_object( const void *k, const struct wine_rb_entry *entry )
|
|
|
|
{
|
|
|
|
struct kernel_object *ptr = WINE_RB_ENTRY_VALUE( entry, struct kernel_object, rb_entry );
|
|
|
|
return memcmp( k, &ptr->user_ptr, sizeof(client_ptr_t) );
|
|
|
|
}
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
static void irp_call_dump( struct object *obj, int verbose )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp = (struct irp_call *)obj;
|
2015-05-18 07:42:03 +00:00
|
|
|
fprintf( stderr, "IRP call file=%p\n", irp->file );
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
static int irp_call_signaled( struct object *obj, struct wait_queue_entry *entry )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp = (struct irp_call *)obj;
|
2007-05-08 18:37:21 +00:00
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
return !irp->file; /* file is cleared once the irp has completed */
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
static void irp_call_destroy( struct object *obj )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp = (struct irp_call *)obj;
|
2007-05-08 18:37:21 +00:00
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
if (irp->async)
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
async_terminate( irp->async, STATUS_CANCELLED );
|
|
|
|
release_object( irp->async );
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
2016-12-04 20:21:25 +00:00
|
|
|
if (irp->iosb) release_object( irp->iosb );
|
2015-05-18 07:42:03 +00:00
|
|
|
if (irp->file) release_object( irp->file );
|
2015-07-13 06:10:30 +00:00
|
|
|
if (irp->thread) release_object( irp->thread );
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 13:50:49 +00:00
|
|
|
static struct irp_call *create_irp( struct device_file *file, const irp_params_t *params, struct async *async )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp;
|
2007-05-08 18:37:21 +00:00
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
if (!file->device->manager) /* it has been deleted */
|
2015-05-05 03:51:11 +00:00
|
|
|
{
|
|
|
|
set_error( STATUS_FILE_DELETED );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
if ((irp = alloc_object( &irp_call_ops )))
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
irp->file = (struct device_file *)grab_object( file );
|
2015-08-16 05:59:48 +00:00
|
|
|
irp->thread = NULL;
|
2015-05-05 02:34:15 +00:00
|
|
|
irp->async = NULL;
|
2015-05-06 02:21:40 +00:00
|
|
|
irp->params = *params;
|
2017-02-22 13:50:49 +00:00
|
|
|
irp->iosb = NULL;
|
2016-12-04 20:21:25 +00:00
|
|
|
|
2017-02-22 13:50:49 +00:00
|
|
|
if (async) irp->iosb = async_get_iosb( async );
|
|
|
|
if (!irp->iosb && !(irp->iosb = create_iosb( NULL, 0, 0 )))
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
release_object( irp );
|
|
|
|
irp = NULL;
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-05 02:34:15 +00:00
|
|
|
return irp;
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
static void set_irp_result( struct irp_call *irp, unsigned int status,
|
2015-05-05 04:35:27 +00:00
|
|
|
const void *out_data, data_size_t out_size, data_size_t result )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file = irp->file;
|
2016-12-04 20:21:25 +00:00
|
|
|
struct iosb *iosb = irp->iosb;
|
2007-05-08 18:37:21 +00:00
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
if (!file) return; /* already finished */
|
2007-05-08 18:37:21 +00:00
|
|
|
|
|
|
|
/* FIXME: handle the STATUS_PENDING case */
|
2016-12-04 20:21:25 +00:00
|
|
|
iosb->status = status;
|
|
|
|
iosb->result = result;
|
|
|
|
iosb->out_size = min( iosb->out_size, out_size );
|
|
|
|
if (iosb->out_size && !(iosb->out_data = memdup( out_data, iosb->out_size )))
|
|
|
|
iosb->out_size = 0;
|
2015-05-18 07:42:03 +00:00
|
|
|
irp->file = NULL;
|
2015-05-05 02:34:15 +00:00
|
|
|
if (irp->async)
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 04:35:27 +00:00
|
|
|
if (result) status = STATUS_ALERTED;
|
2015-05-05 02:34:15 +00:00
|
|
|
async_terminate( irp->async, status );
|
|
|
|
release_object( irp->async );
|
|
|
|
irp->async = NULL;
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
2015-05-05 02:34:15 +00:00
|
|
|
wake_up( &irp->obj, 0 );
|
2007-10-30 10:30:58 +00:00
|
|
|
|
2016-12-04 20:22:05 +00:00
|
|
|
/* remove it from the device queue */
|
|
|
|
list_remove( &irp->dev_entry );
|
|
|
|
release_object( irp ); /* no longer on the device queue */
|
2015-06-16 01:16:10 +00:00
|
|
|
release_object( file );
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
static void device_dump( struct object *obj, int verbose )
|
|
|
|
{
|
2016-01-21 12:08:56 +00:00
|
|
|
fputs( "Device\n", stderr );
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 17:16:42 +00:00
|
|
|
static struct object_type *device_get_type( struct object *obj )
|
|
|
|
{
|
|
|
|
static const WCHAR name[] = {'D','e','v','i','c','e'};
|
|
|
|
static const struct unicode_str str = { name, sizeof(name) };
|
|
|
|
return get_object_type( &str );
|
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
static void device_destroy( struct object *obj )
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
|
|
|
struct device *device = (struct device *)obj;
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
assert( list_empty( &device->files ));
|
|
|
|
|
2015-05-21 08:18:08 +00:00
|
|
|
free( device->unix_path );
|
2015-05-18 07:42:03 +00:00
|
|
|
if (device->manager) list_remove( &device->entry );
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 06:10:30 +00:00
|
|
|
static void add_irp_to_queue( struct device_file *file, struct irp_call *irp, struct thread *thread )
|
2015-07-08 08:55:14 +00:00
|
|
|
{
|
|
|
|
struct device_manager *manager = file->device->manager;
|
|
|
|
|
|
|
|
assert( manager );
|
|
|
|
|
|
|
|
grab_object( irp ); /* grab reference for queued irp */
|
2015-07-13 06:10:30 +00:00
|
|
|
irp->thread = thread ? (struct thread *)grab_object( thread ) : NULL;
|
2015-07-08 08:55:14 +00:00
|
|
|
list_add_tail( &file->requests, &irp->dev_entry );
|
|
|
|
list_add_tail( &manager->requests, &irp->mgr_entry );
|
|
|
|
if (list_head( &manager->requests ) == &irp->mgr_entry) wake_up( &manager->obj, 0 ); /* first one */
|
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
static struct object *device_open_file( struct object *obj, unsigned int access,
|
|
|
|
unsigned int sharing, unsigned int options )
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
|
|
|
struct device *device = (struct device *)obj;
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file;
|
2007-05-08 18:28:37 +00:00
|
|
|
|
2015-07-08 08:55:14 +00:00
|
|
|
if (!(file = alloc_object( &device_file_ops ))) return NULL;
|
|
|
|
|
|
|
|
file->device = (struct device *)grab_object( device );
|
2015-07-08 09:56:01 +00:00
|
|
|
file->user_ptr = 0;
|
2015-07-08 08:55:14 +00:00
|
|
|
list_init( &file->requests );
|
|
|
|
list_add_tail( &device->files, &file->entry );
|
|
|
|
if (device->unix_path)
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-07-08 08:55:14 +00:00
|
|
|
mode_t mode = 0666;
|
|
|
|
access = file->obj.ops->map_access( &file->obj, access );
|
|
|
|
file->fd = open_fd( NULL, device->unix_path, O_NONBLOCK | O_LARGEFILE,
|
|
|
|
&mode, access, sharing, options );
|
|
|
|
if (file->fd) set_fd_user( file->fd, &device_file_fd_ops, &file->obj );
|
|
|
|
}
|
2018-10-29 14:48:44 +00:00
|
|
|
else file->fd = alloc_pseudo_fd( &device_file_fd_ops, &file->obj, options );
|
2015-07-08 08:55:14 +00:00
|
|
|
|
|
|
|
if (!file->fd)
|
|
|
|
{
|
|
|
|
release_object( file );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-24 15:48:56 +00:00
|
|
|
allow_fd_caching( file->fd );
|
|
|
|
|
2015-07-08 08:55:14 +00:00
|
|
|
if (device->manager)
|
|
|
|
{
|
|
|
|
struct irp_call *irp;
|
|
|
|
irp_params_t params;
|
|
|
|
|
2015-08-16 06:00:13 +00:00
|
|
|
memset( ¶ms, 0, sizeof(params) );
|
2015-07-08 08:55:14 +00:00
|
|
|
params.create.major = IRP_MJ_CREATE;
|
|
|
|
params.create.access = access;
|
|
|
|
params.create.sharing = sharing;
|
|
|
|
params.create.options = options;
|
|
|
|
params.create.device = file->device->user_ptr;
|
2015-05-21 08:18:08 +00:00
|
|
|
|
2017-01-25 23:51:49 +00:00
|
|
|
if ((irp = create_irp( file, ¶ms, NULL )))
|
2015-05-18 07:42:03 +00:00
|
|
|
{
|
2015-07-13 06:10:30 +00:00
|
|
|
add_irp_to_queue( file, irp, NULL );
|
2015-07-08 08:55:14 +00:00
|
|
|
release_object( irp );
|
2015-05-18 07:42:03 +00:00
|
|
|
}
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
2015-05-18 07:42:03 +00:00
|
|
|
return &file->obj;
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
static void device_file_dump( struct object *obj, int verbose )
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file = (struct device_file *)obj;
|
|
|
|
|
|
|
|
fprintf( stderr, "File on device %p\n", file->device );
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
static struct fd *device_file_get_fd( struct object *obj )
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file = (struct device_file *)obj;
|
|
|
|
|
|
|
|
return (struct fd *)grab_object( file->fd );
|
|
|
|
}
|
|
|
|
|
2015-07-08 09:05:04 +00:00
|
|
|
static int device_file_close_handle( struct object *obj, struct process *process, obj_handle_t handle )
|
|
|
|
{
|
|
|
|
struct device_file *file = (struct device_file *)obj;
|
|
|
|
|
|
|
|
if (file->device->manager && obj->handle_count == 1) /* last handle */
|
|
|
|
{
|
|
|
|
struct irp_call *irp;
|
|
|
|
irp_params_t params;
|
|
|
|
|
2015-08-16 06:00:13 +00:00
|
|
|
memset( ¶ms, 0, sizeof(params) );
|
2015-07-08 09:56:01 +00:00
|
|
|
params.close.major = IRP_MJ_CLOSE;
|
|
|
|
params.close.file = file->user_ptr;
|
2015-07-08 09:05:04 +00:00
|
|
|
|
2017-01-25 23:51:49 +00:00
|
|
|
if ((irp = create_irp( file, ¶ms, NULL )))
|
2015-07-08 09:05:04 +00:00
|
|
|
{
|
2015-07-13 06:10:30 +00:00
|
|
|
add_irp_to_queue( file, irp, NULL );
|
2015-07-08 09:05:04 +00:00
|
|
|
release_object( irp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
static void device_file_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct device_file *file = (struct device_file *)obj;
|
|
|
|
struct irp_call *irp, *next;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( irp, next, &file->requests, struct irp_call, dev_entry )
|
|
|
|
{
|
|
|
|
list_remove( &irp->dev_entry );
|
|
|
|
release_object( irp ); /* no longer on the device queue */
|
|
|
|
}
|
|
|
|
if (file->fd) release_object( file->fd );
|
|
|
|
list_remove( &file->entry );
|
|
|
|
release_object( file->device );
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
|
2015-07-08 09:56:01 +00:00
|
|
|
static void set_file_user_ptr( struct device_file *file, client_ptr_t ptr )
|
|
|
|
{
|
|
|
|
struct irp_call *irp;
|
|
|
|
|
|
|
|
if (file->user_ptr == ptr) return; /* nothing to do */
|
|
|
|
|
|
|
|
file->user_ptr = ptr;
|
|
|
|
|
|
|
|
/* update already queued irps */
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( irp, &file->requests, struct irp_call, dev_entry )
|
|
|
|
{
|
|
|
|
switch (irp->params.major)
|
|
|
|
{
|
|
|
|
case IRP_MJ_CLOSE: irp->params.close.file = ptr; break;
|
2015-07-08 10:04:32 +00:00
|
|
|
case IRP_MJ_READ: irp->params.read.file = ptr; break;
|
|
|
|
case IRP_MJ_WRITE: irp->params.write.file = ptr; break;
|
|
|
|
case IRP_MJ_FLUSH_BUFFERS: irp->params.flush.file = ptr; break;
|
|
|
|
case IRP_MJ_DEVICE_CONTROL: irp->params.ioctl.file = ptr; break;
|
2015-07-08 09:56:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:51:11 +00:00
|
|
|
/* queue an irp to the device */
|
2017-07-04 13:26:44 +00:00
|
|
|
static int queue_irp( struct device_file *file, const irp_params_t *params, struct async *async )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2017-07-04 13:26:44 +00:00
|
|
|
struct irp_call *irp = create_irp( file, params, async );
|
|
|
|
if (!irp) return 0;
|
2007-05-08 18:37:21 +00:00
|
|
|
|
2017-07-04 13:26:44 +00:00
|
|
|
fd_queue_async( file->fd, async, ASYNC_TYPE_WAIT );
|
2017-02-22 13:50:49 +00:00
|
|
|
irp->async = (struct async *)grab_object( async );
|
2015-07-13 06:10:30 +00:00
|
|
|
add_irp_to_queue( file, irp, current );
|
2017-07-04 13:26:44 +00:00
|
|
|
release_object( irp );
|
2007-05-08 18:37:21 +00:00
|
|
|
set_error( STATUS_PENDING );
|
2017-06-26 10:20:27 +00:00
|
|
|
return 1;
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
static enum server_fd_type device_file_get_fd_type( struct fd *fd )
|
2015-05-05 03:51:11 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
return FD_TYPE_DEVICE;
|
|
|
|
}
|
|
|
|
|
2017-06-26 10:17:36 +00:00
|
|
|
static int device_file_read( struct fd *fd, struct async *async, file_pos_t pos )
|
2015-05-18 07:42:03 +00:00
|
|
|
{
|
|
|
|
struct device_file *file = get_fd_user( fd );
|
2015-05-06 02:21:40 +00:00
|
|
|
irp_params_t params;
|
2015-05-05 03:51:11 +00:00
|
|
|
|
2015-08-16 06:00:13 +00:00
|
|
|
memset( ¶ms, 0, sizeof(params) );
|
2015-07-08 10:04:32 +00:00
|
|
|
params.read.major = IRP_MJ_READ;
|
|
|
|
params.read.key = 0;
|
|
|
|
params.read.pos = pos;
|
|
|
|
params.read.file = file->user_ptr;
|
2017-07-04 13:26:44 +00:00
|
|
|
return queue_irp( file, ¶ms, async );
|
2015-05-05 03:51:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 10:18:23 +00:00
|
|
|
static int device_file_write( struct fd *fd, struct async *async, file_pos_t pos )
|
2015-05-05 03:51:11 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file = get_fd_user( fd );
|
2015-05-06 02:21:40 +00:00
|
|
|
irp_params_t params;
|
|
|
|
|
2015-08-16 06:00:13 +00:00
|
|
|
memset( ¶ms, 0, sizeof(params) );
|
2015-07-08 10:04:32 +00:00
|
|
|
params.write.major = IRP_MJ_WRITE;
|
|
|
|
params.write.key = 0;
|
|
|
|
params.write.pos = pos;
|
|
|
|
params.write.file = file->user_ptr;
|
2017-07-04 13:26:44 +00:00
|
|
|
return queue_irp( file, ¶ms, async );
|
2015-05-05 03:51:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 10:20:20 +00:00
|
|
|
static int device_file_flush( struct fd *fd, struct async *async )
|
2015-05-06 08:13:51 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file = get_fd_user( fd );
|
2015-05-06 08:13:51 +00:00
|
|
|
irp_params_t params;
|
|
|
|
|
2015-08-16 06:00:13 +00:00
|
|
|
memset( ¶ms, 0, sizeof(params) );
|
2015-07-08 10:04:32 +00:00
|
|
|
params.flush.major = IRP_MJ_FLUSH_BUFFERS;
|
|
|
|
params.flush.file = file->user_ptr;
|
2018-01-02 12:56:54 +00:00
|
|
|
return queue_irp( file, ¶ms, async );
|
2015-05-06 08:13:51 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 10:20:10 +00:00
|
|
|
static int device_file_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
|
2015-05-05 03:51:11 +00:00
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
struct device_file *file = get_fd_user( fd );
|
2015-05-06 02:21:40 +00:00
|
|
|
irp_params_t params;
|
2015-05-05 03:51:11 +00:00
|
|
|
|
2015-08-16 06:00:13 +00:00
|
|
|
memset( ¶ms, 0, sizeof(params) );
|
2015-07-08 10:04:32 +00:00
|
|
|
params.ioctl.major = IRP_MJ_DEVICE_CONTROL;
|
|
|
|
params.ioctl.code = code;
|
|
|
|
params.ioctl.file = file->user_ptr;
|
2017-07-04 13:26:44 +00:00
|
|
|
return queue_irp( file, ¶ms, async );
|
2015-05-05 03:51:11 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 12:00:41 +00:00
|
|
|
static struct device *create_device( struct object *root, const struct unicode_str *name,
|
2007-05-08 18:28:37 +00:00
|
|
|
struct device_manager *manager, unsigned int attr )
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
|
2016-02-12 13:57:33 +00:00
|
|
|
if ((device = create_named_object( root, &device_ops, name, attr, NULL )))
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
|
|
|
if (get_error() != STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
{
|
|
|
|
/* initialize it if it didn't already exist */
|
2015-05-21 08:18:08 +00:00
|
|
|
device->unix_path = NULL;
|
2007-05-08 18:28:37 +00:00
|
|
|
device->manager = manager;
|
|
|
|
list_add_tail( &manager->devices, &device->entry );
|
2015-05-18 07:42:03 +00:00
|
|
|
list_init( &device->files );
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2016-07-18 06:34:08 +00:00
|
|
|
struct object *create_unix_device( struct object *root, const struct unicode_str *name,
|
2015-05-21 08:19:51 +00:00
|
|
|
const char *unix_path )
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
|
2016-02-12 13:57:33 +00:00
|
|
|
if ((device = create_named_object( root, &device_ops, name, 0, NULL )))
|
2015-05-21 08:19:51 +00:00
|
|
|
{
|
|
|
|
device->unix_path = strdup( unix_path );
|
|
|
|
device->manager = NULL; /* no manager, requests go straight to the Unix device */
|
|
|
|
list_init( &device->files );
|
|
|
|
}
|
2016-07-18 06:34:08 +00:00
|
|
|
return &device->obj;
|
2015-05-21 08:19:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-18 07:42:03 +00:00
|
|
|
/* terminate requests when the underlying device is deleted */
|
|
|
|
static void delete_file( struct device_file *file )
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp, *next;
|
2007-05-08 18:37:21 +00:00
|
|
|
|
|
|
|
/* terminate all pending requests */
|
2015-05-18 07:42:03 +00:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( irp, next, &file->requests, struct irp_call, dev_entry )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
list_remove( &irp->mgr_entry );
|
2015-05-05 04:35:27 +00:00
|
|
|
set_irp_result( irp, STATUS_FILE_DELETED, NULL, 0, 0 );
|
2007-05-08 18:37:21 +00:00
|
|
|
}
|
2015-05-18 07:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_device( struct device *device )
|
|
|
|
{
|
|
|
|
struct device_file *file, *next;
|
|
|
|
|
|
|
|
if (!device->manager) return; /* already deleted */
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( file, next, &device->files, struct device_file, entry )
|
|
|
|
delete_file( file );
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
unlink_named_object( &device->obj );
|
|
|
|
list_remove( &device->entry );
|
|
|
|
device->manager = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void device_manager_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Device manager\n" );
|
|
|
|
}
|
|
|
|
|
2013-08-26 09:55:04 +00:00
|
|
|
static int device_manager_signaled( struct object *obj, struct wait_queue_entry *entry )
|
2007-05-08 18:37:21 +00:00
|
|
|
{
|
|
|
|
struct device_manager *manager = (struct device_manager *)obj;
|
|
|
|
|
|
|
|
return !list_empty( &manager->requests );
|
|
|
|
}
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
static void device_manager_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct device_manager *manager = (struct device_manager *)obj;
|
2019-03-25 13:37:09 +00:00
|
|
|
struct kernel_object *kernel_object;
|
2007-05-08 18:28:37 +00:00
|
|
|
struct list *ptr;
|
|
|
|
|
2019-03-25 13:37:09 +00:00
|
|
|
while (manager->kernel_objects.root)
|
|
|
|
{
|
|
|
|
kernel_object = WINE_RB_ENTRY_VALUE( manager->kernel_objects.root, struct kernel_object, rb_entry );
|
|
|
|
wine_rb_remove( &manager->kernel_objects, &kernel_object->rb_entry );
|
|
|
|
list_remove( &kernel_object->list_entry );
|
|
|
|
free( kernel_object );
|
|
|
|
}
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
while ((ptr = list_head( &manager->devices )))
|
|
|
|
{
|
|
|
|
struct device *device = LIST_ENTRY( ptr, struct device, entry );
|
|
|
|
delete_device( device );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_manager *create_device_manager(void)
|
|
|
|
{
|
|
|
|
struct device_manager *manager;
|
|
|
|
|
|
|
|
if ((manager = alloc_object( &device_manager_ops )))
|
|
|
|
{
|
|
|
|
list_init( &manager->devices );
|
2007-05-08 18:37:21 +00:00
|
|
|
list_init( &manager->requests );
|
2019-03-25 13:37:09 +00:00
|
|
|
wine_rb_init( &manager->kernel_objects, compare_kernel_object );
|
2007-05-08 18:28:37 +00:00
|
|
|
}
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:37:09 +00:00
|
|
|
void free_kernel_objects( struct object *obj )
|
|
|
|
{
|
|
|
|
struct list *ptr, *list;
|
|
|
|
|
|
|
|
if (!(list = obj->ops->get_kernel_obj_list( obj ))) return;
|
|
|
|
|
|
|
|
while ((ptr = list_head( list )))
|
|
|
|
{
|
|
|
|
struct kernel_object *kernel_object = LIST_ENTRY( ptr, struct kernel_object, list_entry );
|
|
|
|
list_remove( &kernel_object->list_entry );
|
|
|
|
wine_rb_remove( &kernel_object->manager->kernel_objects, &kernel_object->rb_entry );
|
|
|
|
free( kernel_object );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 18:28:37 +00:00
|
|
|
|
|
|
|
/* create a device manager */
|
|
|
|
DECL_HANDLER(create_device_manager)
|
|
|
|
{
|
|
|
|
struct device_manager *manager = create_device_manager();
|
|
|
|
|
|
|
|
if (manager)
|
|
|
|
{
|
|
|
|
reply->handle = alloc_handle( current->process, manager, req->access, req->attributes );
|
|
|
|
release_object( manager );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create a device */
|
|
|
|
DECL_HANDLER(create_device)
|
|
|
|
{
|
|
|
|
struct device *device;
|
2016-01-29 07:36:45 +00:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2007-05-08 18:28:37 +00:00
|
|
|
struct device_manager *manager;
|
2016-02-12 12:00:41 +00:00
|
|
|
struct object *root = NULL;
|
2007-05-08 18:28:37 +00:00
|
|
|
|
|
|
|
if (!(manager = (struct device_manager *)get_handle_obj( current->process, req->manager,
|
|
|
|
0, &device_manager_ops )))
|
|
|
|
return;
|
|
|
|
|
2016-02-12 12:00:41 +00:00
|
|
|
if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir )))
|
2007-05-08 18:28:37 +00:00
|
|
|
{
|
|
|
|
release_object( manager );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((device = create_device( root, &name, manager, req->attributes )))
|
|
|
|
{
|
|
|
|
device->user_ptr = req->user_ptr;
|
|
|
|
reply->handle = alloc_handle( current->process, device, req->access, req->attributes );
|
|
|
|
release_object( device );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root) release_object( root );
|
|
|
|
release_object( manager );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* delete a device */
|
|
|
|
DECL_HANDLER(delete_device)
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
|
|
|
|
if ((device = (struct device *)get_handle_obj( current->process, req->handle, 0, &device_ops )))
|
|
|
|
{
|
|
|
|
delete_device( device );
|
|
|
|
release_object( device );
|
|
|
|
}
|
|
|
|
}
|
2007-05-08 18:40:26 +00:00
|
|
|
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
/* retrieve the next pending device irp request */
|
2007-05-08 18:40:26 +00:00
|
|
|
DECL_HANDLER(get_next_device_request)
|
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp;
|
2007-05-08 18:40:26 +00:00
|
|
|
struct device_manager *manager;
|
|
|
|
struct list *ptr;
|
2016-12-04 20:21:25 +00:00
|
|
|
struct iosb *iosb;
|
2007-05-08 18:40:26 +00:00
|
|
|
|
2015-07-08 08:55:14 +00:00
|
|
|
reply->params.major = IRP_MJ_MAXIMUM_FUNCTION + 1;
|
|
|
|
|
2007-05-08 18:40:26 +00:00
|
|
|
if (!(manager = (struct device_manager *)get_handle_obj( current->process, req->manager,
|
|
|
|
0, &device_manager_ops )))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (req->prev)
|
|
|
|
{
|
2015-05-18 07:42:03 +00:00
|
|
|
if ((irp = (struct irp_call *)get_handle_obj( current->process, req->prev, 0, &irp_call_ops )))
|
2007-05-08 18:40:26 +00:00
|
|
|
{
|
2015-05-05 04:35:27 +00:00
|
|
|
set_irp_result( irp, req->status, NULL, 0, 0 );
|
2007-05-08 18:40:26 +00:00
|
|
|
close_handle( current->process, req->prev ); /* avoid an extra round-trip for close */
|
2015-05-05 02:34:15 +00:00
|
|
|
release_object( irp );
|
2007-05-08 18:40:26 +00:00
|
|
|
}
|
|
|
|
clear_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ptr = list_head( &manager->requests )))
|
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
irp = LIST_ENTRY( ptr, struct irp_call, mgr_entry );
|
2015-07-13 06:10:30 +00:00
|
|
|
if (irp->thread)
|
|
|
|
{
|
|
|
|
reply->client_pid = get_process_id( irp->thread->process );
|
|
|
|
reply->client_tid = get_thread_id( irp->thread );
|
|
|
|
}
|
2015-05-06 02:21:40 +00:00
|
|
|
reply->params = irp->params;
|
2016-12-04 20:21:25 +00:00
|
|
|
iosb = irp->iosb;
|
|
|
|
reply->in_size = iosb->in_size;
|
|
|
|
reply->out_size = iosb->out_size;
|
|
|
|
if (iosb->in_size > get_reply_max_size()) set_error( STATUS_BUFFER_OVERFLOW );
|
2015-05-05 02:34:15 +00:00
|
|
|
else if ((reply->next = alloc_handle( current->process, irp, 0, 0 )))
|
2007-05-08 18:40:26 +00:00
|
|
|
{
|
2016-12-04 20:21:25 +00:00
|
|
|
set_reply_data_ptr( iosb->in_data, iosb->in_size );
|
|
|
|
iosb->in_data = NULL;
|
|
|
|
iosb->in_size = 0;
|
2015-05-05 02:34:15 +00:00
|
|
|
list_remove( &irp->mgr_entry );
|
|
|
|
list_init( &irp->mgr_entry );
|
2007-05-08 18:40:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else set_error( STATUS_PENDING );
|
|
|
|
|
|
|
|
release_object( manager );
|
|
|
|
}
|
2007-05-08 18:45:44 +00:00
|
|
|
|
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
/* store results of an async irp */
|
|
|
|
DECL_HANDLER(set_irp_result)
|
2015-03-11 13:45:51 +00:00
|
|
|
{
|
2015-05-05 02:34:15 +00:00
|
|
|
struct irp_call *irp;
|
2015-03-11 13:45:51 +00:00
|
|
|
|
2015-05-05 02:34:15 +00:00
|
|
|
if ((irp = (struct irp_call *)get_handle_obj( current->process, req->handle, 0, &irp_call_ops )))
|
2015-03-11 13:45:51 +00:00
|
|
|
{
|
2015-07-08 09:56:01 +00:00
|
|
|
if (irp->file) set_file_user_ptr( irp->file, req->file_ptr );
|
2015-05-05 04:35:27 +00:00
|
|
|
set_irp_result( irp, req->status, get_req_data(), get_req_data_size(), req->size );
|
2015-03-11 13:45:51 +00:00
|
|
|
close_handle( current->process, req->handle ); /* avoid an extra round-trip for close */
|
2015-05-05 02:34:15 +00:00
|
|
|
release_object( irp );
|
2015-03-11 13:45:51 +00:00
|
|
|
}
|
|
|
|
}
|