Skip to content

Instantly share code, notes, and snippets.

@kirugan
Created December 6, 2019 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirugan/ec96df764332ae2e727b7026182d252e to your computer and use it in GitHub Desktop.
Save kirugan/ec96df764332ae2e727b7026182d252e to your computer and use it in GitHub Desktop.
Free bits in pointers (tested on amazon graviton processors)
#include <stdio.h>
#include <stdint.h>
int main() {
int x = 10;
int* y = &x;
printf("Hey! %p (size=%zu)\n", y, sizeof(y));
uint64_t mask = 0;
for (int j = 63; j > 55; j--) {
mask |= 1ull << j;
}
int* newPtr = (uint64_t)y ^ mask;
printf("Mask => %llu\n", mask);
printf("new ptr => %p (%d)\n", newPtr, *newPtr);
}
@kirugan
Copy link
Author

kirugan commented Dec 6, 2019

Well, it looks like Amazon's arm64 doesn't care about most significant byte in address i.e. you can fill it with your own information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment