Created
May 7, 2019 09:38
-
-
Save DavidBuchanan314/6ef57215e3d740935f61893da8e675f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <sys/time.h> | |
const size_t nop_len = 8L * 1024 * 1024 * 1024; // 8GiB | |
double time_double() | |
{ | |
struct timeval t; | |
gettimeofday(&t, NULL); | |
return (double)t.tv_sec + (double)t.tv_usec / 1000000; | |
} | |
int main() | |
{ | |
printf("Initialising NOPmark...\n"); | |
uint8_t *nop_sled = mmap(NULL, nop_len, | |
PROT_READ | PROT_WRITE | PROT_EXEC, | |
MAP_ANON | MAP_PRIVATE, -1, 0); | |
if (nop_sled == NULL) { | |
perror("mmap"); | |
return -1; | |
} | |
memset(nop_sled, 0x90, nop_len); | |
nop_sled[nop_len-1] = 0xc3; | |
void (*nop)(void) = (void(*)(void)) nop_sled; | |
printf("Doing the NOPs...\n"); | |
double start = time_double(); | |
nop(); | |
nop(); | |
nop(); | |
nop(); | |
double duration = time_double() - start; | |
printf("Successfully did nothing for %f seconds.\n", duration); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment