[M94 Dev][Tizen] Fix for errors for generating ninja files
[platform/framework/web/chromium-efl.git] / base / native_library_posix.cc
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/native_library.h"
6
7 #include <dlfcn.h>
8
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/strings/strcat.h"
12 #include "base/strings/string_piece.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/scoped_blocking_call.h"
16
17 namespace base {
18
19 std::string NativeLibraryLoadError::ToString() const {
20   return message;
21 }
22
23 NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
24                                            const NativeLibraryOptions& options,
25                                            NativeLibraryLoadError* error) {
26   // dlopen() opens the file off disk.
27   ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
28
29   // We deliberately do not use RTLD_DEEPBIND by default.  For the history why,
30   // please refer to the bug tracker.  Some useful bug reports to read include:
31   // http://crbug.com/17943, http://crbug.com/17557, http://crbug.com/36892,
32   // and http://crbug.com/40794.
33   int flags = RTLD_LAZY;
34 #if defined(OS_ANDROID) || !defined(RTLD_DEEPBIND)
35   // Certain platforms don't define RTLD_DEEPBIND. Android dlopen() requires
36   // further investigation, as it might vary across versions. Crash here to
37   // warn developers that they're trying to rely on uncertain behavior.
38   CHECK(!options.prefer_own_symbols);
39 #else
40   if (options.prefer_own_symbols)
41     flags |= RTLD_DEEPBIND;
42 #endif
43   void* dl = dlopen(library_path.value().c_str(), flags);
44   if (!dl && error)
45     error->message = dlerror();
46
47   return dl;
48 }
49
50 void UnloadNativeLibrary(NativeLibrary library) {
51   int ret = dlclose(library);
52   if (ret < 0) {
53     DLOG(ERROR) << "dlclose failed: " << dlerror();
54     NOTREACHED();
55   }
56 }
57
58 void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
59                                           StringPiece name) {
60   return dlsym(library, name.data());
61 }
62
63 std::string GetNativeLibraryName(StringPiece name) {
64   DCHECK(IsStringASCII(name));
65   return StrCat({"lib", name, ".so"});
66 }
67
68 std::string GetLoadableModuleName(StringPiece name) {
69   return GetNativeLibraryName(name);
70 }
71
72 }  // namespace base