Changes in kernel/generic/src/proc/program.c [fbcdeb8:d1e8440] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/program.c
rfbcdeb8 rd1e8440 71 71 int program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *prg) 72 72 { 73 uspace_arg_t *kernel_uarg; 74 75 kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); 73 prg->loader_status = EE_OK; 74 prg->task = task_create(as, name); 75 if (!prg->task) 76 return ELIMIT; 77 78 /* 79 * Create the stack address space area. 80 */ 81 uintptr_t virt = (uintptr_t) -1; 82 uintptr_t bound = USER_ADDRESS_SPACE_END - (STACK_SIZE_USER - 1); 83 84 /* Adjust bound to create space for the desired guard page. */ 85 bound -= PAGE_SIZE; 86 87 as_area_t *area = as_area_create(as, 88 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE | AS_AREA_GUARD | 89 AS_AREA_LATE_RESERVE, STACK_SIZE_USER, AS_AREA_ATTR_NONE, 90 &anon_backend, NULL, &virt, bound); 91 if (!area) { 92 task_destroy(prg->task); 93 return ENOMEM; 94 } 95 96 uspace_arg_t *kernel_uarg = (uspace_arg_t *) 97 malloc(sizeof(uspace_arg_t), 0); 98 76 99 kernel_uarg->uspace_entry = (void *) entry_addr; 77 kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS; 100 kernel_uarg->uspace_stack = (void *) virt; 101 kernel_uarg->uspace_stack_size = STACK_SIZE_USER; 78 102 kernel_uarg->uspace_thread_function = NULL; 79 103 kernel_uarg->uspace_thread_arg = NULL; 80 104 kernel_uarg->uspace_uarg = NULL; 81 82 prg->task = task_create(as, name);83 if (!prg->task)84 return ELIMIT;85 86 /*87 * Create the stack address space area.88 */89 uintptr_t virt = USTACK_ADDRESS;90 as_area_t *area = as_area_create(as,91 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,92 STACK_SIZE, AS_AREA_ATTR_NONE, &anon_backend, NULL, &virt, 0);93 if (!area)94 return ENOMEM;95 105 96 106 /* … … 98 108 */ 99 109 prg->main_thread = thread_create(uinit, kernel_uarg, prg->task, 100 THREAD_FLAG_USPACE, "uinit", false); 101 if (!prg->main_thread) 110 THREAD_FLAG_USPACE, "uinit"); 111 if (!prg->main_thread) { 112 free(kernel_uarg); 113 as_area_destroy(as, virt); 114 task_destroy(prg->task); 102 115 return ELIMIT; 116 } 103 117 104 118 return EOK; … … 111 125 * executable image. The task is returned in *task. 112 126 * 113 * @param image_addr Address of an executable program image. 114 * @param name Name to set for the program's task. 115 * @param prg Buffer for storing program info. If image_addr 116 * points to a loader image, p->task will be set to 117 * NULL and EOK will be returned. 127 * @param[in] image_addr Address of an executable program image. 128 * @param[in] name Name to set for the program's task. 129 * @param[out] prg Buffer for storing program info. 130 * If image_addr points to a loader image, 131 * prg->task will be set to NULL and EOK 132 * will be returned. 118 133 * 119 134 * @return EOK on success or negative error code. … … 126 141 return ENOMEM; 127 142 128 unsigned int rc= elf_load((elf_header_t *) image_addr, as, 0);129 if ( rc!= EE_OK) {143 prg->loader_status = elf_load((elf_header_t *) image_addr, as, 0); 144 if (prg->loader_status != EE_OK) { 130 145 as_destroy(as); 131 146 prg->task = NULL; 132 147 prg->main_thread = NULL; 133 148 134 if ( rc!= EE_LOADER)149 if (prg->loader_status != EE_LOADER) 135 150 return ENOTSUP; 136 151 … … 140 155 141 156 program_loader = image_addr; 142 LOG("Registered program loader at %p", 143 (void *) image_addr); 157 printf("Program loader at %p\n", (void *) image_addr); 144 158 145 159 return EOK; … … 171 185 } 172 186 173 unsigned int rc= elf_load((elf_header_t *) program_loader, as,187 prg->loader_status = elf_load((elf_header_t *) program_loader, as, 174 188 ELD_F_LOADER); 175 if ( rc!= EE_OK) {189 if (prg->loader_status != EE_OK) { 176 190 as_destroy(as); 177 printf("Cannot spawn loader (%s)\n", elf_error(rc)); 191 printf("Cannot spawn loader (%s)\n", 192 elf_error(prg->loader_status)); 178 193 return ENOENT; 179 194 }
Note:
See TracChangeset
for help on using the changeset viewer.