Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rust-alloc-no-stdlib

> 编程语言
Open source

An interface to a generic allocator so a no_std rust library can allocate memory, with, or without stdlib being linked.

179 stars0 likes1 views
WebsiteGitHub

About

An interface to a generic allocator so a no_std rust library can allocate memory, with, or without stdlib being linked.

Framework for allocating memory in #![no_std] modules.

Requirements

  • Rust 1.6

Documentation

Currently there is no standard way to allocate memory from within a module that is no_std. This provides a mechanism to describe a memory allocation that can be satisfied entirely on the stack, by unsafely linking to calloc, or by unsafely referencing a mutable global variable. This library currently will leak memory if free_cell isn't specifically invoked on memory.

However, if linked by a library that actually can depend on the stdlib then that library can simply pass in a few allocators and use the standard Box allocation and will free automatically.

This library should also make it possible to entirely jail a rust application that needs dynamic allocations by preallocating a maximum limit of data upfront using calloc and using seccomp to disallow future syscalls.

Usage

There are 3 modes for allocating memory, each with advantages and disadvantages

On the stack

This is possible without the stdlib at all However, this eats into the natural ulimit on the stack depth and generally limits the program to only a few megs of dynamically allocated data

Example:

…

On the heap, but uninitialized

This does allocate data every time it is requested, but it does not allocate the memory, so naturally it is unsafe. The caller must initialize the memory properly

rust
let mut halloc = unsafe{HeapAllocUninitialized::::new()};
{ // heap test
    let mut x = halloc.alloc_cell(100000);
    x[0] = 4;
    let mut y = halloc.alloc_cell(110000);
    y[0] = 5;
    let mut z = halloc.alloc_cell(120000);
    z[0] = 6;
    assert_eq!(y[0], 5);
    halloc.free_cell(y);
    assert_eq!(x[0], 4);
    assert_eq!(x[9], 0);
    assert_eq!(z[0], 6);
    ...
}

On the heap in a single pool allocation

This does a single big allocation on the heap, after which no further usage of the stdlib will happen. This can be useful for a jailed application that wishes to restrict syscalls at this point

…

What changed in 3.0.0

Forbid unsafe and moving of the Calloc malloc into the unsafe bin so we can forbid unsafe using the compiler.

Note: this is a breaking change for downstreams that referenced CallocBackingStore/AllocatorC without the "unsafe" feature (e.g. brotli's "seccomp" feature, which should now also enable alloc-no-stdlib/unsafe).

Contributors

  • Daniel Reiter Horn

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言