xref: /third_party/ltp/testcases/kernel/mce-test/tsrc/tkillpoison.c (revision f08c3bdf)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/ltp/testcases/kernel/mce-test/tsrc/
1f08c3bdfSopenharmony_ci// kills itself using poison
2f08c3bdfSopenharmony_ci#define _GNU_SOURCE 1
3f08c3bdfSopenharmony_ci#include <stdlib.h>
4f08c3bdfSopenharmony_ci#include <sys/mman.h>
5f08c3bdfSopenharmony_ci#include <stdio.h>
6f08c3bdfSopenharmony_ci#include <unistd.h>
7f08c3bdfSopenharmony_ci
8f08c3bdfSopenharmony_ci#define MADV_POISON 100
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_ciint main(void)
11f08c3bdfSopenharmony_ci{
12f08c3bdfSopenharmony_ci	int PS = getpagesize();
13f08c3bdfSopenharmony_ci	char *ptr = mmap(NULL, PS, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, 0,0);;
14f08c3bdfSopenharmony_ci	printf("ptr = %p\n", ptr);
15f08c3bdfSopenharmony_ci	madvise(ptr, PS, MADV_POISON);
16f08c3bdfSopenharmony_ci	printf("faulting\n");
17f08c3bdfSopenharmony_ci	*ptr = 1;
18f08c3bdfSopenharmony_ci	printf("waiting\n");
19f08c3bdfSopenharmony_ci	sleep(100);
20f08c3bdfSopenharmony_ci	return 0;
21f08c3bdfSopenharmony_ci}
22

Indexes created Thu Nov 07 10:32:03 CST 2024