~aleteoryx/muditaos

77e37561cd899101398cf556c23300ec9ebbe257 — Maciej Gibowicz 4 years ago 06fa920
[EGD-6769] Preventing use of allocators in interrupts

Abort when trying to use an allocator in an interrupt.
This prevents the heap from being overwritten.
1 files changed, 11 insertions(+), 0 deletions(-)

M module-os/memory/usermem.c
M module-os/memory/usermem.c => module-os/memory/usermem.c +11 -0
@@ 9,6 9,7 @@

#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "macros.h"

/**


@@ 118,6 119,11 @@ void *usermalloc(size_t xWantedSize)
	BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
	void *pvReturn = NULL;

    // Preventing use of an allocator in an interrupt
    if (isIRQ()) {
        abort();
    }

		vTaskSuspendAll();
		{
			/* If this is the first call to malloc then the heap will require


@@ 288,6 294,11 @@ void userfree(void *pv)
	uint8_t *puc = ( uint8_t * ) pv;
	BlockLink_t *pxLink;

    // Preventing use of an allocator in an interrupt
    if (isIRQ()) {
        abort();
    }

		if( pv != NULL )
		{
			/* The memory being freed will have an BlockLink_t structure immediately