add types: (u)int64ptr_t

This type represents an integer value of at least 64 bits which is
capable of being cast to and from pointer types.  It is intended to
replace various spellings of (u)int64_t there the value is expected to
hold a pointer.  This is common in Linux code to allow 32-bit and 64-bit
structures to be the same and used other places including OpenZFS.  With
the introduction of CHERI this no longer works, but we need to preserve
the ABI for integer pointer targets.  Rather than adding ifdefs in every
case, we introduce a new type.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53823
This commit is contained in:
Brooks Davis
2025-11-27 14:54:56 +00:00
parent 6ebbfe723b
commit 4e22cd3bf0
2 changed files with 22 additions and 0 deletions
+16
View File
@@ -78,6 +78,22 @@ typedef __intptr_t intptr_t;
typedef __uintptr_t uintptr_t;
#define _UINTPTR_T_DECLARED
#endif
#if defined(__BSD_VISIBLE) && __BSD_VISIBLE
/*
* Integer types which are 64-bits unless it needs to be larger to hold
* a pointer. These are to be used when the ABI for integer targets
* uses a fixed 64-bit integer to hold values including pointers in
* order to simplify 32- and 64-bit compatibility.
*/
#ifndef _INT64PTR_T_DECLARED
typedef __int64ptr_t int64ptr_t;
#define _INT64PTR_T_DECLARED
#endif
#ifndef _UINT64PTR_T_DECLARED
typedef __uint64ptr_t uint64ptr_t;
#define _UINT64PTR_T_DECLARED
#endif
#endif
#ifndef _INTMAX_T_DECLARED
typedef __intmax_t intmax_t;
#define _INTMAX_T_DECLARED
+6
View File
@@ -70,18 +70,24 @@ typedef __uint64_t __uintmax_t;
#ifdef __CHERI__
typedef __intcap_t __intptr_t;
typedef __intcap_t __intfptr_t;
typedef __intptr_t __int64ptr_t;
typedef __uintcap_t __uintptr_t;
typedef __uintcap_t __uintfptr_t;
typedef __uintptr_t __uint64ptr_t;
#elif __SIZEOF_POINTER__ == 8
typedef __int64_t __intptr_t;
typedef __int64_t __intfptr_t;
typedef __int64_t __int64ptr_t;
typedef __uint64_t __uintptr_t;
typedef __uint64_t __uintfptr_t;
typedef __uint64_t __uint64ptr_t;
#elif __SIZEOF_POINTER__ == 4
typedef __int32_t __intptr_t;
typedef __int32_t __intfptr_t;
typedef __int64_t __int64ptr_t;
typedef __uint32_t __uintptr_t;
typedef __uint32_t __uintfptr_t;
typedef __uint64_t __uint64ptr_t;
#else
#error unsupported pointer size
#endif