FreeBSD kernel kern code
kern_kcov.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/eventhandler.h>
#include <sys/kcov.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/rwlock.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/vm_extern.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
#include <vm/vm_param.h>
Include dependency graph for kern_kcov.c:

Go to the source code of this file.

Data Structures

struct  kcov_info
 

Macros

#define KCOV_ELEMENT_SIZE   sizeof(uint64_t)
 

Enumerations

enum  kcov_state_t {
  KCOV_STATE_INVALID , KCOV_STATE_OPEN , KCOV_STATE_READY , KCOV_STATE_RUNNING ,
  KCOV_STATE_DYING
}
 

Functions

 __FBSDID ("$FreeBSD$")
 
 MALLOC_DEFINE (M_KCOV_INFO, "kcovinfo", "KCOV info type")
 
static int kcov_alloc (struct kcov_info *info, size_t entries)
 
static void kcov_free (struct kcov_info *info)
 
static void kcov_init (const void *unused)
 
 SYSCTL_NODE (_kern, OID_AUTO, kcov, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "Kernel coverage")
 
 SYSCTL_UINT (_kern_kcov, OID_AUTO, max_entries, CTLFLAG_RW, &kcov_max_entries, 0, "Maximum number of entries in the kcov buffer")
 
static struct kcov_info *__nosanitizeaddress __nosanitizememory get_kinfo (struct thread *td)
 
static void __nosanitizeaddress __nosanitizememory trace_pc (uintptr_t ret)
 
static bool __nosanitizeaddress __nosanitizememory trace_cmp (uint64_t type, uint64_t arg1, uint64_t arg2, uint64_t ret)
 
static void kcov_mmap_cleanup (void *arg)
 
static int kcov_open (struct cdev *dev, int oflags, int devtype, struct thread *td)
 
static int kcov_close (struct cdev *dev, int fflag, int devtype, struct thread *td)
 
static int kcov_mmap_single (struct cdev *dev, vm_ooffset_t *offset, vm_size_t size, struct vm_object **object, int nprot)
 
static int kcov_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int fflag __unused, struct thread *td)
 
static void kcov_thread_dtor (void *arg __unused, struct thread *td)
 
 SYSINIT (kcovdev, SI_SUB_LAST, SI_ORDER_ANY, kcov_init, NULL)
 

Variables

static d_open_t kcov_open
 
static d_close_t kcov_close
 
static d_mmap_single_t kcov_mmap_single
 
static d_ioctl_t kcov_ioctl
 
static struct cdevsw kcov_cdevsw
 
static u_int kcov_max_entries = KCOV_MAXENTRIES
 
static struct mtx kcov_lock
 
static int active_count
 

Macro Definition Documentation

◆ KCOV_ELEMENT_SIZE

#define KCOV_ELEMENT_SIZE   sizeof(uint64_t)

Definition at line 71 of file kern_kcov.c.

Enumeration Type Documentation

◆ kcov_state_t

Enumerator
KCOV_STATE_INVALID 
KCOV_STATE_OPEN 
KCOV_STATE_READY 
KCOV_STATE_RUNNING 
KCOV_STATE_DYING 

Definition at line 112 of file kern_kcov.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ get_kinfo()

static struct kcov_info *__nosanitizeaddress __nosanitizememory get_kinfo ( struct thread *  td)
static

Definition at line 169 of file kern_kcov.c.

References KCOV_STATE_RUNNING, and kcov_info::state.

Referenced by trace_cmp(), and trace_pc().

Here is the caller graph for this function:

◆ kcov_alloc()

static int kcov_alloc ( struct kcov_info info,
size_t  entries 
)
static

Definition at line 364 of file kern_kcov.c.

References kcov_info::bufobj, kcov_info::bufsize, kcov_info::entries, KCOV_ELEMENT_SIZE, kcov_max_entries, KCOV_STATE_OPEN, kcov_info::kvaddr, and kcov_info::state.

Referenced by kcov_ioctl().

Here is the caller graph for this function:

◆ kcov_close()

static int kcov_close ( struct cdev *  dev,
int  fflag,
int  devtype,
struct thread *  td 
)
static

Definition at line 323 of file kern_kcov.c.

References KCOV_STATE_RUNNING, and kcov_info::state.

◆ kcov_free()

static void kcov_free ( struct kcov_info info)
static

Definition at line 402 of file kern_kcov.c.

References kcov_info::bufobj, kcov_info::bufsize, free(), and kcov_info::kvaddr.

Referenced by kcov_mmap_cleanup(), and kcov_thread_dtor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kcov_init()

static void kcov_init ( const void *  unused)
static

Definition at line 561 of file kern_kcov.c.

References kcov_cdevsw, kcov_lock, kcov_thread_dtor(), make_dev_s(), printf(), and thread_dtor().

