Example #1
0
int Main() {

    heap_init(&max_heap,malloc(sizeof(int)*M),0,sizeof(int),&max_compare);
    heap_init(&min_heap,malloc(sizeof(int)*M),0,sizeof(int),&min_compare);

    return 0;
}
Example #2
0
int __init vmm_heap_init(void)
{
	int rc;

	/*
	 * Always create normal heap first as book keeping area for other heaps
	 * is allocated from normal heap
	 */

	/* Create Normal heap */
	rc = heap_init(&normal_heap, TRUE,
			CONFIG_HEAP_SIZE_MB * 1024,
			VMM_MEMORY_FLAGS_NORMAL);
	if (rc) {
		return rc;
	}

	/* Create DMA heap */
	rc= heap_init(&dma_heap, FALSE,
			CONFIG_DMA_HEAP_SIZE_KB,
			VMM_MEMORY_FLAGS_DMA);
	if (rc) {
		return rc;
	}

	return VMM_OK;
}
Example #3
0
File: main.c Project: AYFY/Lab7
int main()
{
	void* ptr1 = NULL;
	void* ptr2 = NULL;
	void* ptr3 = NULL;
	void* ptr4 = NULL;
	void* ptr5 = NULL;
	void* ptr6 = NULL;
	void* ptr7 = NULL;
	printf("\nProgram starts here:\n");
	
	heap_init(getpagesize());
	
	ptr1 = _malloc(1000);
	ptr2 = _malloc(500);
	ptr6 = _malloc(100);
	ptr7 = _malloc(5000);
	_free(ptr2);
	_free(ptr1);
	_free(ptr6);
	ptr1 = _malloc(1000);
	memalloc_debug_heap(stderr, HEAP_START);
	printf("Program finished.\n");
	
    return 0;
}
Example #4
0
PmReturn_t
pm_init(uint8_t *heap_base, uint32_t heap_size,
        PmMemSpace_t memspace, uint8_t const * const pusrimg)
{
    PmReturn_t retval;

    /* Initialize the hardware platform */
    retval = plat_init();
    PM_RETURN_IF_ERROR(retval);

    /* Initialize the heap and the globals */
    retval = heap_init(heap_base, heap_size);
    PM_RETURN_IF_ERROR(retval);

    retval = global_init();
    PM_RETURN_IF_ERROR(retval);

    /* Load usr image info if given */
    if (pusrimg != C_NULL)
    {
        retval = img_appendToPath(memspace, pusrimg);
    }

    return retval;
}
Example #5
0
void kmain(multiboot_info_t* mbt, unsigned int magic)
{
    if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
        return;

    graphics_init();

    /* Core modules */
    gdt_init();
    idt_init();
    irq_init();
    isr_init();
    
    /* Kernel heap */
    heap_init();
    
    /* Drivers */
    timer_init();
    tasking_init();
    keyboard_init();
    
    /* Let the games begin */
    set_interrupts(ENABLED);
    
    kprintf("Running kernel tests...\n\n");
    test_kmalloc_kfree();
    test_list();
    test_tasking();
    kprintf("\nDone with kernel tests.\n");
    
    for (;;);
}
void new_characters(heap_t *h, cell_t *cell_arr,
		    character **c_arr, room_t *room_arr,
		    int t_char, int num_room)
{
  int i;

  for(i = 1; i < t_char; i++)
    {
      delete (character *)(*(c_arr +i));
    }

  heap_delete(h);
  
  heap_init(h, character_cmp, 0);

  ((pc *)(*c_arr))->place_pc(cell_arr, room_arr, num_room);

  heap_insert(h, *(c_arr + 0));

  for(i = 1; i < t_char; i++)
    {
      *(c_arr + i) = new npc(cell_arr, room_arr, num_room, i); 

      heap_insert(h, *(c_arr + i));
    }
}
Example #7
0
/*********************************************************************************************************
** Function name:           kheap_create
** Descriptions:            创建内核内存堆
** input parameters:        NONE
** output parameters:       NONE
** Returned value:          NONE
*********************************************************************************************************/
void kheap_create(void)
{
    heap_init(&kern_heap, "kern", (void *)KERN_HEAP_BASE, KERN_HEAP_SIZE);

#if defined(DMA_MEM_BASE) && DMA_MEM_SIZE > 0
    heap_init(&dma_heap, "dma", (void *)DMA_MEM_BASE, DMA_MEM_SIZE);
#endif

#if defined(HW_SHARE_MEM_BASE) && HW_SHARE_MEM_SIZE > 0
    heap_init(&hw_share_heap, "hw_share", (void *)HW_SHARE_MEM_BASE, HW_SHARE_MEM_SIZE);
#endif

#if defined(SW_SHARE_MEM_BASE) && SW_SHARE_MEM_SIZE > 0
    heap_init(&sw_share_heap, "sw_share", (void *)SW_SHARE_MEM_BASE, SW_SHARE_MEM_SIZE);
#endif
}
Example #8
0
/*********************************************************************************************************
** Function name:           libc_init
** Descriptions:            初始化 C 库
** input parameters:        NONE
** output parameters:       NONE
** Returned value:          NONE
*********************************************************************************************************/
void libc_init(void)
{
    /*
     * 设置进程信息
     */
    static pinfo_t info;

    info.reent = _impure_ptr;

    extern int setpinfo(void *info);
    setpinfo(&info);

    /*
     * 创建用户空间内存堆
     */
    extern unsigned char __bss_end;

    /*
     * 在 __bss_end 后, 进程栈空间前, 建立内存堆
     */
    heap_init(&user_heap, "user_heap", &__bss_end,
            PROCESS_SPACE_SIZE - (uint32_t)&__bss_end - PROCESS_STACK_SIZE - PROCESS_PARAM_SIZE);

    /*
     * 打开三个标准文件
     */
    open("/dev/serial0", O_RDONLY, 0666);
    stdin  = fdopen(STDIN_FILENO,  "r");

    open("/dev/serial0", O_WRONLY, 0666);
    stdout = fdopen(STDOUT_FILENO, "w");

    open("/dev/serial0", O_WRONLY, 0666);
    stderr = fdopen(STDERR_FILENO, "w");
}
Example #9
0
int main(void)
{

  heap_init();

  char buffer[64];
  char startString[] = "Please write 10 characters: \n";
  char endString[] = "\nTest complete.\n";

  void *pointer = malloc(sizeof(buffer));



  syscall_write(FILEHANDLE_STDIN, startString, 30);

  syscall_read(FILEHANDLE_STDIN, buffer, 10);

  syscall_write(FILEHANDLE_STDIN, buffer, 10);

  syscall_write(FILEHANDLE_STDIN, endString, 16);

  syscall_halt();
  
  return 0;
}
Example #10
0
int sfqdfull_init()
{
	if (SFQD_FULL_USE_HEAP_QUEUE==1)
	{
		sfqdfull_heap_queue=(struct heap*)malloc(sizeof(struct heap));

		heap_init(sfqdfull_heap_queue);
	}
	else
	{
		sfqdfull_llist_queue=PINT_llist_new();
		assert(sfqdfull_llist_queue!=NULL);
		sfqdfull_list_queue_count=(int*)malloc(num_apps*sizeof(int));
	}

	sfqdfull_last_finish_tags=(int*)malloc(num_apps*sizeof(int));


	int i;
	for (i=0;i<num_apps;i++)
	{
		sfqdfull_list_queue_count[i]=0;
		//last_finish_tags[i]=0; do not forget!
	}
	char* deptht=(char*)malloc(sizeof(char)*40);
	snprintf(deptht, 40, "%s.depthtrack.txt", log_prefix);
	depthtrack = fopen(deptht,"w");//

}
void outputSorted(const Person people[],
        int numPeople,
        int (* compare)(const void *pKey1, const void *pKey2))
{
    Heap heap;
    void *data;
    int i;

    /* Initialize heap */
    heap_init(&heap, compare, NULL);

    /* Add people to heap */
    for (i = 0; i < numPeople; ++i)
        if (heap_insert(&heap, &people[i]) != 0)
            fatalError("Failed to insert person into heap");

    /* Extract and output people from heap */
    while (heap_size(&heap) > 0) {
        if (heap_extract(&heap, &data) != 0)
            fatalError("Failed to extract person from heap");
        outputPerson((const Person *)data);
    }

    /* Destroy heap */
    heap_destroy(&heap);
}
Example #12
0
File: hw.c Project: DIKU-EDU/kudos
int main(void)
{
  char *name;
  int count;

  heap_init(); /* Or malloc() won't work. */

  puts("Hello, World!\n\n");

  while (1) {
    name = (char*)malloc(BUFFER_SIZE);
    printf("Please enter your name (max %d chars): ", BUFFER_SIZE);
    count = readline_static(name, BUFFER_SIZE);

    if (count == 0) {
      break;
    }

    name[count] = 0; /* Chomp off newline */
    printf("And hello to you, %s!\n", name);
    free(name);
  }

  puts("Now I shall exit!\n");

  syscall_exit(2);

  return 0;
}
Example #13
0
/**
 * @brief   ChibiOS/RT initialization.
 * @details After executing this function the current instructions stream
 *          becomes the main thread.
 * @pre     Interrupts must be still disabled when @p chSysInit() is invoked
 *          and are internally enabled.
 * @post    The main thread is created with priority @p NORMALPRIO.
 * @note    This function has special, architecture-dependent, requirements,
 *          see the notes into the various port reference manuals.
 *
 * @special
 */
