Line data Source code
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 : #if defined(WEBRTC_LINUX) || defined(WEBRTC_BSD)
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 : #if defined(WEBRTC_LINUX) || defined(WEBRTC_BSD)
24 : const 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 0 : DllHandle InternalLoadDll(const char dll_name[]) {
36 : #if defined(WEBRTC_LINUX) || defined(WEBRTC_BSD)
37 0 : 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 0 : return handle;
46 : }
47 :
48 0 : void InternalUnloadDll(DllHandle handle) {
49 : #if defined(WEBRTC_LINUX) || defined(WEBRTC_BSD)
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 : #if !defined(ADDRESS_SANITIZER)
58 0 : if (dlclose(handle) != 0) {
59 : WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
60 : "%s", GetDllError());
61 : }
62 : #endif // !defined(ADDRESS_SANITIZER)
63 : #else
64 : #error Not implemented
65 : #endif
66 0 : }
67 :
68 0 : static bool LoadSymbol(DllHandle handle,
69 : const char *symbol_name,
70 : void **symbol) {
71 : #if defined(WEBRTC_LINUX) || defined(WEBRTC_BSD)
72 0 : *symbol = dlsym(handle, symbol_name);
73 0 : const char *err = dlerror();
74 0 : if (err) {
75 : WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
76 : "Error loading symbol %s : %d", symbol_name, err);
77 0 : return false;
78 0 : } else if (!*symbol) {
79 : WEBRTC_TRACE(kTraceError, kTraceAudioDevice, -1,
80 : "Symbol %s is NULL", symbol_name);
81 0 : return false;
82 : }
83 0 : return true;
84 : #else
85 : #error Not implemented
86 : #endif
87 : }
88 :
89 : // 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
91 : // caller may later interpret as a valid address.
92 0 : bool InternalLoadSymbols(DllHandle handle,
93 : int num_symbols,
94 : const char *const symbol_names[],
95 : void *symbols[]) {
96 : #if defined(WEBRTC_LINUX) || defined(WEBRTC_BSD)
97 : // Clear any old errors.
98 0 : dlerror();
99 : #endif
100 0 : for (int i = 0; i < num_symbols; ++i) {
101 0 : if (!LoadSymbol(handle, symbol_names[i], &symbols[i])) {
102 0 : return false;
103 : }
104 : }
105 0 : return true;
106 : }
107 :
108 : } // namespace webrtc_adm_linux
|