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