Added new function chHeapIntegrityCheck().

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15092 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-11-16 13:48:06 +00:00
parent 8ab39c9118
commit e1378a31ca
3 changed files with 18 additions and 1 deletions

View File

@ -160,6 +160,7 @@ extern "C" {
void *chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align);
void chHeapFree(void *p);
size_t chHeapStatus(memory_heap_t *heapp, size_t *totalp, size_t *largestp);
bool chHeapIntegrityCheck(memory_heap_t *heapp);
#ifdef __cplusplus
}
#endif

View File

@ -415,7 +415,7 @@ size_t chHeapStatus(memory_heap_t *heapp, size_t *totalp, size_t *largestp) {
*/
bool chHeapIntegrityCheck(memory_heap_t *heapp) {
bool result = false;
heap_header_t *hp;
heap_header_t *hp, *prevhp;
/* If an heap is not specified then the default system header is used.*/
if (heapp == NULL) {
@ -430,9 +430,22 @@ bool chHeapIntegrityCheck(memory_heap_t *heapp) {
/* Taking heap mutex.*/
H_LOCK(heapp);
prevhp = NULL;
hp = &heapp->header;
while ((hp = H_FREE_NEXT(hp)) != NULL) {
/* Order violation or loop.*/
if (hp <= prevhp) {
result = true;
break;
}
/* Checking pointer alignment.*/
if (!MEM_IS_ALIGNED(hp, CH_HEAP_ALIGNMENT)) {
result = true;
break;
}
/* Validating the found free block.*/
if (!chMemIsAreaWithinX(&heapp->region,
(void *)hp,
@ -440,6 +453,8 @@ bool chHeapIntegrityCheck(memory_heap_t *heapp) {
result = true;
break;
}
prevhp = hp;
}
/* Releasing the heap mutex.*/

View File

@ -74,6 +74,7 @@
*****************************************************************************
*** Next ***
- NEW: Added new function chHeapIntegrityCheck().
- NEW: Added EFL driver implementation for STM32G4xx.
- NEW: Function chCoreGetStatusX() changed to return a memory region object
instead of a simple size.