1 /***********************************************************
3 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6 AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
7 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
8 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 ******************************************************************/
15 #include <X11/Xdefs.h>
16 #include <X11/Xosdefs.h>
17 #include <X11/Xfuncproto.h>
20 /*****************************************************************
22 *****************************************************************/
24 typedef struct _Private PrivateRec
, *PrivatePtr
;
27 /* XSELinux uses the same private keys for numerous objects */
30 /* Otherwise, you get a private in just the requested structure
32 /* These can have objects created before all of the keys are registered */
38 /* These cannot have any objects before all relevant keys are registered */
48 /* extension privates */
55 /* last private type */
59 typedef struct _DevPrivateKeyRec
{
65 struct _DevPrivateKeyRec
*next
;
66 } DevPrivateKeyRec
, *DevPrivateKey
;
68 typedef struct _DevPrivateSetRec
{
73 } DevPrivateSetRec
, *DevPrivateSetPtr
;
75 typedef struct _DevScreenPrivateKeyRec
{
76 DevPrivateKeyRec screenKey
;
77 } DevScreenPrivateKeyRec
, *DevScreenPrivateKey
;
80 * Let drivers know how to initialize private keys
83 #define HAS_DEVPRIVATEKEYREC 1
84 #define HAS_DIXREGISTERPRIVATEKEY 1
87 * Register a new private index for the private type.
89 * This initializes the specified key and optionally requests pre-allocated
90 * private space for your driver/module. If you request no extra space, you
91 * may set and get a single pointer value using this private key. Otherwise,
92 * you can get the address of the extra space and store whatever data you like
95 * You may call dixRegisterPrivateKey more than once on the same key, but the
96 * size and type must match or the server will abort.
98 * dixRegisterPrivateKey returns FALSE if it fails to allocate memory
99 * during its operation.
101 extern _X_EXPORT Bool
102 dixRegisterPrivateKey(DevPrivateKey key
, DevPrivateType type
, unsigned size
);
105 * Check whether a private key has been registered
108 dixPrivateKeyRegistered(DevPrivateKey key
)
110 return key
->initialized
;
114 * Get the address of the private storage.
116 * For keys with pre-defined storage, this gets the base of that storage
117 * Otherwise, it returns the place where the private pointer is stored.
120 dixGetPrivateAddr(PrivatePtr
*privates
, const DevPrivateKey key
)
122 assert(key
->initialized
);
123 return (char *) (*privates
) + key
->offset
;
127 * Fetch a private pointer stored in the object
129 * Returns the pointer stored with dixSetPrivate.
130 * This must only be used with keys that have
131 * no pre-defined storage
134 dixGetPrivate(PrivatePtr
*privates
, const DevPrivateKey key
)
136 assert(key
->size
== 0);
137 return *(void **) dixGetPrivateAddr(privates
, key
);
141 * Associate 'val' with 'key' in 'privates' so that later calls to
142 * dixLookupPrivate(privates, key) will return 'val'.
145 dixSetPrivate(PrivatePtr
*privates
, const DevPrivateKey key
, pointer val
)
147 assert(key
->size
== 0);
148 *(pointer
*) dixGetPrivateAddr(privates
, key
) = val
;
152 #include "resource.h"
155 * Lookup a pointer to the private record.
157 * For privates with defined storage, return the address of the
158 * storage. For privates without defined storage, return the pointer
161 static inline pointer
162 dixLookupPrivate(PrivatePtr
*privates
, const DevPrivateKey key
)
165 return dixGetPrivateAddr(privates
, key
);
167 return dixGetPrivate(privates
, key
);
171 * Look up the address of the pointer to the storage
173 * This returns the place where the private pointer is stored,
174 * which is only valid for privates without predefined storage.
176 static inline pointer
*
177 dixLookupPrivateAddr(PrivatePtr
*privates
, const DevPrivateKey key
)
179 assert(key
->size
== 0);
180 return (pointer
*) dixGetPrivateAddr(privates
, key
);
183 extern _X_EXPORT Bool
185 dixRegisterScreenPrivateKey(DevScreenPrivateKey key
, ScreenPtr pScreen
,
186 DevPrivateType type
, unsigned size
);
188 extern _X_EXPORT DevPrivateKey
189 _dixGetScreenPrivateKey(const DevScreenPrivateKey key
, ScreenPtr pScreen
);
192 dixGetScreenPrivateAddr(PrivatePtr
*privates
, const DevScreenPrivateKey key
,
195 return dixGetPrivateAddr(privates
, _dixGetScreenPrivateKey(key
, pScreen
));
199 dixGetScreenPrivate(PrivatePtr
*privates
, const DevScreenPrivateKey key
,
202 return dixGetPrivate(privates
, _dixGetScreenPrivateKey(key
, pScreen
));
206 dixSetScreenPrivate(PrivatePtr
*privates
, const DevScreenPrivateKey key
,
207 ScreenPtr pScreen
, pointer val
)
209 dixSetPrivate(privates
, _dixGetScreenPrivateKey(key
, pScreen
), val
);
212 static inline pointer
213 dixLookupScreenPrivate(PrivatePtr
*privates
, const DevScreenPrivateKey key
,
216 return dixLookupPrivate(privates
, _dixGetScreenPrivateKey(key
, pScreen
));
219 static inline pointer
*
220 dixLookupScreenPrivateAddr(PrivatePtr
*privates
, const DevScreenPrivateKey key
,
223 return dixLookupPrivateAddr(privates
,
224 _dixGetScreenPrivateKey(key
, pScreen
));
228 * These functions relate to allocations related to a specific screen;
229 * space will only be available for objects allocated for use on that
230 * screen. As such, only objects which are related directly to a specific
231 * screen are candidates for allocation this way, this includes
232 * windows, pixmaps, gcs, pictures and colormaps. This key is
233 * used just like any other key using dixGetPrivate and friends.
235 * This is distinctly different from the ScreenPrivateKeys above which
236 * allocate space in global objects like cursor bits for a specific
237 * screen, allowing multiple screen-related chunks of storage in a
238 * single global object.
241 #define HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS 1
243 extern _X_EXPORT Bool
244 dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen
, DevPrivateKey key
,
245 DevPrivateType type
, unsigned size
);
247 /* Clean up screen-specific privates before CloseScreen */
249 dixFreeScreenSpecificPrivates(ScreenPtr pScreen
);
251 /* Initialize screen-specific privates in AddScreen */
253 dixInitScreenSpecificPrivates(ScreenPtr pScreen
);
255 extern _X_EXPORT
void *
256 _dixAllocateScreenObjectWithPrivates(ScreenPtr pScreen
,
260 DevPrivateType type
);
262 #define dixAllocateScreenObjectWithPrivates(s, t, type) _dixAllocateScreenObjectWithPrivates(s, sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
265 dixScreenSpecificPrivatesSize(ScreenPtr pScreen
, DevPrivateType type
);
267 extern _X_EXPORT
void
268 _dixInitScreenPrivates(ScreenPtr pScreen
, PrivatePtr
*privates
, void *addr
, DevPrivateType type
);
270 #define dixInitScreenPrivates(s, o, v, type) _dixInitScreenPrivates(s, &(o)->devPrivates, (v), type);
273 * Allocates private data separately from main object.
275 * For objects created during server initialization, this allows those
276 * privates to be re-allocated as new private keys are registered.
278 * This includes screens, the serverClient, default colormaps and
279 * extensions entries.
281 extern _X_EXPORT Bool
282 dixAllocatePrivates(PrivatePtr
*privates
, DevPrivateType type
);
285 * Frees separately allocated private data
287 extern _X_EXPORT
void
288 dixFreePrivates(PrivatePtr privates
, DevPrivateType type
);
291 * Initialize privates by zeroing them
293 extern _X_EXPORT
void
294 _dixInitPrivates(PrivatePtr
*privates
, void *addr
, DevPrivateType type
);
296 #define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
301 extern _X_EXPORT
void
302 _dixFiniPrivates(PrivatePtr privates
, DevPrivateType type
);
304 #define dixFiniPrivates(o,t) _dixFiniPrivates((o)->devPrivates,t)
307 * Allocates private data at object creation time. Required
308 * for almost all objects, except for the list described
309 * above for dixAllocatePrivates.
311 extern _X_EXPORT
void *_dixAllocateObjectWithPrivates(unsigned size
,
314 DevPrivateType type
);
316 #define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
318 extern _X_EXPORT
void
320 _dixFreeObjectWithPrivates(void *object
, PrivatePtr privates
,
321 DevPrivateType type
);
323 #define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
326 * Return size of privates for the specified type
329 dixPrivatesSize(DevPrivateType type
);
332 * Dump out private stats to ErrorF
335 dixPrivateUsage(void);
338 * Resets the privates subsystem. dixResetPrivates is called from the main loop
339 * before each server generation. This function must only be called by main().
341 extern _X_EXPORT
void
342 dixResetPrivates(void);
345 * Looks up the offset where the devPrivates field is located.
347 * Returns -1 if the specified resource has no dev privates.
348 * The position of the devPrivates field varies by structure
349 * and calling code might only know the resource type, not the
350 * structure definition.
353 dixLookupPrivateOffset(RESTYPE type
);
356 * Convenience macro for adding an offset to an object pointer
357 * when making a call to one of the devPrivates functions
359 #define DEVPRIV_AT(ptr, offset) ((PrivatePtr *)((char *)(ptr) + offset))
361 #endif /* PRIVATES_H */