# No entry for pvPortMalloc/vPortFree in mpu\_wrappers.h

**URL:** <https://forums.freertos.org/t/no-entry-for-pvportmalloc-vportfree-in-mpu-wrappers-h/6360>\
**Category:** Kernel\
**Created:** [January 31, 2017, 3:46pm UTC](https://forums.freertos.org/t/no-entry-for-pvportmalloc-vportfree-in-mpu-wrappers-h/6360 "2017-01-31T15:46:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 31, 2017, 3:46pm UTC](https://forums.freertos.org/t/no-entry-for-pvportmalloc-vportfree-in-mpu-wrappers-h/6360/1 "2017-01-31T15:46:45Z")

</div>

**[philpem](https://sourceforge.net/u/philpem/)** wrote on [Tuesday, January 31, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/7f0190d2/#15b3):

mpu\_wrappers.h seems to be missing #define statements for several of the MPU wrapper functions which are defined in mpu\_wrappers.c. The most notable of these are MPU\_pvPortMalloc and MPU\_vPortFree.

The net effect of this is that MPU\_pvPortMalloc and MPU\_vPortFree are defined but no prototype is available to MPU-enabled code – calling pvPortMalloc() results in the “privileged” pvPortMalloc() being called. If this is called from a “normal” task, there will be a memory protection error. I was expecting that the MPU shim in mpu\_wrappers.c would be called, until I noticed the define was missing.

Long and short of it: you can’t allocate and free memory from MPU-enabled code.

Adding these calls to mpu\_wrappers.h is fairly simple – is there any adverse implication of doing so which I may have overlooked?

Thanks,  
Phil.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 31, 2017, 4:50pm UTC](https://forums.freertos.org/t/no-entry-for-pvportmalloc-vportfree-in-mpu-wrappers-h/6360/2 "2017-01-31T16:50:28Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, January 31, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/7f0190d2/#15b3/4717):

> mpu\_wrappers.h seems to be missing #define statements for several of the  
> MPU wrapper functions which are defined in mpu\_wrappers.c. The most  
> notable of these are MPU\_pvPortMalloc and MPU\_vPortFree.

Probably deliberate with the rationale that unprivileged tasks should  
not be allowed to dynamically allocate memory (directly).

> The net effect of this is that MPU\_pvPortMalloc and MPU\_vPortFree are  
> defined but no prototype is available to MPU-enabled code – calling  
> pvPortMalloc() results in the “privileged” pvPortMalloc() being called.  
> If this is called from a “normal” task, there will be a memory  
> protection error. I was expecting that the MPU shim in mpu\_wrappers.c  
> would be called, until I noticed the define was missing.

This sounds confused. Either an MPU\_…() function have both a  
implementation in a C file and and entry in the header file, or it  
should not be in either. Possibly it was removed from one (for the  
reason above) but not the other. Either way it doesn’t sound right and  
needs to be straightened.

I’m not sure how calling pvPortMalloc() could result in  
MPU\_pvPortMalloc() being called if the function is not in mpu\_wrappers.h

- I would expect it to result in the normal pvPortMalloc() being called  
a there is nothing mapping it anywhere else.
