This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
time_handlers.py
227 lines (188 loc) · 10.1 KB
/
time_handlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import logging
from util import *
def timer_create_entry_handler(syscall_id, syscall_object, pid):
logging.debug("Entering the timer_create entry handler")
if syscall_object.ret[0] == -1:
raise NotImplementedError('Unsuccessful calls not implemented')
else:
# only SIGEV_NONE is supported as other sigevents can't be replicated as of now
sigev_type = syscall_object.args[3].value.strip()
logging.debug("Sigevent type: " + str(sigev_type))
if sigev_type != 'SIGEV_NONE':
raise NotImplementedError("Sigevent type %s is not supported" % (sigev_type))
addr = cint.peek_register(pid, cint.EDX)
logging.debug('timerid address: %x', addr)
timerid = int(syscall_object.args[-1].value.strip('{}'))
logging.debug(str(timerid))
cint.populate_timer_t_structure(pid, addr, timerid);
noop_current_syscall(pid)
apply_return_conditions(pid, syscall_object)
def timer_extract_and_populate_itimerspec(syscall_object, pid, addr, start_index):
logging.debug('Itimerspec Address: %x', addr)
logging.debug('Extracting itimerspec')
i = start_index
interval_seconds = int(syscall_object.args[i].value.split("{")[2].strip())
interval_nanoseconds = int(syscall_object.args[i+1].value.strip('{}'))
logging.debug('Interval Seconds: %d', interval_seconds)
logging.debug('Interval Nanoseconds: %d', interval_nanoseconds)
value_seconds = int(syscall_object.args[i+2].value.split("{")[1].strip())
value_nanoseconds = int(syscall_object.args[i+3].value.strip('{}'))
logging.debug('Value Seconds: %d', value_seconds)
logging.debug('Value Nanoseconds: %d', value_nanoseconds)
logging.debug('Populating itimerspec structure')
cint.populate_itimerspec_structure(pid, addr,
interval_seconds, interval_nanoseconds,
value_seconds, value_nanoseconds)
def timer_settime_entry_handler(syscall_id, syscall_object, pid):
logging.debug("Entering the timer_settime entry handler")
if syscall_object.ret[0] == -1:
raise NotImplementedError('Unsuccessful calls not implemented')
else:
logging.debug(str(syscall_object.args[-1]))
old_value_present = syscall_object.args[-1].value != 'NULL'
if old_value_present:
logging.debug("Old value present, have to copy it into memory")
addr = cint.peek_register(pid, cint.ESI)
logging.debug('old_value address: %x', addr)
itimerspec_starting_index = 6;
timer_extract_and_populate_itimerspec(syscall_object, pid, addr, itimerspec_starting_index)
noop_current_syscall(pid)
apply_return_conditions(pid, syscall_object)
def timer_gettime_entry_handler(syscall_id, syscall_object, pid):
logging.debug("Entering the timer_gettime entry handler")
if syscall_object.ret[0] == -1:
raise NotImplementedError('Unsuccessful calls not implemented')
else:
logging.debug('Got successful timer_gettime call')
logging.debug('Replaying this system call')
# these should be the same probably?
timer_id_from_trace = int(syscall_object.args[0].value[0].strip('0x'))
timer_id_from_execution = int(cint.peek_register(pid, cint.EBX))
if timer_id_from_trace != timer_id_from_execution:
raise ReplayDeltaError("Timer id ({}) from execution "
"differs from trace ({})"
.format(timer_id_from_execution, timer_id_from_trace))
addr = cint.peek_register(pid, cint.ECX)
itimerspec_starting_index = 1;
timer_extract_and_populate_itimerspec(syscall_object, pid, addr, itimerspec_starting_index)
noop_current_syscall(pid)
apply_return_conditions(pid, syscall_object)
def timer_delete_entry_handler(syscall_id, syscall_object, pid):
logging.debug("Entering the timer_delete entry handler")
noop_current_syscall(pid)
apply_return_conditions(pid, syscall_object)
def time_entry_handler(syscall_id, syscall_object, pid):
logging.debug('Entering time entry handler')
if syscall_object.ret[0] == -1:
raise NotImplementedError('Unsuccessful calls not implemented')
else:
addr = cint.peek_register(pid, cint.EBX)
noop_current_syscall(pid)
logging.debug('Got successful time call')
t = int(syscall_object.ret[0])
logging.debug('time: %d', t)
logging.debug('addr: %d', addr)
if syscall_object.args[0].value != 'NULL':
cint.populate_unsigned_int(pid, addr, t)
apply_return_conditions(pid, syscall_object)
def gettimeofday_entry_handler(syscall_id, syscall_object, pid):
logging.debug('Entering gettimeofday entry handler')
if syscall_object.ret[0] == -1:
raise NotImplementedError('Unsuccessful calls not implemented')
else:
noop_current_syscall(pid)
if syscall_object.args[2].value != 'NULL':
raise NotImplementedError('time zones not implemented')
addr = cint.peek_register(pid, cint.EBX)
seconds = int(syscall_object.args[0].value.strip('{}'))
microseconds = int(syscall_object.args[1].value.strip('{}'))
logging.debug('Address: %x', addr)
logging.debug('Seconds: %d', seconds)
logging.debug('Microseconds: %d', microseconds)
logging.debug('Populating timeval structure')
cint.populate_timeval_structure(pid, addr,
seconds, microseconds)
apply_return_conditions(pid, syscall_object)
def clock_gettime_entry_handler(syscall_id, syscall_object, pid):
logging.debug('Entering clock_gettime entry handler')
if syscall_object.ret[0] == -1:
raise NotImplementedError('Unsuccessful calls not implemented')
else:
logging.debug('Got successful clock_gettime call')
logging.debug('Replaying this system call')
noop_current_syscall(pid)
clock_type_from_trace = syscall_object.args[0].value
clock_type_from_execution = cint.peek_register(pid,
cint.EBX)
# The first arg from execution must be CLOCK_MONOTONIC
# The first arg from the trace must be CLOCK_MONOTONIC
if clock_type_from_trace == 'CLOCK_MONOTONIC':
if clock_type_from_execution != cint.CLOCK_MONOTONIC:
raise ReplayDeltaError('Clock type ({}) from execution '
'differs from trace'
.format(clock_type_from_execution))
if clock_type_from_trace == 'CLOCK_PROCESS_CPUTIME_ID':
if clock_type_from_execution != cint.CLOCK_PROCESS_CPUTIME_ID:
raise ReplayDeltaError('Clock type ({}) from execution '
'differs from trace'
.format(clock_type_from_execution))
seconds = int(syscall_object.args[1].value.strip('{}'))
nanoseconds = int(syscall_object.args[2].value.strip('{}'))
addr = cint.peek_register(pid, cint.ECX)
logging.debug('Seconds: %d', seconds)
logging.debug('Nanoseconds: %d', nanoseconds)
logging.debug('Address: %x', addr)
logging.debug('Populating timespec strucutre')
cint.populate_timespec_structure(pid, addr,
seconds, nanoseconds)
apply_return_conditions(pid, syscall_object)
def times_entry_handler(syscall_id, syscall_object, pid):
logging.debug('Entering times entry handler')
if syscall_object.args[0].value != 'NULL':
raise NotImplementedError('Calls to times() with an out structure are '
'not supported')
logging.debug('Replaying system call')
noop_current_syscall(pid)
apply_return_conditions(pid, syscall_object)
def utimensat_entry_handler(syscall_id, syscall_object, pid):
logging.debug('Entering utimensat entry handler')
validate_integer_argument(pid, syscall_object, 0, 0)
if should_replay_based_on_fd(int(syscall_object.args[0].value)):
noop_current_syscall(pid)
logging.debug('Replaying this system call')
timespec0_addr = cint.peek_register(pid, cint.EDX)
timespec1_addr = timespec0_addr + 4
logging.debug('Timespec 0 addr: %d', timespec0_addr)
logging.debug('Timespec 1 addr: %d', timespec1_addr)
timespec0_seconds = syscall_object.args[2].value
timespec0_seconds = int(timespec0_seconds.strip('{}'))
timespec0_nseconds = syscall_object.args[3].value[0]
timespec0_nseconds = int(timespec0_nseconds.rstrip('}'))
logging.debug('Timespec0 seconds: %d nseconds: %d',
timespec0_seconds,
timespec0_nseconds)
timespec1_seconds = syscall_object.args[4].value
timespec1_seconds = int(timespec1_seconds.strip('{}'))
timespec1_nseconds = syscall_object.args[5].value
timespec1_nseconds = int(timespec1_nseconds.rstrip('}'))
logging.debug('Timespec1 seconds: %d nseconds: %d',
timespec1_seconds,
timespec1_nseconds)
cint.populate_timespec_structure(pid,
timespec0_addr,
timespec0_seconds,
timespec0_nseconds)
cint.populate_timespec_structure(pid,
timespec1_addr,
timespec1_seconds,
timespec1_nseconds)
apply_return_conditions(pid, syscall_object)
else:
swap_trace_fd_to_execution_fd(pid, 0, syscall_object)
logging.debug('Not replaying this system call')
def time_entry_debug_printer(pid, orig_eax, syscall_object):
param = cint.peek_register(pid, cint.EBX)
if param == 0:
logging.debug('Time called with a NULL time_t')
else:
logging.debug('time_t addr: %d', param)