Giter Club home page Giter Club logo

rust-multiboot's Introduction

Multiboot Crates.io Build

This is a multiboot (v1) library written entirely in rust. The code depends only on libcore.

How-to use

extern crate core;

use multiboot::information::{MemoryManagement, Multiboot, PAddr};
use core::{slice, mem};

struct Mem;

impl MemoryManagement for Mem {
    unsafe fn paddr_to_slice(&self, addr: PAddr, size: usize) -> Option<&'static [u8]> {
        let ptr = mem::transmute(addr);
        Some(slice::from_raw_parts(ptr, size))
    }
    
    // If you only want to read fields, you can simply return `None`.
    unsafe fn allocate(&mut self, _length: usize) -> Option<(PAddr, &mut [u8])> {
        None
    }
    
    unsafe fn deallocate(&mut self, addr: PAddr) {
        if addr != 0 {
            unimplemented!()
        }
    }
}

static mut MEM: Mem = Mem;

/// mboot_ptr is the initial pointer to the multiboot structure
/// provided in %ebx on start-up.
pub fn use_multiboot(mboot_ptr: PAddr) -> Option<Multiboot<'static, 'static>> {
    unsafe {
        Multiboot::from_ptr(mboot_ptr, &mut MEM)
    }
}

Functionality is still not complete and patches are welcome!

Documentation

rust-multiboot's People

Contributors

adriandanis avatar dependabot[bot] avatar dschatzberg avatar gz avatar paulcacheux avatar sduverger avatar ytvwld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rust-multiboot's Issues

Adding feature about Elf Sections

Hi, I would be interested in accessing the elf sections, as is possible with the multiboot2 crate (https://crates.io/crates/multiboot2), through this crate.
I can see multiple options to build this:

There is also the problem of the Memory Management trait: can you confirm that the addr: u32 field of ElfSymbols is actually a Virtual Address and thus needs to be converted through the current MemoryManagement ?

32bit Addresses

From the PAddr type, I originally assumed that this crate only works on 64bit. But it also seems to work in my 32bit OS if the pointers are cast correctly.
So maybe it would be a good idea to change the numeric pointer types to usize instead of u64 as using 64bit values on 32bit architectures is costly.

PS: I don't know if size_of::<*const ()>() == size_of::<usize>() is guaranteed on every architecture. In any case, a compile-time check may be helpful:

const _: () = assert!(size_of::<*const ()>() == size_of::<PAddr>());

Functionality missing for using this in bootloaders

I'm planning on writing a Multiboot compatible bootloader and stumbled across this crate.

It looks really nice, but it currently just has functionality to use it in a kernel for parsing the Multiboot information passed by the bootloader.
Would you be willing to merge changes adding the missing functionality (I'm mainly thinking about a new Header type and Multiboot::empty and setters for the various information) or am I better off creating a new crate for that?

Release unaligned_references fixes

Upgrading the compiler version used by hermitcore/libhermit-rs, I get the following warning:

warning: the following packages contain code that will be rejected by a future version of Rust: multiboot v0.7.0
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 2`
$ cargo report future-incompatibilities --id 2
The following warnings were discovered during the build. These warnings are an
indication that the packages contain code that will become an error in a
future release of Rust. These warnings typically cover changes to close
soundness problems, unintended or undocumented behavior, or critical problems
that cannot be fixed in a backwards-compatible fashion, and are not expected
to be in wide use.

Each warning should contain a link for more information on what the warning
means and how to resolve it.


To solve this problem, you can try the following approaches:


- If the issue is not solved by updating the dependencies, a fix has to be
implemented by those dependencies. You can help with that by notifying the
maintainers of this problem (e.g. by creating a bug report) or by proposing a
fix to the maintainers (e.g. by creating a pull request):

  - multiboot:0.7.0
  - Repository: https://github.com/gz/rust-multiboot
  - Detailed warning command: `cargo report future-incompatibilities --id 2 --package multiboot:0.7.0`

- If waiting for an upstream fix is not an option, you can use the `[patch]`
section in `Cargo.toml` to use your own version of the dependency. For more
information, see:
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section

The package `multiboot v0.7.0` currently triggers the following future incompatibility lints:
> warning: reference to packed field is unaligned
>    --> /home/mkroening/.cargo/registry/src/github.com-1ecc6299db9ec823/multiboot-0.7.0/src/information.rs:676:17
>     |
> 676 |                 self.size, self.base_addr, self.length, self.mtype
>     |                 ^^^^^^^^^
>     |
>     = note: `#[allow(unaligned_references)]` on by default
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> warning: reference to packed field is unaligned
>    --> /home/mkroening/.cargo/registry/src/github.com-1ecc6299db9ec823/multiboot-0.7.0/src/information.rs:676:28
>     |
> 676 |                 self.size, self.base_addr, self.length, self.mtype
>     |                            ^^^^^^^^^^^^^^
>     |
>     = note: `#[allow(unaligned_references)]` on by default
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> warning: reference to packed field is unaligned
>    --> /home/mkroening/.cargo/registry/src/github.com-1ecc6299db9ec823/multiboot-0.7.0/src/information.rs:676:44
>     |
> 676 |                 self.size, self.base_addr, self.length, self.mtype
>     |                                            ^^^^^^^^^^^
>     |
>     = note: `#[allow(unaligned_references)]` on by default
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> warning: reference to packed field is unaligned
>    --> /home/mkroening/.cargo/registry/src/github.com-1ecc6299db9ec823/multiboot-0.7.0/src/information.rs:676:57
>     |
> 676 |                 self.size, self.base_addr, self.length, self.mtype
>     |                                                         ^^^^^^^^^^
>     |
>     = note: `#[allow(unaligned_references)]` on by default
>     = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>     = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
>     = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
>     = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
>     = note: this warning originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
>

The issues seem to be fixed already and just need to be released. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.