axlibc/
lib.rs

1//! [ArceOS] user program library for C apps.
2//!
3//! ## Cargo Features
4//!
5//! - CPU
6//!     - `smp`: Enable SMP (symmetric multiprocessing) support.
7//!     - `fp-simd`: Enable floating point and SIMD support.
8//! - Interrupts:
9//!     - `irq`: Enable interrupt handling support.
10//! - Memory
11//!     - `alloc`: Enable dynamic memory allocation.
12//!     - `tls`: Enable thread-local storage.
13//! - Task management
14//!     - `multitask`: Enable multi-threading support.
15//! - Upperlayer stacks
16//!     - `fs`: Enable file system support.
17//!     - `net`: Enable networking support.
18//! - Lib C functions
19//!     - `fd`: Enable file descriptor table.
20//!     - `pipe`: Enable pipe support.
21//!     - `select`: Enable synchronous I/O multiplexing ([select]) support.
22//!     - `epoll`: Enable event polling ([epoll]) support.
23//!
24//! [ArceOS]: https://github.com/arceos-org/arceos
25//! [select]: https://man7.org/linux/man-pages/man2/select.2.html
26//! [epoll]: https://man7.org/linux/man-pages/man7/epoll.7.html
27
28#![cfg_attr(all(not(test), not(doc)), no_std)]
29#![feature(doc_cfg)]
30#![feature(thread_local)]
31#![allow(clippy::missing_safety_doc)]
32
33#[cfg(feature = "alloc")]
34extern crate alloc;
35
36#[path = "."]
37mod ctypes {
38    #[rustfmt::skip]
39    #[path = "libctypes_gen.rs"]
40    #[allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals, clippy::upper_case_acronyms)]
41    mod libctypes;
42
43    pub use arceos_posix_api::ctypes::*;
44    pub use libctypes::*;
45}
46
47#[macro_use]
48mod utils;
49
50#[cfg(feature = "fd")]
51mod fd_ops;
52#[cfg(feature = "fs")]
53mod fs;
54#[cfg(any(feature = "select", feature = "epoll"))]
55mod io_mpx;
56#[cfg(feature = "alloc")]
57mod malloc;
58#[cfg(feature = "net")]
59mod net;
60#[cfg(feature = "pipe")]
61mod pipe;
62#[cfg(feature = "multitask")]
63mod pthread;
64#[cfg(feature = "alloc")]
65mod strftime;
66#[cfg(feature = "fp-simd")]
67mod strtod;
68
69mod errno;
70mod io;
71mod mktime;
72mod rand;
73mod resource;
74mod setjmp;
75mod sys;
76mod time;
77mod unistd;
78
79#[cfg(not(test))]
80pub use self::io::write;
81pub use self::io::{read, writev};
82
83pub use self::errno::strerror;
84pub use self::mktime::mktime;
85pub use self::rand::{rand, random, srand};
86pub use self::resource::{getrlimit, setrlimit};
87pub use self::setjmp::{longjmp, setjmp};
88pub use self::sys::sysconf;
89pub use self::time::{clock_gettime, nanosleep};
90pub use self::unistd::{abort, exit, getpid};
91
92#[cfg(feature = "alloc")]
93pub use self::malloc::{free, malloc};
94#[cfg(feature = "alloc")]
95pub use self::strftime::strftime;
96
97#[cfg(feature = "fd")]
98pub use self::fd_ops::{ax_fcntl, close, dup, dup2, dup3};
99
100#[cfg(feature = "fs")]
101pub use self::fs::{ax_open, fstat, getcwd, lseek, lstat, rename, stat};
102
103#[cfg(feature = "net")]
104pub use self::net::{
105    accept, bind, connect, freeaddrinfo, getaddrinfo, getpeername, getsockname, listen, recv,
106    recvfrom, send, sendto, shutdown, socket,
107};
108
109#[cfg(feature = "multitask")]
110pub use self::pthread::{pthread_create, pthread_exit, pthread_join, pthread_self};
111#[cfg(feature = "multitask")]
112pub use self::pthread::{pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock};
113
114#[cfg(feature = "pipe")]
115pub use self::pipe::pipe;
116
117#[cfg(feature = "select")]
118pub use self::io_mpx::select;
119#[cfg(feature = "epoll")]
120pub use self::io_mpx::{epoll_create, epoll_ctl, epoll_wait};
121
122#[cfg(feature = "fp-simd")]
123pub use self::strtod::{strtod, strtof};