added checkaccess parameter to resolve_class* functions
authoredwin <none@none>
Wed, 22 Jun 2005 16:08:51 +0000 (16:08 +0000)
committeredwin <none@none>
Wed, 22 Jun 2005 16:08:51 +0000 (16:08 +0000)
improved exception handling in typeinfo.c
do not check access rights to classes for subtype checks

14 files changed:
src/native/native.c
src/native/vm/Field.c
src/native/vm/VMClass.c
src/vm/jit/helper.c
src/vm/jit/inline/inline.c
src/vm/jit/inline/parseRT.c
src/vm/jit/inline/parseXTA.c
src/vm/jit/parse.c
src/vm/jit/verify/typecheck.c
src/vm/jit/verify/typeinfo.c
src/vm/jit/verify/typeinfo.h
src/vm/linker.c
src/vm/resolve.c
src/vm/resolve.h

index 0c93b944cd6b12c7faa40101c29225b69590a78b..06e222a15dbbe8ff45b657fe91c73727cfec2f6b 100644 (file)
@@ -30,7 +30,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: native.c 2727 2005-06-17 08:11:34Z twisti $
+   $Id: native.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -1071,7 +1071,7 @@ java_objectarray *get_parametertypes(methodinfo *m)
     /* get classes */
 
        for (i = 0; i < paramcount; i++) {
-               if (!resolve_class_from_typedesc(&paramtypes[i], false,
+               if (!resolve_class_from_typedesc(&paramtypes[i], true, false,
                                                                                 (classinfo **) &result->data[i]))
                        return NULL;
 
@@ -1103,7 +1103,7 @@ java_objectarray* get_exceptiontypes(methodinfo *m)
     result = builtin_anewarray(excount, class_java_lang_Class);
 
     for (i = 0; i < excount; i++) {
-               if (!resolve_classref_or_classinfo(NULL,m->thrownexceptions[i],resolveEager,false,&cls))
+               if (!resolve_classref_or_classinfo(NULL,m->thrownexceptions[i],resolveEager,true,false,&cls))
                        return NULL; /* exception */
                use_class_as_object(cls);
                result->data[i] = (java_objectheader *)cls;
@@ -1123,7 +1123,7 @@ classinfo *get_returntype(methodinfo *m)
 {
        classinfo *cls;
 
-       if (!resolve_class_from_typedesc(&(m->parseddesc->returntype),false,&cls))
+       if (!resolve_class_from_typedesc(&(m->parseddesc->returntype),true,false,&cls))
                return NULL; /* exception */
 
        use_class_as_object(cls);
index ca636ee1e88ebc8e107172e27713eb562ec7fce3..a7cc45ec6ff90669c899a3dcd607f98468219285 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Joseph Wenninger
             Christian Thalinger
 
-   $Id: Field.c 2629 2005-06-09 21:22:01Z twisti $
+   $Id: Field.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -1204,7 +1204,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *
        if (!desc)
                return NULL;
 
-       if (!resolve_class_from_typedesc(desc,false,(classinfo **)&ret))
+       if (!resolve_class_from_typedesc(desc,true,false,(classinfo **)&ret))
                return NULL; /* exception */
        
        use_class_as_object((classinfo*)ret);
index 9438189070e1ecc4957e4b4929bc88f19c03222f..3f5a63aa201b804e67cb490ea1d93284118355d6 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Joseph Wenninger
             Christian Thalinger
 
-   $Id: VMClass.c 2687 2005-06-14 17:29:18Z twisti $
+   $Id: VMClass.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -284,9 +284,9 @@ JNIEXPORT java_objectarray* JNICALL Java_java_lang_VMClass_getDeclaredClasses(JN
                classinfo *inner;
                classinfo *outer;
 
-               if (!resolve_classref_or_classinfo(NULL,c->innerclass[i].inner_class,resolveEager,false,&inner))
+               if (!resolve_classref_or_classinfo(NULL,c->innerclass[i].inner_class,resolveEager,false,false,&inner))
                        return NULL;
-               if (!resolve_classref_or_classinfo(NULL,c->innerclass[i].outer_class,resolveEager,false,&inner))
+               if (!resolve_classref_or_classinfo(NULL,c->innerclass[i].outer_class,resolveEager,false,false,&inner))
                        return NULL;
                
                if ((outer == c) && (notPublicOnly || (inner->flags & ACC_PUBLIC))) {
index 248da7740968366f669a67e0432f509cfa9f9860..9a94013c99e32356714810ba1f7122ec5df58847 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: helper.c 2496 2005-05-23 08:06:06Z twisti $
+   $Id: helper.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -61,7 +61,7 @@ classinfo *helper_resolve_classinfo(constant_classref *cr)
 
        /* resolve and load the class */
 
-       if (!resolve_classref(NULL, cr, resolveEager, true, &c)) {
+       if (!resolve_classref(NULL, cr, resolveEager, true, true, &c)) {
                java_objectheader *xptr;
                java_objectheader *cause;
 
index 46213141a151bbd3eff637d79d4688b3c70fac8c..feeea9b8472128374a003a08a7219987c654ca49 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Dieter Thuernbeck
 
-   $Id: inline.c 2487 2005-05-20 17:43:27Z twisti $
+   $Id: inline.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -732,7 +732,7 @@ inlining_methodinfo *inlining_analyse_method(methodinfo *m,
 
                                        if (opcode ==JAVA_INVOKEINTERFACE) {
                                            imr = class_getconstant(m->class, i, CONSTANT_InterfaceMethodref);
-                                               if (!resolve_classref(m,imr->classref,resolveEager,true,&imrclass)) {
+                                               if (!resolve_classref(m,imr->classref,resolveEager,true, true,&imrclass)) {
                                                        log_text("Could not resolve class reference");
                                                        assert(0);
                                                }
@@ -750,7 +750,7 @@ inlining_methodinfo *inlining_analyse_method(methodinfo *m,
 
                                        } else {
                                                imr = class_getconstant(m->class, i, CONSTANT_Methodref);
-                                               if (!resolve_classref(m,imr->classref,resolveEager,true,&imrclass)) {
+                                               if (!resolve_classref(m,imr->classref,resolveEager,true, true,&imrclass)) {
                                                        log_text("Could not resolve class reference");
                                                        assert(0);
                                                }
index d53d15d6aea692d20e4c32c65bf46f8925453cd5..3b773fd7e93275eabea575502f5df8945b8109c7 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: parseRT.c 2657 2005-06-13 14:14:44Z twisti $
+   $Id: parseRT.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -537,7 +537,7 @@ if ((RTA_DEBUGr)||(RTA_DEBUGopcodes)) printf("\n");
                                classinfo *frclass;
 
                                fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
-                               if (!resolve_classref(m,fr->classref,resolveEager,true,&frclass)) {
+                               if (!resolve_classref(m,fr->classref,resolveEager,true, true,&frclass)) {
                                        log_text("Could not resolve class reference");
                                        assert(0);
                                }
@@ -570,7 +570,7 @@ if ((RTA_DEBUGr)||(RTA_DEBUGopcodes)) printf("\n");
                                classinfo *mrclass;
 
                                mr = class_getconstant(m->class, i, CONSTANT_Methodref);
-                               if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass)) {
+                               if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
                                        log_text("Could not resolve class reference");
                                        assert(0);
                                }
@@ -680,7 +680,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
 
                                mr = m->class->cpinfos[i];
                                 /*mr = class_getconstant(m->class, i, CONSTANT_Methodref)*/
-                                       if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass)) {
+                                       if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
                                                log_text("Could not resolve class reference");
                                                assert(0);
                                        }
@@ -729,7 +729,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                                                classinfo *mrclass;
 
                                 mr = class_getconstant(m->class, i, CONSTANT_InterfaceMethodref);
-                                                               if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass)) {
+                                                               if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
                                                                        log_text("Could not resolve class reference");
                                                                        assert(0);
                                                                }
@@ -761,7 +761,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                constant_classref *cr;
                                classinfo *ci;
                 cr = (constant_classref *)class_getconstant(m->class, i, CONSTANT_Class);
-                               resolve_classref(NULL,cr,resolveEager,false,&ci);
+                               resolve_classref(NULL,cr,resolveEager,true, false,&ci);
                         /*** s_count++; look for s_counts for VTA */
                        /* add marked methods */
                        CLASSNAME(ci,"NEW : do nothing",RTA_DEBUGr);
@@ -778,7 +778,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                classinfo *cls;
 
                                                        cr = (constant_classref*) class_getconstant(m->class, i, CONSTANT_Class);
-                                                       resolve_classref(NULL,cr,resolveEager,false,&cls);
+                                                       resolve_classref(NULL,cr,resolveEager,true, false,&cls);
 
                         LAZYLOADING(cls)
                                CLASSNAMEop(cls,RTA_DEBUGr);
index c37aacc2eb125a0762bb1ff02b4c01459bd944b5..2726854245d6b36ba5561e2dedbc4de63e7147fd 100644 (file)
@@ -42,7 +42,7 @@ Now wondering if there is a memory corruption because XTA seems to finish ok
 
    Changes: Christian Thalinger
 
-   $Id: parseXTA.c 2657 2005-06-13 14:14:44Z twisti $
+   $Id: parseXTA.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -1221,7 +1221,7 @@ if ((XTA_DEBUGr)||(XTA_DEBUGopcodes)) printf("\n");
                                classinfo *frclass;
 
                                fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
-                               if (!resolve_classref(m,fr->classref,resolveEager,true,&frclass)) {
+                               if (!resolve_classref(m,fr->classref,resolveEager,true, true,&frclass)) {
                                        log_text("Could not resolve class reference");
                                        assert(0);
                                }
@@ -1258,7 +1258,7 @@ printf(" PUTSTATIC:");fflush(stdout); utf_display(fi->class->name);printf(".");f
                                classinfo *frclass;
 
                                fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
-                               if (!resolve_classref(m,fr->classref,resolveEager,true,&frclass)) {
+                               if (!resolve_classref(m,fr->classref,resolveEager,true, true,&frclass)) {
                                        log_text("Could not resolve class reference");
                                        assert(0);
                                }
@@ -1299,7 +1299,7 @@ printf(" GETSTATIC:");fflush(stdout); utf_display(fi->class->name);printf(".");f
                                classinfo *mrclass;
 
                                mr = class_getconstant(m->class, i, CONSTANT_Methodref);
-                               if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass)) {
+                               if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
                                        log_text("Could not resolve class reference");
                                        assert(0);
                                }
@@ -1411,7 +1411,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
 
                                mr = m->class->cpinfos[i];
                                 /*mr = class_getconstant(m->class, i, CONSTANT_Methodref)*/
-                                       if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass)) {
+                                       if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
                                                log_text("Could not resolve class reference");
                                                assert(0);
                                        }
@@ -1469,7 +1469,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                                                classinfo *mrclass;
 
                                 mr = class_getconstant(m->class, i, CONSTANT_InterfaceMethodref);
-                                                               if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass)) {
+                                                               if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
                                                                        log_text("Could not resolve class reference");
                                                                        assert(0);
                                                                }
@@ -1501,7 +1501,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                        classinfo *cls;
                        constant_classref *cr;
                        cr = (constant_classref *)class_getconstant(m->class, i, CONSTANT_Class);
-                       resolve_classref(NULL,cr,resolveEager,false,&cls);
+                       resolve_classref(NULL,cr,resolveEager,true, false,&cls);
                         /*** s_count++; look for s_counts for VTA */
                        /* add marked methods */
                        CLASSNAME(cls,"NEW : do nothing",XTA_DEBUGr);
@@ -1518,7 +1518,7 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                                        constant_classref *cr;
                                                        classinfo *cls;
                                                        cr = (constant_classref*) class_getconstant(m->class, i, CONSTANT_Class);
-                                                       resolve_classref(NULL,cr,resolveEager,false,&cls);
+                                                       resolve_classref(NULL,cr,resolveEager,true, false,&cls);
                         LAZYLOADING(cls)
                                CLASSNAMEop(cls,XTA_DEBUGr);
                         if (cls->classUsed == NOTUSED){
index c6201447f55f915131bd1f1804680e252fcaf96e..dafe4ad588f758163d2e4238475d9268b7c26f9b 100644 (file)
@@ -31,7 +31,7 @@
             Joseph Wenninger
             Christian Thalinger
 
-   $Id: parse.c 2783 2005-06-22 12:05:49Z edwin $
+   $Id: parse.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -696,7 +696,7 @@ SHOWOPCODE(DEBUG4)
                        if (!(cr = class_get_classref_multiarray_of(1, compr)))
                                return NULL;
 
-                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
                                return NULL;
 
                        if (c) {
@@ -723,7 +723,7 @@ SHOWOPCODE(DEBUG4)
 
                                cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
                                        return NULL;
 
                                if (c) {
@@ -1193,7 +1193,7 @@ SHOWOPCODE(DEBUG4)
                        i = code_get_u2(p + 1, inline_env->method);
                        cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
+                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
                                                                  &c))
                                return NULL;
 
@@ -1216,7 +1216,7 @@ SHOWOPCODE(DEBUG4)
                        i = code_get_u2(p + 1, inline_env->method);
                        cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
                                return NULL;
 
                        if (cr->name->text[0] == '[') {
@@ -1247,7 +1247,7 @@ SHOWOPCODE(DEBUG4)
                        i = code_get_u2(p + 1,inline_env->method);
                        cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                       if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
                                return NULL;
 
                        if (cr->name->text[0] == '[') {
index 760d1816a29af2c485b4698d833444a58f6cd7be..769017561f8c29e515046dd7fecf30eb7ec4fe4a 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: typecheck.c 2787 2005-06-22 13:24:19Z edwin $
+   $Id: typecheck.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -927,7 +927,8 @@ verify_invocation(verifier_state *state)
        if (rtype != TYPE_VOID) {
                if (rtype != dst->type)
                        TYPECHECK_VERIFYERROR_bool("Return type mismatch in method invocation");
-               typeinfo_init_from_typedesc(&(md->returntype),NULL,&(dst->typeinfo));
+               if (!typeinfo_init_from_typedesc(&(md->returntype),NULL,&(dst->typeinfo)))
+                       return false;
        }
 
        if (callinginit) {
@@ -962,12 +963,14 @@ verify_invocation(verifier_state *state)
                                        TYPESTACK_COPY(sp,copy);
                                }
 
-                               TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(stack->typeinfo,initclass);
+                               if (!typeinfo_init_class(&(stack->typeinfo),initclass))
+                                       return false;
                        }
                        stack = stack->prev;
                }
                /* replace uninitialized object type in locals */
-               typevectorset_init_object(state->localset,ins,initclass,state->numlocals);
+               if (!typevectorset_init_object(state->localset,ins,initclass,state->numlocals))
+                       return false;
 
                /* initializing the 'this' reference? */
                if (!ins) {
@@ -1081,7 +1084,8 @@ verify_builtin(verifier_state *state)
                TYPECHECK_INT(state->curstack->prev);
                if (state->iptr[-1].opc != ICMD_ACONST)
                        TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_newarray without classinfo");
-               TYPEINFO_INIT_CLASSREF(dst->typeinfo,state->iptr[-1].val.a);
+               if (!typeinfo_init_class(&(dst->typeinfo),CLASSREF_OR_CLASSINFO(state->iptr[-1].val.a)))
+                       return false;
        }
        else if (ISBUILTIN(BUILTIN_newarray))
        {
@@ -1124,7 +1128,8 @@ verify_builtin(verifier_state *state)
                TYPECHECK_ADR(state->curstack->prev);
                if (state->iptr[-1].opc != ICMD_ACONST)
                        TYPECHECK_VERIFYERROR_bool("illegal instruction: BUILTIN_arraycheckcast without classinfo");
-               TYPEINFO_INIT_CLASSREF(dst->typeinfo,state->iptr[-1].val.a);
+               if (!typeinfo_init_class(&(dst->typeinfo),CLASSREF_OR_CLASSINFO(state->iptr[-1].val.a)))
+                       return false;
        }
        else if (ISBUILTIN(BUILTIN_aastore)) {
                TYPECHECK_ADR(state->curstack);
@@ -1362,7 +1367,8 @@ verify_basic_block(verifier_state *state)
                                if (!TYPEINFO_MAYBE_ARRAY_OF_REFS(state->curstack->prev->typeinfo))
                                        TYPECHECK_VERIFYERROR_bool("illegal instruction: AALOAD on non-reference array");
 
-                               typeinfo_init_component(&state->curstack->prev->typeinfo,&dst->typeinfo);
+                               if (!typeinfo_init_component(&state->curstack->prev->typeinfo,&dst->typeinfo))
+                                       return false;
                                maythrow = true;
                                break;
 
@@ -1411,7 +1417,8 @@ putfield_tail:
 
                                /* the result is pushed on the stack */
                                if (dst->type == TYPE_ADR) {
-                                       typeinfo_init_from_typedesc(uf->fieldref->parseddesc.fd,NULL,&(dst->typeinfo));
+                                       if (!typeinfo_init_from_typedesc(uf->fieldref->parseddesc.fd,NULL,&(dst->typeinfo)))
+                                               return false;
                                }
                                maythrow = true;
                                break;
@@ -1555,7 +1562,8 @@ putfield_tail:
                                if (cls)
                                        TYPEINFO_INIT_CLASSINFO(dst->typeinfo,cls);
                                else
-                                       TYPEINFO_INIT_CLASSREF(dst->typeinfo,state->iptr[0].target);
+                                       if (!typeinfo_init_class(&(dst->typeinfo),CLASSREF_OR_CLASSINFO(state->iptr[0].target)))
+                                               return false;
                                maythrow = true;
                                break;
 
@@ -1770,7 +1778,8 @@ return_tail:
                                        }
                                        else {
                                                /* XXX do checks in patcher */
-                                               TYPEINFO_INIT_CLASSREF(dst->typeinfo,state->iptr[0].val.a);
+                                               if (!typeinfo_init_class(&(dst->typeinfo),CLASSREF_OR_CLASSINFO(state->iptr[0].val.a)))
+                                                       return false;
                                        }
                                }
                                maythrow = true;
@@ -2083,6 +2092,8 @@ verify_init_locals(verifier_state *state)
                                                                                          true, /* two word types use two slots */
                                                                                          (td - lset->td), /* skip 'this' pointer */
                                                                                          &state->returntype);
+       if (i == -1)
+               return false;
        td += i;
 
        /* variables not used for arguments are initialized to TYPE_VOID */
@@ -2225,7 +2236,6 @@ methodinfo *typecheck(methodinfo *meth, codegendata *cdata, registerdata *rdata)
     LOG("Exception handler stacks set.\n");
 
     /* loop while there are still blocks to be checked */
-
     do {
                TYPECHECK_COUNT(count_iterations);
 
index 5f456d9e960b74e96c6d6f1abbb0b39aa5a724c3..3a5822dc9c3e204966aae55ff2442f829086c7e9 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Edwin Steiner
 
-   $Id: typeinfo.c 2750 2005-06-20 15:11:47Z edwin $
+   $Id: typeinfo.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -195,7 +195,7 @@ typevectorset_store_twoword(typevector *vec,int index,int type)
        } while ((vec = vec->alt) != NULL);
 }
 
-void
+bool
 typevectorset_init_object(typevector *set,void *ins,
                                                  classref_or_classinfo initclass,
                                                  int size)
@@ -208,10 +208,12 @@ typevectorset_init_object(typevector *set,void *ins,
                                && TYPEINFO_IS_NEWOBJECT(set->td[i].info)
                                && TYPEINFO_NEWOBJECT_INSTRUCTION(set->td[i].info) == ins)
                        {
-                               TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(set->td[i].info,initclass);
+                               if (!typeinfo_init_class(&(set->td[i].info),initclass))
+                                       return false;
                        }
                }
        }
+       return true;
 }
 
 bool
