This file is indexed.

/usr/share/systemtap/runtime/pmap-gen.c is in systemtap-common 2.3-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/* -*- linux-c -*- 
 * pmap API generator
 * Copyright (C) 2005-2008, 2012 Red Hat Inc.
 *
 * This file is part of systemtap, and is free software.  You can
 * redistribute it and/or modify it under the terms of the GNU General
 * Public License (GPL); either version 2, or (at your option) any
 * later version.
 */

/** @file pmap-gen.c
 * @brief Pmap function generator
 * This file is a template designed to be included as many times as
 * needed to generate the necessary pmap functions.  It is only included
 * indirectly by map-gen.c, so all the shared #defines are in place.
 */


/* returns 1 on match, 0 otherwise */
static int KEYSYM(pmap_key_cmp) (struct map_node *m1, struct map_node *m2)
{
	struct KEYSYM(map_node) *n1 = KEYSYM(get_map_node)(m1);
	struct KEYSYM(map_node) *n2 = KEYSYM(get_map_node)(m2);
		if (KEY1_EQ_P(n1->key1, n2->key1)
#if KEY_ARITY > 1
		    && KEY2_EQ_P(n1->key2, n2->key2)
#if KEY_ARITY > 2
		    && KEY3_EQ_P(n1->key3, n2->key3)
#if KEY_ARITY > 3
		    && KEY4_EQ_P(n1->key4, n2->key4)
#if KEY_ARITY > 4
		    && KEY5_EQ_P(n1->key5, n2->key5)
#if KEY_ARITY > 5
		    && KEY6_EQ_P(n1->key6, n2->key6)
#if KEY_ARITY > 6
		    && KEY7_EQ_P(n1->key7, n2->key7)
#if KEY_ARITY > 7
		    && KEY8_EQ_P(n1->key8, n2->key8)
#if KEY_ARITY > 8
		    && KEY9_EQ_P(n1->key9, n2->key9)
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
			)
			return 1;
		else
			return 0;
}

/* copy keys for m2 -> m1 */
static void KEYSYM(pmap_copy_keys) (struct map_node *m1, struct map_node *m2)
{
	struct KEYSYM(map_node) *dst = KEYSYM(get_map_node)(m1);
	struct KEYSYM(map_node) *src = KEYSYM(get_map_node)(m2);
#if KEY1_TYPE == STRING
	str_copy (dst->key1, src->key1); 
#else
	dst->key1 = src->key1;
#endif
#if KEY_ARITY > 1
#if KEY2_TYPE == STRING
	str_copy (dst->key2, src->key2); 
#else
	dst->key2 = src->key2;
#endif
#if KEY_ARITY > 2
#if KEY3_TYPE == STRING
	str_copy (dst->key3, src->key3); 
#else
	dst->key3 = src->key3;
#endif
#if KEY_ARITY > 3
#if KEY4_TYPE == STRING
	str_copy (dst->key4, src->key4); 
#else
	dst->key4 = src->key4;
#endif
#if KEY_ARITY > 4
#if KEY5_TYPE == STRING
	str_copy (dst->key5, src->key5); 
#else
	dst->key5 = src->key5;
#endif
#if KEY_ARITY > 5
#if KEY6_TYPE == STRING
	str_copy (dst->key6, src->key6); 
#else
	dst->key6 = src->key6;
#endif
#if KEY_ARITY > 6
#if KEY7_TYPE == STRING
	str_copy (dst->key7, src->key7); 
#else
	dst->key7 = src->key7;
#endif
#if KEY_ARITY > 7
#if KEY8_TYPE == STRING
	str_copy (dst->key8, src->key8); 
#else
	dst->key8 = src->key8;
#endif
#if KEY_ARITY > 8
#if KEY9_TYPE == STRING
	str_copy (dst->key9, src->key9); 
#else
	dst->key9 = src->key9;
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
}

/* update the keys and value of a map_node */
static void KEYSYM(pmap_update_node) (MAP m, struct map_node *m1, struct map_node *m2, int add)
{
	struct KEYSYM(map_node) *src, * dst = KEYSYM(get_map_node)(m1);

	if (!m2) {
		MAP_COPY_VAL(m, dst, NULLRET, 0);
		return;
	}

	src = KEYSYM(get_map_node)(m2);
	if (!add)
		KEYSYM(pmap_copy_keys)(m1, m2);
	MAP_COPY_VAL(m, dst, MAP_GET_VAL(src), add);
}

#if VALUE_TYPE == INT64 || VALUE_TYPE == STRING
static PMAP KEYSYM(_stp_pmap_new) (unsigned max_entries, int wrap)
{
	PMAP pmap = _stp_pmap_new (max_entries, wrap,
				   sizeof(struct KEYSYM(map_node)));
	return pmap;
}
#else
/*
 * _stp_pmap_new_key1_key2...val (num, wrap, HIST_LINEAR, start, end, interval) 
 * _stp_pmap_new_key1_key2...val (num, wrap, HIST_LOG)
 */
