about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/focaccia/deterministic.py14
-rw-r--r--src/focaccia/qemu/_qemu_tool.py20
-rw-r--r--src/focaccia/qemu/deterministic.py9
-rw-r--r--src/focaccia/qemu/x86.py13
4 files changed, 47 insertions, 9 deletions
diff --git a/src/focaccia/deterministic.py b/src/focaccia/deterministic.py
index 2f3980a..4fcc222 100644
--- a/src/focaccia/deterministic.py
+++ b/src/focaccia/deterministic.py
@@ -293,14 +293,17 @@ finally:
         def __init__(self, 
                      events: list[Event], 
                      match_fn: Callable,
-                     from_state: ReadableProgramState | None = None):
+                     from_state: ReadableProgramState | None = None,
+                     skipped_events: list[int] = []):
             self.events = events
             self.matcher = match_fn
+            self.skipped_events = skipped_events
 
             self.matched_count = None
             if from_state:
-                self.match(from_state)
-                self.matched_count -= 1
+                if self.match(from_state):
+                    assert(self.matched_count is not None)
+                    self.matched_count -= 1
 
         def match(self, state: ReadableProgramState) -> Event | None:
             if self.matched_count is None:
@@ -315,6 +318,11 @@ finally:
                 if self.matched_count is None:
                     return None
 
+            # Don't match skipped events
+            if self.matched_count in self.skipped_events:
+                self.matched_count += 1 # proceed to next
+                return None
+
             event = self.events[self.matched_count]
             if self.matcher(event, state):
                 self.matched_count += 1 # proceed to next
diff --git a/src/focaccia/qemu/_qemu_tool.py b/src/focaccia/qemu/_qemu_tool.py
index f4b9752..fdcf579 100644
--- a/src/focaccia/qemu/_qemu_tool.py
+++ b/src/focaccia/qemu/_qemu_tool.py
@@ -27,7 +27,7 @@ from focaccia.deterministic import (
     SyscallEvent,
     MemoryMapping,
 )
-from focaccia.qemu.deterministic import emulated_system_calls, passthrough_system_calls
+from focaccia.qemu.deterministic import emulated_system_calls, passthrough_system_calls, vdso_system_calls
 
 from focaccia.tools.validate_qemu import make_argparser, verbosity
 
@@ -158,10 +158,24 @@ class GDBServerStateIterator:
         self.arch = supported_architectures[archname]
         self.binary = self._process.progspace.filename
 
+        events = self._deterministic_log.events()
+        skipped_events = []
+        for idx in range(len(events)):
+            event = events[idx]
+            if not isinstance(event, SyscallEvent):
+                continue
+
+            if event.syscall_number in vdso_system_calls[archname]:
+                skipped_events.append(idx)
+
+        for idx in skipped_events:
+            debug(f'Skip {events[idx]}')
+
         first_state = self.current_state()
-        self._events = EventMatcher(self._deterministic_log.events(),
+        self._events = EventMatcher(events,
                                     match_event,
-                                    from_state=first_state)
+                                    from_state=first_state,
+                                    skipped_events=skipped_events)
         event = self._events.match(first_state)
         info(f'Synchronized at PC={hex(first_state.read_pc())} to event:\n{event}')
 
diff --git a/src/focaccia/qemu/deterministic.py b/src/focaccia/qemu/deterministic.py
index 51fe9e6..3292518 100644
--- a/src/focaccia/qemu/deterministic.py
+++ b/src/focaccia/qemu/deterministic.py
@@ -1,5 +1,6 @@
 from focaccia.qemu.x86 import emulated_system_calls as x86_emu_syscalls
 from focaccia.qemu.x86 import passthrough_system_calls as x86_pass_syscalls
+from focaccia.qemu.x86 import vdso_system_calls as x86_vdso_syscalls
 
 emulated_system_calls = {
     'x86_64': x86_emu_syscalls,
@@ -14,3 +15,11 @@ passthrough_system_calls = {
     'aarch64l': { },
     'aarch64b': { }
 }
+
+vdso_system_calls = {
+    'x86_64': x86_vdso_syscalls,
+    'aarch64': { },
+    'aarch64l': { },
+    'aarch64b': { }
+}
+
diff --git a/src/focaccia/qemu/x86.py b/src/focaccia/qemu/x86.py
index 8907da3..8bbbf56 100644
--- a/src/focaccia/qemu/x86.py
+++ b/src/focaccia/qemu/x86.py
@@ -9,9 +9,16 @@ emulated_system_calls = {
 }
 
 passthrough_system_calls = {
-    56:  SyscallInfo('clone', patchup_address_registers=['rdx', 'r10'], creates_thread=True),
-    57:  SyscallInfo('fork', creates_thread=True),
-    58:  SyscallInfo('vfork', creates_thread=True),
+    56:   SyscallInfo('clone', patchup_address_registers=['rdx', 'r10'], creates_thread=True),
+    57:   SyscallInfo('fork', creates_thread=True),
+    58:   SyscallInfo('vfork', creates_thread=True),
     435:  SyscallInfo('clone3', patchup_address_registers=['rdi'], creates_thread=True),
 }
 
+vdso_system_calls = {
+    96: SyscallInfo('gettimeofday', patchup_address_registers=['rdi', 'rsi']),
+    201: SyscallInfo('time', patchup_address_registers=['rdi']),
+    228: SyscallInfo('clock_gettime', patchup_address_registers=['rdi']),
+    309: SyscallInfo('getcpu', patchup_address_registers=['rdi', 'rsi', 'rdx'])
+}
+