diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c9ffd098c5c..e35957bbcbf 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -635,6 +635,9 @@ Release 2.1.0-beta - 2013-07-02 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 HADOOP-8924. Hadoop Common creating package-info.java must not depend on diff --git a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c index 88d9240c99f..146e1600914 100644 --- a/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c +++ b/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c @@ -38,9 +38,41 @@ JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_util_NativeCodeLoader_buildSup JNIEXPORT jstring JNICALL Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName (JNIEnv *env, jclass clazz) { +#ifdef UNIX Dl_info dl_info; int ret = dladdr( Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName, &dl_info); 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 }