コード例 #1
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void ReadCovTable(CICcontext *context, struct methodblock *mb)
{
    int attribute_length = get4bytes(context);
    unsigned char *end_ptr = context->ptr  + attribute_length;
    int old_clinit, i;

    old_clinit = context->in_clinit;		
    context->in_clinit = FALSE;		/* Since all storage needed by the class initialization method  
					 * <clinit> can be freed after the class is loaded
					 * we should not place Jcov data into this memory
				         */

    if ((mb->coverage_table_length = get2bytes(context)) > 0) {
	int sz = mb->coverage_table_length * sizeof(struct covtable)
                         + mb->code_length * sizeof(long);
	struct covtable *cv = allocNBytes(context, sz);
        long *hash;
	mb->coverage_table = cv;
        hash = (long*)(mb->coverage_table + mb->coverage_table_length);
	memset(hash, 0, mb->code_length*sizeof(long)); 
	for (i = 0; i < mb->coverage_table_length; cv++) {
	    cv->pc = get2bytes(context);
            *(hash+cv->pc) = i + 1;
	    cv->type = get2bytes(context);
	    cv->where = get4bytes(context);
	    cv->count = 0;
            i++;
	}
    }
    if (context->ptr != end_ptr)
	mb->coverage_table = NULL;	/* Don't use a wrong coverage table */

    context->in_clinit = old_clinit;
}	
コード例 #2
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void ReadInCode(CICcontext *context, struct methodblock *mb)
{
    int attribute_length = get4bytes(context);
    unsigned char *end_ptr = context->ptr + attribute_length;
    int attribute_count;
    int code_length;
    int i;

    if (cbMinorVersion(context->cb) <= 2) { 
	mb->maxstack = get1byte(context);
	mb->nlocals = get1byte(context);
	code_length = mb->code_length = get2bytes(context);
    } else { 
	mb->maxstack = get2bytes(context);
	mb->nlocals = get2bytes(context);
	code_length = mb->code_length = get4bytes(context);
    }
    if (mb->nlocals < mb->args_size)
        JAVA_ERROR(context, "Arguments can't fit into locals");

    if (code_length > 65535) {
	JAVA_ERROR(context, "Byte code size exceeds 65535 bytes");
    }

    mb->code = allocNBytes(context, code_length);

    getNbytes(context, code_length, (char *)mb->code);
    if ((mb->exception_table_length = get2bytes(context)) > 0) {
	unsigned exception_table_size = mb->exception_table_length 
	                                  * sizeof(struct CatchFrame);
	mb->exception_table = allocNBytes(context, exception_table_size);
	for (i = 0; i < (int)mb->exception_table_length; i++) {
	    mb->exception_table[i].start_pc = get2bytes(context);
	    mb->exception_table[i].end_pc = get2bytes(context);		
	    mb->exception_table[i].handler_pc = get2bytes(context); 
	    mb->exception_table[i].catchType = get2bytes(context);
            mb->exception_table[i].compiled_CatchFrame = NULL;
	}
    }
    attribute_count = get2bytes(context);
    for (i = 0; i < attribute_count; i++) {
	char *name = getAsciz(context);
	if (strcmp(name, "LineNumberTable") == 0) {
	    ReadLineTable(context, mb);
#ifdef JCOV
	} else if (strcmp(name, "CoverageTable") == 0 && cov_file) {
	    ReadCovTable(context, mb); 
#endif
	} else if (strcmp(name, "LocalVariableTable") == 0) {
	    ReadLocalVars(context, mb);
	} else {
	    int length = get4bytes(context);
	    getNbytes(context, length, NULL);
	}
    }
    if (context->ptr != end_ptr) 
	JAVA_ERROR(context, "Code segment was wrong length");
}
コード例 #3
0
ファイル: people.cpp プロジェクト: VillainyStudios/opensludge
bool loadAnim (personaAnimation * p, FILE * fp) {
	p -> numFrames = get2bytes (fp);

	if (p -> numFrames) {
		int a = get4bytes (fp);
		p -> frames = new animFrame[p -> numFrames];
		if (! checkNew (p -> frames)) return false;
		p -> theSprites = loadBankForAnim (a);

		for (a = 0; a < p -> numFrames; a ++) {
			p -> frames[a].frameNum = get4bytes (fp);
			p -> frames[a].howMany = get4bytes (fp);
			if (ssgVersion >= VERSION(2,0)) {
				p -> frames[a].noise = get4bytes (fp);
			} else {
				p -> frames[a].noise = 0;
			}
		}
	} else {
		p -> theSprites = NULL;
		p -> frames = NULL;
	}
	return true;
}
コード例 #4
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void
ReadExceptions(CICcontext *context, struct methodblock *mb)
{
    int attribute_length = get4bytes(context);
    unsigned char *end_ptr = context->ptr + attribute_length;
    unsigned short nexceptions = get2bytes(context);

    if ((mb->nexceptions = nexceptions) > 0) {
	unsigned short *ep, *exceptions =
	    allocNBytes(context, nexceptions * sizeof (unsigned short));
	mb->exceptions = ep = exceptions;
	while (nexceptions-- > 0) {
	    *ep++ = get2bytes(context);
	}
    }
    if (context->ptr != end_ptr)
	JAVA_ERROR(context, "Exceptions attribute has wrong length");
}
コード例 #5
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void ReadLineTable(CICcontext *context, struct methodblock *mb)
{
    int attribute_length = get4bytes(context);
    unsigned char *end_ptr = context->ptr  + attribute_length;
    int i;
    if ((mb->line_number_table_length = get2bytes(context)) > 0) {
	struct lineno *ln = 
	    allocNBytes(context, mb->line_number_table_length * 
			sizeof(struct lineno));
	mb->line_number_table = ln;
	for (i = mb->line_number_table_length; --i >= 0; ln++) {
	    ln->pc = get2bytes(context);
	    ln->line_number = get2bytes(context);
	}
    }
    if (context->ptr != end_ptr)
	JAVA_ERROR(context, "Line number table was wrong length?");
}	
コード例 #6
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void ReadLocalVars(CICcontext *context, struct methodblock *mb)
{
    int attribute_length = get4bytes(context);
    unsigned char *end_ptr = context->ptr  + attribute_length;
    int i;
    if ((mb->localvar_table_length = get2bytes(context)) > 0) {
	struct localvar *lv = 
	  allocNBytes(context, mb->localvar_table_length * 
		      sizeof(struct localvar));
	mb->localvar_table = lv;
	for (i = mb->localvar_table_length; --i >= 0; lv++) {
	    lv->pc0 = get2bytes(context);
	    lv->length = get2bytes(context);
	    lv->nameoff = get2bytes(context);
	    lv->sigoff = get2bytes(context);
	    lv->slot = get2bytes(context);
	}
    }
    if (context->ptr != end_ptr)
	JAVA_ERROR(context, "Local variables table was wrong length?");
}	
コード例 #7
0
ファイル: HDX.C プロジェクト: daemqn/Atari_ST_Sources
/*
 * Handle [FORMAT] item.
 *
 */
