| 111 | |
| 112 | # ifdef ANDROID |
| 113 | static const std::string getCudaSupportLibName() |
| 114 | { |
| 115 | Dl_info dl_info; |
| 116 | if(0 != dladdr((void *)getCudaSupportLibName, &dl_info)) |
| 117 | { |
| 118 | LOGD("Library name: %s", dl_info.dli_fname); |
| 119 | LOGD("Library base address: %p", dl_info.dli_fbase); |
| 120 | |
| 121 | const char* libName=dl_info.dli_fname; |
| 122 | while( ((*libName)=='/') || ((*libName)=='.') ) |
| 123 | libName++; |
| 124 | |
| 125 | char lineBuf[2048]; |
| 126 | FILE* file = fopen("/proc/self/smaps", "rt"); |
| 127 | |
| 128 | if(file) |
| 129 | { |
| 130 | while (fgets(lineBuf, sizeof lineBuf, file) != NULL) |
| 131 | { |
| 132 | //verify that line ends with library name |
| 133 | int lineLength = strlen(lineBuf); |
| 134 | int libNameLength = strlen(libName); |
| 135 | |
| 136 | //trim end |
| 137 | for(int i = lineLength - 1; i >= 0 && isspace(lineBuf[i]); --i) |
| 138 | { |
| 139 | lineBuf[i] = 0; |
| 140 | --lineLength; |
| 141 | } |
| 142 | |
| 143 | if (0 != strncmp(lineBuf + lineLength - libNameLength, libName, libNameLength)) |
| 144 | { |
| 145 | //the line does not contain the library name |
| 146 | continue; |
| 147 | } |
| 148 | |
| 149 | //extract path from smaps line |
| 150 | char* pathBegin = strchr(lineBuf, '/'); |
| 151 | if (0 == pathBegin) |
| 152 | { |
| 153 | LOGE("Strange error: could not find path beginning in lin \"%s\"", lineBuf); |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | char* pathEnd = strrchr(pathBegin, '/'); |
| 158 | pathEnd[1] = 0; |
| 159 | |
| 160 | LOGD("Libraries folder found: %s", pathBegin); |
| 161 | |
| 162 | fclose(file); |
| 163 | return std::string(pathBegin) + DYNAMIC_CUDA_LIB_NAME; |
| 164 | } |
| 165 | fclose(file); |
| 166 | LOGE("Could not find library path"); |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | LOGE("Could not read /proc/self/smaps"); |
no test coverage detected