lib.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #![no_std]
  7. #![feature(allocator, const_fn, core_intrinsics, stmt_expr_attributes, drop_types_in_const,
  8. nonzero)]
  9. #![warn(missing_docs)]
  10. #[cfg(target_os = "redox")]
  11. extern crate system;
  12. #[cfg(not(target_os = "redox"))]
  13. #[macro_use]
  14. extern crate syscall;
  15. mod allocator;
  16. mod block;
  17. mod bookkeeper;
  18. mod ptr;
  19. mod sync;
  20. mod sys;
  21. mod vec;
  22. pub mod fail;
  23. pub use allocator::{free, alloc, realloc, realloc_inplace};
  24. /// Rust allocation symbol.
  25. #[no_mangle]
  26. #[cfg(feature = "allocator")]
  27. pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
  28. alloc(size, align)
  29. }
  30. /// Rust deallocation symbol.
  31. #[no_mangle]
  32. #[cfg(feature = "allocator")]
  33. pub unsafe extern fn __rust_deallocate(ptr: *mut u8, size: usize, _align: usize) {
  34. free(ptr, size);
  35. }
  36. /// Rust reallocation symbol.
  37. #[no_mangle]
  38. #[cfg(feature = "allocator")]
  39. pub unsafe extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
  40. realloc(ptr, old_size, size, align)
  41. }
  42. /// Rust reallocation inplace symbol.
  43. #[no_mangle]
  44. #[cfg(feature = "allocator")]
  45. pub unsafe extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize, size: usize, _align: usize) -> usize {
  46. if realloc_inplace(ptr, old_size, size).is_ok() {
  47. size
  48. } else {
  49. old_size
  50. }
  51. }
  52. /// Get the usable size of the some number of bytes of allocated memory.
  53. #[no_mangle]
  54. #[cfg(feature = "allocator")]
  55. pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
  56. // Yay! It matches exactly.
  57. size
  58. }