aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/kcov/cdefs.go
blob: 1272360b9cd8935a5154e21d985404bac40b3bfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2025 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package kcov

// This file defines values required for KCOV ioctl calls. More information on
// the values and their semantics can be found in the kernel documentation under
// Documentation/dev-tools/kcov.rst, or at docs.kernel.org/dev-tools/kcov.html.

import "unsafe"

const (
	sizeofUintPtr = int(unsafe.Sizeof((*int)(nil)))

	iocNrBits   = 8
	iocTypeBits = 8
	iocSizeBits = 14
	iocDirBits  = 2

	iocNrShift   = 0
	iocTypeshift = iocNrShift + iocNrBits
	iocSizeShift = iocTypeshift + iocTypeBits
	iocDirShift  = iocSizeShift + iocSizeBits

	iocNone  = 0
	iocWrite = 1
	iocRead  = 2

	// kcovInitTrace initializes KCOV tracing.
	// #define kcovInitTrace _IOR('c', 1, unsigned long)
	kcovInitTrace uintptr = (iocRead << iocDirShift) |
		(unsafe.Sizeof(uint64(0)) << iocSizeShift) | ('c' << iocTypeshift) | (1 << iocNrShift) // 0x80086301.

	// kcovEnable enables kcov for the current thread.
	// #define kcovEnable _IO('c', 100)
	kcovEnable uintptr = (iocNone << iocDirShift) |
		(0 << iocSizeShift) | ('c' << iocTypeshift) | (100 << iocNrShift) // 0x6364.

	// kcovDisable disables kcov for the current thread.
	// #define kcovDisable _IO('c', 101)
	kcovDisable uintptr = (iocNone << iocDirShift) |
		(0 << iocSizeShift) | ('c' << iocTypeshift) | (101 << iocNrShift) // 0x6365.

	kcovTracePC  = 0
	kcovTraceCMP = 1
)