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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fedac2f was 2541646, checked in by Jakub Jermar <jakub@…>, 13 years ago

Do not slam phones of potentially long gone forwarder tasks.
Instead, slam the caller's phone, if it is still connected.

  • Property mode set to 100644
File size: 22.1 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
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
29/** @addtogroup genericipc
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <errno.h>
37#include <memstr.h>
38#include <ipc/ipc.h>
39#include <abi/ipc/methods.h>
40#include <ipc/sysipc.h>
41#include <ipc/sysipc_ops.h>
42#include <ipc/sysipc_priv.h>
43#include <ipc/irq.h>
44#include <ipc/ipcrsc.h>
45#include <ipc/event.h>
46#include <ipc/kbox.h>
47#include <synch/waitq.h>
48#include <arch/interrupt.h>
49#include <syscall/copy.h>
50#include <security/cap.h>
51#include <console/console.h>
52#include <print.h>
53#include <macros.h>
54
55#define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
56
57/** Decide if the interface and method is a system method.
58 *
59 * @param imethod Interface and method to be decided.
60 *
61 * @return True if the interface and method is a system
62 * interface and method.
63 *
64 */
65static inline bool method_is_system(sysarg_t imethod)
66{
67 if (imethod <= IPC_M_LAST_SYSTEM)
68 return true;
69
70 return false;
71}
72
73/** Decide if the message with this interface and method is forwardable.
74 *
75 * Some system messages may be forwarded, for some of them
76 * it is useless.
77 *
78 * @param imethod Interface and method to be decided.
79 *
80 * @return True if the interface and method is forwardable.
81 *
82 */
83static inline bool method_is_forwardable(sysarg_t imethod)
84{
85 switch (imethod) {
86 case IPC_M_CONNECTION_CLONE:
87 case IPC_M_CLONE_ESTABLISH:
88 case IPC_M_PHONE_HUNGUP:
89 /* This message is meant only for the original recipient. */
90 return false;
91 default:
92 return true;
93 }
94}
95
96/** Decide if the message with this interface and method is immutable on forward.
97 *
98 * Some system messages may be forwarded but their content cannot be altered.
99 *
100 * @param imethod Interface and method to be decided.
101 *
102 * @return True if the interface and method is immutable on forward.
103 *
104 */
105static inline bool method_is_immutable(sysarg_t imethod)
106{
107 switch (imethod) {
108 case IPC_M_SHARE_OUT:
109 case IPC_M_SHARE_IN:
110 case IPC_M_DATA_WRITE:
111 case IPC_M_DATA_READ:
112 case IPC_M_STATE_CHANGE_AUTHORIZE:
113 return true;
114 default:
115 return false;
116 }
117}
118
119
120/***********************************************************************
121 * Functions that preprocess answer before sending it to the recepient.
122 ***********************************************************************/
123
124/** Decide if the caller (e.g. ipc_answer()) should save the old call contents
125 * for answer_preprocess().
126 *
127 * @param call Call structure to be decided.
128 *
129 * @return true if the old call contents should be saved.
130 *
131 */
132static inline bool answer_need_old(call_t *call)
133{
134 switch (IPC_GET_IMETHOD(call->data)) {
135 case IPC_M_CONNECTION_CLONE:
136 case IPC_M_CLONE_ESTABLISH:
137 case IPC_M_CONNECT_TO_ME:
138 case IPC_M_CONNECT_ME_TO:
139 case IPC_M_SHARE_OUT:
140 case IPC_M_SHARE_IN:
141 case IPC_M_DATA_WRITE:
142 case IPC_M_DATA_READ:
143 case IPC_M_STATE_CHANGE_AUTHORIZE:
144 return true;
145 default:
146 return false;
147 }
148}
149
150/** Interpret process answer as control information.
151 *
152 * This function is called directly after sys_ipc_answer().
153 *
154 * @param answer Call structure with the answer.
155 * @param olddata Saved data of the request.
156 *
157 * @return Return EOK on success or a negative error code.
158 *
159 */
160int answer_preprocess(call_t *answer, ipc_data_t *olddata)
161{
162 int rc = EOK;
163 sysipc_ops_t *ops;
164
165 spinlock_lock(&answer->forget_lock);
166 if (answer->forget) {
167 /*
168 * This is a forgotten call and answer->sender is not valid.
169 */
170 spinlock_unlock(&answer->forget_lock);
171
172 ops = sysipc_ops_get(answer->request_method);
173 if (ops->answer_cleanup)
174 ops->answer_cleanup(answer, olddata);
175
176 return rc;
177 } else {
178 ASSERT(answer->active);
179
180 /*
181 * Mark the call as inactive to prevent _ipc_answer_free_call()
182 * from attempting to remove the call from the active list
183 * itself.
184 */
185 answer->active = false;
186
187 /*
188 * Remove the call from the sender's active call list.
189 * We enforce this locking order so that any potential
190 * concurrently executing forget operation is forced to
191 * release its active_calls_lock and lose the race to
192 * forget this soon to be answered call.
193 */
194 spinlock_lock(&answer->sender->active_calls_lock);
195 list_remove(&answer->ta_link);
196 spinlock_unlock(&answer->sender->active_calls_lock);
197 }
198 spinlock_unlock(&answer->forget_lock);
199
200 if ((native_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
201 phone_t *phone = answer->caller_phone;
202 mutex_lock(&phone->lock);
203 if (phone->state == IPC_PHONE_CONNECTED) {
204 irq_spinlock_lock(&phone->callee->lock, true);
205 list_remove(&phone->link);
206 phone->state = IPC_PHONE_SLAMMED;
207 irq_spinlock_unlock(&phone->callee->lock, true);
208 }
209 mutex_unlock(&phone->lock);
210 }
211
212 if (!olddata)
213 return rc;
214
215 ops = sysipc_ops_get(answer->request_method);
216 if (ops->answer_preprocess)
217 rc = ops->answer_preprocess(answer, olddata);
218
219 return rc;
220}
221
222/** Called before the request is sent.
223 *
224 * @param call Call structure with the request.
225 * @param phone Phone that the call will be sent through.
226 *
227 * @return Return 0 on success, ELIMIT or EPERM on error.
228 *
229 */
230static int request_preprocess(call_t *call, phone_t *phone)
231{
232 int rc = EOK;
233
234 call->request_method = IPC_GET_IMETHOD(call->data);
235
236 sysipc_ops_t *ops = sysipc_ops_get(call->request_method);
237 if (ops->request_preprocess)
238 rc = ops->request_preprocess(call, phone);
239
240 return rc;
241}
242
243/*******************************************************************************
244 * Functions called to process received call/answer before passing it to uspace.
245 *******************************************************************************/
246
247/** Do basic kernel processing of received call answer.
248 *
249 * @param call Call structure with the answer.
250 *
251 */
252static void process_answer(call_t *call)
253{
254 if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
255 (call->flags & IPC_CALL_FORWARDED))
256 IPC_SET_RETVAL(call->data, EFORWARD);
257
258 sysipc_ops_t *ops = sysipc_ops_get(call->request_method);
259 if (ops->answer_process)
260 (void) ops->answer_process(call);
261}
262
263
264/** Do basic kernel processing of received call request.
265 *
266 * @param box Destination answerbox structure.
267 * @param call Call structure with the request.
268 *
269 * @return 0 if the call should be passed to userspace.
270 * @return -1 if the call should be ignored.
271 *
272 */
273static int process_request(answerbox_t *box, call_t *call)
274{
275 int rc = EOK;
276
277 sysipc_ops_t *ops = sysipc_ops_get(call->request_method);
278 if (ops->request_process)
279 rc = ops->request_process(call, box);
280
281 return rc;
282}
283
284/** Check that the task did not exceed the allowed limit of asynchronous calls
285 * made over a phone.
286 *
287 * @param phone Phone to check the limit against.
288 *
289 * @return 0 if limit not reached or -1 if limit exceeded.
290 *
291 */
292static int check_call_limit(phone_t *phone)
293{
294 if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
295 return -1;
296
297 return 0;
298}
299
300/** Make a fast asynchronous call over IPC.
301 *
302 * This function can only handle four arguments of payload, but is faster than
303 * the generic function sys_ipc_call_async_slow().
304 *
305 * @param phoneid Phone handle for the call.
306 * @param imethod Interface and method of the call.
307 * @param arg1 Service-defined payload argument.
308 * @param arg2 Service-defined payload argument.
309 * @param arg3 Service-defined payload argument.
310 * @param arg4 Service-defined payload argument.
311 *
312 * @return Call hash on success.
313 * @return IPC_CALLRET_FATAL in case of a fatal error.
314 * @return IPC_CALLRET_TEMPORARY if there are too many pending
315 * asynchronous requests; answers should be handled first.
316 *
317 */
318sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
319 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
320{
321 phone_t *phone;
322 if (phone_get(phoneid, &phone) != EOK)
323 return IPC_CALLRET_FATAL;
324
325 if (check_call_limit(phone))
326 return IPC_CALLRET_TEMPORARY;
327
328 call_t *call = ipc_call_alloc(0);
329 IPC_SET_IMETHOD(call->data, imethod);
330 IPC_SET_ARG1(call->data, arg1);
331 IPC_SET_ARG2(call->data, arg2);
332 IPC_SET_ARG3(call->data, arg3);
333 IPC_SET_ARG4(call->data, arg4);
334
335 /*
336 * To achieve deterministic behavior, zero out arguments that are beyond
337 * the limits of the fast version.
338 */
339 IPC_SET_ARG5(call->data, 0);
340
341 int res = request_preprocess(call, phone);
342
343 if (!res)
344 ipc_call(phone, call);
345 else
346 ipc_backsend_err(phone, call, res);
347
348 return (sysarg_t) call;
349}
350
351/** Make an asynchronous IPC call allowing to transmit the entire payload.
352 *
353 * @param phoneid Phone handle for the call.
354 * @param data Userspace address of call data with the request.
355 *
356 * @return See sys_ipc_call_async_fast().
357 *
358 */
359sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
360{
361 phone_t *phone;
362 if (phone_get(phoneid, &phone) != EOK)
363 return IPC_CALLRET_FATAL;
364
365 if (check_call_limit(phone))
366 return IPC_CALLRET_TEMPORARY;
367
368 call_t *call = ipc_call_alloc(0);
369 int rc = copy_from_uspace(&call->data.args, &data->args,
370 sizeof(call->data.args));
371 if (rc != 0) {
372 ipc_call_free(call);
373 return (sysarg_t) rc;
374 }
375
376 int res = request_preprocess(call, phone);
377
378 if (!res)
379 ipc_call(phone, call);
380 else
381 ipc_backsend_err(phone, call, res);
382
383 return (sysarg_t) call;
384}
385
386/** Forward a received call to another destination
387 *
388 * Common code for both the fast and the slow version.
389 *
390 * @param callid Hash of the call to forward.
391 * @param phoneid Phone handle to use for forwarding.
392 * @param imethod New interface and method to use for the forwarded call.
393 * @param arg1 New value of the first argument for the forwarded call.
394 * @param arg2 New value of the second argument for the forwarded call.
395 * @param arg3 New value of the third argument for the forwarded call.
396 * @param arg4 New value of the fourth argument for the forwarded call.
397 * @param arg5 New value of the fifth argument for the forwarded call.
398 * @param mode Flags that specify mode of the forward operation.
399 * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
400 * the function considers only the fast version arguments:
401 * i.e. arg1 and arg2.
402 *
403 * @return 0 on succes, otherwise an error code.
404 *
405 * Warning: Make sure that ARG5 is not rewritten for certain system IPC
406 *
407 */
408static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
409 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
410 sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
411{
412 call_t *call = get_call(callid);
413 phone_t *phone;
414 bool need_old = answer_need_old(call);
415 bool after_forward = false;
416 ipc_data_t old;
417 int rc;
418
419 if (!call)
420 return ENOENT;
421
422 if (need_old)
423 old = call->data;
424
425 if (phone_get(phoneid, &phone) != EOK) {
426 rc = ENOENT;
427 goto error;
428 }
429
430 if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
431 rc = EPERM;
432 goto error;
433 }
434
435 call->flags |= IPC_CALL_FORWARDED;
436
437 /*
438 * User space is not allowed to change interface and method of system
439 * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
440 * means of imethod, arg1, arg2 and arg3.
441 * If the interface and method is immutable, don't change anything.
442 */
443 if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
444 if (method_is_system(IPC_GET_IMETHOD(call->data))) {
445 if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
446 phone_dealloc(IPC_GET_ARG5(call->data));
447
448 IPC_SET_ARG1(call->data, imethod);
449 IPC_SET_ARG2(call->data, arg1);
450 IPC_SET_ARG3(call->data, arg2);
451
452 if (slow)
453 IPC_SET_ARG4(call->data, arg3);
454
455 /*
456 * For system methods we deliberately don't
457 * overwrite ARG5.
458 */
459 } else {
460 IPC_SET_IMETHOD(call->data, imethod);
461 IPC_SET_ARG1(call->data, arg1);
462 IPC_SET_ARG2(call->data, arg2);
463 if (slow) {
464 IPC_SET_ARG3(call->data, arg3);
465 IPC_SET_ARG4(call->data, arg4);
466 IPC_SET_ARG5(call->data, arg5);
467 }
468 }
469 }
470
471 rc = ipc_forward(call, phone, &TASK->answerbox, mode);
472 if (rc != EOK) {
473 after_forward = true;
474 goto error;
475 }
476
477 return EOK;
478
479error:
480 IPC_SET_RETVAL(call->data, EFORWARD);
481 (void) answer_preprocess(call, need_old ? &old : NULL);
482 if (after_forward)
483 _ipc_answer_free_call(call, false);
484 else
485 ipc_answer(&TASK->answerbox, call);
486
487 return rc;
488}
489
490/** Forward a received call to another destination - fast version.
491 *
492 * In case the original interface and method is a system method, ARG1, ARG2
493 * and ARG3 are overwritten in the forwarded message with the new method and
494 * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
495 * are rewritten with the new interface and method, arg1 and arg2, respectively.
496 * Also note there is a set of immutable methods, for which the new method and
497 * arguments are not set and these values are ignored.
498 *
499 * @param callid Hash of the call to forward.
500 * @param phoneid Phone handle to use for forwarding.
501 * @param imethod New interface and method to use for the forwarded call.
502 * @param arg1 New value of the first argument for the forwarded call.
503 * @param arg2 New value of the second argument for the forwarded call.
504 * @param mode Flags that specify mode of the forward operation.
505 *
506 * @return 0 on succes, otherwise an error code.
507 *
508 */
509sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
510 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
511{
512 return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
513 0, mode, false);
514}
515
516/** Forward a received call to another destination - slow version.
517 *
518 * This function is the slow verision of the sys_ipc_forward_fast interface.
519 * It can copy all five new arguments and the new interface and method from
520 * the userspace. It naturally extends the functionality of the fast version.
521 * For system methods, it additionally stores the new value of arg3 to ARG4.
522 * For non-system methods, it additionally stores the new value of arg3, arg4
523 * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
524 *
525 * @param callid Hash of the call to forward.
526 * @param phoneid Phone handle to use for forwarding.
527 * @param data Userspace address of the new IPC data.
528 * @param mode Flags that specify mode of the forward operation.
529 *
530 * @return 0 on succes, otherwise an error code.
531 *
532 */
533sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
534 ipc_data_t *data, unsigned int mode)
535{
536 ipc_data_t newdata;
537 int rc = copy_from_uspace(&newdata.args, &data->args,
538 sizeof(newdata.args));
539 if (rc != 0)
540 return (sysarg_t) rc;
541
542 return sys_ipc_forward_common(callid, phoneid,
543 IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
544 IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
545 IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
546}
547
548/** Answer an IPC call - fast version.
549 *
550 * This function can handle only two return arguments of payload, but is faster
551 * than the generic sys_ipc_answer().
552 *
553 * @param callid Hash of the call to be answered.
554 * @param retval Return value of the answer.
555 * @param arg1 Service-defined return value.
556 * @param arg2 Service-defined return value.
557 * @param arg3 Service-defined return value.
558 * @param arg4 Service-defined return value.
559 *
560 * @return 0 on success, otherwise an error code.
561 *
562 */
563sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
564 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
565{
566 /* Do not answer notification callids */
567 if (callid & IPC_CALLID_NOTIFICATION)
568 return 0;
569
570 call_t *call = get_call(callid);
571 if (!call)
572 return ENOENT;
573
574 ipc_data_t saved_data;
575 bool saved;
576
577 if (answer_need_old(call)) {
578 memcpy(&saved_data, &call->data, sizeof(call->data));
579 saved = true;
580 } else
581 saved = false;
582
583 IPC_SET_RETVAL(call->data, retval);
584 IPC_SET_ARG1(call->data, arg1);
585 IPC_SET_ARG2(call->data, arg2);
586 IPC_SET_ARG3(call->data, arg3);
587 IPC_SET_ARG4(call->data, arg4);
588
589 /*
590 * To achieve deterministic behavior, zero out arguments that are beyond
591 * the limits of the fast version.
592 */
593 IPC_SET_ARG5(call->data, 0);
594 int rc = answer_preprocess(call, saved ? &saved_data : NULL);
595
596 ipc_answer(&TASK->answerbox, call);
597 return rc;
598}
599
600/** Answer an IPC call.
601 *
602 * @param callid Hash of the call to be answered.
603 * @param data Userspace address of call data with the answer.
604 *
605 * @return 0 on success, otherwise an error code.
606 *
607 */
608sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
609{
610 /* Do not answer notification callids */
611 if (callid & IPC_CALLID_NOTIFICATION)
612 return 0;
613
614 call_t *call = get_call(callid);
615 if (!call)
616 return ENOENT;
617
618 ipc_data_t saved_data;
619 bool saved;
620
621 if (answer_need_old(call)) {
622 memcpy(&saved_data, &call->data, sizeof(call->data));
623 saved = true;
624 } else
625 saved = false;
626
627 int rc = copy_from_uspace(&call->data.args, &data->args,
628 sizeof(call->data.args));
629 if (rc != 0)
630 return rc;
631
632 rc = answer_preprocess(call, saved ? &saved_data : NULL);
633
634 ipc_answer(&TASK->answerbox, call);
635 return rc;
636}
637
638/** Hang up a phone.
639 *
640 * @param Phone handle of the phone to be hung up.
641 *
642 * @return 0 on success or an error code.
643 *
644 */
645sysarg_t sys_ipc_hangup(sysarg_t phoneid)
646{
647 phone_t *phone;
648
649 if (phone_get(phoneid, &phone) != EOK)
650 return ENOENT;
651
652 if (ipc_phone_hangup(phone))
653 return -1;
654
655 return 0;
656}
657
658/** Wait for an incoming IPC call or an answer.
659 *
660 * @param calldata Pointer to buffer where the call/answer data is stored.
661 * @param usec Timeout. See waitq_sleep_timeout() for explanation.
662 * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
663 * for explanation.
664 *
665 * @return Hash of the call.
666 * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
667 * call is a notification. IPC_CALLID_ANSWERED denotes an
668 * answer.
669 *
670 */
671sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
672 unsigned int flags)
673{
674 call_t *call;
675
676restart:
677
678#ifdef CONFIG_UDEBUG
679 udebug_stoppable_begin();
680#endif
681
682 call = ipc_wait_for_call(&TASK->answerbox, usec,
683 flags | SYNCH_FLAGS_INTERRUPTIBLE);
684
685#ifdef CONFIG_UDEBUG
686 udebug_stoppable_end();
687#endif
688
689 if (!call)
690 return 0;
691
692 if (call->flags & IPC_CALL_NOTIF) {
693 /* Set in_phone_hash to the interrupt counter */
694 call->data.phone = (void *) call->priv;
695
696 STRUCT_TO_USPACE(calldata, &call->data);
697
698 ipc_call_free(call);
699
700 return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
701 }
702
703 if (call->flags & IPC_CALL_ANSWERED) {
704 process_answer(call);
705
706 if (call->flags & IPC_CALL_DISCARD_ANSWER) {
707 ipc_call_free(call);
708 goto restart;
709 }
710
711 STRUCT_TO_USPACE(&calldata->args, &call->data.args);
712 ipc_call_free(call);
713
714 return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
715 }
716
717 if (process_request(&TASK->answerbox, call))
718 goto restart;
719
720 /* Include phone address('id') of the caller in the request,
721 * copy whole call->data, not only call->data.args */
722 if (STRUCT_TO_USPACE(calldata, &call->data)) {
723 /*
724 * The callee will not receive this call and no one else has
725 * a chance to answer it. Reply with the EPARTY error code.
726 */
727 ipc_data_t saved_data;
728 bool saved;
729
730 if (answer_need_old(call)) {
731 memcpy(&saved_data, &call->data, sizeof(call->data));
732 saved = true;
733 } else
734 saved = false;
735
736 IPC_SET_RETVAL(call->data, EPARTY);
737 (void) answer_preprocess(call, saved ? &saved_data : NULL);
738 ipc_answer(&TASK->answerbox, call);
739 return 0;
740 }
741
742 return (sysarg_t) call;
743}
744
745/** Interrupt one thread from sys_ipc_wait_for_call().
746 *
747 */
748sysarg_t sys_ipc_poke(void)
749{
750 waitq_unsleep(&TASK->answerbox.wq);
751 return EOK;
752}
753
754/** Connect an IRQ handler to a task.
755 *
756 * @param inr IRQ number.
757 * @param devno Device number.
758 * @param imethod Interface and method to be associated with the notification.
759 * @param ucode Uspace pointer to the top-half pseudocode.
760 *
761 * @return EPERM or a return code returned by ipc_irq_register().
762 *
763 */
764sysarg_t sys_irq_register(inr_t inr, devno_t devno, sysarg_t imethod,
765 irq_code_t *ucode)
766{
767 if (!(cap_get(TASK) & CAP_IRQ_REG))
768 return EPERM;
769
770 return ipc_irq_register(&TASK->answerbox, inr, devno, imethod, ucode);
771}
772
773/** Disconnect an IRQ handler from a task.
774 *
775 * @param inr IRQ number.
776 * @param devno Device number.
777 *
778 * @return Zero on success or EPERM on error.
779 *
780 */
781sysarg_t sys_irq_unregister(inr_t inr, devno_t devno)
782{
783 if (!(cap_get(TASK) & CAP_IRQ_REG))
784 return EPERM;
785
786 ipc_irq_unregister(&TASK->answerbox, inr, devno);
787
788 return 0;
789}
790
791#ifdef __32_BITS__
792
793/** Syscall connect to a task by ID (32 bits)
794 *
795 * @return Phone id on success, or negative error code.
796 *
797 */
798sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
799{
800#ifdef CONFIG_UDEBUG
801 sysarg64_t taskid;
802 int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
803 if (rc != 0)
804 return (sysarg_t) rc;
805
806 return ipc_connect_kbox((task_id_t) taskid);
807#else
808 return (sysarg_t) ENOTSUP;
809#endif
810}
811
812#endif /* __32_BITS__ */
813
814#ifdef __64_BITS__
815
816/** Syscall connect to a task by ID (64 bits)
817 *
818 * @return Phone id on success, or negative error code.
819 *
820 */
821sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
822{
823#ifdef CONFIG_UDEBUG
824 return ipc_connect_kbox((task_id_t) taskid);
825#else
826 return (sysarg_t) ENOTSUP;
827#endif
828}
829
830#endif /* __64_BITS__ */
831
832/** @}
833 */
Note: See TracBrowser for help on using the repository browser.