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

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

Move handling of IPC_M_CONNECT_ME_TO in process_answer() to its private
ops method.

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