/* lowmem.c - how much of segment 0 (the kernel) can user mode read? */ #include #include #include #include static jmp_buf jb; static void h(int s){ longjmp(jb,1); } int main(void){ struct sigaction sa; unsigned long a, first_bad = 0, nread = 0; unsigned v; memset(&sa,0,sizeof sa); sa.sa_handler=h; sigaction(SIGSEGV,&sa,0); sigaction(SIGBUS,&sa,0); setvbuf(stdout,0,_IONBF,0); for (a = 0; a < 0x10000000UL; a += 4096) { if (setjmp(jb)==0) { v = *(volatile unsigned*)a; nread++; } else { if (!first_bad) first_bad = a; if (a > 0x100000UL && a > first_bad + 0x1000000UL) break; } } printf("readable pages in segment 0: %lu (%lu KB); first unreadable page 0x%08lx\n", nread, nread*4, first_bad); for (a = 0; a < 0x1400; a += 0x100) { if (setjmp(jb)==0) { v=*(volatile unsigned*)a; printf(" %08lx: %08x\n", a, v); } } return 0; }