androiddelphiandroid-manifestfiremonkeyheap-corruption

How to enable/disable ARM Top-byte Ignore (TBI) in Delphi 10.3 for Android?


I have an app written in Delphi 10.4.2 with FireMonkey for Android. Now, Google Play Store sometimes reports the following error:

Pointer tag for 0x<sanitized> was truncated, see 'https://source.android.com/devices/tech/debug/tagged-pointers'.

This page describes the error in detail:

Starting in Android 11, for 64-bit processes, all heap allocations have an implementation defined tag set in the top byte of the pointer on devices with kernel support for ARM Top-byte Ignore (TBI). Any application that modifies this tag is terminated when the tag is checked during deallocation. This is necessary for future hardware with ARM Memory Tagging Extension (MTE) support.

The first question is, of course, which module is responsible for that problem, and has to be changed. Because this may take a long period of time, there is an patch available to ease the transitional period.

The following line should be added to the manifest:

<application android:allowNativeHeapPointerTagging="false">
...
</application>

But, when I add this line and the app is deployed, there comes from Delphi the error message:

[PAClient Fehler] Fehler: E6408 D:\Loggy\Android64\Release\Loggy\AndroidManifest.xml:15: error: attribute android:allowNativeHeapPointerTagging not found.

and the deployment is aborted.

How can I activate this Android option? Is there any possibility to configure Delphi?

@Remy Lebeau: After posting, I saw a comment from a user saying that he had this problem too and after changing something in task management the heap violation went away. This comment has now been deleted. I haven't had enough time to memorize the details to see if this might help me.

The comment also makes reference to the core question of which module is responsible for the heap violation. Such errors are very difficult to find and every hint helps - also for other developers. Could you please turn the comment back on?


Solution

  • Delphi 10.4.2 sets targetSdkVersion as 29 in AndroidManifest.xml using AndroidManifest.template.xml if you did not change android:targetSdkVersion value in template file to a hardcoded SDK Version.

    allowNativeHeapPointerTagging is valid only if target SDK Version is >= 30 as specified in https://source.android.com/docs/security/test/tagged-pointers. If your target SDK Version remains 29, then you get the error you specified.

    You should manually instal SDK 30 or higher version to your development machine and define that SDK in SDK Manager of Delphi IDE using Tools - Deployment - SDK Manager menu item. In addition you should write your new SDK version to targetSdkVersion in the AndroidManifest.template.xml or your project, e.g. android:targetSdkVersion="30" .