mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Use the verified Gamescope component and preserve the safe copy fallback. Direct game frames remains experimental and off by default.
52 lines
2.7 KiB
C
52 lines
2.7 KiB
C
#define _GNU_SOURCE
|
|
#include "frame_worker_peer.h"
|
|
#include <assert.h>
|
|
#include <fcntl.h>
|
|
#include <poll.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/syscall.h>
|
|
#include <sys/sysmacros.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
static uint64_t start_ticks(pid_t id) {
|
|
char proc[64], line[4096]; snprintf(proc,sizeof(proc),"/proc/%d/stat",id);
|
|
FILE *f=fopen(proc,"r");assert(f);assert(fgets(line,sizeof(line),f));fclose(f);
|
|
uint64_t ticks=0;
|
|
assert(dd_worker_parse_start(line,&ticks)==DD_WORKER_STAT_OK);
|
|
return ticks;
|
|
}
|
|
static bool check_maps(const struct dd_worker_grant *g,pid_t id,uint64_t ticks) {
|
|
char proc[64],line[4096];snprintf(proc,sizeof(proc),"/proc/%d/maps",id);
|
|
FILE *f=fopen(proc,"r");assert(f);bool found=false;
|
|
while(fgets(line,sizeof(line),f)) if(dd_worker_grant_matches(g,4,getuid(),id,ticks,4,line)){ found=true;break;}
|
|
fclose(f);return found;
|
|
}
|
|
int main(void){
|
|
char p[]="/tmp/dd-live-map.XXXXXX";int fd=mkstemp(p);assert(fd>=0);
|
|
assert(ftruncate(fd,4096)==0);struct stat st;assert(fstat(fd,&st)==0);
|
|
int a[2],b[2];assert(pipe(a)==0&&pipe(b)==0);pid_t id=fork();assert(id>=0);
|
|
if(id==0){
|
|
close(a[0]);close(b[1]);
|
|
void *m=mmap(NULL,4096,PROT_READ|PROT_EXEC,MAP_PRIVATE,fd,0);assert(m!=MAP_FAILED);
|
|
assert(write(a[1],"y",1)==1);
|
|
char c;assert(read(b[0],&c,1)==1);assert(mprotect(m,4096,PROT_READ)==0);
|
|
assert(write(a[1],"y",1)==1);assert(read(b[0],&c,1)==1);_exit(0);
|
|
}
|
|
close(a[1]);close(b[0]);char c;assert(read(a[0],&c,1)==1);
|
|
int pfd=syscall(SYS_pidfd_open,id,0);assert(pfd>=0);
|
|
struct pollfd pfd_poll={.fd=pfd,.events=POLLIN};assert(poll(&pfd_poll,1,0)==0);
|
|
uint64_t start=start_ticks(id);assert(start);
|
|
struct dd_worker_grant g={.owner=4,.uid=getuid(),.pid=id,.dev_major=major(st.st_dev),.dev_minor=minor(st.st_dev),.ino=st.st_ino,.start_ticks=start,.expires=10,.canonical_file=p,.app_launch_verified=true,.final_go=true};
|
|
assert(dd_worker_receipt_allows_reserve(DD_WORKER_STAT_DENIED,0,start+1));
|
|
assert(!check_maps(&g,id,start+1)); // A forged self receipt fails against live post-exec ticks.
|
|
assert(dd_worker_receipt_allows_reserve(DD_WORKER_STAT_OK,start,start));
|
|
assert(check_maps(&g,id,start));
|
|
g.final_go=false;assert(!check_maps(&g,id,start));g.final_go=true;
|
|
assert(write(b[1],"n",1)==1);assert(read(a[0],&c,1)==1);assert(!check_maps(&g,id,start));
|
|
assert(write(b[1],"n",1)==1);assert(poll(&pfd_poll,1,2000)==1);
|
|
assert(pfd_poll.revents&POLLIN);int status;assert(waitpid(id,&status,0)==id&&WIFEXITED(status)&&WEXITSTATUS(status)==0);
|
|
close(fd); close(pfd);unlink(p); puts("Live executable map, start-time reuse rejection, no-GO revocation, non-executable map rejection, and pidfd exit readiness passed.");
|
|
}
|