don't try to mmap 0-sized things (#26)

This commit is contained in:
Ethan Roseman 2022-09-25 02:03:40 +09:00 committed by GitHub
parent b65a585ee3
commit 681137902b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -405,7 +405,9 @@ namespace kernel32 {
fclose(fp);
}
} else if (data.type == handles::TYPE_MAPPED) {
munmap(data.ptr, data.size);
if (data.ptr != (void *) 0x1) {
munmap(data.ptr, data.size);
}
}
return 1;
}
@ -662,10 +664,14 @@ namespace kernel32 {
int64_t size = (int64_t) dwMaximumSizeHigh << 32 | dwMaximumSizeLow;
void* mmapped;
void *mmapped;
if (hFile == (void*) -1) { // INVALID_HANDLE_VALUE
mmapped = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (size == 0) {
mmapped = (void *) 0x1;
} else {
mmapped = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
}
} else {
int fd = fileno(files::fpFromHandle(hFile));
@ -675,7 +681,12 @@ namespace kernel32 {
return (void*) -1;
}
}
mmapped = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (size == 0) {
mmapped = (void *) 0x1;
} else {
mmapped = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
}
}
assert(mmapped != MAP_FAILED);