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:
1
[Defines]
2
LIBRARY_CLASS = UefiDriverEntryPoint|DXE_DRIVER DXE_RUNTIME_DRIVER
Copied!
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:
1
[Defines]
2
......
3
CONSTRUCTOR = HobLibConstructor
Copied!

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:
1
EFI_STATUS
2
EFIAPI
3
BaseConstructor (
4
VOID
5
)
Copied!
  • Library instance in PEIM, PEI_CORE module type:
1
EFI_STATUS
2
EFIAPI
3
PeiServicesTablePointerLibConstructor (
4
IN EFI_PEI_FILE_HANDLE FileHandle,
5
IN CONST EFI_PEI_SERVICES **PeiServices
6
)
Copied!
  • Library instance in DXE_DRIVER, DXE_CORE, DXE_RUNTIME_DRIVER,
    UEFI_APPLICATION, UEFI_DRIVER module type:
1
EFI_STATUS
2
EFIAPI
3
DxeCorePerformanceLibConstructor (
4
IN EFI_HANDLE ImageHandle,
5
IN EFI_SYSTEM_TABLE *SystemTable
6
)
Copied!

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:
1
[Defines]
2
......
3
DESTRUCTOR = HobLibDestructor
Copied!
The prototype of the destructor function is the same as the constructor function mentioned above.