git: d3bfcd66409b - main - libsa: smbios: Detect less-than-64-bit platforms via __SIZEOF_SIZE_T__

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Tue, 07 Oct 2025 08:15:00 UTC
The branch main has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=d3bfcd66409befc2d545e5449963b41c25c369a9

commit d3bfcd66409befc2d545e5449963b41c25c369a9
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-03-11 16:56:20 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-10-07 08:14:41 +0000

    libsa: smbios: Detect less-than-64-bit platforms via __SIZEOF_SIZE_T__
    
    What we really want here is to know if pointers can refer to 64-bit
    addresses, regardless of whether they also hold other information (such
    as capabilities in CHERI).  __SIZEOF_SIZE_T__ is probably the closest
    indication to that piece of information, so let's use it.  __ILP32__
    wasn't wrong in practice though, as we don't support 32-bit CHERI
    hardware (and likely never will).
    
    Consistently with this change, test whether we can actually address the
    64-bit SMBIOS's structure table by converting the end address to
    'size_t' and checking whether its value is preserved.
    
    Suggested by:   jhb (for the __ILP32__ => __SIZEOF_SIZE_T__ part)
    Reviewed by:    jhb, imp
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D49318
---
 stand/libsa/smbios.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/stand/libsa/smbios.c b/stand/libsa/smbios.c
index 32cd198a9537..73b49a111f89 100644
--- a/stand/libsa/smbios.c
+++ b/stand/libsa/smbios.c
@@ -186,14 +186,17 @@ smbios_sigsearch(const caddr_t addr, const uint32_t len)
 		     */
 		    SMBIOS_GET8(cp, 0x0a) != 0 &&
 		    smbios_checksum(cp, SMBIOS_GET8(cp, 0x06)) == 0) {
-#ifdef __ILP32__
+#if __SIZEOF_SIZE_T__ < 8
 			uint64_t end_addr;
 
 			end_addr = SMBIOS_GET64(cp, 0x10) + /* Start address. */
 			    SMBIOS_GET32(cp, 0x0c); /* Maximum size. */
-			/* Is the table (or part of it) located above 4G? */
-			if (end_addr >= (uint64_t)1 << 32)
-				/* Can't access it with 32-bit addressing. */
+			/*
+			 * Is the table (or part of it) located above what we
+			 * can address?
+			 */
+			if ((size_t)end_addr != end_addr)
+				/* Yes, give it up. */
 				continue;
 #endif
 			smbios.is_64bit_ep = 1;