Esempio n. 1
0
/** Create new heap area
 *
 * Should be called only inside the critical section.
 *
 * @param size Size of the area.
 *
 */
static bool area_create(size_t size)
{
	/* Align the heap area size on page boundary */
	size_t asize = ALIGN_UP(size, PAGE_SIZE);
	void *astart = as_area_create(AS_AREA_ANY, asize,
	    AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE);
	if (astart == AS_MAP_FAILED)
		return false;
	
	heap_area_t *area = (heap_area_t *) astart;
	
	area->start = astart;
	area->end = (void *) ((uintptr_t) astart + asize);
	area->prev = NULL;
	area->next = NULL;
	area->magic = HEAP_AREA_MAGIC;
	
	void *block = (void *) AREA_FIRST_BLOCK_HEAD(area);
	size_t bsize = (size_t) (area->end - block);
	
	block_init(block, bsize, true, area);
	
	if (last_heap_area == NULL) {
		first_heap_area = area;
		last_heap_area = area;
	} else {
		area->prev = last_heap_area;
		last_heap_area->next = area;
		last_heap_area = area;
	}
	
	return true;
}
Esempio n. 2
0
/** Create a chargrid.
 *
 * @param[in] cols  Number of columns.
 * @param[in] rows  Number of rows.
 * @param[in] flags Chargrid flags.
 *
 * @return New chargrid.
 * @return NULL on failure.
 *
 */
chargrid_t *chargrid_create(sysarg_t cols, sysarg_t rows,
    chargrid_flag_t flags)
{
	size_t size =
	    sizeof(chargrid_t) + cols * rows * sizeof(charfield_t);
	chargrid_t *scrbuf;
	
	if ((flags & CHARGRID_FLAG_SHARED) == CHARGRID_FLAG_SHARED) {
		scrbuf = (chargrid_t *) as_area_create(AS_AREA_ANY, size,
		    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
		if (scrbuf == AS_MAP_FAILED)
			return NULL;
	} else {
		scrbuf = (chargrid_t *) malloc(size);
		if (scrbuf == NULL)
			return NULL;
	}
	
	scrbuf->size = size;
	scrbuf->flags = flags;
	scrbuf->cols = cols;
	scrbuf->rows = rows;
	scrbuf->cursor_visible = false;
	
	scrbuf->attrs.type = CHAR_ATTR_STYLE;
	scrbuf->attrs.val.style = STYLE_NORMAL;
	
	scrbuf->top_row = 0;
	chargrid_clear(scrbuf);
	
	return scrbuf;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	printf("%s: HelenOS VFS server\n", NAME);
	
	/*
	 * Initialize VFS node hash table.
	 */
	if (!vfs_nodes_init()) {
		printf("%s: Failed to initialize VFS node hash table\n",
		    NAME);
		return ENOMEM;
	}
	
	/*
	 * Allocate and initialize the Path Lookup Buffer.
	 */
	plb = as_area_create(AS_AREA_ANY, PLB_SIZE,
	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
	if (plb == AS_MAP_FAILED) {
		printf("%s: Cannot create address space area\n", NAME);
		return ENOMEM;
	}
	memset(plb, 0, PLB_SIZE);
	
	/*
	 * Set client data constructor and destructor.
	 */
	async_set_client_data_constructor(vfs_client_data_create);
	async_set_client_data_destructor(vfs_client_data_destroy);

	/*
	 * Set a connection handling function/fibril.
	 */
	async_set_client_connection(vfs_connection);

	/*
	 * Set notification handler and subscribe to notifications.
	 */
	async_set_interrupt_received(notification_received);
	event_task_subscribe(EVENT_TASK_STATE_CHANGE, VFS_TASK_STATE_CHANGE);
	
	/*
	 * Register at the naming service.
	 */
	int rc = service_register(SERVICE_VFS);
	if (rc != EOK) {
		printf("%s: Cannot register VFS service\n", NAME);
		return rc;
	}
	
	/*
	 * Start accepting connections.
	 */
	printf("%s: Accepting connections\n", NAME);
	async_manager();
	return 0;
}
Esempio n. 4
0
static void *create_as_area(size_t size)
{
	TPRINTF("Creating AS area...\n");
	
	void *result = as_area_create(AS_AREA_ANY, size,
	    AS_AREA_READ | AS_AREA_WRITE);
	if (result == AS_MAP_FAILED)
		return NULL;
	
	return result;
}
Esempio n. 5
0
void *mmap(void *start, size_t length, int prot, int flags, int fd,
    aoff64_t offset)
{
	if (!start)
		start = AS_AREA_ANY;
	
//	if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
//		return MAP_FAILED;
	
	if (!(flags & MAP_ANONYMOUS))
		return MAP_FAILED;
	
	return as_area_create(start, length, prot);
}
Esempio n. 6
0
/** Create a program using an existing address space.
 *
 * @param as         Address space containing a binary program image.
 * @param entry_addr Program entry-point address in program address space.
 * @param name       Name to set for the program's task.
 * @param prg        Buffer for storing program information.
 *
 * @return EOK on success or negative error code.
 *
 */
int program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *prg)
{
	prg->loader_status = EE_OK;
	prg->task = task_create(as, name);
	if (!prg->task)
		return ELIMIT;
	
	/*
	 * Create the stack address space area.
	 */
	uintptr_t virt = USTACK_ADDRESS;
	as_area_t *area = as_area_create(as,
	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
	    STACK_SIZE, AS_AREA_ATTR_NONE, &anon_backend, NULL, &virt, 0);
	if (!area) {
		task_destroy(prg->task);
		return ENOMEM;
	}
	
	uspace_arg_t *kernel_uarg = (uspace_arg_t *)
	    malloc(sizeof(uspace_arg_t), 0);
	
	kernel_uarg->uspace_entry = (void *) entry_addr;
	kernel_uarg->uspace_stack = (void *) virt;
	kernel_uarg->uspace_stack_size = STACK_SIZE;
	kernel_uarg->uspace_thread_function = NULL;
	kernel_uarg->uspace_thread_arg = NULL;
	kernel_uarg->uspace_uarg = NULL;
	
	/*
	 * Create the main thread.
	 */
	prg->main_thread = thread_create(uinit, kernel_uarg, prg->task,
	    THREAD_FLAG_USPACE, "uinit");
	if (!prg->main_thread) {
		free(kernel_uarg);
		as_area_destroy(as, virt);
		task_destroy(prg->task);
		return ELIMIT;
	}
	
	return EOK;
}