示例#1
0
文件: heap.c 项目: grub4android-g3/lk
void heap_init(void)
{
	LTRACE_ENTRY;

	// set the heap range
	theheap.base = (void *)HEAP_START;
	theheap.len = HEAP_LEN;
	theheap.remaining =0; // will get set by heap_insert_free_chunk()
	theheap.low_watermark = theheap.len;
	LTRACEF("base %p size %zd bytes\n", theheap.base, theheap.len);

	// create a mutex
	mutex_init(&theheap.lock);

	// initialize the free list
	list_initialize(&theheap.free_list);

	// initialize the delayed free list
	list_initialize(&theheap.delayed_free_list);

	// create an initial free chunk
	heap_insert_free_chunk(heap_create_free_chunk(theheap.base, theheap.len, false));

	// dump heap info
//	heap_dump();

//	dprintf(INFO, "running heap tests\n");
//	heap_test();
}
示例#2
0
文件: heap.c 项目: grub4android/lk
void heap_init(void)
{
	LTRACE_ENTRY;

	// create a mutex
	mutex_init(&theheap.lock);

	// initialize the free list
	list_initialize(&theheap.free_list);

	// initialize the delayed free list
	list_initialize(&theheap.delayed_free_list);
	spin_lock_init(&theheap.delayed_free_lock);

	// set the heap range
#if WITH_KERNEL_VM
	theheap.base = pmm_alloc_kpages(HEAP_GROW_SIZE / PAGE_SIZE, NULL);
	theheap.len = HEAP_GROW_SIZE;

	if (theheap.base == 0) {
		panic("HEAP: error allocating initial heap size\n");
	}
#else
	theheap.base = (void *)HEAP_START;
	theheap.len = HEAP_LEN;
#endif
	theheap.remaining = 0; // will get set by heap_insert_free_chunk()
	theheap.low_watermark = theheap.len;
	LTRACEF("base %p size %zd bytes\n", theheap.base, theheap.len);

	// create an initial free chunk
	heap_insert_free_chunk(heap_create_free_chunk(theheap.base, theheap.len, false));
}
示例#3
0
/** Initialize allocated memory as a slab cache */
static void
_slab_cache_create(slab_cache_t *cache,
       size_t size,
       size_t align,
       int (*constructor)(void *obj, int kmflag),
       int (*destructor)(void *obj),
       int flags)
{
    int pages;
 // ipl_t ipl;

//  memsetb((uintptr_t)cache, sizeof(*cache), 0);
//  cache->name = name;

//if (align < sizeof(unative_t))
//    align = sizeof(unative_t);
//  size = ALIGN_UP(size, align);

    cache->size = size;

//  cache->constructor = constructor;
//  cache->destructor = destructor;
    cache->flags = flags;

    list_initialize(&cache->full_slabs);
    list_initialize(&cache->partial_slabs);
    list_initialize(&cache->magazines);
//  spinlock_initialize(&cache->slablock, "slab_lock");
//  spinlock_initialize(&cache->maglock, "slab_maglock");
//  if (! (cache->flags & SLAB_CACHE_NOMAGAZINE))
//    make_magcache(cache);

  /* Compute slab sizes, object counts in slabs etc. */

  /* Minimum slab order */
    pages = SIZE2FRAMES(cache->size);
  /* We need the 2^order >= pages */
    if (pages <= 1)
        cache->order = 0;
    else
        cache->order = fnzb(pages-1)+1;

    while (badness(cache) > SLAB_MAX_BADNESS(cache)) {
        cache->order += 1;
    }
    cache->objects = comp_objects(cache);

  /* Add cache to cache list */
//  ipl = interrupts_disable();
//  spinlock_lock(&slab_cache_lock);

    list_append(&cache->link, &slab_cache_list);

//  spinlock_unlock(&slab_cache_lock);
//  interrupts_restore(ipl);
}
示例#4
0
/**
 * Initializes libraries required for NIC framework - logger
 *
 * @param name	Name of the device/driver (used in logging)
 */
