115 if (length < 0) {
116 JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
117 return 0;
118 }
119
120 body = (jbyte *)malloc(length);
121
122 if (body == 0) {
123 JNU_ThrowOutOfMemoryError(env, 0);
124 return 0;
125 }
126
127 (*env)->GetByteArrayRegion(env, data, offset, length, body);
128
129 if ((*env)->ExceptionOccurred(env))
130 goto free_body;
131
132 if (name != NULL) {
133 utfName = getUTF(env, name, buf, sizeof(buf));
134 if (utfName == NULL) {
135 JNU_ThrowOutOfMemoryError(env, NULL);
136 goto free_body;
137 }
138 VerifyFixClassname(utfName);
139 } else {
140 utfName = NULL;
141 }
142
143 if (source != NULL) {
144 utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
145 if (utfSource == NULL) {
146 JNU_ThrowOutOfMemoryError(env, NULL);
147 goto free_utfName;
148 }
149 } else {
150 utfSource = NULL;
151 }
152 result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);
153
154 if (utfSource && utfSource != sourceBuf)
155 free(utfSource);
156
157 free_utfName:
158 if (utfName && utfName != buf)
159 free(utfName);
160
161 free_body:
162 free(body);
163 return result;
164 }
165
166 JNIEXPORT jclass JNICALL
502 (JNIEnv *env, jclass cls, jstring name)
503 {
504 const char *cname;
505 char *libName;
506 int prefixLen = (int) strlen(JNI_LIB_PREFIX);
507 int suffixLen = (int) strlen(JNI_LIB_SUFFIX);
508 int len;
509 jstring lib;
510 void *ret;
511 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
512
513 if (name == NULL) {
514 JNU_ThrowInternalError(env, "NULL filename for native library");
515 return NULL;
516 }
517 // Can't call initIDs because it will recurse into NativeLibrary via
518 // FindClass to check context so set prochandle here as well.
519 procHandle = getProcessHandle();
520 cname = JNU_GetStringPlatformChars(env, name, 0);
521 if (cname == NULL) {
522 JNU_ThrowOutOfMemoryError(env, NULL);
523 return NULL;
524 }
525 // Copy name Skipping PREFIX
526 len = strlen(cname);
527 if (len <= (prefixLen+suffixLen)) {
528 JNU_ReleaseStringPlatformChars(env, name, cname);
529 return NULL;
530 }
531 libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
532 if (libName == NULL) {
533 JNU_ReleaseStringPlatformChars(env, name, cname);
534 JNU_ThrowOutOfMemoryError(env, NULL);
535 return NULL;
536 }
537 if (len > prefixLen) {
538 strcpy(libName, cname+prefixLen);
539 }
540 JNU_ReleaseStringPlatformChars(env, name, cname);
541
542 // Strip SUFFIX
|
115 if (length < 0) {
116 JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
117 return 0;
118 }
119
120 body = (jbyte *)malloc(length);
121
122 if (body == 0) {
123 JNU_ThrowOutOfMemoryError(env, 0);
124 return 0;
125 }
126
127 (*env)->GetByteArrayRegion(env, data, offset, length, body);
128
129 if ((*env)->ExceptionOccurred(env))
130 goto free_body;
131
132 if (name != NULL) {
133 utfName = getUTF(env, name, buf, sizeof(buf));
134 if (utfName == NULL) {
135 goto free_body;
136 }
137 VerifyFixClassname(utfName);
138 } else {
139 utfName = NULL;
140 }
141
142 if (source != NULL) {
143 utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
144 if (utfSource == NULL) {
145 goto free_utfName;
146 }
147 } else {
148 utfSource = NULL;
149 }
150 result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);
151
152 if (utfSource && utfSource != sourceBuf)
153 free(utfSource);
154
155 free_utfName:
156 if (utfName && utfName != buf)
157 free(utfName);
158
159 free_body:
160 free(body);
161 return result;
162 }
163
164 JNIEXPORT jclass JNICALL
500 (JNIEnv *env, jclass cls, jstring name)
501 {
502 const char *cname;
503 char *libName;
504 int prefixLen = (int) strlen(JNI_LIB_PREFIX);
505 int suffixLen = (int) strlen(JNI_LIB_SUFFIX);
506 int len;
507 jstring lib;
508 void *ret;
509 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
510
511 if (name == NULL) {
512 JNU_ThrowInternalError(env, "NULL filename for native library");
513 return NULL;
514 }
515 // Can't call initIDs because it will recurse into NativeLibrary via
516 // FindClass to check context so set prochandle here as well.
517 procHandle = getProcessHandle();
518 cname = JNU_GetStringPlatformChars(env, name, 0);
519 if (cname == NULL) {
520 return NULL;
521 }
522 // Copy name Skipping PREFIX
523 len = strlen(cname);
524 if (len <= (prefixLen+suffixLen)) {
525 JNU_ReleaseStringPlatformChars(env, name, cname);
526 return NULL;
527 }
528 libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
529 if (libName == NULL) {
530 JNU_ReleaseStringPlatformChars(env, name, cname);
531 JNU_ThrowOutOfMemoryError(env, NULL);
532 return NULL;
533 }
534 if (len > prefixLen) {
535 strcpy(libName, cname+prefixLen);
536 }
537 JNU_ReleaseStringPlatformChars(env, name, cname);
538
539 // Strip SUFFIX
|