Skip to content

ProcMapEntry

Description

One line of /proc/self/maps. path is borrowed from the ProcMaps.raw buffer and stays valid until ProcMapsDeinit. May be empty for anonymous mappings (heap, stacks, vdso, etc.).

Usage example (Cross-references)

Usage examples (Cross-references)
        // mapping of the test binary itself.
        u64                 self_addr = (u64)(uintptr_t)&test_procmaps_find_self;
        const ProcMapEntry *entry     = ProcMapsFindByAddr(&maps, self_addr);
    
        bool ok = entry != NULL && (entry->perms & PROC_MAP_PERM_EXEC) != 0;
        u64 addr = (u64)(uintptr_t)runtime_addr;
    
        const ProcMapEntry *entry = ProcMapsFindByAddr(&self->maps, addr);
        if (!entry || !entry->path || entry->path[0] == '\0') {
            return false;
    // ---------------------------------------------------------------------------
    
    static bool parse_one_line(char **cursor_inout, char *end, ProcMapEntry *out) {
        const char *p          = *cursor_inout;
        const char *line_start = p;
        char *end    = out->raw.data + out->raw.length;
        while (cursor < end) {
            ProcMapEntry e = {0};
            if (!parse_one_line(&cursor, end, &e)) {
                // Skip past whatever line we couldn't parse.
    }
    
    const ProcMapEntry *ProcMapsFindByAddr(const ProcMaps *self, u64 addr) {
        if (!self)
            return NULL;
            return NULL;
        for (u64 i = 0; i < self->entries.length; ++i) {
            const ProcMapEntry *e = &self->entries.data[i];
            if (addr >= e->start && addr < e->end) {
                return e;
        u64         file_offset; // offset within the backing file
        const char *path;        // backing file path, or "" if anonymous
    } ProcMapEntry;
    
    typedef Vec(ProcMapEntry) ProcMapEntries;
    } ProcMapEntry;
    
    typedef Vec(ProcMapEntry) ProcMapEntries;
    
    typedef struct ProcMaps {
    /// FAILURE : Returns NULL if `addr` is not in any mapping.
    ///
    const ProcMapEntry *ProcMapsFindByAddr(const ProcMaps *self, u64 addr);
    
    #endif // MISRA_SYS_PROC_MAPS_H
Last updated on