[b419162] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[b419162] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
[b2951e2] | 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libc
|
---|
| 30 | * @{
|
---|
| 31 | * @}
|
---|
| 32 | */
|
---|
| 33 |
|
---|
[fadd381] | 34 | /** @addtogroup libcipc IPC
|
---|
[b2951e2] | 35 | * @brief HelenOS uspace IPC
|
---|
| 36 | * @{
|
---|
| 37 | * @ingroup libc
|
---|
| 38 | */
|
---|
| 39 | /** @file
|
---|
[6b10dab] | 40 | */
|
---|
[b419162] | 41 |
|
---|
[7ee6aff] | 42 | #include <ipc/ipc.h>
|
---|
[b419162] | 43 | #include <libc.h>
|
---|
[936351c1] | 44 | #include <malloc.h>
|
---|
| 45 | #include <errno.h>
|
---|
[d9c8c81] | 46 | #include <adt/list.h>
|
---|
[35509652] | 47 | #include <futex.h>
|
---|
[bc1f1c2] | 48 | #include <fibril.h>
|
---|
[b419162] | 49 |
|
---|
[36c9234] | 50 | /**
|
---|
| 51 | * Structures of this type are used for keeping track of sent asynchronous calls
|
---|
| 52 | * and queing unsent calls.
|
---|
[936351c1] | 53 | */
|
---|
| 54 | typedef struct {
|
---|
| 55 | link_t list;
|
---|
| 56 |
|
---|
| 57 | ipc_async_callback_t callback;
|
---|
| 58 | void *private;
|
---|
| 59 | union {
|
---|
| 60 | ipc_callid_t callid;
|
---|
| 61 | struct {
|
---|
[4c61e60] | 62 | ipc_call_t data;
|
---|
[936351c1] | 63 | int phoneid;
|
---|
| 64 | } msg;
|
---|
[8b243f2] | 65 | } u;
|
---|
[bc1f1c2] | 66 | fid_t fid; /**< Fibril waiting for sending this call. */
|
---|
[936351c1] | 67 | } async_call_t;
|
---|
| 68 |
|
---|
| 69 | LIST_INITIALIZE(dispatched_calls);
|
---|
[fc42b28] | 70 |
|
---|
[8b243f2] | 71 | /** List of asynchronous calls that were not accepted by kernel.
|
---|
| 72 | *
|
---|
| 73 | * It is protected by async_futex, because if the call cannot be sent into the
|
---|
| 74 | * kernel, the async framework is used automatically.
|
---|
[fc42b28] | 75 | */
|
---|
[8b243f2] | 76 | LIST_INITIALIZE(queued_calls);
|
---|
[936351c1] | 77 |
|
---|
[80649a91] | 78 | static atomic_t ipc_futex = FUTEX_INITIALIZER;
|
---|
[35509652] | 79 |
|
---|
[8b243f2] | 80 | /** Make a fast synchronous call.
|
---|
| 81 | *
|
---|
[2e51969] | 82 | * Only three payload arguments can be passed using this function. However, this
|
---|
| 83 | * function is faster than the generic ipc_call_sync_slow() because the payload
|
---|
| 84 | * is passed directly in registers.
|
---|
[8b243f2] | 85 | *
|
---|
| 86 | * @param phoneid Phone handle for the call.
|
---|
| 87 | * @param method Requested method.
|
---|
| 88 | * @param arg1 Service-defined payload argument.
|
---|
[2e51969] | 89 | * @param arg2 Service-defined payload argument.
|
---|
| 90 | * @param arg3 Service-defined payload argument.
|
---|
| 91 | * @param result1 If non-NULL, the return ARG1 will be stored there.
|
---|
| 92 | * @param result2 If non-NULL, the return ARG2 will be stored there.
|
---|
| 93 | * @param result3 If non-NULL, the return ARG3 will be stored there.
|
---|
| 94 | * @param result4 If non-NULL, the return ARG4 will be stored there.
|
---|
| 95 | * @param result5 If non-NULL, the return ARG5 will be stored there.
|
---|
[8b243f2] | 96 | *
|
---|
| 97 | * @return Negative values represent errors returned by IPC.
|
---|
| 98 | * Otherwise the RETVAL of the answer is returned.
|
---|
| 99 | */
|
---|
[2e51969] | 100 | int
|
---|
[96b02eb9] | 101 | ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1, sysarg_t arg2,
|
---|
| 102 | sysarg_t arg3, sysarg_t *result1, sysarg_t *result2, sysarg_t *result3,
|
---|
| 103 | sysarg_t *result4, sysarg_t *result5)
|
---|
[b419162] | 104 | {
|
---|
[4c61e60] | 105 | ipc_call_t resdata;
|
---|
[06502f7d] | 106 | int callres;
|
---|
| 107 |
|
---|
[2e51969] | 108 | callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
|
---|
| 109 | arg2, arg3, (sysarg_t) &resdata);
|
---|
[06502f7d] | 110 | if (callres)
|
---|
| 111 | return callres;
|
---|
[2e51969] | 112 | if (result1)
|
---|
| 113 | *result1 = IPC_GET_ARG1(resdata);
|
---|
| 114 | if (result2)
|
---|
| 115 | *result2 = IPC_GET_ARG2(resdata);
|
---|
| 116 | if (result3)
|
---|
| 117 | *result3 = IPC_GET_ARG3(resdata);
|
---|
| 118 | if (result4)
|
---|
| 119 | *result4 = IPC_GET_ARG4(resdata);
|
---|
| 120 | if (result5)
|
---|
| 121 | *result5 = IPC_GET_ARG5(resdata);
|
---|
| 122 |
|
---|
[06502f7d] | 123 | return IPC_GET_RETVAL(resdata);
|
---|
[b419162] | 124 | }
|
---|
| 125 |
|
---|
[2e51969] | 126 | /** Make a synchronous call transmitting 5 arguments of payload.
|
---|
[8b243f2] | 127 | *
|
---|
[228e490] | 128 | * @param phoneid Phone handle for the call.
|
---|
| 129 | * @param imethod Requested interface and method.
|
---|
| 130 | * @param arg1 Service-defined payload argument.
|
---|
| 131 | * @param arg2 Service-defined payload argument.
|
---|
| 132 | * @param arg3 Service-defined payload argument.
|
---|
| 133 | * @param arg4 Service-defined payload argument.
|
---|
| 134 | * @param arg5 Service-defined payload argument.
|
---|
| 135 | * @param result1 If non-NULL, storage for the first return argument.
|
---|
| 136 | * @param result2 If non-NULL, storage for the second return argument.
|
---|
| 137 | * @param result3 If non-NULL, storage for the third return argument.
|
---|
| 138 | * @param result4 If non-NULL, storage for the fourth return argument.
|
---|
| 139 | * @param result5 If non-NULL, storage for the fifth return argument.
|
---|
| 140 | *
|
---|
| 141 | * @return Negative value means IPC error.
|
---|
| 142 | * Otherwise the RETVAL of the answer.
|
---|
| 143 | *
|
---|
[8b243f2] | 144 | */
|
---|
[2e51969] | 145 | int
|
---|
[228e490] | 146 | ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
|
---|
[96b02eb9] | 147 | sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *result1,
|
---|
| 148 | sysarg_t *result2, sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
|
---|
[06502f7d] | 149 | {
|
---|
[4c61e60] | 150 | ipc_call_t data;
|
---|
[228e490] | 151 |
|
---|
| 152 | IPC_SET_IMETHOD(data, imethod);
|
---|
[06502f7d] | 153 | IPC_SET_ARG1(data, arg1);
|
---|
| 154 | IPC_SET_ARG2(data, arg2);
|
---|
| 155 | IPC_SET_ARG3(data, arg3);
|
---|
[2e51969] | 156 | IPC_SET_ARG4(data, arg4);
|
---|
| 157 | IPC_SET_ARG5(data, arg5);
|
---|
[228e490] | 158 |
|
---|
| 159 | int callres = __SYSCALL3(SYS_IPC_CALL_SYNC_SLOW, phoneid,
|
---|
| 160 | (sysarg_t) &data, (sysarg_t) &data);
|
---|
[06502f7d] | 161 | if (callres)
|
---|
| 162 | return callres;
|
---|
[228e490] | 163 |
|
---|
[06502f7d] | 164 | if (result1)
|
---|
| 165 | *result1 = IPC_GET_ARG1(data);
|
---|
| 166 | if (result2)
|
---|
| 167 | *result2 = IPC_GET_ARG2(data);
|
---|
| 168 | if (result3)
|
---|
| 169 | *result3 = IPC_GET_ARG3(data);
|
---|
[2e51969] | 170 | if (result4)
|
---|
| 171 | *result4 = IPC_GET_ARG4(data);
|
---|
| 172 | if (result5)
|
---|
| 173 | *result5 = IPC_GET_ARG5(data);
|
---|
[228e490] | 174 |
|
---|
[06502f7d] | 175 | return IPC_GET_RETVAL(data);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[8b243f2] | 178 | /** Syscall to send asynchronous message.
|
---|
| 179 | *
|
---|
[228e490] | 180 | * @param phoneid Phone handle for the call.
|
---|
| 181 | * @param data Call data with the request.
|
---|
| 182 | *
|
---|
| 183 | * @return Hash of the call or an error code.
|
---|
[8b243f2] | 184 | *
|
---|
| 185 | */
|
---|
| 186 | static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
|
---|
[936351c1] | 187 | {
|
---|
[3209923] | 188 | return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
|
---|
[936351c1] | 189 | }
|
---|
| 190 |
|
---|
[8b243f2] | 191 | /** Prolog to ipc_call_async_*() functions.
|
---|
| 192 | *
|
---|
| 193 | * @param private Argument for the answer/error callback.
|
---|
| 194 | * @param callback Answer/error callback.
|
---|
| 195 | *
|
---|
| 196 | * @return New, partially initialized async_call structure or NULL.
|
---|
| 197 | */
|
---|
| 198 | static inline async_call_t *ipc_prepare_async(void *private,
|
---|
| 199 | ipc_async_callback_t callback)
|
---|
[b419162] | 200 | {
|
---|
[936351c1] | 201 | async_call_t *call;
|
---|
[06502f7d] | 202 |
|
---|
[936351c1] | 203 | call = malloc(sizeof(*call));
|
---|
| 204 | if (!call) {
|
---|
[a784a96] | 205 | if (callback)
|
---|
| 206 | callback(private, ENOMEM, NULL);
|
---|
[c1d2c9d] | 207 | return NULL;
|
---|
[936351c1] | 208 | }
|
---|
[fc42b28] | 209 | call->callback = callback;
|
---|
| 210 | call->private = private;
|
---|
| 211 |
|
---|
[c1d2c9d] | 212 | return call;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[8b243f2] | 215 | /** Epilogue of ipc_call_async_*() functions.
|
---|
| 216 | *
|
---|
| 217 | * @param callid Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
|
---|
| 218 | * @param phoneid Phone handle through which the call was made.
|
---|
| 219 | * @param call async_call structure returned by ipc_prepare_async().
|
---|
[c3b25510] | 220 | * @param can_preempt If non-zero, the current fibril can be preempted in this
|
---|
| 221 | * call.
|
---|
[8b243f2] | 222 | */
|
---|
| 223 | static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
|
---|
| 224 | async_call_t *call, int can_preempt)
|
---|
[c1d2c9d] | 225 | {
|
---|
[d8b42fb2] | 226 | if (!call) { /* Nothing to do regardless if failed or not */
|
---|
| 227 | futex_up(&ipc_futex);
|
---|
| 228 | return;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
[b78d0bd] | 231 | if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
|
---|
[fc42b28] | 232 | futex_up(&ipc_futex);
|
---|
[06502f7d] | 233 | /* Call asynchronous handler with error code */
|
---|
[c1d2c9d] | 234 | if (call->callback)
|
---|
| 235 | call->callback(call->private, ENOENT, NULL);
|
---|
[936351c1] | 236 | free(call);
|
---|
[06502f7d] | 237 | return;
|
---|
| 238 | }
|
---|
[936351c1] | 239 |
|
---|
[b78d0bd] | 240 | if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
|
---|
[fc42b28] | 241 | futex_up(&ipc_futex);
|
---|
| 242 |
|
---|
[936351c1] | 243 | call->u.msg.phoneid = phoneid;
|
---|
[b1f51f0] | 244 |
|
---|
[fc42b28] | 245 | futex_down(&async_futex);
|
---|
[936351c1] | 246 | list_append(&call->list, &queued_calls);
|
---|
[fc42b28] | 247 |
|
---|
[b1f51f0] | 248 | if (can_preempt) {
|
---|
[bc1f1c2] | 249 | call->fid = fibril_get_id();
|
---|
[116d3f6f] | 250 | fibril_switch(FIBRIL_TO_MANAGER);
|
---|
[b1f51f0] | 251 | /* Async futex unlocked by previous call */
|
---|
| 252 | } else {
|
---|
[bc1f1c2] | 253 | call->fid = 0;
|
---|
[b1f51f0] | 254 | futex_up(&async_futex);
|
---|
| 255 | }
|
---|
[06502f7d] | 256 | return;
|
---|
| 257 | }
|
---|
[936351c1] | 258 | call->u.callid = callid;
|
---|
[8b243f2] | 259 | /* Add call to the list of dispatched calls */
|
---|
[936351c1] | 260 | list_append(&call->list, &dispatched_calls);
|
---|
[35509652] | 261 | futex_up(&ipc_futex);
|
---|
[c1d2c9d] | 262 |
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[8b243f2] | 265 | /** Make a fast asynchronous call.
|
---|
| 266 | *
|
---|
[3209923] | 267 | * This function can only handle four arguments of payload. It is, however,
|
---|
| 268 | * faster than the more generic ipc_call_async_slow().
|
---|
[8b243f2] | 269 | *
|
---|
| 270 | * Note that this function is a void function.
|
---|
| 271 | * During normal opertation, answering this call will trigger the callback.
|
---|
| 272 | * In case of fatal error, call the callback handler with the proper error code.
|
---|
| 273 | * If the call cannot be temporarily made, queue it.
|
---|
[c1d2c9d] | 274 | *
|
---|
[228e490] | 275 | * @param phoneid Phone handle for the call.
|
---|
| 276 | * @param imethod Requested interface and method.
|
---|
| 277 | * @param arg1 Service-defined payload argument.
|
---|
| 278 | * @param arg2 Service-defined payload argument.
|
---|
| 279 | * @param arg3 Service-defined payload argument.
|
---|
| 280 | * @param arg4 Service-defined payload argument.
|
---|
| 281 | * @param private Argument to be passed to the answer/error callback.
|
---|
| 282 | * @param callback Answer or error callback.
|
---|
| 283 | * @param can_preempt If non-zero, the current fibril will be preempted in
|
---|
| 284 | * case the kernel temporarily refuses to accept more
|
---|
| 285 | * asynchronous calls.
|
---|
| 286 | *
|
---|
[c1d2c9d] | 287 | */
|
---|
[228e490] | 288 | void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
|
---|
[96b02eb9] | 289 | sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private,
|
---|
[3209923] | 290 | ipc_async_callback_t callback, int can_preempt)
|
---|
[c1d2c9d] | 291 | {
|
---|
[d8b42fb2] | 292 | async_call_t *call = NULL;
|
---|
[228e490] | 293 |
|
---|
[d8b42fb2] | 294 | if (callback) {
|
---|
| 295 | call = ipc_prepare_async(private, callback);
|
---|
| 296 | if (!call)
|
---|
| 297 | return;
|
---|
| 298 | }
|
---|
[228e490] | 299 |
|
---|
[8b243f2] | 300 | /*
|
---|
| 301 | * We need to make sure that we get callid before another thread
|
---|
| 302 | * accesses the queue again.
|
---|
| 303 | */
|
---|
[c1d2c9d] | 304 | futex_down(&ipc_futex);
|
---|
[228e490] | 305 | ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
|
---|
| 306 | imethod, arg1, arg2, arg3, arg4);
|
---|
| 307 |
|
---|
[b78d0bd] | 308 | if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
|
---|
[d8b42fb2] | 309 | if (!call) {
|
---|
| 310 | call = ipc_prepare_async(private, callback);
|
---|
| 311 | if (!call)
|
---|
| 312 | return;
|
---|
| 313 | }
|
---|
[228e490] | 314 | IPC_SET_IMETHOD(call->u.msg.data, imethod);
|
---|
[c1d2c9d] | 315 | IPC_SET_ARG1(call->u.msg.data, arg1);
|
---|
| 316 | IPC_SET_ARG2(call->u.msg.data, arg2);
|
---|
[3209923] | 317 | IPC_SET_ARG3(call->u.msg.data, arg3);
|
---|
| 318 | IPC_SET_ARG4(call->u.msg.data, arg4);
|
---|
[8498915] | 319 | /*
|
---|
| 320 | * To achieve deterministic behavior, we always zero out the
|
---|
| 321 | * arguments that are beyond the limits of the fast version.
|
---|
| 322 | */
|
---|
| 323 | IPC_SET_ARG5(call->u.msg.data, 0);
|
---|
[c1d2c9d] | 324 | }
|
---|
[b1f51f0] | 325 | ipc_finish_async(callid, phoneid, call, can_preempt);
|
---|
[c1d2c9d] | 326 | }
|
---|
| 327 |
|
---|
[8b243f2] | 328 | /** Make an asynchronous call transmitting the entire payload.
|
---|
| 329 | *
|
---|
| 330 | * Note that this function is a void function.
|
---|
| 331 | * During normal opertation, answering this call will trigger the callback.
|
---|
| 332 | * In case of fatal error, call the callback handler with the proper error code.
|
---|
| 333 | * If the call cannot be temporarily made, queue it.
|
---|
| 334 | *
|
---|
[228e490] | 335 | * @param phoneid Phone handle for the call.
|
---|
| 336 | * @param imethod Requested interface and method.
|
---|
| 337 | * @param arg1 Service-defined payload argument.
|
---|
| 338 | * @param arg2 Service-defined payload argument.
|
---|
| 339 | * @param arg3 Service-defined payload argument.
|
---|
| 340 | * @param arg4 Service-defined payload argument.
|
---|
| 341 | * @param arg5 Service-defined payload argument.
|
---|
| 342 | * @param private Argument to be passed to the answer/error callback.
|
---|
| 343 | * @param callback Answer or error callback.
|
---|
| 344 | * @param can_preempt If non-zero, the current fibril will be preempted in
|
---|
| 345 | * case the kernel temporarily refuses to accept more
|
---|
| 346 | * asynchronous calls.
|
---|
[c1d2c9d] | 347 | *
|
---|
| 348 | */
|
---|
[228e490] | 349 | void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
|
---|
[96b02eb9] | 350 | sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
|
---|
[3209923] | 351 | ipc_async_callback_t callback, int can_preempt)
|
---|
[c1d2c9d] | 352 | {
|
---|
| 353 | async_call_t *call;
|
---|
| 354 | ipc_callid_t callid;
|
---|
| 355 |
|
---|
| 356 | call = ipc_prepare_async(private, callback);
|
---|
| 357 | if (!call)
|
---|
| 358 | return;
|
---|
| 359 |
|
---|
[228e490] | 360 | IPC_SET_IMETHOD(call->u.msg.data, imethod);
|
---|
[c1d2c9d] | 361 | IPC_SET_ARG1(call->u.msg.data, arg1);
|
---|
| 362 | IPC_SET_ARG2(call->u.msg.data, arg2);
|
---|
| 363 | IPC_SET_ARG3(call->u.msg.data, arg3);
|
---|
[3209923] | 364 | IPC_SET_ARG4(call->u.msg.data, arg4);
|
---|
| 365 | IPC_SET_ARG5(call->u.msg.data, arg5);
|
---|
[8b243f2] | 366 | /*
|
---|
[3209923] | 367 | * We need to make sure that we get callid before another thread
|
---|
| 368 | * accesses the queue again.
|
---|
[8b243f2] | 369 | */
|
---|
[c1d2c9d] | 370 | futex_down(&ipc_futex);
|
---|
| 371 | callid = _ipc_call_async(phoneid, &call->u.msg.data);
|
---|
| 372 |
|
---|
[b1f51f0] | 373 | ipc_finish_async(callid, phoneid, call, can_preempt);
|
---|
[b419162] | 374 | }
|
---|
| 375 |
|
---|
[06502f7d] | 376 |
|
---|
[8b243f2] | 377 | /** Answer a received call - fast version.
|
---|
[250717cc] | 378 | *
|
---|
[b74959bd] | 379 | * The fast answer makes use of passing retval and first four arguments in
|
---|
| 380 | * registers. If you need to return more, use the ipc_answer_slow() instead.
|
---|
[250717cc] | 381 | *
|
---|
[8b243f2] | 382 | * @param callid Hash of the call being answered.
|
---|
| 383 | * @param retval Return value.
|
---|
| 384 | * @param arg1 First return argument.
|
---|
| 385 | * @param arg2 Second return argument.
|
---|
[b74959bd] | 386 | * @param arg3 Third return argument.
|
---|
| 387 | * @param arg4 Fourth return argument.
|
---|
[250717cc] | 388 | *
|
---|
[8b243f2] | 389 | * @return Zero on success or a value from @ref errno.h on failure.
|
---|
[250717cc] | 390 | */
|
---|
[96b02eb9] | 391 | sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
|
---|
| 392 | sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[b419162] | 393 | {
|
---|
[b74959bd] | 394 | return __SYSCALL6(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2, arg3,
|
---|
| 395 | arg4);
|
---|
[b419162] | 396 | }
|
---|
[06502f7d] | 397 |
|
---|
[b74959bd] | 398 | /** Answer a received call - slow full version.
|
---|
[250717cc] | 399 | *
|
---|
[8b243f2] | 400 | * @param callid Hash of the call being answered.
|
---|
[b74959bd] | 401 | * @param retval Return value.
|
---|
| 402 | * @param arg1 First return argument.
|
---|
| 403 | * @param arg2 Second return argument.
|
---|
| 404 | * @param arg3 Third return argument.
|
---|
| 405 | * @param arg4 Fourth return argument.
|
---|
| 406 | * @param arg5 Fifth return argument.
|
---|
[250717cc] | 407 | *
|
---|
[8b243f2] | 408 | * @return Zero on success or a value from @ref errno.h on failure.
|
---|
[250717cc] | 409 | */
|
---|
[96b02eb9] | 410 | sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
|
---|
| 411 | sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
|
---|
[250717cc] | 412 | {
|
---|
[b74959bd] | 413 | ipc_call_t data;
|
---|
| 414 |
|
---|
| 415 | IPC_SET_RETVAL(data, retval);
|
---|
| 416 | IPC_SET_ARG1(data, arg1);
|
---|
| 417 | IPC_SET_ARG2(data, arg2);
|
---|
| 418 | IPC_SET_ARG3(data, arg3);
|
---|
| 419 | IPC_SET_ARG4(data, arg4);
|
---|
| 420 | IPC_SET_ARG5(data, arg5);
|
---|
| 421 |
|
---|
| 422 | return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
|
---|
[250717cc] | 423 | }
|
---|
| 424 |
|
---|
| 425 |
|
---|
[8b243f2] | 426 | /** Try to dispatch queued calls from the async queue. */
|
---|
[936351c1] | 427 | static void try_dispatch_queued_calls(void)
|
---|
| 428 | {
|
---|
| 429 | async_call_t *call;
|
---|
| 430 | ipc_callid_t callid;
|
---|
| 431 |
|
---|
[8b243f2] | 432 | /** @todo
|
---|
| 433 | * Integrate intelligently ipc_futex, so that it is locked during
|
---|
| 434 | * ipc_call_async_*(), until it is added to dispatched_calls.
|
---|
[fc42b28] | 435 | */
|
---|
| 436 | futex_down(&async_futex);
|
---|
[936351c1] | 437 | while (!list_empty(&queued_calls)) {
|
---|
[8b243f2] | 438 | call = list_get_instance(queued_calls.next, async_call_t, list);
|
---|
[8498915] | 439 | callid = _ipc_call_async(call->u.msg.phoneid,
|
---|
| 440 | &call->u.msg.data);
|
---|
[b78d0bd] | 441 | if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
|
---|
[936351c1] | 442 | break;
|
---|
[fc42b28] | 443 | }
|
---|
[936351c1] | 444 | list_remove(&call->list);
|
---|
[35509652] | 445 |
|
---|
[fc42b28] | 446 | futex_up(&async_futex);
|
---|
[bc1f1c2] | 447 | if (call->fid)
|
---|
| 448 | fibril_add_ready(call->fid);
|
---|
[fc42b28] | 449 |
|
---|
[b78d0bd] | 450 | if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
|
---|
[a784a96] | 451 | if (call->callback)
|
---|
| 452 | call->callback(call->private, ENOENT, NULL);
|
---|
[936351c1] | 453 | free(call);
|
---|
| 454 | } else {
|
---|
| 455 | call->u.callid = callid;
|
---|
[fc42b28] | 456 | futex_down(&ipc_futex);
|
---|
[936351c1] | 457 | list_append(&call->list, &dispatched_calls);
|
---|
[fc42b28] | 458 | futex_up(&ipc_futex);
|
---|
[936351c1] | 459 | }
|
---|
[fc42b28] | 460 | futex_down(&async_futex);
|
---|
[936351c1] | 461 | }
|
---|
[fc42b28] | 462 | futex_up(&async_futex);
|
---|
[936351c1] | 463 | }
|
---|
| 464 |
|
---|
[8b243f2] | 465 | /** Handle a received answer.
|
---|
[936351c1] | 466 | *
|
---|
[8b243f2] | 467 | * Find the hash of the answer and call the answer callback.
|
---|
[936351c1] | 468 | *
|
---|
[8b243f2] | 469 | * @todo Make it use hash table.
|
---|
| 470 | *
|
---|
| 471 | * @param callid Hash of the received answer.
|
---|
| 472 | * The answer has the same hash as the request OR'ed with
|
---|
| 473 | * the IPC_CALLID_ANSWERED bit.
|
---|
| 474 | * @param data Call data of the answer.
|
---|
[936351c1] | 475 | */
|
---|
[4c61e60] | 476 | static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
|
---|
[936351c1] | 477 | {
|
---|
| 478 | link_t *item;
|
---|
| 479 | async_call_t *call;
|
---|
| 480 |
|
---|
| 481 | callid &= ~IPC_CALLID_ANSWERED;
|
---|
| 482 |
|
---|
[35509652] | 483 | futex_down(&ipc_futex);
|
---|
[936351c1] | 484 | for (item = dispatched_calls.next; item != &dispatched_calls;
|
---|
[8b243f2] | 485 | item = item->next) {
|
---|
[936351c1] | 486 | call = list_get_instance(item, async_call_t, list);
|
---|
| 487 | if (call->u.callid == callid) {
|
---|
| 488 | list_remove(&call->list);
|
---|
[35509652] | 489 | futex_up(&ipc_futex);
|
---|
[a784a96] | 490 | if (call->callback)
|
---|
| 491 | call->callback(call->private,
|
---|
[8b243f2] | 492 | IPC_GET_RETVAL(*data), data);
|
---|
[a784a96] | 493 | free(call);
|
---|
[936351c1] | 494 | return;
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
[35509652] | 497 | futex_up(&ipc_futex);
|
---|
[936351c1] | 498 | }
|
---|
| 499 |
|
---|
| 500 |
|
---|
[8b243f2] | 501 | /** Wait for a first call to come.
|
---|
| 502 | *
|
---|
| 503 | * @param call Storage where the incoming call data will be stored.
|
---|
| 504 | * @param usec Timeout in microseconds
|
---|
| 505 | * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
|
---|
[b419162] | 506 | *
|
---|
[8b243f2] | 507 | * @return Hash of the call. Note that certain bits have special
|
---|
| 508 | * meaning. IPC_CALLID_ANSWERED will be set in an answer
|
---|
| 509 | * and IPC_CALLID_NOTIFICATION is used for notifications.
|
---|
| 510 | *
|
---|
[b419162] | 511 | */
|
---|
[80649a91] | 512 | ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
|
---|
[b419162] | 513 | {
|
---|
| 514 | ipc_callid_t callid;
|
---|
| 515 |
|
---|
[80649a91] | 516 | callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
|
---|
| 517 | /* Handle received answers */
|
---|
[fc42b28] | 518 | if (callid & IPC_CALLID_ANSWERED) {
|
---|
[80649a91] | 519 | handle_answer(callid, call);
|
---|
[fc42b28] | 520 | try_dispatch_queued_calls();
|
---|
| 521 | }
|
---|
[04a73cdf] | 522 |
|
---|
| 523 | return callid;
|
---|
| 524 | }
|
---|
| 525 |
|
---|
| 526 | /** Wait some time for an IPC call.
|
---|
| 527 | *
|
---|
[8b243f2] | 528 | * The call will return after an answer is received.
|
---|
| 529 | *
|
---|
| 530 | * @param call Storage where the incoming call data will be stored.
|
---|
| 531 | * @param usec Timeout in microseconds.
|
---|
[096ba7a] | 532 | *
|
---|
[8b243f2] | 533 | * @return Hash of the answer.
|
---|
[04a73cdf] | 534 | */
|
---|
| 535 | ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
|
---|
| 536 | {
|
---|
| 537 | ipc_callid_t callid;
|
---|
| 538 |
|
---|
| 539 | do {
|
---|
[2d22049] | 540 | callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
|
---|
[04a73cdf] | 541 | } while (callid & IPC_CALLID_ANSWERED);
|
---|
| 542 |
|
---|
| 543 | return callid;
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | /** Check if there is an IPC call waiting to be picked up.
|
---|
| 547 | *
|
---|
[8b243f2] | 548 | * @param call Storage where the incoming call will be stored.
|
---|
| 549 | * @return Hash of the answer.
|
---|
[04a73cdf] | 550 | */
|
---|
| 551 | ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
|
---|
| 552 | {
|
---|
| 553 | ipc_callid_t callid;
|
---|
| 554 |
|
---|
| 555 | do {
|
---|
[8b243f2] | 556 | callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
|
---|
| 557 | SYNCH_FLAGS_NON_BLOCKING);
|
---|
[06502f7d] | 558 | } while (callid & IPC_CALLID_ANSWERED);
|
---|
[936351c1] | 559 |
|
---|
[b419162] | 560 | return callid;
|
---|
| 561 | }
|
---|
[5106e98] | 562 |
|
---|
[057d21a] | 563 | /** Interrupt one thread of this task from waiting for IPC. */
|
---|
| 564 | void ipc_poke(void)
|
---|
| 565 | {
|
---|
| 566 | __SYSCALL0(SYS_IPC_POKE);
|
---|
| 567 | }
|
---|
| 568 |
|
---|
[51ec40f] | 569 | /** Ask destination to do a callback connection.
|
---|
[4c61e60] | 570 | *
|
---|
[8b243f2] | 571 | * @param phoneid Phone handle used for contacting the other side.
|
---|
| 572 | * @param arg1 Service-defined argument.
|
---|
| 573 | * @param arg2 Service-defined argument.
|
---|
[38c706cc] | 574 | * @param arg3 Service-defined argument.
|
---|
[124c061] | 575 | * @param taskhash Storage where the kernel will store an opaque
|
---|
| 576 | * identifier of the client task.
|
---|
| 577 | * @param phonehash Storage where the kernel will store an opaque
|
---|
[51ec40f] | 578 | * identifier of the phone that will be used for incoming
|
---|
[8b243f2] | 579 | * calls. This identifier can be used for connection
|
---|
| 580 | * tracking.
|
---|
| 581 | *
|
---|
| 582 | * @return Zero on success or a negative error code.
|
---|
[4c61e60] | 583 | */
|
---|
[38c706cc] | 584 | int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3,
|
---|
[124c061] | 585 | sysarg_t *taskhash, sysarg_t *phonehash)
|
---|
[5106e98] | 586 | {
|
---|
[38c706cc] | 587 | return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
|
---|
[124c061] | 588 | arg3, NULL, NULL, NULL, taskhash, phonehash);
|
---|
[5106e98] | 589 | }
|
---|
[11eae82] | 590 |
|
---|
[51ec40f] | 591 | /** Ask through phone for a new connection to some service.
|
---|
[4c61e60] | 592 | *
|
---|
[8b243f2] | 593 | * @param phoneid Phone handle used for contacting the other side.
|
---|
[51ec40f] | 594 | * @param arg1 User defined argument.
|
---|
| 595 | * @param arg2 User defined argument.
|
---|
[b61d47d] | 596 | * @param arg3 User defined argument.
|
---|
[51ec40f] | 597 | *
|
---|
[8b243f2] | 598 | * @return New phone handle on success or a negative error code.
|
---|
[4c61e60] | 599 | */
|
---|
[b61d47d] | 600 | int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3)
|
---|
[11eae82] | 601 | {
|
---|
[96b02eb9] | 602 | sysarg_t newphid;
|
---|
[4c61e60] | 603 | int res;
|
---|
| 604 |
|
---|
[19b28b0] | 605 | res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
|
---|
[90c35436] | 606 | NULL, NULL, NULL, NULL, &newphid);
|
---|
[4c61e60] | 607 | if (res)
|
---|
| 608 | return res;
|
---|
| 609 | return newphid;
|
---|
[11eae82] | 610 | }
|
---|
| 611 |
|
---|
[19b28b0] | 612 | /** Ask through phone for a new connection to some service.
|
---|
| 613 | *
|
---|
| 614 | * If the connection is not available at the moment, the
|
---|
| 615 | * call will block.
|
---|
| 616 | *
|
---|
| 617 | * @param phoneid Phone handle used for contacting the other side.
|
---|
| 618 | * @param arg1 User defined argument.
|
---|
| 619 | * @param arg2 User defined argument.
|
---|
| 620 | * @param arg3 User defined argument.
|
---|
| 621 | *
|
---|
| 622 | * @return New phone handle on success or a negative error code.
|
---|
| 623 | */
|
---|
| 624 | int ipc_connect_me_to_blocking(int phoneid, int arg1, int arg2, int arg3)
|
---|
| 625 | {
|
---|
[96b02eb9] | 626 | sysarg_t newphid;
|
---|
[19b28b0] | 627 | int res;
|
---|
| 628 |
|
---|
| 629 | res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
|
---|
| 630 | IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
|
---|
| 631 | if (res)
|
---|
| 632 | return res;
|
---|
| 633 | return newphid;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
[8b243f2] | 636 | /** Hang up a phone.
|
---|
| 637 | *
|
---|
| 638 | * @param phoneid Handle of the phone to be hung up.
|
---|
| 639 | *
|
---|
| 640 | * @return Zero on success or a negative error code.
|
---|
| 641 | */
|
---|
[7048773] | 642 | int ipc_hangup(int phoneid)
|
---|
| 643 | {
|
---|
| 644 | return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
|
---|
| 645 | }
|
---|
[6180b57] | 646 |
|
---|
[8b243f2] | 647 | /** Forward a received call to another destination.
|
---|
| 648 | *
|
---|
[228e490] | 649 | * @param callid Hash of the call to forward.
|
---|
| 650 | * @param phoneid Phone handle to use for forwarding.
|
---|
| 651 | * @param imethod New interface and method for the forwarded call.
|
---|
| 652 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 653 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 654 | * @param mode Flags specifying mode of the forward operation.
|
---|
[8b243f2] | 655 | *
|
---|
[228e490] | 656 | * @return Zero on success or an error code.
|
---|
[8b243f2] | 657 | *
|
---|
[90c35436] | 658 | * For non-system methods, the old method, arg1 and arg2 are rewritten by the
|
---|
| 659 | * new values. For system methods, the new method, arg1 and arg2 are written
|
---|
[b61d47d] | 660 | * to the old arg1, arg2 and arg3, respectivelly. Calls with immutable
|
---|
| 661 | * methods are forwarded verbatim.
|
---|
[8b243f2] | 662 | */
|
---|
[228e490] | 663 | int ipc_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
|
---|
[96b02eb9] | 664 | sysarg_t arg1, sysarg_t arg2, int mode)
|
---|
[043dcc27] | 665 | {
|
---|
[228e490] | 666 | return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
|
---|
[90c35436] | 667 | arg2, mode);
|
---|
[043dcc27] | 668 | }
|
---|
| 669 |
|
---|
[48daf64] | 670 |
|
---|
[228e490] | 671 | int ipc_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
|
---|
[96b02eb9] | 672 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
|
---|
[48daf64] | 673 | int mode)
|
---|
| 674 | {
|
---|
| 675 | ipc_call_t data;
|
---|
[228e490] | 676 |
|
---|
| 677 | IPC_SET_IMETHOD(data, imethod);
|
---|
[48daf64] | 678 | IPC_SET_ARG1(data, arg1);
|
---|
| 679 | IPC_SET_ARG2(data, arg2);
|
---|
| 680 | IPC_SET_ARG3(data, arg3);
|
---|
| 681 | IPC_SET_ARG4(data, arg4);
|
---|
| 682 | IPC_SET_ARG5(data, arg5);
|
---|
[228e490] | 683 |
|
---|
[5b9d80c5] | 684 | return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data, mode);
|
---|
[48daf64] | 685 | }
|
---|
| 686 |
|
---|
[27d293a] | 687 | /** Wrapper for making IPC_M_SHARE_IN calls.
|
---|
| 688 | *
|
---|
| 689 | * @param phoneid Phone that will be used to contact the receiving side.
|
---|
| 690 | * @param dst Destination address space area base.
|
---|
| 691 | * @param size Size of the destination address space area.
|
---|
| 692 | * @param arg User defined argument.
|
---|
| 693 | * @param flags Storage where the received flags will be stored. Can be
|
---|
| 694 | * NULL.
|
---|
| 695 | *
|
---|
| 696 | * @return Zero on success or a negative error code from errno.h.
|
---|
| 697 | */
|
---|
[96b02eb9] | 698 | int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
|
---|
[27d293a] | 699 | int *flags)
|
---|
| 700 | {
|
---|
[36e9cd1] | 701 | sysarg_t tmp_flags = 0;
|
---|
[96b02eb9] | 702 | int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
|
---|
| 703 | (sysarg_t) size, arg, NULL, &tmp_flags);
|
---|
[36e9cd1] | 704 |
|
---|
[27d293a] | 705 | if (flags)
|
---|
| 706 | *flags = tmp_flags;
|
---|
[36e9cd1] | 707 |
|
---|
[27d293a] | 708 | return res;
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 | /** Wrapper for answering the IPC_M_SHARE_IN calls.
|
---|
| 712 | *
|
---|
| 713 | * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
|
---|
| 714 | * so that the user doesn't have to remember the meaning of each IPC argument.
|
---|
| 715 | *
|
---|
| 716 | * @param callid Hash of the IPC_M_DATA_READ call to answer.
|
---|
| 717 | * @param src Source address space base.
|
---|
| 718 | * @param flags Flags to be used for sharing. Bits can be only cleared.
|
---|
| 719 | *
|
---|
| 720 | * @return Zero on success or a value from @ref errno.h on failure.
|
---|
| 721 | */
|
---|
[215e375] | 722 | int ipc_share_in_finalize(ipc_callid_t callid, void *src, int flags)
|
---|
[27d293a] | 723 | {
|
---|
[96b02eb9] | 724 | return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
|
---|
[27d293a] | 725 | }
|
---|
| 726 |
|
---|
| 727 | /** Wrapper for making IPC_M_SHARE_OUT calls.
|
---|
| 728 | *
|
---|
| 729 | * @param phoneid Phone that will be used to contact the receiving side.
|
---|
| 730 | * @param src Source address space area base address.
|
---|
| 731 | * @param flags Flags to be used for sharing. Bits can be only cleared.
|
---|
| 732 | *
|
---|
| 733 | * @return Zero on success or a negative error code from errno.h.
|
---|
| 734 | */
|
---|
[215e375] | 735 | int ipc_share_out_start(int phoneid, void *src, int flags)
|
---|
[27d293a] | 736 | {
|
---|
[96b02eb9] | 737 | return ipc_call_sync_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
|
---|
| 738 | (sysarg_t) flags);
|
---|
[27d293a] | 739 | }
|
---|
| 740 |
|
---|
| 741 | /** Wrapper for answering the IPC_M_SHARE_OUT calls.
|
---|
| 742 | *
|
---|
| 743 | * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
|
---|
| 744 | * so that the user doesn't have to remember the meaning of each IPC argument.
|
---|
| 745 | *
|
---|
| 746 | * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
|
---|
| 747 | * @param dst Destination address space area base address.
|
---|
| 748 | *
|
---|
| 749 | * @return Zero on success or a value from @ref errno.h on failure.
|
---|
| 750 | */
|
---|
[215e375] | 751 | int ipc_share_out_finalize(ipc_callid_t callid, void *dst)
|
---|
[27d293a] | 752 | {
|
---|
[96b02eb9] | 753 | return ipc_answer_1(callid, EOK, (sysarg_t) dst);
|
---|
[27d293a] | 754 | }
|
---|
| 755 |
|
---|
| 756 |
|
---|
[a55d5f9f] | 757 | /** Wrapper for making IPC_M_DATA_READ calls.
|
---|
| 758 | *
|
---|
| 759 | * @param phoneid Phone that will be used to contact the receiving side.
|
---|
| 760 | * @param dst Address of the beginning of the destination buffer.
|
---|
| 761 | * @param size Size of the destination buffer.
|
---|
| 762 | *
|
---|
| 763 | * @return Zero on success or a negative error code from errno.h.
|
---|
| 764 | */
|
---|
[215e375] | 765 | int ipc_data_read_start(int phoneid, void *dst, size_t size)
|
---|
[a55d5f9f] | 766 | {
|
---|
[96b02eb9] | 767 | return ipc_call_sync_2_0(phoneid, IPC_M_DATA_READ, (sysarg_t) dst,
|
---|
| 768 | (sysarg_t) size);
|
---|
[a55d5f9f] | 769 | }
|
---|
| 770 |
|
---|
| 771 | /** Wrapper for answering the IPC_M_DATA_READ calls.
|
---|
| 772 | *
|
---|
| 773 | * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
|
---|
| 774 | * so that the user doesn't have to remember the meaning of each IPC argument.
|
---|
| 775 | *
|
---|
| 776 | * @param callid Hash of the IPC_M_DATA_READ call to answer.
|
---|
| 777 | * @param src Source address for the IPC_M_DATA_READ call.
|
---|
| 778 | * @param size Size for the IPC_M_DATA_READ call. Can be smaller than
|
---|
| 779 | * the maximum size announced by the sender.
|
---|
| 780 | *
|
---|
| 781 | * @return Zero on success or a value from @ref errno.h on failure.
|
---|
| 782 | */
|
---|
[c61d34b] | 783 | int ipc_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
|
---|
[a55d5f9f] | 784 | {
|
---|
[96b02eb9] | 785 | return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
|
---|
[a55d5f9f] | 786 | }
|
---|
| 787 |
|
---|
[36d852c] | 788 | /** Wrapper for making IPC_M_DATA_WRITE calls.
|
---|
[183b4a0] | 789 | *
|
---|
[26f2af0] | 790 | * @param phoneid Phone that will be used to contact the receiving side.
|
---|
| 791 | * @param src Address of the beginning of the source buffer.
|
---|
| 792 | * @param size Size of the source buffer.
|
---|
| 793 | *
|
---|
| 794 | * @return Zero on success or a negative error code from errno.h.
|
---|
| 795 | */
|
---|
[c61d34b] | 796 | int ipc_data_write_start(int phoneid, const void *src, size_t size)
|
---|
[26f2af0] | 797 | {
|
---|
[96b02eb9] | 798 | return ipc_call_sync_2_0(phoneid, IPC_M_DATA_WRITE, (sysarg_t) src,
|
---|
| 799 | (sysarg_t) size);
|
---|
[26f2af0] | 800 | }
|
---|
| 801 |
|
---|
[36d852c] | 802 | /** Wrapper for answering the IPC_M_DATA_WRITE calls.
|
---|
[183b4a0] | 803 | *
|
---|
[36d852c] | 804 | * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
|
---|
[183b4a0] | 805 | * so that the user doesn't have to remember the meaning of each IPC argument.
|
---|
| 806 | *
|
---|
[36d852c] | 807 | * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
|
---|
| 808 | * @param dst Final destination address for the IPC_M_DATA_WRITE call.
|
---|
| 809 | * @param size Final size for the IPC_M_DATA_WRITE call.
|
---|
[183b4a0] | 810 | *
|
---|
| 811 | * @return Zero on success or a value from @ref errno.h on failure.
|
---|
| 812 | */
|
---|
[215e375] | 813 | int ipc_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
|
---|
[183b4a0] | 814 | {
|
---|
[96b02eb9] | 815 | return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
|
---|
[183b4a0] | 816 | }
|
---|
[9a1b20c] | 817 |
|
---|
| 818 | /** Connect to a task specified by id.
|
---|
[6b10dab] | 819 | *
|
---|
[9a1b20c] | 820 | */
|
---|
| 821 | int ipc_connect_kbox(task_id_t id)
|
---|
| 822 | {
|
---|
[6b10dab] | 823 | #ifdef __32_BITS__
|
---|
| 824 | sysarg64_t arg = (sysarg64_t) id;
|
---|
[9a1b20c] | 825 | return __SYSCALL1(SYS_IPC_CONNECT_KBOX, (sysarg_t) &arg);
|
---|
[6b10dab] | 826 | #endif
|
---|
| 827 |
|
---|
| 828 | #ifdef __64_BITS__
|
---|
| 829 | return __SYSCALL1(SYS_IPC_CONNECT_KBOX, (sysarg_t) id);
|
---|
| 830 | #endif
|
---|
[9a1b20c] | 831 | }
|
---|
[6b10dab] | 832 |
|
---|
[fadd381] | 833 | /** @}
|
---|
[b2951e2] | 834 | */
|
---|