Add a FrameBuffer::into_buffer method for taking ownership#319
Add a FrameBuffer::into_buffer method for taking ownership#319phil-opp merged 3 commits intorust-osdev:mainfrom
FrameBuffer::into_buffer method for taking ownership#319Conversation
|
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. |
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.