690 jclass cb = load_class_local(context, name);
691 unsigned short id = class_to_ID(context, cb, JNI_TRUE);
692 (*env)->DeleteLocalRef(env, cb);
693 return id;
694 }
695
696 bucket = new_bucket(context, pID);
697 bucket->next = 0;
698 bucket->class = 0;
699 bucket->loadable = JNI_TRUE; /* name-only IDs are implicitly loadable */
700 bucket->hash = hash;
701 bucket->name = malloc(strlen(name) + 1);
702 if (bucket->name == 0)
703 CCout_of_memory(context);
704 strcpy(bucket->name, name);
705
706 done:
707 return *pID;
708 }
709
710 static const char *
711 ID_to_class_name(context_type *context, unsigned short ID)
712 {
713 hash_table_type *class_hash = &(context->class_hash);
714 hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
715 return bucket->name;
716 }
717
718 static jclass
719 ID_to_class(context_type *context, unsigned short ID)
720 {
721 hash_table_type *class_hash = &(context->class_hash);
722 hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
723 if (bucket->class == 0) {
724 assert(bucket->loadable == JNI_TRUE);
725 bucket->class = load_class_global(context, bucket->name);
726 }
727 return bucket->class;
728 }
729
730 static fullinfo_type
731 make_loadable_class_info(context_type *context, jclass cb)
732 {
733 return MAKE_FULLINFO(ITEM_Object, 0,
734 class_to_ID(context, cb, JNI_TRUE));
735 }
736
1373 args1 = signature_to_args_size(signature) + 1;
1374 args2 = code[offset + 3];
1375 if (args1 != args2) {
1376 CCerror(context,
1377 "Inconsistent args_size for invokeinterface");
1378 }
1379 if (code[offset + 4] != 0) {
1380 CCerror(context,
1381 "Fourth operand byte of invokeinterface must be zero");
1382 }
1383 pop_and_free(context);
1384 } else if (opcode == JVM_OPC_invokevirtual
1385 || opcode == JVM_OPC_invokespecial)
1386 set_protected(context, inumber, key, opcode);
1387 break;
1388 }
1389
1390 case JVM_OPC_invokedynamic:
1391 CCerror(context,
1392 "invokedynamic bytecode is not supported in this class file version");
1393
1394 case JVM_OPC_instanceof:
1395 case JVM_OPC_checkcast:
1396 case JVM_OPC_new:
1397 case JVM_OPC_anewarray:
1398 case JVM_OPC_multianewarray: {
1399 /* Make sure the constant pool item is a class */
1400 int key = (code[offset + 1] << 8) + code[offset + 2];
1401 fullinfo_type target;
1402 verify_constant_pool_type(context, key, 1 << JVM_CONSTANT_Class);
1403 target = cp_index_to_class_fullinfo(context, key, JVM_CONSTANT_Class);
1404 if (GET_ITEM_TYPE(target) == ITEM_Bogus)
1405 CCerror(context, "Illegal type");
1406 switch(opcode) {
1407 case JVM_OPC_anewarray:
1408 if ((GET_INDIRECTION(target)) >= MAX_ARRAY_DIMENSIONS)
1409 CCerror(context, "Array with too many dimensions");
1410 this_idata->operand.fi = MAKE_FULLINFO(GET_ITEM_TYPE(target),
1411 GET_INDIRECTION(target) + 1,
1412 GET_EXTRA_INFO(target));
1413 break;
1682
1683
1684 /* Given a pointer to an instruction, return its length. Use the table
1685 * opcode_length[] which is automatically built.
1686 */
1687 static int instruction_length(unsigned char *iptr, unsigned char *end)
1688 {
1689 static unsigned char opcode_length[] = JVM_OPCODE_LENGTH_INITIALIZER;
1690 int instruction = *iptr;
1691 switch (instruction) {
1692 case JVM_OPC_tableswitch: {
1693 int *lpc = (int *)UCALIGN(iptr + 1);
1694 int index;
1695 if (lpc + 2 >= (int *)end) {
1696 return -1; /* do not read pass the end */
1697 }
1698 index = _ck_ntohl(lpc[2]) - _ck_ntohl(lpc[1]);
1699 if ((index < 0) || (index > 65535)) {
1700 return -1; /* illegal */
1701 } else {
1702 return (unsigned char *)(&lpc[index + 4]) - iptr;
1703 }
1704 }
1705
1706 case JVM_OPC_lookupswitch: {
1707 int *lpc = (int *) UCALIGN(iptr + 1);
1708 int npairs;
1709 if (lpc + 1 >= (int *)end)
1710 return -1; /* do not read pass the end */
1711 npairs = _ck_ntohl(lpc[1]);
1712 /* There can't be more than 64K labels because of the limit
1713 * on per-method byte code length.
1714 */
1715 if (npairs < 0 || npairs >= 65536)
1716 return -1;
1717 else
1718 return (unsigned char *)(&lpc[2 * (npairs + 1)]) - iptr;
1719 }
1720
1721 case JVM_OPC_wide:
1722 if (iptr + 1 >= end)
1723 return -1; /* do not read pass the end */
1724 switch(iptr[1]) {
1725 case JVM_OPC_ret:
1726 case JVM_OPC_iload: case JVM_OPC_istore:
1727 case JVM_OPC_fload: case JVM_OPC_fstore:
1728 case JVM_OPC_aload: case JVM_OPC_astore:
1729 case JVM_OPC_lload: case JVM_OPC_lstore:
1730 case JVM_OPC_dload: case JVM_OPC_dstore:
1731 return 4;
1732 case JVM_OPC_iinc:
1733 return 6;
1734 default:
1735 return -1;
1736 }
1737
1738 default: {
3811 case JVM_SIGNATURE_LONG:
3812 full_info = MAKE_FULLINFO(ITEM_Long, 0, 0);
3813 result = 'L';
3814 break;
3815
3816 case JVM_SIGNATURE_ARRAY:
3817 array_depth++;
3818 continue; /* only time we ever do the loop > 1 */
3819
3820 case JVM_SIGNATURE_CLASS: {
3821 char buffer_space[256];
3822 char *buffer = buffer_space;
3823 char *finish = strchr(p, JVM_SIGNATURE_ENDCLASS);
3824 int length;
3825 if (finish == NULL) {
3826 /* Signature must have ';' after the class name.
3827 * If it does not, return 0 and ITEM_Bogus in full_info. */
3828 result = 0;
3829 break;
3830 }
3831 length = finish - p;
3832 if (length + 1 > (int)sizeof(buffer_space)) {
3833 buffer = malloc(length + 1);
3834 check_and_push(context, buffer, VM_MALLOC_BLK);
3835 }
3836 memcpy(buffer, p, length);
3837 buffer[length] = '\0';
3838 full_info = make_class_info_from_name(context, buffer);
3839 result = 'A';
3840 p = finish + 1;
3841 if (buffer != buffer_space)
3842 pop_and_free(context);
3843 break;
3844 }
3845 } /* end of switch */
3846 break;
3847 }
3848 *signature_p = p;
3849 if (array_depth == 0 || result == 0) {
3850 /* either not an array, or result is bogus */
3851 *full_info_p = full_info;
|
690 jclass cb = load_class_local(context, name);
691 unsigned short id = class_to_ID(context, cb, JNI_TRUE);
692 (*env)->DeleteLocalRef(env, cb);
693 return id;
694 }
695
696 bucket = new_bucket(context, pID);
697 bucket->next = 0;
698 bucket->class = 0;
699 bucket->loadable = JNI_TRUE; /* name-only IDs are implicitly loadable */
700 bucket->hash = hash;
701 bucket->name = malloc(strlen(name) + 1);
702 if (bucket->name == 0)
703 CCout_of_memory(context);
704 strcpy(bucket->name, name);
705
706 done:
707 return *pID;
708 }
709
710 #ifdef DEBUG
711 static const char *
712 ID_to_class_name(context_type *context, unsigned short ID)
713 {
714 hash_table_type *class_hash = &(context->class_hash);
715 hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
716 return bucket->name;
717 }
718 #endif
719
720 static jclass
721 ID_to_class(context_type *context, unsigned short ID)
722 {
723 hash_table_type *class_hash = &(context->class_hash);
724 hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
725 if (bucket->class == 0) {
726 assert(bucket->loadable == JNI_TRUE);
727 bucket->class = load_class_global(context, bucket->name);
728 }
729 return bucket->class;
730 }
731
732 static fullinfo_type
733 make_loadable_class_info(context_type *context, jclass cb)
734 {
735 return MAKE_FULLINFO(ITEM_Object, 0,
736 class_to_ID(context, cb, JNI_TRUE));
737 }
738
1375 args1 = signature_to_args_size(signature) + 1;
1376 args2 = code[offset + 3];
1377 if (args1 != args2) {
1378 CCerror(context,
1379 "Inconsistent args_size for invokeinterface");
1380 }
1381 if (code[offset + 4] != 0) {
1382 CCerror(context,
1383 "Fourth operand byte of invokeinterface must be zero");
1384 }
1385 pop_and_free(context);
1386 } else if (opcode == JVM_OPC_invokevirtual
1387 || opcode == JVM_OPC_invokespecial)
1388 set_protected(context, inumber, key, opcode);
1389 break;
1390 }
1391
1392 case JVM_OPC_invokedynamic:
1393 CCerror(context,
1394 "invokedynamic bytecode is not supported in this class file version");
1395 break;
1396 case JVM_OPC_instanceof:
1397 case JVM_OPC_checkcast:
1398 case JVM_OPC_new:
1399 case JVM_OPC_anewarray:
1400 case JVM_OPC_multianewarray: {
1401 /* Make sure the constant pool item is a class */
1402 int key = (code[offset + 1] << 8) + code[offset + 2];
1403 fullinfo_type target;
1404 verify_constant_pool_type(context, key, 1 << JVM_CONSTANT_Class);
1405 target = cp_index_to_class_fullinfo(context, key, JVM_CONSTANT_Class);
1406 if (GET_ITEM_TYPE(target) == ITEM_Bogus)
1407 CCerror(context, "Illegal type");
1408 switch(opcode) {
1409 case JVM_OPC_anewarray:
1410 if ((GET_INDIRECTION(target)) >= MAX_ARRAY_DIMENSIONS)
1411 CCerror(context, "Array with too many dimensions");
1412 this_idata->operand.fi = MAKE_FULLINFO(GET_ITEM_TYPE(target),
1413 GET_INDIRECTION(target) + 1,
1414 GET_EXTRA_INFO(target));
1415 break;
1684
1685
1686 /* Given a pointer to an instruction, return its length. Use the table
1687 * opcode_length[] which is automatically built.
1688 */
1689 static int instruction_length(unsigned char *iptr, unsigned char *end)
1690 {
1691 static unsigned char opcode_length[] = JVM_OPCODE_LENGTH_INITIALIZER;
1692 int instruction = *iptr;
1693 switch (instruction) {
1694 case JVM_OPC_tableswitch: {
1695 int *lpc = (int *)UCALIGN(iptr + 1);
1696 int index;
1697 if (lpc + 2 >= (int *)end) {
1698 return -1; /* do not read pass the end */
1699 }
1700 index = _ck_ntohl(lpc[2]) - _ck_ntohl(lpc[1]);
1701 if ((index < 0) || (index > 65535)) {
1702 return -1; /* illegal */
1703 } else {
1704 unsigned char *finish = (unsigned char *)(&lpc[index + 4]);
1705 assert(finish >= iptr);
1706 return (int)(finish - iptr);
1707 }
1708 }
1709
1710 case JVM_OPC_lookupswitch: {
1711 int *lpc = (int *) UCALIGN(iptr + 1);
1712 int npairs;
1713 if (lpc + 1 >= (int *)end)
1714 return -1; /* do not read pass the end */
1715 npairs = _ck_ntohl(lpc[1]);
1716 /* There can't be more than 64K labels because of the limit
1717 * on per-method byte code length.
1718 */
1719 if (npairs < 0 || npairs >= 65536)
1720 return -1;
1721 else {
1722 unsigned char *finish = (unsigned char *)(&lpc[2 * (npairs + 1)]);
1723 assert(finish >= iptr);
1724 return (int)(finish - iptr);
1725 }
1726 }
1727
1728 case JVM_OPC_wide:
1729 if (iptr + 1 >= end)
1730 return -1; /* do not read pass the end */
1731 switch(iptr[1]) {
1732 case JVM_OPC_ret:
1733 case JVM_OPC_iload: case JVM_OPC_istore:
1734 case JVM_OPC_fload: case JVM_OPC_fstore:
1735 case JVM_OPC_aload: case JVM_OPC_astore:
1736 case JVM_OPC_lload: case JVM_OPC_lstore:
1737 case JVM_OPC_dload: case JVM_OPC_dstore:
1738 return 4;
1739 case JVM_OPC_iinc:
1740 return 6;
1741 default:
1742 return -1;
1743 }
1744
1745 default: {
3818 case JVM_SIGNATURE_LONG:
3819 full_info = MAKE_FULLINFO(ITEM_Long, 0, 0);
3820 result = 'L';
3821 break;
3822
3823 case JVM_SIGNATURE_ARRAY:
3824 array_depth++;
3825 continue; /* only time we ever do the loop > 1 */
3826
3827 case JVM_SIGNATURE_CLASS: {
3828 char buffer_space[256];
3829 char *buffer = buffer_space;
3830 char *finish = strchr(p, JVM_SIGNATURE_ENDCLASS);
3831 int length;
3832 if (finish == NULL) {
3833 /* Signature must have ';' after the class name.
3834 * If it does not, return 0 and ITEM_Bogus in full_info. */
3835 result = 0;
3836 break;
3837 }
3838 assert(finish >= p);
3839 length = (int)(finish - p);
3840 if (length + 1 > (int)sizeof(buffer_space)) {
3841 buffer = malloc(length + 1);
3842 check_and_push(context, buffer, VM_MALLOC_BLK);
3843 }
3844 memcpy(buffer, p, length);
3845 buffer[length] = '\0';
3846 full_info = make_class_info_from_name(context, buffer);
3847 result = 'A';
3848 p = finish + 1;
3849 if (buffer != buffer_space)
3850 pop_and_free(context);
3851 break;
3852 }
3853 } /* end of switch */
3854 break;
3855 }
3856 *signature_p = p;
3857 if (array_depth == 0 || result == 0) {
3858 /* either not an array, or result is bogus */
3859 *full_info_p = full_info;
|