Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 997 → Rev 998

/kernel/trunk/generic/include/proc/task.h
40,8 → 40,10
link_t th_head; /**< List of threads contained in this task. */
link_t tasks_link; /**< Link to other tasks within the system. */
as_t *as; /**< Address space. */
/* IPC stuff */
answerbox_t answerbox; /**< Communication endpoint */
phone_t phones[IPC_MAX_PHONES];
atomic_t active_calls; /**< Active asynchronous messages */
};
 
extern spinlock_t tasks_lock;
/kernel/trunk/generic/include/syscall/syscall.h
33,8 → 33,9
SYS_CTL = 0,
SYS_IO,
SYS_MREMAP,
SYS_IPC_CALL_SYNC_FAST,
SYS_IPC_CALL_SYNC,
SYS_IPC_CALL_SYNC_MEDIUM,
SYS_IPC_CALL_ASYNC_FAST,
SYS_IPC_CALL_ASYNC,
SYS_IPC_ANSWER,
SYS_IPC_WAIT,
/kernel/trunk/generic/include/ipc/ipc.h
33,6 → 33,9
/* - the uspace may not be able to utilize full length */
#define IPC_CALL_LEN 4
 
/** Maximum active async calls per thread */
#define IPC_MAX_ASYNC_CALLS 4
 
/* Flags for calls */
#define IPC_CALL_ANSWERED 1 /**< This is answer to a call */
#define IPC_CALL_STATIC_ALLOC 2 /**< This call will not be freed on error */
/kernel/trunk/generic/src/proc/task.c
81,6 → 81,7
memsetb((__address)&ta->phones, sizeof(ta->phones[0])*IPC_MAX_PHONES, 0);
if (ipc_phone_0)
ipc_phone_init(&ta->phones[0], ipc_phone_0);
atomic_set(&ta->active_calls, 0);
ipl = interrupts_disable();
spinlock_lock(&tasks_lock);
/kernel/trunk/generic/src/syscall/syscall.c
56,25 → 56,35
return count;
}
 
static phone_t * get_phone(__native phoneid)
{
phone_t *phone;
 
if (phoneid >= IPC_MAX_PHONES)
return NULL;
 
phone = &TASK->phones[phoneid];
if (!phone->callee)
return NULL;
return phone;
}
 
/** Send a call over IPC, wait for reply, return to user
*
* @return Call identification, returns -1 on fatal error,
-2 on 'Too many async request, handle answers first
*/
static __native sys_ipc_call_sync(__native phoneid, __native method,
__native arg1, __native *data)
static __native sys_ipc_call_sync_fast(__native phoneid, __native method,
__native arg1, __native *data)
{
call_t call;
phone_t *phone;
/* Special answerbox for synchronous messages */
 
if (phoneid >= IPC_MAX_PHONES)
phone = get_phone(phoneid);
if (!phone)
return IPC_CALLRET_FATAL;
 
phone = &TASK->phones[phoneid];
if (!phone->callee)
return IPC_CALLRET_FATAL;
 
ipc_call_init(&call);
IPC_SET_METHOD(call.data, method);
IPC_SET_ARG1(call.data, arg1);
86,19 → 96,17
return 0;
}
 
static __native sys_ipc_call_sync_medium(__native phoneid, __native *data)
/** Synchronous IPC call allowing to send whole message */
static __native sys_ipc_call_sync(__native phoneid, __native *data)
{
call_t call;
phone_t *phone;
/* Special answerbox for synchronous messages */
 
if (phoneid >= IPC_MAX_PHONES)
phone = get_phone(phoneid);
if (!phone)
return IPC_CALLRET_FATAL;
 
phone = &TASK->phones[phoneid];
if (!phone->callee)
return IPC_CALLRET_FATAL;
 
ipc_call_init(&call);
copy_from_uspace(&call.data, data, sizeof(call.data));
109,6 → 117,18
return 0;
}
 
/** Check that the task did not exceed allowed limit
*
* @return 0 - Limit OK, -1 - limit exceeded
*/
static int check_call_limit(void)
{
if (atomic_inc_post(&TASK->active_calls) > IPC_MAX_ASYNC_CALLS) {
atomic_dec(&TASK->active_calls);
return -1;
}
return 0;
}
 
/** Send an asynchronous call over ipc
*
115,23 → 135,19
* @return Call identification, returns -1 on fatal error,
-2 on 'Too many async request, handle answers first
*/
static __native sys_ipc_call_async(__native phoneid, __native method,
__native arg1, __native arg2)
static __native sys_ipc_call_async_fast(__native phoneid, __native method,
__native arg1, __native arg2)
{
call_t *call;
phone_t *phone;
 
if (phoneid >= IPC_MAX_PHONES)
phone = get_phone(phoneid);
if (!phone)
return IPC_CALLRET_FATAL;
 
phone = &TASK->phones[phoneid];
if (!phone->callee)
return IPC_CALLRET_FATAL;
if (check_call_limit())
return IPC_CALLRET_TEMPORARY;
 
/* TODO: Check that we did not exceed system imposed maximum
* of asynchrnously sent messages
* - the userspace should be able to handle it correctly
*/
call = ipc_call_alloc();
IPC_SET_METHOD(call->data, method);
IPC_SET_ARG1(call->data, arg1);
142,6 → 158,31
return (__native) call;
}
 
/** Synchronous IPC call allowing to send whole message
*
* @return The same as sys_ipc_call_async
*/
static __native sys_ipc_call_async(__native phoneid, __native *data)
{
call_t *call;
phone_t *phone;
 
phone = get_phone(phoneid);
if (!phone)
return IPC_CALLRET_FATAL;
 
if (check_call_limit())
return IPC_CALLRET_TEMPORARY;
 
call = ipc_call_alloc();
copy_from_uspace(&call->data, data, sizeof(call->data));
ipc_call(phone, call);
 
return (__native) call;
}
 
 
/** Send IPC answer */
static __native sys_ipc_answer(__native callid, __native retval, __native arg1,
__native arg2)
174,9 → 215,11
call = ipc_wait_for_call(&TASK->answerbox, flags);
 
copy_to_uspace(calldata, &call->data, sizeof(call->data));
 
if (call->flags & IPC_CALL_ANSWERED) {
ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
ipc_call_free(call);
atomic_dec(&TASK->active_calls);
return ((__native)call) | IPC_CALLID_ANSWERED;
}
return (__native)call;
191,8 → 234,9
sys_ctl,
sys_io,
sys_mremap,
sys_ipc_call_sync_fast,
sys_ipc_call_sync,
sys_ipc_call_sync_medium,
sys_ipc_call_async_fast,
sys_ipc_call_async,
sys_ipc_answer,
sys_ipc_wait_for_call
/kernel/trunk/generic/src/ipc/ns.c
45,8 → 45,11
call = ipc_wait_for_call(&ns_answerbox, 0);
switch (IPC_GET_METHOD(call->data)) {
case NS_PING:
printf("Ping.\n");
printf("Ping - %X, %X\n", IPC_GET_ARG1(call->data),
IPC_GET_ARG2(call->data));
IPC_SET_RETVAL(call->data, 0);
IPC_SET_ARG1(call->data, 0xdeaddead);
IPC_SET_ARG2(call->data, 0xdeaddea2);
break;
default:
printf("Unsupported name service call.\n");