Standardize stack checking interface

This commit is contained in:
Gregory Nutt 2013-09-24 11:45:13 -06:00
parent 7c767c4ebe
commit a8461747b9
8 changed files with 48 additions and 75 deletions

View File

@ -17,6 +17,7 @@ config ARCH_ARM
bool "ARM" bool "ARM"
select ARCH_HAVE_INTERRUPTSTACK select ARCH_HAVE_INTERRUPTSTACK
select ARCH_HAVE_VFORK select ARCH_HAVE_VFORK
select ARCH_HAVE_STACKCHECK
---help--- ---help---
The ARM architectures The ARM architectures

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/common/up_checkstack.c * arch/arm/src/common/up_checkstack.c
* *
* Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -134,14 +134,19 @@ size_t up_check_tcbstack(FAR struct tcb_s *tcb)
return mark*4; return mark*4;
} }
ssize_t up_check_tcbstack_remain(FAR struct tcb_s *tcb)
{
return (ssize_t)tcb->adj_stack_size - (ssize_t)up_check_tcbstack(tcb);
}
size_t up_check_stack(void) size_t up_check_stack(void)
{ {
return up_check_tcbstack((FAR struct tcb_s*)g_readytorun.head); return up_check_tcbstack((FAR struct tcb_s*)g_readytorun.head);
} }
size_t up_check_stack_remain(void) ssize_t up_check_stack_remain(void)
{ {
return ((FAR struct tcb_s*)g_readytorun.head)->adj_stack_size - up_check_tcbstack((FAR struct tcb_s*)g_readytorun.head); return up_check_tcbstack_remain((FAR struct tcb_s*)g_readytorun.head);
} }
#endif /* CONFIG_DEBUG && CONFIG_DEBUG_STACK */ #endif /* CONFIG_DEBUG && CONFIG_DEBUG_STACK */

View File

@ -85,7 +85,7 @@
/**************************************************************************** /****************************************************************************
* Name: memset32 * Name: memset32
* *
* On most larger then 8 bit archs this will need to be word aligned so * On most larger than 8 bit archs this will need to be word aligned so
* so maybe some checks should be put in place? * so maybe some checks should be put in place?
* *
****************************************************************************/ ****************************************************************************/

View File

@ -484,28 +484,6 @@ void up_usbuninitialize(void);
void up_rnginitialize(void); void up_rnginitialize(void);
#endif #endif
/****************************************************************************
* Name: up_check_stack
*
* Description:
* Determine (approximately) how much stack has been used be searching the
* stack memory for a high water mark. That is, the deepest level of the
* stack that clobbered some recognizable marker in the stack memory.
*
* Input Parameters:
* None
*
* Returned value:
* The estimated amount of stack space used.
*
****************************************************************************/
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
size_t up_check_stack(void);
size_t up_check_tcbstack(FAR struct tcb_s);
size_t up_check_tcbstack_remain(FAR struct tcb_s);
#endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_COMMON_UP_INTERNAL_H */ #endif /* __ARCH_ARM_SRC_COMMON_UP_INTERNAL_H */

View File

