Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3173 → Rev 3174

/branches/dynload/uspace/lib/libc/generic/task.c
38,6 → 38,7
#include <ipc/loader.h>
#include <libc.h>
#include <string.h>
#include <stdlib.h>
#include <async.h>
#include <errno.h>
 
61,6 → 62,60
return phone_id;
}
 
static int loader_set_args(int phone_id, const char *argv[])
{
aid_t req;
ipc_call_t answer;
int rc;
 
const char **ap;
char *dp;
char *arg_buf;
size_t buffer_size;
size_t len;
 
/*
* Serialize the arguments into a single array. First
* compute size of the buffer needed.
*/
ap = argv;
buffer_size = 0;
while (*ap != NULL) {
buffer_size += strlen(*ap) + 1;
++ap;
}
 
arg_buf = malloc(buffer_size);
if (arg_buf == NULL) return ENOMEM;
 
/* Now fill the buffer with null-terminated argument strings */
ap = argv;
dp = arg_buf;
while (*ap != NULL) {
strcpy(dp, *ap);
dp += strlen(*ap) + 1;
 
++ap;
}
 
/* Send serialized arguments to the loader */
 
req = async_send_0(phone_id, LOADER_SET_ARGS, &answer);
rc = ipc_data_write_start(phone_id, (void *)arg_buf, buffer_size);
if (rc != EOK) {
async_wait_for(req, NULL);
return rc;
}
 
async_wait_for(req, &rc);
if (rc != EOK) return rc;
 
/* Free temporary buffer */
free(arg_buf);
 
return EOK;
}
 
/** Create a new task by running an executable from VFS.
*
* @param path pathname of the binary to execute
94,15 → 149,24
}
 
async_wait_for(req, &rc);
if (rc != EOK) return 0;
if (rc != EOK) goto error;
 
/* Send arguments */
rc = loader_set_args(phone_id, argv);
if (rc != EOK) goto error;
 
/* Request loader to start the program */
rc = async_req_0_0(phone_id, LOADER_RUN);
if (rc != EOK) return 0;
if (rc != EOK) goto error;
 
/* Success */
ipc_hangup(phone_id);
return 1;
 
return 1;
/* Error exit */
error:
ipc_hangup(phone_id);
return 0;
}
 
int task_spawn(void *image, size_t size)