From ebcc6affe5ec1d2fa2ba2e5f48cf1989419edec4 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 3 Feb 2026 14:30:15 -0500 Subject: [PATCH] StandaloneMmPkg: Replace include guards with #pragma once Replace traditional `#ifndef`/`#define`/`#endif` include guards with `#pragma` once. `#pragma once` is a widely supported preprocessor directive that prevents header files from being included multiple times. It is supported by all toolchains used to build edk2: GCC, Clang/LLVM, and MSVC. Compared to macro-based include guards, `#pragma once`: - Eliminates the risk of macro name collisions or copy/paste errors where two headers inadvertently use the same guard macro. - Eliminate inconsistency in the way include guard macros are named (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.). - Reduces boilerplate (three lines replaced by one). - Avoids polluting the macro namespace with guard symbols. - Can improve build times as the preprocessor can skip re-opening the file entirely, rather than re-reading it to find the matching `#endif` ("multiple-include optimization"). - Note that some compilers may already optimize traditional include guards, by recognzining the idiomatic pattern. This change is made acknowledging that overall portability of the code will technically be reduced, as `#pragma once` is not part of the C/C++ standards. However, this is considered acceptable given: 1. edk2 already defines a subset of supported compilers in BaseTools/Conf/tools_def.template, all of which have supported `#pragma once` for over two decades. 2. There have been concerns raised to the project about inconsistent include guard naming and potential macro collisions. Approximate compiler support dates: - MSVC: Supported since Visual C++ 4.2 (1996) - GCC: Supported since 3.4 (2004) (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html) - Clang (LLVM based): Since initial release in 2007 Signed-off-by: Michael Kubacki --- StandaloneMmPkg/Core/StandaloneMmCore.h | 5 +---- StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h | 5 +---- .../Drivers/MmCommunicationDxe/MmCommunicationDxe.h | 5 +---- .../MmCommunicationNotifyDxe/MmCommunicationNotifyDxe.h | 5 +---- .../Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h | 5 +---- StandaloneMmPkg/Include/Guid/MmFvDispatch.h | 5 +---- StandaloneMmPkg/Include/Guid/MmStatusCodeUseSerial.h | 5 +---- StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h | 5 +---- StandaloneMmPkg/Include/Guid/MpInformation.h | 5 +---- StandaloneMmPkg/Include/Library/MmPlatformHobProducerLib.h | 5 +---- StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h | 5 +---- StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h | 5 +---- StandaloneMmPkg/Include/StandaloneMm.h | 5 +---- .../Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h | 5 +---- 14 files changed, 14 insertions(+), 56 deletions(-) diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.h b/StandaloneMmPkg/Core/StandaloneMmCore.h index da123c530c..ba7266249d 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.h +++ b/StandaloneMmPkg/Core/StandaloneMmCore.h @@ -9,8 +9,7 @@ **/ -#ifndef _MM_CORE_H_ -#define _MM_CORE_H_ +#pragma once #include #include @@ -1025,5 +1024,3 @@ VOID MmFreeShadowedFvs ( VOID ); - -#endif diff --git a/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h b/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h index 03b0261ef0..04dfdbe158 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h +++ b/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h @@ -8,8 +8,7 @@ **/ -#ifndef _STANDALONE_MM_CORE_PRIVATE_DATA_H_ -#define _STANDALONE_MM_CORE_PRIVATE_DATA_H_ +#pragma once // // Page management @@ -54,5 +53,3 @@ typedef struct { } FREE_POOL_HEADER; extern LIST_ENTRY mMmPoolLists[MAX_POOL_INDEX]; - -#endif diff --git a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h index 80d2bfa2b3..58cd5d9ff5 100644 --- a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h +++ b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h @@ -5,8 +5,7 @@ **/ -#ifndef MM_COMMUNICATION_DXE_H_ -#define MM_COMMUNICATION_DXE_H_ +#pragma once #include @@ -138,5 +137,3 @@ MmVirtualAddressChangeEvent ( IN EFI_EVENT Event, IN VOID *Context ); - -#endif diff --git a/StandaloneMmPkg/Drivers/MmCommunicationNotifyDxe/MmCommunicationNotifyDxe.h b/StandaloneMmPkg/Drivers/MmCommunicationNotifyDxe/MmCommunicationNotifyDxe.h index 83391dcabd..a45dad88e6 100644 --- a/StandaloneMmPkg/Drivers/MmCommunicationNotifyDxe/MmCommunicationNotifyDxe.h +++ b/StandaloneMmPkg/Drivers/MmCommunicationNotifyDxe/MmCommunicationNotifyDxe.h @@ -5,8 +5,7 @@ **/ -#ifndef MM_COMMUNICATION_NOTIFY_DXE_H_ -#define MM_COMMUNICATION_NOTIFY_DXE_H_ +#pragma once #include @@ -152,5 +151,3 @@ MmEndOfDxeEventNotify ( IN EFI_EVENT Event, IN VOID *Context ); - -#endif diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h index 430e7c578b..b82363e26f 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h @@ -6,8 +6,7 @@ **/ -#ifndef STANDALONE_MM_IPL_PEI_H_ -#define STANDALONE_MM_IPL_PEI_H_ +#pragma once #include #include @@ -176,5 +175,3 @@ CreateMmHobHandoffInfoTable ( IN EFI_HOB_HANDOFF_INFO_TABLE *Hob, IN VOID *HobEnd ); - -#endif diff --git a/StandaloneMmPkg/Include/Guid/MmFvDispatch.h b/StandaloneMmPkg/Include/Guid/MmFvDispatch.h index 6ddc89bb87..8b773f452c 100644 --- a/StandaloneMmPkg/Include/Guid/MmFvDispatch.h +++ b/StandaloneMmPkg/Include/Guid/MmFvDispatch.h @@ -8,8 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef __MM_FV_DISPATCH_H__ -#define __MM_FV_DISPATCH_H__ +#pragma once #define MM_FV_DISPATCH_GUID \ { 0xb65694cc, 0x9e3, 0x4c3b, { 0xb5, 0xcd, 0x5, 0xf4, 0x4d, 0x3c, 0xdb, 0xff }} @@ -29,5 +28,3 @@ typedef struct { EFI_MM_COMMUNICATE_FV_DISPATCH_DATA Data; } EFI_MM_COMMUNICATE_FV_DISPATCH; #pragma pack() - -#endif diff --git a/StandaloneMmPkg/Include/Guid/MmStatusCodeUseSerial.h b/StandaloneMmPkg/Include/Guid/MmStatusCodeUseSerial.h index 1477b9bda2..bea15c1419 100644 --- a/StandaloneMmPkg/Include/Guid/MmStatusCodeUseSerial.h +++ b/StandaloneMmPkg/Include/Guid/MmStatusCodeUseSerial.h @@ -8,8 +8,7 @@ **/ -#ifndef MM_STATUS_CODE_USE_SERIAL_H_ -#define MM_STATUS_CODE_USE_SERIAL_H_ +#pragma once /// /// The GUID of the StatusCodeUseSerial GUIDed HOB. @@ -31,5 +30,3 @@ typedef struct { } MM_STATUS_CODE_USE_SERIAL; extern EFI_GUID gMmStatusCodeUseSerialHobGuid; - -#endif diff --git a/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h b/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h index 1159d3adcf..4dc89636b9 100644 --- a/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h +++ b/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h @@ -18,8 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef _EFI_MM_PEI_MMRAM_MEMORY_RESERVE_H_ -#define _EFI_MM_PEI_MMRAM_MEMORY_RESERVE_H_ +#pragma once #define EFI_MM_PEI_MMRAM_MEMORY_RESERVE \ { \ @@ -51,5 +50,3 @@ typedef struct { } EFI_MMRAM_HOB_DESCRIPTOR_BLOCK; extern EFI_GUID gEfiMmPeiSmramMemoryReserveGuid; - -#endif diff --git a/StandaloneMmPkg/Include/Guid/MpInformation.h b/StandaloneMmPkg/Include/Guid/MpInformation.h index dbf88d12de..32f8c91d6a 100644 --- a/StandaloneMmPkg/Include/Guid/MpInformation.h +++ b/StandaloneMmPkg/Include/Guid/MpInformation.h @@ -10,8 +10,7 @@ **/ -#ifndef _MP_INFORMATION_H_ -#define _MP_INFORMATION_H_ +#pragma once #include #include @@ -31,5 +30,3 @@ typedef struct { #pragma pack() extern EFI_GUID gMpInformationHobGuid; - -#endif diff --git a/StandaloneMmPkg/Include/Library/MmPlatformHobProducerLib.h b/StandaloneMmPkg/Include/Library/MmPlatformHobProducerLib.h index ec01152e3b..5c4ef329fa 100644 --- a/StandaloneMmPkg/Include/Library/MmPlatformHobProducerLib.h +++ b/StandaloneMmPkg/Include/Library/MmPlatformHobProducerLib.h @@ -10,8 +10,7 @@ **/ -#ifndef MM_PLATFORM_HOB_PRODUCER_LIB_H_ -#define MM_PLATFORM_HOB_PRODUCER_LIB_H_ +#pragma once /** Create the platform specific HOBs needed by the Standalone MM environment. @@ -51,5 +50,3 @@ CreateMmPlatformHob ( IN VOID *Buffer, IN OUT UINTN *BufferSize ); - -#endif diff --git a/StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h b/StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h index 9c48995fd7..383a1fc500 100644 --- a/StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h +++ b/StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h @@ -12,8 +12,7 @@ **/ -#ifndef _MM_MEM_LIB_H_ -#define _MM_MEM_LIB_H_ +#pragma once /** This function check if the buffer is valid per processor architecture and not overlap with MMRAM. @@ -130,5 +129,3 @@ MmSetMem ( IN UINTN Length, IN UINT8 Value ); - -#endif diff --git a/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h b/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h index 5769ac4212..8c6e0709b6 100644 --- a/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h +++ b/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h @@ -9,8 +9,7 @@ **/ -#ifndef MM_CORE_FV_LOCATION_PPI_H_ -#define MM_CORE_FV_LOCATION_PPI_H_ +#pragma once #pragma pack(1) @@ -30,5 +29,3 @@ typedef struct { extern EFI_GUID gMmCoreFvLocationPpiGuid; #pragma pack() - -#endif diff --git a/StandaloneMmPkg/Include/StandaloneMm.h b/StandaloneMmPkg/Include/StandaloneMm.h index 743ab517f9..ba7573d713 100644 --- a/StandaloneMmPkg/Include/StandaloneMm.h +++ b/StandaloneMmPkg/Include/StandaloneMm.h @@ -8,8 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef _STANDALONE_MM_H_ -#define _STANDALONE_MM_H_ +#pragma once #include @@ -31,5 +30,3 @@ VOID // Will remove it once all the code references are removed. // typedef MM_FOUNDATION_ENTRY_POINT STANDALONE_MM_FOUNDATION_ENTRY_POINT; - -#endif diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h index bb3701a3a0..1f58f9bc6f 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h @@ -6,8 +6,7 @@ **/ -#ifndef STANDALONE_MM_MEM_LIB_INTERNAL_H_ -#define STANDALONE_MM_MEM_LIB_INTERNAL_H_ +#pragma once #include @@ -56,5 +55,3 @@ MmMemLibIsValidNonMmramRange ( IN EFI_PHYSICAL_ADDRESS Buffer, IN UINT64 Length ); - -#endif