Skip to main content

ax_libc/
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(thread_local)]
30#![allow(clippy::missing_safety_doc)]
31
32#[cfg(feature = "alloc")]
33extern crate alloc;
34
35mod ctypes {
36    #[rustfmt::skip]
37    #[allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals, clippy::upper_case_acronyms)]
38    mod libctypes {
39        include!(concat!(env!("OUT_DIR"), "/libctypes_gen.rs"));
40    }
41
42    pub use ax_posix_api::ctypes::*;
43    pub use libctypes::*;
44}
45
46#[macro_use]
47mod utils;
48
49#[cfg(feature = "fd")]
50mod fd_ops;
51#[cfg(feature = "fs")]
52mod fs;
53#[cfg(any(feature = "select", feature = "epoll"))]
54mod io_mpx;
55#[cfg(feature = "alloc")]
56mod malloc;
57#[cfg(feature = "net")]
58mod net;
59#[cfg(feature = "pipe")]
60mod pipe;
61#[cfg(feature = "multitask")]
62mod pthread;
63#[cfg(feature = "alloc")]
64mod strftime;
65#[cfg(feature = "fp-simd")]
66mod strtod;
67
68mod errno;
69mod io;
70mod mktime;
71mod rand;
72mod resource;
73mod setjmp;
74mod sys;
75mod time;
76mod unistd;
77
78#[cfg(feature = "fd")]
79pub use self::fd_ops::{ax_fcntl, close, dup, dup2, dup3};
80#[cfg(feature = "fs")]
81pub use self::fs::{ax_open, fstat, getcwd, lseek, lstat, rename, stat};
82#[cfg(not(test))]
83pub use self::io::write;
84#[cfg(feature = "select")]
85pub use self::io_mpx::select;
86#[cfg(feature = "epoll")]
87pub use self::io_mpx::{epoll_create, epoll_ctl, epoll_wait};
88#[cfg(feature = "alloc")]
89pub use self::malloc::{free, malloc};
90#[cfg(feature = "net")]
91pub use self::net::{
92    accept, bind, connect, freeaddrinfo, getaddrinfo, getpeername, getsockname, listen, recv,
93    recvfrom, send, sendto, shutdown, socket,
94};
95#[cfg(feature = "pipe")]
96pub use self::pipe::pipe;
97#[cfg(feature = "multitask")]
98pub use self::pthread::{pthread_create, pthread_exit, pthread_join, pthread_self};
99#[cfg(feature = "multitask")]
100pub use self::pthread::{pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock};
101#[cfg(feature = "alloc")]
102pub use self::strftime::strftime;
103#[cfg(feature = "fp-simd")]
104pub use self::strtod::{strtod, strtof};
105pub use self::{
106    errno::strerror,
107    io::{read, writev},
108    mktime::mktime,
109    rand::{rand, random, srand},
110    resource::{getrlimit, setrlimit},
111    setjmp::{longjmp, setjmp},
112    sys::sysconf,
113    time::{clock_gettime, nanosleep},
114    unistd::{abort, exit, getpid},
115};