blob: 7d3e67a441a8af3957b6a0ef32349b28baa4a3db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/* $OpenBSD: exec_self.c,v 1.2 2016/03/17 19:40:43 krw Exp $ */
/*
* Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <sys/types.h>
#include <sys/mman.h>
struct {
const char pad1[256*1024]; /* avoid read-ahead. */
const char string[256*1024]; /* at least one page */
const char pad2[256*1024]; /* avoid read-behind. */
} const blob = {
"padding1",
"the_test",
"padding2"
};
int
main(int argc, char **argv)
{
int pgsz = getpagesize();
vaddr_t va, off;
if (argc > 1) {
return (0);
}
va = (vaddr_t)&blob;
off = va & (pgsz - 1);
/* Make sure that nothing in the "blob" is cached. */
if (madvise((void *)(va - off), sizeof(blob) + (off > 0 ? pgsz : 0),
MADV_FREE))
err(1, "madvise");
if (execl(argv[0], argv[0], &blob.string, (char *)NULL))
err(1, "execl");
/* NOTREACHED */
return (1);
}
|