From cc0f5ca1cdb124a6279cffe442407e4ff638d3cc Mon Sep 17 00:00:00 2001 From: armink Date: Tue, 23 Oct 2018 16:03:17 +0800 Subject: [kernel][mem] Improve some ISR check range. --- src/mem.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/mem.c') diff --git a/src/mem.c b/src/mem.c index cb96ab9ee0..2fefb48b67 100644 --- a/src/mem.c +++ b/src/mem.c @@ -261,11 +261,11 @@ void *rt_malloc(rt_size_t size) rt_size_t ptr, ptr2; struct heap_mem *mem, *mem2; - RT_DEBUG_NOT_IN_INTERRUPT; - if (size == 0) return RT_NULL; + RT_DEBUG_NOT_IN_INTERRUPT; + if (size != RT_ALIGN(size, RT_ALIGN_SIZE)) RT_DEBUG_LOG(RT_DEBUG_MEM, ("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE))); @@ -513,8 +513,6 @@ void *rt_calloc(rt_size_t count, rt_size_t size) { void *p; - RT_DEBUG_NOT_IN_INTERRUPT; - /* allocate 'count' objects of size 'size' */ p = rt_malloc(count * size); @@ -536,10 +534,11 @@ void rt_free(void *rmem) { struct heap_mem *mem; - RT_DEBUG_NOT_IN_INTERRUPT; - if (rmem == RT_NULL) return; + + RT_DEBUG_NOT_IN_INTERRUPT; + RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0); RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr && (rt_uint8_t *)rmem < (rt_uint8_t *)heap_end); -- cgit v1.3.1 From 484afe9d2cb07c9e552ff905328eecb7170e8c8a Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 26 Oct 2018 06:35:42 +0800 Subject: [Kernel] Add 64bit CPU support. --- components/finsh/cmd.c | 4 ++-- include/rtdef.h | 18 +++++++++++++----- include/rthw.h | 10 +++++----- include/rtthread.h | 12 ++++++------ libcpu/Kconfig | 15 +++++++++++++++ src/ipc.c | 13 +++++++------ src/kservice.c | 23 ++++++++++++++--------- src/mem.c | 43 ++++++++++++++++++++++++++++--------------- src/memheap.c | 4 ++-- src/scheduler.c | 24 ++++++++++++------------ src/thread.c | 2 +- 11 files changed, 105 insertions(+), 63 deletions(-) (limited to 'src/mem.c') diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 0e04b794e9..7f12671429 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -102,9 +102,9 @@ static long _list_thread(struct rt_list_node *list) while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", - thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), + thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp), thread->stack_size, - (thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t) thread->stack_addr)) * 100 + (thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100 / thread->stack_size, thread->remaining_tick, thread->error); diff --git a/include/rtdef.h b/include/rtdef.h index 99caa1c7d5..fef08599c7 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -25,6 +25,7 @@ * 2018-09-04 Bernard change version number to v3.1.1 * 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel * 2018-10-13 Bernard change version number to v4.0.0 + * 2018-10-02 Bernard add 64bit arch support */ #ifndef __RT_DEF_H__ @@ -55,13 +56,20 @@ extern "C" { /* RT-Thread basic data type definitions */ typedef signed char rt_int8_t; /**< 8bit integer type */ typedef signed short rt_int16_t; /**< 16bit integer type */ -typedef signed long rt_int32_t; /**< 32bit integer type */ +typedef signed int rt_int32_t; /**< 32bit integer type */ typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */ typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */ -typedef unsigned long rt_uint32_t; /**< 32bit unsigned integer type */ -typedef int rt_bool_t; /**< boolean type */ +typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */ -/* 32bit CPU */ +#ifdef ARCH_CPU_64BIT +typedef signed long rt_int64_t; /**< 64bit integer type */ +typedef unsigned long rt_uint64_t; /**< 64bit unsigned integer type */ +#else +typedef signed long long rt_int64_t; /**< 64bit integer type */ +typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */ +#endif + +typedef int rt_bool_t; /**< boolean type */ typedef long rt_base_t; /**< Nbit CPU related date type */ typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */ @@ -648,7 +656,7 @@ struct rt_mailbox { struct rt_ipc_object parent; /**< inherit from ipc_object */ - rt_uint32_t *msg_pool; /**< start address of message buffer */ + rt_ubase_t *msg_pool; /**< start address of message buffer */ rt_uint16_t size; /**< size of message pool */ diff --git a/include/rthw.h b/include/rthw.h index c6af392e62..17151de99a 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -98,14 +98,14 @@ void rt_hw_interrupt_enable(rt_base_t level); /* * Context interfaces */ -void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to); -void rt_hw_context_switch_to(rt_uint32_t to); -void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to); +void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to); +void rt_hw_context_switch_to(rt_ubase_t to); +void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to); void rt_hw_console_output(const char *str); -void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry); -void rt_hw_show_memory(rt_uint32_t addr, rt_uint32_t size); +void rt_hw_backtrace(rt_uint32_t *fp, rt_ubase_t thread_entry); +void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size); /* * Exception interfaces diff --git a/include/rtthread.h b/include/rtthread.h index fc5029a220..814fa454d8 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -256,7 +256,7 @@ void rt_page_free(void *addr, rt_size_t npages); #endif #ifdef RT_USING_HOOK -void rt_malloc_sethook(void (*hook)(void *ptr, rt_uint32_t size)); +void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size)); void rt_free_sethook(void (*hook)(void *ptr)); #endif @@ -269,9 +269,9 @@ void rt_free_sethook(void (*hook)(void *ptr)); rt_err_t rt_memheap_init(struct rt_memheap *memheap, const char *name, void *start_addr, - rt_uint32_t size); + rt_size_t size); rt_err_t rt_memheap_detach(struct rt_memheap *heap); -void *rt_memheap_alloc(struct rt_memheap *heap, rt_uint32_t size); +void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size); void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize); void rt_memheap_free(void *ptr); #endif @@ -347,11 +347,11 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb); rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag); rt_err_t rt_mb_delete(rt_mailbox_t mb); -rt_err_t rt_mb_send(rt_mailbox_t mb, rt_uint32_t value); +rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value); rt_err_t rt_mb_send_wait(rt_mailbox_t mb, - rt_uint32_t value, + rt_ubase_t value, rt_int32_t timeout); -rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout); +rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout); rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg); #endif diff --git a/libcpu/Kconfig b/libcpu/Kconfig index 0a280d4b5c..69d9220da1 100644 --- a/libcpu/Kconfig +++ b/libcpu/Kconfig @@ -1,3 +1,6 @@ +config ARCH_CPU_64BIT + bool + config ARCH_ARM bool @@ -83,6 +86,18 @@ config ARCH_POWERPC config ARCH_RISCV bool +config ARCH_RISCV_FPU + bool + +config ARCH_RISCV32 + select ARCH_RISCV + bool + +config ARCH_RISCV64 + select ARCH_RISCV + select ARCH_CPU_64BIT + bool + config ARCH_IA32 bool diff --git a/src/ipc.c b/src/ipc.c index 56045911a8..7f603cfc4d 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -32,6 +32,7 @@ * 2010-11-10 Bernard add IPC reset command implementation. * 2011-12-18 Bernard add more parameter checking in message queue * 2013-09-14 Grissiom add an option check in rt_event_recv + * 2018-10-02 Bernard add 64bit support for mailbox */ #include @@ -486,10 +487,10 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg) if (cmd == RT_IPC_CMD_RESET) { - rt_uint32_t value; + rt_ubase_t value; /* get value */ - value = (rt_uint32_t)arg; + value = (rt_ubase_t)arg; /* disable interrupt */ level = rt_hw_interrupt_disable(); @@ -1373,7 +1374,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) /* init mailbox */ mb->size = size; - mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_uint32_t)); + mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t)); if (mb->msg_pool == RT_NULL) { /* delete mailbox object */ @@ -1436,7 +1437,7 @@ RTM_EXPORT(rt_mb_delete); * @return the error code */ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, - rt_uint32_t value, + rt_ubase_t value, rt_int32_t timeout) { struct rt_thread *thread; @@ -1567,7 +1568,7 @@ RTM_EXPORT(rt_mb_send_wait); * * @return the error code */ -rt_err_t rt_mb_send(rt_mailbox_t mb, rt_uint32_t value) +rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value) { return rt_mb_send_wait(mb, value, 0); } @@ -1583,7 +1584,7 @@ RTM_EXPORT(rt_mb_send); * * @return the error code */ -rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout) +rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) { struct rt_thread *thread; register rt_ubase_t temp; diff --git a/src/kservice.c b/src/kservice.c index dbc4a2fb0e..95c9308182 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1189,31 +1189,36 @@ RTM_EXPORT(rt_kprintf); */ void *rt_malloc_align(rt_size_t size, rt_size_t align) { - void *align_ptr; void *ptr; + void *align_ptr; + int uintptr_size; rt_size_t align_size; - /* align the alignment size to 4 byte */ - align = ((align + 0x03) & ~0x03); + /* sizeof pointer */ + uintptr_size = sizeof(void*); + uintptr_size -= 1; + + /* align the alignment size to uintptr size byte */ + align = ((align + uintptr_size) & ~uintptr_size); /* get total aligned size */ - align_size = ((size + 0x03) & ~0x03) + align; + align_size = ((size + uintptr_size) & ~uintptr_size) + align; /* allocate memory block from heap */ ptr = rt_malloc(align_size); if (ptr != RT_NULL) { /* the allocated memory block is aligned */ - if (((rt_uint32_t)ptr & (align - 1)) == 0) + if (((rt_ubase_t)ptr & (align - 1)) == 0) { - align_ptr = (void *)((rt_uint32_t)ptr + align); + align_ptr = (void *)((rt_ubase_t)ptr + align); } else { - align_ptr = (void *)(((rt_uint32_t)ptr + (align - 1)) & ~(align - 1)); + align_ptr = (void *)(((rt_ubase_t)ptr + (align - 1)) & ~(align - 1)); } /* set the pointer before alignment pointer to the real pointer */ - *((rt_uint32_t *)((rt_uint32_t)align_ptr - sizeof(void *))) = (rt_uint32_t)ptr; + *((rt_ubase_t *)((rt_ubase_t)align_ptr - sizeof(void *))) = (rt_ubase_t)ptr; ptr = align_ptr; } @@ -1232,7 +1237,7 @@ void rt_free_align(void *ptr) { void *real_ptr; - real_ptr = (void *) * (rt_uint32_t *)((rt_uint32_t)ptr - sizeof(void *)); + real_ptr = (void *) * (rt_ubase_t *)((rt_ubase_t)ptr - sizeof(void *)); rt_free(real_ptr); } RTM_EXPORT(rt_free_align); diff --git a/src/mem.c b/src/mem.c index 2fefb48b67..ca5329404e 100644 --- a/src/mem.c +++ b/src/mem.c @@ -11,6 +11,7 @@ * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca * 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer. * 2017-07-14 armink fix rt_realloc issue when new size is 0 + * 2018-10-02 Bernard Add 64bit support */ /* @@ -97,12 +98,19 @@ struct heap_mem /* magic and used flag */ rt_uint16_t magic; rt_uint16_t used; +#ifdef ARCH_CPU_64BIT + rt_uint32_t resv; +#endif rt_size_t next, prev; #ifdef RT_USING_MEMTRACE +#ifdef ARCH_CPU_64BIT + rt_uint8_t thread[8]; +#else rt_uint8_t thread[4]; /* thread name */ #endif +#endif }; /** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */ @@ -111,7 +119,12 @@ static rt_uint8_t *heap_ptr; /** the last entry, always unused! */ static struct heap_mem *heap_end; +#ifdef ARCH_CPU_64BIT +#define MIN_SIZE 24 +#else #define MIN_SIZE 12 +#endif + #define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE) #define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE) @@ -191,8 +204,8 @@ static void plug_holes(struct heap_mem *mem) void rt_system_heap_init(void *begin_addr, void *end_addr) { struct heap_mem *mem; - rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE); - rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE); + rt_ubase_t begin_align = RT_ALIGN((rt_ubase_t)begin_addr, RT_ALIGN_SIZE); + rt_ubase_t end_align = RT_ALIGN_DOWN((rt_ubase_t)end_addr, RT_ALIGN_SIZE); RT_DEBUG_NOT_IN_INTERRUPT; @@ -206,7 +219,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) else { rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n", - (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr); + (rt_ubase_t)begin_addr, (rt_ubase_t)end_addr); return; } @@ -215,7 +228,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) heap_ptr = (rt_uint8_t *)begin_align; RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n", - (rt_uint32_t)heap_ptr, mem_size_aligned)); + (rt_ubase_t)heap_ptr, mem_size_aligned)); /* initialize the start of the heap */ mem = (struct heap_mem *)heap_ptr; @@ -374,14 +387,14 @@ void *rt_malloc(rt_size_t size) } rt_sem_release(&heap_sem); - RT_ASSERT((rt_uint32_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_uint32_t)heap_end); - RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0); - RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE - 1)) == 0); + RT_ASSERT((rt_ubase_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_ubase_t)heap_end); + RT_ASSERT((rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0); + RT_ASSERT((((rt_ubase_t)mem) & (RT_ALIGN_SIZE - 1)) == 0); RT_DEBUG_LOG(RT_DEBUG_MEM, ("allocate memory at 0x%x, size: %d\n", - (rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM), - (rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr)))); + (rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM), + (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr)))); RT_OBJECT_HOOK_CALL(rt_malloc_hook, (((void *)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size)); @@ -539,7 +552,7 @@ void rt_free(void *rmem) RT_DEBUG_NOT_IN_INTERRUPT; - RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0); + RT_ASSERT((((rt_ubase_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0); RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr && (rt_uint8_t *)rmem < (rt_uint8_t *)heap_end); @@ -558,8 +571,8 @@ void rt_free(void *rmem) RT_DEBUG_LOG(RT_DEBUG_MEM, ("release memory 0x%x, size: %d\n", - (rt_uint32_t)rmem, - (rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr)))); + (rt_ubase_t)rmem, + (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr)))); /* protect the heap from concurrent access */ @@ -624,12 +637,12 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information) int memcheck(void) { int position; - rt_uint32_t level; + rt_ubase_t level; struct heap_mem *mem; level = rt_hw_interrupt_disable(); for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next]) { - position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr; + position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr; if (position < 0) goto __exit; if (position > mem_size_aligned) goto __exit; if (mem->magic != HEAP_MAGIC) goto __exit; @@ -664,7 +677,7 @@ int memtrace(int argc, char **argv) rt_kprintf("\n--memory item information --\n"); for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next]) { - int position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr; + int position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr; int size; rt_kprintf("[0x%08x - ", mem); diff --git a/src/memheap.c b/src/memheap.c index 946f163b64..eb5d710029 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -50,7 +50,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap, const char *name, void *start_addr, - rt_uint32_t size) + rt_size_t size) { struct rt_memheap_item *item; @@ -135,7 +135,7 @@ rt_err_t rt_memheap_detach(struct rt_memheap *heap) } RTM_EXPORT(rt_memheap_detach); -void *rt_memheap_alloc(struct rt_memheap *heap, rt_uint32_t size) +void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size) { rt_err_t result; rt_uint32_t free_size; diff --git a/src/scheduler.c b/src/scheduler.c index 95b5d487df..446b153e1b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -75,11 +75,11 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) RT_ASSERT(thread != RT_NULL); if (*((rt_uint8_t *)thread->stack_addr) != '#' || - (rt_uint32_t)thread->sp <= (rt_uint32_t)thread->stack_addr || - (rt_uint32_t)thread->sp > - (rt_uint32_t)thread->stack_addr + (rt_uint32_t)thread->stack_size) + (rt_ubase_t)thread->sp <= (rt_ubase_t)thread->stack_addr || + (rt_ubase_t)thread->sp > + (rt_ubase_t)thread->stack_addr + (rt_ubase_t)thread->stack_size) { - rt_uint32_t level; + rt_ubase_t level; rt_kprintf("thread:%s stack overflow\n", thread->name); #ifdef RT_USING_FINSH @@ -91,7 +91,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) level = rt_hw_interrupt_disable(); while (level); } - else if ((rt_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32)) + else if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32)) { rt_kprintf("warning: %s stack is close to end of stack address.\n", thread->name); @@ -159,7 +159,7 @@ void rt_system_scheduler_start(void) rt_current_thread = to_thread; /* switch to new thread */ - rt_hw_context_switch_to((rt_uint32_t)&to_thread->sp); + rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp); /* never come back */ } @@ -214,8 +214,8 @@ void rt_schedule(void) /* switch to new thread */ RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("[%d]switch to priority#%d " - "thread:%.*s(sp:0x%p), " - "from thread:%.*s(sp: 0x%p)\n", + "thread:%.*s(sp:0x%08x), " + "from thread:%.*s(sp: 0x%08x)\n", rt_interrupt_nest, highest_ready_priority, RT_NAME_MAX, to_thread->name, to_thread->sp, RT_NAME_MAX, from_thread->name, from_thread->sp)); @@ -228,8 +228,8 @@ void rt_schedule(void) { extern void rt_thread_handle_sig(rt_bool_t clean_state); - rt_hw_context_switch((rt_uint32_t)&from_thread->sp, - (rt_uint32_t)&to_thread->sp); + rt_hw_context_switch((rt_ubase_t)&from_thread->sp, + (rt_ubase_t)&to_thread->sp); /* enable interrupt */ rt_hw_interrupt_enable(level); @@ -243,8 +243,8 @@ void rt_schedule(void) { RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("switch in interrupt\n")); - rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp, - (rt_uint32_t)&to_thread->sp); + rt_hw_context_switch_interrupt((rt_ubase_t)&from_thread->sp, + (rt_ubase_t)&to_thread->sp); /* enable interrupt */ rt_hw_interrupt_enable(level); } diff --git a/src/thread.c b/src/thread.c index 6d79ece54b..82eb18942c 100644 --- a/src/thread.c +++ b/src/thread.c @@ -137,7 +137,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, /* init thread stack */ rt_memset(thread->stack_addr, '#', thread->stack_size); thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, - (void *)((char *)thread->stack_addr + thread->stack_size - 4), + (void *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), (void *)rt_thread_exit); /* priority init */ -- cgit v1.3.1 From 7383269905417f9e4f8f5304e164e0ae31d7169a Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 12 Feb 2019 14:33:45 +0800 Subject: [Kernel] Code cleanup for compiling warning. --- components/dfs/src/dfs.c | 10 +++++----- components/drivers/serial/serial.c | 2 +- src/kservice.c | 2 +- src/mem.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/mem.c') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 066c800568..6d52129b06 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -123,7 +123,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) int idx; /* find an empty fd entry */ - for (idx = startfd; idx < fdt->maxfd; idx++) + for (idx = startfd; idx < (int)fdt->maxfd; idx++) { if (fdt->fds[idx] == RT_NULL) break; @@ -155,7 +155,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) } /* allocate 'struct dfs_fd' */ - if (idx < fdt->maxfd &&fdt->fds[idx] == RT_NULL) + if (idx < (int)fdt->maxfd && fdt->fds[idx] == RT_NULL) { fdt->fds[idx] = rt_calloc(1, sizeof(struct dfs_fd)); if (fdt->fds[idx] == RT_NULL) @@ -223,7 +223,7 @@ struct dfs_fd *fd_get(int fd) fdt = dfs_fdtable_get(); fd = fd - DFS_FD_OFFSET; - if (fd < 0 || fd >= fdt->maxfd) + if (fd < 0 || fd >= (int)fdt->maxfd) return NULL; dfs_lock(); @@ -263,7 +263,7 @@ void fd_put(struct dfs_fd *fd) struct dfs_fdtable *fdt; fdt = dfs_fdtable_get(); - for (index = 0; index < fdt->maxfd; index ++) + for (index = 0; index < (int)fdt->maxfd; index ++) { if (fdt->fds[index] == fd) { @@ -531,7 +531,7 @@ int list_fd(void) rt_kprintf("fd type ref magic path\n"); rt_kprintf("-- ------ --- ----- ------\n"); - for (index = 0; index < fd_table->maxfd; index ++) + for (index = 0; index < (int)fd_table->maxfd; index ++) { struct dfs_fd *fd = fd_table->fds[index]; diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 77f2a645a1..a03e4a719e 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -478,7 +478,7 @@ rt_inline int _serial_dma_rx(struct rt_serial_device *serial, rt_uint8_t *data, RT_ASSERT(rx_fifo != RT_NULL); - if (length < fifo_recved_len) + if (length < (int)fifo_recved_len) recv_len = length; else recv_len = fifo_recved_len; diff --git a/src/kservice.c b/src/kservice.c index dc7370d58b..b640107a33 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -476,7 +476,7 @@ rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen) { const char *sc; - for (sc = s; *sc != '\0' && sc - s < maxlen; ++sc) /* nothing */ + for (sc = s; *sc != '\0' && sc - s < (int)maxlen; ++sc) /* nothing */ ; return sc - s; diff --git a/src/mem.c b/src/mem.c index ca5329404e..8099b6bb7e 100644 --- a/src/mem.c +++ b/src/mem.c @@ -644,7 +644,7 @@ int memcheck(void) { position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr; if (position < 0) goto __exit; - if (position > mem_size_aligned) goto __exit; + if (position > (int)mem_size_aligned) goto __exit; if (mem->magic != HEAP_MAGIC) goto __exit; if (mem->used != 0 && mem->used != 1) goto __exit; } -- cgit v1.3.1 From b082876c9b06d8a883726e6ddec50c2b49b6c4da Mon Sep 17 00:00:00 2001 From: greed-island <62747314+greed-island@users.noreply.github.com> Date: Fri, 27 Mar 2020 18:57:29 +0800 Subject: Update mem.c rt_realloc may cause change, if we don't change timely, it may cause memory leakage --- src/mem.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/mem.c') diff --git a/src/mem.c b/src/mem.c index 8099b6bb7e..c03c8b3452 100644 --- a/src/mem.c +++ b/src/mem.c @@ -489,6 +489,12 @@ void *rt_realloc(void *rmem, rt_size_t newsize) { ((struct heap_mem *)&heap_ptr[mem2->next])->prev = ptr2; } + + if (mem2 < lfree) + { + /* the splited struct is now the lowest */ + lfree = mem2; + } plug_holes(mem2); -- cgit v1.3.1