dodiform()
{
  extern char bootstop;
  extern char bootend;
  int dev, v, w, i, br;
  int modesel;			/* flag for mode select */
  long cnt, hdsiz;
  char *s, *d, *wgetstr();
  char buf[10], bs[512], sendata[32];
  char pnam[128];
  char *seldev = "X", *id = "XXXXX";
  HINFO hinfo;
  char devnames[NAMSIZ];	/* device type name buffer */
  long nbad;
  extern long gbslsiz(), nument(), dsmarkbad();
  long pattern, temp;
  long longrandom();
  char pr_id[10];	/* partition scheme id */
  int mask = 0x0001;
  int set, scsidrv, bsiz, other = 0;
  
  /*
   * Throw up generic formatting/partition warning,
   * then get physical dev they want to clobber.
   */
  yesscan = 0;
  noinfo = 0;
  for (i = 0; i < NAMSIZ; i++)
  	devnames[i] = "\0";
  fwarning[FWARNCN].ob_state = NORMAL;
  fwarning[FWARNOK].ob_state = NORMAL;
  if (execform(fwarning) != FWARNOK) return BAILOUT;

  if ((dev = gphysdev()) < 0) {
      return BAILOUT;
  }
  strcpy(id, "mn");
  br = 0;

  /* display doing SCSI massage */

  if (dev > 7)  {	/* do the SCSI drive */
  	noinfo = 1;
  	goto stfm;
  }
  
  inqfmt:
  /* Get all available disk types from wincap 'mn' entries */  
  wallents(devnames, id);
  if (!*devnames) 	{
  	noinfo = 1;
  	goto stfm;
  }
  
  /* Shove format name text into buttons */
  for (i = 0, s = devnames; i < 14 && *s; ++i) {
      dsknames[pfmt[i]].ob_type = G_BUTTON;	/* button */
      dsknames[pfmt[i]].ob_spec = (long)s;
      dsknames[pfmt[i]].ob_state = NORMAL;
      dsknames[pfmt[i]].ob_flags = SELECTABLE | RBUTTON;
      while (*s++)
	;
  }
  other = i;							/* the other button */
  dsknames[pfmt[i]].ob_type = G_BUTTON;	/* button */
  dsknames[pfmt[i]].ob_spec = "OTHER";
  dsknames[pfmt[i]].ob_state = NORMAL;
  dsknames[pfmt[i]].ob_flags = SELECTABLE | RBUTTON;
  i++;

  /* rest of buttons are invisible and untouchable */
  for (; i < 16; ++i) {
      dsknames[pfmt[i]].ob_type = G_IBOX;	/* invisible box */
      dsknames[pfmt[i]].ob_spec = 0;		/* no thickness */
      dsknames[pfmt[i]].ob_state = DISABLED;	/* nobody home */
      dsknames[pfmt[i]].ob_flags = NONE;		/* disabled */
  }
  
  /* clean up rest of the form and throw it up */
  dsknames[PFOK].ob_state = NORMAL;
  dsknames[PFCN].ob_state = NORMAL;
  if (execform(dsknames) != PFOK)
    return BAILOUT;
  
  /* search for format they picked */
  for (i = 0; i < 16; ++i)
    if (dsknames[pfmt[i]].ob_state & SELECTED)
      break;
  if (i >= 16) {		/* nothing picked */
      return BAILOUT;
  } else if (other == i)	{  /* the OTHER button was selected */
  	  noinfo = 1;
	  goto stfm;
  }
  
	if ((!br) && (dev < 8))		{
	  	if (wgetent(dsknames[pfmt[i]].ob_spec, "mn") == ERROR)	{
			nofmt[NOSCHFMT].ob_spec = dsknames[pfmt[i]].ob_spec;
			nofmt[NOSCHFMT].ob_state = NORMAL;
			execform(nofmt, 0);
			return ERROR;
		}
		if ((s = wgetstr("br")) != NULL)	{
			strcpy(id, s);
			br = 1;			/* processing the branch */
			goto inqfmt;	/* start over */
		}
	}

stfm:
	modesel = 1;
  if (gfparm(dev, noinfo, &modesel, &hinfo, dsknames[pfmt[i]].ob_spec,id)!= 0) {
      return ERROR;
  }
  
  /* get data pattern to test the disk */
  if (wgetnum("dp", &pattern) != OK) {
      pattern = longrandom();  /* can't find pattern from wincap, make one */
  } else {
      temp = pattern;
      pattern <<= 16;	/* shift pattern to hi word */
      pattern |= temp;
  }


  br = (dev > 7) ? (dev-8) : (dev);	/* minus 8 for the scsi drive number */
  /*
   * One last chance to bail out.
   */
  *seldev = br + '0';
  (fmtfnl[FUNIT].ob_spec)->te_ptext = seldev;
  fmtfnl[FMTYES].ob_state = NORMAL;
  fmtfnl[FMTNO].ob_state = NORMAL;
  if (execform(fmtfnl) != FMTYES) return BAILOUT;

  /* For REAL !! */  
  dsplymsg(fmtmsg);

  bsl = 0L;
  
  /* Get size of Bad Sector List */
  if ((bslsiz = gbslsiz(dev)) > 0L) {
      /* Allocate memory for existing BSL */
      if ((bsl = (BYTE *)mymalloc((int)bslsiz*512)) <= 0) {
          ret = err(nomemory);
          goto formend;
      }
      
      /* Read in BSL */
      if ((ret = rdbsl(dev)) != OK) {
          /* Create a new BSL if current one is unusable */
	  	if (creabsl(dev, NEW, 0L) != OK) {
	  	    ret = ERROR;
	  	    goto formend;
	  	}
      } else {
      	  /* Remove USER BSL */
      	  if (creabsl(dev, EXPAND, nument(VENDOR)) != OK) {
      	      ret = ERROR;
      	      goto formend;
      	  }
      }
  } else if (bslsiz == 0L || bslsiz == ERROR) {	/* no bsl or read error */
      if (creabsl(dev, NEW, 0L) != OK) {
          ret = ERROR;
          goto formend;
      }
  } else {	/* bslsiz == MDMERR; medium changed error */
      ret = ERROR;
      goto formend;
  }
  
  /*
   * In supervisor mode
   * set disk format parameters
   * and format the disk.
   */
  ostack = Super(NULL);
  v = OK;				    /* assume everything is OK */
  w = -1;
  if (modesel)	{			/* normal mode select ? */
      v = ms(dev, &hinfo);	/* Yes, do noprmal mode set */
	  if (v == OK) w = OK;
  	  /* Find formatted capacity of drive */
      hdsiz = (long)hinfo.hi_cc * (long)hinfo.hi_dhc * (long)hinfo.hi_spt;
  }	else {					/* No, do special mode set */
  	set = typedev & (mask << dev);
	scsidrv = typedrv & (mask << dev);
	bsiz = ((set) || (scsidrv)) ? (16) : (22);
	for (i = 0; i < 32; i++)
		sendata[i] = 0;
	if ((set) || (scsidrv))	{
  		v = mdsense(dev, 4, 0, 32, sendata);
  		for (i = 0; i < 32; i++) /* the lenght of sendata */
  			if (sendata[i])
				break;
  		if (i == 32)	{ /* no infomations returned */
			ret = 111;		
			delay();
			goto jjj;
  		}
		hdsiz = get3bytes(sendata+5);
  		delay();				    /* kludge delay */
		v = sqms(dev, sendata);
		delay();
		goto kkk;
	}
jjj:
  	if ((v = mdsense(dev, 0, 0, bsiz, sendata)) == OK)		{
  		for (i = 0; i < bsiz; i++)
  			if (sendata[i])
				break;
  		if (i == bsiz)	{ /* no infomations returned */
			ret = 111;		
			delay();
  			Super(ostack);
			goto formend;
  		}
		hdsiz = get3bytes(sendata+5);
  		delay();				    /* kludge delay */
		v = sqms(dev, sendata);
	} else {
  		for (i = 0; i < bsiz; i++)
  			if (sendata[i])
				break;
  		if (i == bsiz)	{ /* no infomations returned */
			ret = 111;		
			delay();
  			Super(ostack);
			goto formend;
  		}
	}

kkk:
 	delay();				    /* kludge delay */
	w = OK;
	if (dev > 7)				/* the drive is scsi */
		if ((w = readcap(dev, 0, (long)0, buf)) == OK)
			hdsiz = get4bytes(buf) + 1;
  }
  disksiz = hdsiz;
  delay();				    /* kludge delay */
  if ((v == OK) || (w == OK))
  	v = format(dev, (UWORD)hinfo.hi_in);  /* format */
  delay();				    /* kludge delay */
  Super(ostack);
  
  if ((v != 0) || (w != 0)) {
      ret = errcode(dev);
      if (tsterr(ret) != OK)
          formaterr(dev);
      ret = ERROR;
      goto formend;
  }
  
  ret = OK;
  rebootp = 1;
formend:
  erasemsg();	/* Erase formatting box */
  if (ret == 111)		/* HDX may not support this drive */
  		ret = err(needinfo);
  if (ret < 0) {
      if (bsl > 0) free(bsl);
      return ERROR;
  }
  
  /*------------------------------------------*
   * Markbad the device destructively.	      *
   * Bad Sectors found are added to the BSL.  *
   * Write BSL to device.		      *
   *------------------------------------------*/
  if ((nbad = dsmarkbad(dev, hdsiz, 1, pattern)) < 0) {
      free(bsl);
      return ERROR;
  }
  if (wrbsl(dev) != OK) {
      free(bsl);
      return ERROR;
  }
  free(bsl);

    
  /*
   * Install boot-stopper in sector image;
   * write root sector to device.
   * 6-13-88  Setting of soft format parameters in root sector sets
   *		the hard disk size only.
   */
  fillbuf(bs, 512L, 0L);	/* create new root sector */
  sbslparm(bs);			/* set BSL parameters */
  if (modesel)	{
  	sfmtparm(bs, &hinfo);
  } else {
  	sdisksiz(bs, disksiz);
  }
  for (d = bs, s = &bootstop, cnt = (long)(&bootend - &bootstop); --cnt;)
    *d++ = *s++;
  Protobt(bs, -1L, -1, 1);	/* make root sector executable */
  
  if ((ret = putroot(dev, bs, (SECTOR)0)) != OK) {
      if (tsterr(ret) != OK)
	  	err(rootwrit);
      return ERROR;
  }

  /*
   * Make a copy of the default partition name.
   * Figure out the partition scheme id.
   */
  if (!noinfo)	{
  	s = wgetstr("pt");
  	strcpy(pnam, s);
  }
  /* ??
  figprid(disksiz, pr_id);
  */
  dodipart(dev, pnam, disksiz);
  return OK;
}
コード例 #8
0
ファイル: dhcpc.c プロジェクト: flachmann/PROCEMA_Webserver
//----------------------------------------------------------------------------
//read all the options
//pointer to the variables and size from options to packet end
void dhcp_parse_options (unsigned char *msg, struct dhcp_cache *c, unsigned int size)
{
  unsigned int ix;

  ix = 0;
  do
  {
    switch (msg[ix])
    {
      case 0: //Padding
      ix++;
      break;
      case 1: //Netmask
        ix++;
        if ( msg[ix] == 4 )
        {
          ix++;
          get4bytes(&msg[ix], &c->netmask[0]);
          ix += 4;
        }
        else
        {
          ix += (msg[ix]+1);
        }
      break;
      case 3: //router (gateway IP)
        ix++;
        if ( msg[ix] == 4 )
        {
          ix++;
          get4bytes(&msg[ix], &c->router_ip[0]);
          ix += 4;
        }
        else
        {
          ix += (msg[ix]+1);
        }
      break;
      case 6: //dns len = n * 4
        ix++;
        if ( msg[ix] == 4 )
        {
          ix++;
          get4bytes(&msg[ix], &c->dns1_ip[0]);
          ix += 4;
        }
        else
        if ( msg[ix] == 8 )
        {
          ix++;
          get4bytes(&msg[ix], &c->dns1_ip[0]);
          ix += 4;
          get4bytes(&msg[ix], &c->dns2_ip[0]);
          ix += 4;
        }
        else
        {
          ix += (msg[ix]+1);
        }
      break;
      case 51: //lease time
        ix++;
        if ( msg[ix] == 4 )
        {
          ix++;
          get4bytes(&msg[ix], &c->lease[0]);
          ix += 4;
        }
        else
        {
          ix += msg[ix]+1;
        }
      break;
      case 52: //Options overload 
        ix++;
        if ( msg[ix] == 1 )   //size == 1
        {
          ix++;
          c->ovld   = msg[ix];
          ix++;
        }
        else
        {
          ix += (msg[ix]+1);
        }
      break;
      case 53: //DHCP Type 
        ix++;
        if ( msg[ix] == 1 )   //size == 1
        {
          ix++;
          c->type = msg[ix];
          ix++;
        }
        else
        {
          ix += (msg[ix]+1);
        }
      break;
      case 54: //Server identifier
        ix++;
        if ( msg[ix] == 4 )
        {
          ix++;
          get4bytes(&msg[ix], &c->serv_id[0]);
          ix += 4;
        }
        else
        {
          ix += msg[ix]+1;
        }
      break;
      case 99:   //Magic cookie
        ix += 4;
      break;
      case 0xff: //end option
      break;
      default: 
        DHCP_DEBUG("Unknown Option: %2x\r\n", msg[ix]);
        ix++;
        ix += (msg[ix]+1);
      break;
    }
  }
  while ( (msg[ix] != 0xff) && (ix < size) ); 
}
コード例 #9
0
int
convert_S_records(
    FILE *ifp,
    char *inm,
    FILE *ofp,
    char *onm)
{
    char buff[512];
    char *p;
    u8 cksum;
    int incksum;
    int c;
    int len;                        /* data length of current line */
    int rectype;                    /* record type */
    u32 addr;
    bool endrecord = FALSE;
    buffer_rec tb;

    while ( ! endrecord && (fgets(buff, sizeof(buff), ifp)))
    {
        p = &buff[0];

        if (p[strlen(p)-1] == '\n')                 /* get rid of newline */
            p[strlen(p)-1] = '\0';

        if (p[strlen(p)-1] == '\r')                 /* get rid of any CR */
            p[strlen(p)-1] = '\0';

        tb.dl_count = 0;

        if (*p != 'S')
            badformat(p, inm, BADFMT);
        p++;

        if ((rectype = getnibble(&p)) == -1)        /* record type */
            badformat(buff, inm, BADTYPE);

        if ((len = getbyte(&p)) == -1)              /* record len */
            badformat(buff, inm, BADLEN);
        cksum = len;

        switch (rectype)
        {
            case 0x00:                  /* comment field, ignored */
                goto write_it;

            case 0x01:                          /* data record, 16 bit addr */
                if ((addr = get2bytes(&p)) == -1L)
                    badformat(buff, inm, BADADDR);
                len -= 3;
                goto doit;

            case 0x02:                          /* ... 24 bit addr */
                if ((addr = get3bytes(&p)) == -1L)
                    badformat(buff, inm, BADADDR);
                len -= 4;
                goto doit;

            case 0x03:                          /* ... 32 bit addr */
                if ((addr = get4bytes(&p)) == -1L)
                    badformat(buff, inm, BADADDR);
                len -= 5;
    doit:
                cksum += B0(addr) + B1(addr) + B2(addr) + B3(addr);

                tb.dl_destaddr = addr;
                while (len--)
                {
                    if ((c = getbyte(&p)) == -1)
                        badformat(buff, inm, BADDATA);
                    cksum += c;
                    filesum += c;
                    tb.dl_buf[tb.dl_count++] = c;
                }
                break;

            case 0x07:                  /* 32 bit end record */
                if ((addr = get4bytes(&p)) == -1L)
                    badformat(buff, inm, BADADDR);
                goto end_rec;

            case 0x08:                  /* 24 bit end record */
                if ((addr = get3bytes(&p)) == -1L)
                    badformat(buff, inm, BADADDR);
                goto end_rec;

            case 0x09:                  /* 16 bit end record */
                if ((addr = get2bytes(&p)) == -1L)
                    badformat(buff, inm, BADADDR);

end_rec:
                cksum += B0(addr) + B1(addr) + B2(addr) + B3(addr);
                tb.dl_jumpaddr = addr;
                break;

            default:
                error(0, "unknown Motorola-S record type: 0x%02x", rectype);
                badformat(buff, inm, BADTYPE);
                break;
        }

        /*
         * Verify checksums are correct in file.
         */

        cksum = (~cksum) & 0xff;
        if ((incksum = getbyte(&p)) == -1)
            badformat(buff, inm, BADCSUM);
        if (((u8) incksum) != cksum)
            badformat(buff, inm, MISCSUM);

write_it:
        if (tb.dl_count)
            write_record(&tb, ofp);
    }
    return 0;
}
コード例 #10
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void LoadConstantPool(CICcontext *context) 
{
    ClassClass *cb = context->cb;
    int nconstants = get2bytes(context);
    cp_item_type *constant_pool;
    unsigned char *type_table;
    int i;
    Java8 t1;
    
	if (nconstants > 16384) {
		JAVA_ERROR(context, "Preverifier only "
				   "handles constant pool size up to 16K");
	}

    t1.x[0] = 0; /* shut off warning */
    if (nconstants < CONSTANT_POOL_UNUSED_INDEX) {
	JAVA_ERROR(context, "Illegal constant pool size");
    }
    
    constant_pool = (cp_item_type *)
        allocNBytes(context, nconstants * sizeof(cp_item_type));
    type_table = allocNBytes(context, nconstants * sizeof(char));

    for (i = CONSTANT_POOL_UNUSED_INDEX; i < nconstants; i++) {
	int type = get1byte(context);
	CONSTANT_POOL_TYPE_TABLE_PUT(type_table, i, type);
	switch (type) {
	  case CONSTANT_Utf8: {
	      int length = get2bytes(context);
	      char *result = allocNBytes(context, length + 1);
	      getNbytes(context, length, result);
	      result[length] = '\0';
	      constant_pool[i].cp = result;
	      CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i);
	      break;
	  }
	
	  case CONSTANT_Class:
	  case CONSTANT_String:
	    constant_pool[i].i = get2bytes(context);
	    break;

	  case CONSTANT_Fieldref:
	  case CONSTANT_Methodref:
	  case CONSTANT_InterfaceMethodref:
	  case CONSTANT_NameAndType:
	    constant_pool[i].i = get4bytes(context);
	    break;
	    
	  case CONSTANT_Float:
	      if (check_on) {
		  panic("floating-point constants should not appear");
	      }
	  case CONSTANT_Integer:
	    constant_pool[i].i = get4bytes(context);
	    CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i);
	    break;

	  case CONSTANT_Double: 
	      if (check_on) {
		  panic("floating-point constants should not appear");
	      }
	  case CONSTANT_Long: {
	      unsigned high = get4bytes(context);
	      unsigned low = get4bytes(context);
	      int64_t value;
	      value = ll_add(ll_shl(uint2ll(high), 32), uint2ll(low));
	      SET_INT64(t1, &constant_pool[i], value);
	      CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i);
	      i++;		/* increment i for loop, too */
	      if (i >= nconstants) {
		JAVA_ERROR(context, "illegal constant pool entry");
	      }
	      /* Indicate that the next object in the constant pool cannot
	       * be accessed independently.    */
	      CONSTANT_POOL_TYPE_TABLE_PUT(type_table, i, 0);
	      CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i);
	      break;
	  }

	  default:
	      JAVA_ERROR(context, "Illegal constant pool type");
	}
    }
    /* It is important to only set these after everything is setup,
       so that the GC sees a consistent state.*/
    cbConstantPool(cb) = constant_pool;
    cbConstantPoolCount(cb) = nconstants;
    constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type = type_table;
}
コード例 #11
0
ファイル: classloader.c プロジェクト: eruffaldi/pitos
static void
createInternalClass0(CICcontext *context, ClassClass *cb, 
		     struct Hjava_lang_ClassLoader *loader, char *name)
{
    int i, j;
    union cp_item_type *constant_pool;
    unsigned char *type_table;
    int attribute_count;
    unsigned fields_count;
    struct methodblock *mb;
    struct fieldblock *fb;
    struct Classjava_lang_Class *ucb = unhand(cb);
    
