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

Side by Side Diff: base/android/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: Rename library 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 SafeDeref() {
73 return (--ref_count_ == 0);
74 }
75
76 // Decrement reference count. If it reaches zero, destroy the object.
77 void Deref() {
78 if (SafeDeref())
79 delete this;
80 }
81
82 // Lookup a symbol from this library.
83 // If this is a crazy library, perform a breadth-first search,
84 // for system libraries, use dlsym() instead.
85 void* LookupSymbol(const char* symbol_name);
86
87 // Retrieve library information.
88 bool GetInfo(size_t* load_address,
89 size_t* load_size,
90 size_t* relro_start,
91 size_t* relro_size,
92 int* relro_fd,
93 Error* error);
94
95 // Enable RELRO section sharing. On This moves the RELRO section into
96 // a shareable ashmem region. On success, return true and sets
97 // |*load_address| to the library load address, |*load_size| to its
98 // full load size, |*relro_start| to the start of the RELRO section
99 // in memory, |*relro_size| to its size, and |*relro_fd| to the ashmem
100 // region's file descriptor.
101 // On failure, return false and sets |error| message.
102 bool EnableSharedRelro(Error* error);
103
104 // Use a shared RELRO section from another process. |relro_start|
105 // and |relro_size| are the start and size of the RELRO section,
106 // and |relro_fd| is a file descriptor for the ashmem region.
107 // On success, return true. On failure, return false and sets
108 // |error| message.
109 // NOTE: This function doesn't do anything except return CRAZY_STATUS_OK
110 // if |relro_fd| is negative, or |relro_size| is 0. This shall correspond
111 // to the case where there is no RELRO section in a library.
112 bool UseSharedRelro(size_t relro_start,
113 size_t relro_size,
114 int relro_fd,
115 Error* error);
116
117 private:
118 uint32_t type_;
119 SharedLibrary* crazy_;
120 void* system_;
121 String name_;
122 int ref_count_;
123 };
124
125 } // namespace crazy
126
127 #endif // CRAZY_LINKER_LIBRARY_VIEW_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698