etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libsys / alloc_util.c
blobe09bb8e76b35513e3954133686e2d2220afb67b0
2 #include "syslib.h"
4 #include <stdlib.h>
5 #include <errno.h>
6 #include <sys/mman.h>
7 #include <minix/sysutil.h>
9 void *alloc_contig(size_t len, int flags, phys_bytes *phys)
11 void* buf;
12 int mmapflags = MAP_PREALLOC|MAP_CONTIG|MAP_ANON;
14 if(flags & AC_LOWER16M)
15 mmapflags |= MAP_LOWER16M;
16 if(flags & AC_LOWER1M)
17 mmapflags |= MAP_LOWER1M;
18 if(flags & AC_ALIGN64K)
19 mmapflags |= MAP_ALIGNMENT_64KB;
21 /* First try to get memory with mmap. This is guaranteed
22 * to be page-aligned, and we can tell VM it has to be
23 * pre-allocated and contiguous.
25 errno = 0;
26 buf = sef_llvm_ac_mmap(0, len, PROT_READ|PROT_WRITE, mmapflags, -1, 0);
27 if(buf == MAP_FAILED) {
28 return NULL;
31 /* Get physical address, if requested. */
32 if(phys != NULL && sys_umap(SELF, VM_D, (vir_bytes)buf, len,
33 phys) != OK)
34 panic("sys_umap_data_fb failed");
36 return buf;
39 int free_contig(void *addr, size_t len)
41 return sef_llvm_ac_munmap(addr, len);