struct service * service_create(const char * name, struct process * owner) { if(rbtree_key_exists(service_table, name)) return 0; struct service * retval = mm_allocate(sizeof(struct service), MM_DEFAULT_ALIGNMENT, MM_MEM_NORMAL); retval->name = mm_allocate(strlen(name) + 1, MM_DEFAULT_ALIGNMENT, MM_MEM_NORMAL); memcpy(retval->name, name, strlen(name) + 1); retval->owner = owner; retval->listening_thread = 0; retval->backlog = queue_new(); rbtree_insert(service_table, name, retval); return retval; }
struct thread_context * context_new(void) { struct thread_context * retval = mm_allocate(sizeof(struct thread_context), MM_DEFAULT_ALIGNMENT, MM_MEM_NORMAL); memclr(retval, sizeof(struct thread_context)); // Set the initial mode to user-mode, ARM instruction mode: retval->spsr = PROCESSOR_MODE_USR; return retval; }
struct irq_object * irq_object_create(unsigned irq) { if(irq_get_handler(irq) != 0) return 0; struct irq_object * retval = mm_allocate(sizeof(struct irq_object), MM_DEFAULT_ALIGNMENT, MM_MEM_NORMAL); retval->irq = irq; retval->listener = 0; irq_register(irq, irq_object_handler, retval); return retval; }
BLOCK *MemoryManager::new_block(void) { BLOCK *b; b = mm_allocate(BLOCK); if (b == NULL) { return NULL; } b->block = new_array(quint8, BLOCKSIZE); if (b->block == NULL) { MemoryManager::free_ptr(b); return NULL; } b->ptr = b->block; b->remain = BLOCKSIZE; b->next = NULL; return b; }
TREELIST *MemoryManager::cluster_tree(unsigned int cluster) { int bucket; TREELIST *tl, *last; /* Pick a bucket, any bucket. */ bucket = cluster % TBUCKETS; /* Find the tree in this bucket with that cluster number. */ last = NULL; for (tl = Treelist[bucket]; tl; tl = tl->next) { if (tl->cluster == cluster) { break; } last = tl; } /* If we didn't find it, make a new one and add it to the list. */ if (tl == NULL) { tl = mm_allocate(TREELIST); if (tl == NULL) { return NULL; } tl->tree = NULL; tl->cluster = cluster; tl->next = NULL; if (last == NULL) { Treelist[bucket] = tl; } else { last->next = tl; } } return tl; }