Implemented riscv64 syscall support

Besides, this commit also contains the following changes:

1. Added build suffix to musl to distinguish archs and modes.

2. Implemented prebuild hook so that opensbi would be cloned
    while building under riscv64.

3. Fixed boot page table in riscv64 so that dtb won't cause
    a page fault.

4. Updated github CI under riscv64.
This commit is contained in:
Sssssaltyfish 2024-03-16 03:27:45 +08:00
parent 34d4927177
commit 92b6335db0
20 changed files with 592 additions and 32 deletions

View File

@ -47,6 +47,12 @@ jobs:
crate: cargo-binutils
version: latest
use-tool-cache: true
# musl toolchain is also needed in non-musl apps
# because we need to build opensbi under riscv64
- uses: ./.github/workflows/actions/setup-musl
with:
arch: ${{ matrix.arch }}
- name: Build display/basic_painting
run: make ARCH=${{ matrix.arch }} A=apps/display/basic_painting
- name: Build display/draw_map
@ -54,9 +60,6 @@ jobs:
- name: Build fs/shell
run: make ARCH=${{ matrix.arch }} A=apps/fs/shell
- uses: ./.github/workflows/actions/setup-musl
with:
arch: ${{ matrix.arch }}
- name: Build c/helloworld
run: make ARCH=${{ matrix.arch }} A=apps/c/helloworld
- name: Build c/memtest

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "patches/opensbi"]
path = patches/opensbi
url = https://github.com/Sssssaltyfish/opensbi.git

12
Cargo.lock generated
View File

@ -1756,21 +1756,17 @@ dependencies = [
[[package]]
name = "sbi-rt"
version = "0.0.2"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c113c53291db8ac141e01f43224ed488b8d6001ab66737b82e04695a43a42b7"
checksum = "7fbaa69be1eedc61c426e6d489b2260482e928b465360576900d52d496a58bd0"
dependencies = [
"sbi-spec",
]
[[package]]
name = "sbi-spec"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d4027cf9bb591a9fd0fc0e283be6165c5abe96cb73e9f0e24738c227f425377"
dependencies = [
"static_assertions",
]
version = "0.0.7"
source = "git+https://github.com/Sssssaltyfish/rustsbi.git?rev=a25d448d3d770c6db493a472e3e78d949b63f523#a25d448d3d770c6db493a472e3e78d949b63f523"
[[package]]
name = "scheduler"

View File

@ -19,7 +19,7 @@ members = [
"crates/driver_net",
"crates/driver_pci",
"crates/driver_virtio",
"crates/dtb",
"crates/dtb",
"crates/flatten_objects",
"crates/lazy_init",
"crates/linked_list",
@ -67,3 +67,6 @@ lto = true
[profile.reldebug]
inherits = "release"
debug = true
[patch.crates-io]
sbi-spec = { git = "https://github.com/Sssssaltyfish/rustsbi.git", rev = "a25d448d3d770c6db493a472e3e78d949b63f523", optional = true }

View File

@ -166,8 +166,19 @@ LD_SCRIPT := $(CURDIR)/modules/ruxhal/linker_$(PLATFORM_NAME).lds
OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM_NAME).elf
OUT_BIN := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM_NAME).bin
PREBUILD := $(CURDIR)/scripts/prebuild/$(ARCH).mk
all: build
# prebuild option to be overriden in `$(PREBUILD)`
define run_prebuild
endef
# prebuild makefile might override some variables by their own
# so it must be placed before the rest of the makefiles
ifneq ($(wildcard $(PREBUILD)),)
include $(PREBUILD)
endif
include scripts/make/utils.mk
include scripts/make/build.mk
include scripts/make/qemu.mk
@ -178,6 +189,16 @@ else ifeq ($(PLATFORM_NAME), aarch64-bsta1000b)
include scripts/make/bsta1000b-fada.mk
endif
_force: ;
# prebuild scripts must track their dependencies by themselves
prebuild: _force
$(call run_prebuild)
$(OUT_DIR): prebuild
$(OUT_BIN): prebuild
build: $(OUT_DIR) $(OUT_BIN)
disasm:
@ -248,4 +269,5 @@ 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 clean_musl doc disk_image debug_no_attach
.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c\
clean_musl doc disk_image debug_no_attach prebuild _force

