Compare commits

...

6 commits

Author SHA1 Message Date
Mike.
48313d65b0
Merge 3f9dd51ec8 into a2d4d74af7 2025-01-12 16:52:57 +08:00
hujun5
a2d4d74af7 clock_timekeeping: remove enter_critical_section in sched/clock/clock_timekeeping.c
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 16:51:40 +08:00
wangmingrong1
2149d89336 macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 16:48:35 +08:00
Yanfeng Liu
71a4e86718 risc-v/Toolchain.defs: guard -r in LDELFFLAGS
This guards use of `-r` in LDELFFLAGS in risc-v common/Toolchain.defs so
that it is only used when BINFMT_ELF_RELOCATABLE is selected.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2025-01-12 16:47:54 +08:00
Leo Chung
63c8de5f03 sim: Fixes the linker 'noexecstack' warning
Signed-off-by: Leo Chung <gewalalb@gmail.com>
2025-01-12 16:17:52 +08:00
wangmingrong1
3f9dd51ec8 mm: The alignment length in mm is consistent with Kasan
preceding will cause the mm alignment to be inconsistent with the kasan alignment

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-08 12:39:34 +08:00
19 changed files with 104 additions and 84 deletions

View file

@ -727,6 +727,7 @@ else()
OUTPUT nuttx.rel OUTPUT nuttx.rel
COMMAND COMMAND
${CMAKE_C_COMPILER} ARGS -r $<$<BOOL:${CONFIG_SIM_M32}>:-m32> ${CMAKE_C_COMPILER} ARGS -r $<$<BOOL:${CONFIG_SIM_M32}>:-m32>
$<$<BOOL:${CONFIG_HOST_LINUX}>:-Wl,-z,noexecstack>
$<TARGET_OBJECTS:sim_head> $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--start-group> $<TARGET_OBJECTS:sim_head> $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--start-group>
${nuttx_libs_paths} $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--end-group> -o ${nuttx_libs_paths} $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--end-group> -o
nuttx.rel nuttx.rel

View file

@ -1103,7 +1103,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
&src_freq); &src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -1161,7 +1161,7 @@ static void imxrt_lpi2c_setclock(struct imxrt_lpi2c_priv_s *priv,
#endif #endif
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -1010,7 +1010,7 @@ static void s32k1xx_lpi2c_setclock(struct s32k1xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0); DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -990,7 +990,7 @@ static void s32k3xx_lpi2c_setclock(struct s32k3xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0); DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -1122,7 +1122,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
imx9_get_rootclock(priv->config->clk_root, &src_freq); imx9_get_rootclock(priv->config->clk_root, &src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -433,7 +433,12 @@ LDMODULEFLAGS = -r -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld)
CELFFLAGS = $(CFLAGS) -fvisibility=hidden CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden
LDELFFLAGS = -r -e main LDELFFLAGS = -e main
ifeq ($(CONFIG_BINFMT_ELF_RELOCATABLE),y)
LDELFFLAGS += -r
endif
ifeq ($(CONFIG_ARCH_RV32),y) ifeq ($(CONFIG_ARCH_RV32),y)
LDELFFLAGS += --oformat elf32-littleriscv LDELFFLAGS += --oformat elf32-littleriscv
else else

View file

@ -200,3 +200,7 @@ else()
add_link_options(-Wl,--gc-sections) add_link_options(-Wl,--gc-sections)
add_link_options(-Wl,-Ttext-segment=0x40000000) add_link_options(-Wl,-Ttext-segment=0x40000000)
endif() endif()
if(CONFIG_HOST_LINUX)
add_link_options(-Wl,-z,noexecstack)
endif()

View file

@ -31,18 +31,13 @@
#include <errno.h> #include <errno.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/nuttx.h>
#include <nuttx/binfmt/binfmt.h> #include <nuttx/binfmt/binfmt.h>
#include "binfmt.h" #include "binfmt.h"
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE) #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -98,8 +93,8 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
case SPAWN_FILE_ACTION_OPEN: case SPAWN_FILE_ACTION_OPEN:
open = (FAR struct spawn_open_file_action_s *)entry; open = (FAR struct spawn_open_file_action_s *)entry;
size += ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)), size += ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
sizeof(FAR void *)); sizeof(FAR void *));
break; break;
default: default:
@ -155,8 +150,8 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
strcpy(open->path, tmp->path); strcpy(open->path, tmp->path);
buffer = (FAR char *)buffer + buffer = (FAR char *)buffer +
ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)), ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
sizeof(FAR void *)); sizeof(FAR void *));
break; break;
default: default:

