-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Omit configTOTAL_HEAP_SIZE for Application Allocated Heap #351
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
Omit configTOTAL_HEAP_SIZE for Application Allocated Heap #351
Conversation
Hi @Finwood, Thank you for pointed out this. I think it is a reasonable using senario and should be considered. But regarding to the change you made, maybe using a pointer would be better than declaring a non-size array?
Regards, |
portable/MemMang/heap_1.c
Outdated
@@ -58,7 +58,7 @@ | |||
|
|||
/* The application writer has already defined the array used for the RTOS | |||
* heap - probably so it can be placed in a special segment or address. */ | |||
extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; | |||
extern uint8_t ucHeap[ ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this better? So no need to worry about if the compiler suppot or not.
extern uint8_t ucHeap[ ]; | |
extern uint8_t *ucHeap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work for the implementation of heap_4.c, since ucHeap
is only ever accessed like a pointer would:
FreeRTOS-Kernel/portable/MemMang/heap_4.c
Lines 351 to 361 in 6a84f2c
/* Ensure the heap starts on a correctly aligned boundary. */ | |
uxAddress = ( size_t ) ucHeap; | |
if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) | |
{ | |
uxAddress += ( portBYTE_ALIGNMENT - 1 ); | |
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); | |
xTotalHeapSize -= uxAddress - ( size_t ) ucHeap; | |
} | |
pucAlignedHeap = ( uint8_t * ) uxAddress; |
In heap_1.c this would break, since the existing implementation accesses ucHeap[ portBYTE_ALIGNMENT ]
, which would be invalid if ucHeap
would be a pointer:
FreeRTOS-Kernel/portable/MemMang/heap_1.c
Lines 96 to 100 in 6a84f2c
if( pucAlignedHeap == NULL ) | |
{ | |
/* Ensure the heap starts on a correctly aligned boundary. */ | |
pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); | |
} |
Since pointers and arrays aren't equivalent I would advise against having the type of ucHeap depend on configAPPLICATION_ALLOCATED_HEAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Finwood,
The pointer indexing shouldn't be a problem here. But we are considering how to preperly handle configTOTAL_HEAP_SIZE things. The heap_4 uses configTOTAL_HEAP_SIZE in the init function. The current code force user to set configTOTAL_HEAP_SIZE. However with the change in this PR, it may cause some problem if user forget setting configTOTAL_HEAP_SIZE when allocate the heap memory in application. As for now please just made the change from you code to resolve your issue and we will keep you updated on this PR.
Thank you!
Regards,
Ming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in f31a1ac 👍
Codecov Report
@@ Coverage Diff @@
## main #351 +/- ##
=======================================
Coverage 92.13% 92.13%
=======================================
Files 4 4
Lines 1272 1272
Branches 342 342
=======================================
Hits 1172 1172
Misses 53 53
Partials 47 47
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I've run tests locally - for heap_2.c, this line crashes with not-constant configTOTAL_HEAP_SIZE: FreeRTOS-Kernel/portable/MemMang/heap_2.c Line 90 in f31a1ac
Moving the assignment into prvHeapInit() could solve that: static size_t xFreeBytesRemaining; // or possibly initialize to zero
// [...]
static void prvHeapInit( void )
{
xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;
// [...]
} |
Hi @Finwood, Reviewing back this PR. The above change can work but as mentioned in the last comment user who forget setting configTOTAL_HEAP_SIZE may not receive the ERROR anymore. You can do the change for heap_4 at your local copy. Or there is another way to resolve your issue by using heap_5 and you don't have to change the FreeRTOS code. Please referce https://www.freertos.org/a00111.html#heap_5 about using Heap_5. And specific for your case, you may want: `
` Close this PR and issue #347. Please feel free to reopen the issue if you have any further question. Thank you! Regards, |
The mbedTLS sources used to show up in the root directory of the Visual Studio Project. This change updates WIN32.vcxproj.filters so that it appears under FreeRTOS+\mbedtls\library instead.
This PR implements a solution for the issue described in #347.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.