// print the stack mapping top (where env/argv strings are placed) under ADDR_NO_RANDOMIZE
#include <stdio.h>
#include <string.h>
#include <sys/personality.h>
#include <unistd.h>
#include <stdlib.h>
int main(){
  personality(0x00040000); // ADDR_NO_RANDOMIZE
  // read /proc/self/maps, find the stack mapping (the last rw-p region usually)
  FILE *f = fopen("/proc/self/maps","r");
  char line[512]; unsigned long hi=0,lo=0; int isstack=0;
  while (fgets(line,sizeof(line),f)){
    if (strstr(line,"rw-p") && strstr(line,"[stack]")){
      unsigned long a,b; sscanf(line,"%lx-%lx",&a,&b);
      printf("stack region: %p - %p (top=0x%lx)\n",(void*)a,(void*)b,b);
    }
  }
  fclose(f);
  return 0;
}
