2 * UCW Library -- Allocation of Large Aligned Buffers
4 * (c) 2006--2007 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.
17 return ALIGN_TO(len, (u64)CPU_PAGE_SIZE);
24 #ifndef CPU_64BIT_POINTERS
26 die("big_alloc: Size %ju is too large for a 32-bit machine", (uintmax_t) len);
29 len += 2*CPU_PAGE_SIZE;
31 byte *p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
32 if (p == (byte*) MAP_FAILED)
33 die("Cannot mmap %ju bytes of memory: %m", (uintmax_t) len);
35 mprotect(p, CPU_PAGE_SIZE, PROT_NONE);
36 mprotect(p+len-CPU_PAGE_SIZE, CPU_PAGE_SIZE, PROT_NONE);
43 big_free(void *start, u64 len)
46 ASSERT(!((uintptr_t) p & (CPU_PAGE_SIZE-1)));
50 len += 2*CPU_PAGE_SIZE;
59 byte *p = big_alloc(123456);