mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user