diff --git a/Cargo.lock b/Cargo.lock index 5a1d50d6..4f622ce9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ dependencies = [ "core2", "embedded-graphics", "spin", - "talc 2.1.0", + "talc", ] [[package]] @@ -34,7 +34,7 @@ dependencies = [ "cfg-if", "once_cell", "version_check", - "zerocopy 0.7.32", + "zerocopy", ] [[package]] @@ -104,7 +104,7 @@ dependencies = [ "derive_utils", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -144,7 +144,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.48", + "syn 2.0.65", "which", ] @@ -245,7 +245,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -409,7 +409,7 @@ checksum = "57aaaad9185d3bcb3afe63549d8ba60b2fb0ea8dc2da83f62dd56805edf56fd1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -586,7 +586,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30d2b3721e861707777e3195b0158f950ae6dc4a27e4d02ff9f67e3eb3de199e" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -627,7 +627,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -669,13 +669,13 @@ checksum = "61bb5a1014ce6dfc2a378578509abe775a5aa06bff584a547555d9efdb81b926" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] name = "devfs" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "lock_api", "log", @@ -709,7 +709,7 @@ dependencies = [ "smoltcp", "spin", "vfscore", - "virtio-drivers 0.5.0 (git+https://github.com/rcore-os/virtio-drivers?rev=de1c3b1)", + "virtio-drivers", ] [[package]] @@ -724,7 +724,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.1", + "libloading 0.7.4", ] [[package]] @@ -763,7 +763,7 @@ dependencies = [ "timer", "uart16550", "uart8250", - "virtio-drivers 0.5.0 (git+https://github.com/rcore-os/virtio-drivers?rev=de1c3b1)", + "virtio-drivers", "virtio-net", "visionfive2-sd", ] @@ -816,7 +816,7 @@ checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "dynfs" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "lock_api", "log", @@ -938,7 +938,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fat-vfs" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "fatfs", "lock_api", @@ -1076,7 +1076,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -1336,7 +1336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62a416f1e9fc42c2bf1f171e5be38a8155850fcd390fce300869bcc9d6c9c117" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -1408,6 +1408,19 @@ dependencies = [ "web-sys", ] +[[package]] +name = "int-enum" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a37a9c11c6ecfec8b9bed97337dfecff3686d02ba8f52e8addad2829d047128" +dependencies = [ + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "syn 2.0.65", + "version_check", +] + [[package]] name = "integer-sqrt" version = "0.1.5" @@ -1699,7 +1712,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "loopback" version = "0.1.0" -source = "git+https://github.com/os-module/simple-net#9201deb305a2f93c9914af0d4742d580a9ce9b37" +source = "git+https://github.com/os-module/simple-net#a85df2813f0a9f66f16484641ba3cce0d05e76a4" dependencies = [ "netcore", ] @@ -1742,7 +1755,7 @@ dependencies = [ [[package]] name = "lwext4-vfs" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "bitflags 1.3.2", "embedded-io", @@ -1821,7 +1834,7 @@ dependencies = [ "pager", "platform", "spin", - "talc 4.4.1", + "talc", ] [[package]] @@ -1955,14 +1968,13 @@ dependencies = [ [[package]] name = "netcore" version = "0.1.0" -source = "git+https://github.com/os-module/simple-net#9201deb305a2f93c9914af0d4742d580a9ce9b37" +source = "git+https://github.com/os-module/simple-net#a85df2813f0a9f66f16484641ba3cce0d05e76a4" dependencies = [ "kernel-sync", "log", "preprint", "smoltcp", "spin", - "virtio-drivers 0.5.0 (git+https://github.com/rcore-os/virtio-drivers?rev=de1c3b130e507702f13d142b9bee55670a4a2858)", ] [[package]] @@ -2051,7 +2063,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -2063,15 +2075,9 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] -[[package]] -name = "numeric-enum-macro" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300e4bdb6b46b592948e700ea1ef24a4296491f6a0ee722b258040abd15a3714" - [[package]] name = "objc" version = "0.2.7" @@ -2187,10 +2193,11 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pconst" version = "0.1.0" -source = "git+https://github.com/os-module/pconst.git#fc3c576d8ac476d87af3e417c138739c4b3914c0" +source = "git+https://github.com/os-module/pconst.git#1a376a236849ccddd26d12adcfbc03399de66132" dependencies = [ "bitflags 1.3.2", - "numeric-enum-macro", + "int-enum", + "pod", "syscall-table", ] @@ -2229,7 +2236,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -2287,6 +2294,24 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "pod" +version = "0.1.0" +source = "git+https://github.com/asterinas/pod?rev=d7dba56#d7dba56cc202a10d483b60aba4f734b1f49cb37b" +dependencies = [ + "pod-derive", +] + +[[package]] +name = "pod-derive" +version = "0.1.0" +source = "git+https://github.com/asterinas/pod?rev=d7dba56#d7dba56cc202a10d483b60aba4f734b1f49cb37b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "portable-atomic" version = "1.6.0" @@ -2315,7 +2340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -2385,13 +2410,26 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.65", + "version_check", + "yansi", +] + [[package]] name = "pwd" version = "0.1.0" @@ -2429,7 +2467,7 @@ dependencies = [ [[package]] name = "ramfs" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "lock_api", "log", @@ -2708,7 +2746,7 @@ checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -2991,7 +3029,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -3017,9 +3055,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" dependencies = [ "proc-macro2", "quote", @@ -3053,15 +3091,7 @@ version = "0.1.0" source = "git+https://github.com/os-module/syscall-table.git#8363c7c6619a57580bad6e0a07c4c830ad184f74" dependencies = [ "quote", - "syn 2.0.48", -] - -[[package]] -name = "talc" -version = "2.1.0" -source = "git+https://github.com/SFBdragon/talc?rev=5e478e985472695a1ae9c1ef74931ee20d5a657b#5e478e985472695a1ae9c1ef74931ee20d5a657b" -dependencies = [ - "lock_api", + "syn 2.0.65", ] [[package]] @@ -3112,7 +3142,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -3396,7 +3426,7 @@ checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" [[package]] name = "unifs" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "lock_api", "log", @@ -3527,7 +3557,7 @@ dependencies = [ [[package]] name = "vfscore" version = "0.1.0" -source = "git+https://github.com/os-module/rvfs.git#6ced9655ebf0b75aed0e5693ba0d85f00b9bfcb2" +source = "git+https://github.com/os-module/rvfs.git#478afddaef7f99afaa8f850a8ffe49212c2fca0e" dependencies = [ "bitflags 1.3.2", "downcast-rs", @@ -3546,22 +3576,12 @@ dependencies = [ [[package]] name = "virtio-drivers" -version = "0.5.0" -source = "git+https://github.com/rcore-os/virtio-drivers?rev=de1c3b1#de1c3b130e507702f13d142b9bee55670a4a2858" -dependencies = [ - "bitflags 2.4.2", - "log", - "zerocopy 0.6.6", -] - -[[package]] -name = "virtio-drivers" -version = "0.5.0" -source = "git+https://github.com/rcore-os/virtio-drivers?rev=de1c3b130e507702f13d142b9bee55670a4a2858#de1c3b130e507702f13d142b9bee55670a4a2858" +version = "0.7.2" +source = "git+https://github.com/rcore-os/virtio-drivers#3a9a69c7ae36dd9f9fb393209c59f8dca49009b4" dependencies = [ "bitflags 2.4.2", "log", - "zerocopy 0.6.6", + "zerocopy", ] [[package]] @@ -3572,10 +3592,10 @@ source = "git+https://github.com/os-module/virtio-input-decoder.git#10c726892cb2 [[package]] name = "virtio-net" version = "0.1.0" -source = "git+https://github.com/os-module/simple-net#9201deb305a2f93c9914af0d4742d580a9ce9b37" +source = "git+https://github.com/os-module/simple-net#a85df2813f0a9f66f16484641ba3cce0d05e76a4" dependencies = [ "netcore", - "virtio-drivers 0.5.0 (git+https://github.com/rcore-os/virtio-drivers?rev=de1c3b1)", + "virtio-drivers", ] [[package]] @@ -3631,7 +3651,7 @@ checksum = "6b2b8eecdb8e4284adf5546fc518f048f6dc33e7203dbe36fa93a4add39b31f6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] @@ -3655,7 +3675,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", "wasm-bindgen-shared", ] @@ -3677,7 +3697,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4104,20 +4124,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" [[package]] -name = "zero" -version = "0.1.3" +name = "yansi" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fe21bcc34ca7fe6dd56cc2cb1261ea59d6b93620215aefb5ea6032265527784" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] -name = "zerocopy" -version = "0.6.6" +name = "zero" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6" -dependencies = [ - "byteorder", - "zerocopy-derive 0.6.6", -] +checksum = "2fe21bcc34ca7fe6dd56cc2cb1261ea59d6b93620215aefb5ea6032265527784" [[package]] name = "zerocopy" @@ -4125,18 +4141,8 @@ version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ - "zerocopy-derive 0.7.32", -] - -[[package]] -name = "zerocopy-derive" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", + "byteorder", + "zerocopy-derive", ] [[package]] @@ -4147,7 +4153,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.65", ] [[package]] diff --git a/kernel/src/fs/basic.rs b/kernel/src/fs/basic.rs index b46ec631..8e44b55b 100644 --- a/kernel/src/fs/basic.rs +++ b/kernel/src/fs/basic.rs @@ -44,7 +44,7 @@ pub fn sys_mount( ); let find = vfs::system_support_fs(&fs_type).ok_or(LinuxErrno::EINVAL)?; let path = VfsPath::new(vfs::system_root_fs(), system_root_fs()); - let fs_root = match find.fs_name() { + let fs_root = match find.fs_name().as_str() { name @ ("tmpfs" | "ramfs" | "fat32") => { let fs = vfs::system_support_fs(name).unwrap(); let dev = if name.eq("fat32") { @@ -365,7 +365,7 @@ pub fn sys_writev(fd: usize, iovec: usize, iovcnt: usize) -> AlienResult continue; } let len = iov.len; - let buf = process.transfer_buffer(base, len); + let buf = process.transfer_buffer(base as *mut u8, len); for b in buf.iter() { let r = file.write(b)?; count += r; @@ -394,7 +394,7 @@ pub fn sys_readv(fd: usize, iovec: usize, iovcnt: usize) -> AlienResult { continue; } let len = iov.len; - let mut buf = task.transfer_buffer(base, len); + let mut buf = task.transfer_buffer(base as *mut u8, len); for b in buf.iter_mut() { info!("read file: {:?}, len:{:?}", fd, b.len()); let r = file.read(b)?; diff --git a/kernel/src/fs/control.rs b/kernel/src/fs/control.rs index 9e82c30f..f6a27715 100644 --- a/kernel/src/fs/control.rs +++ b/kernel/src/fs/control.rs @@ -29,7 +29,7 @@ const FD_CLOEXEC: usize = 1; pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> AlienResult { let task = current_task().unwrap(); let file = task.get_file(fd).ok_or(LinuxErrno::EBADF)?; - let cmd = Fcntl64Cmd::try_from(cmd).map_err(|_| LinuxErrno::EINVAL)?; + let cmd = Fcntl64Cmd::try_from(cmd as u32).map_err(|_| LinuxErrno::EINVAL)?; info!("fcntl:{:?} {:?} ", cmd, arg); match cmd { Fcntl64Cmd::F_DUPFD => { diff --git a/kernel/src/ipc/signal.rs b/kernel/src/ipc/signal.rs index dbd3dea3..8bd82444 100644 --- a/kernel/src/ipc/signal.rs +++ b/kernel/src/ipc/signal.rs @@ -41,7 +41,11 @@ pub fn get_signals_from_tid(tid: usize) -> Option>> { pub fn send_signal(tid: usize, signum: usize) { if let Some(signals) = get_signals_from_tid(tid) { // 获取目标线程(可以是自己)的 signals 数组 - warn!("send signal {:?} to {}", SignalNumber::from(signum), tid); + warn!( + "send signal {:?} to {}", + SignalNumber::try_from(signum as u8), + tid + ); signals.lock().try_add_bit(signum); } } @@ -62,7 +66,7 @@ pub fn sigaction(sig: usize, action: usize, old_action: usize) -> isize { let action = action as *const SigAction; let old_action = old_action as *mut SigAction; // check whether sig is valid - let signum = SignalNumber::from(sig); + let signum = SignalNumber::try_from(sig as u8).unwrap(); if signum == SignalNumber::SIGSTOP || signum == SignalNumber::SIGKILL || signum == SignalNumber::ERR @@ -182,7 +186,7 @@ pub fn sigprocmask(how: usize, set: usize, oldset: usize, _sig_set_size: usize) let set_mut = task_inner.transfer_raw_ptr_mut(oldset as *mut usize); *set_mut = signal_receivers.mask.bits(); } - let how = SigProcMaskHow::from(how); + let how = SigProcMaskHow::try_from(how).unwrap(); warn!("sigprocmask: how: {:?}, set: {:x}", how, set); if set != 0 { let set = task_inner.transfer_raw_ptr(set as *const usize); @@ -196,9 +200,6 @@ pub fn sigprocmask(how: usize, set: usize, oldset: usize, _sig_set_size: usize) SigProcMaskHow::SigSetMask => { signal_receivers.mask = SimpleBitSet::from(*set); } - SigProcMaskHow::Unknown => { - return LinuxErrno::EINVAL as isize; - } } } let mask: Vec = signal_receivers.mask.into(); @@ -222,7 +223,11 @@ pub fn sigprocmask(how: usize, set: usize, oldset: usize, _sig_set_size: usize) /// Reference: [kill](https://man7.org/linux/man-pages/man2/kill.2.html) #[syscall_func(129)] pub fn kill(pid: usize, sig: usize) -> isize { - warn!("kill pid {}, signal id {:?}", pid, SignalNumber::from(sig)); + warn!( + "kill pid {}, signal id {:?}", + pid, + SignalNumber::try_from(sig as u8).unwrap() + ); if pid > 0 { //println!("kill pid {}, signal id {}", pid, signal_id); if sig > 0 { @@ -244,7 +249,11 @@ pub fn kill(pid: usize, sig: usize) -> isize { /// Reference: [tkill](https://man7.org/linux/man-pages/man2/tkill.2.html) #[syscall_func(130)] pub fn tkill(tid: usize, sig: usize) -> isize { - warn!("tkill tid {}, signal id {:?}", tid, SignalNumber::from(sig)); + warn!( + "tkill tid {}, signal id {:?}", + tid, + SignalNumber::try_from(sig as u8).unwrap() + ); if tid > 0 && sig > 0 { //println!("kill pid {}, signal id {}", pid, signal_id); send_signal(tid, sig); @@ -292,7 +301,7 @@ pub fn signal_handler() { let handler = task_inner.signal_handlers.clone(); let handler = handler.lock(); if let Some(signum) = receiver.get_one_signal() { - let sig = SignalNumber::from(signum); + let sig = SignalNumber::try_from(signum as u8).unwrap(); error!("task {:?} receive signal {:?}", task.tid, sig); match sig { SignalNumber::SIGSEGV | SignalNumber::SIGBUS => { diff --git a/kernel/src/main.rs b/kernel/src/main.rs index a02509c9..5a14ae80 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -1,5 +1,4 @@ #![feature(atomic_from_mut)] -#![feature(ip_in_core)] #![no_std] #![no_main] diff --git a/kernel/src/mm/map.rs b/kernel/src/mm/map.rs index f4a871c3..60a3ce84 100644 --- a/kernel/src/mm/map.rs +++ b/kernel/src/mm/map.rs @@ -3,7 +3,7 @@ use core::ops::Range; use bitflags::bitflags; use config::{FRAME_SIZE, PROCESS_HEAP_MAX}; -use constants::{io::MapFlags, AlienResult, LinuxErrno}; +use constants::{io::MMapFlags, AlienResult, LinuxErrno}; use page_table::{ addr::{align_up_4k, VirtAddr}, pte::MappingFlags, @@ -58,7 +58,7 @@ pub struct MMapRegion { /// The protection flags of the mapping pub prot: ProtFlags, /// The flags of the mapping - pub flags: MapFlags, + pub flags: MMapFlags, /// The file descriptor to map pub fd: Option>, /// The offset in the file to start from @@ -121,7 +121,7 @@ impl MMapRegion { len: usize, map_len: usize, prot: ProtFlags, - flags: MapFlags, + flags: MMapFlags, fd: Option>, offset: usize, ) -> Self { @@ -152,7 +152,7 @@ impl MMapRegion { pub fn set_prot(&mut self, prot: ProtFlags) { self.prot = prot; } - pub fn set_flags(&mut self, flags: MapFlags) { + pub fn set_flags(&mut self, flags: MMapFlags) { self.flags = flags; } } @@ -174,7 +174,7 @@ pub fn do_munmap(start: usize, len: usize) -> isize { /// + `start`: 所要创建的映射区的起始地址。当该值为0时,内核将自动为其分配一段内存空间创建内存映射。该值在函数运行过程中将被调整为与4K对齐。 /// + `len`: 指明所要创建的映射区的长度。该值在函数运行过程中将被调整为与4K对齐。 /// + `prot`: 指明创建内存映射区的初始保护位。具体可见[`ProtFlags`]。 -/// + `flags`: 指明mmap操作的相关设置。具体可见[`MapFlags`]。 +/// + `flags`: 指明mmap操作的相关设置。具体可见[`MMapFlags`]。 /// + `fd`: 指明要创建内存映射的文件的文件描述符。 /// + `offset`: 将从文件中偏移量为`offset`处开始映射。该值需要和4K对齐。 /// @@ -192,7 +192,7 @@ pub fn do_mmap( let process = current_task().unwrap(); let mut process_inner = process.access_inner(); let prot = ProtFlags::from_bits_truncate(prot); - let flags = MapFlags::from_bits_truncate(flags); + let flags = MMapFlags::from_bits_truncate(flags); warn!( "mmap: start: {:#x}, len: {:#x}, prot: {:?}, flags: {:?}, fd: {}, offset: {:#x}", start, len, prot, flags, fd, offset diff --git a/kernel/src/system.rs b/kernel/src/system.rs index 8c5aeab6..2b3dabc5 100644 --- a/kernel/src/system.rs +++ b/kernel/src/system.rs @@ -2,7 +2,8 @@ use core::cmp::min; use constants::{ - sys::{Rusage, RusageFlag, Sysinfo, SyslogAction, TimeVal}, + sys::{Rusage, RusageFlag, Sysinfo, SyslogAction}, + time::TimeVal, AlienResult, LinuxErrno, }; use syscall_table::syscall_func; @@ -209,7 +210,7 @@ pub fn getrusage(who: isize, usage: usize) -> AlienResult { info!("getrusage: who: {:?}, usage: {}", who, usage); let task = current_task().unwrap(); let static_info = task.access_inner().statistical_data().clone(); - let mut task_usage = Rusage::new(); + let mut task_usage = Rusage::default(); task_usage.ru_utime = TimeVal::from_freq(static_info.tms_utime); task_usage.ru_stime = TimeVal::from_freq(static_info.tms_stime); task.access_inner() diff --git a/kernel/src/task/cpu.rs b/kernel/src/task/cpu.rs index 3d17c24a..017d887c 100644 --- a/kernel/src/task/cpu.rs +++ b/kernel/src/task/cpu.rs @@ -11,7 +11,7 @@ use constants::{ ipc::FutexOp, signal::SignalNumber, task::{CloneFlags, WaitOptions}, - AlienError, AlienResult, PrLimit, PrLimitRes, + AlienError, AlienResult, PrLimitResType, RLimit64, }; use ksync::Mutex; use log::{info, warn}; @@ -266,7 +266,7 @@ pub fn clone(flag: usize, stack: usize, ptid: usize, tls: usize, ctid: usize) -> let clone_flag = CloneFlags::from_bits_truncate(flag as u32); // check whether flag include signal let sig = flag & 0xff; - let sig = SignalNumber::from(sig); + let sig = SignalNumber::try_from(sig as u8).unwrap(); let mut task = current_task().unwrap(); let child_num = task.access_inner().children.len(); @@ -426,23 +426,23 @@ pub fn prlimit64(pid: usize, resource: usize, new_limit: *const u8, old_limit: * assert!(pid == 0 || pid == current_task().unwrap().get_pid() as usize); let task = current_task().unwrap(); let mut inner = task.access_inner(); - if let Ok(resource) = PrLimitRes::try_from(resource) { + if let Ok(resource) = PrLimitResType::try_from(resource) { if !old_limit.is_null() { let limit = inner.get_prlimit(resource); warn!("get rlimit nofile to {:?}", limit); - inner.copy_to_user(&limit, old_limit as *mut PrLimit); + inner.copy_to_user(&limit, old_limit as *mut RLimit64); } match resource { - PrLimitRes::RlimitStack => {} - PrLimitRes::RlimitNofile => { + PrLimitResType::RlimitStack => {} + PrLimitResType::RlimitNofile => { if !new_limit.is_null() { - let mut limit = PrLimit::new(0, 0); - inner.copy_from_user(new_limit as *const PrLimit, &mut limit); + let mut limit = RLimit64::new(0, 0); + inner.copy_from_user(new_limit as *const RLimit64, &mut limit); warn!("set rlimit nofile to {:?}", limit); inner.set_prlimit(resource, limit); } } - PrLimitRes::RlimitAs => {} + PrLimitResType::RlimitAs => {} } } 0 diff --git a/kernel/src/task/task.rs b/kernel/src/task/task.rs index ec3fc55a..388815f1 100644 --- a/kernel/src/task/task.rs +++ b/kernel/src/task/task.rs @@ -20,13 +20,12 @@ use bit_field::BitField; use config::*; use constants::{ aux::*, - io::MapFlags, + io::MMapFlags, ipc::RobustList, signal::{SignalHandlers, SignalNumber, SignalReceivers, SignalUserContext}, - sys::TimeVal, task::CloneFlags, - time::TimerType, - AlienError, AlienResult, LinuxErrno, PrLimit, PrLimitRes, + time::{TimeVal, TimerType}, + AlienError, AlienResult, LinuxErrno, PrLimitResType, RLimit64, }; use gmanager::MinimalManager; use ksync::{Mutex, MutexGuard}; @@ -161,7 +160,7 @@ impl TaskTimer { /// 清除当前的计数器信息,将 timer_remained 置为 0 pub fn clear(&mut self) { self.timer_type = TimerType::NONE; - self.timer_interval = TimeVal::new(); + self.timer_interval = TimeVal::default(); self.timer_remained = 0; self.expired = false; } @@ -172,7 +171,7 @@ impl Default for TaskTimer { fn default() -> Self { Self { timer_type: TimerType::NONE, - timer_interval: TimeVal::new(), + timer_interval: TimeVal::default(), timer_remained: 0, start: 0, expired: false, @@ -546,26 +545,28 @@ impl TaskInner { } /// 获取当前进程对于资源的限制 - pub fn get_prlimit(&self, resource: PrLimitRes) -> PrLimit { + pub fn get_prlimit(&self, resource: PrLimitResType) -> RLimit64 { match resource { - PrLimitRes::RlimitStack => PrLimit::new(USER_STACK_SIZE as u64, USER_STACK_SIZE as u64), - PrLimitRes::RlimitNofile => { + PrLimitResType::RlimitStack => { + RLimit64::new(USER_STACK_SIZE as u64, USER_STACK_SIZE as u64) + } + PrLimitResType::RlimitNofile => { let max_fd = self.fd_table.lock().max(); - PrLimit::new(max_fd as u64, max_fd as u64) + RLimit64::new(max_fd as u64, max_fd as u64) } - PrLimitRes::RlimitAs => PrLimit::new(u64::MAX, u64::MAX), + PrLimitResType::RlimitAs => RLimit64::new(u64::MAX, u64::MAX), } } /// 设置当前进程对于资源的限制 - pub fn set_prlimit(&mut self, resource: PrLimitRes, value: PrLimit) { + pub fn set_prlimit(&mut self, resource: PrLimitResType, value: RLimit64) { match resource { - PrLimitRes::RlimitStack => {} - PrLimitRes::RlimitNofile => { + PrLimitResType::RlimitStack => {} + PrLimitResType::RlimitNofile => { let new_max_fd = value.rlim_cur; self.fd_table.lock().set_max(new_max_fd as usize); } - PrLimitRes::RlimitAs => {} + PrLimitResType::RlimitAs => {} } } @@ -913,7 +914,7 @@ impl TaskInner { } // 到此说明计时器已经到时间了,更新计时器 // 如果是 one-shot 计时器,则 timer_interval_us == 0,这样赋值也恰好是符合语义的 - self.timer.timer_remained = if self.timer.timer_interval == TimeVal::new() { + self.timer.timer_remained = if self.timer.timer_interval == TimeVal::default() { 0 } else { self.timer.start = now; @@ -980,7 +981,7 @@ impl TaskInner { /// + `start`: 所要创建的映射区的起始地址。当该值为0时,内核将自动为其分配一段内存空间创建内存映射。该值在函数运行过程中将被调整为与4K对齐。 /// + `len`: 指明所要创建的映射区的长度。该值在函数运行过程中将被调整为与4K对齐。 /// + `prot`: 指明创建内存映射区的初始保护位。具体可见[`ProtFlags`]。 - /// + `flags`: 指明mmap操作的相关设置。具体可见[`MapFlags`]。 + /// + `flags`: 指明mmap操作的相关设置。具体可见[`MMapFlags`]。 /// + `fd`: 指明要创建内存映射的文件的文件描述符。 /// + `offset`: 将从文件中偏移量为`offset`处开始映射。该值需要和4K对齐。 /// @@ -990,12 +991,12 @@ impl TaskInner { start: usize, len: usize, prot: ProtFlags, - flags: MapFlags, + flags: MMapFlags, fd: usize, offset: usize, ) -> AlienResult { // start == 0 表明需要OS为其找一段内存,而 MAP_FIXED 表明必须 mmap 在固定位置。两者是冲突的 - if start == 0 && flags.contains(MapFlags::MAP_FIXED) { + if start == 0 && flags.contains(MMapFlags::MAP_FIXED) { return Err(LinuxErrno::EINVAL); } @@ -1005,7 +1006,7 @@ impl TaskInner { } // not map to file - let fd = if flags.contains(MapFlags::MAP_ANONYMOUS) { + let fd = if flags.contains(MMapFlags::MAP_ANONYMOUS) { None } else { let file = self @@ -1033,7 +1034,7 @@ impl TaskInner { start = 0x1000; } start..start + len - } else if flags.contains(MapFlags::MAP_FIXED) { + } else if flags.contains(MMapFlags::MAP_FIXED) { let len = align_up_4k(len); if start > self.heap.lock().start { error!("mmap fixed address conflict with heap"); @@ -1296,7 +1297,7 @@ impl TaskInner { AlienError::EAGAIN } else { error!("do_store_page_fault panic :{:#x}", o_addr); - AlienError::ETMP + AlienError::EPERM } })?; // .expect(format!("addr:{:#x}", addr).as_str()); diff --git a/kernel/src/time.rs b/kernel/src/time.rs index 6c0d1b7a..2f000481 100644 --- a/kernel/src/time.rs +++ b/kernel/src/time.rs @@ -11,9 +11,8 @@ //! //! 对于时间片 (每次引发时钟中断的时间间隔) 大小的设计:目前 Alien 中用户态和内核态下采用相同的时间片间隔,1s 内触发 10 次时钟中断。 use constants::{ - sys::TimeVal, - time::{ClockId, TimerType}, - LinuxErrno, + time::{ClockId, TimeVal, TimerType}, + FromUsize, LinuxErrno, }; use log::{info, warn}; use platform::{config::CLOCK_FREQ, set_timer}; @@ -117,7 +116,7 @@ pub fn nanosleep(req: *mut u8, _: *mut u8) -> isize { /// Reference: [clock_get_time](https://www.man7.org/linux/man-pages/man3/clock_gettime.3.html) #[syscall_func(113)] pub fn clock_get_time(clock_id: usize, tp: *mut u8) -> isize { - let id = ClockId::from_raw(clock_id).unwrap(); + let id = ClockId::try_from(clock_id).unwrap(); let task = current_task().unwrap(); match id { ClockId::Monotonic | ClockId::Realtime | ClockId::ProcessCputimeId => { @@ -147,7 +146,7 @@ pub fn getitimer(_which: usize, current_value: usize) -> isize { let timer = &task.access_inner().timer; let itimer = ITimerVal { it_interval: timer.timer_interval, - it_value: timer.timer_remained.into(), + it_value: TimeVal::from_usize(timer.timer_remained), }; task.access_inner() .copy_to_user(&itimer, current_value as *mut ITimerVal); @@ -176,7 +175,7 @@ pub fn setitimer(which: usize, current_value: usize, old_value: usize) -> isize let timer = task.access_inner().get_timer(); let itimer = ITimerVal { it_interval: timer.timer_interval.into(), - it_value: timer.timer_remained.into(), + it_value: TimeVal::from_usize(timer.timer_remained), }; task.access_inner() .copy_to_user(&itimer, old_value as *mut ITimerVal); @@ -196,7 +195,7 @@ pub fn setitimer(which: usize, current_value: usize, old_value: usize) -> isize /// Reference: [clock_getres](https://www.man7.org/linux/man-pages/man3/clock_getres.3.html) #[syscall_func(114)] pub fn clock_getres(id: usize, res: usize) -> isize { - let id = ClockId::from_raw(id).unwrap(); + let id = ClockId::try_from(id).unwrap(); info!("clock_getres: id {:?} ,res {:#x}", id, res); let task = current_task().unwrap(); let time_res = match id { @@ -224,7 +223,7 @@ pub fn clock_getres(id: usize, res: usize) -> isize { #[syscall_func(115)] pub fn clock_nanosleep(clock_id: usize, flags: usize, req: usize, remain: usize) -> isize { const TIMER_ABSTIME: usize = 1; - let id = ClockId::from_raw(clock_id).unwrap(); + let id = ClockId::try_from(clock_id).unwrap(); info!( "clock_nanosleep: id {:?} ,flags {:#x}, req {:#x}, remain {:#x}", id, flags, req, remain diff --git a/kernel/src/trap/mod.rs b/kernel/src/trap/mod.rs index 48c93a51..8e9b9d7c 100644 --- a/kernel/src/trap/mod.rs +++ b/kernel/src/trap/mod.rs @@ -142,7 +142,7 @@ impl TrapHandler for Trap { if err == AlienError::EAGAIN { // println!("thread need wait"); do_suspend(); - } else if err == AlienError::ETMP { + } else if err == AlienError::EPERM { do_exit(-1); } else { send_signal(tid as usize, SignalNumber::SIGSEGV as usize) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index dad58ce0..4dfc2da6 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2023-12-01" +channel = "nightly-2024-05-01" components = ["rust-src", "llvm-tools-preview", "rustfmt", "clippy"] targets = ["riscv64gc-unknown-none-elf"] diff --git a/subsystems/constants/Cargo.toml b/subsystems/constants/Cargo.toml index 1cd1d88b..6d53e5ad 100644 --- a/subsystems/constants/Cargo.toml +++ b/subsystems/constants/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -pconst = { git = "https://github.com/os-module/pconst.git", features = ["trick"] } +pconst = { git = "https://github.com/os-module/pconst.git", features = ["trick"] } \ No newline at end of file diff --git a/subsystems/constants/src/lib.rs b/subsystems/constants/src/lib.rs index 4797a30e..4ab4f7e9 100644 --- a/subsystems/constants/src/lib.rs +++ b/subsystems/constants/src/lib.rs @@ -1,7 +1,9 @@ #![no_std] //! 导出 `pconst` 中的常量和数据结构, 定义Alien OS的错误类型 +use pconst::time::TimeVal; pub use pconst::*; + pub type AlienError = LinuxErrno; pub type AlienResult = Result; @@ -36,3 +38,18 @@ impl From for DeviceId { } pub const AT_FDCWD: isize = -100isize; + +const USEC_PER_SEC: usize = 1000_000; + +pub trait FromUsize { + fn from_usize(value: usize) -> Self; +} + +impl FromUsize for TimeVal { + fn from_usize(value: usize) -> Self { + Self { + tv_sec: value / USEC_PER_SEC, + tv_usec: value % USEC_PER_SEC, + } + } +} diff --git a/subsystems/devices/Cargo.toml b/subsystems/devices/Cargo.toml index bae715de..53f25077 100644 --- a/subsystems/devices/Cargo.toml +++ b/subsystems/devices/Cargo.toml @@ -22,7 +22,7 @@ vfscore = { git = "https://github.com/os-module/rvfs.git", features = [ "linux_error", ] } -virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers",rev = "de1c3b1" } +virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers" } netcore = { git = "https://github.com/os-module/simple-net" } diff --git a/subsystems/drivers/Cargo.toml b/subsystems/drivers/Cargo.toml index 90c3e666..72c0c0a4 100644 --- a/subsystems/drivers/Cargo.toml +++ b/subsystems/drivers/Cargo.toml @@ -19,7 +19,7 @@ shim = { path = "../shim", features = ["lib"] } spin = "0" -virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers",rev = "de1c3b1" } +virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers" } rtc = { git = "https://github.com/os-module/rtc.git" } lru = "0" diff --git a/subsystems/drivers/src/block_device.rs b/subsystems/drivers/src/block_device.rs index 55dce404..c435d11c 100644 --- a/subsystems/drivers/src/block_device.rs +++ b/subsystems/drivers/src/block_device.rs @@ -223,14 +223,14 @@ impl LowBlockDevice for VirtIOBlkWrapper { let res = self .device .lock() - .read_block(block_id, buf) + .read_blocks(block_id, buf) .map_err(|_| LinuxErrno::EIO.into()); res } fn write_block(&self, block_id: usize, buf: &[u8]) -> AlienResult<()> { self.device .lock() - .write_block(block_id, buf) + .write_blocks(block_id, buf) .map_err(|_| LinuxErrno::EIO.into()) } diff --git a/subsystems/knet/src/lib.rs b/subsystems/knet/src/lib.rs index 1a5f6af7..004aed08 100644 --- a/subsystems/knet/src/lib.rs +++ b/subsystems/knet/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(ip_in_core)] extern crate alloc; #[macro_use] diff --git a/subsystems/platform/src/qemu_riscv/config.rs b/subsystems/platform/src/qemu_riscv/config.rs index 5a9937d9..6b1ae780 100644 --- a/subsystems/platform/src/qemu_riscv/config.rs +++ b/subsystems/platform/src/qemu_riscv/config.rs @@ -1,6 +1,6 @@ pub const CLOCK_FREQ: usize = 1250_0000; pub const BLOCK_CACHE_FRAMES: usize = 1024 * 4 * 4; -pub const HEAP_SIZE: usize = 0x30_00000; // (32+6)MB +pub const HEAP_SIZE: usize = 0x40_00000; // (32+6)MB /// qemu的设备地址空间 pub const MMIO: &[(usize, usize)] = &[ diff --git a/subsystems/timer/src/lib.rs b/subsystems/timer/src/lib.rs index 775f569c..492cfd11 100644 --- a/subsystems/timer/src/lib.rs +++ b/subsystems/timer/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] -use constants::sys::TimeVal; +use constants::time::TimeVal; use platform::config::CLOCK_FREQ; use vfscore::utils::VfsTimeSpec; /// 每秒包含的毫秒数 diff --git a/subsystems/vfs/src/lib.rs b/subsystems/vfs/src/lib.rs index 94b0870a..351c522d 100644 --- a/subsystems/vfs/src/lib.rs +++ b/subsystems/vfs/src/lib.rs @@ -143,8 +143,13 @@ pub fn init_filesystem() -> AlienResult<()> { .open(None) .expect("open /dev/sda failed") .inode()?; + + println!("mount fs success XXXXX"); let diskfs_root = diskfs.i_mount(0, "/tests", Some(blk_inode), &[])?; + println!("mount fs success XXXXX"); path.join("tests")?.mount(diskfs_root, 0)?; + println!("mount fs success"); + vfscore::path::print_fs_tree(&mut VfsOutPut, ramfs_root.clone(), "".to_string(), false) .unwrap(); diff --git a/subsystems/vfs/src/proc/filesystem.rs b/subsystems/vfs/src/proc/filesystem.rs index 7803344d..0882a7cc 100644 --- a/subsystems/vfs/src/proc/filesystem.rs +++ b/subsystems/vfs/src/proc/filesystem.rs @@ -29,7 +29,7 @@ impl SystemSupportFS { } else { res.push_str(" "); } - res.push_str(fs.fs_name()); + res.push_str(&fs.fs_name()); res.push_str("\n"); } res diff --git a/user/apps/.cargo/config b/user/apps/.cargo/config.toml similarity index 100% rename from user/apps/.cargo/config rename to user/apps/.cargo/config.toml diff --git a/user/userlib/Cargo.toml b/user/userlib/Cargo.toml index 606d5cf5..d174b22f 100644 --- a/user/userlib/Cargo.toml +++ b/user/userlib/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" core2 = { version = "0.4.0", default-features = false, features = ["alloc", "nightly"] } spin = "0.9.2" bitflags = "1.3.2" -talc = { git = "https://github.com/SFBdragon/talc", rev = "5e478e985472695a1ae9c1ef74931ee20d5a657b" } +talc = "4" embedded-graphics = { version = "0.8", optional = true } diff --git a/user/userlib/src/heap.rs b/user/userlib/src/heap.rs index 586e89c7..df24c4ac 100644 --- a/user/userlib/src/heap.rs +++ b/user/userlib/src/heap.rs @@ -1,4 +1,7 @@ -use core::alloc::{GlobalAlloc, Layout}; +use core::{ + alloc::{GlobalAlloc, Layout}, + sync::atomic::AtomicUsize, +}; use spin::Mutex; use talc::{OomHandler, Span, Talc, Talck}; @@ -8,14 +11,19 @@ use crate::{common::FRAME_SIZE, memory::sbrk}; #[global_allocator] static ALLOCATOR: Talck, MyOomHandler> = Talc::new(MyOomHandler).lock(); +static HEAP_START: AtomicUsize = AtomicUsize::new(0); +static HEAP_END: AtomicUsize = AtomicUsize::new(0); pub fn init_heap() { let heap_began = sbrk(0); let after_alloc = sbrk(0x1000) + 0x1000; // println!("init heap range: {:#x} - {:#x}", heap_began, after_alloc); + HEAP_START.store(heap_began as usize, core::sync::atomic::Ordering::Relaxed); + HEAP_END.store(after_alloc as usize, core::sync::atomic::Ordering::Relaxed); + unsafe { ALLOCATOR - .talc() - .init(Span::new(heap_began as *mut u8, after_alloc as *mut u8)); + .lock() + .claim((Span::new(heap_began as *mut u8, after_alloc as *mut u8))); } } @@ -23,41 +31,22 @@ struct MyOomHandler; impl OomHandler for MyOomHandler { fn handle_oom(talc: &mut Talc, layout: Layout) -> Result<(), ()> { - // alloc doesn't have enough memory, and we just got called! we must free up some memory - // we'll go through an example of how to handle this situation - - // we can inspect `layout` to estimate how much we should free up for this allocation - // or we can extend by any amount (increasing powers of two has good time complexity) - - // this function will be repeatly called until we free up enough memory or - // we return Err(()) causing allocation failure. Be careful to avoid conditions where - // the arena isn't sufficiently extended indefinitely, causing an infinite loop - - // an arbitrary address limit for the sake of example - let size = layout.size(); let size = (size + FRAME_SIZE - 1) / FRAME_SIZE * FRAME_SIZE + 1; // more than 1 frame let alloc_heap = sbrk(size as isize) + size as isize; - // println!("oom occur, alloc_heap: {:#x}", alloc_heap); - let old_arena = talc.get_arena(); - - // we're going to extend the arena upward, doubling its size - // but we'll be sure not to extend past the limit - let new_arena = old_arena - .extend(0, old_arena.size()) - .below(alloc_heap as *mut u8); + let old_end = HEAP_END.load(core::sync::atomic::Ordering::Relaxed); + HEAP_END.store(alloc_heap as usize, core::sync::atomic::Ordering::Relaxed); + let start = HEAP_START.load(core::sync::atomic::Ordering::Relaxed); + let old_heap = Span::new(start as *mut u8, old_end as *mut u8); + let new_heap = Span::new(start as *mut u8, alloc_heap as *mut u8); - if new_arena == old_arena { - // we won't be extending the arena, so we should return Err + let res = unsafe { talc.extend(old_heap, new_heap) }; + if res == old_heap { + // println!("oom failed"); return Err(()); } - unsafe { - // we're assuming the new memory up to ARENA_TOP_LIMIT is allocatable - talc.extend(new_arena); - }; - Ok(()) } }