xref: /freebsd/tools/test/stress2/misc/kevent10.sh (revision e0c4386e)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org>
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
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.
16#
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
27# SUCH DAMAGE.
28#
29
30# Regression test for
31# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=217435
32# by Tim Newsham <tim newsham nccgroup trust>
33
34# panic: Assertion size > 0 failed at ../../../kern/subr_vmem.c:1082
35# cpuid = 2
36# time = 1501182301
37# KDB: stack backtrace:
38# db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0173117650
39# vpanic() at vpanic+0x19c/frame 0xfffffe01731176d0
40# kassert_panic() at kassert_panic+0x126/frame 0xfffffe0173117740
41# vmem_alloc() at vmem_alloc+0x11b/frame 0xfffffe0173117780
42# kmem_malloc() at kmem_malloc+0x33/frame 0xfffffe01731177b0
43# uma_large_malloc() at uma_large_malloc+0x48/frame 0xfffffe01731177f0
44# malloc() at malloc+0xe3/frame 0xfffffe0173117840
45# ktrgenio() at ktrgenio+0x60/frame 0xfffffe0173117880
46# sys_kevent() at sys_kevent+0x12f/frame 0xfffffe0173117930
47# amd64_syscall() at amd64_syscall+0x7d2/frame 0xfffffe0173117ab0
48
49# Fixed by r315155.
50
51. ../default.cfg
52
53cat > /tmp/kevent10.c <<EOF
54#include <sys/param.h>
55#include <sys/event.h>
56#include <sys/time.h>
57#include <sys/uio.h>
58#include <sys/ktrace.h>
59
60#include <err.h>
61#include <errno.h>
62#include <fcntl.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66#include <unistd.h>
67
68int
69main(void)
70{
71	struct kevent changes;
72	struct kevent events;
73	char *fn = "/tmp/kevent10.trace";
74
75	if (open(fn, O_RDWR | O_CREAT, 0666) == -1)
76		err(1, "%s", fn);
77	if (ktrace(fn, KTRFLAG_DESCEND | KTROP_SET, KTRFAC_GENIO, 0) == -1)
78		err(1, "ktrace");
79	memset(&changes, 0, sizeof(struct kevent));
80	memset(&events, 0, sizeof(struct kevent));
81	if (kevent(0, &changes, -1, &events, 1, 0) == -1)
82		if (errno != EBADF)
83			err(1, "kevent");
84	if (ktrace(fn, KTROP_CLEARFILE, KTRFAC_GENIO, 0) == -1)
85		err(1, "ktrace clear");
86
87	return (0);
88}
89EOF
90
91mycc -o /tmp/kevent10 -Wall -Wextra -O2 /tmp/kevent10.c || exit 1
92rm /tmp/kevent10.c
93
94/tmp/kevent10
95s=$?
96
97rm /tmp/kevent10 /tmp/kevent10.trace
98exit $s
99