Skip to main content

check_dump_file

Function check_dump_file 

Source
pub fn check_dump_file(
    file: &str,
    sbuf: &Metadata,
    name: &str,
    test_only: bool,
) -> Option<(Vec<u32>, bool)>
Expand description

Port of Eprog check_dump_file(char *file, struct stat *sbuf, char *name, int *ksh, int test_only) from Src/parse.c:3833. Walks the dumps mmap list looking for (dev, ino) matching sbuf; on miss, calls load_dump_header to read the .zwc header. Then dump_find_func(d, name) locates the function table entry. Returns the wordcode slice + ksh-load flag.

Eprog
check_dump_file(char *file, struct stat *sbuf, char *name,
                int *ksh, int test_only)
{
    int isrec = 0;
    Wordcode d;
    FDHead h;
    FuncDump f;
    struct stat lsbuf;
    if (!sbuf) {
        if (zwcstat(file, &lsbuf)) return NULL;
        sbuf = &lsbuf;
    }
  rec:
    d = NULL;
    for (f = dumps; f; f = f->next)
        if (f->dev == sbuf->st_dev && f->ino == sbuf->st_ino)
            { d = f->map; break; }
    if (!f && (isrec || !(d = load_dump_header(NULL, file, 0))))
        return NULL;
    if ((h = dump_find_func(d, name))) {
        if (test_only) return &dummy_eprog;
        /* allocate Eprog from f->map at h offset, incrdumpcount,
           return prog */
    }
    return NULL;
}

Rust port returns Option<(Vec<u32>, bool)> instead of the C Eprog pointer + *ksh out-param: tuple element 0 is the wordcode slice, element 1 is true if the function was a ksh- loaded entry.