-
Notifications
You must be signed in to change notification settings - Fork 214
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
Add a FrameBuffer::into_buffer
method for taking ownership
#319
Conversation
This is unsound: Decoupling the lifetime of the // Get two mutable references to the same buffer.
let buffer1 = frame_buffer.buffer_mut();
let buffer2 = frame_buffer.buffer_mut();
// Access the first buffer.
// This shouldn't compile. Calling `buffer_mut` the second time should invalidate the lifetime of `buffer1`.
buffer1[0] = 0; |
So, how can we fix my issue? |
With these changes, the methods basically already use We could add |
// kernel/src/main.rs #![no_std] use core::panic::PanicInfo; pub static BOOTLOADER_CONFIG: BootloaderConfig = { entry_point!(main, config = &BOOTLOADER_CONFIG); fn main(bootinfo: &'static mut BootInfo) -> ! { #[panic_handler] |
// kernel/src/lib.rs pub mod logger; use bootloader_api::info::FrameBufferInfo; pub fn init_logger(framebuffer: &'static mut [u8], info: FrameBufferInfo) { |
// kernel/src/logger.rs use bootloader_api::info::{FrameBufferInfo, PixelFormat}; /// The global logger instance used for the /// A [ /// Additional vertical space between lines /// Padding from the border. Prevent that font is too close to border. /// Constants for the usage of the [
} /// Returns the raster of the given char or the raster of [ impl LockedLogger {
} impl log::Log for LockedLogger {
} /// Allows logging text to a pixel-based framebuffer. impl Logger {
} unsafe impl Send for Logger {} impl fmt::Write for Logger { |
Sorry for the formatting. |
Ok, so to fix that, we could either add the |
The first option, will do the same that my change, I think. |
The difference is that |
OK, thanks! I will create a commit for fixing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
FrameBuffer::into_buffer
method for taking ownership
Hello,
I had a problem related to lifetimes when I was adding support for the logger in my kernel. I got E0597. Framebuffer must outlive 'static. This was strange for me because the logger code is same that is in the bootloader. But I noticed that the methods buffer() and buffer_mut don't use any lifetime.
With this lifetime annotation in the both methods it works.
Thanks.