@ -44,6 +44,7 @@ endchoice
config ARCH_FAMILY_AVR config ARCH_FAMILY_AVR
bool bool
default y if ARCH_CHIP_ATMEGA128 || ARCH_CHIP_AT90USB646 || ARCH_CHIP_AT90USB647 || ARCH_CHIP_AT90USB1286 || ARCH_CHIP_AT90USB1287 default y if ARCH_CHIP_ATMEGA128 || ARCH_CHIP_AT90USB646 || ARCH_CHIP_AT90USB647 || ARCH_CHIP_AT90USB1286 || ARCH_CHIP_AT90USB1287
select ARCH_HAVE_STACKCHECK
config ARCH_FAMILY_AVR32 config ARCH_FAMILY_AVR32
bool bool

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/avr/src/avr/avr_internal.h * arch/avr/src/avr/avr_internal.h
* *
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -104,7 +104,7 @@ extern uint16_t g_idle_topstack;
* *
************************************************************************************/ ************************************************************************************/
extern void up_copystate(uint8_t *dest, uint8_t *src); void up_copystate(uint8_t *dest, uint8_t *src);
/************************************************************************************ /************************************************************************************
* Name: up_fullcontextrestore * Name: up_fullcontextrestore
@ -114,7 +114,7 @@ extern void up_copystate(uint8_t *dest, uint8_t *src);
* *
************************************************************************************/ ************************************************************************************/
extern void up_fullcontextrestore(uint8_t *restoreregs) noreturn_function; void up_fullcontextrestore(uint8_t *restoreregs) noreturn_function;
/************************************************************************************ /************************************************************************************
* Name: up_switchcontext * Name: up_switchcontext
@ -124,7 +124,7 @@ extern void up_fullcontextrestore(uint8_t *restoreregs) noreturn_function;
* *
************************************************************************************/ ************************************************************************************/
extern void up_switchcontext(uint8_t *saveregs, uint8_t *restoreregs); void up_switchcontext(uint8_t *saveregs, uint8_t *restoreregs);
/************************************************************************************ /************************************************************************************
* Name: up_doirq * Name: up_doirq
@ -134,7 +134,7 @@ extern void up_switchcontext(uint8_t *saveregs, uint8_t *restoreregs);
* *
************************************************************************************/ ************************************************************************************/
extern uint8_t *up_doirq(uint8_t irq, uint8_t *regs); uint8_t *up_doirq(uint8_t irq, uint8_t *regs);
/************************************************************************************ /************************************************************************************
* Name: avr_spiselect, avr_spitatus, and avr_spicmddata * Name: avr_spiselect, avr_spitatus, and avr_spicmddata
@ -167,33 +167,13 @@ struct spi_dev_s;
enum spi_dev_e; enum spi_dev_e;
#ifdef CONFIG_AVR_SPI #ifdef CONFIG_AVR_SPI
extern void avr_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected); void avr_spiselect(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected);
extern uint8_t avr_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid); uint8_t avr_spistatus(FAR struct spi_dev_s *dev, enum spi_dev_e devid);
#ifdef CONFIG_SPI_CMDDATA #ifdef CONFIG_SPI_CMDDATA
extern int avr_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd); int avr_spicmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd);
#endif #endif
#endif #endif
/****************************************************************************
* Name: up_check_stack
*
* Description:
* Determine (approximately) how much stack has been used be searching the
* stack memory for a high water mark. That is, the deepest level of the
* stack that clobbered some recognizable marker in the stack memory.
*
* Input Parameters:
* None
*
* Returned value:
* The estimated amount of stack space used.
*
****************************************************************************/
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK)
extern size_t up_check_stack(void);
#endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __ARCH_AVR_SRC_AVR_AVR_INTERNAL_H */ #endif /* __ARCH_AVR_SRC_AVR_AVR_INTERNAL_H */

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/avr/src/avr/up_checkstack.c * arch/avr/src/avr/up_checkstack.c
* *
* Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -133,9 +133,19 @@ size_t up_check_tcbstack(FAR struct tcb_s *tcb)
return mark; return mark;
} }
ssize_t up_check_tcbstack_remain(FAR struct tcb_s *tcb)
{
return (ssize_t)tcb->adj_stack_size - (ssize_t)up_check_tcbstack(tcb);
}
size_t up_check_stack(void) size_t up_check_stack(void)
{ {
return up_check_tcbstack((FAR struct tcb_s*)g_readytorun.head); return up_check_tcbstack((FAR struct tcb_s*)g_readytorun.head);
} }
ssize_t up_check_stack_remain(void)
{
return up_check_tcbstack_remain((FAR struct tcb_s*)g_readytorun.head);
}
#endif /* CONFIG_DEBUG && CONFIG_DEBUG_STACK */ #endif /* CONFIG_DEBUG && CONFIG_DEBUG_STACK */

