HADOOP-9759. Add support for NativeCodeLoader#getLibraryName on Windows. Contributed by Chuan Liu.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1506325 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a42e459b9e
commit
77fa04457c
|
@ -635,6 +635,9 @@ Release 2.1.0-beta - 2013-07-02
|
||||||
|
|
||||||
HADOOP-9738. TestDistCh fails. (jing9 via kihwal)
|
HADOOP-9738. TestDistCh fails. (jing9 via kihwal)
|
||||||
|
|
||||||
|
HADOOP-9759. Add support for NativeCodeLoader#getLibraryName on Windows.
|
||||||
|
(Chuan Liu via cnauroth)
|
||||||
|
|
||||||
BREAKDOWN OF HADOOP-8562 SUBTASKS AND RELATED JIRAS
|
BREAKDOWN OF HADOOP-8562 SUBTASKS AND RELATED JIRAS
|
||||||
|
|
||||||
HADOOP-8924. Hadoop Common creating package-info.java must not depend on
|
HADOOP-8924. Hadoop Common creating package-info.java must not depend on
|
||||||
|
|
|
@ -38,9 +38,41 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_util_NativeCodeLoader_buildSup
|
||||||
JNIEXPORT jstring JNICALL Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName
|
JNIEXPORT jstring JNICALL Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
|
#ifdef UNIX
|
||||||
Dl_info dl_info;
|
Dl_info dl_info;
|
||||||
int ret = dladdr(
|
int ret = dladdr(
|
||||||
Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName,
|
Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName,
|
||||||
&dl_info);
|
&dl_info);
|
||||||
return (*env)->NewStringUTF(env, ret==0 ? "Unavailable" : dl_info.dli_fname);
|
return (*env)->NewStringUTF(env, ret==0 ? "Unavailable" : dl_info.dli_fname);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
SIZE_T ret = 0;
|
||||||
|
DWORD size = MAX_PATH;
|
||||||
|
LPWSTR filename = NULL;
|
||||||
|
HMODULE mod = NULL;
|
||||||
|
DWORD err = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
MEMORY_BASIC_INFORMATION mbi;
|
||||||
|
ret = VirtualQuery(Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName,
|
||||||
|
&mbi, sizeof(mbi));
|
||||||
|
if (ret == 0) goto cleanup;
|
||||||
|
mod = mbi.AllocationBase;
|
||||||
|
|
||||||
|
do {
|
||||||
|
filename = (LPWSTR) realloc(filename, size * sizeof(WCHAR));
|
||||||
|
if (filename == NULL) goto cleanup;
|
||||||
|
GetModuleFileName(mod, filename, size);
|
||||||
|
size <<= 1;
|
||||||
|
err = GetLastError();
|
||||||
|
} while (err == ERROR_INSUFFICIENT_BUFFER);
|
||||||
|
|
||||||
|
if (err != ERROR_SUCCESS) goto cleanup;
|
||||||
|
|
||||||
|
return (*env)->NewString(env, filename, (jsize) wcslen(filename));
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (filename != NULL) free(filename);
|
||||||
|
return (*env)->NewStringUTF(env, "Unavailable");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue