Beispiel #1
0
static ke_handle memory_virtual_alloc(struct sysreq_memory_virtual_alloc *req)
{
	unsigned long base, sz, type;

	ke_handle handle;
	struct ko_section *ks_virtual;
	
	if (req->name)
	{
		type = KS_TYPE_SHARE;
		TRACE_UNIMPLEMENTED("命名内存空间还没有支持");
		goto err0;
	}
	else
		type = KS_TYPE_PRIVATE;
	
	base	= req->base_address;
	sz		= req->size;
	ks_virtual = ks_create(KP_CURRENT(), type, base, sz, req->mem_prot);
	if (!ks_virtual) goto err0;
	handle = ke_handle_create(ks_virtual);
	if (handle == KE_INVALID_HANDLE) goto err1;
	
	/* Fill output */
	req->out_base = ks_virtual->node.start;
	req->out_size = ks_virtual->node.size;
	return handle;
	
err1:
	TODO("分配内存段错误,须回收");
err0:
	return KE_INVALID_HANDLE;
}
Beispiel #2
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;
}
Beispiel #3
0
/**
	@brief Create a new user thread
*/
static ke_handle thread_create(struct sysreq_thread_create *req)
{
	ke_handle h;
	struct ko_thread *t;
	struct kt_thread_creating_context ctx = {0};

	ctx.thread_entry	= req->entry;
	ctx.fate_entry		= req->wrapper;	
	ctx.para			= req->para;
	ctx.flags			= req->run?KT_CREATE_RUN:0;
	if ((t = kt_create(KP_CURRENT(), &ctx)) == NULL)
		goto err;
	if (KE_INVALID_HANDLE == (h = ke_handle_create((void*)t)))
		goto err;
	
	return h;

err:
	if (t)
	{
		//TODO:
	}
	return KE_INVALID_HANDLE; 
}
Beispiel #4
0
/**
	@brief Thread synchronizing operation
 
	@return kt_sync_wait_result
*/
static int thread_sync_ops(struct sysreq_thread_sync *req)
{
	int i;
	int ops = req->ops;

	switch(ops)
	{
		/* 等待同步对象 */
		case SYSREQ_THREAD_SYNC_WAIT_OBJS:
		{
			int count = req->detail.wait_objs.count;
			struct kt_sync_base *sync_objs[Y_SYNC_MAX_OBJS_COUNT];
			y_handle sync_handles[Y_SYNC_MAX_OBJS_COUNT];
			kt_sync_wait_result ret = KE_WAIT_ERROR;
			
			if (count > Y_SYNC_MAX_OBJS_COUNT)
				goto wait_end;
			
			for (i = 0; i < count; i++)
			{
				sync_handles[i] =(ke_handle)req->detail.wait_objs.sync_objects[i];
				sync_objs[i] = ke_handle_translate(sync_handles[i]);
				if (!sync_objs[i])
					goto unwind_translate;
			}
			ret = kt_wait_objects(kt_current(), count, sync_objs,
							req->detail.wait_objs.wait_all,
							req->detail.wait_objs.timeout, NULL);

unwind_translate:
			for (i = 0; i < count; i++)
			{
				if (sync_objs[i])
					ke_handle_put(sync_handles[i], sync_objs[i]);
			}
wait_end:
			return ret;
		}
		case SYSREQ_THREAD_SYNC_WAIT_MS:
		{
			TODO("");
			break;	
		}

		case SYSREQ_THREAD_SYNC_EVENT:
		{
			ke_handle hevent;
			struct ke_event *event;
			
			switch (req->detail.event.ops)
			{
				case 's':
				{
					/* 唤醒线程,返回唤醒数量 */
					int count;
					
					hevent = req->detail.event.event;
					if (!(event = ke_handle_translate(hevent)))
						goto invalid_handle;
					count = ke_event_set(event);
					ke_handle_put(hevent, event);
					
					return count;
				}
				case 'c':
				{
					/* Create event, return handle */
					if (!(event = ke_event_object_create(req->detail.event.is_manual, req->detail.event.is_set)))
						goto invalid_handle;
					if (KE_INVALID_HANDLE == (hevent = ke_handle_create(event)))
					{
						km_vfree(event);
						goto invalid_handle;
					}
				
					return hevent;
				}
				case 'd':
				{
					/* delete the event, cause everybody wakeup */
#if 0
					hevent = req->detail.event.event;
					if (!(event = ke_handle_translate(hevent)))
						goto invalid_handle;
					ke_handle_and_object_destory(hevent, event);
#else
					TODO("事件对象用户模型还缺少cl_object的封装,无法销毁对象");
#endif
					return 0;
				}
			}
			break;
		}
	}
	
invalid_handle:
	return KE_INVALID_HANDLE;
}
Beispiel #5
0
/**
	@brief dynamic linker ops
 */
static ke_handle process_ld(struct sysreq_process_ld *req)
{
	ke_handle handle;
	xstring module_name;
	
	switch (req->function_type)
	{
		case SYSREQ_PROCESS_OPEN_EXE:
		{
			struct ko_exe *image;
			
			module_name = req->name;
			
			if (ke_validate_user_buffer(req->context, req->context_length, true) == false)
				goto ld_0_err;
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto ld_0_err;
			if (ke_validate_user_buffer(&req->map_base, sizeof(req->map_base), true) == false)
				goto ld_0_err;			
			if ((image = kp_exe_open_by_name(KP_CURRENT(), module_name, &req->map_base)) == NULL)			
				goto ld_0_err;
			if (kp_exe_copy_private(image, req->context, req->context_length) == false)
				goto ld_0_err1;
			
			/* Create handle for this image */
			handle = ke_handle_create(image);
			if (handle == KE_INVALID_HANDLE)
				goto ld_0_err1;

			return handle;
			
		ld_0_err1:
			//TODO: close the object
		ld_0_err:
			return KE_INVALID_HANDLE;
		}
		
		/* Return the map base */
		case SYSREQ_PROCESS_MAP_EXE_FILE:
		{
			struct ko_section *file_section;
			
			module_name = req->name;
			//printk("mapping exe file %s at user.\n", module_name);
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto map_0_err;				
			file_section = map_file(KP_CURRENT(), module_name, KM_PROT_READ, &req->context_length);
			if (file_section == NULL)
				goto map_0_err;
			
			/* We are preparing to use this section for EXE file ananlyzing, so no real handle is needed */
			//printk("map ok\n");
			return (ke_handle)file_section->node.start;
			
		map_0_err:
			return 0;
		}
		
		/* 
			Unamp file or module in current process space,
			req->handle is the module handle(if not by address of req->name)
			req->name is map base, return bool
		*/
		case SYSREQ_PROCESS_UNMAP_EXE_FILE:
		{
			if (req->name)
				return unmap_file(KP_CURRENT(), req->name);
			//TODO handle
		}
		break;
		
		/* Add a new exe object, return bool */
		case SYSREQ_PROCESS_ENJECT_EXE:
		{
			void *ctx;
			int ctx_size;
			struct ko_section *file_section;
			
			ctx_size		= req->context_length;
			ctx				= req->context;
			module_name		= req->name;

			if (ke_validate_user_buffer(ctx, ctx_size, false) == false)
				goto ld_3_err;
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto ld_3_err;
			if (ctx_size > kp_exe_get_context_size())
				goto ld_3_err;
			if ((file_section = map_file(kp_get_file_process(), module_name, KM_PROT_READ, NULL)) == NULL)
				goto ld_3_err;
			if (kp_exe_create_from_file(module_name, file_section, ctx, NULL) == NULL)
				goto ld_3_err;

			return true;
			
		ld_3_err:
			return false;
		}
		
		default:
			break;
	}

	return 0;
}
Beispiel #6
0
/**
 @brief dynamic linker ops
 */
