From b5c681071a40cbc8a8989d701954c4c8e6314cbf Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Thu, 21 Nov 2019 17:38:17 -0800 Subject: [PATCH] kernel: don't use u32_t for data sizes Use a size_t instead. Signed-off-by: Andrew Boie --- include/kernel.h | 4 ++-- kernel/thread.c | 12 ++++++------ tests/kernel/mem_protect/userspace/src/main.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/kernel.h b/include/kernel.h index 9ea145afe86..19e140994f7 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -4973,7 +4973,7 @@ extern void z_timer_expiration_handler(struct _timeout *t); #define K_THREAD_STACK_LEN(size) ARCH_THREAD_STACK_LEN(size) #define K_THREAD_STACK_MEMBER(sym, size) ARCH_THREAD_STACK_MEMBER(sym, size) #define K_THREAD_STACK_SIZEOF(sym) ARCH_THREAD_STACK_SIZEOF(sym) -#define K_THREAD_STACK_RESERVED ARCH_THREAD_STACK_RESERVED +#define K_THREAD_STACK_RESERVED ((size_t)ARCH_THREAD_STACK_RESERVED) static inline char *Z_THREAD_STACK_BUFFER(k_thread_stack_t *sym) { return ARCH_THREAD_STACK_BUFFER(sym); @@ -5082,7 +5082,7 @@ static inline char *Z_THREAD_STACK_BUFFER(k_thread_stack_t *sym) * the stack object, and does not account for additional space used due to * enforce alignment. */ -#define K_THREAD_STACK_RESERVED 0 +#define K_THREAD_STACK_RESERVED ((size_t)0U) /** * @brief Get a pointer to the physical stack buffer diff --git a/kernel/thread.c b/kernel/thread.c index 1a2ac59271c..ef50f137bcb 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -599,7 +599,7 @@ k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread, void *p1, void *p2, void *p3, int prio, u32_t options, s32_t delay) { - u32_t total_size; + size_t total_size; struct _k_object *stack_object; /* The thread and stack objects *must* be in an uninitialized state */ @@ -613,17 +613,17 @@ k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread, /* Verify that the stack size passed in is OK by computing the total * size and comparing it with the size value in the object metadata */ - Z_OOPS(Z_SYSCALL_VERIFY_MSG(!u32_add_overflow(K_THREAD_STACK_RESERVED, - stack_size, &total_size), - "stack size overflow (%u+%u)", - (unsigned int) stack_size, + Z_OOPS(Z_SYSCALL_VERIFY_MSG(!size_add_overflow(K_THREAD_STACK_RESERVED, + stack_size, &total_size), + "stack size overflow (%zu+%zu)", + stack_size, K_THREAD_STACK_RESERVED)); /* Testing less-than-or-equal since additional room may have been * allocated for alignment constraints */ Z_OOPS(Z_SYSCALL_VERIFY_MSG(total_size <= stack_object->data, - "stack size %u is too big, max is %lu", + "stack size %zu is too big, max is %lu", total_size, stack_object->data)); /* User threads may only create other user threads and they can't diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index 7d7ba606112..a15f44eae07 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -1048,7 +1048,7 @@ void scenario_entry(void *stack_obj, size_t obj_size) void test_stack_buffer(void) { - printk("Reserved space: %u\n", K_THREAD_STACK_RESERVED); + printk("Reserved space: %zu\n", K_THREAD_STACK_RESERVED); printk("Provided stack size: %u\n", STEST_STACKSIZE); scenario_entry(stest_stack, sizeof(stest_stack));