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/rms_client.c # 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 / rms_client.c` 114 lines ยท 5694 bytes Raw Blame History 1 /* TEST ONLY fake CUSE kernel. The included CUDApp client is not patched. 2 * Test transport replaces OS operations only; checked Omega client policy stays enabled. 3 * Anonymous CPU backing belongs to this fake kernel, never to a GPU/device mapping. */ 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 #include 19 #include 20 #include 21 static int kernel_fd; 22 static uint64_t unique, tokens[32]; 23 static unsigned char response[16384]; 24 static int frame(unsigned op,const void *body,size_t size) { 25 unsigned char wire[16384]={0}; 26 struct fuse_in_header h={.len=40+size,.opcode=op,.unique=++unique}; 27 assert(h.len<=sizeof wire);memcpy(wire,&h,sizeof h);memcpy(wire+40,body,size); 28 assert(send(kernel_fd,wire,h.len,MSG_NOSIGNAL)==h.len); 29 ssize_t n=recv(kernel_fd,response,sizeof response,0); 30 assert(n>=16);struct fuse_out_header out;memcpy(&out,response,16); 31 assert(out.len==(unsigned)n && out.unique==unique); 32 if(out.error){errno=-out.error;return -1;} 33 return (int)n; 34 } 35 static uint32_t token(int fd) {assert(fd>=100&&fd<132&&tokens[fd-100]);return tokens[fd-100];} 36 static int host_open(const char *path,int flags,...) { 37 (void)flags;assert(!strncmp(path,"/dev/nvidia",11)); 38 struct fuse_open_in in={0};assert(frame(FUSE_OPEN,&in,sizeof in)>0); 39 struct fuse_open_out out;memcpy(&out,response+16,sizeof out); 40 for(int i=0;i<32;i++)if(!tokens[i]){tokens[i]=out.fh;return 100+i;} 41 abort(); 42 } 43 static int host_close(int fd) { 44 struct fuse_release_in in={.fh=token(fd)};int r=frame(FUSE_RELEASE,&in,sizeof in); 45 tokens[fd-100]=0;return r<0?-1:0; 46 } 47 /* Faithful unrestricted FUSE ioctl retries: each output iov is copied back to 48 * precisely the address supplied by the client. No endpoint pointer dereference. */ 49 static int kernel_ioctl(int fd,unsigned long cmd,void *arg) { 50 unsigned char wire[16384]={0}; 51 struct fuse_ioctl_in in={.fh=token(fd),.flags=FUSE_IOCTL_UNRESTRICTED,.cmd=cmd,.arg=(uintptr_t)arg}; 52 struct fuse_ioctl_iovec outvec[3];unsigned outcount=0; 53 for(unsigned step=0;step<5;step++) { 54 memcpy(wire,&in,sizeof in); 55 int n=frame(FUSE_IOCTL,wire,sizeof in+in.in_size);if(n<0)return -1; 56 struct fuse_ioctl_out out;memcpy(&out,response+16,sizeof out); 57 if(!(out.flags&FUSE_IOCTL_RETRY)){ 58 assert(n==32+(int)in.out_size);size_t at=32; 59 for(unsigned i=0;i=100){(void)token(fd);assert(off==0);return mmap(addr,n,prot,(flags&~MAP_SHARED)|MAP_PRIVATE|MAP_ANONYMOUS,-1,0);} 88 return mmap(addr,n,prot,flags,fd,off); 89 } 90 #define CUDAPP_NVRM_TEST_TRANSPORT 1 91 #define open host_open 92 #define close host_close 93 #define ioctl host_ioctl 94 #define mmap host_mmap 95 #include "nvrm.c" 96 #undef open 97 #undef close 98 #undef ioctl 99 #undef mmap 100 int main(int argc,char **argv) { 101 assert(argc==3);int pair[2];assert(!socketpair(AF_UNIX,SOCK_SEQPACKET,0,pair)); 102 pid_t child=fork();assert(child>=0); 103 if(!child){close(pair[0]);assert(dup2(pair[1],0)==0&&dup2(pair[1],1)==1);close(pair[1]);execl(argv[1],argv[1],"--fake","--host-model",argv[2],NULL);_exit(127);} 104 close(pair[1]);kernel_fd=pair[0]; 105 struct cuse_init_in init={.major=7,.minor=31,.flags=CUSE_UNRESTRICTED_IOCTL};assert(frame(CUSE_INIT,&init,sizeof init)>0); 106 Nvrm rm;int rc=nvrm_open(&rm);if(rc){fprintf(stderr,"nvrm_open: %s\n",rm.err);return 2;} 107 assert(rm.target_sm==121);assert(!memcmp(rm.gpu_uuid,"HOST_MODEL_UUID1",16)); 108 NvrmMem m;rc=nvrm_alloc(&rm,8192,&m);if(rc){fprintf(stderr,"nvrm_alloc: %s\n",rm.err);return 3;} 109 const char sample[]="HOST_MODEL CPU bytes only";char copy[sizeof sample]; 110 assert(!nvrm_copy_to(&rm,&m,0,sample,sizeof sample));assert(!nvrm_copy_from(&rm,&m,0,copy,sizeof copy));assert(!memcmp(sample,copy,sizeof copy)); 111 assert(!nvrm_free(&rm,&m));assert(!nvrm_close(&rm));close(kernel_fd); 112 int status;assert(waitpid(child,&status,0)==child&&WIFEXITED(status)&&WEXITSTATUS(status)==0); 113 puts("UNMODIFIED CUDApp nvrm open/alloc/control/map/free HOST_MODEL PASS; GPU_BACKING/DOORBELLS NOT_RUN");return 0; 114 }