ProcMapsLoadFrom
Description
Parse /proc/self/maps-format text from an in-memory source instead of the live kernel file. The bytes are COPIED into out->raw, so each entry’s borrowed path stays valid for the ProcMaps lifetime. Lets callers parse crafted or captured maps text without a live /proc (tests, and future core-file / remote backends).
ProcMapsLoadFrom(out, src[, alloc]) dispatches on the source type:
File *: read the open file to EOF (caller still owns/closes it)Str *: parse the string’s bytesBuf *: parse the buffer’s bytes(Zstr bytes, u64 len, alloc): parselenbytes atbytes
The File/Str/Buf forms take an optional trailing allocator (defaulting to MisraScope); the raw (bytes, len) form takes an explicit allocator.
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Populated on success; left zeroed on failure. |
alloc |
in | Allocator for out->raw and the entries vector. |
Success
Returns true; out->entries is populated (possibly empty).
Failure
Returns false; logs the failing step. out is left zeroed.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ProcMaps.c:258:
bool proc_maps_load_from_file(ProcMaps *out, File *f, Allocator *alloc) {
if (!out || !f || !alloc) {
LOG_FATAL("ProcMapsLoadFrom: NULL argument");
}
MemSet(out, 0, sizeof(*out));- In
ProcMaps.c:264:
out->entries = VecInitT(out->entries, alloc);
if (!FileIsOpen(f)) {
LOG_ERROR("ProcMapsLoadFrom: file is not open");
ProcMapsDeinit(out);
return false;- In
ProcMaps.c:269:
}
if (!proc_maps_read_all(f, &out->raw)) {
LOG_ERROR("ProcMapsLoadFrom: FileRead failed");
ProcMapsDeinit(out);
return false;- In
ProcMaps.c:278:
bool proc_maps_load_from_bytes(ProcMaps *out, const u8 *bytes, u64 len, Allocator *alloc) {
if (!out || !alloc || (!bytes && len)) {
LOG_FATAL("ProcMapsLoadFrom: NULL argument");
}
MemSet(out, 0, sizeof(*out));- In
ProcMaps.c:23:
// line is skipped, not a hard failure).
static bool pm_load_text(ProcMaps *m, Zstr text, DefaultAllocator *alloc) {
return ProcMapsLoadFrom(m, text, ZstrLen(text), alloc);
}- In
ProcMaps.c:607:
ProcMaps m;
bool loaded = ProcMapsLoadFrom(&m, &rf, &alloc);
FileClose(&rf);- In
ProcMaps.c:648:
ProcMaps m;
bool loaded = ProcMapsLoadFrom(&m, &dir, base);
FileClose(&dir);
Last updated on