These functions provide a wrapper that protect access to pointers.
More...
These functions provide a wrapper that protect access to pointers.
Eina_Safepointer is an pointer to index converter that allow an increased level of safety by forbidding direct access to the pointer. The protection work by using a set of indirection table that are mmapped and mprotected against write access. This the pointer they store and that map to a specific index is always correct. Also once a pointer is unregistered the index won't be served back for 2^8 on 32 bits system and 2^28 on 64 bits system for that specific slot. Finally we do guarantee that the lower 2 bits of the returned index are actually never used and completly ignored by our API. So you can safely store whatever information you want in it, we will ignore it and threat as if it wasn't there.
- Note
- The use of Eina_Safepointer is thread safe.
◆ eina_safepointer_register()
Register a pointer and get an Eina_Safepointer that map to it.
- Parameters
-
target | The pointer to register. |
- Returns
- A valid pointer that is an index to the mapped pointer.
- Note
- It will return
NULL
on error or if target
is NULL
.
-
The lower 2 bits of the returned pointer will always be 0.
-
The returned pointer can be used like a pointer, but can not be touched except with Eina_Safepointer functions.
- Since
- 1.18
References eina_spinlock_release(), and eina_spinlock_take().
◆ eina_safepointer_unregister()
◆ eina_safepointer_get()
Get the associated pointer from an Eina_Safepointer mapping.
- Parameters
-
safe | The Eina_Safepointer index to lookup at. |
- Returns
- The pointer registered with that index or
NULL
in any other case.
- Note
- It is always safe to ask for a pointer for any value of the mapping. If the pointer is invalid or
NULL
, we will return NULL
and not crash.