| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/audio_device/linux/latebindingsymboltable_linux.h" | 11 #include "webrtc/modules/audio_device/linux/latebindingsymboltable_linux.h" |
| 12 | 12 |
| 13 #include "webrtc/system_wrappers/include/trace.h" | 13 #include "webrtc/rtc_base/logging.h" |
| 14 | 14 |
| 15 #ifdef WEBRTC_LINUX | 15 #ifdef WEBRTC_LINUX |
| 16 #include <dlfcn.h> | 16 #include <dlfcn.h> |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 namespace adm_linux { | 20 namespace adm_linux { |
| 21 | 21 |
| 22 inline static const char *GetDllError() { | 22 inline static const char *GetDllError() { |
| 23 #ifdef WEBRTC_LINUX | 23 #ifdef WEBRTC_LINUX |
| 24 char *err = dlerror(); | 24 char *err = dlerror(); |
| 25 if (err) { | 25 if (err) { |
| 26 return err; | 26 return err; |
| 27 } else { | 27 } else { |
| 28 return "No error"; | 28 return "No error"; |
| 29 } | 29 } |
| 30 #else | 30 #else |
| 31 #error Not implemented | 31 #error Not implemented |
| 32 #endif | 32 #endif |
| 33 } | 33 } |
| 34 | 34 |
| 35 DllHandle InternalLoadDll(const char dll_name[]) { | 35 DllHandle InternalLoadDll(const char dll_name[]) { |
| 36 #ifdef WEBRTC_LINUX | 36 #ifdef WEBRTC_LINUX |
| 37 DllHandle handle = dlopen(dll_name, RTLD_NOW); | 37 DllHandle handle = dlopen(dll_name, RTLD_NOW); |
| 38 #else | 38 #else |
| 39 #error Not implemented | 39 #error Not implemented |
| 40 #endif | 40 #endif |
| 41 if (handle == kInvalidDllHandle) { | 41 if (handle == kInvalidDllHandle) { |
| 42 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, -1, | 42 LOG(LS_WARNING) << "Can't load " << dll_name << " : " << GetDllError(); |
| 43 "Can't load %s : %s", dll_name, GetDllError()); | |
| 44 } | 43 } |
| 45 return handle; | 44 return handle; |
| 46 } | 45 } |
| 47 | 46 |
| 48 void InternalUnloadDll(DllHandle handle) { | 47 void InternalUnloadDll(DllHandle handle) { |
| 49 #ifdef WEBRTC_LINUX | 48 #ifdef WEBRTC_LINUX |
| 50 // TODO(pbos): Remove this dlclose() exclusion when leaks and suppressions from | 49 // TODO(pbos): Remove this dlclose() exclusion when leaks and suppressions from |
| 51 // here are gone (or AddressSanitizer can display them properly). | 50 // here are gone (or AddressSanitizer can display them properly). |
| 52 // | 51 // |
| 53 // Skip dlclose() on AddressSanitizer as leaks including this module in the | 52 // Skip dlclose() on AddressSanitizer as leaks including this module in the |
| 54 // stack trace gets displayed as <unknown module> instead of the actual library | 53 // stack trace gets displayed as <unknown module> instead of the actual library |
| 55 // -> it can not be suppressed. | 54 // -> it can not be suppressed. |
| 56 // https://code.google.com/p/address-sanitizer/issues/detail?id=89 | 55 // https://code.google.com/p/address-sanitizer/issues/detail?id=89 |
| 57 #if !defined(ADDRESS_SANITIZER) | 56 #if !defined(ADDRESS_SANITIZER) |
| 58 if (dlclose(handle) != 0) { | 57 if (dlclose(handle) != 0) { |
| 59 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1, | 58 LOG(LS_ERROR) << GetDllError(); |
| 60 "%s", GetDllError()); | |
| 61 } | 59 } |
| 62 #endif // !defined(ADDRESS_SANITIZER) | 60 #endif // !defined(ADDRESS_SANITIZER) |
| 63 #else | 61 #else |
| 64 #error Not implemented | 62 #error Not implemented |
| 65 #endif | 63 #endif |
| 66 } | 64 } |
| 67 | 65 |
| 68 static bool LoadSymbol(DllHandle handle, | 66 static bool LoadSymbol(DllHandle handle, |
| 69 const char *symbol_name, | 67 const char *symbol_name, |
| 70 void **symbol) { | 68 void **symbol) { |
| 71 #ifdef WEBRTC_LINUX | 69 #ifdef WEBRTC_LINUX |
| 72 *symbol = dlsym(handle, symbol_name); | 70 *symbol = dlsym(handle, symbol_name); |
| 73 char *err = dlerror(); | 71 char *err = dlerror(); |
| 74 if (err) { | 72 if (err) { |
| 75 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1, | 73 LOG(LS_ERROR) << "Error loading symbol " << symbol_name << " : " << err; |
| 76 "Error loading symbol %s : %d", symbol_name, err); | |
| 77 return false; | 74 return false; |
| 78 } else if (!*symbol) { | 75 } else if (!*symbol) { |
| 79 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1, | 76 LOG(LS_ERROR) << "Symbol " << symbol_name << " is NULL"; |
| 80 "Symbol %s is NULL", symbol_name); | |
| 81 return false; | 77 return false; |
| 82 } | 78 } |
| 83 return true; | 79 return true; |
| 84 #else | 80 #else |
| 85 #error Not implemented | 81 #error Not implemented |
| 86 #endif | 82 #endif |
| 87 } | 83 } |
| 88 | 84 |
| 89 // This routine MUST assign SOME value for every symbol, even if that value is | 85 // This routine MUST assign SOME value for every symbol, even if that value is |
| 90 // NULL, or else some symbols may be left with uninitialized data that the | 86 // NULL, or else some symbols may be left with uninitialized data that the |
| 91 // caller may later interpret as a valid address. | 87 // caller may later interpret as a valid address. |
| 92 bool InternalLoadSymbols(DllHandle handle, | 88 bool InternalLoadSymbols(DllHandle handle, |
| 93 int num_symbols, | 89 int num_symbols, |
| 94 const char *const symbol_names[], | 90 const char *const symbol_names[], |
| 95 void *symbols[]) { | 91 void *symbols[]) { |
| 96 #ifdef WEBRTC_LINUX | 92 #ifdef WEBRTC_LINUX |
| 97 // Clear any old errors. | 93 // Clear any old errors. |
| 98 dlerror(); | 94 dlerror(); |
| 99 #endif | 95 #endif |
| 100 for (int i = 0; i < num_symbols; ++i) { | 96 for (int i = 0; i < num_symbols; ++i) { |
| 101 if (!LoadSymbol(handle, symbol_names[i], &symbols[i])) { | 97 if (!LoadSymbol(handle, symbol_names[i], &symbols[i])) { |
| 102 return false; | 98 return false; |
| 103 } | 99 } |
| 104 } | 100 } |
| 105 return true; | 101 return true; |
| 106 } | 102 } |
| 107 | 103 |
| 108 } // namespace adm_linux | 104 } // namespace adm_linux |
| 109 } // namespace webrtc | 105 } // namespace webrtc |
| OLD | NEW |