1 /* In OpenBSD, if you write to a file, another process doesn't see it
2 * in its mmap. Returns with exit status 0 if that is the case, 1 if
3 * it's coherent, and other if there's a problem. */
14 #define DATA "coherent.mmap"
16 int main(int argc
, char *argv
[])
18 int tochild
[2], toparent
[2];
20 volatile unsigned char *map
;
22 const char *fname
= argv
[1];
25 if (pipe(tochild
) != 0 || pipe(toparent
) != 0)
26 err(2, "Creating pipe");
31 fd
= open(fname
, O_RDWR
|O_CREAT
|O_TRUNC
, 0600);
33 err(2, "opening %s", fname
);
43 /* Wait for parent to create file. */
44 if (read(tochild
[0], &c
, 1) != 1)
45 err(2, "reading from parent");
47 /* Alter first byte. */
50 if (write(toparent
[1], &c
, 1) != 1)
51 err(2, "writing to parent");
58 /* Create a file and mmap it. */
59 page
= malloc(getpagesize());
60 memset(page
, 0x42, getpagesize());
61 if (write(fd
, page
, getpagesize()) != getpagesize())
62 err(2, "writing first page");
63 map
= mmap(NULL
, getpagesize(), PROT_READ
|PROT_WRITE
,
65 if (map
== MAP_FAILED
)
66 err(2, "mapping file");
69 errx(2, "first byte isn't 0x42!");
71 /* Tell child to alter file. */
72 if (write(tochild
[1], &c
, 1) != 1)
73 err(2, "writing to child");
75 if (read(toparent
[0], &c
, 1) != 1)
76 err(2, "reading from child");
79 errx(0, "mmap incoherent: first byte isn't 0.");