[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 |
|
---|
[8b243f2] | 493 | /** Called before the request is sent.
|
---|
| 494 | *
|
---|
[da1bafb] | 495 | * @param call Call structure with the request.
|
---|
| 496 | * @param phone Phone that the call will be sent through.
|
---|
| 497 | *
|
---|
| 498 | * @return Return 0 on success, ELIMIT or EPERM on error.
|
---|
[7c7aae16] | 499 | *
|
---|
| 500 | */
|
---|
[9a1b20c] | 501 | static int request_preprocess(call_t *call, phone_t *phone)
|
---|
[7c7aae16] | 502 | {
|
---|
[228e490] | 503 | switch (IPC_GET_IMETHOD(call->data)) {
|
---|
[2c0e5d2] | 504 | case IPC_M_CONNECTION_CLONE: {
|
---|
| 505 | phone_t *cloned_phone;
|
---|
[c9fff17] | 506 | if (phone_get(IPC_GET_ARG1(call->data), &cloned_phone) != EOK)
|
---|
| 507 | return ENOENT;
|
---|
[da1bafb] | 508 |
|
---|
[bf1fb9f] | 509 | phones_lock(cloned_phone, phone);
|
---|
[da1bafb] | 510 |
|
---|
[2c0e5d2] | 511 | if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
|
---|
| 512 | phone->state != IPC_PHONE_CONNECTED) {
|
---|
[bf1fb9f] | 513 | phones_unlock(cloned_phone, phone);
|
---|
[2c0e5d2] | 514 | return EINVAL;
|
---|
| 515 | }
|
---|
[da1bafb] | 516 |
|
---|
[2c0e5d2] | 517 | /*
|
---|
| 518 | * We can be pretty sure now that both tasks exist and we are
|
---|
| 519 | * connected to them. As we continue to hold the phone locks,
|
---|
| 520 | * we are effectively preventing them from finishing their
|
---|
| 521 | * potential cleanup.
|
---|
[da1bafb] | 522 | *
|
---|
[2c0e5d2] | 523 | */
|
---|
[da1bafb] | 524 | int newphid = phone_alloc(phone->callee->task);
|
---|
[2c0e5d2] | 525 | if (newphid < 0) {
|
---|
[bf1fb9f] | 526 | phones_unlock(cloned_phone, phone);
|
---|
[2c0e5d2] | 527 | return ELIMIT;
|
---|
| 528 | }
|
---|
[da1bafb] | 529 |
|
---|
[2c0e5d2] | 530 | ipc_phone_connect(&phone->callee->task->phones[newphid],
|
---|
| 531 | cloned_phone->callee);
|
---|
[bf1fb9f] | 532 | phones_unlock(cloned_phone, phone);
|
---|
[da1bafb] | 533 |
|
---|
[2c0e5d2] | 534 | /* Set the new phone for the callee. */
|
---|
| 535 | IPC_SET_ARG1(call->data, newphid);
|
---|
| 536 | break;
|
---|
| 537 | }
|
---|
[6aae539d] | 538 | case IPC_M_CLONE_ESTABLISH:
|
---|
[96b02eb9] | 539 | IPC_SET_ARG5(call->data, (sysarg_t) phone);
|
---|
[2c0e5d2] | 540 | break;
|
---|
[da1bafb] | 541 | case IPC_M_CONNECT_ME_TO: {
|
---|
| 542 | int newphid = phone_alloc(TASK);
|
---|
[7c7aae16] | 543 | if (newphid < 0)
|
---|
| 544 | return ELIMIT;
|
---|
[da1bafb] | 545 |
|
---|
[6364d3c] | 546 | /* Set arg5 for server */
|
---|
[96b02eb9] | 547 | IPC_SET_ARG5(call->data, (sysarg_t) &TASK->phones[newphid]);
|
---|
[7c7aae16] | 548 | call->flags |= IPC_CALL_CONN_ME_TO;
|
---|
[0c1a5d8a] | 549 | call->priv = newphid;
|
---|
[7c7aae16] | 550 | break;
|
---|
[da1bafb] | 551 | }
|
---|
| 552 | case IPC_M_SHARE_OUT: {
|
---|
| 553 | size_t size = as_area_get_size(IPC_GET_ARG1(call->data));
|
---|
[8b243f2] | 554 | if (!size)
|
---|
[7c23af9] | 555 | return EPERM;
|
---|
[da1bafb] | 556 |
|
---|
[fd4d8c0] | 557 | IPC_SET_ARG2(call->data, size);
|
---|
[7c23af9] | 558 | break;
|
---|
[da1bafb] | 559 | }
|
---|
| 560 | case IPC_M_DATA_READ: {
|
---|
| 561 | size_t size = IPC_GET_ARG2(call->data);
|
---|
[f6bffee] | 562 | if (size > DATA_XFER_LIMIT) {
|
---|
| 563 | int flags = IPC_GET_ARG3(call->data);
|
---|
| 564 | if (flags & IPC_XF_RESTRICT)
|
---|
| 565 | IPC_SET_ARG2(call->data, DATA_XFER_LIMIT);
|
---|
| 566 | else
|
---|
| 567 | return ELIMIT;
|
---|
| 568 | }
|
---|
[a55d5f9f] | 569 | break;
|
---|
[da1bafb] | 570 | }
|
---|
| 571 | case IPC_M_DATA_WRITE: {
|
---|
| 572 | uintptr_t src = IPC_GET_ARG1(call->data);
|
---|
| 573 | size_t size = IPC_GET_ARG2(call->data);
|
---|
[7918fce] | 574 |
|
---|
[f6bffee] | 575 | if (size > DATA_XFER_LIMIT) {
|
---|
| 576 | int flags = IPC_GET_ARG3(call->data);
|
---|
| 577 | if (flags & IPC_XF_RESTRICT) {
|
---|
| 578 | size = DATA_XFER_LIMIT;
|
---|
| 579 | IPC_SET_ARG2(call->data, size);
|
---|
| 580 | } else
|
---|
| 581 | return ELIMIT;
|
---|
| 582 | }
|
---|
[7918fce] | 583 |
|
---|
| 584 | call->buffer = (uint8_t *) malloc(size, 0);
|
---|
[da1bafb] | 585 | int rc = copy_from_uspace(call->buffer, (void *) src, size);
|
---|
[7918fce] | 586 | if (rc != 0) {
|
---|
| 587 | free(call->buffer);
|
---|
| 588 | return rc;
|
---|
| 589 | }
|
---|
[da1bafb] | 590 |
|
---|
[7918fce] | 591 | break;
|
---|
[da1bafb] | 592 | }
|
---|
[fdd4898] | 593 | case IPC_M_STATE_CHANGE_AUTHORIZE: {
|
---|
| 594 | phone_t *sender_phone;
|
---|
| 595 | task_t *other_task_s;
|
---|
| 596 |
|
---|
| 597 | if (phone_get(IPC_GET_ARG5(call->data), &sender_phone) != EOK)
|
---|
| 598 | return ENOENT;
|
---|
| 599 |
|
---|
| 600 | mutex_lock(&sender_phone->lock);
|
---|
| 601 | if (sender_phone->state != IPC_PHONE_CONNECTED) {
|
---|
| 602 | mutex_unlock(&sender_phone->lock);
|
---|
| 603 | return EINVAL;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | other_task_s = sender_phone->callee->task;
|
---|
| 607 |
|
---|
| 608 | mutex_unlock(&sender_phone->lock);
|
---|
| 609 |
|
---|
| 610 | /* Remember the third party task hash. */
|
---|
| 611 | IPC_SET_ARG5(call->data, (sysarg_t) other_task_s);
|
---|
| 612 | break;
|
---|
| 613 | }
|
---|
[9a1b20c] | 614 | #ifdef CONFIG_UDEBUG
|
---|
[79ae36dd] | 615 | case IPC_M_DEBUG:
|
---|
[9a1b20c] | 616 | return udebug_request_preprocess(call, phone);
|
---|
| 617 | #endif
|
---|
[7c7aae16] | 618 | default:
|
---|
| 619 | break;
|
---|
| 620 | }
|
---|
[da1bafb] | 621 |
|
---|
[7c7aae16] | 622 | return 0;
|
---|
| 623 | }
|
---|
| 624 |
|
---|
[8b243f2] | 625 | /*******************************************************************************
|
---|
| 626 | * Functions called to process received call/answer before passing it to uspace.
|
---|
| 627 | *******************************************************************************/
|
---|
[2d5a54f3] | 628 |
|
---|
[8b243f2] | 629 | /** Do basic kernel processing of received call answer.
|
---|
| 630 | *
|
---|
[da1bafb] | 631 | * @param call Call structure with the answer.
|
---|
| 632 | *
|
---|
[8b243f2] | 633 | */
|
---|
[7c7aae16] | 634 | static void process_answer(call_t *call)
|
---|
[2d5a54f3] | 635 | {
|
---|
[6c441cf8] | 636 | if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
|
---|
[51ec40f] | 637 | (call->flags & IPC_CALL_FORWARDED))
|
---|
[9f22213] | 638 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[da1bafb] | 639 |
|
---|
[7c7aae16] | 640 | if (call->flags & IPC_CALL_CONN_ME_TO) {
|
---|
| 641 | if (IPC_GET_RETVAL(call->data))
|
---|
[0c1a5d8a] | 642 | phone_dealloc(call->priv);
|
---|
[7c7aae16] | 643 | else
|
---|
[b61d47d] | 644 | IPC_SET_ARG5(call->data, call->priv);
|
---|
[7c7aae16] | 645 | }
|
---|
[da1bafb] | 646 |
|
---|
[a55d5f9f] | 647 | if (call->buffer) {
|
---|
[da1bafb] | 648 | /*
|
---|
| 649 | * This must be an affirmative answer to IPC_M_DATA_READ
|
---|
[79ae36dd] | 650 | * or IPC_M_DEBUG/UDEBUG_M_MEM_READ...
|
---|
[da1bafb] | 651 | *
|
---|
| 652 | */
|
---|
[a55d5f9f] | 653 | uintptr_t dst = IPC_GET_ARG1(call->data);
|
---|
| 654 | size_t size = IPC_GET_ARG2(call->data);
|
---|
| 655 | int rc = copy_to_uspace((void *) dst, call->buffer, size);
|
---|
| 656 | if (rc)
|
---|
| 657 | IPC_SET_RETVAL(call->data, rc);
|
---|
| 658 | free(call->buffer);
|
---|
| 659 | call->buffer = NULL;
|
---|
| 660 | }
|
---|
[2d5a54f3] | 661 | }
|
---|
| 662 |
|
---|
[8b243f2] | 663 | /** Do basic kernel processing of received call request.
|
---|
| 664 | *
|
---|
[da1bafb] | 665 | * @param box Destination answerbox structure.
|
---|
| 666 | * @param call Call structure with the request.
|
---|
| 667 | *
|
---|
| 668 | * @return 0 if the call should be passed to userspace.
|
---|
| 669 | * @return -1 if the call should be ignored.
|
---|
[2d5a54f3] | 670 | *
|
---|
| 671 | */
|
---|
[51ec40f] | 672 | static int process_request(answerbox_t *box, call_t *call)
|
---|
[2d5a54f3] | 673 | {
|
---|
[228e490] | 674 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME) {
|
---|
[da1bafb] | 675 | int phoneid = phone_alloc(TASK);
|
---|
[4e5dabf] | 676 | if (phoneid < 0) { /* Failed to allocate phone */
|
---|
[2d5a54f3] | 677 | IPC_SET_RETVAL(call->data, ELIMIT);
|
---|
[8b243f2] | 678 | ipc_answer(box, call);
|
---|
[2d5a54f3] | 679 | return -1;
|
---|
| 680 | }
|
---|
[da1bafb] | 681 |
|
---|
[38c706cc] | 682 | IPC_SET_ARG5(call->data, phoneid);
|
---|
[9a1b20c] | 683 | }
|
---|
[da1bafb] | 684 |
|
---|
[228e490] | 685 | switch (IPC_GET_IMETHOD(call->data)) {
|
---|
[79ae36dd] | 686 | case IPC_M_DEBUG:
|
---|
[9a1b20c] | 687 | return -1;
|
---|
| 688 | default:
|
---|
| 689 | break;
|
---|
| 690 | }
|
---|
[da1bafb] | 691 |
|
---|
[2d5a54f3] | 692 | return 0;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
[97d17fe] | 695 | /** Check that the task did not exceed the allowed limit of asynchronous calls
|
---|
| 696 | * made over a phone.
|
---|
[2d5a54f3] | 697 | *
|
---|
[228e490] | 698 | * @param phone Phone to check the limit against.
|
---|
| 699 | *
|
---|
[da1bafb] | 700 | * @return 0 if limit not reached or -1 if limit exceeded.
|
---|
| 701 | *
|
---|
[2d5a54f3] | 702 | */
|
---|
[97d17fe] | 703 | static int check_call_limit(phone_t *phone)
|
---|
[2d5a54f3] | 704 | {
|
---|
[97d17fe] | 705 | if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
|
---|
[2d5a54f3] | 706 | return -1;
|
---|
[da1bafb] | 707 |
|
---|
[2d5a54f3] | 708 | return 0;
|
---|
| 709 | }
|
---|
| 710 |
|
---|
[8b243f2] | 711 | /** Make a fast asynchronous call over IPC.
|
---|
[2d5a54f3] | 712 | *
|
---|
[3209923] | 713 | * This function can only handle four arguments of payload, but is faster than
|
---|
| 714 | * the generic function sys_ipc_call_async_slow().
|
---|
[8b243f2] | 715 | *
|
---|
[da1bafb] | 716 | * @param phoneid Phone handle for the call.
|
---|
[228e490] | 717 | * @param imethod Interface and method of the call.
|
---|
[da1bafb] | 718 | * @param arg1 Service-defined payload argument.
|
---|
| 719 | * @param arg2 Service-defined payload argument.
|
---|
| 720 | * @param arg3 Service-defined payload argument.
|
---|
| 721 | * @param arg4 Service-defined payload argument.
|
---|
| 722 | *
|
---|
| 723 | * @return Call hash on success.
|
---|
| 724 | * @return IPC_CALLRET_FATAL in case of a fatal error.
|
---|
| 725 | * @return IPC_CALLRET_TEMPORARY if there are too many pending
|
---|
| 726 | * asynchronous requests; answers should be handled first.
|
---|
| 727 | *
|
---|
[2d5a54f3] | 728 | */
|
---|
[228e490] | 729 | sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
|
---|
[96b02eb9] | 730 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 731 | {
|
---|
[da1bafb] | 732 | phone_t *phone;
|
---|
[c9fff17] | 733 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 734 | return IPC_CALLRET_FATAL;
|
---|
[228e490] | 735 |
|
---|
[97d17fe] | 736 | if (check_call_limit(phone))
|
---|
| 737 | return IPC_CALLRET_TEMPORARY;
|
---|
[da1bafb] | 738 |
|
---|
| 739 | call_t *call = ipc_call_alloc(0);
|
---|
[228e490] | 740 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[2d5a54f3] | 741 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 742 | IPC_SET_ARG2(call->data, arg2);
|
---|
[3209923] | 743 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 744 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 745 |
|
---|
[8498915] | 746 | /*
|
---|
| 747 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 748 | * the limits of the fast version.
|
---|
| 749 | */
|
---|
| 750 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 751 |
|
---|
| 752 | int res = request_preprocess(call, phone);
|
---|
| 753 |
|
---|
| 754 | if (!res)
|
---|
[7c7aae16] | 755 | ipc_call(phone, call);
|
---|
| 756 | else
|
---|
| 757 | ipc_backsend_err(phone, call, res);
|
---|
[da1bafb] | 758 |
|
---|
[96b02eb9] | 759 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 760 | }
|
---|
| 761 |
|
---|
[8b243f2] | 762 | /** Make an asynchronous IPC call allowing to transmit the entire payload.
|
---|
| 763 | *
|
---|
[da1bafb] | 764 | * @param phoneid Phone handle for the call.
|
---|
| 765 | * @param data Userspace address of call data with the request.
|
---|
| 766 | *
|
---|
| 767 | * @return See sys_ipc_call_async_fast().
|
---|
[2d5a54f3] | 768 | *
|
---|
| 769 | */
|
---|
[96b02eb9] | 770 | sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
|
---|
[2d5a54f3] | 771 | {
|
---|
[da1bafb] | 772 | phone_t *phone;
|
---|
[c9fff17] | 773 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 774 | return IPC_CALLRET_FATAL;
|
---|
[4e49572] | 775 |
|
---|
[97d17fe] | 776 | if (check_call_limit(phone))
|
---|
| 777 | return IPC_CALLRET_TEMPORARY;
|
---|
| 778 |
|
---|
[da1bafb] | 779 | call_t *call = ipc_call_alloc(0);
|
---|
| 780 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 781 | sizeof(call->data.args));
|
---|
[f58af46] | 782 | if (rc != 0) {
|
---|
| 783 | ipc_call_free(call);
|
---|
[96b02eb9] | 784 | return (sysarg_t) rc;
|
---|
[f58af46] | 785 | }
|
---|
[da1bafb] | 786 |
|
---|
| 787 | int res = request_preprocess(call, phone);
|
---|
| 788 |
|
---|
| 789 | if (!res)
|
---|
[7c7aae16] | 790 | ipc_call(phone, call);
|
---|
| 791 | else
|
---|
| 792 | ipc_backsend_err(phone, call, res);
|
---|
[da1bafb] | 793 |
|
---|
[96b02eb9] | 794 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 795 | }
|
---|
| 796 |
|
---|
[da1bafb] | 797 | /** Forward a received call to another destination
|
---|
| 798 | *
|
---|
| 799 | * Common code for both the fast and the slow version.
|
---|
| 800 | *
|
---|
| 801 | * @param callid Hash of the call to forward.
|
---|
| 802 | * @param phoneid Phone handle to use for forwarding.
|
---|
[228e490] | 803 | * @param imethod New interface and method to use for the forwarded call.
|
---|
[da1bafb] | 804 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 805 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 806 | * @param arg3 New value of the third argument for the forwarded call.
|
---|
| 807 | * @param arg4 New value of the fourth argument for the forwarded call.
|
---|
| 808 | * @param arg5 New value of the fifth argument for the forwarded call.
|
---|
| 809 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 810 | * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
|
---|
| 811 | * the function considers only the fast version arguments:
|
---|
| 812 | * i.e. arg1 and arg2.
|
---|
| 813 | *
|
---|
| 814 | * @return 0 on succes, otherwise an error code.
|
---|
| 815 | *
|
---|
| 816 | * Warning: Make sure that ARG5 is not rewritten for certain system IPC
|
---|
| 817 | *
|
---|
[2ba7810] | 818 | */
|
---|
[96b02eb9] | 819 | static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
|
---|
[228e490] | 820 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
|
---|
[96b02eb9] | 821 | sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
|
---|
[2ba7810] | 822 | {
|
---|
[da1bafb] | 823 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 824 | if (!call)
|
---|
| 825 | return ENOENT;
|
---|
[48daf64] | 826 |
|
---|
[9f22213] | 827 | call->flags |= IPC_CALL_FORWARDED;
|
---|
[da1bafb] | 828 |
|
---|
| 829 | phone_t *phone;
|
---|
[c9fff17] | 830 | if (phone_get(phoneid, &phone) != EOK) {
|
---|
[2ba7810] | 831 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
| 832 | ipc_answer(&TASK->answerbox, call);
|
---|
| 833 | return ENOENT;
|
---|
[c9fff17] | 834 | }
|
---|
[da1bafb] | 835 |
|
---|
[228e490] | 836 | if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
|
---|
[2ba7810] | 837 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
| 838 | ipc_answer(&TASK->answerbox, call);
|
---|
| 839 | return EPERM;
|
---|
| 840 | }
|
---|
[da1bafb] | 841 |
|
---|
[0dc4258] | 842 | /*
|
---|
[4e5dabf] | 843 | * User space is not allowed to change interface and method of system
|
---|
[228e490] | 844 | * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
|
---|
[4e5dabf] | 845 | * means of imethod, arg1, arg2 and arg3.
|
---|
[228e490] | 846 | * If the interface and method is immutable, don't change anything.
|
---|
[2ba7810] | 847 | */
|
---|
[228e490] | 848 | if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
|
---|
| 849 | if (method_is_system(IPC_GET_IMETHOD(call->data))) {
|
---|
| 850 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
|
---|
[b61d47d] | 851 | phone_dealloc(IPC_GET_ARG5(call->data));
|
---|
[da1bafb] | 852 |
|
---|
[228e490] | 853 | IPC_SET_ARG1(call->data, imethod);
|
---|
[0dc4258] | 854 | IPC_SET_ARG2(call->data, arg1);
|
---|
[b61d47d] | 855 | IPC_SET_ARG3(call->data, arg2);
|
---|
[da1bafb] | 856 |
|
---|
[4e5dabf] | 857 | if (slow)
|
---|
[48daf64] | 858 | IPC_SET_ARG4(call->data, arg3);
|
---|
[4e5dabf] | 859 |
|
---|
| 860 | /*
|
---|
| 861 | * For system methods we deliberately don't
|
---|
| 862 | * overwrite ARG5.
|
---|
| 863 | */
|
---|
[0dc4258] | 864 | } else {
|
---|
[228e490] | 865 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[0dc4258] | 866 | IPC_SET_ARG1(call->data, arg1);
|
---|
[b61d47d] | 867 | IPC_SET_ARG2(call->data, arg2);
|
---|
[48daf64] | 868 | if (slow) {
|
---|
| 869 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 870 | IPC_SET_ARG4(call->data, arg4);
|
---|
| 871 | IPC_SET_ARG5(call->data, arg5);
|
---|
| 872 | }
|
---|
[0dc4258] | 873 | }
|
---|
[2ba7810] | 874 | }
|
---|
[da1bafb] | 875 |
|
---|
[d40a8ff] | 876 | return ipc_forward(call, phone, &TASK->answerbox, mode);
|
---|
[2ba7810] | 877 | }
|
---|
| 878 |
|
---|
[48daf64] | 879 | /** Forward a received call to another destination - fast version.
|
---|
| 880 | *
|
---|
[228e490] | 881 | * In case the original interface and method is a system method, ARG1, ARG2
|
---|
| 882 | * and ARG3 are overwritten in the forwarded message with the new method and
|
---|
| 883 | * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
|
---|
| 884 | * are rewritten with the new interface and method, arg1 and arg2, respectively.
|
---|
| 885 | * Also note there is a set of immutable methods, for which the new method and
|
---|
| 886 | * arguments are not set and these values are ignored.
|
---|
[da1bafb] | 887 | *
|
---|
| 888 | * @param callid Hash of the call to forward.
|
---|
| 889 | * @param phoneid Phone handle to use for forwarding.
|
---|
[228e490] | 890 | * @param imethod New interface and method to use for the forwarded call.
|
---|
[da1bafb] | 891 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 892 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 893 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 894 | *
|
---|
| 895 | * @return 0 on succes, otherwise an error code.
|
---|
| 896 | *
|
---|
[48daf64] | 897 | */
|
---|
[96b02eb9] | 898 | sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
|
---|
[228e490] | 899 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
|
---|
[48daf64] | 900 | {
|
---|
[228e490] | 901 | return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
|
---|
[48daf64] | 902 | 0, mode, false);
|
---|
| 903 | }
|
---|
| 904 |
|
---|
| 905 | /** Forward a received call to another destination - slow version.
|
---|
| 906 | *
|
---|
| 907 | * This function is the slow verision of the sys_ipc_forward_fast interface.
|
---|
[228e490] | 908 | * It can copy all five new arguments and the new interface and method from
|
---|
| 909 | * the userspace. It naturally extends the functionality of the fast version.
|
---|
| 910 | * For system methods, it additionally stores the new value of arg3 to ARG4.
|
---|
| 911 | * For non-system methods, it additionally stores the new value of arg3, arg4
|
---|
| 912 | * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
|
---|
[da1bafb] | 913 | *
|
---|
| 914 | * @param callid Hash of the call to forward.
|
---|
| 915 | * @param phoneid Phone handle to use for forwarding.
|
---|
| 916 | * @param data Userspace address of the new IPC data.
|
---|
| 917 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 918 | *
|
---|
| 919 | * @return 0 on succes, otherwise an error code.
|
---|
| 920 | *
|
---|
[48daf64] | 921 | */
|
---|
[96b02eb9] | 922 | sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
|
---|
[da1bafb] | 923 | ipc_data_t *data, unsigned int mode)
|
---|
[48daf64] | 924 | {
|
---|
| 925 | ipc_data_t newdata;
|
---|
[da1bafb] | 926 | int rc = copy_from_uspace(&newdata.args, &data->args,
|
---|
[48daf64] | 927 | sizeof(newdata.args));
|
---|
[da1bafb] | 928 | if (rc != 0)
|
---|
[96b02eb9] | 929 | return (sysarg_t) rc;
|
---|
[da1bafb] | 930 |
|
---|
[48daf64] | 931 | return sys_ipc_forward_common(callid, phoneid,
|
---|
[228e490] | 932 | IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
|
---|
[48daf64] | 933 | IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
|
---|
| 934 | IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
|
---|
| 935 | }
|
---|
| 936 |
|
---|
[8b243f2] | 937 | /** Answer an IPC call - fast version.
|
---|
| 938 | *
|
---|
| 939 | * This function can handle only two return arguments of payload, but is faster
|
---|
| 940 | * than the generic sys_ipc_answer().
|
---|
| 941 | *
|
---|
[da1bafb] | 942 | * @param callid Hash of the call to be answered.
|
---|
| 943 | * @param retval Return value of the answer.
|
---|
| 944 | * @param arg1 Service-defined return value.
|
---|
| 945 | * @param arg2 Service-defined return value.
|
---|
| 946 | * @param arg3 Service-defined return value.
|
---|
| 947 | * @param arg4 Service-defined return value.
|
---|
| 948 | *
|
---|
| 949 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 950 | *
|
---|
| 951 | */
|
---|
[96b02eb9] | 952 | sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
|
---|
| 953 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 954 | {
|
---|
[897f2e76] | 955 | /* Do not answer notification callids */
|
---|
| 956 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 957 | return 0;
|
---|
[da1bafb] | 958 |
|
---|
| 959 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 960 | if (!call)
|
---|
| 961 | return ENOENT;
|
---|
[da1bafb] | 962 |
|
---|
| 963 | ipc_data_t saved_data;
|
---|
| 964 | bool saved;
|
---|
| 965 |
|
---|
[9f22213] | 966 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 967 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 968 | saved = true;
|
---|
| 969 | } else
|
---|
| 970 | saved = false;
|
---|
| 971 |
|
---|
[2d5a54f3] | 972 | IPC_SET_RETVAL(call->data, retval);
|
---|
| 973 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 974 | IPC_SET_ARG2(call->data, arg2);
|
---|
[b74959bd] | 975 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 976 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 977 |
|
---|
[8498915] | 978 | /*
|
---|
| 979 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 980 | * the limits of the fast version.
|
---|
| 981 | */
|
---|
| 982 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 983 | int rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
| 984 |
|
---|
[2d5a54f3] | 985 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 986 | return rc;
|
---|
[2d5a54f3] | 987 | }
|
---|
| 988 |
|
---|
[8b243f2] | 989 | /** Answer an IPC call.
|
---|
| 990 | *
|
---|
[da1bafb] | 991 | * @param callid Hash of the call to be answered.
|
---|
| 992 | * @param data Userspace address of call data with the answer.
|
---|
| 993 | *
|
---|
| 994 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 995 | *
|
---|
| 996 | */
|
---|
[96b02eb9] | 997 | sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
|
---|
[2d5a54f3] | 998 | {
|
---|
[897f2e76] | 999 | /* Do not answer notification callids */
|
---|
| 1000 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 1001 | return 0;
|
---|
[da1bafb] | 1002 |
|
---|
| 1003 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 1004 | if (!call)
|
---|
| 1005 | return ENOENT;
|
---|
[da1bafb] | 1006 |
|
---|
| 1007 | ipc_data_t saved_data;
|
---|
| 1008 | bool saved;
|
---|
| 1009 |
|
---|
[9f22213] | 1010 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 1011 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 1012 | saved = true;
|
---|
| 1013 | } else
|
---|
| 1014 | saved = false;
|
---|
| 1015 |
|
---|
| 1016 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 1017 | sizeof(call->data.args));
|
---|
[e3c762cd] | 1018 | if (rc != 0)
|
---|
| 1019 | return rc;
|
---|
[da1bafb] | 1020 |
|
---|
| 1021 | rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[2d5a54f3] | 1022 |
|
---|
| 1023 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 1024 | return rc;
|
---|
[2d5a54f3] | 1025 | }
|
---|
| 1026 |
|
---|
[8b243f2] | 1027 | /** Hang up a phone.
|
---|
[2d5a54f3] | 1028 | *
|
---|
[da1bafb] | 1029 | * @param Phone handle of the phone to be hung up.
|
---|
| 1030 | *
|
---|
| 1031 | * @return 0 on success or an error code.
|
---|
[8b243f2] | 1032 | *
|
---|
[fbcfd458] | 1033 | */
|
---|
[96b02eb9] | 1034 | sysarg_t sys_ipc_hangup(sysarg_t phoneid)
|
---|
[fbcfd458] | 1035 | {
|
---|
| 1036 | phone_t *phone;
|
---|
[da1bafb] | 1037 |
|
---|
[c9fff17] | 1038 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 1039 | return ENOENT;
|
---|
[da1bafb] | 1040 |
|
---|
[d8f7362] | 1041 | if (ipc_phone_hangup(phone))
|
---|
[fbcfd458] | 1042 | return -1;
|
---|
[da1bafb] | 1043 |
|
---|
[fbcfd458] | 1044 | return 0;
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
[8b243f2] | 1047 | /** Wait for an incoming IPC call or an answer.
|
---|
[fbcfd458] | 1048 | *
|
---|
[da1bafb] | 1049 | * @param calldata Pointer to buffer where the call/answer data is stored.
|
---|
| 1050 | * @param usec Timeout. See waitq_sleep_timeout() for explanation.
|
---|
| 1051 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
|
---|
| 1052 | * for explanation.
|
---|
| 1053 | *
|
---|
| 1054 | * @return Hash of the call.
|
---|
| 1055 | * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
|
---|
| 1056 | * call is a notification. IPC_CALLID_ANSWERED denotes an
|
---|
| 1057 | * answer.
|
---|
[bd5a663] | 1058 | *
|
---|
[2d5a54f3] | 1059 | */
|
---|
[96b02eb9] | 1060 | sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
|
---|
[da1bafb] | 1061 | unsigned int flags)
|
---|
[2d5a54f3] | 1062 | {
|
---|
| 1063 | call_t *call;
|
---|
[da1bafb] | 1064 |
|
---|
[741fd16] | 1065 | restart:
|
---|
[da1bafb] | 1066 |
|
---|
[741fd16] | 1067 | #ifdef CONFIG_UDEBUG
|
---|
| 1068 | udebug_stoppable_begin();
|
---|
[da1bafb] | 1069 | #endif
|
---|
| 1070 |
|
---|
[51ec40f] | 1071 | call = ipc_wait_for_call(&TASK->answerbox, usec,
|
---|
| 1072 | flags | SYNCH_FLAGS_INTERRUPTIBLE);
|
---|
[da1bafb] | 1073 |
|
---|
[741fd16] | 1074 | #ifdef CONFIG_UDEBUG
|
---|
| 1075 | udebug_stoppable_end();
|
---|
| 1076 | #endif
|
---|
[da1bafb] | 1077 |
|
---|
[9f22213] | 1078 | if (!call)
|
---|
| 1079 | return 0;
|
---|
[da1bafb] | 1080 |
|
---|
[5626277] | 1081 | if (call->flags & IPC_CALL_NOTIF) {
|
---|
[43752b6] | 1082 | /* Set in_phone_hash to the interrupt counter */
|
---|
[0c1a5d8a] | 1083 | call->data.phone = (void *) call->priv;
|
---|
[43752b6] | 1084 |
|
---|
| 1085 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[da1bafb] | 1086 |
|
---|
[5626277] | 1087 | ipc_call_free(call);
|
---|
| 1088 |
|
---|
[96b02eb9] | 1089 | return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
|
---|
[5626277] | 1090 | }
|
---|
[da1bafb] | 1091 |
|
---|
[2d5a54f3] | 1092 | if (call->flags & IPC_CALL_ANSWERED) {
|
---|
[7c7aae16] | 1093 | process_answer(call);
|
---|
[da1bafb] | 1094 |
|
---|
[fbcfd458] | 1095 | if (call->flags & IPC_CALL_DISCARD_ANSWER) {
|
---|
| 1096 | ipc_call_free(call);
|
---|
| 1097 | goto restart;
|
---|
| 1098 | }
|
---|
[da1bafb] | 1099 |
|
---|
[fbcfd458] | 1100 | STRUCT_TO_USPACE(&calldata->args, &call->data.args);
|
---|
[2d5a54f3] | 1101 | ipc_call_free(call);
|
---|
[da1bafb] | 1102 |
|
---|
[96b02eb9] | 1103 | return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
|
---|
[2d5a54f3] | 1104 | }
|
---|
[da1bafb] | 1105 |
|
---|
[2d5a54f3] | 1106 | if (process_request(&TASK->answerbox, call))
|
---|
| 1107 | goto restart;
|
---|
[da1bafb] | 1108 |
|
---|
[7c7aae16] | 1109 | /* Include phone address('id') of the caller in the request,
|
---|
| 1110 | * copy whole call->data, not only call->data.args */
|
---|
[bd55bbb] | 1111 | if (STRUCT_TO_USPACE(calldata, &call->data)) {
|
---|
[e06da7e] | 1112 | /*
|
---|
| 1113 | * The callee will not receive this call and no one else has
|
---|
| 1114 | * a chance to answer it. Reply with the EPARTY error code.
|
---|
[b11ee88] | 1115 | */
|
---|
[e06da7e] | 1116 | ipc_data_t saved_data;
|
---|
[da1bafb] | 1117 | bool saved;
|
---|
| 1118 |
|
---|
[e06da7e] | 1119 | if (answer_need_old(call)) {
|
---|
| 1120 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 1121 | saved = true;
|
---|
| 1122 | } else
|
---|
| 1123 | saved = false;
|
---|
[e06da7e] | 1124 |
|
---|
| 1125 | IPC_SET_RETVAL(call->data, EPARTY);
|
---|
[da1bafb] | 1126 | (void) answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[e06da7e] | 1127 | ipc_answer(&TASK->answerbox, call);
|
---|
[bd55bbb] | 1128 | return 0;
|
---|
| 1129 | }
|
---|
[da1bafb] | 1130 |
|
---|
[96b02eb9] | 1131 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 1132 | }
|
---|
[5626277] | 1133 |
|
---|
[da1bafb] | 1134 | /** Interrupt one thread from sys_ipc_wait_for_call().
|
---|
| 1135 | *
|
---|
| 1136 | */
|
---|
[96b02eb9] | 1137 | sysarg_t sys_ipc_poke(void)
|
---|
[057d21a] | 1138 | {
|
---|
[da1bafb] | 1139 | waitq_unsleep(&TASK->answerbox.wq);
|
---|
[057d21a] | 1140 | return EOK;
|
---|
| 1141 | }
|
---|
| 1142 |
|
---|
[8b243f2] | 1143 | /** Connect an IRQ handler to a task.
|
---|
[2b017ba] | 1144 | *
|
---|
[228e490] | 1145 | * @param inr IRQ number.
|
---|
| 1146 | * @param devno Device number.
|
---|
| 1147 | * @param imethod Interface and method to be associated with the notification.
|
---|
| 1148 | * @param ucode Uspace pointer to the top-half pseudocode.
|
---|
[da1bafb] | 1149 | *
|
---|
| 1150 | * @return EPERM or a return code returned by ipc_irq_register().
|
---|
[2b017ba] | 1151 | *
|
---|
| 1152 | */
|
---|
[f044e96] | 1153 | sysarg_t sys_irq_register(inr_t inr, devno_t devno, sysarg_t imethod,
|
---|
[51ec40f] | 1154 | irq_code_t *ucode)
|
---|
[5626277] | 1155 | {
|
---|
[2bb8648] | 1156 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
---|
| 1157 | return EPERM;
|
---|
[da1bafb] | 1158 |
|
---|
[228e490] | 1159 | return ipc_irq_register(&TASK->answerbox, inr, devno, imethod, ucode);
|
---|
[5626277] | 1160 | }
|
---|
| 1161 |
|
---|
[8b243f2] | 1162 | /** Disconnect an IRQ handler from a task.
|
---|
| 1163 | *
|
---|
[da1bafb] | 1164 | * @param inr IRQ number.
|
---|
| 1165 | * @param devno Device number.
|
---|
| 1166 | *
|
---|
| 1167 | * @return Zero on success or EPERM on error.
|
---|
[2b017ba] | 1168 | *
|
---|
| 1169 | */
|
---|
[f044e96] | 1170 | sysarg_t sys_irq_unregister(inr_t inr, devno_t devno)
|
---|
[5626277] | 1171 | {
|
---|
[2bb8648] | 1172 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
---|
| 1173 | return EPERM;
|
---|
[da1bafb] | 1174 |
|
---|
[2b017ba] | 1175 | ipc_irq_unregister(&TASK->answerbox, inr, devno);
|
---|
[da1bafb] | 1176 |
|
---|
[5626277] | 1177 | return 0;
|
---|
| 1178 | }
|
---|
[b45c443] | 1179 |
|
---|
[6b10dab] | 1180 | #ifdef __32_BITS__
|
---|
[9a1b20c] | 1181 |
|
---|
[6b10dab] | 1182 | /** Syscall connect to a task by ID (32 bits)
|
---|
[da1bafb] | 1183 | *
|
---|
| 1184 | * @return Phone id on success, or negative error code.
|
---|
[9a1b20c] | 1185 | *
|
---|
| 1186 | */
|
---|
[6b10dab] | 1187 | sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
|
---|
[9a1b20c] | 1188 | {
|
---|
| 1189 | #ifdef CONFIG_UDEBUG
|
---|
[6b10dab] | 1190 | sysarg64_t taskid;
|
---|
| 1191 | int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
|
---|
[9a1b20c] | 1192 | if (rc != 0)
|
---|
[96b02eb9] | 1193 | return (sysarg_t) rc;
|
---|
[da1bafb] | 1194 |
|
---|
[6b10dab] | 1195 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
[9a1b20c] | 1196 | #else
|
---|
[96b02eb9] | 1197 | return (sysarg_t) ENOTSUP;
|
---|
[9a1b20c] | 1198 | #endif
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
[6b10dab] | 1201 | #endif /* __32_BITS__ */
|
---|
| 1202 |
|
---|
| 1203 | #ifdef __64_BITS__
|
---|
| 1204 |
|
---|
| 1205 | /** Syscall connect to a task by ID (64 bits)
|
---|
| 1206 | *
|
---|
| 1207 | * @return Phone id on success, or negative error code.
|
---|
| 1208 | *
|
---|
| 1209 | */
|
---|
| 1210 | sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
|
---|
| 1211 | {
|
---|
| 1212 | #ifdef CONFIG_UDEBUG
|
---|
| 1213 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
| 1214 | #else
|
---|
| 1215 | return (sysarg_t) ENOTSUP;
|
---|
| 1216 | #endif
|
---|
| 1217 | }
|
---|
| 1218 |
|
---|
| 1219 | #endif /* __64_BITS__ */
|
---|
| 1220 |
|
---|
[cc73a8a1] | 1221 | /** @}
|
---|
[b45c443] | 1222 | */
|
---|