#include #include #include #include #include void print_maps(void) { pid_t pid; char s[2000]; pid=getpid(); sprintf(s,"cat /proc/%d/maps | grep /dev/dri/card", pid); system(s); } int maps_inited=0; #define MAX_MAPS 20 int n_maps=0; #define FLAG_VIDEO_RAM 1 #define FLAG_SMALL 2 #define FLAG_REGISTER_APERTURE 4 struct { unsigned long a; unsigned long b; unsigned long source; unsigned char *p; unsigned long length; int flags; long non_zero_count; long last_non_zero; long changed; unsigned char *copy0; } maps[MAX_MAPS]; void init_maps(void) { pid_t pid; char s[2000]; FILE *fin; FILE *flog; unsigned int *p; int i; if(maps_inited)return; maps_inited=1; pid=getpid(); sprintf(s,"cat /proc/%d/maps | grep /dev/dri/card |tr \\- \\ > /tmp/maps ", pid); system(s); memset(maps, 0, sizeof(maps)); fin=fopen("/tmp/maps","r"); flog=fopen("maps.log","w"); while(!feof(fin)){ fgets(s, 2000, fin); sscanf(s,"%x %x rw s %x", &(maps[n_maps].a), &(maps[n_maps].b), &(maps[n_maps].source)); maps[n_maps].p=maps[n_maps].a; maps[n_maps].length=maps[n_maps].b-maps[n_maps].a; maps[n_maps].copy0=calloc(maps[n_maps].length,1); maps[n_maps].flags=0; if(maps[n_maps].copy0==NULL){ fprintf(stderr,"Could not allocated %ld bytes\n",maps[n_maps].length); } #if 0 if(maps[n_maps].source<0xe0000000){ #endif if(maps[n_maps].length>32*1024*1024){ maps[n_maps].flags|=FLAG_VIDEO_RAM; } if(maps[n_maps].length<(10*1024*1024)){ maps[n_maps].flags|=FLAG_SMALL; } fprintf(stderr, "Found map %d 0x%08x-0x%08x starting at 0x%08x (%d) %ld KB\n", n_maps, maps[n_maps].a, maps[n_maps].b, maps[n_maps].source, maps[n_maps].flags, maps[n_maps].length/1024); fprintf(flog, "Found map %d 0x%08x-0x%08x starting at 0x%08x (%d) %ld KB\n", n_maps, maps[n_maps].a, maps[n_maps].b, maps[n_maps].source, maps[n_maps].flags, maps[n_maps].length/1024); n_maps++; } fprintf(stderr,"%d maps found\n",n_maps); fprintf(flog,"%d maps found\n",n_maps); fprintf(stderr,"Attempting to identify register aperture\n"); sleep(1); /* let engine become quescient */ for(i=0;i>2]&0xffff)!=0x1002)continue; fprintf(stderr,"Map %d might be register aperture\n",i); fprintf(flog,"Map %d might be register aperture\n",i); maps[i].flags|=FLAG_REGISTER_APERTURE; } fclose(fin); fclose(flog); } void copy_maps(void) { int i; for(i=0;i1024*1024)continue; //if(maps[i].changed==0)continue; dump_map(i,count); } } void check_maps(void) { /* Wait until engine is queiscent */ sleep(5); if(!maps_inited){ init_maps(); copy_maps(); count_nonzeros(); return; } count++; if(count<3){ count_nonzeros(); verify_maps(); dump_maps(); copy_maps(); } else exit(0); }