1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-24 17:57:34 +03:00

boot: Use uintptr_t when converting EFI_PHYSICAL_ADDRESS

uintptr_t is the more appropriate type when casting to/from pointers.
This commit is contained in:
Jan Janssen 2022-07-12 09:43:13 +02:00
parent 12a233265d
commit 34938db5b3

View File

@ -144,22 +144,16 @@ EFI_STATUS open_directory(EFI_FILE *root_dir, const char16_t *path, EFI_FILE **r
/* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on /* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on
* 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the * 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the
* conversion indirectly: first into UINTN (which is defined by UEFI to have the same size as a pointer), and * conversion indirectly: first into uintptr_t and then extended to EFI_PHYSICAL_ADDRESS. */
* then extended to EFI_PHYSICAL_ADDRESS. */
static inline EFI_PHYSICAL_ADDRESS POINTER_TO_PHYSICAL_ADDRESS(const void *p) { static inline EFI_PHYSICAL_ADDRESS POINTER_TO_PHYSICAL_ADDRESS(const void *p) {
return (EFI_PHYSICAL_ADDRESS) (UINTN) p; return (EFI_PHYSICAL_ADDRESS) (uintptr_t) p;
} }
static inline void *PHYSICAL_ADDRESS_TO_POINTER(EFI_PHYSICAL_ADDRESS addr) { static inline void *PHYSICAL_ADDRESS_TO_POINTER(EFI_PHYSICAL_ADDRESS addr) {
#if __SIZEOF_POINTER__ == 4
/* On 32bit systems the address might not be convertible (as pointers are 32bit but /* On 32bit systems the address might not be convertible (as pointers are 32bit but
* EFI_PHYSICAL_ADDRESS 64bit) */ * EFI_PHYSICAL_ADDRESS 64bit) */
assert(addr <= UINT32_MAX); assert(addr <= UINTPTR_MAX);
#elif __SIZEOF_POINTER__ != 8 return (void *) (uintptr_t) addr;
#error "Unexpected pointer size"
#endif
return (void*) (UINTN) addr;
} }
uint64_t get_os_indications_supported(void); uint64_t get_os_indications_supported(void);