int nic_driver_init(const char *name)
{
	list_initialize(&nic_globals.frame_list_cache);
	nic_globals.frame_list_cache_size = 0;
	list_initialize(&nic_globals.frame_cache);
	nic_globals.frame_cache_size = 0;
	fibril_mutex_initialize(&nic_globals.lock);
	
	char buffer[256];
	snprintf(buffer, 256, "drv/" DEVICE_CATEGORY_NIC "/%s", name);
	
	return EOK;
}
示例#5
0
/** Create new association structure.
 *
 * @param lsock		Local socket (will be deeply copied)
 * @param fsock		Foreign socket (will be deeply copied)
 * @return		New association or NULL
 */
udp_assoc_t *udp_assoc_new(udp_sock_t *lsock, udp_sock_t *fsock)
{
	udp_assoc_t *assoc = NULL;

	/* Allocate association structure */
	assoc = calloc(1, sizeof(udp_assoc_t));
	if (assoc == NULL)
		goto error;

	fibril_mutex_initialize(&assoc->lock);

	/* One for the user */
	atomic_set(&assoc->refcnt, 1);

	/* Initialize receive queue */
	list_initialize(&assoc->rcv_queue);
	fibril_condvar_initialize(&assoc->rcv_queue_cv);

	if (lsock != NULL)
		assoc->ident.local = *lsock;
	if (fsock != NULL)
		assoc->ident.foreign = *fsock;

	return assoc;
error:
	return NULL;
}
示例#6
0
void init_core_dll()
{
    PIMAGE_DOS_HEADER        dos;
    PIMAGE_NT_HEADERS32      nt;
    PIMAGE_EXPORT_DIRECTORY  exp;

    dos =  (PIMAGE_DOS_HEADER)LOAD_BASE;
    nt  =  MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew);
    exp =  MakePtr(PIMAGE_EXPORT_DIRECTORY,LOAD_BASE,
                   nt->OptionalHeader.DataDirectory[0].VirtualAddress);

    list_initialize(&core_dll.link);

    core_dll.img_base = LOAD_BASE;
    core_dll.img_size = nt->OptionalHeader.SizeOfImage;
    core_dll.img_md   = NULL;

    core_dll.img_hdr  = nt;
    core_dll.img_sec  = MakePtr(PIMAGE_SECTION_HEADER,nt, sizeof(IMAGE_NT_HEADERS32));
    core_dll.img_exp  = MakePtr(PIMAGE_EXPORT_DIRECTORY,LOAD_BASE,
                        nt->OptionalHeader.DataDirectory[0].VirtualAddress);
    core_dll.img_name = strupr(MakePtr(char*, LOAD_BASE, exp->Name));

    dll_slab = slab_cache_create(sizeof(dll_t), 16,NULL,NULL,SLAB_CACHE_MAGDEFERRED);

    DBG("%s base %x size %x sections %d exports %x\n",
        core_dll.img_name, core_dll.img_base,
        core_dll.img_size, nt->FileHeader.NumberOfSections,
        core_dll.img_exp );
};
示例#7
0
// Direct initialzie `d` by a brace-enclosed list of expressions
// `es`.
Expr&
Parser::on_brace_initialization(Decl& d, Expr_list& es)
{
  Expr& i = list_initialize(cxt, declared_type(d), es);
  initialize_declaration(d, i);
  return i;
}
示例#8
0
文件: vm.c 项目: grub4android/lk
/* mark the physical pages backing a range of virtual as in use.
 * allocate the physical pages and throw them away */
