Skip to content

Commit 9851846

Browse files
committed
Don't patch instructions associated with syscalls on the current thread that have been interrupted by signals
We already do this for other threads. The current thread might also have a syscall that has been interrupted by a signal that we don't want to stomp on.
1 parent 702fbd8 commit 9851846

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

src/Monkeypatcher.cc

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -903,32 +903,25 @@ static string bytes_to_string(uint8_t* bytes, size_t size) {
903903
return ss.str();
904904
}
905905

906-
static bool task_safe_for_syscall_patching(RecordTask* t, remote_code_ptr start,
907-
remote_code_ptr end) {
908-
if (t->is_stopped()) {
909-
remote_code_ptr ip = t->ip();
910-
if (start <= ip && ip < end) {
911-
return false;
912-
}
913-
}
914-
for (auto& e : t->pending_events) {
915-
if (e.is_syscall_event()) {
916-
remote_code_ptr ip = e.Syscall().regs.ip();
906+
static bool safe_for_syscall_patching(remote_code_ptr start,
907+
remote_code_ptr end,
908+
RecordTask* exclude_stopped) {
909+
for (auto& p : exclude_stopped->session().tasks()) {
910+
RecordTask* rt = static_cast<RecordTask*>(p.second);
911+
if (rt != exclude_stopped && rt->is_stopped()) {
912+
remote_code_ptr ip = rt->ip();
917913
if (start <= ip && ip < end) {
918914
return false;
919915
}
920916
}
921-
}
922-
return true;
923-
}
924917

925-
static bool safe_for_syscall_patching(remote_code_ptr start,
926-
remote_code_ptr end,
927-
RecordTask* exclude) {
928-
for (auto& p : exclude->session().tasks()) {
929-
RecordTask* rt = static_cast<RecordTask*>(p.second);
930-
if (rt != exclude && !task_safe_for_syscall_patching(rt, start, end)) {
931-
return false;
918+
for (auto& e : rt->pending_events) {
919+
if (e.is_syscall_event()) {
920+
remote_code_ptr ip = e.Syscall().regs.ip();
921+
if (start <= ip && ip < end) {
922+
return false;
923+
}
924+
}
932925
}
933926
}
934927
return true;

0 commit comments

Comments
 (0)