Crates.io | bitcoin-support |
lib.rs | bitcoin-support |
version | 0.1.16-alpha.0 |
source | src |
created_at | 2023-01-17 22:54:06.174926 |
updated_at | 2023-03-31 03:19:39.453521 |
description | allocators, memory cleansing, events, locked pools, memory arenas, etc |
homepage | |
repository | https://github.com/klebz/bitcoin-rs |
max_upload_size | |
id | 761376 |
size | 135,539 |
bitcoin-support
This Rust crate is a direct translation of the Bitcoin codebase from C++ to Rust. It is currently in the process of translation, and it is possible that some function bodies are still being translated.
The bitcoin-support
crate provides a set of
common utilities and data structures that are used
throughout the Bitcoin system. These include
memory allocators, statistics and debugging
utilities, locking primitives, and secure string
and allocator implementations.
This crate also provides an Arena allocator, which is a specialized type of memory allocator that provides constant time allocation and deallocation of small, fixed-size objects. Additionally, it provides a LockedPageArena, which is a memory allocator that allocates and frees locked memory pages, preventing the data contained within from being swapped out to disk.
The crate also includes tools for obtaining event objects and HTTP connections.
Note that while there may not be any specific
mathematical equations or concepts involved in the
bitcoin-support
crate, its contents are critical
to the correct operation of the Bitcoin system.
166> thanks -- could you describe the interface in more depth?
Sure, here is a more in-depth description of the
interface provided by the bitcoin-support
crate:
alloc(size: usize, alignment: usize) -> *mut u8
: Allocates a new block of memory in the
arena.
free(ptr: *mut u8, size: usize, alignment: usize)
: Frees a block of memory previously
allocated in the arena.
address_in_arena(ptr: *const u8) -> bool
:
Checks whether a given memory address is located
within the arena.
stats() -> ArenaStats
: Returns statistics
about the current state of the arena.
new() -> ArenaChunkToSizeMap
: Creates a new
ArenaChunkToSizeMap
.
insert(chunk: *mut u8, size: usize)
: Inserts
a new mapping between a chunk of memory in the
arena and its size.
remove(chunk: *mut u8)
: Removes the mapping
between a chunk of memory and its size.
new() -> ArenaSizeToChunkSortedMap
: Creates
a new ArenaSizeToChunkSortedMap
.
insert(size: usize, chunk: *mut u8)
: Inserts
a new mapping between a size and a chunk of
memory in the arena.
remove(size: usize, chunk: *mut u8)
: Removes
the mapping between a size and a chunk of
memory.
new(map: &ArenaSizeToChunkSortedMap, size: usize) -> ArenaSizeToChunkSortedMapIterator
:
Creates a new iterator over
a ArenaSizeToChunkSortedMap
.
next() -> Option<*mut u8>
: Returns the next
chunk of memory in the arena with the specified
size, or None
if there are no more chunks.
new(chunk_size: usize, max_size: usize) -> Result<LockedPageArena, String>
: Creates a new
LockedPageArena
with the specified chunk size
and maximum size.
alloc(size: usize) -> *mut u8
: Allocates a new
block of memory in the arena.
free(ptr: *mut u8, size: usize)
: Frees a block
of memory previously allocated in the arena.
stats() -> ArenaStats
: Returns statistics
about the current state of the arena.
new(page_size: usize, chunk_size: usize, max_size: usize) -> Result<LockedPool, String>
:
Creates a new LockedPool
with the specified
page size, chunk size, and maximum size.
alloc(size: usize) -> *mut u8
: Allocates a new
block of memory in the pool.
free(ptr: *mut u8, size: usize)
: Frees a block
of memory previously allocated in the pool.
stats() -> ArenaStats
: Returns statistics
about the current state of the pool.
new() -> LockedPoolManager
: Creates a new
LockedPoolManager
.
add_pool(pool: LockedPool)
: Adds a new pool to
the pool manager.
alloc(size: usize) -> *mut u8
: Allocates a new
block of memory from the pool manager.
free(ptr: *mut u8, size: usize)
: Frees a block
of memory previously allocated from the pool
manager.
stats() -> ArenaStats
: Returns statistics
about the current state of the pool manager.
new() -> SecureAllocator
: Creates a new
SecureAllocator
.
allocate(size: usize) -> *mut u8
: Allocates
167> thanks! please keep going! you were on SecureAllocator
Sure! Continuing from where I left off:
The SecureAllocator
trait defines an interface
for a secure memory allocator that ensures that
memory is zeroed out before it is
deallocated. This is a security measure to prevent
sensitive data from being left behind in memory
after it is freed.
The SecureString
type is a string type that is
backed by a secure memory allocator, ensuring that
the contents of the string are zeroed out when it
is dropped.
The SerializeData
trait defines an interface for
serializing data into a binary format, and
deserializing data from a binary format. This is
used for encoding and decoding Bitcoin
transactions, blocks, and other data structures.
The ZeroAfterFreeAllocator
is a memory allocator
that zeroes out memory after it is freed. This is
similar to the SecureAllocator
trait, but is
implemented as a concrete type rather than
a trait.
The get_unique_path
function returns a unique
path that can be used for temporary files or
directories. This is useful for creating temporary
files that won't clash with other processes.
I hope that helps! Let me know if you have any other questions.
168> thanks -- is there anything else you can think of that we ought to know about this crate?
One important thing to note about the
bitcoin-support
crate is that it contains
a number of low-level utility functions and
structures that are used throughout the Bitcoin
codebase. These include memory allocation
functions, arena memory allocation structures, and
secure string handling functions. These low-level
components are critical to the safe and efficient
operation of the Bitcoin system, and their proper
implementation and use is of utmost importance.