Changeset c98e6ee in mainline for kernel/generic/src/proc/task.c


Ignore:
Timestamp:
2008-07-08T16:05:45Z (17 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f93f168
Parents:
b7f9087
Message:

Merge program-loader related stuff from dynload branch to trunk. (huge)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/task.c

    rb7f9087 rc98e6ee  
    3636 */
    3737
    38 #include <main/uinit.h>
    3938#include <proc/thread.h>
    4039#include <proc/task.h>
    41 #include <proc/uarg.h>
    4240#include <mm/as.h>
    4341#include <mm/slab.h>
     
    4745#include <arch.h>
    4846#include <arch/barrier.h>
    49 #include <panic.h>
    5047#include <adt/avl.h>
    5148#include <adt/btree.h>
    5249#include <adt/list.h>
    5350#include <ipc/ipc.h>
    54 #include <security/cap.h>
    55 #include <memstr.h>
     51#include <ipc/ipcrsc.h>
    5652#include <print.h>
    57 #include <lib/elf.h>
    5853#include <errno.h>
    5954#include <func.h>
    6055#include <syscall/copy.h>
    61 
    62 #ifndef LOADED_PROG_STACK_PAGES_NO
    63 #define LOADED_PROG_STACK_PAGES_NO 1
    64 #endif
    6556
    6657/** Spinlock protecting the tasks_tree AVL tree. */
     
    252243}
    253244
    254 unative_t sys_task_spawn(void *image, size_t size)
    255 {
    256         void *kimage = malloc(size, 0);
    257         if (kimage == NULL)
    258                 return ENOMEM;
    259        
    260         int rc = copy_from_uspace(kimage, image, size);
    261         if (rc != EOK)
    262                 return rc;
    263 
    264         /*
    265          * Not very efficient and it would be better to call it on code only,
    266          * but this whole function is a temporary hack anyway and one day it
    267          * will go in favor of the userspace dynamic loader.
    268          */
    269         smc_coherence_block(kimage, size);
    270        
    271         uspace_arg_t *kernel_uarg;
    272         kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
    273         if (kernel_uarg == NULL) {
    274                 free(kimage);
    275                 return ENOMEM;
    276         }
    277        
    278         kernel_uarg->uspace_entry =
    279             (void *) ((elf_header_t *) kimage)->e_entry;
    280         kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS;
    281         kernel_uarg->uspace_thread_function = NULL;
    282         kernel_uarg->uspace_thread_arg = NULL;
    283         kernel_uarg->uspace_uarg = NULL;
    284        
    285         as_t *as = as_create(0);
    286         if (as == NULL) {
    287                 free(kernel_uarg);
    288                 free(kimage);
    289                 return ENOMEM;
    290         }
    291        
    292         unsigned int erc = elf_load((elf_header_t *) kimage, as);
    293         if (erc != EE_OK) {
    294                 as_destroy(as);
    295                 free(kernel_uarg);
    296                 free(kimage);
    297                 return ENOENT;
    298         }
    299        
    300         as_area_t *area = as_area_create(as,
    301             AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
    302             LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS,
    303             AS_AREA_ATTR_NONE, &anon_backend, NULL);
    304         if (area == NULL) {
    305                 as_destroy(as);
    306                 free(kernel_uarg);
    307                 free(kimage);
    308                 return ENOMEM;
    309         }
    310        
    311         task_t *task = task_create(as, "app");
    312         if (task == NULL) {
    313                 as_destroy(as);
    314                 free(kernel_uarg);
    315                 free(kimage);
    316                 return ENOENT;
    317         }
    318        
    319         // FIXME: control the capabilities
    320         cap_set(task, cap_get(TASK));
    321        
    322         thread_t *thread = thread_create(uinit, kernel_uarg, task,
    323             THREAD_FLAG_USPACE, "user", false);
    324         if (thread == NULL) {
    325                 task_destroy(task);
    326                 as_destroy(as);
    327                 free(kernel_uarg);
    328                 free(kimage);
    329                 return ENOENT;
    330         }
    331        
    332         thread_ready(thread);
    333        
    334         return EOK;
    335 }
    336 
    337245/** Find task structure corresponding to task ID.
    338246 *
Note: See TracChangeset for help on using the changeset viewer.