aboutsummaryrefslogtreecommitdiffstats
path: root/os/lib/src/chmempools.c
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2019-01-06 15:45:01 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2019-01-06 15:45:01 +0000
commit2e2a38cd10e11d3e085c62149440dddb474ea7bf (patch)
tree6dced32c2c9c8f0fac8b51d386a377d5c5dbec76 /os/lib/src/chmempools.c
parent6421004d21f26d809d6b7dcd18d5b0d6ee02eb8c (diff)
downloadChibiOS-2e2a38cd10e11d3e085c62149440dddb474ea7bf.tar.gz
ChibiOS-2e2a38cd10e11d3e085c62149440dddb474ea7bf.tar.bz2
ChibiOS-2e2a38cd10e11d3e085c62149440dddb474ea7bf.zip
chFifoObjectInit() renamed to chFifoObjectInitAligned(). Added a new chFifoObjectInit() without the alignment parameter. Stricter alignment checks in memory pools.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12535 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/lib/src/chmempools.c')
-rw-r--r--os/lib/src/chmempools.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/os/lib/src/chmempools.c b/os/lib/src/chmempools.c
index 2fcd0cb3b..996b66329 100644
--- a/os/lib/src/chmempools.c
+++ b/os/lib/src/chmempools.c
@@ -77,7 +77,10 @@
void chPoolObjectInitAligned(memory_pool_t *mp, size_t size,
unsigned align, memgetfunc_t provider) {
- chDbgCheck((mp != NULL) && (size >= sizeof(void *)));
+ chDbgCheck((mp != NULL) &&
+ (size >= sizeof(void *)) &&
+ (align >= PORT_NATURAL_ALIGN) &&
+ MEM_IS_VALID_ALIGNMENT(align));
mp->next = NULL;
mp->object_size = size;
@@ -136,6 +139,9 @@ void *chPoolAllocI(memory_pool_t *mp) {
}
else if (mp->provider != NULL) {
objp = mp->provider(mp->object_size, mp->align);
+
+ chDbgAssert(MEM_IS_ALIGNED(objp, mp->align),
+ "returned object not aligned");
}
/*lint -restore*/
@@ -178,10 +184,9 @@ void chPoolFreeI(memory_pool_t *mp, void *objp) {
struct pool_header *php = objp;
chDbgCheckClassI();
- chDbgCheck((mp != NULL) && (objp != NULL));
-
- chDbgAssert(((size_t)objp & MEM_ALIGN_MASK(mp->align)) == 0U,
- "unaligned object");
+ chDbgCheck((mp != NULL) &&
+ (objp != NULL) &&
+ MEM_IS_ALIGNED(objp, mp->align));
php->next = mp->next;
mp->next = php;