Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  This code provides functions to handle gcc's profiling data format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  introduced with gcc 4.7.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  This file is based heavily on gcc_3_4.c file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  For a better understanding, refer to gcc source:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  gcc/gcov-io.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  libgcc/libgcov.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  Uses gcc-internal data definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "gcov.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #if (__GNUC__ >= 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define GCOV_COUNTERS			8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #elif (__GNUC__ >= 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define GCOV_COUNTERS			9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #elif (__GNUC__ > 5) || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define GCOV_COUNTERS			10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #elif __GNUC__ == 4 && __GNUC_MINOR__ >= 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define GCOV_COUNTERS			9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define GCOV_COUNTERS			8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define GCOV_TAG_FUNCTION_LENGTH	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static struct gcov_info *gcov_info_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * struct gcov_ctr_info - information about counters for a single function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * @num: number of counter values for this type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * @values: array of counter values for this type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * This data is generated by gcc during compilation and doesn't change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * at run-time with the exception of the values array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) struct gcov_ctr_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	unsigned int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	gcov_type *values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * struct gcov_fn_info - profiling meta data per function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * @key: comdat key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * @ident: unique ident of function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * @lineno_checksum: function lineo_checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * @cfg_checksum: function cfg checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @ctrs: instrumented counters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * This data is generated by gcc during compilation and doesn't change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * at run-time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Information about a single function.  This uses the trailing array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * idiom. The number of counters is determined from the merge pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * array in gcov_info.  The key is used to detect which of a set of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * comdat functions was selected -- it points to the gcov_info object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * of the object file containing the selected comdat function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) struct gcov_fn_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	const struct gcov_info *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned int ident;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned int lineno_checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned int cfg_checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct gcov_ctr_info ctrs[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * struct gcov_info - profiling data per object file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * @version: gcov version magic indicating the gcc version used for compilation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * @next: list head for a singly-linked list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * @stamp: uniquifying time stamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * @filename: name of the associated gcov data file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @merge: merge functions (null for unused counter type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * @n_functions: number of instrumented functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * @functions: pointer to pointers to function information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * This data is generated by gcc during compilation and doesn't change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * at run-time with the exception of the next pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) struct gcov_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned int version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct gcov_info *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned int stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned int n_functions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct gcov_fn_info **functions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * gcov_info_filename - return info filename
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) const char *gcov_info_filename(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return info->filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * gcov_info_version - return info version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned int gcov_info_version(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return info->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * gcov_info_next - return next profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * Returns next gcov_info following @info or first gcov_info in the chain if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * @info is %NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct gcov_info *gcov_info_next(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return gcov_info_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return info->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * gcov_info_link - link/add profiling data set to the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void gcov_info_link(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	info->next = gcov_info_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	gcov_info_head = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * gcov_info_unlink - unlink/remove profiling data set from the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @prev: previous profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		prev->next = info->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		gcov_info_head = info->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * gcov_info_within_module - check if a profiling data set belongs to a module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * @mod: module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * Returns true if profiling data belongs module, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) bool gcov_info_within_module(struct gcov_info *info, struct module *mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return within_module((unsigned long)info, mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Symbolic links to be created for each profiling data file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) const struct gcov_link gcov_link[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	{ OBJ_TREE, "gcno" },	/* Link to .gcno file in $(objtree). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{ 0, NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * Determine whether a counter is active. Doesn't change at run-time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int counter_active(struct gcov_info *info, unsigned int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return info->merge[type] ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Determine number of active counters. Based on gcc magic. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static unsigned int num_counter_active(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	unsigned int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	for (i = 0; i < GCOV_COUNTERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		if (counter_active(info, i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			result++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * gcov_info_reset - reset profiling data to zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @info: profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) void gcov_info_reset(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct gcov_ctr_info *ci_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	unsigned int fi_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	unsigned int ct_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ci_ptr = info->functions[fi_idx]->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			if (!counter_active(info, ct_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			memset(ci_ptr->values, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 					sizeof(gcov_type) * ci_ptr->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			ci_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * gcov_info_is_compatible - check if profiling data can be added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * @info1: first profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * @info2: second profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * Returns non-zero if profiling data can be added, zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return (info1->stamp == info2->stamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * gcov_info_add - add up profiling data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * @dest: profiling data set to which data is added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * @source: profiling data set which is added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * Adds profiling counts of @source to @dest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) void gcov_info_add(struct gcov_info *dst, struct gcov_info *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct gcov_ctr_info *dci_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct gcov_ctr_info *sci_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	unsigned int fi_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	unsigned int ct_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	unsigned int val_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	for (fi_idx = 0; fi_idx < src->n_functions; fi_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		dci_ptr = dst->functions[fi_idx]->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		sci_ptr = src->functions[fi_idx]->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			if (!counter_active(src, ct_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			for (val_idx = 0; val_idx < sci_ptr->num; val_idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				dci_ptr->values[val_idx] +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 					sci_ptr->values[val_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			dci_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			sci_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * gcov_info_dup - duplicate profiling data set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * @info: profiling data set to duplicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * Return newly allocated duplicate on success, %NULL on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct gcov_info *gcov_info_dup(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct gcov_info *dup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct gcov_ctr_info *dci_ptr; /* dst counter info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct gcov_ctr_info *sci_ptr; /* src counter info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	unsigned int active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	unsigned int fi_idx; /* function info idx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	unsigned int ct_idx; /* counter type idx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	size_t fi_size; /* function info size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	size_t cv_size; /* counter values size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	dup = kmemdup(info, sizeof(*dup), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (!dup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	dup->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	dup->filename = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	dup->functions = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	dup->filename = kstrdup(info->filename, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!dup->filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	dup->functions = kcalloc(info->n_functions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 				 sizeof(struct gcov_fn_info *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (!dup->functions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	active = num_counter_active(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	fi_size = sizeof(struct gcov_fn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	fi_size += sizeof(struct gcov_ctr_info) * active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		dup->functions[fi_idx] = kzalloc(fi_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		if (!dup->functions[fi_idx])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		*(dup->functions[fi_idx]) = *(info->functions[fi_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		sci_ptr = info->functions[fi_idx]->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		dci_ptr = dup->functions[fi_idx]->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		for (ct_idx = 0; ct_idx < active; ct_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			cv_size = sizeof(gcov_type) * sci_ptr->num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			dci_ptr->values = vmalloc(cv_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			if (!dci_ptr->values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 				goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			dci_ptr->num = sci_ptr->num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			memcpy(dci_ptr->values, sci_ptr->values, cv_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			sci_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			dci_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	return dup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	gcov_info_free(dup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * gcov_info_free - release memory for profiling data set duplicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * @info: profiling data set duplicate to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) void gcov_info_free(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	unsigned int active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	unsigned int fi_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	unsigned int ct_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct gcov_ctr_info *ci_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (!info->functions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		goto free_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	active = num_counter_active(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		if (!info->functions[fi_idx])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		ci_ptr = info->functions[fi_idx]->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		for (ct_idx = 0; ct_idx < active; ct_idx++, ci_ptr++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			vfree(ci_ptr->values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		kfree(info->functions[fi_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) free_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	kfree(info->functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	kfree(info->filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #define ITER_STRIDE	PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * struct gcov_iterator - specifies current file position in logical records
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * @info: associated profiling data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * @buffer: buffer containing file data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * @size: size of buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * @pos: current position in file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct gcov_iterator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	struct gcov_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * store_gcov_u32 - store 32 bit number in gcov format to buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  * @buffer: target buffer or NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * @off: offset into the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * @v: value to be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * Number format defined by gcc: numbers are recorded in the 32 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * unsigned binary form of the endianness of the machine generating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * file. Returns the number of bytes stored. If @buffer is %NULL, doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * store anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static size_t store_gcov_u32(void *buffer, size_t off, u32 v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	u32 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		data = buffer + off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		*data = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return sizeof(*data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  * store_gcov_u64 - store 64 bit number in gcov format to buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * @buffer: target buffer or NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * @off: offset into the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * @v: value to be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * Number format defined by gcc: numbers are recorded in the 32 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * unsigned binary form of the endianness of the machine generating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * file. 64 bit numbers are stored as two 32 bit numbers, the low part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * first. Returns the number of bytes stored. If @buffer is %NULL, doesn't store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static size_t store_gcov_u64(void *buffer, size_t off, u64 v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	u32 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		data = buffer + off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		data[0] = (v & 0xffffffffUL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		data[1] = (v >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return sizeof(*data) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  * convert_to_gcda - convert profiling data set to gcda file format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * @buffer: the buffer to store file data or %NULL if no data should be stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  * @info: profiling data set to be converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * Returns the number of bytes that were/would have been stored into the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static size_t convert_to_gcda(char *buffer, struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct gcov_fn_info *fi_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	struct gcov_ctr_info *ci_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	unsigned int fi_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	unsigned int ct_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	unsigned int cv_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	size_t pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	/* File header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	pos += store_gcov_u32(buffer, pos, GCOV_DATA_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	pos += store_gcov_u32(buffer, pos, info->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	pos += store_gcov_u32(buffer, pos, info->stamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	for (fi_idx = 0; fi_idx < info->n_functions; fi_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		fi_ptr = info->functions[fi_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		/* Function record. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		pos += store_gcov_u32(buffer, pos, GCOV_TAG_FUNCTION_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		pos += store_gcov_u32(buffer, pos, fi_ptr->ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		pos += store_gcov_u32(buffer, pos, fi_ptr->lineno_checksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		pos += store_gcov_u32(buffer, pos, fi_ptr->cfg_checksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		ci_ptr = fi_ptr->ctrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		for (ct_idx = 0; ct_idx < GCOV_COUNTERS; ct_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			if (!counter_active(info, ct_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			/* Counter record. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			pos += store_gcov_u32(buffer, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 					      GCOV_TAG_FOR_COUNTER(ct_idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			pos += store_gcov_u32(buffer, pos, ci_ptr->num * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			for (cv_idx = 0; cv_idx < ci_ptr->num; cv_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 				pos += store_gcov_u64(buffer, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 						      ci_ptr->values[cv_idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			ci_ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  * gcov_iter_new - allocate and initialize profiling data iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)  * @info: profiling data set to be iterated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  * Return file iterator on success, %NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct gcov_iterator *gcov_iter_new(struct gcov_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	struct gcov_iterator *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	iter = kzalloc(sizeof(struct gcov_iterator), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	if (!iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	iter->info = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/* Dry-run to get the actual buffer size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	iter->size = convert_to_gcda(NULL, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	iter->buffer = vmalloc(iter->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (!iter->buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	convert_to_gcda(iter->buffer, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	return iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	kfree(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  * gcov_iter_get_info - return profiling data set for given file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  * @iter: file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) void gcov_iter_free(struct gcov_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	vfree(iter->buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	kfree(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  * gcov_iter_get_info - return profiling data set for given file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * @iter: file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct gcov_info *gcov_iter_get_info(struct gcov_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	return iter->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)  * gcov_iter_start - reset file iterator to starting position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  * @iter: file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) void gcov_iter_start(struct gcov_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	iter->pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)  * gcov_iter_next - advance file iterator to next logical record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  * @iter: file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)  * Return zero if new position is valid, non-zero if iterator has reached end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) int gcov_iter_next(struct gcov_iterator *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	if (iter->pos < iter->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		iter->pos += ITER_STRIDE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	if (iter->pos >= iter->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  * gcov_iter_write - write data for current pos to seq_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  * @iter: file iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  * @seq: seq_file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * Return zero on success, non-zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) int gcov_iter_write(struct gcov_iterator *iter, struct seq_file *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	if (iter->pos >= iter->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	len = ITER_STRIDE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (iter->pos + len > iter->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		len = iter->size - iter->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	seq_write(seq, iter->buffer + iter->pos, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }