Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: third_party/crazy_linker/crazy_linker/src/crazy_linker_library_view.h

Issue 23717023: Android: Add chrome-specific dynamic linker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error (previous patch was a mistake). Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #ifndef CRAZY_LINKER_LIBRARY_VIEW_H
6 #define CRAZY_LINKER_LIBRARY_VIEW_H
7
8 #include "crazy_linker_error.h"
9 #include "crazy_linker_util.h"
10
11 namespace crazy {
12
13 class SharedLibrary;
14
15 // A LibraryView is a reference-counted handle to either a
16 // crazy::SharedLibrary object or a library handle returned by the system's
17 // dlopen() function.
18 //
19 // It has a name, which is always a base name, because only one
20 // library with a given base name can be loaded in the system.
21 class LibraryView {
22 public:
23 enum {
24 TYPE_NONE = 0xbaadbaad,
25 TYPE_SYSTEM = 0x2387cef,
26 TYPE_CRAZY = 0xcdef2387,
27 };
28
29 LibraryView()
30 : type_(TYPE_NONE),
31 crazy_(NULL),
32 system_(NULL),
33 name_(),
34 ref_count_(1) {}
35
36 ~LibraryView();
37
38 bool IsSystem() const { return type_ == TYPE_SYSTEM; }
39
40 bool IsCrazy() const { return type_ == TYPE_CRAZY; }
41
42 void SetSystem(void* system_lib, const char* name) {
43 type_ = TYPE_SYSTEM;
44 system_ = system_lib;
45 name_ = name;
46 }
47
48 void SetCrazy(SharedLibrary* crazy_lib, const char* name) {
49 type_ = TYPE_CRAZY;
50 crazy_ = crazy_lib;
51 name_ = name;
52 }
53
54 const char* GetName() {
55 return name_.c_str();
56 }
57
58 SharedLibrary* GetCrazy() {
59 return IsCrazy() ? crazy_ : NULL;
60 }
61
62 void* GetSystem() {
63 return IsSystem() ? system_ : NULL;
64 }
65
66 void AddRef() {
67 ref_count_++;
68 }
69
70 // Decrement reference count. Returns true iff it reaches 0.
71 // This never destroys the object.
72 bool SafeDecrementRef() {
73 return (--ref_count_ == 0);
74 }
75
76 // Lookup a symbol from this library.
77 // If this is a crazy library, perform a breadth-first search,
78 // for system libraries, use dlsym() instead.
79 void* LookupSymbol(const char* symbol_name);
80
81 // Retrieve library information.
82 bool GetInfo(size_t* load_address,
83 size_t* load_size,
84 size_t* relro_start,
85 size_t* relro_size,
86 int* relro_fd,
87 Error* error);
88
89 // Enable RELRO section sharing. On This moves the RELRO section into
90 // a shareable ashmem region. On success, return true and sets
91 // |*load_address| to the library load address, |*load_size| to its
92 // full load size, |*relro_start| to the start of the RELRO section
93 // in memory, |*relro_size| to its size, and |*relro_fd| to the ashmem
94 // region's file descriptor.
95 // On failure, return false and sets |error| message.
96 bool EnableSharedRelro(Error* error);
97
98 // Use a shared RELRO section from another process. |relro_start|
99 // and |relro_size| are the start and size of the RELRO section,
100 // and |relro_fd| is a file descriptor for the ashmem region.
101 // On success, return true. On failure, return false and sets
102 // |error| message.
103 // NOTE: This function doesn't do anything except return CRAZY_STATUS_OK
104 // if |relro_fd| is negative, or |relro_size| is 0. This shall correspond
105 // to the case where there is no RELRO section in a library.
106 bool UseSharedRelro(size_t relro_start,
107 size_t relro_size,
108 int relro_fd,
109 Error* error);
110
111 // Only used for debugging.
112 int ref_count() const { return ref_count_; }
113
114 private:
115 uint32_t type_;
116 SharedLibrary* crazy_;
117 void* system_;
118 String name_;
119 int ref_count_;
120 };
121
122 } // namespace crazy
123
124 #endif // CRAZY_LINKER_LIBRARY_VIEW_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698