Skip to content
Open
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
23 changes: 21 additions & 2 deletions speculos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import socket
import sys
import threading
import time
from dataclasses import dataclass
from elftools.elf.elffile import ELFFile
from ledgered.binary import LedgerBinaryApp
Expand Down Expand Up @@ -67,8 +68,26 @@ def set_pdeath(sig):
'''Set the parent death signal of the calling process.'''

PR_SET_PDEATHSIG = 1
libc = ctypes.cdll.LoadLibrary('libc.so.6')
libc.prctl(PR_SET_PDEATHSIG, sig)
if sys.platform.startswith('linux'):
libc = ctypes.cdll.LoadLibrary('libc.so.6')
libc.prctl(PR_SET_PDEATHSIG, sig)
elif sys.platform == 'darwin':
libc = ctypes.cdll.LoadLibrary('libSystem.dylib')
parent_pid = os.getppid()
def monitor_parent():
while True:
try:
result = libc.kill(parent_pid, 0)
if result != 0:
libc.kill(os.getpid(), sig)
break
except:
libc.kill(os.getpid(), sig)
break
time.sleep(1)
monitor_thread = threading.Thread(target=monitor_parent, daemon=True)
monitor_thread.start()



def get_elf_infos(app_path, use_bagl, args):
Expand Down