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 <andrew.p.boie@intel.com>
diff --git a/kernel/include/syscall_handler.h b/kernel/include/syscall_handler.h
index ce8526e..831b9c5 100644
--- a/kernel/include/syscall_handler.h
+++ b/kernel/include/syscall_handler.h
@@ -106,6 +106,16 @@
 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
  *
  * Used in handler functions to perform various runtime checks on arguments,
diff --git a/kernel/userspace.c b/kernel/userspace.c
index 8f97957..3b3abf2 100644
--- a/kernel/userspace.c
+++ b/kernel/userspace.c
@@ -260,6 +260,19 @@
 	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)
 {