mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 02:43:24 +00:00
Inject a scalable buddy system allocator to OSTD
Co-authored-by: Zhe Tang <tangzh@stu.pku.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
92bc8cbbf7
commit
5f05963ee5
@ -1,6 +1,8 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#![feature(linkage)]
|
||||
|
||||
extern crate #TARGET_NAME#;
|
||||
|
||||
#[panic_handler]
|
||||
@ -10,3 +12,12 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||
}
|
||||
unsafe { __ostd_panic_handler(info); }
|
||||
}
|
||||
|
||||
use ostd::mm::frame::GlobalFrameAllocator;
|
||||
|
||||
use osdk_frame_allocator::FrameAllocator;
|
||||
static FRAME_ALLOCATOR: FrameAllocator = FrameAllocator;
|
||||
|
||||
#[no_mangle]
|
||||
#[linkage = "weak"]
|
||||
static __GLOBAL_FRAME_ALLOCATOR_REF: &'static dyn GlobalFrameAllocator = &FRAME_ALLOCATOR;
|
||||
|
@ -57,8 +57,8 @@ pub enum BaseCrateType {
|
||||
/// Create a new base crate that will be built by cargo.
|
||||
///
|
||||
/// The dependencies of the base crate will be the target crate. If
|
||||
/// `link_unit_test_runner` is set to true, the base crate will also depend on
|
||||
/// the `ostd-test-runner` crate.
|
||||
/// `link_unit_test_kernel` is set to true, the base crate will also depend on
|
||||
/// the `ostd-test-kernel` crate.
|
||||
///
|
||||
/// It returns the path to the base crate.
|
||||
pub fn new_base_crate(
|
||||
@ -66,7 +66,7 @@ pub fn new_base_crate(
|
||||
base_crate_path_stem: impl AsRef<Path>,
|
||||
dep_crate_name: &str,
|
||||
dep_crate_path: impl AsRef<Path>,
|
||||
link_unit_test_runner: bool,
|
||||
link_unit_test_kernel: bool,
|
||||
) -> PathBuf {
|
||||
let base_crate_path: PathBuf = PathBuf::from(
|
||||
(base_crate_path_stem.as_ref().as_os_str().to_string_lossy()
|
||||
@ -85,7 +85,7 @@ pub fn new_base_crate(
|
||||
&base_crate_tmp_path,
|
||||
dep_crate_name,
|
||||
&dep_crate_path,
|
||||
link_unit_test_runner,
|
||||
link_unit_test_kernel,
|
||||
);
|
||||
let cargo_result = are_files_identical(
|
||||
&base_crate_path.join("Cargo.toml"),
|
||||
@ -105,7 +105,7 @@ pub fn new_base_crate(
|
||||
&base_crate_path,
|
||||
dep_crate_name,
|
||||
dep_crate_path,
|
||||
link_unit_test_runner,
|
||||
link_unit_test_kernel,
|
||||
);
|
||||
|
||||
base_crate_path
|
||||
@ -115,7 +115,7 @@ fn do_new_base_crate(
|
||||
base_crate_path: impl AsRef<Path>,
|
||||
dep_crate_name: &str,
|
||||
dep_crate_path: impl AsRef<Path>,
|
||||
link_unit_test_runner: bool,
|
||||
link_unit_test_kernel: bool,
|
||||
) {
|
||||
let workspace_root = {
|
||||
let meta = get_cargo_metadata(None::<&str>, None::<&[&str]>).unwrap();
|
||||
@ -182,7 +182,7 @@ fn do_new_base_crate(
|
||||
fs::write("src/main.rs", main_rs).unwrap();
|
||||
|
||||
// Add dependencies to the Cargo.toml
|
||||
add_manifest_dependency(dep_crate_name, dep_crate_path, link_unit_test_runner);
|
||||
add_manifest_dependency(dep_crate_name, dep_crate_path, link_unit_test_kernel);
|
||||
|
||||
// Copy the manifest configurations from the target crate to the base crate
|
||||
copy_profile_configurations(workspace_root);
|
||||
@ -197,7 +197,7 @@ fn do_new_base_crate(
|
||||
fn add_manifest_dependency(
|
||||
crate_name: &str,
|
||||
crate_path: impl AsRef<Path>,
|
||||
link_unit_test_runner: bool,
|
||||
link_unit_test_kernel: bool,
|
||||
) {
|
||||
let manifest_path = "Cargo.toml";
|
||||
|
||||
@ -224,31 +224,47 @@ fn add_manifest_dependency(
|
||||
.unwrap();
|
||||
dependencies.as_table_mut().unwrap().extend(target_dep);
|
||||
|
||||
if link_unit_test_runner {
|
||||
let dep_str = match option_env!("OSDK_LOCAL_DEV") {
|
||||
Some("1") => {
|
||||
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let test_kernel_dir = crate_dir.join("deps").join("test-kernel");
|
||||
format!(
|
||||
"osdk-test-kernel = {{ path = \"{}\" }}",
|
||||
test_kernel_dir.display()
|
||||
)
|
||||
}
|
||||
_ => concat!(
|
||||
"osdk-test-kernel = { version = \"",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
"\" }"
|
||||
)
|
||||
.to_owned(),
|
||||
};
|
||||
let test_runner_dep = toml::Table::from_str(&dep_str).unwrap();
|
||||
dependencies.as_table_mut().unwrap().extend(test_runner_dep);
|
||||
if link_unit_test_kernel {
|
||||
add_manifest_dependency_to(
|
||||
dependencies,
|
||||
"osdk-test-kernel",
|
||||
Path::new("deps").join("test-kernel"),
|
||||
);
|
||||
}
|
||||
|
||||
add_manifest_dependency_to(
|
||||
dependencies,
|
||||
"osdk-frame-allocator",
|
||||
Path::new("deps").join("frame-allocator"),
|
||||
);
|
||||
|
||||
add_manifest_dependency_to(dependencies, "ostd", Path::new("..").join("ostd"));
|
||||
|
||||
let content = toml::to_string(&manifest).unwrap();
|
||||
fs::write(manifest_path, content).unwrap();
|
||||
}
|
||||
|
||||
fn add_manifest_dependency_to(manifest: &mut toml::Value, dep_name: &str, path: PathBuf) {
|
||||
let dep_str = match option_env!("OSDK_LOCAL_DEV") {
|
||||
Some("1") => {
|
||||
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let dep_crate_dir = crate_dir.join(path);
|
||||
format!(
|
||||
"{} = {{ path = \"{}\" }}",
|
||||
dep_name,
|
||||
dep_crate_dir.display()
|
||||
)
|
||||
}
|
||||
_ => format!(
|
||||
"{} = {{ version = \"{}\" }}",
|
||||
dep_name,
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
),
|
||||
};
|
||||
let dep_val = toml::Table::from_str(&dep_str).unwrap();
|
||||
manifest.as_table_mut().unwrap().extend(dep_val);
|
||||
}
|
||||
|
||||
fn copy_profile_configurations(workspace_root: impl AsRef<Path>) {
|
||||
let target_manifest_path = workspace_root.as_ref().join("Cargo.toml");
|
||||
let manifest_path = "Cargo.toml";
|
||||
|
Reference in New Issue
Block a user