| Crates.io | polished_memory |
| lib.rs | polished_memory |
| version | 1.0.1 |
| created_at | 2025-06-12 08:53:29.574261+00 |
| updated_at | 2025-06-12 20:25:26.612397+00 |
| description | Memory management for the Polished OS project. |
| homepage | |
| repository | https://codeberg.org/ofluffydev/polished |
| max_upload_size | |
| id | 1709564 |
| size | 12,230 |
Polished Memory is a Rust library providing fundamental memory manipulation routines—memset, memcmp, memcpy, and memmove—for use in no_std environments such as kernels, bootloaders, or embedded systems. It is a core component of the Polished OS project, ensuring that essential low-level memory operations are available even when the Rust standard library is not.
Version 1.0.0 and above: This crate is considered stable and safe for production use. The API will not change in a breaking way without a major version bump.
This crate implements the following C-style memory functions:
memset: Sets a block of memory to a specific byte value.memcmp: Compares two blocks of memory byte by byte.memcpy: Copies a block of memory from one location to another (non-overlapping).memmove: Copies a block of memory from one location to another, correctly handling overlapping regions.All functions are marked with #[no_mangle] and use C ABI (extern "C"), making them available to both Rust and C code, and ensuring the correct symbol names are exported for the linker.
In no_std Rust environments, the standard library is unavailable—including its implementations of these essential memory routines. However, the Rust compiler and core library expect these symbols to exist, as they are used for:
core crate, which is always linked in no_std projects, assumes these functions are present for low-level operations.If these symbols are missing, linking will fail or runtime errors may occur. By providing them, this crate ensures that Rust code (and any C code linked in) can safely and efficiently perform basic memory operations, even in bare-metal or OS development contexts.
let x = [0u8; 1024]; or dst.copy_from_slice(src), the compiler may generate calls to memset or memcpy.clone_from_slice, rely on these routines for performance and correctness.All functions in this crate are unsafe and require the caller to uphold strict invariants regarding pointer validity, alignment, and region overlap. Incorrect usage can lead to undefined behavior, memory corruption, or security vulnerabilities. See each function's documentation for details.
Add this crate to your no_std project to satisfy the compiler's requirements for these memory routines. You may also use these functions directly if needed:
// Example: Zero a buffer
unsafe {
memory::memset(buf.as_mut_ptr(), 0, buf.len());
}
Typically, you do not need to call these functions directly—Rust and the core library will use them automatically as needed.
unsafe due to raw pointer manipulation.#![no_std] and suitable for bare-metal or OS development.This library is licensed under the zlib License. See the root of the repository for details.
Polished Memory is part of the Polished OS project. Contributions and feedback are welcome!