diff --git a/escher/src/image_view.cpp b/escher/src/image_view.cpp index 5b5556549..2259c827b 100644 --- a/escher/src/image_view.cpp +++ b/escher/src/image_view.cpp @@ -23,8 +23,8 @@ void ImageView::drawRect(KDContext * ctx, KDRect rect) const { KDColor pixelBuffer[maxPixelBufferSize]; int pixelBufferSize = m_image->width() * m_image->height(); - // CAUTION: That's a VERY big buffer we're allocating on the stack assert(pixelBufferSize <= maxPixelBufferSize); + assert(Ion::stackSafe()); // That's a VERY big buffer we're allocating on the stack Ion::decompress( m_image->compressedPixelData(), diff --git a/ion/include/ion.h b/ion/include/ion.h index a5b2b43a0..83cb25b36 100644 --- a/ion/include/ion.h +++ b/ion/include/ion.h @@ -43,6 +43,9 @@ uint32_t random(); // Decompress data void decompress(const uint8_t * src, uint8_t * dst, int srcSize, int dstSize); +// Tells wether the stack pointer is within acceptable bounds +bool stackSafe(); + } #endif diff --git a/ion/src/blackbox/Makefile b/ion/src/blackbox/Makefile index 82d051496..d387bff79 100644 --- a/ion/src/blackbox/Makefile +++ b/ion/src/blackbox/Makefile @@ -19,6 +19,7 @@ objs += $(addprefix ion/src/shared/, \ dummy/led.o \ dummy/keyboard.o \ dummy/serial_number.o \ + dummy/stack.o \ dummy/usb.o \ ) diff --git a/ion/src/device/Makefile b/ion/src/device/Makefile index 6aeb2dc97..c61bd7d24 100644 --- a/ion/src/device/Makefile +++ b/ion/src/device/Makefile @@ -25,6 +25,7 @@ objs += $(addprefix ion/src/device/, \ led.o\ power.o\ sd_card.o\ + stack.o\ swd.o \ usb.o \ wakeup.o \ diff --git a/ion/src/device/stack.cpp b/ion/src/device/stack.cpp new file mode 100644 index 000000000..141e222b5 --- /dev/null +++ b/ion/src/device/stack.cpp @@ -0,0 +1,10 @@ +#include + +extern const void * _stack_start; +extern const void * _stack_end; + +bool Ion::stackSafe() { + volatile int stackDummy; + volatile void * stackPointer = &stackDummy; + return (stackPointer >= &_stack_end && stackPointer <= &_stack_start); +} diff --git a/ion/src/emscripten/Makefile b/ion/src/emscripten/Makefile index eaea97440..042e45dd6 100644 --- a/ion/src/emscripten/Makefile +++ b/ion/src/emscripten/Makefile @@ -15,5 +15,6 @@ objs += $(addprefix ion/src/shared/, \ dummy/fcc_id.o \ dummy/led.o \ dummy/serial_number.o \ + dummy/stack.o \ dummy/usb.o \ ) diff --git a/ion/src/shared/dummy/stack.cpp b/ion/src/shared/dummy/stack.cpp new file mode 100644 index 000000000..4639d859f --- /dev/null +++ b/ion/src/shared/dummy/stack.cpp @@ -0,0 +1,5 @@ +#include + +bool Ion::stackSafe() { + return true; +} diff --git a/ion/src/simulator/Makefile b/ion/src/simulator/Makefile index 9185e96b4..5df0e25eb 100644 --- a/ion/src/simulator/Makefile +++ b/ion/src/simulator/Makefile @@ -18,6 +18,7 @@ objs += $(addprefix ion/src/shared/, \ dummy/fcc_id.o \ dummy/led.o \ dummy/serial_number.o \ + dummy/stack.o \ dummy/usb.o \ )