In the kernel build, allocate the stacks for kernel threads from the kernel heap so that they are protected from medddling by the applications

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5766 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-03-20 20:27:08 +00:00
parent 020cc2248e
commit c86f502f2e
29 changed files with 711 additions and 265 deletions

View File

@ -146,17 +146,19 @@ static void *memset32(void *s, uint32_t c, size_t n)
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -164,12 +166,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);
@ -218,7 +240,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
*/
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
memset32(tcb->stack_alloc_ptr, 0xDEADBEEF, tcb->adj_stack_size/4);
memset32(tcb->stack_alloc_ptr, 0xdeadbeef, tcb->adj_stack_size/4);
#endif
up_ledon(LED_STACKCREATED);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/common/up_releasestack.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
@ -91,11 +91,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -121,12 +121,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes... Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -105,17 +105,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -123,12 +125,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (FAR void *)kuzalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (FAR void *)kumalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
#endif
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/avr/src/avr/up_usestack.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
@ -98,12 +98,12 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
if (tcb->stack_alloc_ptr)
{
/* Yes.. free it */
/* Yes.. Release the old stack allocation */
sched_ufree(tcb->stack_alloc_ptr);
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -104,17 +104,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -122,12 +124,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (FAR void *)kuzalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t *)kzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (FAR void *)kumalloc(stack_size);
tcb->stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
#endif
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/avr/src/avr32/up_usestack.c
*
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -94,12 +94,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/avr/src/common/up_releasestack.c
*
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Copyright (C) 2010, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -91,12 +91,32 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -101,17 +101,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -119,12 +121,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/hc/src/common/up_releasestack.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
@ -92,11 +92,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/hc/src/common/up_usestack.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
@ -93,13 +93,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -122,17 +122,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -140,12 +142,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/common/up_releasestack.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
@ -91,11 +91,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/mips/src/common/up_usestack.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
@ -94,12 +94,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -113,6 +113,7 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
uint32_t *stack_alloc_ptr;
int ret = ERROR;
size_t *adj_stack_ptr;
@ -123,7 +124,16 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
/* Allocate the memory for the stack */
uint32_t *stack_alloc_ptr = (uint32_t*)kumalloc(adj_stack_size);
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL) {
stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
} else
#endif
{
stack_alloc_ptr = (uint32_t*)kumalloc(adj_stack_size);
}
if (stack_alloc_ptr) {
/* This is the address of the last word in the allocation */
@ -160,9 +170,24 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
void up_release_stack(struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr) {
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL) {
kfree(dtcb->stack_alloc_ptr);
} else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
kufree(dtcb->stack_alloc_ptr);
}
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
dtcb->adj_stack_size = 0;

View File

@ -101,17 +101,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -119,12 +121,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/sh/src/common/up_releasestack.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
@ -91,11 +91,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/sh/src/common/up_usestack.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
@ -94,12 +94,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -102,6 +102,7 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
uint32_t *stack_alloc_ptr;
int ret = ERROR;
/* Move up to next even word boundary if necessary */
@ -111,7 +112,21 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
/* Allocate the memory for the stack */
uint32_t *stack_alloc_ptr = (uint32_t*)kumalloc(adj_stack_size);
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
stack_alloc_ptr = (uint32_t *)kmalloc(stack_size);
}
else
#endif
{
stack_alloc_ptr = (uint32_t*)kumalloc(adj_stack_size);
}
/* Was the allocation successful? */
if (stack_alloc_ptr)
{
/* This is the address of the last word in the allocation */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* up_releasestack.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
@ -93,10 +93,27 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
free(dtcb->stack_alloc_ptr);
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
dtcb->adj_stack_size = 0;

View File

@ -103,17 +103,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -121,12 +123,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/x86/src/common/up_releasestack.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
@ -91,11 +91,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/x86/src/common/up_usestack.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
@ -94,12 +94,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -102,17 +102,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -120,12 +122,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* common/up_releasestack.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
@ -91,11 +91,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/z16/common/up_usestack.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
@ -94,12 +94,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;

View File

@ -101,17 +101,19 @@
int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
{
/* Is there already a stack allocated of a different size? */
/* Is there already a stack allocated of a different size? Because of
* alignment issues, stack_size might erroneously appear to be of a
* different size. Fortunately, this is not a critical operation.
*/
if (tcb->stack_alloc_ptr && tcb->adj_stack_size != stack_size)
{
/* Yes.. free it */
/* Yes.. Release the old stack */
sched_ufree(tcb->stack_alloc_ptr);
tcb->stack_alloc_ptr = NULL;
up_release_stack(tcb, ttype);
}
/* Do we need to allocate a stack? */
/* Do we need to allocate a new stack? */
if (!tcb->stack_alloc_ptr)
{
@ -119,12 +121,32 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* then create a zeroed stack to make stack dumps easier to trace.
*/
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
#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
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
#if defined(CONFIG_DEBUG) && !defined(CONFIG_DEBUG_STACK)
tcb->stack_alloc_ptr = (uint32_t *)kuzalloc(stack_size);
#else
tcb->stack_alloc_ptr = (uint32_t *)kumalloc(stack_size);
#endif
}
#ifdef CONFIG_DEBUG
/* Was the allocation successful? */
if (!tcb->stack_alloc_ptr)
{
sdbg("ERROR: Failed to allocate stack, size %d\n", stack_size);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* common/up_releasestack.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
@ -91,11 +91,31 @@
void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype)
{
/* Is there a stack allocated? */
if (dtcb->stack_alloc_ptr)
{
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
/* Use the kernel allocator if this is a kernel thread */
if (ttype == TCB_FLAG_TTYPE_KERNEL)
{
sched_kfree(dtcb->stack_alloc_ptr);
}
else
#endif
{
/* Use the user-space allocator if this is a task or pthread */
sched_ufree(dtcb->stack_alloc_ptr);
}
/* Mark the stack freed */
dtcb->stack_alloc_ptr = NULL;
}
/* The size of the allocated stack is now zero */
dtcb->adj_stack_size = 0;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/z80/src/common/up_usestack.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
@ -93,12 +93,16 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
size_t top_of_stack;
size_t size_of_stack;
/* Is there already a stack allocated? */
if (tcb->stack_alloc_ptr)
{
sched_ufree(tcb->stack_alloc_ptr);
/* Yes.. Release the old stack allocation */
up_release_stack(tcb, tcb->flags & TCB_FLAG_TTYPE_MASK);
}
/* Save the stack allocation */
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;