Skip to content

Commit 8213aa1

Browse files
committed
update allcator
1 parent 15569c3 commit 8213aa1

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

Cargo.lock

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/allocator/build.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::{env, fs, path::PathBuf};
2+
3+
fn main() {
4+
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("can't find manifest dir"));
5+
let heap_size = env::var("HEAP_SIZE").unwrap_or("0x0180_0000".into());
6+
fs::write(
7+
out_dir.join("consts.rs"),
8+
format!("pub const HEAP_SIZE: usize = {heap_size};"),
9+
)
10+
.expect("can't write data to temp file in the out_dir");
11+
12+
println!("cargo:rerun-if-env-changed=HEAP_SIZE");
13+
println!("cargo:rerun-if-changed=build.rs");
14+
}

crates/allocator/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ extern crate alloc;
55
use buddy_system_allocator::LockedHeap;
66
use log::info;
77

8+
include!(concat!(env!("OUT_DIR"), "/consts.rs"));
9+
810
// 堆大小
9-
const HEAP_SIZE: usize = 0x0180_0000;
11+
// const HEAP_SIZE: usize = 0x0180_0000;
12+
// pub const HEAP_SIZE: usize = 0x0180_0000;
1013

1114
// 堆空间
1215
#[link_section = ".bss.heap"]
@@ -24,9 +27,10 @@ pub fn init() {
2427
.init(HEAP.as_mut_ptr() as usize, HEAP_SIZE);
2528

2629
info!(
27-
"kernel HEAP init: {:#x} - {:#x}",
30+
"kernel HEAP init: {:#x} - {:#x} size: {:#x}",
2831
HEAP.as_ptr() as usize,
29-
HEAP.as_ptr() as usize + HEAP_SIZE
32+
HEAP.as_ptr() as usize + HEAP_SIZE,
33+
HEAP_SIZE
3034
);
3135
}
3236
}

kernel/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ serde = "1.0.136"
1313
serde_derive = "1.0.136"
1414

1515
[dependencies]
16-
allocator = { path = "../crates/allocator" }
16+
allocator = { git = "https://github.com/Byte-OS/allocator.git" }
1717
crate_interface = { git = "https://github.com/Byte-OS/crate_interface.git" }
1818
frame_allocator = { git = "https://github.com/Byte-OS/bit_frame_allocator.git" }
1919
logging = { git = "https://github.com/Byte-OS/logging.git" }

0 commit comments

Comments
 (0)