Changeset 241f1985 in mainline for uspace/lib/c
- Timestamp:
- 2019-08-31T10:45:17Z (6 years ago)
- Children:
- 102f641
- Parents:
- f92b315
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-23 22:04:34)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-31 10:45:17)
- Location:
- uspace/lib/c
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async/client.c
rf92b315 r241f1985 99 99 #include <async.h> 100 100 #include "../private/async.h" 101 #include "../private/ns.h"102 101 #undef _LIBC_ASYNC_C_ 103 102 … … 114 113 #include <stdbool.h> 115 114 #include <stdlib.h> 115 #include <stdatomic.h> 116 116 #include <mem.h> 117 #include <stdlib.h>118 117 #include <macros.h> 119 118 #include <as.h> … … 174 173 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3) 175 174 { 176 async_sess_t *session = (async_sess_t *) malloc(sizeof(async_sess_t));175 async_sess_t *session = (async_sess_t *) calloc(1, sizeof(async_sess_t)); 177 176 178 177 if (session != NULL) { 179 session->iface = 0;180 178 session->mgmt = mgmt; 181 179 session->phone = phone; … … 189 187 list_initialize(&session->exch_list); 190 188 fibril_mutex_initialize(&session->mutex); 191 atomic_set(&session->refcnt, 0);192 &session.exchanges = 0;193 189 } else { 194 190 errno = ENOMEM; … … 198 194 } 199 195 200 int async_session_phone(async_sess_t *sess)196 cap_phone_handle_t async_session_phone(async_sess_t *sess) 201 197 { 202 198 return sess->phone; … … 859 855 } 860 856 861 async_sess_t *sess = create_session(phone, mgmt, iface, arg2, arg3);857 async_sess_t *sess = create_session(phone, iface & IFACE_EXCHANGE_MASK, iface, arg2, arg3); 862 858 if (sess == NULL) { 863 859 ipc_hangup(phone); 864 860 } 861 sess->iface = iface; 865 862 866 863 return sess; … … 912 909 if (rc != EOK) { 913 910 errno = rc; 914 free(sess);915 911 return NULL; 916 912 } 917 913 918 async_sess_t *sess = create_session(phone, mgmt, iface, arg2, arg3);914 async_sess_t *sess = create_session(phone, iface & IFACE_EXCHANGE_MASK, iface, arg2, arg3); 919 915 if (sess == NULL) { 920 916 ipc_hangup(phone); 921 917 } 918 sess->iface = iface; 922 919 923 920 return sess; -
uspace/lib/c/generic/async/server.c
rf92b315 r241f1985 216 216 } 217 217 218 static async_client_conn_t implicit_connection = NULL; 218 static async_port_handler_t implicit_connection = NULL; 219 220 /** Setter for implicit_connection function pointer. 221 * 222 * @param conn Function that will implement a new connection fibril for 223 * unrouted calls. 224 * 225 */ 226 void async_set_implicit_connection(async_port_handler_t conn) 227 { 228 assert(implicit_connection == NULL); 229 implicit_connection = conn; 230 } 231 232 219 233 static fibril_rmutex_t client_mutex; 220 234 static hash_table_t client_hash_table; … … 969 983 return; 970 984 } else if (implicit_connection != NULL) { 971 async_new_connection(call->in_task_id, call->in_phone_hash, 972 callid, call, implicit_connection, NULL); 985 connection_t *conn = calloc(1, sizeof(connection_t)); 986 if (!conn) { 987 ipc_answer_0(call->cap_handle, ENOMEM); 988 return; 989 } 990 991 async_new_connection(conn, call->task_id, call, implicit_connection, NULL); 973 992 return; 974 993 } … … 1749 1768 async_sess_t *sess = create_session(phandle, mgmt, 0, 0, 0); 1750 1769 if (sess == NULL) { 1751 ipc_hangup(ph one);1770 ipc_hangup(phandle); 1752 1771 async_answer_0(&call, errno); 1753 1772 } else { -
uspace/lib/c/generic/ns.c
rf92b315 r241f1985 59 59 } 60 60 61 /*62 * XXX ns does not know about session_primary, so we create an extra session for63 * actual communicaton64 */65 static async_sess_t *sess_primary = NULL;66 67 61 errno_t service_register(service_t service, iface_t iface, 68 62 async_port_handler_t handler, void *data) … … 96 90 async_set_fallback_port_handler(handler, data); 97 91 98 async_sess_t *sess = get_session_primary(); 99 if (sess == NULL) 100 return EIO; 101 102 async_exch_t *exch = async_exchange_begin(sess); 92 async_exch_t *exch = ns_exchange_begin(); 103 93 104 94 ipc_call_t answer; … … 106 96 errno_t rc = async_connect_to_me(exch, INTERFACE_ANY, service, 0); 107 97 108 async_exchange_end(exch);98 ns_exchange_end(exch); 109 99 110 100 if (rc != EOK) { … … 138 128 async_sess_args_set(sess, iface, arg3, 0); 139 129 140 return csess;130 return sess; 141 131 } 142 132 … … 164 154 errno_t ns_ping(void) 165 155 { 166 async_exch_t *exch = ns_exchange_begin( sess);156 async_exch_t *exch = ns_exchange_begin(); 167 157 errno_t rc = async_req_0_0(exch, NS_PING); 168 158 ns_exchange_end(exch); -
uspace/lib/c/generic/private/async.h
rf92b315 r241f1985 42 42 #include <time.h> 43 43 #include <stdbool.h> 44 #include <stdatomic.h> 44 45 45 46 /** Session data */ … … 106 107 107 108 extern void async_reply_received(ipc_call_t *); 108 extern async_sess_t *create_session( int, exch_mgmt_t,109 extern async_sess_t *create_session(cap_phone_handle_t, exch_mgmt_t, 109 110 sysarg_t, sysarg_t, sysarg_t); 110 extern int async_session_phone(async_sess_t *);111 extern cap_phone_handle_t async_session_phone(async_sess_t *); 111 112 112 113 #endif -
uspace/lib/c/generic/private/taskman.h
rf92b315 r241f1985 36 36 #define LIBC_PRIVATE_TASKMAN_H_ 37 37 38 #include <async.h>38 #include "async.h" 39 39 40 40 extern async_sess_t *session_taskman; -
uspace/lib/c/generic/task.c
rf92b315 r241f1985 385 385 if (rc == EOK || rc == EINTR) { 386 386 if (wait->flags & TASK_WAIT_EXIT && texit) 387 *texit = ipc_get_arg1( wait->result);387 *texit = ipc_get_arg1(&wait->result); 388 388 if (wait->flags & TASK_WAIT_RETVAL && retval) 389 *retval = ipc_get_arg2( wait->result);389 *retval = ipc_get_arg2(&wait->result); 390 390 391 391 } … … 394 394 /* Is there another wait to be done? Wait for it! */ 395 395 int old_flags = wait->flags; 396 wait->flags = ipc_get_arg3( wait->result);396 wait->flags = ipc_get_arg3(&wait->result); 397 397 if (wait->flags != 0 && (old_flags & TASK_WAIT_BOTH)) { 398 398 rc = task_setup_wait(wait->tid, wait); … … 438 438 return EIO; 439 439 440 errno_t rc = (int)async_req_2_0(exch, TASKMAN_RETVAL, val, wait_for_exit);440 errno_t rc = async_req_2_0(exch, TASKMAN_RETVAL, val, wait_for_exit); 441 441 taskman_exchange_end(exch); 442 442 -
uspace/lib/c/generic/task_event.c
rf92b315 r241f1985 37 37 #include <macros.h> 38 38 #include <task.h> 39 #include <assert.h> 39 40 40 41 #include "private/taskman.h" … … 42 43 static task_event_handler_t task_event_handler = NULL; 43 44 44 static void taskman_task_event(ipc_call id_t iid, ipc_call_t *icall)45 static void taskman_task_event(ipc_call_t *icall) 45 46 { 46 47 task_id_t tid = (task_id_t) 47 MERGE_LOUP32( IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall));48 int flags = IPC_GET_ARG3(*icall);49 task_exit_t texit = IPC_GET_ARG4(*icall);50 int retval = IPC_GET_ARG5(*icall);48 MERGE_LOUP32(ipc_get_arg1(icall), ipc_get_arg2(icall)); 49 int flags = ipc_get_arg3(icall); 50 task_exit_t texit = ipc_get_arg4(icall); 51 int retval = ipc_get_arg5(icall); 51 52 52 53 task_event_handler(tid, flags, texit, retval); 53 54 54 async_answer_0(i id, EOK);55 async_answer_0(icall, EOK); 55 56 } 56 57 57 static void taskman_event_conn(ipc_call id_t iid, ipc_call_t *icall, void *arg)58 static void taskman_event_conn(ipc_call_t *icall, void *arg) 58 59 { 59 60 /* Accept connection */ 60 async_answer_0(i id, EOK);61 async_answer_0(icall, EOK); 61 62 62 63 while (true) { 63 64 ipc_call_t call; 64 ipc_callid_t callid = async_get_call(&call); 65 66 if (!IPC_GET_IMETHOD(call)) { 65 66 if (!async_get_call(&call) || !ipc_get_imethod(&call)) { 67 67 /* Hangup, end of game */ 68 68 break; 69 69 } 70 70 71 switch ( IPC_GET_IMETHOD(call)) {71 switch (ipc_get_imethod(&call)) { 72 72 case TASKMAN_EV_TASK: 73 taskman_task_event( callid,&call);73 taskman_task_event(&call); 74 74 break; 75 75 default: 76 async_answer_0( callid, ENOTSUP);76 async_answer_0(&call, ENOTSUP); 77 77 break; 78 78 } … … 83 83 * Blocks, calls handler in another fibril 84 84 */ 85 int task_register_event_handler(task_event_handler_t handler, bool past_events)85 errno_t task_register_event_handler(task_event_handler_t handler, bool past_events) 86 86 { 87 87 /* … … 97 97 aid_t req = async_send_1(exch, TASKMAN_EVENT_CALLBACK, past_events, NULL); 98 98 99 int rc = async_connect_to_me(exch, 0, 0, 0, taskman_event_conn, NULL); 99 port_id_t port; 100 errno_t rc = async_create_callback_port(exch, INTERFACE_TASKMAN_CB, 0, 0, 101 taskman_event_conn, NULL, &port); 100 102 taskman_exchange_end(exch); 101 103 … … 104 106 } 105 107 106 sysarg_t retval;108 errno_t retval; 107 109 async_wait_for(req, &retval); 108 110 return retval; -
uspace/lib/c/generic/taskman.c
rf92b315 r241f1985 103 103 assert(exch); 104 104 105 async_sess_t *sess = async_connect_me_to( EXCHANGE_ATOMIC,106 exch, TASKMAN_CONNECT_TO_NS, 0, 0);105 async_sess_t *sess = async_connect_me_to(exch, INTERFACE_NS, 106 TASKMAN_CONNECT_TO_NS, 0); 107 107 async_exchange_end(exch); 108 108 … … 116 116 117 117 async_exch_t *exch = async_exchange_begin(session_taskman); 118 async_sess_t *sess = async_connect_me_to( EXCHANGE_SERIALIZE,119 exch, TASKMAN_CONNECT_TO_LOADER, 0, 0);118 async_sess_t *sess = async_connect_me_to(exch, INTERFACE_LOADER, 119 TASKMAN_CONNECT_TO_LOADER, 0); 120 120 async_exchange_end(exch); 121 121 … … 136 136 * @return EOK on success, otherwise propagated error code 137 137 */ 138 int taskman_intro_loader(void)138 errno_t taskman_intro_loader(void) 139 139 { 140 140 assert(session_taskman); 141 141 142 142 async_exch_t *exch = async_exchange_begin(session_taskman); 143 int rc = async_connect_to_me( 144 exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL); 143 errno_t rc = async_connect_to_me(exch, INTERFACE_LOADER, TASKMAN_LOADER_CALLBACK, 0); 145 144 async_exchange_end(exch); 146 145 … … 152 151 * @return EOK on success, otherwise propagated error code 153 152 */ 154 int taskman_intro_ns(void)153 errno_t taskman_intro_ns(void) 155 154 { 156 155 assert(session_taskman); … … 159 158 aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL); 160 159 161 int rc = async_connect_to_me(exch, 0, 0, 0, NULL, NULL);160 errno_t rc = async_connect_to_me(exch, INTERFACE_NS, 0, 0); 162 161 taskman_exchange_end(exch); 163 162 … … 166 165 } 167 166 168 sysarg_t retval;167 errno_t retval; 169 168 async_wait_for(req, &retval); 170 169 return retval; -
uspace/lib/c/generic/taskman_noasync.c
rf92b315 r241f1985 33 33 */ 34 34 35 #define LIBC_ASYNC_C_36 #include <ipc/ipc.h>37 35 #include "private/async.h" 38 36 #include "private/taskman.h" 39 #undef LIBC_ASYNC_C_ 37 38 #undef _LIBC_ASYNC_H_ 39 #include <ipc/ipc.h> 40 #define _LIBC_ASYNC_H_ 40 41 41 42 #include <errno.h> … … 50 51 * @return EOK on success, otherwise propagated error code 51 52 */ 52 int taskman_intro_ns_noasync(void)53 errno_t taskman_intro_ns_noasync(void) 53 54 { 54 55 assert(session_taskman); 55 int phone = async_session_phone(session_taskman);56 cap_phone_handle_t phone = async_session_phone(session_taskman); 56 57 57 ipc_call_async_0(phone, TASKMAN_I_AM_NS, NULL , NULL, false);58 ipc_call_async_0(phone, TASKMAN_I_AM_NS, NULL); 58 59 59 ipc_call_async_3(phone, IPC_M_CONNECT_TO_ME, 0, 0, 0, NULL , NULL, false);60 ipc_call_async_3(phone, IPC_M_CONNECT_TO_ME, 0, 0, 0, NULL); 60 61 61 62 /* … … 67 68 68 69 69 void task_retval_noasync( int retval)70 void task_retval_noasync(errno_t retval) 70 71 { 71 72 assert(session_taskman); 72 int phone = async_session_phone(session_taskman);73 cap_phone_handle_t phone = async_session_phone(session_taskman); 73 74 74 75 /* Just send it and don't wait for an answer. */ 75 ipc_call_async_2(phone, TASKMAN_RETVAL, retval, false, 76 NULL, NULL, false); 76 ipc_call_async_2(phone, TASKMAN_RETVAL, retval, false, NULL); 77 77 } 78 78 -
uspace/lib/c/include/adt/dyn_array.h
rf92b315 r241f1985 41 41 typedef struct { 42 42 /** Data buffer of array */ 43 uint8_t*_data;43 void *_data; 44 44 /** Size on bytes of a single item */ 45 45 size_t _item_size; -
uspace/lib/c/include/async.h
rf92b315 r241f1985 132 132 extern void async_put_client_data_by_id(task_id_t); 133 133 134 extern void async_set_implicit_connection(async_ client_conn_t);134 extern void async_set_implicit_connection(async_port_handler_t); 135 135 136 136 extern errno_t async_create_port(iface_t, async_port_handler_t, void *, -
uspace/lib/c/include/ipc/services.h
rf92b315 r241f1985 55 55 #define SERVICE_NAME_CLIPBOARD "clipboard" 56 56 #define SERVICE_NAME_CORECFG "corecfg" 57 #define SERVICE_NAME_DEVMAN "devman" 57 58 #define SERVICE_NAME_DHCP "net/dhcp" 58 59 #define SERVICE_NAME_DNSR "net/dnsr" -
uspace/lib/c/include/task.h
rf92b315 r241f1985 76 76 77 77 /* Implemented in task_event.c */ 78 extern int task_register_event_handler(task_event_handler_t, bool);78 extern errno_t task_register_event_handler(task_event_handler_t, bool); 79 79 80 80 #endif -
uspace/lib/c/include/taskman.h
rf92b315 r241f1985 40 40 /* Internal functions to be used by loader only */ 41 41 extern async_sess_t *taskman_get_session(void); 42 extern int taskman_intro_loader(void);42 extern errno_t taskman_intro_loader(void); 43 43 44 44 /* Internal functions to be used by NS only */ 45 extern int taskman_intro_ns(void);45 extern errno_t taskman_intro_ns(void); 46 46 47 47 #endif
Note:
See TracChangeset
for help on using the changeset viewer.