__aeabi_ldivmod: fix sign logic
[minix.git] / lib / libc / sys-minix / mmap.c
bloba84034e924ee2ea7b86d3971ca97e0fe79cc6530
1 #define _SYSTEM 1
2 #include <sys/cdefs.h>
3 #include "namespace.h"
4 #include <lib.h>
6 /* INCLUDES HERE */
8 #ifdef __weak_alias
9 __weak_alias(vm_remap, _vm_remap)
10 __weak_alias(vm_unmap, _vm_unmap)
11 __weak_alias(vm_getphys, _vm_getphys)
12 __weak_alias(vm_getrefcount, _vm_getrefcount)
13 __weak_alias(minix_mmap, _minix_mmap)
14 __weak_alias(minix_munmap, _minix_munmap)
15 #endif
18 #include <sys/mman.h>
19 #include <stdarg.h>
20 #include <string.h>
21 #include <errno.h>
23 void *minix_mmap_for(endpoint_t forwhom,
24 void *addr, size_t len, int prot, int flags, int fd, off_t offset)
26 message m;
27 int r;
29 m.VMM_ADDR = (vir_bytes) addr;
30 m.VMM_LEN = len;
31 m.VMM_PROT = prot;
32 m.VMM_FLAGS = flags;
33 m.VMM_FD = fd;
34 m.VMM_OFFSET = offset;
35 m.VMM_FORWHOM = forwhom;
37 if(forwhom != SELF) {
38 m.VMM_FLAGS |= MAP_THIRDPARTY;
41 r = _syscall(VM_PROC_NR, VM_MMAP, &m);
43 if(r != OK) {
44 return MAP_FAILED;
47 return (void *) m.VMM_RETADDR;
50 void *minix_mmap(void *addr, size_t len, int prot, int flags,
51 int fd, off_t offset)
53 return minix_mmap_for(SELF, addr, len, prot, flags, fd, offset);
56 int minix_munmap(void *addr, size_t len)
58 message m;
60 m.VMUM_ADDR = addr;
61 m.VMUM_LEN = len;
63 return _syscall(VM_PROC_NR, VM_MUNMAP, &m);
67 void *vm_remap(endpoint_t d,
68 endpoint_t s,
69 void *da,
70 void *sa,
71 size_t size)
73 message m;
74 int r;
76 m.VMRE_D = d;
77 m.VMRE_S = s;
78 m.VMRE_DA = (char *) da;
79 m.VMRE_SA = (char *) sa;
80 m.VMRE_SIZE = size;
82 r = _syscall(VM_PROC_NR, VM_REMAP, &m);
83 if (r != OK)
84 return MAP_FAILED;
85 return (void *) m.VMRE_RETA;
88 void *vm_remap_ro(endpoint_t d,
89 endpoint_t s,
90 void *da,
91 void *sa,
92 size_t size)
94 message m;
95 int r;
97 m.VMRE_D = d;
98 m.VMRE_S = s;
99 m.VMRE_DA = (char *) da;
100 m.VMRE_SA = (char *) sa;
101 m.VMRE_SIZE = size;
103 r = _syscall(VM_PROC_NR, VM_REMAP_RO, &m);
104 if (r != OK)
105 return MAP_FAILED;
106 return (void *) m.VMRE_RETA;
109 int vm_unmap(endpoint_t endpt, void *addr)
111 message m;
113 m.VMUN_ENDPT = endpt;
114 m.VMUN_ADDR = (long) addr;
116 return _syscall(VM_PROC_NR, VM_SHM_UNMAP, &m);
119 unsigned long vm_getphys(int endpt, void *addr)
121 message m;
122 int r;
124 m.VMPHYS_ENDPT = endpt;
125 m.VMPHYS_ADDR = (long) addr;
127 r = _syscall(VM_PROC_NR, VM_GETPHYS, &m);
128 if (r != OK)
129 return 0;
130 return m.VMPHYS_RETA;
133 u8_t vm_getrefcount(endpoint_t endpt, void *addr)
135 message m;
136 int r;
138 m.VMREFCNT_ENDPT = endpt;
139 m.VMREFCNT_ADDR = (long) addr;
141 r = _syscall(VM_PROC_NR, VM_GETREF, &m);
142 if (r != OK)
143 return (u8_t) -1;
144 return (u8_t) m.VMREFCNT_RETC;