#include #include #include void *foo() { int ii; return (void *)ⅈ } uint check_page_width() { int min_pagewidth=12; size_t i=getpagesize(),j; for (j=0;i>>=1;j++); j=j (long) foo()) return -1; else return 1; } ulong check_stack_address() { void *v; unsigned long i,j,m; j=1; m = check_page_width(); j<<=m; j<<=16; i=(unsigned long)&v; if ((long)foo()>i) i-=j; j--; i+=j; i&=~j; return i-1; } ulong check_mem_top() { unsigned long i,j,k,l,m,n; for (i=2,k=1;i;k=i,i<<=1); l = check_stack_address(); n = check_stack_direction(); l=n==1 ? (l>=1,i|=j); if (j<(k>>3)) i=0; j=1; m = check_page_width(); j<<=m; j<<=4; j--; i+=j; i&=~j; return i; } ulong check_mem_range() { unsigned long j, mem_top=check_mem_top(); mem_top=0x80000000; for (j=1;j && !(j& mem_top);j<<=1); return j>>1; } int main() { fprintf(stdout,"page_width=%u\n", check_page_width()); fprintf(stdout,"stack_direction=%d\n", check_stack_direction()); fprintf(stdout,"stack_address=0x%lx\n", check_stack_address()); fprintf(stdout,"mem_top=0x%lx\n", check_mem_top()); fprintf(stdout,"mem_range=0x%lx\n", check_mem_range()); return 0; }