View File

@ -98,7 +98,7 @@ impl Pthread {
}
/// Posix create, used by musl libc
#[cfg(all(feature = "musl", any(target_arch = "x86_64", target_arch = "aarch64")))]
#[cfg(feature = "musl")]
fn pcreate(
_attr: *const ctypes::pthread_attr_t,
start_routine: extern "C" fn(arg: *mut c_void) -> *mut c_void,
@ -246,7 +246,10 @@ 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", target_arch = "aarch64"))]
#[cfg(all(
feature = "musl",
any(target_arch = "aarch64", target_arch = "riscv64")
))]
pub unsafe fn sys_clone(
flags: c_int,
stack: *mut c_void,

View File

@ -111,11 +111,7 @@ pub use imp::signal::{sys_getitimer, sys_kill, sys_setitimer, sys_sigaction, sys
#[cfg(feature = "multitask")]
pub use imp::pthread::futex::sys_futex;
#[cfg(all(
feature = "multitask",
feature = "musl",
any(target_arch = "aarch64", target_arch = "x86_64")
))]
#[cfg(all(feature = "multitask", feature = "musl"))]
pub use imp::pthread::sys_clone;
#[cfg(all(feature = "multitask", feature = "musl"))]
pub use imp::pthread::sys_set_tid_address;

View File

@ -50,7 +50,7 @@ raw-cpuid = "11.0"
[target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies]
riscv = "0.10"
sbi-rt = { version = "0.0.2", features = ["legacy"] }
sbi-rt = { version = "0.0.3", features = ["legacy"] }
dtb = {path = "../../crates/dtb" }
[target.'cfg(target_arch = "aarch64")'.dependencies]

View File

