Skip to content
Snippets Groups Projects
Commit be1b67a1 authored by patacongo's avatar patacongo
Browse files

Add debug output when memory allocations fail

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5686 42af7a65-404d-4744-a932-0658087f49c3
parent 268167a2
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
......@@ -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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
/****************************************************************************
* 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;
}
......@@ -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;
}
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment