Changeset 5be1923 in mainline
- Timestamp:
- 2006-03-14T12:11:28Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d3e7ff4
- Parents:
- 4bb4836d
- Location:
- generic
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/mm/as.h
r4bb4836d r5be1923 108 108 extern int as_page_fault(__address page); 109 109 extern void as_switch(as_t *old, as_t *new); 110 extern void as_free(as_t *as); 110 111 111 112 /* Interface to be implemented by architectures. */ -
generic/include/proc/task.h
r4bb4836d r5be1923 50 50 extern void task_init(void); 51 51 extern task_t *task_create(as_t *as); 52 extern task_t *task_run_program(void * program_addr); 52 53 53 54 #endif -
generic/src/lib/elf.c
r4bb4836d r5be1923 186 186 return EE_UNSUPPORTED; 187 187 188 /*189 * Copying the segment out is certainly necessary for segments with p_filesz < p_memsz190 * because of the effect of .bss-like sections. For security reasons, it looks like a191 * good idea to copy the segment anyway.192 */193 188 segment_size = ALIGN_UP(max(entry->p_filesz, entry->p_memsz), PAGE_SIZE); 194 segment = malloc(segment_size, 0); 195 if (entry->p_filesz < entry->p_memsz) 189 if ((entry->p_flags & PF_W)) { 190 /* If writable, copy data (should be COW in the future) */ 191 segment = malloc(segment_size, 0); 196 192 memsetb((__address) (segment + entry->p_filesz), segment_size - entry->p_filesz, 0); 197 memcpy(segment, (void *) (((__address) elf) + entry->p_offset), entry->p_filesz); 193 memcpy(segment, (void *) (((__address) elf) + entry->p_offset), entry->p_filesz); 194 } else /* Map identically original data */ 195 segment = ((void *) elf) + entry->p_offset; 198 196 199 197 a = as_area_create(as, type, SIZE2FRAMES(entry->p_memsz), entry->p_vaddr); -
generic/src/main/kinit.c
r4bb4836d r5be1923 28 28 29 29 #include <main/kinit.h> 30 #include <main/uinit.h>31 30 #include <config.h> 32 31 #include <arch.h> … … 47 46 #include <interrupt.h> 48 47 #include <console/kconsole.h> 49 #include <elf.h>50 48 #include <ipc/ns.h> 51 49 … … 72 70 { 73 71 thread_t *t; 74 as_t *as;75 as_area_t *a;76 int rc;77 task_t *u;78 72 79 73 interrupts_disable(); … … 150 144 if (config.init_addr % FRAME_SIZE) 151 145 panic("config.init_addr is not frame aligned"); 152 153 as = as_create(0);154 if (!as)155 panic("as_create\n");156 146 157 rc = elf_load((elf_header_t *) config.init_addr, as); 158 if (rc != EE_OK) { 159 printf("elf_load failed: %s\n", elf_error(rc)); 160 } else { 161 u = task_create(as); 162 if (!u) 163 panic("task_create\n"); 164 t = thread_create(uinit, (void *)((elf_header_t *) config.init_addr)->e_entry, u, THREAD_USER_STACK); 165 if (!t) 166 panic("thread_create\n"); 167 168 /* 169 * Create the data as_area. 170 */ 171 a = as_area_create(as, AS_AREA_STACK, 1, USTACK_ADDRESS); 172 if (!a) 173 panic("as_area_create: stack\n"); 174 175 thread_ready(t); 147 if (!task_run_program((void *)config.init_addr)) { 148 printf("Userspace not started.\n"); 176 149 } 177 150 } -
generic/src/mm/as.c
r4bb4836d r5be1923 104 104 } 105 105 106 /** Free Adress space */ 107 void as_free(as_t *as) 108 { 109 ASSERT(as->refcount == 0); 110 111 /* TODO: free as_areas and other resources held by as */ 112 /* TODO: free page table */ 113 free(as); 114 } 115 106 116 /** Create address space area of common attributes. 107 117 * -
generic/src/proc/task.c
r4bb4836d r5be1923 27 27 */ 28 28 29 #include <main/uinit.h> 29 30 #include <proc/thread.h> 30 31 #include <proc/task.h> … … 39 40 #include <ipc/ns.h> 40 41 #include <memstr.h> 42 43 #include <elf.h> 41 44 42 45 SPINLOCK_INITIALIZE(tasks_lock); … … 60 63 * @param as Task's address space. 61 64 * 62 * @return New task's structure on success, NULL on failure.65 * @return New task's structure 63 66 * 64 67 */ … … 89 92 } 90 93 94 /** Create new task with 1 thread and run it 95 * 96 * @return Task of the running program or NULL on error 97 */ 98 task_t * task_run_program(void *program_addr) 99 { 100 as_t *as; 101 as_area_t *a; 102 int rc; 103 thread_t *t; 104 task_t *task; 105 106 as = as_create(0); 107 108 rc = elf_load((elf_header_t *) config.init_addr, as); 109 if (rc != EE_OK) { 110 as_free(as); 111 return NULL; 112 } 113 114 task = task_create(as); 115 t = thread_create(uinit, (void *)((elf_header_t *) config.init_addr)->e_entry, 116 task, THREAD_USER_STACK); 117 118 /* 119 * Create the data as_area. 120 */ 121 a = as_area_create(as, AS_AREA_STACK, 1, USTACK_ADDRESS); 122 123 thread_ready(t); 124 125 return task; 126 }
Note:
See TracChangeset
for help on using the changeset viewer.