2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
#define _SYSTEM 1
|
|
|
|
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
#include <minix/ds.h>
|
|
|
|
#include <minix/endpoint.h>
|
|
|
|
#include <minix/keymap.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <minix/type.h>
|
|
|
|
#include <minix/ipc.h>
|
|
|
|
#include <minix/sysutil.h>
|
|
|
|
#include <minix/syslib.h>
|
|
|
|
#include <minix/safecopies.h>
|
2009-09-21 16:49:49 +02:00
|
|
|
#include <minix/bitmap.h>
|
2010-04-12 13:25:24 +02:00
|
|
|
#include <minix/debug.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
2010-04-12 13:25:24 +02:00
|
|
|
#include <assert.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <env.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <memory.h>
|
|
|
|
|
|
|
|
#include "glo.h"
|
|
|
|
#include "proto.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "region.h"
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_mmap *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_mmap(message *m)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
int mfflags = 0;
|
2012-01-22 18:20:45 +01:00
|
|
|
vir_bytes addr;
|
2008-11-19 13:26:10 +01:00
|
|
|
struct vir_region *vr = NULL;
|
2012-06-06 19:05:28 +02:00
|
|
|
int execpriv = 0;
|
|
|
|
|
|
|
|
/* RS and VFS can do slightly more special mmap() things */
|
|
|
|
if(m->m_source == VFS_PROC_NR || m->m_source == RS_PROC_NR)
|
|
|
|
execpriv = 1;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2012-06-06 00:50:13 +02:00
|
|
|
if(m->VMM_FLAGS & MAP_THIRDPARTY) {
|
2012-06-06 19:05:28 +02:00
|
|
|
if(!execpriv) return EPERM;
|
2012-06-06 00:50:13 +02:00
|
|
|
if((r=vm_isokendpt(m->VMM_FORWHOM, &n)) != OK)
|
|
|
|
return ESRCH;
|
|
|
|
} else {
|
|
|
|
/* regular mmap, i.e. for caller */
|
|
|
|
if((r=vm_isokendpt(m->m_source, &n)) != OK) {
|
|
|
|
panic("do_mmap: message from strange source: %d",
|
|
|
|
m->m_source);
|
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
vmp = &vmproc[n];
|
|
|
|
|
|
|
|
if(!(vmp->vm_flags & VMF_HASPT))
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
if(m->VMM_FD == -1 || (m->VMM_FLAGS & MAP_ANON)) {
|
2009-02-12 13:26:08 +01:00
|
|
|
u32_t vrflags = VR_ANON | VR_WRITABLE;
|
2008-11-19 13:26:10 +01:00
|
|
|
size_t len = (vir_bytes) m->VMM_LEN;
|
|
|
|
|
2011-07-19 08:58:01 +02:00
|
|
|
if(m->VMM_FD != -1 || len <= 0) {
|
2008-11-19 13:26:10 +01:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-07-20 20:57:25 +02:00
|
|
|
/* Contiguous phys memory has to be preallocated. */
|
|
|
|
if((m->VMM_FLAGS & (MAP_CONTIG|MAP_PREALLOC)) == MAP_CONTIG) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
if(m->VMM_FLAGS & MAP_PREALLOC) mfflags |= MF_PREALLOC;
|
2009-09-21 16:49:49 +02:00
|
|
|
if(m->VMM_FLAGS & MAP_LOWER16M) vrflags |= VR_LOWER16MB;
|
|
|
|
if(m->VMM_FLAGS & MAP_LOWER1M) vrflags |= VR_LOWER1MB;
|
2009-02-12 13:26:08 +01:00
|
|
|
if(m->VMM_FLAGS & MAP_ALIGN64K) vrflags |= VR_PHYS64K;
|
2012-06-06 19:05:28 +02:00
|
|
|
if(m->VMM_FLAGS & MAP_UNINITIALIZED) {
|
|
|
|
if(!execpriv) return EPERM;
|
|
|
|
vrflags |= VR_UNINITIALIZED;
|
|
|
|
}
|
2011-07-15 18:10:50 +02:00
|
|
|
if(m->VMM_FLAGS & MAP_IPC_SHARED) {
|
|
|
|
vrflags |= VR_SHARED;
|
|
|
|
/* Shared memory has to be preallocated. */
|
2011-09-08 15:57:03 +02:00
|
|
|
if((m->VMM_FLAGS & (MAP_PREALLOC|MAP_ANON)) !=
|
2011-07-15 18:10:50 +02:00
|
|
|
(MAP_PREALLOC|MAP_ANON)) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2010-04-12 13:25:24 +02:00
|
|
|
if(m->VMM_FLAGS & MAP_CONTIG) vrflags |= VR_CONTIG;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
if(len % VM_PAGE_SIZE)
|
|
|
|
len += VM_PAGE_SIZE - (len % VM_PAGE_SIZE);
|
|
|
|
|
2012-01-22 18:20:45 +01:00
|
|
|
vr = NULL;
|
2012-05-30 19:34:07 +02:00
|
|
|
if (m->VMM_ADDR || (m->VMM_FLAGS & MAP_FIXED)) {
|
2012-01-22 18:20:45 +01:00
|
|
|
/* An address is given, first try at that address. */
|
|
|
|
addr = arch_vir2map(vmp, m->VMM_ADDR);
|
|
|
|
vr = map_page_region(vmp, addr, 0, len, MAP_NONE,
|
|
|
|
vrflags, mfflags);
|
2012-04-11 17:15:15 +02:00
|
|
|
if(!vr && (m->VMM_FLAGS & MAP_FIXED))
|
|
|
|
return ENOMEM;
|
2012-01-22 18:20:45 +01:00
|
|
|
}
|
|
|
|
if (!vr) {
|
|
|
|
/* No address given or address already in use. */
|
|
|
|
addr = arch_vir2map(vmp, vmp->vm_stacktop);
|
|
|
|
vr = map_page_region(vmp, addr, VM_DATATOP, len,
|
|
|
|
MAP_NONE, vrflags, mfflags);
|
|
|
|
}
|
|
|
|
if (!vr) {
|
2008-11-19 13:26:10 +01:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return mapping, as seen from process. */
|
2010-04-12 14:37:28 +02:00
|
|
|
assert(vr);
|
2008-11-19 13:26:10 +01:00
|
|
|
m->VMM_RETADDR = arch_map2vir(vmp, vr->vaddr);
|
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2009-11-03 12:12:23 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* map_perm_check *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int map_perm_check(endpoint_t caller, endpoint_t target,
|
2009-11-03 12:12:23 +01:00
|
|
|
phys_bytes physaddr, phys_bytes len)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* TTY and memory are allowed to do anything.
|
|
|
|
* They have to be special cases as they have to be able to do
|
|
|
|
* anything; TTY even on behalf of anyone for the TIOCMAPMEM
|
|
|
|
* ioctl. MEM just for itself.
|
|
|
|
*/
|
|
|
|
if(caller == TTY_PROC_NR)
|
|
|
|
return OK;
|
|
|
|
if(caller != target)
|
|
|
|
return EPERM;
|
|
|
|
if(caller == MEM_PROC_NR)
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
/* Anyone else needs explicit permission from the kernel (ultimately
|
|
|
|
* set by PCI).
|
|
|
|
*/
|
|
|
|
r = sys_privquery_mem(caller, physaddr, len);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_map_phys *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_map_phys(message *m)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
endpoint_t target;
|
|
|
|
struct vir_region *vr;
|
2008-12-11 18:36:33 +01:00
|
|
|
vir_bytes len;
|
2009-11-03 12:12:23 +01:00
|
|
|
phys_bytes startaddr;
|
2010-10-21 19:07:05 +02:00
|
|
|
size_t offset;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
target = m->VMMP_EP;
|
2009-11-03 12:12:23 +01:00
|
|
|
len = m->VMMP_LEN;
|
|
|
|
|
2011-07-19 08:58:01 +02:00
|
|
|
if (len <= 0) return EINVAL;
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
if(target == SELF)
|
|
|
|
target = m->m_source;
|
|
|
|
|
2008-12-08 17:43:20 +01:00
|
|
|
if((r=vm_isokendpt(target, &n)) != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
return EINVAL;
|
|
|
|
|
2009-11-03 12:12:23 +01:00
|
|
|
startaddr = (vir_bytes)m->VMMP_PHADDR;
|
|
|
|
|
|
|
|
/* First check permission, then round range down/up. Caller can't
|
|
|
|
* help it if we can't map in lower than page granularity.
|
|
|
|
*/
|
|
|
|
if(map_perm_check(m->m_source, target, startaddr, len) != OK) {
|
|
|
|
printf("VM: unauthorized mapping of 0x%lx by %d\n",
|
|
|
|
startaddr, m->m_source);
|
|
|
|
return EPERM;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
vmp = &vmproc[n];
|
|
|
|
|
|
|
|
if(!(vmp->vm_flags & VMF_HASPT))
|
|
|
|
return ENXIO;
|
|
|
|
|
2010-10-21 19:07:05 +02:00
|
|
|
offset = startaddr % VM_PAGE_SIZE;
|
|
|
|
len += offset;
|
|
|
|
startaddr -= offset;
|
|
|
|
|
2008-12-11 18:36:33 +01:00
|
|
|
if(len % VM_PAGE_SIZE)
|
|
|
|
len += VM_PAGE_SIZE - (len % VM_PAGE_SIZE);
|
|
|
|
|
2008-12-08 17:43:20 +01:00
|
|
|
if(!(vr = map_page_region(vmp, arch_vir2map(vmp, vmp->vm_stacktop),
|
2009-11-03 12:12:23 +01:00
|
|
|
VM_DATATOP, len, startaddr,
|
2008-11-19 13:26:10 +01:00
|
|
|
VR_DIRECT | VR_NOPF | VR_WRITABLE, 0))) {
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2010-10-21 19:07:05 +02:00
|
|
|
m->VMMP_VADDR_REPLY = (void *) (arch_map2vir(vmp, vr->vaddr) + offset);
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_unmap_phys *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_unmap_phys(message *m)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
endpoint_t target;
|
|
|
|
struct vir_region *region;
|
|
|
|
|
|
|
|
target = m->VMUP_EP;
|
|
|
|
if(target == SELF)
|
|
|
|
target = m->m_source;
|
|
|
|
|
2008-12-08 17:43:20 +01:00
|
|
|
if((r=vm_isokendpt(target, &n)) != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
vmp = &vmproc[n];
|
|
|
|
|
2008-12-08 17:43:20 +01:00
|
|
|
if(!(region = map_lookup(vmp,
|
|
|
|
arch_vir2map(vmp, (vir_bytes) m->VMUM_ADDR)))) {
|
2008-11-19 13:26:10 +01:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(region->flags & VR_DIRECT)) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
if(map_unmap_region(vmp, region, region->length) != OK) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_remap *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_remap(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
2010-06-09 11:14:53 +02:00
|
|
|
int dn, sn;
|
2009-09-21 16:49:49 +02:00
|
|
|
vir_bytes da, sa, startv;
|
|
|
|
size_t size;
|
2011-06-01 11:30:58 +02:00
|
|
|
struct vir_region *region;
|
2009-09-21 16:49:49 +02:00
|
|
|
struct vmproc *dvmp, *svmp;
|
|
|
|
int r;
|
2011-11-28 19:05:50 +01:00
|
|
|
int readonly;
|
|
|
|
|
|
|
|
if(m->m_type == VM_REMAP)
|
|
|
|
readonly = 0;
|
|
|
|
else if(m->m_type == VM_REMAP_RO)
|
|
|
|
readonly = 1;
|
|
|
|
else panic("do_remap: can't be");
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
da = (vir_bytes) m->VMRE_DA;
|
|
|
|
sa = (vir_bytes) m->VMRE_SA;
|
|
|
|
size = m->VMRE_SIZE;
|
|
|
|
|
2011-07-19 08:58:01 +02:00
|
|
|
if (size <= 0) return EINVAL;
|
|
|
|
|
2010-06-09 11:14:53 +02:00
|
|
|
if ((r = vm_isokendpt((endpoint_t) m->VMRE_D, &dn)) != OK)
|
2009-09-21 16:49:49 +02:00
|
|
|
return EINVAL;
|
2010-06-09 11:14:53 +02:00
|
|
|
if ((r = vm_isokendpt((endpoint_t) m->VMRE_S, &sn)) != OK)
|
2009-09-21 16:49:49 +02:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
dvmp = &vmproc[dn];
|
|
|
|
svmp = &vmproc[sn];
|
|
|
|
|
|
|
|
/* da is not translated by arch_vir2map(),
|
|
|
|
* it's handled a little differently,
|
|
|
|
* since in map_remap(), we have to know
|
|
|
|
* about whether the user needs to bind to
|
|
|
|
* THAT address or be chosen by the system.
|
|
|
|
*/
|
|
|
|
sa = arch_vir2map(svmp, sa);
|
|
|
|
|
|
|
|
if (!(region = map_lookup(svmp, sa)))
|
|
|
|
return EINVAL;
|
|
|
|
|
2010-04-12 13:25:24 +02:00
|
|
|
if(region->vaddr != sa) {
|
|
|
|
printf("VM: do_remap: not start of region.\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(region->flags & VR_SHARED)) {
|
|
|
|
printf("VM: do_remap: not shared.\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size % VM_PAGE_SIZE)
|
|
|
|
size += VM_PAGE_SIZE - size % VM_PAGE_SIZE;
|
|
|
|
|
|
|
|
if(size != region->length) {
|
|
|
|
printf("VM: do_remap: not size of region.\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
2011-11-28 19:05:50 +01:00
|
|
|
if ((r = map_remap(dvmp, da, size, region, &startv, readonly)) != OK)
|
2009-09-21 16:49:49 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
m->VMRE_RETA = (char *) arch_map2vir(dvmp, startv);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_shared_unmap *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_shared_unmap(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
endpoint_t target;
|
|
|
|
struct vir_region *vr;
|
|
|
|
vir_bytes addr;
|
|
|
|
|
|
|
|
target = m->VMUN_ENDPT;
|
2011-10-18 20:21:07 +02:00
|
|
|
if (target == SELF)
|
|
|
|
target = m->m_source;
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
if ((r = vm_isokendpt(target, &n)) != OK)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
vmp = &vmproc[n];
|
|
|
|
|
|
|
|
addr = arch_vir2map(vmp, m->VMUN_ADDR);
|
|
|
|
|
|
|
|
if(!(vr = map_lookup(vmp, addr))) {
|
|
|
|
printf("VM: addr 0x%lx not found.\n", m->VMUN_ADDR);
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vr->vaddr != addr) {
|
|
|
|
printf("VM: wrong address for shared_unmap.\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(vr->flags & VR_SHARED)) {
|
|
|
|
printf("VM: address does not point to shared region.\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map_unmap_region(vmp, vr, vr->length) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_shared_unmap: map_unmap_region failed");
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_get_phys *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_get_phys(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
endpoint_t target;
|
|
|
|
phys_bytes ret;
|
|
|
|
vir_bytes addr;
|
|
|
|
|
|
|
|
target = m->VMPHYS_ENDPT;
|
|
|
|
addr = m->VMPHYS_ADDR;
|
|
|
|
|
|
|
|
if ((r = vm_isokendpt(target, &n)) != OK)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
vmp = &vmproc[n];
|
|
|
|
addr = arch_vir2map(vmp, addr);
|
|
|
|
|
|
|
|
r = map_get_phys(vmp, addr, &ret);
|
|
|
|
|
|
|
|
m->VMPHYS_RETA = ret;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_get_refcount *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_get_refcount(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
endpoint_t target;
|
|
|
|
u8_t cnt;
|
|
|
|
vir_bytes addr;
|
|
|
|
|
|
|
|
target = m->VMREFCNT_ENDPT;
|
|
|
|
addr = m->VMREFCNT_ADDR;
|
|
|
|
|
|
|
|
if ((r = vm_isokendpt(target, &n)) != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
return EINVAL;
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
vmp = &vmproc[n];
|
|
|
|
addr = arch_vir2map(vmp, addr);
|
|
|
|
|
|
|
|
r = map_get_ref(vmp, addr, &cnt);
|
|
|
|
|
|
|
|
m->VMREFCNT_RETC = cnt;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_munmap *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_munmap(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
int r, n;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
vir_bytes addr, len;
|
|
|
|
struct vir_region *vr;
|
|
|
|
|
|
|
|
if((r=vm_isokendpt(m->m_source, &n)) != OK) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_mmap: message from strange source: %d", m->m_source);
|
2009-09-21 16:49:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vmp = &vmproc[n];
|
|
|
|
|
|
|
|
if(!(vmp->vm_flags & VMF_HASPT))
|
|
|
|
return ENXIO;
|
2009-09-23 15:34:04 +02:00
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
if(m->m_type == VM_MUNMAP) {
|
|
|
|
addr = (vir_bytes) arch_vir2map(vmp, (vir_bytes) m->VMUM_ADDR);
|
|
|
|
} else if(m->m_type == VM_MUNMAP_TEXT) {
|
|
|
|
addr = (vir_bytes) arch_vir2map_text(vmp, (vir_bytes) m->VMUM_ADDR);
|
|
|
|
} else {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_munmap: strange type");
|
2009-09-21 16:49:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(vr = map_lookup(vmp, addr))) {
|
2010-07-05 15:58:57 +02:00
|
|
|
printf("VM: unmap: virtual address %p not found in %d\n",
|
2009-09-21 16:49:49 +02:00
|
|
|
m->VMUM_ADDR, vmp->vm_endpoint);
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = m->VMUM_LEN;
|
2010-01-05 10:40:07 +01:00
|
|
|
if (len % VM_PAGE_SIZE)
|
|
|
|
len += VM_PAGE_SIZE - (len % VM_PAGE_SIZE);
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
if(addr != vr->vaddr || len > vr->length || len < VM_PAGE_SIZE) {
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(map_unmap_region(vmp, vr, len) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_munmap: map_unmap_region failed");
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unmap_ok = 0;
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* munmap_lin (used for overrides for VM) *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int munmap_lin(vir_bytes addr, size_t len)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
if(addr % VM_PAGE_SIZE) {
|
|
|
|
printf("munmap_lin: offset not page aligned\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len % VM_PAGE_SIZE) {
|
|
|
|
printf("munmap_lin: len not page aligned\n");
|
|
|
|
return EFAULT;
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:11:12 +02:00
|
|
|
if(pt_writemap(NULL, &vmproc[VM_PROC_NR].vm_pt, addr, MAP_NONE, len, 0,
|
2009-09-21 16:49:49 +02:00
|
|
|
WMF_OVERWRITE | WMF_FREE) != OK) {
|
|
|
|
printf("munmap_lin: pt_writemap failed\n");
|
|
|
|
return EFAULT;
|
2008-11-19 13:26:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2009-09-21 16:49:49 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* munmap (override for VM) *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int minix_munmap(void *addr, size_t len)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
vir_bytes laddr;
|
|
|
|
if(!unmap_ok)
|
|
|
|
return ENOSYS;
|
|
|
|
laddr = (vir_bytes) arch_vir2map(&vmproc[VM_PROC_NR], (vir_bytes) addr);
|
|
|
|
return munmap_lin(laddr, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* munmap_text (override for VM) *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int minix_munmap_text(void *addr, size_t len)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
|
|
|
vir_bytes laddr;
|
|
|
|
if(!unmap_ok)
|
|
|
|
return ENOSYS;
|
|
|
|
laddr = (vir_bytes) arch_vir2map_text(&vmproc[VM_PROC_NR],
|
|
|
|
(vir_bytes) addr);
|
|
|
|
return munmap_lin(laddr, len);
|
|
|
|
}
|
|
|
|
|