Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-driver/blob/main/tests/irqvfio_ref.py # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-driver / tests / irqvfio_ref.py` 251 lines ยท 11151 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 """Verification-only Linux/AArch64 UAPI emulator over a child-owned memfd. 3 4 No device is opened. Real eventfd/read/write/poll/mmap execute in the kernel. 5 Only ENOTTY responses to the memfd's VFIO ioctls are replaced. This is NOT a 6 VFIO device, firmware emulator, interrupt delivery test, or hardware receipt. 7 Constants/layout: Linux asm-generic/unistd.h, linux/ptrace.h, linux/vfio.h, 8 and asm/ptrace.h (user_pt_regs); the compiler lane's C oracle is independent. 9 """ 10 import ctypes as C 11 import errno 12 import os 13 import signal 14 import struct 15 16 libc = C.CDLL(None, use_errno=True) 17 libc.ptrace.restype = C.c_long 18 libc.ptrace.argtypes = (C.c_uint, C.c_int, C.c_void_p, C.c_void_p) 19 20 class Registers(C.Structure): 21 _fields_ = [('r', C.c_ulonglong * 31), ('sp', C.c_ulonglong), 22 ('pc', C.c_ulonglong), ('pstate', C.c_ulonglong)] 23 24 class Iovec(C.Structure): 25 _fields_ = [('base', C.c_void_p), ('length', C.c_size_t)] 26 27 def ptrace(request, pid, address=0, data=0): 28 C.set_errno(0) 29 result = libc.ptrace(request, pid, address, data) 30 error = C.get_errno() 31 if result == -1 and error: 32 raise OSError(error, os.strerror(error)) 33 return result 34 35 def registers(pid): 36 regs = Registers() 37 vec = Iovec(C.cast(C.pointer(regs), C.c_void_p), C.sizeof(regs)) 38 ptrace(0x4204, pid, 1, C.cast(C.pointer(vec), C.c_void_p)) 39 return regs 40 41 def setregisters(pid, regs): 42 vec = Iovec(C.cast(C.pointer(regs), C.c_void_p), C.sizeof(regs)) 43 ptrace(0x4205, pid, 1, C.cast(C.pointer(vec), C.c_void_p)) 44 45 def fetch(pid, address, count): 46 result = bytearray() 47 for offset in range(0, count, 8): 48 result += struct.pack('= 0: 180 eventfd = result 181 if call == 29: 182 if result != -errno.ENOTTY: 183 failures.append('VFIO fixture must be memfd ENOTTY') 184 if request == 15210: 185 replacement = device 186 injected += 1 187 elif request == 15212: 188 flags = 3 if mode == 10 else 7 189 size = 2048 if mode == 9 else 4096 190 store(child, address, struct.pack('