View file

@ -35,6 +35,7 @@
#include <nuttx/init.h> #include <nuttx/init.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/nuttx.h>
#include <nuttx/spinlock.h> #include <nuttx/spinlock.h>
/**************************************************************************** /****************************************************************************
@ -112,11 +113,6 @@
#define MAXARCS (1 << 20) #define MAXARCS (1 << 20)
/* General rounding functions. */
#define ROUNDDOWN(x, y) (((x) / (y)) * (y))
#define ROUNDUP(x, y) ((((x) + (y) - 1) / (y)) * (y))
/* See profil(2) where this is described (incorrectly) */ /* See profil(2) where this is described (incorrectly) */
#define SCALE_1_TO_1 0x10000 #define SCALE_1_TO_1 0x10000
@ -288,13 +284,13 @@ void moncontrol(int mode)
if (mode) if (mode)
{ {
uintptr_t lowpc = ROUNDDOWN((uintptr_t)&_stext, uintptr_t lowpc = ALIGN_DOWN((uintptr_t)&_stext,
HISTFRACTION * sizeof(HISTCOUNTER)); HISTFRACTION * sizeof(HISTCOUNTER));
uintptr_t highpc = ROUNDUP((uintptr_t)&_etext, uintptr_t highpc = ALIGN_UP((uintptr_t)&_etext,
HISTFRACTION * sizeof(HISTCOUNTER)); HISTFRACTION * sizeof(HISTCOUNTER));
size_t textsize = highpc - lowpc; size_t textsize = highpc - lowpc;
size_t kcountsize = ROUNDUP(textsize / HISTFRACTION, size_t kcountsize = ALIGN_UP(textsize / HISTFRACTION,
sizeof(*p->kcount)); sizeof(*p->kcount));
int scale = kcountsize >= textsize ? SCALE_1_TO_1 : int scale = kcountsize >= textsize ? SCALE_1_TO_1 :
(float)kcountsize / textsize * SCALE_1_TO_1; (float)kcountsize / textsize * SCALE_1_TO_1;
FAR unsigned short *kcount = kmm_zalloc(kcountsize); FAR unsigned short *kcount = kmm_zalloc(kcountsize);
@ -370,10 +366,10 @@ void monstartup(unsigned long lowpc, unsigned long highpc)
* so the rest of the scaling (here and in gprof) stays in ints. * so the rest of the scaling (here and in gprof) stays in ints.
*/ */
lowpc = ROUNDDOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER)); lowpc = ALIGN_DOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
highpc = ROUNDUP(highpc, HISTFRACTION * sizeof(HISTCOUNTER)); highpc = ALIGN_UP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
textsize = highpc - lowpc; textsize = highpc - lowpc;
fromssize = ROUNDUP(textsize / HASHFRACTION, sizeof(*p->froms)); fromssize = ALIGN_UP(textsize / HASHFRACTION, sizeof(*p->froms));
tolimit = textsize * ARCDENSITY / 100; tolimit = textsize * ARCDENSITY / 100;
if (tolimit < MINARCS) if (tolimit < MINARCS)

View file

@ -41,8 +41,6 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG) #if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
# define ioberr _err # define ioberr _err
# define iobwarn _warn # define iobwarn _warn

View file

