Ejemplo n.º 1
0
JNIEXPORT jint JNICALL
Java_MyPackage_GetNamedModuleTest_check(JNIEnv *env, jclass cls) {
    jobject loader = NULL;

    if (jvmti == NULL) {
        throw_exc(env, "JVMTI client was not properly loaded!\n");
        return FAILED;
    }

    get_all_modules(env);

    printf("\n*** Check for bad ClassLoader ***\n\n");
    result = check_bad_loader(env, (jobject)cls);
    if (result != PASSED) {
        throw_exc(env, "check #L1: failed to return JVMTI_ERROR_ILLEGAL_ARGUMENT for bad loader");
        return result;
    }

    loader = get_class_loader(cls);
    if (loader == NULL) {
        throw_exc(env, "check #L2: failed to return non-NULL loader for valid test class");
        return FAILED;
    }

    printf("\n*** Checks for System ClassLoader ***\n\n");
    result = check_system_loader(env, loader);
    if (result != PASSED) {
        return result;
    }

    printf("\n*** Checks for Bootstrap ClassLoader ***\n\n");
    result = check_bootstrap_loader(env, NULL);

    return result;
}
Ejemplo n.º 2
0
static inline uint32_t
format_to_fourcc(JNIEnv *env,
                 jstring format)
{
    if(!format)
        goto invalid;

    int n = (*env)->GetStringLength(env, format);
    if(0 >= n || n > 4)
        goto invalid;

    char fmtstr[8];
    (*env)->GetStringUTFRegion(env, format, 0, n, fmtstr);

    uint32_t fourcc = 0;
    int i;
    for(i = 0; i < n; i++) {
        if(fmtstr[i] < ' ' || 'Z' < fmtstr[i] ||
           ('9' < fmtstr[i] && fmtstr[i] < 'A') ||
           (' ' < fmtstr[i] && fmtstr[i] < '0'))
            goto invalid;
        fourcc |= ((uint32_t)fmtstr[i]) << (8 * i);
    }
    return(fourcc);

invalid:
    throw_exc(env, "java/lang/IllegalArgumentException",
              "invalid format fourcc");
    return(0);
}
Ejemplo n.º 3
0
JNIEXPORT void JNICALL
Java_net_sourceforge_zbar_ImageScanner_parseConfig (JNIEnv *env,
                                                    jobject obj,
                                                    jstring cfg)
{
    const char *cfgstr = (*env)->GetStringUTFChars(env, cfg, NULL);
    if(!cfgstr)
        return;
    if(zbar_image_scanner_parse_config(GET_PEER(ImageScanner, obj), cfgstr))
        throw_exc(env, "java/lang/IllegalArgumentException",
                  "unknown configuration");
}
Ejemplo n.º 4
0
JNIEXPORT jlong JNICALL
Java_net_sourceforge_zbar_ImageScanner_create (JNIEnv *env,
                                               jobject obj)
{
    zbar_image_scanner_t *zscn = zbar_image_scanner_create();
    if(!zscn) {
        throw_exc(env, "java/lang/OutOfMemoryError", NULL);
        return(0);
    }
    stats.ImageScanner_create++;
    return((intptr_t)zscn);
}
Ejemplo n.º 5
0
JNIEXPORT jint JNICALL
Java_net_sourceforge_zbar_ImageScanner_scanImage (JNIEnv *env,
                                                  jobject obj,
                                                  jobject image)
{
    zbar_image_scanner_t *zscn = GET_PEER(ImageScanner, obj);
    zbar_image_t *zimg = GET_PEER(Image, image);

    int n = zbar_scan_image(zscn, zimg);
    if(n < 0)
        throw_exc(env, "java/lang/UnsupportedOperationException",
                  "unsupported image format");
    return(n);
}
Ejemplo n.º 6
0
JNIEXPORT void JNICALL
Java_net_sourceforge_zbar_Image_setSize___3I (JNIEnv *env,
                                              jobject obj,
                                              jintArray size)
{
    if((*env)->GetArrayLength(env, size) != 2)
        throw_exc(env, "java/lang/IllegalArgumentException",
                  "size must be an array of two ints");
    jint dims[2];
    (*env)->GetIntArrayRegion(env, size, 0, 2, dims);
    if(dims[0] < 0) dims[0] = 0;
    if(dims[1] < 0) dims[1] = 0;
    zbar_image_set_size(GET_PEER(Image, obj), dims[0], dims[1]);
}
Ejemplo n.º 7
0
JNIEXPORT void JNICALL
Java_net_sourceforge_zbar_Image_setCrop___3I (JNIEnv *env,
                                              jobject obj,
                                              jintArray crop)
{
    if((*env)->GetArrayLength(env, crop) != 4)
        throw_exc(env, "java/lang/IllegalArgumentException",
                  "crop must be an array of four ints");
    jint dims[4];
    (*env)->GetIntArrayRegion(env, crop, 0, 4, dims);
    VALIDATE_CROP(dims[0], dims[2]);
    VALIDATE_CROP(dims[1], dims[3]);
    zbar_image_set_crop(GET_PEER(Image, obj),
                        dims[0], dims[1], dims[2], dims[3]);
}
Ejemplo n.º 8
0
JNIEXPORT jlong JNICALL
Java_net_sourceforge_zbar_Image_convert (JNIEnv *env,
                                         jobject obj,
                                         jlong peer,
                                         jstring format)
{
    uint32_t fourcc = format_to_fourcc(env, format);
    if(!fourcc)
        return(0);
    zbar_image_t *zimg = zbar_image_convert(PEER_CAST(peer), fourcc);
    if(!zimg)
        throw_exc(env, "java/lang/UnsupportedOperationException",
                  "unsupported image format");
    else
        stats.Image_create++;
    return((intptr_t)zimg);
}
Ejemplo n.º 9
0
static
jint check_bootstrap_loader(JNIEnv *env, jobject loader) {
    jvmtiError err = JVMTI_ERROR_NONE;
    jobject module = NULL;
    const char* exp_name = NULL;
    const char* mod_name = NULL;

    // NULL pointer for package name
    err = get_module(env, loader, NULL, &module, &mod_name);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #BN1: failed to return JVMTI_ERROR_NULL_POINTER for NULL package");
        return FAILED;
    }

    // NULL pointer for module_ptr
    err = (*jvmti)->GetNamedModule(jvmti, loader, "", NULL);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #BN2: failed to return JVMTI_ERROR_NULL_POINTER for NULL module_ptr");
        return FAILED;
    }

    // Unnamed/default package ""
    err = get_module(env, loader, "", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #B1: failed to return JVMTI_ERROR_NONE for default package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #B2: failed to return NULL-module for default package");
        return FAILED;
    }

    // Normal package from java.base module: "java/lang"
    exp_name = "java.base";
    err = get_module(env, loader, "java/lang", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #B3: failed to return JVMTI_ERROR_NONE for java/lang package");
        return FAILED;
    }
    if (module == NULL || mod_name == NULL) {
        throw_exc(env, "check #B4: failed to return named module for java/lang package");
        return FAILED;
    }
    if (strcmp(exp_name, mod_name) != 0) {
        printf("check #B5: failed to return right module, expected: %s, returned: %s\n",
               exp_name, mod_name);
        throw_exc(env, "check #B5: failed to return expected module for java/lang package");
        return FAILED;
    }

    // Non-existing package: "bad/package/name"
    err = get_module(env, loader, "bad/package/name", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #B6: failed to return JVMTI_ERROR_NONE for bad package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #B7: failed to return NULL-module for bad package");
        return FAILED;
    }
    return PASSED;
}
Ejemplo n.º 10
0
static
jint check_system_loader(JNIEnv *env, jobject loader) {
    jvmtiError err = JVMTI_ERROR_NONE;
    jobject module = NULL;
    const char* exp_name = NULL;
    const char* mod_name = NULL;

    // NULL pointer for package name
    err = get_module(env, loader, NULL, &module, &mod_name);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #SN1: failed to return JVMTI_ERROR_NULL_POINTER for NULL package");
        return FAILED;
    }

    // NULL pointer for module_ptr
    err = (*jvmti)->GetNamedModule(jvmti, loader, "", NULL);
    if (err != JVMTI_ERROR_NULL_POINTER) {
        throw_exc(env, "check #SN2: failed to return JVMTI_ERROR_NULL_POINTER for NULL module_ptr");
        return FAILED;
    }

    // Unnamed/default package ""
    err = get_module(env, loader, "", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S1: failed to return JVMTI_ERROR_NONE for default package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #S2: failed to return NULL-module for default package");
        return FAILED;
    }

    // Test package: MyPackage
    err = get_module(env, loader, "MyPackage", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S3: failed to return JVMTI_ERROR_NONE for MyPackage");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #S4: failed to return NULL-module for MyPackage");
        return FAILED;
    }

    // Package: com/sun/jdi
    exp_name = "jdk.jdi";
    err = get_module(env, loader, "com/sun/jdi", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S5: failed to return JVMTI_ERROR_NONE for test package");
        return FAILED;
    }
    if (module == NULL || mod_name == NULL) {
        throw_exc(env, "check #S6: failed to return named module for com/sun/jdi package");
        return FAILED;
    }
    if (strcmp(mod_name, exp_name) != 0) {
        printf("check #S7: failed to return right module, expected: %s, returned: %s\n",
               exp_name, mod_name);
        throw_exc(env, "check #S7: failed to return jdk.jdi module for com/sun/jdi package");
        return FAILED;
    }

    // Non-existing package: "bad/package/name"
    err = get_module(env, loader, "bad/package/name", &module, &mod_name);
    if (err != JVMTI_ERROR_NONE) {
        throw_exc(env, "check #S8: failed to return JVMTI_ERROR_NONE for bad package");
        return FAILED;
    }
    if (module != NULL || mod_name != NULL) {
        throw_exc(env, "check #S9: failed to return NULL-module for bad package");
        return FAILED;
    }
    return PASSED;
}