diff --git a/emu/memory.c b/emu/memory.c index 67782c4bbf..593835dd51 100644 --- a/emu/memory.c +++ b/emu/memory.c @@ -115,8 +115,15 @@ int pt_set_flags(struct mem *mem, page_t start, pages_t pages, int flags) { for (page_t page = start; page < start + pages; page++) if (mem->pt[page].data == NULL) return _ENOMEM; - for (page_t page = start; page < start + pages; page++) - mem->pt[page].flags = flags; + for (page_t page = start; page < start + pages; page++) { + struct pt_entry *entry = &mem->pt[page]; + entry->flags = flags; + void *data = (char *) entry->data->data + entry->offset; + int prot = PROT_READ; + if (flags & P_WRITE) prot |= PROT_WRITE; + if (mprotect(data, PAGE_SIZE, prot) < 0) + return errno_map(); + } mem_changed(mem); return 0; } diff --git a/fs/real.c b/fs/real.c index 041c702fab..dca00be9b4 100644 --- a/fs/real.c +++ b/fs/real.c @@ -152,13 +152,17 @@ off_t realfs_lseek(struct fd *fd, off_t offset, int whence) { int realfs_mmap(struct fd *fd, struct mem *mem, page_t start, pages_t pages, off_t offset, int prot, int flags) { if (pages == 0) return 0; + int mmap_flags = 0; if (flags & MMAP_PRIVATE) mmap_flags |= MAP_PRIVATE; if (flags & MMAP_SHARED) mmap_flags |= MAP_SHARED; + int mmap_prot = PROT_READ; + if (prot & P_WRITE) mmap_prot |= PROT_WRITE; + off_t real_offset = (offset / real_page_size) * real_page_size; off_t correction = offset - real_offset; char *memory = mmap(NULL, (pages * PAGE_SIZE) + correction, - PROT_READ | PROT_WRITE, mmap_flags, fd->real_fd, real_offset); + mmap_prot, mmap_flags, fd->real_fd, real_offset); if (memory != MAP_FAILED) memory += correction; return pt_map(mem, start, pages, memory, prot); diff --git a/kernel/exec.c b/kernel/exec.c index fdc4af0ae7..05d6a0cc60 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -67,7 +67,7 @@ static int load_entry(struct prg_header ph, addr_t bias, struct fd *fd) { addr_t memsize = ph.memsize; addr_t filesize = ph.filesize; - int flags = 0; + int flags = P_READ; if (ph.flags & PH_W) flags |= P_WRITE; if ((err = fd->ops->mmap(fd, curmem, PAGE(addr),