xref: /drstd/dlibc/src/lib.rs (revision b38c79420b3f9b2af3cf74b30d9faaadb20eb8b0)
1 //! libc - Raw FFI bindings to platforms' system libraries
2 //!
3 //! [Documentation for other platforms][pd].
4 //!
5 //! [pd]: https://rust-lang.github.io/libc/#platform-specific-documentation
6 //!
7 
8 #![feature(core_intrinsics)]
9 #![feature(linkage)]
10 #![feature(thread_local)]
11 #![feature(start)]
12 #![feature(naked_functions)]
13 #![feature(slice_internals)]
14 #![feature(c_variadic)]
15 #![feature(stmt_expr_attributes)]
16 #![feature(lang_items)]
17 
18 
19 #![crate_name = "dlibc"]
20 #![crate_type = "staticlib"]
21 #![allow(
22     renamed_and_removed_lints, // Keep this order.
23     unknown_lints, // Keep this order.
24     bad_style,
25     overflowing_literals,
26     improper_ctypes,
27     // This lint is renamed but we run CI for old stable rustc so should be here.
28     redundant_semicolon,
29     redundant_semicolons,
30     unused_macros,
31     unused_macro_rules,
32     internal_features,
33     hidden_glob_reexports,
34     ambiguous_glob_reexports,
35 )]
36 #![cfg_attr(libc_deny_warnings, deny(warnings))]
37 // Attributes needed when building as part of the standard library
38 #![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
39 #![cfg_attr(libc_thread_local, feature(thread_local))]
40 // Enable extra lints:
41 #![cfg_attr(feature = "extra_traits", deny(missing_debug_implementations))]
42 //#![deny(missing_copy_implementations, safe_packed_borrows)]
43 #![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
44 #![cfg_attr(feature = "rustc-dep-of-std", no_core)]
45 #![cfg_attr(libc_const_extern_fn_unstable, feature(const_extern_fn))]
46 
47 #[macro_use]
48 extern crate alloc;
49 extern crate core_io;
50 #[macro_use]
51 extern crate lazy_static;
52 extern crate memchr;
53 extern crate goblin;
54 extern crate rand;
55 extern crate posix_regex;
56 extern crate cbitset;
57 extern crate num_traits;
58 
59 
60 #[macro_use]
61 mod macros;
62 
63 cfg_if! {
64     if #[cfg(feature = "rustc-dep-of-std")] {
65         extern crate rustc_std_workspace_core as core;
66         #[allow(unused_imports)]
67         use core::iter;
68         #[allow(unused_imports)]
69         use core::ops;
70         #[allow(unused_imports)]
71         use core::option;
72     }
73 }
74 cfg_if! {
75     if #[cfg(libc_priv_mod_use)] {
76         #[cfg(libc_core_cvoid)]
77         #[allow(unused_imports)]
78         use core::ffi;
79         #[allow(unused_imports)]
80         use core::fmt;
81         #[allow(unused_imports)]
82         use core::hash;
83         #[allow(unused_imports)]
84         use core::num;
85         #[allow(unused_imports)]
86         use core::mem;
87         #[doc(hidden)]
88         #[allow(unused_imports)]
89         use core::clone::Clone;
90         #[doc(hidden)]
91         #[allow(unused_imports)]
92         use core::marker::{Copy, Send, Sync};
93         #[doc(hidden)]
94         #[allow(unused_imports)]
95         use core::option::Option;
96     } else {
97         #[doc(hidden)]
98         #[allow(unused_imports)]
99         pub use core::fmt;
100         #[doc(hidden)]
101         #[allow(unused_imports)]
102         pub use core::hash;
103         #[doc(hidden)]
104         #[allow(unused_imports)]
105         pub use core::num;
106         #[doc(hidden)]
107         #[allow(unused_imports)]
108         pub use core::mem;
109         #[doc(hidden)]
110         #[allow(unused_imports)]
111         pub use core::clone::Clone;
112         #[doc(hidden)]
113         #[allow(unused_imports)]
114         pub use core::marker::{Copy, Send, Sync};
115         #[doc(hidden)]
116         #[allow(unused_imports)]
117         pub use core::option::Option;
118     }
119 }
120 
121 #[cfg(target_os = "dragonos")]
122 pub mod unix;
123 #[cfg(target_os = "dragonos")]
124 pub use unix::*;
125 #[cfg(target_os = "dragonos")]
126 #[macro_use]
127 extern crate dsc;
128 #[cfg(target_os = "dragonos")]
129 #[global_allocator]
130 static ALLOCATOR: crate::unix::platform::allocator::Allocator = crate::unix::platform::allocator::ALLOCATOR;
131 #[cfg(target_os = "dragonos")]
132 pub use crate::unix::macros::*;
133 
134 
135 
136 #[lang = "eh_personality"]
137 extern "C" fn eh_personality() {}
138 
139 #[cfg(target_os = "dragonos")]
140 #[panic_handler]
141 fn panic_handler(info: &core::panic::PanicInfo) -> ! {
142     // 在这里执行自定义的处理逻辑
143     println!("Panic occurred: {:?}", info);
144 
145     // 可以选择进行一些清理或其他操作
146 
147     // 结束程序,例如通过调用 `std::process::exit`
148     crate::unix::platform::pal::exit(0);
149 }