Changeset c98e6ee in mainline for kernel/generic/src/proc/task.c
- Timestamp:
- 2008-07-08T16:05:45Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f93f168
- Parents:
- b7f9087
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/task.c
rb7f9087 rc98e6ee 36 36 */ 37 37 38 #include <main/uinit.h>39 38 #include <proc/thread.h> 40 39 #include <proc/task.h> 41 #include <proc/uarg.h>42 40 #include <mm/as.h> 43 41 #include <mm/slab.h> … … 47 45 #include <arch.h> 48 46 #include <arch/barrier.h> 49 #include <panic.h>50 47 #include <adt/avl.h> 51 48 #include <adt/btree.h> 52 49 #include <adt/list.h> 53 50 #include <ipc/ipc.h> 54 #include <security/cap.h> 55 #include <memstr.h> 51 #include <ipc/ipcrsc.h> 56 52 #include <print.h> 57 #include <lib/elf.h>58 53 #include <errno.h> 59 54 #include <func.h> 60 55 #include <syscall/copy.h> 61 62 #ifndef LOADED_PROG_STACK_PAGES_NO63 #define LOADED_PROG_STACK_PAGES_NO 164 #endif65 56 66 57 /** Spinlock protecting the tasks_tree AVL tree. */ … … 252 243 } 253 244 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 it267 * 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 capabilities320 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 337 245 /** Find task structure corresponding to task ID. 338 246 *
Note:
See TracChangeset
for help on using the changeset viewer.