1 /**
2  * \file
3  * Receive endpoint C interface.
4  */
5 /*
6  * (c) 2017 Alexander Warg <alexander.warg@kernkonzept.com>
7  *
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU General Public License 2.
10  * Please see the COPYING-GPL-2 file for details.
11  *
12  * As a special exception, you may use this file as part of a free software
13  * library without restriction.  Specifically, if other files instantiate
14  * templates or use macros or inline functions from this file, or you compile
15  * this file and link it with other files to produce an executable, this
16  * file does not by itself cause the resulting executable to be covered by
17  * the GNU General Public License.  This exception does not however
18  * invalidate any other reasons why the executable file might be covered by
19  * the GNU General Public License.
20  */
21 #pragma once
22 
23 #include <l4/sys/utcb.h>
24 #include <l4/sys/types.h>
25 
26 /**
27  * Bind the IPC gate to a thread.
28  * \ingroup l4_kernel_object_gate_api
29  *
30  * \param ep      The IPC receive endpoint object.
31  * \param thread  The thread object that shall be bound to `ep`.
32  * \param label   Label to assign to `ep`. The two least significant bits
33  *                should usually be set to zero.
34  *
35  * \return Syscall return tag containing one of the following return codes.
36  *
37  * \retval L4_EOK      Operation successful.
38  * \retval -L4_EINVAL  `thread` is not a thread object or other arguments were
39  *                     malformed.
40  * \retval -L4_EPERM   No #L4_CAP_FPAGE_S rights on `ep` or `thread`.
41  */
42 
43 L4_INLINE l4_msgtag_t
44 l4_rcv_ep_bind_thread(l4_cap_idx_t ep, l4_cap_idx_t thread,
45                       l4_umword_t label);
46 
47 /**
48  * \internal
49  * \ingroup l4_kernel_object_gate_api
50  */
51 L4_INLINE l4_msgtag_t
52 l4_rcv_ep_bind_thread_u(l4_cap_idx_t ep, l4_cap_idx_t thread,
53                         l4_umword_t label, l4_utcb_t *utcb);
54 
55 /// Receive endpoint operations.
56 enum L4_rcv_ep_ops
57 {
58   L4_RCV_EP_BIND_OP     = 0x10, /**< Bind operation */
59 };
60 
61 /* IMPLEMENTATION -----------------------------------------------------------*/
62 
63 #include <l4/sys/ipc.h>
64 
65 L4_INLINE l4_msgtag_t
l4_rcv_ep_bind_thread_u(l4_cap_idx_t ep,l4_cap_idx_t thread,l4_umword_t label,l4_utcb_t * utcb)66 l4_rcv_ep_bind_thread_u(l4_cap_idx_t ep,
67                         l4_cap_idx_t thread, l4_umword_t label,
68                         l4_utcb_t *utcb)
69 {
70   l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
71   m->mr[0] = L4_RCV_EP_BIND_OP;
72   m->mr[1] = label;
73   m->mr[2] = l4_map_obj_control(0, 0);
74   m->mr[3] = l4_obj_fpage(thread, 0, L4_CAP_FPAGE_RWS).raw;
75   return l4_ipc_call(ep, utcb, l4_msgtag(L4_PROTO_KOBJECT, 2, 1, 0),
76                      L4_IPC_NEVER);
77 }
78 
79 L4_INLINE l4_msgtag_t
l4_rcv_ep_bind_thread(l4_cap_idx_t ep,l4_cap_idx_t thread,l4_umword_t label)80 l4_rcv_ep_bind_thread(l4_cap_idx_t ep, l4_cap_idx_t thread,
81                       l4_umword_t label)
82 {
83   return l4_rcv_ep_bind_thread_u(ep, thread, label, l4_utcb());
84 }
85 
86 
87