kernel: delete separate logic for priv stacks

This never needed to be put in a separate gperf table.
Privilege mode stacks can be generated by the main
gen_kobject_list.py logic, which we do here.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h
index 15f6d4a..c1fd0e2 100644
--- a/kernel/include/kernel_internal.h
+++ b/kernel/include/kernel_internal.h
@@ -124,6 +124,10 @@
 extern K_THREAD_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_NUM_CPUS,
 				   CONFIG_ISR_STACK_SIZE);
 
+#ifdef CONFIG_GEN_PRIV_STACKS
+extern u8_t *z_priv_stack_find(k_thread_stack_t *stack);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/kernel/thread.c b/kernel/thread.c
index d0c3f55..ce14b20 100644
--- a/kernel/thread.c
+++ b/kernel/thread.c
@@ -641,7 +641,7 @@
 			       void *p1, void *p2, void *p3,
 			       int prio, u32_t options, s32_t delay)
 {
-	size_t total_size;
+	size_t total_size, stack_obj_size;
 	struct z_object *stack_object;
 
 	/* The thread and stack objects *must* be in an uninitialized state */
@@ -664,9 +664,14 @@
 	/* Testing less-than-or-equal since additional room may have been
 	 * allocated for alignment constraints
 	 */
-	Z_OOPS(Z_SYSCALL_VERIFY_MSG(total_size <= stack_object->data.stack_size,
+#ifdef CONFIG_GEN_PRIV_STACKS
+	stack_obj_size = stack_object->data.stack_data->size;
+#else
+	stack_obj_size = stack_object->data.stack_size;
+#endif
+	Z_OOPS(Z_SYSCALL_VERIFY_MSG(total_size <= stack_obj_size,
 				    "stack size %zu is too big, max is %zu",
-				    total_size, stack_object->data.stack_size));
+				    total_size, stack_obj_size));
 
 	/* User threads may only create other user threads and they can't
 	 * be marked as essential
diff --git a/kernel/userspace.c b/kernel/userspace.c
index 728671f..281f072 100644
--- a/kernel/userspace.c
+++ b/kernel/userspace.c
@@ -90,6 +90,25 @@
 	struct k_thread *parent;
 };
 
+#ifdef CONFIG_GEN_PRIV_STACKS
+/* See write_gperf_table() in scripts/gen_kobject_list.py. The privilege
+ * mode stacks are allocated as an array. The base of the array is
+ * aligned to Z_PRIVILEGE_STACK_ALIGN, and all members must be as well.
+ */
+BUILD_ASSERT(CONFIG_PRIVILEGED_STACK_SIZE % Z_PRIVILEGE_STACK_ALIGN == 0);
+
+u8_t *z_priv_stack_find(k_thread_stack_t *stack)
+{
+	struct z_object *obj = z_object_find(stack);
+
+	__ASSERT(obj != NULL, "stack object not found");
+	__ASSERT(obj->type == K_OBJ_THREAD_STACK_ELEMENT,
+		 "bad stack object");
+
+	return obj->data.stack_data->priv;
+}
+#endif /* CONFIG_GEN_PRIV_STACKS */
+
 #ifdef CONFIG_DYNAMIC_OBJECTS
 struct dyn_obj {
 	struct z_object kobj;