Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side handle management |
| 3 | * |
| 4 | * Copyright (C) 1998 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | #include "wine/port.h" |
| 23 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 24 | #include <assert.h> |
| 25 | #include <limits.h> |
| 26 | #include <string.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 27 | #include <stdarg.h> |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 31 | #include "ntstatus.h" |
| 32 | #define WIN32_NO_STATUS |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 33 | #include "windef.h" |
Vitaliy Margolen | a996000 | 2005-10-27 18:30:37 +0000 | [diff] [blame] | 34 | #include "winternl.h" |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 35 | |
| 36 | #include "handle.h" |
| 37 | #include "process.h" |
| 38 | #include "thread.h" |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 39 | #include "request.h" |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 40 | |
| 41 | struct handle_entry |
| 42 | { |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 43 | struct object *ptr; /* object */ |
| 44 | unsigned int access; /* access rights */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 47 | struct handle_table |
| 48 | { |
| 49 | struct object obj; /* object header */ |
| 50 | struct process *process; /* process owning this table */ |
| 51 | int count; /* number of allocated entries */ |
| 52 | int last; /* last used entry */ |
| 53 | int free; /* first entry that may be free */ |
| 54 | struct handle_entry *entries; /* handle entries */ |
| 55 | }; |
| 56 | |
| 57 | static struct handle_table *global_table; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 58 | |
| 59 | /* reserved handle access rights */ |
Alexandre Julliard | 78a3e63 | 2005-06-09 12:07:12 +0000 | [diff] [blame] | 60 | #define RESERVED_SHIFT 26 |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 61 | #define RESERVED_INHERIT (HANDLE_FLAG_INHERIT << RESERVED_SHIFT) |
| 62 | #define RESERVED_CLOSE_PROTECT (HANDLE_FLAG_PROTECT_FROM_CLOSE << RESERVED_SHIFT) |
| 63 | #define RESERVED_ALL (RESERVED_INHERIT | RESERVED_CLOSE_PROTECT) |
| 64 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 65 | #define MIN_HANDLE_ENTRIES 32 |
| 66 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 67 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 68 | /* handle to table index conversion */ |
| 69 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 70 | /* handles are a multiple of 4 under NT; handle 0 is not used */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 71 | inline static obj_handle_t index_to_handle( int index ) |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 72 | { |
Mike McCormack | e1c16ff | 2006-06-15 17:10:07 +0900 | [diff] [blame] | 73 | return (obj_handle_t)((unsigned long)(index + 1) << 2); |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 74 | } |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 75 | inline static int handle_to_index( obj_handle_t handle ) |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 76 | { |
Mike McCormack | e1c16ff | 2006-06-15 17:10:07 +0900 | [diff] [blame] | 77 | return ((unsigned long)handle >> 2) - 1; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /* global handle conversion */ |
| 81 | |
| 82 | #define HANDLE_OBFUSCATOR 0x544a4def |
| 83 | |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 84 | inline static int handle_is_global( obj_handle_t handle) |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 85 | { |
| 86 | return ((unsigned long)handle ^ HANDLE_OBFUSCATOR) < 0x10000; |
| 87 | } |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 88 | inline static obj_handle_t handle_local_to_global( obj_handle_t handle ) |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 89 | { |
| 90 | if (!handle) return 0; |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 91 | return (obj_handle_t)((unsigned long)handle ^ HANDLE_OBFUSCATOR); |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 92 | } |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 93 | inline static obj_handle_t handle_global_to_local( obj_handle_t handle ) |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 94 | { |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 95 | return (obj_handle_t)((unsigned long)handle ^ HANDLE_OBFUSCATOR); |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 99 | static void handle_table_dump( struct object *obj, int verbose ); |
| 100 | static void handle_table_destroy( struct object *obj ); |
| 101 | |
| 102 | static const struct object_ops handle_table_ops = |
| 103 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 104 | sizeof(struct handle_table), /* size */ |
| 105 | handle_table_dump, /* dump */ |
| 106 | no_add_queue, /* add_queue */ |
| 107 | NULL, /* remove_queue */ |
| 108 | NULL, /* signaled */ |
| 109 | NULL, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 110 | no_signal, /* signal */ |
Alexandre Julliard | 1ab243b | 2000-12-19 02:12:45 +0000 | [diff] [blame] | 111 | no_get_fd, /* get_fd */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 112 | no_map_access, /* map_access */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 113 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 114 | no_close_handle, /* close_handle */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 115 | handle_table_destroy /* destroy */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | /* dump a handle table */ |
| 119 | static void handle_table_dump( struct object *obj, int verbose ) |
| 120 | { |
| 121 | int i; |
| 122 | struct handle_table *table = (struct handle_table *)obj; |
| 123 | struct handle_entry *entry = table->entries; |
| 124 | |
| 125 | assert( obj->ops == &handle_table_ops ); |
| 126 | |
| 127 | fprintf( stderr, "Handle table last=%d count=%d process=%p\n", |
| 128 | table->last, table->count, table->process ); |
| 129 | if (!verbose) return; |
| 130 | entry = table->entries; |
| 131 | for (i = 0; i <= table->last; i++, entry++) |
| 132 | { |
| 133 | if (!entry->ptr) continue; |
Alexandre Julliard | 0ec183c | 2005-09-27 09:36:54 +0000 | [diff] [blame] | 134 | fprintf( stderr, " %p: %p %08x ", |
| 135 | index_to_handle(i), entry->ptr, entry->access ); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 136 | entry->ptr->ops->dump( entry->ptr, 0 ); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* destroy a handle table */ |
| 141 | static void handle_table_destroy( struct object *obj ) |
| 142 | { |
| 143 | int i; |
| 144 | struct handle_table *table = (struct handle_table *)obj; |
Alexandre Julliard | 0901b23 | 2005-06-14 19:16:56 +0000 | [diff] [blame] | 145 | struct handle_entry *entry; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 146 | |
| 147 | assert( obj->ops == &handle_table_ops ); |
| 148 | |
Alexandre Julliard | 0901b23 | 2005-06-14 19:16:56 +0000 | [diff] [blame] | 149 | /* first notify all objects that handles are being closed */ |
| 150 | if (table->process) |
| 151 | { |
| 152 | for (i = 0, entry = table->entries; i <= table->last; i++, entry++) |
| 153 | { |
| 154 | struct object *obj = entry->ptr; |
| 155 | if (obj) obj->ops->close_handle( obj, table->process, index_to_handle(i) ); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | for (i = 0, entry = table->entries; i <= table->last; i++, entry++) |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 160 | { |
| 161 | struct object *obj = entry->ptr; |
| 162 | entry->ptr = NULL; |
| 163 | if (obj) release_object( obj ); |
| 164 | } |
| 165 | free( table->entries ); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* allocate a new handle table */ |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 169 | struct handle_table *alloc_handle_table( struct process *process, int count ) |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 170 | { |
| 171 | struct handle_table *table; |
| 172 | |
| 173 | if (count < MIN_HANDLE_ENTRIES) count = MIN_HANDLE_ENTRIES; |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 174 | if (!(table = alloc_object( &handle_table_ops ))) |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 175 | return NULL; |
| 176 | table->process = process; |
| 177 | table->count = count; |
| 178 | table->last = -1; |
| 179 | table->free = 0; |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 180 | if ((table->entries = mem_alloc( count * sizeof(*table->entries) ))) return table; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 181 | release_object( table ); |
| 182 | return NULL; |
| 183 | } |
| 184 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 185 | /* grow a handle table */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 186 | static int grow_handle_table( struct handle_table *table ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 187 | { |
| 188 | struct handle_entry *new_entries; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 189 | int count = table->count; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 190 | |
| 191 | if (count >= INT_MAX / 2) return 0; |
| 192 | count *= 2; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 193 | if (!(new_entries = realloc( table->entries, count * sizeof(struct handle_entry) ))) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 194 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 195 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 196 | return 0; |
| 197 | } |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 198 | table->entries = new_entries; |
| 199 | table->count = count; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 200 | return 1; |
| 201 | } |
| 202 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 203 | /* allocate the first free entry in the handle table */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 204 | static obj_handle_t alloc_entry( struct handle_table *table, void *obj, unsigned int access ) |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 205 | { |
| 206 | struct handle_entry *entry = table->entries + table->free; |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 207 | int i; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 208 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 209 | for (i = table->free; i <= table->last; i++, entry++) if (!entry->ptr) goto found; |
| 210 | if (i >= table->count) |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 211 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 212 | if (!grow_handle_table( table )) return 0; |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 213 | entry = table->entries + i; /* the entries may have moved */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 214 | } |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 215 | table->last = i; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 216 | found: |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 217 | table->free = i + 1; |
| 218 | entry->ptr = grab_object( obj ); |
| 219 | entry->access = access; |
| 220 | return index_to_handle(i); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 223 | /* allocate a handle for an object, incrementing its refcount */ |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 224 | /* return the handle, or 0 on error */ |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 225 | obj_handle_t alloc_handle( struct process *process, void *ptr, unsigned int access, unsigned int attr ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 226 | { |
Alexandre Julliard | 28beba3 | 2005-12-12 14:57:40 +0100 | [diff] [blame] | 227 | struct object *obj = ptr; |
| 228 | |
| 229 | access = obj->ops->map_access( obj, access ); |
Alexandre Julliard | c976db1 | 2005-07-13 12:09:49 +0000 | [diff] [blame] | 230 | access &= ~RESERVED_ALL; |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 231 | if (attr & OBJ_INHERIT) access |= RESERVED_INHERIT; |
Alexandre Julliard | c976db1 | 2005-07-13 12:09:49 +0000 | [diff] [blame] | 232 | if (!process->handles) |
| 233 | { |
| 234 | set_error( STATUS_NO_MEMORY ); |
| 235 | return 0; |
| 236 | } |
| 237 | return alloc_entry( process->handles, obj, access ); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* allocate a global handle for an object, incrementing its refcount */ |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 241 | /* return the handle, or 0 on error */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 242 | static obj_handle_t alloc_global_handle( void *obj, unsigned int access ) |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 243 | { |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 244 | if (!global_table) |
| 245 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 246 | if (!(global_table = (struct handle_table *)alloc_handle_table( NULL, 0 ))) |
| 247 | return 0; |
Alexandre Julliard | b00fb17 | 2006-03-22 20:32:04 +0100 | [diff] [blame] | 248 | make_object_static( &global_table->obj ); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 249 | } |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 250 | return handle_local_to_global( alloc_entry( global_table, obj, access )); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 253 | /* return a handle entry, or NULL if the handle is invalid */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 254 | static struct handle_entry *get_handle( struct process *process, obj_handle_t handle ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 255 | { |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 256 | struct handle_table *table = process->handles; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 257 | struct handle_entry *entry; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 258 | int index; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 259 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 260 | if (handle_is_global(handle)) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 261 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 262 | handle = handle_global_to_local(handle); |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 263 | table = global_table; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 264 | } |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 265 | if (!table) goto error; |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 266 | index = handle_to_index( handle ); |
| 267 | if (index < 0) goto error; |
| 268 | if (index > table->last) goto error; |
| 269 | entry = table->entries + index; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 270 | if (!entry->ptr) goto error; |
| 271 | return entry; |
| 272 | |
| 273 | error: |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 274 | set_error( STATUS_INVALID_HANDLE ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 275 | return NULL; |
| 276 | } |
| 277 | |
| 278 | /* attempt to shrink a table */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 279 | static void shrink_handle_table( struct handle_table *table ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 280 | { |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 281 | struct handle_entry *entry = table->entries + table->last; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 282 | struct handle_entry *new_entries; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 283 | int count = table->count; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 284 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 285 | while (table->last >= 0) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 286 | { |
| 287 | if (entry->ptr) break; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 288 | table->last--; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 289 | entry--; |
| 290 | } |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 291 | if (table->last >= count / 4) return; /* no need to shrink */ |
| 292 | if (count < MIN_HANDLE_ENTRIES * 2) return; /* too small to shrink */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 293 | count /= 2; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 294 | if (!(new_entries = realloc( table->entries, count * sizeof(*new_entries) ))) return; |
| 295 | table->count = count; |
| 296 | table->entries = new_entries; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* copy the handle table of the parent process */ |
| 300 | /* return 1 if OK, 0 on error */ |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 301 | struct handle_table *copy_handle_table( struct process *process, struct process *parent ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 302 | { |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 303 | struct handle_table *parent_table = parent->handles; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 304 | struct handle_table *table; |
| 305 | int i; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 306 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 307 | assert( parent_table ); |
| 308 | assert( parent_table->obj.ops == &handle_table_ops ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 309 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 310 | if (!(table = (struct handle_table *)alloc_handle_table( process, parent_table->count ))) |
| 311 | return NULL; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 312 | |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 313 | if ((table->last = parent_table->last) >= 0) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 314 | { |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 315 | struct handle_entry *ptr = table->entries; |
| 316 | memcpy( ptr, parent_table->entries, (table->last + 1) * sizeof(struct handle_entry) ); |
| 317 | for (i = 0; i <= table->last; i++, ptr++) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 318 | { |
| 319 | if (!ptr->ptr) continue; |
| 320 | if (ptr->access & RESERVED_INHERIT) grab_object( ptr->ptr ); |
| 321 | else ptr->ptr = NULL; /* don't inherit this entry */ |
| 322 | } |
| 323 | } |
| 324 | /* attempt to shrink the table */ |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 325 | shrink_handle_table( table ); |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 326 | return table; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* close a handle and decrement the refcount of the associated object */ |
| 330 | /* return 1 if OK, 0 on error */ |
Alexandre Julliard | 8700c43 | 2006-11-02 20:52:05 +0100 | [diff] [blame] | 331 | int close_handle( struct process *process, obj_handle_t handle ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 332 | { |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 333 | struct handle_table *table; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 334 | struct handle_entry *entry; |
| 335 | struct object *obj; |
| 336 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 337 | if (!(entry = get_handle( process, handle ))) return 0; |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 338 | if (entry->access & RESERVED_CLOSE_PROTECT) |
| 339 | { |
Alexandre Julliard | f895ad1 | 2005-07-29 14:41:14 +0000 | [diff] [blame] | 340 | set_error( STATUS_HANDLE_NOT_CLOSABLE ); |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 341 | return 0; |
| 342 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 343 | obj = entry->ptr; |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 344 | if (!obj->ops->close_handle( obj, process, handle )) |
| 345 | { |
Alexandre Julliard | f895ad1 | 2005-07-29 14:41:14 +0000 | [diff] [blame] | 346 | set_error( STATUS_HANDLE_NOT_CLOSABLE ); |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 347 | return 0; |
| 348 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 349 | entry->ptr = NULL; |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 350 | table = handle_is_global(handle) ? global_table : process->handles; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 351 | if (entry < table->entries + table->free) table->free = entry - table->entries; |
| 352 | if (entry == table->entries + table->last) shrink_handle_table( table ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 353 | release_object( obj ); |
| 354 | return 1; |
| 355 | } |
| 356 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 357 | /* retrieve the object corresponding to one of the magic pseudo-handles */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 358 | static inline struct object *get_magic_handle( obj_handle_t handle ) |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 359 | { |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 360 | switch((unsigned long)handle) |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 361 | { |
| 362 | case 0xfffffffe: /* current thread pseudo-handle */ |
| 363 | return ¤t->obj; |
| 364 | case 0x7fffffff: /* current process pseudo-handle */ |
| 365 | case 0xffffffff: /* current process pseudo-handle */ |
| 366 | return (struct object *)current->process; |
| 367 | default: |
| 368 | return NULL; |
| 369 | } |
| 370 | } |
| 371 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 372 | /* retrieve the object corresponding to a handle, incrementing its refcount */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 373 | struct object *get_handle_obj( struct process *process, obj_handle_t handle, |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 374 | unsigned int access, const struct object_ops *ops ) |
| 375 | { |
| 376 | struct handle_entry *entry; |
| 377 | struct object *obj; |
| 378 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 379 | if (!(obj = get_magic_handle( handle ))) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 380 | { |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 381 | if (!(entry = get_handle( process, handle ))) return NULL; |
| 382 | if ((entry->access & access) != access) |
| 383 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 384 | set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 385 | return NULL; |
| 386 | } |
| 387 | obj = entry->ptr; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 388 | } |
| 389 | if (ops && (obj->ops != ops)) |
| 390 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 391 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); /* not the right type */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 392 | return NULL; |
| 393 | } |
| 394 | return grab_object( obj ); |
| 395 | } |
| 396 | |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 397 | /* retrieve the access rights of a given handle */ |
| 398 | unsigned int get_handle_access( struct process *process, obj_handle_t handle ) |
| 399 | { |
| 400 | struct handle_entry *entry; |
| 401 | |
| 402 | if (get_magic_handle( handle )) return ~0U; /* magic handles have all access rights */ |
| 403 | if (!(entry = get_handle( process, handle ))) return 0; |
| 404 | return entry->access; |
| 405 | } |
| 406 | |
Alexandre Julliard | 526a28d | 2002-10-02 23:49:30 +0000 | [diff] [blame] | 407 | /* find the first inherited handle of the given type */ |
| 408 | /* this is needed for window stations and desktops (don't ask...) */ |
| 409 | obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops ) |
| 410 | { |
| 411 | struct handle_table *table = process->handles; |
| 412 | struct handle_entry *ptr; |
| 413 | int i; |
| 414 | |
| 415 | if (!table) return 0; |
| 416 | |
| 417 | for (i = 0, ptr = table->entries; i <= table->last; i++, ptr++) |
| 418 | { |
| 419 | if (!ptr->ptr) continue; |
| 420 | if (ptr->ptr->ops != ops) continue; |
| 421 | if (ptr->access & RESERVED_INHERIT) return index_to_handle(i); |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 426 | /* get/set the handle reserved flags */ |
| 427 | /* return the old flags (or -1 on error) */ |
Alexandre Julliard | 38502f7 | 2005-08-23 18:43:50 +0000 | [diff] [blame] | 428 | static int set_handle_flags( struct process *process, obj_handle_t handle, int mask, int flags ) |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 429 | { |
| 430 | struct handle_entry *entry; |
| 431 | unsigned int old_access; |
| 432 | |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 433 | if (get_magic_handle( handle )) |
| 434 | { |
| 435 | /* we can retrieve but not set info for magic handles */ |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 436 | if (mask) set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | ceeb693 | 1999-11-04 02:33:45 +0000 | [diff] [blame] | 437 | return 0; |
| 438 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 439 | if (!(entry = get_handle( process, handle ))) return -1; |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 440 | old_access = entry->access; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 441 | mask = (mask << RESERVED_SHIFT) & RESERVED_ALL; |
| 442 | flags = (flags << RESERVED_SHIFT) & mask; |
| 443 | entry->access = (entry->access & ~mask) | flags; |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 444 | return (old_access & RESERVED_ALL) >> RESERVED_SHIFT; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* duplicate a handle */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 448 | obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, struct process *dst, |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 449 | unsigned int access, unsigned int attr, unsigned int options ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 450 | { |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 451 | obj_handle_t res; |
Alexandre Julliard | 0042cb3 | 1999-05-29 11:17:25 +0000 | [diff] [blame] | 452 | struct object *obj = get_handle_obj( src, src_handle, 0, NULL ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 453 | |
Alexandre Julliard | 8081e5a | 2001-01-05 04:08:07 +0000 | [diff] [blame] | 454 | if (!obj) return 0; |
Alexandre Julliard | 0042cb3 | 1999-05-29 11:17:25 +0000 | [diff] [blame] | 455 | if (options & DUP_HANDLE_SAME_ACCESS) |
| 456 | { |
| 457 | struct handle_entry *entry = get_handle( src, src_handle ); |
| 458 | if (entry) |
| 459 | access = entry->access; |
| 460 | else /* pseudo-handle, give it full access */ |
| 461 | { |
| 462 | access = STANDARD_RIGHTS_ALL | SPECIFIC_RIGHTS_ALL; |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 463 | clear_error(); |
Alexandre Julliard | 0042cb3 | 1999-05-29 11:17:25 +0000 | [diff] [blame] | 464 | } |
| 465 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 466 | access &= ~RESERVED_ALL; |
Alexandre Julliard | eb2e77f | 1999-06-04 19:49:54 +0000 | [diff] [blame] | 467 | if (options & DUP_HANDLE_MAKE_GLOBAL) |
| 468 | res = alloc_global_handle( obj, access ); |
| 469 | else |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 470 | res = alloc_handle( dst, obj, access, attr ); |
Alexandre Julliard | 0042cb3 | 1999-05-29 11:17:25 +0000 | [diff] [blame] | 471 | release_object( obj ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 472 | return res; |
| 473 | } |
| 474 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 475 | /* open a new handle to an existing object */ |
Alexandre Julliard | ead9b06 | 2005-11-18 16:31:18 +0000 | [diff] [blame] | 476 | obj_handle_t open_object( const struct namespace *namespace, const struct unicode_str *name, |
Vitaliy Margolen | a996000 | 2005-10-27 18:30:37 +0000 | [diff] [blame] | 477 | const struct object_ops *ops, unsigned int access, unsigned int attr ) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 478 | { |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 479 | obj_handle_t handle = 0; |
Alexandre Julliard | ead9b06 | 2005-11-18 16:31:18 +0000 | [diff] [blame] | 480 | struct object *obj = find_object( namespace, name, attr ); |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 481 | if (obj) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 482 | { |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 483 | if (ops && obj->ops != ops) |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 484 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 485 | else |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 486 | handle = alloc_handle( current->process, obj, access, attr ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 487 | release_object( obj ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 488 | } |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 489 | else |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 490 | set_error( STATUS_OBJECT_NAME_NOT_FOUND ); |
Alexandre Julliard | d16319c | 1999-11-25 21:30:24 +0000 | [diff] [blame] | 491 | return handle; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Eric Pouech | 9fd54b2 | 2003-09-16 01:07:21 +0000 | [diff] [blame] | 494 | /* return the size of the handle table of a given process */ |
| 495 | unsigned int get_handle_table_count( struct process *process ) |
| 496 | { |
Alexandre Julliard | c976db1 | 2005-07-13 12:09:49 +0000 | [diff] [blame] | 497 | if (!process->handles) return 0; |
Eric Pouech | 9fd54b2 | 2003-09-16 01:07:21 +0000 | [diff] [blame] | 498 | return process->handles->count; |
| 499 | } |
| 500 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 501 | /* close a handle */ |
| 502 | DECL_HANDLER(close_handle) |
| 503 | { |
Alexandre Julliard | 8700c43 | 2006-11-02 20:52:05 +0100 | [diff] [blame] | 504 | close_handle( current->process, req->handle ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* set a handle information */ |
| 508 | DECL_HANDLER(set_handle_info) |
| 509 | { |
Alexandre Julliard | 38502f7 | 2005-08-23 18:43:50 +0000 | [diff] [blame] | 510 | reply->old_flags = set_handle_flags( current->process, req->handle, req->mask, req->flags ); |
| 511 | } |
| 512 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 513 | /* duplicate a handle */ |
| 514 | DECL_HANDLER(dup_handle) |
| 515 | { |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 516 | struct process *src, *dst; |
| 517 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 518 | reply->handle = 0; |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 519 | if ((src = get_process_from_handle( req->src_process, PROCESS_DUP_HANDLE ))) |
| 520 | { |
| 521 | if (req->options & DUP_HANDLE_MAKE_GLOBAL) |
| 522 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 523 | reply->handle = duplicate_handle( src, req->src_handle, NULL, |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 524 | req->access, req->attributes, req->options ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 525 | } |
| 526 | else if ((dst = get_process_from_handle( req->dst_process, PROCESS_DUP_HANDLE ))) |
| 527 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 528 | reply->handle = duplicate_handle( src, req->src_handle, dst, |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 529 | req->access, req->attributes, req->options ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 530 | release_object( dst ); |
| 531 | } |
| 532 | /* close the handle no matter what happened */ |
| 533 | if (req->options & DUP_HANDLE_CLOSE_SOURCE) |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 534 | { |
Alexandre Julliard | 28418cc | 2006-11-02 20:48:19 +0100 | [diff] [blame] | 535 | unsigned int err = get_error(); /* don't overwrite error from the above calls */ |
Alexandre Julliard | 8700c43 | 2006-11-02 20:52:05 +0100 | [diff] [blame] | 536 | reply->closed = close_handle( src, req->src_handle ); |
Alexandre Julliard | 28418cc | 2006-11-02 20:48:19 +0100 | [diff] [blame] | 537 | set_error( err ); |
Alexandre Julliard | d549f69 | 2000-12-22 02:04:15 +0000 | [diff] [blame] | 538 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 539 | release_object( src ); |
| 540 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 541 | } |