提交 e7b7c205 编写于 作者: A alanb

8028792: (ch) Channels native code needs to be checked for methods calling JNI...

8028792: (ch) Channels native code needs to be checked for methods calling JNI with pending excepitons
Summary: added null checks to JNI functoin call return values
Reviewed-by: chegar, coffeys
上级 237bb706
......@@ -43,7 +43,7 @@ class AixNativeDispatcher extends UnixNativeDispatcher {
static native UnixMountEntry[] getmntctl() throws UnixException;
// initialize
private static native int init();
private static native void init();
static {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
......
......@@ -56,23 +56,26 @@ static void throwUnixException(JNIEnv* env, int errnum) {
/**
* Initialization
*/
JNIEXPORT jint JNICALL
JNIEXPORT void JNICALL
Java_sun_nio_fs_AixNativeDispatcher_init(JNIEnv* env, jclass this)
{
jint flags = 0;
jclass clazz;
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL) {
return 0;
}
CHECK_NULL(clazz);
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
CHECK_NULL(entry_name);
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
CHECK_NULL(entry_dir);
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
CHECK_NULL(entry_fstype);
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
CHECK_NULL(entry_options);
entry_cls = (*env)->NewGlobalRef(env, clazz);
return 0;
if (entry_cls == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
}
/**
......
......@@ -283,6 +283,10 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
struct dirent64 *result;
int len, maxlen;
jobjectArray rv, old;
jclass str_class;
str_class = JNU_ClassString(env);
CHECK_NULL_RETURN(str_class, NULL);
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
dir = opendir(path);
......@@ -299,7 +303,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
/* Allocate an initial String array */
len = 0;
maxlen = 16;
rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL);
rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
if (rv == NULL) goto error;
/* Scan the directory */
......@@ -309,8 +313,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
continue;
if (len == maxlen) {
old = rv;
rv = (*env)->NewObjectArray(env, maxlen <<= 1,
JNU_ClassString(env), NULL);
rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
if (rv == NULL) goto error;
if (JNU_CopyObjectArray(env, rv, old, len) < 0) goto error;
(*env)->DeleteLocalRef(env, old);
......@@ -329,7 +332,7 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
/* Copy the final results into an appropriately-sized array */
old = rv;
rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL);
rv = (*env)->NewObjectArray(env, len, str_class, NULL);
if (rv == NULL) {
return NULL;
}
......
......@@ -56,18 +56,28 @@ JNIEXPORT void JNICALL
Java_sun_nio_ch_DatagramChannelImpl_initIDs(JNIEnv *env, jclass clazz)
{
clazz = (*env)->FindClass(env, "java/net/InetSocketAddress");
CHECK_NULL(clazz);
isa_class = (*env)->NewGlobalRef(env, clazz);
if (isa_class == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
isa_ctorID = (*env)->GetMethodID(env, clazz, "<init>",
"(Ljava/net/InetAddress;I)V");
CHECK_NULL(isa_ctorID);
clazz = (*env)->FindClass(env, "sun/nio/ch/DatagramChannelImpl");
CHECK_NULL(clazz);
dci_senderID = (*env)->GetFieldID(env, clazz, "sender",
"Ljava/net/SocketAddress;");
CHECK_NULL(dci_senderID);
dci_senderAddrID = (*env)->GetFieldID(env, clazz,
"cachedSenderInetAddress",
"Ljava/net/InetAddress;");
CHECK_NULL(dci_senderAddrID);
dci_senderPortID = (*env)->GetFieldID(env, clazz,
"cachedSenderPort", "I");
CHECK_NULL(dci_senderPortID);
}
JNIEXPORT void JNICALL
......@@ -192,17 +202,11 @@ Java_sun_nio_ch_DatagramChannelImpl_receive0(JNIEnv *env, jobject this,
if (senderAddr == NULL) {
jobject isa = NULL;
int port;
jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa,
&port);
jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
if (ia != NULL) {
isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
}
if (isa == NULL) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
return IOS_THROWN;
}
CHECK_NULL_RETURN(isa, IOS_THROWN);
(*env)->SetObjectField(env, this, dci_senderAddrID, ia);
(*env)->SetIntField(env, this, dci_senderPortID,
......
......@@ -43,8 +43,8 @@ static jfieldID key_st_ino; /* id for FileKey.st_ino */
JNIEXPORT void JNICALL
Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz)
{
key_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J");
key_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J");
CHECK_NULL(key_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J"));
CHECK_NULL(key_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J"));
}
......
......@@ -42,8 +42,8 @@ static jfieldID fd_fdID; /* for jint 'fd' in java.io.FileDescriptor */
JNIEXPORT void JNICALL
Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz)
{
clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor"));
CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"));
}
JNIEXPORT jboolean JNICALL
......
......@@ -57,12 +57,20 @@ Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass c)
jclass cls;
cls = (*env)->FindClass(env, "java/io/FileDescriptor");
CHECK_NULL(cls);
fd_fdID = (*env)->GetFieldID(env, cls, "fd", "I");
CHECK_NULL(fd_fdID);
cls = (*env)->FindClass(env, "java/net/InetSocketAddress");
CHECK_NULL(cls);
isa_class = (*env)->NewGlobalRef(env, cls);
if (isa_class == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
"(Ljava/net/InetAddress;I)V");
CHECK_NULL(isa_ctorID);
}
JNIEXPORT jint JNICALL
......@@ -79,6 +87,10 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
jint remote_port;
NET_AllocSockaddr(&sa, &alloc_len);
if (sa == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return IOS_THROWN;
}
/*
* accept connection but ignore ECONNABORTED indicating that
......@@ -110,8 +122,9 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
(*env)->SetIntField(env, newfdo, fd_fdID, newfd);
remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port);
free((void *)sa);
isa = (*env)->NewObject(env, isa_class, isa_ctorID,
remote_ia, remote_port);
CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
CHECK_NULL_RETURN(isa, IOS_THROWN);
(*env)->SetObjectArrayElement(env, isaa, 0, isa);
return 1;
}
......@@ -213,6 +213,7 @@ void handleSendFailed
/* retrieved address from sockaddr */
isaObj = SockAddrToInetSocketAddress(env, sap);
CHECK_NULL(isaObj);
/* data retrieved from sff_data */
if (dataLength > 0) {
......@@ -337,6 +338,7 @@ void handlePeerAddrChange
}
addressObj = SockAddrToInetSocketAddress(env, (struct sockaddr*)&spc->spc_aaddr);
CHECK_NULL(addressObj);
/* create PeerAddressChanged */
resultObj = (*env)->NewObject(env, spc_class, spc_ctrID, spc->spc_assoc_id,
......@@ -393,6 +395,7 @@ void handleMessage
}
isa = SockAddrToInetSocketAddress(env, sap);
CHECK_NULL(isa);
getControlData(msg, cdata);
/* create MessageInfoImpl */
......@@ -613,4 +616,3 @@ JNIEXPORT jint JNICALL Java_sun_nio_ch_sctp_SctpChannelImpl_checkConnect
return Java_sun_nio_ch_SocketChannelImpl_checkConnect(env, this,
fdo, block, ready);
}
......@@ -382,7 +382,8 @@ JNIEXPORT jobjectArray JNICALL Java_sun_nio_ch_sctp_SctpNet_getLocalAddresses0
ia = NET_SockaddrToInetAddress(env, sap, &port);
if (ia != NULL)
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
if (isa != NULL)
if (isa == NULL)
break;
(*env)->SetObjectArrayElement(env, isaa, i, isa);
if (sap->sa_family == AF_INET)
......@@ -433,7 +434,8 @@ jobjectArray getRemoteAddresses
ia = NET_SockaddrToInetAddress(env, sap, &port);
if (ia != NULL)
isa = (*env)->NewObject(env, isaCls, isaCtrID, ia, port);
if (isa != NULL)
if (isa == NULL)
break;
(*env)->SetObjectArrayElement(env, isaa, i, isa);
if (sap->sa_family == AF_INET)
......
......@@ -72,13 +72,15 @@ Java_sun_nio_fs_BsdNativeDispatcher_initIDs(JNIEnv* env, jclass this)
jclass clazz;
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
CHECK_NULL(entry_name);
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
CHECK_NULL(entry_dir);
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
CHECK_NULL(entry_fstype);
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
CHECK_NULL(entry_options);
}
JNIEXPORT jlong JNICALL
......@@ -201,4 +203,3 @@ Java_sun_nio_fs_BsdNativeDispatcher_endfsstat(JNIEnv* env, jclass this, jlong va
free(iter);
}
}
......@@ -68,13 +68,15 @@ Java_sun_nio_fs_LinuxNativeDispatcher_init(JNIEnv *env, jclass clazz)
my_flistxattr_func = (flistxattr_func*)dlsym(RTLD_DEFAULT, "flistxattr");
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL)
return;
CHECK_NULL(clazz);
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
CHECK_NULL(entry_name);
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
CHECK_NULL(entry_dir);
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
CHECK_NULL(entry_fstype);
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
CHECK_NULL(entry_options);
}
JNIEXPORT jint JNICALL
......
......@@ -55,14 +55,17 @@ static void throwUnixException(JNIEnv* env, int errnum) {
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL)
return;
CHECK_NULL(clazz);
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
CHECK_NULL(entry_name);
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
CHECK_NULL(entry_dir);
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
CHECK_NULL(entry_fstype);
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
CHECK_NULL(entry_options);
entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
CHECK_NULL(entry_dev);
}
JNIEXPORT jint JNICALL
......
......@@ -179,46 +179,64 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
jclass clazz;
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileAttributes");
if (clazz == NULL) {
return 0;
}
CHECK_NULL_RETURN(clazz, 0);
attrs_st_mode = (*env)->GetFieldID(env, clazz, "st_mode", "I");
CHECK_NULL_RETURN(attrs_st_mode, 0);
attrs_st_ino = (*env)->GetFieldID(env, clazz, "st_ino", "J");
CHECK_NULL_RETURN(attrs_st_ino, 0);
attrs_st_dev = (*env)->GetFieldID(env, clazz, "st_dev", "J");
CHECK_NULL_RETURN(attrs_st_dev, 0);
attrs_st_rdev = (*env)->GetFieldID(env, clazz, "st_rdev", "J");
CHECK_NULL_RETURN(attrs_st_rdev, 0);
attrs_st_nlink = (*env)->GetFieldID(env, clazz, "st_nlink", "I");
CHECK_NULL_RETURN(attrs_st_nlink, 0);
attrs_st_uid = (*env)->GetFieldID(env, clazz, "st_uid", "I");
CHECK_NULL_RETURN(attrs_st_uid, 0);
attrs_st_gid = (*env)->GetFieldID(env, clazz, "st_gid", "I");
CHECK_NULL_RETURN(attrs_st_gid, 0);
attrs_st_size = (*env)->GetFieldID(env, clazz, "st_size", "J");
CHECK_NULL_RETURN(attrs_st_size, 0);
attrs_st_atime_sec = (*env)->GetFieldID(env, clazz, "st_atime_sec", "J");
CHECK_NULL_RETURN(attrs_st_atime_sec, 0);
attrs_st_atime_nsec = (*env)->GetFieldID(env, clazz, "st_atime_nsec", "J");
CHECK_NULL_RETURN(attrs_st_atime_nsec, 0);
attrs_st_mtime_sec = (*env)->GetFieldID(env, clazz, "st_mtime_sec", "J");
CHECK_NULL_RETURN(attrs_st_mtime_sec, 0);
attrs_st_mtime_nsec = (*env)->GetFieldID(env, clazz, "st_mtime_nsec", "J");
CHECK_NULL_RETURN(attrs_st_mtime_nsec, 0);
attrs_st_ctime_sec = (*env)->GetFieldID(env, clazz, "st_ctime_sec", "J");
CHECK_NULL_RETURN(attrs_st_ctime_sec, 0);
attrs_st_ctime_nsec = (*env)->GetFieldID(env, clazz, "st_ctime_nsec", "J");
CHECK_NULL_RETURN(attrs_st_ctime_nsec, 0);
#ifdef _DARWIN_FEATURE_64_BIT_INODE
attrs_st_birthtime_sec = (*env)->GetFieldID(env, clazz, "st_birthtime_sec", "J");
CHECK_NULL_RETURN(attrs_st_birthtime_sec, 0);
#endif
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixFileStoreAttributes");
if (clazz == NULL) {
return 0;
}
CHECK_NULL_RETURN(clazz, 0);
attrs_f_frsize = (*env)->GetFieldID(env, clazz, "f_frsize", "J");
CHECK_NULL_RETURN(attrs_f_frsize, 0);
attrs_f_blocks = (*env)->GetFieldID(env, clazz, "f_blocks", "J");
CHECK_NULL_RETURN(attrs_f_blocks, 0);
attrs_f_bfree = (*env)->GetFieldID(env, clazz, "f_bfree", "J");
CHECK_NULL_RETURN(attrs_f_bfree, 0);
attrs_f_bavail = (*env)->GetFieldID(env, clazz, "f_bavail", "J");
CHECK_NULL_RETURN(attrs_f_bavail, 0);
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
if (clazz == NULL) {
return 0;
}
CHECK_NULL_RETURN(clazz, 0);
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
CHECK_NULL_RETURN(entry_name, 0);
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
CHECK_NULL_RETURN(entry_dir, 0);
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
CHECK_NULL_RETURN(entry_fstype, 0);
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
CHECK_NULL_RETURN(entry_options, 0);
entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
CHECK_NULL_RETURN(entry_dev, 0);
/* system calls that might not be available at run time */
......
......@@ -48,8 +48,8 @@ jfieldID IO_handle_fdID;
JNIEXPORT void JNICALL
Java_java_io_FileDescriptor_initIDs(JNIEnv *env, jclass fdClass) {
IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I");
IO_handle_fdID = (*env)->GetFieldID(env, fdClass, "handle", "J");
CHECK_NULL(IO_fd_fdID = (*env)->GetFieldID(env, fdClass, "fd", "I"));
CHECK_NULL(IO_handle_fdID = (*env)->GetFieldID(env, fdClass, "handle", "J"));
}
JNIEXPORT jlong JNICALL
......
......@@ -59,10 +59,12 @@ JNIEXPORT void JNICALL
Java_java_io_WinNTFileSystem_initIDs(JNIEnv *env, jclass cls)
{
HMODULE handle;
jclass fileClass = (*env)->FindClass(env, "java/io/File");
if (!fileClass) return;
ids.path =
(*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;");
jclass fileClass;
fileClass = (*env)->FindClass(env, "java/io/File");
CHECK_NULL(fileClass);
ids.path = (*env)->GetFieldID(env, fileClass, "path", "Ljava/lang/String;");
CHECK_NULL(ids.path);
// GetFinalPathNameByHandle requires Windows Vista or newer
if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
......@@ -247,7 +249,7 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
WCHAR canonicalPath[MAX_PATH_LENGTH];
WITH_UNICODE_STRING(env, pathname, path) {
/*we estimate the max length of memory needed as
/* we estimate the max length of memory needed as
"currentDir. length + pathname.length"
*/
int len = (int)wcslen(path);
......@@ -262,12 +264,11 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
} else
if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
} else if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath));
}
} END_UNICODE_STRING(env, path);
if (rv == NULL) {
if (rv == NULL && !(*env)->ExceptionCheck(env)) {
JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
}
return rv;
......@@ -296,15 +297,14 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this,
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
} else
if (wcanonicalizeWithPrefix(canonicalPrefix,
} else if (wcanonicalizeWithPrefix(canonicalPrefix,
pathWithCanonicalPrefix,
canonicalPath, MAX_PATH_LENGTH) >= 0) {
rv = (*env)->NewString(env, canonicalPath, (jsize)wcslen(canonicalPath));
}
} END_UNICODE_STRING(env, pathWithCanonicalPrefix);
} END_UNICODE_STRING(env, canonicalPrefix);
if (rv == NULL) {
if (rv == NULL && !(*env)->ExceptionCheck(env)) {
JNU_ThrowIOExceptionWithLastError(env, "Bad pathname");
}
return rv;
......@@ -624,8 +624,13 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
jobjectArray rv, old;
DWORD fattr;
jstring name;
jclass str_class;
WCHAR *pathbuf;
WCHAR *pathbuf = fileToNTPath(env, file, ids.path);
str_class = JNU_ClassString(env);
CHECK_NULL_RETURN(str_class, NULL);
pathbuf = fileToNTPath(env, file, ids.path);
if (pathbuf == NULL)
return NULL;
search_path = (WCHAR*)malloc(2*wcslen(pathbuf) + 6);
......@@ -673,7 +678,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
return NULL;
} else {
// No files found - return an empty array
rv = (*env)->NewObjectArray(env, 0, JNU_ClassString(env), NULL);
rv = (*env)->NewObjectArray(env, 0, str_class, NULL);
return rv;
}
}
......@@ -681,7 +686,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
/* Allocate an initial String array */
len = 0;
maxlen = 16;
rv = (*env)->NewObjectArray(env, maxlen, JNU_ClassString(env), NULL);
rv = (*env)->NewObjectArray(env, maxlen, str_class, NULL);
if (rv == NULL) // Couldn't allocate an array
return NULL;
/* Scan the directory */
......@@ -695,10 +700,8 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
return NULL; // error;
if (len == maxlen) {
old = rv;
rv = (*env)->NewObjectArray(env, maxlen <<= 1,
JNU_ClassString(env), NULL);
if ( rv == NULL
|| JNU_CopyObjectArray(env, rv, old, len) < 0)
rv = (*env)->NewObjectArray(env, maxlen <<= 1, str_class, NULL);
if (rv == NULL || JNU_CopyObjectArray(env, rv, old, len) < 0)
return NULL; // error
(*env)->DeleteLocalRef(env, old);
}
......@@ -713,7 +716,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
/* Copy the final results into an appropriately-sized array */
old = rv;
rv = (*env)->NewObjectArray(env, len, JNU_ClassString(env), NULL);
rv = (*env)->NewObjectArray(env, len, str_class, NULL);
if (rv == NULL)
return NULL; /* error */
if (JNU_CopyObjectArray(env, rv, old, len) < 0)
......
......@@ -45,18 +45,28 @@ JNIEXPORT void JNICALL
Java_sun_nio_ch_DatagramChannelImpl_initIDs(JNIEnv *env, jclass clazz)
{
clazz = (*env)->FindClass(env, "java/net/InetSocketAddress");
CHECK_NULL(clazz);
isa_class = (*env)->NewGlobalRef(env, clazz);
if (isa_class == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
isa_ctorID = (*env)->GetMethodID(env, clazz, "<init>",
"(Ljava/net/InetAddress;I)V");
CHECK_NULL(isa_ctorID);
clazz = (*env)->FindClass(env, "sun/nio/ch/DatagramChannelImpl");
CHECK_NULL(clazz);
dci_senderID = (*env)->GetFieldID(env, clazz, "sender",
"Ljava/net/SocketAddress;");
CHECK_NULL(dci_senderID);
dci_senderAddrID = (*env)->GetFieldID(env, clazz,
"cachedSenderInetAddress",
"Ljava/net/InetAddress;");
CHECK_NULL(dci_senderAddrID);
dci_senderPortID = (*env)->GetFieldID(env, clazz,
"cachedSenderPort", "I");
CHECK_NULL(dci_senderPortID);
}
/*
......@@ -185,17 +195,11 @@ Java_sun_nio_ch_DatagramChannelImpl_receive0(JNIEnv *env, jobject this,
if (senderAddr == NULL) {
jobject isa = NULL;
int port;
jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa,
&port);
jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
if (ia != NULL) {
isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
}
if (isa == NULL) {
JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
return IOS_THROWN;
}
CHECK_NULL_RETURN(isa, IOS_THROWN);
// update cachedSenderInetAddress/cachedSenderPort
(*env)->SetObjectField(env, this, dci_senderAddrID, ia);
......
......@@ -38,9 +38,9 @@ static jfieldID key_indexLow; /* id for FileKey.nFileIndexLow */
JNIEXPORT void JNICALL
Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz)
{
key_volumeSN = (*env)->GetFieldID(env, clazz, "dwVolumeSerialNumber", "J");
key_indexHigh = (*env)->GetFieldID(env, clazz, "nFileIndexHigh", "J");
key_indexLow = (*env)->GetFieldID(env, clazz, "nFileIndexLow", "J");
CHECK_NULL(key_volumeSN = (*env)->GetFieldID(env, clazz, "dwVolumeSerialNumber", "J"));
CHECK_NULL(key_indexHigh = (*env)->GetFieldID(env, clazz, "nFileIndexHigh", "J"));
CHECK_NULL(key_indexLow = (*env)->GetFieldID(env, clazz, "nFileIndexLow", "J"));
}
......
......@@ -52,9 +52,9 @@ Java_sun_security_provider_NativeSeedGenerator_nativeGenerateSeed
JNIEXPORT void JNICALL
Java_sun_nio_ch_IOUtil_initIDs(JNIEnv *env, jclass clazz)
{
clazz = (*env)->FindClass(env, "java/io/FileDescriptor");
fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I");
handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");
CHECK_NULL(clazz = (*env)->FindClass(env, "java/io/FileDescriptor"));
CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, clazz, "fd", "I"));
CHECK_NULL(handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J"));
}
/**************************************************************
......
......@@ -46,16 +46,15 @@ Java_sun_nio_ch_Iocp_initIDs(JNIEnv* env, jclass this)
jclass clazz;
clazz = (*env)->FindClass(env, "sun/nio/ch/Iocp$CompletionStatus");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
if (completionStatus_error == NULL) return;
CHECK_NULL(completionStatus_error);
completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
if (completionStatus_bytesTransferred == NULL) return;
CHECK_NULL(completionStatus_bytesTransferred);
completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "I");
if (completionStatus_completionKey == NULL) return;
CHECK_NULL(completionStatus_completionKey);
completionStatus_overlapped = (*env)->GetFieldID(env, clazz, "overlapped", "J");
CHECK_NULL(completionStatus_overlapped);
}
JNIEXPORT jint JNICALL
......
......@@ -56,12 +56,20 @@ JNIEXPORT void JNICALL
Java_sun_nio_ch_ServerSocketChannelImpl_initIDs(JNIEnv *env, jclass cls)
{
cls = (*env)->FindClass(env, "java/io/FileDescriptor");
CHECK_NULL(cls);
fd_fdID = (*env)->GetFieldID(env, cls, "fd", "I");
CHECK_NULL(fd_fdID);
cls = (*env)->FindClass(env, "java/net/InetSocketAddress");
CHECK_NULL(cls);
isa_class = (*env)->NewGlobalRef(env, cls);
if (isa_class == NULL) {
JNU_ThrowOutOfMemoryError(env, NULL);
return;
}
isa_ctorID = (*env)->GetMethodID(env, cls, "<init>",
"(Ljava/net/InetAddress;I)V");
CHECK_NULL(isa_ctorID);
}
JNIEXPORT void JNICALL
......@@ -99,10 +107,10 @@ Java_sun_nio_ch_ServerSocketChannelImpl_accept0(JNIEnv *env, jobject this,
(*env)->SetIntField(env, newfdo, fd_fdID, newfd);
remote_ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, (int *)&remote_port);
CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
isa = (*env)->NewObject(env, isa_class, isa_ctorID,
remote_ia, remote_port);
isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
CHECK_NULL_RETURN(isa, IOS_THROWN);
(*env)->SetObjectArrayElement(env, isaa, 0, isa);
return 1;
}
......@@ -42,8 +42,8 @@ static jfieldID ia_addrID; /* java.net.InetAddress.address */
JNIEXPORT void JNICALL
Java_sun_nio_ch_SocketChannelImpl_initIDs(JNIEnv *env, jclass cls)
{
cls = (*env)->FindClass(env, "java/net/InetAddress");
ia_addrID = (*env)->GetFieldID(env, cls, "address", "I");
CHECK_NULL(cls = (*env)->FindClass(env, "java/net/InetAddress"));
CHECK_NULL(ia_addrID = (*env)->GetFieldID(env, cls, "address", "I"));
}
jint
......
......@@ -111,65 +111,70 @@ Java_sun_nio_fs_WindowsNativeDispatcher_initIDs(JNIEnv* env, jclass this)
HMODULE h;
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstFile");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
findFirst_handle = (*env)->GetFieldID(env, clazz, "handle", "J");
CHECK_NULL(findFirst_handle);
findFirst_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
CHECK_NULL(findFirst_name);
findFirst_attributes = (*env)->GetFieldID(env, clazz, "attributes", "I");
CHECK_NULL(findFirst_attributes);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$FirstStream");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
findStream_handle = (*env)->GetFieldID(env, clazz, "handle", "J");
CHECK_NULL(findStream_handle);
findStream_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
CHECK_NULL(findStream_name);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$VolumeInformation");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
volumeInfo_fsName = (*env)->GetFieldID(env, clazz, "fileSystemName", "Ljava/lang/String;");
CHECK_NULL(volumeInfo_fsName);
volumeInfo_volName = (*env)->GetFieldID(env, clazz, "volumeName", "Ljava/lang/String;");
CHECK_NULL(volumeInfo_volName);
volumeInfo_volSN = (*env)->GetFieldID(env, clazz, "volumeSerialNumber", "I");
CHECK_NULL(volumeInfo_volSN);
volumeInfo_flags = (*env)->GetFieldID(env, clazz, "flags", "I");
CHECK_NULL(volumeInfo_flags);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$DiskFreeSpace");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
diskSpace_bytesAvailable = (*env)->GetFieldID(env, clazz, "freeBytesAvailable", "J");
CHECK_NULL(diskSpace_bytesAvailable);
diskSpace_totalBytes = (*env)->GetFieldID(env, clazz, "totalNumberOfBytes", "J");
CHECK_NULL(diskSpace_totalBytes);
diskSpace_totalFree = (*env)->GetFieldID(env, clazz, "totalNumberOfFreeBytes", "J");
CHECK_NULL(diskSpace_totalFree);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$Account");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
account_domain = (*env)->GetFieldID(env, clazz, "domain", "Ljava/lang/String;");
CHECK_NULL(account_domain);
account_name = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
CHECK_NULL(account_name);
account_use = (*env)->GetFieldID(env, clazz, "use", "I");
CHECK_NULL(account_use);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$AclInformation");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
aclInfo_aceCount = (*env)->GetFieldID(env, clazz, "aceCount", "I");
CHECK_NULL(aclInfo_aceCount);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$CompletionStatus");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
completionStatus_error = (*env)->GetFieldID(env, clazz, "error", "I");
CHECK_NULL(completionStatus_error);
completionStatus_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
CHECK_NULL(completionStatus_bytesTransferred);
completionStatus_completionKey = (*env)->GetFieldID(env, clazz, "completionKey", "J");
CHECK_NULL(completionStatus_completionKey);
clazz = (*env)->FindClass(env, "sun/nio/fs/WindowsNativeDispatcher$BackupResult");
if (clazz == NULL) {
return;
}
CHECK_NULL(clazz);
backupResult_bytesTransferred = (*env)->GetFieldID(env, clazz, "bytesTransferred", "I");
CHECK_NULL(backupResult_bytesTransferred);
backupResult_context = (*env)->GetFieldID(env, clazz, "context", "J");
CHECK_NULL(backupResult_context);
// get handle to kernel32
if (GetModuleHandleExW((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册