Skip to content

Commit

Permalink
Add example for wrap.sh based HWASan
Browse files Browse the repository at this point in the history
  • Loading branch information
fmayer committed Jan 10, 2024
1 parent f50ef3c commit 3d43054
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
13 changes: 13 additions & 0 deletions sanitizers/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
// HWASan for devices starting from Android 14. Does no longer require a special system image.
// See https://developer.android.com/ndk/guides/hwasan.
hwasan {
initWith debug
debuggable true
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared", "-DSANITIZE=hwasan"
Expand Down Expand Up @@ -86,6 +94,11 @@ android {
buildFeatures {
viewBinding true
}
androidComponents {
beforeVariants(selector().withBuildType("hwasan")) { variantBuilder ->
variantBuilder.minSdk = 34
}
}
}

dependencies {
Expand Down
2 changes: 2 additions & 0 deletions sanitizers/app/src/hwasan/resources/lib/arm64-v8a/wrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/system/bin/sh
LD_HWASAN=1 exec "$@"
2 changes: 1 addition & 1 deletion sanitizers/app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Java_com_example_sanitizers_MainActivity_stringFromJNI(JNIEnv* env,

std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
}
6 changes: 3 additions & 3 deletions sanitizers/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'com.android.application' version '8.2.1' apply false
id 'com.android.library' version '8.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
}
2 changes: 1 addition & 1 deletion sanitizers/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jan 17 09:59:11 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 3d43054

Please sign in to comment.