Refactor in a single package with subpackages
[deliverable/lttng-analyses.git] / lttnganalyses / linuxautomaton / syscalls.py
1 #!/usr/bin/env python3
2 #
3 # The MIT License (MIT)
4 #
5 # Copyright (C) 2015 - Julien Desfossez <jdesfossez@efficios.com>
6 # 2015 - Antoine Busque <abusque@efficios.com>
7 #
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
14 #
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 # SOFTWARE.
25
26 from . import sp, sv
27
28
29 class SyscallsStateProvider(sp.StateProvider):
30 def __init__(self, state):
31 cbs = {
32 'syscall_entry': self._process_syscall_entry,
33 'syscall_exit': self._process_syscall_exit
34 }
35
36 self._state = state
37 self._register_cbs(cbs)
38
39 def process_event(self, ev):
40 self._process_event_cb(ev)
41
42 def _process_syscall_entry(self, event):
43 cpu_id = event['cpu_id']
44
45 if cpu_id not in self._state.cpus:
46 return
47
48 cpu = self._state.cpus[cpu_id]
49 if cpu.current_tid is None:
50 return
51
52 proc = self._state.tids[cpu.current_tid]
53 proc.current_syscall = sv.SyscallEvent.new_from_entry(event)
54
55 def _process_syscall_exit(self, event):
56 cpu_id = event['cpu_id']
57 if cpu_id not in self._state.cpus:
58 return
59
60 cpu = self._state.cpus[cpu_id]
61 if cpu.current_tid is None:
62 return
63
64 proc = self._state.tids[cpu.current_tid]
65 current_syscall = proc.current_syscall
66 if current_syscall is None:
67 return
68
69 current_syscall.process_exit(event)
70
71 self._state.send_notification_cb('syscall_exit',
72 proc=proc,
73 event=event)
74
75 # If it's an IO Syscall, the IO state provider will take care of
76 # clearing the current syscall, so only clear here if it's not
77 if current_syscall.name not in sv.SyscallConsts.IO_SYSCALLS:
78 self._state.tids[cpu.current_tid].current_syscall = None
This page took 0.031076 seconds and 5 git commands to generate.