Пример #1
0
/* Ktap Main Entry */
static int ktap_main(struct file *file, struct ktap_user_parm *uparm_ptr)
{
	unsigned long *buff = NULL;
	ktap_State *ks;
	Closure *cl;
	int argc;
	char **argv, *argstr;
	int ret;

	argstr = kmalloc(uparm_ptr->arglen, GFP_KERNEL);
	if (!argstr)
		return -ENOMEM;

	ret = copy_from_user(argstr, (void __user *)uparm_ptr->argstr,
			     uparm_ptr->arglen);
	if (ret < 0) {
		kfree(argstr);
		return -EFAULT;
	}

	argv = argv_split(GFP_KERNEL, argstr, &argc);
	if (!argv) {
		kfree(argstr);
		pr_err("out of memory");
		return -ENOMEM;
	}

	kfree(argstr);

	ret = load_trunk(uparm_ptr, &buff);
	if (ret) {
		pr_err("cannot load file %s\n", argv[0]);
		argv_free(argv);
		return ret;
	}

	ks = kp_newstate((ktap_State **)&file->private_data, argc, argv);

	argv_free(argv);
	if (unlikely(!ks)) {
		vfree(buff);
		return -ENOEXEC;
	}

	cl = kp_load(ks, (unsigned char *)buff);

	vfree(buff);

	if (cl) {
		/* optimize bytecode before excuting */
		kp_optimize_code(ks, 0, cl->l.p);
		kp_call(ks, ks->top - 1, 0);
	}

	kp_exit(ks);
	return 0;
}
Пример #2
0
Файл: ktap.c Проект: pcn/ktap
/* Ktap Main Entry */
static int ktap_main(struct file *file, ktap_parm *parm)
{
	unsigned long *buff = NULL;
	ktap_state *ks;
	ktap_closure *cl;
	int start_time, delta_time;
	int ret;

	if (atomic_inc_return(&kp_is_running) != 1) {
		atomic_dec(&kp_is_running);
		pr_info("only one ktap thread allow to run\n");
		return -EBUSY;
	}

	start_time = gettimeofday_us();

	ks = kp_newstate(parm, kp_dir_dentry);
	if (unlikely(!ks)) {
		ret = -ENOEXEC;
		goto out;
	}

	file->private_data = ks;

	ret = load_trunk(parm, &buff);
	if (ret) {
		pr_err("cannot load file\n");
		goto out;
	}

	cl = kp_load(ks, (unsigned char *)buff);

	vfree(buff);

	if (cl) {
		/* optimize bytecode before excuting */
		kp_optimize_code(ks, 0, cl->p);

		delta_time = gettimeofday_us() - start_time;
		kp_verbose_printf(ks, "booting time: %d (us)\n", delta_time);
		kp_call(ks, ks->top - 1, 0);
	}

	kp_final_exit(ks);

 out:
	atomic_dec(&kp_is_running);	
	return ret;
}
Пример #3
0
/* Ktap Main Entry */
static int ktap_main(struct file *file, ktap_option_t *parm)
{
	unsigned long *buff = NULL;
	ktap_state_t *ks;
	ktap_proto_t *pt;
	long start_time, delta_time;
	int ret;

	start_time = gettimeofday_ns();

	ks = kp_vm_new_state(parm, kp_dir_dentry);
	if (unlikely(!ks))
		return -ENOEXEC;

	file->private_data = ks;

	ret = load_trunk(parm, &buff);
	if (ret) {
		kp_error(ks, "cannot load file\n");
		goto out;
	}

	pt = kp_bcread(ks, (unsigned char *)buff, parm->trunk_len);

	vfree(buff);

	if (pt) {
		/* validate byte code */
		if (kp_vm_validate_code(ks, pt, ks->stack))
			goto out;

		delta_time = (gettimeofday_ns() - start_time) / NSEC_PER_USEC;
		kp_verbose_printf(ks, "booting time: %d (us)\n", delta_time);

		/* enter vm */
		kp_vm_call_proto(ks, pt);
	}

 out:
	kp_vm_exit(ks);
	return ret;
}
Пример #4
0
/* Ktap Main Entry */
static int ktap_main(struct file *file, ktap_parm *parm)
{
	unsigned long *buff = NULL;
	ktap_state *ks;
	ktap_closure *cl;
	int start_time, delta_time;
	int ret;

	start_time = gettimeofday_us();

	ks = kp_newstate(parm, kp_dir_dentry);
	if (unlikely(!ks))
		return -ENOEXEC;

	file->private_data = ks;

	ret = load_trunk(parm, &buff);
	if (ret) {
		pr_err("cannot load file\n");
		return ret;
	}

	cl = kp_load(ks, (unsigned char *)buff);

	vfree(buff);

	if (cl) {
		/* optimize bytecode before excuting */
		kp_optimize_code(ks, 0, cl->p);

		delta_time = gettimeofday_us() - start_time;
		kp_verbose_printf(ks, "booting time: %d (us)\n", delta_time);
		kp_call(ks, ks->top - 1, 0);
	}

	kp_final_exit(ks);
	return ret;
}