From 807283ba0390f0401f1a8b6296f540462fef45bb Mon Sep 17 00:00:00 2001 From: Hesham Almatary Date: Wed, 18 Feb 2026 06:50:21 +0000 Subject: [PATCH] RISC-V: change pointer and stack types portPOINTER_SIZE_TYPE is used in FreeRTOS to store both pointer and integer values. Using a plain integer type for this purpose is unsafe on architectures that distinguish between pointers and integers, where an integer type (e.g. uint64_t) may not be able to represent all pointer values. The standard intptr_t type is explicitly defined to safely hold either a pointer or an integer. This commit changes portPOINTER_SIZE_TYPE to intptr_t, similar to the existing POSIX port, improving portability of the RISC-V port. Similarly, portSTACK_TYPE is used to store word-sized values on the stack that may represent either integers or pointers, and is often cast to pointer types. Changing it to uintptr_t makes this usage explicit and correct, improving portability, intent, and safety for capability-based extensions such as CHERI-RISC-V. Signed-off-by: Hesham Almatary --- portable/GCC/RISC-V/portmacro.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/portable/GCC/RISC-V/portmacro.h b/portable/GCC/RISC-V/portmacro.h index a516a2467..f7d2f3ef1 100644 --- a/portable/GCC/RISC-V/portmacro.h +++ b/portable/GCC/RISC-V/portmacro.h @@ -48,13 +48,10 @@ /* Type definitions. */ #if __riscv_xlen == 64 - #define portSTACK_TYPE uint64_t #define portBASE_TYPE int64_t #define portUBASE_TYPE uint64_t #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL - #define portPOINTER_SIZE_TYPE uint64_t #elif __riscv_xlen == 32 - #define portSTACK_TYPE uint32_t #define portBASE_TYPE int32_t #define portUBASE_TYPE uint32_t #define portMAX_DELAY ( TickType_t ) 0xffffffffUL @@ -62,6 +59,9 @@ #error "Assembler did not define __riscv_xlen" #endif /* if __riscv_xlen == 64 */ +#define portPOINTER_SIZE_TYPE intptr_t +#define portSTACK_TYPE uintptr_t + typedef portSTACK_TYPE StackType_t; typedef portBASE_TYPE BaseType_t; typedef portUBASE_TYPE UBaseType_t;