static void mark_pages_in_use(vaddr_t va, size_t len)
{
    LTRACEF("va 0x%lx, len 0x%zx\n", va, len);

    struct list_node list;
    list_initialize(&list);

    /* make sure we are inclusive of all of the pages in the address range */
    len = PAGE_ALIGN(len + (va & (PAGE_SIZE - 1)));
    va = ROUNDDOWN(va, PAGE_SIZE);

    LTRACEF("aligned va 0x%lx, len 0x%zx\n", va, len);

    for (size_t offset = 0; offset < len; offset += PAGE_SIZE) {
        uint flags;
        paddr_t pa;

        status_t err = arch_mmu_query(va + offset, &pa, &flags);
        if (err >= 0) {
            //LTRACEF("va 0x%x, pa 0x%x, flags 0x%x, err %d\n", va + offset, pa, flags, err);

            /* alloate the range, throw the results away */
            pmm_alloc_range(pa, 1, &list);
        } else {
            panic("Could not find pa for va 0x%lx\n", va);
        }
    }
}
示例#9
0
/** Create buddy system.
 *
 * Allocate memory for and initialize new buddy system.
 *
 * @param b		Preallocated buddy system control data.
 * @param max_order	The biggest allocable size will be 2^max_order.
 * @param op		Operations for new buddy system.
 * @param data		Pointer to be used by implementation.
 *
 * @return		New buddy system.
 */
void
buddy_system_create(buddy_system_t *b, uint8_t max_order,
    buddy_system_operations_t *op, void *data)
{
	int i;

	ASSERT(max_order < BUDDY_SYSTEM_INNER_BLOCK);

	ASSERT(op->find_buddy);
	ASSERT(op->set_order);
	ASSERT(op->get_order);
	ASSERT(op->bisect);
	ASSERT(op->coalesce);
	ASSERT(op->mark_busy);

	/*
	 * Use memory after our own structure.
	 */
	b->order = (list_t *) (&b[1]);
	
	for (i = 0; i <= max_order; i++)
		list_initialize(&b->order[i]);

	b->max_order = max_order;
	b->op = op;
	b->data = data;
}
示例#10
0
void heap_init(void)
{
	int z;
	LTRACE_ENTRY;

	// set the heap range in normal zone
	theheap[ZONE_NORMAL].base = (void *)HEAP_START;
	theheap[ZONE_NORMAL].len = HEAP_LEN;

#ifdef WITH_DMA_ZONE
	theheap[ZONE_DMA].base = (void *)DMA_START;
	theheap[ZONE_DMA].len = DMA_LEN;
#endif

	for (z = 0; z < MAX_ZONES; z++) {
		LTRACEF("base %p size %zd bytes (%s)\n", theheap[z].base, theheap[z].len,
			zone_name(z));

		// initialize the free list
		list_initialize(&theheap[z].free_list);

		// create an initial free chunk
		heap_insert_free_chunk(z,
			heap_create_free_chunk(theheap[z].base, theheap[z].len));
	}

	// dump heap info
//	heap_dump();

//	dprintf(INFO, "running heap tests\n");
//	heap_test();
}
示例#11
0
void fibril_rwlock_initialize(fibril_rwlock_t *frw)
{
	frw->oi.owned_by = NULL;
	frw->writers = 0;
	frw->readers = 0;
	list_initialize(&frw->waiters);
}
示例#12
0
/**
 * Initialize audio pipe structure.
 * @param pipe The pipe structure to initialize.
 */
