userspace: add _k_object_recycle()

This is used to reset the permissions on an object while
also initializing it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2018-07-31 14:39:11 -07:00 committed by Andrew Boie
commit 83fda7c68f
2 changed files with 30 additions and 0 deletions

View file

@ -125,6 +125,25 @@ extern void _thread_perms_all_clear(struct k_thread *thread);
*/
void _k_object_uninit(void *obj);
/**
* Initialize and reset permissions to only access by the caller
*
* Intended for scenarios where objects are fetched from slab pools
* and may have had different permissions set during prior usage.
*
* This is only intended for pools of objects, where such objects are
* acquired and released to the pool. If an object has already been used,
* we do not want stale permission information hanging around, the object
* should only have permissions on the caller. Objects which are not
* managed by a pool-like mechanism should not use this API.
*
* The object will be marked as initialized and the calling thread
* granted access to it.
*
* @param object Address of the kernel object
*/
void _k_object_recycle(void *obj);
/**
* @brief Obtain the size of a C string passed from user mode
*

View file

@ -546,6 +546,17 @@ void _k_object_init(void *object)
ko->flags |= K_OBJ_FLAG_INITIALIZED;
}
void _k_object_recycle(void *object)
{
struct _k_object *ko = _k_object_find(object);
if (ko) {
memset(ko->perms, 0, sizeof(ko->perms));
_thread_perms_set(ko, k_current_get());
ko->flags |= K_OBJ_FLAG_INITIALIZED;
}
}
void _k_object_uninit(void *object)
{
struct _k_object *ko;