1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * alloc_tag IOCTL API definition 4 * 5 * Copyright (C) 2026 Google, LLC. All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12 #ifndef _UAPI_ALLOC_TAG_H 13 #define _UAPI_ALLOC_TAG_H 14 15 #include <linux/types.h> 16 17 /* 18 * Function, file and module names often have the same prefixes, therefore 19 * when filtering by these criteria, we compare the last 64 characters to 20 * minimize the chances of name collisions 21 */ 22 #define ALLOCINFO_STR_SIZE 64 23 24 struct allocinfo_content_id { 25 __u64 id; 26 }; 27 28 struct allocinfo_tag { 29 /* Longer names are trimmed */ 30 char modname[ALLOCINFO_STR_SIZE]; 31 char function[ALLOCINFO_STR_SIZE]; 32 char filename[ALLOCINFO_STR_SIZE]; 33 __u64 lineno; 34 }; 35 36 /* The alignment ensures 32-bit compatible interfaces are not broken */ 37 struct allocinfo_counter { 38 __u64 bytes; 39 __u64 calls; 40 __u8 accurate; 41 __u8 pad[7]; 42 } __attribute__((aligned(8))); 43 44 struct allocinfo_tag_data { 45 struct allocinfo_tag tag; 46 struct allocinfo_counter counter; 47 }; 48 49 enum { 50 ALLOCINFO_FILTER_MODNAME, 51 ALLOCINFO_FILTER_FUNCTION, 52 ALLOCINFO_FILTER_FILENAME, 53 ALLOCINFO_FILTER_LINENO, 54 ALLOCINFO_FILTER_INACCURATE, 55 ALLOCINFO_FILTER_MIN_SIZE, 56 ALLOCINFO_FILTER_MAX_SIZE, 57 __ALLOCINFO_FILTER_LAST = ALLOCINFO_FILTER_MAX_SIZE 58 }; 59 60 #define ALLOCINFO_FILTER_MASK_MODNAME (1 << ALLOCINFO_FILTER_MODNAME) 61 #define ALLOCINFO_FILTER_MASK_FUNCTION (1 << ALLOCINFO_FILTER_FUNCTION) 62 #define ALLOCINFO_FILTER_MASK_FILENAME (1 << ALLOCINFO_FILTER_FILENAME) 63 #define ALLOCINFO_FILTER_MASK_LINENO (1 << ALLOCINFO_FILTER_LINENO) 64 #define ALLOCINFO_FILTER_MASK_INACCURATE (1 << ALLOCINFO_FILTER_INACCURATE) 65 #define ALLOCINFO_FILTER_MASK_MIN_SIZE (1 << ALLOCINFO_FILTER_MIN_SIZE) 66 #define ALLOCINFO_FILTER_MASK_MAX_SIZE (1 << ALLOCINFO_FILTER_MAX_SIZE) 67 68 #define ALLOCINFO_FILTER_MASKS \ 69 ((1 << (__ALLOCINFO_FILTER_LAST + 1)) - 1) 70 71 struct allocinfo_filter { 72 __u64 mask; /* bitmask of the filter fields used */ 73 struct allocinfo_tag fields; 74 __u64 min_size; 75 __u64 max_size; 76 /* filter criteria only; see allocinfo_counter.accurate for actual accuracy */ 77 __u64 inaccurate; 78 }; 79 80 struct allocinfo_get_at { 81 /* inputs */ 82 __u64 pos; 83 struct allocinfo_filter filter; 84 /* output */ 85 struct allocinfo_tag_data data; 86 }; 87 88 #define _ALLOCINFO_IOC_CONTENT_ID 0 89 #define _ALLOCINFO_IOC_GET_AT 1 90 #define _ALLOCINFO_IOC_GET_NEXT 2 91 92 #define ALLOCINFO_IOC_BASE 0xA6 93 #define ALLOCINFO_IOC_CONTENT_ID _IOR(ALLOCINFO_IOC_BASE, _ALLOCINFO_IOC_CONTENT_ID, \ 94 struct allocinfo_content_id) 95 #define ALLOCINFO_IOC_GET_AT _IOWR(ALLOCINFO_IOC_BASE, _ALLOCINFO_IOC_GET_AT, \ 96 struct allocinfo_get_at) 97 #define ALLOCINFO_IOC_GET_NEXT _IOR(ALLOCINFO_IOC_BASE, _ALLOCINFO_IOC_GET_NEXT, \ 98 struct allocinfo_tag_data) 99 100 #endif /* _UAPI_ALLOC_TAG_H */ 101