Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply more idiomatic Rust patterns in RustAdvancedLoggerDxe #498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions AdvLoggerPkg/Crates/RustAdvancedLoggerDxe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern crate std; //allow rustdoc links to reference std (e.g. println docs belo
use core::{
ffi::c_void,
fmt::{self, Write},
ptr,
sync::atomic::{AtomicPtr, Ordering},
};
use r_efi::{
Expand Down Expand Up @@ -78,22 +79,26 @@ struct AdvancedLogger {
impl AdvancedLogger {
// creates a new AdvancedLogger
const fn new() -> Self {
AdvancedLogger { protocol: AtomicPtr::new(core::ptr::null_mut()) }
AdvancedLogger { protocol: AtomicPtr::new(ptr::null_mut()) }
}

// initialize the AdvancedLogger by acquiring a pointer to the AdvancedLogger protocol.
fn init(&self, bs: *mut BootServices) {
let boot_services = unsafe { bs.as_mut().expect("Boot Services Pointer is NULL") };
let mut ptr: *mut c_void = core::ptr::null_mut();
assert!(!bs.is_null(), "BootServices should not be NULL");
let boot_services = unsafe { &mut ptr::read(bs) };

let mut ptr: *mut c_void = ptr::null_mut();

let status = (boot_services.locate_protocol)(
&ADVANCED_LOGGER_PROTOCOL_GUID as *const Guid as *mut Guid,
core::ptr::null_mut(),
core::ptr::addr_of_mut!(ptr),
&ADVANCED_LOGGER_PROTOCOL_GUID as *const _ as *mut _,
ptr::null_mut(),
ptr::addr_of_mut!(ptr),
);
match status {
Status::SUCCESS => self.protocol.store(ptr as *mut AdvancedLoggerProtocol, Ordering::SeqCst),
_ => self.protocol.store(core::ptr::null_mut(), Ordering::SeqCst),
}

self.protocol.store(
if status == Status::SUCCESS { ptr as *mut AdvancedLoggerProtocol } else { ptr::null_mut() },
Ordering::SeqCst,
)
}

// log the debug output in `args` at the given log level.
Expand All @@ -106,9 +111,6 @@ impl AdvancedLogger {
}
}

unsafe impl Sync for AdvancedLogger {}
unsafe impl Send for AdvancedLogger {}

struct LogTransactor<'a> {
protocol: &'a mut AdvancedLoggerProtocol,
level: usize,
Expand Down
6 changes: 5 additions & 1 deletion HidPkg/UefiHidDxe/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ use hidparser::{
ReportDescriptor, ReportField, VariableField,
};
use memoffset::{offset_of, raw_field};
use r_efi::{efi, protocols::absolute_pointer, protocols::driver_binding, system};
use r_efi::{
efi,
protocols::{absolute_pointer, driver_binding},
system,
};
use rust_advanced_logger_dxe::{debugln, DEBUG_INFO, DEBUG_WARN};

use crate::{hid::HidContext, BOOT_SERVICES};
Expand Down
Loading