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

Unified 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: Remove findbugs issues. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/crazy_linker/crazy_linker/src/crazy_linker_library_view.h
diff --git a/third_party/crazy_linker/crazy_linker/src/crazy_linker_library_view.h b/third_party/crazy_linker/crazy_linker/src/crazy_linker_library_view.h
new file mode 100644
index 0000000000000000000000000000000000000000..a65477991f79409891c3c4fd56fff76adb47732f
--- /dev/null
+++ b/third_party/crazy_linker/crazy_linker/src/crazy_linker_library_view.h
@@ -0,0 +1,130 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CRAZY_LINKER_LIBRARY_VIEW_H
+#define CRAZY_LINKER_LIBRARY_VIEW_H
+
+#include "crazy_linker_error.h"
+#include "crazy_linker_util.h"
+
+namespace crazy {
+
+class SharedLibrary;
+
+// A LibraryView is a reference-counted handle to either a
+// crazy::SharedLibrary object or a library handle returned by the system's
+// dlopen() function.
+//
+// It has a name, which is always a base name, because only one
+// library with a given base name can be loaded in the system.
+class LibraryView {
+public:
+ enum {
+ TYPE_NONE = 0xbaadbaad,
+ TYPE_SYSTEM = 0x2387cef,
+ TYPE_CRAZY = 0xcdef2387,
+ };
+
+ LibraryView()
+ : type_(TYPE_NONE),
+ crazy_(NULL),
+ system_(NULL),
+ name_(),
+ ref_count_(1) {}
+
+ ~LibraryView();
+
+ bool IsSystem() const { return type_ == TYPE_SYSTEM; }
+
+ bool IsCrazy() const { return type_ == TYPE_CRAZY; }
+
+ void SetSystem(void* system_lib, const char* name) {
+ type_ = TYPE_SYSTEM;
+ system_ = system_lib;
+ name_ = name;
+ }
+
+ void SetCrazy(SharedLibrary* crazy_lib, const char* name) {
+ type_ = TYPE_CRAZY;
+ crazy_ = crazy_lib;
+ name_ = name;
+ }
+
+ const char* GetName() {
+ return name_.c_str();
+ }
+
+ SharedLibrary* GetCrazy() {
+ return IsCrazy() ? crazy_ : NULL;
+ }
+
+ void* GetSystem() {
+ return IsSystem() ? system_ : NULL;
+ }
+
+ void AddRef() {
+ ref_count_++;
+ }
+
+ // Decrement reference count. Returns true iff it reaches 0.
+ // This never destroys the object.
+ bool SafeDeref() {
bulach 2013/09/09 16:14:15 nit: how about DecrementRef for this one, and "Rel
digit1 2013/09/10 09:23:30 I've remove Deref(), which isn't used anymore, and
+ return (--ref_count_ == 0);
+ }
+
+ // Decrement reference count. If it reaches zero, destroy the object.
+ void Deref() {
+ if (SafeDeref())
+ delete this;
+ }
+
+ // Lookup a symbol from this library.
+ // If this is a crazy library, perform a breadth-first search,
+ // for system libraries, use dlsym() instead.
+ void* LookupSymbol(const char* symbol_name);
+
+ // Retrieve library information.
+ bool GetInfo(size_t* load_address,
+ size_t* load_size,
+ size_t* relro_start,
+ size_t* relro_size,
+ int* relro_fd,
+ Error* error);
+
+ // Enable RELRO section sharing. On This moves the RELRO section into
+ // a shareable ashmem region. On success, return true and sets
+ // |*load_address| to the library load address, |*load_size| to its
+ // full load size, |*relro_start| to the start of the RELRO section
+ // in memory, |*relro_size| to its size, and |*relro_fd| to the ashmem
+ // region's file descriptor.
+ // On failure, return false and sets |error| message.
+ bool EnableSharedRelro(Error* error);
+
+ // Use a shared RELRO section from another process. |relro_start|
+ // and |relro_size| are the start and size of the RELRO section,
+ // and |relro_fd| is a file descriptor for the ashmem region.
+ // On success, return true. On failure, return false and sets
+ // |error| message.
+ // NOTE: This function doesn't do anything except return CRAZY_STATUS_OK
+ // if |relro_fd| is negative, or |relro_size| is 0. This shall correspond
+ // to the case where there is no RELRO section in a library.
+ bool UseSharedRelro(size_t relro_start,
+ size_t relro_size,
+ int relro_fd,
+ Error* error);
+
+ // Only used for debugging.
+ int ref_count() const { return ref_count_; }
+
+private:
+ uint32_t type_;
+ SharedLibrary* crazy_;
+ void* system_;
+ String name_;
+ int ref_count_;
+};
+
+} // namespace crazy
+
+#endif // CRAZY_LINKER_LIBRARY_VIEW_H

Powered by Google App Engine
This is Rietveld 408576698