[2d5a54f3] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[2d5a54f3] | 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.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[174156fd] | 29 | /** @addtogroup kernel_generic_ipc
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[2d5a54f3] | 35 | #include <arch.h>
|
---|
[63e27ef] | 36 | #include <assert.h>
|
---|
[2d5a54f3] | 37 | #include <errno.h>
|
---|
[44a7ee5] | 38 | #include <mem.h>
|
---|
[2d5a54f3] | 39 | #include <ipc/ipc.h>
|
---|
[c0699467] | 40 | #include <abi/ipc/methods.h>
|
---|
[2d5a54f3] | 41 | #include <ipc/sysipc.h>
|
---|
[e8039a86] | 42 | #include <ipc/sysipc_ops.h>
|
---|
[5d3ed34] | 43 | #include <ipc/sysipc_priv.h>
|
---|
[162f919] | 44 | #include <ipc/irq.h>
|
---|
[4e49572] | 45 | #include <ipc/ipcrsc.h>
|
---|
[fdd4898] | 46 | #include <ipc/event.h>
|
---|
[e028660] | 47 | #include <ipc/kbox.h>
|
---|
[057d21a] | 48 | #include <synch/waitq.h>
|
---|
[5626277] | 49 | #include <arch/interrupt.h>
|
---|
[e3c762cd] | 50 | #include <syscall/copy.h>
|
---|
[719a208] | 51 | #include <security/perm.h>
|
---|
[6b10dab] | 52 | #include <console/console.h>
|
---|
[253f35a1] | 53 | #include <print.h>
|
---|
[e2ab36f1] | 54 | #include <macros.h>
|
---|
[01c3bb4] | 55 | #include <cap/cap.h>
|
---|
[2d5a54f3] | 56 |
|
---|
[da1bafb] | 57 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
|
---|
[7918fce] | 58 |
|
---|
[228e490] | 59 | /** Decide if the interface and method is a system method.
|
---|
[8b243f2] | 60 | *
|
---|
[228e490] | 61 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 62 | *
|
---|
[228e490] | 63 | * @return True if the interface and method is a system
|
---|
| 64 | * interface and method.
|
---|
[8b243f2] | 65 | *
|
---|
| 66 | */
|
---|
[228e490] | 67 | static inline bool method_is_system(sysarg_t imethod)
|
---|
[2ba7810] | 68 | {
|
---|
[228e490] | 69 | if (imethod <= IPC_M_LAST_SYSTEM)
|
---|
[da1bafb] | 70 | return true;
|
---|
[a35b458] | 71 |
|
---|
[da1bafb] | 72 | return false;
|
---|
[2ba7810] | 73 | }
|
---|
| 74 |
|
---|
[228e490] | 75 | /** Decide if the message with this interface and method is forwardable.
|
---|
[2ba7810] | 76 | *
|
---|
[228e490] | 77 | * Some system messages may be forwarded, for some of them
|
---|
| 78 | * it is useless.
|
---|
[8b243f2] | 79 | *
|
---|
[228e490] | 80 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 81 | *
|
---|
[228e490] | 82 | * @return True if the interface and method is forwardable.
|
---|
[8b243f2] | 83 | *
|
---|
[2ba7810] | 84 | */
|
---|
[228e490] | 85 | static inline bool method_is_forwardable(sysarg_t imethod)
|
---|
[2ba7810] | 86 | {
|
---|
[228e490] | 87 | switch (imethod) {
|
---|
[7918fce] | 88 | case IPC_M_PHONE_HUNGUP:
|
---|
| 89 | /* This message is meant only for the original recipient. */
|
---|
[da1bafb] | 90 | return false;
|
---|
[7918fce] | 91 | default:
|
---|
[da1bafb] | 92 | return true;
|
---|
[7918fce] | 93 | }
|
---|
[2ba7810] | 94 | }
|
---|
| 95 |
|
---|
[228e490] | 96 | /** Decide if the message with this interface and method is immutable on forward.
|
---|
[0dc4258] | 97 | *
|
---|
[228e490] | 98 | * Some system messages may be forwarded but their content cannot be altered.
|
---|
[0dc4258] | 99 | *
|
---|
[228e490] | 100 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 101 | *
|
---|
[228e490] | 102 | * @return True if the interface and method is immutable on forward.
|
---|
[0dc4258] | 103 | *
|
---|
| 104 | */
|
---|
[228e490] | 105 | static inline bool method_is_immutable(sysarg_t imethod)
|
---|
[0dc4258] | 106 | {
|
---|
[228e490] | 107 | switch (imethod) {
|
---|
[072607b] | 108 | case IPC_M_PAGE_IN:
|
---|
[27d293a] | 109 | case IPC_M_SHARE_OUT:
|
---|
| 110 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 111 | case IPC_M_DATA_WRITE:
|
---|
| 112 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 113 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 114 | return true;
|
---|
[0dc4258] | 115 | default:
|
---|
[da1bafb] | 116 | return false;
|
---|
[0dc4258] | 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[6ff23ff] | 120 | /*
|
---|
[8b243f2] | 121 | * Functions that preprocess answer before sending it to the recepient.
|
---|
[6ff23ff] | 122 | */
|
---|
[8b243f2] | 123 |
|
---|
| 124 | /** Decide if the caller (e.g. ipc_answer()) should save the old call contents
|
---|
| 125 | * for answer_preprocess().
|
---|
| 126 | *
|
---|
[da1bafb] | 127 | * @param call Call structure to be decided.
|
---|
| 128 | *
|
---|
| 129 | * @return true if the old call contents should be saved.
|
---|
[8b243f2] | 130 | *
|
---|
[2d5a54f3] | 131 | */
|
---|
[da1bafb] | 132 | static inline bool answer_need_old(call_t *call)
|
---|
[2d5a54f3] | 133 | {
|
---|
[228e490] | 134 | switch (IPC_GET_IMETHOD(call->data)) {
|
---|
[7918fce] | 135 | case IPC_M_CONNECT_TO_ME:
|
---|
| 136 | case IPC_M_CONNECT_ME_TO:
|
---|
[072607b] | 137 | case IPC_M_PAGE_IN:
|
---|
[27d293a] | 138 | case IPC_M_SHARE_OUT:
|
---|
| 139 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 140 | case IPC_M_DATA_WRITE:
|
---|
| 141 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 142 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 143 | return true;
|
---|
[7918fce] | 144 | default:
|
---|
[da1bafb] | 145 | return false;
|
---|
[7918fce] | 146 | }
|
---|
[2d5a54f3] | 147 | }
|
---|
| 148 |
|
---|
[8b243f2] | 149 | /** Interpret process answer as control information.
|
---|
| 150 | *
|
---|
| 151 | * This function is called directly after sys_ipc_answer().
|
---|
[46fc2f9] | 152 | *
|
---|
[da1bafb] | 153 | * @param answer Call structure with the answer.
|
---|
| 154 | * @param olddata Saved data of the request.
|
---|
| 155 | *
|
---|
[cde999a] | 156 | * @return Return EOK on success or an error code.
|
---|
[8b243f2] | 157 | *
|
---|
[46fc2f9] | 158 | */
|
---|
[b7fd2a0] | 159 | errno_t answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
---|
[2d5a54f3] | 160 | {
|
---|
[b7fd2a0] | 161 | errno_t rc = EOK;
|
---|
[9956fad9] | 162 |
|
---|
[2405bb5] | 163 | spinlock_lock(&answer->forget_lock);
|
---|
| 164 | if (answer->forget) {
|
---|
| 165 | /*
|
---|
| 166 | * This is a forgotten call and answer->sender is not valid.
|
---|
| 167 | */
|
---|
| 168 | spinlock_unlock(&answer->forget_lock);
|
---|
[b1e6269] | 169 |
|
---|
[466e95f7] | 170 | SYSIPC_OP(answer_cleanup, answer, olddata);
|
---|
[2405bb5] | 171 | return rc;
|
---|
| 172 | } else {
|
---|
[63e27ef] | 173 | assert(answer->active);
|
---|
[20282ef3] | 174 |
|
---|
| 175 | /*
|
---|
| 176 | * Mark the call as inactive to prevent _ipc_answer_free_call()
|
---|
| 177 | * from attempting to remove the call from the active list
|
---|
| 178 | * itself.
|
---|
| 179 | */
|
---|
| 180 | answer->active = false;
|
---|
| 181 |
|
---|
| 182 | /*
|
---|
| 183 | * Remove the call from the sender's active call list.
|
---|
| 184 | * We enforce this locking order so that any potential
|
---|
| 185 | * concurrently executing forget operation is forced to
|
---|
| 186 | * release its active_calls_lock and lose the race to
|
---|
[1b20da0] | 187 | * forget this soon to be answered call.
|
---|
[20282ef3] | 188 | */
|
---|
| 189 | spinlock_lock(&answer->sender->active_calls_lock);
|
---|
| 190 | list_remove(&answer->ta_link);
|
---|
| 191 | spinlock_unlock(&answer->sender->active_calls_lock);
|
---|
[2405bb5] | 192 | }
|
---|
| 193 | spinlock_unlock(&answer->forget_lock);
|
---|
| 194 |
|
---|
[b7fd2a0] | 195 | if ((errno_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
|
---|
[2541646] | 196 | phone_t *phone = answer->caller_phone;
|
---|
| 197 | mutex_lock(&phone->lock);
|
---|
| 198 | if (phone->state == IPC_PHONE_CONNECTED) {
|
---|
| 199 | irq_spinlock_lock(&phone->callee->lock, true);
|
---|
| 200 | list_remove(&phone->link);
|
---|
[3dab10ae] | 201 | /* Drop callee->connected_phones reference */
|
---|
| 202 | kobject_put(phone->kobject);
|
---|
[2541646] | 203 | phone->state = IPC_PHONE_SLAMMED;
|
---|
[6769005] | 204 | phone->label = 0;
|
---|
[2541646] | 205 | irq_spinlock_unlock(&phone->callee->lock, true);
|
---|
[ca687ad] | 206 | }
|
---|
[2541646] | 207 | mutex_unlock(&phone->lock);
|
---|
[9f22213] | 208 | }
|
---|
[a35b458] | 209 |
|
---|
[53af6e8c] | 210 | if (!olddata)
|
---|
[9956fad9] | 211 | return rc;
|
---|
[e8039a86] | 212 |
|
---|
[466e95f7] | 213 | return SYSIPC_OP(answer_preprocess, answer, olddata);
|
---|
[2d5a54f3] | 214 | }
|
---|
| 215 |
|
---|
[8b243f2] | 216 | /** Called before the request is sent.
|
---|
| 217 | *
|
---|
[da1bafb] | 218 | * @param call Call structure with the request.
|
---|
| 219 | * @param phone Phone that the call will be sent through.
|
---|
| 220 | *
|
---|
| 221 | * @return Return 0 on success, ELIMIT or EPERM on error.
|
---|
[7c7aae16] | 222 | *
|
---|
| 223 | */
|
---|
[b7fd2a0] | 224 | static errno_t request_preprocess(call_t *call, phone_t *phone)
|
---|
[7c7aae16] | 225 | {
|
---|
[32e4643] | 226 | call->request_method = IPC_GET_IMETHOD(call->data);
|
---|
[466e95f7] | 227 | return SYSIPC_OP(request_preprocess, call, phone);
|
---|
[7c7aae16] | 228 | }
|
---|
| 229 |
|
---|
[6ff23ff] | 230 | /*
|
---|
[8b243f2] | 231 | * Functions called to process received call/answer before passing it to uspace.
|
---|
[6ff23ff] | 232 | */
|
---|
[2d5a54f3] | 233 |
|
---|
[8b243f2] | 234 | /** Do basic kernel processing of received call answer.
|
---|
| 235 | *
|
---|
[da1bafb] | 236 | * @param call Call structure with the answer.
|
---|
| 237 | *
|
---|
[8b243f2] | 238 | */
|
---|
[7c7aae16] | 239 | static void process_answer(call_t *call)
|
---|
[2d5a54f3] | 240 | {
|
---|
[b7fd2a0] | 241 | if (((errno_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
|
---|
[51ec40f] | 242 | (call->flags & IPC_CALL_FORWARDED))
|
---|
[9f22213] | 243 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[a35b458] | 244 |
|
---|
[466e95f7] | 245 | SYSIPC_OP(answer_process, call);
|
---|
[2d5a54f3] | 246 | }
|
---|
| 247 |
|
---|
[8b243f2] | 248 | /** Do basic kernel processing of received call request.
|
---|
| 249 | *
|
---|
[da1bafb] | 250 | * @param box Destination answerbox structure.
|
---|
| 251 | * @param call Call structure with the request.
|
---|
| 252 | *
|
---|
| 253 | * @return 0 if the call should be passed to userspace.
|
---|
| 254 | * @return -1 if the call should be ignored.
|
---|
[2d5a54f3] | 255 | *
|
---|
| 256 | */
|
---|
[51ec40f] | 257 | static int process_request(answerbox_t *box, call_t *call)
|
---|
[2d5a54f3] | 258 | {
|
---|
[466e95f7] | 259 | return SYSIPC_OP(request_process, call, box);
|
---|
[2d5a54f3] | 260 | }
|
---|
| 261 |
|
---|
[bc117a5] | 262 | /** Make a call over IPC and wait for reply.
|
---|
| 263 | *
|
---|
[48bcf49] | 264 | * @param handle Phone capability handle for the call.
|
---|
[05ffb41] | 265 | * @param data[inout] Structure with request/reply data.
|
---|
| 266 | * @param priv Value to be stored in call->priv.
|
---|
[bc117a5] | 267 | *
|
---|
| 268 | * @return EOK on success.
|
---|
| 269 | * @return ENOENT if there is no such phone handle.
|
---|
| 270 | *
|
---|
| 271 | */
|
---|
[eadaeae8] | 272 | errno_t
|
---|
| 273 | ipc_req_internal(cap_phone_handle_t handle, ipc_data_t *data, sysarg_t priv)
|
---|
[bc117a5] | 274 | {
|
---|
[48bcf49] | 275 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 276 | if (!kobj->phone)
|
---|
[bc117a5] | 277 | return ENOENT;
|
---|
[a35b458] | 278 |
|
---|
[bc117a5] | 279 | call_t *call = ipc_call_alloc(0);
|
---|
[ae66564] | 280 | call->priv = priv;
|
---|
[bc117a5] | 281 | memcpy(call->data.args, data->args, sizeof(data->args));
|
---|
[a35b458] | 282 |
|
---|
[b7fd2a0] | 283 | errno_t rc = request_preprocess(call, kobj->phone);
|
---|
[bc117a5] | 284 | if (!rc) {
|
---|
| 285 | #ifdef CONFIG_UDEBUG
|
---|
| 286 | udebug_stoppable_begin();
|
---|
| 287 | #endif
|
---|
| 288 |
|
---|
[d51a0d6] | 289 | kobject_add_ref(call->kobject);
|
---|
[48bcf49] | 290 | rc = ipc_call_sync(kobj->phone, call);
|
---|
[43e2cbc] | 291 | spinlock_lock(&call->forget_lock);
|
---|
| 292 | bool forgotten = call->forget;
|
---|
| 293 | spinlock_unlock(&call->forget_lock);
|
---|
[d51a0d6] | 294 | kobject_put(call->kobject);
|
---|
[bc117a5] | 295 |
|
---|
| 296 | #ifdef CONFIG_UDEBUG
|
---|
| 297 | udebug_stoppable_end();
|
---|
| 298 | #endif
|
---|
| 299 |
|
---|
[43e2cbc] | 300 | if (rc != EOK) {
|
---|
| 301 | if (!forgotten) {
|
---|
| 302 | /*
|
---|
| 303 | * There was an error, but it did not result
|
---|
| 304 | * in the call being forgotten. In fact, the
|
---|
| 305 | * call was not even sent. We are still
|
---|
| 306 | * its owners and are responsible for its
|
---|
| 307 | * deallocation.
|
---|
| 308 | */
|
---|
[d51a0d6] | 309 | kobject_put(call->kobject);
|
---|
[43e2cbc] | 310 | } else {
|
---|
| 311 | /*
|
---|
| 312 | * The call was forgotten and it changed hands.
|
---|
| 313 | * We are no longer expected to free it.
|
---|
| 314 | */
|
---|
[63e27ef] | 315 | assert(rc == EINTR);
|
---|
[43e2cbc] | 316 | }
|
---|
[48bcf49] | 317 | kobject_put(kobj);
|
---|
| 318 | return rc;
|
---|
[43e2cbc] | 319 | }
|
---|
[bc117a5] | 320 |
|
---|
| 321 | process_answer(call);
|
---|
| 322 | } else
|
---|
| 323 | IPC_SET_RETVAL(call->data, rc);
|
---|
[a35b458] | 324 |
|
---|
[bc117a5] | 325 | memcpy(data->args, call->data.args, sizeof(data->args));
|
---|
[d51a0d6] | 326 | kobject_put(call->kobject);
|
---|
[48bcf49] | 327 | kobject_put(kobj);
|
---|
[a35b458] | 328 |
|
---|
[bc117a5] | 329 | return EOK;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[97d17fe] | 332 | /** Check that the task did not exceed the allowed limit of asynchronous calls
|
---|
| 333 | * made over a phone.
|
---|
[2d5a54f3] | 334 | *
|
---|
[228e490] | 335 | * @param phone Phone to check the limit against.
|
---|
| 336 | *
|
---|
[da1bafb] | 337 | * @return 0 if limit not reached or -1 if limit exceeded.
|
---|
| 338 | *
|
---|
[2d5a54f3] | 339 | */
|
---|
[97d17fe] | 340 | static int check_call_limit(phone_t *phone)
|
---|
[2d5a54f3] | 341 | {
|
---|
[036e97c] | 342 | if (atomic_load(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
|
---|
[2d5a54f3] | 343 | return -1;
|
---|
[a35b458] | 344 |
|
---|
[2d5a54f3] | 345 | return 0;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[8b243f2] | 348 | /** Make a fast asynchronous call over IPC.
|
---|
[2d5a54f3] | 349 | *
|
---|
[7c0e1f5] | 350 | * This function can only handle three arguments of payload, but is faster than
|
---|
[3209923] | 351 | * the generic function sys_ipc_call_async_slow().
|
---|
[8b243f2] | 352 | *
|
---|
[48bcf49] | 353 | * @param handle Phone capability handle for the call.
|
---|
| 354 | * @param imethod Interface and method of the call.
|
---|
| 355 | * @param arg1 Service-defined payload argument.
|
---|
| 356 | * @param arg2 Service-defined payload argument.
|
---|
| 357 | * @param arg3 Service-defined payload argument.
|
---|
[7c0e1f5] | 358 | * @param label User-defined label.
|
---|
[da1bafb] | 359 | *
|
---|
[d7e245a] | 360 | * @return EOK on success.
|
---|
[cde999a] | 361 | * @return An error code on error.
|
---|
[da1bafb] | 362 | *
|
---|
[2d5a54f3] | 363 | */
|
---|
[eadaeae8] | 364 | sys_errno_t sys_ipc_call_async_fast(cap_phone_handle_t handle, sysarg_t imethod,
|
---|
[7c0e1f5] | 365 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t label)
|
---|
[2d5a54f3] | 366 | {
|
---|
[48bcf49] | 367 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 368 | if (!kobj)
|
---|
[d7e245a] | 369 | return ENOENT;
|
---|
[a35b458] | 370 |
|
---|
[48bcf49] | 371 | if (check_call_limit(kobj->phone)) {
|
---|
| 372 | kobject_put(kobj);
|
---|
[d7e245a] | 373 | return ELIMIT;
|
---|
[48bcf49] | 374 | }
|
---|
[a35b458] | 375 |
|
---|
[da1bafb] | 376 | call_t *call = ipc_call_alloc(0);
|
---|
[228e490] | 377 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[2d5a54f3] | 378 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 379 | IPC_SET_ARG2(call->data, arg2);
|
---|
[3209923] | 380 | IPC_SET_ARG3(call->data, arg3);
|
---|
[a35b458] | 381 |
|
---|
[8498915] | 382 | /*
|
---|
| 383 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 384 | * the limits of the fast version.
|
---|
| 385 | */
|
---|
| 386 | IPC_SET_ARG5(call->data, 0);
|
---|
[7c0e1f5] | 387 |
|
---|
| 388 | /* Set the user-defined label */
|
---|
[6769005] | 389 | call->data.answer_label = label;
|
---|
[a35b458] | 390 |
|
---|
[b7fd2a0] | 391 | errno_t res = request_preprocess(call, kobj->phone);
|
---|
[a35b458] | 392 |
|
---|
[da1bafb] | 393 | if (!res)
|
---|
[48bcf49] | 394 | ipc_call(kobj->phone, call);
|
---|
[7c7aae16] | 395 | else
|
---|
[48bcf49] | 396 | ipc_backsend_err(kobj->phone, call, res);
|
---|
[a35b458] | 397 |
|
---|
[48bcf49] | 398 | kobject_put(kobj);
|
---|
[474c68b] | 399 | return EOK;
|
---|
[2d5a54f3] | 400 | }
|
---|
| 401 |
|
---|
[8b243f2] | 402 | /** Make an asynchronous IPC call allowing to transmit the entire payload.
|
---|
| 403 | *
|
---|
[48bcf49] | 404 | * @param handle Phone capability for the call.
|
---|
[da1bafb] | 405 | * @param data Userspace address of call data with the request.
|
---|
[7c0e1f5] | 406 | * @param label User-defined label.
|
---|
[da1bafb] | 407 | *
|
---|
| 408 | * @return See sys_ipc_call_async_fast().
|
---|
[2d5a54f3] | 409 | *
|
---|
| 410 | */
|
---|
[eadaeae8] | 411 | sys_errno_t sys_ipc_call_async_slow(cap_phone_handle_t handle, ipc_data_t *data,
|
---|
[7c0e1f5] | 412 | sysarg_t label)
|
---|
[2d5a54f3] | 413 | {
|
---|
[48bcf49] | 414 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 415 | if (!kobj)
|
---|
[d7e245a] | 416 | return ENOENT;
|
---|
[4e49572] | 417 |
|
---|
[48bcf49] | 418 | if (check_call_limit(kobj->phone)) {
|
---|
| 419 | kobject_put(kobj);
|
---|
[d7e245a] | 420 | return ELIMIT;
|
---|
[48bcf49] | 421 | }
|
---|
[97d17fe] | 422 |
|
---|
[da1bafb] | 423 | call_t *call = ipc_call_alloc(0);
|
---|
[b7fd2a0] | 424 | errno_t rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 425 | sizeof(call->data.args));
|
---|
[a53ed3a] | 426 | if (rc != EOK) {
|
---|
[d51a0d6] | 427 | kobject_put(call->kobject);
|
---|
[48bcf49] | 428 | kobject_put(kobj);
|
---|
[b7fd2a0] | 429 | return (sys_errno_t) rc;
|
---|
[f58af46] | 430 | }
|
---|
[7c0e1f5] | 431 |
|
---|
| 432 | /* Set the user-defined label */
|
---|
[6769005] | 433 | call->data.answer_label = label;
|
---|
[a35b458] | 434 |
|
---|
[b7fd2a0] | 435 | errno_t res = request_preprocess(call, kobj->phone);
|
---|
[a35b458] | 436 |
|
---|
[da1bafb] | 437 | if (!res)
|
---|
[48bcf49] | 438 | ipc_call(kobj->phone, call);
|
---|
[7c7aae16] | 439 | else
|
---|
[48bcf49] | 440 | ipc_backsend_err(kobj->phone, call, res);
|
---|
[a35b458] | 441 |
|
---|
[48bcf49] | 442 | kobject_put(kobj);
|
---|
[474c68b] | 443 | return EOK;
|
---|
[2d5a54f3] | 444 | }
|
---|
| 445 |
|
---|
[da1bafb] | 446 | /** Forward a received call to another destination
|
---|
| 447 | *
|
---|
| 448 | * Common code for both the fast and the slow version.
|
---|
| 449 | *
|
---|
[01c3bb4] | 450 | * @param chandle Call handle of the forwarded call.
|
---|
| 451 | * @param phandle Phone handle to use for forwarding.
|
---|
[48bcf49] | 452 | * @param imethod New interface and method to use for the forwarded call.
|
---|
| 453 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 454 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 455 | * @param arg3 New value of the third argument for the forwarded call.
|
---|
| 456 | * @param arg4 New value of the fourth argument for the forwarded call.
|
---|
| 457 | * @param arg5 New value of the fifth argument for the forwarded call.
|
---|
| 458 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 459 | * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
|
---|
| 460 | * the function considers only the fast version arguments:
|
---|
| 461 | * i.e. arg1 and arg2.
|
---|
[da1bafb] | 462 | *
|
---|
| 463 | * @return 0 on succes, otherwise an error code.
|
---|
| 464 | *
|
---|
| 465 | * Warning: Make sure that ARG5 is not rewritten for certain system IPC
|
---|
| 466 | *
|
---|
[2ba7810] | 467 | */
|
---|
[eadaeae8] | 468 | static sys_errno_t sys_ipc_forward_common(cap_call_handle_t chandle,
|
---|
| 469 | cap_phone_handle_t phandle, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
|
---|
| 470 | sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
|
---|
[2ba7810] | 471 | {
|
---|
[01c3bb4] | 472 | kobject_t *ckobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
|
---|
| 473 | if (!ckobj)
|
---|
[2ba7810] | 474 | return ENOENT;
|
---|
[a35b458] | 475 |
|
---|
[01c3bb4] | 476 | call_t *call = ckobj->call;
|
---|
| 477 |
|
---|
[09024119] | 478 | ipc_data_t old;
|
---|
| 479 | bool need_old = answer_need_old(call);
|
---|
[f9841e69] | 480 | if (need_old)
|
---|
| 481 | old = call->data;
|
---|
[a35b458] | 482 |
|
---|
[09024119] | 483 | bool after_forward = false;
|
---|
[b7fd2a0] | 484 | errno_t rc;
|
---|
[05ffb41] | 485 |
|
---|
[01c3bb4] | 486 | kobject_t *pkobj = kobject_get(TASK, phandle, KOBJECT_TYPE_PHONE);
|
---|
| 487 | if (!pkobj) {
|
---|
[95a3082] | 488 | rc = ENOENT;
|
---|
| 489 | goto error;
|
---|
[c9fff17] | 490 | }
|
---|
[a35b458] | 491 |
|
---|
[228e490] | 492 | if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
|
---|
[95a3082] | 493 | rc = EPERM;
|
---|
| 494 | goto error;
|
---|
[2ba7810] | 495 | }
|
---|
[a35b458] | 496 |
|
---|
[95a3082] | 497 | call->flags |= IPC_CALL_FORWARDED;
|
---|
[a35b458] | 498 |
|
---|
[0dc4258] | 499 | /*
|
---|
[4e5dabf] | 500 | * User space is not allowed to change interface and method of system
|
---|
[228e490] | 501 | * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
|
---|
[4e5dabf] | 502 | * means of imethod, arg1, arg2 and arg3.
|
---|
[228e490] | 503 | * If the interface and method is immutable, don't change anything.
|
---|
[2ba7810] | 504 | */
|
---|
[228e490] | 505 | if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
|
---|
| 506 | if (method_is_system(IPC_GET_IMETHOD(call->data))) {
|
---|
[6769005] | 507 | if (IPC_GET_IMETHOD(call->data) ==
|
---|
| 508 | IPC_M_CONNECT_TO_ME) {
|
---|
| 509 | kobject_put((kobject_t *) call->priv);
|
---|
| 510 | call->priv = 0;
|
---|
| 511 | cap_free(TASK,
|
---|
| 512 | (cap_handle_t) IPC_GET_ARG5(call->data));
|
---|
| 513 | }
|
---|
[a35b458] | 514 |
|
---|
[228e490] | 515 | IPC_SET_ARG1(call->data, imethod);
|
---|
[0dc4258] | 516 | IPC_SET_ARG2(call->data, arg1);
|
---|
[b61d47d] | 517 | IPC_SET_ARG3(call->data, arg2);
|
---|
[a35b458] | 518 |
|
---|
[4e5dabf] | 519 | if (slow)
|
---|
[48daf64] | 520 | IPC_SET_ARG4(call->data, arg3);
|
---|
[a35b458] | 521 |
|
---|
[4e5dabf] | 522 | /*
|
---|
| 523 | * For system methods we deliberately don't
|
---|
| 524 | * overwrite ARG5.
|
---|
| 525 | */
|
---|
[0dc4258] | 526 | } else {
|
---|
[228e490] | 527 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[0dc4258] | 528 | IPC_SET_ARG1(call->data, arg1);
|
---|
[b61d47d] | 529 | IPC_SET_ARG2(call->data, arg2);
|
---|
[48daf64] | 530 | if (slow) {
|
---|
| 531 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 532 | IPC_SET_ARG4(call->data, arg4);
|
---|
| 533 | IPC_SET_ARG5(call->data, arg5);
|
---|
| 534 | }
|
---|
[0dc4258] | 535 | }
|
---|
[2ba7810] | 536 | }
|
---|
[a35b458] | 537 |
|
---|
[01c3bb4] | 538 | rc = ipc_forward(call, pkobj->phone, &TASK->answerbox, mode);
|
---|
[f9841e69] | 539 | if (rc != EOK) {
|
---|
| 540 | after_forward = true;
|
---|
| 541 | goto error;
|
---|
| 542 | }
|
---|
[95a3082] | 543 |
|
---|
[01c3bb4] | 544 | cap_free(TASK, chandle);
|
---|
| 545 | kobject_put(ckobj);
|
---|
| 546 | kobject_put(pkobj);
|
---|
[f9841e69] | 547 | return EOK;
|
---|
[95a3082] | 548 |
|
---|
[f9841e69] | 549 | error:
|
---|
[fcfa926b] | 550 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[9ef1b79b] | 551 | (void) answer_preprocess(call, need_old ? &old : NULL);
|
---|
[f9841e69] | 552 | if (after_forward)
|
---|
| 553 | _ipc_answer_free_call(call, false);
|
---|
| 554 | else
|
---|
| 555 | ipc_answer(&TASK->answerbox, call);
|
---|
| 556 |
|
---|
[931afbc] | 557 | cap_free(TASK, chandle);
|
---|
| 558 | kobject_put(ckobj);
|
---|
[01c3bb4] | 559 |
|
---|
| 560 | if (pkobj)
|
---|
| 561 | kobject_put(pkobj);
|
---|
[95a3082] | 562 | return rc;
|
---|
[2ba7810] | 563 | }
|
---|
| 564 |
|
---|
[48daf64] | 565 | /** Forward a received call to another destination - fast version.
|
---|
| 566 | *
|
---|
[228e490] | 567 | * In case the original interface and method is a system method, ARG1, ARG2
|
---|
| 568 | * and ARG3 are overwritten in the forwarded message with the new method and
|
---|
| 569 | * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
|
---|
| 570 | * are rewritten with the new interface and method, arg1 and arg2, respectively.
|
---|
| 571 | * Also note there is a set of immutable methods, for which the new method and
|
---|
| 572 | * arguments are not set and these values are ignored.
|
---|
[da1bafb] | 573 | *
|
---|
[01c3bb4] | 574 | * @param chandle Call handle of the call to forward.
|
---|
| 575 | * @param phandle Phone handle to use for forwarding.
|
---|
[48bcf49] | 576 | * @param imethod New interface and method to use for the forwarded call.
|
---|
| 577 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 578 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 579 | * @param mode Flags that specify mode of the forward operation.
|
---|
[da1bafb] | 580 | *
|
---|
| 581 | * @return 0 on succes, otherwise an error code.
|
---|
| 582 | *
|
---|
[48daf64] | 583 | */
|
---|
[eadaeae8] | 584 | sys_errno_t sys_ipc_forward_fast(cap_call_handle_t chandle,
|
---|
| 585 | cap_phone_handle_t phandle, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
|
---|
| 586 | unsigned int mode)
|
---|
[48daf64] | 587 | {
|
---|
[01c3bb4] | 588 | return sys_ipc_forward_common(chandle, phandle, imethod, arg1, arg2, 0,
|
---|
| 589 | 0, 0, mode, false);
|
---|
[48daf64] | 590 | }
|
---|
| 591 |
|
---|
| 592 | /** Forward a received call to another destination - slow version.
|
---|
| 593 | *
|
---|
| 594 | * This function is the slow verision of the sys_ipc_forward_fast interface.
|
---|
[228e490] | 595 | * It can copy all five new arguments and the new interface and method from
|
---|
| 596 | * the userspace. It naturally extends the functionality of the fast version.
|
---|
| 597 | * For system methods, it additionally stores the new value of arg3 to ARG4.
|
---|
| 598 | * For non-system methods, it additionally stores the new value of arg3, arg4
|
---|
| 599 | * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
|
---|
[da1bafb] | 600 | *
|
---|
[01c3bb4] | 601 | * @param chandle Call handle of the call to forward.
|
---|
| 602 | * @param phandle Phone handle to use for forwarding.
|
---|
| 603 | * @param data Userspace address of the new IPC data.
|
---|
| 604 | * @param mode Flags that specify mode of the forward operation.
|
---|
[da1bafb] | 605 | *
|
---|
| 606 | * @return 0 on succes, otherwise an error code.
|
---|
| 607 | *
|
---|
[48daf64] | 608 | */
|
---|
[eadaeae8] | 609 | sys_errno_t sys_ipc_forward_slow(cap_call_handle_t chandle,
|
---|
| 610 | cap_phone_handle_t phandle, ipc_data_t *data, unsigned int mode)
|
---|
[48daf64] | 611 | {
|
---|
| 612 | ipc_data_t newdata;
|
---|
[b7fd2a0] | 613 | errno_t rc = copy_from_uspace(&newdata.args, &data->args,
|
---|
[48daf64] | 614 | sizeof(newdata.args));
|
---|
[a53ed3a] | 615 | if (rc != EOK)
|
---|
[b7fd2a0] | 616 | return (sys_errno_t) rc;
|
---|
[a35b458] | 617 |
|
---|
[01c3bb4] | 618 | return sys_ipc_forward_common(chandle, phandle,
|
---|
[228e490] | 619 | IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
|
---|
[48daf64] | 620 | IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
|
---|
[01c3bb4] | 621 | IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
|
---|
[48daf64] | 622 | }
|
---|
| 623 |
|
---|
[8b243f2] | 624 | /** Answer an IPC call - fast version.
|
---|
| 625 | *
|
---|
| 626 | * This function can handle only two return arguments of payload, but is faster
|
---|
| 627 | * than the generic sys_ipc_answer().
|
---|
| 628 | *
|
---|
[01c3bb4] | 629 | * @param chandle Call handle to be answered.
|
---|
| 630 | * @param retval Return value of the answer.
|
---|
| 631 | * @param arg1 Service-defined return value.
|
---|
| 632 | * @param arg2 Service-defined return value.
|
---|
| 633 | * @param arg3 Service-defined return value.
|
---|
| 634 | * @param arg4 Service-defined return value.
|
---|
[da1bafb] | 635 | *
|
---|
| 636 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 637 | *
|
---|
| 638 | */
|
---|
[eadaeae8] | 639 | sys_errno_t sys_ipc_answer_fast(cap_call_handle_t chandle, sysarg_t retval,
|
---|
| 640 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 641 | {
|
---|
[01c3bb4] | 642 | kobject_t *kobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
|
---|
| 643 | if (!kobj)
|
---|
[2ba7810] | 644 | return ENOENT;
|
---|
[a35b458] | 645 |
|
---|
[01c3bb4] | 646 | call_t *call = kobj->call;
|
---|
[931afbc] | 647 | assert(!(call->flags & IPC_CALL_ANSWERED));
|
---|
[01c3bb4] | 648 |
|
---|
[da1bafb] | 649 | ipc_data_t saved_data;
|
---|
| 650 | bool saved;
|
---|
[a35b458] | 651 |
|
---|
[9f22213] | 652 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 653 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 654 | saved = true;
|
---|
| 655 | } else
|
---|
| 656 | saved = false;
|
---|
[a35b458] | 657 |
|
---|
[2d5a54f3] | 658 | IPC_SET_RETVAL(call->data, retval);
|
---|
| 659 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 660 | IPC_SET_ARG2(call->data, arg2);
|
---|
[b74959bd] | 661 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 662 | IPC_SET_ARG4(call->data, arg4);
|
---|
[a35b458] | 663 |
|
---|
[8498915] | 664 | /*
|
---|
| 665 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 666 | * the limits of the fast version.
|
---|
| 667 | */
|
---|
| 668 | IPC_SET_ARG5(call->data, 0);
|
---|
[b7fd2a0] | 669 | errno_t rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[a35b458] | 670 |
|
---|
[2d5a54f3] | 671 | ipc_answer(&TASK->answerbox, call);
|
---|
[01c3bb4] | 672 |
|
---|
| 673 | kobject_put(kobj);
|
---|
| 674 | cap_free(TASK, chandle);
|
---|
| 675 |
|
---|
[7c23af9] | 676 | return rc;
|
---|
[2d5a54f3] | 677 | }
|
---|
| 678 |
|
---|
[8b243f2] | 679 | /** Answer an IPC call.
|
---|
| 680 | *
|
---|
[01c3bb4] | 681 | * @param chandle Call handle to be answered.
|
---|
| 682 | * @param data Userspace address of call data with the answer.
|
---|
[da1bafb] | 683 | *
|
---|
| 684 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 685 | *
|
---|
| 686 | */
|
---|
[eadaeae8] | 687 | sys_errno_t sys_ipc_answer_slow(cap_call_handle_t chandle, ipc_data_t *data)
|
---|
[2d5a54f3] | 688 | {
|
---|
[01c3bb4] | 689 | kobject_t *kobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
|
---|
| 690 | if (!kobj)
|
---|
[2ba7810] | 691 | return ENOENT;
|
---|
[a35b458] | 692 |
|
---|
[01c3bb4] | 693 | call_t *call = kobj->call;
|
---|
[931afbc] | 694 | assert(!(call->flags & IPC_CALL_ANSWERED));
|
---|
[01c3bb4] | 695 |
|
---|
[da1bafb] | 696 | ipc_data_t saved_data;
|
---|
| 697 | bool saved;
|
---|
[a35b458] | 698 |
|
---|
[9f22213] | 699 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 700 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 701 | saved = true;
|
---|
| 702 | } else
|
---|
| 703 | saved = false;
|
---|
[a35b458] | 704 |
|
---|
[1b20da0] | 705 | errno_t rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 706 | sizeof(call->data.args));
|
---|
[a53ed3a] | 707 | if (rc != EOK) {
|
---|
[01c3bb4] | 708 | /*
|
---|
| 709 | * Republish the capability so that the call does not get lost.
|
---|
| 710 | */
|
---|
| 711 | cap_publish(TASK, chandle, kobj);
|
---|
[e3c762cd] | 712 | return rc;
|
---|
[01c3bb4] | 713 | }
|
---|
[a35b458] | 714 |
|
---|
[da1bafb] | 715 | rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[a35b458] | 716 |
|
---|
[2d5a54f3] | 717 | ipc_answer(&TASK->answerbox, call);
|
---|
[01c3bb4] | 718 |
|
---|
| 719 | kobject_put(kobj);
|
---|
| 720 | cap_free(TASK, chandle);
|
---|
| 721 |
|
---|
[7c23af9] | 722 | return rc;
|
---|
[2d5a54f3] | 723 | }
|
---|
| 724 |
|
---|
[8b243f2] | 725 | /** Hang up a phone.
|
---|
[2d5a54f3] | 726 | *
|
---|
[48bcf49] | 727 | * @param handle Phone capability handle of the phone to be hung up.
|
---|
[da1bafb] | 728 | *
|
---|
| 729 | * @return 0 on success or an error code.
|
---|
[8b243f2] | 730 | *
|
---|
[fbcfd458] | 731 | */
|
---|
[eadaeae8] | 732 | sys_errno_t sys_ipc_hangup(cap_phone_handle_t handle)
|
---|
[fbcfd458] | 733 | {
|
---|
[c25a39e] | 734 | kobject_t *kobj = cap_unpublish(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
[48bcf49] | 735 | if (!kobj)
|
---|
[c9fff17] | 736 | return ENOENT;
|
---|
[a35b458] | 737 |
|
---|
[b7fd2a0] | 738 | errno_t rc = ipc_phone_hangup(kobj->phone);
|
---|
[48bcf49] | 739 | kobject_put(kobj);
|
---|
[c25a39e] | 740 | cap_free(TASK, handle);
|
---|
[7565a4b] | 741 | return rc;
|
---|
[fbcfd458] | 742 | }
|
---|
| 743 |
|
---|
[8b243f2] | 744 | /** Wait for an incoming IPC call or an answer.
|
---|
[fbcfd458] | 745 | *
|
---|
[da1bafb] | 746 | * @param calldata Pointer to buffer where the call/answer data is stored.
|
---|
| 747 | * @param usec Timeout. See waitq_sleep_timeout() for explanation.
|
---|
| 748 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
|
---|
| 749 | * for explanation.
|
---|
| 750 | *
|
---|
[cde999a] | 751 | * @return An error code on error.
|
---|
[2d5a54f3] | 752 | */
|
---|
[b7fd2a0] | 753 | sys_errno_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
|
---|
[da1bafb] | 754 | unsigned int flags)
|
---|
[2d5a54f3] | 755 | {
|
---|
[acf6b55] | 756 | call_t *call = NULL;
|
---|
[a35b458] | 757 |
|
---|
[741fd16] | 758 | restart:
|
---|
[a35b458] | 759 |
|
---|
[741fd16] | 760 | #ifdef CONFIG_UDEBUG
|
---|
| 761 | udebug_stoppable_begin();
|
---|
[da1bafb] | 762 | #endif
|
---|
[a35b458] | 763 |
|
---|
[acf6b55] | 764 | errno_t rc = ipc_wait_for_call(&TASK->answerbox, usec,
|
---|
| 765 | flags | SYNCH_FLAGS_INTERRUPTIBLE, &call);
|
---|
[a35b458] | 766 |
|
---|
[741fd16] | 767 | #ifdef CONFIG_UDEBUG
|
---|
| 768 | udebug_stoppable_end();
|
---|
| 769 | #endif
|
---|
[01c3bb4] | 770 |
|
---|
[acf6b55] | 771 | if (rc != EOK)
|
---|
| 772 | return rc;
|
---|
| 773 |
|
---|
| 774 | assert(call);
|
---|
[a35b458] | 775 |
|
---|
[a1026da] | 776 | call->data.flags = call->flags;
|
---|
[5626277] | 777 | if (call->flags & IPC_CALL_NOTIF) {
|
---|
[6769005] | 778 | /* Set the request_label to the interrupt counter */
|
---|
| 779 | call->data.request_label = (sysarg_t) call->priv;
|
---|
[a35b458] | 780 |
|
---|
[6deb2cd] | 781 | call->data.cap_handle = CAP_NIL;
|
---|
[503ffce] | 782 |
|
---|
[43752b6] | 783 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[d51a0d6] | 784 | kobject_put(call->kobject);
|
---|
[a35b458] | 785 |
|
---|
[6deb2cd] | 786 | return EOK;
|
---|
[5626277] | 787 | }
|
---|
[a35b458] | 788 |
|
---|
[2d5a54f3] | 789 | if (call->flags & IPC_CALL_ANSWERED) {
|
---|
[7c7aae16] | 790 | process_answer(call);
|
---|
[a35b458] | 791 |
|
---|
[fbcfd458] | 792 | if (call->flags & IPC_CALL_DISCARD_ANSWER) {
|
---|
[d51a0d6] | 793 | kobject_put(call->kobject);
|
---|
[fbcfd458] | 794 | goto restart;
|
---|
| 795 | }
|
---|
[503ffce] | 796 |
|
---|
[6deb2cd] | 797 | call->data.cap_handle = CAP_NIL;
|
---|
[a35b458] | 798 |
|
---|
[1d81eb6] | 799 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[d51a0d6] | 800 | kobject_put(call->kobject);
|
---|
[a35b458] | 801 |
|
---|
[6deb2cd] | 802 | return EOK;
|
---|
[2d5a54f3] | 803 | }
|
---|
[a35b458] | 804 |
|
---|
[2d5a54f3] | 805 | if (process_request(&TASK->answerbox, call))
|
---|
| 806 | goto restart;
|
---|
[a35b458] | 807 |
|
---|
[eadaeae8] | 808 | cap_handle_t handle = CAP_NIL;
|
---|
[acf6b55] | 809 | rc = cap_alloc(TASK, &handle);
|
---|
[09d01f2] | 810 | if (rc != EOK) {
|
---|
[01c3bb4] | 811 | goto error;
|
---|
[bd55bbb] | 812 | }
|
---|
[a35b458] | 813 |
|
---|
[6deb2cd] | 814 | call->data.cap_handle = handle;
|
---|
| 815 |
|
---|
[01c3bb4] | 816 | /*
|
---|
| 817 | * Include phone hash of the caller in the request, copy the whole
|
---|
| 818 | * call->data, not only call->data.args.
|
---|
| 819 | */
|
---|
| 820 | rc = STRUCT_TO_USPACE(calldata, &call->data);
|
---|
| 821 | if (rc != EOK)
|
---|
| 822 | goto error;
|
---|
| 823 |
|
---|
| 824 | kobject_add_ref(call->kobject);
|
---|
| 825 | cap_publish(TASK, handle, call->kobject);
|
---|
[6deb2cd] | 826 | return EOK;
|
---|
[01c3bb4] | 827 |
|
---|
| 828 | error:
|
---|
[eadaeae8] | 829 | if (CAP_HANDLE_VALID(handle))
|
---|
[01c3bb4] | 830 | cap_free(TASK, handle);
|
---|
| 831 |
|
---|
| 832 | /*
|
---|
| 833 | * The callee will not receive this call and no one else has a chance to
|
---|
[a1026da] | 834 | * answer it. Set the IPC_CALL_AUTO_REPLY flag and return the EPARTY
|
---|
| 835 | * error code.
|
---|
[01c3bb4] | 836 | */
|
---|
| 837 | ipc_data_t saved_data;
|
---|
| 838 | bool saved;
|
---|
| 839 |
|
---|
| 840 | if (answer_need_old(call)) {
|
---|
| 841 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
| 842 | saved = true;
|
---|
| 843 | } else
|
---|
| 844 | saved = false;
|
---|
| 845 |
|
---|
| 846 | IPC_SET_RETVAL(call->data, EPARTY);
|
---|
| 847 | (void) answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[a1026da] | 848 | call->flags |= IPC_CALL_AUTO_REPLY;
|
---|
[01c3bb4] | 849 | ipc_answer(&TASK->answerbox, call);
|
---|
| 850 |
|
---|
| 851 | return rc;
|
---|
[2d5a54f3] | 852 | }
|
---|
[5626277] | 853 |
|
---|
[da1bafb] | 854 | /** Interrupt one thread from sys_ipc_wait_for_call().
|
---|
| 855 | *
|
---|
| 856 | */
|
---|
[b7fd2a0] | 857 | sys_errno_t sys_ipc_poke(void)
|
---|
[057d21a] | 858 | {
|
---|
[96c30c8] | 859 | waitq_wakeup(&TASK->answerbox.wq, WAKEUP_FIRST);
|
---|
[057d21a] | 860 | return EOK;
|
---|
| 861 | }
|
---|
| 862 |
|
---|
[8b243f2] | 863 | /** Connect an IRQ handler to a task.
|
---|
[2b017ba] | 864 | *
|
---|
[228e490] | 865 | * @param inr IRQ number.
|
---|
| 866 | * @param imethod Interface and method to be associated with the notification.
|
---|
| 867 | * @param ucode Uspace pointer to the top-half pseudocode.
|
---|
[da1bafb] | 868 | *
|
---|
[eadaeae8] | 869 | * @param[out] uspace_handle Uspace pointer to IRQ capability handle
|
---|
[9233e9d] | 870 | *
|
---|
[e9d15d9] | 871 | * @return EPERM
|
---|
| 872 | * @return Error code returned by ipc_irq_subscribe().
|
---|
[2b017ba] | 873 | *
|
---|
| 874 | */
|
---|
[eadaeae8] | 875 | sys_errno_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod,
|
---|
| 876 | irq_code_t *ucode, cap_irq_handle_t *uspace_handle)
|
---|
[5626277] | 877 | {
|
---|
[719a208] | 878 | if (!(perm_get(TASK) & PERM_IRQ_REG))
|
---|
[2bb8648] | 879 | return EPERM;
|
---|
[a35b458] | 880 |
|
---|
[9233e9d] | 881 | return ipc_irq_subscribe(&TASK->answerbox, inr, imethod, ucode, uspace_handle);
|
---|
[5626277] | 882 | }
|
---|
| 883 |
|
---|
[8b243f2] | 884 | /** Disconnect an IRQ handler from a task.
|
---|
| 885 | *
|
---|
[eadaeae8] | 886 | * @param handle IRQ capability handle.
|
---|
[da1bafb] | 887 | *
|
---|
| 888 | * @return Zero on success or EPERM on error.
|
---|
[2b017ba] | 889 | *
|
---|
| 890 | */
|
---|
[eadaeae8] | 891 | sys_errno_t sys_ipc_irq_unsubscribe(cap_irq_handle_t handle)
|
---|
[5626277] | 892 | {
|
---|
[719a208] | 893 | if (!(perm_get(TASK) & PERM_IRQ_REG))
|
---|
[2bb8648] | 894 | return EPERM;
|
---|
[a35b458] | 895 |
|
---|
[eadaeae8] | 896 | ipc_irq_unsubscribe(&TASK->answerbox, handle);
|
---|
[a35b458] | 897 |
|
---|
[5626277] | 898 | return 0;
|
---|
| 899 | }
|
---|
[b45c443] | 900 |
|
---|
[0016674] | 901 | /** Syscall connect to a task by ID
|
---|
[da1bafb] | 902 | *
|
---|
[569a51a] | 903 | * @return Error code.
|
---|
[9a1b20c] | 904 | *
|
---|
| 905 | */
|
---|
[eadaeae8] | 906 | sys_errno_t sys_ipc_connect_kbox(task_id_t *uspace_taskid,
|
---|
| 907 | cap_phone_handle_t *uspace_phone)
|
---|
[9a1b20c] | 908 | {
|
---|
| 909 | #ifdef CONFIG_UDEBUG
|
---|
[0016674] | 910 | task_id_t taskid;
|
---|
[eadaeae8] | 911 | cap_phone_handle_t phone;
|
---|
[a35b458] | 912 |
|
---|
[b7fd2a0] | 913 | errno_t rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(task_id_t));
|
---|
[569a51a] | 914 | if (rc == EOK) {
|
---|
| 915 | rc = ipc_connect_kbox((task_id_t) taskid, &phone);
|
---|
| 916 | }
|
---|
[a35b458] | 917 |
|
---|
[569a51a] | 918 | if (rc == EOK) {
|
---|
| 919 | rc = copy_to_uspace(uspace_phone, &phone, sizeof(cap_handle_t));
|
---|
[0016674] | 920 | if (rc != EOK) {
|
---|
| 921 | // Clean up the phone on failure.
|
---|
| 922 | sys_ipc_hangup(phone);
|
---|
| 923 | }
|
---|
[569a51a] | 924 | }
|
---|
[a35b458] | 925 |
|
---|
[b7fd2a0] | 926 | return (sys_errno_t) rc;
|
---|
[6b10dab] | 927 | #else
|
---|
[b7fd2a0] | 928 | return (sys_errno_t) ENOTSUP;
|
---|
[6b10dab] | 929 | #endif
|
---|
| 930 | }
|
---|
| 931 |
|
---|
[cc73a8a1] | 932 | /** @}
|
---|
[b45c443] | 933 | */
|
---|