Changes in uspace/lib/c/generic/async.c [4d6629f:569a51a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
r4d6629f r569a51a 77 77 * } 78 78 * 79 * port_handler(ic allid, *icall)79 * port_handler(ichandle, *icall) 80 80 * { 81 81 * if (want_refuse) { 82 * async_answer_0(ic allid, ELIMIT);82 * async_answer_0(ichandle, ELIMIT); 83 83 * return; 84 84 * } 85 * async_answer_0(ic allid, EOK);86 * 87 * c allid= async_get_call(&call);88 * somehow_handle_the_call(c allid, call);89 * async_answer_2(c allid, 1, 2, 3);90 * 91 * c allid= async_get_call(&call);85 * async_answer_0(ichandle, EOK); 86 * 87 * chandle = async_get_call(&call); 88 * somehow_handle_the_call(chandle, call); 89 * async_answer_2(chandle, 1, 2, 3); 90 * 91 * chandle = async_get_call(&call); 92 92 * ... 93 93 * } … … 106 106 #include <fibril.h> 107 107 #include <adt/hash_table.h> 108 #include <adt/hash.h> 108 109 #include <adt/list.h> 109 110 #include <assert.h> … … 112 113 #include <libarch/barrier.h> 113 114 #include <stdbool.h> 114 #include < malloc.h>115 #include <stdlib.h> 115 116 #include <mem.h> 116 117 #include <stdlib.h> … … 184 185 link_t link; 185 186 186 ipc_callid_t callid;187 cap_handle_t chandle; 187 188 ipc_call_t call; 188 189 } msg_t; … … 236 237 237 238 /** Identification of the opening call. */ 238 ipc_callid_t callid;239 cap_handle_t chandle; 239 240 240 241 /** Call data of the opening call. */ … … 242 243 243 244 /** Identification of the closing call. */ 244 ipc_callid_t close_callid;245 cap_handle_t close_chandle; 245 246 246 247 /** Fibril function that will be used to handle the connection. */ … … 373 374 /** Default fallback fibril function. 374 375 * 375 * This fallback fibril function gets called on incomming 376 * connections that donot have a specific handler defined.377 * 378 * @param c allid Hashof the incoming call.379 * @param call Data of the incoming call.380 * @param arg Local argument381 * 382 */ 383 static void default_fallback_port_handler( ipc_callid_t callid, ipc_call_t *call,384 void *arg)385 { 386 ipc_answer_0(c allid, ENOENT);376 * This fallback fibril function gets called on incomming connections that do 377 * not have a specific handler defined. 378 * 379 * @param chandle Handle of the incoming call. 380 * @param call Data of the incoming call. 381 * @param arg Local argument 382 * 383 */ 384 static void default_fallback_port_handler(cap_handle_t chandle, 385 ipc_call_t *call, void *arg) 386 { 387 ipc_answer_0(chandle, ENOENT); 387 388 } 388 389 … … 587 588 }; 588 589 589 /** Compute hash into the connection hash table based on the source phone hash. 590 * 591 * @param key Pointer to source phone hash. 590 typedef struct { 591 task_id_t task_id; 592 sysarg_t phone_hash; 593 } conn_key_t; 594 595 /** Compute hash into the connection hash table 596 * 597 * The hash is based on the source task ID and the source phone hash. The task 598 * ID is included in the hash because a phone hash alone might not be unique 599 * while we still track connections for killed tasks due to kernel's recycling 600 * of phone structures. 601 * 602 * @param key Pointer to the connection key structure. 592 603 * 593 604 * @return Index into the connection hash table. … … 596 607 static size_t conn_key_hash(void *key) 597 608 { 598 sysarg_t in_phone_hash = *(sysarg_t *) key; 599 return in_phone_hash; 609 conn_key_t *ck = (conn_key_t *) key; 610 611 size_t hash = 0; 612 hash = hash_combine(hash, LOWER32(ck->task_id)); 613 hash = hash_combine(hash, UPPER32(ck->task_id)); 614 hash = hash_combine(hash, ck->phone_hash); 615 return hash; 600 616 } 601 617 … … 603 619 { 604 620 connection_t *conn = hash_table_get_inst(item, connection_t, link); 605 return conn_key_hash(&conn->in_phone_hash); 621 return conn_key_hash(&(conn_key_t){ 622 .task_id = conn->in_task_id, 623 .phone_hash = conn->in_phone_hash 624 }); 606 625 } 607 626 608 627 static bool conn_key_equal(void *key, const ht_link_t *item) 609 628 { 610 sysarg_t in_phone_hash = *(sysarg_t *) key;629 conn_key_t *ck = (conn_key_t *) key; 611 630 connection_t *conn = hash_table_get_inst(item, connection_t, link); 612 return (in_phone_hash == conn->in_phone_hash); 631 return ((ck->task_id == conn->in_task_id) && 632 (ck->phone_hash == conn->in_phone_hash)); 613 633 } 614 634 … … 695 715 client_t *client = async_client_get(fibril_connection->in_task_id, true); 696 716 if (!client) { 697 ipc_answer_0(fibril_connection->c allid, ENOMEM);717 ipc_answer_0(fibril_connection->chandle, ENOMEM); 698 718 return 0; 699 719 } … … 704 724 * Call the connection handler function. 705 725 */ 706 fibril_connection->handler(fibril_connection->c allid,726 fibril_connection->handler(fibril_connection->chandle, 707 727 &fibril_connection->call, fibril_connection->data); 708 728 … … 716 736 */ 717 737 futex_down(&async_futex); 718 hash_table_remove(&conn_hash_table, &fibril_connection->in_phone_hash); 738 hash_table_remove(&conn_hash_table, &(conn_key_t){ 739 .task_id = fibril_connection->in_task_id, 740 .phone_hash = fibril_connection->in_phone_hash 741 }); 719 742 futex_up(&async_futex); 720 743 … … 728 751 729 752 list_remove(&msg->link); 730 ipc_answer_0(msg->c allid, EHANGUP);753 ipc_answer_0(msg->chandle, EHANGUP); 731 754 free(msg); 732 755 } … … 736 759 * i.e. IPC_M_PHONE_HUNGUP. 737 760 */ 738 if (fibril_connection->close_c allid)739 ipc_answer_0(fibril_connection->close_c allid, EOK);761 if (fibril_connection->close_chandle) 762 ipc_answer_0(fibril_connection->close_chandle, EOK); 740 763 741 764 free(fibril_connection); … … 745 768 /** Create a new fibril for a new connection. 746 769 * 747 * Create new fibril for connection, fill in connection structures 748 * and insert it into the hash table, so that later we can easily749 * do routing of messages toparticular fibrils.750 * 751 * @param in_task_id Identification of the incoming connection.752 * @param in_phone_hash Identification of the incoming connection.753 * @param c allid Hashof the opening IPC_M_CONNECT_ME_TO call.754 * If callid is zero, the connection was opened by755 * accepting the IPC_M_CONNECT_TO_ME call and this756 * function is called directly by the server.757 * @param call Call data of the opening call.758 * @param handler Connection handler.759 * @param data Client argument to pass to the connection handler.760 * 761 * @return New fibril id or NULL on failure.770 * Create new fibril for connection, fill in connection structures and insert it 771 * into the hash table, so that later we can easily do routing of messages to 772 * particular fibrils. 773 * 774 * @param in_task_id Identification of the incoming connection. 775 * @param in_phone_hash Identification of the incoming connection. 776 * @param chandle Handle of the opening IPC_M_CONNECT_ME_TO call. 777 * If chandle is CAP_NIL, the connection was opened by 778 * accepting the IPC_M_CONNECT_TO_ME call and this 779 * function is called directly by the server. 780 * @param call Call data of the opening call. 781 * @param handler Connection handler. 782 * @param data Client argument to pass to the connection handler. 783 * 784 * @return New fibril id or NULL on failure. 762 785 * 763 786 */ 764 787 static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 765 ipc_callid_t callid, ipc_call_t *call, async_port_handler_t handler,788 cap_handle_t chandle, ipc_call_t *call, async_port_handler_t handler, 766 789 void *data) 767 790 { 768 791 connection_t *conn = malloc(sizeof(*conn)); 769 792 if (!conn) { 770 if (c allid)771 ipc_answer_0(c allid, ENOMEM);793 if (chandle != CAP_NIL) 794 ipc_answer_0(chandle, ENOMEM); 772 795 773 796 return (uintptr_t) NULL; … … 777 800 conn->in_phone_hash = in_phone_hash; 778 801 list_initialize(&conn->msg_queue); 779 conn->c allid = callid;780 conn->close_c allid = 0;802 conn->chandle = chandle; 803 conn->close_chandle = CAP_NIL; 781 804 conn->handler = handler; 782 805 conn->data = data; … … 792 815 free(conn); 793 816 794 if (c allid)795 ipc_answer_0(c allid, ENOMEM);817 if (chandle != CAP_NIL) 818 ipc_answer_0(chandle, ENOMEM); 796 819 797 820 return (uintptr_t) NULL; … … 869 892 870 893 fid_t fid = async_new_connection(answer.in_task_id, phone_hash, 871 0, NULL, handler, data);894 CAP_NIL, NULL, handler, data); 872 895 if (fid == (uintptr_t) NULL) 873 896 return ENOMEM; … … 938 961 * timeouts are unregistered. 939 962 * 940 * @param c allid Hashof the incoming call.941 * @param call Data of the incoming call.963 * @param chandle Handle of the incoming call. 964 * @param call Data of the incoming call. 942 965 * 943 966 * @return False if the call doesn't match any connection. … … 945 968 * 946 969 */ 947 static bool route_call( ipc_callid_t callid, ipc_call_t *call)970 static bool route_call(cap_handle_t chandle, ipc_call_t *call) 948 971 { 949 972 assert(call); … … 951 974 futex_down(&async_futex); 952 975 953 ht_link_t *link = hash_table_find(&conn_hash_table, &call->in_phone_hash); 976 ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){ 977 .task_id = call->in_task_id, 978 .phone_hash = call->in_phone_hash 979 }); 954 980 if (!link) { 955 981 futex_up(&async_futex); … … 965 991 } 966 992 967 msg->c allid = callid;993 msg->chandle = chandle; 968 994 msg->call = *call; 969 995 list_append(&msg->link, &conn->msg_queue); 970 996 971 997 if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP) 972 conn->close_c allid = callid;998 conn->close_chandle = chandle; 973 999 974 1000 /* If the connection fibril is waiting for an event, activate it */ … … 991 1017 /** Process notification. 992 1018 * 993 * @param callid Hash of the incoming call.994 1019 * @param call Data of the incoming call. 995 1020 * 996 1021 */ 997 static void process_notification(ipc_call id_t callid, ipc_call_t *call)1022 static void process_notification(ipc_call_t *call) 998 1023 { 999 1024 async_notification_handler_t handler = NULL; … … 1016 1041 1017 1042 if (handler) 1018 handler(call id, call, data);1043 handler(call, data); 1019 1044 } 1020 1045 … … 1026 1051 * @param ucode Top-half pseudocode handler. 1027 1052 * 1028 * @return IRQ capability handle on success. 1053 * @param[out] handle IRQ capability handle on success. 1054 * 1029 1055 * @return Negative error code. 1030 1056 * 1031 1057 */ 1032 1058 int async_irq_subscribe(int inr, async_notification_handler_t handler, 1033 void *data, const irq_code_t *ucode )1059 void *data, const irq_code_t *ucode, cap_handle_t *handle) 1034 1060 { 1035 1061 notification_t *notification = … … 1051 1077 futex_up(&async_futex); 1052 1078 1053 return ipc_irq_subscribe(inr, imethod, ucode); 1079 cap_handle_t cap; 1080 int rc = ipc_irq_subscribe(inr, imethod, ucode, &cap); 1081 if (rc == EOK && handle != NULL) { 1082 *handle = cap; 1083 } 1084 return rc; 1054 1085 } 1055 1086 … … 1161 1192 /** Return new incoming message for the current (fibril-local) connection. 1162 1193 * 1163 * @param call Storage where the incoming call data will be stored. 1164 * @param usecs Timeout in microseconds. Zero denotes no timeout. 1165 * 1166 * @return If no timeout was specified, then a hash of the 1167 * incoming call is returned. If a timeout is specified, 1168 * then a hash of the incoming call is returned unless 1169 * the timeout expires prior to receiving a message. In 1170 * that case zero is returned. 1171 * 1172 */ 1173 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs) 1194 * @param call Storage where the incoming call data will be stored. 1195 * @param usecs Timeout in microseconds. Zero denotes no timeout. 1196 * 1197 * @return If no timeout was specified, then a handle of the incoming call is 1198 * returned. If a timeout is specified, then a handle of the incoming 1199 * call is returned unless the timeout expires prior to receiving a 1200 * message. In that case zero CAP_NIL is returned. 1201 */ 1202 cap_handle_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs) 1174 1203 { 1175 1204 assert(call); … … 1194 1223 /* If nothing in queue, wait until something arrives */ 1195 1224 while (list_empty(&conn->msg_queue)) { 1196 if (conn->close_c allid) {1225 if (conn->close_chandle) { 1197 1226 /* 1198 1227 * Handle the case when the connection was already … … 1205 1234 IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP); 1206 1235 futex_up(&async_futex); 1207 return conn->close_c allid;1236 return conn->close_chandle; 1208 1237 } 1209 1238 … … 1230 1259 /* If we timed out -> exit */ 1231 1260 futex_up(&async_futex); 1232 return 0;1261 return CAP_NIL; 1233 1262 } 1234 1263 } … … 1238 1267 list_remove(&msg->link); 1239 1268 1240 ipc_callid_t callid = msg->callid;1269 cap_handle_t chandle = msg->chandle; 1241 1270 *call = msg->call; 1242 1271 free(msg); 1243 1272 1244 1273 futex_up(&async_futex); 1245 return c allid;1274 return chandle; 1246 1275 } 1247 1276 … … 1306 1335 * Otherwise the call is routed to its connection fibril. 1307 1336 * 1308 * @param c allid Hashof the incoming call.1309 * @param call Data of the incoming call.1310 * 1311 */ 1312 static void handle_call( ipc_callid_t callid, ipc_call_t *call)1337 * @param chandle Handle of the incoming call. 1338 * @param call Data of the incoming call. 1339 * 1340 */ 1341 static void handle_call(cap_handle_t chandle, ipc_call_t *call) 1313 1342 { 1314 1343 assert(call); 1315 1344 1316 1345 /* Kernel notification */ 1317 if ((c allid & IPC_CALLID_NOTIFICATION)) {1346 if ((chandle == CAP_NIL) && (call->flags & IPC_CALL_NOTIF)) { 1318 1347 fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data; 1319 1348 unsigned oldsw = fibril->switches; 1320 1349 1321 process_notification(call id, call);1350 process_notification(call); 1322 1351 1323 1352 if (oldsw != fibril->switches) { … … 1345 1374 sysarg_t in_phone_hash = IPC_GET_ARG5(*call); 1346 1375 1347 async_ notification_handler_t handler = fallback_port_handler;1376 async_port_handler_t handler = fallback_port_handler; 1348 1377 void *data = fallback_port_data; 1349 1378 … … 1355 1384 } 1356 1385 1357 async_new_connection(call->in_task_id, in_phone_hash, c allid,1386 async_new_connection(call->in_task_id, in_phone_hash, chandle, 1358 1387 call, handler, data); 1359 1388 return; … … 1361 1390 1362 1391 /* Try to route the call through the connection hash table */ 1363 if (route_call(c allid, call))1392 if (route_call(chandle, call)) 1364 1393 return; 1365 1394 1366 1395 /* Unknown call from unknown phone - hang it up */ 1367 ipc_answer_0(c allid, EHANGUP);1396 ipc_answer_0(chandle, EHANGUP); 1368 1397 } 1369 1398 … … 1460 1489 1461 1490 ipc_call_t call; 1462 i pc_callid_t callid= ipc_wait_cycle(&call, timeout, flags);1491 int rc = ipc_wait_cycle(&call, timeout, flags); 1463 1492 1464 1493 atomic_dec(&threads_in_ipc_wait); 1465 1494 1466 if (!callid) { 1467 handle_expired_timeouts(); 1495 assert(rc == EOK); 1496 1497 if (call.cap_handle == CAP_NIL) { 1498 if (call.flags == 0) { 1499 /* This neither a notification nor an answer. */ 1500 handle_expired_timeouts(); 1501 continue; 1502 } 1503 } 1504 1505 if (call.flags & IPC_CALL_ANSWERED) 1468 1506 continue; 1469 } 1470 1471 if (callid & IPC_CALLID_ANSWERED) 1472 continue; 1473 1474 handle_call(callid, &call); 1475 } 1476 1507 1508 handle_call(call.cap_handle, &call); 1509 } 1510 1477 1511 return 0; 1478 1512 } … … 1605 1639 * @param arg3 Service-defined payload argument. 1606 1640 * @param arg4 Service-defined payload argument. 1607 * @param dataptr If non-NULL, storage where the reply data will be 1608 * stored. 1641 * @param dataptr If non-NULL, storage where the reply data will be stored. 1609 1642 * 1610 1643 * @return Hash of the sent message or 0 on error. … … 1843 1876 } 1844 1877 1878 /** Delay execution for the specified number of seconds 1879 * 1880 * @param sec Number of seconds to sleep 1881 */ 1882 void async_sleep(unsigned int sec) 1883 { 1884 /* 1885 * Sleep in 1000 second steps to support 1886 * full argument range 1887 */ 1888 1889 while (sec > 0) { 1890 unsigned int period = (sec > 1000) ? 1000 : sec; 1891 1892 async_usleep(period * 1000000); 1893 sec -= period; 1894 } 1895 } 1896 1845 1897 /** Pseudo-synchronous message sending - fast version. 1846 1898 * … … 1992 2044 } 1993 2045 1994 sysarg_t async_answer_0( ipc_callid_t callid, sysarg_t retval)1995 { 1996 return ipc_answer_0(c allid, retval);1997 } 1998 1999 sysarg_t async_answer_1( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)2000 { 2001 return ipc_answer_1(c allid, retval, arg1);2002 } 2003 2004 sysarg_t async_answer_2( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2046 sysarg_t async_answer_0(cap_handle_t chandle, sysarg_t retval) 2047 { 2048 return ipc_answer_0(chandle, retval); 2049 } 2050 2051 sysarg_t async_answer_1(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1) 2052 { 2053 return ipc_answer_1(chandle, retval, arg1); 2054 } 2055 2056 sysarg_t async_answer_2(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2005 2057 sysarg_t arg2) 2006 2058 { 2007 return ipc_answer_2(c allid, retval, arg1, arg2);2008 } 2009 2010 sysarg_t async_answer_3( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2059 return ipc_answer_2(chandle, retval, arg1, arg2); 2060 } 2061 2062 sysarg_t async_answer_3(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2011 2063 sysarg_t arg2, sysarg_t arg3) 2012 2064 { 2013 return ipc_answer_3(c allid, retval, arg1, arg2, arg3);2014 } 2015 2016 sysarg_t async_answer_4( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2065 return ipc_answer_3(chandle, retval, arg1, arg2, arg3); 2066 } 2067 2068 sysarg_t async_answer_4(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2017 2069 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4) 2018 2070 { 2019 return ipc_answer_4(c allid, retval, arg1, arg2, arg3, arg4);2020 } 2021 2022 sysarg_t async_answer_5( ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,2071 return ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4); 2072 } 2073 2074 sysarg_t async_answer_5(cap_handle_t chandle, sysarg_t retval, sysarg_t arg1, 2023 2075 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5) 2024 2076 { 2025 return ipc_answer_5(c allid, retval, arg1, arg2, arg3, arg4, arg5);2026 } 2027 2028 int async_forward_fast( ipc_callid_t callid, async_exch_t *exch,2077 return ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5); 2078 } 2079 2080 int async_forward_fast(cap_handle_t chandle, async_exch_t *exch, 2029 2081 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode) 2030 2082 { … … 2032 2084 return ENOENT; 2033 2085 2034 return ipc_forward_fast(c allid, exch->phone, imethod, arg1, arg2, mode);2035 } 2036 2037 int async_forward_slow( ipc_callid_t callid, async_exch_t *exch,2086 return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode); 2087 } 2088 2089 int async_forward_slow(cap_handle_t chandle, async_exch_t *exch, 2038 2090 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 2039 2091 sysarg_t arg4, sysarg_t arg5, unsigned int mode) … … 2042 2094 return ENOENT; 2043 2095 2044 return ipc_forward_slow(c allid, exch->phone, imethod, arg1, arg2, arg3,2096 return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3, 2045 2097 arg4, arg5, mode); 2046 2098 } … … 2077 2129 2078 2130 static int async_connect_me_to_internal(int phone, sysarg_t arg1, sysarg_t arg2, 2079 sysarg_t arg3, sysarg_t arg4 )2131 sysarg_t arg3, sysarg_t arg4, int *out_phone) 2080 2132 { 2081 2133 ipc_call_t result; 2134 2135 // XXX: Workaround for GCC's inability to infer association between 2136 // rc == EOK and *out_phone being assigned. 2137 *out_phone = -1; 2082 2138 2083 2139 amsg_t *msg = amsg_create(); … … 2097 2153 return rc; 2098 2154 2099 return (int) IPC_GET_ARG5(result); 2155 *out_phone = (int) IPC_GET_ARG5(result); 2156 return EOK; 2100 2157 } 2101 2158 … … 2127 2184 } 2128 2185 2129 int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3, 2130 0); 2131 if (phone < 0) { 2132 errno = phone; 2186 int phone; 2187 int rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3, 2188 0, &phone); 2189 if (rc != EOK) { 2190 errno = rc; 2133 2191 free(sess); 2134 2192 return NULL; … … 2179 2237 } 2180 2238 2181 int phone = async_connect_me_to_internal(exch->phone, iface, arg2, 2182 arg3, 0); 2183 if (phone < 0) { 2184 errno = phone; 2239 int phone; 2240 int rc = async_connect_me_to_internal(exch->phone, iface, arg2, 2241 arg3, 0, &phone); 2242 if (rc != EOK) { 2243 errno = rc; 2185 2244 free(sess); 2186 2245 return NULL; … … 2249 2308 } 2250 2309 2251 int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3, 2252 IPC_FLAG_BLOCKING); 2253 2254 if (phone < 0) { 2255 errno = phone; 2310 int phone; 2311 int rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3, 2312 IPC_FLAG_BLOCKING, &phone); 2313 2314 if (rc != EOK) { 2315 errno = rc; 2256 2316 free(sess); 2257 2317 return NULL; … … 2302 2362 } 2303 2363 2304 int phone = async_connect_me_to_internal(exch->phone, iface, arg2, 2305 arg3, IPC_FLAG_BLOCKING); 2306 if (phone < 0) { 2307 errno = phone; 2364 int phone; 2365 int rc = async_connect_me_to_internal(exch->phone, iface, arg2, 2366 arg3, IPC_FLAG_BLOCKING, &phone); 2367 if (rc != EOK) { 2368 errno = rc; 2308 2369 free(sess); 2309 2370 return NULL; … … 2337 2398 } 2338 2399 2339 int phone = ipc_connect_kbox(id); 2340 if (phone < 0) { 2341 errno = phone; 2400 cap_handle_t phone; 2401 int rc = ipc_connect_kbox(id, &phone); 2402 if (rc != EOK) { 2403 errno = rc; 2342 2404 free(sess); 2343 2405 return NULL; … … 2456 2518 } else if (mgmt == EXCHANGE_PARALLEL) { 2457 2519 int phone; 2520 int rc; 2458 2521 2459 2522 retry: … … 2461 2524 * Make a one-time attempt to connect a new data phone. 2462 2525 */ 2463 phone= async_connect_me_to_internal(sess->phone, sess->arg1,2464 sess->arg2, sess->arg3, 0 );2465 if ( phone >= 0) {2526 rc = async_connect_me_to_internal(sess->phone, sess->arg1, 2527 sess->arg2, sess->arg3, 0, &phone); 2528 if (rc == EOK) { 2466 2529 exch = (async_exch_t *) malloc(sizeof(async_exch_t)); 2467 2530 if (exch != NULL) { … … 2578 2641 * So far, this wrapper is to be used from within a connection fibril. 2579 2642 * 2580 * @param c allid Storage for the hashof the IPC_M_SHARE_IN call.2581 * @param size Destination address space area size.2643 * @param chandle Storage for the handle of the IPC_M_SHARE_IN call. 2644 * @param size Destination address space area size. 2582 2645 * 2583 2646 * @return True on success, false on failure. 2584 2647 * 2585 2648 */ 2586 bool async_share_in_receive( ipc_callid_t *callid, size_t *size)2587 { 2588 assert(c allid);2649 bool async_share_in_receive(cap_handle_t *chandle, size_t *size) 2650 { 2651 assert(chandle); 2589 2652 assert(size); 2590 2653 2591 2654 ipc_call_t data; 2592 *c allid= async_get_call(&data);2655 *chandle = async_get_call(&data); 2593 2656 2594 2657 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN) … … 2605 2668 * argument. 2606 2669 * 2607 * @param c allid Hashof the IPC_M_DATA_READ call to answer.2608 * @param src Source address space base.2609 * @param flags Flags to be used for sharing. Bits can be only cleared.2670 * @param chandle Handle of the IPC_M_DATA_READ call to answer. 2671 * @param src Source address space base. 2672 * @param flags Flags to be used for sharing. Bits can be only cleared. 2610 2673 * 2611 2674 * @return Zero on success or a value from @ref errno.h on failure. 2612 2675 * 2613 2676 */ 2614 int async_share_in_finalize( ipc_callid_t callid, void *src, unsigned int flags)2615 { 2616 return ipc_answer_3(c allid, EOK, (sysarg_t) src, (sysarg_t) flags,2677 int async_share_in_finalize(cap_handle_t chandle, void *src, unsigned int flags) 2678 { 2679 return ipc_answer_3(chandle, EOK, (sysarg_t) src, (sysarg_t) flags, 2617 2680 (sysarg_t) __entry); 2618 2681 } … … 2644 2707 * So far, this wrapper is to be used from within a connection fibril. 2645 2708 * 2646 * @param c allidStorage for the hash of the IPC_M_SHARE_OUT call.2647 * @param size Storage for the source address space area size.2648 * @param flags Storage for the sharing flags.2709 * @param chandle Storage for the hash of the IPC_M_SHARE_OUT call. 2710 * @param size Storage for the source address space area size. 2711 * @param flags Storage for the sharing flags. 2649 2712 * 2650 2713 * @return True on success, false on failure. 2651 2714 * 2652 2715 */ 2653 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags) 2654 { 2655 assert(callid); 2716 bool async_share_out_receive(cap_handle_t *chandle, size_t *size, 2717 unsigned int *flags) 2718 { 2719 assert(chandle); 2656 2720 assert(size); 2657 2721 assert(flags); 2658 2722 2659 2723 ipc_call_t data; 2660 *c allid= async_get_call(&data);2724 *chandle = async_get_call(&data); 2661 2725 2662 2726 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT) … … 2674 2738 * argument. 2675 2739 * 2676 * @param c allid Hashof the IPC_M_DATA_WRITE call to answer.2677 * @param dst Address of the storage for the destination address space area2678 * base address.2679 * 2680 * @return Zero on success or a value from @ref errno.h on failure.2681 * 2682 */ 2683 int async_share_out_finalize( ipc_callid_t callid, void **dst)2684 { 2685 return ipc_answer_2(c allid, EOK, (sysarg_t) __entry, (sysarg_t) dst);2740 * @param chandle Handle of the IPC_M_DATA_WRITE call to answer. 2741 * @param dst Address of the storage for the destination address space area 2742 * base address. 2743 * 2744 * @return Zero on success or a value from @ref errno.h on failure. 2745 * 2746 */ 2747 int async_share_out_finalize(cap_handle_t chandle, void **dst) 2748 { 2749 return ipc_answer_2(chandle, EOK, (sysarg_t) __entry, (sysarg_t) dst); 2686 2750 } 2687 2751 … … 2729 2793 * So far, this wrapper is to be used from within a connection fibril. 2730 2794 * 2731 * @param c allid Storage for the hashof the IPC_M_DATA_READ.2732 * @param size Storage for the maximum size. Can be NULL.2795 * @param chandle Storage for the handle of the IPC_M_DATA_READ. 2796 * @param size Storage for the maximum size. Can be NULL. 2733 2797 * 2734 2798 * @return True on success, false on failure. 2735 2799 * 2736 2800 */ 2737 bool async_data_read_receive( ipc_callid_t *callid, size_t *size)2801 bool async_data_read_receive(cap_handle_t *chandle, size_t *size) 2738 2802 { 2739 2803 ipc_call_t data; 2740 return async_data_read_receive_call(c allid, &data, size);2804 return async_data_read_receive_call(chandle, &data, size); 2741 2805 } 2742 2806 … … 2749 2813 * So far, this wrapper is to be used from within a connection fibril. 2750 2814 * 2751 * @param c allid Storage for the hashof the IPC_M_DATA_READ.2752 * @param size Storage for the maximum size. Can be NULL.2815 * @param chandle Storage for the handle of the IPC_M_DATA_READ. 2816 * @param size Storage for the maximum size. Can be NULL. 2753 2817 * 2754 2818 * @return True on success, false on failure. 2755 2819 * 2756 2820 */ 2757 bool async_data_read_receive_call( ipc_callid_t *callid, ipc_call_t *data,2821 bool async_data_read_receive_call(cap_handle_t *chandle, ipc_call_t *data, 2758 2822 size_t *size) 2759 2823 { 2760 assert(c allid);2824 assert(chandle); 2761 2825 assert(data); 2762 2826 2763 *c allid= async_get_call(data);2827 *chandle = async_get_call(data); 2764 2828 2765 2829 if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ) … … 2778 2842 * argument. 2779 2843 * 2780 * @param c allid Hashof the IPC_M_DATA_READ call to answer.2781 * @param src Source address for the IPC_M_DATA_READ call.2782 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than2783 * the maximum size announced by the sender.2784 * 2785 * @return Zero on success or a value from @ref errno.h on failure.2786 * 2787 */ 2788 int async_data_read_finalize( ipc_callid_t callid, const void *src, size_t size)2789 { 2790 return ipc_answer_2(c allid, EOK, (sysarg_t) src, (sysarg_t) size);2844 * @param chandle Handle of the IPC_M_DATA_READ call to answer. 2845 * @param src Source address for the IPC_M_DATA_READ call. 2846 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 2847 * the maximum size announced by the sender. 2848 * 2849 * @return Zero on success or a value from @ref errno.h on failure. 2850 * 2851 */ 2852 int async_data_read_finalize(cap_handle_t chandle, const void *src, size_t size) 2853 { 2854 return ipc_answer_2(chandle, EOK, (sysarg_t) src, (sysarg_t) size); 2791 2855 } 2792 2856 … … 2801 2865 return ENOENT; 2802 2866 2803 ipc_callid_t callid;2804 if (!async_data_read_receive(&c allid, NULL)) {2805 ipc_answer_0(c allid, EINVAL);2867 cap_handle_t chandle; 2868 if (!async_data_read_receive(&chandle, NULL)) { 2869 ipc_answer_0(chandle, EINVAL); 2806 2870 return EINVAL; 2807 2871 } … … 2810 2874 dataptr); 2811 2875 if (msg == 0) { 2812 ipc_answer_0(c allid, EINVAL);2876 ipc_answer_0(chandle, EINVAL); 2813 2877 return EINVAL; 2814 2878 } 2815 2879 2816 int retval = ipc_forward_fast(c allid, exch->phone, 0, 0, 0,2880 int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0, 2817 2881 IPC_FF_ROUTE_FROM_ME); 2818 2882 if (retval != EOK) { 2819 2883 async_forget(msg); 2820 ipc_answer_0(c allid, retval);2884 ipc_answer_0(chandle, retval); 2821 2885 return retval; 2822 2886 } … … 2854 2918 * So far, this wrapper is to be used from within a connection fibril. 2855 2919 * 2856 * @param c allid Storage for the hashof the IPC_M_DATA_WRITE.2857 * @param size Storage for the suggested size. May be NULL.2858 * 2859 * @return True on success, false on failure.2860 * 2861 */ 2862 bool async_data_write_receive( ipc_callid_t *callid, size_t *size)2920 * @param chandle Storage for the handle of the IPC_M_DATA_WRITE. 2921 * @param size Storage for the suggested size. May be NULL. 2922 * 2923 * @return True on success, false on failure. 2924 * 2925 */ 2926 bool async_data_write_receive(cap_handle_t *chandle, size_t *size) 2863 2927 { 2864 2928 ipc_call_t data; 2865 return async_data_write_receive_call(c allid, &data, size);2929 return async_data_write_receive_call(chandle, &data, size); 2866 2930 } 2867 2931 … … 2874 2938 * So far, this wrapper is to be used from within a connection fibril. 2875 2939 * 2876 * @param c allid Storage for the hashof the IPC_M_DATA_WRITE.2877 * @param data Storage for the ipc call data.2878 * @param size Storage for the suggested size. May be NULL.2940 * @param chandle Storage for the handle of the IPC_M_DATA_WRITE. 2941 * @param data Storage for the ipc call data. 2942 * @param size Storage for the suggested size. May be NULL. 2879 2943 * 2880 2944 * @return True on success, false on failure. 2881 2945 * 2882 2946 */ 2883 bool async_data_write_receive_call( ipc_callid_t *callid, ipc_call_t *data,2947 bool async_data_write_receive_call(cap_handle_t *chandle, ipc_call_t *data, 2884 2948 size_t *size) 2885 2949 { 2886 assert(c allid);2950 assert(chandle); 2887 2951 assert(data); 2888 2952 2889 *c allid= async_get_call(data);2953 *chandle = async_get_call(data); 2890 2954 2891 2955 if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE) … … 2904 2968 * argument. 2905 2969 * 2906 * @param c allid Hashof the IPC_M_DATA_WRITE call to answer.2907 * @param dst Final destination address for the IPC_M_DATA_WRITE call.2908 * @param size Final size for the IPC_M_DATA_WRITE call.2909 * 2910 * @return Zero on success or a value from @ref errno.h on failure.2911 * 2912 */ 2913 int async_data_write_finalize( ipc_callid_t callid, void *dst, size_t size)2914 { 2915 return ipc_answer_2(c allid, EOK, (sysarg_t) dst, (sysarg_t) size);2970 * @param chandle Handle of the IPC_M_DATA_WRITE call to answer. 2971 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 2972 * @param size Final size for the IPC_M_DATA_WRITE call. 2973 * 2974 * @return Zero on success or a value from @ref errno.h on failure. 2975 * 2976 */ 2977 int async_data_write_finalize(cap_handle_t chandle, void *dst, size_t size) 2978 { 2979 return ipc_answer_2(chandle, EOK, (sysarg_t) dst, (sysarg_t) size); 2916 2980 } 2917 2981 … … 2943 3007 assert(data); 2944 3008 2945 ipc_callid_t callid;3009 cap_handle_t chandle; 2946 3010 size_t size; 2947 if (!async_data_write_receive(&c allid, &size)) {2948 ipc_answer_0(c allid, EINVAL);3011 if (!async_data_write_receive(&chandle, &size)) { 3012 ipc_answer_0(chandle, EINVAL); 2949 3013 return EINVAL; 2950 3014 } 2951 3015 2952 3016 if (size < min_size) { 2953 ipc_answer_0(c allid, EINVAL);3017 ipc_answer_0(chandle, EINVAL); 2954 3018 return EINVAL; 2955 3019 } 2956 3020 2957 3021 if ((max_size > 0) && (size > max_size)) { 2958 ipc_answer_0(c allid, EINVAL);3022 ipc_answer_0(chandle, EINVAL); 2959 3023 return EINVAL; 2960 3024 } 2961 3025 2962 3026 if ((granularity > 0) && ((size % granularity) != 0)) { 2963 ipc_answer_0(c allid, EINVAL);3027 ipc_answer_0(chandle, EINVAL); 2964 3028 return EINVAL; 2965 3029 } … … 2973 3037 2974 3038 if (arg_data == NULL) { 2975 ipc_answer_0(c allid, ENOMEM);3039 ipc_answer_0(chandle, ENOMEM); 2976 3040 return ENOMEM; 2977 3041 } 2978 3042 2979 int rc = async_data_write_finalize(c allid, arg_data, size);3043 int rc = async_data_write_finalize(chandle, arg_data, size); 2980 3044 if (rc != EOK) { 2981 3045 free(arg_data); … … 3002 3066 void async_data_write_void(sysarg_t retval) 3003 3067 { 3004 ipc_callid_t callid;3005 async_data_write_receive(&c allid, NULL);3006 ipc_answer_0(c allid, retval);3068 cap_handle_t chandle; 3069 async_data_write_receive(&chandle, NULL); 3070 ipc_answer_0(chandle, retval); 3007 3071 } 3008 3072 … … 3017 3081 return ENOENT; 3018 3082 3019 ipc_callid_t callid;3020 if (!async_data_write_receive(&c allid, NULL)) {3021 ipc_answer_0(c allid, EINVAL);3083 cap_handle_t chandle; 3084 if (!async_data_write_receive(&chandle, NULL)) { 3085 ipc_answer_0(chandle, EINVAL); 3022 3086 return EINVAL; 3023 3087 } … … 3026 3090 dataptr); 3027 3091 if (msg == 0) { 3028 ipc_answer_0(c allid, EINVAL);3092 ipc_answer_0(chandle, EINVAL); 3029 3093 return EINVAL; 3030 3094 } 3031 3095 3032 int retval = ipc_forward_fast(c allid, exch->phone, 0, 0, 0,3096 int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0, 3033 3097 IPC_FF_ROUTE_FROM_ME); 3034 3098 if (retval != EOK) { 3035 3099 async_forget(msg); 3036 ipc_answer_0(c allid, retval);3100 ipc_answer_0(chandle, retval); 3037 3101 return retval; 3038 3102 } … … 3059 3123 /* Accept the phone */ 3060 3124 ipc_call_t call; 3061 ipc_callid_t callid = async_get_call(&call); 3062 int phone = (int) IPC_GET_ARG5(call); 3063 3064 if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || 3065 (phone < 0)) { 3066 async_answer_0(callid, EINVAL); 3125 cap_handle_t chandle = async_get_call(&call); 3126 cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call); 3127 3128 if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) { 3129 async_answer_0(chandle, EINVAL); 3067 3130 return NULL; 3068 3131 } … … 3070 3133 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t)); 3071 3134 if (sess == NULL) { 3072 async_answer_0(c allid, ENOMEM);3135 async_answer_0(chandle, ENOMEM); 3073 3136 return NULL; 3074 3137 } … … 3076 3139 sess->iface = 0; 3077 3140 sess->mgmt = mgmt; 3078 sess->phone = ph one;3141 sess->phone = phandle; 3079 3142 sess->arg1 = 0; 3080 3143 sess->arg2 = 0; … … 3089 3152 3090 3153 /* Acknowledge the connected phone */ 3091 async_answer_0(c allid, EOK);3154 async_answer_0(chandle, EOK); 3092 3155 3093 3156 return sess; … … 3110 3173 async_sess_t *async_callback_receive_start(exch_mgmt_t mgmt, ipc_call_t *call) 3111 3174 { 3112 int phone = (int) IPC_GET_ARG5(*call); 3113 3114 if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || 3115 (phone < 0)) 3175 cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(*call); 3176 3177 if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) 3116 3178 return NULL; 3117 3179 … … 3122 3184 sess->iface = 0; 3123 3185 sess->mgmt = mgmt; 3124 sess->phone = ph one;3186 sess->phone = phandle; 3125 3187 sess->arg1 = 0; 3126 3188 sess->arg2 = 0; … … 3144 3206 } 3145 3207 3146 bool async_state_change_receive( ipc_callid_t *callid, sysarg_t *arg1,3208 bool async_state_change_receive(cap_handle_t *chandle, sysarg_t *arg1, 3147 3209 sysarg_t *arg2, sysarg_t *arg3) 3148 3210 { 3149 assert(c allid);3211 assert(chandle); 3150 3212 3151 3213 ipc_call_t call; 3152 *c allid= async_get_call(&call);3214 *chandle = async_get_call(&call); 3153 3215 3154 3216 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) … … 3165 3227 } 3166 3228 3167 int async_state_change_finalize( ipc_callid_t callid, async_exch_t *other_exch)3168 { 3169 return ipc_answer_1(c allid, EOK, other_exch->phone);3229 int async_state_change_finalize(cap_handle_t chandle, async_exch_t *other_exch) 3230 { 3231 return ipc_answer_1(chandle, EOK, other_exch->phone); 3170 3232 } 3171 3233
Note:
See TracChangeset
for help on using the changeset viewer.