1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* Copyright (c) [2023] [Syswonder Community]
 *   [Rukos] is licensed under Mulan PSL v2.
 *   You can use this software according to the terms and conditions of the Mulan PSL v2.
 *   You may obtain a copy of Mulan PSL v2 at:
 *               http://license.coscl.org.cn/MulanPSL2
 *   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *   See the Mulan PSL v2 for more details.
 */

//! POSIX-compatible APIs for [ArceOS] modules
//!
//! [ArceOS]: https://github.com/rcore-os/arceos

#![cfg_attr(all(not(test), not(doc)), no_std)]
#![feature(ip_in_core)]
#![feature(result_option_inspect)]
#![feature(doc_cfg)]
#![feature(doc_auto_cfg)]
#![allow(clippy::missing_safety_doc)]

#[macro_use]
extern crate axlog;
extern crate axruntime;

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "alloc")]
pub use axruntime::{environ, environ_iter, RX_ENVIRON};

#[macro_use]
mod utils;

mod imp;

/// Platform-specific constants and parameters.
pub mod config {
    pub use axconfig::*;
    pub use memory_addr::PAGE_SIZE_4K;
}

/// POSIX C types.
#[rustfmt::skip]
#[path = "./ctypes_gen.rs"]
#[allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals, clippy::upper_case_acronyms, missing_docs)]
pub mod ctypes;

pub use imp::io::{sys_read, sys_write, sys_writev};
pub use imp::resources::{sys_getrlimit, sys_prlimit64, sys_setrlimit};
pub use imp::rt_sig::{sys_rt_sigaction, sys_rt_sigprocmask};
pub use imp::stat::sys_umask;
pub use imp::sys::sys_sysinfo;
pub use imp::sys_invalid;
pub use imp::task::{sys_exit, sys_getpid, sys_sched_yield};
pub use imp::time::{sys_clock_gettime, sys_clock_settime, sys_nanosleep};

#[cfg(all(feature = "fd", feature = "musl"))]
pub use imp::fd_ops::sys_dup3;
#[cfg(feature = "fd")]
pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl};
#[cfg(feature = "fs")]
pub use imp::fs::{
    sys_fstat, sys_fsync, sys_getcwd, sys_lseek, sys_lstat, sys_mkdir, sys_mkdirat, sys_newfstatat,
    sys_open, sys_openat, sys_rename, sys_rmdir, sys_stat, sys_unlink, sys_unlinkat,sys_getegid,sys_geteuid
};
#[cfg(feature = "epoll")]
pub use imp::io_mpx::{sys_epoll_create, sys_epoll_ctl, sys_epoll_pwait, sys_epoll_wait};
#[cfg(feature = "poll")]
pub use imp::io_mpx::{sys_poll, sys_ppoll};
#[cfg(feature = "select")]
pub use imp::io_mpx::{sys_pselect6, sys_select};
#[cfg(feature = "fd")]
pub use imp::ioctl::sys_ioctl;
#[cfg(feature = "alloc")]
pub use imp::mmap::{sys_mmap, sys_mprotect, sys_munmap};
#[cfg(feature = "net")]
pub use imp::net::{
    sys_accept, sys_bind, sys_connect, sys_freeaddrinfo, sys_getaddrinfo, sys_getpeername,
    sys_getsockname, sys_listen, sys_recv, sys_recvfrom, sys_send, sys_sendmsg, sys_sendto,
    sys_setsockopt, sys_shutdown, sys_socket,
};
#[cfg(feature = "pipe")]
pub use imp::pipe::{sys_pipe, sys_pipe2};
#[cfg(feature = "multitask")]
pub use imp::pthread::condvar::{
    sys_pthread_cond_broadcast, sys_pthread_cond_destroy, sys_pthread_cond_init,
    sys_pthread_cond_signal, sys_pthread_cond_timedwait, sys_pthread_cond_wait,
};
#[cfg(feature = "multitask")]
pub use imp::pthread::mutex::{
    sys_pthread_mutex_destroy, sys_pthread_mutex_init, sys_pthread_mutex_lock,
    sys_pthread_mutex_trylock, sys_pthread_mutex_unlock,
};
#[cfg(feature = "multitask")]
pub use imp::pthread::{
    sys_pthread_getspecific, sys_pthread_key_create, sys_pthread_key_delete,
    sys_pthread_setspecific,
};
#[cfg(feature = "signal")]
pub use imp::signal::sys_sigaction;
#[cfg(feature = "signal")]
pub use imp::time::{sys_getitimer, sys_setitimer};

#[cfg(feature = "multitask")]
pub use imp::pthread::futex::sys_futex;
#[cfg(all(feature = "multitask", feature = "musl"))]
pub use imp::pthread::{sys_clone, sys_set_tid_address};
#[cfg(feature = "multitask")]
pub use imp::pthread::{sys_pthread_create, sys_pthread_exit, sys_pthread_join, sys_pthread_self};