void DebugDrawManager::init() { PosColorVertex::init(); m_numLines[0] = m_numLines[1] = 0; m_lines[0] = DEBUG_ALLOC(DebugLine, MAX_DEBUG_LINES); m_lines[1] = DEBUG_ALLOC(DebugLine, MAX_DEBUG_LINES); }
static void* sec_acquire_pages (size_t *sz, const char *during_tag) { void *pages; unsigned long pgsize; ASSERT (sz); ASSERT (*sz); ASSERT (during_tag); /* Make sure sz is a multiple of the page size */ pgsize = getpagesize (); *sz = (*sz + pgsize -1) & ~(pgsize - 1); #if defined(HAVE_MLOCK) pages = mmap (0, *sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (pages == MAP_FAILED) { if (lock_warning && egg_secure_warnings) fprintf (stderr, "couldn't map %lu bytes of memory (%s): %s\n", (unsigned long)*sz, during_tag, strerror (errno)); lock_warning = 0; return NULL; } if (mlock (pages, *sz) < 0) { if (lock_warning && egg_secure_warnings && errno != EPERM) { fprintf (stderr, "couldn't lock %lu bytes of memory (%s): %s\n", (unsigned long)*sz, during_tag, strerror (errno)); lock_warning = 0; } munmap (pages, *sz); return NULL; } DEBUG_ALLOC ("gkr-secure-memory: new block ", *sz); lock_warning = 1; return pages; #else if (lock_warning && egg_secure_warnings) fprintf (stderr, "your system does not support private memory"); lock_warning = 0; return NULL; #endif }
static void sec_release_pages (void *pages, size_t sz) { ASSERT (pages); ASSERT (sz % getpagesize () == 0); #if defined(HAVE_MLOCK) if (munlock (pages, sz) < 0 && egg_secure_warnings) fprintf (stderr, "couldn't unlock private memory: %s\n", strerror (errno)); if (munmap (pages, sz) < 0 && egg_secure_warnings) fprintf (stderr, "couldn't unmap private anonymous memory: %s\n", strerror (errno)); DEBUG_ALLOC ("gkr-secure-memory: freed block ", sz); #else ASSERT (FALSE); #endif }
int efrm_buddy_alloc(struct efrm_buddy_allocator *b, unsigned order) { unsigned smallest; unsigned addr; DEBUG_ALLOC(EFRM_NOTICE("%s(%u)", __FUNCTION__, order)); EFRM_ASSERT(b); /* Find smallest chunk that is big enough. ?? Can optimise this by ** keeping array of pointers to smallest chunk for each order. */ smallest = order; while (smallest <= b->order && efrm_buddy_free_list_empty(b, smallest)) ++smallest; if (smallest > b->order) { DEBUG_ALLOC(EFRM_NOTICE ("buddy - alloc order %d failed - max order %d", order, b->order););
int efrm_buddy_ctor(struct efrm_buddy_allocator *b, unsigned order) { unsigned o; unsigned size = 1 << order; DEBUG_ALLOC(EFRM_NOTICE("%s(%u)", __FUNCTION__, order)); EFRM_ASSERT(b); EFRM_ASSERT(order <= sizeof(unsigned) * 8 - 1); b->order = order; b->free_lists = kmalloc((order + 1) * sizeof(b->free_lists[0]), GFP_KERNEL); if (b->free_lists == NULL) goto fail1; b->links = vmalloc(size * sizeof(b->links[0])); if (b->links == NULL) goto fail2; b->orders = vmalloc(size * sizeof(b->orders[0])); if (b->orders == NULL) goto fail3; memset(b->links, 0, size * sizeof(b->links[0])); for (o = 0; o <= b->order; ++o) INIT_LIST_HEAD(b->free_lists + o); efrm_buddy_free_list_add(b, b->order, 0); return 0; fail3: vfree(b->links); fail2: kfree(b->free_lists); fail1: return -ENOMEM; }