    if (get4bytes(context) != JAVA_CLASSFILE_MAGIC) 
	JAVA_ERROR(context, "Bad magic number");

    ucb->minor_version = get2bytes(context);
    ucb->major_version = get2bytes(context);
    ucb->loader = loader;
    if (ucb->major_version != JAVA_VERSION) 
	JAVA_ERROR(context, "Bad major version number");

    LoadConstantPool(context);
    constant_pool = ucb->constantpool;
    type_table = constant_pool[CONSTANT_POOL_TYPE_TABLE_INDEX].type;

    ucb->access = get2bytes(context) & ACC_WRITTEN_FLAGS;

	/* Work around javac bug */
	if (ucb->access & ACC_INTERFACE) {
		ucb->access |= ACC_ABSTRACT;
	}


    /* Get the name of the class */
    i = get2bytes(context);	/* index in constant pool of class */
    ucb->name = getAscizFromClass(context, i);
    if (name != NULL && strcmp(ucb->name, name) != 0)
	JAVA_ERROR(context, "Wrong name");
    constant_pool[i].clazz = cb;
    CONSTANT_POOL_TYPE_TABLE_SET_RESOLVED(type_table, i);

    if (loader) { 
	/* We don't trust a classloader to do the right thing. . . */
	ClassClass **pcb, **end_pcb;
	char *name = ucb->name;
	if (name == NULL || !IsLegalClassname(name, FALSE)) {
	    JAVA_ERROR(context, "Bad name");
	}
	BINCLASS_LOCK();
	for (pcb = binclasses, end_pcb = pcb + nbinclasses; 
	         pcb < end_pcb; pcb++) { 
	    ClassClass *cb = *pcb;
	    if ((cbLoader(cb) == loader) && (strcmp(name, cbName(cb)) == 0))
	        break;
	}
	BINCLASS_UNLOCK();
	if (pcb < end_pcb)
	    /* There's already a class with the same name and loader */
	    JAVA_ERROR(context, "Duplicate name");
    }

