Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3189 → Rev 3190

/branches/dynload/kernel/generic/include/proc/task.h
140,7 → 140,6
 
extern unative_t sys_task_get_id(task_id_t *uspace_task_id);
extern unative_t sys_task_spawn_loader(int *uspace_phone_id);
extern unative_t sys_task_spawn(void *image, size_t size);
 
#endif
 
/branches/dynload/kernel/generic/include/proc/thread.h
248,8 → 248,6
extern void thread_update_accounting(void);
extern bool thread_exists(thread_t *t);
 
extern thread_t *thread_create_program(void *program_addr, char *name);
 
/** Fpu context slab cache. */
extern slab_cache_t *fpu_context_slab;
 
/branches/dynload/kernel/generic/include/syscall/syscall.h
44,7 → 44,6
SYS_THREAD_GET_ID,
SYS_TASK_GET_ID,
SYS_TASK_SPAWN,
SYS_TASK_SPAWN_LOADER,
SYS_FUTEX_SLEEP,
/branches/dynload/kernel/generic/src/proc/task.c
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
/branches/dynload/kernel/generic/src/proc/thread.c
672,74 → 672,6
return node != NULL;
}
 
 
/** Create new user task with 1 thread from image
*
* @param program_addr Address of program executable image.
* @param name Program name.
*
* @return Initialized main thread of the task or NULL on error.
*/
thread_t *thread_create_program(void *program_addr, char *name)
{
as_t *as;
as_area_t *area;
unsigned int rc;
task_t *task;
uspace_arg_t *kernel_uarg;
kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
if (kernel_uarg == NULL)
return NULL;
kernel_uarg->uspace_entry =
(void *) ((elf_header_t *) program_addr)->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 = as_create(0);
if (as == NULL) {
free(kernel_uarg);
return NULL;
}
 
rc = elf_load((elf_header_t *) program_addr, as, ELD_F_NONE);
if (rc != EE_OK) {
free(kernel_uarg);
as_destroy(as);
return NULL;
}
/*
* Create the data as_area.
*/
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) {
free(kernel_uarg);
as_destroy(as);
return NULL;
}
task = task_create(as, name);
if (task == NULL) {
free(kernel_uarg);
as_destroy(as);
return NULL;
}
/*
* Create the main thread.
*/
return thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE,
"uinit", false);
}
 
 
/** Update accounting of current thread.
*
* Note that thread_lock on THREAD must be already held and
/branches/dynload/kernel/generic/src/syscall/syscall.c
130,7 → 130,6
(syshandler_t) sys_thread_get_id,
(syshandler_t) sys_task_get_id,
(syshandler_t) sys_task_spawn,
(syshandler_t) sys_task_spawn_loader,
/* Synchronization related syscalls. */