custom message type for VM_SHM_UNMAP
[minix3.git] / lib / libc / sys-minix / mmap.c
blobea073a063afe941e19c21716cdf0b203130188fe
1 #define _SYSTEM 1
2 #define _MINIX_SYSTEM 1
3 #include <sys/cdefs.h>
4 #include "namespace.h"
5 #include <lib.h>
6 #include <minix/u64.h>
7 #include <minix/vm.h>
9 /* INCLUDES HERE */
11 #include <sys/mman.h>
12 #include <stdarg.h>
13 #include <string.h>
14 #include <errno.h>
16 #ifdef __weak_alias
17 __weak_alias(mmap, _mmap)
18 __weak_alias(munmap, _munmap)
19 #endif
21 void *minix_mmap_for(endpoint_t forwhom,
22 void *addr, size_t len, int prot, int flags, int fd, off_t offset)
24 message m;
25 int r;
27 memset(&m, 0, sizeof(m));
28 m.VMM_ADDR = addr;
29 m.VMM_LEN = len;
30 m.VMM_PROT = prot;
31 m.VMM_FLAGS = flags;
32 m.VMM_FD = fd;
33 m.VMM_OFFSET = offset;
34 m.VMM_FORWHOM = forwhom;
36 if(forwhom != SELF) {
37 m.VMM_FLAGS |= MAP_THIRDPARTY;
40 r = _syscall(VM_PROC_NR, VM_MMAP, &m);
42 if(r != OK) {
43 return MAP_FAILED;
46 return m.VMM_RETADDR;
49 int minix_vfs_mmap(endpoint_t who, off_t offset, size_t len,
50 dev_t dev, ino_t ino, int fd, u32_t vaddr, u16_t clearend,
51 u16_t flags)
53 message m;
55 memset(&m, 0, sizeof(message));
57 m.m_vm_vfs_mmap.who = who;
58 m.m_vm_vfs_mmap.offset = offset;
59 m.m_vm_vfs_mmap.dev = dev;
60 m.m_vm_vfs_mmap.ino = ino;
61 m.m_vm_vfs_mmap.vaddr = vaddr;
62 m.m_vm_vfs_mmap.len = len;
63 m.m_vm_vfs_mmap.fd = fd;
64 m.m_vm_vfs_mmap.clearend = clearend;
65 m.m_vm_vfs_mmap.flags = flags;
67 return _syscall(VM_PROC_NR, VM_VFS_MMAP, &m);
70 void *mmap(void *addr, size_t len, int prot, int flags,
71 int fd, off_t offset)
73 return minix_mmap_for(SELF, addr, len, prot, flags, fd, offset);
76 int munmap(void *addr, size_t len)
78 message m;
80 memset(&m, 0, sizeof(m));
81 m.VMUM_ADDR = addr;
82 m.VMUM_LEN = len;
84 return _syscall(VM_PROC_NR, VM_MUNMAP, &m);
88 void *vm_remap(endpoint_t d,
89 endpoint_t s,
90 void *da,
91 void *sa,
92 size_t size)
94 message m;
95 int r;
97 memset(&m, 0, sizeof(m));
98 m.m_lsys_vm_vmremap.destination = d;
99 m.m_lsys_vm_vmremap.source = s;
100 m.m_lsys_vm_vmremap.dest_addr = da;
101 m.m_lsys_vm_vmremap.src_addr = sa;
102 m.m_lsys_vm_vmremap.size = size;
104 r = _syscall(VM_PROC_NR, VM_REMAP, &m);
105 if (r != OK)
106 return MAP_FAILED;
107 return m.m_lsys_vm_vmremap.ret_addr;
110 void *vm_remap_ro(endpoint_t d,
111 endpoint_t s,
112 void *da,
113 void *sa,
114 size_t size)
116 message m;
117 int r;
119 memset(&m, 0, sizeof(m));
120 m.m_lsys_vm_vmremap.destination = d;
121 m.m_lsys_vm_vmremap.source = s;
122 m.m_lsys_vm_vmremap.dest_addr = da;
123 m.m_lsys_vm_vmremap.src_addr = sa;
124 m.m_lsys_vm_vmremap.size = size;
126 r = _syscall(VM_PROC_NR, VM_REMAP_RO, &m);
127 if (r != OK)
128 return MAP_FAILED;
129 return m.m_lsys_vm_vmremap.ret_addr;
132 int vm_unmap(endpoint_t endpt, void *addr)
134 message m;
136 memset(&m, 0, sizeof(m));
137 m.m_lc_vm_shm_unmap.forwhom = endpt;
138 m.m_lc_vm_shm_unmap.addr = addr;
140 return _syscall(VM_PROC_NR, VM_SHM_UNMAP, &m);
143 unsigned long vm_getphys(endpoint_t endpt, void *addr)
145 message m;
146 int r;
148 memset(&m, 0, sizeof(m));
149 m.VMPHYS_ENDPT = endpt;
150 m.VMPHYS_ADDR = (long) addr;
152 r = _syscall(VM_PROC_NR, VM_GETPHYS, &m);
153 if (r != OK)
154 return 0;
155 return m.VMPHYS_RETA;
158 u8_t vm_getrefcount(endpoint_t endpt, void *addr)
160 message m;
161 int r;
163 memset(&m, 0, sizeof(m));
164 m.VMREFCNT_ENDPT = endpt;
165 m.VMREFCNT_ADDR = (long) addr;
167 r = _syscall(VM_PROC_NR, VM_GETREF, &m);
168 if (r != OK)
169 return (u8_t) -1;
170 return (u8_t) m.VMREFCNT_RETC;