include/nuttx.h: replace all the align macros to nuttx version

1. add IS_ALIGNED()  definitions for NuttX;
2. replace all the ALIGN_UP() and ALIGN_DOWN() to use common
   align implementation;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
Bowen Wang
2024-08-02 23:13:02 +08:00
committed by GUIDINGLI
parent a041ebbaef
commit 313d6df787
32 changed files with 112 additions and 219 deletions
+1 -3
View File
@@ -33,15 +33,13 @@
#include <nuttx/kmalloc.h>
#include <nuttx/mm/kasan.h>
#include <nuttx/mm/mempool.h>
#include <nuttx/nuttx.h>
#include <nuttx/sched.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#undef ALIGN_UP
#define ALIGN_UP(x, a) (((x) + ((a) - 1)) & (~((a) - 1)))
#if CONFIG_MM_BACKTRACE >= 0
#define MEMPOOL_MAGIC_FREE 0xAAAAAAAA
#define MEMPOOL_MAGIC_ALLOC 0x55555555
+4 -13
View File
@@ -24,26 +24,17 @@
* Included Files
****************************************************************************/
#include <assert.h>
#include <strings.h>
#include <syslog.h>
#include <sys/param.h>
#include <nuttx/mutex.h>
#include <nuttx/nuttx.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mm/mempool.h>
#include <nuttx/mm/kasan.h>
#include <assert.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#undef ALIGN_UP
#define ALIGN_UP(x, a) ((((size_t)x) + ((a) - 1)) & (~((a) - 1)))
#undef ALIGN_DOWN
#define ALIGN_DOWN(x, a) ((size_t)(x) & (~((a) - 1)))
/****************************************************************************
* Private Types
****************************************************************************/
@@ -195,7 +186,7 @@ retry:
sq_addfirst(&chunk->entry, &mpool->chunk_queue);
}
ret = (FAR void *)ALIGN_UP(chunk->next, align);
ret = (FAR void *)ALIGN_UP((uintptr_t)chunk->next, align);
if ((uintptr_t)chunk->end - (uintptr_t)ret < size)
{
goto retry;
@@ -725,7 +716,7 @@ FAR void *mempool_multiple_memalign(FAR struct mempool_multiple_s *mpool,
FAR char *blk = mempool_allocate(pool);
if (blk != NULL)
{
return (FAR void *)ALIGN_UP(blk, alignment);
return (FAR void *)ALIGN_UP((uintptr_t)blk, alignment);
}
}
while (++pool < end);
+2 -6
View File
@@ -29,16 +29,12 @@
#include <debug.h>
#include <stdio.h>
#include <nuttx/nuttx.h>
#include "ubsan.h"
#ifndef CONFIG_MM_UBSAN_DUMMY
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define IS_ALIGNED(x, a) (((x) & ((a) - 1)) == 0)
/****************************************************************************
* Private Data
****************************************************************************/