lib.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //! **Ralloc:** The memory efficient allocator.
  2. //!
  3. //! This crates define the user space allocator for Redox, which emphasizes performance and memory
  4. //! efficiency.
  5. #![cfg_attr(feature = "allocator", allocator)]
  6. #![cfg_attr(feature = "clippy", feature(plugin))]
  7. #![cfg_attr(feature = "clippy", plugin(clippy))]
  8. #![no_std]
  9. #![feature(allocator, const_fn, core_intrinsics, stmt_expr_attributes, drop_types_in_const,
  10. nonzero, optin_builtin_traits, type_ascription, question_mark, try_from)]
  11. #![warn(missing_docs, cast_precision_loss, cast_sign_loss, cast_possible_wrap,
  12. cast_possible_truncation, filter_map, if_not_else, items_after_statements,
  13. invalid_upcast_comparisons, mutex_integer, nonminimal_bool, shadow_same, shadow_unrelated,
  14. single_match_else, string_add, string_add_assign, wrong_pub_self_convention)]
  15. #[cfg(feature = "libc_write")]
  16. #[macro_use]
  17. mod write;
  18. #[macro_use]
  19. mod log;
  20. mod allocator;
  21. mod block;
  22. mod bookkeeper;
  23. mod fail;
  24. mod leak;
  25. mod prelude;
  26. mod ptr;
  27. mod sync;
  28. mod sys;
  29. mod vec;
  30. pub use allocator::{lock, Allocator};
  31. pub use fail::set_oom_handler;
  32. pub use sys::sbrk;
  33. /// Rust allocation symbol.
  34. #[no_mangle]
  35. #[inline]
  36. #[cfg(feature = "allocator")]
  37. pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
  38. lock().alloc(size, align)
  39. }
  40. /// Rust deallocation symbol.
  41. #[no_mangle]
  42. #[inline]
  43. #[cfg(feature = "allocator")]
  44. pub unsafe extern fn __rust_deallocate(ptr: *mut u8, size: usize, _align: usize) {
  45. lock().free(ptr, size);
  46. }
  47. /// Rust reallocation symbol.
  48. #[no_mangle]
  49. #[inline]
  50. #[cfg(feature = "allocator")]
  51. pub unsafe extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
  52. lock().realloc(ptr, old_size, size, align)
  53. }
  54. /// Rust reallocation inplace symbol.
  55. #[no_mangle]
  56. #[inline]
  57. #[cfg(feature = "allocator")]
  58. pub unsafe extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize, size: usize, _align: usize) -> usize {
  59. if lock().realloc_inplace(ptr, old_size, size).is_ok() {
  60. size
  61. } else {
  62. old_size
  63. }
  64. }
  65. /// Get the usable size of the some number of bytes of allocated memory.
  66. #[no_mangle]
  67. #[inline]
  68. #[cfg(feature = "allocator")]
  69. pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
  70. // Yay! It matches exactly.
  71. size
  72. }