void chSysInit(void) {
  static Thread mainthread;

  port_init();
  scheduler_init();
  vt_init();
#if CH_USE_MEMCORE
  core_init();
#endif
#if CH_USE_HEAP
  heap_init();
#endif
#if CH_DBG_ENABLE_TRACE
  trace_init();
#endif

  /* Now this instructions flow becomes the main thread.*/
  setcurrp(_thread_init(&mainthread, NORMALPRIO));
  currp->p_state = THD_STATE_CURRENT;
  chSysEnable();

#if !CH_NO_IDLE_THREAD
  /* This thread has the lowest priority in the system, its role is just to
     serve interrupts in its context while keeping the lowest energy saving
     mode compatible with the system status.*/
  chThdCreateStatic(_idle_thread_wa, sizeof(_idle_thread_wa), IDLEPRIO,
                    (tfunc_t)_idle_thread, NULL);
#endif
}
Example #14
0
/* --------------- threadpool API ------------------ */
threadpool_t *threadpool_create(int init, int max, int stack_size) {
    threadpool_t *pool;
    int i;
    assert(init > 0 && max >= init && stack_size >= 0);

    /* Allocate memory and zero all them. */
    pool = (threadpool_t *)calloc(1, sizeof(*pool));
    if (!pool) {
        return NULL;
    }

    Pthread_mutex_init(&pool->mutex, NULL);
    Pthread_cond_init(&pool->cond, NULL);
    Pthread_cond_init(&pool->exit_cond, NULL);
    Pthread_cond_init(&pool->task_over_cond, NULL);

    heap_init(&pool->task_queue);
    heap_set_less(&pool->task_queue, priority_less);
    pool->thread_stack_size = (stack_size == 0) ? THREAD_STACK_SIZE :
        stack_size;

    for (i = 0; i < init; ++i) {
        threadpool_thread_create(pool);
    }

    pool->threads_idle = init;
    pool->threads_num = init;
    pool->threads_max = max;
    return pool;
}
Example #15
0
void init_dungeon(dungeon_t *d)
{
  empty_dungeon(d);

  memset(&d->next_turn, 0, sizeof (d->next_turn));
  heap_init(&d->next_turn, compare_characters_by_next_turn, character_delete);
}
Example #16
0
void kmain(void){
	vga_init();
	heap_init();
	unreal_init();

	// DETECT MEMORY
	puts("Detecting memory... ");
	memdetect();
	uint16_t count = *((uint16_t *) 0x7E00);
	if(!count){
		puts("error - something is wrong with INT15/EAX=E820");
		while(1);
	}

	uint16_t i;
	uint32_t amount = 0;
	for(i = 0;i < count;i++){
		amount += *((uint32_t *) 0x7008 + i * 4);
	}
	
	uint32_t mb = amount / 1048576;
	amount %= 1048576;
	uint8_t point = amount / 131072;
	if(amount % 131072 > 65536) point++;

	putd(mb);
	putc('.');
	putd(point);
	puts(" MB\n");

	unreal_disk();
	read_unbuffered(0, 0x30000, 1);
	puts("Done!");
	while(1);
}
Example #17
0
int arch_main(void)
{
	/* call early initcalls */
	do_initcalls_early();

	/* map the first 4mb (phys) to 3gb (virtual) */
	paging_init_pre();
	/* get rid of trickgdt and put a proper one */
	gdt_init();
	mm_init();
	paging_alloc_init();
	/* now we can setup interrupts */
	idt_init();
	/* unmap the first 4mb of pages */
	paging_init_post();

	heap_init();

	kern_page_dir_clone();

	/* we can safely enable interrupts here */
	asm volatile("sti");

	/* call the arch initcalls */
	do_initcalls_arch();

	return main();
}
Example #18
0
File: main.c Project: eerimoq/simba
static int test_big_buffer(struct harness_t *harness)
{
    struct heap_t heap;
    void *buffers[4];
    size_t sizes[8] = { 16, 32, 64, 128, 256, 512, 512, 512 };

    BTASSERT(heap_init(&heap, buffer, sizeof(buffer), sizes) == 0);

    /* Allocate new block. */
    buffers[0] = heap_alloc(&heap, 513);
    BTASSERT(buffers[0] != NULL);
    BTASSERT(heap_free(&heap, buffers[0]) == 0);

    /* Allocate from the free list. */
    buffers[0] = heap_alloc(&heap, 513);
    BTASSERT(buffers[0] != NULL);
    BTASSERT(heap_free(&heap, buffers[0]) == 0);

    /* Allocate from the end of the free list*/
    buffers[0] = heap_alloc(&heap, 513);
    BTASSERT(buffers[0] != NULL);
    buffers[1] = heap_alloc(&heap, 514);
    BTASSERT(buffers[0] != NULL);
    BTASSERT(heap_free(&heap, buffers[1]) == 0);
    BTASSERT(heap_free(&heap, buffers[0]) == 0);
    buffers[0] = heap_alloc(&heap, 514);
    BTASSERT(buffers[0] != NULL);
    BTASSERT(heap_free(&heap, buffers[0]) == 0);

    return (0);
}
Example #19
0
int main (void)
{
    int i;
    char outOld;
    char out;
    BOOL allesJut;
    srand (time (NULL));
    heap_init ();

    for (i = 0; i < 10; i++)
    {
        heap_insert ( (26 * (rand () / (RAND_MAX + 1.0))) + 97);
    }

    heap_print ();

    heap_extract_min (&outOld);
    allesJut = heap_extract_min (&out);
    while (allesJut) 
    {
        printf ("\n  %c <= %c\n", outOld, out);
        if (outOld <= out)
        {
            outOld = out;
            allesJut = heap_extract_min (&out);
        }
        else
        {
            printf ("\n\tFUCK\n");
            allesJut = FALSE;
        }
    }

}
Example #20
0
File: main.c Project: eerimoq/simba
static int test_alloc_free(struct harness_t *harness)
{
    int i;
    struct heap_t heap;
    void *buffers[16];
    size_t sizes[8] = { 16, 32, 64, 128, 256, 512, 512, 512 };

    BTASSERT(heap_init(&heap, buffer, sizeof(buffer), sizes) == 0);

    /* Allocate a few buffers... */
    for (i = 0; i < 16; i++) {
        buffers[i] = heap_alloc(&heap, 1 + (4 * i));
        BTASSERT(buffers[i] != NULL);
    }

    /* ...and free them. */
    for (i = 0; i < 16; i++) {
        BTASSERT(heap_free(&heap, buffers[i]) == 0);
    }

    /* Allocate from the free list... */
    for (i = 0; i < 16; i++) {
        buffers[i] = heap_alloc(&heap, 1 + (4 * i));
        BTASSERT(buffers[i] != NULL);
    }

    /* ...and free them. */
    for (i = 0; i < 16; i++) {
        BTASSERT(heap_free(&heap, buffers[i]) == 0);
    }

    return (0);
}
Example #21
0
void kernel_c(){
	//init basic data&struct
	heap_init();
	proc_init();
	init_fs();
	mem_entity[0]='G';
	mem_entity[1]='M';
	mem_entity[2]='K';
	mem_entity[3]='B';
	k_screen_reset();
	detect_cpu();
	oprintf("detecting cpu...cpu identify:%s\n",cpu_string);
//	oprintf("mm init..\nring0_pgdir:%x,ring0_pgtbl:%x,base_proc_pgdir:%x,addr_kernel_info:%x,pages:%x\n",RING0_PGDIR,RING0_PGTBL,BASE_PROC_PGDIR,ADDR_KERNEL_INFO,PAGES);
	global_equal_map();
	__asm__("mov $0x101000,%eax\t\n"
			"mov %eax,%cr3\t\n"
			"mov %cr0,%eax\t\n"
			"or $0x80000000,%eax\t\n"
			"mov %eax,%cr0\t\n"
			);
	oprintf("global page-mapping for kernel built..open MMU\n");
	create_kernel_process((int)&idle,9,0xffff,"idle",0);	//pid must =0
	create_kernel_process((int)hs,2,0xffff,"hs",1);//hs的时间片要非常多,保证在下一轮时间片重置之前不会被挂起 ERR:pid must =1
	create_kernel_process((int)fs_ext,4,10,"fs_ext",1);//pid must =2

	create_kernel_process((int)mm,3,10,"mm",1);//ERR mm has great prio,because it shall run and prepare condition for other process
	create_kernel_process((int)tty,5,10,"tty",1);
	create_kernel_process((int)&p1,8,10,"p1",1);
//	ofork(t1,9,15,"t1",1);
//	ofork(t2,9,5,"t2",1);
//	ofork((int)&p2,7,5,"p2",3);
	oprintf("basic process ofork done..now open IRQ,proc-dispatch begin\n");
	__asm__("sti");
	while(1);//内核陷入死循环,等待第一次时钟中断
}
Example #22
0
gas_t *gas_pgas_new(const config_t *cfg, boot_t *boot) {
  size_t heap_size = cfg->heapsize;

  if (global_heap) {
    return &_pgas_vtable;
  }

  global_heap = malloc(sizeof(*global_heap));
  if (!global_heap) {
    dbg_error("could not allocate global heap\n");
    return NULL;
  }

  if (heap_init(global_heap, heap_size) != LIBHPX_OK) {
    dbg_error("failed to allocate global heap\n");
    free(global_heap);
    return NULL;
  }

  global_allocator_init();
  if (here->rank == 0) {
    cyclic_allocator_init();
  }

  return &_pgas_vtable;
}
Example #23
0
File: core.c Project: catoc/Comojs
        /* If the performance interval is zero, there's no support. */
        if (hrtime_interval_ == 0) {
            return 0;
        }

        if (!QueryPerformanceCounter(&counter)) {
            return 0;
        }

        return (uint64_t) ((double) counter.QuadPart * hrtime_interval_ * scale);
    #else
        struct timeval tv;
        gettimeofday(&tv, NULL);
        return (uint64_t) tv.tv_sec * scale + tv.tv_usec/scale;
    #endif
}

