L4Re - L4 Runtime Environment
thread
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
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 
58 class Thread :
59  public Kobject_t<Thread, Kobject, L4_PROTO_THREAD,
60  Type_info::Demand_t<1> >
61 {
62 public:
86  l4_umword_t flags,
87  l4_utcb_t *utcb = l4_utcb()) throw()
88  { return l4_thread_ex_regs_u(cap(), ip, sp, flags, utcb); }
89 
112  l4_umword_t *flags,
113  l4_utcb_t *utcb = l4_utcb()) throw()
114  { return l4_thread_ex_regs_ret_u(cap(), ip, sp, flags, utcb); }
115 
116 
125  class Attr
126  {
127  private:
128  friend class L4::Thread;
129  l4_utcb_t *_u;
130 
131  public:
138  explicit Attr(l4_utcb_t *utcb = l4_utcb()) throw() : _u(utcb)
139  { l4_thread_control_start_u(utcb); }
140 
148  void pager(Cap<void> const &pager) throw()
149  { l4_thread_control_pager_u(pager.cap(), _u); }
150 
157  Cap<void> pager() throw()
158  { return Cap<void>(l4_utcb_mr_u(_u)->mr[1]); }
159 
167  void exc_handler(Cap<void> const &exc_handler) throw()
168  { l4_thread_control_exc_handler_u(exc_handler.cap(), _u); }
169 
177  { return Cap<void>(l4_utcb_mr_u(_u)->mr[2]); }
178 
191  void bind(l4_utcb_t *thread_utcb, Cap<Task> const &task) throw()
192  { l4_thread_control_bind_u(thread_utcb, task.cap(), _u); }
193 
197  void alien(int on) throw()
198  { l4_thread_control_alien_u(_u, on); }
199 
205  void ux_host_syscall(int on) throw()
206  { l4_thread_control_ux_host_syscall_u(_u, on); }
207 
208  };
209 
215  l4_msgtag_t control(Attr const &attr) throw()
216  { return l4_thread_control_commit_u(cap(), attr._u); }
217 
226  { return l4_thread_switch_u(cap(), utcb); }
227 
237  l4_utcb_t *utcb = l4_utcb()) throw()
238  { return l4_thread_stats_time_u(cap(), us, utcb); }
239 
246  { return l4_thread_vcpu_resume_start_u(utcb); }
247 
254  l4_utcb_t *utcb = l4_utcb()) throw()
255  { return l4_thread_vcpu_resume_commit_u(cap(), tag, utcb); }
256 
273  throw()
274  { return l4_thread_vcpu_control_u(cap(), vcpu_state, utcb); }
275 
297  l4_utcb_t *utcb = l4_utcb()) throw()
298  { return l4_thread_vcpu_control_ext_u(cap(), ext_vcpu_state, utcb); }
299 
314  { return l4_thread_register_del_irq_u(cap(), irq.cap(), u); }
315 
324  {
325  private:
326  friend class Thread;
327  l4_utcb_t *utcb;
328  unsigned cnt;
329 
330  public:
331  explicit Modify_senders(l4_utcb_t *u = l4_utcb()) throw()
332  : utcb(u), cnt(1)
333  {
334  l4_utcb_mr_u(utcb)->mr[0] = L4_THREAD_MODIFY_SENDER_OP;
335  }
336 
352  int add(l4_umword_t match_mask, l4_umword_t match,
353  l4_umword_t del_bits, l4_umword_t add_bits) throw()
354  {
355  l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
356  if (cnt >= L4_UTCB_GENERIC_DATA_SIZE - 4)
357  return -L4_ENOMEM;
358  m->mr[cnt++] = match_mask;
359  m->mr[cnt++] = match;
360  m->mr[cnt++] = del_bits;
361  m->mr[cnt++] = add_bits;
362  return 0;
363  }
364  };
365 
374  {
375  return l4_ipc_call(cap(), todo.utcb, l4_msgtag(L4_PROTO_THREAD, todo.cnt, 0, 0), L4_IPC_NEVER);
376  }
377 };
378 }
l4_msgtag_t ex_regs(l4_addr_t ip, l4_addr_t sp, l4_umword_t flags, l4_utcb_t *utcb=l4_utcb())
Exchange basic thread registers.
Definition: thread:85
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Total number of message register (MRs) available.
Definition: utcb.h:47
l4_msgtag_t l4_thread_vcpu_control_ext_u(l4_cap_idx_t thread, l4_addr_t ext_vcpu_state, l4_utcb_t *utcb) L4_NOTHROW
Enable or disable the extended vCPU feature for the thread.
Definition: thread.h:952
l4_msgtag_t l4_thread_ex_regs_ret_u(l4_cap_idx_t thread, l4_addr_t *ip, l4_addr_t *sp, l4_umword_t *flags, l4_utcb_t *utcb) L4_NOTHROW
Exchange basic thread registers and return previous values.
Definition: thread.h:702
Cap< void > pager()
Get the capability selector used for page-fault messages.
Definition: thread:157
int add(l4_umword_t match_mask, l4_umword_t match, l4_umword_t del_bits, l4_umword_t add_bits)
Add a rule.
Definition: thread:352
l4_msgtag_t switch_to(l4_utcb_t *utcb=l4_utcb())
Switch execution to this thread.
Definition: thread:225
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Cap< void > exc_handler()
Get the capability selector used for exception messages.
Definition: thread:176
l4_msgtag_t vcpu_control(l4_addr_t vcpu_state, l4_utcb_t *utcb=l4_utcb())
Enable or disable the vCPU feature for the thread.
Definition: thread:272
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition: ipc.h:445
l4_msgtag_t stats_time(l4_kernel_clock_t *us, l4_utcb_t *utcb=l4_utcb())
Get consumed time of thread in us.
Definition: thread:236
L4 low-level kernel interface.
Wrapper class for modifying senders.
Definition: thread:323
l4_msgtag_t ex_regs(l4_addr_t *ip, l4_addr_t *sp, l4_umword_t *flags, l4_utcb_t *utcb=l4_utcb())
Exchange basic thread registers and return previous values.
Definition: thread:111
void exc_handler(Cap< void > const &exc_handler)
Set the exception-handler capability selector.
Definition: thread:167
C++ L4 kernel thread interface.
Definition: thread:58
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
L4::Cap related definitions.
Protocol for messages to a thread object.
Definition: types.h:64
void bind(l4_utcb_t *thread_utcb, Cap< Task > const &task)
Bind the thread to a task.
Definition: thread:191
l4_msgtag_t vcpu_resume_commit(l4_msgtag_t tag, l4_utcb_t *utcb=l4_utcb())
vCPU resume, commit.
Definition: thread:253
Attr(l4_utcb_t *utcb=l4_utcb())
Create a thread-attribute object with the given UTCB.
Definition: thread:138
l4_cap_idx_t cap() const
Return capability selector.
Definition: capability.h:52
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition: l4int.h:65
l4_msgtag_t l4_thread_vcpu_control_u(l4_cap_idx_t thread, l4_addr_t vcpu_state, l4_utcb_t *utcb) L4_NOTHROW
Enable or disable the vCPU feature for the thread.
Definition: thread.h:937
l4_msgtag_t register_del_irq(Cap< Irq > irq, l4_utcb_t *u=l4_utcb())
Register an IRQ that will trigger upon deletion events.
Definition: thread:313
l4_msgtag_t l4_thread_ex_regs_u(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp, l4_umword_t flags, l4_utcb_t *utcb) L4_NOTHROW
Exchange basic thread registers.
Definition: thread.h:691
Thread attributes used for control_commit().
Definition: thread:125
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
No memory.
Definition: err.h:50
l4_msgtag_t vcpu_control_ext(l4_addr_t ext_vcpu_state, l4_utcb_t *utcb=l4_utcb())
Enable or disable the extended vCPU feature for the thread.
Definition: thread:296
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
void ux_host_syscall(int on)
Allow host system calls on Fiasco-UX.
Definition: thread:205
l4_cap_idx_t cap() const
Return capability selector.
Definition: kobject:79
l4_msgtag_t vcpu_resume_start(l4_utcb_t *utcb=l4_utcb())
vCPU resume, start.
Definition: thread:245
Helper class to create an L4Re interface class that is derived from a single base class...
Definition: __typeinfo.h:759
l4_msgtag_t control(Attr const &attr)
Commit the given thread-attributes object.
Definition: thread:215
void pager(Cap< void > const &pager)
Set the pager capability selector.
Definition: thread:148
void alien(int on)
Set the thread to alien mode.
Definition: thread:197
C++ interface for capabilities.
Definition: capability.h:13
Message tag data structure.
Definition: types.h:159
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
l4_msgtag_t modify_senders(Modify_senders const &todo)
Apply sender modification rules.
Definition: thread:373
Modify all senders IDs that match the given pattern.
Definition: thread.h:620