Subversion Repositories HelenOS

Rev

Rev 3104 | Rev 3565 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3104 Rev 3222
Line 670... Line 670...
670
    node = avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) t));
670
    node = avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) t));
671
   
671
   
672
    return node != NULL;
672
    return node != NULL;
673
}
673
}
674
 
674
 
675
 
-
 
676
/** Create new user task with 1 thread from image
-
 
677
 *
-
 
678
 * @param program_addr Address of program executable image.
-
 
679
 * @param name Program name.
-
 
680
 *
-
 
681
 * @return Initialized main thread of the task or NULL on error.
-
 
682
 */
-
 
683
thread_t *thread_create_program(void *program_addr, char *name)
-
 
684
{
-
 
685
    as_t *as;
-
 
686
    as_area_t *area;
-
 
687
    unsigned int rc;
-
 
688
    task_t *task;
-
 
689
    uspace_arg_t *kernel_uarg;
-
 
690
   
-
 
691
    kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
-
 
692
    if (kernel_uarg == NULL)
-
 
693
        return NULL;
-
 
694
   
-
 
695
    kernel_uarg->uspace_entry =
-
 
696
        (void *) ((elf_header_t *) program_addr)->e_entry;
-
 
697
    kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS;
-
 
698
    kernel_uarg->uspace_thread_function = NULL;
-
 
699
    kernel_uarg->uspace_thread_arg = NULL;
-
 
700
    kernel_uarg->uspace_uarg = NULL;
-
 
701
 
-
 
702
    as = as_create(0);
-
 
703
    if (as == NULL) {
-
 
704
        free(kernel_uarg);
-
 
705
        return NULL;
-
 
706
    }
-
 
707
 
-
 
708
    rc = elf_load((elf_header_t *) program_addr, as);
-
 
709
    if (rc != EE_OK) {
-
 
710
        free(kernel_uarg);
-
 
711
        as_destroy(as);
-
 
712
        return NULL;
-
 
713
    }
-
 
714
   
-
 
715
    /*
-
 
716
     * Create the data as_area.
-
 
717
     */
-
 
718
    area = as_area_create(as,
-
 
719
        AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
-
 
720
        LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS,
-
 
721
        AS_AREA_ATTR_NONE, &anon_backend, NULL);
-
 
722
    if (area == NULL) {
-
 
723
        free(kernel_uarg);
-
 
724
        as_destroy(as);
-
 
725
        return NULL;
-
 
726
    }
-
 
727
   
-
 
728
    task = task_create(as, name);
-
 
729
    if (task == NULL) {
-
 
730
        free(kernel_uarg);
-
 
731
        as_destroy(as);
-
 
732
        return NULL;
-
 
733
    }
-
 
734
   
-
 
735
    /*
-
 
736
     * Create the main thread.
-
 
737
     */
-
 
738
    return thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE,
-
 
739
        "uinit", false);
-
 
740
}
-
 
741
 
-
 
742
 
-
 
743
/** Update accounting of current thread.
675
/** Update accounting of current thread.
744
 *
676
 *
745
 * Note that thread_lock on THREAD must be already held and
677
 * Note that thread_lock on THREAD must be already held and
746
 * interrupts must be already disabled.
678
 * interrupts must be already disabled.
747
 *
679
 *