]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/syscalls-log.cpp
update
[l4.git] / kernel / fiasco / src / kern / syscalls-log.cpp
1 IMPLEMENTATION [log]:
2
3 #include <alloca.h>
4 #include <cstring>
5 #include "config.h"
6 #include "jdb_trace.h"
7 #include "jdb_tbuf.h"
8 #include "types.h"
9 #include "cpu_lock.h"
10
11
12 /** IPC logging.
13     called from interrupt gate.
14  */
15 extern "C" void sys_ipc_log_wrapper(void)
16 {
17   Thread *curr = current_thread();
18   Entry_frame   *regs      = reinterpret_cast<Entry_frame*>(curr->regs());
19   Syscall_frame *ipc_regs  = reinterpret_cast<Syscall_frame*>(curr->regs());
20
21   Mword entry_event_num    = (Mword)-1;
22   Unsigned8 have_snd       = (ipc_regs->ref().op() & L4_obj_ref::Ipc_send)
23                              || (ipc_regs->ref().op() == L4_obj_ref::Ipc_call);
24   Unsigned8 is_next_period = ipc_regs->next_period();
25   Utcb *utcb = curr->utcb().access(true);
26   int do_log               = Jdb_ipc_trace::log() &&
27                                 Jdb_ipc_trace::check_restriction (curr->dbg_id(),
28                                          static_cast<Task*>(curr->space())->dbg_id(),
29                                          ipc_regs, 0);
30
31   if (Jdb_nextper_trace::log() && is_next_period)
32     {
33       Tb_entry_ipc *tb = static_cast<Tb_entry_ipc*>(Jdb_tbuf::new_entry());
34       tb->set(curr, regs->ip(), ipc_regs, utcb,
35               0, curr->sched_context()->left());
36       Jdb_tbuf::commit_entry();
37       goto skip_ipc_log;
38     }
39
40   if (do_log)
41     {
42       Mword dbg_id;
43         {
44           Obj_cap r = ipc_regs->ref();
45           unsigned char rights;
46           Kobject_iface *o = r.deref(&rights, true);
47           if (o)
48             dbg_id = o->dbg_info()->dbg_id();
49           else
50             dbg_id = ~0UL;
51         }
52       Tb_entry_ipc *tb = static_cast<Tb_entry_ipc*>
53         (EXPECT_TRUE(Jdb_ipc_trace::log_buf()) ? Jdb_tbuf::new_entry()
54                                            : alloca(sizeof(Tb_entry_ipc)));
55       tb->set(curr, regs->ip(), ipc_regs, utcb,
56               dbg_id, curr->sched_context()->left());
57
58       entry_event_num = tb->number();
59
60       if (EXPECT_TRUE(Jdb_ipc_trace::log_buf()))
61         Jdb_tbuf::commit_entry();
62       else
63         Jdb_tbuf::direct_log_entry(tb, "IPC");
64     }
65
66 skip_ipc_log:
67
68   // now pass control to regular sys_ipc()
69   sys_ipc_wrapper();
70
71   if (Jdb_nextper_trace::log() && is_next_period)
72     {
73       Tb_entry_ipc_res *tb =
74             static_cast<Tb_entry_ipc_res*>(Jdb_tbuf::new_entry());
75       tb->set(curr, regs->ip(), ipc_regs, utcb, 0,
76               entry_event_num, have_snd, is_next_period);
77       Jdb_tbuf::commit_entry();
78       goto skip_ipc_res_log;
79     }
80
81   if (Jdb_ipc_trace::log() && Jdb_ipc_trace::log_result() && do_log)
82     {
83       Tb_entry_ipc_res *tb = static_cast<Tb_entry_ipc_res*>
84         (EXPECT_TRUE(Jdb_ipc_trace::log_buf()) ? Jdb_tbuf::new_entry()
85                                             : alloca(sizeof(Tb_entry_ipc_res)));
86       tb->set(curr, regs->ip(), ipc_regs, utcb, utcb->error.raw(),
87               entry_event_num, have_snd, is_next_period);
88
89       if (EXPECT_TRUE(Jdb_ipc_trace::log_buf()))
90         Jdb_tbuf::commit_entry();
91       else
92         Jdb_tbuf::direct_log_entry(tb, "IPC result");
93     }
94
95 skip_ipc_res_log:
96   ;
97 }
98
99 /** IPC tracing.
100  */
101 extern "C" void sys_ipc_trace_wrapper(void)
102 {
103   Thread *curr = current_thread();
104   Entry_frame *ef      = nonull_static_cast<Entry_frame*>(curr->regs());
105   Syscall_frame *regs  = curr->regs();
106
107   //Mword      from_spec = regs->from_spec();
108   L4_obj_ref snd_dst   = regs->ref();
109
110   Unsigned64 orig_tsc  = Cpu::rdtsc();
111
112   // first try the fastpath, then the "slowpath"
113   sys_ipc_wrapper();
114
115   // kernel is locked here => no Lock_guard <...> needed
116   Tb_entry_ipc_trace *tb =
117     static_cast<Tb_entry_ipc_trace*>(Jdb_tbuf::new_entry());
118
119   tb->set(curr, ef->ip(), orig_tsc, snd_dst, regs->from_spec(),
120           L4_msg_tag(0,0,0,0), 0, 0);
121
122   Jdb_tbuf::commit_entry();
123 }
124
125