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