/branches/dynload/uspace/app/iloader/main.c |
---|
49,7 → 49,9 |
#include <fcntl.h> |
#include <sys/types.h> |
#include <ipc/ipc.h> |
#include <ipc/loader.h> |
#include <errno.h> |
#include <async.h> |
#include <as.h> |
#include <elf.h> |
70,32 → 72,32 |
* @param rid |
* @param request |
*/ |
void iloader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
static void iloader_set_pathname(ipc_callid_t rid, ipc_call_t *request) |
{ |
// ipc_callid_t callid; |
ipc_callid_t callid; |
size_t len; |
char *name_buf; |
/* printf("iloader_set_pathname\n"); |
printf("iloader_set_pathname\n"); |
if (!ipc_data_write_receive(&callid, &len)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
return; |
} |
*/ |
len = IPC_GET_ARG2(*request); |
printf("alloc %d bytes\n", len+1); |
name_buf = malloc(len + 1); |
if (!name_buf) { |
// ipc_answer_0(callid, ENOMEM); |
ipc_answer_0(callid, ENOMEM); |
ipc_answer_0(rid, ENOMEM); |
return; |
} |
printf("write_finalize\n"); |
ipc_data_write_finalize(rid, name_buf, len); |
// ipc_answer_0(rid, EOK); |
ipc_data_write_finalize(callid, name_buf, len); |
printf("answer\n"); |
ipc_answer_0(rid, EOK); |
if (pathname != NULL) { |
free(pathname); |
102,6 → 104,7 |
pathname = NULL; |
} |
name_buf[len] = '\0'; |
pathname = name_buf; |
} |
111,7 → 114,7 |
* @param request |
* @return 0 on success, !0 on error. |
*/ |
int iloader_run(ipc_callid_t rid, ipc_call_t *request) |
static int iloader_run(ipc_callid_t rid, ipc_call_t *request) |
{ |
int rc; |
pcb_t *pcb; |
157,24 → 160,29 |
return 0; |
} |
/** Program loader main function. |
/** Handle loader connection. |
* |
* Receive and carry out commands (of which the last one should be |
* to execute the loaded program). |
*/ |
int main(int argc, char *argv[]) |
static void loader_connection(ipc_callid_t iid, ipc_call_t *icall) |
{ |
ipc_callid_t callid; |
ipc_call_t call; |
int retval; |
int len; |
/* Ignore parameters, the connection is already open */ |
(void)iid; (void)icall; |
while (1) { |
callid = ipc_wait_for_call(&call); |
printf("received call, method=%d\n", IPC_GET_METHOD(call)); |
callid = async_get_call(&call); |
printf("received call from phone %d, method=%d\n", |
call.in_phone_hash, IPC_GET_METHOD(call)); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_DATA_WRITE: |
case LOADER_SET_PATHNAME: |
iloader_set_pathname(callid, &call); |
continue; |
case LOADER_RUN: |
iloader_run(callid, &call); |
exit(0); |
continue; |
187,7 → 195,35 |
ipc_answer_0(callid, EINVAL); |
} |
} |
} |
/** Program loader main function. |
*/ |
int main(int argc, char *argv[]) |
{ |
ipc_callid_t callid; |
ipc_call_t call; |
ipcarg_t phone_hash; |
/* The first call only communicates the incoming phone hash */ |
callid = ipc_wait_for_call(&call); |
if (IPC_GET_METHOD(call) != LOADER_HELLO) { |
if (IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) |
ipc_answer_0(callid, EINVAL); |
return 1; |
} |
ipc_answer_0(callid, EOK); |
phone_hash = call.in_phone_hash; |
/* |
* FIXME: up until now no async calls can be used!!! |
* (Which means e.g. printf() cannot be used) |
*/ |
async_new_connection(phone_hash, 0, NULL, loader_connection); |
async_manager(); |
/* not reached */ |
return 0; |
} |
/branches/dynload/uspace/lib/libc/include/ipc/loader.h |
---|
0,0 → 1,49 |
/* |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup libcipc |
* @{ |
*/ |
/** @file |
*/ |
#ifndef LIBC_LOADER_H_ |
#define LIBC_LOADER_H_ |
#include <ipc/ipc.h> |
typedef enum { |
LOADER_HELLO = IPC_FIRST_USER_METHOD, |
LOADER_SET_PATHNAME, |
LOADER_RUN |
} fb_request_t; |
#endif |
/** @} |
*/ |
/branches/dynload/uspace/lib/libc/generic/task.c |
---|
1,5 → 1,6 |
/* |
* Copyright (c) 2006 Jakub Jermar |
* Copyright (c) 2008 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
34,7 → 35,9 |
#include <task.h> |
#include <ipc/ipc.h> |
#include <ipc/loader.h> |
#include <libc.h> |
#include <string.h> |
#include <async.h> |
#include <errno.h> |
57,8 → 60,13 |
return phone_id; |
} |
#include <stdio.h> |
#include <unistd.h> |
/** Create a new task by running an executable from VFS. |
* |
* @param path pathname of the binary to execute |
* @param argv command-line arguments |
* @return ID of the newly created task or zero on error. |
*/ |
task_id_t task_spawn(const char *path, const char *argv[]) |
{ |
int phone_id; |
65,30 → 73,35 |
ipc_call_t answer; |
aid_t req; |
int rc; |
/* Spawn a program loader */ |
phone_id = task_spawn_loader(); |
if (phone_id < 0) return 0; |
printf("phone_id:%d\n", phone_id); |
// getchar(); |
/* |
* Say hello so that the loader knows the incoming connection's |
* phone hash. |
*/ |
rc = async_req_0_0(phone_id, LOADER_HELLO); |
if (rc != EOK) return 0; |
// req = async_send_0(phone_id, 1024, &answer); |
/* Send program pathname */ |
req = async_send_0(phone_id, LOADER_SET_PATHNAME, &answer); |
rc = ipc_data_write_start(phone_id, (void *)path, strlen(path)); |
printf("->%d\n", rc); |
if (rc != EOK) { |
// async_wait_for(req, NULL); |
async_wait_for(req, NULL); |
return 1; |
} |
// async_wait_for(req, &rc); |
async_wait_for(req, &rc); |
if (rc != EOK) return 0; |
// rc = async_req_0_0(phone_id, 1025); |
// printf("->%d\n", rc); |
// if (rc != EOK) return 0; |
// ipc_hangup(phone_id); |
/* Request loader to start the program */ |
rc = async_req_0_0(phone_id, LOADER_RUN); |
if (rc != EOK) return 0; |
ipc_hangup(phone_id); |
return 1; |
} |