@@ -657,10 +659,8 @@ typeinfo_init_class(typeinfo *info,classref_or_classinfo c)
 
        /* if necessary, try to resolve lazily */
        if (!resolve_classref_or_classinfo(NULL /* XXX should now method */,
-                               c,resolveLazy,true,&cls))
+                               c,resolveLazy,false,true,&cls))
        {
-               log_text("XXX could not resolve class reference"); /* XXX */
-               assert(0);
                return false;
        }
        
@@ -701,7 +701,7 @@ typeinfo_init_class(typeinfo *info,classref_or_classinfo c)
        return true;
 }
 
-void
+bool
 typeinfo_init_from_typedesc(typedesc *desc,u1 *type,typeinfo *info)
 {
        TYPEINFO_ASSERT(desc);
@@ -718,15 +718,17 @@ typeinfo_init_from_typedesc(typedesc *desc,u1 *type,typeinfo *info)
        if (info) {
                if (desc->type == TYPE_ADR) {
                        TYPEINFO_ASSERT(desc->classref);
-                       TYPEINFO_INIT_CLASSREF(*info,desc->classref);
+                       if (!typeinfo_init_class(info,CLASSREF_OR_CLASSINFO(desc->classref)))
+                               return false;
                }
                else {
                        TYPEINFO_INIT_PRIMITIVE(*info);
                }
        }
+       return true;
 }
 
