Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arceos posix api #119

Merged
merged 1 commit into from
Sep 6, 2023
Merged

Arceos posix api #119

merged 1 commit into from
Sep 6, 2023

Conversation

coolyjg
Copy link
Contributor

@coolyjg coolyjg commented Aug 30, 2023

  • Add arceos posix_api layer to provide syscall api. This PR finishes work including:
    • Refactor framework: ulib/axlibc -> arceos-posix-api-> arceos modules/crates. Remove axstd dependency in axlibc.
    • Provide syscalls
    • ulib/axlibc should call syscalls to access kernel modules. And re-implemented some libc functions in pure Rust.
  • Syscall IDs are similar to Linux syscall IDs. HOWEVER there are some arceos-specific syscalls (syscall ids exceed 500),
    which are not standard syscall, such as:
    • sys_pthread create (should be sys_clone)
    • sys_open (should be sys_openat)
    • sys_pthread self (should not be a syscall, but it accesses kernel struct).
  • Nonstandard syscalls, like syscalls mentioned above, will be discussed and reconstructed in future work. This PR aims to refactor the framework of current ARCEOS.
  • Things remains TODO:
    • Framework check: is this framework acceptable?
    • More precise debug information: axlibc layer vs arceos_posix_api layer
    • Re-implement more libc functions in Rust.
    • Redundant c to rust binding file in both axlibc and arceos_posix_api.
    • Where to put STDIN/STDOUT and how to handle fd_table with fd = 0, 1, 2.

@equation314
Copy link
Member

  1. I think syscall ID is unnecessary, arceos_posix_api is API compatible rather than ABI compatible. e.g., call sys_pthread_create in pthread_create directly instead of sys_clone.
  2. We should not put any debug info in axlibc (Do you see any debug output from libc?).
  3. May be in next PR.
  4. We can export C structures in arceos_posix_api so that axlibc can access them without C to Rust bindings.
  5. Put stdin/stdout into arceos_posix_api and make sys_read/sys_write with fd 0/1/2 work fine.

@coolyjg
Copy link
Contributor Author

coolyjg commented Sep 1, 2023

Changes:

  1. Remove syscall/syscall_id related code.
  2. Remove c to rust bingdings in axlibc.
  3. Move stdin/stdout to arceos-posix-api layer, remove print_str (call write), keep println_str (use Mutex)
  4. Why change write to ax_write again: I found that if I keep a function named write in rust packages, this package cannot pass cargo test (caused signal: 11, SIGSEGV: invalid memory reference), which fails the unit-test. And relibc encounters the same thing as well. Maybe cargo test uses this write to print messages?

api/arceos_posix_api/cbindgen.toml Outdated Show resolved Hide resolved
api/arceos_posix_api/src/lib.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/lib.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/lib.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/lib.rs Show resolved Hide resolved
api/arceos_posix_api/src/imp/io_ops.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/file.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/task.rs Show resolved Hide resolved
api/arceos_posix_api/src/imp/stdio_imp.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/mod.rs Outdated Show resolved Hide resolved
ulib/axlibc/Cargo.toml Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/task.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/uio.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/sync.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/lib.rs Show resolved Hide resolved
ulib/axlibc/src/sys.rs Outdated Show resolved Hide resolved
ulib/axlibc/Cargo.toml Outdated Show resolved Hide resolved
ulib/axlibc/build.rs Show resolved Hide resolved
ulib/axlibc/src/uio.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/libctypes_gen.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/resource.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/config.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/errno.rs Show resolved Hide resolved
api/arceos_posix_api/src/imp/fd_ops.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/lib.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/io_mpx/mod.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/strftime.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/thread.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/time.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/io_mpx/mod.rs Outdated Show resolved Hide resolved
ulib/axlibc/build.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/stdio.rs Show resolved Hide resolved
api/arceos_posix_api/src/imp/io.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/io.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/io.rs Show resolved Hide resolved
api/arceos_posix_api/src/imp/io.rs Show resolved Hide resolved
api/arceos_posix_api/src/imp/pipe.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/time.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/lib.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/sys.rs Outdated Show resolved Hide resolved
ulib/axlibc/Cargo.toml Outdated Show resolved Hide resolved
ulib/axlibc/Cargo.toml Outdated Show resolved Hide resolved
ulib/axlibc/Cargo.toml Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/fs.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/utils.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/fs.rs Outdated Show resolved Hide resolved
ulib/axlibc/src/io_mpx.rs Outdated Show resolved Hide resolved
@equation314
Copy link
Member

  1. Why change write to ax_write again: I found that if I keep a function named write in rust packages, this package cannot pass cargo test (caused signal: 11, SIGSEGV: invalid memory reference), which fails the unit-test. And relibc encounters the same thing as well. Maybe cargo test uses this write to print messages?

You can add #[cfg(not(test))] above pub unsafe extern "C" fn write to resolve it.

api/arceos_posix_api/src/lib.rs Show resolved Hide resolved
ulib/axlibc/src/lib.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/stdio.rs Outdated Show resolved Hide resolved
api/arceos_posix_api/src/imp/socket.rs Outdated Show resolved Hide resolved
ulib/axlibc/include/fcntl.h Outdated Show resolved Hide resolved
@equation314 equation314 force-pushed the arceos-posix-api branch 2 times, most recently from 03aa776 to 4d89364 Compare September 4, 2023 15:55
@equation314
Copy link
Member

equation314 commented Sep 5, 2023

Good job! Please organize commits.

Thanks for your contribution~

@equation314 equation314 merged commit d4ca91e into arceos-org:main Sep 6, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants