2 * UCW Library -- Allocation of Large Aligned Buffers
4 * (c) 2006 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
15 big_round(unsigned int len)
17 return ALIGN_TO(len, CPU_PAGE_SIZE);
21 big_alloc(unsigned int len)
25 len += 2*CPU_PAGE_SIZE;
27 byte *p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
28 if (p == (byte*) MAP_FAILED)
29 die("Cannot mmap %d bytes of memory: %m", len);
31 mprotect(p, CPU_PAGE_SIZE, PROT_NONE);
32 mprotect(p+len-CPU_PAGE_SIZE, CPU_PAGE_SIZE, PROT_NONE);
39 big_free(void *start, unsigned int len)
42 ASSERT(!((addr_int_t) p & (CPU_PAGE_SIZE-1)));
46 len += 2*CPU_PAGE_SIZE;
55 byte *p = big_alloc(123456);