Changeset 7c7aae16 in mainline for generic/src/ipc/sysipc.c


Ignore:
Timestamp:
2006-03-19T19:42:00Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ad64a2d
Parents:
9f22213
Message:

Reduced unnecessary IPC system calls.
Allow everything to be sync & async, everything is handled using messages.

File:
1 edited

Legend:

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

    r9f22213 r7c7aae16  
    4848}
    4949
    50 #define STRUCT_TO_USPACE(dst,src) copy_to_uspace(dst,src,sizeof(*src))
     50#define STRUCT_TO_USPACE(dst,src) copy_to_uspace(dst,src,sizeof(*(src)))
    5151
    5252/** Return true if the method is a system method */
     
    106106                        phone_dealloc(phoneid);
    107107                } else {
    108                                 /* The connection was accepted */
     108                        /* The connection was accepted */
    109109                        phone_connect(phoneid,&answer->sender->answerbox);
     110                        /* Set 'phone identification' as arg3 of response */
     111                        IPC_SET_ARG3(answer->data, (__native)&TASK->phones[phoneid]);
    110112                }
    111113        } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) {
     
    118120}
    119121
     122/** Called before the request is sent
     123 *
     124 * @return 0 - no error, -1 - report error to user
     125 */
     126static int request_preprocess(call_t *call)
     127{
     128        int newphid;
     129
     130        switch (IPC_GET_METHOD(call->data)) {
     131        case IPC_M_CONNECT_ME_TO:
     132                newphid = phone_alloc();
     133                if (newphid < 0)
     134                        return ELIMIT;
     135                /* Set arg3 for server */
     136                IPC_SET_ARG3(call->data, (__native)&TASK->phones[newphid]);
     137                call->flags |= IPC_CALL_CONN_ME_TO;
     138                call->private = newphid;
     139                break;
     140        default:
     141                break;
     142        }
     143        return 0;
     144}
     145
    120146/****************************************************/
    121147/* Functions called to process received call/answer
     
    124150
    125151/** Do basic kernel processing of received call answer */
    126 static int process_answer(answerbox_t *box,call_t *call)
     152static void process_answer(call_t *call)
    127153{
    128154        if (IPC_GET_RETVAL(call->data) == EHANGUP && \
    129155            call->flags & IPC_CALL_FORWARDED)
    130156                IPC_SET_RETVAL(call->data, EFORWARD);
    131         return 0;
     157
     158        if (call->flags & IPC_CALL_CONN_ME_TO) {
     159                if (IPC_GET_RETVAL(call->data))
     160                        phone_dealloc(call->private);
     161                else
     162                        IPC_SET_ARG3(call->data, call->private);
     163        }
    132164}
    133165
     
    162194        call_t call;
    163195        phone_t *phone;
    164 
    165         if (is_system_method(method))
    166                 return EPERM;
     196        int res;
    167197
    168198        GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     
    171201        IPC_SET_METHOD(call.data, method);
    172202        IPC_SET_ARG1(call.data, arg1);
    173        
    174         ipc_call_sync(phone, &call);
    175 
     203
     204        if (!(res=request_preprocess(&call))) {
     205                ipc_call_sync(phone, &call);
     206                process_answer(&call);
     207        } else
     208                IPC_SET_RETVAL(call.data, res);
    176209        STRUCT_TO_USPACE(&data->args, &call.data.args);
    177210
     
    185218        call_t call;
    186219        phone_t *phone;
     220        int res;
    187221
    188222        ipc_call_static_init(&call);
    189223        copy_from_uspace(&call.data.args, &question->args, sizeof(call.data.args));
    190224
    191         if (is_system_method(IPC_GET_METHOD(call.data)))
    192                 return EPERM;
    193        
    194225        GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    195226
    196         ipc_call_sync(phone, &call);
     227        if (!(res=request_preprocess(&call))) {
     228                ipc_call_sync(phone, &call);
     229                process_answer(&call);
     230        } else
     231                IPC_SET_RETVAL(call.data, res);
    197232
    198233        STRUCT_TO_USPACE(&reply->args, &call.data.args);
     
    224259        call_t *call;
    225260        phone_t *phone;
    226 
    227         if (is_system_method(method))
    228                 return IPC_CALLRET_FATAL;
     261        int res;
    229262
    230263        if (check_call_limit())
    231264                return IPC_CALLRET_TEMPORARY;
    232265
    233         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     266        GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL);
    234267
    235268        call = ipc_call_alloc();
     
    238271        IPC_SET_ARG2(call->data, arg2);
    239272
    240         ipc_call(phone, call);
     273        if (!(res=request_preprocess(call)))
     274                ipc_call(phone, call);
     275        else
     276                ipc_backsend_err(phone, call, res);
    241277
    242278        return (__native) call;
     
    251287        call_t *call;
    252288        phone_t *phone;
     289        int res;
    253290
    254291        if (check_call_limit())
    255292                return IPC_CALLRET_TEMPORARY;
    256293
    257         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
     294        GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL);
    258295
    259296        call = ipc_call_alloc();
    260297        copy_from_uspace(&call->data.args, &data->args, sizeof(call->data.args));
    261 
    262         if (is_system_method(IPC_GET_METHOD(call->data))) {
    263                 ipc_call_free(call);
    264                 return EPERM;
    265         }
    266        
    267         ipc_call(phone, call);
     298        if (!(res=request_preprocess(call)))
     299                ipc_call(phone, call);
     300        else
     301                ipc_backsend_err(phone, call, res);
    268302
    269303        return (__native) call;
     
    305339         */
    306340        if (is_system_method(IPC_GET_METHOD(call->data))) {
     341                if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME)
     342                        phone_dealloc(IPC_GET_ARG3(call->data));
     343
    307344                IPC_SET_ARG1(call->data, method);
    308345                IPC_SET_ARG2(call->data, arg1);
     
    366403}
    367404
    368 /** Ask the other side of connection to do 'callback' connection
    369  *
    370  * @return 0 if no error, error otherwise
    371  */
    372 __native sys_ipc_connect_to_me(__native phoneid, __native arg1,
    373                                __native arg2, task_id_t *taskid)
    374 {
    375         call_t call;
    376         phone_t *phone;
    377 
    378         ipc_call_static_init(&call);
    379         IPC_SET_METHOD(call.data, IPC_M_CONNECT_TO_ME);
    380         IPC_SET_ARG1(call.data, arg1);
    381         IPC_SET_ARG2(call.data, arg2);
    382        
    383         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    384 
    385         ipc_call_sync(phone, &call);
    386 
    387         if (!IPC_GET_RETVAL(call.data) && taskid)
    388                 STRUCT_TO_USPACE(taskid, &phone->callee->task->taskid);
    389 
    390         return IPC_GET_RETVAL(call.data);
    391 }
    392 
    393 /** Ask target process to connect me somewhere
    394  *
    395  * @return phoneid - on success, error otherwise
    396  */
    397 __native sys_ipc_connect_me_to(__native phoneid, __native arg1,
    398                                __native arg2)
    399 {
    400         call_t call;
    401         phone_t *phone;
    402         int newphid;
    403 
    404         GET_CHECK_PHONE(phone, phoneid, return ENOENT);
    405 
    406         newphid = phone_alloc();
    407         if (newphid < 0)
    408                 return ELIMIT;
    409 
    410         ipc_call_static_init(&call);
    411         IPC_SET_METHOD(call.data, IPC_M_CONNECT_ME_TO);
    412         IPC_SET_ARG1(call.data, arg1);
    413         IPC_SET_ARG2(call.data, arg2);
    414         IPC_SET_ARG3(call.data, (__native)&TASK->phones[newphid]);
    415 
    416         ipc_call_sync(phone, &call);
    417 
    418         if (IPC_GET_RETVAL(call.data)) { /* Connection failed */
    419                 phone_dealloc(newphid);
    420                 return IPC_GET_RETVAL(call.data);
    421         }
    422 
    423         return newphid;
    424 }
    425 
    426405/** Hang up the phone
    427  *
    428  *
    429406 *
    430407 */
     
    449426 * @return Callid, if callid & 1, then the call is answer
    450427 */
    451 __native sys_ipc_wait_for_call(ipc_data_t *calldata, task_id_t *taskid,
    452                                __native flags)
    453                                              
     428__native sys_ipc_wait_for_call(ipc_data_t *calldata, __native flags)
    454429{
    455430        call_t *call;
     
    461436
    462437        if (call->flags & IPC_CALL_ANSWERED) {
    463                 if (process_answer(&TASK->answerbox, call))
    464                         goto restart;
     438                process_answer(call);
    465439
    466440                ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC));
     
    482456                goto restart;
    483457
    484         /* Include phone address('id') of the caller in the request */
     458        /* Include phone address('id') of the caller in the request,
     459         * copy whole call->data, not only call->data.args */
    485460        STRUCT_TO_USPACE(calldata, &call->data);
    486         if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO)
    487                 STRUCT_TO_USPACE(taskid, &TASK->taskid);
    488461        return (__native)call;
    489462}
Note: See TracChangeset for help on using the changeset viewer.