Rev 3204 | Rev 4343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3204 | Rev 3569 | ||
---|---|---|---|
Line 64... | Line 64... | ||
64 | 64 | ||
65 | /** Create a program using an existing address space. |
65 | /** Create a program using an existing address space. |
66 | * |
66 | * |
67 | * @param as Address space containing a binary program image. |
67 | * @param as Address space containing a binary program image. |
68 | * @param entry_addr Program entry-point address in program address space. |
68 | * @param entry_addr Program entry-point address in program address space. |
- | 69 | * @param name Name to set for the program's task. |
|
69 | * @param p Buffer for storing program information. |
70 | * @param p Buffer for storing program information. |
70 | */ |
71 | */ |
71 | void program_create(as_t *as, uintptr_t entry_addr, program_t *p) |
72 | void program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *p) |
72 | { |
73 | { |
73 | as_area_t *a; |
74 | as_area_t *a; |
74 | uspace_arg_t *kernel_uarg; |
75 | uspace_arg_t *kernel_uarg; |
75 | 76 | ||
76 | kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
77 | kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0); |
Line 78... | Line 79... | ||
78 | kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS; |
79 | kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS; |
79 | kernel_uarg->uspace_thread_function = NULL; |
80 | kernel_uarg->uspace_thread_function = NULL; |
80 | kernel_uarg->uspace_thread_arg = NULL; |
81 | kernel_uarg->uspace_thread_arg = NULL; |
81 | kernel_uarg->uspace_uarg = NULL; |
82 | kernel_uarg->uspace_uarg = NULL; |
82 | 83 | ||
83 | p->task = task_create(as, "app"); |
84 | p->task = task_create(as, name); |
84 | ASSERT(p->task); |
85 | ASSERT(p->task); |
85 | 86 | ||
86 | /* |
87 | /* |
87 | * Create the data as_area. |
88 | * Create the data as_area. |
88 | */ |
89 | */ |
Line 103... | Line 104... | ||
103 | * If the image belongs to a program loader, it is registered as such, |
104 | * If the image belongs to a program loader, it is registered as such, |
104 | * (and *task is set to NULL). Otherwise a task is created from the |
105 | * (and *task is set to NULL). Otherwise a task is created from the |
105 | * executable image. The task is returned in *task. |
106 | * executable image. The task is returned in *task. |
106 | * |
107 | * |
107 | * @param image_addr Address of an executable program image. |
108 | * @param image_addr Address of an executable program image. |
- | 109 | * @param name Name to set for the program's task. |
|
108 | * @param p Buffer for storing program info. If image_addr |
110 | * @param p Buffer for storing program info. If image_addr |
109 | * points to a loader image, p->task will be set to |
111 | * points to a loader image, p->task will be set to |
110 | * NULL and EOK will be returned. |
112 | * NULL and EOK will be returned. |
111 | * |
113 | * |
112 | * @return EOK on success or negative error code. |
114 | * @return EOK on success or negative error code. |
113 | */ |
115 | */ |
114 | int program_create_from_image(void *image_addr, program_t *p) |
116 | int program_create_from_image(void *image_addr, char *name, program_t *p) |
115 | { |
117 | { |
116 | as_t *as; |
118 | as_t *as; |
117 | unsigned int rc; |
119 | unsigned int rc; |
118 | 120 | ||
119 | as = as_create(0); |
121 | as = as_create(0); |
Line 131... | Line 133... | ||
131 | ASSERT(program_loader == NULL); |
133 | ASSERT(program_loader == NULL); |
132 | program_loader = image_addr; |
134 | program_loader = image_addr; |
133 | return EOK; |
135 | return EOK; |
134 | } |
136 | } |
135 | 137 | ||
136 | program_create(as, ((elf_header_t *) image_addr)->e_entry, p); |
138 | program_create(as, ((elf_header_t *) image_addr)->e_entry, name, p); |
137 | 139 | ||
138 | return EOK; |
140 | return EOK; |
139 | } |
141 | } |
140 | 142 | ||
141 | /** Create a task from the program loader image. |
143 | /** Create a task from the program loader image. |
142 | * |
144 | * |
143 | * @param p Buffer for storing program info. |
145 | * @param p Buffer for storing program info. |
- | 146 | * @param name Name to set for the program's task. |
|
- | 147 | * |
|
144 | * @return EOK on success or negative error code. |
148 | * @return EOK on success or negative error code. |
145 | */ |
149 | */ |
146 | int program_create_loader(program_t *p) |
150 | int program_create_loader(program_t *p, char *name) |
147 | { |
151 | { |
148 | as_t *as; |
152 | as_t *as; |
149 | unsigned int rc; |
153 | unsigned int rc; |
150 | void *loader; |
154 | void *loader; |
151 | 155 | ||
Line 159... | Line 163... | ||
159 | if (rc != EE_OK) { |
163 | if (rc != EE_OK) { |
160 | as_destroy(as); |
164 | as_destroy(as); |
161 | return ENOENT; |
165 | return ENOENT; |
162 | } |
166 | } |
163 | 167 | ||
164 | program_create(as, ((elf_header_t *) program_loader)->e_entry, p); |
168 | program_create(as, ((elf_header_t *) program_loader)->e_entry, |
- | 169 | name, p); |
|
165 | 170 | ||
166 | return EOK; |
171 | return EOK; |
167 | } |
172 | } |
168 | 173 | ||
169 | /** Make program ready. |
174 | /** Make program ready. |
Line 180... | Line 185... | ||
180 | /** Syscall for creating a new loader instance from userspace. |
185 | /** Syscall for creating a new loader instance from userspace. |
181 | * |
186 | * |
182 | * Creates a new task from the program loader image, connects a phone |
187 | * Creates a new task from the program loader image, connects a phone |
183 | * to it and stores the phone id into the provided buffer. |
188 | * to it and stores the phone id into the provided buffer. |
184 | * |
189 | * |
185 | * @param uspace_phone_id Userspace address where to store the phone id. |
190 | * @param uspace_phone_id Userspace address where to store the phone id. |
- | 191 | * @param name Name to set on the new task (typically the same |
|
- | 192 | * as the command used to execute it). |
|
186 | * |
193 | * |
187 | * @return 0 on success or an error code from @ref errno.h. |
194 | * @return 0 on success or an error code from @ref errno.h. |
188 | */ |
195 | */ |
189 | unative_t sys_program_spawn_loader(int *uspace_phone_id) |
196 | unative_t sys_program_spawn_loader(int *uspace_phone_id, char *uspace_name, |
- | 197 | size_t name_len) |
|
190 | { |
198 | { |
191 | program_t p; |
199 | program_t p; |
192 | int fake_id; |
200 | int fake_id; |
193 | int rc; |
201 | int rc; |
194 | int phone_id; |
202 | int phone_id; |
- | 203 | char namebuf[TASK_NAME_BUFLEN]; |
|
195 | 204 | ||
196 | fake_id = 0; |
205 | fake_id = 0; |
197 | 206 | ||
198 | /* Before we even try creating the task, see if we can write the id */ |
207 | /* Before we even try creating the task, see if we can write the id */ |
199 | rc = (unative_t) copy_to_uspace(uspace_phone_id, &fake_id, |
208 | rc = (unative_t) copy_to_uspace(uspace_phone_id, &fake_id, |
200 | sizeof(fake_id)); |
209 | sizeof(fake_id)); |
201 | if (rc != 0) |
210 | if (rc != 0) |
202 | return rc; |
211 | return rc; |
203 | 212 | ||
- | 213 | /* Cap length of name and copy it from userspace. */ |
|
- | 214 | ||
- | 215 | if (name_len > THREAD_NAME_BUFLEN - 1) |
|
- | 216 | name_len = THREAD_NAME_BUFLEN - 1; |
|
- | 217 | ||
- | 218 | rc = copy_from_uspace(namebuf, uspace_name, name_len); |
|
- | 219 | if (rc != 0) |
|
- | 220 | return (unative_t) rc; |
|
- | 221 | ||
- | 222 | namebuf[name_len] = '\0'; |
|
- | 223 | ||
- | 224 | /* Allocate the phone for communicating with the new task. */ |
|
- | 225 | ||
204 | phone_id = phone_alloc(); |
226 | phone_id = phone_alloc(); |
205 | if (phone_id < 0) |
227 | if (phone_id < 0) |
206 | return ELIMIT; |
228 | return ELIMIT; |
207 | 229 | ||
- | 230 | /* Spawn the new task. */ |
|
- | 231 | ||
208 | rc = program_create_loader(&p); |
232 | rc = program_create_loader(&p, namebuf); |
209 | if (rc != 0) |
233 | if (rc != 0) |
210 | return rc; |
234 | return rc; |
211 | 235 | ||
212 | phone_connect(phone_id, &p.task->answerbox); |
236 | phone_connect(phone_id, &p.task->answerbox); |
213 | 237 |