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-mv/blob/main/tests/kfd/trace.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / kfd / trace.c` 116 lines ยท 5013 bytes Raw Blame History 1 /* Independent AArch64 ptrace instrument. No device access. ioctls use fd -1. 2 * Observe actual generated arguments; poison only private output pointers after 3 * the real EBADF, proving copy-out never discloses compiler-bound addresses. */ 4 #define _GNU_SOURCE 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 19 static void die(const char *s) { perror(s); exit(90); } 20 static uint64_t peek(pid_t p, uint64_t a) { 21 errno=0; 22 long v=ptrace(PTRACE_PEEKDATA,p,(void *)(uintptr_t)a,0); 23 if (errno) die("peek"); 24 return (uint64_t)v; 25 } 26 static void poke(pid_t p, uint64_t a, uint64_t v) { 27 if (ptrace(PTRACE_POKEDATA,p,(void *)(uintptr_t)a,(void *)(uintptr_t)v)) die("poke"); 28 } 29 int main(int argc, char **argv) { 30 if (argc!=2 && argc!=3 && argc!=4) return 90; 31 uint64_t wp=0,rp=0; 32 if (argc==4) { wp=strtoull(argv[2],NULL,10); rp=strtoull(argv[3],NULL,10); } 33 uint64_t aperture_offset=argc==3 ? strtoull(argv[2],NULL,10) : 0; 34 pid_t p=fork(); 35 if (p<0) die("fork"); 36 if (!p) { 37 if (ptrace(PTRACE_TRACEME,0,0,0)) _exit(91); 38 raise(SIGSTOP); 39 execl(argv[1],argv[1],(char *)0); 40 _exit(92); 41 } 42 int status; 43 if (waitpid(p,&status,0)!=p || !WIFSTOPPED(status)) die("initial wait"); 44 if (ptrace(PTRACE_SETOPTIONS,p,0,PTRACE_O_TRACESYSGOOD|PTRACE_O_EXITKILL)) die("options"); 45 int entering=1, seen=0; 46 uint64_t call=0,q=0,h=0,base=0,payload=0,arg0=0,arg1=0; 47 unsigned offsets[5],count=0; 48 for (;;) { 49 if (ptrace(PTRACE_SYSCALL,p,0,0)) die("continue"); 50 if (waitpid(p,&status,0)!=p) die("wait"); 51 if (WIFEXITED(status)) { 52 if (WEXITSTATUS(status) || seen!=1) { 53 fprintf(stderr,"FAIL trace child=%d seen=%d\n",WEXITSTATUS(status),seen); 54 return 1; 55 } 56 fprintf(stderr,"PASS checked binding and private copy-out request=%#llx\n",(unsigned long long)q); 57 return 0; 58 } 59 if (!WIFSTOPPED(status)) return 1; 60 if (WSTOPSIG(status)==SIGTRAP) continue; 61 if (WSTOPSIG(status)!=(SIGTRAP|0x80)) return 1; 62 struct user_pt_regs regs; 63 struct iovec io={®s,sizeof regs}; 64 if (ptrace(PTRACE_GETREGSET,p,(void *)NT_PRSTATUS,&io)) die("regs"); 65 if (entering) { 66 call=regs.regs[8]; arg0=regs.regs[0]; arg1=regs.regs[1]; 67 if (call==SYS_write && arg0==1) payload=arg1; 68 if (call==SYS_munmap && arg0==base) base+=arg1; 69 if (call==SYS_ioctl) { 70 if ((int64_t)arg0!=-1) return 1; 71 q=arg1; h=regs.regs[2]; count=0; 72 uint64_t expected=base; 73 switch (q) { 74 case AMDKFD_IOC_GET_PROCESS_APERTURES_NEW: 75 offsets[count++]=0; expected=argc==3 ? base+aperture_offset : payload; break; 76 case AMDKFD_IOC_WAIT_EVENTS: 77 offsets[count++]=0; expected=payload; break; 78 case AMDKFD_IOC_MAP_MEMORY_TO_GPU: 79 case AMDKFD_IOC_UNMAP_MEMORY_FROM_GPU: 80 offsets[count++]=8; expected=payload; break; 81 case AMDKFD_IOC_ALLOC_MEMORY_OF_GPU: 82 case AMDKFD_IOC_SET_SCRATCH_BACKING_VA: 83 offsets[count++]=0; break; 84 case AMDKFD_IOC_CREATE_QUEUE: 85 offsets[count++]=0; offsets[count++]=8; offsets[count++]=16; 86 offsets[count++]=56; offsets[count++]=72; break; 87 case AMDKFD_IOC_GET_VERSION: break; 88 default: return 1; 89 } 90 for (unsigned i=0;i=0) base=regs.regs[0]; 106 if (call==SYS_ioctl) { 107 if ((int64_t)regs.regs[0]!=-EBADF) return 1; 108 for (unsigned i=0;i