Function tikv_jemalloc_ctl::raw::read_str_mib
source · pub unsafe fn read_str_mib(mib: &[usize]) -> Result<&'static [u8]>
Expand description
Uses the MIB mib
as key to the MALLCTL NAMESPACE and reads its value.
The name_to_mib
API translates a string of the key (e.g. arenas.nbins
)
to a mib
(Management Information Base).
§Safety
This function is unsafe because if the key does not return a pointer to a null-terminated string the behavior is undefined.
For example, a key for a u64
value can be used to read a pointer on 64-bit
platform, where this pointer will point to the address denoted by the u64
s
representation. Also, a key to a *mut extent_hooks_t
will return a pointer
that will not point to a null-terminated string.
This function needs to compute the length of the string by looking for the
null-terminator: \0
. This requires reading the memory behind the pointer.
If the pointer is invalid (e.g. because it was converted from a u64
that
does not represent a valid address), reading the string to look for \0
will dereference a non-dereferenceable pointer, which is undefined behavior.
If the pointer is valid but it does not point to a null-terminated string,
looking for \0
will read garbage and might end up reading out-of-bounds,
which is undefined behavior.