Rev 3424 | Rev 3426 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3424 | Rev 3425 | ||
---|---|---|---|
Line 681... | Line 681... | ||
681 | node = avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) t)); |
681 | node = avltree_search(&threads_tree, (avltree_key_t) ((uintptr_t) t)); |
682 | 682 | ||
683 | return node != NULL; |
683 | return node != NULL; |
684 | } |
684 | } |
685 | 685 | ||
686 | - | ||
687 | /** Create new user task with 1 thread from image |
- | |
688 | * |
- | |
689 | * @param program_addr Address of program executable image. |
- | |
690 | * @param name Program name. |
- | |
691 | * |
- | |
692 | * @return Initialized main thread of the task or NULL on error. |
- | |
693 | */ |
- | |
694 | thread_t *thread_create_program(void *program_addr, char *name) |
- | |
695 | { |
- | |
696 | as_t *as; |
- | |
697 | as_area_t *area; |
- | |
698 | unsigned int rc; |
- | |
699 | task_t *task; |
- | |
700 | uspace_arg_t *kernel_uarg; |
- | |
701 | - | ||
702 | kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
- | |
703 | if (kernel_uarg == NULL) |
- | |
704 | return NULL; |
- | |
705 | - | ||
706 | kernel_uarg->uspace_entry = |
- | |
707 | (void *) ((elf_header_t *) program_addr)->e_entry; |
- | |
708 | kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS; |
- | |
709 | kernel_uarg->uspace_thread_function = NULL; |
- | |
710 | kernel_uarg->uspace_thread_arg = NULL; |
- | |
711 | kernel_uarg->uspace_uarg = NULL; |
- | |
712 | - | ||
713 | as = as_create(0); |
- | |
714 | if (as == NULL) { |
- | |
715 | free(kernel_uarg); |
- | |
716 | return NULL; |
- | |
717 | } |
- | |
718 | - | ||
719 | rc = elf_load((elf_header_t *) program_addr, as); |
- | |
720 | if (rc != EE_OK) { |
- | |
721 | free(kernel_uarg); |
- | |
722 | as_destroy(as); |
- | |
723 | return NULL; |
- | |
724 | } |
- | |
725 | - | ||
726 | /* |
- | |
727 | * Create the data as_area. |
- | |
728 | */ |
- | |
729 | area = as_area_create(as, |
- | |
730 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE, |
- | |
731 | LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS, |
- | |
732 | AS_AREA_ATTR_NONE, &anon_backend, NULL); |
- | |
733 | if (area == NULL) { |
- | |
734 | free(kernel_uarg); |
- | |
735 | as_destroy(as); |
- | |
736 | return NULL; |
- | |
737 | } |
- | |
738 | - | ||
739 | task = task_create(as, name); |
- | |
740 | if (task == NULL) { |
- | |
741 | free(kernel_uarg); |
- | |
742 | as_destroy(as); |
- | |
743 | return NULL; |
- | |
744 | } |
- | |
745 | - | ||
746 | /* |
- | |
747 | * Create the main thread. |
- | |
748 | */ |
- | |
749 | return thread_create(uinit, kernel_uarg, task, THREAD_FLAG_USPACE, |
- | |
750 | "uinit", false); |
- | |
751 | } |
- | |
752 | - | ||
753 | - | ||
754 | /** Update accounting of current thread. |
686 | /** Update accounting of current thread. |
755 | * |
687 | * |
756 | * Note that thread_lock on THREAD must be already held and |
688 | * Note that thread_lock on THREAD must be already held and |
757 | * interrupts must be already disabled. |
689 | * interrupts must be already disabled. |
758 | * |
690 | * |