void audio_pipe_init(audio_pipe_t *pipe)
{
	assert(pipe);
	list_initialize(&pipe->list);
	fibril_mutex_initialize(&pipe->guard);
	pipe->frames = 0;
	pipe->bytes = 0;
}
示例#13
0
文件: semaphore.c 项目: raphui/rnk
void sem_init(struct semaphore *sem, unsigned int value)
{
	sem->value = value;
	sem->count = 0;
	sem->waiting = 0;

	list_initialize(&sem->waiting_threads);
}
示例#14
0
static void unused_initialize(unused_t *u, service_id_t service_id)
{
	link_initialize(&u->link);
	u->service_id = service_id;
	u->next = 0;
	u->remaining = ((uint64_t)((fs_index_t)-1)) + 1;
	list_initialize(&u->freed_list);
}
示例#15
0
文件: barber.c 项目: jvesely/helenos
int main(int argc, char *argv[])
{
	if (argc < 2) {
		printf("Compositor server not specified.\n");
		return 1;
	}
	
	list_initialize(&led_devs);
	int rc = loc_register_cat_change_cb(loc_callback);
	if (rc != EOK) {
		printf("Unable to register callback for device discovery.\n");
		return 1;
	}
	
	led_timer = fibril_timer_create(NULL);
	if (!led_timer) {
		printf("Unable to create LED timer.\n");
		return 1;
	}
	
	frame_timer = fibril_timer_create(NULL);
	if (!frame_timer) {
		printf("Unable to create frame timer.\n");
		return 1;
	}
	
	if (!decode_frames())
		return 1;
	
	winreg = argv[1];
	window_t *main_window = window_open(argv[1], NULL,
	    WINDOW_MAIN | WINDOW_DECORATED, "barber");
	if (!main_window) {
		printf("Cannot open main window.\n");
		return 1;
	}
	
	frame_canvas = create_canvas(window_root(main_window), NULL,
	    FRAME_WIDTH, FRAME_HEIGHT, frames[frame]);
	
	if (!frame_canvas) {
		window_close(main_window);
		printf("Cannot create widgets.\n");
		return 1;
	}
	
	window_resize(main_window, 0, 0, FRAME_WIDTH + 8, FRAME_HEIGHT + 28,
	    WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_BOTTOM);
	window_exec(main_window);
	
	plan_led_timer();
	plan_frame_timer(0);
	
	task_retval(0);
	async_manager();
	
	return 0;
}
示例#16
0
文件: list.c 项目: shonma29/eotan
void list_remove(list_t *entry)
{
	list_t *next = entry->next;
	list_t *prev = entry->prev;

	next->prev = prev;
	prev->next = next;
	list_initialize(entry);
}
示例#17
0
文件: hash.c 项目: shonma29/eotan
static void init_list(list_t *head, hash_entry_t *entries, const size_t size) {
	hash_entry_t *p = entries;
	size_t i;

	list_initialize(head);

	for (i = size; i > 0; p++, i--)
		list_append(head, &(p->list));
}
示例#18
0
void modbus_rtu_master_initialize(void)
{
    uint8_t i;
    modbus* bus;
    
    // reset all busses
    for(i = 0; i < MODBUS_NUMBER_OF_BUSSES; i++)
    {
        bus = &busses[i];
        bus->identifier = i;
        bus->uartChannel = i;
        list_initialize(&bus->messageQueue);
        bus->state = BUS_STATE_IDLE;
    }

    list_initialize(&completedList);
    
    NABTO_LOG_INFO(("Initialized."));
}
示例#19
0
文件: list.c 项目: shonma29/eotan
void list_release(list_t *guard)
{
	list_t *entry = guard;

	do {
		list_t *next = entry->next;

		list_initialize(entry);
		entry = next;
	} while (!list_is_edge(guard, entry));
}
示例#20
0
zx_status_t usb_midi_sink_create(zx_device_t* device, usb_protocol_t* usb, int index,
                                  const usb_interface_descriptor_t* intf,
                                  const usb_endpoint_descriptor_t* ep,
                                  const size_t parent_req_size) {
    usb_midi_sink_t* sink = calloc(1, sizeof(usb_midi_sink_t));
    if (!sink) {
        printf("Not enough memory for usb_midi_sink_t\n");
        return ZX_ERR_NO_MEMORY;
    }

    list_initialize(&sink->free_write_reqs);
    sink->usb_mxdev = device;
    memcpy(&sink->usb, usb, sizeof(sink->usb));

    int packet_size = usb_ep_max_packet(ep);
    if (intf->bAlternateSetting != 0) {
        usb_set_interface(usb, intf->bInterfaceNumber, intf->bAlternateSetting);
    }

    sink->parent_req_size = parent_req_size;
    for (int i = 0; i < WRITE_REQ_COUNT; i++) {
        usb_request_t* req;
        zx_status_t status = usb_request_alloc(&req, usb_ep_max_packet(ep), ep->bEndpointAddress,
                                               parent_req_size + sizeof(usb_req_internal_t));
        if (status != ZX_OK) {
            usb_midi_sink_free(sink);
            return ZX_ERR_NO_MEMORY;
        }
        req->header.length = packet_size;
        status = usb_req_list_add_head(&sink->free_write_reqs, req, parent_req_size);
        ZX_DEBUG_ASSERT(status == ZX_OK);
    }
    sync_completion_signal(&sink->free_write_completion);

    char name[ZX_DEVICE_NAME_MAX];
    snprintf(name, sizeof(name), "usb-midi-sink-%d", index);

    device_add_args_t args = {
        .version = DEVICE_ADD_ARGS_VERSION,
        .name = name,
        .ctx = sink,
        .ops = &usb_midi_sink_device_proto,
        .proto_id = ZX_PROTOCOL_MIDI,
    };

    zx_status_t status = device_add(device, &args, &sink->mxdev);
    if (status != ZX_OK) {
        printf("device_add failed in usb_midi_sink_create\n");
        usb_midi_sink_free(sink);
    }

    return status;
}
示例#21
0
文件: service.c 项目: jvesely/helenos
int service_init(void)
{
	if (!hash_table_create(&service_hash_table, 0, 0,
	    &service_hash_table_ops)) {
		printf("%s: No memory available for services\n", NAME);
		return ENOMEM;
	}
	
	list_initialize(&pending_conn);
	
	return EOK;
}
示例#22
0
static void tmpfs_node_initialize(tmpfs_node_t *nodep)
{
	nodep->bp = NULL;
	nodep->index = 0;
	nodep->service_id = 0;
	nodep->type = TMPFS_NONE;
	nodep->lnkcnt = 0;
	nodep->size = 0;
	nodep->data = NULL;
	link_initialize(&nodep->nh_link);
	list_initialize(&nodep->cs_list);
}
示例#23
0
/**
 * Allocate a new frame list
 *
 * @return New frame list or NULL on error.
 */
