use custom mmap struct type directly
This commit is contained in:
parent
3610b3b1a6
commit
7cb7ac5b42
3 changed files with 28 additions and 36 deletions
|
@ -671,14 +671,6 @@
|
||||||
|
|
||||||
/* General calls. */
|
/* General calls. */
|
||||||
#define VM_MMAP (VM_RQ_BASE+10)
|
#define VM_MMAP (VM_RQ_BASE+10)
|
||||||
# define VMM_ADDR m_mmap.addr
|
|
||||||
# define VMM_LEN m_mmap.len
|
|
||||||
# define VMM_PROT m_mmap.prot
|
|
||||||
# define VMM_FLAGS m_mmap.flags
|
|
||||||
# define VMM_FD m_mmap.fd
|
|
||||||
# define VMM_OFFSET m_mmap.offset
|
|
||||||
# define VMM_FORWHOM m_mmap.forwhom
|
|
||||||
# define VMM_RETADDR m_mmap.retaddr
|
|
||||||
|
|
||||||
#define VM_MUNMAP (VM_RQ_BASE+17)
|
#define VM_MUNMAP (VM_RQ_BASE+17)
|
||||||
# define VMUM_ADDR m_mmap.addr
|
# define VMUM_ADDR m_mmap.addr
|
||||||
|
|
|
@ -25,16 +25,16 @@ void *minix_mmap_for(endpoint_t forwhom,
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
memset(&m, 0, sizeof(m));
|
memset(&m, 0, sizeof(m));
|
||||||
m.VMM_ADDR = addr;
|
m.m_mmap.addr = addr;
|
||||||
m.VMM_LEN = len;
|
m.m_mmap.len = len;
|
||||||
m.VMM_PROT = prot;
|
m.m_mmap.prot = prot;
|
||||||
m.VMM_FLAGS = flags;
|
m.m_mmap.flags = flags;
|
||||||
m.VMM_FD = fd;
|
m.m_mmap.fd = fd;
|
||||||
m.VMM_OFFSET = offset;
|
m.m_mmap.offset = offset;
|
||||||
m.VMM_FORWHOM = forwhom;
|
m.m_mmap.forwhom = forwhom;
|
||||||
|
|
||||||
if(forwhom != SELF) {
|
if(forwhom != SELF) {
|
||||||
m.VMM_FLAGS |= MAP_THIRDPARTY;
|
m.m_mmap.flags |= MAP_THIRDPARTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = _syscall(VM_PROC_NR, VM_MMAP, &m);
|
r = _syscall(VM_PROC_NR, VM_MMAP, &m);
|
||||||
|
@ -43,7 +43,7 @@ void *minix_mmap_for(endpoint_t forwhom,
|
||||||
return MAP_FAILED;
|
return MAP_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.VMM_RETADDR;
|
return m.m_mmap.retaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int minix_vfs_mmap(endpoint_t who, off_t offset, size_t len,
|
int minix_vfs_mmap(endpoint_t who, off_t offset, size_t len,
|
||||||
|
|
|
@ -167,7 +167,7 @@ static void mmap_file_cont(struct vmproc *vmp, message *replymsg, void *cbarg,
|
||||||
int writable = 0;
|
int writable = 0;
|
||||||
vir_bytes v = (vir_bytes) MAP_FAILED;
|
vir_bytes v = (vir_bytes) MAP_FAILED;
|
||||||
|
|
||||||
if(origmsg->VMM_PROT & PROT_WRITE)
|
if(origmsg->m_mmap.prot & PROT_WRITE)
|
||||||
writable = 1;
|
writable = 1;
|
||||||
|
|
||||||
if(replymsg->VMV_RESULT != OK) {
|
if(replymsg->VMV_RESULT != OK) {
|
||||||
|
@ -178,18 +178,18 @@ static void mmap_file_cont(struct vmproc *vmp, message *replymsg, void *cbarg,
|
||||||
result = origmsg->VMV_RESULT;
|
result = origmsg->VMV_RESULT;
|
||||||
} else {
|
} else {
|
||||||
/* Finish mmap */
|
/* Finish mmap */
|
||||||
result = mmap_file(vmp, replymsg->VMV_FD, origmsg->VMM_OFFSET,
|
result = mmap_file(vmp, replymsg->VMV_FD, origmsg->m_mmap.offset,
|
||||||
origmsg->VMM_FLAGS,
|
origmsg->m_mmap.flags,
|
||||||
replymsg->VMV_INO, replymsg->VMV_DEV,
|
replymsg->VMV_INO, replymsg->VMV_DEV,
|
||||||
(u64_t) replymsg->VMV_SIZE_PAGES*PAGE_SIZE,
|
(u64_t) replymsg->VMV_SIZE_PAGES*PAGE_SIZE,
|
||||||
(vir_bytes) origmsg->VMM_ADDR,
|
(vir_bytes) origmsg->m_mmap.addr,
|
||||||
origmsg->VMM_LEN, &v, 0, writable, 1);
|
origmsg->m_mmap.len, &v, 0, writable, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unblock requesting process. */
|
/* Unblock requesting process. */
|
||||||
memset(&mmap_reply, 0, sizeof(mmap_reply));
|
memset(&mmap_reply, 0, sizeof(mmap_reply));
|
||||||
mmap_reply.m_type = result;
|
mmap_reply.m_type = result;
|
||||||
mmap_reply.VMM_RETADDR = (void *) v;
|
mmap_reply.m_mmap.retaddr = (void *) v;
|
||||||
|
|
||||||
if(ipc_send(vmp->vm_endpoint, &mmap_reply) != OK)
|
if(ipc_send(vmp->vm_endpoint, &mmap_reply) != OK)
|
||||||
panic("VM: mmap_file_cont: ipc_send() failed");
|
panic("VM: mmap_file_cont: ipc_send() failed");
|
||||||
|
@ -202,18 +202,18 @@ int do_mmap(message *m)
|
||||||
{
|
{
|
||||||
int r, n;
|
int r, n;
|
||||||
struct vmproc *vmp;
|
struct vmproc *vmp;
|
||||||
vir_bytes addr = (vir_bytes) m->VMM_ADDR;
|
vir_bytes addr = (vir_bytes) m->m_mmap.addr;
|
||||||
struct vir_region *vr = NULL;
|
struct vir_region *vr = NULL;
|
||||||
int execpriv = 0;
|
int execpriv = 0;
|
||||||
size_t len = (vir_bytes) m->VMM_LEN;
|
size_t len = (vir_bytes) m->m_mmap.len;
|
||||||
|
|
||||||
/* RS and VFS can do slightly more special mmap() things */
|
/* RS and VFS can do slightly more special mmap() things */
|
||||||
if(m->m_source == VFS_PROC_NR || m->m_source == RS_PROC_NR)
|
if(m->m_source == VFS_PROC_NR || m->m_source == RS_PROC_NR)
|
||||||
execpriv = 1;
|
execpriv = 1;
|
||||||
|
|
||||||
if(m->VMM_FLAGS & MAP_THIRDPARTY) {
|
if(m->m_mmap.flags & MAP_THIRDPARTY) {
|
||||||
if(!execpriv) return EPERM;
|
if(!execpriv) return EPERM;
|
||||||
if((r=vm_isokendpt(m->VMM_FORWHOM, &n)) != OK)
|
if((r=vm_isokendpt(m->m_mmap.forwhom, &n)) != OK)
|
||||||
return ESRCH;
|
return ESRCH;
|
||||||
} else {
|
} else {
|
||||||
/* regular mmap, i.e. for caller */
|
/* regular mmap, i.e. for caller */
|
||||||
|
@ -230,25 +230,25 @@ int do_mmap(message *m)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m->VMM_FD == -1 || (m->VMM_FLAGS & MAP_ANON)) {
|
if(m->m_mmap.fd == -1 || (m->m_mmap.flags & MAP_ANON)) {
|
||||||
/* actual memory in some form */
|
/* actual memory in some form */
|
||||||
mem_type_t *mt = NULL;
|
mem_type_t *mt = NULL;
|
||||||
|
|
||||||
if(m->VMM_FD != -1) {
|
if(m->m_mmap.fd != -1) {
|
||||||
printf("VM: mmap: fd %d, len 0x%x\n", m->VMM_FD, len);
|
printf("VM: mmap: fd %d, len 0x%x\n", m->m_mmap.fd, len);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Contiguous phys memory has to be preallocated. */
|
/* Contiguous phys memory has to be preallocated. */
|
||||||
if((m->VMM_FLAGS & (MAP_CONTIG|MAP_PREALLOC)) == MAP_CONTIG) {
|
if((m->m_mmap.flags & (MAP_CONTIG|MAP_PREALLOC)) == MAP_CONTIG) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m->VMM_FLAGS & MAP_CONTIG) {
|
if(m->m_mmap.flags & MAP_CONTIG) {
|
||||||
mt = &mem_type_anon_contig;
|
mt = &mem_type_anon_contig;
|
||||||
} else mt = &mem_type_anon;
|
} else mt = &mem_type_anon;
|
||||||
|
|
||||||
if(!(vr = mmap_region(vmp, addr, m->VMM_FLAGS, len,
|
if(!(vr = mmap_region(vmp, addr, m->m_mmap.flags, len,
|
||||||
VR_WRITABLE | VR_ANON, mt, execpriv))) {
|
VR_WRITABLE | VR_ANON, mt, execpriv))) {
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
@ -259,11 +259,11 @@ int do_mmap(message *m)
|
||||||
/* For files, we only can't accept writable MAP_SHARED
|
/* For files, we only can't accept writable MAP_SHARED
|
||||||
* mappings.
|
* mappings.
|
||||||
*/
|
*/
|
||||||
if((m->VMM_FLAGS & MAP_SHARED) && (m->VMM_PROT & PROT_WRITE)) {
|
if((m->m_mmap.flags & MAP_SHARED) && (m->m_mmap.prot & PROT_WRITE)) {
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vfs_request(VMVFSREQ_FDLOOKUP, m->VMM_FD, vmp, 0, 0,
|
if(vfs_request(VMVFSREQ_FDLOOKUP, m->m_mmap.fd, vmp, 0, 0,
|
||||||
mmap_file_cont, NULL, m, sizeof(*m)) != OK) {
|
mmap_file_cont, NULL, m, sizeof(*m)) != OK) {
|
||||||
printf("VM: vfs_request for mmap failed\n");
|
printf("VM: vfs_request for mmap failed\n");
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
|
@ -274,7 +274,7 @@ int do_mmap(message *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return mapping, as seen from process. */
|
/* Return mapping, as seen from process. */
|
||||||
m->VMM_RETADDR = (void *) vr->vaddr;
|
m->m_mmap.retaddr = (void *) vr->vaddr;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue