static struct boundary_tag* allocate_new_tag( unsigned int size ) { unsigned int pages; unsigned int usage; struct boundary_tag *tag; // This is how much space is required. usage = size + sizeof(struct boundary_tag); // Perfect amount of space pages = usage / l_pageSize; if ( (usage % l_pageSize) != 0 ) pages += 1; // Make sure it's >= the minimum size. if ( pages < l_pageCount ) pages = l_pageCount; tag = (struct boundary_tag*)liballoc_alloc( pages ); if ( tag == NULL ) return NULL; // uh oh, we ran out of memory. tag->magic = LIBALLOC_MAGIC; tag->size = size; tag->real_size = pages * l_pageSize; tag->index = -1; tag->next = NULL; tag->prev = NULL; tag->split_left = NULL; tag->split_right = NULL; return tag; }
static struct liballoc_major *allocate_new_page( unsigned int size ) { unsigned int st; struct liballoc_major *maj; // This is how much space is required. st = size + sizeof(struct liballoc_major); st += sizeof(struct liballoc_minor); // Perfect amount of space? if ( (st % l_pageSize) == 0 ) st = st / (l_pageSize); else st = st / (l_pageSize) + 1; // No, add the buffer. // Make sure it's >= the minimum size. if ( st < l_pageCount ) st = l_pageCount; maj = (struct liballoc_major*)liballoc_alloc( st ); if ( maj == NULL ) return NULL; // uh oh, we ran out of memory. maj->prev = NULL; maj->next = NULL; maj->pages = st; maj->usage = sizeof(struct liballoc_major); maj->first = NULL; return maj; }
Process * newProcess(void * entry_point,uint64_t rax,uint64_t rdi, uint64_t rsi, uint64_t ppid,uint8_t fg){ void * stack_base = liballoc_alloc(INIT_STACK_PAGES); Process * ans = (Process *)la_malloc(sizeof(Process)); ans->entry_point = entry_point; ans->stack_base = stack_base; ans->stack_npages = INIT_STACK_PAGES; ans->stack_pointer = fillStackFrame(entry_point,toStackAddress(stack_base,ans->stack_npages),rax,rdi,rsi); ans->pid = pids++; ans->ppid = ppid; ans->fg = fg; return ans; }
static struct liballoc_major *allocate_new_page(unsigned int size) { unsigned int st; struct liballoc_major *maj; // This is how much space is required. st = size + sizeof(struct liballoc_major); st += sizeof(struct liballoc_minor); // Perfect amount of space? if ((st % l_pageSize) == 0) st = st / (l_pageSize); else st = st / (l_pageSize)+1; // No, add the buffer. // Make sure it's >= the minimum size. if (st < l_pageCount) st = l_pageCount; maj = (struct liballoc_major*)liballoc_alloc(st); if (maj == NULL) { l_warningCount += 1; #if defined DEBUG || defined INFO write_serial_string("liballoc: WARNING: liballoc_alloc( %i ) return NULL\n"); FLUSH(); #endif return NULL; // uh oh, we ran out of memory. } maj->prev = NULL; maj->next = NULL; maj->pages = st; maj->size = st * l_pageSize; maj->usage = sizeof(struct liballoc_major); maj->first = NULL; l_allocated += maj->size; #ifdef DEBUG write_serial_string("liballoc: Resource allocated %x of %i pages (%i bytes) for %i size.\n", maj, st, maj->size, size); write_serial_string("liballoc: Total memory usage = %i KB\n", (int)((l_allocated / (1024)))); FLUSH(); #endif return maj; }
static struct boundary_tag* allocate_new_tag( unsigned int size ) { unsigned int pages; unsigned int usage; struct boundary_tag *tag; // This is how much space is required. usage = size + sizeof(struct boundary_tag); // Perfect amount of space pages = usage / l_pageSize; if ( (usage % l_pageSize) != 0 ) pages += 1; // Make sure it's >= the minimum size. if ( pages < l_pageCount ) pages = l_pageCount; tag = (struct boundary_tag*)liballoc_alloc( pages ); if ( tag == NULL ) return NULL; // uh oh, we ran out of memory. tag->magic = LIBALLOC_MAGIC; tag->size = size; tag->real_size = pages * l_pageSize; tag->index = -1; tag->next = NULL; tag->prev = NULL; tag->split_left = NULL; tag->split_right = NULL; #ifdef DEBUG printf("Resource allocated %x of %i pages (%i bytes) for %i size.\n", tag, pages, pages * l_pageSize, size ); l_allocated += pages * l_pageSize; printf("Total memory usage = %i KB\n", (int)((l_allocated / (1024))) ); #endif return tag; }