Skip to content

Commit

Permalink
Merge pull request #12 from csssuf/devpath-fixes
Browse files Browse the repository at this point in the history
protocol/device_path: A few small fixups/additions
  • Loading branch information
csssuf authored Jun 30, 2017
2 parents 9641c4b + fed5e56 commit f2f0375
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/protocol/device_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ impl DevicePathFromTextProtocol {
str_to_utf16_ptr(path)
.map(|utf16_str| {
let out = unsafe { &*((self.text_to_device_path_node)(utf16_str)) };
::get_system_table().boot_services().free_pool(utf16_str);
// FIXME(csssuf)
// Ideally, at this point, we'd free utf16_str. However, free_pool(utf16_str) seems
// to hang here for unknown reasons. So we leak it.
out
})
}
Expand All @@ -267,7 +269,9 @@ impl DevicePathFromTextProtocol {
str_to_utf16_ptr(path)
.map(|utf16_str| {
let out = unsafe { &*((self.text_to_device_path)(utf16_str)) };
::get_system_table().boot_services().free_pool(utf16_str);
// FIXME(csssuf)
// Ideally, at this point, we'd free utf16_str. However, free_pool(utf16_str) seems
// to hang here for unknown reasons. So we leak it.
out
})
}
Expand All @@ -278,7 +282,7 @@ pub struct DevicePathUtilitiesProtocol {
get_device_path_size: *const CVoid,
duplicate_device_path: *const CVoid,
append_device_path: unsafe extern "win64" fn(src1: *const DevicePathProtocol, src2: *const DevicePathProtocol) -> *const DevicePathProtocol,
append_device_node: *const CVoid,
append_device_node: unsafe extern "win64" fn(path: *const DevicePathProtocol, node: *const DevicePathProtocol) -> *const DevicePathProtocol,
append_device_path_instance: *const CVoid,
get_next_device_path_instance: *const CVoid,
is_device_path_multi_instance: *const CVoid,
Expand All @@ -296,7 +300,23 @@ impl DevicePathUtilitiesProtocol {
unsafe {
let out = (self.append_device_path)(src1, src2);
if out == 0 as *const DevicePathProtocol {
return Err(Status::InvalidParameter);
// `out` being a null pointer indicates, according to the spec, that "memory could
// not be allocate[sic]." Whether that's due to memory conditions, bad parameters
// being passed in, or another reason is unspecified. Unless the caller passes in
// a massive DevicePathProtocol, it's unlikely that it's due to the actual
// parameters, so error here is represented as OutOfResources.
return Err(Status::OutOfResources);
}
Ok(out)
}
}

pub fn append_device_node(&self, path: *const DevicePathProtocol, node: *const DevicePathProtocol) -> Result<*const DevicePathProtocol, Status> {
unsafe {
let out = (self.append_device_node)(path, node);
if out == 0 as *const DevicePathProtocol {
// See comment in append_device_path.
return Err(Status::OutOfResources);
}
Ok(out)
}
Expand Down

0 comments on commit f2f0375

Please sign in to comment.