From 4a9a4240c6a381c5764ea0ca5fdffd14b6c0bf6b Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Thu, 5 Oct 2017 12:21:36 -0700 Subject: [PATCH] userspace: add _k_object_uninit() API to assist with re-using objects, such as terminated threads or kernel objects returned to a pool. Signed-off-by: Andrew Boie --- kernel/include/syscall_handler.h | 10 ++++++++++ kernel/userspace.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/kernel/include/syscall_handler.h b/kernel/include/syscall_handler.h index ce8526efe54..831b9c59ae8 100644 --- a/kernel/include/syscall_handler.h +++ b/kernel/include/syscall_handler.h @@ -105,6 +105,16 @@ extern void _thread_perms_clear(struct _k_object *ko, struct k_thread *thread); */ extern void _thread_perms_all_set(struct _k_object *ko); +/** + * Clear initialization state of a kernel object + * + * Intended for thread objects upon thread exit, or for other kernel objects + * that were released back to an object pool. + * + * @param object Address of the kernel object + */ +void _k_object_uninit(void *obj); + /** * @brief Runtime expression check for system call arguments * diff --git a/kernel/userspace.c b/kernel/userspace.c index 8f97957dd16..3b3abf2bad2 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -260,6 +260,19 @@ void _k_object_init(void *object) ko->flags |= K_OBJ_FLAG_INITIALIZED; } +void _k_object_uninit(void *object) +{ + struct _k_object *ko; + + /* See comments in _k_object_init() */ + ko = _k_object_find(object); + if (!ko) { + return; + } + + ko->flags &= ~K_OBJ_FLAG_INITIALIZED; +} + static u32_t _handler_bad_syscall(u32_t bad_id, u32_t arg2, u32_t arg3, u32_t arg4, u32_t arg5, u32_t arg6, void *ssf) {