new type: ptraddr_t

ptraddr_t is an unsigned integer type that can hold the address of any
pointer.  It differes from uintptr_t in that it does not carry
provenance which is useful for CHERI in that it can disambigurate the
provenance of uintptr_t expressions.  It differes from size_t in that
some segmented architecture (not supported by FreeBSD) may have a size_t
that does not hold an address.

ptraddr_t is not yet standardized, but is currently proposed for
inclusion in C++2Y.

Prefer the compiler defined __PTRADDR_TYPE__ defintion where available
as this a new type and we don't need to worry about historical values.
Fall back to __size_t where unavailable.

Reviewed by:	kib, markj
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D53817
This commit is contained in:
Brooks Davis
2025-11-27 14:54:55 +00:00
parent 39cbfc78b5
commit dca634d154
3 changed files with 17 additions and 2 deletions
+3 -2
View File
@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd October 1, 2025
.Dd November 27, 2025
.Dt ARCH 7
.Os
.Sh NAME
@@ -48,7 +48,8 @@ and later, unless otherwise noted.
.Fx
uses a flat address space.
Variables of types
.Vt unsigned long
.Vt unsigned long ,
.Vt ptraddr_t ,
and
.Vt size_t
have the same representation.
+6
View File
@@ -103,6 +103,12 @@ typedef __int32_t __ptrdiff_t; /* ptr1 - ptr2 */
#error unsupported ptrdiff_t size
#endif
#ifdef __PTRADDR_TYPE__
typedef __PTRADDR_TYPE__ __ptraddr_t;
#else
typedef __size_t __ptraddr_t;
#endif
/*
* Target-dependent type definitions.
*/
+8
View File
@@ -32,6 +32,14 @@
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
#include <sys/_visible.h>
#if __BSD_VISIBLE
#ifndef _PTRADDR_T_DECLARED
typedef __ptraddr_t ptraddr_t;
#define _PTRADDR_T_DECLARED
#endif
#endif
#ifndef _PTRDIFF_T_DECLARED
typedef __ptrdiff_t ptrdiff_t;