Beispiel #1
0
vm_context_t *vm_context_create(vm_module_t *module)
{
	vm_context_t *ctx;

	ctx = (vm_context_t *)vm_alloc(sizeof(*ctx));
	if (!ctx) {
		vm_panic("vm_context_create: failed to allocate context.");
	}

	ctx->dstack = vm_stack_create(65536);
	ctx->cstack = vm_stack_create(8192);	
	ctx->pc = module->entry;
	ctx->locals = NULL;
	ctx->module = module;

	return ctx;
}
Beispiel #2
0
struct thread * thread_create() {
	struct thread *t;

	pthread_once(&key_once, thread_make_key);

	if ((t = (struct thread *)heap_malloc(heap, sizeof(struct thread))) == NULL)
		mvm_halt();

	t->ref = 0;
	t->state = new_state;
	t->pc = 0;

	if ((t->ref_buckets = (struct heap_ref *)
	     calloc(HEAP_NUM_BUCKETS, sizeof(struct heap_ref))) == NULL) {
		perror("mvm: malloc");
		mvm_halt();
	}

	if ((t->free_buckets = (struct free_bucket *)
	     calloc(THREAD_NUM_FREE_BUCKETS, sizeof(struct free_bucket))) == NULL) {
		perror("mvm: malloc");
		mvm_halt();
	}

	if ((t->vm_stack = vm_stack_create()) == NULL)
		mvm_halt();

	if ((t->excluded_set = ref_set_create(0)) == NULL)
		mvm_halt();

#ifdef DMP	
	if (dmp == NULL)
		t->dmp = NULL;
	else
		t->dmp = dmp_create_thread_dmp(dmp, t);
#endif

	return t;
}