\hypertarget{kern__kcov_8c_source}{}\doxysection{kern\+\_\+kcov.\+c}
\label{kern__kcov_8c_source}\index{kern/kern\_kcov.c@{kern/kern\_kcov.c}}
\mbox{\hyperlink{kern__kcov_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (C) 2018 The FreeBSD Foundation. All rights reserved.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00005}00005 \textcolor{comment}{ * Copyright (C) 2018, 2019 Andrew Turner}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00006}00006 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00007}00007 \textcolor{comment}{ * This software was developed by Mitchell Horne under sponsorship of}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00008}00008 \textcolor{comment}{ * the FreeBSD Foundation.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00009}00009 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00010}00010 \textcolor{comment}{ * This software was developed by SRI International and the University of}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00011}00011 \textcolor{comment}{ * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-\/10-\/C-\/0237}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00012}00012 \textcolor{comment}{ * ("{}CTSRD"{}), as part of the DARPA CRASH research programme.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00013}00013 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00014}00014 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00015}00015 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00016}00016 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00017}00017 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00018}00018 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00019}00019 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00020}00020 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00021}00021 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00022}00022 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00023}00023 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00024}00024 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00025}00025 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00026}00026 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00027}00027 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00028}00028 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00029}00029 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00030}00030 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00031}00031 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00032}00032 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00033}00033 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00034}00034 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00035}00035 \textcolor{comment}{ * \$FreeBSD\$}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00036}00036 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00037}00037 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00038}00038 \textcolor{comment}{/* Interceptors are required for KMSAN. */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00039}00039 \textcolor{preprocessor}{\#if defined(KASAN) || defined(KCSAN)}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00040}00040 \textcolor{preprocessor}{\#define SAN\_RUNTIME}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00041}00041 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00042}00042 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00044}\mbox{\hyperlink{kern__kcov_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00044}} \mbox{\hyperlink{kern__kcov_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00045}00045 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00046}00046 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00047}00047 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00048}00048 \textcolor{preprocessor}{\#include <sys/conf.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00049}00049 \textcolor{preprocessor}{\#include <sys/eventhandler.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00050}00050 \textcolor{preprocessor}{\#include <sys/kcov.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00051}00051 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00052}00052 \textcolor{preprocessor}{\#include <sys/limits.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00053}00053 \textcolor{preprocessor}{\#include <sys/lock.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00054}00054 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00055}00055 \textcolor{preprocessor}{\#include <sys/mman.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00056}00056 \textcolor{preprocessor}{\#include <sys/mutex.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00057}00057 \textcolor{preprocessor}{\#include <sys/proc.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00058}00058 \textcolor{preprocessor}{\#include <sys/rwlock.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00059}00059 \textcolor{preprocessor}{\#include <sys/sysctl.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00060}00060 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00061}00061 \textcolor{preprocessor}{\#include <vm/vm.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00062}00062 \textcolor{preprocessor}{\#include <vm/pmap.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00063}00063 \textcolor{preprocessor}{\#include <vm/vm\_extern.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00064}00064 \textcolor{preprocessor}{\#include <vm/vm\_object.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00065}00065 \textcolor{preprocessor}{\#include <vm/vm\_page.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00066}00066 \textcolor{preprocessor}{\#include <vm/vm\_pager.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00067}00067 \textcolor{preprocessor}{\#include <vm/vm\_param.h>}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00068}00068 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00069}\mbox{\hyperlink{kern__kcov_8c_a998cea8c275617a3c280109d71d7fd3c}{00069}} \mbox{\hyperlink{kern__kcov_8c_a998cea8c275617a3c280109d71d7fd3c}{MALLOC\_DEFINE}}(M\_KCOV\_INFO, \textcolor{stringliteral}{"{}kcovinfo"{}}, \textcolor{stringliteral}{"{}KCOV info type"{}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00070}00070 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00071}\mbox{\hyperlink{kern__kcov_8c_ab5e98ddd255a8656be60277e70b0afc3}{00071}} \textcolor{preprocessor}{\#define KCOV\_ELEMENT\_SIZE       sizeof(uint64\_t)}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00072}00072 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00073}00073 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00074}00074 \textcolor{comment}{ * To know what the code can safely perform at any point in time we use a}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00075}00075 \textcolor{comment}{ * state machine. In the normal case the state transitions are:}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00076}00076 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00077}00077 \textcolor{comment}{ * OPEN -\/> READY -\/> RUNNING -\/> DYING}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00078}00078 \textcolor{comment}{ *  |       | \string^        |        \string^ \string^}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00079}00079 \textcolor{comment}{ *  |       | +-\/-\/-\/-\/-\/-\/-\/-\/+        | |}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00080}00080 \textcolor{comment}{ *  |       +-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/+ |}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00081}00081 \textcolor{comment}{ *  +-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/+}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00082}00082 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00083}00083 \textcolor{comment}{ * The states are:}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00084}00084 \textcolor{comment}{ *  OPEN:   The kcov fd has been opened, but no buffer is available to store}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00085}00085 \textcolor{comment}{ *          coverage data.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00086}00086 \textcolor{comment}{ *  READY:  The buffer to store coverage data has been allocated. Userspace}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00087}00087 \textcolor{comment}{ *          can set this by using ioctl(fd, KIOSETBUFSIZE, entries);. When}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00088}00088 \textcolor{comment}{ *          this has been set the buffer can be written to by the kernel,}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00089}00089 \textcolor{comment}{ *          and mmaped by userspace.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00090}00090 \textcolor{comment}{ * RUNNING: The coverage probes are able to store coverage data in the buffer.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00091}00091 \textcolor{comment}{ *          This is entered with ioctl(fd, KIOENABLE, mode);. The READY state}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00092}00092 \textcolor{comment}{ *          can be exited by ioctl(fd, KIODISABLE); or exiting the thread to}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00093}00093 \textcolor{comment}{ *          return to the READY state to allow tracing to be reused, or by}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00094}00094 \textcolor{comment}{ *          closing the kcov fd to enter the DYING state.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00095}00095 \textcolor{comment}{ * DYING:   The fd has been closed. All states can enter into this state when}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00096}00096 \textcolor{comment}{ *          userspace closes the kcov fd.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00097}00097 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00098}00098 \textcolor{comment}{ * We need to be careful when moving into and out of the RUNNING state. As}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00099}00099 \textcolor{comment}{ * an interrupt may happen while this is happening the ordering of memory}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00100}00100 \textcolor{comment}{ * operations is important so struct kcov\_info is valid for the tracing}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00101}00101 \textcolor{comment}{ * functions.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00102}00102 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00103}00103 \textcolor{comment}{ * When moving into the RUNNING state prior stores to struct kcov\_info need}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00104}00104 \textcolor{comment}{ * to be observed before the state is set. This allows for interrupts that}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00105}00105 \textcolor{comment}{ * may call into one of the coverage functions to fire at any point while}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00106}00106 \textcolor{comment}{ * being enabled and see a consistent struct kcov\_info.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00107}00107 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00108}00108 \textcolor{comment}{ * When moving out of the RUNNING state any later stores to struct kcov\_info}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00109}00109 \textcolor{comment}{ * need to be observed after the state is set. As with entering this is to}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00110}00110 \textcolor{comment}{ * present a consistent struct kcov\_info to interrupts.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00111}00111 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00112}\mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40}{00112}} \textcolor{keyword}{typedef} \textcolor{keyword}{enum} \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00113}\mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40aed3b2c097ee929a553bfa3624d86d071}{00113}}         \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40aed3b2c097ee929a553bfa3624d86d071}{KCOV\_STATE\_INVALID}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00114}\mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a354d9865ffe8443741991d7a98278268}{00114}}         \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a354d9865ffe8443741991d7a98278268}{KCOV\_STATE\_OPEN}}, \textcolor{comment}{/* The device is open, but with no buffer */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00115}\mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a00bc2d8db6b83ab28589286a028771a5}{00115}}         \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a00bc2d8db6b83ab28589286a028771a5}{KCOV\_STATE\_READY}},       \textcolor{comment}{/* The buffer has been allocated */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00116}\mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40acac408f64486fff4f11800ed3c9d1c76}{00116}}         \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40acac408f64486fff4f11800ed3c9d1c76}{KCOV\_STATE\_RUNNING}},   \textcolor{comment}{/* Recording trace data */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00117}\mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40aff90aacb60bab0c1202f96fe4598a160}{00117}}         \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40aff90aacb60bab0c1202f96fe4598a160}{KCOV\_STATE\_DYING}},       \textcolor{comment}{/* The fd was closed */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00118}00118 \} \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40}{kcov\_state\_t}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00119}00119 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00120}00120 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00121}00121 \textcolor{comment}{ * (l) Set while holding the kcov\_lock mutex and not in the RUNNING state.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00122}00122 \textcolor{comment}{ * (o) Only set once while in the OPEN state. Cleaned up while in the DYING}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00123}00123 \textcolor{comment}{ *     state, and with no thread associated with the struct kcov\_info.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00124}00124 \textcolor{comment}{ * (s) Set atomically to enter or exit the RUNNING state, non-\/atomically}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00125}00125 \textcolor{comment}{ *     otherwise. See above for a description of the other constraints while}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00126}00126 \textcolor{comment}{ *     moving into or out of the RUNNING state.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00127}00127 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00128}\mbox{\hyperlink{structkcov__info}{00128}} \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00129}\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{00129}}         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}}     *\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}};  \textcolor{comment}{/* (l) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00130}\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{00130}}         vm\_object\_t     \mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}};           \textcolor{comment}{/* (o) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00131}\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{00131}}         vm\_offset\_t     \mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}};           \textcolor{comment}{/* (o) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00132}\mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{00132}}         \textcolor{keywordtype}{size\_t}          \mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}}; \textcolor{comment}{/* (o) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00133}\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{00133}}         \textcolor{keywordtype}{size\_t}          \mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}}; \textcolor{comment}{/* (o) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00134}\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{00134}}         \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40}{kcov\_state\_t}}        \mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}};             \textcolor{comment}{/* (s) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00135}\mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{00135}}         \textcolor{keywordtype}{int}             \mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{mode}};               \textcolor{comment}{/* (l) */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00136}00136 \};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00137}00137 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00138}00138 \textcolor{comment}{/* Prototypes */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00139}\mbox{\hyperlink{kern__kcov_8c_a1de1dedbae8ea96b46e7adf42a046b46}{00139}} \textcolor{keyword}{static} d\_open\_t         \mbox{\hyperlink{kern__kcov_8c_a1de1dedbae8ea96b46e7adf42a046b46}{kcov\_open}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00140}\mbox{\hyperlink{kern__kcov_8c_ae9f8aeab2c3b477bd4b1ff6de31ff2bf}{00140}} \textcolor{keyword}{static} d\_close\_t        \mbox{\hyperlink{kern__kcov_8c_ae9f8aeab2c3b477bd4b1ff6de31ff2bf}{kcov\_close}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00141}\mbox{\hyperlink{kern__kcov_8c_a5eb9546d59695b38ff0a8a0c5e49a54f}{00141}} \textcolor{keyword}{static} d\_mmap\_single\_t  \mbox{\hyperlink{kern__kcov_8c_a5eb9546d59695b38ff0a8a0c5e49a54f}{kcov\_mmap\_single}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00142}\mbox{\hyperlink{kern__kcov_8c_a3104c41dc245db29dbf647d5756b103b}{00142}} \textcolor{keyword}{static} d\_ioctl\_t        \mbox{\hyperlink{kern__kcov_8c_a3104c41dc245db29dbf647d5756b103b}{kcov\_ioctl}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00143}00143 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00144}00144 \textcolor{keyword}{static} \textcolor{keywordtype}{int}  \mbox{\hyperlink{kern__kcov_8c_abbbfec71409334dd0ff2b8aff8027f7b}{kcov\_alloc}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info}{kcov\_info}} *info, \textcolor{keywordtype}{size\_t} entries);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00145}00145 \textcolor{keyword}{static} \textcolor{keywordtype}{void} \mbox{\hyperlink{kern__kcov_8c_a9c3a451d0d7b2a190e19edfe669d7f66}{kcov\_free}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info}{kcov\_info}} *info);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00146}00146 \textcolor{keyword}{static} \textcolor{keywordtype}{void} \mbox{\hyperlink{kern__kcov_8c_aa992ecf8122321b18f82bb862c9056f9}{kcov\_init}}(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *unused);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00147}00147 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00148}\mbox{\hyperlink{kern__kcov_8c_aeadada31eb103591cd294cdc0e9b9841}{00148}} \textcolor{keyword}{static} \textcolor{keyword}{struct }cdevsw \mbox{\hyperlink{kern__kcov_8c_aeadada31eb103591cd294cdc0e9b9841}{kcov\_cdevsw}} = \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00149}00149         .d\_version =    D\_VERSION,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00150}00150         .d\_open =       \mbox{\hyperlink{kern__kcov_8c_a1de1dedbae8ea96b46e7adf42a046b46}{kcov\_open}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00151}00151         .d\_close =      \mbox{\hyperlink{kern__kcov_8c_ae9f8aeab2c3b477bd4b1ff6de31ff2bf}{kcov\_close}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00152}00152         .d\_mmap\_single = \mbox{\hyperlink{kern__kcov_8c_a5eb9546d59695b38ff0a8a0c5e49a54f}{kcov\_mmap\_single}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00153}00153         .d\_ioctl =      \mbox{\hyperlink{kern__kcov_8c_a3104c41dc245db29dbf647d5756b103b}{kcov\_ioctl}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00154}00154         .d\_name =       \textcolor{stringliteral}{"{}kcov"{}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00155}00155 \};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00156}00156 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00157}\mbox{\hyperlink{kern__kcov_8c_a6f88a9f0bed374d21498696b00322712}{00157}} \mbox{\hyperlink{kern__kcov_8c_a6f88a9f0bed374d21498696b00322712}{SYSCTL\_NODE}}(\_kern, OID\_AUTO, kcov, CTLFLAG\_RW | CTLFLAG\_MPSAFE, 0,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00158}00158     \textcolor{stringliteral}{"{}Kernel coverage"{}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00159}00159 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00160}\mbox{\hyperlink{kern__kcov_8c_a382728c3f6dd37d673bc984806d59b71}{00160}} \textcolor{keyword}{static} u\_int \mbox{\hyperlink{kern__kcov_8c_a382728c3f6dd37d673bc984806d59b71}{kcov\_max\_entries}} = KCOV\_MAXENTRIES;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00161}\mbox{\hyperlink{kern__kcov_8c_a95292de38ac81ac346fd0252c8a44c0c}{00161}} \mbox{\hyperlink{kern__kcov_8c_a95292de38ac81ac346fd0252c8a44c0c}{SYSCTL\_UINT}}(\_kern\_kcov, OID\_AUTO, max\_entries, CTLFLAG\_RW,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00162}00162     \&\mbox{\hyperlink{kern__kcov_8c_a382728c3f6dd37d673bc984806d59b71}{kcov\_max\_entries}}, 0,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00163}00163     \textcolor{stringliteral}{"{}Maximum number of entries in the kcov buffer"{}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00164}00164 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00165}\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{00165}} \textcolor{keyword}{static} \textcolor{keyword}{struct }\mbox{\hyperlink{uipc__ktls_8c_a7b5de10a04be6deb16c42cef5da02110}{mtx}} \mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00166}\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{00166}} \textcolor{keyword}{static} \textcolor{keywordtype}{int} \mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00167}00167 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00168}00168 \textcolor{keyword}{static} \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} * \_\_nosanitizeaddress \_\_nosanitizememory}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00169}\mbox{\hyperlink{kern__kcov_8c_a4802d70066afa791ccdf44e32caaca42}{00169}} \mbox{\hyperlink{kern__kcov_8c_a4802d70066afa791ccdf44e32caaca42}{get\_kinfo}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} *td)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00170}00170 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00171}00171         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00172}00172 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00173}00173         \textcolor{comment}{/* We might have a NULL thread when releasing the secondary CPUs */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00174}00174         \textcolor{keywordflow}{if} (td == NULL)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00175}00175                 \textcolor{keywordflow}{return} (NULL);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00176}00176 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00177}00177         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00178}00178 \textcolor{comment}{         * We are in an interrupt, stop tracing as it is not explicitly}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00179}00179 \textcolor{comment}{         * part of a syscall.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00180}00180 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00181}00181         \textcolor{keywordflow}{if} (td-\/>td\_intr\_nesting\_level > 0 || td-\/>td\_intr\_frame != NULL)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00182}00182                 \textcolor{keywordflow}{return} (NULL);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00183}00183 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00184}00184         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00185}00185 \textcolor{comment}{         * If info is NULL or the state is not running we are not tracing.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00186}00186 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00187}00187         info = td-\/>td\_kcov\_info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00188}00188         \textcolor{keywordflow}{if} (info == NULL ||}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00189}00189             atomic\_load\_acq\_int(\&info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}}) != \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40acac408f64486fff4f11800ed3c9d1c76}{KCOV\_STATE\_RUNNING}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00190}00190                 \textcolor{keywordflow}{return} (NULL);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00191}00191 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00192}00192         \textcolor{keywordflow}{return} (info);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00193}00193 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00194}00194 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00195}00195 \textcolor{keyword}{static} \textcolor{keywordtype}{void} \_\_nosanitizeaddress \_\_nosanitizememory}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00196}\mbox{\hyperlink{kern__kcov_8c_a5ea13e2ec4b0f6bf64a68af62e7965c8}{00196}} \mbox{\hyperlink{kern__kcov_8c_a5ea13e2ec4b0f6bf64a68af62e7965c8}{trace\_pc}}(uintptr\_t ret)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00197}00197 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00198}00198         \textcolor{keyword}{struct }thread *td;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00199}00199         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00200}00200         uint64\_t *\mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}, index;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00201}00201 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00202}00202         td = curthread;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00203}00203         info = \mbox{\hyperlink{kern__kcov_8c_a4802d70066afa791ccdf44e32caaca42}{get\_kinfo}}(td);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00204}00204         \textcolor{keywordflow}{if} (info == NULL)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00205}00205                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00206}00206 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00207}00207         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00208}00208 \textcolor{comment}{         * Check we are in the PC-\/trace mode.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00209}00209 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00210}00210         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{mode}} != KCOV\_MODE\_TRACE\_PC)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00211}00211                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00212}00212 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00213}00213         KASSERT(info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} != 0, (\textcolor{stringliteral}{"{}\%s: NULL buf while running"{}}, \_\_func\_\_));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00214}00214 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00215}00215         \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}} = (uint64\_t *)info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00216}00216 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00217}00217         \textcolor{comment}{/* The first entry of the buffer holds the index */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00218}00218         index = \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[0];}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00219}00219         if (index + 2 > info-\/>\mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00220}00220                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00221}00221 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00222}00222         \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[index + 1] = ret;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00223}00223         \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[0] = index + 1;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00224}00224 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00225}00225 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00226}00226 \textcolor{keyword}{static} \textcolor{keywordtype}{bool} \_\_nosanitizeaddress \_\_nosanitizememory}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00227}\mbox{\hyperlink{kern__kcov_8c_a8eb24330e183677e3c874207925d5242}{00227}} \mbox{\hyperlink{kern__kcov_8c_a8eb24330e183677e3c874207925d5242}{trace\_cmp}}(uint64\_t \mbox{\hyperlink{group__BUS_ga0141f9c2e01a93ce25d669aa4851ec87}{type}}, uint64\_t arg1, uint64\_t arg2, uint64\_t ret)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00228}00228 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00229}00229         \textcolor{keyword}{struct }thread *td;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00230}00230         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00231}00231         uint64\_t *\mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}, index;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00232}00232 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00233}00233         td = curthread;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00234}00234         info = \mbox{\hyperlink{kern__kcov_8c_a4802d70066afa791ccdf44e32caaca42}{get\_kinfo}}(td);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00235}00235         \textcolor{keywordflow}{if} (info == NULL)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00236}00236                 \textcolor{keywordflow}{return} (\textcolor{keyword}{false});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00237}00237 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00238}00238         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00239}00239 \textcolor{comment}{         * Check we are in the comparison-\/trace mode.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00240}00240 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00241}00241         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{mode}} != KCOV\_MODE\_TRACE\_CMP)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00242}00242                 \textcolor{keywordflow}{return} (\textcolor{keyword}{false});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00243}00243 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00244}00244         KASSERT(info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} != 0, (\textcolor{stringliteral}{"{}\%s: NULL buf while running"{}}, \_\_func\_\_));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00245}00245 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00246}00246         \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}} = (uint64\_t *)info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00247}00247 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00248}00248         \textcolor{comment}{/* The first entry of the buffer holds the index */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00249}00249         index = \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[0];}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00250}00250 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00251}00251         \textcolor{comment}{/* Check we have space to store all elements */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00252}00252         if (index * 4 + 4 + 1 > info-\/>\mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00253}00253                 \textcolor{keywordflow}{return} (\textcolor{keyword}{false});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00254}00254 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00255}00255         \textcolor{keywordflow}{while} (1) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00256}00256                 \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[index * 4 + 1] = \mbox{\hyperlink{group__BUS_ga0141f9c2e01a93ce25d669aa4851ec87}{type}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00257}00257                 \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[index * 4 + 2] = arg1;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00258}00258                 \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[index * 4 + 3] = arg2;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00259}00259                 \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[index * 4 + 4] = ret;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00260}00260 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00261}00261                 \textcolor{keywordflow}{if} (\mbox{\hyperlink{subr__atomic64_8c_aaa69fb0691b0e78493d86e6309b4a6f4}{atomic\_cmpset\_64}}(\&\mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[0], index, index + 1))}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00262}00262                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00263}00263                 \mbox{\hyperlink{vfs__syscalls_8c_a6defe41b89c760943b86089ec1838319}{buf}}[0] = index;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00264}00264         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00265}00265 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00266}00266         \textcolor{keywordflow}{return} (\textcolor{keyword}{true});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00267}00267 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00268}00268 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00269}00269 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00270}00270 \textcolor{comment}{ * The fd is being closed, cleanup everything we can.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00271}00271 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00272}00272 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00273}\mbox{\hyperlink{kern__kcov_8c_a8de37bb2c9a2e9161a94546c27d23841}{00273}} \mbox{\hyperlink{kern__kcov_8c_a8de37bb2c9a2e9161a94546c27d23841}{kcov\_mmap\_cleanup}}(\textcolor{keywordtype}{void} *arg)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00274}00274 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00275}00275         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info = arg;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00276}00276         \textcolor{keyword}{struct }thread *thread;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00277}00277 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00278}00278         mtx\_lock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00279}00279         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00280}00280 \textcolor{comment}{         * Move to KCOV\_STATE\_DYING to stop adding new entries.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00281}00281 \textcolor{comment}{         *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00282}00282 \textcolor{comment}{         * If the thread is running we need to wait until thread exit to}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00283}00283 \textcolor{comment}{         * clean up as it may currently be adding a new entry. If this is}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00284}00284 \textcolor{comment}{         * the case being in KCOV\_STATE\_DYING will signal that the buffer}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00285}00285 \textcolor{comment}{         * needs to be cleaned up.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00286}00286 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00287}00287         atomic\_store\_int(\&info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}}, \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40aff90aacb60bab0c1202f96fe4598a160}{KCOV\_STATE\_DYING}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00288}00288         atomic\_thread\_fence\_seq\_cst();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00289}00289         thread = info-\/>\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00290}00290         mtx\_unlock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00291}00291 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00292}00292         \textcolor{keywordflow}{if} (thread != NULL)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00293}00293                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00294}00294 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00295}00295         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00296}00296 \textcolor{comment}{         * We can safely clean up the info struct as it is in the}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00297}00297 \textcolor{comment}{         * KCOV\_STATE\_DYING state with no thread associated.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00298}00298 \textcolor{comment}{         *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00299}00299 \textcolor{comment}{         * The KCOV\_STATE\_DYING stops new threads from using it.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00300}00300 \textcolor{comment}{         * The lack of a thread means nothing is currently using the buffers.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00301}00301 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00302}00302         \mbox{\hyperlink{kern__kcov_8c_a9c3a451d0d7b2a190e19edfe669d7f66}{kcov\_free}}(info);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00303}00303 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00304}00304 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00305}00305 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00306}\mbox{\hyperlink{kern__kcov_8c_a62f25c62588f0035285a3d777654c6ba}{00306}} \mbox{\hyperlink{kern__kcov_8c_a1de1dedbae8ea96b46e7adf42a046b46}{kcov\_open}}(\textcolor{keyword}{struct} cdev *dev, \textcolor{keywordtype}{int} oflags, \textcolor{keywordtype}{int} devtype, \textcolor{keyword}{struct} thread *td)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00307}00307 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00308}00308         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00309}00309         \textcolor{keywordtype}{int} error;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00310}00310 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00311}00311         info = \mbox{\hyperlink{kern__malloc_8c_a13e924a88f20870d2d55e3f7fb660352}{malloc}}(\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info}{kcov\_info}}), M\_KCOV\_INFO, M\_ZERO | M\_WAITOK);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00312}00312         info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} = \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a354d9865ffe8443741991d7a98278268}{KCOV\_STATE\_OPEN}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00313}00313         info-\/>\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} = NULL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00314}00314         info-\/>\mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{mode}} = -\/1;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00315}00315 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00316}00316         \textcolor{keywordflow}{if} ((error = devfs\_set\_cdevpriv(info, \mbox{\hyperlink{kern__kcov_8c_a8de37bb2c9a2e9161a94546c27d23841}{kcov\_mmap\_cleanup}})) != 0)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00317}00317                 \mbox{\hyperlink{kern__kcov_8c_a8de37bb2c9a2e9161a94546c27d23841}{kcov\_mmap\_cleanup}}(info);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00318}00318 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00319}00319         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00320}00320 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00321}00321 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00322}00322 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00323}\mbox{\hyperlink{kern__kcov_8c_a371aad0bc13edb90fd58edde3ae3bd1d}{00323}} \mbox{\hyperlink{kern__kcov_8c_ae9f8aeab2c3b477bd4b1ff6de31ff2bf}{kcov\_close}}(\textcolor{keyword}{struct} cdev *dev, \textcolor{keywordtype}{int} fflag, \textcolor{keywordtype}{int} devtype, \textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} *td)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00324}00324 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00325}00325         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00326}00326         \textcolor{keywordtype}{int} error;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00327}00327 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00328}00328         \textcolor{keywordflow}{if} ((error = devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&info)) != 0)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00329}00329                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00330}00330 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00331}00331         KASSERT(info != NULL, (\textcolor{stringliteral}{"{}kcov\_close with no kcov\_info structure"{}}));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00332}00332 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00333}00333         \textcolor{comment}{/* Trying to close, but haven't disabled */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00334}00334         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} == \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40acac408f64486fff4f11800ed3c9d1c76}{KCOV\_STATE\_RUNNING}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00335}00335                 \textcolor{keywordflow}{return} (EBUSY);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00336}00336 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00337}00337         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00338}00338 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00339}00339 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00340}00340 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00341}\mbox{\hyperlink{kern__kcov_8c_ac34652257fa09cdc9c15c40f4327ddf5}{00341}} \mbox{\hyperlink{kern__kcov_8c_a5eb9546d59695b38ff0a8a0c5e49a54f}{kcov\_mmap\_single}}(\textcolor{keyword}{struct} cdev *dev, vm\_ooffset\_t *offset, vm\_size\_t size,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00342}00342     \textcolor{keyword}{struct} vm\_object **\textcolor{keywordtype}{object}, \textcolor{keywordtype}{int} nprot)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00343}00343 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00344}00344         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00345}00345         \textcolor{keywordtype}{int} error;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00346}00346 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00347}00347         \textcolor{keywordflow}{if} ((nprot \& (PROT\_EXEC | PROT\_READ | PROT\_WRITE)) !=}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00348}00348             (PROT\_READ | PROT\_WRITE))}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00349}00349                 \textcolor{keywordflow}{return} (EINVAL);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00350}00350 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00351}00351         \textcolor{keywordflow}{if} ((error = devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&info)) != 0)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00352}00352                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00353}00353 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00354}00354         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} == 0 || size / \mbox{\hyperlink{kern__kcov_8c_ab5e98ddd255a8656be60277e70b0afc3}{KCOV\_ELEMENT\_SIZE}} != info-\/>\mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00355}00355                 \textcolor{keywordflow}{return} (EINVAL);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00356}00356 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00357}00357         vm\_object\_reference(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00358}00358         *offset = 0;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00359}00359         *\textcolor{keywordtype}{object} = info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00360}00360         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00361}00361 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00362}00362 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00363}00363 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00364}\mbox{\hyperlink{kern__kcov_8c_abbbfec71409334dd0ff2b8aff8027f7b}{00364}} \mbox{\hyperlink{kern__kcov_8c_abbbfec71409334dd0ff2b8aff8027f7b}{kcov\_alloc}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info}{kcov\_info}} *info, \textcolor{keywordtype}{size\_t} \mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00365}00365 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00366}00366         \textcolor{keywordtype}{size\_t} n, pages;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00367}00367         vm\_page\_t m;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00368}00368 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00369}00369         KASSERT(info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} == 0, (\textcolor{stringliteral}{"{}kcov\_alloc: Already have a buffer"{}}));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00370}00370         KASSERT(info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} == \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a354d9865ffe8443741991d7a98278268}{KCOV\_STATE\_OPEN}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00371}00371             (\textcolor{stringliteral}{"{}kcov\_alloc: Not in open state (\%x)"{}}, info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}}));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00372}00372 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00373}00373         \textcolor{keywordflow}{if} (entries < 2 || entries > \mbox{\hyperlink{kern__kcov_8c_a382728c3f6dd37d673bc984806d59b71}{kcov\_max\_entries}})}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00374}00374                 \textcolor{keywordflow}{return} (EINVAL);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00375}00375 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00376}00376         \textcolor{comment}{/* Align to page size so mmap can't access other kernel memory */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00377}00377         info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}} = roundup2(\mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}} * \mbox{\hyperlink{kern__kcov_8c_ab5e98ddd255a8656be60277e70b0afc3}{KCOV\_ELEMENT\_SIZE}}, PAGE\_SIZE);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00378}00378         pages = info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}} / PAGE\_SIZE;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00379}00379 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00380}00380         \textcolor{keywordflow}{if} ((info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} = kva\_alloc(info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}})) == 0)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00381}00381                 \textcolor{keywordflow}{return} (ENOMEM);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00382}00382 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00383}00383         info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}} = vm\_pager\_allocate(OBJT\_PHYS, 0, info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}},}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00384}00384             PROT\_READ | PROT\_WRITE, 0, curthread-\/>td\_ucred);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00385}00385 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00386}00386         VM\_OBJECT\_WLOCK(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00387}00387         \textcolor{keywordflow}{for} (n = 0; n < pages; n++) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00388}00388                 m = vm\_page\_grab(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}}, n,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00389}00389                     VM\_ALLOC\_ZERO | VM\_ALLOC\_WIRED);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00390}00390                 vm\_page\_valid(m);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00391}00391                 vm\_page\_xunbusy(m);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00392}00392                 pmap\_qenter(info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} + n * PAGE\_SIZE, \&m, 1);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00393}00393         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00394}00394         VM\_OBJECT\_WUNLOCK(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00395}00395 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00396}00396         info-\/>\mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}} = \mbox{\hyperlink{structkcov__info_a1ebdc1e7cecc0f0cb5599815cc144476}{entries}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00397}00397 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00398}00398         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00399}00399 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00400}00400 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00401}00401 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00402}\mbox{\hyperlink{kern__kcov_8c_a9c3a451d0d7b2a190e19edfe669d7f66}{00402}} \mbox{\hyperlink{kern__kcov_8c_a9c3a451d0d7b2a190e19edfe669d7f66}{kcov\_free}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info}{kcov\_info}} *info)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00403}00403 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00404}00404         vm\_page\_t m;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00405}00405         \textcolor{keywordtype}{size\_t} i;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00406}00406 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00407}00407         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}} != 0) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00408}00408                 pmap\_qremove(info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}}, info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}} / PAGE\_SIZE);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00409}00409                 kva\_free(info-\/>\mbox{\hyperlink{structkcov__info_a466c8518a81408d6a37f741c0ce91ab2}{kvaddr}}, info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00410}00410         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00411}00411         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}} != NULL) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00412}00412                 VM\_OBJECT\_WLOCK(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00413}00413                 m = vm\_page\_lookup(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}}, 0);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00414}00414                 \textcolor{keywordflow}{for} (i = 0; i < info-\/>\mbox{\hyperlink{structkcov__info_ac40efd0527f57dbb3f796791a3239535}{bufsize}} / PAGE\_SIZE; i++) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00415}00415                         vm\_page\_unwire\_noq(m);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00416}00416                         m = vm\_page\_next(m);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00417}00417                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00418}00418                 VM\_OBJECT\_WUNLOCK(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00419}00419                 vm\_object\_deallocate(info-\/>\mbox{\hyperlink{structkcov__info_a59595a81b4f53d5ba69f43922a4a5f26}{bufobj}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00420}00420         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00421}00421         \mbox{\hyperlink{kern__malloc_8c_af6592f7dfb186f55f99e52892336fff0}{free}}(info, M\_KCOV\_INFO);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00422}00422 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00423}00423 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00424}00424 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00425}\mbox{\hyperlink{kern__kcov_8c_a0a232b81dfc1bc97044d91b232e463da}{00425}} \mbox{\hyperlink{kern__kcov_8c_a3104c41dc245db29dbf647d5756b103b}{kcov\_ioctl}}(\textcolor{keyword}{struct} cdev *dev, u\_long cmd, caddr\_t \mbox{\hyperlink{msi__if_8m_a67f97bb317cd4853ec5319a7da661c1f}{data}}, \textcolor{keywordtype}{int} fflag \_\_unused,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00426}00426     \textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} *td)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00427}00427 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00428}00428         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00429}00429         \textcolor{keywordtype}{int} \mbox{\hyperlink{vfs__syscalls_8c_adc8d3cf511ceb277aea0cfa1cd027c59}{mode}}, error;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00430}00430 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00431}00431         \textcolor{keywordflow}{if} ((error = devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&info)) != 0)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00432}00432                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00433}00433 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00434}00434         \textcolor{keywordflow}{if} (cmd == KIOSETBUFSIZE) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00435}00435                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00436}00436 \textcolor{comment}{                 * Set the size of the coverage buffer. Should be called}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00437}00437 \textcolor{comment}{                 * before enabling coverage collection for that thread.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00438}00438 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00439}00439                 \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} != \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a354d9865ffe8443741991d7a98278268}{KCOV\_STATE\_OPEN}}) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00440}00440                         \textcolor{keywordflow}{return} (EBUSY);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00441}00441                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00442}00442                 error = \mbox{\hyperlink{kern__kcov_8c_abbbfec71409334dd0ff2b8aff8027f7b}{kcov\_alloc}}(info, *(u\_int *)\mbox{\hyperlink{msi__if_8m_a67f97bb317cd4853ec5319a7da661c1f}{data}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00443}00443                 \textcolor{keywordflow}{if} (error == 0)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00444}00444                         info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} = \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a00bc2d8db6b83ab28589286a028771a5}{KCOV\_STATE\_READY}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00445}00445                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00446}00446         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00447}00447 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00448}00448         mtx\_lock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00449}00449         \textcolor{keywordflow}{switch} (cmd) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00450}00450         \textcolor{keywordflow}{case} KIOENABLE:}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00451}00451                 \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} != \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a00bc2d8db6b83ab28589286a028771a5}{KCOV\_STATE\_READY}}) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00452}00452                         error = EBUSY;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00453}00453                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00454}00454                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00455}00455                 \textcolor{keywordflow}{if} (td-\/>td\_kcov\_info != NULL) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00456}00456                         error = EINVAL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00457}00457                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00458}00458                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00459}00459                 \mbox{\hyperlink{vfs__syscalls_8c_adc8d3cf511ceb277aea0cfa1cd027c59}{mode}} = *(\textcolor{keywordtype}{int} *)\mbox{\hyperlink{msi__if_8m_a67f97bb317cd4853ec5319a7da661c1f}{data}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00460}00460                 \textcolor{keywordflow}{if} (\mbox{\hyperlink{vfs__syscalls_8c_adc8d3cf511ceb277aea0cfa1cd027c59}{mode}} != KCOV\_MODE\_TRACE\_PC \&\& \mbox{\hyperlink{vfs__syscalls_8c_adc8d3cf511ceb277aea0cfa1cd027c59}{mode}} != KCOV\_MODE\_TRACE\_CMP) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00461}00461                         error = EINVAL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00462}00462                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00463}00463                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00464}00464 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00465}00465                 \textcolor{comment}{/* Lets hope nobody opens this 2 billion times */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00466}00466                 KASSERT(\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}} < INT\_MAX,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00467}00467                     (\textcolor{stringliteral}{"{}\%s: Open too many times"{}}, \_\_func\_\_));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00468}00468                 \mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}}++;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00469}00469                 \textcolor{keywordflow}{if} (\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}} == 1) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00470}00470                         \mbox{\hyperlink{subr__coverage_8c_a0fa4fd8d590cd77d9ca2977558718811}{cov\_register\_pc}}(\&\mbox{\hyperlink{kern__kcov_8c_a5ea13e2ec4b0f6bf64a68af62e7965c8}{trace\_pc}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00471}00471                         \mbox{\hyperlink{subr__coverage_8c_ac77fa52c2f16ce58f49af508d3c05f15}{cov\_register\_cmp}}(\&\mbox{\hyperlink{kern__kcov_8c_a8eb24330e183677e3c874207925d5242}{trace\_cmp}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00472}00472                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00473}00473 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00474}00474                 KASSERT(info-\/>\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} == NULL,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00475}00475                     (\textcolor{stringliteral}{"{}Enabling kcov when already enabled"{}}));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00476}00476                 info-\/>\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} = td;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00477}00477                 info-\/>\mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{mode}} = \mbox{\hyperlink{vfs__syscalls_8c_adc8d3cf511ceb277aea0cfa1cd027c59}{mode}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00478}00478                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00479}00479 \textcolor{comment}{                 * Ensure the mode has been set before starting coverage}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00480}00480 \textcolor{comment}{                 * tracing.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00481}00481 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00482}00482                 atomic\_store\_rel\_int(\&info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}}, \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40acac408f64486fff4f11800ed3c9d1c76}{KCOV\_STATE\_RUNNING}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00483}00483                 td-\/>td\_kcov\_info = info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00484}00484                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00485}00485         \textcolor{keywordflow}{case} KIODISABLE:}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00486}00486                 \textcolor{comment}{/* Only the currently enabled thread may disable itself */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00487}00487                 \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} != \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40acac408f64486fff4f11800ed3c9d1c76}{KCOV\_STATE\_RUNNING}} ||}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00488}00488                     info != td-\/>td\_kcov\_info) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00489}00489                         error = EINVAL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00490}00490                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00491}00491                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00492}00492                 KASSERT(\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}} > 0, (\textcolor{stringliteral}{"{}\%s: Open count is zero"{}}, \_\_func\_\_));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00493}00493                 \mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}}-\/-\/;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00494}00494                 \textcolor{keywordflow}{if} (\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}} == 0) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00495}00495                         \mbox{\hyperlink{subr__coverage_8c_a86f9c5ce575fe49c6a8fe584ce7a52ae}{cov\_unregister\_pc}}();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00496}00496                         \mbox{\hyperlink{subr__coverage_8c_a562e82408b0af94a5bf053317163aa98}{cov\_unregister\_cmp}}();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00497}00497                 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00498}00498 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00499}00499                 td-\/>td\_kcov\_info = NULL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00500}00500                 atomic\_store\_int(\&info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}}, \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a00bc2d8db6b83ab28589286a028771a5}{KCOV\_STATE\_READY}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00501}00501                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00502}00502 \textcolor{comment}{                 * Ensure we have exited the READY state before clearing the}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00503}00503 \textcolor{comment}{                 * rest of the info struct.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00504}00504 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00505}00505                 atomic\_thread\_fence\_rel();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00506}00506                 info-\/>\mbox{\hyperlink{structkcov__info_a6bffa982f65d081e716cfd93fee337e2}{mode}} = -\/1;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00507}00507                 info-\/>\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} = NULL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00508}00508                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00509}00509         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00510}00510                 error = EINVAL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00511}00511                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00512}00512         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00513}00513         mtx\_unlock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00514}00514 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00515}00515         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00516}00516 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00517}00517 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00518}00518 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00519}\mbox{\hyperlink{kern__kcov_8c_adf7f274d5de131285280cdeed497e029}{00519}} \mbox{\hyperlink{kern__kcov_8c_adf7f274d5de131285280cdeed497e029}{kcov\_thread\_dtor}}(\textcolor{keywordtype}{void} *arg \_\_unused, \textcolor{keyword}{struct} \mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} *td)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00520}00520 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00521}00521         \textcolor{keyword}{struct }\mbox{\hyperlink{structkcov__info}{kcov\_info}} *info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00522}00522 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00523}00523         info = td-\/>td\_kcov\_info;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00524}00524         \textcolor{keywordflow}{if} (info == NULL)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00525}00525                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00526}00526 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00527}00527         mtx\_lock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00528}00528         KASSERT(\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}} > 0, (\textcolor{stringliteral}{"{}\%s: Open count is zero"{}}, \_\_func\_\_));}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00529}00529         \mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}}-\/-\/;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00530}00530         \textcolor{keywordflow}{if} (\mbox{\hyperlink{kern__kcov_8c_a7f7d45d86644c99bc88e46889e97d27a}{active\_count}} == 0) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00531}00531                 \mbox{\hyperlink{subr__coverage_8c_a86f9c5ce575fe49c6a8fe584ce7a52ae}{cov\_unregister\_pc}}();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00532}00532                 \mbox{\hyperlink{subr__coverage_8c_a562e82408b0af94a5bf053317163aa98}{cov\_unregister\_cmp}}();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00533}00533         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00534}00534         td-\/>td\_kcov\_info = NULL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00535}00535         \textcolor{keywordflow}{if} (info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}} != \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40aff90aacb60bab0c1202f96fe4598a160}{KCOV\_STATE\_DYING}}) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00536}00536                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00537}00537 \textcolor{comment}{                 * The kcov file is still open. Mark it as unused and}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00538}00538 \textcolor{comment}{                 * wait for it to be closed before cleaning up.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00539}00539 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00540}00540                 atomic\_store\_int(\&info-\/>\mbox{\hyperlink{structkcov__info_ab98c218ea50ee8ef0829d8f0c0560c17}{state}}, \mbox{\hyperlink{kern__kcov_8c_acfbbfb7b9f6e417cbe2fd19c1c74de40a00bc2d8db6b83ab28589286a028771a5}{KCOV\_STATE\_READY}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00541}00541                 atomic\_thread\_fence\_seq\_cst();}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00542}00542                 \textcolor{comment}{/* This info struct is unused */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00543}00543                 info-\/>\mbox{\hyperlink{structkcov__info_a7f384938f7736264302879d5e1d2a98d}{thread}} = NULL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00544}00544                 mtx\_unlock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00545}00545                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00546}00546         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00547}00547         mtx\_unlock\_spin(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00548}00548 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00549}00549         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00550}00550 \textcolor{comment}{         * We can safely clean up the info struct as it is in the}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00551}00551 \textcolor{comment}{         * KCOV\_STATE\_DYING state where the info struct is associated with}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00552}00552 \textcolor{comment}{         * the current thread that's about to exit.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00553}00553 \textcolor{comment}{         *}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00554}00554 \textcolor{comment}{         * The KCOV\_STATE\_DYING stops new threads from using it.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00555}00555 \textcolor{comment}{         * It also stops the current thread from trying to use the info struct.}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00556}00556 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00557}00557         \mbox{\hyperlink{kern__kcov_8c_a9c3a451d0d7b2a190e19edfe669d7f66}{kcov\_free}}(info);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00558}00558 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00559}00559 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00560}00560 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00561}\mbox{\hyperlink{kern__kcov_8c_aa992ecf8122321b18f82bb862c9056f9}{00561}} \mbox{\hyperlink{kern__kcov_8c_aa992ecf8122321b18f82bb862c9056f9}{kcov\_init}}(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *unused)}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00562}00562 \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00563}00563         \textcolor{keyword}{struct }make\_dev\_args args;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00564}00564         \textcolor{keyword}{struct }cdev *dev;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00565}00565 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00566}00566         mtx\_init(\&\mbox{\hyperlink{kern__kcov_8c_a70c3c3960f25441811b2f0f9199d02f2}{kcov\_lock}}, \textcolor{stringliteral}{"{}kcov lock"{}}, NULL, MTX\_SPIN);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00567}00567 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00568}00568         make\_dev\_args\_init(\&args);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00569}00569         args.mda\_devsw = \&\mbox{\hyperlink{kern__kcov_8c_aeadada31eb103591cd294cdc0e9b9841}{kcov\_cdevsw}};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00570}00570         args.mda\_uid = UID\_ROOT;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00571}00571         args.mda\_gid = GID\_WHEEL;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00572}00572         args.mda\_mode = 0600;}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00573}00573         \textcolor{keywordflow}{if} (\mbox{\hyperlink{kern__conf_8c_a99ee21194c13c6b70a695f27cbcf800c}{make\_dev\_s}}(\&args, \&dev, \textcolor{stringliteral}{"{}kcov"{}}) != 0) \{}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00574}00574                 \mbox{\hyperlink{subr__prf_8c_a55f3d956bb2ba20b5059e9e25484a47f}{printf}}(\textcolor{stringliteral}{"{}\%s"{}}, \textcolor{stringliteral}{"{}Failed to create kcov device"{}});}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00575}00575                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00576}00576         \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00577}00577 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00578}00578         EVENTHANDLER\_REGISTER(\mbox{\hyperlink{kern__thread_8c_a0e522351d3dde4132d1dbbee67130769}{thread\_dtor}}, \mbox{\hyperlink{kern__kcov_8c_adf7f274d5de131285280cdeed497e029}{kcov\_thread\_dtor}}, NULL,}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00579}00579             EVENTHANDLER\_PRI\_ANY);}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00580}00580 \}}
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00581}00581 }
\DoxyCodeLine{\Hypertarget{kern__kcov_8c_source_l00582}\mbox{\hyperlink{kern__kcov_8c_a4f7d7a0ac0fdc680dab0e24abe23b879}{00582}} \mbox{\hyperlink{kern__kcov_8c_a4f7d7a0ac0fdc680dab0e24abe23b879}{SYSINIT}}(kcovdev, SI\_SUB\_LAST, SI\_ORDER\_ANY, \mbox{\hyperlink{kern__kcov_8c_aa992ecf8122321b18f82bb862c9056f9}{kcov\_init}}, NULL);}

\end{DoxyCode}
