summaryrefslogtreecommitdiff
path: root/include/uapi/linux/alloc_tag.h
blob: e3ad94444864d5e4a2fcd0cf57334e98f188042f (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
 * alloc_tag IOCTL API definition
 *
 * Copyright (C) 2026 Google, LLC.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef _UAPI_ALLOC_TAG_H
#define _UAPI_ALLOC_TAG_H

#include <linux/types.h>

/*
 * Function, file and module names often have the same prefixes, therefore
 * when filtering by these criteria, we compare the last 64 characters to
 * minimize the chances of name collisions
 */
#define ALLOCINFO_STR_SIZE	64

struct allocinfo_content_id {
	__u64 id;
};

struct allocinfo_tag {
	/* Longer names are trimmed */
	char modname[ALLOCINFO_STR_SIZE];
	char function[ALLOCINFO_STR_SIZE];
	char filename[ALLOCINFO_STR_SIZE];
	__u64 lineno;
};

/* The alignment ensures 32-bit compatible interfaces are not broken */
struct allocinfo_counter {
	__u64 bytes;
	__u64 calls;
	__u8 accurate;
} __attribute__((aligned(8)));

struct allocinfo_tag_data {
	struct allocinfo_tag tag;
	struct allocinfo_counter counter;
};

enum {
	ALLOCINFO_FILTER_MODNAME,
	ALLOCINFO_FILTER_FUNCTION,
	ALLOCINFO_FILTER_FILENAME,
	ALLOCINFO_FILTER_LINENO,
	ALLOCINFO_FILTER_INACCURATE,
	ALLOCINFO_FILTER_MIN_SIZE,
	ALLOCINFO_FILTER_MAX_SIZE,
	__ALLOCINFO_FILTER_LAST = ALLOCINFO_FILTER_MAX_SIZE
};

#define ALLOCINFO_FILTER_MASK_MODNAME		(1 << ALLOCINFO_FILTER_MODNAME)
#define ALLOCINFO_FILTER_MASK_FUNCTION		(1 << ALLOCINFO_FILTER_FUNCTION)
#define ALLOCINFO_FILTER_MASK_FILENAME		(1 << ALLOCINFO_FILTER_FILENAME)
#define ALLOCINFO_FILTER_MASK_LINENO		(1 << ALLOCINFO_FILTER_LINENO)
#define ALLOCINFO_FILTER_MASK_INACCURATE	(1 << ALLOCINFO_FILTER_INACCURATE)
#define ALLOCINFO_FILTER_MASK_MIN_SIZE		(1 << ALLOCINFO_FILTER_MIN_SIZE)
#define ALLOCINFO_FILTER_MASK_MAX_SIZE		(1 << ALLOCINFO_FILTER_MAX_SIZE)

#define ALLOCINFO_FILTER_MASKS \
	((1 << (__ALLOCINFO_FILTER_LAST + 1)) - 1)

struct allocinfo_filter {
	__u64 mask; /* bitmask of the filter fields used */
	struct allocinfo_tag fields;
	__u64 min_size;
	__u64 max_size;
	/* filter criteria only; see allocinfo_counter.accurate for actual accuracy */
	__u64 inaccurate;
};

struct allocinfo_get_at {
	/* inputs */
	__u64 pos;
	struct allocinfo_filter filter;
	/* output */
	struct allocinfo_tag_data data;
};

#define _ALLOCINFO_IOC_CONTENT_ID	0
#define _ALLOCINFO_IOC_GET_AT		1
#define _ALLOCINFO_IOC_GET_NEXT		2

#define ALLOCINFO_IOC_BASE		0xA6
#define ALLOCINFO_IOC_CONTENT_ID	_IOR(ALLOCINFO_IOC_BASE, _ALLOCINFO_IOC_CONTENT_ID,	\
					     struct allocinfo_content_id)
#define ALLOCINFO_IOC_GET_AT		_IOWR(ALLOCINFO_IOC_BASE, _ALLOCINFO_IOC_GET_AT,	\
					      struct allocinfo_get_at)
#define ALLOCINFO_IOC_GET_NEXT		_IOR(ALLOCINFO_IOC_BASE, _ALLOCINFO_IOC_GET_NEXT,	\
					     struct allocinfo_tag_data)

#endif /* _UAPI_ALLOC_TAG_H */