Importance of the high order bits from Android memory allocations?

153 views Asked by At

We’re using Visual Studio to develop our Android app and have recently moved from Microsoft’s Cross Platform environment to Google’s new “Android Game Development Extension” (AGDE). This change moved us from NDK 21 to 22, and we’re now seeing a slight difference in the addresses we’re getting from the memory allocators. We’re not sure if it’s the NDK upgrade or something else related to our transition, but previously we’d get addresses that looked like this (in this case it was memalign):

0x0000 007b 0ae2 7000

Now we’re seeing addresses like this:

0xb400 007b abdc aa80

The two addresses look very similar except for the top 8 bits. As an experiment we masked off those bits fully expecting the application to crash. But it didn’t. It ran just fine. Removing 0xb4 didn’t seem to make a difference.

These upper bit are always 0xb4 and we’re wondering what they mean, if anything. They don’t seem to be vital to the address itself and we can’t find any documentation about the operating system’s logical address space or the significance of these bits. Any insight into their meaning or where to go for an answer would be greatly appreciated.

1

There are 1 answers

0
Pacdan On

We're building the arm64-v8a architecture and Michael pointed us to the answer:

https://source.android.com/devices/tech/debug/tagged-pointers

"MTE works by tagging the 56th-59th address bits of each memory allocation on the stack, heap, and globals. The hardware and instruction set automatically checks that the correct tag is used upon every memory access."

Thank you!