[ion] Add Ion::stackSafe

This allows asserting the stack is within bounds
This commit is contained in:
Romain Goyet
2018-10-10 10:35:01 +02:00
committed by LeaNumworks
parent f4f567814e
commit f1198d3c76
8 changed files with 23 additions and 1 deletions

View File

@@ -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(),

View File

@@ -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

View File

@@ -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 \
)

View File

@@ -25,6 +25,7 @@ objs += $(addprefix ion/src/device/, \
led.o\
power.o\
sd_card.o\
stack.o\
swd.o \
usb.o \
wakeup.o \

10
ion/src/device/stack.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include <ion.h>
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);
}

View File

@@ -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 \
)

View File

@@ -0,0 +1,5 @@
#include <ion.h>
bool Ion::stackSafe() {
return true;
}

View File

@@ -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 \
)