Split C-interface to a new crate

master
WangRunji 7 years ago
parent e56b22fa74
commit 4aac6474f1

@ -3,20 +3,9 @@ name = "simple-filesystem"
version = "0.0.1" version = "0.0.1"
authors = ["WangRunji <wangrunji0408@163.com>"] authors = ["WangRunji <wangrunji0408@163.com>"]
[lib]
#crate-type = ["staticlib"]
[profile.dev]
panic = 'abort' # prevent `_Unwind_Resume` link error
[dependencies] [dependencies]
spin = "0.4"
bit-set = { default-features = false, version = "0.5" } # default-features contains 'std' bit-set = { default-features = false, version = "0.5" } # default-features contains 'std'
static_assertions = "0.2.5" static_assertions = "0.2.5"
[target.ucore.dependencies]
bitflags = "1.0"
[features] [features]
debug_print = [] debug_print = []
ucore = []

@ -1,2 +0,0 @@
[target.ucore.dependencies]
alloc = {}

@ -1,6 +1,6 @@
ucore: ucore:
rustup override set nightly-2018-04-01 rustup override set nightly-2018-04-01
RUST_TARGET_PATH=$(shell pwd) xargo build --target ucore --features ucore RUST_TARGET_PATH=$(shell pwd) xargo build --target ucore --release
install-rust: install-rust:
which cargo || ( curl https://sh.rustup.rs -sSf | sh ) which cargo || ( curl https://sh.rustup.rs -sSf | sh )

@ -0,0 +1,2 @@
[dependencies]
alloc = {}

@ -3,6 +3,18 @@
//! NOTE: Must link these sections: //! NOTE: Must link these sections:
//! `*.got.*` `*.data.*` `*.rodata.*` //! `*.got.*` `*.data.*` `*.rodata.*`
#![feature(allocator_api, global_allocator, lang_items)]
#![feature(alloc)]
#![no_std]
#[macro_use]
extern crate alloc;
extern crate simple_filesystem;
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate static_assertions;
use alloc::{rc::Rc, boxed::Box, BTreeMap}; use alloc::{rc::Rc, boxed::Box, BTreeMap};
use core::cell::RefCell; use core::cell::RefCell;
use core::slice; use core::slice;
@ -11,8 +23,8 @@ use core::cmp::Ordering;
use alloc::heap::{Alloc, AllocErr, Layout}; use alloc::heap::{Alloc, AllocErr, Layout};
use core::mem::{size_of, self}; use core::mem::{size_of, self};
use core::ptr; use core::ptr;
use vfs; use simple_filesystem as sfs;
use blocked_device::BlockedDevice; use simple_filesystem as vfs;
/// Lang items for bare lib /// Lang items for bare lib
mod lang { mod lang {
@ -331,7 +343,7 @@ impl IoBuf {
} }
} }
impl BlockedDevice for Device { impl vfs::BlockedDevice for Device {
fn block_size_log2(&self) -> u8 { fn block_size_log2(&self) -> u8 {
if self.blocksize != 4096 { if self.blocksize != 4096 {
unimplemented!("block_size != 4096 is not supported yet"); unimplemented!("block_size != 4096 is not supported yet");
@ -562,6 +574,9 @@ static FS_OPS: FsOps = {
/// Allocator supported by ucore functions /// Allocator supported by ucore functions
pub struct UcoreAllocator; pub struct UcoreAllocator;
#[global_allocator]
pub static UCORE_ALLOCATOR: UcoreAllocator = UcoreAllocator;
unsafe impl<'a> Alloc for &'a UcoreAllocator { unsafe impl<'a> Alloc for &'a UcoreAllocator {
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> { unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
// cprintf!("alloc %d\n", layout.size()); // cprintf!("alloc %d\n", layout.size());

@ -1,18 +1,13 @@
#![feature(alloc)] #![feature(alloc)]
#![feature(const_fn)] #![feature(const_fn)]
#![cfg_attr(feature = "ucore", feature(allocator_api, global_allocator, lang_items))]
#![no_std] #![no_std]
#[cfg(test)] #[cfg(any(test, feature = "std"))]
#[macro_use] #[macro_use]
extern crate std; extern crate std;
extern crate spin;
#[macro_use] #[macro_use]
extern crate alloc; extern crate alloc;
extern crate bit_set; extern crate bit_set;
#[cfg(feature = "ucore")]
#[macro_use]
extern crate bitflags;
#[macro_use] #[macro_use]
extern crate static_assertions; extern crate static_assertions;
@ -29,15 +24,9 @@ mod blocked_device;
mod vfs; mod vfs;
mod sfs; mod sfs;
mod structs; mod structs;
#[cfg(feature = "ucore")]
pub mod c_interface;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub use sfs::*; pub use sfs::*;
pub use vfs::*; pub use vfs::*;
pub use blocked_device::BlockedDevice; pub use blocked_device::BlockedDevice;
#[cfg(feature = "ucore")]
#[global_allocator]
pub static UCORE_ALLOCATOR: c_interface::UcoreAllocator = c_interface::UcoreAllocator{};

@ -1,4 +1,3 @@
use spin::Mutex;
use bit_set::BitSet; use bit_set::BitSet;
use alloc::{boxed::Box, Vec, BTreeMap, rc::{Rc, Weak}, String}; use alloc::{boxed::Box, Vec, BTreeMap, rc::{Rc, Weak}, String};
use core::cell::{RefCell, RefMut}; use core::cell::{RefCell, RefMut};

Loading…
Cancel
Save