Skip to content

MemSet

Description

Set memory region to a value. A zero byte count returns dst without writing to it.

Parameters

Name Direction Description
dst out Destination memory region.
val in Byte value to write (low 8 bits used).
n in Number of bytes to set.

Success

Returns destination pointer.

Failure

Aborts via LOG_FATAL when n > 0 and dst is NULL.

Usage example (Cross-references)

Usage examples (Cross-references)
             } UNPL(_s) = {{0}, 0};                                                                                        \
             UNPL(_s).done == 0;                                                                                           \
             MemSet(UNPL(_s).d, 0, sizeof(UNPL(_s).d)), UNPL(_s).done = 1)                                                 \
            for (Vec(T) name = {.length      = 0,                                                                          \
                                .capacity    = (ne),                                                                       \
                     *UNPL(_done) = &name;                                                                                  \
                 UNPL(_done);                                                                                              \
                 MemSet(&name, 0, sizeof(name)), UNPL(_done) = NULL)
    
    ///
    #define StrInitStack(name, ne)                                                                                         \
        for (char UNPL(_d)[(ne) + 1] = {0}, *UNPL(_loop) = UNPL(_d); UNPL(_loop);                                          \
             MemSet(UNPL(_d), 0, sizeof(UNPL(_d))), UNPL(_loop) = NULL)                                                    \
            for (Str name = {.length      = 0,                                                                             \
                             .capacity    = (ne),                                                                          \
                     *UNPL(_done) = &name;                                                                                  \
                 UNPL(_done);                                                                                              \
                 MemSet(&name, 0, sizeof(name)), UNPL(_done) = NULL)
    
        ///
    
        if (!map->key_copy_init) {
            MemSet(key_src, 0, key_size);
        }
    
        if (!map->value_copy_init) {
            MemSet(value_src, 0, value_size);
        }
    static inline bool map_zero_value_source_on_success(GenericMap *map, void *value_src, size value_size, bool success) {
        if (success && !map->value_copy_init) {
            MemSet(value_src, 0, value_size);
        }
             "BudgetAllocatorInit: buffer too small for bitmap + one padded slot"                                          \
         ),                                                                                                                \
         MemSet(                                                                                                           \
             PTR_ALIGN_UP_POW2((buf_ptr), 8u),                                                                             \
             0,                                                                                                            \
    
    __attribute__((used)) void *memset(void *dst, int c, freestanding_size_t n) {
        MemSet(dst, c, (size)n);
        return dst;
    }
    #    if !PLATFORM_WINDOWS
    __attribute__((used)) void bzero(void *dst, freestanding_size_t n) {
        MemSet(dst, 0, (size)n);
    }
    #    endif
    }
    
    void *MemSet(void *dst, i32 val, size n) {
        if (n == 0) {
            return dst;
        clone_allocator = alloc ? (Allocator *)alloc : src->allocator;
    
        MemSet(dst, 0, sizeof(Str));
        *dst             = StrInit(clone_allocator);
        dst->copy_init   = src->copy_init;
                }
            } else {
                MemSet(vec->data, 0, item_size * (vec->capacity + 1));
            }
        // __magic at the next validate call instead of silently dispatching
        // into freed pointers.
        MemSet(vec, 0, sizeof(*vec));
    }
                }
            } else {
                MemSet(vec->data, 0, item_size * (vec->capacity + 1));
            }
        }
            }
            vec->data = (char *)ptr;
            MemSet(ptr + old_capacity * item_size, 0, item_size * (n + 1 - old_capacity));
            vec->capacity = n;
            MAGIC_MARK_DIRTY(vec);
        for (size i = 0; i < count; i++) {
            if (vec->copy_init) {
                MemSet(vec_ptr_at(vec, idx + i, item_size), 0, item_size);
                if (!vec->copy_init(vec_ptr_at(vec, idx + i, item_size), item_data + i * item_size, vec->allocator)) {
                    for (size s = 0; s < inserted_count; s++) {
                    }
    
                    MemSet(vec_ptr_at(vec, idx, item_size), 0, count * item_size);
                    if (idx < vec->length) {
                        MemMove(
                            (vec->length - idx) * item_size
                        );
                        MemSet(vec_ptr_at(vec, vec->length, item_size), 0, count * item_size);
                    }
        vec->length += count;
    
        MemSet(vec_ptr_at(vec, vec->length, item_size), 0, item_size);
        return true;
    }
        for (size i = 0; i < count; i++) {
            if (vec->copy_init) {
                MemSet(vec_ptr_at(vec, idx + i, item_size), 0, item_size);
                if (!vec->copy_init(vec_ptr_at(vec, idx + i, item_size), item_data + i * item_size, vec->allocator)) {
                    for (size s = 0; s < inserted_count; s++) {
                    }
    
                    MemSet(vec_ptr_at(vec, vec->length, item_size), 0, item_size * count);
                    return false;
                }
        vec->length += count;
    
        MemSet(vec_ptr_at(vec, vec->length, item_size), 0, item_size);
        return true;
    }
                }
            } else {
                MemSet(vec_ptr_at(vec, start, item_size), 0, count * item_size);
            }
        }
            (vec->length - start - count) * item_size
        );
        MemSet(vec_ptr_at(vec, (vec->length - count), item_size), 0, count * item_size);
    
        vec->length -= count;
        vec->length -= count;
    
        MemSet(vec_ptr_at(vec, vec->length, item_size), 0, item_size);
    }
                }
            } else {
                MemSet(vec_ptr_at(vec, start, item_size), 0, count * item_size);
            }
        }
        }
    
        MemSet(vec_ptr_at(vec, vec->length - count, item_size), 0, count * item_size);
    
        vec->length -= count;
        // Keep the post-length sentinel slot zeroed so VecBegin-returned arrays
        // are safe to treat as NUL-terminated where the element type allows.
        MemSet(vec_ptr_at(vec, vec->length, item_size), 0, item_size);
    }
    
        if (vec->data) {
            MemSet(vec_ptr_at(vec, vec->length, item_size), 0, item_size);
        }
        }
    
        MemSet(map_entry_ptr(map, entry_size, idx), 0, entry_size);
    }
        void *dst_val = entry + value_offset;
    
        MemSet(entry, 0, entry_size);
    
        if (map->key_copy_init) {
                    map->key_copy_deinit(dst_key, map->allocator);
                }
                MemSet(entry, 0, entry_size);
                return false;
            }
                    map->key_copy_deinit(dst_key, map->allocator);
                }
                MemSet(entry, 0, entry_size);
                return false;
            }
        AllocatorFree(map->allocator, map->states);
    
        MemSet(map, 0, sizeof(*map));
    }
        }
    
        MemSet(dst_value, 0, value_size);
    
        if (map->value_copy_init) {
        }
    
        MemSet(map_entry_ptr(map, entry_size, idx), 0, entry_size);
        map->states[idx]  = MAP_SLOT_TOMBSTONE;
        map->length      -= 1;
            graph->copy_deinit(data, graph->allocator);
        } else {
            MemSet(data, 0, item_size);
        }
        deinit_vec(GENERIC_VEC(&graph->pending_edge_removals), sizeof(GraphPendingEdgeRemoval));
    
        MemSet(graph, 0, sizeof(*graph));
    }
    
        if (node_id && !graph->copy_init) {
            MemSet(item_data, 0, item_size);
        }
        }
    
        MemSet(bytes, 0, bytes_to_copy);
    
        for (u64 i = 0; i < bytes_to_copy; i++) {
        }
    
        MemSet(bytes, 0, bytes_to_copy);
    
        for (u64 i = 0; i < bytes_to_copy; i++) {
        clear_list(list, item_size);
    
        MemSet(list, 0, sizeof(*list));
    }
                MemCopy((u8 *)removed_data + c * item_size, node->data, item_size);
    
                MemSet(node->data, 0, item_size);
                AllocatorFree(list->allocator, node->data);
                node->data = NULL;
                    list->copy_deinit(node->data, list->allocator);
                } else {
                    MemSet(node->data, 0, item_size);
                }
            AllocatorFree(bitvec->allocator, bitvec->data);
        }
        MemSet(bitvec, 0, sizeof(*bitvec));
    }
        bitvec->length = 0;
        if (bitvec->data && bitvec->byte_size > 0) {
            MemSet(bitvec->data, 0, bitvec->byte_size);
        }
    }
    
            if (new_bytes > old_bytes) {
                MemSet(bitvec->data + old_bytes, 0, new_bytes - old_bytes);
            }
    
        if (new_byte_size > bitvec->byte_size) {
            MemSet(new_data + bitvec->byte_size, 0, new_byte_size - bitvec->byte_size);
        }
    
        // Zero first so the OR-in loop below can leave 0-bits implicit.
        MemSet(bytes, 0, bytes_to_copy);
    
        for (u64 i = 0; i < bv->length && i / 8 < bytes_to_copy; i++) {
                // unconditionally on the in-chunk path.
                if (zeroed) {
                    MemSet(out, 0, padded);
                }
                result = out;
            chunk = next;
        }
        MemSet(self, 0, sizeof(*self));
    }
    
        DebugRecord rec;
        MemSet(&rec, 0, sizeof(rec));
        rec.requested_size = bytes;
        rec.padded_size    = padded;
        // `self->page` was never used and has no live state to release.
    
        MemSet(self, 0, sizeof(*self));
    }
        void *slot = self->slots + (size)idx * self->slot_size;
        if (zeroed)
            MemSet(slot, 0, self->slot_size);
    #if FEATURE_ALLOC_STATS
        // bytes_in_use tracks slot_size (what budget_allocator_deallocate
        // The caller still owns `buf`; just wipe our header so any
        // post-deinit dispatch trips ValidateAllocator on zero __magic.
        MemSet(self, 0, sizeof(*self));
    }
                page_table_remove_sorted_at(self->free_entries, &self->free_len, hit);
                if (zeroed) {
                    MemSet(ptr, 0, rounded);
                }
                result = ptr;
            os_page_unmap(&self->base, self->free_entries, self->free_entries_bytes);
        }
        MemSet(self, 0, sizeof(*self));
    }
                void *slot      = (u8 *)self->slabs[i] + ((size)slot_idx << self->slot_size_shift);
                if (zeroed) {
                    MemSet(slot, 0, self->slot_size);
                }
    #if FEATURE_ALLOC_STATS
        void *slot  = self->slabs[idx];
        if (zeroed) {
            MemSet(slot, 0, self->slot_size);
        }
    #if FEATURE_ALLOC_STATS
            );
        }
        MemSet(self, 0, sizeof(*self));
    }
            heap->retention_bytes -= (u64)total;
            if (zeroed)
                MemSet(ptr, 0, total);
        } else {
            ptr = os_page_map(&heap->base, total);
                effective = heap_class_size[cls];
                if (zeroed) {
                    MemSet(out, 0, effective);
                }
            }
        if (self->recycle)
            os_page_unmap(&self->base, self->recycle, os_page_round_up((size)self->recycle_cap * sizeof(void *)));
        MemSet(self, 0, sizeof(*self));
    }
    
        ResolverCacheEntry entry;
        MemSet(&entry, 0, sizeof(entry));
        entry.path = path;
        if (!ElfOpen(&entry.elf, path, self->allocator)) {
            LOG_FATAL("SymbolResolverInit: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->allocator = alloc;
        out->cache     = VecInitT(out->cache, alloc);
        if (!ProcMapsLoad(&out->maps, alloc)) {
            VecDeinit(&out->cache);
            MemSet(out, 0, sizeof(*out));
            return false;
        }
        VecDeinit(&self->cache);
        ProcMapsDeinit(&self->maps);
        MemSet(self, 0, sizeof(*self));
    }
        if (!self || !out)
            return false;
        MemSet(out, 0, sizeof(*out));
    
        u64 addr = (u64)runtime_addr;
        }
        PdbCacheEntry entry;
        MemSet(&entry, 0, sizeof(entry));
    
        if (!StrTryInitFromCstr(&entry.module_path, module_path, ZstrLen(module_path), self->allocator)) {
        }
        VecDeinit(&self->entries);
        MemSet(self, 0, sizeof(*self));
    }
            return false;
        }
        MemSet(out, 0, sizeof(*out));
        out->allocator   = alloc;
        out->hosts       = VecInitT(out->hosts, alloc);
        ULONG64      sym_buf[(sizeof(SYMBOL_INFO) + MAX_NAME + sizeof(ULONG64) - 1) / sizeof(ULONG64)];
        SYMBOL_INFO *sym = (SYMBOL_INFO *)sym_buf;
        MemSet(sym, 0, sizeof(*sym));
        sym->SizeOfStruct = sizeof(SYMBOL_INFO);
        sym->MaxNameLen   = MAX_NAME;
    
        IMAGEHLP_LINE64 line;
        MemSet(&line, 0, sizeof(line));
        line.SizeOfStruct = sizeof(line);
    // the right field for each platform.
    static void fill_socket_addr_from_sockaddr(SocketAddr *out, const struct sockaddr *sa, u32 len) {
        MemSet(out, 0, sizeof(*out));
        if (len > (u32)SOCKET_ADDR_MAX_SIZE) {
            len = (u32)SOCKET_ADDR_MAX_SIZE;
            LOG_FATAL("SocketAddrParse: out is NULL");
        }
        MemSet(out, 0, sizeof(*out));
    
        if (!spec) {
            if (parse_ipv4(host_data, v4)) {
                struct sockaddr_in *sa = (struct sockaddr_in *)out->raw;
                MemSet(out, 0, sizeof(*out));
                sa->sin_family = AF_INET;
                sa->sin_port   = FROM_BIG_ENDIAN2(port);
            if (parse_ipv6(host_data, v6)) {
                struct sockaddr_in6 *sa = (struct sockaddr_in6 *)out->raw;
                MemSet(out, 0, sizeof(*out));
                sa->sin6_family = AF_INET6;
                sa->sin6_port   = FROM_BIG_ENDIAN2(port);
            LOG_FATAL("SocketAddrParse: out is NULL");
        }
        MemSet(out, 0, sizeof(*out));
    
        if (!spec) {
            LOG_FATAL("ListenerOpen: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->fd = SOCKET_FD_INVALID;
            LOG_FATAL("ListenerLocalAddr: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        u8  buf[SOCKET_ADDR_MAX_SIZE];
        u32 len = (u32)sizeof(buf);
            LOG_FATAL("ListenerAccept: NULL argument");
        }
        MemSet(out_conn, 0, sizeof(*out_conn));
        out_conn->fd = SOCKET_FD_INVALID;
            plat_close(self->fd);
        }
        MemSet(self, 0, sizeof(*self));
        self->fd = SOCKET_FD_INVALID;
    }
            LOG_FATAL("SocketConnect: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->fd = SOCKET_FD_INVALID;
            plat_close(self->fd);
        }
        MemSet(self, 0, sizeof(*self));
        self->fd = SOCKET_FD_INVALID;
    }
        }
        MachoCacheEntry entry;
        MemSet(&entry, 0, sizeof(entry));
    
        if (!StrTryInitFromCstr(&entry.module_path, module_path, ZstrLen(module_path), self->allocator)) {
        }
        VecDeinit(&self->entries);
        MemSet(self, 0, sizeof(*self));
    }
    #    error "MutexDeinit: unsupported platform/architecture (no direct-syscall path)"
    #endif
        MemSet(m, 0, sizeof(Mutex));
    }
    #endif
        }
        MemSet(proc, 0, sizeof(*proc));
    }
        }
        Buf taken = *in;
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        out->data = taken;
        // Initialize the sections vec up-front so PeDeinit on a
        BufDeinit(&self->data);
        VecDeinit(&self->sections);
        MemSet(self, 0, sizeof(*self));
    }
            LOG_FATAL("DwarfFunctionsBuildFromSlices: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->allocator   = alloc;
        out->entries     = VecInitT(out->entries, alloc);
        if (!ok) {
            DwarfFunctionsDeinit(out);
            MemSet(out, 0, sizeof(*out));
        }
        if (StrAllocator(&self->string_pool))
            StrDeinit(&self->string_pool);
        MemSet(self, 0, sizeof(*self));
    }
        rec->target = StrInit(alloc);
        rec->rdata  = VecInitT(rec->rdata, alloc);
        MemSet(rec->ipv4, 0, sizeof(rec->ipv4));
        MemSet(rec->ipv6, 0, sizeof(rec->ipv6));
        rec->rdata  = VecInitT(rec->rdata, alloc);
        MemSet(rec->ipv4, 0, sizeof(rec->ipv4));
        MemSet(rec->ipv6, 0, sizeof(rec->ipv6));
    
        if (!decode_name(it, &rec->name)) {
            return false;
        }
        MemSet(out, 0, sizeof(*out));
        out->answers    = VecInitT(out->answers, alloc);
        out->authority  = VecInitT(out->authority, alloc);
        }
        Buf taken = *in;
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        out->data      = taken;
        out->functions = VecInitT(out->functions, BufAllocator(&taken));
        VecDeinit(&self->functions);
        BufDeinit(&self->data);
        MemSet(self, 0, sizeof(*self));
    }
            LOG_FATAL("ProcMapsLoad: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->raw     = StrInit(alloc);
        out->entries = VecInitT(out->entries, alloc);
            LOG_FATAL("ProcMapsLoadFrom: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->raw     = StrInit(alloc);
        out->entries = VecInitT(out->entries, alloc);
            LOG_FATAL("ProcMapsLoadFrom: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->raw     = StrInit(alloc);
        out->entries = VecInitT(out->entries, alloc);
        StrDeinit(&self->raw);
        VecDeinit(&self->entries);
        MemSet(self, 0, sizeof(*self));
    }
        StrDeinit(&header->key);
        StrDeinit(&header->value);
        MemSet(header, 0, sizeof(*header));
    }
        StrDeinit(&header->key);
        StrDeinit(&header->value);
        MemSet(header, 0, sizeof(*header));
    }
        StrDeinit(&req->url);
        VecDeinit(&req->headers);
        MemSet(req, 0, sizeof(*req));
    }
        StrDeinit(&response->body);
        VecDeinit(&response->headers);
        MemSet(response, 0, sizeof(*response));
    }
    
    static bool parse_cie(BufIter *body, u64 cie_offset, DwarfCie *out) {
        MemSet(out, 0, sizeof(*out));
        out->offset = cie_offset;
        DwarfFde       *out
    ) {
        MemSet(out, 0, sizeof(*out));
        out->offset     = (u64)(body_start - section_data);
        out->cie_offset = cie_offset;
            LOG_FATAL("DwarfCfiBuildFromElf: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->allocator = alloc;
        out->cies      = VecInitT(out->cies, alloc);
        VecDeinit(&self->cies);
        VecDeinit(&self->fdes);
        MemSet(self, 0, sizeof(*self));
    }
    
    static void cfi_vm_init(CfiVm *vm, const DwarfCie *cie, u64 fde_pc_begin, u8 ra_reg) {
        MemSet(vm, 0, sizeof(*vm));
        vm->row.return_address_register = ra_reg;
        vm->location                    = fde_pc_begin;
        }
        MachoSegment seg;
        MemSet(&seg, 0, sizeof(seg));
        // Must-precondition for the next two moves: `cmdsize >=
        // SEG64_CMD_SIZE_MIN` (checked above) reserves the 8-byte prefix
            BufIter      sec_it = IterCarve(cmd, SECT64_SIZE);
            MachoSection sec;
            MemSet(&sec, 0, sizeof(sec));
            MemCopy(sec.section, IterDataAt(&sec_it, IterIndex(&sec_it)), 16);
            sec.section[16] = '\0';
        }
        Buf taken = *in;
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        out->data     = taken;
        out->segments = VecInitT(out->segments, BufAllocator(&taken));
        VecDeinit(&self->sections);
        VecDeinit(&self->symbols);
        MemSet(self, 0, sizeof(*self));
    }
        }
        Buf taken = *in;
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        MemSet(in, 0, sizeof(*in));
    
        MemSet(out, 0, sizeof(*out));
        out->data            = taken;
        out->sections        = VecInitT(out->sections, BufAllocator(&taken));
        VecDeinit(&self->symbols);
        VecDeinit(&self->dynamic_symbols);
        MemSet(self, 0, sizeof(*self));
    }
    // directory / file tables are walked separately by collect_cu_strings.
    static bool decode_line_program_header(BufIter *cur, LineProgHeader *out) {
        MemSet(out, 0, sizeof(*out));
    
        u32 unit_length = 0;
    
    static void lnp_reset(LnpState *st, bool default_is_stmt) {
        MemSet(st, 0, sizeof(*st));
        st->file    = 1;
        st->line    = 1;
    ) {
        DwarfLineEntry e;
        MemSet(&e, 0, sizeof(e));
        e.address      = st->address;
        e.line         = st->line;
            LOG_FATAL("DwarfLinesBuildFromElf: NULL argument");
        }
        MemSet(out, 0, sizeof(*out));
        out->allocator   = alloc;
        out->entries     = VecInitT(out->entries, alloc);
        VecDeinit(&self->entries);
        StrDeinit(&self->string_pool);
        MemSet(self, 0, sizeof(*self));
    }
        Int value = IntFrom(0x0102, &alloc.base);
        u8  buf[4];
        MemSet(buf, 0xAA, sizeof(buf));
    
        u64 written = IntToBytesBE(&value, buf, sizeof(buf));
    static bool test_alignment_honored(void) {
        static u8 buf[1024];
        MemSet(buf, 0, sizeof(buf));
        BudgetAllocator bp    = BudgetAllocatorInitAligned(buf, sizeof(buf), sizeof(int), 64);
        Allocator      *alloc = ALLOCATOR_OF(&bp);
        // Create a buffer to store the removed characters
        char buffer[6];
        MemSet(buffer, 0, sizeof(buffer));
    
        // Remove a range of characters
    
    static void build_pe_blob(Zstr pdb_path) {
        MemSet(pe_blob, 0, sizeof(pe_blob));
    
        pe_blob[0] = 'M';
    // even though PdbOpen itself still succeeds.
    static void build_pdb_blob_va(Zstr func_name, u32 sec_va, u32 func_rva, bool match_guid) {
        MemSet(pdb_blob, 0, sizeof(pdb_blob));
    
        // Compute S_PUB32 record size based on function name length.
        // A sidecar that exists on disk but is NOT a valid PDB (no MSF magic).
        u8 junk[256];
        MemSet(junk, 0xAB, sizeof(junk));
        bool wrote = write_file(pe_path, pe_blob, sizeof(pe_blob)) && write_file(pdb_path, junk, sizeof(junk));
    bool test_sk3_listener_unspec_family_fails(void) {
        SocketAddr bad;
        MemSet(&bad, 0, sizeof(bad)); // family = SOCKET_FAMILY_UNSPEC
    
        Listener listener;
    
    static u64 build_macho_image(u8 *out, const u8 uuid[16], const SymSpec *syms, u32 nsyms) {
        MemSet(out, 0, BLOB_CAP);
    
        // Compute placement.
    
    static u64 mc_build_macho_image(u8 *out, const u8 uuid[16], const McSymSpec *syms, u32 nsyms) {
        MemSet(out, 0, MC_BLOB_CAP);
    
        u32 seg_off      = MC_HDR_SIZE;
    // their file offsets.
    static u64 mc_build_dwarf_dsym(u8 *out, const u8 uuid[16], u64 low, u64 high_off, Zstr fn_name) {
        MemSet(out, 0, MC_BLOB_CAP);
    
        // ncmds: __TEXT segment (1 sect), LC_SYMTAB (0 syms), LC_UUID,
        };
        u8 strbuf[256];
        MemSet(strbuf, 0, sizeof(strbuf));
        u64 name_len = ZstrLen(fn_name);
        MemCopy(&strbuf[MC_NAME_STRP], fn_name, name_len);
        for (u32 i = 0; i < 3; ++i) {
            u8 *s = &out[dwarf_seg_off + MC_SEG64_HDR + i * MC_SECT64_SIZE];
            MemSet(&s[0], 0, 16);
            u32 j = 0;
            while (dsects[i].name[j]) {
    
    static u64 bl_build_stripped_main(u8 *out, const u8 uuid[16]) {
        MemSet(out, 0, BL_BLOB_CAP);
    
        u32 seg_off      = BL_HDR_SIZE;
    // abbrev entries, corrupting the abbrev table.
    static u64 bl_build_dwarf_dsym(u8 *out, const u8 uuid[16], u64 low, u64 high_off, Zstr fn_name) {
        MemSet(out, 0, BL_BLOB_CAP);
    
        u32 text_seg_off  = BL_HDR_SIZE;
        };
        u8 strbuf[256];
        MemSet(strbuf, 0, sizeof(strbuf));
        u64 name_len = ZstrLen(fn_name);
        MemCopy(&strbuf[BL_NAME_STRP], fn_name, name_len);
        for (u32 i = 0; i < 3; ++i) {
            u8 *s = &out[dwarf_seg_off + BL_SEG64_HDR + i * BL_SECT64_SIZE];
            MemSet(&s[0], 0, 16);
            u32 j = 0;
            while (dsects[i].name[j]) {
    
    static void build_pe_blob(void) {
        MemSet(blob, 0, sizeof(blob));
    
        // --- DOS header --------------------------------------------------------
    // directory of one entry, and a single CodeView (RSDS) record.
    static void build_pe_blob_m1(void) {
        MemSet(blob, 0, sizeof(blob));
    
        blob[0] = 'M';
    static const u64 PE32_IMAGE_BASE = 0x00400000ull;
    static void      build_pe32_blob(void) {
        MemSet(blob, 0, sizeof(blob));
    
        blob[0] = 'M';
    
        u8 garbage[256];
        MemSet(garbage, 0, sizeof(garbage));
        garbage[0] = 'X';
        garbage[1] = 'X';
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[2];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".text\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 2);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[2];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va = 0x1000;
        u32 total = SECTION_TBL_OFF + 2u * SECTION_ENTSIZE;
        u8  blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 2);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, "ABCDEFGH", 8); // all 8 bytes used
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[2];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va = 0x1000;
        u32 total = SECTION_TBL_OFF + SECTION_ENTSIZE + 20;
        u8  blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 2);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[2];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va       = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 2);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va       = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va    = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va      = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[2];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".text\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 2);
    
        SecDesc secs[2];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".text\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_SIZE];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 2);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        blob[NT_OFF] = 'Q'; // corrupt the 'P' of "PE\0\0" -> fails after DOS
    
        SecDesc secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".text\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
    
        u8 junk[256];
        MemSet(junk, 0, sizeof(junk));
        junk[0] = 'X';
        junk[1] = 'Y';
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        DefaultAllocator alloc = DefaultAllocatorInit();
        SecDesc          secs[1];
        MemSet(secs, 0, sizeof(secs));
        MemCopy(secs[0].name, ".a\0\0\0\0\0\0", 8);
        secs[0].va = 0x1000;
    
        u8 blob[BLOB_CAP];
        MemSet(blob, 0, sizeof(blob));
        build_blob(blob, secs, 1);
        blob[1] = 'X'; // 'MZ' -> 'MX'
    
    static void build_msf_blob(void) {
        MemSet(blob, 0, sizeof(blob));
    
        // --- Superblock (page 0) -------------------------------------------------
    
        u8 garbage[256];
        MemSet(garbage, 0xCC, sizeof(garbage));
    
        Pdb  pdb;
    
    static void build_full_pdb_blob(void) {
        MemSet(fblob, 0, sizeof(fblob));
    
        // Directory size: 4 (count) + N_STREAMS*4 (sizes) + block_id_count*4
    
    static void build_multi_pdb_blob(u32 *out_symrec_size) {
        MemSet(mblob, 0, sizeof(mblob));
    
        // --- SymRecord stream (#4): three out-of-order publics --------------
    
        u8 buf[256];
        MemSet(buf, 0, sizeof(buf));
        MemCopy(buf, kMagic, 32);
        wr_u32(&buf[32], 333); // bogus block size
    // Build the full blob; returns nothing. `p` describes the DBI stream.
    static void build_blob_m1(const DbiParams *p) {
        MemSet(gblob, 0, sizeof(gblob));
    
        const u32 dir_bytes = 4 + D1_NUM_STREAMS * 4 + 4 * 4; // 44
        // OptionalDbgHeader) with `filler` so any mis-located read lands on a
        // recognisable, invalid SectionHdr index (0xFF -> 0xFFFF).
        MemSet(dbi + 64, p->filler, (p->optdbg_off > 64 ? p->optdbg_off - 64 : 0) + p->optdbg_size + 16);
    
        wr_u32(&dbi[0], 0xFFFFFFFFu);    // VersionSignature = -1
    // bytes so its reconstructed content is identifiable.
    static u32 build_blob_m2(u32 bs, const u32 *sizes, u32 n, u32 *out_dir_bytes, u32 *out_num_pages) {
        MemSet(g_blob, 0, sizeof(g_blob));
    
        // How many content pages? One per non-empty stream.
            // Fill the content page with a recognizable pattern.
            u8 *content = &g_blob[data_page * bs];
            MemSet(content, (u8)(0xA0 + i), sizes[i] < bs ? sizes[i] : bs);
            bid_idx   += 1;
            data_page += 1;
    static u32 build_blob_multiblock(const u32 *sizes, u32 n) {
        const u32 bs = B_BS;
        MemSet(g_blob, 0, sizeof(g_blob));
        g_mb_blockid_count = 0;
                g_mb_blockids[g_mb_blockid_count++] = data_page;
                // Fill each page with a recognizable pattern.
                MemSet(&g_blob[data_page * bs], (u8)(0xA0 + i), bs);
                bid_idx   += 1;
                data_page += 1;
    
        u8 buf[256];
        MemSet(buf, 0, sizeof(buf));
        MemCopy(buf, kMagic, 32);
        wr_u32(&buf[32], 256);
    
        u8 buf[55]; // one short of the 56-byte superblock
        MemSet(buf, 0, sizeof(buf));
        MemCopy(buf, kMagic, 32);
        wr_u32(&buf[32], B_BS);
    
    static void build_two_block_dir(void) {
        MemSet(g_tblob, 0, sizeof(g_tblob));
    
        MemCopy(g_tblob, kMagic, 32);
        // Build the directory bytes contiguously, then split across pages.
        u8 dir[T_DIR_BYTES];
        MemSet(dir, 0, sizeof(dir));
        wr_u32(&dir[0], T_NUM_STREAMS);
        // All streams empty except stream 1, which has a single block.
    
        // Stream 1 content.
        MemSet(&g_tblob[T_DATA_PG * T_BS], 0x5A, T_DATA_SIZE);
    }
            Z_DIR   = 4
        };
        MemSet(g_blob, 0, sizeof(g_blob));
        MemCopy(g_blob, kMagic, 32);
        wr_u32(&g_blob[32], Z_BS);
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        MemSet(g_hblob, 0, sizeof(g_hblob));
        MemCopy(g_hblob, kMagic, 32);
        wr_u32(&g_hblob[32], H_BS);
    
    static void build_filter_blob(void) {
        MemSet(g_blob_filter, 0, sizeof(g_blob_filter));
    
        u8 *sym = &g_blob_filter[G_SYMREC_PAGE * G_BLOCK_SIZE];
    
    static void build_sect_blob(void) {
        MemSet(g_blob_sect, 0, sizeof(g_blob_sect));
    
        u8 *sym = &g_blob_sect[G_SYMREC_PAGE * G_BLOCK_SIZE];
    
    static void build_oob_seg_blob(void) {
        MemSet(g_blob_oob, 0, sizeof(g_blob_oob));
    
        u8 *sym = &g_blob_oob[G_SYMREC_PAGE * G_BLOCK_SIZE];
    
    static void build_size_blob(void) {
        MemSet(g_blob_size, 0, sizeof(g_blob_size));
    
        u8 *sym = &g_blob_size[G_SYMREC_PAGE * G_BLOCK_SIZE];
    
    static void build_sort_blob(void) {
        MemSet(g_blob_sort, 0, sizeof(g_blob_sort));
    
        u8 *sym = &g_blob_sort[G_SYMREC_PAGE * G_BLOCK_SIZE];
    
    static void build_mal_blob(void) {
        MemSet(g_blob_mal, 0, sizeof(g_blob_mal));
    
        u8 *sym = &g_blob_mal[G_SYMREC_PAGE * G_BLOCK_SIZE];
    
    static void build_ovf_blob(void) {
        MemSet(g_blob_ovf, 0, sizeof(g_blob_ovf));
    
        u8 *sym = &g_blob_ovf[G_SYMREC_PAGE * G_BLOCK_SIZE];
    // function record straddling the 512-byte block boundary.
    static void build_crossblock_blob(void) {
        MemSet(xblob, 0, sizeof(xblob));
    
        // Fill the decoy gap page (9) and unused regions with a distinctive
        // 0xEE pattern so an accidental over-read of page 8 into page 9
        // would corrupt the straddling record's tail.
        MemSet(&xblob[9 * X_BLOCK_SIZE], 0xEE, X_BLOCK_SIZE);
    
        // Directory: 4 (count) + 6*4 (sizes) + 5 block ids * 4.
        // halves into the two non-adjacent pages.
        u8 sym_flat[X_SYM_SIZE];
        MemSet(sym_flat, 0, sizeof(sym_flat));
    
        // Records are packed contiguously from offset 0 so the walker never
    // the info-stream read fail.
    static void build_info_blob(u32 info_block_id) {
        MemSet(sblob, 0, sizeof(sblob));
    
        MemCopy(sblob, kMagic, 32);
    
        u8 junk[256];
        MemSet(junk, 0xCC, sizeof(junk)); // bad magic
        if (FileWriteAndClose(X_TMP_JUNK, junk, (u64)sizeof(junk)) < 0) {
            DefaultAllocatorDeinit(&alloc);
        u16            symrec_stream_override
    ) {
        MemSet(blob, 0, P5_BLOB_SIZE);
    
        // --- SectionHdr stream (#5) ---------------------------------------
    static Blob build_blob(u32 bs, const u32 *sizes, u32 n, u32 dir_bytes_override) {
        Blob b;
        MemSet(&b, 0, sizeof(b));
        MemSet(g_buf, 0, sizeof(g_buf));
        b.bytes = g_buf;
        Blob b;
        MemSet(&b, 0, sizeof(b));
        MemSet(g_buf, 0, sizeof(g_buf));
        b.bytes = g_buf;
        b.bs    = bs;
        };
        u32 sizes[N];
        MemSet(sizes, 0, sizeof(sizes));
        sizes[1] = 28;
        sizes[3] = 76;
        DebugAllocator alloc = DebugAllocatorInit();
        ProcMaps       pm;
        MemSet(&pm, 0, sizeof(pm));
        pm.raw     = StrInit(ALLOCATOR_OF(&alloc));
        pm.entries = VecInitT(pm.entries, ALLOCATOR_OF(&alloc));
    
    static void build_macho_blob(void) {
        MemSet(blob, 0, sizeof(blob));
    
        // --- Mach header (32 bytes) -------------------------------------------
    static u64 build_seg_with_sections(u8 *buf, u32 nsects) {
        u32 cmdsize = (u32)(SEG64_HDR + nsects * SECT64_SIZE);
        MemSet(buf, 0, HDR_SIZE + cmdsize);
        put_header(buf, 1, cmdsize);
    
    static u64 build_symbol_blob(const u64 *values, u32 nsyms) {
        MemSet(g_symblob, 0, sizeof(g_symblob));
    
        u32 seg_off    = HDR_SIZE;
    
        u8 fat[64];
        MemSet(fat, 0, sizeof(fat));
        wr_u32(&fat[0], 0xCAFEBABEu);
        u8 buf[64];
    
        MemSet(buf, 0, sizeof(buf));
        wr_u32(&buf[0], 0xFEEDFACEu); // MH_MAGIC_32
        bool ok = macho_rejects(buf, sizeof(buf));
        bool ok = macho_rejects(buf, sizeof(buf));
    
        MemSet(buf, 0, sizeof(buf));
        wr_u32(&buf[0], 0xCFFAEDFEu); // MH_CIGAM_64 (byte-swapped 64-bit)
        ok = ok && macho_rejects(buf, sizeof(buf));
        ok = ok && macho_rejects(buf, sizeof(buf));
    
        MemSet(buf, 0, sizeof(buf));
        wr_u32(&buf[0], 0xDEADBEEFu); // not a Mach-O at all
        ok = ok && macho_rejects(buf, sizeof(buf));
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        SymCfg cfg = {.buf_size = BUF, .symoff = 0x100, .nsyms = 1, .stroff = 0x110, .strsize = 16};
        build_scaffold(b, &cfg);
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        SymCfg cfg = {.buf_size = BUF, .symoff = 0x100, .nsyms = 0, .stroff = 0x110, .strsize = 0};
        build_scaffold(b, &cfg);
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        // strtab: \0 "alpha" \0 "beta" \0   (alpha at 1, beta at 7)
        u32    stroff  = 0x120;
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        SymCfg cfg = {.buf_size = BUF, .symoff = 0x100, .nsyms = 1, .stroff = 0x110, .strsize = 16};
        build_scaffold(b, &cfg);
        }; // 288
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    stroff  = 0x100;
        u32    strsize = 16;
        }; // 288
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    symoff  = 0x100;         // nlist at 0x100..0x110
        u32    strsize = 16;
        u32 BUF     = stroff + strsize + 16;
        u8  b[0x300];                     // must cover BUF (=544 here); 0x200 overflowed
        MemSet(b, 0, sizeof(b));
        SymCfg cfg = {.buf_size = BUF, .symoff = symoff, .nsyms = NSY, .stroff = stroff, .strsize = strsize};
        build_scaffold(b, &cfg);
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    symoff  = 0x100;
        u32    stroff  = 0x130; // within buffer
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    symoff  = 0x100;
        u32    strsize = 16;
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    symoff  = 0x100;
        u32    stroff  = 0x110;
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    symoff  = 0x100;
        u32    stroff  = 0x110;
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        u32    symoff  = 0x100;
        u32    stroff  = 0x110;
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
        SymCfg cfg = {.buf_size = BUF, .symoff = 0x100, .nsyms = 0, .stroff = 0x110, .strsize = 0};
        build_scaffold(b, &cfg);
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
    
        // mach_header_64
    
        u8 buf[HDR_SIZE];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 0, 0); // ncmds = 0, sizeofcmds = 0
    
        u8 buf[HDR_SIZE + SEG64_HDR];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, SEG64_HDR);
    
        u8 buf[HDR_SIZE + SEG64_HDR];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, SEG64_HDR);
    
        u8 buf[HDR_SIZE + SEG64_HDR + SECT64_SIZE];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, SEG64_HDR + SECT64_SIZE);
        // exactly 32 + 72 = 104.
        u8 buf[HDR_SIZE + SEG64_HDR];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, SEG64_HDR);
    
        u8 buf[HDR_SIZE + 8];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, 8); // one command, sizeofcmds == 8
    
        u8 buf[HDR_SIZE + SEG64_HDR];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, SEG64_HDR);
        u8 *seg = &buf[HDR_SIZE];
        // Bad magic (not a Mach-O), but enough bytes to read successfully.
        u8 garbage[64];
        MemSet(garbage, 0, sizeof(garbage));
        wr_u32(&garbage[0], 0xDEADBEEFu);
        // rejects after decode_header succeeds.
        u8 buf[HDR_SIZE + 16];
        MemSet(buf, 0, sizeof(buf));
        put_header(buf, 1, 16);
        u8 *lc = &buf[HDR_SIZE];
        };
        u8 b[BUF];
        MemSet(b, 0, sizeof(b));
    
        // mach_header_64: one load command (the LC_UUID), sizeofcmds = 24.
    
    static void build_elf_blob(void) {
        MemSet(elf_blob, 0, sizeof(elf_blob));
    
        // --- ELF header -------------------------------------------------------
    
    static void build_dbg_blob(void) {
        MemSet(dbg_blob, 0, sizeof(dbg_blob));
    
        // --- ELF header -------------------------------------------------------
    bool test_el1_strtab_unterminated_name_is_empty(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        MemSet(elf_blob, 0, sizeof(elf_blob));
    
        // Minimal valid header.
    bool test_el1_strtab_nul_at_size_boundary_is_empty(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        MemSet(elf_blob, 0, sizeof(elf_blob));
    
        elf_blob[0] = 0x7f;
    bool test_el1_strtab_forward_scan_name(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        MemSet(elf_blob, 0, sizeof(elf_blob));
    
        elf_blob[0] = 0x7f;
    // image flips the mutant.
    static void build_min64(u8 *b) {
        MemSet(b, 0, 64);
        b[0] = 0x7f;
        b[1] = 'E';
    
    static void build_sym_blob(void) {
        MemSet(sym_blob, 0, sizeof(sym_blob));
    
        wr_ehdr(sym_blob, (u16)ELF_TYPE_EXEC, SF_SHT_OFF, SF_N_SECTIONS, SF_SEC_SHSTRTAB);
    
    static void build_bid_blob(const u8 *note_payload, u32 note_size, u64 note_off_override) {
        MemSet(bid_blob, 0, sizeof(bid_blob));
        wr_ehdr(bid_blob, (u16)ELF_TYPE_DYN, BID_SHT_OFF, BID_N_SECTIONS, BID_SEC_SHSTRTAB);
    
    static void build_dl_blob(const u8 *payload, u32 dl_size, u64 off_override) {
        MemSet(dl_blob, 0, sizeof(dl_blob));
        wr_ehdr(dl_blob, (u16)ELF_TYPE_DYN, DL_SHT_OFF, DL_N_SECTIONS, DL_SEC_SHSTRTAB);
        // payload: "abc.debug\0" (10) padded to 12, then 4-byte crc -> 16 bytes
        u8 payload[16];
        MemSet(payload, 0, sizeof(payload));
        const char fname[] = "abc.debug";
        MemCopy(payload, fname, sizeof(fname)); // includes NUL
        DefaultAllocator alloc = DefaultAllocatorInit();
        u8               payload[16];
        MemSet(payload, 0, sizeof(payload)); // base[0] == '\0' -> empty name
        wr_u32(&payload[12], 0x01020304u);
        build_dl_blob(payload, 16, 0);
        DefaultAllocator alloc = DefaultAllocatorInit();
        u8               payload[16];
        MemSet(payload, 0, sizeof(payload));
        const char fname[] = "abc.debug";
        MemCopy(payload, fname, sizeof(fname));
        };
        u8 blob[BLOB_LEN];
        MemSet(blob, 0, sizeof(blob));
        wr_ehdr_exec(blob, SHOFF, SHNUM, /*shstrndx=*/0);
    // sections; pass the "good" defaults for a valid image.
    static void build_dbg(u8 *blob, u64 note_off, u64 note_size, u64 dl_off, u64 dl_size) {
        MemSet(blob, 0, DBG_BLOB_SIZE);
        wr_ehdr_exec(blob, DBG_SHT_OFF, DBG_N_SEC, DBG_SEC_SHSTRTAB);
        blob[16] = (u8)ELF_TYPE_DYN; // e_type low byte (DYN); harmless cosmetic
        };
        u8 buf[FSIZE];
        MemSet(buf, 0, sizeof(buf));
        bl_wr_header(buf, SHT_OFF, NSEC, 1);
    // .shstrtab, .debug_line) and return total length into `*out_len`.
    static void build_elf_with_debug_line(u8 *elf, u64 *out_len, const u8 *dl, u64 dl_len) {
        MemSet(elf, 0, 4096);
        // shstrtab content: "\0.shstrtab\0.debug_line\0"
        static const char shstr[]            = "\0.shstrtab\0.debug_line";
    // --- Shared 8192-ELF builder + lines_from_debug_line (Mutants3 & Mutants5) ---
    static void build_elf_with_debug_line_8192(u8 *elf, u64 *out_len, const u8 *dl, u64 dl_len) {
        MemSet(elf, 0, 8192);
        static const char shstr[]            = "\0.shstrtab\0.debug_line";
        const u32         shstrtab_name_off  = 1;
        // declared operand count of 2; the rest 0.
        u8 std_lengths[19];
        MemSet(std_lengths, 0, sizeof(std_lengths));
        // indices 0..11 -> opcodes 1..12
        static const u8 base12[12] = {0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1};
        // opcode_base = 15 -> 14 std_opcode_lengths entries (opcodes 1..14).
        u8 std_lengths[14];
        MemSet(std_lengths, 0, sizeof(std_lengths));
        static const u8 base12[12] = {0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1};
        for (u32 i = 0; i < 12; ++i)
Last updated on