-void
+bool
 typeinfo_init_from_methoddesc(methoddesc *desc,u1 *typebuf,typeinfo *infobuf,
                               int buflen,bool twoword,
                               u1 *returntype,typeinfo *returntypeinfo)
@@ -751,7 +753,8 @@ typeinfo_init_from_methoddesc(methoddesc *desc,u1 *typebuf,typeinfo *infobuf,
                        assert(0);
                }
 
-               typeinfo_init_from_typedesc(desc->paramtypes + i,typebuf++,infobuf++);
+               if (!typeinfo_init_from_typedesc(desc->paramtypes + i,typebuf++,infobuf++))
+                       return false;
                
                if (twoword && (typebuf[-1] == TYPE_LONG || typebuf[-1] == TYPE_DOUBLE)) {
                        if (++args > buflen) {
@@ -767,21 +770,26 @@ typeinfo_init_from_methoddesc(methoddesc *desc,u1 *typebuf,typeinfo *infobuf,
 
     /* check returntype */
     if (returntype) {
-               typeinfo_init_from_typedesc(&(desc->returntype),returntype,returntypeinfo);
+               if (!typeinfo_init_from_typedesc(&(desc->returntype),returntype,returntypeinfo))
+                       return false;
        }
+
+       return true;
 }
 
-void
+bool
 typedescriptor_init_from_typedesc(typedescriptor *td,
                                                                  typedesc *desc)
 {
        td->type = desc->type;
        if (td->type == TYPE_ADR) {
-               TYPEINFO_INIT_CLASSREF(td->info,desc->classref);
+               if (!typeinfo_init_class(&(td->info),CLASSREF_OR_CLASSINFO(desc->classref)))
+                       return false;
        }
        else {
                TYPEINFO_INIT_PRIMITIVE(td->info);
        }
+       return true;
 }
 
 int
@@ -800,7 +808,8 @@ typedescriptors_init_from_methoddesc(typedescriptor *td,
                        assert(0);
                }
 
-               typedescriptor_init_from_typedesc(td,desc->paramtypes + i);
+               if (!typedescriptor_init_from_typedesc(td,desc->paramtypes + i))
+                       return -1;
                td++;
 
                if (twoword && (td[-1].type == TYPE_LONG || td[-1].type == TYPE_DOUBLE)) {
@@ -817,18 +826,19 @@ typedescriptors_init_from_methoddesc(typedescriptor *td,
 
     /* check returntype */
     if (returntype) {
-               typedescriptor_init_from_typedesc(returntype,&(desc->returntype));
+               if (!typedescriptor_init_from_typedesc(returntype,&(desc->returntype)))
+                       return -1;
        }
 
        return args;
 }
 
-void
+bool
 typeinfo_init_component(typeinfo *srcarray,typeinfo *dst)
 {
     if (TYPEINFO_IS_NULLTYPE(*srcarray)) {
         TYPEINFO_INIT_NULLTYPE(*dst);
-        return;
+        return true;
     }
     
     if (!TYPEINFO_IS_ARRAY(*srcarray)) {
@@ -840,18 +850,20 @@ typeinfo_init_component(typeinfo *srcarray,typeinfo *dst)
                constant_classref *comp;
                comp = class_get_classref_component_of(srcarray->typeclass.ref);
 
-               if (comp)
-                       TYPEINFO_INIT_CLASSREF(*dst,comp);
-               else
+               if (comp) {
+                       if (!typeinfo_init_class(dst,CLASSREF_OR_CLASSINFO(comp)))
+                               return false;
+               }
+               else {
                        TYPEINFO_INIT_PRIMITIVE(*dst);
+               }
        }
        else {
                vftbl_t *comp;
                
                if (!srcarray->typeclass.cls->linked) {
                        if (!link_class(srcarray->typeclass.cls)) {
-                               log_text("XXX could not link class");
-                               assert(0);
+                               return false;
                        }
                }
 
@@ -866,6 +878,7 @@ typeinfo_init_component(typeinfo *srcarray,typeinfo *dst)
        }
     
     dst->merged = srcarray->merged; /* XXX should we do a deep copy? */
+       return true;
 }
 
 void
index 7e38b74161855877950436458b46fb78b37f5871..2eae71337336292cbd7d0415880b2705dabb2919 100644 (file)
@@ -26,7 +26,7 @@
 
    Authors: Edwin Steiner
 
-   $Id: typeinfo.h 2749 2005-06-20 15:04:31Z edwin $
+   $Id: typeinfo.h 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -456,12 +456,6 @@ struct typevector {
             }                                                           \
             (info).merged = NULL;} while(0)
 
-#define TYPEINFO_INIT_CLASSREF(info,c)    \
-            typeinfo_init_class(&(info),CLASSREF_OR_CLASSINFO(c))
-
-#define TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(info,c)    \
-            typeinfo_init_class(&(info),c)
-
 /* macros for copying types (destinition is not checked or freed) ***********/
 
 /* TYPEINFO_COPY makes a shallow copy, the merged pointer is simply copied. */
@@ -493,7 +487,7 @@ int typevectorset_mergedtype(typevector *set,int index,typeinfo *temp,typeinfo *
 void typevectorset_store(typevector *set,int index,int type,typeinfo *info);
 void typevectorset_store_retaddr(typevector *set,int index,typeinfo *info);
 void typevectorset_store_twoword(typevector *set,int index,int type);
-void typevectorset_init_object(typevector *set,void *ins,classref_or_classinfo initclass,int size);
+bool typevectorset_init_object(typevector *set,void *ins,classref_or_classinfo initclass,int size);
 
 /* vector functions */
 bool typevector_separable_from(typevector *a,typevector *b,int size);
@@ -518,15 +512,23 @@ tristate_t typeinfo_is_assignable_to_class(typeinfo *value,classref_or_classinfo
 
 /* initialization functions *************************************************/
 
+/* RETURN VALUE (bool):
+ *     true.............ok,
+ *     false............an exception has been thrown.
+ *
+ * RETURN VALUE (int):
+ *     >= 0.............ok,
+ *     -1...............an exception has been thrown.
+ */
 bool typeinfo_init_class(typeinfo *info,classref_or_classinfo c);
-void typeinfo_init_component(typeinfo *srcarray,typeinfo *dst);
+bool typeinfo_init_component(typeinfo *srcarray,typeinfo *dst);
 
-void typeinfo_init_from_typedesc(typedesc *desc,u1 *type,typeinfo *info);
-void typeinfo_init_from_methoddesc(methoddesc *desc,u1 *typebuf,
+bool typeinfo_init_from_typedesc(typedesc *desc,u1 *type,typeinfo *info);
+bool typeinfo_init_from_methoddesc(methoddesc *desc,u1 *typebuf,
                                    typeinfo *infobuf,
                                    int buflen,bool twoword,
                                    u1 *returntype,typeinfo *returntypeinfo);
-void  typedescriptor_init_from_typedesc(typedescriptor *td,
+bool  typedescriptor_init_from_typedesc(typedescriptor *td,
                                                                            typedesc *desc);
 int  typedescriptors_init_from_methoddesc(typedescriptor *td,
                                                                                  methoddesc *desc,
index b70543204dc89d85872928cce62de6934b0c9b6e..8ecbe2f2fb1e28f06c3b04e0fc5a31504beccd0a 100644 (file)
@@ -32,7 +32,7 @@
             Edwin Steiner
             Christian Thalinger
 
-   $Id: linker.c 2728 2005-06-17 08:12:26Z twisti $
+   $Id: linker.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -444,7 +444,7 @@ static classinfo *link_class_intern(classinfo *c)
                /* resolve this super interface */
 
                if (!resolve_classref_or_classinfo(NULL, c->interfaces[i], resolveEager,
-                                                                                  false, &tc))
+                                                                                  true, false, &tc))
                        return NULL;
 
                c->interfaces[i].cls = tc;
@@ -489,7 +489,7 @@ static classinfo *link_class_intern(classinfo *c)
        } else {
                /* resolve super class */
 
-               if (!resolve_classref_or_classinfo(NULL, c->super, resolveEager, false,
+               if (!resolve_classref_or_classinfo(NULL, c->super, resolveEager, true, false,
                                                                                   &super))
                        return NULL;
                c->super.cls = super;
@@ -794,14 +794,14 @@ static classinfo *link_class_intern(classinfo *c)
                                continue;
                        if (!resolve_classref_or_classinfo(NULL,
                                                                                           m->exceptiontable[j].catchtype,
-                                                                                          resolveEager, false,
+                                                                                          resolveEager, true, false,
                                                                                           &(m->exceptiontable[j].catchtype.cls)))
                                return NULL;
                }
 
                for (j = 0; j < m->thrownexceptionscount; j++)
                        if (!resolve_classref_or_classinfo(NULL, m->thrownexceptions[j],
-                                                                                          resolveEager, false,
+                                                                                          resolveEager, true, false,
                                                                                           &(m->thrownexceptions[j].cls)))
                                return NULL;
        }
index bb2575404dd250052ef4dfbebf581905fadda333..efb934219132ccd6f0c54aab65edb5da61ed510e 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Christan Thalinger
 
-   $Id: resolve.c 2784 2005-06-22 12:09:11Z edwin $
+   $Id: resolve.c 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -73,6 +73,7 @@ bool
 resolve_class_from_name(classinfo *referer,methodinfo *refmethod,
                          utf *classname,
                          resolve_mode_t mode,
+                         bool checkaccess,
                          bool link,
                          classinfo **result)
 {
@@ -92,7 +93,7 @@ resolve_class_from_name(classinfo *referer,methodinfo *refmethod,
        utf_fprint(stderr,referer->name);
        fprintf(stderr,",");
        utf_fprint(stderr,classname);
-       fprintf(stderr,")\n");
+       fprintf(stderr,",%d,%d)\n",(int)checkaccess,(int)link);
 #endif
 
        /* lookup if this class has already been loaded */
@@ -118,7 +119,7 @@ resolve_class_from_name(classinfo *referer,methodinfo *refmethod,
                                        /* resolve the component type */
                                        if (!resolve_class_from_name(referer,refmethod,
                                                                           utf_new(utf_ptr,len),
-                                                                          mode,link,&cls))
+                                                                          mode,checkaccess,link,&cls))
                                                return false; /* exception */
                                        if (!cls) {
                                                RESOLVE_ASSERT(mode == resolveLazy);
@@ -157,9 +158,19 @@ resolve_class_from_name(classinfo *referer,methodinfo *refmethod,
 #endif
        
        /* check access rights of referer to refered class */
-       if (!is_accessible_class(referer,cls)) {
-               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException,
-                               "class is not accessible XXX add message");
+       if (checkaccess && !is_accessible_class(referer,cls)) {
+               int msglen;
+               char *message;
+
+               msglen = utf_strlen(cls->name) + utf_strlen(referer->name) + 100;
+               message = MNEW(char,msglen);
+               strcpy(message,"class is not accessible (");
+               utf_sprint_classname(message+strlen(message),cls->name);
+               strcat(message," from ");
+               utf_sprint_classname(message+strlen(message),referer->name);
+               strcat(message,")");
+               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException,message);
+               MFREE(message,char,msglen);
                return false; /* exception */
        }
 
@@ -183,16 +194,18 @@ bool
 resolve_classref(methodinfo *refmethod,
                                 constant_classref *ref,
                                 resolve_mode_t mode,
+                                bool checkaccess,
                             bool link,
                                 classinfo **result)
 {
-       return resolve_classref_or_classinfo(refmethod,CLASSREF_OR_CLASSINFO(ref),mode,link,result);
+       return resolve_classref_or_classinfo(refmethod,CLASSREF_OR_CLASSINFO(ref),mode,checkaccess,link,result);
 }
 
 bool
 resolve_classref_or_classinfo(methodinfo *refmethod,
                                                          classref_or_classinfo cls,
                                                          resolve_mode_t mode,
+                                                         bool checkaccess,
                                                          bool link,
                                                          classinfo **result)
 {
@@ -205,7 +218,7 @@ resolve_classref_or_classinfo(methodinfo *refmethod,
 #ifdef RESOLVE_VERBOSE
        fprintf(stderr,"resolve_classref_or_classinfo(");
        utf_fprint(stderr,(IS_CLASSREF(cls)) ? cls.ref->name : cls.cls->name);
-       fprintf(stderr,",%i,%i)\n",mode,link);
+       fprintf(stderr,",%i,%i,%i)\n",mode,(int)checkaccess,(int)link);
 #endif
 
        *result = NULL;
@@ -213,7 +226,7 @@ resolve_classref_or_classinfo(methodinfo *refmethod,
        if (IS_CLASSREF(cls)) {
                /* we must resolve this reference */
                if (!resolve_class_from_name(cls.ref->referer,refmethod,cls.ref->name,
-                                                                       mode,link,&c))
+                                                                       mode,checkaccess,link,&c))
                        return false; /* exception */
        }
        else {
@@ -242,7 +255,7 @@ resolve_classref_or_classinfo(methodinfo *refmethod,
 }
 
 bool 
-resolve_class_from_typedesc(typedesc *d, bool link, classinfo **result)
+resolve_class_from_typedesc(typedesc *d, bool checkaccess, bool link, classinfo **result)
 {
        classinfo *cls;
        
@@ -254,13 +267,13 @@ resolve_class_from_typedesc(typedesc *d, bool link, classinfo **result)
 #ifdef RESOLVE_VERBOSE
        fprintf(stderr,"resolve_class_from_typedesc(");
        descriptor_debug_print_typedesc(stderr,d);
-       fprintf(stderr,",%i)\n",link);
+       fprintf(stderr,",%i,%i)\n",(int)checkaccess,(int)link);
 #endif
 
        if (d->classref) {
                /* a reference type */
                if (!resolve_classref_or_classinfo(NULL,CLASSREF_OR_CLASSINFO(d->classref),
-                                                                                  resolveEager,link,&cls))
+                                                                                  resolveEager,checkaccess,link,&cls))
                        return false; /* exception */
        }
        else {
@@ -336,7 +349,7 @@ resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
                *checked = false;
 
        /* first resolve the type if necessary */
-       if (!resolve_classref_or_classinfo(refmethod,typeref,mode,true,&type))
+       if (!resolve_classref_or_classinfo(refmethod,typeref,mode,false,true,&type))
                return false; /* exception */
        if (!type)
                return true; /* be lazy */
@@ -348,7 +361,7 @@ resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
 
        for (; setp->any; ++setp) {
                /* first resolve the set member if necessary */
-               if (!resolve_classref_or_classinfo(refmethod,*setp,mode,true,&result))
+               if (!resolve_classref_or_classinfo(refmethod,*setp,mode,false,true,&result))
                        return false; /* exception */
                if (!result)
                        return true; /* be lazy */
@@ -417,6 +430,7 @@ throw_error:
 bool
 resolve_class(unresolved_class *ref,
                          resolve_mode_t mode,
+                         bool checkaccess,
                          classinfo **result)
 {
        classinfo *cls;
@@ -434,7 +448,7 @@ resolve_class(unresolved_class *ref,
 
        /* first we must resolve the class */
        if (!resolve_classref(ref->referermethod,
-                                             ref->classref,mode,true,&cls))
+                                             ref->classref,mode,checkaccess,true,&cls))
        {
                /* the class reference could not be resolved */
                return false; /* exception */
@@ -496,7 +510,7 @@ resolve_field(unresolved_field *ref,
 
        /* first we must resolve the class containg the field */
        if (!resolve_class_from_name(referer,ref->referermethod,
-                                          ref->fieldref->classref->name,mode,true,&container))
+                                          ref->fieldref->classref->name,mode,true,true,&container))
        {
                /* the class reference could not be resolved */
                return false; /* exception */
@@ -590,8 +604,20 @@ resolve_field(unresolved_field *ref,
        fprintf(stderr,"    checking access rights...\n");
 #endif
        if (!is_accessible_member(referer,declarer,fi->flags)) {
-               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException,
-                               "field is not accessible XXX add message");
+               int msglen;
+               char *message;
+
+               msglen = utf_strlen(declarer->name) + utf_strlen(fi->name) + utf_strlen(referer->name) + 100;
+               message = MNEW(char,msglen);
+               strcpy(message,"field is not accessible (");
+               utf_sprint_classname(message+strlen(message),declarer);
+               strcat(message,".");
+               utf_sprint(message+strlen(message),fi->name);
+               strcat(message," from ");
+               utf_sprint_classname(message+strlen(message),referer->name);
+               strcat(message,")");
+               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException,message);
+               MFREE(message,char,msglen);
                return false; /* exception */
        }
 #ifdef RESOLVE_VERBOSE
@@ -672,7 +698,7 @@ resolve_method(unresolved_method *ref, resolve_mode_t mode, methodinfo **result)
 
        /* first we must resolve the class containg the method */
        if (!resolve_class_from_name(referer,ref->referermethod,
-                                          ref->methodref->classref->name,mode,true,&container))
+                                          ref->methodref->classref->name,mode,true,true,&container))
        {
                /* the class reference could not be resolved */
                return false; /* exception */
@@ -773,8 +799,22 @@ resolve_method(unresolved_method *ref, resolve_mode_t mode, methodinfo **result)
        /* check access rights */
 
        if (!is_accessible_member(referer,declarer,mi->flags)) {
-               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException,
-                               "method is not accessible XXX add message");
+               int msglen;
+               char *message;
+
+               msglen = utf_strlen(declarer->name) + utf_strlen(mi->name) + 
+                       utf_strlen(mi->descriptor) + utf_strlen(referer->name) + 100;
+               message = MNEW(char,msglen);
+               strcpy(message,"method is not accessible (");
+               utf_sprint_classname(message+strlen(message),declarer);
+               strcat(message,".");
+               utf_sprint(message+strlen(message),mi->name);
+               utf_sprint(message+strlen(message),mi->descriptor);
+               strcat(message," from ");
+               utf_sprint_classname(message+strlen(message),referer->name);
+               strcat(message,")");
+               *exceptionptr = new_exception_message(string_java_lang_IllegalAccessException,message);
+               MFREE(message,char,msglen);
                return false; /* exception */
        }
 
@@ -1322,8 +1362,9 @@ constrain_unresolved_method(unresolved_method *ref,
                        instruction *ins = (instruction*)TYPEINFO_NEWOBJECT_INSTRUCTION(instanceslot->typeinfo);
                        classref_or_classinfo initclass = (ins) ? CLASSREF_OR_CLASSINFO(ins[-1].val.a)
                                                                                 : CLASSREF_OR_CLASSINFO(refmethod->class);
-                       TYPEINFO_INIT_CLASSREF_OR_CLASSINFO(tinfo,initclass);
                        tip = &tinfo;
+                       if (!typeinfo_init_class(tip,initclass))
+                               return false;
                }
                else {
                        tip = &(instanceslot->typeinfo);
index 619d14a23143f7d6ca998ce3b6fe3346a7659af8..3c4c5c446968d1ca5b5aa34e10f52bf0f771e5ee 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: resolve.h 2738 2005-06-18 16:37:34Z edwin $
+   $Id: resolve.h 2788 2005-06-22 16:08:51Z edwin $
 
 */
 
@@ -122,6 +122,7 @@ struct unresolved_method {
                             resolveLazy...only resolve if it does not
                                           require loading classes
                             resolveEager..load classes if necessary
+          checkaccess......if true, access rights to the class are checked
           link.............if true, guarantee that the returned class, if any,
                            has been linked
   
@@ -146,6 +147,7 @@ bool
 resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
                                                utf *classname,
                                                resolve_mode_t mode,
+                                               bool checkaccess,
                                                bool link,
                                                classinfo **result);
 
@@ -161,6 +163,7 @@ resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
                             resolveLazy...only resolve if it does not
                                           require loading classes
                             resolveEager..load classes if necessary
+          checkaccess......if true, access rights to the class are checked
           link.............if true, guarantee that the returned class, if any,
                            has been linked
   
@@ -181,6 +184,7 @@ bool
 resolve_classref(methodinfo *refmethod,
                                 constant_classref *ref,
                                 resolve_mode_t mode,
+                                bool checkaccess,
                             bool link,
                                 classinfo **result);
 
@@ -196,6 +200,7 @@ resolve_classref(methodinfo *refmethod,
                             resolveLazy...only resolve if it does not
                                           require loading classes
                             resolveEager..load classes if necessary
+          checkaccess......if true, access rights to the class are checked
           link.............if true, guarantee that the returned class, if any,
                            has been linked
   
@@ -216,6 +221,7 @@ bool
 resolve_classref_or_classinfo(methodinfo *refmethod,
                                                          classref_or_classinfo cls,
                                                          resolve_mode_t mode,
+                                                         bool checkaccess,
                                                          bool link,
                                                          classinfo **result);
 
@@ -225,6 +231,7 @@ resolve_classref_or_classinfo(methodinfo *refmethod,
   
    IN:
        d................type descriptor
+          checkaccess......if true, access rights to the class are checked
           link.............if true, guarantee that the returned class, if any,
                            has been linked
    OUT:
@@ -242,11 +249,11 @@ resolve_classref_or_classinfo(methodinfo *refmethod,
    
 *******************************************************************************/
 
-bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
+bool resolve_class_from_typedesc(typedesc *d,bool checkaccess,bool link,classinfo **result);
 
 /* resolve_class ***************************************************************
  
-   Resolve an unresolved class reference
+   Resolve an unresolved class reference. The class is also linked.
   
    IN:
        ref..............struct containing the reference
@@ -254,7 +261,8 @@ bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
                             resolveLazy...only resolve if it does not
                                           require loading classes
                             resolveEager..load classes if necessary
-  
+          checkaccess......if true, access rights to the class are checked
+   
    OUT:
        *result..........set to the result of resolution, or to NULL if
                         the reference has not been resolved
@@ -271,6 +279,7 @@ bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
 bool
 resolve_class(unresolved_class *ref,
                          resolve_mode_t mode,
+                         bool checkaccess,
                          classinfo **result);
 
 /* resolve_field ***************************************************************