View File

@ -126,17 +126,17 @@ extern uint32_t _ebss; /* End+1 of .bss */
/* Defined in files with the same name as the function */ /* Defined in files with the same name as the function */
extern void up_boot(void); void up_boot(void);
extern void up_irqinitialize(void); void up_irqinitialize(void);
#ifdef CONFIG_ARCH_DMA #ifdef CONFIG_ARCH_DMA
extern void weak_function up_dmainitialize(void); void weak_function up_dmainitialize(void);
#endif #endif
extern void up_sigdeliver(void); void up_sigdeliver(void);
extern int up_timerisr(int irq, uint32_t *regs); int up_timerisr(int irq, uint32_t *regs);
extern void up_lowputc(char ch); void up_lowputc(char ch);
extern void up_puts(const char *str); void up_puts(const char *str);
extern void up_lowputs(const char *str); void up_lowputs(const char *str);
extern void up_dumpstate(void); void up_dumpstate(void);
/* Defined in common/up_allocateheap.c or chip/xxx_allocateheap.c */ /* Defined in common/up_allocateheap.c or chip/xxx_allocateheap.c */
@ -152,13 +152,13 @@ void up_addregion(void);
* before the OS gets started (clocks, console, LEDs, etc.) * before the OS gets started (clocks, console, LEDs, etc.)
*/ */
extern void up_lowinit(void); void up_lowinit(void);
/* Defined in chip/xxx_serial.c */ /* Defined in chip/xxx_serial.c */
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
extern void up_earlyserialinit(void); void up_earlyserialinit(void);
extern void up_serialinit(void); void up_serialinit(void);
#else #else
# define up_earlyserialinit() # define up_earlyserialinit()
# define up_serialinit() # define up_serialinit()
@ -167,7 +167,7 @@ extern void up_serialinit(void);
/* Defined in drivers/lowconsole.c */ /* Defined in drivers/lowconsole.c */
#ifdef CONFIG_DEV_LOWCONSOLE #ifdef CONFIG_DEV_LOWCONSOLE
extern void lowconsole_init(void); void lowconsole_init(void);
#else #else
# define lowconsole_init() # define lowconsole_init()
#endif #endif
@ -179,8 +179,8 @@ extern void up_timerinit(void);
/* Defined in configs/<board-name>/src/up_leds.c */ /* Defined in configs/<board-name>/src/up_leds.c */
#ifdef CONFIG_ARCH_LEDS #ifdef CONFIG_ARCH_LEDS
extern void up_ledon(int led); void up_ledon(int led);
extern void up_ledoff(int led); void up_ledoff(int led);
#else #else
# define up_ledon(led) # define up_ledon(led)
# define up_ledoff(led) # define up_ledoff(led)
@ -189,7 +189,7 @@ extern void up_ledoff(int led);
/* Defined in chip/xxx_ethernet.c */ /* Defined in chip/xxx_ethernet.c */
#ifdef CONFIG_NET #ifdef CONFIG_NET
extern void up_netinitialize(void); void up_netinitialize(void);
#else #else
# define up_netinitialize() # define up_netinitialize()
#endif #endif
@ -197,14 +197,12 @@ extern void up_netinitialize(void);
/* Defined in chip/xxx_usbdev.c */ /* Defined in chip/xxx_usbdev.c */
#ifdef CONFIG_USBDEV #ifdef CONFIG_USBDEV
extern void up_usbinitialize(void); void up_usbinitialize(void);
extern void up_usbuninitialize(void); void up_usbuninitialize(void);
#else #else
# define up_usbinitialize() # define up_usbinitialize()
# define up_usbuninitialize() # define up_usbuninitialize()
#endif #endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __UP_INTERNAL_H */ #endif /* __UP_INTERNAL_H */