Skip to content

Commit

Permalink
remove ruxlibc from ulibc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ken4647 committed Jan 14, 2025
1 parent 59adfc1 commit 6b4a4cc
Show file tree
Hide file tree
Showing 217 changed files with 435 additions and 10,653 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
clippy:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
fail-fast: false
steps:
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
arch: [x86_64, riscv64, aarch64]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
arch: [x86_64]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
doc:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
fail-fast: false
permissions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:

jobs:
unit-test:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -26,7 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-22.04]
arch: [x86_64, riscv64, aarch64]
steps:
- uses: actions/checkout@v3
Expand Down
18 changes: 7 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ members = [
"api/ruxos_posix_api",

"ulib/axstd",
"ulib/ruxlibc",
"ulib/ruxmusl",

"apps/display/basic_painting",
Expand Down
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ V ?=
# App options
A ?= apps/c/helloworld
APP ?= $(A)
FEATURES ?= multitask paging fs
FEATURES ?=
APP_FEATURES ?=

# QEMU options
Expand Down Expand Up @@ -79,7 +79,7 @@ ARGS ?=
ENVS ?=

# Libc options
MUSL ?= n
MUSL ?= y

# App type
ifeq ($(wildcard $(APP)),)
Expand Down Expand Up @@ -250,9 +250,6 @@ doc_check_missing:
fmt:
cargo fmt --all

fmt_c:
@clang-format --style=file -i $(shell find ulib/ruxlibc -iname '*.c' -o -iname '*.h')

test:
$(call app_test)

Expand All @@ -274,12 +271,11 @@ clean: clean_c clean_musl
cargo clean

clean_c::
rm -rf ulib/ruxlibc/build_*
rm -rf $(app-objs)

clean_musl:
rm -rf ulib/ruxmusl/build_*
rm -rf ulib/ruxmusl/install

.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c\
.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean \
clean_musl doc disk_image debug_no_attach prebuild _force
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The currently supported applications and programming languages, as well as their

| Language | Description |
|- | - |
| C | Run C apps by RuxOS ruxlibc or standard musl libc supported by ruxmusl. Evaluated by libc-bench. |
| C | Run C apps by standard musl libc supported by ruxmusl. Evaluated by libc-bench. |
| C++ | Run C++ apps by c++ static library provided by musl libc. Passed c++ benchmark. Evaluated by c++ benchmark. |
| [Perl](https://github.com/syswonder/rux-perl) | Run Perl standard library by musl libc. Evaluated by Perl benchmark. |
| [Python](https://github.com/syswonder/rux-python3) | Run Python apps by dynamically loading Python modules. Evaluated by Python benchmark. |
Expand Down
2 changes: 2 additions & 0 deletions api/arceos_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ myfs = ["ruxfeat/myfs"]
dummy-if-not-enabled = []

[dependencies]
crate_interface = "0.1.1"
ruxfeat = { path = "../ruxfeat" }
ruxruntime = { path = "../../modules/ruxruntime" }
ruxconfig = { path = "../../modules/ruxconfig" }
ruxmm = {path = "../../modules/ruxmm"}
axlog = { path = "../../modules/axlog" }
axio = { path = "../../crates/axio" }
axerrno = { path = "../../crates/axerrno" }
Expand Down
2 changes: 2 additions & 0 deletions api/arceos_api/src/imp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

mod mem;
mod task;
#[cfg(feature = "paging")]
mod trap;

cfg_fs! {
mod fs;
Expand Down
15 changes: 8 additions & 7 deletions ulib/ruxlibc/src/utils.rs → api/arceos_api/src/imp/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
* See the Mulan PSL v2 for more details.
*/

use core::ffi::c_int;
use ruxhal::trap::{PageFaultCause, TrapHandler};

pub fn e(ret: c_int) -> c_int {
if ret < 0 {
crate::errno::set_errno(ret.abs());
-1
} else {
ret as _
struct TrapHandlerImpl;

#[crate_interface::impl_interface]
impl TrapHandler for TrapHandlerImpl {
fn handle_page_fault(vaddr: usize, cause: PageFaultCause) -> bool {
// TODO: handle page fault
panic!("Page fault at {:#x} with cause {:?}.", vaddr, cause);
}
}
2 changes: 1 addition & 1 deletion api/ruxos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ruxfdtable = { path = "../../modules/ruxfdtable" }
ruxmm = { path = "../../modules/ruxmm", optional = true }
ruxfutex = { path = "../../modules/ruxfutex", optional = true }
axalloc = { path = "../../modules/axalloc", optional = true }
ruxtask = { path = "../../modules/ruxtask", optional = true }
ruxtask = { path = "../../modules/ruxtask", features = ["notest"], optional = true }
ruxfs = { path = "../../modules/ruxfs", optional = true }
ruxnet = { path = "../../modules/ruxnet", optional = true }

Expand Down
6 changes: 3 additions & 3 deletions api/ruxos_posix_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ typedef struct {{

let mut builder = bindgen::Builder::default()
.header(in_file)
.clang_arg("-I./../../ulib/ruxlibc/include")
.clang_arg("-I./../../ulib/include")
.parse_callbacks(Box::new(MyCallbacks))
.derive_default(true)
.size_t_is_usize(false)
Expand All @@ -167,7 +167,7 @@ typedef struct {{
.expect("Couldn't write bindings!");
}

gen_pthread_mutex("../../ulib/ruxlibc/include/ax_pthread_mutex.h").unwrap();
gen_pthread_cond("../../ulib/ruxlibc/include/ax_pthread_cond.h").unwrap();
gen_pthread_mutex("../../ulib/include/ax_pthread_mutex.h").unwrap();
gen_pthread_cond("../../ulib/include/ax_pthread_cond.h").unwrap();
gen_c_to_rust_bindings("ctypes.h", "src/ctypes_gen.rs");
}
2 changes: 1 addition & 1 deletion api/ruxos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct InitFsImpl;

#[crate_interface::impl_interface]
impl ruxtask::fs::InitFs for InitFsImpl {
fn init(fs: &mut ruxtask::fs::FileSystem) {
fn add_stdios_to_fd_table(fs: &mut ruxtask::fs::FileSystem) {
debug!("init initial process's fd_table");
let fd_table = &mut fs.fd_table;
fd_table.add_at(0, Arc::new(stdin()) as _).unwrap(); // stdin
Expand Down
2 changes: 1 addition & 1 deletion api/ruxos_posix_api/src/imp/mmap/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ pub fn sys_msync(start: *mut c_void, len: ctypes::size_t, flags: c_int) -> c_int
for (&vaddr, page_info) in current().mm.mem_map.lock().range(start..end) {
if let Some(FileInfo { file, offset, size }) = &page_info.mapping_file {
let src = vaddr as *mut u8;
write_into(&file, src, *offset as u64, *size);
write_into(file, src, *offset as u64, *size);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions api/ruxos_posix_api/src/imp/mmap/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ impl ruxhal::trap::TrapHandler for TrapHandlerImpl {
dst.copy_from(vaddr as *mut u8, size);
}
let paddr = direct_virt_to_phys(fake_vaddr);
let mapping_file = memory_map.get(&vaddr.into()).unwrap().mapping_file.clone();
memory_map.remove(&vaddr.into());
let mapping_file = memory_map.get(&vaddr).unwrap().mapping_file.clone();
memory_map.remove(&vaddr);
memory_map.insert(
vaddr.into(),
vaddr,
Arc::new(PageInfo {
paddr,
#[cfg(feature = "fs")]
Expand Down
21 changes: 3 additions & 18 deletions api/ruxos_posix_api/src/imp/mmap/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub(crate) fn release_pages_mapped(start: usize, end: usize) {
#[cfg(feature = "fs")]
if let Some(FileInfo { file, offset, size }) = &page_info.mapping_file {
let src = vaddr as *mut u8;
write_into(&file, src, *offset as u64, *size);
write_into(file, src, *offset as u64, *size);
}
if pte_unmap_page(VirtAddr::from(vaddr)).is_err() {
panic!("Release page failed when munmapping!");
Expand Down Expand Up @@ -294,7 +294,7 @@ pub(crate) fn shift_mapped_page(start: usize, end: usize, vma_offset: usize, cop

used_fs! {
let mut opt_buffer = Vec::new();
for (&start, &ref off_in_swap) in swaped_map.range(start..end) {
for (&start, off_in_swap) in swaped_map.range(start..end) {
opt_buffer.push((start, off_in_swap.clone()));
}
for (start, swap_info) in opt_buffer {
Expand Down Expand Up @@ -334,7 +334,7 @@ pub(crate) fn preload_page_with_swap(
// For file mapping, the mapped content will be written directly to the original file.
Some(FileInfo { file, offset, size }) => {
let offset = *offset as u64;
write_into(&file, vaddr_swapped as *mut u8, offset, *size);
write_into(file, vaddr_swapped as *mut u8, offset, *size);
pte_swap_preload(VirtAddr::from(vaddr_swapped)).unwrap()
}
// For anonymous mapping, you need to save the mapped memory to the prepared swap file,
Expand All @@ -354,21 +354,6 @@ pub(crate) fn preload_page_with_swap(
}
}
}
// For anonymous mapping, you need to save the mapped memory to the prepared swap file,
// and record the memory address and its offset in the swap file.
// Some((vaddr_swapped, PageInfo{paddr:_, mapping_file:Some(FileInfo{file, offset, size})})) => {
// let offset_get = off_pool.pop();
// let offset = offset_get.unwrap();
// swaped_map.insert(vaddr_swapped, Arc::new(offset));

// write_into(
// &SWAP_FILE,
// vaddr_swapped as *mut u8,
// offset as u64,
// PAGE_SIZE_4K,
// );
// pte_swap_preload(VirtAddr::from(vaddr_swapped)).unwrap()
// }
_ => panic!("No memory for mmap, check if huge memory leaky exists"),
},

Expand Down
1 change: 0 additions & 1 deletion api/ruxos_posix_api/src/imp/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ impl Pipe {

pub fn write_end_close(&self) -> bool {
let write_end_count = Arc::weak_count(&self.buffer);
// error!("Pipe::write_end_close <= buffer: {:#?} {:#?}", write_end_count, Arc::as_ptr(&self.buffer));
write_end_count == 0
}
}
Expand Down
57 changes: 53 additions & 4 deletions api/ruxos_posix_api/src/imp/pthread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@ unsafe impl<T> Send for ForceSendSync<T> {}
unsafe impl<T> Sync for ForceSendSync<T> {}

/// Create new thread by `sys_clone`, return new thread ID
#[cfg(all(
feature = "musl",
any(target_arch = "aarch64", target_arch = "riscv64")
))]
#[cfg(all(feature = "musl", target_arch = "aarch64"))]
pub unsafe fn sys_clone(
flags: c_int,
stack: *mut c_void,
Expand Down Expand Up @@ -332,6 +329,58 @@ pub unsafe fn sys_clone(
})
}

/// Create new thread by `sys_clone`, return new thread ID
#[cfg(all(feature = "musl", target_arch = "riscv64"))]
pub unsafe fn sys_clone(
flags: c_int,
stack: *mut c_void,
ptid: *mut ctypes::pid_t,
tls: *mut c_void,
ctid: *mut ctypes::pid_t,
) -> c_int {
debug!(
"sys_clone <= flags: {:x}, stack: {:p}, ctid: {:x}",
flags, stack, ctid as usize
);

syscall_body!(sys_clone, {
if (flags as u32 & ctypes::CLONE_THREAD) != 0 {
let func = unsafe {
core::mem::transmute::<*const (), extern "C" fn(arg: *mut c_void) -> *mut c_void>(
(*(stack as *mut usize)) as *const (),
)
};
let args = unsafe { *((stack as usize + 8) as *mut usize) } as *mut c_void;

let set_tid = if (flags as u32 & ctypes::CLONE_CHILD_SETTID) != 0 {
core::sync::atomic::AtomicU64::new(ctid as _)
} else {
core::sync::atomic::AtomicU64::new(0)
};

let (tid, task_inner) = Pthread::pcreate(
core::ptr::null(),
func,
args,
tls,
set_tid,
core::sync::atomic::AtomicU64::from(ctid as u64),
)?;

// write tid to ptid
if (flags as u32 & ctypes::CLONE_PARENT_SETTID) != 0 {
unsafe { *ptid = tid as c_int };
}
ruxtask::put_task(task_inner);

return Ok(tid);
} else {
debug!("ONLY support CLONE_THREAD and SIGCHLD");
return Err(LinuxError::EINVAL);
}
})
}

/// Create new thread by `sys_clone`, return new thread ID
#[cfg(all(feature = "musl", target_arch = "x86_64"))]
pub unsafe fn sys_clone(
Expand Down
Loading

0 comments on commit 6b4a4cc

Please sign in to comment.