source: mainline/kernel/generic/src/ipc/sysipc.c@ b538ca5c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b538ca5c was c0699467, checked in by Martin Decky <martin@…>, 14 years ago

do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared
externalize headers which serve as kernel/uspace API/ABI into a special tree

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