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