static allocnode * getnode(allochead *h) { allocnode *n; heapnode *p; /* If we have no more allocation node slots left then we must allocate * some more memory for them. An extra MP_ALLOCFACTOR pages of memory * should suffice. */ if ((n = (allocnode *) __mp_getslot(&h->table)) == NULL) { if ((p = __mp_heapalloc(&h->heap, h->heap.memory.page * MP_ALLOCFACTOR, h->table.entalign, 1)) == NULL) return NULL; __mp_initslots(&h->table, p->block, p->size); n = (allocnode *) __mp_getslot(&h->table); n->lnode.next = n->lnode.prev = NULL; __mp_treeinsert(&h->itree, &n->tnode, (unsigned long) p->block); n->block = p->block; n->size = p->size; n->info = NULL; h->isize += p->size; n = (allocnode *) __mp_getslot(&h->table); } return n; }
MP_GLOBAL heapnode * __mp_heapalloc(heaphead *h, size_t l, size_t a, int i) { heapnode *n; void *p; size_t s; /* If we have no more heap node slots left then we must allocate * some more memory for them. An extra MP_ALLOCFACTOR pages of memory * should suffice. */ if ((n = (heapnode *) __mp_getslot(&h->table)) == NULL) { s = h->memory.page * MP_ALLOCFACTOR; if ((p = __mp_memalloc(&h->memory, &s, h->table.entalign, 0)) == NULL) return NULL; __mp_initslots(&h->table, p, s); n = (heapnode *) __mp_getslot(&h->table); __mp_treeinsert(&h->itree, &n->node, (unsigned long) p); n->block = p; n->size = s; h->isize += s; if (h->tracing) __mp_traceheap(p, s, 1); #if MP_INUSE_SUPPORT _Inuse_heapalloc(p, s); #endif /* MP_INUSE_SUPPORT */ n = (heapnode *) __mp_getslot(&h->table); } /* Allocate the requested block of memory and add it to the heap. */ if ((p = __mp_memalloc(&h->memory, &l, a, !i)) == NULL) { __mp_freeslot(&h->table, n); return NULL; } __mp_treeinsert(&h->dtree, &n->node, (unsigned long) p); n->block = p; n->size = l; h->dsize += l; if (h->tracing) __mp_traceheap(p, l, i); #if MP_INUSE_SUPPORT _Inuse_heapalloc(p, l); #endif /* MP_INUSE_SUPPORT */ return n; }
static allocation * newalloc(unsigned long i, unsigned long e, void *a, size_t l) { allocation *n; if (n = (allocation *) __mp_search(alloctree.root, i)) { if (n->time == 0) fprintf(stderr, "%s: Allocation index `%lu' has been allocated " "twice without being freed\n", progname, i); } else { if ((n = (allocation *) malloc(sizeof(allocation))) == NULL) { fprintf(stderr, "%s: Out of memory\n", progname); exit(EXIT_FAILURE); } __mp_treeinsert(&alloctree, &n->node, i); n->event = e; } if (simfile != NULL) { if ((n->entry = __mp_getslot(&table)) == NULL) { fprintf(stderr, "%s: Too many allocations in use\n", progname); exit(EXIT_FAILURE); } } else n->entry = NULL; n->addr = a; n->size = l; n->time = 0; return n; }