]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ux/task-ux.cpp
update
[l4.git] / kernel / fiasco / src / kern / ux / task-ux.cpp
1 IMPLEMENTATION [ux]:
2
3 #include <sys/ptrace.h>
4 #include <sys/wait.h>
5
6 #include "cpu_lock.h"
7 #include "hostproc.h"
8 #include "lock_guard.h"
9 #include "map_util.h"
10 #include "mem_layout.h"
11
12 IMPLEMENT
13 void
14 Task::host_init()
15 {
16   mem_space()->set_pid (Hostproc::create());
17 }
18
19 PRIVATE inline
20 bool
21 Task::invoke_arch(L4_msg_tag &tag, Utcb *utcb)
22 {
23
24   switch (utcb->values[0])
25     {
26     case Ldt_set_x86:
27         {
28           enum
29           {
30             Utcb_values_per_ldt_entry
31               = Cpu::Ldt_entry_size / sizeof(utcb->values[0]),
32           };
33           if (EXPECT_FALSE(tag.words() < 3
34                            || tag.words() % Utcb_values_per_ldt_entry))
35             {
36               tag = commit_result(-L4_err::EInval);
37               return true;
38             }
39
40           unsigned entry_number  = utcb->values[1];
41           unsigned idx           = 2;
42           Mword *trampoline_page = (Mword *)Kmem::kernel_trampoline_page;
43
44           for (; idx < tag.words()
45               ; idx += Utcb_values_per_ldt_entry,
46               ++entry_number)
47             {
48               Gdt_entry *d = (Gdt_entry *)&utcb->values[idx];
49               if (!d->limit())
50                 continue;
51
52               Ldt_user_desc info;
53               info.entry_number    = entry_number;
54               info.base_addr       =  d->base();
55               info.limit           =  d->limit();
56               info.seg_32bit       =  d->seg32();
57               info.contents        =  d->contents();
58               info.read_exec_only  = !d->writable();
59               info.limit_in_pages  =  d->granularity();
60               info.seg_not_present = !d->present();
61               info.useable         =  d->avl();
62
63
64               // Set up data on trampoline
65               for (unsigned i = 0; i < sizeof(info) / sizeof(Mword); i++)
66                 *(trampoline_page + i + 1) = *(((Mword *)&info) + i);
67
68               // Call modify_ldt for given user process
69               Trampoline::syscall(pid(), __NR_modify_ldt,
70                                   1, // write LDT
71                                   Mem_layout::Trampoline_page + sizeof(Mword),
72                                   sizeof(info));
73
74               // Also set this for the fiasco kernel so that
75               // segment registers can be set, this is necessary for signal
76               // handling, esp. for sigreturn to work in the Fiasco kernel
77               // with the context of the client (gs/fs values).
78               if (*(trampoline_page + 1))
79                 Emulation::modify_ldt(*(trampoline_page + 1), // entry
80                                       0,                      // base
81                                       1);                     // size
82             }
83         }
84       return true;
85     }
86
87   return false;
88 }
89
90 /** Map tracebuffer into each userland task for easy access. */
91 IMPLEMENT
92 void
93 Task::map_tbuf ()
94 {
95   return; // FIXME
96 #if 0
97   if (id() != Config::sigma0_taskno)
98     {
99       mem_map (sigma0_task, 
100           L4_fpage(0, 1, Config::PAGE_SHIFT, 
101             Kmem::virt_to_phys ((const void*)(Mem_layout::Tbuf_status_page))),
102           nonull_static_cast<Space*>(this),    // to: space
103           L4_fpage(0, 0, Config::PAGE_SHIFT,
104             Mem_layout::Tbuf_ustatus_page, L4_fpage::Cached), 0);
105
106       for (Address size=0; size<Jdb_tbuf::size(); size+=Config::PAGE_SIZE)
107         {
108           mem_map (sigma0_task,                            // from: space
109               L4_fpage(0, 1, Config::PAGE_SHIFT,
110                 Kmem::virt_to_phys ((const void*)
111                   (Mem_layout::Tbuf_buffer_area+size))),
112               nonull_static_cast<Space*>(this),    // to: space
113               L4_fpage(0, 0, Config::PAGE_SHIFT, 
114                 Mem_layout::Tbuf_ubuffer_area+size, L4_fpage::Cached), 0);
115         }
116     }
117 #endif
118 }
119
120 IMPLEMENT
121 Task::~Task()
122 {
123   free_utcbs();
124   //_state = Dying;
125   //unregister_space();
126   //shutdown();
127   //dequeue_at_parent();
128
129 #if 0
130   if (id() == Config::kernel_taskno)
131     {
132       reset_dirty();            // Must not deallocate kernel pagetable.
133       return;                   // No need to kill kernel process.
134     }
135 #endif
136
137   Lock_guard<Cpu_lock> guard (&cpu_lock);
138
139   pid_t hostpid = pid();
140   ptrace (PTRACE_KILL, hostpid, NULL, NULL);
141
142   while (waitpid (hostpid, NULL, 0) != hostpid)
143     ;
144 }
145
146
147 IMPLEMENT
148 void
149 Task::map_utcb_ptr_page()
150 {
151   //Mem_space::Status res =
152         mem_space()->v_insert(
153             Mem_space::Phys_addr::create(Mem_layout::Utcb_ptr_frame),
154             Mem_space::Addr::create(Mem_layout::Utcb_ptr_page_user),
155             Mem_space::Size::create(Config::PAGE_SIZE),
156             Mem_space::Page_writable
157             | Mem_space::Page_user_accessible
158             | Mem_space::Page_cacheable);
159 }
160