Here is the call graph for this function:

◆ kcov_ioctl()

static int kcov_ioctl ( struct cdev *  dev,
u_long  cmd,
caddr_t  data,
int fflag  __unused,
struct thread *  td 
)
static

◆ kcov_mmap_cleanup()

static void kcov_mmap_cleanup ( void *  arg)
static

Definition at line 273 of file kern_kcov.c.

References kcov_free(), kcov_lock, KCOV_STATE_DYING, kcov_info::state, and kcov_info::thread.

Referenced by kcov_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kcov_mmap_single()

static int kcov_mmap_single ( struct cdev *  dev,
vm_ooffset_t *  offset,
vm_size_t  size,
struct vm_object **  object,
int  nprot 
)
static

◆ kcov_open()

static int kcov_open ( struct cdev *  dev,
int  oflags,
int  devtype,
struct thread *  td 
)
static

Definition at line 306 of file kern_kcov.c.

References kcov_mmap_cleanup(), KCOV_STATE_OPEN, malloc(), kcov_info::mode, kcov_info::state, and kcov_info::thread.

Here is the call graph for this function:

◆ kcov_thread_dtor()

static void kcov_thread_dtor ( void *arg  __unused,
struct thread *  td 
)
static

Definition at line 519 of file kern_kcov.c.

References active_count, cov_unregister_cmp(), cov_unregister_pc(), kcov_free(), kcov_lock, KCOV_STATE_DYING, KCOV_STATE_READY, kcov_info::state, and kcov_info::thread.

Referenced by kcov_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MALLOC_DEFINE()

MALLOC_DEFINE ( M_KCOV_INFO  ,
"kcovinfo"  ,
"KCOV info type  
)

◆ SYSCTL_NODE()

SYSCTL_NODE ( _kern  ,
OID_AUTO  ,
kcov  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
"Kernel coverage"   
)

◆ SYSCTL_UINT()

SYSCTL_UINT ( _kern_kcov  ,
OID_AUTO  ,
max_entries  ,
CTLFLAG_RW  ,
kcov_max_entries,
,
"Maximum number of entries in the kcov buffer"   
)

◆ SYSINIT()

SYSINIT ( kcovdev  ,
SI_SUB_LAST  ,
SI_ORDER_ANY  ,
kcov_init  ,
NULL   
)

◆ trace_cmp()

static bool __nosanitizeaddress __nosanitizememory trace_cmp ( uint64_t  type,
uint64_t  arg1,
uint64_t  arg2,
uint64_t  ret 
)
static

◆ trace_pc()

static void __nosanitizeaddress __nosanitizememory trace_pc ( uintptr_t  ret)
static

Definition at line 196 of file kern_kcov.c.

References buf, kcov_info::entries, get_kinfo(), kcov_info::kvaddr, and kcov_info::mode.

Referenced by __sanitizer_cov_trace_pc(), cov_register_pc(), and kcov_ioctl().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ active_count

int active_count
static

Definition at line 166 of file kern_kcov.c.

Referenced by kcov_ioctl(), and kcov_thread_dtor().

◆ kcov_cdevsw

struct cdevsw kcov_cdevsw
static
Initial value:
= {
.d_version = D_VERSION,
.d_open = kcov_open,
.d_close = kcov_close,
.d_mmap_single = kcov_mmap_single,
.d_ioctl = kcov_ioctl,
.d_name = "kcov",
}
static d_open_t kcov_open
Definition: kern_kcov.c:139
static d_ioctl_t kcov_ioctl
Definition: kern_kcov.c:142
static d_mmap_single_t kcov_mmap_single
Definition: kern_kcov.c:141
static d_close_t kcov_close
Definition: kern_kcov.c:140

Definition at line 148 of file kern_kcov.c.

Referenced by kcov_init().

◆ kcov_close

d_close_t kcov_close
static

Definition at line 140 of file kern_kcov.c.

◆ kcov_ioctl

d_ioctl_t kcov_ioctl
static

Definition at line 142 of file kern_kcov.c.

◆ kcov_lock

struct mtx kcov_lock
static

Definition at line 165 of file kern_kcov.c.

Referenced by kcov_init(), kcov_ioctl(), kcov_mmap_cleanup(), and kcov_thread_dtor().

◆ kcov_max_entries

u_int kcov_max_entries = KCOV_MAXENTRIES
static

Definition at line 160 of file kern_kcov.c.

Referenced by kcov_alloc().

◆ kcov_mmap_single

d_mmap_single_t kcov_mmap_single
static

Definition at line 141 of file kern_kcov.c.

◆ kcov_open

d_open_t kcov_open
static

Definition at line 139 of file kern_kcov.c.