@ -35,6 +35,7 @@
#ifdef CONFIG_IOB_ALLOC #ifdef CONFIG_IOB_ALLOC
# include <nuttx/kmalloc.h> # include <nuttx/kmalloc.h>
#endif #endif
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h> #include <nuttx/mm/iob.h>
#include "iob.h" #include "iob.h"
@ -333,7 +334,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
FAR struct iob_s *iob; FAR struct iob_s *iob;
size_t alignsize; size_t alignsize;
alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size; alignsize = ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize); iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
if (iob) if (iob)
@ -344,8 +345,8 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
iob->io_bufsize = size; /* Total length of the iob buffer */ iob->io_bufsize = size; /* Total length of the iob buffer */
iob->io_pktlen = 0; /* Total length of the packet */ iob->io_pktlen = 0; /* Total length of the packet */
iob->io_free = iob_free_dynamic; /* Customer free callback */ iob->io_free = iob_free_dynamic; /* Customer free callback */
iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1), iob->io_data = (FAR uint8_t *)ALIGN_UP((uintptr_t)(iob + 1),
CONFIG_IOB_ALIGNMENT); CONFIG_IOB_ALIGNMENT);
} }
return iob; return iob;

View file

@ -28,6 +28,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h> #include <nuttx/mm/iob.h>
#include "iob.h" #include "iob.h"
@ -39,10 +40,10 @@
/* Fix the I/O Buffer size with specified alignment size */ /* Fix the I/O Buffer size with specified alignment size */
#ifdef CONFIG_IOB_ALLOC #ifdef CONFIG_IOB_ALLOC
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \ # define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
CONFIG_IOB_ALIGNMENT) CONFIG_IOB_ALIGNMENT)
#else #else
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) # define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
#endif #endif
#define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \ #define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \
@ -137,8 +138,8 @@ void iob_initialize(void)
* aligned to the CONFIG_IOB_ALIGNMENT memory boundary * aligned to the CONFIG_IOB_ALIGNMENT memory boundary
*/ */
buf = ROUNDUP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data), buf = ALIGN_UP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data); CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data);
/* Get I/O buffer instance from the start address and add each I/O buffer /* Get I/O buffer instance from the start address and add each I/O buffer
* to the free list * to the free list

View file

@ -25,6 +25,7 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/nuttx.h> #include <nuttx/nuttx.h>
#include <nuttx/mm/mm.h>
#include <nuttx/mm/kasan.h> #include <nuttx/mm/kasan.h>
#include <nuttx/compiler.h> #include <nuttx/compiler.h>
#include <nuttx/spinlock.h> #include <nuttx/spinlock.h>
@ -44,10 +45,8 @@
#define KASAN_LAST_WORD_MASK(end) \ #define KASAN_LAST_WORD_MASK(end) \
(UINTPTR_MAX >> (-(end) & (KASAN_BITS_PER_WORD - 1))) (UINTPTR_MAX >> (-(end) & (KASAN_BITS_PER_WORD - 1)))
#define KASAN_SHADOW_SCALE (sizeof(uintptr_t))
#define KASAN_SHADOW_SIZE(size) \ #define KASAN_SHADOW_SIZE(size) \
(KASAN_BYTES_PER_WORD * ((size) / KASAN_SHADOW_SCALE / KASAN_BITS_PER_WORD)) (KASAN_BYTES_PER_WORD * ((size) / MM_ALIGN / KASAN_BITS_PER_WORD))
#define KASAN_REGION_SIZE(size) \ #define KASAN_REGION_SIZE(size) \
(sizeof(struct kasan_region_s) + KASAN_SHADOW_SIZE(size)) (sizeof(struct kasan_region_s) + KASAN_SHADOW_SIZE(size))
@ -87,7 +86,7 @@ kasan_mem_to_shadow(FAR const void *ptr, size_t size,
{ {
DEBUGASSERT(addr + size <= g_region[i]->end); DEBUGASSERT(addr + size <= g_region[i]->end);
addr -= g_region[i]->begin; addr -= g_region[i]->begin;
addr /= KASAN_SHADOW_SCALE; addr /= MM_ALIGN;
*bit = addr % KASAN_BITS_PER_WORD; *bit = addr % KASAN_BITS_PER_WORD;
return &g_region[i]->shadow[addr / KASAN_BITS_PER_WORD]; return &g_region[i]->shadow[addr / KASAN_BITS_PER_WORD];
} }
@ -110,15 +109,15 @@ kasan_is_poisoned(FAR const void *addr, size_t size)
return kasan_global_is_poisoned(addr, size); return kasan_global_is_poisoned(addr, size);
} }
if (size <= KASAN_SHADOW_SCALE) if (size <= MM_ALIGN)
{ {
return ((*p >> bit) & 1); return ((*p >> bit) & 1);
} }
nbit = KASAN_BITS_PER_WORD - bit % KASAN_BITS_PER_WORD; nbit = KASAN_BITS_PER_WORD - bit % KASAN_BITS_PER_WORD;
mask = KASAN_FIRST_WORD_MASK(bit); mask = KASAN_FIRST_WORD_MASK(bit);
size = ALIGN_UP(size, KASAN_SHADOW_SCALE); size = ALIGN_UP(size, MM_ALIGN);
size /= KASAN_SHADOW_SCALE; size /= MM_ALIGN;
while (size >= nbit) while (size >= nbit)
{ {
@ -155,6 +154,9 @@ static void kasan_set_poison(FAR const void *addr, size_t size,
unsigned int nbit; unsigned int nbit;
uintptr_t mask; uintptr_t mask;
DEBUGASSERT((uintptr_t)addr % MM_ALIGN == 0);
DEBUGASSERT(size % MM_ALIGN == 0);
p = kasan_mem_to_shadow(addr, size, &bit); p = kasan_mem_to_shadow(addr, size, &bit);
if (p == NULL) if (p == NULL)
{ {
@ -163,7 +165,7 @@ static void kasan_set_poison(FAR const void *addr, size_t size,
nbit = KASAN_BITS_PER_WORD - bit % KASAN_BITS_PER_WORD; nbit = KASAN_BITS_PER_WORD - bit % KASAN_BITS_PER_WORD;
mask = KASAN_FIRST_WORD_MASK(bit); mask = KASAN_FIRST_WORD_MASK(bit);
size /= KASAN_SHADOW_SCALE; size /= MM_ALIGN;
flags = spin_lock_irqsave(&g_lock); flags = spin_lock_irqsave(&g_lock);
while (size >= nbit) while (size >= nbit)

View file

@ -22,6 +22,7 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/mm/mm.h>
#include <nuttx/mm/kasan.h> #include <nuttx/mm/kasan.h>
#include <nuttx/compiler.h> #include <nuttx/compiler.h>
#include <nuttx/spinlock.h> #include <nuttx/spinlock.h>
@ -45,10 +46,8 @@
#define kasan_random_tag() (1 + rand() % ((1 << (64 - KASAN_TAG_SHIFT)) - 2)) #define kasan_random_tag() (1 + rand() % ((1 << (64 - KASAN_TAG_SHIFT)) - 2))
#define KASAN_SHADOW_SCALE (sizeof(uintptr_t))
#define KASAN_SHADOW_SIZE(size) \ #define KASAN_SHADOW_SIZE(size) \
((size) + KASAN_SHADOW_SCALE - 1) / KASAN_SHADOW_SCALE ((size) + MM_ALIGN - 1) / MM_ALIGN
#define KASAN_REGION_SIZE(size) \ #define KASAN_REGION_SIZE(size) \
(sizeof(struct kasan_region_s) + KASAN_SHADOW_SIZE(size)) (sizeof(struct kasan_region_s) + KASAN_SHADOW_SIZE(size))
@ -89,7 +88,7 @@ kasan_mem_to_shadow(FAR const void *ptr, size_t size)
{ {
DEBUGASSERT(addr + size <= g_region[i]->end); DEBUGASSERT(addr + size <= g_region[i]->end);
addr -= g_region[i]->begin; addr -= g_region[i]->begin;
return &g_region[i]->shadow[addr / KASAN_SHADOW_SCALE]; return &g_region[i]->shadow[addr / MM_ALIGN];
} }
} }
@ -135,6 +134,9 @@ static void kasan_set_poison(FAR const void *addr,
irqstate_t flags; irqstate_t flags;
FAR uint8_t *p; FAR uint8_t *p;
DEBUGASSERT((uintptr_t)addr % MM_ALIGN == 0);
DEBUGASSERT(size % MM_ALIGN == 0);
p = kasan_mem_to_shadow(addr, size); p = kasan_mem_to_shadow(addr, size);
if (p == NULL) if (p == NULL)
{ {

View file

@ -143,7 +143,7 @@
* previous freenode * previous freenode
*/ */
#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t)) #define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - MM_ALIGN)
/* Get the node size */ /* Get the node size */
@ -173,7 +173,12 @@ typedef size_t mmsize_t;
struct mm_allocnode_s struct mm_allocnode_s
{ {
mmsize_t preceding; /* Physical preceding chunk size */ union
{
mmsize_t preceding; /* Physical preceding chunk size */
uint8_t align[MM_ALIGN];
};
mmsize_t size; /* Size of this chunk */ mmsize_t size; /* Size of this chunk */
#if CONFIG_MM_BACKTRACE >= 0 #if CONFIG_MM_BACKTRACE >= 0
pid_t pid; /* The pid for caller */ pid_t pid; /* The pid for caller */
@ -182,13 +187,19 @@ struct mm_allocnode_s
FAR void *backtrace[CONFIG_MM_BACKTRACE]; /* The backtrace buffer for caller */ FAR void *backtrace[CONFIG_MM_BACKTRACE]; /* The backtrace buffer for caller */
# endif # endif
#endif #endif
}; }
aligned_data(MM_ALIGN);
/* This describes a free chunk */ /* This describes a free chunk */
struct mm_freenode_s struct mm_freenode_s
{ {
mmsize_t preceding; /* Physical preceding chunk size */ union
{
mmsize_t preceding; /* Physical preceding chunk size */
uint8_t align[MM_ALIGN];
};
mmsize_t size; /* Size of this chunk */ mmsize_t size; /* Size of this chunk */
#if CONFIG_MM_BACKTRACE >= 0 #if CONFIG_MM_BACKTRACE >= 0
pid_t pid; /* The pid for caller */ pid_t pid; /* The pid for caller */
@ -199,7 +210,8 @@ struct mm_freenode_s
#endif #endif
FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */ FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
FAR struct mm_freenode_s *blink; FAR struct mm_freenode_s *blink;
}; }
aligned_data(MM_ALIGN);
static_assert(MM_SIZEOF_ALLOCNODE <= MM_MIN_CHUNK, static_assert(MM_SIZEOF_ALLOCNODE <= MM_MIN_CHUNK,
"Error size for struct mm_allocnode_s\n"); "Error size for struct mm_allocnode_s\n");

