Skip to content

MachoDeinit

Description

Release storage owned by a Macho. Frees the data Buf through its carried allocator (unconditional – the parser always owns its bytes) and tears down the vectors. Safe on a zeroed struct.

Success

Returns to the caller. *self is zeroed.

Failure

Function cannot fail. NULL self is a no-op.

Usage example (Cross-references)

Usage examples (Cross-references)
        if (!MachoHasUuid(&e->dsym) || MemCompare(MachoUuid(&e->dsym), MachoUuid(&e->main), 16) != 0) {
            LOG_ERROR("MachoCache: dSYM UUID mismatch for {}", e->module_path);
            MachoDeinit(&e->dsym);
            return false;
        }
                DwarfFunctionsDeinit(&e->fns);
            if (e->dsym_open)
                MachoDeinit(&e->dsym);
            if (e->main_open)
                MachoDeinit(&e->main);
                MachoDeinit(&e->dsym);
            if (e->main_open)
                MachoDeinit(&e->main);
            StrDeinit(&e->module_path);
        }
    
    fail:
        MachoDeinit(out);
        return false;
    }
    }
    
    void MachoDeinit(Macho *self) {
        if (!self)
            return;
        ok = ok && VecPtrAt(&m.symbols, 0)->value == 0x100000010ull;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && s == NULL;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && MachoFindSection(&m, "__TEXT", "__nope") == NULL;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             opened = MachoOpenFromMemoryCopy(&m, bytes, len, ALLOCATOR_OF(&alloc));
        if (opened)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
        ok = ok && s != NULL && s->value == 0x100000040ull;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && VecLen(&m.symbols) > 0;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
                  ZstrFindSubstring(sym->name, "test_macho_resolves_running_binary_symbol") != NULL;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            ok = ok && ZstrCompare(VecPtrAt(&m.symbols, 0)->name, "fn_a") == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && m.has_uuid && MemCompare(m.uuid, kUuid, 16) == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.symbols) == 1 && VecPtrAt(&m.symbols, 0)->section_index == 5;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.symbols) == 1 && ZstrCompare(VecPtrAt(&m.symbols, 0)->name, "fit") == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.symbols) == 1 && ZstrCompare(VecPtrAt(&m.symbols, 0)->name, "edge") == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.symbols) == NSY;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool  opened = open_blob(&m, b, BUF, &alloc);
        if (opened)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return !opened; // real: rejected.
        bool  opened = open_blob(&m, b, BUF, &alloc);
        if (opened)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
        ok       = ok && VecLen(&m.symbols) == 0; // real: symbol skipped
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.symbols) == 0; // real: skipped (no NUL in range)
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.symbols) == 1; // real: forward scan finds NUL
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && MachoFindSection(&m, "__DATA", "__text") == NULL;
        ok = ok && MachoFindSection(&m, "__TEXT", "__nope") == NULL;
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && hit != NULL && hit->addr == 0x100000100ull && hit->size == 0x80 && hit->offset == 0x100;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && m.cputype == 0x01000007u && m.filetype == MACHO_FILE_TYPE_EXECUTE;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecPtrAt(&m.segments, 0)->vmaddr == 0x1000;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && ZstrCompare(VecPtrAt(&m.segments, 0)->name, "ABCDEFGHIJKLMNOP") == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecPtrAt(&m.sections, 1)->addr == 0x100001000ull;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->segment, "QRSTUVWXYZ012345") == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.segments) == 1;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok       = ok && VecLen(&m.segments) == 0 && VecLen(&m.sections) == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok                   = ok && s != NULL && s->value == 0x100000040ull;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && s != NULL && s->value == 0x100000010ull && s->section_index == 2;
    
        MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok           = ok && opened && VecLen(&m.segments) == 1;
        if (opened)
            MachoDeinit(&m);
    
        FileRemove(&path);
        bool  opened = MachoOpen(&m, &path, base);
        if (opened)
            MachoDeinit(&m);
        ok = ok && !opened; // garbage must be rejected
        bool  opened = MachoOpenFromMemoryCopy(&m, buf, sizeof(buf), base);
        if (opened)
            MachoDeinit(&m);
    
        // The open must have failed AND left no live allocations behind.
        ok = ok && m.has_uuid == true && MemCompare(m.uuid, kUuid, 16) == 0;
        if (ok)
            MachoDeinit(&m);
        DefaultAllocatorDeinit(&alloc);
        return ok;
Last updated on