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)
        out->allocator = alloc;
        out->cache     = VecInitT(out->cache, alloc);
        if (!ProcMapsLoad(&out->maps, alloc)) {
            VecDeinit(&out->cache);
            MemSet(out, 0, sizeof(*out));
    bool proc_maps_load(ProcMaps *out, Allocator *alloc) {
        if (!out || !alloc) {
            LOG_FATAL("ProcMapsLoad: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        File f = FileOpen("/proc/self/maps", "rb");
        if (!FileIsOpen(&f)) {
            LOG_ERROR("ProcMapsLoad: FileOpen(/proc/self/maps) failed");
            ProcMapsDeinit(out);
            return false;
            u64 grown_to = StrLen(&out->raw) + CHUNK + 1;
            if (!StrReserve(&out->raw, grown_to)) {
                LOG_ERROR("ProcMapsLoad: failed to grow buffer");
                FileClose(&f);
                ProcMapsDeinit(out);
            i64 n = FileRead(&f, StrEnd(&out->raw), CHUNK);
            if (n < 0) {
                LOG_ERROR("ProcMapsLoad: FileRead failed");
                FileClose(&f);
                ProcMapsDeinit(out);
        FileClose(&f);
        if (StrLen(&out->raw) == 0) {
            LOG_ERROR("ProcMapsLoad: /proc/self/maps was empty");
            ProcMapsDeinit(out);
            return false;
        ProcMaps         maps;
        bool             got = false;
        if (ProcMapsLoad(&maps, ALLOCATOR_OF(&a))) {
            for (u64 i = 0; i < VecLen(&maps.entries); ++i) {
                const ProcMapEntry *m = VecPtrAt(&maps.entries, i);
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        volatile int local = 0xABCD;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        ProcMaps         maps;
    
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
        DefaultAllocator alloc = DefaultAllocatorInit();
        ProcMaps         maps;
        if (!ProcMapsLoad(&maps, ALLOCATOR_OF(&alloc))) {
            DefaultAllocatorDeinit(&alloc);
            return false;
Last updated on