summaryrefslogtreecommitdiff
path: root/nuttx/include
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-09-14 09:53:54 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-09-14 09:53:54 -0600
commitdef9063a49cb5c309b03ad0dcd858d71a31a0ad5 (patch)
treedb1a6538db4823142b5e4ca2817f64e06f163a78 /nuttx/include
parent659cb309b3e0dde2ce2f69320569bcd3ebda93af (diff)
downloadnuttx-def9063a49cb5c309b03ad0dcd858d71a31a0ad5.tar.gz
nuttx-def9063a49cb5c309b03ad0dcd858d71a31a0ad5.tar.bz2
nuttx-def9063a49cb5c309b03ad0dcd858d71a31a0ad5.zip
Add the initial implementation of the process kernel stack logic. Not yet integrated into the main OS logic nor tested.
Diffstat (limited to 'nuttx/include')
-rw-r--r--nuttx/include/nuttx/addrenv.h15
-rw-r--r--nuttx/include/nuttx/arch.h55
2 files changed, 70 insertions, 0 deletions
diff --git a/nuttx/include/nuttx/addrenv.h b/nuttx/include/nuttx/addrenv.h
index ac5dce56e..77c7463a6 100644
--- a/nuttx/include/nuttx/addrenv.h
+++ b/nuttx/include/nuttx/addrenv.h
@@ -303,6 +303,21 @@ struct addrenv_reserve_s
* up_addrenv_vustack - Returns the virtual base address of the stack
* up_addrenv_ustackselect - Instantiate a stack address environment
*
+ * If CONFIG_ARCH_KERNEL_STACK is selected, then each user process will have
+ * two stacks: (1) a large (and possibly dynamic) user stack and (2) a
+ * smaller kernel stack. However, this option is *required* if both
+ * CONFIG_BUILD_KERNEL and CONFIG_LIBC_EXECFUNCS are selected. Why? Because
+ * when we instantiate and initialize the address environment of the new
+ * user process, we will temporarily lose the address environment of the old
+ * user process, including its stack contents. The kernel C logic will crash
+ * immediately with no valid stack in place.
+ *
+ * If CONFIG_ARCH_STACK_DYNAMIC=y is selected then the platform specific
+ * code must export these additional interfaces:
+ *
+ * up_addrenv_kstackalloc - Create a stack in the kernel address environment
+ * up_addrenv_kstackfree - Destroy the kernel stack.
+ *
****************************************************************************/
/* Prototyped in include/nuttx/arch.h as part of the OS/platform interface */
diff --git a/nuttx/include/nuttx/arch.h b/nuttx/include/nuttx/arch.h
index 7199b836b..d4b55d841 100644
--- a/nuttx/include/nuttx/arch.h
+++ b/nuttx/include/nuttx/arch.h
@@ -768,6 +768,21 @@ uintptr_t pgalloc(uintptr_t brkaddr, unsigned int npages);
* up_addrenv_vustack - Returns the virtual base address of the stack
* up_addrenv_ustackselect - Instantiate a stack address environment
*
+ * If CONFIG_ARCH_KERNEL_STACK is selected, then each user process will have
+ * two stacks: (1) a large (and possibly dynamic) user stack and (2) a
+ * smaller kernel stack. However, this option is *required* if both
+ * CONFIG_BUILD_KERNEL and CONFIG_LIBC_EXECFUNCS are selected. Why? Because
+ * when we instantiate and initialize the address environment of the new
+ * user process, we will temporarily lose the address environment of the old
+ * user process, including its stack contents. The kernel C logic will crash
+ * immediately with no valid stack in place.
+ *
+ * If CONFIG_ARCH_KERNEL_STACK=y is selected then the platform specific
+ * code must export these additional interfaces:
+ *
+ * up_addrenv_kstackalloc - Create a stack in the kernel address environment
+ * up_addrenv_kstackfree - Destroy the kernel stack.
+ *
****************************************************************************/
/****************************************************************************
* Name: up_addrenv_create
@@ -1132,6 +1147,46 @@ int up_addrenv_ustackselect(FAR const struct tcb_s *tcb);
#endif
/****************************************************************************
+ * Name: up_addrenv_kstackalloc
+ *
+ * Description:
+ * This function is called when a new thread is created to allocate
+ * the new thread's kernel stack.
+ *
+ * Input Parameters:
+ * tcb - The TCB of the thread that requires the kernel stack.
+ * stacksize - The size (in bytes) of the kernel stack needed by the
+ * thread.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
+int up_addrenv_kstackalloc(FAR struct tcb_s *tcb, size_t stacksize);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_kstackfree
+ *
+ * Description:
+ * This function is called when any thread exits. This function frees
+ * the kernel stack.
+ *
+ * Input Parameters:
+ * tcb - The TCB of the thread that no longer requires the kernel stack.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
+int up_addrenv_kstackfree(FAR struct tcb_s *tcb);
+#endif
+
+/****************************************************************************
* Name: up_interrupt_context
*
* Description: