2011-02-17 18:11:09 +01:00
|
|
|
#define _SYSTEM 1
|
2014-03-05 12:21:55 +01:00
|
|
|
#define _MINIX_SYSTEM 1
|
2011-02-17 18:11:09 +01:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <lib.h>
|
2013-03-20 19:45:10 +01:00
|
|
|
#include <minix/u64.h>
|
|
|
|
#include <minix/vm.h>
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
/* INCLUDES HERE */
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2013-12-06 12:04:52 +01:00
|
|
|
#ifdef __weak_alias
|
|
|
|
__weak_alias(mmap, _mmap)
|
|
|
|
__weak_alias(munmap, _munmap)
|
|
|
|
#endif
|
|
|
|
|
2012-06-06 00:50:13 +02:00
|
|
|
void *minix_mmap_for(endpoint_t forwhom,
|
2013-12-06 12:04:52 +01:00
|
|
|
void *addr, size_t len, int prot, int flags, int fd, off_t offset)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-07-26 13:53:56 +02:00
|
|
|
m.m_mmap.addr = addr;
|
|
|
|
m.m_mmap.len = len;
|
|
|
|
m.m_mmap.prot = prot;
|
|
|
|
m.m_mmap.flags = flags;
|
|
|
|
m.m_mmap.fd = fd;
|
|
|
|
m.m_mmap.offset = offset;
|
|
|
|
m.m_mmap.forwhom = forwhom;
|
2012-06-06 00:50:13 +02:00
|
|
|
|
|
|
|
if(forwhom != SELF) {
|
2014-07-26 13:53:56 +02:00
|
|
|
m.m_mmap.flags |= MAP_THIRDPARTY;
|
2012-06-06 00:50:13 +02:00
|
|
|
}
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_MMAP, &m);
|
|
|
|
|
|
|
|
if(r != OK) {
|
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
|
|
|
|
2014-07-26 13:53:56 +02:00
|
|
|
return m.m_mmap.retaddr;
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|
|
|
|
|
2013-11-28 17:51:21 +01:00
|
|
|
int minix_vfs_mmap(endpoint_t who, off_t offset, size_t len,
|
|
|
|
dev_t dev, ino_t ino, int fd, u32_t vaddr, u16_t clearend,
|
2013-05-07 14:41:07 +02:00
|
|
|
u16_t flags)
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
|
|
|
memset(&m, 0, sizeof(message));
|
|
|
|
|
2013-11-28 18:59:46 +01:00
|
|
|
m.m_vm_vfs_mmap.who = who;
|
|
|
|
m.m_vm_vfs_mmap.offset = offset;
|
|
|
|
m.m_vm_vfs_mmap.dev = dev;
|
|
|
|
m.m_vm_vfs_mmap.ino = ino;
|
|
|
|
m.m_vm_vfs_mmap.vaddr = vaddr;
|
|
|
|
m.m_vm_vfs_mmap.len = len;
|
|
|
|
m.m_vm_vfs_mmap.fd = fd;
|
|
|
|
m.m_vm_vfs_mmap.clearend = clearend;
|
|
|
|
m.m_vm_vfs_mmap.flags = flags;
|
2013-05-07 14:41:07 +02:00
|
|
|
|
|
|
|
return _syscall(VM_PROC_NR, VM_VFS_MMAP, &m);
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:38:29 +01:00
|
|
|
void *mmap(void *addr, size_t len, int prot, int flags,
|
2012-06-06 00:50:13 +02:00
|
|
|
int fd, off_t offset)
|
|
|
|
{
|
|
|
|
return minix_mmap_for(SELF, addr, len, prot, flags, fd, offset);
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:38:29 +01:00
|
|
|
int munmap(void *addr, size_t len)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2011-02-17 18:11:09 +01:00
|
|
|
m.VMUM_ADDR = addr;
|
|
|
|
m.VMUM_LEN = len;
|
|
|
|
|
|
|
|
return _syscall(VM_PROC_NR, VM_MUNMAP, &m);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void *vm_remap(endpoint_t d,
|
2011-02-17 18:11:09 +01:00
|
|
|
endpoint_t s,
|
|
|
|
void *da,
|
|
|
|
void *sa,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-07-26 13:53:43 +02:00
|
|
|
m.m_lsys_vm_vmremap.destination = d;
|
|
|
|
m.m_lsys_vm_vmremap.source = s;
|
|
|
|
m.m_lsys_vm_vmremap.dest_addr = da;
|
|
|
|
m.m_lsys_vm_vmremap.src_addr = sa;
|
|
|
|
m.m_lsys_vm_vmremap.size = size;
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_REMAP, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return MAP_FAILED;
|
2014-07-26 13:53:43 +02:00
|
|
|
return m.m_lsys_vm_vmremap.ret_addr;
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void *vm_remap_ro(endpoint_t d,
|
2011-11-28 19:05:50 +01:00
|
|
|
endpoint_t s,
|
|
|
|
void *da,
|
|
|
|
void *sa,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-07-26 13:53:43 +02:00
|
|
|
m.m_lsys_vm_vmremap.destination = d;
|
|
|
|
m.m_lsys_vm_vmremap.source = s;
|
|
|
|
m.m_lsys_vm_vmremap.dest_addr = da;
|
|
|
|
m.m_lsys_vm_vmremap.src_addr = sa;
|
|
|
|
m.m_lsys_vm_vmremap.size = size;
|
2011-11-28 19:05:50 +01:00
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_REMAP_RO, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return MAP_FAILED;
|
2014-07-26 13:53:43 +02:00
|
|
|
return m.m_lsys_vm_vmremap.ret_addr;
|
2011-11-28 19:05:50 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
int vm_unmap(endpoint_t endpt, void *addr)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-07-26 13:53:44 +02:00
|
|
|
m.m_lc_vm_shm_unmap.forwhom = endpt;
|
|
|
|
m.m_lc_vm_shm_unmap.addr = addr;
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
return _syscall(VM_PROC_NR, VM_SHM_UNMAP, &m);
|
|
|
|
}
|
|
|
|
|
2013-04-23 01:50:45 +02:00
|
|
|
unsigned long vm_getphys(endpoint_t endpt, void *addr)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-07-26 13:53:45 +02:00
|
|
|
m.m_lc_vm_getphys.endpt = endpt;
|
|
|
|
m.m_lc_vm_getphys.addr = addr;
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_GETPHYS, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return 0;
|
2014-07-26 13:53:45 +02:00
|
|
|
return (unsigned long) m.m_lc_vm_getphys.ret_addr;
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
u8_t vm_getrefcount(endpoint_t endpt, void *addr)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-07-26 13:53:46 +02:00
|
|
|
m.m_lsys_vm_getref.endpt = endpt;
|
|
|
|
m.m_lsys_vm_getref.addr = addr;
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_GETREF, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return (u8_t) -1;
|
2014-07-26 13:53:46 +02:00
|
|
|
return (u8_t) m.m_lsys_vm_getref.retc;
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|
|
|
|
|