    /* Get the super class name. */
    i = get2bytes(context);	/* index in constant pool of class */
    if (i > 0) {
	ucb->super_name = getAscizFromClass(context, i);
	if (!IsLegalClassname(ucb->super_name, FALSE)) { 
	    JAVA_ERROR(context, "Bad superclass name");
	}

    } 

    i = ucb->implements_count = get2bytes(context);
    if (i > 0) {
	int j;
	ucb->implements = allocNBytes(context, i * sizeof(short));
	for (j = 0; j < i; j++) {
	    ucb->implements[j] = get2bytes(context);
	}
    }

    fields_count = ucb->fields_count = get2bytes(context);
    if (fields_count > 0) 
        ucb->fields = (struct fieldblock *)
	    allocNBytes(context, ucb->fields_count * sizeof(struct fieldblock));
    for (i = fields_count, fb = ucb->fields; --i >= 0; fb++) {
	fieldclass(fb) = cb;
	fb->access = get2bytes(context) & ACC_WRITTEN_FLAGS;
	fb->name = getAsciz(context);
	fb->signature = getAsciz(context);
	attribute_count = get2bytes(context);
	for (j = 0; j < (int)attribute_count; j++) {
	    char *name = getAsciz(context);
	    int length = get4bytes(context);
	    if ((fb->access & ACC_STATIC) 
		 && strcmp(name, "ConstantValue") == 0) {
		if (length != 2) 
		    JAVA_ERROR(context, "Wrong size for VALUE attribute");
		fb->access |= ACC_VALKNOWN;
		/* we'll change this below */
		fb->u.offset = get2bytes(context); 
	    } else {
		getNbytes(context, length, NULL);
	    }
	}
	/*
	if (fb->access & ACC_STATIC) {
	    InitializeStaticVar(fb, context);
	}
	*/
    }

