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 <michael.kubacki@microsoft.com>
This commit is contained in:
Michael Kubacki 2026-02-03 14:30:15 -05:00 committed by mergify[bot]
parent 5f2142819f
commit ebcc6affe5
14 changed files with 14 additions and 56 deletions

View file

@ -9,8 +9,7 @@
**/
#ifndef _MM_CORE_H_
#define _MM_CORE_H_
#pragma once
#include <PiMm.h>
#include <StandaloneMm.h>
@ -1025,5 +1024,3 @@ VOID
MmFreeShadowedFvs (
VOID
);
#endif

View file

@ -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

View file

@ -5,8 +5,7 @@
**/
#ifndef MM_COMMUNICATION_DXE_H_
#define MM_COMMUNICATION_DXE_H_
#pragma once
#include <PiDxe.h>
@ -138,5 +137,3 @@ MmVirtualAddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
);
#endif

View file

@ -5,8 +5,7 @@
**/
#ifndef MM_COMMUNICATION_NOTIFY_DXE_H_
#define MM_COMMUNICATION_NOTIFY_DXE_H_
#pragma once
#include <PiDxe.h>
@ -152,5 +151,3 @@ MmEndOfDxeEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
);
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef STANDALONE_MM_IPL_PEI_H_
#define STANDALONE_MM_IPL_PEI_H_
#pragma once
#include <StandaloneMm.h>
#include <Guid/MmCommBuffer.h>
@ -176,5 +175,3 @@ CreateMmHobHandoffInfoTable (
IN EFI_HOB_HANDOFF_INFO_TABLE *Hob,
IN VOID *HobEnd
);
#endif

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -10,8 +10,7 @@
**/
#ifndef _MP_INFORMATION_H_
#define _MP_INFORMATION_H_
#pragma once
#include <Protocol/MpService.h>
#include <PiPei.h>
@ -31,5 +30,3 @@ typedef struct {
#pragma pack()
extern EFI_GUID gMpInformationHobGuid;
#endif

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -8,8 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _STANDALONE_MM_H_
#define _STANDALONE_MM_H_
#pragma once
#include <PiMm.h>
@ -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

View file

@ -6,8 +6,7 @@
**/
#ifndef STANDALONE_MM_MEM_LIB_INTERNAL_H_
#define STANDALONE_MM_MEM_LIB_INTERNAL_H_
#pragma once
#include <PiMm.h>
@ -56,5 +55,3 @@ MmMemLibIsValidNonMmramRange (
IN EFI_PHYSICAL_ADDRESS Buffer,
IN UINT64 Length
);
#endif