L4Re - L4 Runtime Environment
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
thread
1 // vi:ft=cpp
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>
9  * economic rights: Technische Universität Dresden (Germany)
10  *
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU General Public License 2.
13  * Please see the COPYING-GPL-2 file for details.
14  *
15  * As a special exception, you may use this file as part of a free software
16  * library without restriction. Specifically, if other files instantiate
17  * templates or use macros or inline functions from this file, or you compile
18  * this file and link it with other files to produce an executable, this
19  * file does not by itself cause the resulting executable to be covered by
20  * the GNU General Public License. This exception does not however
21  * invalidate any other reasons why the executable file might be covered by
22  * the GNU General Public License.
23  */
24 
25 #pragma once
26 
27 #include <l4/sys/capability>
28 #include <l4/sys/thread.h>
29 
30 namespace L4 {
31 
38 class Thread : public Kobject_t<Thread, Kobject, L4_PROTO_THREAD>
39 {
41 
42 public:
48  l4_umword_t flags,
49  l4_utcb_t *utcb = l4_utcb()) throw()
50  { return l4_thread_ex_regs_u(cap(), ip, sp, flags, utcb); }
51 
57  l4_umword_t *flags,
58  l4_utcb_t *utcb = l4_utcb()) throw()
59  { return l4_thread_ex_regs_ret_u(cap(), ip, sp, flags, utcb); }
60 
61 
70  class Attr
71  {
72  private:
73  friend class L4::Thread;
74  l4_utcb_t *_u;
75 
76  public:
82  explicit Attr(l4_utcb_t *utcb = l4_utcb()) throw() : _u(utcb)
83  { l4_thread_control_start_u(utcb); }
84 
91  void pager(Cap<void> const &pager) throw()
92  { l4_thread_control_pager_u(pager.cap(), _u); }
93 
99  Cap<void> pager() throw()
100  { return Cap<void>(l4_utcb_mr_u(_u)->mr[1]); }
101 
108  void exc_handler(Cap<void> const &exc_handler) throw()
109  { l4_thread_control_exc_handler_u(exc_handler.cap(), _u); }
110 
117  { return Cap<void>(l4_utcb_mr_u(_u)->mr[2]); }
118 
130  void bind(l4_utcb_t *thread_utcb, Cap<Task> const &task) throw()
131  { l4_thread_control_bind_u(thread_utcb, task.cap(), _u); }
132 
136  void alien(int on) throw()
137  { l4_thread_control_alien_u(_u, on); }
138 
143  void ux_host_syscall(int on) throw()
144  { l4_thread_control_ux_host_syscall_u(_u, on); }
145 
146  };
147 
152  l4_msgtag_t control(Attr const &attr) throw()
153  { return l4_thread_control_commit_u(cap(), attr._u); }
154 
162  { return l4_thread_switch_u(cap(), utcb); }
163 
172  { return l4_thread_stats_time_u(cap(), utcb); }
173 
180  { return l4_thread_vcpu_resume_start_u(utcb); }
181 
188  l4_utcb_t *utcb = l4_utcb()) throw()
189  { return l4_thread_vcpu_resume_commit_u(cap(), tag, utcb); }
190 
195  throw()
196  { return l4_thread_vcpu_control_u(cap(), vcpu_state, utcb); }
197 
202  l4_utcb_t *utcb = l4_utcb()) throw()
203  { return l4_thread_vcpu_control_ext_u(cap(), ext_vcpu_state, utcb); }
204 
211  { return l4_thread_register_del_irq_u(cap(), irq.cap(), u); }
212 
221  {
222  private:
223  friend class Thread;
224  l4_utcb_t *utcb;
225  unsigned cnt;
226 
227  public:
228  explicit Modify_senders(l4_utcb_t *u = l4_utcb()) throw()
229  : utcb(u), cnt(1)
230  {
231  l4_utcb_mr_u(utcb)->mr[0] = L4_THREAD_MODIFY_SENDER_OP;
232  }
233 
249  int add(l4_umword_t match_mask, l4_umword_t match,
250  l4_umword_t del_bits, l4_umword_t add_bits) throw()
251  {
252  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
253  if (cnt >= L4_UTCB_GENERIC_DATA_SIZE - 4)
254  return -L4_ENOMEM;
255  m->mr[cnt++] = match_mask;
256  m->mr[cnt++] = match;
257  m->mr[cnt++] = del_bits;
258  m->mr[cnt++] = add_bits;
259  return 0;
260  }
261  };
262 
271  {
272  return l4_ipc_call(cap(), todo.utcb, l4_msgtag(L4_PROTO_THREAD, todo.cnt, 0, 0), L4_IPC_NEVER);
273  }
274 };
275 }
L4Re - L4 Runtime Environment