symbols.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //! Rust allocation symbols.
  2. // TODO: Remove this, this is a false positive.
  3. #![allow(private_no_mangle_fns)]
  4. use allocator;
  5. /// Rust allocation symbol.
  6. #[linkage = "external"]
  7. #[no_mangle]
  8. #[inline]
  9. pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
  10. allocator::alloc(size, align)
  11. }
  12. /// Rust deallocation symbol.
  13. #[linkage = "external"]
  14. #[no_mangle]
  15. #[inline]
  16. pub unsafe extern fn __rust_deallocate(ptr: *mut u8, size: usize, _align: usize) {
  17. allocator::free(ptr, size);
  18. }
  19. /// Rust reallocation symbol.
  20. #[linkage = "external"]
  21. #[no_mangle]
  22. #[inline]
  23. pub unsafe extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
  24. allocator::realloc(ptr, old_size, size, align)
  25. }
  26. /// Rust reallocation inplace symbol.
  27. #[linkage = "external"]
  28. #[no_mangle]
  29. #[inline]
  30. pub unsafe extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize, size: usize, _align: usize) -> usize {
  31. if allocator::realloc_inplace(ptr, old_size, size).is_ok() {
  32. size
  33. } else {
  34. old_size
  35. }
  36. }
  37. /// Get the usable size of the some number of bytes of allocated memory.
  38. #[linkage = "external"]
  39. #[no_mangle]
  40. #[inline]
  41. pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
  42. // Yay! It matches exactly.
  43. size
  44. }