blob: 3d20fe43f8a12616c4460c22d8b2ff57cdf79354 [file] [log] [blame]
Yong WU355383f2014-07-24 21:32:15 +08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_NATIVE_BRIDGE_H_
18#define ART_RUNTIME_NATIVE_BRIDGE_H_
19
20#include "base/mutex.h"
21
Andreas Gampe855564b2014-07-25 02:32:19 -070022#include <string>
23
Yong WU355383f2014-07-24 21:32:15 +080024namespace art {
25
26struct NativeBridgeCallbacks;
27
28class NativeBridge {
29 public:
Andreas Gampe855564b2014-07-25 02:32:19 -070030 // Initialize the native bridge, if any. Should be called by Runtime::Init(). An empty string
31 // signals that we do not want to load a native bridge.
32 static void SetNativeBridgeLibraryString(std::string& native_bridge_library_string);
33
Yong WU355383f2014-07-24 21:32:15 +080034 // Load a shared library that is supported by the native-bridge.
35 static void* LoadLibrary(const char* libpath, int flag);
36 // Get a native-bridge trampoline for specified native method.
37 static void* GetTrampoline(void* handle, const char* name, const char* shorty, uint32_t len);
38 // True if native library is valid and is for an ABI that is supported by native-bridge.
Andreas Gampe855564b2014-07-25 02:32:19 -070039 static bool IsSupported(const char* libpath);
Yong WU355383f2014-07-24 21:32:15 +080040
41 private:
Andreas Gampe855564b2014-07-25 02:32:19 -070042 static bool Initialize();
43
44 // The library name we are supposed to load.
45 static std::string native_bridge_library_string_;
46
47 // Whether we have already initialized (or tried to).
48 static bool initialized_ GUARDED_BY(lock_);
Yong WU355383f2014-07-24 21:32:15 +080049 static Mutex lock_;
Andreas Gampe855564b2014-07-25 02:32:19 -070050
51 // Whether a native bridge is available (loaded and ready).
52 static bool available_;
53
Yong WU355383f2014-07-24 21:32:15 +080054 static NativeBridgeCallbacks* callbacks_;
55};
56
57}; // namespace art
58
59#endif // ART_RUNTIME_NATIVE_BRIDGE_H_