Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3003 → Rev 3004

/branches/dynload/kernel/generic/src/proc/task.c
50,6 → 50,7
#include <adt/btree.h>
#include <adt/list.h>
#include <ipc/ipc.h>
#include <ipc/ipcrsc.h>
#include <security/cap.h>
#include <memstr.h>
#include <print.h>
323,27 → 324,33
 
/** Create a task from the program loader image.
*
* @param program_addr Address of program executable image.
* @param name Program name.
* @param t Buffer for storing pointer to the newly created task.
*
* @return Task of the running program or NULL on error.
*/
task_t *task_create_from_loader(char *name)
int task_create_from_loader(char *name, task_t **t)
{
as_t *as;
unsigned int rc;
void *loader;
 
as = as_create(0);
ASSERT(as);
 
loader = program_loader;
if (!loader) return ENOENT;
 
rc = elf_load((elf_header_t *) program_loader, as, ELD_F_LOADER);
if (rc != EE_OK) {
as_destroy(as);
return NULL;
return ENOENT;
}
 
return task_create_from_as(
*t = task_create_from_as(
as, ((elf_header_t *) program_loader)->e_entry, name);
 
return EOK;
}
 
/** Make task ready.
379,33 → 386,44
 
/** Syscall for creating a new task from userspace.
*
* Creates a new task from the program loader image and stores its
* task id into the provided buffer.
* Creates a new task from the program loader image, connects a phone
* to it and stores the phone id into the provided buffer.
*
* @param uspace_task_id Userspace address of 8-byte buffer where to store
* current task ID.
* @param uspace_phone_id Userspace address where to store the phone id.
*
* @return 0 on success or an error code from @ref errno.h.
*/
unative_t sys_task_spawn(task_id_t *uspace_task_id)
unative_t sys_task_spawn(int *uspace_phone_id)
{
task_t *t;
task_id_t fake_id;
int fake_id;
int rc;
int phone_id;
 
fake_id = 0;
 
/* Before we even try creating the task, see if we can write the id */
rc = (unative_t) copy_to_uspace(uspace_task_id, &fake_id,
rc = (unative_t) copy_to_uspace(uspace_phone_id, &fake_id,
sizeof(fake_id));
if (rc != 0)
return rc;
 
t = task_create_from_loader("loader");
phone_id = phone_alloc();
if (phone_id < 0)
return ELIMIT;
 
rc = task_create_from_loader("loader", &t);
if (rc != 0)
return rc;
 
phone_connect(phone_id, &t->answerbox);
 
/* No need to aquire lock before task_ready() */
rc = (unative_t) copy_to_uspace(uspace_task_id, &t->taskid,
sizeof(t->taskid));
rc = (unative_t) copy_to_uspace(uspace_phone_id, &phone_id,
sizeof(phone_id));
if (rc != 0) {
/* Ooops */
ipc_phone_hangup(&TASK->phones[phone_id]);
task_kill(t->taskid);
return rc;
}