442,89 → 442,6 |
return EOK; |
} |
|
unative_t sys_task_spawn(void *image, size_t size) |
{ |
void *kimage = malloc(size, 0); |
if (kimage == NULL) |
return ENOMEM; |
|
int rc = copy_from_uspace(kimage, image, size); |
if (rc != EOK) |
return rc; |
|
/* |
* Not very efficient and it would be better to call it on code only, |
* but this whole function is a temporary hack anyway and one day it |
* will go in favor of the userspace dynamic loader. |
*/ |
smc_coherence_block(kimage, size); |
|
uspace_arg_t *kernel_uarg; |
kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
if (kernel_uarg == NULL) { |
free(kimage); |
return ENOMEM; |
} |
|
kernel_uarg->uspace_entry = |
(void *) ((elf_header_t *) kimage)->e_entry; |
kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS; |
kernel_uarg->uspace_thread_function = NULL; |
kernel_uarg->uspace_thread_arg = NULL; |
kernel_uarg->uspace_uarg = NULL; |
|
as_t *as = as_create(0); |
if (as == NULL) { |
free(kernel_uarg); |
free(kimage); |
return ENOMEM; |
} |
|
unsigned int erc = elf_load((elf_header_t *) kimage, as, ELD_F_NONE); |
if (erc != EE_OK) { |
as_destroy(as); |
free(kernel_uarg); |
free(kimage); |
return ENOENT; |
} |
|
as_area_t *area = as_area_create(as, |
AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, |
LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS, |
AS_AREA_ATTR_NONE, &anon_backend, NULL); |
if (area == NULL) { |
as_destroy(as); |
free(kernel_uarg); |
free(kimage); |
return ENOMEM; |
} |
|
task_t *task = task_create(as, "app"); |
if (task == NULL) { |
as_destroy(as); |
free(kernel_uarg); |
free(kimage); |
return ENOENT; |
} |
|
// FIXME: control the capabilities |
cap_set(task, cap_get(TASK)); |
|
thread_t *thread = thread_create(uinit, kernel_uarg, task, |
THREAD_FLAG_USPACE, "user", false); |
if (thread == NULL) { |
task_destroy(task); |
as_destroy(as); |
free(kernel_uarg); |
free(kimage); |
return ENOENT; |
} |
|
thread_ready(thread); |
|
return EOK; |
} |
|
/** Find task structure corresponding to task ID. |
* |
* The tasks_lock must be already held by the caller of this function |