Skip to content
ProcMapsLoadFrom

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 bytes
  • Buf * : parse the buffer’s bytes
  • (Zstr bytes, u64 len, alloc) : parse len bytes at bytes

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)
    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));
        out->entries = VecInitT(out->entries, alloc);
        if (!FileIsOpen(f)) {
            LOG_ERROR("ProcMapsLoadFrom: file is not open");
            ProcMapsDeinit(out);
            return false;
        }
        if (!proc_maps_read_all(f, &out->raw)) {
            LOG_ERROR("ProcMapsLoadFrom: FileRead failed");
            ProcMapsDeinit(out);
            return false;
    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));
    // 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);
    }
    
        ProcMaps m;
        bool     loaded = ProcMapsLoadFrom(&m, &rf, &alloc);
        FileClose(&rf);
    
        ProcMaps m;
        bool     loaded = ProcMapsLoadFrom(&m, &dir, base);
        FileClose(&dir);
Last updated on