Esempio n. 1
0
int readsects(unsigned char *buf,
              int drive,
              unsigned long start,
              unsigned long size)
 {
 unsigned cyl=start/headsects;
 unsigned head=start%headsects;
 unsigned sect=head%sects;
 head/=sects;
 while(size)
  if(sects-sect<size)
   {
   if(getsects(buf,sects-sect,cyl,head,sect,drive)) return -1;
   buf+=((sects-sect)<<sectshft);
   size-=sects-sect;
   sect=0;
   if(++head==heads) head=0, ++cyl;
   }
  else
   {
   if(getsects(buf,size,cyl,head,sect,drive)) return -1;
   size=0;
   }
 return 0;
 }
Esempio n. 2
0
void getpart(void)
 {
 int x;
 int ofst;
 unsigned long pofst=0;		/* Sector no. of current extended partition */
 unsigned pcyl, phead, psect;	/* cyl/head/sect of extended partition */
 unsigned char *buf;
 ofst=0;
 pcyl=0; phead=0; psect=0;
 next:
 /* Get partition table */
 if(getsects(sect,1,pcyl,phead,psect,128))
  {
  fprintf(stderr,"Couldn't read partition table\n");
  exit(1);
  }
 /* Get partition table data into structure */
 buf=sect+mbrPART;
 for(x=0;x!=4;++x,buf+=16)
  {
  entries[x+ofst].active=buf[partACTIVE];
  entries[x+ofst].beghead=buf[partBEGHEAD];
  entries[x+ofst].begsect=buf[partBEGSECT]&63;
  entries[x+ofst].begcyl=buf[partBEGCYL]+((buf[partBEGSECT]&0xC0)<<2);
  entries[x+ofst].id=buf[partID];
  entries[x+ofst].endhead=buf[partENDHEAD];
  if(entries[x+ofst].id) heads=entries[x+ofst].endhead+1;
  entries[x+ofst].endsect=buf[partENDSECT]&63;
  if(entries[x+ofst].id) sects=entries[x+ofst].endsect;
  headsects=heads*sects;
  entries[x+ofst].endcyl=buf[partENDCYL]+((buf[partENDSECT]&0xC0)<<2);
  entries[x+ofst].start=(unsigned long)buf[partSTART]+
                   ((unsigned long)buf[partSTART+1]<<8)+
                   ((unsigned long)buf[partSTART+2]<<16)+
                   ((unsigned long)buf[partSTART+3]<<24)+pofst;
  entries[x+ofst].size=(unsigned long)buf[partSIZE]+
                  ((unsigned long)buf[partSIZE+1]<<8)+
                  ((unsigned long)buf[partSIZE+2]<<16)+
                  ((unsigned long)buf[partSIZE+3]<<24);
  entries[x+ofst].str=lookupid(entries[x+ofst].id);
  }
 /* Search for extended partition */
 for(x=0;x!=4;++x)
  if(entries[x+ofst].id==5)
   {
   pcyl=entries[x+ofst].begcyl;
   phead=entries[x+ofst].beghead;
   psect=entries[x+ofst].begsect-1;
   pofst=entries[x+ofst].start;
   ofst+=4;
   goto next;
   }
 nentries=ofst+4;
 }
Esempio n. 3
0
int main(int argc, char *argv[])
{
  unsigned long long start, finish;
  void *handle;
  void (*func)(bfd *obj);
  char *error;
  char *err;

  bfd *file;
  bfd_init ();
  char *default_target = "elf64-x86-64";  //"elf64-x86-64" ;
  file = bfd_openr (argv[1], default_target);
  if (file != NULL)
  {
    write(1," opened\n",sizeof(" opened\n"));
  }

  if (bfd_check_format (file, bfd_object))
  {
    //printf ("format checked\n");
    write(1,"format checked\n",sizeof("format checked\n"));
  }
  //  _bfd_new_bfd();

  int flag_num = 1;
  char *NOW = "2";
  
  if(argv[2] != NULL){
    char *flag = argv[2];
    if(strcmp(flag,NOW) == 0){
      flag_num = 2;
      write(1, "Setting flag to RTLD_NOW\n",sizeof("Setting flag to RTLD_NOW\n"));
    }
    else{
      flag_num = 1;
      write(1, "Use default flag:RTLD_LAZY\n",sizeof("Use default flag:RTLD_LAZY\n"));    
    }  
  }
  else{
    write(1, "Use default flag:RTLD_LAZY\n",sizeof("Use default flag:RTLD_LAZY\n"));
  }


  rdtsc(&start);    
  handle = dlopen("./libobjdata.so",flag_num); // 1 = LAZY , 2 = NOW
  if (!handle) {
    fputs (dlerror(), stderr);
    exit(1);
  }
  dlclose(handle);
  rdtsc(&finish);


  write(1,"\nstart: ", sizeof("\nstart: "));
  print_int(start, 10);

  write(1,"\nfinished: ", sizeof("\nfinished: "));
  print_int(finish, 10);

  write(1,"\nrdtsc time: ", sizeof("\nrdtsc time: "));
  int t = (finish-start)/2.5;///2500 000 000 Hz/s  2500 000Hz/ms 2500Hz/micro s   2.5Hz/nano s;
  //double temp = (finish-start)/2.5;
  print_int(t, 10); 

  write(1,"nano second\n", sizeof("nano second\n"));

  


  func = dlsym(handle, "getsects");
  if ((error = dlerror()) != NULL)  {
    fputs(error, stderr);
    exit(1);
  }  
  getsects(file);


  dlclose(handle);
  bfd_close (file);

}