Skip to content

ProcMapsLoad

Description

Read and parse /proc/self/maps. The full file is held inside out->raw for the lifetime of the ProcMaps so each entry’s path can borrow from it without a separate copy.

Parameters

Name Direction Description
out out Populated on success.
alloc in Allocator for the raw buffer and entries vector.

Success

Returns true; out->entries is populated.

Failure

Returns false; logs the failing step. out is left zeroed.

Usage example (Cross-references)

Usage examples (Cross-references)
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        out->allocator = alloc;
        out->cache     = VecInitT(out->cache, alloc);
        if (!ProcMapsLoad(&out->maps, alloc)) {
            VecDeinit(&out->cache);
            MemSet(out, 0, sizeof(*out));
    // ---------------------------------------------------------------------------
    
    bool ProcMapsLoad(ProcMaps *out, Allocator *alloc) {
        if (!out || !alloc) {
            LOG_ERROR("ProcMapsLoad: NULL argument");
    bool ProcMapsLoad(ProcMaps *out, Allocator *alloc) {
        if (!out || !alloc) {
            LOG_ERROR("ProcMapsLoad: NULL argument");
            return false;
        }
        FILE *f = fopen("/proc/self/maps", "rb");
        if (!f) {
            LOG_SYS_ERROR("ProcMapsLoad: fopen(/proc/self/maps) failed");
            ProcMapsDeinit(out);
            return false;
            u64 grown_to = out->raw.length + CHUNK + 1;
            if (!StrReserve(&out->raw, grown_to)) {
                LOG_ERROR("ProcMapsLoad: failed to grow buffer");
                fclose(f);
                ProcMapsDeinit(out);
        fclose(f);
        if (out->raw.length == 0) {
            LOG_ERROR("ProcMapsLoad: /proc/self/maps was empty");
            ProcMapsDeinit(out);
            return false;
Last updated on