    if ((ucb->methods_count = get2bytes(context)) > 0) 
	ucb->methods = (struct methodblock *)
	  allocNBytes(context, ucb->methods_count * sizeof(struct methodblock));
    for (i = cbMethodsCount(cb), mb = cbMethods(cb); --i >= 0; mb++) {
	fieldclass(&mb->fb) = cb;
	mb->fb.access = get2bytes(context) & ACC_WRITTEN_FLAGS;
	mb->fb.name = getAsciz(context);
	mb->fb.signature = getAsciz(context);

	if (strcmp(mb->fb.name, "<clinit>") == 0 &&
	    strcmp(mb->fb.signature, "()V") == 0)
	    context->in_clinit = TRUE;

	mb->args_size = Signature2ArgsSize(mb->fb.signature) 
	                + ((mb->fb.access & ACC_STATIC) ? 0 : 1);
	if (mb->args_size > 255)
	    JAVA_ERROR(context, "Too many arguments");
	attribute_count = get2bytes(context);
	for (j = 0; j < attribute_count; j++) {
	    char *attr_name = getAsciz(context);
            if ((strcmp(attr_name, "Code") == 0) 
		       && ((mb->fb.access & (ACC_NATIVE | ACC_ABSTRACT))==0)) {
		ReadInCode(context, mb);
	    } else if (strcmp(attr_name, "Exceptions") == 0) {
		ReadExceptions(context, mb);
	    } else {
		int length = get4bytes(context);
		getNbytes(context, length, NULL);
	    }
	}
	context->in_clinit = FALSE;
    }

    /* See if there are class attributes */
    attribute_count = get2bytes(context); 
    for (j = 0; j < attribute_count; j++) {
	char *name = getAsciz(context);
	int length = get4bytes(context);
	if (strcmp(name, "SourceFile") == 0) {
	    if (length != 2) {
		JAVA_ERROR(context, "Wrong size for VALUE attribute");
	    }
	    ucb->source_name = getAsciz(context);
#ifdef JCOV
	} else if (strcmp(name, "AbsoluteSourcePath") == 0) {
	    if (length == 2) {
	    	ucb->absolute_source_name = getAsciz(context);
	    } else
		getNbytes(context, length, NULL);
	} else if (strcmp(name, "TimeStamp") == 0) {
	    unsigned high;
	    unsigned low;
	    int64_t  value;
	    Java8    t1;

	    if (length == 8) {
		high = get4bytes(context);
		low  = get4bytes(context);
	    	value = ll_add(ll_shl(uint2ll(high), 32), uint2ll(low));
	    	SET_INT64(t1, &ucb->timestamp, value);
	    } else 
	    	getNbytes(context, length, NULL);
#endif
	} else {
	    getNbytes(context, length, NULL);
	}
    }
}