Skip to content

Instantly share code, notes, and snippets.

@JacobTDC
Created May 9, 2022 02:53
Show Gist options
  • Save JacobTDC/ef973ea4d6b93a4b0063e435936b30d6 to your computer and use it in GitHub Desktop.
Save JacobTDC/ef973ea4d6b93a4b0063e435936b30d6 to your computer and use it in GitHub Desktop.
Fix for openjdk to disable tagged pointers in Termux on Android 12+
// C code to disable tagged pointers in Termux.
// Compile and add the path to LD_PRELOAD.
// See https://github.com/termux/termux-packages/issues/7332#issuecomment-1078588433
// for more info.
#include <android/log.h>
void __attribute__((constructor)) disable_tagged_pointer_hook() {
#ifndef __ANDROID_SDK__
__android_log_print(ANDROID_LOG_INFO, "DEBUG", "undefined __ANDROID_SDK__");
#elif __ANDROID_SDK__ >= 31 // ANDROID 12
extern int mallopt(int param, int value);
mallopt(-204, 0);
#elif __ANDROID_SDK__ >= 30 // ANDROID 11
int tmp = 0;
extern int android_mallopt(int opcode, void *arg, size_t arg_size);
android_mallopt(8, &tmp, sizeof(tmp));
#else
__android_log_print(ANDROID_LOG_INFO, "DEBUG", "__ANDROID_SDK__: %i", __ANDROID_SDK__);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment