Changeset fbcfd458 in mainline for generic/src/ipc/sysipc.c


Ignore:
Timestamp:
2006-03-18T23:02:08Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b4b45210
Parents:
ba81cab
Message:

Untested better IPC functions.

  • There is some bug in MIPS, unpredicatbly sometimes the thread gets mapped

different frame for stack.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/ipc/sysipc.c

    rba81cab rfbcfd458  
    4343#include <proc/thread.h>
    4444
    45 /* TODO: multi-threaded connect-to-me can cause race condition
    46  * on phone, add counter + thread_kill??
    47  *
    48  */
    49 
    5045#define GET_CHECK_PHONE(phone,phoneid,err) { \
    5146      if (phoneid > IPC_MAX_PHONES) { err; } \
     
    5348}
    5449
     50#define STRUCT_TO_USPACE(dst,src) copy_to_uspace(dst,src,sizeof(*src))
    5551
    5652/** Return true if the method is a system method */
     
    6965static inline int is_forwardable(__native method)
    7066{
     67        if (method == IPC_M_PHONE_HUNGUP)
     68                return 0; /* This message is meant only for the receiver */
    7169        return 1;
    7270}
     
    8280static inline int answer_will_preprocess(call_t *call)
    8381{
    84         if (IPC_GET_METHOD(call->data) == IPC_M_CONNECTTOME)
     82        if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME)
    8583                return 1;
    86         if (IPC_GET_METHOD(call->data) == IPC_M_CONNECTMETO)
     84        if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO)
    8785                return 1;
    8886        return 0;
     
    9492        int phoneid;
    9593
    96         if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECTTOME) {
     94        if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_TO_ME) {
    9795                phoneid = IPC_GET_ARG3(*olddata);
    9896                if (IPC_GET_RETVAL(answer->data)) {
     
    103101                        phone_connect(phoneid,&answer->sender->answerbox);
    104102                }
    105         } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECTMETO) {
     103        } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) {
    106104                /* If the users accepted call, connect */
    107105                if (!IPC_GET_RETVAL(answer->data)) {
     
    131129        int phoneid;
    132130
    133         if (IPC_GET_METHOD(call->data) == IPC_M_CONNECTTOME) {
     131        if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) {
    134132                phoneid = phone_alloc();
    135133                if (phoneid < 0) { /* Failed to allocate phone */
     
    149147 */
    150148__native sys_ipc_call_sync_fast(__native phoneid, __native method,
    151                                 __native arg1, __native *data)
     149                                __native arg1, ipc_data_t *data)
    152150{
    153151        call_t call;
     
    165163        ipc_call_sync(phone, &call);
    166164
    167         copy_to_uspace(data, &call.data, sizeof(call.data));
     165        STRUCT_TO_USPACE(&data->args, &call.data.args);
    168166
    169167        return 0;
     
    171169
    172170/** Synchronous IPC call allowing to send whole message */
    173 __native sys_ipc_call_sync(__native phoneid, __native *question,
    174                            __native *reply)
     171__native sys_ipc_call_sync(__native phoneid, ipc_data_t *question,
     172                           ipc_data_t *reply)
    175173{
    176174        call_t call;
     
    178176
    179177        ipc_call_static_init(&call);
    180         copy_from_uspace(&call.data, question, sizeof(call.data));
     178        copy_from_uspace(&call.data.args, &question->args, sizeof(call.data.args));
    181179
    182180        if (is_system_method(IPC_GET_METHOD(call.data)))
     
    187185        ipc_call_sync(phone, &call);
    188186
    189         copy_to_uspace(reply, &call.data, sizeof(call.data));
     187        STRUCT_TO_USPACE(&reply->args, &call.data.args);
    190188
    191189        return 0;
     
    238236 * @return The same as sys_ipc_call_async
    239237 */
    240 __native sys_ipc_call_async(__native phoneid, __native *data)
     238__native sys_ipc_call_async(__native phoneid, ipc_data_t *data)
    241239{
    242240        call_t *call;
     
    249247
    250248        call = ipc_call_alloc();
    251         copy_from_uspace(&call->data, data, sizeof(call->data));
     249        copy_from_uspace(&call->data.args, &data->args, sizeof(call->data.args));
    252250
    253251        if (is_system_method(IPC_GET_METHOD(call->data))) {
     
    335333
    336334/** Send IPC answer */
    337 inline __native sys_ipc_answer(__native callid, __native *data)
     335__native sys_ipc_answer(__native callid, ipc_data_t *data)
    338336{
    339337        call_t *call;
     
    349347                preprocess = 1;
    350348        }
    351         copy_from_uspace(&call->data, data, sizeof(call->data));
     349        copy_from_uspace(&call->data.args, &data->args,
     350                         sizeof(call->data.args));
    352351
    353352        if (preprocess)
     
    370369
    371370        ipc_call_static_init(&call);
    372         IPC_SET_METHOD(call.data, IPC_M_CONNECTTOME);
     371        IPC_SET_METHOD(call.data, IPC_M_CONNECT_TO_ME);
    373372        IPC_SET_ARG1(call.data, arg1);
    374373        IPC_SET_ARG2(call.data, arg2);
     
    379378
    380379        if (!IPC_GET_RETVAL(call.data) && taskid)
    381                 copy_to_uspace(taskid,
    382                                &phone->callee->task->taskid,
    383                                sizeof(TASK->taskid));
     380                STRUCT_TO_USPACE(taskid, &phone->callee->task->taskid);
    384381
    385382        return IPC_GET_RETVAL(call.data);
     
    404401
    405402        ipc_call_static_init(&call);
    406         IPC_SET_METHOD(call.data, IPC_M_CONNECTMETO);
     403        IPC_SET_METHOD(call.data, IPC_M_CONNECT_ME_TO);
    407404        IPC_SET_ARG1(call.data, arg1);
    408405        IPC_SET_ARG2(call.data, arg2);
     
    419416}
    420417
     418/** Hang up the phone
     419 *
     420 *
     421 *
     422 */
     423__native sys_ipc_hangup(int phoneid)
     424{
     425        phone_t *phone;
     426
     427        GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     428
     429        if (ipc_phone_hangup(phone))
     430                return -1;
     431
     432        return 0;
     433}
     434
    421435/** Wait for incoming ipc call or answer
    422436 *
    423  * Generic function - can serve either as inkernel or userspace call
    424  * - inside kernel does probably unnecessary copying of data (TODO)
    425  *
    426  * @param result
    427  * @param taskid
     437 * @param calldata Pointer to buffer where the call/answer data is stored
     438 * @param taskid On 'CONNECT_ME_TO' call it is filled with 'taskid' of
     439 *               the caller.
    428440 * @param flags
    429441 * @return Callid, if callid & 1, then the call is answer
    430442 */
    431 inline __native sys_ipc_wait_for_call(ipc_data_t *calldata,
    432                                       task_id_t *taskid,
    433                                       __native flags)
     443__native sys_ipc_wait_for_call(ipc_data_t *calldata, task_id_t *taskid,
     444                               __native flags)
    434445                                             
    435446{
     
    443454                        goto restart;
    444455
    445                 copy_to_uspace(calldata, &call->data, sizeof(call->data));
     456                ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
     457
    446458                atomic_dec(&TASK->active_calls);
    447                 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
     459
     460                if (call->flags & IPC_CALL_DISCARD_ANSWER) {
     461                        ipc_call_free(call);
     462                        goto restart;
     463                }
     464
     465                STRUCT_TO_USPACE(&calldata->args, &call->data.args);
    448466                ipc_call_free(call);
    449467
    450468                return ((__native)call) | IPC_CALLID_ANSWERED;
    451469        }
     470
    452471        if (process_request(&TASK->answerbox, call))
    453472                goto restart;
    454         copy_to_uspace(calldata, &call->data, sizeof(call->data));
    455         copy_to_uspace(taskid, (void *)&TASK->taskid, sizeof(TASK->taskid));
     473
     474        /* Include phone address('id') of the caller in the request */
     475        STRUCT_TO_USPACE(calldata, &call->data);
     476        if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO)
     477                STRUCT_TO_USPACE(taskid, &TASK->taskid);
    456478        return (__native)call;
    457479}
    458 
Note: See TracChangeset for help on using the changeset viewer.