Skip to content

Commit a1d02e6

Browse files
authored
Merge pull request #1552 from rust-osdev/bishop-pxe-unsafe
uefi: Mark all function pointers in pxe::BaseCode unsafe
2 parents 8bcd3bb + 75017f6 commit a1d02e6

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

uefi/src/proto/network/pxe.rs

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ pub use uefi_raw::protocol::network::pxe::{
3131
#[allow(clippy::type_complexity)]
3232
pub struct BaseCode {
3333
revision: u64,
34-
start: extern "efiapi" fn(this: &Self, use_ipv6: bool) -> Status,
35-
stop: extern "efiapi" fn(this: &Self) -> Status,
36-
dhcp: extern "efiapi" fn(this: &Self, sort_offers: bool) -> Status,
37-
discover: extern "efiapi" fn(
34+
start: unsafe extern "efiapi" fn(this: &Self, use_ipv6: bool) -> Status,
35+
stop: unsafe extern "efiapi" fn(this: &Self) -> Status,
36+
dhcp: unsafe extern "efiapi" fn(this: &Self, sort_offers: bool) -> Status,
37+
discover: unsafe extern "efiapi" fn(
3838
this: &Self,
3939
ty: BootstrapType,
4040
layer: &mut u16,
@@ -78,26 +78,26 @@ pub struct BaseCode {
7878
buffer_size: &mut usize,
7979
buffer_ptr: *mut c_void,
8080
) -> Status,
81-
set_ip_filter: extern "efiapi" fn(this: &Self, new_filter: &IpFilter) -> Status,
82-
arp: extern "efiapi" fn(
81+
set_ip_filter: unsafe extern "efiapi" fn(this: &Self, new_filter: &IpFilter) -> Status,
82+
arp: unsafe extern "efiapi" fn(
8383
this: &Self,
8484
ip_addr: &IpAddress,
8585
mac_addr: Option<&mut MacAddress>,
8686
) -> Status,
87-
set_parameters: extern "efiapi" fn(
87+
set_parameters: unsafe extern "efiapi" fn(
8888
this: &Self,
8989
new_auto_arp: Option<&bool>,
9090
new_send_guid: Option<&bool>,
9191
new_ttl: Option<&u8>,
9292
new_tos: Option<&u8>,
9393
new_make_callback: Option<&bool>,
9494
) -> Status,
95-
set_station_ip: extern "efiapi" fn(
95+
set_station_ip: unsafe extern "efiapi" fn(
9696
this: &Self,
9797
new_station_ip: Option<&IpAddress>,
9898
new_subnet_mask: Option<&IpAddress>,
9999
) -> Status,
100-
set_packets: extern "efiapi" fn(
100+
set_packets: unsafe extern "efiapi" fn(
101101
this: &Self,
102102
new_dhcp_discover_valid: Option<&bool>,
103103
new_dhcp_ack_received: Option<&bool>,
@@ -118,18 +118,18 @@ pub struct BaseCode {
118118
impl BaseCode {
119119
/// Enables the use of the PXE Base Code Protocol functions.
120120
pub fn start(&mut self, use_ipv6: bool) -> Result {
121-
(self.start)(self, use_ipv6).to_result()
121+
unsafe { (self.start)(self, use_ipv6) }.to_result()
122122
}
123123

124124
/// Disables the use of the PXE Base Code Protocol functions.
125125
pub fn stop(&mut self) -> Result {
126-
(self.stop)(self).to_result()
126+
unsafe { (self.stop)(self) }.to_result()
127127
}
128128

129129
/// Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request /
130130
/// acknowledge) or DHCPv6 S.A.R.R (solicit / advertise / request / reply) sequence.
131131
pub fn dhcp(&mut self, sort_offers: bool) -> Result {
132-
(self.dhcp)(self, sort_offers).to_result()
132+
unsafe { (self.dhcp)(self, sort_offers) }.to_result()
133133
}
134134

135135
/// Attempts to complete the PXE Boot Server and/or boot image discovery
@@ -148,7 +148,7 @@ impl BaseCode {
148148
})
149149
.unwrap_or(null());
150150

151-
(self.discover)(self, ty, layer, use_bis, info).to_result()
151+
unsafe { (self.discover)(self, ty, layer, use_bis, info) }.to_result()
152152
}
153153

154154
/// Returns the size of a file located on a TFTP server.
@@ -537,12 +537,12 @@ impl BaseCode {
537537
/// Updates the IP receive filters of a network device and enables software
538538
/// filtering.
539539
pub fn set_ip_filter(&mut self, new_filter: &IpFilter) -> Result {
540-
(self.set_ip_filter)(self, new_filter).to_result()
540+
unsafe { (self.set_ip_filter)(self, new_filter) }.to_result()
541541
}
542542

543543
/// Uses the ARP protocol to resolve a MAC address.
544544
pub fn arp(&mut self, ip_addr: &IpAddress, mac_addr: Option<&mut MacAddress>) -> Result {
545-
(self.arp)(self, ip_addr, mac_addr).to_result()
545+
unsafe { (self.arp)(self, ip_addr, mac_addr) }.to_result()
546546
}
547547

548548
/// Updates the parameters that affect the operation of the PXE Base Code
@@ -555,14 +555,16 @@ impl BaseCode {
555555
new_tos: Option<u8>,
556556
new_make_callback: Option<bool>,
557557
) -> Result {
558-
(self.set_parameters)(
559-
self,
560-
new_auto_arp.as_ref(),
561-
new_send_guid.as_ref(),
562-
new_ttl.as_ref(),
563-
new_tos.as_ref(),
564-
new_make_callback.as_ref(),
565-
)
558+
unsafe {
559+
(self.set_parameters)(
560+
self,
561+
new_auto_arp.as_ref(),
562+
new_send_guid.as_ref(),
563+
new_ttl.as_ref(),
564+
new_tos.as_ref(),
565+
new_make_callback.as_ref(),
566+
)
567+
}
566568
.to_result()
567569
}
568570

@@ -573,7 +575,7 @@ impl BaseCode {
573575
new_station_ip: Option<&IpAddress>,
574576
new_subnet_mask: Option<&IpAddress>,
575577
) -> Result {
576-
(self.set_station_ip)(self, new_station_ip, new_subnet_mask).to_result()
578+
unsafe { (self.set_station_ip)(self, new_station_ip, new_subnet_mask) }.to_result()
577579
}
578580

579581
/// Updates the contents of the cached DHCP and Discover packets.
@@ -593,21 +595,23 @@ impl BaseCode {
593595
new_pxe_reply: Option<&Packet>,
594596
new_pxe_bis_reply: Option<&Packet>,
595597
) -> Result {
596-
(self.set_packets)(
597-
self,
598-
new_dhcp_discover_valid.as_ref(),
599-
new_dhcp_ack_received.as_ref(),
600-
new_proxy_offer_received.as_ref(),
601-
new_pxe_discover_valid.as_ref(),
602-
new_pxe_reply_received.as_ref(),
603-
new_pxe_bis_reply_received.as_ref(),
604-
new_dhcp_discover,
605-
new_dhcp_ack,
606-
new_proxy_offer,
607-
new_pxe_discover,
608-
new_pxe_reply,
609-
new_pxe_bis_reply,
610-
)
598+
unsafe {
599+
(self.set_packets)(
600+
self,
601+
new_dhcp_discover_valid.as_ref(),
602+
new_dhcp_ack_received.as_ref(),
603+
new_proxy_offer_received.as_ref(),
604+
new_pxe_discover_valid.as_ref(),
605+
new_pxe_reply_received.as_ref(),
606+
new_pxe_bis_reply_received.as_ref(),
607+
new_dhcp_discover,
608+
new_dhcp_ack,
609+
new_proxy_offer,
610+
new_pxe_discover,
611+
new_pxe_reply,
612+
new_pxe_bis_reply,
613+
)
614+
}
611615
.to_result()
612616
}
613617

0 commit comments

Comments
 (0)