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 <Hesham.Almatary@cl.cam.ac.uk>
This commit is contained in:
Hesham Almatary 2026-02-18 06:50:21 +00:00 committed by Patrick Cook
parent f1043c49d5
commit 807283ba03

View file

@ -48,13 +48,10 @@
/* Type definitions. */ /* Type definitions. */
#if __riscv_xlen == 64 #if __riscv_xlen == 64
#define portSTACK_TYPE uint64_t
#define portBASE_TYPE int64_t #define portBASE_TYPE int64_t
#define portUBASE_TYPE uint64_t #define portUBASE_TYPE uint64_t
#define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL
#define portPOINTER_SIZE_TYPE uint64_t
#elif __riscv_xlen == 32 #elif __riscv_xlen == 32
#define portSTACK_TYPE uint32_t
#define portBASE_TYPE int32_t #define portBASE_TYPE int32_t
#define portUBASE_TYPE uint32_t #define portUBASE_TYPE uint32_t
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
@ -62,6 +59,9 @@
#error "Assembler did not define __riscv_xlen" #error "Assembler did not define __riscv_xlen"
#endif /* if __riscv_xlen == 64 */ #endif /* if __riscv_xlen == 64 */
#define portPOINTER_SIZE_TYPE intptr_t
#define portSTACK_TYPE uintptr_t
typedef portSTACK_TYPE StackType_t; typedef portSTACK_TYPE StackType_t;
typedef portBASE_TYPE BaseType_t; typedef portBASE_TYPE BaseType_t;
typedef portUBASE_TYPE UBaseType_t; typedef portUBASE_TYPE UBaseType_t;