2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2015, Joyent, Inc.
17 * Tests to make sure that a parent and child do not get the same arc4random
18 * state across a forkall. This source file is used to make two tests. One which
19 * initializes the data in advance, one of which does not.
26 #include <sys/types.h>
30 typedef struct arc4_fork
{
33 uint8_t af_pbuf
[4096];
34 uint8_t af_cbuf
[4096];
37 arc4_fork_t
*fork_data
;
49 fork_data
= (arc4_fork_t
*)mmap(NULL
, sizeof (arc4_fork_t
),
50 PROT_READ
| PROT_WRITE
, MAP_SHARED
| MAP_ANON
, -1, 0);
51 assert(fork_data
!= MAP_FAILED
);
56 fork_data
->af_child
= arc4random();
57 arc4random_buf(fork_data
->af_cbuf
, sizeof (fork_data
->af_cbuf
));
61 fork_data
->af_parent
= arc4random();
62 arc4random_buf(fork_data
->af_pbuf
, sizeof (fork_data
->af_pbuf
));
65 } while (child
== -1 && errno
== EINTR
);
68 /* Now verify our data doesn't match */
69 assert(fork_data
->af_parent
!= fork_data
->af_child
);
72 * For the buffer here, we're mostly concerned that they aren't somehow
73 * getting the same stream.
75 for (i
= 0; i
< sizeof (fork_data
->af_pbuf
); i
++) {
76 if (fork_data
->af_pbuf
[i
] != fork_data
->af_cbuf
[i
])
79 assert(i
!= sizeof (fork_data
->af_pbuf
));