void loop_update_time (evLoop *loop){
    loop->time = loop_hrtime(1000);
}

evLoop *gLoop; /* global loop instance */
evLoop *loop_init (){
    evLoop *loop = malloc(sizeof(*loop));
    memset(loop, 0, sizeof(*loop));
    
    loop->active_handles = 0;
    loop->stop = 0;
    loop->time = 0;
    loop->timer_counter = 0;
    
    /* timer update */
    loop_update_time(loop);
    
    /* defined in select.c or any other io poll backend */
    loop_poll_create(loop);

    heap_init((struct heap*) &loop->timer_heap);
    
    QUEUE_INIT(&loop->handle_queue);
    QUEUE_INIT(&loop->closing_queue);
    QUEUE_INIT(&loop->io_queue);
    
    if (gLoop == NULL) gLoop = loop;
    
    return loop;
}
Example #24
0
File: map.c Project: 91he/Test
struct Path *road_min(struct Graph *graph, int from, int to){
	Heap *heap;
	HNode *array;
	Edge *edge, *tmp;
	struct Path *p, *q;
	int i, j, val, n = graph->num;
	int end = find_node(graph, to)->adj;
	int start = find_node(graph, from)->adj;
	struct VNode **path = malloc(sizeof(struct VNode*) * n);

	heap = heap_init();
	heap->num = n;
	array = heap->array;
	bzero(path, sizeof(struct VNode*) * n);

