2011-02-17 18:11:09 +01:00
|
|
|
#define _SYSTEM 1
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <lib.h>
|
|
|
|
|
|
|
|
/* INCLUDES HERE */
|
|
|
|
|
|
|
|
#ifdef __weak_alias
|
|
|
|
__weak_alias(vm_remap, _vm_remap)
|
|
|
|
__weak_alias(vm_unmap, _vm_unmap)
|
|
|
|
__weak_alias(vm_getphys, _vm_getphys)
|
|
|
|
__weak_alias(vm_getrefcount, _vm_getrefcount)
|
2011-07-16 16:52:21 +02:00
|
|
|
__weak_alias(minix_mmap, _minix_mmap)
|
|
|
|
__weak_alias(minix_munmap, _minix_munmap)
|
2011-02-17 18:11:09 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2012-06-06 00:50:13 +02:00
|
|
|
void *minix_mmap_for(endpoint_t forwhom,
|
|
|
|
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;
|
|
|
|
|
|
|
|
m.VMM_ADDR = (vir_bytes) addr;
|
|
|
|
m.VMM_LEN = len;
|
|
|
|
m.VMM_PROT = prot;
|
|
|
|
m.VMM_FLAGS = flags;
|
|
|
|
m.VMM_FD = fd;
|
|
|
|
m.VMM_OFFSET = offset;
|
2012-06-06 00:50:13 +02:00
|
|
|
m.VMM_FORWHOM = forwhom;
|
|
|
|
|
|
|
|
if(forwhom != SELF) {
|
|
|
|
m.VMM_FLAGS |= MAP_THIRDPARTY;
|
|
|
|
}
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_MMAP, &m);
|
|
|
|
|
|
|
|
if(r != OK) {
|
|
|
|
return MAP_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (void *) m.VMM_RETADDR;
|
|
|
|
}
|
|
|
|
|
2012-06-06 00:50:13 +02:00
|
|
|
void *minix_mmap(void *addr, size_t len, int prot, int flags,
|
|
|
|
int fd, off_t offset)
|
|
|
|
{
|
|
|
|
return minix_mmap_for(SELF, addr, len, prot, flags, fd, offset);
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
int minix_munmap(void *addr, size_t len)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
m.VMRE_D = d;
|
|
|
|
m.VMRE_S = s;
|
|
|
|
m.VMRE_DA = (char *) da;
|
|
|
|
m.VMRE_SA = (char *) sa;
|
|
|
|
m.VMRE_SIZE = size;
|
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_REMAP, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return MAP_FAILED;
|
|
|
|
return (void *) m.VMRE_RETA;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
m.VMRE_D = d;
|
|
|
|
m.VMRE_S = s;
|
|
|
|
m.VMRE_DA = (char *) da;
|
|
|
|
m.VMRE_SA = (char *) sa;
|
|
|
|
m.VMRE_SIZE = size;
|
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_REMAP_RO, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return MAP_FAILED;
|
|
|
|
return (void *) m.VMRE_RETA;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
m.VMUN_ENDPT = endpt;
|
|
|
|
m.VMUN_ADDR = (long) addr;
|
|
|
|
|
|
|
|
return _syscall(VM_PROC_NR, VM_SHM_UNMAP, &m);
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
unsigned long vm_getphys(int endpt, void *addr)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
m.VMPHYS_ENDPT = endpt;
|
|
|
|
m.VMPHYS_ADDR = (long) addr;
|
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_GETPHYS, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return 0;
|
|
|
|
return m.VMPHYS_RETA;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
m.VMREFCNT_ENDPT = endpt;
|
|
|
|
m.VMREFCNT_ADDR = (long) addr;
|
|
|
|
|
|
|
|
r = _syscall(VM_PROC_NR, VM_GETREF, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return (u8_t) -1;
|
|
|
|
return (u8_t) m.VMREFCNT_RETC;
|
|
|
|
}
|
|
|
|
|