3.3 Additional Steps for Library Instances

3.3.1 Define Produced Library Class

A library instance is always related to a single library class and implements all interfaces defined in the library class. Therefore, the library class name must be specified in the [Defines] section of the library instance INF file as follows:

[Defines]
  LIBRARY_CLASS = UefiDriverEntryPoint|DXE_DRIVER DXE_RUNTIME_DRIVER

In above sample, UefiDriverEntryPoint is the library class name produced by the library instance. In addition, following "DXE_DRIVER DXE_RUNTIME_DRIVER" are the type of modules to the library instance supports.

3.3.2 Define a Library Constructor (Optional)

The library instance module can define a library constructor function that is invoked by the entry point of each linked module. In a library constructor function, some initialization work can be done before any library interface is used:

[Defines]
  ......
  CONSTRUCTOR = HobLibConstructor

3.3.2.1 Types of library constructor functions

There are three types of library constructor functions, according to the different module type of library instance:

  • Library instance in BASE module type:
EFI_STATUS
EFIAPI
BaseConstructor (
VOID
)
  • Library instance in PEIM, PEI_CORE module type:
EFI_STATUS
EFIAPI
PeiServicesTablePointerLibConstructor (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
  • Library instance in DXE_DRIVER, DXE_CORE, DXE_RUNTIME_DRIVER, UEFI_APPLICATION, UEFI_DRIVER module type:
EFI_STATUS
EFIAPI
DxeCorePerformanceLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)

3.3.3 Define a Library Destructor (Optional)

The library instance module can define a library destructor function that is invoked by ExitDriver() for DXE_DRIVER, UEFI_DRIVER etc. In a library destructor function, some un-initialization works can be done.

The destructor function should be declared in an INF file explicitly, as follows:

[Defines]
  ......
  DESTRUCTOR = HobLibDestructor

The prototype of the destructor function is the same as the constructor function mentioned above.

results matching ""

    No results matching ""