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