Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for Java 8 static linking. (#50)
* Adding support for Java 8 static linking. I'm not really sure of an easy way to test this ATM, since the library would have to be statically linked with the JVM. I think for now, we should just get this in and cross the testing bridge when we get there. Fixes #33
- Loading branch information
Nathan Mittler
committed
Jan 23, 2017
1 parent
f3a26b6
commit 160e730
Showing
10 changed files
with
219 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2017 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <jni.h> | ||
|
||
#include "CompatibilityCloseMonitor.h" | ||
#include "JniConstants.h" | ||
#include "NativeCrypto.h" | ||
#include "macros.h" | ||
|
||
#ifndef CONSCRYPT_JNI_VERSION | ||
#define CONSCRYPT_JNI_VERSION JNI_VERSION_1_6 | ||
#endif // !CONSCRYPT_JNI_VERSION | ||
|
||
using namespace conscrypt; | ||
|
||
// Give client libs everything they need to initialize our JNI | ||
jint libconscrypt_JNI_OnLoad(JavaVM* vm, void*) { | ||
JNIEnv* env; | ||
if (vm->GetEnv((void**)&env, CONSCRYPT_JNI_VERSION) != JNI_OK) { | ||
ALOGE("Could not get JNIEnv"); | ||
return JNI_ERR; | ||
} | ||
|
||
// Initialize the JNI constants. | ||
JniConstants::init(vm, env); | ||
|
||
// Register all of the native JNI methods. | ||
NativeCrypto::registerNativeMethods(env); | ||
|
||
// Perform static initialization of the close monitor (if required on this platform). | ||
CompatibilityCloseMonitor::init(); | ||
return CONSCRYPT_JNI_VERSION; | ||
} | ||
|
||
#ifdef STATIC_LIB | ||
|
||
// A version of OnLoad called when the Conscrypt library has been statically linked to the JVM (For | ||
// Java >= 1.8). The manner in which the library is statically linked is implementation specific. | ||
// | ||
// See http://openjdk.java.net/jeps/178 | ||
CONSCRYPT_PUBLIC jint JNI_OnLoad_conscrypt(JavaVM* vm, void* reserved) { | ||
return libconscrypt_JNI_OnLoad(vm, reserved); | ||
} | ||
|
||
#else // !STATIC_LIB | ||
|
||
// Method called by the JVM when the Conscrypt shared library is loaded. | ||
CONSCRYPT_PUBLIC jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { | ||
return libconscrypt_JNI_OnLoad(vm, reserved); | ||
} | ||
|
||
#endif // !STATIC_LIB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2017 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef CONSCRYPT_NATIVECRYPTO_H_ | ||
#define CONSCRYPT_NATIVECRYPTO_H_ | ||
|
||
#include <jni.h> | ||
|
||
namespace conscrypt { | ||
|
||
/** | ||
* Provides registration support for all native methods exported by Conscrypt. | ||
*/ | ||
class NativeCrypto { | ||
private: | ||
NativeCrypto() {} | ||
~NativeCrypto() {} | ||
|
||
public: | ||
/** | ||
* Register all native JNI methods exported by Conscrypt. | ||
*/ | ||
static void registerNativeMethods(JNIEnv* env); | ||
}; | ||
|
||
} // namespace conscrypt | ||
|
||
#endif // CONSCRYPT_NATIVECRYPTO_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.