Subversion Repositories HelenOS

Rev

Rev 3569 | Rev 4344 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3569 Rev 4343
Line 182... Line 182...
182
    thread_ready(p->main_thread);
182
    thread_ready(p->main_thread);
183
}
183
}
184
 
184
 
185
/** Syscall for creating a new loader instance from userspace.
185
/** Syscall for creating a new loader instance from userspace.
186
 *
186
 *
187
 * Creates a new task from the program loader image, connects a phone
187
 * Creates a new task from the program loader image and sets
188
 * to it and stores the phone id into the provided buffer.
188
 * the task name.
189
 *
189
 *
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
190
 * @param name          Name to set on the new task (typically the same
192
 *              as the command used to execute it).
191
 *              as the command used to execute it).
193
 *
192
 *
194
 * @return 0 on success or an error code from @ref errno.h.
193
 * @return 0 on success or an error code from @ref errno.h.
195
 */
194
 */
196
unative_t sys_program_spawn_loader(int *uspace_phone_id, char *uspace_name,
195
unative_t sys_program_spawn_loader(char *uspace_name, size_t name_len)
197
    size_t name_len)
-
 
198
{
196
{
199
    program_t p;
197
    program_t p;
200
    int fake_id;
-
 
201
    int rc;
198
    int rc;
202
    int phone_id;
-
 
203
    char namebuf[TASK_NAME_BUFLEN];
199
    char namebuf[TASK_NAME_BUFLEN];
204
 
200
 
205
    fake_id = 0;
-
 
206
 
-
 
207
    /* Before we even try creating the task, see if we can write the id */
-
 
208
    rc = (unative_t) copy_to_uspace(uspace_phone_id, &fake_id,
-
 
209
        sizeof(fake_id));
-
 
210
    if (rc != 0)
-
 
211
        return rc;
-
 
212
 
-
 
213
    /* Cap length of name and copy it from userspace. */
201
    /* Cap length of name and copy it from userspace. */
214
 
202
 
215
    if (name_len > THREAD_NAME_BUFLEN - 1)
203
    if (name_len > THREAD_NAME_BUFLEN - 1)
216
        name_len = THREAD_NAME_BUFLEN - 1;
204
        name_len = THREAD_NAME_BUFLEN - 1;
217
 
205
 
Line 219... Line 207...
219
    if (rc != 0)
207
    if (rc != 0)
220
        return (unative_t) rc;
208
        return (unative_t) rc;
221
 
209
 
222
    namebuf[name_len] = '\0';
210
    namebuf[name_len] = '\0';
223
 
211
 
224
    /* Allocate the phone for communicating with the new task. */
-
 
225
 
-
 
226
    phone_id = phone_alloc();
-
 
227
    if (phone_id < 0)
-
 
228
        return ELIMIT;
-
 
229
 
-
 
230
    /* Spawn the new task. */
212
    /* Spawn the new task. */
231
 
213
 
232
    rc = program_create_loader(&p, namebuf);
214
    rc = program_create_loader(&p, namebuf);
233
    if (rc != 0)
215
    if (rc != 0)
234
        return rc;
216
        return rc;
235
 
217
 
236
    phone_connect(phone_id, &p.task->answerbox);
-
 
237
 
-
 
238
    /* No need to aquire lock before task_ready() */
-
 
239
    rc = (unative_t) copy_to_uspace(uspace_phone_id, &phone_id,
-
 
240
        sizeof(phone_id));
-
 
241
    if (rc != 0) {
-
 
242
        /* Ooops */
-
 
243
        ipc_phone_hangup(&TASK->phones[phone_id]);
-
 
244
        task_kill(p.task->taskid);
-
 
245
        return rc;
-
 
246
    }
-
 
247
 
-
 
248
    // FIXME: control the capabilities
218
    // FIXME: control the capabilities
249
    cap_set(p.task, cap_get(TASK));
219
    cap_set(p.task, cap_get(TASK));
250
 
220
 
251
    program_ready(&p);
221
    program_ready(&p);
252
 
222