2 * UCW Library -- Allocation of Large Aligned Buffers
4 * (c) 2006--2007 Martin Mares <mj@ucw.cz>
5 * (c) 2007 Pavel Charvat <char@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
23 die("page_alloc: Size %llu is too large for the current architecture", (long long) len);
24 ASSERT(!(len & (CPU_PAGE_SIZE-1)));
25 byte *p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
26 if (p == (byte*) MAP_FAILED)
27 die("Cannot mmap %llu bytes of memory: %m", (long long)len);
32 page_alloc_zero(u64 len)
34 void *p = page_alloc(len);
40 page_free(void *start, u64 len)
42 ASSERT(!(len & (CPU_PAGE_SIZE-1)));
43 ASSERT(!((uintptr_t) start & (CPU_PAGE_SIZE-1)));
48 page_realloc(void *start, u64 old_len, u64 new_len)
50 void *p = page_alloc(new_len);
51 memcpy(p, start, MIN(old_len, new_len));
52 page_free(start, old_len);
59 return ALIGN_TO(len, (u64)CPU_PAGE_SIZE);
65 u64 l = big_round(len);
66 if (l > SIZE_MAX - 2*CPU_PAGE_SIZE)
67 die("big_alloc: Size %llu is too large for the current architecture", (long long) len);
68 #ifdef CONFIG_UCW_DEBUG
71 byte *p = page_alloc(l);
72 #ifdef CONFIG_UCW_DEBUG
74 mprotect(p, CPU_PAGE_SIZE, PROT_NONE);
75 mprotect(p+l-CPU_PAGE_SIZE, CPU_PAGE_SIZE, PROT_NONE);
82 big_alloc_zero(u64 len)
84 void *p = big_alloc(len);
85 bzero(p, big_round(len));
90 big_free(void *start, u64 len)
93 u64 l = big_round(len);
94 #ifdef CONFIG_UCW_DEBUG
96 mprotect(p, CPU_PAGE_SIZE, PROT_READ);
97 ASSERT(*(u64*)p == len);
107 byte *p = big_alloc(123456);