summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/arch/arm/src/common/up_createstack.c48
-rw-r--r--nuttx/arch/avr/src/avr/up_createstack.c72
-rw-r--r--nuttx/arch/avr/src/avr32/up_createstack.c88
-rw-r--r--nuttx/arch/hc/src/common/up_createstack.c105
-rw-r--r--nuttx/arch/mips/src/common/up_createstack.c108
-rw-r--r--nuttx/arch/sh/src/common/up_createstack.c110
-rw-r--r--nuttx/arch/sim/src/up_createstack.c3
-rw-r--r--nuttx/arch/x86/src/i486/up_createstack.c91
-rw-r--r--nuttx/arch/z16/src/common/up_createstack.c110
-rw-r--r--nuttx/arch/z80/src/common/up_createstack.c110
-rw-r--r--nuttx/mm/mm_malloc.c19
-rw-r--r--nuttx/sched/task_create.c1
-rw-r--r--nuttx/sched/task_vfork.c1
13 files changed, 553 insertions, 313 deletions
diff --git a/nuttx/arch/arm/src/common/up_createstack.c b/nuttx/arch/arm/src/common/up_createstack.c
index e3f963227..b17e13b5b 100644
--- a/nuttx/arch/arm/src/common/up_createstack.c
+++ b/nuttx/arch/arm/src/common/up_createstack.c
@@ -111,41 +111,58 @@ static void *memset32(void *s, uint32_t c, size_t n)
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup
- * up stack-related information in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
- * adj_stack_size: Stack size after adjustment for hardware,
- * processor, etc. This value is retained only for debug
- * purposes.
+ * adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
* stack_alloc_ptr: Pointer to allocated stack
- * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
- * initial value of the stack pointer.
+ * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much
- * must be allocated.
+ * stack_size: The requested stack size. At least this how much must be
+ * allocated.
+ *
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
- if (tcb->stack_alloc_ptr &&
- tcb->adj_stack_size != stack_size)
+ /* Is there already a stack allocated of a different size? */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
+ /* Do we need to allocate a stack? */
+
if (!tcb->stack_alloc_ptr)
{
-#ifdef CONFIG_DEBUG
- tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
#else
- tcb->stack_alloc_ptr = (uint32_t*)kmalloc(stack_size);
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
#endif
}
+ /* Did we successfully allocate a stack? */
+
if (tcb->stack_alloc_ptr)
{
size_t top_of_stack;
@@ -194,4 +211,3 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size)
return ERROR;
}
-
diff --git a/nuttx/arch/avr/src/avr/up_createstack.c b/nuttx/arch/avr/src/avr/up_createstack.c
index 904a4acab..aed449f82 100644
--- a/nuttx/arch/avr/src/avr/up_createstack.c
+++ b/nuttx/arch/avr/src/avr/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/avr/src/avr/up_createstack.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -71,7 +71,7 @@
*
* Description:
* Allocate a stack for a new thread and setup up stack-related
- * information in the TCB.
+ * information in the TCB.
*
* The following TCB fields must be initialized:
* adj_stack_size: Stack size after adjustment for hardware, processor,
@@ -99,52 +99,58 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size)
tcb->stack_alloc_ptr = NULL;
}
- /* Do we need to allocate a stack? */
-
- if (!tcb->stack_alloc_ptr)
- {
- /* Allocate the stack. If DEBUG is enabled (but not stack debug),
- * then create a zeroed stack to make stack dumps easier to trace.
- */
+ /* Do we need to allocate a stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
- tcb->stack_alloc_ptr = (FAR void *)zalloc(stack_size);
+ tcb->stack_alloc_ptr = (FAR void *)kzalloc(stack_size);
#else
- tcb->stack_alloc_ptr = (FAR void *)malloc(stack_size);
+ tcb->stack_alloc_ptr = (FAR void *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
#endif
- }
+ }
- /* Did we successfully allocate a stack? */
+ /* Did we successfully allocate a stack? */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
- /* Yes.. If stack debug is enabled, then fill the stack with a
- * recognizable value that we can use later to test for high
- * water marks.
- */
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
- memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
#endif
- /* The AVR uses a push-down stack: the stack grows toward lower
- * addresses in memory. The stack pointer register, points to the
- * lowest, valid work address (the "top" of the stack). Items on the
- * stack are referenced as positive word offsets from sp.
- */
+ /* The AVR uses a push-down stack: the stack grows toward lower
+ * addresses in memory. The stack pointer register, points to the
+ * lowest, valid work address (the "top" of the stack). Items on the
+ * stack are referenced as positive word offsets from sp.
+ */
- top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 1;
+ top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 1;
- /* Save the adjusted stack values in the struct tcb_s */
+ /* Save the adjusted stack values in the struct tcb_s */
- tcb->adj_stack_ptr = (FAR void *)top_of_stack;
- tcb->adj_stack_size = stack_size;
+ tcb->adj_stack_ptr = (FAR void *)top_of_stack;
+ tcb->adj_stack_size = stack_size;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/avr/src/avr32/up_createstack.c b/nuttx/arch/avr/src/avr32/up_createstack.c
index 93bbad6af..bfe87743f 100644
--- a/nuttx/arch/avr/src/avr32/up_createstack.c
+++ b/nuttx/arch/avr/src/avr32/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/avr/src/avr32/up_createstack.c
*
- * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2010-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,7 @@
*
* Description:
* Allocate a stack for a new thread and setup up stack-related
- * information in the TCB.
+ * information in the TCB.
*
* The following TCB fields must be initialized:
* adj_stack_size: Stack size after adjustment for hardware, processor,
@@ -88,50 +88,76 @@
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
- if (tcb->stack_alloc_ptr &&
- tcb->adj_stack_size != stack_size)
+ /* Is there already a stack allocated of a different size? */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
-#ifdef CONFIG_DEBUG
- tcb->stack_alloc_ptr = (FAR void *)zalloc(stack_size);
+ /* Do we need to allocate a stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (FAR void *)kzalloc(stack_size);
#else
- tcb->stack_alloc_ptr = (FAR void *)malloc(stack_size);
+ tcb->stack_alloc_ptr = (FAR void *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
#endif
- }
+ }
+
+ /* Did we successfully allocate a stack? */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
- /* The AVR32 uses a push-down stack: the stack grows toward lower
- * addresses in memory. The stack pointer register, points to the
- * lowest, valid work address (the "top" of the stack). Items on
- * the stack are referenced as positive word offsets from sp.
- */
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 4;
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- /* The AVR32 stack must be aligned at word (4 byte) boundaries. If
- * necessary top_of_stack must be rounded down to the next boundary
- */
+ /* The AVR32 uses a push-down stack: the stack grows toward lower
+ * addresses in memory. The stack pointer register, points to the
+ * lowest, valid work address (the "top" of the stack). Items on
+ * the stack are referenced as positive word offsets from sp.
+ */
- top_of_stack &= ~3;
- size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr + 4;
+ top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size - 4;
- /* Save the adjusted stack values in the struct tcb_s */
+ /* The AVR32 stack must be aligned at word (4 byte) boundaries. If
+ * necessary top_of_stack must be rounded down to the next boundary
+ */
- tcb->adj_stack_ptr = (FAR void *)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr + 4;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ tcb->adj_stack_ptr = (FAR void *)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/hc/src/common/up_createstack.c b/nuttx/arch/hc/src/common/up_createstack.c
index 8c29190ae..272c4e849 100644
--- a/nuttx/arch/hc/src/common/up_createstack.c
+++ b/nuttx/arch/hc/src/common/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/hc/src/common/up_createstack.c
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -66,66 +66,97 @@
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup up stack-related information
- * in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
- * adj_stack_size: Stack size after adjustment for hardware, processor, etc.
- * This value is retained only for debug purposes.
+ * adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
* stack_alloc_ptr: Pointer to allocated stack
- * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of the
- * stack pointer.
+ * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much must be
- * allocated.
+ * stack_size: The requested stack size. At least this how much must be
+ * allocated.
*
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
+ /* Is there already a stack allocated of a different size? */
+
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
- tcb->stack_alloc_ptr = (uint32_t *)malloc(stack_size);
- }
+ /* Do we need to allocate a stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
+#else
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
+#endif
+ }
+
+ /* Did we successfully allocate a stack? */
+
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- /* The CPU12 uses a push-down stack: the stack grows
- * toward lower addresses in memory. Because the CPU12 stack
- * operates as a decrement then store stack, the value assigned
- * to the initial stack pointer is one more than the last valid
- * stack address.
- */
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size;
+ /* The CPU12 uses a push-down stack: the stack grows
+ * toward lower addresses in memory. Because the CPU12 stack
+ * operates as a decrement then store stack, the value assigned
+ * to the initial stack pointer is one more than the last valid
+ * stack address.
+ */
- /* The CPU12 stack should be aligned at half-word (2 byte)
- * boundaries. If necessary top_of_stack must be rounded
- * down to the next boundary
- */
+ top_of_stack = (size_t)tcb->stack_alloc_ptr + stack_size;
- top_of_stack &= ~1;
- size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr;
+ /* The CPU12 stack should be aligned at half-word (2 byte)
+ * boundaries. If necessary top_of_stack must be rounded
+ * down to the next boundary
+ */
- /* Save the adjusted stack values in the struct tcb_s */
+ top_of_stack &= ~1;
+ size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr;
- tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ /* Save the adjusted stack values in the struct tcb_s */
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/mips/src/common/up_createstack.c b/nuttx/arch/mips/src/common/up_createstack.c
index f72701042..02cdd83d7 100644
--- a/nuttx/arch/mips/src/common/up_createstack.c
+++ b/nuttx/arch/mips/src/common/up_createstack.c
@@ -87,71 +87,97 @@
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup
- * up stack-related information in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
- * adj_stack_size: Stack size after adjustment for hardware,
- * processor, etc. This value is retained only for debug
- * purposes.
+ * adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
* stack_alloc_ptr: Pointer to allocated stack
- * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
- * initial value of the stack pointer.
+ * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much
- * must be allocated.
+ * stack_size: The requested stack size. At least this how much must be
+ * allocated.
+ *
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
- if (tcb->stack_alloc_ptr &&
- tcb->adj_stack_size != stack_size)
+ /* Is there already a stack allocated of a different size? */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
-#ifdef CONFIG_DEBUG
- tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
+ /* Do we need to allocate a stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
#else
- tcb->stack_alloc_ptr = (uint32_t*)kmalloc(stack_size);
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
#endif
- }
+ }
+
+ /* Did we successfully allocate a stack? */
+
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
+
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- /* MIPS uses a push-down stack: the stack grows toward lower
- * addresses in memory. The stack pointer register points to the
- * lowest, valid working address (the "top" of the stack). Items on
- * the stack are referenced as positive word offsets from sp.
- */
+ /* MIPS uses a push-down stack: the stack grows toward lower
+ * addresses in memory. The stack pointer register points to the
+ * lowest, valid working address (the "top" of the stack). Items on
+ * the stack are referenced as positive word offsets from sp.
+ */
- top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
- /* The MIPS stack must be aligned at word (4 byte) boundaries; for
- * floating point use, the stack must be aligned to 8-byte addresses.
- * If necessary top_of_stack must be rounded down to the next
- * boundary to meet these alignment requirements.
- */
+ /* The MIPS stack must be aligned at word (4 byte) boundaries; for
+ * floating point use, the stack must be aligned to 8-byte addresses.
+ * If necessary top_of_stack must be rounded down to the next
+ * boundary to meet these alignment requirements.
+ */
- top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
- size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+ top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
- /* Save the adjusted stack values in the struct tcb_s */
+ /* Save the adjusted stack values in the struct tcb_s */
- tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/sh/src/common/up_createstack.c b/nuttx/arch/sh/src/common/up_createstack.c
index f868750de..296245a49 100644
--- a/nuttx/arch/sh/src/common/up_createstack.c
+++ b/nuttx/arch/sh/src/common/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/sh/src/common/up_createstack.c
*
- * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -66,67 +66,97 @@
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup
- * up stack-related information in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
- * adj_stack_size: Stack size after adjustment for hardware,
- * processor, etc. This value is retained only for debug
- * purposes.
+ * adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
* stack_alloc_ptr: Pointer to allocated stack
- * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
- * initial value of the stack pointer.
+ * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much
- * must be allocated.
+ * stack_size: The requested stack size. At least this how much must be
+ * allocated.
+ *
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
- if (tcb->stack_alloc_ptr &&
- tcb->adj_stack_size != stack_size)
+ /* Is there already a stack allocated of a different size? */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
- tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
- }
+ /* Do we need to allocate a stack? */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
+#else
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
+#endif
+ }
- /* The Arm7Tdmi uses a push-down stack: the stack grows
- * toward loweraddresses in memory. The stack pointer
- * register, points to the lowest, valid work address
- * (the "top" of the stack). Items on the stack are
- * referenced as positive word offsets from sp.
- */
+ /* Did we successfully allocate a stack? */
- top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
- /* The Arm7Tdmi stack must be aligned at word (4 byte)
- * boundaries. If necessary top_of_stack must be rounded
- * down to the next boundary
- */
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- top_of_stack &= ~3;
- size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- /* Save the adjusted stack values in the struct tcb_s */
+ /* The SH family uses a push-down stack: the stack grows
+ * toward loweraddresses in memory. The stack pointer
+ * register, points to the lowest, valid work address
+ * (the "top" of the stack). Items on the stack are
+ * referenced as positive word offsets from sp.
+ */
- tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ /* The SH stack must be aligned at word (4 byte)
+ * boundaries. If necessary top_of_stack must be rounded
+ * down to the next boundary
+ */
+
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/sim/src/up_createstack.c b/nuttx/arch/sim/src/up_createstack.c
index 268a9ba46..fb7e80081 100644
--- a/nuttx/arch/sim/src/up_createstack.c
+++ b/nuttx/arch/sim/src/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/sim/src/up_createstack.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -110,5 +110,6 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size)
tcb->adj_stack_ptr = adj_stack_ptr;
ret = OK;
}
+
return ret;
}
diff --git a/nuttx/arch/x86/src/i486/up_createstack.c b/nuttx/arch/x86/src/i486/up_createstack.c
index fc739afdc..62a763b30 100644
--- a/nuttx/arch/x86/src/i486/up_createstack.c
+++ b/nuttx/arch/x86/src/i486/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/x86/src/i486/up_createstack.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -68,8 +68,8 @@
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup up stack-related information
- * in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
* adj_stack_size: Stack size after adjustment for hardware, processor,
@@ -78,58 +78,85 @@
* adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
* the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much must be
+ * stack_size: The requested stack size. At least this how much must be
* allocated.
*
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
+ /* Is there already a stack allocated of a different size? */
+
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
-#ifdef CONFIG_DEBUG
- tcb->stack_alloc_ptr = (uint32_t*)zalloc(stack_size);
+ /* Do we need to allocate a stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
#else
- tcb->stack_alloc_ptr = (uint32_t*)malloc(stack_size);
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
#endif
- }
+ }
+
+ /* Did we successfully allocate a stack? */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
- /* The i486 uses a push-down stack: the stack grows toward lower
- * addresses in memory. The stack pointer register, points to the
- * lowest, valid work address (the "top" of the stack). Items on
- * the stack are referenced as positive word offsets from sp.
- */
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- /* The i486 stack must be aligned at word (4 byte) boundaries. If
- * necessary top_of_stack must be rounded down to the next boundary
- */
+ /* The i486 uses a push-down stack: the stack grows toward lower
+ * addresses in memory. The stack pointer register, points to the
+ * lowest, valid work address (the "top" of the stack). Items on
+ * the stack are referenced as positive word offsets from sp.
+ */
- top_of_stack &= ~3;
- size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
- /* Save the adjusted stack values in the struct tcb_s */
+ /* The i486 stack must be aligned at word (4 byte) boundaries. If
+ * necessary top_of_stack must be rounded down to the next boundary
+ */
- tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/z16/src/common/up_createstack.c b/nuttx/arch/z16/src/common/up_createstack.c
index a65c69917..b2deb4bf0 100644
--- a/nuttx/arch/z16/src/common/up_createstack.c
+++ b/nuttx/arch/z16/src/common/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/z16/common/up_createstack.c
*
- * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2008-2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -67,67 +67,97 @@
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup
- * up stack-related information in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
- * adj_stack_size: Stack size after adjustment for hardware,
- * processor, etc. This value is retained only for debug
- * purposes.
+ * adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
* stack_alloc_ptr: Pointer to allocated stack
- * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
- * initial value of the stack pointer.
+ * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much
- * must be allocated.
+ * stack_size: The requested stack size. At least this how much must be
+ * allocated.
+ *
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
- if (tcb->stack_alloc_ptr &&
- tcb->adj_stack_size != stack_size)
+ /* Is there already a stack allocated of a different size? */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
- tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
- }
+ /* Do we need to allocate a stack? */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
+#else
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
+#endif
+ }
- /* The Arm7Tdmi uses a push-down stack: the stack grows
- * toward loweraddresses in memory. The stack pointer
- * register, points to the lowest, valid work address
- * (the "top" of the stack). Items on the stack are
- * referenced as positive word offsets from sp.
- */
+ /* Did we successfully allocate a stack? */
- top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
- /* The Arm7Tdmi stack must be aligned at word (4 byte)
- * boundaries. If necessary top_of_stack must be rounded
- * down to the next boundary
- */
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- top_of_stack &= ~3;
- size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- /* Save the adjusted stack values in the struct tcb_s */
+ /* The ZNeo uses a push-down stack: the stack grows
+ * toward loweraddresses in memory. The stack pointer
+ * register, points to the lowest, valid work address
+ * (the "top" of the stack). Items on the stack are
+ * referenced as positive word offsets from sp.
+ */
- tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ /* The ZNeo stack must be aligned at word (4 byte)
+ * boundaries. If necessary top_of_stack must be rounded
+ * down to the next boundary
+ */
+
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+
+ /* Save the adjusted stack values in the struct tcb_s */
+
+ tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
+
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/arch/z80/src/common/up_createstack.c b/nuttx/arch/z80/src/common/up_createstack.c
index 6636643b1..c00f5f071 100644
--- a/nuttx/arch/z80/src/common/up_createstack.c
+++ b/nuttx/arch/z80/src/common/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/z80/src/common/up_createstack.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,7 @@
#include <stdint.h>
#include <sched.h>
#include <debug.h>
+
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
@@ -65,67 +66,96 @@
* Name: up_create_stack
*
* Description:
- * Allocate a stack for a new thread and setup
- * up stack-related information in the TCB.
+ * Allocate a stack for a new thread and setup up stack-related
+ * information in the TCB.
*
* The following TCB fields must be initialized:
- * adj_stack_size: Stack size after adjustment for hardware,
- * processor, etc. This value is retained only for debug
- * purposes.
+ * adj_stack_size: Stack size after adjustment for hardware, processor,
+ * etc. This value is retained only for debug purposes.
* stack_alloc_ptr: Pointer to allocated stack
- * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
- * initial value of the stack pointer.
+ * adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
+ * the stack pointer.
*
- * Inputs:
+ * Input Parameters:
* tcb: The TCB of new task
- * stack_size: The requested stack size. At least this much
- * must be allocated.
+ * stack_size: The requested stack size. At least this how much must be
+ * allocated.
+ *
****************************************************************************/
int up_create_stack(struct tcb_s *tcb, size_t stack_size)
{
- if (tcb->stack_alloc_ptr &&
- tcb->adj_stack_size != stack_size)
+ /* Is there already a stack allocated of a different size? */
+
+ if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
+ /* Yes.. free it */
+
sched_free(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
}
- if (!tcb->stack_alloc_ptr)
- {
- tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
- }
+ /* Do we need to allocate a stack? */
+
+ if (!tcb->stack_alloc_ptr)
+ {
+ /* Allocate the stack. If DEBUG is enabled (but not stack debug),
+ * then create a zeroed stack to make stack dumps easier to trace.
+ */
+
+#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
+ tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
+#else
+ tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
+#endif
+#ifdef CONFIG_DEBUG
+ if (!tcb->stack_alloc_ptr)
+ {
+ sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
+ }
+#endif
+ }
+
+ /* Did we successfully allocate a stack? */
+
+ if (tcb->stack_alloc_ptr)
+ {
+ size_t top_of_stack;
+ size_t size_of_stack;
+
+ /* Yes.. If stack debug is enabled, then fill the stack with a
+ * recognizable value that we can use later to test for high
+ * water marks.
+ */
- if (tcb->stack_alloc_ptr)
- {
- size_t top_of_stack;
- size_t size_of_stack;
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
+ memset(tcb->stack_alloc_ptr, 0xaa, stack_size);
+#endif
- /* The Arm7Tdmi uses a push-down stack: the stack grows
- * toward loweraddresses in memory. The stack pointer
- * register, points to the lowest, valid work address
- * (the "top" of the stack). Items on the stack are
- * referenced as positive word offsets from sp.
- */
+ /* The Z80 family uses a push-down stack: the stack grows
+ * toward loweraddresses in memory. The stack pointer
+ * register, points to the lowest, valid work address
+ * (the "top" of the stack). Items on the stack are
+ * referenced as positive word offsets from sp.
+ */
- top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
+ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
- /* The Arm7Tdmi stack must be aligned at word (4 byte)
- * boundaries. If necessary top_of_stack must be rounded
- * down to the next boundary
- */
+ /* The Z80 stack does not need to be aligned. Here is is aligned at
+ * word (4 byte) boundary.
+ */
- top_of_stack &= ~3;
- size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
+ top_of_stack &= ~3;
+ size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
- /* Save the adjusted stack values in the struct tcb_s */
+ /* Save the adjusted stack values in the struct tcb_s */
- tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
- tcb->adj_stack_size = size_of_stack;
+ tcb->adj_stack_ptr = (uint32_t*)top_of_stack;
+ tcb->adj_stack_size = size_of_stack;
- up_ledon(LED_STACKCREATED);
- return OK;
- }
+ up_ledon(LED_STACKCREATED);
+ return OK;
+ }
return ERROR;
}
diff --git a/nuttx/mm/mm_malloc.c b/nuttx/mm/mm_malloc.c
index 8a21e7324..4f138957f 100644
--- a/nuttx/mm/mm_malloc.c
+++ b/nuttx/mm/mm_malloc.c
@@ -1,7 +1,7 @@
/****************************************************************************
* mm/mm_malloc.c
*
- * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -196,6 +196,21 @@ FAR void *malloc(size_t size)
}
mm_givesemaphore();
- mvdbg("Allocated %p, size %d\n", ret, size);
+
+ /* If CONFIG_DEBUG_MM is defined, then output the result of the allocation
+ * to the SYSLOG.
+ */
+
+#ifdef CONFIG_DEBUG_MM
+ if (!ret)
+ {
+ mdbg("Allocation failed, size %d\n", size);
+ }
+ else
+ {
+ mvdbg("Allocated %p, size %d\n", ret, size);
+ }
+#endif
+
return ret;
}
diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c
index c160cb52c..3db41bf5f 100644
--- a/nuttx/sched/task_create.c
+++ b/nuttx/sched/task_create.c
@@ -116,6 +116,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority,
tcb = (FAR struct task_tcb_s *)kzalloc(sizeof(struct task_tcb_s));
if (!tcb)
{
+ sdbg("ERROR: Failed to allocate TCB\n");
errcode = ENOMEM;
goto errout;
}
diff --git a/nuttx/sched/task_vfork.c b/nuttx/sched/task_vfork.c
index 58b4152ed..1f365e916 100644
--- a/nuttx/sched/task_vfork.c
+++ b/nuttx/sched/task_vfork.c
@@ -122,6 +122,7 @@ FAR struct task_tcb_s *task_vforksetup(start_t retaddr)
child = (FAR struct task_tcb_s *)kzalloc(sizeof(struct task_tcb_s));
if (!child)
{
+ sdbg("ERROR: Failed to allocate TCB\n");
set_errno(ENOMEM);
return NULL;
}