From 89717aa6370e640b7b067d02f2e4448154884d99 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 23 Jan 2021 11:28:06 +0000 Subject: [PATCH] Fixed bug #1141. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14022 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/oslib/src/chfactory.c | 30 +++++++++++++++++++++--------- readme.txt | 5 ++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/os/oslib/src/chfactory.c b/os/oslib/src/chfactory.c index 8490026c7..0644ce187 100644 --- a/os/oslib/src/chfactory.c +++ b/os/oslib/src/chfactory.c @@ -135,7 +135,8 @@ static dyn_element_t *dyn_list_unlink(dyn_element_t *element, #if CH_FACTORY_REQUIRES_HEAP || defined(__DOXYGEN__) static dyn_element_t *dyn_create_object_heap(const char *name, dyn_list_t *dlp, - size_t size) { + size_t size, + unsigned align) { dyn_element_t *dep; chDbgCheck(name != NULL); @@ -147,7 +148,7 @@ static dyn_element_t *dyn_create_object_heap(const char *name, } /* Allocating space for the new buffer object.*/ - dep = (dyn_element_t *)chHeapAlloc(NULL, size); + dep = (dyn_element_t *)chHeapAllocAligned(NULL, size, align); if (dep == NULL) { return NULL; } @@ -421,7 +422,8 @@ dyn_buffer_t *chFactoryCreateBuffer(const char *name, size_t size) { dbp = (dyn_buffer_t *)dyn_create_object_heap(name, &ch_factory.buf_list, - size); + size, + CH_HEAP_ALIGNMENT); if (dbp != NULL) { /* Initializing buffer object data.*/ memset((void *)(dbp + 1), 0, size); @@ -582,7 +584,8 @@ dyn_mailbox_t *chFactoryCreateMailbox(const char *name, size_t n) { dmp = (dyn_mailbox_t *)dyn_create_object_heap(name, &ch_factory.mbx_list, sizeof (dyn_mailbox_t) + - (n * sizeof (msg_t))); + (n * sizeof (msg_t)), + CH_HEAP_ALIGNMENT); if (dmp != NULL) { /* Initializing mailbox object data.*/ chMBObjectInit(&dmp->mbx, (msg_t *)(dmp + 1), n); @@ -662,21 +665,29 @@ dyn_objects_fifo_t *chFactoryCreateObjectsFIFO(const char *name, size_t objsize, size_t objn, unsigned objalign) { + size_t size1, size2; dyn_objects_fifo_t *dofp; F_LOCK(); + /* Enforcing alignment for the objects array.*/ + objsize = MEM_ALIGN_NEXT(objsize, objalign); + size1 = MEM_ALIGN_NEXT(sizeof (dyn_objects_fifo_t) + (objn * sizeof (msg_t)), + objalign); + size2 = objn * objsize; + + /* Allocating the FIFO object with messages buffer and objects buffer.*/ dofp = (dyn_objects_fifo_t *)dyn_create_object_heap(name, &ch_factory.fifo_list, - sizeof (dyn_objects_fifo_t) + - (objn * sizeof (msg_t)) + - (objn * objsize)); + size1 + size2, + objalign); if (dofp != NULL) { msg_t *msgbuf = (msg_t *)(dofp + 1); + uint8_t *objbuf = (uint8_t *)dofp + size1; /* Initializing mailbox object data.*/ chFifoObjectInitAligned(&dofp->fifo, objsize, objn, objalign, - (void *)&msgbuf[objn], msgbuf); + (void *)objbuf, msgbuf); } F_UNLOCK(); @@ -755,7 +766,8 @@ dyn_pipe_t *chFactoryCreatePipe(const char *name, size_t size) { dpp = (dyn_pipe_t *)dyn_create_object_heap(name, &ch_factory.pipe_list, - sizeof (dyn_pipe_t) + size); + sizeof (dyn_pipe_t) + size, + CH_HEAP_ALIGNMENT); if (dpp != NULL) { /* Initializing mailbox object data.*/ chPipeObjectInit(&dpp->pipe, (uint8_t *)(dpp + 1), size); diff --git a/readme.txt b/readme.txt index 1c64d9b7a..279f650bd 100644 --- a/readme.txt +++ b/readme.txt @@ -74,7 +74,6 @@ ***************************************************************************** *** Next *** -- FIX: Fixed chsnprintf() sign mode/filler mode conflict (bug #1140) - NEW: Added time conversion macros and functions for monotonic time stamps - NEW: Added support for STM32WB55. - NEW: Added chscanf() and buffered streams, contributed by Alex Lewontin. @@ -129,6 +128,10 @@ MEMS Accelerometers. - NEW: Safer messages mechanism for sandboxes (to be backported to 20.3.1). - NEW: Added latency measurement test application. +- FIX: Fixed Heap allocation of aligned FIFO objects in chFactory (bug #1141) + (backported to 20.3.3)(backported to 19.1.5). +- FIX: Fixed chsnprintf() sign mode/filler mode conflict (bug #1140) + (backported to 20.3.3). - FIX: Fixed GCC 10 causes warning in factory module (bug #1139) (backported to 20.3.3)(backported to 19.1.5). - FIX: Fixed STM32H7xx Missing CRC RCC macros (bug #1137)