nic_frame_list_t *nic_alloc_frame_list(void)
{
	nic_frame_list_t *frames;
	fibril_mutex_lock(&nic_globals.lock);
	
	if (nic_globals.frame_list_cache_size > 0) {
		frames =
		    list_get_instance(list_first(&nic_globals.frame_list_cache),
		    nic_frame_list_t, head);
		list_remove(&frames->head);
		list_initialize(frames);
		nic_globals.frame_list_cache_size--;
		fibril_mutex_unlock(&nic_globals.lock);
	} else {
		fibril_mutex_unlock(&nic_globals.lock);
		
		frames = malloc(sizeof (nic_frame_list_t));
		if (frames != NULL)
			list_initialize(frames);
	}
	
	return frames;
}
示例#24
0
void *vfs_client_data_create(void)
{
	vfs_client_data_t *vfs_data;

	vfs_data = malloc(sizeof(vfs_client_data_t));
	if (vfs_data) {
		fibril_mutex_initialize(&vfs_data->lock);
		fibril_condvar_initialize(&vfs_data->cv);
		list_initialize(&vfs_data->passed_handles);
		vfs_data->files = NULL;
	}
	
	return vfs_data;
}
示例#25
0
文件: task.c 项目: jvesely/helenos
int task_init(void)
{
	if (!hash_table_create(&task_hash_table, 0, 0, &task_hash_table_ops)) {
		printf(NAME ": No memory available for tasks\n");
		return ENOMEM;
	}
	
	if (!hash_table_create(&phone_to_id, 0, 0, &p2i_ops)) {
		printf(NAME ": No memory available for tasks\n");
		return ENOMEM;
	}
	
	list_initialize(&pending_wait);
	return EOK;
}
示例#26
0
void test_order() {
	struct node *item1, *item2, *item3, *ptr;
	list_initialize();
	item1 = insert_after(1, head);
	item2 = insert_after(2, item1);
	item3 = insert_after(3, item2);
	ptr = head;
	assert(ptr->next == item1);
	ptr = ptr->next;
	assert(ptr->key == 1);
	assert(ptr->next == item2);
	ptr = ptr->next;
	assert(ptr->key == 2);
	assert(ptr->next == item3);
	printf("+");
}
示例#27
0
文件: devconn.c 项目: jvesely/helenos
static vhc_virtdev_t *vhc_virtdev_create(void)
{
	vhc_virtdev_t *dev = malloc(sizeof(vhc_virtdev_t));
	if (dev == NULL) {
		return NULL;
	}
	dev->address = 0;
	dev->dev_sess = NULL;
	dev->dev_local = NULL;
	dev->plugged = true;
	link_initialize(&dev->link);
	fibril_mutex_initialize(&dev->guard);
	list_initialize(&dev->transfer_queue);

	return dev;
}
示例#28
0
// Inicializacao com buffer pre-alocado
void rst_init_ptr(rst_buffer_t *ptr, u_int64_t id1, u_int64_t id2)
{
    int fd;
    char fname[30];
    char hostname[MAXHOSTNAMELEN+1];
       
    if ( ptr == NULL ) {
        fprintf(stderr, "[rastro] error inicializing - invalid pointer\n");
        return;
    }
    
#ifdef THREADED
    if (!rst_key_initialized) {
        pthread_key_create(&rst_key, rst_destroy_buffer);
        rst_key_initialized = 1;
    }
#endif
    
    if(!list_init){
    	list_initialize(&list, list_copy, list_cmp, list_destroy);
	list_init=true;
    }
    
    RST_SET_PTR(ptr);
    ptr->rst_buffer_size = 100000;
    ptr->rst_buffer = malloc(ptr->rst_buffer_size);
    RST_RESET(ptr);
    
    sprintf(fname, "rastro-%"PRIu64"-%"PRIu64".rst",/* dirname,*/ id1, id2);
    fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    if (fd == -1) {
        fprintf(stderr, "[rastro] cannot open file %s: %s\n", 
                        fname, strerror(errno));
        return;
    }
    
    list_insert_after(&list, NULL, (void *)ptr );
    
    RST_SET_FD(ptr, fd);
    
    // this will force first event to register sync time
    RST_SET_T0(ptr, 0);

    gethostname(hostname, sizeof(hostname));
    
    XCAT(rst_event_,LETRA_UINT64,LETRA_STRING,_ptr)(ptr, RST_EVENT_INIT, id1, id2, hostname);
}
示例#29
0
int task_init(void)
{
	if (!hash_table_create(&task_hash_table, TASK_HASH_TABLE_CHAINS,
	    2, &task_hash_table_ops)) {
		printf(NAME ": No memory available for tasks\n");
		return ENOMEM;
	}
	
	if (!hash_table_create(&phone_to_id, P2I_HASH_TABLE_CHAINS,
	    1, &p2i_ops)) {
		printf(NAME ": No memory available for tasks\n");
		return ENOMEM;
	}
	
	list_initialize(&pending_wait);
	return EOK;
}
示例#30
0
static int ldr_load_dyn_linked(elf_info_t *p_info)
{
	runtime_env = &dload_re;

	DPRINTF("Load dynamically linked program.\n");

	/*
	 * First we need to process dynamic sections of the executable
	 * program and insert it into the module graph.
	 */

	DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
	dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
	prog_mod.bias = 0;
	prog_mod.dyn.soname = "[program]";

	/* Initialize list of loaded modules */
	list_initialize(&runtime_env->modules);
	list_append(&prog_mod.modules_link, &runtime_env->modules);

	/* Pointer to program module. Used as root of the module graph. */
	runtime_env->program = &prog_mod;

	/* Work around non-existent memory space allocation. */
	runtime_env->next_bias = 0x1000000;

	/*
	 * Now we can continue with loading all other modules.
	 */

	DPRINTF("Load all program dependencies\n");
	module_load_deps(&prog_mod);

	/*
	 * Now relocate/link all modules together.
	 */

	/* Process relocations in all modules */
	DPRINTF("Relocate all modules\n");
	modules_process_relocs(&prog_mod);

	/* Pass runtime evironment pointer through PCB. */
	pcb.rtld_runtime = (void *) runtime_env;

	return 0;
}