Created
December 6, 2019 20:45
-
-
Save kirugan/ec96df764332ae2e727b7026182d252e to your computer and use it in GitHub Desktop.
Free bits in pointers (tested on amazon graviton processors)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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