@ -29,6 +29,21 @@ fn riscv_trap_handler(tf: &mut TrapFrame, _from_user: bool) {
match scause.cause() {
Trap::Exception(E::Breakpoint) => handle_breakpoint(&mut tf.sepc),
Trap::Interrupt(_) => crate::trap::handle_irq_extern(scause.bits()),
#[cfg(feature = "musl")]
Trap::Exception(E::UserEnvCall) => {
let ret = crate::trap::handle_syscall(
tf.regs.a7,
[
tf.regs.a0 as _,
tf.regs.a1 as _,
tf.regs.a2 as _,
tf.regs.a3 as _,
tf.regs.a4 as _,
tf.regs.a5 as _,
],
);
tf.regs.a0 = ret as _;
}
_ => {
panic!(
"Unhandled trap {:?} @ {:#x}:\n{:#x?}",

View File

@ -9,7 +9,7 @@
use riscv::register::satp;
use ruxconfig::{PHYS_VIRT_OFFSET, TASK_STACK_SIZE};
use ruxconfig::{PHYS_MEMORY_SIZE, PHYS_VIRT_OFFSET, TASK_STACK_SIZE};
#[link_section = ".bss.stack"]
static mut BOOT_STACK: [u8; TASK_STACK_SIZE] = [0; TASK_STACK_SIZE];
@ -18,10 +18,18 @@ static mut BOOT_STACK: [u8; TASK_STACK_SIZE] = [0; TASK_STACK_SIZE];
static mut BOOT_PT_SV39: [u64; 512] = [0; 512];
unsafe fn init_boot_page_table() {
// 0x8000_0000..0xc000_0000, VRWX_GAD, 1G block
BOOT_PT_SV39[2] = (0x80000 << 10) | 0xef;
// 0xffff_ffc0_8000_0000..0xffff_ffc0_c000_0000, VRWX_GAD, 1G block
BOOT_PT_SV39[0x102] = (0x80000 << 10) | 0xef;
const MEMORY_GBS: usize = PHYS_MEMORY_SIZE.div_ceil(1024 * 1024 * 1024);
const PPN_2_OFFSET: u64 = 10 + 9 + 9;
// start from 0x8000_0000, first block 0x8000_0000..0xc000_0000
// VRWX_GAD, 1G Gigapages
for i in 0..MEMORY_GBS {
BOOT_PT_SV39[2 + i] = ((2 + i as u64) << PPN_2_OFFSET) | 0xef;
}
// start from 0xffff_ffc0_8000_0000, first block 0xffff_ffc0_8000_0000..0xffff_ffc0_c000_0000
// VRWX_GAD, 1G Gigapages
for i in 0..MEMORY_GBS {
BOOT_PT_SV39[0x102 + i] = ((2 + i as u64) << PPN_2_OFFSET) | 0xef;
}
}
unsafe fn init_mmu() {

1
patches/opensbi Submodule

@ -0,0 +1 @@
Subproject commit 76345f7ae076b6b0087fe0febe2658a52aef368b

View File

@ -9,7 +9,7 @@ family = "aarch64-qemu-virt"
phys-memory-base = "0x4000_0000"
# Size of the whole physical memory.
# phys-memory-size = "0x800_0000" # 128M
# phys-memory-size = "0x1000_0000" # 1G
# phys-memory-size = "0x4000_0000" # 1G
phys-memory-size = "0x8000_0000" # 2G
# phys-memory-size = "0xc000_0000" # 3G
# phys-memory-size = "0x1_0000_0000" # 4G

View File

@ -8,8 +8,14 @@ family = "riscv64-qemu-virt"
# Base address of the whole physical memory.
phys-memory-base = "0x8000_0000"
# Size of the whole physical memory.
# Size of the whole physical memory.
# phys-memory-size = "0x800_0000" # 128M
# phys-memory-size = "0x4000_0000" # 1G
phys-memory-size = "0x8000_0000" # 2G
# phys-memory-size = "0xc000_0000" # 3G
# phys-memory-size = "0x1_0000_0000" # 4G
# phys-memory-size = "0x1_8000_0000" # 6G
# phys-memory-size = "0x2_0000_0000" # 8G
# Base physical address of the kernel image.
kernel-base-paddr = "0x8020_0000"
# Base virtual address of the kernel image.

View File

@ -71,6 +71,8 @@ app-objs := $(addprefix $(APP)/,$(app-objs))
$(ulib_hdr): _cargo_build
$(app-objs): $(ulib_hdr) prebuild
$(APP)/%.o: $(APP)/%.c $(ulib_hdr)
$(call run_cmd,$(CC),$(CFLAGS) $(APP_CFLAGS) -c -o $@ $<)

View File

@ -3,11 +3,16 @@ rust_lib := target/$(TARGET)/$(MODE)/lib$(rust_lib_name).a
musl_version := 1.2.3
build_suffix := _$(ARCH)_$(MODE)
muslibc_dir := ulib/ruxmusl
build_dir := $(muslibc_dir)/build_musl_$(ARCH)
build_dir := $(muslibc_dir)/build_musl$(build_suffix)
install_dir_name := install$(build_suffix)
install_dir := $(muslibc_dir)/$(install_dir_name)
musl_dir := $(muslibc_dir)/musl-$(musl_version)
inc_dir := $(muslibc_dir)/install/include
c_lib := $(muslibc_dir)/install/lib/libc.a
inc_dir := $(install_dir)/include
c_lib := $(install_dir)/lib/libc.a
libgcc :=
CFLAGS += -nostdinc -fno-builtin -ffreestanding -Wall
@ -42,14 +47,14 @@ else
endif
build_musl:
ifeq ($(wildcard $(build_dir)),)
ifeq ($(wildcard $(install_dir)),)
ifeq ($(wildcard $(musl_dir)),)
@echo "Download musl-1.2.3 source code"
wget https://musl.libc.org/releases/musl-1.2.3.tar.gz -P $(muslibc_dir)
tar -zxvf $(muslibc_dir)/musl-1.2.3.tar.gz -C $(muslibc_dir) && rm -f $(muslibc_dir)/musl-1.2.3.tar.gz
endif
mkdir -p $(build_dir)
cd $(build_dir) && ../musl-1.2.3/configure --prefix=../install --exec-prefix=../ --syslibdir=../install/lib --disable-shared ARCH=$(RUX_ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS='$(CFLAGS)'
cd $(build_dir) && ../musl-1.2.3/configure --prefix=../$(install_dir_name) --exec-prefix=../ --syslibdir=../$(install_dir_name)/lib --disable-shared ARCH=$(RUX_ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS='$(CFLAGS)'
cd $(build_dir) && $(MAKE) -j && $(MAKE) install
endif
@ -61,6 +66,8 @@ app-objs := main.o
app-objs := $(addprefix $(APP)/,$(app-objs))
$(app-objs): build_musl prebuild
$(APP)/%.o: $(APP)/%.c build_musl
$(call run_cmd,$(CC),$(CFLAGS) $(APP_CFLAGS) -c -o $@ $<)

View File

@ -0,0 +1,12 @@
# non-musl riscv64 still needs a usable bios
# instead of the non-funtioning default one
define run_prebuild
git submodule update --init --recursive --remote patches/opensbi
endef
RISCV_BIOS := $(CURDIR)/patches/opensbi/build/platform/generic/firmware/fw_dynamic.bin
$(RISCV_BIOS): prebuild
CROSS_COMPILE=riscv64-linux-musl- $(MAKE) -C patches/opensbi PLATFORM=generic
build: $(RISCV_BIOS)

View File

@ -1,3 +1,4 @@
build_*
install
install_*
musl-*

View File

@ -22,6 +22,9 @@ cfg_if::cfg_if! {
mod x86_64;
#[cfg(feature = "musl")]
use x86_64::{syscall, syscall_id};
} else if #[cfg(target_arch = "riscv64")]{
mod riscv64;
use riscv64::{syscall, syscall_id};
} else {
mod dummy;
use dummy::{syscall, syscall_id};

View File

@ -0,0 +1,354 @@
pub mod syscall_id;
use core::ffi::c_int;
use ruxos_posix_api::ctypes;
use syscall_id::SyscallId;
pub fn syscall(syscall_id: SyscallId, args: [usize; 6]) -> isize {
debug!("syscall <= syscall_name: {:?}", syscall_id);
unsafe {
match syscall_id {
SyscallId::INVALID => ruxos_posix_api::sys_invalid(syscall_id as usize as c_int) as _,
#[cfg(feature = "fs")]
SyscallId::GETCWD => {
ruxos_posix_api::sys_getcwd(args[0] as *mut core::ffi::c_char, args[1]) as _
}
#[cfg(feature = "epoll")]
SyscallId::EPOLL_CREATE1 => ruxos_posix_api::sys_epoll_create(args[0] as c_int) as _,
#[cfg(feature = "epoll")]
SyscallId::EPOLL_CTL => ruxos_posix_api::sys_epoll_ctl(
args[0] as c_int,
args[1] as c_int,
args[2] as c_int,
args[3] as *mut ctypes::epoll_event,
) as _,
#[cfg(feature = "epoll")]
SyscallId::EPOLL_PWAIT => ruxos_posix_api::sys_epoll_pwait(
args[0] as c_int,
args[1] as *mut ctypes::epoll_event,
args[2] as c_int,
args[3] as c_int,
args[4] as *const ctypes::sigset_t,
args[5] as *const ctypes::size_t,
) as _,
#[cfg(feature = "fd")]
SyscallId::DUP => ruxos_posix_api::sys_dup(args[0] as c_int) as _,
#[cfg(feature = "fd")]
SyscallId::DUP3 => {
ruxos_posix_api::sys_dup3(args[0] as c_int, args[1] as c_int, args[2] as c_int) as _
}
#[cfg(feature = "fd")]
SyscallId::FCNTL => {
ruxos_posix_api::sys_fcntl(args[0] as c_int, args[1] as c_int, args[2]) as _
}
#[cfg(feature = "fd")]
SyscallId::IOCTL => ruxos_posix_api::sys_ioctl(args[0] as c_int, args[1], args[2]) as _,
#[cfg(feature = "fs")]
SyscallId::MKDIRAT => ruxos_posix_api::sys_mkdirat(
args[0] as c_int,
args[1] as *const core::ffi::c_char,
args[2] as ctypes::mode_t,
) as _,
#[cfg(feature = "fs")]
SyscallId::UNLINKAT => ruxos_posix_api::sys_unlinkat(
args[0] as c_int,
args[1] as *const core::ffi::c_char,
args[2] as c_int,
) as _,
#[cfg(feature = "fs")]
SyscallId::FCHOWNAT => ruxos_posix_api::sys_fchownat(
args[0] as c_int,
args[1] as *const core::ffi::c_char,
args[2] as ctypes::uid_t,
args[3] as ctypes::gid_t,
args[4] as c_int,
) as _,
#[cfg(feature = "fs")]
SyscallId::RENAMEAT => ruxos_posix_api::sys_renameat(
args[0] as c_int,
args[1] as *const core::ffi::c_char,
args[2] as c_int,
args[3] as *const core::ffi::c_char,
) as _,
#[cfg(feature = "fs")]
SyscallId::OPENAT => ruxos_posix_api::sys_openat(
args[0],
args[1] as *const core::ffi::c_char,
args[2] as c_int,
args[3] as ctypes::mode_t,
) as _,
#[cfg(feature = "fd")]
SyscallId::CLOSE => ruxos_posix_api::sys_close(args[0] as c_int) as _,
#[cfg(feature = "pipe")]
SyscallId::PIPE2 => ruxos_posix_api::sys_pipe2(
core::slice::from_raw_parts_mut(args[0] as *mut c_int, 2),
args[1] as c_int,
) as _,
#[cfg(feature = "fs")]
SyscallId::GETDENTS64 => ruxos_posix_api::sys_getdents64(
args[0] as c_int,
args[1] as *mut ctypes::dirent,
args[2] as ctypes::size_t,
) as _,
#[cfg(feature = "fs")]
SyscallId::LSEEK => ruxos_posix_api::sys_lseek(
args[0] as c_int,
args[1] as ctypes::off_t,
args[2] as c_int,
) as _,
SyscallId::READ => ruxos_posix_api::sys_read(
args[0] as c_int,
args[1] as *mut core::ffi::c_void,
args[2],
) as _,
SyscallId::WRITE => ruxos_posix_api::sys_write(
args[0] as c_int,
args[1] as *mut core::ffi::c_void,
args[2],
) as _,
#[cfg(feature = "fd")]
SyscallId::READV => ruxos_posix_api::sys_readv(
args[0] as c_int,
args[1] as *const ctypes::iovec,
args[2] as c_int,
) as _,
#[cfg(feature = "fd")]
SyscallId::WRITEV => ruxos_posix_api::sys_writev(
args[0] as c_int,
args[1] as *const ctypes::iovec,
args[2] as c_int,
) as _,
#[cfg(feature = "select")]
SyscallId::PSELECT6 => ruxos_posix_api::sys_pselect6(
args[0] as c_int,
args[1] as *mut ctypes::fd_set,
args[2] as *mut ctypes::fd_set,
args[3] as *mut ctypes::fd_set,
args[4] as *mut ctypes::timeval,
args[5] as *const core::ffi::c_void,
) as _,
#[cfg(feature = "poll")]
SyscallId::PPOLL => ruxos_posix_api::sys_ppoll(
args[0] as *mut ctypes::pollfd,
args[1] as ctypes::nfds_t,
args[2] as *const ctypes::timespec,
args[3] as *const ctypes::sigset_t,
args[4] as ctypes::size_t,
) as _,
#[cfg(feature = "fs")]
SyscallId::READLINKAT => ruxos_posix_api::sys_readlinkat(
args[0] as c_int,
args[1] as *const core::ffi::c_char,
args[2] as *mut core::ffi::c_char,
args[3] as ctypes::size_t,
) as _,
#[cfg(feature = "fs")]
SyscallId::NEWFSTATAT => ruxos_posix_api::sys_newfstatat(
args[0] as c_int,
args[1] as *const core::ffi::c_char,
args[2] as *mut ctypes::kstat,
args[3] as c_int,
) as _,
#[cfg(feature = "fs")]
SyscallId::FSTAT => {
ruxos_posix_api::sys_fstat(args[0] as c_int, args[1] as *mut core::ffi::c_void) as _
}
#[cfg(feature = "fs")]
SyscallId::FSYNC => ruxos_posix_api::sys_fsync(args[0] as c_int) as _,
SyscallId::GETEUID => ruxos_posix_api::sys_geteuid() as _,
SyscallId::GETEGID => ruxos_posix_api::sys_getegid() as _,
#[cfg(feature = "fs")]
SyscallId::FDATASYNC => ruxos_posix_api::sys_fdatasync(args[0] as c_int) as _,
#[allow(unreachable_code)]
#[cfg(not(feature = "multitask"))]
SyscallId::EXIT => ruxos_posix_api::sys_exit(args[0] as c_int) as _,
#[allow(unreachable_code)]
#[cfg(feature = "multitask")]
SyscallId::EXIT => {
ruxos_posix_api::sys_pthread_exit(args[0] as *mut core::ffi::c_void) as _
}
#[cfg(feature = "multitask")]
SyscallId::SET_TID_ADDRESS => ruxos_posix_api::sys_set_tid_address(args[0]) as _,
#[cfg(feature = "multitask")]
SyscallId::FUTEX => ruxos_posix_api::sys_futex(
args[0],
args[1] as _,
args[2] as _,
args[3],
args[4] as _,
args[5] as _,
) as _,
SyscallId::NANO_SLEEP => ruxos_posix_api::sys_nanosleep(
args[0] as *const ctypes::timespec,
args[1] as *mut ctypes::timespec,
) as _,
SyscallId::CLOCK_SETTIME => ruxos_posix_api::sys_clock_settime(
args[0] as ctypes::clockid_t,
args[1] as *const ctypes::timespec,
) as _,
SyscallId::CLOCK_GETTIME => ruxos_posix_api::sys_clock_gettime(
args[0] as ctypes::clockid_t,
args[1] as *mut ctypes::timespec,
) as _,
SyscallId::SCHED_YIELD => ruxos_posix_api::sys_sched_yield() as _,
#[cfg(feature = "signal")]
SyscallId::SIGALTSTACK => ruxos_posix_api::sys_sigaltstack(
args[0] as *const core::ffi::c_void,
args[1] as *mut core::ffi::c_void,
) as _,
#[cfg(feature = "signal")]
SyscallId::RT_SIGACTION => ruxos_posix_api::sys_rt_sigaction(
args[0] as c_int,
args[1] as *const ctypes::sigaction,
args[2] as *mut ctypes::sigaction,
args[3] as ctypes::size_t,
) as _,
#[cfg(feature = "signal")]
SyscallId::RT_SIGPROCMASK => ruxos_posix_api::sys_rt_sigprocmask(
args[0] as c_int,
args[1] as *const usize,
args[2] as *mut usize,
args[3],
) as _,
SyscallId::UNAME => ruxos_posix_api::sys_uname(args[0] as *mut core::ffi::c_void) as _,
SyscallId::GETRLIMIT => {
ruxos_posix_api::sys_getrlimit(args[0] as c_int, args[1] as *mut ctypes::rlimit)
as _
}
SyscallId::SETRLIMIT => {
ruxos_posix_api::sys_setrlimit(args[0] as c_int, args[1] as *const ctypes::rlimit)
as _
}
SyscallId::UMASK => ruxos_posix_api::sys_umask(args[0] as ctypes::mode_t) as _,
#[cfg(feature = "multitask")]
SyscallId::GETPID => ruxos_posix_api::sys_getpid() as _,
SyscallId::SYSINFO => {
ruxos_posix_api::sys_sysinfo(args[0] as *mut ctypes::sysinfo) as _
}
#[cfg(feature = "net")]
SyscallId::SOCKET => {
ruxos_posix_api::sys_socket(args[0] as c_int, args[1] as c_int, args[2] as c_int)
as _
}
#[cfg(feature = "net")]
SyscallId::BIND => ruxos_posix_api::sys_bind(
args[0] as c_int,
args[1] as *const ctypes::sockaddr,
args[2] as ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::LISTEN => {
ruxos_posix_api::sys_listen(args[0] as c_int, args[1] as c_int) as _
}
#[cfg(feature = "net")]
SyscallId::ACCEPT => ruxos_posix_api::sys_accept(
args[0] as c_int,
args[1] as *mut ctypes::sockaddr,
args[2] as *mut ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::CONNECT => ruxos_posix_api::sys_connect(
args[0] as c_int,
args[1] as *const ctypes::sockaddr,
args[2] as ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::GETSOCKNAME => ruxos_posix_api::sys_getsockname(
args[0] as c_int,
args[1] as *mut ctypes::sockaddr,
args[2] as *mut ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::GETPEERNAME => ruxos_posix_api::sys_getpeername(
args[0] as c_int,
args[1] as *mut ctypes::sockaddr,
args[2] as *mut ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::SENDTO => ruxos_posix_api::sys_sendto(
args[0] as c_int,
args[1] as *const core::ffi::c_void,
args[2] as ctypes::size_t,
args[3] as c_int,
args[4] as *const ctypes::sockaddr,
args[5] as ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::RECVFROM => ruxos_posix_api::sys_recvfrom(
args[0] as c_int,
args[1] as *mut core::ffi::c_void,
args[2] as ctypes::size_t,
args[3] as c_int,
args[4] as *mut ctypes::sockaddr,
args[5] as *mut ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::SETSOCKOPT => ruxos_posix_api::sys_setsockopt(
args[0] as c_int,
args[1] as c_int,
args[2] as c_int,
args[3] as *const core::ffi::c_void,
args[4] as ctypes::socklen_t,
) as _,
#[cfg(feature = "net")]
SyscallId::SHUTDOWN => {
ruxos_posix_api::sys_shutdown(args[0] as c_int, args[1] as c_int) as _
}
#[cfg(feature = "net")]
SyscallId::SENDMSG => ruxos_posix_api::sys_sendmsg(
args[0] as c_int,
args[1] as *const ctypes::msghdr,
args[2] as c_int,
) as _,
#[cfg(feature = "alloc")]
SyscallId::MUNMAP => ruxos_posix_api::sys_munmap(
args[0] as *mut core::ffi::c_void,
args[1] as ctypes::size_t,
) as _,
#[cfg(feature = "alloc")]
SyscallId::MREMAP => ruxos_posix_api::sys_mremap(
args[0] as *mut core::ffi::c_void,
args[1] as ctypes::size_t,
args[2] as ctypes::size_t,
args[3] as c_int,
args[4] as *mut core::ffi::c_void,
) as _,
#[cfg(feature = "multitask")]
SyscallId::CLONE => ruxos_posix_api::sys_clone(
args[0] as c_int,
args[1] as *mut core::ffi::c_void,
args[2] as *mut ctypes::pid_t,
args[3] as *mut core::ffi::c_void,
args[4] as *mut ctypes::pid_t,
) as _,
#[cfg(feature = "alloc")]
SyscallId::MMAP => ruxos_posix_api::sys_mmap(
args[0] as *mut core::ffi::c_void,
args[1] as ctypes::size_t,
args[2] as c_int,
args[3] as c_int,
args[4] as c_int,
args[5] as ctypes::off_t,
) as _,
#[cfg(feature = "alloc")]
SyscallId::MADVISE => ruxos_posix_api::sys_madvise(
args[0] as *mut core::ffi::c_void,
args[1] as ctypes::size_t,
args[2] as c_int,
) as _,
#[cfg(feature = "alloc")]
SyscallId::MPROTECT => ruxos_posix_api::sys_mprotect(
args[0] as *mut core::ffi::c_void,
args[1] as ctypes::size_t,
args[2] as c_int,
) as _,
SyscallId::PRLIMIT64 => ruxos_posix_api::sys_prlimit64(
args[0] as ctypes::pid_t,
args[1] as c_int,
args[2] as *const ctypes::rlimit,
args[3] as *mut ctypes::rlimit,
) as _,
}
}
}

View File

@ -0,0 +1,125 @@
use num_enum::TryFromPrimitive;
// TODO: syscall id are architecture-dependent
#[allow(clippy::upper_case_acronyms)]
#[allow(non_camel_case_types)]
#[repr(usize)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, TryFromPrimitive)]
pub enum SyscallId {
INVALID = 999,
#[cfg(feature = "fs")]
GETCWD = 17,
#[cfg(feature = "epoll")]
EPOLL_CREATE1 = 20,
#[cfg(feature = "epoll")]
EPOLL_CTL = 21,
#[cfg(feature = "epoll")]
EPOLL_PWAIT = 22,
#[cfg(feature = "fd")]
DUP = 23,
#[cfg(feature = "fd")]
DUP3 = 24,
#[cfg(feature = "fd")]
FCNTL = 25,
#[cfg(feature = "fd")]
IOCTL = 29,
#[cfg(feature = "fs")]
MKDIRAT = 34,
#[cfg(feature = "fs")]
UNLINKAT = 35,
#[cfg(feature = "fs")]
RENAMEAT = 38,
#[cfg(feature = "fs")]
FCHOWNAT = 54,
#[cfg(feature = "fs")]
OPENAT = 56,
#[cfg(feature = "fd")]
CLOSE = 57,
#[cfg(feature = "pipe")]
PIPE2 = 59,
#[cfg(feature = "fs")]
GETDENTS64 = 61,
#[cfg(feature = "fs")]
LSEEK = 62,
READ = 63,
WRITE = 64,
#[cfg(feature = "fd")]
READV = 65,
#[cfg(feature = "fd")]
WRITEV = 66,
#[cfg(feature = "select")]
PSELECT6 = 72,
#[cfg(feature = "poll")]
PPOLL = 73,
#[cfg(feature = "fs")]
READLINKAT = 78,
#[cfg(feature = "fs")]
NEWFSTATAT = 79,
#[cfg(feature = "fs")]
FSTAT = 80,
#[cfg(feature = "fs")]
FSYNC = 82,
#[cfg(feature = "fs")]
FDATASYNC = 83,
EXIT = 93,
#[cfg(feature = "multitask")]
SET_TID_ADDRESS = 96,
#[cfg(feature = "multitask")]
FUTEX = 98,
NANO_SLEEP = 101,
CLOCK_SETTIME = 112,
CLOCK_GETTIME = 113,
SCHED_YIELD = 124,
#[cfg(feature = "signal")]
SIGALTSTACK = 132,
#[cfg(feature = "signal")]
RT_SIGACTION = 134,
#[cfg(feature = "signal")]
RT_SIGPROCMASK = 135,
UNAME = 160,
GETRLIMIT = 163,
SETRLIMIT = 164,
UMASK = 166,
#[cfg(feature = "multitask")]
GETPID = 172,
GETEUID = 175,
GETEGID = 177,
SYSINFO = 179,
#[cfg(feature = "net")]
SOCKET = 198,
#[cfg(feature = "net")]
BIND = 200,
#[cfg(feature = "net")]
LISTEN = 201,
#[cfg(feature = "net")]
ACCEPT = 202,
#[cfg(feature = "net")]
CONNECT = 203,
#[cfg(feature = "net")]
GETSOCKNAME = 204,
#[cfg(feature = "net")]
GETPEERNAME = 205,
#[cfg(feature = "net")]
SENDTO = 206,
#[cfg(feature = "net")]
RECVFROM = 207,
#[cfg(feature = "net")]
SETSOCKOPT = 208,
#[cfg(feature = "net")]
SHUTDOWN = 210,
#[cfg(feature = "net")]
SENDMSG = 211,
#[cfg(feature = "alloc")]
MUNMAP = 215,
#[cfg(feature = "alloc")]
MREMAP = 216,
#[cfg(feature = "multitask")]
CLONE = 220,
#[cfg(feature = "alloc")]
MMAP = 222,
#[cfg(feature = "alloc")]
MADVISE = 233,
#[cfg(feature = "alloc")]
MPROTECT = 226,
PRLIMIT64 = 261,
}