Skip to content

Commit 26acc20

Browse files
uefi: Convert remaining uses of IpAddress to uefi_raw::IpAddress in pxe::BaseCode
This is an intermediate step towards using the uefi-raw definition of the protocol.
1 parent aac4efe commit 26acc20

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

uefi/src/proto/network/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ impl IpAddress {
4040
// compatible.
4141
self.0.as_ptr().cast()
4242
}
43+
44+
#[must_use]
45+
fn as_raw_ptr_mut(&mut self) -> *mut uefi_raw::IpAddress {
46+
// The uefi-raw type is defined differently, but the layout is
47+
// compatible.
48+
self.0.as_mut_ptr().cast()
49+
}
4350
}
4451

4552
impl From<core::net::Ipv4Addr> for IpAddress {

uefi/src/proto/network/pxe.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ pub struct BaseCode {
6767
udp_read: unsafe extern "efiapi" fn(
6868
this: &Self,
6969
op_flags: UdpOpFlags,
70-
dest_ip: Option<&mut IpAddress>,
70+
dest_ip: *mut uefi_raw::IpAddress,
7171
dest_port: Option<&mut u16>,
72-
src_ip: Option<&mut IpAddress>,
72+
src_ip: *mut uefi_raw::IpAddress,
7373
src_port: Option<&mut u16>,
7474
header_size: Option<&usize>,
7575
header_ptr: *mut c_void,
@@ -519,9 +519,9 @@ impl BaseCode {
519519
(self.udp_read)(
520520
self,
521521
op_flags,
522-
dest_ip,
522+
opt_ip_addr_to_ptr_mut(dest_ip),
523523
dest_port,
524-
src_ip,
524+
opt_ip_addr_to_ptr_mut(src_ip),
525525
src_port,
526526
header_size,
527527
header_ptr,
@@ -641,6 +641,11 @@ fn opt_ip_addr_to_ptr(arg: Option<&IpAddress>) -> *const uefi_raw::IpAddress {
641641
arg.map(|arg| arg.as_raw_ptr()).unwrap_or_else(null)
642642
}
643643

644+
/// Convert an `Option<&mut IpAddress>` to a `*mut uefi_raw::IpAddress`.
645+
fn opt_ip_addr_to_ptr_mut(arg: Option<&mut IpAddress>) -> *mut uefi_raw::IpAddress {
646+
arg.map(|arg| arg.as_raw_ptr_mut()).unwrap_or_else(null_mut)
647+
}
648+
644649
opaque_type! {
645650
/// Opaque type that should be used to represent a pointer to a [`DiscoverInfo`] in
646651
/// foreign function interfaces. This type produces a thin pointer, unlike

0 commit comments

Comments
 (0)