static PMAP
KEYSYM(_stp_pmap_new) (unsigned max_entries, int wrap, int htype, ...)
{
	int start=0, stop=0, interval=0;
	PMAP pmap;

	if (htype == HIST_LINEAR) {
		va_list ap;
		va_start (ap, htype);
		start = va_arg(ap, int);
		stop = va_arg(ap, int);
		interval = va_arg(ap, int);
		va_end (ap);
	}

	switch (htype) {
	case HIST_NONE:
		pmap = _stp_pmap_new_hstat (max_entries, wrap,
					    sizeof(struct KEYSYM(map_node)));
		break;
	case HIST_LOG:
		pmap = _stp_pmap_new_hstat_log (max_entries, wrap,
						sizeof(struct KEYSYM(map_node)));
		break;
	case HIST_LINEAR:
		pmap = _stp_pmap_new_hstat_linear (max_entries, wrap,
						   sizeof(struct KEYSYM(map_node)),
						   start, stop, interval);
		break;
	default:
		_stp_warn ("Unknown histogram type %d\n", htype);
		pmap = NULL;
	}

	return pmap;
}

#endif /* VALUE_TYPE */

static int KEYSYM(_stp_pmap_set) (PMAP pmap, ALLKEYSD(key), VSTYPE val)
{
	int res;
	MAP m = _stp_pmap_get_map (pmap, MAP_GET_CPU());
#ifdef NEED_MAP_LOCKS
	if (!MAP_TRYLOCK(m)) {
		MAP_PUT_CPU();
		return -3;
	}
#endif
	res = KEYSYM(__stp_map_set) (m, ALLKEYS(key), val, 0);
	MAP_UNLOCK(m);
        MAP_PUT_CPU();
	return res;
}

static int KEYSYM(_stp_pmap_add) (PMAP pmap, ALLKEYSD(key), VSTYPE val)
{
	int res;
	MAP m = _stp_pmap_get_map (pmap, MAP_GET_CPU());
#ifdef NEED_MAP_LOCKS
	if (!MAP_TRYLOCK(m)) {
		MAP_PUT_CPU();
		return -3;
	}
#endif
	res = KEYSYM(__stp_map_set) (m, ALLKEYS(key), val, 1);
	MAP_UNLOCK(m);
        MAP_PUT_CPU();
	return res;
}


static VALTYPE KEYSYM(_stp_pmap_get_cpu) (PMAP pmap, ALLKEYSD(key))
{
	unsigned int hv;
	struct mhlist_head *head;
	struct mhlist_node *e;
	struct KEYSYM(map_node) *n;
	VALTYPE res;
	MAP map;

	if (pmap == NULL)
		return NULLRET;

	map = _stp_pmap_get_map (pmap, MAP_GET_CPU());
#ifdef NEED_MAP_LOCKS
	if (!MAP_TRYLOCK(map)) {
		MAP_PUT_CPU();
		return NULLRET;
	}
#endif

	hv = KEYSYM(hash) (ALLKEYS(key));
	head = &map->hashes[hv];
	mhlist_for_each_entry(n, e, head, node.hnode) {
		if (KEY_EQ_P(n)) {
			res = MAP_GET_VAL(n);
			MAP_UNLOCK(map);
			MAP_PUT_CPU();
			return res;
		}
	}
	/* key not found */
	MAP_UNLOCK(map);
        MAP_PUT_CPU();
	return NULLRET;
}

static VALTYPE KEYSYM(_stp_pmap_get) (PMAP pmap, ALLKEYSD(key))
{
	unsigned int hv;
	int cpu, clear_agg = 0;
	struct mhlist_head *head, *ahead;
	struct mhlist_node *e;
	struct KEYSYM(map_node) *n;
	struct map_node *anode = NULL;
	MAP map, agg;

	if (pmap == NULL)
		return NULLRET;

	hv = KEYSYM(hash) (ALLKEYS(key));

	/* first look it up in the aggregation map */
	agg = _stp_pmap_get_agg(pmap);
	ahead = &agg->hashes[hv];
	mhlist_for_each_entry(n, e, ahead, node.hnode) {
		if (KEY_EQ_P(n)) {
			anode = &n->node;
			clear_agg = 1;
			break;
		}
	}

	/* now total each cpu */
	for_each_possible_cpu(cpu) {
		map = _stp_pmap_get_map (pmap, cpu);
#ifdef NEED_MAP_LOCKS
		if (!MAP_TRYLOCK(map))
			return NULLRET;
#endif

		head = &map->hashes[hv];
		mhlist_for_each_entry(n, e, head, node.hnode) {
			if (KEY_EQ_P(n)) {
				if (anode == NULL) {
					anode = _stp_new_agg(agg, ahead, &n->node,
							     KEYSYM(pmap_update_node));
				} else {
					if (clear_agg) {
						KEYSYM(pmap_update_node)(agg, anode, NULL, 0);
						clear_agg = 0;
					}
					KEYSYM(pmap_update_node)(agg, anode, &n->node, 1);
				}
			}
		}
		MAP_UNLOCK(map);
	}
	if (anode && !clear_agg) 
		return MAP_GET_VAL(KEYSYM(get_map_node)(anode));

	/* key not found */
	return NULLRET;
}

static MAP KEYSYM(_stp_pmap_agg) (PMAP pmap)
{
	return _stp_pmap_agg(pmap, KEYSYM(pmap_update_node),
			     KEYSYM(pmap_key_cmp));
}

static int KEYSYM(_stp_pmap_del) (PMAP pmap, ALLKEYSD(key))
{
	int res;
	MAP m = _stp_pmap_get_map (pmap, MAP_GET_CPU());
#ifdef NEED_MAP_LOCKS
	if (!MAP_TRYLOCK(m)) {
		MAP_PUT_CPU();
		return -1;
	}
#endif
	res = KEYSYM(_stp_map_del) (m, ALLKEYS(key));
	MAP_UNLOCK(m);
	MAP_PUT_CPU();
	return res;
}