lib.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #![no_std]
  2. #![allow(non_camel_case_types)]
  3. #![allow(non_upper_case_globals)]
  4. #![allow(unused_variables)]
  5. #![feature(alloc_error_handler)]
  6. #![feature(allocator_api)]
  7. #![feature(array_chunks)]
  8. #![feature(asm_const)]
  9. #![feature(box_into_pin)]
  10. #![feature(c_variadic)]
  11. #![feature(const_btree_new)]
  12. #![feature(core_intrinsics)]
  13. #![feature(lang_items)]
  14. #![feature(linkage)]
  15. #![feature(stmt_expr_attributes)]
  16. #![feature(str_internals)]
  17. #![feature(thread_local)]
  18. #![feature(vec_into_raw_parts)]
  19. #![allow(clippy::cast_lossless)]
  20. #![allow(clippy::cast_ptr_alignment)]
  21. #![allow(clippy::derive_hash_xor_eq)]
  22. #![allow(clippy::eval_order_dependence)]
  23. #![allow(clippy::mut_from_ref)]
  24. // TODO: fix these
  25. #![warn(unaligned_references)]
  26. #[macro_use]
  27. extern crate alloc;
  28. extern crate cbitset;
  29. extern crate core_io;
  30. extern crate goblin;
  31. #[macro_use]
  32. extern crate lazy_static;
  33. extern crate memchr;
  34. #[macro_use]
  35. extern crate memoffset;
  36. extern crate posix_regex;
  37. extern crate rand;
  38. #[cfg(target_os = "linux")]
  39. #[macro_use]
  40. extern crate sc;
  41. // TODO: fix this: adjust to dragonos sc
  42. #[cfg(target_os = "dragonos")]
  43. #[macro_use]
  44. extern crate dsc;
  45. #[cfg(target_os = "redox")]
  46. extern crate syscall;
  47. #[cfg(target_os = "redox")]
  48. extern crate spin;
  49. #[macro_use]
  50. mod macros;
  51. pub mod c_str;
  52. pub mod c_vec;
  53. pub mod cxa;
  54. pub mod db;
  55. pub mod fs;
  56. pub mod header;
  57. pub mod io;
  58. pub mod ld_so;
  59. pub mod platform;
  60. pub mod start;
  61. pub mod sync;
  62. use crate::platform::{Allocator, Pal, Sys, NEWALLOCATOR};
  63. #[global_allocator]
  64. static ALLOCATOR: Allocator = NEWALLOCATOR;
  65. #[no_mangle]
  66. pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! {
  67. use core::fmt::Write;
  68. let mut w = platform::FileWriter(2);
  69. let _ = w.write_fmt(format_args!("RELIBC PANIC: {}\n", pi));
  70. Sys::exit(1);
  71. }
  72. #[cfg(not(test))]
  73. #[panic_handler]
  74. #[linkage = "weak"]
  75. #[no_mangle]
  76. pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
  77. relibc_panic(pi)
  78. }
  79. #[cfg(not(test))]
  80. #[lang = "eh_personality"]
  81. #[no_mangle]
  82. #[linkage = "weak"]
  83. pub extern "C" fn rust_eh_personality() {}
  84. #[cfg(not(test))]
  85. #[alloc_error_handler]
  86. #[linkage = "weak"]
  87. #[no_mangle]
  88. pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
  89. use core::fmt::Write;
  90. let mut w = platform::FileWriter(2);
  91. let _ = w.write_fmt(format_args!(
  92. "RELIBC OOM: {} bytes aligned to {} bytes\n",
  93. layout.size(),
  94. layout.align()
  95. ));
  96. Sys::exit(1);
  97. }
  98. #[cfg(not(test))]
  99. #[allow(non_snake_case)]
  100. #[linkage = "weak"]
  101. #[no_mangle]
  102. pub extern "C" fn _Unwind_Resume() -> ! {
  103. use core::fmt::Write;
  104. let mut w = platform::FileWriter(2);
  105. let _ = w.write_str("_Unwind_Resume\n");
  106. Sys::exit(1);
  107. }