1 /**
2  * \file
3  */
4 /*
5  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
6  *               Michael Hohmuth <hohmuth@os.inf.tu-dresden.de>
7  *     economic rights: Technische Universität Dresden (Germany)
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU Lesser General Public License 2.1.
10  * Please see the COPYING-LGPL-2.1 file for details.
11  */
12 
13 #include <l4/sys/types.h>
14 #include <l4/sys/factory.h>
15 #include <l4/sys/thread.h>
16 #include <l4/sys/scheduler.h>
17 
18 #include <l4/util/thread.h>
19 
20 L4_CV long
l4util_create_thread(l4_cap_idx_t id,l4_utcb_t * thread_utcb,l4_cap_idx_t factory,l4_umword_t pc,l4_umword_t sp,l4_cap_idx_t pager,l4_cap_idx_t task,l4_cap_idx_t scheduler,l4_sched_param_t scp)21 l4util_create_thread(l4_cap_idx_t id, l4_utcb_t *thread_utcb,
22                      l4_cap_idx_t factory,
23                      l4_umword_t pc, l4_umword_t sp, l4_cap_idx_t pager,
24                      l4_cap_idx_t task,
25                      l4_cap_idx_t scheduler, l4_sched_param_t scp) L4_NOTHROW
26 {
27   l4_msgtag_t res = l4_factory_create_thread(factory, id);
28   if (l4_error(res))
29     return l4_error(res);
30 
31   l4_thread_control_start();
32   l4_thread_control_pager(pager);
33   l4_thread_control_bind(thread_utcb, task);
34   res = l4_thread_control_commit(id);
35   if (l4_error(res))
36     return l4_error(res);
37 
38   res = l4_thread_ex_regs(id, pc, sp, 0);
39   if (l4_error(res))
40     return l4_error(res);
41 
42   if (!l4_is_invalid_cap(scheduler))
43     {
44       res = l4_scheduler_run_thread(scheduler, id, &scp);
45       if (l4_error(res))
46         return l4_error(res);
47     }
48 
49   return 0;
50 }
51