diff --git a/kernel/include/syscall_handler.h b/kernel/include/syscall_handler.h index eb0c1f16848..a0d595097eb 100644 --- a/kernel/include/syscall_handler.h +++ b/kernel/include/syscall_handler.h @@ -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 * diff --git a/kernel/userspace.c b/kernel/userspace.c index 0053028bed8..fce86b449c3 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -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;