sysprog21 / semu

A minimalist RISC-V system emulator capable of running Linux kernel
MIT License
251 stars 47 forks source link

Replace fread with mmap #18

Closed zoanana990 closed 1 year ago

zoanana990 commented 1 year ago

Replace fread with mmap method

Performance comparison Load Linux image:

jserv commented 1 year ago

Check https://github.com/jserv/semu/blob/master/CONTRIBUTING.md carefully and ensure the consistent style.

jserv commented 1 year ago

Any update?

zoanana990 commented 1 year ago

yes, coding style was changed, but i don't know why i need to use atexit(3) to perform the munmap operation, is this for error handling? like the following code:

void cleanup(*addr, size_t len)
{
    munmap(...)
}
static void read_file_into_ram(char **ram_loc, const char *name)
{
...
    if (*ram_loc == MAP_FAILED) {
        fprintf(stderr, "mmap failed\n");
        atexit(cleanup);
    }
}
jserv commented 1 year ago

yes, coding style was changed, but i don't know why i need to use atexit(3) to perform the munmap operation, is this for error handling? like the following code:

No, atexit is invoked right after mmap succeeds. It is used for normal execution path rather than the abnormal one. i.e., exception handling.

jserv commented 1 year ago

Superseded by commit 944a51d612aef623b51ebcdd4956336bae61e0a6

jserv commented 1 year ago

Thank @zoanana990 for contributing.