View file

@ -150,7 +150,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
heapbase = MM_ALIGN_UP((uintptr_t)heapstart + 2 * MM_SIZEOF_ALLOCNODE) - heapbase = MM_ALIGN_UP((uintptr_t)heapstart + 2 * MM_SIZEOF_ALLOCNODE) -
2 * MM_SIZEOF_ALLOCNODE; 2 * MM_SIZEOF_ALLOCNODE;
heapsize = heapsize - (heapbase - (uintptr_t)heapstart); heapsize = MM_ALIGN_DOWN(heapsize - (heapbase - (uintptr_t)heapstart));
/* Register KASan for access rights check. We need to register after /* Register KASan for access rights check. We need to register after
* address alignment. * address alignment.

View file

@ -53,6 +53,7 @@ static struct timespec g_clock_wall_time;
static uint64_t g_clock_last_counter; static uint64_t g_clock_last_counter;
static uint64_t g_clock_mask; static uint64_t g_clock_mask;
static long g_clock_adjust; static long g_clock_adjust;
static spinlock_t g_clock_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -72,7 +73,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
time_t sec; time_t sec;
int ret; int ret;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter); ret = up_timer_gettick(&counter);
if (ret < 0) if (ret < 0)
@ -96,7 +97,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
ts->tv_sec = base->tv_sec + sec; ts->tv_sec = base->tv_sec + sec;
errout_in_critical_section: errout_in_critical_section:
leave_critical_section(flags); spin_unlock_irqrestore(&g_clock_lock, flags);
return ret; return ret;
} }
@ -123,7 +124,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
uint64_t counter; uint64_t counter;
int ret; int ret;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter); ret = up_timer_gettick(&counter);
if (ret < 0) if (ret < 0)
@ -137,7 +138,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
g_clock_last_counter = counter; g_clock_last_counter = counter;
errout_in_critical_section: errout_in_critical_section:
leave_critical_section(flags); spin_unlock_irqrestore(&g_clock_lock, flags);
return ret; return ret;
} }
@ -188,7 +189,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
return -1; return -1;
} }
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_clock_lock);
adjust_usec = delta->tv_sec * USEC_PER_SEC + delta->tv_usec; adjust_usec = delta->tv_sec * USEC_PER_SEC + delta->tv_usec;
@ -199,7 +200,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
g_clock_adjust = adjust_usec; g_clock_adjust = adjust_usec;
leave_critical_section(flags); spin_unlock_irqrestore(&g_clock_lock, flags);
return OK; return OK;
} }
@ -217,7 +218,7 @@ void clock_update_wall_time(void)
time_t sec; time_t sec;
int ret; int ret;
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter); ret = up_timer_gettick(&counter);
if (ret < 0) if (ret < 0)
@ -271,7 +272,7 @@ void clock_update_wall_time(void)
g_clock_last_counter = counter; g_clock_last_counter = counter;
errout_in_critical_section: errout_in_critical_section:
leave_critical_section(flags); spin_unlock_irqrestore(&g_clock_lock, flags);
} }
/**************************************************************************** /****************************************************************************
@ -280,6 +281,9 @@ errout_in_critical_section:
void clock_inittimekeeping(FAR const struct timespec *tp) void clock_inittimekeeping(FAR const struct timespec *tp)
{ {
irqstate_t flags;
flags = spin_lock_irqsave(&g_clock_lock);
up_timer_getmask(&g_clock_mask); up_timer_getmask(&g_clock_mask);
if (tp) if (tp)
@ -292,6 +296,7 @@ void clock_inittimekeeping(FAR const struct timespec *tp)
} }
up_timer_gettick(&g_clock_last_counter); up_timer_gettick(&g_clock_last_counter);
spin_unlock_irqrestore(&g_clock_lock, flags);
} }
#endif /* CONFIG_CLOCK_TIMEKEEPING */ #endif /* CONFIG_CLOCK_TIMEKEEPING */

