vita-system-alloc-wrapper 0.1.0

A proxy for std::alloc::System which wraps dealloc in std::hint::black_box
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 3.34 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • vita-rust/vita-newlib-shims
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nikarh
vita-system-alloc-wrapper-0.1.0 has been yanked.

vita-system-alloc-wrapper

The standard library in Rust has a std::alloc::System allocator, which internally calls libc::malloc and libc::free for allocations. For PlayStation Vita, these functions are provided by newlib, which uses a preallocated pool for heap memory.

This should work and works for the majority of cases. Unfortunately though, with the -O3 optimization level compiled specifically for the PlayStation Vita target, it is possible for LLVM to incorrectly optimize libc::free calls, leading to crashes when heap-allocated structs are dropped in Rust.

This crate does a hack to fix that by providing a custom allocator, which proxies, all calls to std::alloc::System allocator, and wrapping dealloc call in std::hint::black_box, which prevents LLVM from doing any optimizations on libc::free call.

If you are experiencing crashes in Drop calls in seemingly correct code on PlayStation Vita, try adding this crate as a dependency, and registering provided allocator as a GlobalAllocator:

#[cfg(target_os = "vita")]
#[global_allocator]
static GLOBAL: vita_system_alloc_wrapper::SystemAllocWrapper = vita_system_alloc_wrapper::SystemAllocWrapper;