Example #1
0
static ke_handle process_create(struct sysreq_process_create * req)
{
	struct ko_process *process;
	struct ko_exe *ke_ld;
	ke_handle handle;

	if ((ke_ld = kp_exe_search_by_name("/os/i386/dl.sys")) == NULL)
		goto err1;
	if ((process = kp_run_user(ke_ld, req->cmdline)) == NULL)
		goto err2;
	if ((handle = ke_handle_create(KP_CURRENT())) == KE_INVALID_HANDLE)
		goto err3;
	kp_exe_put(ke_ld);
	
	return handle;

err3:
	//TODO: delete the process
err2:
	//TODO: close the object
err1:
	return KE_INVALID_HANDLE;
}
Example #2
0
/**
	@brief run startup process
 */
void ke_run_first_user_process(void *data, int size, char *cmdline)
{
	char *first_space, first_exe_name[128] = {0};
	struct ko_section *ks;
	void *entry_address;
	struct ko_exe *kee, *ke_tmp = kp_exe_create_temp();

	first_space = strchr(cmdline, ' ');
	if (!first_space)
		goto err;
	if (first_space - cmdline >= sizeof(first_exe_name) - sizeof(xchar))
		goto err;
	strncpy(first_exe_name, cmdline, first_space - cmdline);

	/* Kernel file process, because early we cannot copy lv2 table of driver */
	kernel_file_process = kp_create(KP_CPL0_FAKE, "操作系统文件进程");
	if (!kernel_file_process)
		goto err;
	printk("启动用户第一个可执行文件%x, size %d.\n", data, size);
	
	if (size == 0/*no file*/ || size == 1/*buffer error*/)
		goto err;
	if (elf_analyze(data, size, &entry_address, KO_EXE_TO_PRIVATE(ke_tmp)) == false)
		goto err;

	ks = ks_create(kp_get_file_process(), KS_TYPE_PRIVATE, 0, size, KM_PROT_READ|KM_PROT_WRITE);
	if (!ks)
		goto err;
	kee = kp_exe_create_from_file(first_exe_name, ks, KO_EXE_TO_PRIVATE(ke_tmp), entry_address);		
	if (!kee)
		goto err;
	
	/* But this is a special one, we have to fill the data on it */
	do {
		
		struct kt_thread_creating_context ctx = {0};
		
		struct file_process_startup_para package;
		
		package.ks_start	= ks->node.start;
		package.size		= size;
		package.data		= data;
		ctx.thread_entry	= file_thread;
		ctx.flags			= KT_CREATE_RUN;
		ctx.para			= (unsigned long)&package;
		if (kt_create(kernel_file_process, &ctx) == NULL)
			goto err;
		
		/* Wait it to finish */
		while (package.data)
			kt_schedule();
	} while(0);
	
	/* OK, create the process */
	if (kp_run_user(kee, ++first_space/*Real application*/) == false)
		goto err;
	
	return;
err:
	printk("启动第一可执行文件失败。\n");

}