| [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>
|
|---|
| 36 | #include <proc/task.h>
|
|---|
| [e3c762cd] | 37 | #include <proc/thread.h>
|
|---|
| [2d5a54f3] | 38 | #include <errno.h>
|
|---|
| 39 | #include <memstr.h>
|
|---|
| 40 | #include <debug.h>
|
|---|
| 41 | #include <ipc/ipc.h>
|
|---|
| [c0699467] | 42 | #include <abi/ipc/methods.h>
|
|---|
| [2d5a54f3] | 43 | #include <ipc/sysipc.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>
|
|---|
| [9a1b20c] | 49 | #include <udebug/udebug_ipc.h>
|
|---|
| [5626277] | 50 | #include <arch/interrupt.h>
|
|---|
| [e3c762cd] | 51 | #include <syscall/copy.h>
|
|---|
| [2bb8648] | 52 | #include <security/cap.h>
|
|---|
| [6b10dab] | 53 | #include <console/console.h>
|
|---|
| [7c23af9] | 54 | #include <mm/as.h>
|
|---|
| [253f35a1] | 55 | #include <print.h>
|
|---|
| [e2ab36f1] | 56 | #include <macros.h>
|
|---|
| [2d5a54f3] | 57 |
|
|---|
| [36d852c] | 58 | /**
|
|---|
| 59 | * Maximum buffer size allowed for IPC_M_DATA_WRITE and IPC_M_DATA_READ
|
|---|
| 60 | * requests.
|
|---|
| 61 | */
|
|---|
| [da1bafb] | 62 | #define DATA_XFER_LIMIT (64 * 1024)
|
|---|
| 63 |
|
|---|
| 64 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
|
|---|
| [7918fce] | 65 |
|
|---|
| [c9fff17] | 66 | /** Get phone from the current task by ID.
|
|---|
| 67 | *
|
|---|
| [da1bafb] | 68 | * @param phoneid Phone ID.
|
|---|
| 69 | * @param phone Place to store pointer to phone.
|
|---|
| 70 | *
|
|---|
| 71 | * @return EOK on success, EINVAL if ID is invalid.
|
|---|
| 72 | *
|
|---|
| [c9fff17] | 73 | */
|
|---|
| [96b02eb9] | 74 | static int phone_get(sysarg_t phoneid, phone_t **phone)
|
|---|
| [c9fff17] | 75 | {
|
|---|
| 76 | if (phoneid >= IPC_MAX_PHONES)
|
|---|
| 77 | return EINVAL;
|
|---|
| [da1bafb] | 78 |
|
|---|
| [c9fff17] | 79 | *phone = &TASK->phones[phoneid];
|
|---|
| 80 | return EOK;
|
|---|
| [ba81cab] | 81 | }
|
|---|
| 82 |
|
|---|
| [228e490] | 83 | /** Decide if the interface and method is a system method.
|
|---|
| [8b243f2] | 84 | *
|
|---|
| [228e490] | 85 | * @param imethod Interface and method to be decided.
|
|---|
| [da1bafb] | 86 | *
|
|---|
| [228e490] | 87 | * @return True if the interface and method is a system
|
|---|
| 88 | * interface and method.
|
|---|
| [8b243f2] | 89 | *
|
|---|
| 90 | */
|
|---|
| [228e490] | 91 | static inline bool method_is_system(sysarg_t imethod)
|
|---|
| [2ba7810] | 92 | {
|
|---|
| [228e490] | 93 | if (imethod <= IPC_M_LAST_SYSTEM)
|
|---|
| [da1bafb] | 94 | return true;
|
|---|
| 95 |
|
|---|
| 96 | return false;
|
|---|
| [2ba7810] | 97 | }
|
|---|
| 98 |
|
|---|
| [228e490] | 99 | /** Decide if the message with this interface and method is forwardable.
|
|---|
| [2ba7810] | 100 | *
|
|---|
| [228e490] | 101 | * Some system messages may be forwarded, for some of them
|
|---|
| 102 | * it is useless.
|
|---|
| [8b243f2] | 103 | *
|
|---|
| [228e490] | 104 | * @param imethod Interface and method to be decided.
|
|---|
| [da1bafb] | 105 | *
|
|---|
| [228e490] | 106 | * @return True if the interface and method is forwardable.
|
|---|
| [8b243f2] | 107 | *
|
|---|
| [2ba7810] | 108 | */
|
|---|
| [228e490] | 109 | static inline bool method_is_forwardable(sysarg_t imethod)
|
|---|
| [2ba7810] | 110 | {
|
|---|
| [228e490] | 111 | switch (imethod) {
|
|---|
| [2c0e5d2] | 112 | case IPC_M_CONNECTION_CLONE:
|
|---|
| [6aae539d] | 113 | case IPC_M_CLONE_ESTABLISH:
|
|---|
| [7918fce] | 114 | case IPC_M_PHONE_HUNGUP:
|
|---|
| 115 | /* This message is meant only for the original recipient. */
|
|---|
| [da1bafb] | 116 | return false;
|
|---|
| [7918fce] | 117 | default:
|
|---|
| [da1bafb] | 118 | return true;
|
|---|
| [7918fce] | 119 | }
|
|---|
| [2ba7810] | 120 | }
|
|---|
| 121 |
|
|---|
| [228e490] | 122 | /** Decide if the message with this interface and method is immutable on forward.
|
|---|
| [0dc4258] | 123 | *
|
|---|
| [228e490] | 124 | * Some system messages may be forwarded but their content cannot be altered.
|
|---|
| [0dc4258] | 125 | *
|
|---|
| [228e490] | 126 | * @param imethod Interface and method to be decided.
|
|---|
| [da1bafb] | 127 | *
|
|---|
| [228e490] | 128 | * @return True if the interface and method is immutable on forward.
|
|---|
| [0dc4258] | 129 | *
|
|---|
| 130 | */
|
|---|
| [228e490] | 131 | static inline bool method_is_immutable(sysarg_t imethod)
|
|---|
| [0dc4258] | 132 | {
|
|---|
| [228e490] | 133 | switch (imethod) {
|
|---|
| [27d293a] | 134 | case IPC_M_SHARE_OUT:
|
|---|
| 135 | case IPC_M_SHARE_IN:
|
|---|
| [36d852c] | 136 | case IPC_M_DATA_WRITE:
|
|---|
| 137 | case IPC_M_DATA_READ:
|
|---|
| [fdd4898] | 138 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
|---|
| [da1bafb] | 139 | return true;
|
|---|
| [0dc4258] | 140 | default:
|
|---|
| [da1bafb] | 141 | return false;
|
|---|
| [0dc4258] | 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| [2d5a54f3] | 145 |
|
|---|
| [8b243f2] | 146 | /***********************************************************************
|
|---|
| 147 | * Functions that preprocess answer before sending it to the recepient.
|
|---|
| 148 | ***********************************************************************/
|
|---|
| 149 |
|
|---|
| 150 | /** Decide if the caller (e.g. ipc_answer()) should save the old call contents
|
|---|
| 151 | * for answer_preprocess().
|
|---|
| 152 | *
|
|---|
| [da1bafb] | 153 | * @param call Call structure to be decided.
|
|---|
| 154 | *
|
|---|
| 155 | * @return true if the old call contents should be saved.
|
|---|
| [8b243f2] | 156 | *
|
|---|
| [2d5a54f3] | 157 | */
|
|---|
| [da1bafb] | 158 | static inline bool answer_need_old(call_t *call)
|
|---|
| [2d5a54f3] | 159 | {
|
|---|
| [228e490] | 160 | switch (IPC_GET_IMETHOD(call->data)) {
|
|---|
| [2c0e5d2] | 161 | case IPC_M_CONNECTION_CLONE:
|
|---|
| [6aae539d] | 162 | case IPC_M_CLONE_ESTABLISH:
|
|---|
| [7918fce] | 163 | case IPC_M_CONNECT_TO_ME:
|
|---|
| 164 | case IPC_M_CONNECT_ME_TO:
|
|---|
| [27d293a] | 165 | case IPC_M_SHARE_OUT:
|
|---|
| 166 | case IPC_M_SHARE_IN:
|
|---|
| [36d852c] | 167 | case IPC_M_DATA_WRITE:
|
|---|
| 168 | case IPC_M_DATA_READ:
|
|---|
| [fdd4898] | 169 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
|---|
| [da1bafb] | 170 | return true;
|
|---|
| [7918fce] | 171 | default:
|
|---|
| [da1bafb] | 172 | return false;
|
|---|
| [7918fce] | 173 | }
|
|---|
| [2d5a54f3] | 174 | }
|
|---|
| 175 |
|
|---|
| [9956fad9] | 176 | static int a_preprocess_m_connection_clone(call_t *answer, ipc_data_t *olddata)
|
|---|
| 177 | {
|
|---|
| 178 | int phoneid = (int) IPC_GET_ARG1(*olddata);
|
|---|
| 179 | phone_t *phone = &TASK->phones[phoneid];
|
|---|
| 180 |
|
|---|
| 181 | if (IPC_GET_RETVAL(answer->data) != EOK) {
|
|---|
| 182 | /*
|
|---|
| 183 | * The recipient of the cloned phone rejected the offer. In
|
|---|
| 184 | * this case, the connection was established at the request
|
|---|
| 185 | * time and therefore we need to slam the phone. We don't
|
|---|
| 186 | * merely hangup as that would result in sending IPC_M_HUNGUP
|
|---|
| 187 | * to the third party on the other side of the cloned phone.
|
|---|
| 188 | */
|
|---|
| 189 | mutex_lock(&phone->lock);
|
|---|
| 190 | if (phone->state == IPC_PHONE_CONNECTED) {
|
|---|
| 191 | irq_spinlock_lock(&phone->callee->lock, true);
|
|---|
| 192 | list_remove(&phone->link);
|
|---|
| 193 | phone->state = IPC_PHONE_SLAMMED;
|
|---|
| 194 | irq_spinlock_unlock(&phone->callee->lock, true);
|
|---|
| 195 | }
|
|---|
| 196 | mutex_unlock(&phone->lock);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | return EOK;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | static int a_preprocess_m_clone_establish(call_t *answer, ipc_data_t *olddata)
|
|---|
| 203 | {
|
|---|
| 204 | phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
|
|---|
| 205 |
|
|---|
| 206 | if (IPC_GET_RETVAL(answer->data) != EOK) {
|
|---|
| 207 | /*
|
|---|
| 208 | * The other party on the cloned phoned rejected our request
|
|---|
| 209 | * for connection on the protocol level. We need to break the
|
|---|
| 210 | * connection without sending IPC_M_HUNGUP back.
|
|---|
| 211 | */
|
|---|
| 212 | mutex_lock(&phone->lock);
|
|---|
| 213 | if (phone->state == IPC_PHONE_CONNECTED) {
|
|---|
| 214 | irq_spinlock_lock(&phone->callee->lock, true);
|
|---|
| 215 | list_remove(&phone->link);
|
|---|
| 216 | phone->state = IPC_PHONE_SLAMMED;
|
|---|
| 217 | irq_spinlock_unlock(&phone->callee->lock, true);
|
|---|
| 218 | }
|
|---|
| 219 | mutex_unlock(&phone->lock);
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | return EOK;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | static int a_preprocess_m_connect_to_me(call_t *answer, ipc_data_t *olddata)
|
|---|
| 226 | {
|
|---|
| 227 | int phoneid = (int) IPC_GET_ARG5(*olddata);
|
|---|
| 228 |
|
|---|
| 229 | if (IPC_GET_RETVAL(answer->data) != EOK) {
|
|---|
| 230 | /* The connection was not accepted */
|
|---|
| 231 | phone_dealloc(phoneid);
|
|---|
| 232 | } else {
|
|---|
| 233 | /* The connection was accepted */
|
|---|
| 234 | phone_connect(phoneid, &answer->sender->answerbox);
|
|---|
| 235 | /* Set 'phone hash' as arg5 of response */
|
|---|
| 236 | IPC_SET_ARG5(answer->data, (sysarg_t) &TASK->phones[phoneid]);
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | return EOK;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | static int a_preprocess_m_connect_me_to(call_t *answer, ipc_data_t *olddata)
|
|---|
| 243 | {
|
|---|
| 244 | phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
|
|---|
| 245 |
|
|---|
| 246 | /* If the users accepted call, connect */
|
|---|
| 247 | if (IPC_GET_RETVAL(answer->data) == EOK)
|
|---|
| 248 | ipc_phone_connect(phone, &TASK->answerbox);
|
|---|
| 249 |
|
|---|
| 250 | return EOK;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | static int a_preprocess_m_share_out(call_t *answer, ipc_data_t *olddata)
|
|---|
| 254 | {
|
|---|
| 255 | int rc = EOK;
|
|---|
| 256 |
|
|---|
| 257 | if (!IPC_GET_RETVAL(answer->data)) {
|
|---|
| 258 | /* Accepted, handle as_area receipt */
|
|---|
| 259 |
|
|---|
| 260 | irq_spinlock_lock(&answer->sender->lock, true);
|
|---|
| 261 | as_t *as = answer->sender->as;
|
|---|
| 262 | irq_spinlock_unlock(&answer->sender->lock, true);
|
|---|
| 263 |
|
|---|
| 264 | uintptr_t dst_base = (uintptr_t) -1;
|
|---|
| 265 | rc = as_area_share(as, IPC_GET_ARG1(*olddata),
|
|---|
| 266 | IPC_GET_ARG2(*olddata), AS, IPC_GET_ARG3(*olddata),
|
|---|
| 267 | &dst_base, IPC_GET_ARG1(answer->data));
|
|---|
| 268 |
|
|---|
| 269 | if (rc == EOK) {
|
|---|
| 270 | rc = copy_to_uspace((void *) IPC_GET_ARG2(answer->data),
|
|---|
| 271 | &dst_base, sizeof(dst_base));
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | IPC_SET_RETVAL(answer->data, rc);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | return rc;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | static int a_preprocess_m_share_in(call_t *answer, ipc_data_t *olddata)
|
|---|
| 281 | {
|
|---|
| 282 | if (!IPC_GET_RETVAL(answer->data)) {
|
|---|
| 283 | irq_spinlock_lock(&answer->sender->lock, true);
|
|---|
| 284 | as_t *as = answer->sender->as;
|
|---|
| 285 | irq_spinlock_unlock(&answer->sender->lock, true);
|
|---|
| 286 |
|
|---|
| 287 | uintptr_t dst_base = (uintptr_t) -1;
|
|---|
| 288 | int rc = as_area_share(AS, IPC_GET_ARG1(answer->data),
|
|---|
| 289 | IPC_GET_ARG1(*olddata), as, IPC_GET_ARG2(answer->data),
|
|---|
| 290 | &dst_base, IPC_GET_ARG3(answer->data));
|
|---|
| 291 | IPC_SET_ARG4(answer->data, dst_base);
|
|---|
| 292 | IPC_SET_RETVAL(answer->data, rc);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | return EOK;
|
|---|
| 296 | }
|
|---|
| 297 |
|
|---|
| 298 | static int a_preprocess_m_data_read(call_t *answer, ipc_data_t *olddata)
|
|---|
| 299 | {
|
|---|
| 300 | ASSERT(!answer->buffer);
|
|---|
| 301 | if (!IPC_GET_RETVAL(answer->data)) {
|
|---|
| 302 | /* The recipient agreed to send data. */
|
|---|
| 303 | uintptr_t src = IPC_GET_ARG1(answer->data);
|
|---|
| 304 | uintptr_t dst = IPC_GET_ARG1(*olddata);
|
|---|
| 305 | size_t max_size = IPC_GET_ARG2(*olddata);
|
|---|
| 306 | size_t size = IPC_GET_ARG2(answer->data);
|
|---|
| 307 | if (size && size <= max_size) {
|
|---|
| 308 | /*
|
|---|
| 309 | * Copy the destination VA so that this piece of
|
|---|
| 310 | * information is not lost.
|
|---|
| 311 | */
|
|---|
| 312 | IPC_SET_ARG1(answer->data, dst);
|
|---|
| 313 |
|
|---|
| 314 | answer->buffer = malloc(size, 0);
|
|---|
| 315 | int rc = copy_from_uspace(answer->buffer,
|
|---|
| 316 | (void *) src, size);
|
|---|
| 317 | if (rc) {
|
|---|
| 318 | IPC_SET_RETVAL(answer->data, rc);
|
|---|
| 319 | free(answer->buffer);
|
|---|
| 320 | answer->buffer = NULL;
|
|---|
| 321 | }
|
|---|
| 322 | } else if (!size) {
|
|---|
| 323 | IPC_SET_RETVAL(answer->data, EOK);
|
|---|
| 324 | } else {
|
|---|
| 325 | IPC_SET_RETVAL(answer->data, ELIMIT);
|
|---|
| 326 | }
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | return EOK;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | static int a_preprocess_m_data_write(call_t *answer, ipc_data_t *olddata)
|
|---|
| 333 | {
|
|---|
| 334 | ASSERT(answer->buffer);
|
|---|
| 335 | if (!IPC_GET_RETVAL(answer->data)) {
|
|---|
| 336 | /* The recipient agreed to receive data. */
|
|---|
| 337 | uintptr_t dst = (uintptr_t)IPC_GET_ARG1(answer->data);
|
|---|
| 338 | size_t size = (size_t)IPC_GET_ARG2(answer->data);
|
|---|
| 339 | size_t max_size = (size_t)IPC_GET_ARG2(*olddata);
|
|---|
| 340 |
|
|---|
| 341 | if (size <= max_size) {
|
|---|
| 342 | int rc = copy_to_uspace((void *) dst,
|
|---|
| 343 | answer->buffer, size);
|
|---|
| 344 | if (rc)
|
|---|
| 345 | IPC_SET_RETVAL(answer->data, rc);
|
|---|
| 346 | } else {
|
|---|
| 347 | IPC_SET_RETVAL(answer->data, ELIMIT);
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 | free(answer->buffer);
|
|---|
| 351 | answer->buffer = NULL;
|
|---|
| 352 |
|
|---|
| 353 | return EOK;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | static int
|
|---|
| 357 | a_preprocess_m_state_change_authorize(call_t *answer, ipc_data_t *olddata)
|
|---|
| 358 | {
|
|---|
| 359 | int rc = EOK;
|
|---|
| 360 |
|
|---|
| 361 | if (!IPC_GET_RETVAL(answer->data)) {
|
|---|
| 362 | /* The recipient authorized the change of state. */
|
|---|
| 363 | phone_t *recipient_phone;
|
|---|
| 364 | task_t *other_task_s;
|
|---|
| 365 | task_t *other_task_r;
|
|---|
| 366 |
|
|---|
| 367 | rc = phone_get(IPC_GET_ARG1(answer->data),
|
|---|
| 368 | &recipient_phone);
|
|---|
| 369 | if (rc != EOK) {
|
|---|
| 370 | IPC_SET_RETVAL(answer->data, ENOENT);
|
|---|
| 371 | return ENOENT;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | mutex_lock(&recipient_phone->lock);
|
|---|
| 375 | if (recipient_phone->state != IPC_PHONE_CONNECTED) {
|
|---|
| 376 | mutex_unlock(&recipient_phone->lock);
|
|---|
| 377 | IPC_SET_RETVAL(answer->data, EINVAL);
|
|---|
| 378 | return EINVAL;
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | other_task_r = recipient_phone->callee->task;
|
|---|
| 382 | other_task_s = (task_t *) IPC_GET_ARG5(*olddata);
|
|---|
| 383 |
|
|---|
| 384 | /*
|
|---|
| 385 | * See if both the sender and the recipient meant the
|
|---|
| 386 | * same third party task.
|
|---|
| 387 | */
|
|---|
| 388 | if (other_task_r != other_task_s) {
|
|---|
| 389 | IPC_SET_RETVAL(answer->data, EINVAL);
|
|---|
| 390 | rc = EINVAL;
|
|---|
| 391 | } else {
|
|---|
| 392 | rc = event_task_notify_5(other_task_r,
|
|---|
| 393 | EVENT_TASK_STATE_CHANGE, false,
|
|---|
| 394 | IPC_GET_ARG1(*olddata),
|
|---|
| 395 | IPC_GET_ARG2(*olddata),
|
|---|
| 396 | IPC_GET_ARG3(*olddata),
|
|---|
| 397 | LOWER32(olddata->task_id),
|
|---|
| 398 | UPPER32(olddata->task_id));
|
|---|
| 399 | IPC_SET_RETVAL(answer->data, rc);
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | mutex_unlock(&recipient_phone->lock);
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | return rc;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| [8b243f2] | 408 | /** Interpret process answer as control information.
|
|---|
| 409 | *
|
|---|
| 410 | * This function is called directly after sys_ipc_answer().
|
|---|
| [46fc2f9] | 411 | *
|
|---|
| [da1bafb] | 412 | * @param answer Call structure with the answer.
|
|---|
| 413 | * @param olddata Saved data of the request.
|
|---|
| 414 | *
|
|---|
| [9956fad9] | 415 | * @return Return EOK on success or a negative error code.
|
|---|
| [8b243f2] | 416 | *
|
|---|
| [46fc2f9] | 417 | */
|
|---|
| [9956fad9] | 418 | static int answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
|---|
| [2d5a54f3] | 419 | {
|
|---|
| [9956fad9] | 420 | int rc = EOK;
|
|---|
| 421 |
|
|---|
| [6c441cf8] | 422 | if ((native_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
|
|---|
| [ca687ad] | 423 | /* In case of forward, hangup the forwared phone,
|
|---|
| 424 | * not the originator
|
|---|
| 425 | */
|
|---|
| [ff48a15] | 426 | mutex_lock(&answer->data.phone->lock);
|
|---|
| [da1bafb] | 427 | irq_spinlock_lock(&TASK->answerbox.lock, true);
|
|---|
| [eb3d379] | 428 | if (answer->data.phone->state == IPC_PHONE_CONNECTED) {
|
|---|
| [c4e4507] | 429 | list_remove(&answer->data.phone->link);
|
|---|
| [eb3d379] | 430 | answer->data.phone->state = IPC_PHONE_SLAMMED;
|
|---|
| [ca687ad] | 431 | }
|
|---|
| [da1bafb] | 432 | irq_spinlock_unlock(&TASK->answerbox.lock, true);
|
|---|
| [ff48a15] | 433 | mutex_unlock(&answer->data.phone->lock);
|
|---|
| [9f22213] | 434 | }
|
|---|
| [da1bafb] | 435 |
|
|---|
| [9f22213] | 436 | if (!olddata)
|
|---|
| [9956fad9] | 437 | return rc;
|
|---|
| [da1bafb] | 438 |
|
|---|
| [9956fad9] | 439 | switch (IPC_GET_IMETHOD(*olddata)) {
|
|---|
| 440 | case IPC_M_CONNECTION_CLONE:
|
|---|
| 441 | rc = a_preprocess_m_connection_clone(answer, olddata);
|
|---|
| 442 | break;
|
|---|
| 443 | case IPC_M_CLONE_ESTABLISH:
|
|---|
| 444 | rc = a_preprocess_m_clone_establish(answer, olddata);
|
|---|
| 445 | break;
|
|---|
| 446 | case IPC_M_CONNECT_TO_ME:
|
|---|
| 447 | rc = a_preprocess_m_connect_to_me(answer, olddata);
|
|---|
| 448 | break;
|
|---|
| 449 | case IPC_M_CONNECT_ME_TO:
|
|---|
| 450 | rc = a_preprocess_m_connect_me_to(answer, olddata);
|
|---|
| 451 | break;
|
|---|
| 452 | case IPC_M_SHARE_OUT:
|
|---|
| 453 | rc = a_preprocess_m_share_out(answer, olddata);
|
|---|
| 454 | break;
|
|---|
| 455 | case IPC_M_SHARE_IN:
|
|---|
| 456 | rc = a_preprocess_m_share_in(answer, olddata);
|
|---|
| 457 | break;
|
|---|
| 458 | case IPC_M_DATA_READ:
|
|---|
| 459 | rc = a_preprocess_m_data_read(answer, olddata);
|
|---|
| 460 | break;
|
|---|
| 461 | case IPC_M_DATA_WRITE:
|
|---|
| 462 | rc = a_preprocess_m_data_write(answer, olddata);
|
|---|
| 463 | break;
|
|---|
| 464 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
|---|
| 465 | rc = a_preprocess_m_state_change_authorize(answer, olddata);
|
|---|
| 466 | break;
|
|---|
| [9a82ac1] | 467 | default:
|
|---|
| 468 | break;
|
|---|
| [2d5a54f3] | 469 | }
|
|---|
| [da1bafb] | 470 |
|
|---|
| [9956fad9] | 471 | return rc;
|
|---|
| [2d5a54f3] | 472 | }
|
|---|
| 473 |
|
|---|
| [bf1fb9f] | 474 | static void phones_lock(phone_t *p1, phone_t *p2)
|
|---|
| 475 | {
|
|---|
| 476 | if (p1 < p2) {
|
|---|
| 477 | mutex_lock(&p1->lock);
|
|---|
| 478 | mutex_lock(&p2->lock);
|
|---|
| 479 | } else if (p1 > p2) {
|
|---|
| 480 | mutex_lock(&p2->lock);
|
|---|
| 481 | mutex_lock(&p1->lock);
|
|---|
| [da1bafb] | 482 | } else
|
|---|
| [bf1fb9f] | 483 | mutex_lock(&p1->lock);
|
|---|
| 484 | }
|
|---|
| 485 |
|
|---|
| 486 | static void phones_unlock(phone_t *p1, phone_t *p2)
|
|---|
| 487 | {
|
|---|
| 488 | mutex_unlock(&p1->lock);
|
|---|
| 489 | if (p1 != p2)
|
|---|
| 490 | mutex_unlock(&p2->lock);
|
|---|
| 491 | }
|
|---|
| 492 |
|
|---|
| [924c2530] | 493 | static int r_preprocess_m_connection_clone(call_t *call, phone_t *phone)
|
|---|
| 494 | {
|
|---|
| 495 | phone_t *cloned_phone;
|
|---|
| 496 |
|
|---|
| 497 | if (phone_get(IPC_GET_ARG1(call->data), &cloned_phone) != EOK)
|
|---|
| 498 | return ENOENT;
|
|---|
| 499 |
|
|---|
| 500 | phones_lock(cloned_phone, phone);
|
|---|
| 501 |
|
|---|
| 502 | if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
|
|---|
| 503 | phone->state != IPC_PHONE_CONNECTED) {
|
|---|
| 504 | phones_unlock(cloned_phone, phone);
|
|---|
| 505 | return EINVAL;
|
|---|
| 506 | }
|
|---|
| 507 |
|
|---|
| 508 | /*
|
|---|
| 509 | * We can be pretty sure now that both tasks exist and we are
|
|---|
| 510 | * connected to them. As we continue to hold the phone locks,
|
|---|
| 511 | * we are effectively preventing them from finishing their
|
|---|
| 512 | * potential cleanup.
|
|---|
| 513 | *
|
|---|
| 514 | */
|
|---|
| 515 | int newphid = phone_alloc(phone->callee->task);
|
|---|
| 516 | if (newphid < 0) {
|
|---|
| 517 | phones_unlock(cloned_phone, phone);
|
|---|
| 518 | return ELIMIT;
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | ipc_phone_connect(&phone->callee->task->phones[newphid],
|
|---|
| 522 | cloned_phone->callee);
|
|---|
| 523 | phones_unlock(cloned_phone, phone);
|
|---|
| 524 |
|
|---|
| 525 | /* Set the new phone for the callee. */
|
|---|
| 526 | IPC_SET_ARG1(call->data, newphid);
|
|---|
| 527 |
|
|---|
| 528 | return EOK;
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | static int r_preprocess_m_clone_establish(call_t *call, phone_t *phone)
|
|---|
| 532 | {
|
|---|
| 533 | IPC_SET_ARG5(call->data, (sysarg_t) phone);
|
|---|
| 534 |
|
|---|
| 535 | return EOK;
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | static int r_preprocess_m_connect_me_to(call_t *call, phone_t *phone)
|
|---|
| 539 | {
|
|---|
| 540 | int newphid = phone_alloc(TASK);
|
|---|
| 541 |
|
|---|
| 542 | if (newphid < 0)
|
|---|
| 543 | return ELIMIT;
|
|---|
| 544 |
|
|---|
| 545 | /* Set arg5 for server */
|
|---|
| 546 | IPC_SET_ARG5(call->data, (sysarg_t) &TASK->phones[newphid]);
|
|---|
| 547 | call->flags |= IPC_CALL_CONN_ME_TO;
|
|---|
| 548 | call->priv = newphid;
|
|---|
| 549 |
|
|---|
| 550 | return EOK;
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | static int r_preprocess_m_share_out(call_t *call, phone_t *phone)
|
|---|
| 554 | {
|
|---|
| 555 | size_t size = as_area_get_size(IPC_GET_ARG1(call->data));
|
|---|
| 556 |
|
|---|
| 557 | if (!size)
|
|---|
| 558 | return EPERM;
|
|---|
| 559 | IPC_SET_ARG2(call->data, size);
|
|---|
| 560 |
|
|---|
| 561 | return EOK;
|
|---|
| 562 | }
|
|---|
| 563 |
|
|---|
| 564 | static int r_preprocess_m_data_read(call_t *call, phone_t *phone)
|
|---|
| 565 | {
|
|---|
| 566 | size_t size = IPC_GET_ARG2(call->data);
|
|---|
| 567 |
|
|---|
| 568 | if (size > DATA_XFER_LIMIT) {
|
|---|
| 569 | int flags = IPC_GET_ARG3(call->data);
|
|---|
| 570 |
|
|---|
| 571 | if (flags & IPC_XF_RESTRICT)
|
|---|
| 572 | IPC_SET_ARG2(call->data, DATA_XFER_LIMIT);
|
|---|
| 573 | else
|
|---|
| 574 | return ELIMIT;
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | return EOK;
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | static int r_preprocess_m_data_write(call_t *call, phone_t *phone)
|
|---|
| 581 | {
|
|---|
| 582 | uintptr_t src = IPC_GET_ARG1(call->data);
|
|---|
| 583 | size_t size = IPC_GET_ARG2(call->data);
|
|---|
| 584 |
|
|---|
| 585 | if (size > DATA_XFER_LIMIT) {
|
|---|
| 586 | int flags = IPC_GET_ARG3(call->data);
|
|---|
| 587 |
|
|---|
| 588 | if (flags & IPC_XF_RESTRICT) {
|
|---|
| 589 | size = DATA_XFER_LIMIT;
|
|---|
| 590 | IPC_SET_ARG2(call->data, size);
|
|---|
| 591 | } else
|
|---|
| 592 | return ELIMIT;
|
|---|
| 593 | }
|
|---|
| 594 |
|
|---|
| 595 | call->buffer = (uint8_t *) malloc(size, 0);
|
|---|
| 596 | int rc = copy_from_uspace(call->buffer, (void *) src, size);
|
|---|
| 597 | if (rc != 0) {
|
|---|
| 598 | free(call->buffer);
|
|---|
| 599 | return rc;
|
|---|
| 600 | }
|
|---|
| 601 |
|
|---|
| 602 | return EOK;
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | static int r_preprocess_m_state_change_authorize(call_t *call, phone_t *phone)
|
|---|
| 606 | {
|
|---|
| 607 | phone_t *sender_phone;
|
|---|
| 608 | task_t *other_task_s;
|
|---|
| 609 |
|
|---|
| 610 | if (phone_get(IPC_GET_ARG5(call->data), &sender_phone) != EOK)
|
|---|
| 611 | return ENOENT;
|
|---|
| 612 |
|
|---|
| 613 | mutex_lock(&sender_phone->lock);
|
|---|
| 614 | if (sender_phone->state != IPC_PHONE_CONNECTED) {
|
|---|
| 615 | mutex_unlock(&sender_phone->lock);
|
|---|
| 616 | return EINVAL;
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | other_task_s = sender_phone->callee->task;
|
|---|
| 620 |
|
|---|
| 621 | mutex_unlock(&sender_phone->lock);
|
|---|
| 622 |
|
|---|
| 623 | /* Remember the third party task hash. */
|
|---|
| 624 | IPC_SET_ARG5(call->data, (sysarg_t) other_task_s);
|
|---|
| 625 |
|
|---|
| 626 | return EOK;
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| [8b243f2] | 629 | /** Called before the request is sent.
|
|---|
| 630 | *
|
|---|
| [da1bafb] | 631 | * @param call Call structure with the request.
|
|---|
| 632 | * @param phone Phone that the call will be sent through.
|
|---|
| 633 | *
|
|---|
| 634 | * @return Return 0 on success, ELIMIT or EPERM on error.
|
|---|
| [7c7aae16] | 635 | *
|
|---|
| 636 | */
|
|---|
| [9a1b20c] | 637 | static int request_preprocess(call_t *call, phone_t *phone)
|
|---|
| [7c7aae16] | 638 | {
|
|---|
| [924c2530] | 639 | int rc = EOK;
|
|---|
| 640 |
|
|---|
| [228e490] | 641 | switch (IPC_GET_IMETHOD(call->data)) {
|
|---|
| [924c2530] | 642 | case IPC_M_CONNECTION_CLONE:
|
|---|
| 643 | rc = r_preprocess_m_connection_clone(call, phone);
|
|---|
| [2c0e5d2] | 644 | break;
|
|---|
| [6aae539d] | 645 | case IPC_M_CLONE_ESTABLISH:
|
|---|
| [924c2530] | 646 | rc = r_preprocess_m_clone_establish(call, phone);
|
|---|
| [2c0e5d2] | 647 | break;
|
|---|
| [924c2530] | 648 | case IPC_M_CONNECT_ME_TO:
|
|---|
| 649 | rc = r_preprocess_m_connect_me_to(call, phone);
|
|---|
| [7c7aae16] | 650 | break;
|
|---|
| [924c2530] | 651 | case IPC_M_SHARE_OUT:
|
|---|
| 652 | rc = r_preprocess_m_share_out(call, phone);
|
|---|
| [7c23af9] | 653 | break;
|
|---|
| [924c2530] | 654 | case IPC_M_DATA_READ:
|
|---|
| 655 | rc = r_preprocess_m_data_read(call, phone);
|
|---|
| [a55d5f9f] | 656 | break;
|
|---|
| [924c2530] | 657 | case IPC_M_DATA_WRITE:
|
|---|
| 658 | rc = r_preprocess_m_data_write(call, phone);
|
|---|
| [7918fce] | 659 | break;
|
|---|
| [924c2530] | 660 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
|---|
| 661 | rc = r_preprocess_m_state_change_authorize(call, phone);
|
|---|
| [fdd4898] | 662 | break;
|
|---|
| [9a1b20c] | 663 | #ifdef CONFIG_UDEBUG
|
|---|
| [79ae36dd] | 664 | case IPC_M_DEBUG:
|
|---|
| [924c2530] | 665 | rc = udebug_request_preprocess(call, phone);
|
|---|
| 666 | break;
|
|---|
| [9a1b20c] | 667 | #endif
|
|---|
| [7c7aae16] | 668 | default:
|
|---|
| 669 | break;
|
|---|
| 670 | }
|
|---|
| [da1bafb] | 671 |
|
|---|
| [924c2530] | 672 | return rc;
|
|---|
| [7c7aae16] | 673 | }
|
|---|
| 674 |
|
|---|
| [8b243f2] | 675 | /*******************************************************************************
|
|---|
| 676 | * Functions called to process received call/answer before passing it to uspace.
|
|---|
| 677 | *******************************************************************************/
|
|---|
| [2d5a54f3] | 678 |
|
|---|
| [8b243f2] | 679 | /** Do basic kernel processing of received call answer.
|
|---|
| 680 | *
|
|---|
| [da1bafb] | 681 | * @param call Call structure with the answer.
|
|---|
| 682 | *
|
|---|
| [8b243f2] | 683 | */
|
|---|
| [7c7aae16] | 684 | static void process_answer(call_t *call)
|
|---|
| [2d5a54f3] | 685 | {
|
|---|
| [6c441cf8] | 686 | if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
|
|---|
| [51ec40f] | 687 | (call->flags & IPC_CALL_FORWARDED))
|
|---|
| [9f22213] | 688 | IPC_SET_RETVAL(call->data, EFORWARD);
|
|---|
| [da1bafb] | 689 |
|
|---|
| [7c7aae16] | 690 | if (call->flags & IPC_CALL_CONN_ME_TO) {
|
|---|
| 691 | if (IPC_GET_RETVAL(call->data))
|
|---|
| [0c1a5d8a] | 692 | phone_dealloc(call->priv);
|
|---|
| [7c7aae16] | 693 | else
|
|---|
| [b61d47d] | 694 | IPC_SET_ARG5(call->data, call->priv);
|
|---|
| [7c7aae16] | 695 | }
|
|---|
| [da1bafb] | 696 |
|
|---|
| [a55d5f9f] | 697 | if (call->buffer) {
|
|---|
| [da1bafb] | 698 | /*
|
|---|
| 699 | * This must be an affirmative answer to IPC_M_DATA_READ
|
|---|
| [79ae36dd] | 700 | * or IPC_M_DEBUG/UDEBUG_M_MEM_READ...
|
|---|
| [da1bafb] | 701 | *
|
|---|
| 702 | */
|
|---|
| [a55d5f9f] | 703 | uintptr_t dst = IPC_GET_ARG1(call->data);
|
|---|
| 704 | size_t size = IPC_GET_ARG2(call->data);
|
|---|
| 705 | int rc = copy_to_uspace((void *) dst, call->buffer, size);
|
|---|
| 706 | if (rc)
|
|---|
| 707 | IPC_SET_RETVAL(call->data, rc);
|
|---|
| 708 | free(call->buffer);
|
|---|
| 709 | call->buffer = NULL;
|
|---|
| 710 | }
|
|---|
| [2d5a54f3] | 711 | }
|
|---|
| 712 |
|
|---|
| [8b243f2] | 713 | /** Do basic kernel processing of received call request.
|
|---|
| 714 | *
|
|---|
| [da1bafb] | 715 | * @param box Destination answerbox structure.
|
|---|
| 716 | * @param call Call structure with the request.
|
|---|
| 717 | *
|
|---|
| 718 | * @return 0 if the call should be passed to userspace.
|
|---|
| 719 | * @return -1 if the call should be ignored.
|
|---|
| [2d5a54f3] | 720 | *
|
|---|
| 721 | */
|
|---|
| [51ec40f] | 722 | static int process_request(answerbox_t *box, call_t *call)
|
|---|
| [2d5a54f3] | 723 | {
|
|---|
| [228e490] | 724 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME) {
|
|---|
| [da1bafb] | 725 | int phoneid = phone_alloc(TASK);
|
|---|
| [4e5dabf] | 726 | if (phoneid < 0) { /* Failed to allocate phone */
|
|---|
| [2d5a54f3] | 727 | IPC_SET_RETVAL(call->data, ELIMIT);
|
|---|
| [8b243f2] | 728 | ipc_answer(box, call);
|
|---|
| [2d5a54f3] | 729 | return -1;
|
|---|
| 730 | }
|
|---|
| [da1bafb] | 731 |
|
|---|
| [38c706cc] | 732 | IPC_SET_ARG5(call->data, phoneid);
|
|---|
| [9a1b20c] | 733 | }
|
|---|
| [da1bafb] | 734 |
|
|---|
| [228e490] | 735 | switch (IPC_GET_IMETHOD(call->data)) {
|
|---|
| [79ae36dd] | 736 | case IPC_M_DEBUG:
|
|---|
| [9a1b20c] | 737 | return -1;
|
|---|
| 738 | default:
|
|---|
| 739 | break;
|
|---|
| 740 | }
|
|---|
| [da1bafb] | 741 |
|
|---|
| [2d5a54f3] | 742 | return 0;
|
|---|
| 743 | }
|
|---|
| 744 |
|
|---|
| [97d17fe] | 745 | /** Check that the task did not exceed the allowed limit of asynchronous calls
|
|---|
| 746 | * made over a phone.
|
|---|
| [2d5a54f3] | 747 | *
|
|---|
| [228e490] | 748 | * @param phone Phone to check the limit against.
|
|---|
| 749 | *
|
|---|
| [da1bafb] | 750 | * @return 0 if limit not reached or -1 if limit exceeded.
|
|---|
| 751 | *
|
|---|
| [2d5a54f3] | 752 | */
|
|---|
| [97d17fe] | 753 | static int check_call_limit(phone_t *phone)
|
|---|
| [2d5a54f3] | 754 | {
|
|---|
| [97d17fe] | 755 | if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
|
|---|
| [2d5a54f3] | 756 | return -1;
|
|---|
| [da1bafb] | 757 |
|
|---|
| [2d5a54f3] | 758 | return 0;
|
|---|
| 759 | }
|
|---|
| 760 |
|
|---|
| [8b243f2] | 761 | /** Make a fast asynchronous call over IPC.
|
|---|
| [2d5a54f3] | 762 | *
|
|---|
| [3209923] | 763 | * This function can only handle four arguments of payload, but is faster than
|
|---|
| 764 | * the generic function sys_ipc_call_async_slow().
|
|---|
| [8b243f2] | 765 | *
|
|---|
| [da1bafb] | 766 | * @param phoneid Phone handle for the call.
|
|---|
| [228e490] | 767 | * @param imethod Interface and method of the call.
|
|---|
| [da1bafb] | 768 | * @param arg1 Service-defined payload argument.
|
|---|
| 769 | * @param arg2 Service-defined payload argument.
|
|---|
| 770 | * @param arg3 Service-defined payload argument.
|
|---|
| 771 | * @param arg4 Service-defined payload argument.
|
|---|
| 772 | *
|
|---|
| 773 | * @return Call hash on success.
|
|---|
| 774 | * @return IPC_CALLRET_FATAL in case of a fatal error.
|
|---|
| 775 | * @return IPC_CALLRET_TEMPORARY if there are too many pending
|
|---|
| 776 | * asynchronous requests; answers should be handled first.
|
|---|
| 777 | *
|
|---|
| [2d5a54f3] | 778 | */
|
|---|
| [228e490] | 779 | sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
|
|---|
| [96b02eb9] | 780 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
|---|
| [2d5a54f3] | 781 | {
|
|---|
| [da1bafb] | 782 | phone_t *phone;
|
|---|
| [c9fff17] | 783 | if (phone_get(phoneid, &phone) != EOK)
|
|---|
| 784 | return IPC_CALLRET_FATAL;
|
|---|
| [228e490] | 785 |
|
|---|
| [97d17fe] | 786 | if (check_call_limit(phone))
|
|---|
| 787 | return IPC_CALLRET_TEMPORARY;
|
|---|
| [da1bafb] | 788 |
|
|---|
| 789 | call_t *call = ipc_call_alloc(0);
|
|---|
| [228e490] | 790 | IPC_SET_IMETHOD(call->data, imethod);
|
|---|
| [2d5a54f3] | 791 | IPC_SET_ARG1(call->data, arg1);
|
|---|
| 792 | IPC_SET_ARG2(call->data, arg2);
|
|---|
| [3209923] | 793 | IPC_SET_ARG3(call->data, arg3);
|
|---|
| 794 | IPC_SET_ARG4(call->data, arg4);
|
|---|
| [da1bafb] | 795 |
|
|---|
| [8498915] | 796 | /*
|
|---|
| 797 | * To achieve deterministic behavior, zero out arguments that are beyond
|
|---|
| 798 | * the limits of the fast version.
|
|---|
| 799 | */
|
|---|
| 800 | IPC_SET_ARG5(call->data, 0);
|
|---|
| [da1bafb] | 801 |
|
|---|
| 802 | int res = request_preprocess(call, phone);
|
|---|
| 803 |
|
|---|
| 804 | if (!res)
|
|---|
| [7c7aae16] | 805 | ipc_call(phone, call);
|
|---|
| 806 | else
|
|---|
| 807 | ipc_backsend_err(phone, call, res);
|
|---|
| [da1bafb] | 808 |
|
|---|
| [96b02eb9] | 809 | return (sysarg_t) call;
|
|---|
| [2d5a54f3] | 810 | }
|
|---|
| 811 |
|
|---|
| [8b243f2] | 812 | /** Make an asynchronous IPC call allowing to transmit the entire payload.
|
|---|
| 813 | *
|
|---|
| [da1bafb] | 814 | * @param phoneid Phone handle for the call.
|
|---|
| 815 | * @param data Userspace address of call data with the request.
|
|---|
| 816 | *
|
|---|
| 817 | * @return See sys_ipc_call_async_fast().
|
|---|
| [2d5a54f3] | 818 | *
|
|---|
| 819 | */
|
|---|
| [96b02eb9] | 820 | sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
|
|---|
| [2d5a54f3] | 821 | {
|
|---|
| [da1bafb] | 822 | phone_t *phone;
|
|---|
| [c9fff17] | 823 | if (phone_get(phoneid, &phone) != EOK)
|
|---|
| 824 | return IPC_CALLRET_FATAL;
|
|---|
| [4e49572] | 825 |
|
|---|
| [97d17fe] | 826 | if (check_call_limit(phone))
|
|---|
| 827 | return IPC_CALLRET_TEMPORARY;
|
|---|
| 828 |
|
|---|
| [da1bafb] | 829 | call_t *call = ipc_call_alloc(0);
|
|---|
| 830 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
|---|
| [51ec40f] | 831 | sizeof(call->data.args));
|
|---|
| [f58af46] | 832 | if (rc != 0) {
|
|---|
| 833 | ipc_call_free(call);
|
|---|
| [96b02eb9] | 834 | return (sysarg_t) rc;
|
|---|
| [f58af46] | 835 | }
|
|---|
| [da1bafb] | 836 |
|
|---|
| 837 | int res = request_preprocess(call, phone);
|
|---|
| 838 |
|
|---|
| 839 | if (!res)
|
|---|
| [7c7aae16] | 840 | ipc_call(phone, call);
|
|---|
| 841 | else
|
|---|
| 842 | ipc_backsend_err(phone, call, res);
|
|---|
| [da1bafb] | 843 |
|
|---|
| [96b02eb9] | 844 | return (sysarg_t) call;
|
|---|
| [2d5a54f3] | 845 | }
|
|---|
| 846 |
|
|---|
| [da1bafb] | 847 | /** Forward a received call to another destination
|
|---|
| 848 | *
|
|---|
| 849 | * Common code for both the fast and the slow version.
|
|---|
| 850 | *
|
|---|
| 851 | * @param callid Hash of the call to forward.
|
|---|
| 852 | * @param phoneid Phone handle to use for forwarding.
|
|---|
| [228e490] | 853 | * @param imethod New interface and method to use for the forwarded call.
|
|---|
| [da1bafb] | 854 | * @param arg1 New value of the first argument for the forwarded call.
|
|---|
| 855 | * @param arg2 New value of the second argument for the forwarded call.
|
|---|
| 856 | * @param arg3 New value of the third argument for the forwarded call.
|
|---|
| 857 | * @param arg4 New value of the fourth argument for the forwarded call.
|
|---|
| 858 | * @param arg5 New value of the fifth argument for the forwarded call.
|
|---|
| 859 | * @param mode Flags that specify mode of the forward operation.
|
|---|
| 860 | * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
|
|---|
| 861 | * the function considers only the fast version arguments:
|
|---|
| 862 | * i.e. arg1 and arg2.
|
|---|
| 863 | *
|
|---|
| 864 | * @return 0 on succes, otherwise an error code.
|
|---|
| 865 | *
|
|---|
| 866 | * Warning: Make sure that ARG5 is not rewritten for certain system IPC
|
|---|
| 867 | *
|
|---|
| [2ba7810] | 868 | */
|
|---|
| [96b02eb9] | 869 | static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
|
|---|
| [228e490] | 870 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
|
|---|
| [96b02eb9] | 871 | sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
|
|---|
| [2ba7810] | 872 | {
|
|---|
| [da1bafb] | 873 | call_t *call = get_call(callid);
|
|---|
| [2ba7810] | 874 | if (!call)
|
|---|
| 875 | return ENOENT;
|
|---|
| [48daf64] | 876 |
|
|---|
| [9f22213] | 877 | call->flags |= IPC_CALL_FORWARDED;
|
|---|
| [da1bafb] | 878 |
|
|---|
| 879 | phone_t *phone;
|
|---|
| [c9fff17] | 880 | if (phone_get(phoneid, &phone) != EOK) {
|
|---|
| [2ba7810] | 881 | IPC_SET_RETVAL(call->data, EFORWARD);
|
|---|
| 882 | ipc_answer(&TASK->answerbox, call);
|
|---|
| 883 | return ENOENT;
|
|---|
| [c9fff17] | 884 | }
|
|---|
| [da1bafb] | 885 |
|
|---|
| [228e490] | 886 | if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
|
|---|
| [2ba7810] | 887 | IPC_SET_RETVAL(call->data, EFORWARD);
|
|---|
| 888 | ipc_answer(&TASK->answerbox, call);
|
|---|
| 889 | return EPERM;
|
|---|
| 890 | }
|
|---|
| [da1bafb] | 891 |
|
|---|
| [0dc4258] | 892 | /*
|
|---|
| [4e5dabf] | 893 | * User space is not allowed to change interface and method of system
|
|---|
| [228e490] | 894 | * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
|
|---|
| [4e5dabf] | 895 | * means of imethod, arg1, arg2 and arg3.
|
|---|
| [228e490] | 896 | * If the interface and method is immutable, don't change anything.
|
|---|
| [2ba7810] | 897 | */
|
|---|
| [228e490] | 898 | if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
|
|---|
| 899 | if (method_is_system(IPC_GET_IMETHOD(call->data))) {
|
|---|
| 900 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
|
|---|
| [b61d47d] | 901 | phone_dealloc(IPC_GET_ARG5(call->data));
|
|---|
| [da1bafb] | 902 |
|
|---|
| [228e490] | 903 | IPC_SET_ARG1(call->data, imethod);
|
|---|
| [0dc4258] | 904 | IPC_SET_ARG2(call->data, arg1);
|
|---|
| [b61d47d] | 905 | IPC_SET_ARG3(call->data, arg2);
|
|---|
| [da1bafb] | 906 |
|
|---|
| [4e5dabf] | 907 | if (slow)
|
|---|
| [48daf64] | 908 | IPC_SET_ARG4(call->data, arg3);
|
|---|
| [4e5dabf] | 909 |
|
|---|
| 910 | /*
|
|---|
| 911 | * For system methods we deliberately don't
|
|---|
| 912 | * overwrite ARG5.
|
|---|
| 913 | */
|
|---|
| [0dc4258] | 914 | } else {
|
|---|
| [228e490] | 915 | IPC_SET_IMETHOD(call->data, imethod);
|
|---|
| [0dc4258] | 916 | IPC_SET_ARG1(call->data, arg1);
|
|---|
| [b61d47d] | 917 | IPC_SET_ARG2(call->data, arg2);
|
|---|
| [48daf64] | 918 | if (slow) {
|
|---|
| 919 | IPC_SET_ARG3(call->data, arg3);
|
|---|
| 920 | IPC_SET_ARG4(call->data, arg4);
|
|---|
| 921 | IPC_SET_ARG5(call->data, arg5);
|
|---|
| 922 | }
|
|---|
| [0dc4258] | 923 | }
|
|---|
| [2ba7810] | 924 | }
|
|---|
| [da1bafb] | 925 |
|
|---|
| [d40a8ff] | 926 | return ipc_forward(call, phone, &TASK->answerbox, mode);
|
|---|
| [2ba7810] | 927 | }
|
|---|
| 928 |
|
|---|
| [48daf64] | 929 | /** Forward a received call to another destination - fast version.
|
|---|
| 930 | *
|
|---|
| [228e490] | 931 | * In case the original interface and method is a system method, ARG1, ARG2
|
|---|
| 932 | * and ARG3 are overwritten in the forwarded message with the new method and
|
|---|
| 933 | * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
|
|---|
| 934 | * are rewritten with the new interface and method, arg1 and arg2, respectively.
|
|---|
| 935 | * Also note there is a set of immutable methods, for which the new method and
|
|---|
| 936 | * arguments are not set and these values are ignored.
|
|---|
| [da1bafb] | 937 | *
|
|---|
| 938 | * @param callid Hash of the call to forward.
|
|---|
| 939 | * @param phoneid Phone handle to use for forwarding.
|
|---|
| [228e490] | 940 | * @param imethod New interface and method to use for the forwarded call.
|
|---|
| [da1bafb] | 941 | * @param arg1 New value of the first argument for the forwarded call.
|
|---|
| 942 | * @param arg2 New value of the second argument for the forwarded call.
|
|---|
| 943 | * @param mode Flags that specify mode of the forward operation.
|
|---|
| 944 | *
|
|---|
| 945 | * @return 0 on succes, otherwise an error code.
|
|---|
| 946 | *
|
|---|
| [48daf64] | 947 | */
|
|---|
| [96b02eb9] | 948 | sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
|
|---|
| [228e490] | 949 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
|
|---|
| [48daf64] | 950 | {
|
|---|
| [228e490] | 951 | return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
|
|---|
| [48daf64] | 952 | 0, mode, false);
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| 955 | /** Forward a received call to another destination - slow version.
|
|---|
| 956 | *
|
|---|
| 957 | * This function is the slow verision of the sys_ipc_forward_fast interface.
|
|---|
| [228e490] | 958 | * It can copy all five new arguments and the new interface and method from
|
|---|
| 959 | * the userspace. It naturally extends the functionality of the fast version.
|
|---|
| 960 | * For system methods, it additionally stores the new value of arg3 to ARG4.
|
|---|
| 961 | * For non-system methods, it additionally stores the new value of arg3, arg4
|
|---|
| 962 | * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
|
|---|
| [da1bafb] | 963 | *
|
|---|
| 964 | * @param callid Hash of the call to forward.
|
|---|
| 965 | * @param phoneid Phone handle to use for forwarding.
|
|---|
| 966 | * @param data Userspace address of the new IPC data.
|
|---|
| 967 | * @param mode Flags that specify mode of the forward operation.
|
|---|
| 968 | *
|
|---|
| 969 | * @return 0 on succes, otherwise an error code.
|
|---|
| 970 | *
|
|---|
| [48daf64] | 971 | */
|
|---|
| [96b02eb9] | 972 | sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
|
|---|
| [da1bafb] | 973 | ipc_data_t *data, unsigned int mode)
|
|---|
| [48daf64] | 974 | {
|
|---|
| 975 | ipc_data_t newdata;
|
|---|
| [da1bafb] | 976 | int rc = copy_from_uspace(&newdata.args, &data->args,
|
|---|
| [48daf64] | 977 | sizeof(newdata.args));
|
|---|
| [da1bafb] | 978 | if (rc != 0)
|
|---|
| [96b02eb9] | 979 | return (sysarg_t) rc;
|
|---|
| [da1bafb] | 980 |
|
|---|
| [48daf64] | 981 | return sys_ipc_forward_common(callid, phoneid,
|
|---|
| [228e490] | 982 | IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
|
|---|
| [48daf64] | 983 | IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
|
|---|
| 984 | IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
|
|---|
| 985 | }
|
|---|
| 986 |
|
|---|
| [8b243f2] | 987 | /** Answer an IPC call - fast version.
|
|---|
| 988 | *
|
|---|
| 989 | * This function can handle only two return arguments of payload, but is faster
|
|---|
| 990 | * than the generic sys_ipc_answer().
|
|---|
| 991 | *
|
|---|
| [da1bafb] | 992 | * @param callid Hash of the call to be answered.
|
|---|
| 993 | * @param retval Return value of the answer.
|
|---|
| 994 | * @param arg1 Service-defined return value.
|
|---|
| 995 | * @param arg2 Service-defined return value.
|
|---|
| 996 | * @param arg3 Service-defined return value.
|
|---|
| 997 | * @param arg4 Service-defined return value.
|
|---|
| 998 | *
|
|---|
| 999 | * @return 0 on success, otherwise an error code.
|
|---|
| [8b243f2] | 1000 | *
|
|---|
| 1001 | */
|
|---|
| [96b02eb9] | 1002 | sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
|
|---|
| 1003 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
|---|
| [2d5a54f3] | 1004 | {
|
|---|
| [897f2e76] | 1005 | /* Do not answer notification callids */
|
|---|
| 1006 | if (callid & IPC_CALLID_NOTIFICATION)
|
|---|
| 1007 | return 0;
|
|---|
| [da1bafb] | 1008 |
|
|---|
| 1009 | call_t *call = get_call(callid);
|
|---|
| [2ba7810] | 1010 | if (!call)
|
|---|
| 1011 | return ENOENT;
|
|---|
| [da1bafb] | 1012 |
|
|---|
| 1013 | ipc_data_t saved_data;
|
|---|
| 1014 | bool saved;
|
|---|
| 1015 |
|
|---|
| [9f22213] | 1016 | if (answer_need_old(call)) {
|
|---|
| [2ba7810] | 1017 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
|---|
| [da1bafb] | 1018 | saved = true;
|
|---|
| 1019 | } else
|
|---|
| 1020 | saved = false;
|
|---|
| 1021 |
|
|---|
| [2d5a54f3] | 1022 | IPC_SET_RETVAL(call->data, retval);
|
|---|
| 1023 | IPC_SET_ARG1(call->data, arg1);
|
|---|
| 1024 | IPC_SET_ARG2(call->data, arg2);
|
|---|
| [b74959bd] | 1025 | IPC_SET_ARG3(call->data, arg3);
|
|---|
| 1026 | IPC_SET_ARG4(call->data, arg4);
|
|---|
| [da1bafb] | 1027 |
|
|---|
| [8498915] | 1028 | /*
|
|---|
| 1029 | * To achieve deterministic behavior, zero out arguments that are beyond
|
|---|
| 1030 | * the limits of the fast version.
|
|---|
| 1031 | */
|
|---|
| 1032 | IPC_SET_ARG5(call->data, 0);
|
|---|
| [da1bafb] | 1033 | int rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
|---|
| 1034 |
|
|---|
| [2d5a54f3] | 1035 | ipc_answer(&TASK->answerbox, call);
|
|---|
| [7c23af9] | 1036 | return rc;
|
|---|
| [2d5a54f3] | 1037 | }
|
|---|
| 1038 |
|
|---|
| [8b243f2] | 1039 | /** Answer an IPC call.
|
|---|
| 1040 | *
|
|---|
| [da1bafb] | 1041 | * @param callid Hash of the call to be answered.
|
|---|
| 1042 | * @param data Userspace address of call data with the answer.
|
|---|
| 1043 | *
|
|---|
| 1044 | * @return 0 on success, otherwise an error code.
|
|---|
| [8b243f2] | 1045 | *
|
|---|
| 1046 | */
|
|---|
| [96b02eb9] | 1047 | sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
|
|---|
| [2d5a54f3] | 1048 | {
|
|---|
| [897f2e76] | 1049 | /* Do not answer notification callids */
|
|---|
| 1050 | if (callid & IPC_CALLID_NOTIFICATION)
|
|---|
| 1051 | return 0;
|
|---|
| [da1bafb] | 1052 |
|
|---|
| 1053 | call_t *call = get_call(callid);
|
|---|
| [2ba7810] | 1054 | if (!call)
|
|---|
| 1055 | return ENOENT;
|
|---|
| [da1bafb] | 1056 |
|
|---|
| 1057 | ipc_data_t saved_data;
|
|---|
| 1058 | bool saved;
|
|---|
| 1059 |
|
|---|
| [9f22213] | 1060 | if (answer_need_old(call)) {
|
|---|
| [2ba7810] | 1061 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
|---|
| [da1bafb] | 1062 | saved = true;
|
|---|
| 1063 | } else
|
|---|
| 1064 | saved = false;
|
|---|
| 1065 |
|
|---|
| 1066 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
|---|
| [51ec40f] | 1067 | sizeof(call->data.args));
|
|---|
| [e3c762cd] | 1068 | if (rc != 0)
|
|---|
| 1069 | return rc;
|
|---|
| [da1bafb] | 1070 |
|
|---|
| 1071 | rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
|---|
| [2d5a54f3] | 1072 |
|
|---|
| 1073 | ipc_answer(&TASK->answerbox, call);
|
|---|
| [7c23af9] | 1074 | return rc;
|
|---|
| [2d5a54f3] | 1075 | }
|
|---|
| 1076 |
|
|---|
| [8b243f2] | 1077 | /** Hang up a phone.
|
|---|
| [2d5a54f3] | 1078 | *
|
|---|
| [da1bafb] | 1079 | * @param Phone handle of the phone to be hung up.
|
|---|
| 1080 | *
|
|---|
| 1081 | * @return 0 on success or an error code.
|
|---|
| [8b243f2] | 1082 | *
|
|---|
| [fbcfd458] | 1083 | */
|
|---|
| [96b02eb9] | 1084 | sysarg_t sys_ipc_hangup(sysarg_t phoneid)
|
|---|
| [fbcfd458] | 1085 | {
|
|---|
| 1086 | phone_t *phone;
|
|---|
| [da1bafb] | 1087 |
|
|---|
| [c9fff17] | 1088 | if (phone_get(phoneid, &phone) != EOK)
|
|---|
| 1089 | return ENOENT;
|
|---|
| [da1bafb] | 1090 |
|
|---|
| [d8f7362] | 1091 | if (ipc_phone_hangup(phone))
|
|---|
| [fbcfd458] | 1092 | return -1;
|
|---|
| [da1bafb] | 1093 |
|
|---|
| [fbcfd458] | 1094 | return 0;
|
|---|
| 1095 | }
|
|---|
| 1096 |
|
|---|
| [8b243f2] | 1097 | /** Wait for an incoming IPC call or an answer.
|
|---|
| [fbcfd458] | 1098 | *
|
|---|
| [da1bafb] | 1099 | * @param calldata Pointer to buffer where the call/answer data is stored.
|
|---|
| 1100 | * @param usec Timeout. See waitq_sleep_timeout() for explanation.
|
|---|
| 1101 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
|
|---|
| 1102 | * for explanation.
|
|---|
| 1103 | *
|
|---|
| 1104 | * @return Hash of the call.
|
|---|
| 1105 | * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
|
|---|
| 1106 | * call is a notification. IPC_CALLID_ANSWERED denotes an
|
|---|
| 1107 | * answer.
|
|---|
| [bd5a663] | 1108 | *
|
|---|
| [2d5a54f3] | 1109 | */
|
|---|
| [96b02eb9] | 1110 | sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
|
|---|
| [da1bafb] | 1111 | unsigned int flags)
|
|---|
| [2d5a54f3] | 1112 | {
|
|---|
| 1113 | call_t *call;
|
|---|
| [da1bafb] | 1114 |
|
|---|
| [741fd16] | 1115 | restart:
|
|---|
| [da1bafb] | 1116 |
|
|---|
| [741fd16] | 1117 | #ifdef CONFIG_UDEBUG
|
|---|
| 1118 | udebug_stoppable_begin();
|
|---|
| [da1bafb] | 1119 | #endif
|
|---|
| 1120 |
|
|---|
| [51ec40f] | 1121 | call = ipc_wait_for_call(&TASK->answerbox, usec,
|
|---|
| 1122 | flags | SYNCH_FLAGS_INTERRUPTIBLE);
|
|---|
| [da1bafb] | 1123 |
|
|---|
| [741fd16] | 1124 | #ifdef CONFIG_UDEBUG
|
|---|
| 1125 | udebug_stoppable_end();
|
|---|
| 1126 | #endif
|
|---|
| [da1bafb] | 1127 |
|
|---|
| [9f22213] | 1128 | if (!call)
|
|---|
| 1129 | return 0;
|
|---|
| [da1bafb] | 1130 |
|
|---|
| [5626277] | 1131 | if (call->flags & IPC_CALL_NOTIF) {
|
|---|
| [43752b6] | 1132 | /* Set in_phone_hash to the interrupt counter */
|
|---|
| [0c1a5d8a] | 1133 | call->data.phone = (void *) call->priv;
|
|---|
| [43752b6] | 1134 |
|
|---|
| 1135 | STRUCT_TO_USPACE(calldata, &call->data);
|
|---|
| [da1bafb] | 1136 |
|
|---|
| [5626277] | 1137 | ipc_call_free(call);
|
|---|
| 1138 |
|
|---|
| [96b02eb9] | 1139 | return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
|
|---|
| [5626277] | 1140 | }
|
|---|
| [da1bafb] | 1141 |
|
|---|
| [2d5a54f3] | 1142 | if (call->flags & IPC_CALL_ANSWERED) {
|
|---|
| [7c7aae16] | 1143 | process_answer(call);
|
|---|
| [da1bafb] | 1144 |
|
|---|
| [fbcfd458] | 1145 | if (call->flags & IPC_CALL_DISCARD_ANSWER) {
|
|---|
| 1146 | ipc_call_free(call);
|
|---|
| 1147 | goto restart;
|
|---|
| 1148 | }
|
|---|
| [da1bafb] | 1149 |
|
|---|
| [fbcfd458] | 1150 | STRUCT_TO_USPACE(&calldata->args, &call->data.args);
|
|---|
| [2d5a54f3] | 1151 | ipc_call_free(call);
|
|---|
| [da1bafb] | 1152 |
|
|---|
| [96b02eb9] | 1153 | return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
|
|---|
| [2d5a54f3] | 1154 | }
|
|---|
| [da1bafb] | 1155 |
|
|---|
| [2d5a54f3] | 1156 | if (process_request(&TASK->answerbox, call))
|
|---|
| 1157 | goto restart;
|
|---|
| [da1bafb] | 1158 |
|
|---|
| [7c7aae16] | 1159 | /* Include phone address('id') of the caller in the request,
|
|---|
| 1160 | * copy whole call->data, not only call->data.args */
|
|---|
| [bd55bbb] | 1161 | if (STRUCT_TO_USPACE(calldata, &call->data)) {
|
|---|
| [e06da7e] | 1162 | /*
|
|---|
| 1163 | * The callee will not receive this call and no one else has
|
|---|
| 1164 | * a chance to answer it. Reply with the EPARTY error code.
|
|---|
| [b11ee88] | 1165 | */
|
|---|
| [e06da7e] | 1166 | ipc_data_t saved_data;
|
|---|
| [da1bafb] | 1167 | bool saved;
|
|---|
| 1168 |
|
|---|
| [e06da7e] | 1169 | if (answer_need_old(call)) {
|
|---|
| 1170 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
|---|
| [da1bafb] | 1171 | saved = true;
|
|---|
| 1172 | } else
|
|---|
| 1173 | saved = false;
|
|---|
| [e06da7e] | 1174 |
|
|---|
| 1175 | IPC_SET_RETVAL(call->data, EPARTY);
|
|---|
| [da1bafb] | 1176 | (void) answer_preprocess(call, saved ? &saved_data : NULL);
|
|---|
| [e06da7e] | 1177 | ipc_answer(&TASK->answerbox, call);
|
|---|
| [bd55bbb] | 1178 | return 0;
|
|---|
| 1179 | }
|
|---|
| [da1bafb] | 1180 |
|
|---|
| [96b02eb9] | 1181 | return (sysarg_t) call;
|
|---|
| [2d5a54f3] | 1182 | }
|
|---|
| [5626277] | 1183 |
|
|---|
| [da1bafb] | 1184 | /** Interrupt one thread from sys_ipc_wait_for_call().
|
|---|
| 1185 | *
|
|---|
| 1186 | */
|
|---|
| [96b02eb9] | 1187 | sysarg_t sys_ipc_poke(void)
|
|---|
| [057d21a] | 1188 | {
|
|---|
| [da1bafb] | 1189 | waitq_unsleep(&TASK->answerbox.wq);
|
|---|
| [057d21a] | 1190 | return EOK;
|
|---|
| 1191 | }
|
|---|
| 1192 |
|
|---|
| [8b243f2] | 1193 | /** Connect an IRQ handler to a task.
|
|---|
| [2b017ba] | 1194 | *
|
|---|
| [228e490] | 1195 | * @param inr IRQ number.
|
|---|
| 1196 | * @param devno Device number.
|
|---|
| 1197 | * @param imethod Interface and method to be associated with the notification.
|
|---|
| 1198 | * @param ucode Uspace pointer to the top-half pseudocode.
|
|---|
| [da1bafb] | 1199 | *
|
|---|
| 1200 | * @return EPERM or a return code returned by ipc_irq_register().
|
|---|
| [2b017ba] | 1201 | *
|
|---|
| 1202 | */
|
|---|
| [f044e96] | 1203 | sysarg_t sys_irq_register(inr_t inr, devno_t devno, sysarg_t imethod,
|
|---|
| [51ec40f] | 1204 | irq_code_t *ucode)
|
|---|
| [5626277] | 1205 | {
|
|---|
| [2bb8648] | 1206 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
|---|
| 1207 | return EPERM;
|
|---|
| [da1bafb] | 1208 |
|
|---|
| [228e490] | 1209 | return ipc_irq_register(&TASK->answerbox, inr, devno, imethod, ucode);
|
|---|
| [5626277] | 1210 | }
|
|---|
| 1211 |
|
|---|
| [8b243f2] | 1212 | /** Disconnect an IRQ handler from a task.
|
|---|
| 1213 | *
|
|---|
| [da1bafb] | 1214 | * @param inr IRQ number.
|
|---|
| 1215 | * @param devno Device number.
|
|---|
| 1216 | *
|
|---|
| 1217 | * @return Zero on success or EPERM on error.
|
|---|
| [2b017ba] | 1218 | *
|
|---|
| 1219 | */
|
|---|
| [f044e96] | 1220 | sysarg_t sys_irq_unregister(inr_t inr, devno_t devno)
|
|---|
| [5626277] | 1221 | {
|
|---|
| [2bb8648] | 1222 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
|---|
| 1223 | return EPERM;
|
|---|
| [da1bafb] | 1224 |
|
|---|
| [2b017ba] | 1225 | ipc_irq_unregister(&TASK->answerbox, inr, devno);
|
|---|
| [da1bafb] | 1226 |
|
|---|
| [5626277] | 1227 | return 0;
|
|---|
| 1228 | }
|
|---|
| [b45c443] | 1229 |
|
|---|
| [6b10dab] | 1230 | #ifdef __32_BITS__
|
|---|
| [9a1b20c] | 1231 |
|
|---|
| [6b10dab] | 1232 | /** Syscall connect to a task by ID (32 bits)
|
|---|
| [da1bafb] | 1233 | *
|
|---|
| 1234 | * @return Phone id on success, or negative error code.
|
|---|
| [9a1b20c] | 1235 | *
|
|---|
| 1236 | */
|
|---|
| [6b10dab] | 1237 | sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
|
|---|
| [9a1b20c] | 1238 | {
|
|---|
| 1239 | #ifdef CONFIG_UDEBUG
|
|---|
| [6b10dab] | 1240 | sysarg64_t taskid;
|
|---|
| 1241 | int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
|
|---|
| [9a1b20c] | 1242 | if (rc != 0)
|
|---|
| [96b02eb9] | 1243 | return (sysarg_t) rc;
|
|---|
| [da1bafb] | 1244 |
|
|---|
| [6b10dab] | 1245 | return ipc_connect_kbox((task_id_t) taskid);
|
|---|
| [9a1b20c] | 1246 | #else
|
|---|
| [96b02eb9] | 1247 | return (sysarg_t) ENOTSUP;
|
|---|
| [9a1b20c] | 1248 | #endif
|
|---|
| 1249 | }
|
|---|
| 1250 |
|
|---|
| [6b10dab] | 1251 | #endif /* __32_BITS__ */
|
|---|
| 1252 |
|
|---|
| 1253 | #ifdef __64_BITS__
|
|---|
| 1254 |
|
|---|
| 1255 | /** Syscall connect to a task by ID (64 bits)
|
|---|
| 1256 | *
|
|---|
| 1257 | * @return Phone id on success, or negative error code.
|
|---|
| 1258 | *
|
|---|
| 1259 | */
|
|---|
| 1260 | sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
|
|---|
| 1261 | {
|
|---|
| 1262 | #ifdef CONFIG_UDEBUG
|
|---|
| 1263 | return ipc_connect_kbox((task_id_t) taskid);
|
|---|
| 1264 | #else
|
|---|
| 1265 | return (sysarg_t) ENOTSUP;
|
|---|
| 1266 | #endif
|
|---|
| 1267 | }
|
|---|
| 1268 |
|
|---|
| 1269 | #endif /* __64_BITS__ */
|
|---|
| 1270 |
|
|---|
| [cc73a8a1] | 1271 | /** @}
|
|---|
| [b45c443] | 1272 | */
|
|---|