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