	for(i = 1; i <= n; i++){
		array[i].value = INF;
		array[i].vertex = i;
		array[i].pos = i;
	}

	array[start + 1].value = 0;
	heap_up(heap, start + 1);

	do{
		j = array[1].vertex - 1;

		if(j == end){
			break;
		}
		val = array[1].value;

		for(edge = graph->array[j]->link; edge; tmp = edge->next, edge = tmp){
			i = edge->node->adj + 1;
			if(array[array[i].pos].value > val + edge->dut){
				array[array[i].pos].value = val + edge->dut;
				heap_up(heap, array[i].pos);
				path[i - 1] = graph->array[j];
			}
		}
	}while(heap_top_del(heap));

	heap_destroy(heap);
	
	i = end;
	q = NULL;
	while(path[i]){
		j = path[i]->adj;
		p = malloc(sizeof(Path));
		p->node = path[i];
		p->next = q;
		q = p;
		i = j;
	}

	free(path);

	return q;
}
Example #25
0
File: obj.c Project: jxy859/nvml
/*
 * pmemobj_descr_create -- (internal) create obj pool descriptor
 */
static int
pmemobj_descr_create(PMEMobjpool *pop, const char *layout, size_t poolsize)
{
	LOG(3, "pop %p layout %s poolsize %zu", pop, layout, poolsize);

	ASSERTeq(poolsize % Pagesize, 0);

	/* opaque info lives at the beginning of mapped memory pool */
	void *dscp = (void *)((uintptr_t)(&pop->hdr) +
				sizeof (struct pool_hdr));

	/* create the persistent part of pool's descriptor */
	memset(dscp, 0, OBJ_DSC_P_SIZE);
	if (layout)
		strncpy(pop->layout, layout, PMEMOBJ_MAX_LAYOUT - 1);

	/* initialize run_id, it will be incremented later */
	pop->run_id = 0;
	pmem_msync(&pop->run_id, sizeof (pop->run_id));

	pop->lanes_offset = OBJ_LANES_OFFSET;
	pop->nlanes = OBJ_NLANES;

	/* zero all lanes */
	void *lanes_layout = (void *)((uintptr_t)pop +
						pop->lanes_offset);

	memset(lanes_layout, 0,
		pop->nlanes * sizeof (struct lane_layout));
	pmem_msync(lanes_layout, pop->nlanes *
		sizeof (struct lane_layout));

	/* initialization of the obj_store */
	pop->obj_store_offset = pop->lanes_offset +
		pop->nlanes * sizeof (struct lane_layout);
	pop->obj_store_size = (PMEMOBJ_NUM_OID_TYPES + 1) *
		sizeof (struct object_store_item);
		/* + 1 - for root object */
	void *store = (void *)((uintptr_t)pop + pop->obj_store_offset);
	memset(store, 0, pop->obj_store_size);
	pmem_msync(store, pop->obj_store_size);

	pop->heap_offset = pop->obj_store_offset + pop->obj_store_size;
	pop->heap_offset = (pop->heap_offset + Pagesize - 1) & ~(Pagesize - 1);
	pop->heap_size = poolsize - pop->heap_offset;

	/* initialize heap prior to storing the checksum */
	if ((errno = heap_init(pop)) != 0) {
		ERR("!heap_init");
		return -1;
	}

	util_checksum(dscp, OBJ_DSC_P_SIZE, &pop->checksum, 1);

	/* store the persistent part of pool's descriptor (2kB) */
	pmem_msync(dscp, OBJ_DSC_P_SIZE);

	return 0;
}
Example #26
0
void heap_sort(int *a, const int n) {
	heap_init(a, n);
	int i;
	for(i = n - 1; i >= 0; i--) {
		swap(a + i, a);
		heap_adjust(a, 0, i);
	}
}  //堆排序
Example #27
0
static int
wf2qp_new_sched(struct dn_sch_inst *_si)
{
	struct wf2qp_si *si = (struct wf2qp_si *)(_si + 1);
	int ofs = offsetof(struct wf2qp_queue, heap_pos);

	/* all heaps support extract from middle */
	if (heap_init(&si->idle_heap, 16, ofs) ||
	    heap_init(&si->sch_heap, 16, ofs) ||
	    heap_init(&si->ne_heap, 16, ofs)) {
		heap_free(&si->ne_heap);
		heap_free(&si->sch_heap);
		heap_free(&si->idle_heap);
		return ENOMEM;
	}
	return 0;
}
Example #28
0
heap_t *heap_create() {
    heap_t *h = (heap_t*)malloc(sizeof(*h));
    if (!h) return NULL;
    if (heap_init(h) != 0) {
        free(h);
        return NULL;
    }
    return h;
}
Example #29
0
/* called from arch code */
void lk_main(ulong arg0, ulong arg1, ulong arg2, ulong arg3)
{
	// save the boot args
	lk_boot_args[0] = arg0;
	lk_boot_args[1] = arg1;
	lk_boot_args[2] = arg2;
	lk_boot_args[3] = arg3;

	// get us into some sort of thread context
	thread_init_early();

	// early arch stuff
	lk_primary_cpu_init_level(LK_INIT_LEVEL_EARLIEST, LK_INIT_LEVEL_ARCH_EARLY - 1);
	arch_early_init();

	// do any super early platform initialization
	lk_primary_cpu_init_level(LK_INIT_LEVEL_ARCH_EARLY, LK_INIT_LEVEL_PLATFORM_EARLY - 1);
	platform_early_init();

	// do any super early target initialization
	lk_primary_cpu_init_level(LK_INIT_LEVEL_PLATFORM_EARLY, LK_INIT_LEVEL_TARGET_EARLY - 1);
	target_early_init();

#if WITH_SMP
	dprintf(INFO, "\nwelcome to lk/MP\n\n");
#else
	dprintf(INFO, "\nwelcome to lk\n\n");
#endif
	dprintf(INFO, "boot args 0x%lx 0x%lx 0x%lx 0x%lx\n",
		lk_boot_args[0], lk_boot_args[1], lk_boot_args[2], lk_boot_args[3]);

	// deal with any static constructors
	dprintf(SPEW, "calling constructors\n");
	call_constructors();

	// bring up the kernel heap
	dprintf(SPEW, "initializing heap\n");
	lk_primary_cpu_init_level(LK_INIT_LEVEL_TARGET_EARLY, LK_INIT_LEVEL_HEAP - 1);
	heap_init();

	// initialize the kernel
	lk_primary_cpu_init_level(LK_INIT_LEVEL_HEAP, LK_INIT_LEVEL_KERNEL - 1);
	kernel_init();

	lk_primary_cpu_init_level(LK_INIT_LEVEL_KERNEL, LK_INIT_LEVEL_THREADING - 1);

	// create a thread to complete system initialization
	dprintf(SPEW, "creating bootstrap completion thread\n");
	thread_t *t = thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	t->pinned_cpu = 0;
	thread_detach(t);
	thread_resume(t);

	// become the idle thread and enable interrupts to start the scheduler
	thread_become_idle();
}
Example #30
0
File: main.c Project: sndnvaps/lk-1
void lk_main(void)
{
	inc_critical_section();

	// get us into some sort of thread context
	thread_init_early();

	// early arch stuff
	lk_init_level(LK_INIT_LEVEL_ARCH_EARLY - 1);
	arch_early_init();

	// do any super early platform initialization
	lk_init_level(LK_INIT_LEVEL_PLATFORM_EARLY - 1);
	platform_early_init();

	// do any super early target initialization
	lk_init_level(LK_INIT_LEVEL_TARGET_EARLY - 1);
	target_early_init();

	dprintf(INFO, "welcome to lk\n\n");
#if WITH_PLATFORM_MSM_SHARED
	bs_set_timestamp(BS_BL_START);
#endif

	// deal with any static constructors
	dprintf(SPEW, "calling constructors\n");
	call_constructors();

	// bring up the kernel heap
	dprintf(SPEW, "initializing heap\n");
	lk_init_level(LK_INIT_LEVEL_HEAP - 1);
	heap_init();

#if WITH_PLATFORM_MSM_SHARED
	__stack_chk_guard_setup();
#endif

	// initialize the kernel
	lk_init_level(LK_INIT_LEVEL_KERNEL - 1);
	kernel_init();

	lk_init_level(LK_INIT_LEVEL_THREADING - 1);

#if (!ENABLE_NANDWRITE)
	// create a thread to complete system initialization
	dprintf(SPEW, "creating bootstrap completion thread\n");
	thread_t *t = thread_create("bootstrap2", &bootstrap2, NULL, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE);
	thread_detach(t);
	thread_resume(t);

	// become the idle thread and enable interrupts to start the scheduler
	thread_become_idle();
#else
	bootstrap_nandwrite();
#endif
}