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; |
} |