xref: /aosp_15_r20/bootable/libbootloader/gbl/libefi/src/protocol/loaded_image.rs (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Rust wrapper for `EFI_LOADED_IMAGE_PROTOCOL`.
16 
17 use crate::protocol::{Protocol, ProtocolInfo};
18 use crate::DeviceHandle;
19 use efi_types::{EfiGuid, EfiLoadedImageProtocol};
20 use liberror::Result;
21 
22 /// EFI_LOADED_IMAGE_PROTOCOL
23 pub struct LoadedImageProtocol;
24 
25 impl ProtocolInfo for LoadedImageProtocol {
26     type InterfaceType = EfiLoadedImageProtocol;
27 
28     const GUID: EfiGuid =
29         EfiGuid::new(0x5b1b31a1, 0x9562, 0x11d2, [0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b]);
30 }
31 
32 impl<'a> Protocol<'a, LoadedImageProtocol> {
33     /// Wraps `EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle`.
device_handle(&self) -> Result<DeviceHandle>34     pub fn device_handle(&self) -> Result<DeviceHandle> {
35         Ok(DeviceHandle(self.interface()?.device_handle))
36     }
37 }
38