4 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 # Copyright (c) 2019 Dell EMC Isilon
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # "panic: vm_page_free_prep: freeing mapped page 0x657936c" seen.
31 # https://people.freebsd.org/~pho/stress/log/sem_wait.txt
36 cat > /tmp/sem_wait.c <<EOF
37 #include <sys/param.h>
44 #include <semaphore.h>
52 static sem_t *semaphore;
57 setproctitle("%s", __func__);
60 if (sem_wait(semaphore) == -1)
62 if (sem_post(semaphore) == -1)
73 setproctitle("%s", __func__);
76 if ((semaphore = mmap(NULL, len, PROT_READ | PROT_WRITE,
77 MAP_ANON | MAP_SHARED, -1, 0)) == MAP_FAILED)
80 // initialize semaphore and set value to 1
81 if (sem_init(semaphore, 1, 1) == -1)
84 if ((pid = fork()) == 0)
92 while (time(NULL) - start < 60) {
93 if (sem_wait(semaphore) == -1)
95 if (sem_post(semaphore) == -1)
99 if (waitpid(pid, NULL, 0) != pid)
105 mycc -o /tmp/sem_wait -Wall -Wextra -O2 /tmp/sem_wait.c || exit 1
106 timeout 6m /tmp/sem_wait; s=$?
107 [ $s -eq 124 ] && echo "Timed out"
108 rm -f /tmp/sem_wait /tmp/sem_wait.c