Пример #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;
}
Пример #2
0
Файл: srv.c Проект: hxhlb/GridOS
/**
	@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;
}