Changeset fbcfd458 in mainline for generic/src/ipc/sysipc.c
- Timestamp:
- 2006-03-18T23:02:08Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b4b45210
- Parents:
- ba81cab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/ipc/sysipc.c
rba81cab rfbcfd458 43 43 #include <proc/thread.h> 44 44 45 /* TODO: multi-threaded connect-to-me can cause race condition46 * on phone, add counter + thread_kill??47 *48 */49 50 45 #define GET_CHECK_PHONE(phone,phoneid,err) { \ 51 46 if (phoneid > IPC_MAX_PHONES) { err; } \ … … 53 48 } 54 49 50 #define STRUCT_TO_USPACE(dst,src) copy_to_uspace(dst,src,sizeof(*src)) 55 51 56 52 /** Return true if the method is a system method */ … … 69 65 static inline int is_forwardable(__native method) 70 66 { 67 if (method == IPC_M_PHONE_HUNGUP) 68 return 0; /* This message is meant only for the receiver */ 71 69 return 1; 72 70 } … … 82 80 static inline int answer_will_preprocess(call_t *call) 83 81 { 84 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT TOME)82 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) 85 83 return 1; 86 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT METO)84 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO) 87 85 return 1; 88 86 return 0; … … 94 92 int phoneid; 95 93 96 if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT TOME) {94 if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_TO_ME) { 97 95 phoneid = IPC_GET_ARG3(*olddata); 98 96 if (IPC_GET_RETVAL(answer->data)) { … … 103 101 phone_connect(phoneid,&answer->sender->answerbox); 104 102 } 105 } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT METO) {103 } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) { 106 104 /* If the users accepted call, connect */ 107 105 if (!IPC_GET_RETVAL(answer->data)) { … … 131 129 int phoneid; 132 130 133 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT TOME) {131 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) { 134 132 phoneid = phone_alloc(); 135 133 if (phoneid < 0) { /* Failed to allocate phone */ … … 149 147 */ 150 148 __native sys_ipc_call_sync_fast(__native phoneid, __native method, 151 __native arg1, __native*data)149 __native arg1, ipc_data_t *data) 152 150 { 153 151 call_t call; … … 165 163 ipc_call_sync(phone, &call); 166 164 167 copy_to_uspace(data, &call.data, sizeof(call.data));165 STRUCT_TO_USPACE(&data->args, &call.data.args); 168 166 169 167 return 0; … … 171 169 172 170 /** 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) 175 173 { 176 174 call_t call; … … 178 176 179 177 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)); 181 179 182 180 if (is_system_method(IPC_GET_METHOD(call.data))) … … 187 185 ipc_call_sync(phone, &call); 188 186 189 copy_to_uspace(reply, &call.data, sizeof(call.data));187 STRUCT_TO_USPACE(&reply->args, &call.data.args); 190 188 191 189 return 0; … … 238 236 * @return The same as sys_ipc_call_async 239 237 */ 240 __native sys_ipc_call_async(__native phoneid, __native*data)238 __native sys_ipc_call_async(__native phoneid, ipc_data_t *data) 241 239 { 242 240 call_t *call; … … 249 247 250 248 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)); 252 250 253 251 if (is_system_method(IPC_GET_METHOD(call->data))) { … … 335 333 336 334 /** Send IPC answer */ 337 inline __native sys_ipc_answer(__native callid, __native*data)335 __native sys_ipc_answer(__native callid, ipc_data_t *data) 338 336 { 339 337 call_t *call; … … 349 347 preprocess = 1; 350 348 } 351 copy_from_uspace(&call->data, data, sizeof(call->data)); 349 copy_from_uspace(&call->data.args, &data->args, 350 sizeof(call->data.args)); 352 351 353 352 if (preprocess) … … 370 369 371 370 ipc_call_static_init(&call); 372 IPC_SET_METHOD(call.data, IPC_M_CONNECT TOME);371 IPC_SET_METHOD(call.data, IPC_M_CONNECT_TO_ME); 373 372 IPC_SET_ARG1(call.data, arg1); 374 373 IPC_SET_ARG2(call.data, arg2); … … 379 378 380 379 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); 384 381 385 382 return IPC_GET_RETVAL(call.data); … … 404 401 405 402 ipc_call_static_init(&call); 406 IPC_SET_METHOD(call.data, IPC_M_CONNECT METO);403 IPC_SET_METHOD(call.data, IPC_M_CONNECT_ME_TO); 407 404 IPC_SET_ARG1(call.data, arg1); 408 405 IPC_SET_ARG2(call.data, arg2); … … 419 416 } 420 417 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 421 435 /** Wait for incoming ipc call or answer 422 436 * 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. 428 440 * @param flags 429 441 * @return Callid, if callid & 1, then the call is answer 430 442 */ 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) 434 445 435 446 { … … 443 454 goto restart; 444 455 445 copy_to_uspace(calldata, &call->data, sizeof(call->data)); 456 ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); 457 446 458 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); 448 466 ipc_call_free(call); 449 467 450 468 return ((__native)call) | IPC_CALLID_ANSWERED; 451 469 } 470 452 471 if (process_request(&TASK->answerbox, call)) 453 472 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); 456 478 return (__native)call; 457 479 } 458
Note:
See TracChangeset
for help on using the changeset viewer.