Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pvPortRealloc (backport #99) #100

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions microros_crazyflie21_extensions/src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,25 @@ void *pvPortRealloc( void *pv, size_t xWantedSize )

void * newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = ( void * ) puc;
puc -= xHeapStructSize;
pxLink = ( void * ) puc;


char *in_src = (char*)pv;
char *in_dest = (char*)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char*)pv;
char *in_dest = (char*)newmem;

while(count--)
*in_dest++ = *in_src++;
size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

vPortFree(pv);
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
}

( void ) xTaskResumeAll();

Expand Down Expand Up @@ -463,4 +467,3 @@ uint8_t *puc;
mtCOVERAGE_TEST_MARKER();
}
}

23 changes: 14 additions & 9 deletions microros_nucleo_f446re_extensions/Core/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 14 additions & 9 deletions microros_nucleo_f446ze_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 14 additions & 9 deletions microros_nucleo_f746zg_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 14 additions & 9 deletions microros_nucleo_f767zi_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 13 additions & 10 deletions microros_olimex_e407_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,24 @@ void *pvPortRealloc( void *pv, size_t xWantedSize )

void * newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = ( void * ) puc;
puc -= xHeapStructSize;
pxLink = ( void * ) puc;

char *in_src = (char*)pv;
char *in_dest = (char*)newmem;

char *in_src = (char*)pv;
char *in_dest = (char*)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while(count--)
*in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

( void ) xTaskResumeAll();

Expand Down