~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/server/user.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Server-side USER handles
  3  *
  4  * Copyright (C) 2001 Alexandre Julliard
  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
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "thread.h"
 22 #include "user.h"
 23 #include "request.h"
 24 
 25 struct user_handle
 26 {
 27     void          *ptr;          /* pointer to object */
 28     unsigned short type;         /* object type (0 if free) */
 29     unsigned short generation;   /* generation counter */
 30 };
 31 
 32 static struct user_handle *handles;
 33 static struct user_handle *freelist;
 34 static int nb_handles;
 35 static int allocated_handles;
 36 
 37 static struct user_handle *handle_to_entry( user_handle_t handle )
 38 {
 39     unsigned short generation;
 40     int index = ((handle & 0xffff) - FIRST_USER_HANDLE) >> 1;
 41     if (index < 0 || index >= nb_handles) return NULL;
 42     if (!handles[index].type) return NULL;
 43     generation = handle >> 16;
 44     if (generation == handles[index].generation || !generation || generation == 0xffff)
 45         return &handles[index];
 46     return NULL;
 47 }
 48 
 49 static inline user_handle_t entry_to_handle( struct user_handle *ptr )
 50 {
 51     unsigned int index = ptr - handles;
 52     return (index << 1) + FIRST_USER_HANDLE + (ptr->generation << 16);
 53 }
 54 
 55 static inline struct user_handle *alloc_user_entry(void)
 56 {
 57     struct user_handle *handle;
 58 
 59     if (freelist)
 60     {
 61         handle = freelist;
 62         freelist = handle->ptr;
 63         return handle;
 64     }
 65     if (nb_handles >= allocated_handles)  /* need to grow the array */
 66     {
 67         struct user_handle *new_handles;
 68         /* grow array by 50% (but at minimum 32 entries) */
 69         int growth = max( 32, allocated_handles / 2 );
 70         int new_size = min( allocated_handles + growth, (LAST_USER_HANDLE-FIRST_USER_HANDLE+1) >> 1 );
 71         if (new_size <= allocated_handles) return NULL;
 72         if (!(new_handles = realloc( handles, new_size * sizeof(*handles) )))
 73             return NULL;
 74         handles = new_handles;
 75         allocated_handles = new_size;
 76     }
 77     handle = &handles[nb_handles++];
 78     handle->generation = 0;
 79     return handle;
 80 }
 81 
 82 static inline void *free_user_entry( struct user_handle *ptr )
 83 {
 84     void *ret;
 85     ret = ptr->ptr;
 86     ptr->ptr  = freelist;
 87     ptr->type = 0;
 88     freelist  = ptr;
 89     return ret;
 90 }
 91 
 92 /* allocate a user handle for a given object */
 93 user_handle_t alloc_user_handle( void *ptr, enum user_object type )
 94 {
 95     struct user_handle *entry = alloc_user_entry();
 96     if (!entry) return 0;
 97     entry->ptr  = ptr;
 98     entry->type = type;
 99     if (++entry->generation >= 0xffff) entry->generation = 1;
100     return entry_to_handle( entry );
101 }
102 
103 /* return a pointer to a user object from its handle */
104 void *get_user_object( user_handle_t handle, enum user_object type )
105 {
106     struct user_handle *entry;
107 
108     if (!(entry = handle_to_entry( handle )) || entry->type != type) return NULL;
109     return entry->ptr;
110 }
111 
112 /* get the full handle for a possibly truncated handle */
113 user_handle_t get_user_full_handle( user_handle_t handle )
114 {
115     struct user_handle *entry;
116 
117     if (handle >> 16) return handle;
118     if (!(entry = handle_to_entry( handle ))) return handle;
119     return entry_to_handle( entry );
120 }
121 
122 /* same as get_user_object plus set the handle to the full 32-bit value */
123 void *get_user_object_handle( user_handle_t *handle, enum user_object type )
124 {
125     struct user_handle *entry;
126 
127     if (!(entry = handle_to_entry( *handle )) || entry->type != type) return NULL;
128     *handle = entry_to_handle( entry );
129     return entry->ptr;
130 }
131 
132 /* free a user handle and return a pointer to the object */
133 void *free_user_handle( user_handle_t handle )
134 {
135     struct user_handle *entry;
136 
137     if (!(entry = handle_to_entry( handle )))
138     {
139         set_error( STATUS_INVALID_HANDLE );
140         return NULL;
141     }
142     return free_user_entry( entry );
143 }
144 
145 /* return the next user handle after 'handle' that is of a given type */
146 void *next_user_handle( user_handle_t *handle, enum user_object type )
147 {
148     struct user_handle *entry;
149 
150     if (!*handle) entry = handles;
151     else
152     {
153         int index = ((*handle & 0xffff) - FIRST_USER_HANDLE) >> 1;
154         if (index < 0 || index >= nb_handles) return NULL;
155         entry = handles + index + 1;  /* start from the next one */
156     }
157     while (entry < handles + nb_handles)
158     {
159         if (!type || entry->type == type)
160         {
161             *handle = entry_to_handle( entry );
162             return entry->ptr;
163         }
164         entry++;
165     }
166     return NULL;
167 }
168 
169 /* free client-side user handles managed by the process */
170 void free_process_user_handles( struct process *process )
171 {
172     unsigned int i;
173 
174     for (i = 0; i < nb_handles; i++)
175         if (handles[i].type == USER_CLIENT && handles[i].ptr == process)
176             free_user_entry( &handles[i] );
177 }
178 
179 /* allocate an arbitrary user handle */
180 DECL_HANDLER(alloc_user_handle)
181 {
182     reply->handle = alloc_user_handle( current->process, USER_CLIENT );
183 }
184 
185 
186 /* free an arbitrary user handle */
187 DECL_HANDLER(free_user_handle)
188 {
189     struct user_handle *entry;
190 
191     if ((entry = handle_to_entry( req->handle )) && entry->type == USER_CLIENT)
192         free_user_entry( entry );
193     else
194         set_error( STATUS_INVALID_HANDLE );
195 }
196 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.