Skip to content

Commit 807283b

Browse files
heshamelmatarycookpate
authored andcommitted
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>
1 parent f1043c4 commit 807283b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

portable/GCC/RISC-V/portmacro.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848

4949
/* Type definitions. */
5050
#if __riscv_xlen == 64
51-
#define portSTACK_TYPE uint64_t
5251
#define portBASE_TYPE int64_t
5352
#define portUBASE_TYPE uint64_t
5453
#define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffUL
55-
#define portPOINTER_SIZE_TYPE uint64_t
5654
#elif __riscv_xlen == 32
57-
#define portSTACK_TYPE uint32_t
5855
#define portBASE_TYPE int32_t
5956
#define portUBASE_TYPE uint32_t
6057
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
6158
#else /* if __riscv_xlen == 64 */
6259
#error "Assembler did not define __riscv_xlen"
6360
#endif /* if __riscv_xlen == 64 */
6461

62+
#define portPOINTER_SIZE_TYPE intptr_t
63+
#define portSTACK_TYPE uintptr_t
64+
6565
typedef portSTACK_TYPE StackType_t;
6666
typedef portBASE_TYPE BaseType_t;
6767
typedef portUBASE_TYPE UBaseType_t;

0 commit comments

Comments
 (0)