static ke_handle process_ld(struct sysreq_process_ld * req)
{
	ke_handle handle;
	xstring module_name;
	
	switch (req->function_type)
	{
		case SYSREQ_PROCESS_OPEN_EXE:
		{
			struct ko_exe *image;
			
			module_name = req->name;
			
			/* Validate the user buffer */
			if (ke_validate_user_buffer(req->context, req->context_length, true) == false)
				goto ld_0_err;
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto ld_0_err;
			if (ke_validate_user_buffer(&req->map_base, sizeof(req->map_base), true) == false)
				goto ld_0_err;
			
			/* Open the image by name */
			image = 0;
			if (!image) goto ld_0_err;
			if (kp_exe_copy_private(image, req->context, req->context_length) == false)
				goto ld_0_err1;
			
			/* Create handle for this image */
			handle = ke_handle_create(image);
			if (handle == KE_INVALID_HANDLE)
				goto ld_0_err1;

			return handle;
			
		ld_0_err1:
			//TODO: close the object
		ld_0_err:
			return KE_INVALID_HANDLE;
		}
		
		/* Get file base and size */
		case SYSREQ_PROCESS_MAP_EXE_FILE:
		{
			void *base;
		
			module_name = req->name;
		}
		
		/* 删除本地map的文件 */
		case SYSREQ_PROCESS_UNMAP_EXE_FILE:
		{
			void *base = req->name;
		}
		
		/* Add a new exe object, return bool */
		case SYSREQ_PROCESS_ENJECT_EXE:
		{
			struct ko_exe *image;
			void *ctx		= req->context;
			int ctx_size	= req->context_length;
			
			if (ke_validate_user_buffer(ctx, ctx_size, false) == false)
				goto ld_3_err;
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto ld_3_err;
			if (ctx_size > kp_exe_get_context_size())
				goto ld_3_err;
			if (kp_exe_create_from_file(module_name, ctx) == NULL)
				goto ld_3_err;
			return true;
			
		ld_3_err:
			return false;
		}
		default:
			break;
	}
}
Beispiel #7
0
/**
	@brief dynamic linker ops
 */
static ke_handle process_ld(struct sysreq_process_ld * req)
{
	ke_handle handle;
	xstring module_name;
	
	switch (req->function_type)
	{
		case SYSREQ_PROCESS_OPEN_EXE:
		{
			struct ko_exe *image;
			
			module_name = req->name;
			
			if (ke_validate_user_buffer(req->context, req->context_length, true) == false)
				goto ld_0_err;
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto ld_0_err;
			if (ke_validate_user_buffer(&req->map_base, sizeof(req->map_base), true) == false)
				goto ld_0_err;			
			if ((image = kp_exe_open_by_name(KP_CURRENT(), module_name, &req->map_base)) == NULL)			
				goto ld_0_err;
			if (kp_exe_copy_private(image, req->context, req->context_length) == false)
				goto ld_0_err1;
			
			/* Create handle for this image */
			handle = ke_handle_create(image);
			if (handle == KE_INVALID_HANDLE)
				goto ld_0_err1;

			return handle;
			
		ld_0_err1:
			//TODO: close the object
		ld_0_err:
			return KE_INVALID_HANDLE;
		}
		
		/* Return the map base */
		case SYSREQ_PROCESS_MAP_EXE_FILE:
		{
			struct ko_section *file_section;
			
			module_name = req->name;
			
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto map_0_err;				
			file_section = map_file(KP_CURRENT(), module_name, KM_PROT_READ, &req->context_length);
			if (file_section == NULL)
				goto map_0_err;
			
			return (ke_handle)file_section->node.start;
			
		map_0_err:
			return 0;
		}
		
		/* 删除本地map的文件 */
		case SYSREQ_PROCESS_UNMAP_EXE_FILE:
		{
			void *base = req->name;
			TRACE_UNIMPLEMENTED("");
		}
		break;
		
		/* Add a new exe object, return bool */
		case SYSREQ_PROCESS_ENJECT_EXE:
		{
			struct ko_exe *image;
			void *ctx;
			int ctx_size;
			unsigned long size;
			struct ko_section *file_section;
			
			ctx_size		= req->context_length;
			ctx				= req->context;
			module_name		= req->name;
			
			if (ke_validate_user_buffer(ctx, ctx_size, false) == false)
				goto ld_3_err;
			if (ke_validate_user_buffer(module_name, strlen(module_name), false) == false)
				goto ld_3_err;
			if (ctx_size > kp_exe_get_context_size())
				goto ld_3_err;
			if ((file_section = map_file(kp_get_file_process(), module_name, KM_PROT_READ, &size)) == NULL)
				goto ld_3_err;
			if (kp_exe_create_from_file(module_name, file_section, ctx, NULL) == NULL)
				goto ld_3_err;
			
			return true;
			
		ld_3_err:
			return false;
		}
		default:
			break;
	}

	return 0;
}