Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make munmap() actually work #198

Merged
merged 1 commit into from
May 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libc-bottom-half/mman/mman.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ struct map {
int flags;
off_t offset;
size_t length;
char body[];
};

void *mmap(void *addr, size_t length, int prot, int flags,
Expand Down Expand Up @@ -84,8 +83,9 @@ void *mmap(void *addr, size_t length, int prot, int flags,

// Initialize the main memory buffer, either with the contents of a file,
// or with zeros.
addr = map + 1;
if ((flags & MAP_ANON) == 0) {
char *body = map->body;
char *body = (char *)addr;
while (length > 0) {
const ssize_t nread = pread(fd, body, length, offset);
if (nread < 0) {
Expand All @@ -100,10 +100,10 @@ void *mmap(void *addr, size_t length, int prot, int flags,
body += (size_t)nread;
}
} else {
memset(map->body, 0, length);
memset(addr, 0, length);
}

return map->body;
return addr;
}

int munmap(void *addr, size_t length) {
Expand Down