diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-06-09 21:21:29 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-06-09 21:21:29 +0000 |
commit | d8249796c804f056363cf9dc0fa588a1f718de0b (patch) | |
tree | 1b834fef2d7d690ef62b75beb5f9612f26a4744a | |
parent | 0aee551ab2f5762fd5d82c24b548bb5fddb297ff (diff) | |
download | px4-nuttx-d8249796c804f056363cf9dc0fa588a1f718de0b.tar.gz px4-nuttx-d8249796c804f056363cf9dc0fa588a1f718de0b.tar.bz2 px4-nuttx-d8249796c804f056363cf9dc0fa588a1f718de0b.zip |
Fixes most integer overflows for AVR
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3689 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/arch/avr/src/common/up_createstack.c | 29 | ||||
-rw-r--r-- | nuttx/include/nuttx/compiler.h | 8 |
2 files changed, 22 insertions, 15 deletions
diff --git a/nuttx/arch/avr/src/common/up_createstack.c b/nuttx/arch/avr/src/common/up_createstack.c index 7b83357b6..15871ebc5 100644 --- a/nuttx/arch/avr/src/common/up_createstack.c +++ b/nuttx/arch/avr/src/common/up_createstack.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/avr/src/common/up_createstack.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,7 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <nuttx/compiler.h> #include <sys/types.h> #include <stdint.h> @@ -97,9 +98,9 @@ int up_create_stack(_TCB *tcb, size_t stack_size) if (!tcb->stack_alloc_ptr) { #ifdef CONFIG_DEBUG - tcb->stack_alloc_ptr = (uint32_t*)zalloc(stack_size); + tcb->stack_alloc_ptr = (FAR void *)zalloc(stack_size); #else - tcb->stack_alloc_ptr = (uint32_t*)malloc(stack_size); + tcb->stack_alloc_ptr = (FAR void *)malloc(stack_size); #endif } @@ -109,25 +110,25 @@ int up_create_stack(_TCB *tcb, size_t stack_size) size_t size_of_stack; /* The AVR32 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. - */ + * 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 = (size_t)tcb->stack_alloc_ptr + stack_size - 4; /* The AVR32 stack must be aligned at word (4 byte) - * boundaries. If necessary top_of_stack must be rounded - * down to the next boundary - */ + * 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; + size_of_stack = top_of_stack - (size_t)tcb->stack_alloc_ptr + 4; /* Save the adjusted stack values in the _TCB */ - tcb->adj_stack_ptr = (uint32_t*)top_of_stack; + tcb->adj_stack_ptr = (FAR void *)top_of_stack; tcb->adj_stack_size = size_of_stack; up_ledon(LED_STACKCREATED); diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h index 6fb3e6790..c44ff329e 100644 --- a/nuttx/include/nuttx/compiler.h +++ b/nuttx/include/nuttx/compiler.h @@ -99,7 +99,11 @@ # define DSEG # define CODE -#if defined(__m32c__) +/* Handle cases where sizeof(int) is 16-bits, sizeof(long) is 32-bits, and + * pointers are 16-bits. + */ + +#if defined(__m32c__) || defined(__AVR__) /* Select the small, 16-bit addressing model */ # define CONFIG_SMALL_MEMORY 1 @@ -112,6 +116,8 @@ # undef CONFIG_PTR_IS_NOT_INT +/* Handle cases where sizeof(int) may or may not be 16-bits */ + #elif defined(__mc68hc1x__) /* Select the small, 16-bit addressing model */ |