int main(int argc, char **argv) { char *filename = NULL, *opt = NULL; progname = argv[0]; crc32_gentab(); if (argc == 2) { filename= argv[1]; } else if (argc == 3) { opt = argv[1]; filename= argv[2]; } else usage(); if (opt != NULL && strcmp(opt, "-d")) usage(); MMAP_FILE(MODE_READ, filename) FIND_TEXT island_t *p, *islands; islands = find_islands(m + text_offset, m + text_offset + text_size); int stat[15], total = 0, dump = 0, i; if (opt != NULL && !strcmp(opt, "-d")) dump = 1; printf("file: %s\n", filename); for (i = 0; i < 15; i++) stat[i] = 0; if (dump) printf("Found islands:\n"); for (p = islands; p != NULL; p = p->next) { if (dump) printf("%08x %d\n", p->offset - (uint32_t)m - text_offset + text_addr, p->length); stat[p->length]++; total += p->length - 5; } for (i = 0; i < 15; i++) if (stat[i]) printf("%d\t", i); putchar('\n'); for (i = 0; i < 15; i++) if (stat[i]) printf("%d\t", stat[i]); putchar('\n'); printf("Total: %d bytes\n", total); return 0; }
static int app_init_mmap(void) { int fd; int result; fd=open(MMAP_TOTAL_FILE,O_CREAT|O_RDWR|O_TRUNC,0777); lseek(fd,sizeof(total_stat)-1,SEEK_SET); write(fd," ",1); //MAP_HUGETLB is supported since 2.6.32 ptotal_stat=(total_stat *)mmap(NULL,sizeof(total_stat),PROT_READ|PROT_WRITE,MAP_SHARED|MAP_LOCKED,fd,0); if(ptotal_stat == NULL){ printf("mmap failed,Error num=%d\n",errno); return -1; } memset(ptotal_stat,0,sizeof(total_stat)); close(fd); #if 0 int i; if(unlikely(worker_id==0)){ fprintf(stderr,"Warning,no worker lcore\n"); return ; } if(worker_id > WORK_NUM){ fprintf(stderr,"Please change pdst_stat_info definition\n"); return ; } for (i=0;i<worker_id;i++){ fd=open(MMAP_FILE(i),O_CREAT|O_RDWR|O_TRUNC,0777); lseek(fd,sizeof(stat_info)*STAT_INFO_SIZE-1,SEEK_SET); write(fd,"",1); PDST_STAT_INFO(i)=(stat_info*)mmap(NULL,sizeof(stat_info)*STAT_INFO_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_HUGETLB,fd,0); close(fd); } #endif fd=open(MMAP_FILE(0),O_CREAT|O_RDWR|O_TRUNC,0777); lseek(fd,sizeof(stat_info)*STAT_INFO_SIZE-1,SEEK_SET); write(fd," ",1); pdst_stat_info=(stat_info *)mmap(NULL,sizeof(stat_info)*STAT_INFO_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_LOCKED,fd,0); if(pdst_stat_info == NULL){ printf("mmap failed,Error num=%d\n",errno); return -1; } else printf("!!!!!!!!!!!!!mmap success,size=%x\n",sizeof(stat_info)*STAT_INFO_SIZE); memset(pdst_stat_info,0,sizeof(stat_info)*STAT_INFO_SIZE); close(fd); //init tcp half open state fd=open(MMAP_HALF_FILE,O_CREAT|O_RDWR|O_TRUNC,0777); result=lseek(fd,sizeof(tcp_listen)*LHASH_SIZE-1,SEEK_SET); if(result == -1){ close(fd); perror("lhash lseek error\n"); exit(-1); } //printf("lseek offset=%x\n",result); result=write(fd," ",1); if(result == -1){ close(fd); perror("lhash write error\n"); exit(-1); } //printf("written bytes=%x\n",result); tcp_hashinfo.lhash=(tcp_listen *)mmap(NULL,sizeof(tcp_listen)*LHASH_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_LOCKED,fd,0); if(tcp_hashinfo.lhash== NULL){ printf("mmap failed,Error num=%d\n",errno); return -1; } else printf("!!!!!!!!!!!!!mmap success,size=%x\n",sizeof(tcp_listen)*LHASH_SIZE); memset(tcp_hashinfo.lhash,0,sizeof(tcp_listen)*LHASH_SIZE); close(fd); //init tcp established state fd=open(MMAP_EST_FILE,O_CREAT|O_RDWR|O_TRUNC,0777); result=lseek(fd,sizeof(tcp_est)*EHASH_SIZE-1,SEEK_SET); if(result == -1){ close(fd); perror("ehash lseek error\n"); exit(-1); } //printf("lseek offset=%x\n",result); result=write(fd," ",1); if(result == -1){ close(fd); perror("ehash write error\n"); exit(-1); } //printf("written bytes=%x\n",result); tcp_hashinfo.ehash=(tcp_est *)mmap(NULL,sizeof(tcp_est)*EHASH_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED|MAP_LOCKED,fd,0); if(tcp_hashinfo.ehash== NULL){ printf("mmap failed,Error num=%d\n",errno); return -1; } else printf("!!!!!!!!!!!!!mmap success,size=%x\n",sizeof(tcp_est)*EHASH_SIZE); memset(tcp_hashinfo.ehash,0,sizeof(tcp_est)*EHASH_SIZE); close(fd); }