Last active
December 8, 2020 04:56
-
-
Save arosh/1a9bbbeba7d2c9e2b30e0d930c413c17 to your computer and use it in GitHub Desktop.
hwpoison
This file contains hidden or 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 <stdlib.h> | |
#include <errno.h> | |
#include <sys/mman.h> | |
const int SIZE = 4096; | |
int main(void) { | |
int *addr = malloc(sizeof(int)*SIZE); | |
posix_memalign(&addr, 4096, sizeof(int)*SIZE); | |
for (int i = 0; i < SIZE; i++) { | |
addr[i] = i; | |
} | |
int err = madvise(addr, sizeof(int)*SIZE, MADV_HWPOISON); | |
printf("err = %d\n", err); | |
if (err != 0) { | |
perror(NULL); | |
} | |
int sum = 0; | |
for (int i = 0; i < SIZE; i++) { | |
sum += addr[i]; | |
} | |
printf("sum = %d\n", sum); | |
free(addr); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment