[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 |
|
---|
[cc73a8a1] | 29 | /** @addtogroup genericipc
|
---|
[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>
|
---|
[2d5a54f3] | 55 |
|
---|
[da1bafb] | 56 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
|
---|
[7918fce] | 57 |
|
---|
[228e490] | 58 | /** Decide if the interface and method is a system method.
|
---|
[8b243f2] | 59 | *
|
---|
[228e490] | 60 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 61 | *
|
---|
[228e490] | 62 | * @return True if the interface and method is a system
|
---|
| 63 | * interface and method.
|
---|
[8b243f2] | 64 | *
|
---|
| 65 | */
|
---|
[228e490] | 66 | static inline bool method_is_system(sysarg_t imethod)
|
---|
[2ba7810] | 67 | {
|
---|
[228e490] | 68 | if (imethod <= IPC_M_LAST_SYSTEM)
|
---|
[da1bafb] | 69 | return true;
|
---|
| 70 |
|
---|
| 71 | return false;
|
---|
[2ba7810] | 72 | }
|
---|
| 73 |
|
---|
[228e490] | 74 | /** Decide if the message with this interface and method is forwardable.
|
---|
[2ba7810] | 75 | *
|
---|
[228e490] | 76 | * Some system messages may be forwarded, for some of them
|
---|
| 77 | * it is useless.
|
---|
[8b243f2] | 78 | *
|
---|
[228e490] | 79 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 80 | *
|
---|
[228e490] | 81 | * @return True if the interface and method is forwardable.
|
---|
[8b243f2] | 82 | *
|
---|
[2ba7810] | 83 | */
|
---|
[228e490] | 84 | static inline bool method_is_forwardable(sysarg_t imethod)
|
---|
[2ba7810] | 85 | {
|
---|
[228e490] | 86 | switch (imethod) {
|
---|
[7918fce] | 87 | case IPC_M_PHONE_HUNGUP:
|
---|
| 88 | /* This message is meant only for the original recipient. */
|
---|
[da1bafb] | 89 | return false;
|
---|
[7918fce] | 90 | default:
|
---|
[da1bafb] | 91 | return true;
|
---|
[7918fce] | 92 | }
|
---|
[2ba7810] | 93 | }
|
---|
| 94 |
|
---|
[228e490] | 95 | /** Decide if the message with this interface and method is immutable on forward.
|
---|
[0dc4258] | 96 | *
|
---|
[228e490] | 97 | * Some system messages may be forwarded but their content cannot be altered.
|
---|
[0dc4258] | 98 | *
|
---|
[228e490] | 99 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 100 | *
|
---|
[228e490] | 101 | * @return True if the interface and method is immutable on forward.
|
---|
[0dc4258] | 102 | *
|
---|
| 103 | */
|
---|
[228e490] | 104 | static inline bool method_is_immutable(sysarg_t imethod)
|
---|
[0dc4258] | 105 | {
|
---|
[228e490] | 106 | switch (imethod) {
|
---|
[072607b] | 107 | case IPC_M_PAGE_IN:
|
---|
[27d293a] | 108 | case IPC_M_SHARE_OUT:
|
---|
| 109 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 110 | case IPC_M_DATA_WRITE:
|
---|
| 111 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 112 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 113 | return true;
|
---|
[0dc4258] | 114 | default:
|
---|
[da1bafb] | 115 | return false;
|
---|
[0dc4258] | 116 | }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[2d5a54f3] | 119 |
|
---|
[8b243f2] | 120 | /***********************************************************************
|
---|
| 121 | * Functions that preprocess answer before sending it to the recepient.
|
---|
| 122 | ***********************************************************************/
|
---|
| 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 | *
|
---|
[9956fad9] | 156 | * @return Return EOK on success or a negative error code.
|
---|
[8b243f2] | 157 | *
|
---|
[46fc2f9] | 158 | */
|
---|
[5d3ed34] | 159 | int answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
---|
[2d5a54f3] | 160 | {
|
---|
[9956fad9] | 161 | int rc = EOK;
|
---|
| 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
|
---|
| 187 | * forget this soon to be answered call.
|
---|
| 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 |
|
---|
[6c441cf8] | 195 | if ((native_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);
|
---|
| 201 | phone->state = IPC_PHONE_SLAMMED;
|
---|
| 202 | irq_spinlock_unlock(&phone->callee->lock, true);
|
---|
[ca687ad] | 203 | }
|
---|
[2541646] | 204 | mutex_unlock(&phone->lock);
|
---|
[9f22213] | 205 | }
|
---|
[da1bafb] | 206 |
|
---|
[53af6e8c] | 207 | if (!olddata)
|
---|
[9956fad9] | 208 | return rc;
|
---|
[e8039a86] | 209 |
|
---|
[466e95f7] | 210 | return SYSIPC_OP(answer_preprocess, answer, olddata);
|
---|
[2d5a54f3] | 211 | }
|
---|
| 212 |
|
---|
[8b243f2] | 213 | /** Called before the request is sent.
|
---|
| 214 | *
|
---|
[da1bafb] | 215 | * @param call Call structure with the request.
|
---|
| 216 | * @param phone Phone that the call will be sent through.
|
---|
| 217 | *
|
---|
| 218 | * @return Return 0 on success, ELIMIT or EPERM on error.
|
---|
[7c7aae16] | 219 | *
|
---|
| 220 | */
|
---|
[9a1b20c] | 221 | static int request_preprocess(call_t *call, phone_t *phone)
|
---|
[7c7aae16] | 222 | {
|
---|
[32e4643] | 223 | call->request_method = IPC_GET_IMETHOD(call->data);
|
---|
[466e95f7] | 224 | return SYSIPC_OP(request_preprocess, call, phone);
|
---|
[7c7aae16] | 225 | }
|
---|
| 226 |
|
---|
[8b243f2] | 227 | /*******************************************************************************
|
---|
| 228 | * Functions called to process received call/answer before passing it to uspace.
|
---|
| 229 | *******************************************************************************/
|
---|
[2d5a54f3] | 230 |
|
---|
[8b243f2] | 231 | /** Do basic kernel processing of received call answer.
|
---|
| 232 | *
|
---|
[da1bafb] | 233 | * @param call Call structure with the answer.
|
---|
| 234 | *
|
---|
[8b243f2] | 235 | */
|
---|
[7c7aae16] | 236 | static void process_answer(call_t *call)
|
---|
[2d5a54f3] | 237 | {
|
---|
[6c441cf8] | 238 | if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
|
---|
[51ec40f] | 239 | (call->flags & IPC_CALL_FORWARDED))
|
---|
[9f22213] | 240 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[da1bafb] | 241 |
|
---|
[466e95f7] | 242 | SYSIPC_OP(answer_process, call);
|
---|
[2d5a54f3] | 243 | }
|
---|
| 244 |
|
---|
[691d8d8] | 245 |
|
---|
[8b243f2] | 246 | /** Do basic kernel processing of received call request.
|
---|
| 247 | *
|
---|
[da1bafb] | 248 | * @param box Destination answerbox structure.
|
---|
| 249 | * @param call Call structure with the request.
|
---|
| 250 | *
|
---|
| 251 | * @return 0 if the call should be passed to userspace.
|
---|
| 252 | * @return -1 if the call should be ignored.
|
---|
[2d5a54f3] | 253 | *
|
---|
| 254 | */
|
---|
[51ec40f] | 255 | static int process_request(answerbox_t *box, call_t *call)
|
---|
[2d5a54f3] | 256 | {
|
---|
[466e95f7] | 257 | return SYSIPC_OP(request_process, call, box);
|
---|
[2d5a54f3] | 258 | }
|
---|
| 259 |
|
---|
[bc117a5] | 260 | /** Make a call over IPC and wait for reply.
|
---|
| 261 | *
|
---|
[48bcf49] | 262 | * @param handle Phone capability handle for the call.
|
---|
[05ffb41] | 263 | * @param data[inout] Structure with request/reply data.
|
---|
| 264 | * @param priv Value to be stored in call->priv.
|
---|
[bc117a5] | 265 | *
|
---|
| 266 | * @return EOK on success.
|
---|
| 267 | * @return ENOENT if there is no such phone handle.
|
---|
| 268 | *
|
---|
| 269 | */
|
---|
[48bcf49] | 270 | int ipc_req_internal(cap_handle_t handle, ipc_data_t *data, sysarg_t priv)
|
---|
[bc117a5] | 271 | {
|
---|
[48bcf49] | 272 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 273 | if (!kobj->phone)
|
---|
[bc117a5] | 274 | return ENOENT;
|
---|
| 275 |
|
---|
| 276 | call_t *call = ipc_call_alloc(0);
|
---|
[ae66564] | 277 | call->priv = priv;
|
---|
[bc117a5] | 278 | memcpy(call->data.args, data->args, sizeof(data->args));
|
---|
| 279 |
|
---|
[48bcf49] | 280 | int rc = request_preprocess(call, kobj->phone);
|
---|
[bc117a5] | 281 | if (!rc) {
|
---|
| 282 | #ifdef CONFIG_UDEBUG
|
---|
| 283 | udebug_stoppable_begin();
|
---|
| 284 | #endif
|
---|
| 285 |
|
---|
[43e2cbc] | 286 | ipc_call_hold(call);
|
---|
[48bcf49] | 287 | rc = ipc_call_sync(kobj->phone, call);
|
---|
[43e2cbc] | 288 | spinlock_lock(&call->forget_lock);
|
---|
| 289 | bool forgotten = call->forget;
|
---|
| 290 | spinlock_unlock(&call->forget_lock);
|
---|
| 291 | ipc_call_release(call);
|
---|
[bc117a5] | 292 |
|
---|
| 293 | #ifdef CONFIG_UDEBUG
|
---|
| 294 | udebug_stoppable_end();
|
---|
| 295 | #endif
|
---|
| 296 |
|
---|
[43e2cbc] | 297 | if (rc != EOK) {
|
---|
| 298 | if (!forgotten) {
|
---|
| 299 | /*
|
---|
| 300 | * There was an error, but it did not result
|
---|
| 301 | * in the call being forgotten. In fact, the
|
---|
| 302 | * call was not even sent. We are still
|
---|
| 303 | * its owners and are responsible for its
|
---|
| 304 | * deallocation.
|
---|
| 305 | */
|
---|
| 306 | ipc_call_free(call);
|
---|
| 307 | } else {
|
---|
| 308 | /*
|
---|
| 309 | * The call was forgotten and it changed hands.
|
---|
| 310 | * We are no longer expected to free it.
|
---|
| 311 | */
|
---|
[63e27ef] | 312 | assert(rc == EINTR);
|
---|
[43e2cbc] | 313 | }
|
---|
[48bcf49] | 314 | kobject_put(kobj);
|
---|
| 315 | return rc;
|
---|
[43e2cbc] | 316 | }
|
---|
[bc117a5] | 317 |
|
---|
| 318 | process_answer(call);
|
---|
| 319 | } else
|
---|
| 320 | IPC_SET_RETVAL(call->data, rc);
|
---|
| 321 |
|
---|
| 322 | memcpy(data->args, call->data.args, sizeof(data->args));
|
---|
| 323 | ipc_call_free(call);
|
---|
[48bcf49] | 324 | kobject_put(kobj);
|
---|
[bc117a5] | 325 |
|
---|
| 326 | return EOK;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[97d17fe] | 329 | /** Check that the task did not exceed the allowed limit of asynchronous calls
|
---|
| 330 | * made over a phone.
|
---|
[2d5a54f3] | 331 | *
|
---|
[228e490] | 332 | * @param phone Phone to check the limit against.
|
---|
| 333 | *
|
---|
[da1bafb] | 334 | * @return 0 if limit not reached or -1 if limit exceeded.
|
---|
| 335 | *
|
---|
[2d5a54f3] | 336 | */
|
---|
[97d17fe] | 337 | static int check_call_limit(phone_t *phone)
|
---|
[2d5a54f3] | 338 | {
|
---|
[97d17fe] | 339 | if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
|
---|
[2d5a54f3] | 340 | return -1;
|
---|
[da1bafb] | 341 |
|
---|
[2d5a54f3] | 342 | return 0;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[8b243f2] | 345 | /** Make a fast asynchronous call over IPC.
|
---|
[2d5a54f3] | 346 | *
|
---|
[3209923] | 347 | * This function can only handle four arguments of payload, but is faster than
|
---|
| 348 | * the generic function sys_ipc_call_async_slow().
|
---|
[8b243f2] | 349 | *
|
---|
[48bcf49] | 350 | * @param handle Phone capability handle for the call.
|
---|
| 351 | * @param imethod Interface and method of the call.
|
---|
| 352 | * @param arg1 Service-defined payload argument.
|
---|
| 353 | * @param arg2 Service-defined payload argument.
|
---|
| 354 | * @param arg3 Service-defined payload argument.
|
---|
| 355 | * @param arg4 Service-defined payload argument.
|
---|
[da1bafb] | 356 | *
|
---|
| 357 | * @return Call hash on success.
|
---|
| 358 | * @return IPC_CALLRET_FATAL in case of a fatal error.
|
---|
| 359 | * @return IPC_CALLRET_TEMPORARY if there are too many pending
|
---|
| 360 | * asynchronous requests; answers should be handled first.
|
---|
| 361 | *
|
---|
[2d5a54f3] | 362 | */
|
---|
[48bcf49] | 363 | sysarg_t sys_ipc_call_async_fast(sysarg_t handle, sysarg_t imethod,
|
---|
[96b02eb9] | 364 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 365 | {
|
---|
[48bcf49] | 366 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 367 | if (!kobj)
|
---|
[c9fff17] | 368 | return IPC_CALLRET_FATAL;
|
---|
[228e490] | 369 |
|
---|
[48bcf49] | 370 | if (check_call_limit(kobj->phone)) {
|
---|
| 371 | kobject_put(kobj);
|
---|
[97d17fe] | 372 | return IPC_CALLRET_TEMPORARY;
|
---|
[48bcf49] | 373 | }
|
---|
[da1bafb] | 374 |
|
---|
| 375 | call_t *call = ipc_call_alloc(0);
|
---|
[228e490] | 376 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[2d5a54f3] | 377 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 378 | IPC_SET_ARG2(call->data, arg2);
|
---|
[3209923] | 379 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 380 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 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);
|
---|
[da1bafb] | 387 |
|
---|
[48bcf49] | 388 | int res = request_preprocess(call, kobj->phone);
|
---|
[da1bafb] | 389 |
|
---|
| 390 | if (!res)
|
---|
[48bcf49] | 391 | ipc_call(kobj->phone, call);
|
---|
[7c7aae16] | 392 | else
|
---|
[48bcf49] | 393 | ipc_backsend_err(kobj->phone, call, res);
|
---|
[da1bafb] | 394 |
|
---|
[48bcf49] | 395 | kobject_put(kobj);
|
---|
[96b02eb9] | 396 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 397 | }
|
---|
| 398 |
|
---|
[8b243f2] | 399 | /** Make an asynchronous IPC call allowing to transmit the entire payload.
|
---|
| 400 | *
|
---|
[48bcf49] | 401 | * @param handle Phone capability for the call.
|
---|
[da1bafb] | 402 | * @param data Userspace address of call data with the request.
|
---|
| 403 | *
|
---|
| 404 | * @return See sys_ipc_call_async_fast().
|
---|
[2d5a54f3] | 405 | *
|
---|
| 406 | */
|
---|
[48bcf49] | 407 | sysarg_t sys_ipc_call_async_slow(sysarg_t handle, ipc_data_t *data)
|
---|
[2d5a54f3] | 408 | {
|
---|
[48bcf49] | 409 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 410 | if (!kobj)
|
---|
[c9fff17] | 411 | return IPC_CALLRET_FATAL;
|
---|
[4e49572] | 412 |
|
---|
[48bcf49] | 413 | if (check_call_limit(kobj->phone)) {
|
---|
| 414 | kobject_put(kobj);
|
---|
[97d17fe] | 415 | return IPC_CALLRET_TEMPORARY;
|
---|
[48bcf49] | 416 | }
|
---|
[97d17fe] | 417 |
|
---|
[da1bafb] | 418 | call_t *call = ipc_call_alloc(0);
|
---|
| 419 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 420 | sizeof(call->data.args));
|
---|
[f58af46] | 421 | if (rc != 0) {
|
---|
| 422 | ipc_call_free(call);
|
---|
[48bcf49] | 423 | kobject_put(kobj);
|
---|
[96b02eb9] | 424 | return (sysarg_t) rc;
|
---|
[f58af46] | 425 | }
|
---|
[da1bafb] | 426 |
|
---|
[48bcf49] | 427 | int res = request_preprocess(call, kobj->phone);
|
---|
[da1bafb] | 428 |
|
---|
| 429 | if (!res)
|
---|
[48bcf49] | 430 | ipc_call(kobj->phone, call);
|
---|
[7c7aae16] | 431 | else
|
---|
[48bcf49] | 432 | ipc_backsend_err(kobj->phone, call, res);
|
---|
[da1bafb] | 433 |
|
---|
[48bcf49] | 434 | kobject_put(kobj);
|
---|
[96b02eb9] | 435 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 436 | }
|
---|
| 437 |
|
---|
[da1bafb] | 438 | /** Forward a received call to another destination
|
---|
| 439 | *
|
---|
| 440 | * Common code for both the fast and the slow version.
|
---|
| 441 | *
|
---|
[48bcf49] | 442 | * @param callid Hash of the call to forward.
|
---|
| 443 | * @param handle Phone capability to use for forwarding.
|
---|
| 444 | * @param imethod New interface and method to use for the forwarded call.
|
---|
| 445 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 446 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 447 | * @param arg3 New value of the third argument for the forwarded call.
|
---|
| 448 | * @param arg4 New value of the fourth argument for the forwarded call.
|
---|
| 449 | * @param arg5 New value of the fifth argument for the forwarded call.
|
---|
| 450 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 451 | * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
|
---|
| 452 | * the function considers only the fast version arguments:
|
---|
| 453 | * i.e. arg1 and arg2.
|
---|
[da1bafb] | 454 | *
|
---|
| 455 | * @return 0 on succes, otherwise an error code.
|
---|
| 456 | *
|
---|
| 457 | * Warning: Make sure that ARG5 is not rewritten for certain system IPC
|
---|
| 458 | *
|
---|
[2ba7810] | 459 | */
|
---|
[48bcf49] | 460 | static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t handle,
|
---|
[228e490] | 461 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
|
---|
[96b02eb9] | 462 | sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
|
---|
[2ba7810] | 463 | {
|
---|
[da1bafb] | 464 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 465 | if (!call)
|
---|
| 466 | return ENOENT;
|
---|
[09024119] | 467 |
|
---|
| 468 | ipc_data_t old;
|
---|
| 469 | bool need_old = answer_need_old(call);
|
---|
[f9841e69] | 470 | if (need_old)
|
---|
| 471 | old = call->data;
|
---|
[48daf64] | 472 |
|
---|
[09024119] | 473 | bool after_forward = false;
|
---|
| 474 | int rc;
|
---|
[05ffb41] | 475 |
|
---|
[48bcf49] | 476 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 477 | if (!kobj) {
|
---|
[95a3082] | 478 | rc = ENOENT;
|
---|
| 479 | goto error;
|
---|
[c9fff17] | 480 | }
|
---|
[da1bafb] | 481 |
|
---|
[228e490] | 482 | if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
|
---|
[95a3082] | 483 | rc = EPERM;
|
---|
| 484 | goto error;
|
---|
[2ba7810] | 485 | }
|
---|
[09024119] | 486 |
|
---|
[95a3082] | 487 | call->flags |= IPC_CALL_FORWARDED;
|
---|
[da1bafb] | 488 |
|
---|
[0dc4258] | 489 | /*
|
---|
[4e5dabf] | 490 | * User space is not allowed to change interface and method of system
|
---|
[228e490] | 491 | * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
|
---|
[4e5dabf] | 492 | * means of imethod, arg1, arg2 and arg3.
|
---|
[228e490] | 493 | * If the interface and method is immutable, don't change anything.
|
---|
[2ba7810] | 494 | */
|
---|
[228e490] | 495 | if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
|
---|
| 496 | if (method_is_system(IPC_GET_IMETHOD(call->data))) {
|
---|
| 497 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
|
---|
[b61d47d] | 498 | phone_dealloc(IPC_GET_ARG5(call->data));
|
---|
[da1bafb] | 499 |
|
---|
[228e490] | 500 | IPC_SET_ARG1(call->data, imethod);
|
---|
[0dc4258] | 501 | IPC_SET_ARG2(call->data, arg1);
|
---|
[b61d47d] | 502 | IPC_SET_ARG3(call->data, arg2);
|
---|
[da1bafb] | 503 |
|
---|
[4e5dabf] | 504 | if (slow)
|
---|
[48daf64] | 505 | IPC_SET_ARG4(call->data, arg3);
|
---|
[4e5dabf] | 506 |
|
---|
| 507 | /*
|
---|
| 508 | * For system methods we deliberately don't
|
---|
| 509 | * overwrite ARG5.
|
---|
| 510 | */
|
---|
[0dc4258] | 511 | } else {
|
---|
[228e490] | 512 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[0dc4258] | 513 | IPC_SET_ARG1(call->data, arg1);
|
---|
[b61d47d] | 514 | IPC_SET_ARG2(call->data, arg2);
|
---|
[48daf64] | 515 | if (slow) {
|
---|
| 516 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 517 | IPC_SET_ARG4(call->data, arg4);
|
---|
| 518 | IPC_SET_ARG5(call->data, arg5);
|
---|
| 519 | }
|
---|
[0dc4258] | 520 | }
|
---|
[2ba7810] | 521 | }
|
---|
[da1bafb] | 522 |
|
---|
[48bcf49] | 523 | rc = ipc_forward(call, kobj->phone, &TASK->answerbox, mode);
|
---|
[f9841e69] | 524 | if (rc != EOK) {
|
---|
| 525 | after_forward = true;
|
---|
| 526 | goto error;
|
---|
| 527 | }
|
---|
[95a3082] | 528 |
|
---|
[48bcf49] | 529 | kobject_put(kobj);
|
---|
[f9841e69] | 530 | return EOK;
|
---|
[95a3082] | 531 |
|
---|
[f9841e69] | 532 | error:
|
---|
[fcfa926b] | 533 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[9ef1b79b] | 534 | (void) answer_preprocess(call, need_old ? &old : NULL);
|
---|
[f9841e69] | 535 | if (after_forward)
|
---|
| 536 | _ipc_answer_free_call(call, false);
|
---|
| 537 | else
|
---|
| 538 | ipc_answer(&TASK->answerbox, call);
|
---|
| 539 |
|
---|
[48bcf49] | 540 | if (kobj)
|
---|
| 541 | kobject_put(kobj);
|
---|
[95a3082] | 542 | return rc;
|
---|
[2ba7810] | 543 | }
|
---|
| 544 |
|
---|
[48daf64] | 545 | /** Forward a received call to another destination - fast version.
|
---|
| 546 | *
|
---|
[228e490] | 547 | * In case the original interface and method is a system method, ARG1, ARG2
|
---|
| 548 | * and ARG3 are overwritten in the forwarded message with the new method and
|
---|
| 549 | * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
|
---|
| 550 | * are rewritten with the new interface and method, arg1 and arg2, respectively.
|
---|
| 551 | * Also note there is a set of immutable methods, for which the new method and
|
---|
| 552 | * arguments are not set and these values are ignored.
|
---|
[da1bafb] | 553 | *
|
---|
[48bcf49] | 554 | * @param callid Hash of the call to forward.
|
---|
| 555 | * @param handle Phone handle to use for forwarding.
|
---|
| 556 | * @param imethod New interface and method to use for the forwarded call.
|
---|
| 557 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 558 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 559 | * @param mode Flags that specify mode of the forward operation.
|
---|
[da1bafb] | 560 | *
|
---|
| 561 | * @return 0 on succes, otherwise an error code.
|
---|
| 562 | *
|
---|
[48daf64] | 563 | */
|
---|
[48bcf49] | 564 | sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t handle,
|
---|
[228e490] | 565 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
|
---|
[48daf64] | 566 | {
|
---|
[48bcf49] | 567 | return sys_ipc_forward_common(callid, handle, imethod, arg1, arg2, 0, 0,
|
---|
[48daf64] | 568 | 0, mode, false);
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | /** Forward a received call to another destination - slow version.
|
---|
| 572 | *
|
---|
| 573 | * This function is the slow verision of the sys_ipc_forward_fast interface.
|
---|
[228e490] | 574 | * It can copy all five new arguments and the new interface and method from
|
---|
| 575 | * the userspace. It naturally extends the functionality of the fast version.
|
---|
| 576 | * For system methods, it additionally stores the new value of arg3 to ARG4.
|
---|
| 577 | * For non-system methods, it additionally stores the new value of arg3, arg4
|
---|
| 578 | * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
|
---|
[da1bafb] | 579 | *
|
---|
| 580 | * @param callid Hash of the call to forward.
|
---|
[48bcf49] | 581 | * @param handle Phone handle to use for forwarding.
|
---|
[da1bafb] | 582 | * @param data Userspace address of the new IPC data.
|
---|
| 583 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 584 | *
|
---|
| 585 | * @return 0 on succes, otherwise an error code.
|
---|
| 586 | *
|
---|
[48daf64] | 587 | */
|
---|
[48bcf49] | 588 | sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t handle,
|
---|
[da1bafb] | 589 | ipc_data_t *data, unsigned int mode)
|
---|
[48daf64] | 590 | {
|
---|
| 591 | ipc_data_t newdata;
|
---|
[da1bafb] | 592 | int rc = copy_from_uspace(&newdata.args, &data->args,
|
---|
[48daf64] | 593 | sizeof(newdata.args));
|
---|
[da1bafb] | 594 | if (rc != 0)
|
---|
[96b02eb9] | 595 | return (sysarg_t) rc;
|
---|
[da1bafb] | 596 |
|
---|
[48bcf49] | 597 | return sys_ipc_forward_common(callid, handle,
|
---|
[228e490] | 598 | IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
|
---|
[48daf64] | 599 | IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
|
---|
| 600 | IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
|
---|
| 601 | }
|
---|
| 602 |
|
---|
[8b243f2] | 603 | /** Answer an IPC call - fast version.
|
---|
| 604 | *
|
---|
| 605 | * This function can handle only two return arguments of payload, but is faster
|
---|
| 606 | * than the generic sys_ipc_answer().
|
---|
| 607 | *
|
---|
[da1bafb] | 608 | * @param callid Hash of the call to be answered.
|
---|
| 609 | * @param retval Return value of the answer.
|
---|
| 610 | * @param arg1 Service-defined return value.
|
---|
| 611 | * @param arg2 Service-defined return value.
|
---|
| 612 | * @param arg3 Service-defined return value.
|
---|
| 613 | * @param arg4 Service-defined return value.
|
---|
| 614 | *
|
---|
| 615 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 616 | *
|
---|
| 617 | */
|
---|
[96b02eb9] | 618 | sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
|
---|
| 619 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 620 | {
|
---|
[897f2e76] | 621 | /* Do not answer notification callids */
|
---|
| 622 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 623 | return 0;
|
---|
[da1bafb] | 624 |
|
---|
| 625 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 626 | if (!call)
|
---|
| 627 | return ENOENT;
|
---|
[da1bafb] | 628 |
|
---|
| 629 | ipc_data_t saved_data;
|
---|
| 630 | bool saved;
|
---|
| 631 |
|
---|
[9f22213] | 632 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 633 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 634 | saved = true;
|
---|
| 635 | } else
|
---|
| 636 | saved = false;
|
---|
| 637 |
|
---|
[2d5a54f3] | 638 | IPC_SET_RETVAL(call->data, retval);
|
---|
| 639 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 640 | IPC_SET_ARG2(call->data, arg2);
|
---|
[b74959bd] | 641 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 642 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 643 |
|
---|
[8498915] | 644 | /*
|
---|
| 645 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 646 | * the limits of the fast version.
|
---|
| 647 | */
|
---|
| 648 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 649 | int rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
| 650 |
|
---|
[2d5a54f3] | 651 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 652 | return rc;
|
---|
[2d5a54f3] | 653 | }
|
---|
| 654 |
|
---|
[8b243f2] | 655 | /** Answer an IPC call.
|
---|
| 656 | *
|
---|
[da1bafb] | 657 | * @param callid Hash of the call to be answered.
|
---|
| 658 | * @param data Userspace address of call data with the answer.
|
---|
| 659 | *
|
---|
| 660 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 661 | *
|
---|
| 662 | */
|
---|
[96b02eb9] | 663 | sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
|
---|
[2d5a54f3] | 664 | {
|
---|
[897f2e76] | 665 | /* Do not answer notification callids */
|
---|
| 666 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 667 | return 0;
|
---|
[da1bafb] | 668 |
|
---|
| 669 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 670 | if (!call)
|
---|
| 671 | return ENOENT;
|
---|
[da1bafb] | 672 |
|
---|
| 673 | ipc_data_t saved_data;
|
---|
| 674 | bool saved;
|
---|
| 675 |
|
---|
[9f22213] | 676 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 677 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 678 | saved = true;
|
---|
| 679 | } else
|
---|
| 680 | saved = false;
|
---|
| 681 |
|
---|
| 682 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 683 | sizeof(call->data.args));
|
---|
[e3c762cd] | 684 | if (rc != 0)
|
---|
| 685 | return rc;
|
---|
[da1bafb] | 686 |
|
---|
| 687 | rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[2d5a54f3] | 688 |
|
---|
| 689 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 690 | return rc;
|
---|
[2d5a54f3] | 691 | }
|
---|
| 692 |
|
---|
[8b243f2] | 693 | /** Hang up a phone.
|
---|
[2d5a54f3] | 694 | *
|
---|
[48bcf49] | 695 | * @param handle Phone capability handle of the phone to be hung up.
|
---|
[da1bafb] | 696 | *
|
---|
| 697 | * @return 0 on success or an error code.
|
---|
[8b243f2] | 698 | *
|
---|
[fbcfd458] | 699 | */
|
---|
[48bcf49] | 700 | sysarg_t sys_ipc_hangup(sysarg_t handle)
|
---|
[fbcfd458] | 701 | {
|
---|
[48bcf49] | 702 | kobject_t *kobj = kobject_get(TASK, handle, KOBJECT_TYPE_PHONE);
|
---|
| 703 | if (!kobj)
|
---|
[c9fff17] | 704 | return ENOENT;
|
---|
[da1bafb] | 705 |
|
---|
[48bcf49] | 706 | if (ipc_phone_hangup(kobj->phone)) {
|
---|
| 707 | kobject_put(kobj);
|
---|
[fbcfd458] | 708 | return -1;
|
---|
[48bcf49] | 709 | }
|
---|
[da1bafb] | 710 |
|
---|
[48bcf49] | 711 | kobject_put(kobj);
|
---|
[fbcfd458] | 712 | return 0;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
[8b243f2] | 715 | /** Wait for an incoming IPC call or an answer.
|
---|
[fbcfd458] | 716 | *
|
---|
[da1bafb] | 717 | * @param calldata Pointer to buffer where the call/answer data is stored.
|
---|
| 718 | * @param usec Timeout. See waitq_sleep_timeout() for explanation.
|
---|
| 719 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
|
---|
| 720 | * for explanation.
|
---|
| 721 | *
|
---|
| 722 | * @return Hash of the call.
|
---|
| 723 | * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
|
---|
| 724 | * call is a notification. IPC_CALLID_ANSWERED denotes an
|
---|
| 725 | * answer.
|
---|
[bd5a663] | 726 | *
|
---|
[2d5a54f3] | 727 | */
|
---|
[96b02eb9] | 728 | sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
|
---|
[da1bafb] | 729 | unsigned int flags)
|
---|
[2d5a54f3] | 730 | {
|
---|
| 731 | call_t *call;
|
---|
[da1bafb] | 732 |
|
---|
[741fd16] | 733 | restart:
|
---|
[da1bafb] | 734 |
|
---|
[741fd16] | 735 | #ifdef CONFIG_UDEBUG
|
---|
| 736 | udebug_stoppable_begin();
|
---|
[da1bafb] | 737 | #endif
|
---|
| 738 |
|
---|
[51ec40f] | 739 | call = ipc_wait_for_call(&TASK->answerbox, usec,
|
---|
| 740 | flags | SYNCH_FLAGS_INTERRUPTIBLE);
|
---|
[da1bafb] | 741 |
|
---|
[741fd16] | 742 | #ifdef CONFIG_UDEBUG
|
---|
| 743 | udebug_stoppable_end();
|
---|
| 744 | #endif
|
---|
[da1bafb] | 745 |
|
---|
[9f22213] | 746 | if (!call)
|
---|
| 747 | return 0;
|
---|
[da1bafb] | 748 |
|
---|
[5626277] | 749 | if (call->flags & IPC_CALL_NOTIF) {
|
---|
[43752b6] | 750 | /* Set in_phone_hash to the interrupt counter */
|
---|
[0c1a5d8a] | 751 | call->data.phone = (void *) call->priv;
|
---|
[43752b6] | 752 |
|
---|
| 753 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[da1bafb] | 754 |
|
---|
[5626277] | 755 | ipc_call_free(call);
|
---|
| 756 |
|
---|
[96b02eb9] | 757 | return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
|
---|
[5626277] | 758 | }
|
---|
[da1bafb] | 759 |
|
---|
[2d5a54f3] | 760 | if (call->flags & IPC_CALL_ANSWERED) {
|
---|
[7c7aae16] | 761 | process_answer(call);
|
---|
[da1bafb] | 762 |
|
---|
[fbcfd458] | 763 | if (call->flags & IPC_CALL_DISCARD_ANSWER) {
|
---|
| 764 | ipc_call_free(call);
|
---|
| 765 | goto restart;
|
---|
| 766 | }
|
---|
[da1bafb] | 767 |
|
---|
[1d81eb6] | 768 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[2d5a54f3] | 769 | ipc_call_free(call);
|
---|
[da1bafb] | 770 |
|
---|
[96b02eb9] | 771 | return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
|
---|
[2d5a54f3] | 772 | }
|
---|
[da1bafb] | 773 |
|
---|
[2d5a54f3] | 774 | if (process_request(&TASK->answerbox, call))
|
---|
| 775 | goto restart;
|
---|
[da1bafb] | 776 |
|
---|
[7c7aae16] | 777 | /* Include phone address('id') of the caller in the request,
|
---|
| 778 | * copy whole call->data, not only call->data.args */
|
---|
[bd55bbb] | 779 | if (STRUCT_TO_USPACE(calldata, &call->data)) {
|
---|
[e06da7e] | 780 | /*
|
---|
| 781 | * The callee will not receive this call and no one else has
|
---|
| 782 | * a chance to answer it. Reply with the EPARTY error code.
|
---|
[b11ee88] | 783 | */
|
---|
[e06da7e] | 784 | ipc_data_t saved_data;
|
---|
[da1bafb] | 785 | bool saved;
|
---|
| 786 |
|
---|
[e06da7e] | 787 | if (answer_need_old(call)) {
|
---|
| 788 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 789 | saved = true;
|
---|
| 790 | } else
|
---|
| 791 | saved = false;
|
---|
[e06da7e] | 792 |
|
---|
| 793 | IPC_SET_RETVAL(call->data, EPARTY);
|
---|
[da1bafb] | 794 | (void) answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[e06da7e] | 795 | ipc_answer(&TASK->answerbox, call);
|
---|
[bd55bbb] | 796 | return 0;
|
---|
| 797 | }
|
---|
[da1bafb] | 798 |
|
---|
[96b02eb9] | 799 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 800 | }
|
---|
[5626277] | 801 |
|
---|
[da1bafb] | 802 | /** Interrupt one thread from sys_ipc_wait_for_call().
|
---|
| 803 | *
|
---|
| 804 | */
|
---|
[96b02eb9] | 805 | sysarg_t sys_ipc_poke(void)
|
---|
[057d21a] | 806 | {
|
---|
[da1bafb] | 807 | waitq_unsleep(&TASK->answerbox.wq);
|
---|
[057d21a] | 808 | return EOK;
|
---|
| 809 | }
|
---|
| 810 |
|
---|
[8b243f2] | 811 | /** Connect an IRQ handler to a task.
|
---|
[2b017ba] | 812 | *
|
---|
[228e490] | 813 | * @param inr IRQ number.
|
---|
| 814 | * @param imethod Interface and method to be associated with the notification.
|
---|
| 815 | * @param ucode Uspace pointer to the top-half pseudocode.
|
---|
[da1bafb] | 816 | *
|
---|
[e9d15d9] | 817 | * @return IRQ kernel object capability
|
---|
| 818 | * @return EPERM
|
---|
| 819 | * @return Error code returned by ipc_irq_subscribe().
|
---|
[2b017ba] | 820 | *
|
---|
| 821 | */
|
---|
[24abb85d] | 822 | sysarg_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod, irq_code_t *ucode)
|
---|
[5626277] | 823 | {
|
---|
[719a208] | 824 | if (!(perm_get(TASK) & PERM_IRQ_REG))
|
---|
[2bb8648] | 825 | return EPERM;
|
---|
[da1bafb] | 826 |
|
---|
[24abb85d] | 827 | return ipc_irq_subscribe(&TASK->answerbox, inr, imethod, ucode);
|
---|
[5626277] | 828 | }
|
---|
| 829 |
|
---|
[8b243f2] | 830 | /** Disconnect an IRQ handler from a task.
|
---|
| 831 | *
|
---|
[da1bafb] | 832 | * @param inr IRQ number.
|
---|
| 833 | * @param devno Device number.
|
---|
| 834 | *
|
---|
| 835 | * @return Zero on success or EPERM on error.
|
---|
[2b017ba] | 836 | *
|
---|
| 837 | */
|
---|
[e9d15d9] | 838 | sysarg_t sys_ipc_irq_unsubscribe(sysarg_t cap)
|
---|
[5626277] | 839 | {
|
---|
[719a208] | 840 | if (!(perm_get(TASK) & PERM_IRQ_REG))
|
---|
[2bb8648] | 841 | return EPERM;
|
---|
[da1bafb] | 842 |
|
---|
[e9d15d9] | 843 | ipc_irq_unsubscribe(&TASK->answerbox, cap);
|
---|
[da1bafb] | 844 |
|
---|
[5626277] | 845 | return 0;
|
---|
| 846 | }
|
---|
[b45c443] | 847 |
|
---|
[6b10dab] | 848 | #ifdef __32_BITS__
|
---|
[9a1b20c] | 849 |
|
---|
[6b10dab] | 850 | /** Syscall connect to a task by ID (32 bits)
|
---|
[da1bafb] | 851 | *
|
---|
| 852 | * @return Phone id on success, or negative error code.
|
---|
[9a1b20c] | 853 | *
|
---|
| 854 | */
|
---|
[6b10dab] | 855 | sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
|
---|
[9a1b20c] | 856 | {
|
---|
| 857 | #ifdef CONFIG_UDEBUG
|
---|
[6b10dab] | 858 | sysarg64_t taskid;
|
---|
| 859 | int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
|
---|
[9a1b20c] | 860 | if (rc != 0)
|
---|
[96b02eb9] | 861 | return (sysarg_t) rc;
|
---|
[da1bafb] | 862 |
|
---|
[6b10dab] | 863 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
[9a1b20c] | 864 | #else
|
---|
[96b02eb9] | 865 | return (sysarg_t) ENOTSUP;
|
---|
[9a1b20c] | 866 | #endif
|
---|
| 867 | }
|
---|
| 868 |
|
---|
[6b10dab] | 869 | #endif /* __32_BITS__ */
|
---|
| 870 |
|
---|
| 871 | #ifdef __64_BITS__
|
---|
| 872 |
|
---|
| 873 | /** Syscall connect to a task by ID (64 bits)
|
---|
| 874 | *
|
---|
| 875 | * @return Phone id on success, or negative error code.
|
---|
| 876 | *
|
---|
| 877 | */
|
---|
| 878 | sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
|
---|
| 879 | {
|
---|
| 880 | #ifdef CONFIG_UDEBUG
|
---|
| 881 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
| 882 | #else
|
---|
| 883 | return (sysarg_t) ENOTSUP;
|
---|
| 884 | #endif
|
---|
| 885 | }
|
---|
| 886 |
|
---|
| 887 | #endif /* __64_BITS__ */
|
---|
| 888 |
|
---|
[cc73a8a1] | 889 | /** @}
|
---|
[b45c443] | 890 | */
|
---|