View file

@ -32,6 +32,7 @@
#include <nuttx/coredump.h> #include <nuttx/coredump.h>
#include <nuttx/elf.h> #include <nuttx/elf.h>
#include <nuttx/nuttx.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include "sched/sched.h" #include "sched/sched.h"
@ -54,9 +55,6 @@
#define PROGRAM_ALIGNMENT 64 #define PROGRAM_ALIGNMENT 64
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@ -166,8 +164,8 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo) static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo)
{ {
off_t align = ROUNDUP(cinfo->stream->nput, off_t align = ALIGN_UP(cinfo->stream->nput,
ELF_PAGESIZE) - cinfo->stream->nput; ELF_PAGESIZE) - cinfo->stream->nput;
unsigned char null[256]; unsigned char null[256];
off_t total = align; off_t total = align;
off_t ret = 0; off_t ret = 0;
@ -258,10 +256,10 @@ static int elf_get_note_size(int stksegs)
{ {
int total; int total;
total = stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) + total = stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prstatus_t)); sizeof(elf_prstatus_t));
total += stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) + total += stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prpsinfo_t)); sizeof(elf_prpsinfo_t));
return total; return total;
} }
@ -276,7 +274,7 @@ static int elf_get_note_size(int stksegs)
static void elf_emit_tcb_note(FAR struct elf_dumpinfo_s *cinfo, static void elf_emit_tcb_note(FAR struct elf_dumpinfo_s *cinfo,
FAR struct tcb_s *tcb) FAR struct tcb_s *tcb)
{ {
char name[ROUNDUP(CONFIG_TASK_NAME_SIZE, 8)]; char name[ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8)];
elf_prstatus_t status; elf_prstatus_t status;
elf_prpsinfo_t info; elf_prpsinfo_t info;
FAR uintptr_t *regs; FAR uintptr_t *regs;
@ -414,8 +412,8 @@ static void elf_emit_tcb_stack(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr); (tcb->stack_base_ptr - tcb->stack_alloc_ptr);
} }
sp = ROUNDDOWN(buf, PROGRAM_ALIGNMENT); sp = ALIGN_DOWN(buf, PROGRAM_ALIGNMENT);
len = ROUNDUP(len + (buf - sp), PROGRAM_ALIGNMENT); len = ALIGN_UP(len + (buf - sp), PROGRAM_ALIGNMENT);
buf = sp; buf = sp;
elf_emit(cinfo, (FAR void *)buf, len); elf_emit(cinfo, (FAR void *)buf, len);
@ -546,17 +544,17 @@ static void elf_emit_tcb_phdr(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr); (tcb->stack_base_ptr - tcb->stack_alloc_ptr);
} }
sp = ROUNDDOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT); sp = ALIGN_DOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ROUNDUP(phdr->p_filesz + phdr->p_filesz = ALIGN_UP(phdr->p_filesz +
(phdr->p_vaddr - sp), PROGRAM_ALIGNMENT); (phdr->p_vaddr - sp), PROGRAM_ALIGNMENT);
phdr->p_vaddr = sp; phdr->p_vaddr = sp;
phdr->p_type = PT_LOAD; phdr->p_type = PT_LOAD;
phdr->p_offset = ROUNDUP(*offset, ELF_PAGESIZE); phdr->p_offset = ALIGN_UP(*offset, ELF_PAGESIZE);
phdr->p_paddr = phdr->p_vaddr; phdr->p_paddr = phdr->p_vaddr;
phdr->p_memsz = phdr->p_filesz; phdr->p_memsz = phdr->p_filesz;
phdr->p_flags = PF_X | PF_W | PF_R; phdr->p_flags = PF_X | PF_W | PF_R;
*offset += ROUNDUP(phdr->p_memsz, ELF_PAGESIZE); *offset += ALIGN_UP(phdr->p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, phdr, sizeof(*phdr)); elf_emit(cinfo, phdr, sizeof(*phdr));
} }
@ -608,13 +606,13 @@ static void elf_emit_phdr(FAR struct elf_dumpinfo_s *cinfo,
for (i = 0; i < memsegs; i++) for (i = 0; i < memsegs; i++)
{ {
phdr.p_type = PT_LOAD; phdr.p_type = PT_LOAD;
phdr.p_offset = ROUNDUP(offset, ELF_PAGESIZE); phdr.p_offset = ALIGN_UP(offset, ELF_PAGESIZE);
phdr.p_vaddr = cinfo->regions[i].start; phdr.p_vaddr = cinfo->regions[i].start;
phdr.p_paddr = phdr.p_vaddr; phdr.p_paddr = phdr.p_vaddr;
phdr.p_filesz = cinfo->regions[i].end - cinfo->regions[i].start; phdr.p_filesz = cinfo->regions[i].end - cinfo->regions[i].start;
phdr.p_memsz = phdr.p_filesz; phdr.p_memsz = phdr.p_filesz;
phdr.p_flags = cinfo->regions[i].flags; phdr.p_flags = cinfo->regions[i].flags;
offset += ROUNDUP(phdr.p_memsz, ELF_PAGESIZE); offset += ALIGN_UP(phdr.p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, &phdr, sizeof(phdr)); elf_emit(cinfo, &phdr, sizeof(phdr));
} }
} }