wined3d: Simplify wined3d_rendertarget_view_create_from_sub_resource().
[wine.git] / server / handle.c
blob8d6637ea3a09366dc9595842af5ca6031f287973
1 /*
2 * Server-side handle management
4 * Copyright (C) 1998 Alexandre Julliard
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.
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.
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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <limits.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "winternl.h"
36 #include "handle.h"
37 #include "process.h"
38 #include "thread.h"
39 #include "security.h"
40 #include "request.h"
42 struct handle_entry
44 struct object *ptr; /* object */
45 unsigned int access; /* access rights */
48 struct handle_table
50 struct object obj; /* object header */
51 struct process *process; /* process owning this table */
52 int count; /* number of allocated entries */
53 int last; /* last used entry */
54 int free; /* first entry that may be free */
55 struct handle_entry *entries; /* handle entries */
58 static struct handle_table *global_table;
60 /* reserved handle access rights */
61 #define RESERVED_SHIFT 26
62 #define RESERVED_INHERIT (HANDLE_FLAG_INHERIT << RESERVED_SHIFT)
63 #define RESERVED_CLOSE_PROTECT (HANDLE_FLAG_PROTECT_FROM_CLOSE << RESERVED_SHIFT)
64 #define RESERVED_ALL (RESERVED_INHERIT | RESERVED_CLOSE_PROTECT)
66 #define MIN_HANDLE_ENTRIES 32
67 #define MAX_HANDLE_ENTRIES 0x00ffffff
70 /* handle to table index conversion */
72 /* handles are a multiple of 4 under NT; handle 0 is not used */
73 static inline obj_handle_t index_to_handle( int index )
75 return (obj_handle_t)((index + 1) << 2);
77 static inline int handle_to_index( obj_handle_t handle )
79 return (handle >> 2) - 1;
82 /* global handle conversion */
84 #define HANDLE_OBFUSCATOR 0x544a4def
86 static inline int handle_is_global( obj_handle_t handle)
88 return (handle ^ HANDLE_OBFUSCATOR) <= (MAX_HANDLE_ENTRIES << 2);
90 static inline obj_handle_t handle_local_to_global( obj_handle_t handle )
92 if (!handle) return 0;
93 return handle ^ HANDLE_OBFUSCATOR;
95 static inline obj_handle_t handle_global_to_local( obj_handle_t handle )
97 return handle ^ HANDLE_OBFUSCATOR;
100 /* grab an object and increment its handle count */
101 static struct object *grab_object_for_handle( struct object *obj )
103 obj->handle_count++;
104 return grab_object( obj );
107 /* release an object and decrement its handle count */
108 static void release_object_from_handle( struct object *obj )
110 assert( obj->handle_count );
111 obj->handle_count--;
112 release_object( obj );
115 static void handle_table_dump( struct object *obj, int verbose );
116 static void handle_table_destroy( struct object *obj );
118 static const struct object_ops handle_table_ops =
120 sizeof(struct handle_table), /* size */
121 handle_table_dump, /* dump */
122 no_get_type, /* get_type */
123 no_add_queue, /* add_queue */
124 NULL, /* remove_queue */
125 NULL, /* signaled */
126 NULL, /* satisfied */
127 no_signal, /* signal */
128 no_get_fd, /* get_fd */
129 no_map_access, /* map_access */
130 default_get_sd, /* get_sd */
131 default_set_sd, /* set_sd */
132 no_lookup_name, /* lookup_name */
133 no_open_file, /* open_file */
134 no_close_handle, /* close_handle */
135 handle_table_destroy /* destroy */
138 /* dump a handle table */
139 static void handle_table_dump( struct object *obj, int verbose )
141 int i;
142 struct handle_table *table = (struct handle_table *)obj;
143 struct handle_entry *entry;
145 assert( obj->ops == &handle_table_ops );
147 fprintf( stderr, "Handle table last=%d count=%d process=%p\n",
148 table->last, table->count, table->process );
149 if (!verbose) return;
150 entry = table->entries;
151 for (i = 0; i <= table->last; i++, entry++)
153 if (!entry->ptr) continue;
154 fprintf( stderr, " %04x: %p %08x ",
155 index_to_handle(i), entry->ptr, entry->access );
156 dump_object_name( entry->ptr );
157 entry->ptr->ops->dump( entry->ptr, 0 );
161 /* destroy a handle table */
162 static void handle_table_destroy( struct object *obj )
164 int i;
165 struct handle_table *table = (struct handle_table *)obj;
166 struct handle_entry *entry;
168 assert( obj->ops == &handle_table_ops );
170 /* first notify all objects that handles are being closed */
171 if (table->process)
173 for (i = 0, entry = table->entries; i <= table->last; i++, entry++)
175 struct object *obj = entry->ptr;
176 if (obj) obj->ops->close_handle( obj, table->process, index_to_handle(i) );
180 for (i = 0, entry = table->entries; i <= table->last; i++, entry++)
182 struct object *obj = entry->ptr;
183 entry->ptr = NULL;
184 if (obj) release_object_from_handle( obj );
186 free( table->entries );
189 /* close all the process handles and free the handle table */
190 void close_process_handles( struct process *process )
192 struct handle_table *table = process->handles;
194 process->handles = NULL;
195 if (table) release_object( table );
198 /* allocate a new handle table */
199 struct handle_table *alloc_handle_table( struct process *process, int count )
201 struct handle_table *table;
203 if (count < MIN_HANDLE_ENTRIES) count = MIN_HANDLE_ENTRIES;
204 if (!(table = alloc_object( &handle_table_ops )))
205 return NULL;
206 table->process = process;
207 table->count = count;
208 table->last = -1;
209 table->free = 0;
210 if ((table->entries = mem_alloc( count * sizeof(*table->entries) ))) return table;
211 release_object( table );
212 return NULL;
215 /* grow a handle table */
216 static int grow_handle_table( struct handle_table *table )
218 struct handle_entry *new_entries;
219 int count = min( table->count * 2, MAX_HANDLE_ENTRIES );
221 if (count == table->count ||
222 !(new_entries = realloc( table->entries, count * sizeof(struct handle_entry) )))
224 set_error( STATUS_INSUFFICIENT_RESOURCES );
225 return 0;
227 table->entries = new_entries;
228 table->count = count;
229 return 1;
232 /* allocate the first free entry in the handle table */
233 static obj_handle_t alloc_entry( struct handle_table *table, void *obj, unsigned int access )
235 struct handle_entry *entry = table->entries + table->free;
236 int i;
238 for (i = table->free; i <= table->last; i++, entry++) if (!entry->ptr) goto found;
239 if (i >= table->count)
241 if (!grow_handle_table( table )) return 0;
242 entry = table->entries + i; /* the entries may have moved */
244 table->last = i;
245 found:
246 table->free = i + 1;
247 entry->ptr = grab_object_for_handle( obj );
248 entry->access = access;
249 return index_to_handle(i);
252 /* allocate a handle for an object, incrementing its refcount */
253 static obj_handle_t alloc_handle_entry( struct process *process, void *ptr,
254 unsigned int access, unsigned int attr )
256 struct object *obj = ptr;
258 assert( !(access & RESERVED_ALL) );
259 if (attr & OBJ_INHERIT) access |= RESERVED_INHERIT;
260 if (!process->handles)
262 set_error( STATUS_PROCESS_IS_TERMINATING );
263 return 0;
265 return alloc_entry( process->handles, obj, access );
268 /* allocate a handle for an object, incrementing its refcount */
269 /* return the handle, or 0 on error */
270 obj_handle_t alloc_handle_no_access_check( struct process *process, void *ptr, unsigned int access, unsigned int attr )
272 struct object *obj = ptr;
273 access = obj->ops->map_access( obj, access ) & ~RESERVED_ALL;
274 return alloc_handle_entry( process, ptr, access, attr );
277 /* allocate a handle for an object, checking the dacl allows the process to */
278 /* access it and incrementing its refcount */
279 /* return the handle, or 0 on error */
280 obj_handle_t alloc_handle( struct process *process, void *ptr, unsigned int access, unsigned int attr )
282 struct object *obj = ptr;
283 access = obj->ops->map_access( obj, access ) & ~RESERVED_ALL;
284 if (access && !check_object_access( obj, &access )) return 0;
285 return alloc_handle_entry( process, ptr, access, attr );
288 /* allocate a global handle for an object, incrementing its refcount */
289 /* return the handle, or 0 on error */
290 static obj_handle_t alloc_global_handle_no_access_check( void *obj, unsigned int access )
292 if (!global_table)
294 if (!(global_table = alloc_handle_table( NULL, 0 )))
295 return 0;
296 make_object_static( &global_table->obj );
298 return handle_local_to_global( alloc_entry( global_table, obj, access ));
301 /* allocate a global handle for an object, checking the dacl allows the */
302 /* process to access it and incrementing its refcount and incrementing its refcount */
303 /* return the handle, or 0 on error */
304 static obj_handle_t alloc_global_handle( void *obj, unsigned int access )
306 if (access && !check_object_access( obj, &access )) return 0;
307 return alloc_global_handle_no_access_check( obj, access );
310 /* return a handle entry, or NULL if the handle is invalid */
311 static struct handle_entry *get_handle( struct process *process, obj_handle_t handle )
313 struct handle_table *table = process->handles;
314 struct handle_entry *entry;
315 int index;
317 if (handle_is_global(handle))
319 handle = handle_global_to_local(handle);
320 table = global_table;
322 if (!table) return NULL;
323 index = handle_to_index( handle );
324 if (index < 0) return NULL;
325 if (index > table->last) return NULL;
326 entry = table->entries + index;
327 if (!entry->ptr) return NULL;
328 return entry;
331 /* attempt to shrink a table */
332 static void shrink_handle_table( struct handle_table *table )
334 struct handle_entry *entry = table->entries + table->last;
335 struct handle_entry *new_entries;
336 int count = table->count;
338 while (table->last >= 0)
340 if (entry->ptr) break;
341 table->last--;
342 entry--;
344 if (table->last >= count / 4) return; /* no need to shrink */
345 if (count < MIN_HANDLE_ENTRIES * 2) return; /* too small to shrink */
346 count /= 2;
347 if (!(new_entries = realloc( table->entries, count * sizeof(*new_entries) ))) return;
348 table->count = count;
349 table->entries = new_entries;
352 /* copy the handle table of the parent process */
353 /* return 1 if OK, 0 on error */
354 struct handle_table *copy_handle_table( struct process *process, struct process *parent )
356 struct handle_table *parent_table = parent->handles;
357 struct handle_table *table;
358 int i;
360 assert( parent_table );
361 assert( parent_table->obj.ops == &handle_table_ops );
363 if (!(table = alloc_handle_table( process, parent_table->count )))
364 return NULL;
366 if ((table->last = parent_table->last) >= 0)
368 struct handle_entry *ptr = table->entries;
369 memcpy( ptr, parent_table->entries, (table->last + 1) * sizeof(struct handle_entry) );
370 for (i = 0; i <= table->last; i++, ptr++)
372 if (!ptr->ptr) continue;
373 if (ptr->access & RESERVED_INHERIT) grab_object_for_handle( ptr->ptr );
374 else ptr->ptr = NULL; /* don't inherit this entry */
377 /* attempt to shrink the table */
378 shrink_handle_table( table );
379 return table;
382 /* close a handle and decrement the refcount of the associated object */
383 unsigned int close_handle( struct process *process, obj_handle_t handle )
385 struct handle_table *table;
386 struct handle_entry *entry;
387 struct object *obj;
389 if (!(entry = get_handle( process, handle ))) return STATUS_INVALID_HANDLE;
390 if (entry->access & RESERVED_CLOSE_PROTECT) return STATUS_HANDLE_NOT_CLOSABLE;
391 obj = entry->ptr;
392 if (!obj->ops->close_handle( obj, process, handle )) return STATUS_HANDLE_NOT_CLOSABLE;
393 entry->ptr = NULL;
394 table = handle_is_global(handle) ? global_table : process->handles;
395 if (entry < table->entries + table->free) table->free = entry - table->entries;
396 if (entry == table->entries + table->last) shrink_handle_table( table );
397 release_object_from_handle( obj );
398 return STATUS_SUCCESS;
401 /* retrieve the object corresponding to one of the magic pseudo-handles */
402 static inline struct object *get_magic_handle( obj_handle_t handle )
404 switch(handle)
406 case 0xfffffffe: /* current thread pseudo-handle */
407 return &current->obj;
408 case 0x7fffffff: /* current process pseudo-handle */
409 case 0xffffffff: /* current process pseudo-handle */
410 return (struct object *)current->process;
411 default:
412 return NULL;
416 /* retrieve the object corresponding to a handle, incrementing its refcount */
417 struct object *get_handle_obj( struct process *process, obj_handle_t handle,
418 unsigned int access, const struct object_ops *ops )
420 struct handle_entry *entry;
421 struct object *obj;
423 if (!(obj = get_magic_handle( handle )))
425 if (!(entry = get_handle( process, handle )))
427 set_error( STATUS_INVALID_HANDLE );
428 return NULL;
430 obj = entry->ptr;
431 if (ops && (obj->ops != ops))
433 set_error( STATUS_OBJECT_TYPE_MISMATCH ); /* not the right type */
434 return NULL;
436 if ((entry->access & access) != access)
438 set_error( STATUS_ACCESS_DENIED );
439 return NULL;
442 else if (ops && (obj->ops != ops))
444 set_error( STATUS_OBJECT_TYPE_MISMATCH ); /* not the right type */
445 return NULL;
447 return grab_object( obj );
450 /* retrieve the access rights of a given handle */
451 unsigned int get_handle_access( struct process *process, obj_handle_t handle )
453 struct handle_entry *entry;
455 if (get_magic_handle( handle )) return ~RESERVED_ALL; /* magic handles have all access rights */
456 if (!(entry = get_handle( process, handle ))) return 0;
457 return entry->access & ~RESERVED_ALL;
460 /* find the first inherited handle of the given type */
461 /* this is needed for window stations and desktops (don't ask...) */
462 obj_handle_t find_inherited_handle( struct process *process, const struct object_ops *ops )
464 struct handle_table *table = process->handles;
465 struct handle_entry *ptr;
466 int i;
468 if (!table) return 0;
470 for (i = 0, ptr = table->entries; i <= table->last; i++, ptr++)
472 if (!ptr->ptr) continue;
473 if (ptr->ptr->ops != ops) continue;
474 if (ptr->access & RESERVED_INHERIT) return index_to_handle(i);
476 return 0;
479 /* enumerate handles of a given type */
480 /* this is needed for window stations and desktops */
481 obj_handle_t enumerate_handles( struct process *process, const struct object_ops *ops,
482 unsigned int *index )
484 struct handle_table *table = process->handles;
485 unsigned int i;
486 struct handle_entry *entry;
488 if (!table) return 0;
490 for (i = *index, entry = &table->entries[i]; i <= table->last; i++, entry++)
492 if (!entry->ptr) continue;
493 if (entry->ptr->ops != ops) continue;
494 *index = i + 1;
495 return index_to_handle(i);
497 return 0;
500 /* get/set the handle reserved flags */
501 /* return the old flags (or -1 on error) */
502 static int set_handle_flags( struct process *process, obj_handle_t handle, int mask, int flags )
504 struct handle_entry *entry;
505 unsigned int old_access;
507 if (get_magic_handle( handle ))
509 /* we can retrieve but not set info for magic handles */
510 if (mask) set_error( STATUS_ACCESS_DENIED );
511 return 0;
513 if (!(entry = get_handle( process, handle )))
515 set_error( STATUS_INVALID_HANDLE );
516 return -1;
518 old_access = entry->access;
519 mask = (mask << RESERVED_SHIFT) & RESERVED_ALL;
520 flags = (flags << RESERVED_SHIFT) & mask;
521 entry->access = (entry->access & ~mask) | flags;
522 return (old_access & RESERVED_ALL) >> RESERVED_SHIFT;
525 /* duplicate a handle */
526 obj_handle_t duplicate_handle( struct process *src, obj_handle_t src_handle, struct process *dst,
527 unsigned int access, unsigned int attr, unsigned int options )
529 obj_handle_t res;
530 struct handle_entry *entry;
531 unsigned int src_access;
532 struct object *obj = get_handle_obj( src, src_handle, 0, NULL );
534 if (!obj) return 0;
535 if ((entry = get_handle( src, src_handle )))
536 src_access = entry->access;
537 else /* pseudo-handle, give it full access */
538 src_access = obj->ops->map_access( obj, GENERIC_ALL );
539 src_access &= ~RESERVED_ALL;
541 if (options & DUP_HANDLE_SAME_ACCESS)
542 access = src_access;
543 else
544 access = obj->ops->map_access( obj, access ) & ~RESERVED_ALL;
546 /* asking for the more access rights than src_access? */
547 if (access & ~src_access)
549 if (options & DUP_HANDLE_MAKE_GLOBAL)
550 res = alloc_global_handle( obj, access );
551 else
552 res = alloc_handle( dst, obj, access, attr );
554 else
556 if (options & DUP_HANDLE_MAKE_GLOBAL)
557 res = alloc_global_handle_no_access_check( obj, access );
558 else if ((options & DUP_HANDLE_CLOSE_SOURCE) && src == dst &&
559 entry && !(entry->access & RESERVED_CLOSE_PROTECT))
561 if (attr & OBJ_INHERIT) access |= RESERVED_INHERIT;
562 entry->access = access;
563 res = src_handle;
565 else
566 res = alloc_handle_entry( dst, obj, access, attr );
569 release_object( obj );
570 return res;
573 /* open a new handle to an existing object */
574 obj_handle_t open_object( struct process *process, obj_handle_t parent, unsigned int access,
575 const struct object_ops *ops, const struct unicode_str *name,
576 unsigned int attributes )
578 obj_handle_t handle = 0;
579 struct directory *root = NULL;
580 struct object *obj;
582 if (name->len >= 65534)
584 set_error( STATUS_OBJECT_NAME_INVALID );
585 return 0;
588 if (parent && !(root = get_directory_obj( process, parent, 0 ))) return 0;
590 if ((obj = open_object_dir( root, name, attributes, ops )))
592 handle = alloc_handle( process, obj, access, attributes );
593 release_object( obj );
595 if (root) release_object( root );
596 return handle;
599 /* return the size of the handle table of a given process */
600 unsigned int get_handle_table_count( struct process *process )
602 if (!process->handles) return 0;
603 return process->handles->count;
606 /* close a handle */
607 DECL_HANDLER(close_handle)
609 unsigned int err = close_handle( current->process, req->handle );
610 set_error( err );
613 /* set a handle information */
614 DECL_HANDLER(set_handle_info)
616 reply->old_flags = set_handle_flags( current->process, req->handle, req->mask, req->flags );
619 /* duplicate a handle */
620 DECL_HANDLER(dup_handle)
622 struct process *src, *dst = NULL;
624 reply->handle = 0;
625 if ((src = get_process_from_handle( req->src_process, PROCESS_DUP_HANDLE )))
627 if (req->options & DUP_HANDLE_MAKE_GLOBAL)
629 reply->handle = duplicate_handle( src, req->src_handle, NULL,
630 req->access, req->attributes, req->options );
632 else if ((dst = get_process_from_handle( req->dst_process, PROCESS_DUP_HANDLE )))
634 reply->handle = duplicate_handle( src, req->src_handle, dst,
635 req->access, req->attributes, req->options );
636 release_object( dst );
638 /* close the handle no matter what happened */
639 if ((req->options & DUP_HANDLE_CLOSE_SOURCE) && (src != dst || req->src_handle != reply->handle))
640 reply->closed = !close_handle( src, req->src_handle );
641 reply->self = (src == current->process);
642 release_object( src );
646 DECL_HANDLER(get_object_info)
648 struct object *obj;
649 WCHAR *name;
651 if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
653 reply->access = get_handle_access( current->process, req->handle );
654 reply->ref_count = obj->refcount;
655 reply->handle_count = obj->handle_count;
656 if ((name = get_object_full_name( obj, &reply->total )))
657 set_reply_data_ptr( name, min( reply->total, get_reply_max_size() ));
658 release_object( obj );
661 DECL_HANDLER(set_security_object)
663 data_size_t sd_size = get_req_data_size();
664 const struct security_descriptor *sd = get_req_data();
665 struct object *obj;
666 unsigned int access = 0;
668 if (!sd_is_valid( sd, sd_size ))
670 set_error( STATUS_ACCESS_VIOLATION );
671 return;
674 if (req->security_info & OWNER_SECURITY_INFORMATION ||
675 req->security_info & GROUP_SECURITY_INFORMATION)
676 access |= WRITE_OWNER;
677 if (req->security_info & SACL_SECURITY_INFORMATION)
678 access |= ACCESS_SYSTEM_SECURITY;
679 if (req->security_info & DACL_SECURITY_INFORMATION)
680 access |= WRITE_DAC;
682 if (!(obj = get_handle_obj( current->process, req->handle, access, NULL ))) return;
684 obj->ops->set_sd( obj, sd, req->security_info );
685 release_object( obj );
688 DECL_HANDLER(get_security_object)
690 const struct security_descriptor *sd;
691 struct object *obj;
692 unsigned int access = READ_CONTROL;
693 struct security_descriptor req_sd;
694 int present;
695 const SID *owner, *group;
696 const ACL *sacl, *dacl;
698 if (req->security_info & SACL_SECURITY_INFORMATION)
699 access |= ACCESS_SYSTEM_SECURITY;
701 if (!(obj = get_handle_obj( current->process, req->handle, access, NULL ))) return;
703 sd = obj->ops->get_sd( obj );
704 if (sd)
706 req_sd.control = sd->control & ~SE_SELF_RELATIVE;
708 owner = sd_get_owner( sd );
709 if (req->security_info & OWNER_SECURITY_INFORMATION)
710 req_sd.owner_len = sd->owner_len;
711 else
712 req_sd.owner_len = 0;
714 group = sd_get_group( sd );
715 if (req->security_info & GROUP_SECURITY_INFORMATION)
716 req_sd.group_len = sd->group_len;
717 else
718 req_sd.group_len = 0;
720 req_sd.control |= SE_SACL_PRESENT;
721 sacl = sd_get_sacl( sd, &present );
722 if (req->security_info & SACL_SECURITY_INFORMATION && present)
723 req_sd.sacl_len = sd->sacl_len;
724 else
725 req_sd.sacl_len = 0;
727 req_sd.control |= SE_DACL_PRESENT;
728 dacl = sd_get_dacl( sd, &present );
729 if (req->security_info & DACL_SECURITY_INFORMATION && present)
730 req_sd.dacl_len = sd->dacl_len;
731 else
732 req_sd.dacl_len = 0;
734 reply->sd_len = sizeof(req_sd) + req_sd.owner_len + req_sd.group_len +
735 req_sd.sacl_len + req_sd.dacl_len;
736 if (reply->sd_len <= get_reply_max_size())
738 char *ptr = set_reply_data_size(reply->sd_len);
740 memcpy( ptr, &req_sd, sizeof(req_sd) );
741 ptr += sizeof(req_sd);
742 memcpy( ptr, owner, req_sd.owner_len );
743 ptr += req_sd.owner_len;
744 memcpy( ptr, group, req_sd.group_len );
745 ptr += req_sd.group_len;
746 memcpy( ptr, sacl, req_sd.sacl_len );
747 ptr += req_sd.sacl_len;
748 memcpy( ptr, dacl, req_sd.dacl_len );
750 else
751 set_error(STATUS_BUFFER_TOO_SMALL);
754 release_object( obj );
757 struct enum_handle_info
759 unsigned int count;
760 struct handle_info *handle;
763 static int enum_handles( struct process *process, void *user )
765 struct enum_handle_info *info = user;
766 struct handle_table *table = process->handles;
767 struct handle_entry *entry;
768 struct handle_info *handle;
769 unsigned int i;
771 if (!table)
772 return 0;
774 for (i = 0, entry = table->entries; i <= table->last; i++, entry++)
776 if (!entry->ptr) continue;
777 if (!info->handle)
779 info->count++;
780 continue;
782 assert( info->count );
783 handle = info->handle++;
784 handle->owner = process->id;
785 handle->handle = index_to_handle(i);
786 handle->access = entry->access & ~RESERVED_ALL;
787 info->count--;
790 return 0;
793 DECL_HANDLER(get_system_handles)
795 struct enum_handle_info info;
796 struct handle_info *handle;
797 data_size_t max_handles = get_reply_max_size() / sizeof(*handle);
799 info.handle = NULL;
800 info.count = 0;
801 enum_processes( enum_handles, &info );
802 reply->count = info.count;
804 if (max_handles < info.count)
805 set_error( STATUS_BUFFER_TOO_SMALL );
806 else if ((handle = set_reply_data_size( info.count * sizeof(*handle) )))
808 info.handle = handle;
809 enum_processes( enum_handles, &info );