Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions qiling/os/linux/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def __init__(self, ql: Qiling, start_address: int, exit_point: int, context = No
if self._set_child_tid_address != None:
self.ql.mem.write_ptr(self._set_child_tid_address, self.id, 4)

self.ql.os.thread_management.add_thread(self)

@property
def ql(self):
return self._ql
Expand Down Expand Up @@ -551,10 +553,15 @@ def stop_thread(self, t):
t.stop()
if t in self.threads:
self.threads.remove(t)
self.ql.log.debug(f"[Thread Manager] Thread IDs: { {t.id for t in self.threads} }")
# Exit the world.
if t == self.main_thread:
self.stop()

def add_thread(self, t):
self.threads.add(t)
self.ql.log.debug(f"[Thread Manager] Thread IDs: { {t.id for t in self.threads} }")

def _clear_queued_msg(self):
try:
msg_before_main_thread = self.ql._msg_before_main_thread
Expand Down Expand Up @@ -586,8 +593,10 @@ def _prepare_lib_patch(self):
def stop(self):
self.ql.log.debug("[Thread Manager] Stop the world.")
self.ql.emu_stop()
for t in self.threads:
gevent.kill(t)
while len(self.threads) != 0:
t = self.threads.pop()
self.ql.log.debug(f"[Thread Manager] Thread IDs: { {t.id for t in self.threads} }")
self.stop_thread(t)

def run(self):
previous_thread = self._prepare_lib_patch()
Expand Down
4 changes: 2 additions & 2 deletions qiling/os/posix/syscall/unistd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def ql_syscall_exit(ql: Qiling, code: int):
if ql.multithread:
def _sched_cb_exit(cur_thread):
ql.log.debug(f"[Thread {cur_thread.get_id()}] Terminated")
cur_thread.stop()
ql.os.thread_management.stop_thread(cur_thread)
cur_thread.exit_code = code

td = ql.os.thread_management.cur_thread
Expand All @@ -43,7 +43,7 @@ def ql_syscall_exit_group(ql: Qiling, code: int):
if ql.multithread:
def _sched_cb_exit(cur_thread):
ql.log.debug(f"[Thread {cur_thread.get_id()}] Terminated")
cur_thread.stop()
ql.os.thread_management.stop_thread(cur_thread)
cur_thread.exit_code = code

td = ql.os.thread_management.cur_thread
Expand Down