#include #include #include /* for PAGESIZE */ #ifndef PAGESIZE #define PAGESIZE 4096 #endif int main(int ac,char** av) { __label__ FOO; uint8_t* code; uint8_t* p; register int a; register int b; int n,m; if (ac<2) { printf("supply a number between 0 and 5\n"); exit(1); } m = n = atoi(av[1]); if (m < 0 || m > 5) { printf("supply a number between 0 and 5\n"); exit(1); } printf("n: %d\n",n); code=&&FOO; p = (uint8_t*)&main - PAGESIZE; p = (char *)(((int) p + PAGESIZE-1) & ~(PAGESIZE-1)); if (mprotect(p, PAGESIZE*2, PROT_READ|PROT_WRITE|PROT_EXEC)) { perror("Couldn't mprotect"); exit(1); } code++; *((uint32_t*)code) = 63245986; // 39 code+=5; *((uint32_t*)code) = 102334155; // 40 code+=14; while (n--) { *(--code)=0x90; *(--code)=0x90; } FOO: a = 0; b = 0; a += b; // 41 b += a; // 42 a += b; // 43 b += a; // 44 a += b; // 45 b += a; // 46 printf("fib %d: %u\n", (46-m), b); return 0; }