mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
TcgTpmPkg: Fix SIZE_MAX, UINTPTR_MAX and intptr_t definitions
CrtLibSupport.h defines SIZE_MAX and UINTPTR_MAX as 32-bit constants. The UINTPTR_MAX definition was controlled by "#if (UINT_MAX > 0xFFFFFFFFUL)" (can never be true), and SIZE_MAX was just hard-coded to 0xFFFFFFFF. The fix cannot just use MAX_UINTN because that isn't usable in preprocessor conditions. Instead, define SIZE_MAX and UINTPTR_MAX based on CPU. Also correct intptr_t, which was a typedef of the unsigned UINTN. The neighbouring ptrdiff_t and ssize_t already use INTN. PlatformTpmNullLib casts a pointer to intptr_t in NVMem.c, so the signedness matters. Nothing in TcgTpmPkg currently evaluates SIZE_MAX or UINTPTR_MAX, so this does not change the built output today; it corrects definitions that are wrong on 64-bit targets and keeps the header identical to the CryptoPkg copy, which is fixed by a separate patch. Tested by building TcgTpmPkg/TcgTpmPkg.dsc with GCC for AARCH64 (the only architecture the package supports). It builds cleanly before and after. Signed-off-by: Doug Cook <dcook@microsoft.com>
This commit is contained in:
parent
2970e5699b
commit
9e13bd2f88
1 changed files with 23 additions and 7 deletions
|
|
@ -50,6 +50,26 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// Largest value representable in UINTN, as a plain integer constant.
|
||||
//
|
||||
// The architecture list deliberately matches the one used above to select
|
||||
// SIXTY_FOUR_BIT.
|
||||
//
|
||||
// Cannot be based on SIXTY_FOUR_BIT -- that guides the integer width to use
|
||||
// for bignum computations and is not guaranteed to match UINTN or size_t.
|
||||
//
|
||||
// Cannot use MAX_UINTN because that expands to a cast and cannot be used for
|
||||
// preprocessor expressions.
|
||||
//
|
||||
#if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64) || defined (MDE_CPU_IA64) || defined (MDE_CPU_RISCV64) || defined (MDE_CPU_LOONGARCH64)
|
||||
#define CRT_MAX_UINTN 0xFFFFFFFFFFFFFFFFUL
|
||||
#elif defined (MDE_CPU_IA32) || defined (MDE_CPU_EBC)
|
||||
#define CRT_MAX_UINTN 0xFFFFFFFFUL
|
||||
#else
|
||||
#error Unknown target architecture
|
||||
#endif
|
||||
|
||||
//
|
||||
// Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
|
||||
//
|
||||
|
|
@ -70,7 +90,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
#define UINT_MAX 0xFFFFFFFF /* Maximum unsigned int value */
|
||||
#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
|
||||
#define CHAR_BIT 8 /* Number of bits in a char */
|
||||
#define SIZE_MAX 0xFFFFFFFF /* Maximum unsigned size_t */
|
||||
#define SIZE_MAX CRT_MAX_UINTN /* Maximum unsigned size_t */
|
||||
#define INT16_MAX 0x7FFF /* Maximum (signed) short value */
|
||||
#define UINT16_MAX 0xFFFF /* Maximum unsigned short value */
|
||||
|
||||
|
|
@ -97,7 +117,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
typedef UINTN size_t;
|
||||
typedef UINTN off_t;
|
||||
typedef UINTN u_int;
|
||||
typedef UINTN intptr_t;
|
||||
typedef INTN intptr_t;
|
||||
typedef INTN ptrdiff_t;
|
||||
typedef INTN ssize_t;
|
||||
typedef INT64 time_t;
|
||||
|
|
@ -487,8 +507,4 @@ memcpy (
|
|||
#endif
|
||||
|
||||
#undef UINTPTR_MAX
|
||||
#if (UINT_MAX > 0xFFFFFFFFUL)
|
||||
#define UINTPTR_MAX 0xFFFFFFFFFFFFFFFFUL
|
||||
#else
|
||||
#define UINTPTR_MAX 0xFFFFFFFFUL
|
||||
#endif
|
||||
#define UINTPTR_MAX CRT_MAX_UINTN
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue