Subversion Repositories HelenOS

Rev

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

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