# Static uint8\_t ucHeap\[ configTOTAL\_HEAP\_SIZE \] , privileged data or not?

**URL:** <https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867>\
**Category:** Kernel\
**Created:** [May 25, 2020, 12:43pm UTC](https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867 "2020-05-25T12:43:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/eugene/32/377_2.png) [@Eugene](https://forums.freertos.org/u/Eugene)\
**Post date:** [May 25, 2020, 12:43pm UTC](https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867/1 "2020-05-25T12:43:47Z")

</div>

Hi !

Heap\_4 file have reservation for heap area and for my understanding this is privileged data  
and for my understanding should be defined as:

static uint8\_t ucHeap[configTOTAL\_HEAP\_SIZE] PRIVILEGED\_DATA;

But it cause hardFault.

Why it happens. Does in rtos kernel exists some accesses to this area with unprivileged rights ?  
It should be used for allocate internal buffers and be accessed in privileged mode only.  
I have few unprivileged tasks and one privileged.

Regards,  
Eugene

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 26, 2020, 11:36pm UTC](https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867/2 "2020-05-26T23:36:39Z")

</div>

I tried to make the same change and it does not result in a fault for me. I have tried it with this sample project: [https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS/Demo/CORTEX\_MPU\_M33F\_NXP\_LPC55S69\_MCUXpresso](https://github.com/FreeRTOS/FreeRTOS/tree/master/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso)

Can you describe what your tasks are doing - just trying to figure out if I am missing anything here.

Thanks.

---

<div class="post-metadata">

**Author:** ![Eugene](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/eugene/32/377_2.png) [@Eugene](https://forums.freertos.org/u/Eugene)\
**Post date:** [May 27, 2020, 7:45am UTC](https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867/3 "2020-05-27T07:45:21Z")

</div>

Hi Gaurav !

I’m using the same LPC55S69 port but from NXP SDk directly. I have secure and nonsecure part  
of code and hardfault report reason “Another secure bus error.\r\n”. I think it some how connected with security violation, but I haven’t got a idea how heap can be involved to that picture. Any idea ? I need start point for investigation.

I’m able to relocate other variables from heap\_4.c without any problem.

```auto
/* The size of the structure placed at the beginning of each allocated memory
block must by correctly byte aligned. */
PRIVILEGED_FUNCTION
static const size_t xHeapStructSize	= ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );

/* Create a couple of list links to mark the start and end of the list. */
PRIVILEGED_DATA static BlockLink_t xStart, *pxEnd = NULL; //

/* Keeps track of the number of free bytes remaining, but says nothing about
fragmentation. */
PRIVILEGED_DATA static size_t xFreeBytesRemaining = 0U; //
PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U; //

/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize
member of an BlockLink_t structure is set then the block belongs to the
application. When the bit is free the block is still part of the free heap
space. */
PRIVILEGED_DATA static size_t xBlockAllocatedBit = 0; //

```

On secure side I haven’t touch secure heap yet. It is used for allocate stacks of tasks what have secure context. But problem with this approach that some tasks can run with user privileges and some - privileged and it difficult to separate privileged and nonprivileged data.

As you know LPC55S69 require well done separation of priliges/nonprivileged code and data ,  
in other case is not possible to enforce AHB bus privilege checking for secure and non secure sides ( AHB misc register.). And I should be able to have MPU\_S/NS settings in way when MPU boundaries aligned with MPC/PPC sections as well.

Regards,  
Eugene

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 28, 2020, 5:52pm UTC](https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867/4 "2020-05-28T17:52:05Z")

</div>

Hi Eugene,

Are you allocating any memory from heap which is used by any unprivileged task? Another reason may be that an unprivileged task is causing some memory overrun into the heap area which was not detected earlier because the heap memory array was not protected.

Is it possible for you to create a small sample project showing this problem so that I can investigate?

Thanks,  
Gaurav

---

<div class="post-metadata">

**Author:** ![Eugene](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/eugene/32/377_2.png) [@Eugene](https://forums.freertos.org/u/Eugene)\
**Post date:** [May 29, 2020, 8:51am UTC](https://forums.freertos.org/t/static-uint8-t-ucheap-configtotal-heap-size-privileged-data-or-not/9867/5 "2020-05-29T08:51:25Z")

</div>

Hi Gaurav !

I have quite huge enviroment and narrow down it to problematic part is basically only one way to find reason.

I have disabled all my tasks and only IDLE and Timer task remains.  
Also I have disabled Secure context creation in IDLE task as well.  
And it still generate the same HardFault.  
I think this is somewhere in generic rtos code but no idea yet where.  
Do you have some suggestion what part to check more ?

Regards,  
Eugene
