Read random memory until something is nonzero.
authorMatt Mullins <mmullins@mmlx.us>
Sat, 21 Sep 2013 17:24:01 +0000 (17:24 +0000)
committerMatt Mullins <mmullins@mmlx.us>
Sat, 21 Sep 2013 17:24:01 +0000 (17:24 +0000)
mmap_everything.c

index a1b4b77..ae1d529 100644 (file)
@@ -45,9 +45,8 @@ int main() {
        }
 
        srand48(time(NULL));
-       while (1) {
-               printf("Press enter to read a random byte of memory. (pid %d) >", pid);
-               while (getchar() != '\n');
+       int *pi;
+       do {
                uint32_t lower = lrand48();
                uint32_t upper = lrand48();
 
@@ -55,8 +54,8 @@ int main() {
                // align to integer, keep in "userspace" address space
                pvalue &= 0x00007FFFFFFFFFF0;
 
-               int *pi = (void*)(pvalue);
+               pi = (void*)(pvalue);
                printf("*%p = ", (void*)pi);
                printf("%x\n", *pi);
-       }
+       } while (*pi == 0);
 }