/kernel/trunk/generic/include/ipc/ipc.h |
---|
99,6 → 99,9 |
* - sys_connect_me_to - send a synchronous message to name server |
* indicating that it wants to be connected to some |
* service |
* - arg1/2 are user specified, arg3 contains |
* address of the phone that should be connected |
* (TODO: it leaks to userspace) |
* recepient - if ipc_answer == 0, then accept connection |
* - otherwise connection refused |
* - recepient may forward message. Forwarding |
170,6 → 173,7 |
extern void ipc_answerbox_init(answerbox_t *box); |
extern void ipc_call_init(call_t *call); |
extern void ipc_forward(call_t *call, answerbox_t *newbox,answerbox_t *oldbox); |
extern void task_print_list(void); |
extern answerbox_t *ipc_phone_0; |
/kernel/trunk/generic/src/console/cmd.c |
---|
53,6 → 53,7 |
#include <mm/slab.h> |
#include <proc/scheduler.h> |
#include <proc/thread.h> |
#include <proc/task.h> |
/** Data and methods for 'help' command. */ |
static int cmd_help(cmd_arg_t *argv); |
253,7 → 254,15 |
.argc = 0 |
}; |
static int cmd_tasks(cmd_arg_t *argv); |
static cmd_info_t tasks_info = { |
.name = "tasks", |
.description = "List all tasks", |
.func = cmd_tasks, |
.argc = 0 |
}; |
static int cmd_sched(cmd_arg_t *argv); |
static cmd_info_t sched_info = { |
.name = "scheduler", |
338,6 → 347,7 |
&symaddr_info, |
&sched_info, |
&threads_info, |
&tasks_info, |
&tlb_info, |
&version_info, |
&zones_info, |
628,6 → 638,17 |
return 1; |
} |
/** Command for listings Task information |
* |
* @param argv Ignores |
* |
* @return Always 1 |
*/ |
int cmd_tasks(cmd_arg_t * argv) { |
task_print_list(); |
return 1; |
} |
/** Command for listings Thread information |
* |
* @param argv Ignores |
/kernel/trunk/generic/src/proc/task.c |
---|
38,6 → 38,7 |
#include <adt/list.h> |
#include <ipc/ipc.h> |
#include <memstr.h> |
#include <print.h> |
#include <elf.h> |
131,3 → 132,33 |
return task; |
} |
/** Print task list */ |
void task_print_list(void) |
{ |
link_t *cur; |
task_t *t; |
ipl_t ipl; |
int i; |
/* Messing with thread structures, avoid deadlock */ |
ipl = interrupts_disable(); |
spinlock_lock(&tasks_lock); |
for (cur=tasks_head.next; cur!=&tasks_head; cur=cur->next) { |
t = list_get_instance(cur, task_t, tasks_link); |
spinlock_lock(&t->lock); |
printf("Task: %Q ActiveCalls: %d", t->taskid, |
atomic_get(&t->active_calls)); |
for (i=0; i < IPC_MAX_PHONES; i++) { |
if (t->phones[i].callee) |
printf(" Ph(%d): %P ", i,t->phones[i].callee); |
} |
printf("\n"); |
spinlock_unlock(&t->lock); |
} |
spinlock_unlock(&tasks_lock); |
interrupts_restore(ipl); |
} |
/kernel/trunk/generic/src/proc/thread.c |
---|
412,10 → 412,9 |
printf("Thr: %d(%s) ", t->tid, thread_states[t->state]); |
if (t->cpu) |
printf("cpu%d ", t->cpu->id); |
printf("\n"); |
} |
spinlock_unlock(&threads_lock); |
interrupts_enable(); |
interrupts_restore(ipl); |
} |
/kernel/trunk/generic/src/ipc/sysipc.c |
---|
35,7 → 35,11 |
#include <debug.h> |
#include <ipc/ipc.h> |
#include <ipc/sysipc.h> |
#include <print.h> |
#include <arch.h> |
#include <proc/thread.h> |
/* TODO: multi-threaded connect-to-me can cause race condition |
* on phone, add counter + thread_kill?? |
138,6 → 142,8 |
{ |
if (IPC_GET_METHOD(call->data) == IPC_M_CONNECTTOME) |
return 1; |
if (IPC_GET_METHOD(call->data) == IPC_M_CONNECTMETO) |
return 1; |
return 0; |
} |
155,6 → 161,13 |
/* The connection was accepted */ |
phone_connect(phoneid,&answer->sender->answerbox); |
} |
} else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECTMETO) { |
/* If the users accepted call, connect */ |
if (!IPC_GET_RETVAL(answer->data)) { |
printf("Connecting Phone %P\n",IPC_GET_ARG3(*olddata)); |
ipc_phone_connect((phone_t *)IPC_GET_ARG3(*olddata), |
&TASK->answerbox); |
} |
} |
} |
318,6 → 331,9 |
/** Forward received call to another destination |
* |
* The arg1 and arg2 are changed in the forwarded message |
* |
* Warning: If implementing non-fast version, make sure that |
* arg3 is not rewritten for certain system IPC |
*/ |
__native sys_ipc_forward_fast(__native callid, __native phoneid, |
__native method, __native arg1) |
436,6 → 452,7 |
copy_to_uspace(taskid, |
&phone->callee->task->taskid, |
sizeof(TASK->taskid)); |
return IPC_GET_RETVAL(call.data); |
} |
448,22 → 465,30 |
{ |
call_t call; |
phone_t *phone; |
int newphid; |
phone = get_phone(phoneid); |
if (!phone) |
return ENOENT; |
newphid = phone_alloc(); |
if (newphid < 0) |
return ELIMIT; |
ipc_call_init(&call); |
IPC_SET_METHOD(call.data, IPC_M_CONNECTMETO); |
IPC_SET_ARG1(call.data, arg1); |
IPC_SET_ARG2(call.data, arg2); |
IPC_SET_ARG3(call.data, (__native)&TASK->phones[newphid]); |
ipc_call_sync(phone, &call); |
if (!IPC_GET_RETVAL(call.data)) { |
/* Everybody accepted, we should be connected by now */ |
if (IPC_GET_RETVAL(call.data)) { /* Connection failed */ |
phone_dealloc(newphid); |
return IPC_GET_RETVAL(call.data); |
} |
return 0; |
return newphid; |
} |
/** Wait for incoming ipc call or answer |
485,7 → 510,6 |
restart: |
call = ipc_wait_for_call(&TASK->answerbox, flags); |
printf("Received call %P from sender: %P\n", call, call->sender); |
if (call->flags & IPC_CALL_ANSWERED) { |
if (process_answer(&TASK->answerbox, call)) |