This file is indexed.

/usr/src/lttng-modules-2.5.1/lib/bitfield.h is in lttng-modules-dkms 2.5.1-1.

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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#ifndef _BABELTRACE_BITFIELD_H
#define _BABELTRACE_BITFIELD_H

/*
 * BabelTrace
 *
 * Bitfields read/write functions.
 *
 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "../lttng-endian.h"

#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif

/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */
#define _bt_piecewise_rshift(_v, _shift)				\
({									\
	typeof(_v) ___v = (_v);						\
	typeof(_shift) ___shift = (_shift);				\
	unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1);	\
	unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \
									\
	for (; sb; sb--)						\
		___v >>= sizeof(___v) * CHAR_BIT - 1;			\
	___v >>= final;							\
})

#define _bt_piecewise_lshift(_v, _shift)				\
({									\
	typeof(_v) ___v = (_v);						\
	typeof(_shift) ___shift = (_shift);				\
	unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1);	\
	unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \
									\
	for (; sb; sb--)						\
		___v <<= sizeof(___v) * CHAR_BIT - 1;			\
	___v <<= final;							\
})

#define _bt_is_signed_type(type)	(((type)(-1)) < 0)

#define _bt_unsigned_cast(type, v)					\
({									\
	(sizeof(v) < sizeof(type)) ?					\
		((type) (v)) & (~(~(type) 0 << (sizeof(v) * CHAR_BIT))) : \
		(type) (v);						\
})

/*
 * bt_bitfield_write - write integer to a bitfield in native endianness
 *
 * Save integer to the bitfield, which starts at the "start" bit, has "len"
 * bits.
 * The inside of a bitfield is from high bits to low bits.
 * Uses native endianness.
 * For unsigned "v", pad MSB with 0 if bitfield is larger than v.
 * For signed "v", sign-extend v if bitfield is larger than v.
 *
 * On little endian, bytes are placed from the less significant to the most
 * significant. Also, consecutive bitfields are placed from lower bits to higher
 * bits.
 *
 * On big endian, bytes are places from most significant to less significant.
 * Also, consecutive bitfields are placed from higher to lower bits.
 */

#define _bt_bitfield_write_le(_ptr, type, _start, _length, _v)		\
do {									\
	typeof(_v) __v = (_v);						\
	type *__ptr = (void *) (_ptr);					\
	unsigned long __start = (_start), __length = (_length);		\
	type mask, cmask;						\
	unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */	\
	unsigned long start_unit, end_unit, this_unit;			\
	unsigned long end, cshift; /* cshift is "complement shift" */	\
									\
	if (!__length)							\
		break;							\
									\
	end = __start + __length;					\
	start_unit = __start / ts;					\
	end_unit = (end + (ts - 1)) / ts;				\
									\
	/* Trim v high bits */						\
	if (__length < sizeof(__v) * CHAR_BIT)				\
		__v &= ~((~(typeof(__v)) 0) << __length);		\
									\
	/* We can now append v with a simple "or", shift it piece-wise */ \
	this_unit = start_unit;						\
	if (start_unit == end_unit - 1) {				\
		mask = ~((~(type) 0) << (__start % ts));		\
		if (end % ts)						\
			mask |= (~(type) 0) << (end % ts);		\
		cmask = (type) __v << (__start % ts);			\
		cmask &= ~mask;						\
		__ptr[this_unit] &= mask;				\
		__ptr[this_unit] |= cmask;				\
		break;							\
	}								\
	if (__start % ts) {						\
		cshift = __start % ts;					\
		mask = ~((~(type) 0) << cshift);			\
		cmask = (type) __v << cshift;				\
		cmask &= ~mask;						\
		__ptr[this_unit] &= mask;				\
		__ptr[this_unit] |= cmask;				\
		__v = _bt_piecewise_rshift(__v, ts - cshift);		\
		__start += ts - cshift;					\
		this_unit++;						\
	}								\
	for (; this_unit < end_unit - 1; this_unit++) {			\
		__ptr[this_unit] = (type) __v;				\
		__v = _bt_piecewise_rshift(__v, ts);			\
		__start += ts;						\
	}								\
	if (end % ts) {							\
		mask = (~(type) 0) << (end % ts);			\
		cmask = (type) __v;					\
		cmask &= ~mask;						\
		__ptr[this_unit] &= mask;				\
		__ptr[this_unit] |= cmask;				\
	} else								\
		__ptr[this_unit] = (type) __v;				\
} while (0)

#define _bt_bitfield_write_be(_ptr, type, _start, _length, _v)		\
do {									\
	typeof(_v) __v = (_v);						\
	type *__ptr = (void *) (_ptr);					\
	unsigned long __start = (_start), __length = (_length);		\
	type mask, cmask;						\
	unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */	\
	unsigned long start_unit, end_unit, this_unit;			\
	unsigned long end, cshift; /* cshift is "complement shift" */	\
									\
	if (!__length)							\
		break;							\
									\
	end = __start + __length;					\
	start_unit = __start / ts;					\
	end_unit = (end + (ts - 1)) / ts;				\
									\
	/* Trim v high bits */						\
	if (__length < sizeof(__v) * CHAR_BIT)				\
		__v &= ~((~(typeof(__v)) 0) << __length);		\
									\
	/* We can now append v with a simple "or", shift it piece-wise */ \
	this_unit = end_unit - 1;					\
	if (start_unit == end_unit - 1) {				\
		mask = ~((~(type) 0) << ((ts - (end % ts)) % ts));	\
		if (__start % ts)					\
			mask |= (~((type) 0)) << (ts - (__start % ts));	\
		cmask = (type) __v << ((ts - (end % ts)) % ts);		\
		cmask &= ~mask;						\
		__ptr[this_unit] &= mask;				\
		__ptr[this_unit] |= cmask;				\
		break;							\
	}								\
	if (end % ts) {							\
		cshift = end % ts;					\
		mask = ~((~(type) 0) << (ts - cshift));			\
		cmask = (type) __v << (ts - cshift);			\
		cmask &= ~mask;						\
		__ptr[this_unit] &= mask;				\
		__ptr[this_unit] |= cmask;				\
		__v = _bt_piecewise_rshift(__v, cshift);		\
		end -= cshift;						\
		this_unit--;						\
	}								\
	for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \
		__ptr[this_unit] = (type) __v;				\
		__v = _bt_piecewise_rshift(__v, ts);			\
		end -= ts;						\
	}								\
	if (__start % ts) {						\
		mask = (~(type) 0) << (ts - (__start % ts));		\
		cmask = (type) __v;					\
		cmask &= ~mask;						\
		__ptr[this_unit] &= mask;				\
		__ptr[this_unit] |= cmask;				\
	} else								\
		__ptr[this_unit] = (type) __v;				\
} while (0)

/*
 * bt_bitfield_write - write integer to a bitfield in native endianness
 * bt_bitfield_write_le - write integer to a bitfield in little endian
 * bt_bitfield_write_be - write integer to a bitfield in big endian
 */

#if (__BYTE_ORDER == __LITTLE_ENDIAN)

#define bt_bitfield_write(ptr, type, _start, _length, _v)		\
	_bt_bitfield_write_le(ptr, type, _start, _length, _v)

#define bt_bitfield_write_le(ptr, type, _start, _length, _v)		\
	_bt_bitfield_write_le(ptr, type, _start, _length, _v)
	
#define bt_bitfield_write_be(ptr, type, _start, _length, _v)		\
	_bt_bitfield_write_be(ptr, unsigned char, _start, _length, _v)

#elif (__BYTE_ORDER == __BIG_ENDIAN)

#define bt_bitfield_write(ptr, type, _start, _length, _v)		\
	_bt_bitfield_write_be(ptr, type, _start, _length, _v)

#define bt_bitfield_write_le(ptr, type, _start, _length, _v)		\
	_bt_bitfield_write_le(ptr, unsigned char, _start, _length, _v)
	
#define bt_bitfield_write_be(ptr, type, _start, _length, _v)		\
	_bt_bitfield_write_be(ptr, type, _start, _length, _v)

#else /* (BYTE_ORDER == PDP_ENDIAN) */

#error "Byte order not supported"

#endif

#define _bt_bitfield_read_le(_ptr, type, _start, _length, _vptr)	\
do {									\
	typeof(*(_vptr)) *__vptr = (_vptr);				\
	typeof(*__vptr) __v;						\
	type *__ptr = (void *) (_ptr);					\
	unsigned long __start = (_start), __length = (_length);		\
	type mask, cmask;						\
	unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */	\
	unsigned long start_unit, end_unit, this_unit;			\
	unsigned long end, cshift; /* cshift is "complement shift" */	\
									\
	if (!__length) {						\
		*__vptr = 0;						\
		break;							\
	}								\
									\
	end = __start + __length;					\
	start_unit = __start / ts;					\
	end_unit = (end + (ts - 1)) / ts;				\
									\
	this_unit = end_unit - 1;					\
	if (_bt_is_signed_type(typeof(__v))				\
	    && (__ptr[this_unit] & ((type) 1 << ((end % ts ? : ts) - 1)))) \
		__v = ~(typeof(__v)) 0;					\
	else								\
		__v = 0;						\
	if (start_unit == end_unit - 1) {				\
		cmask = __ptr[this_unit];				\
		cmask >>= (__start % ts);				\
		if ((end - __start) % ts) {				\
			mask = ~((~(type) 0) << (end - __start));	\
			cmask &= mask;					\
		}							\
		__v = _bt_piecewise_lshift(__v, end - __start);		\
		__v |= _bt_unsigned_cast(typeof(__v), cmask);		\
		*__vptr = __v;						\
		break;							\
	}								\
	if (end % ts) {							\
		cshift = end % ts;					\
		mask = ~((~(type) 0) << cshift);			\
		cmask = __ptr[this_unit];				\
		cmask &= mask;						\
		__v = _bt_piecewise_lshift(__v, cshift);		\
		__v |= _bt_unsigned_cast(typeof(__v), cmask);		\
		end -= cshift;						\
		this_unit--;						\
	}								\
	for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \
		__v = _bt_piecewise_lshift(__v, ts);			\
		__v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\
		end -= ts;						\
	}								\
	if (__start % ts) {						\
		mask = ~((~(type) 0) << (ts - (__start % ts)));		\
		cmask = __ptr[this_unit];				\
		cmask >>= (__start % ts);				\
		cmask &= mask;						\
		__v = _bt_piecewise_lshift(__v, ts - (__start % ts));	\
		__v |= _bt_unsigned_cast(typeof(__v), cmask);		\
	} else {							\
		__v = _bt_piecewise_lshift(__v, ts);			\
		__v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\
	}								\
	*__vptr = __v;							\
} while (0)

#define _bt_bitfield_read_be(_ptr, type, _start, _length, _vptr)	\
do {									\
	typeof(*(_vptr)) *__vptr = (_vptr);				\
	typeof(*__vptr) __v;						\
	type *__ptr = (void *) (_ptr);					\
	unsigned long __start = (_start), __length = (_length);		\
	type mask, cmask;						\
	unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */	\
	unsigned long start_unit, end_unit, this_unit;			\
	unsigned long end, cshift; /* cshift is "complement shift" */	\
									\
	if (!__length) {						\
		*__vptr = 0;						\
		break;							\
	}								\
									\
	end = __start + __length;					\
	start_unit = __start / ts;					\
	end_unit = (end + (ts - 1)) / ts;				\
									\
	this_unit = start_unit;						\
	if (_bt_is_signed_type(typeof(__v))				\
	    && (__ptr[this_unit] & ((type) 1 << (ts - (__start % ts) - 1)))) \
		__v = ~(typeof(__v)) 0;					\
	else								\
		__v = 0;						\
	if (start_unit == end_unit - 1) {				\
		cmask = __ptr[this_unit];				\
		cmask >>= (ts - (end % ts)) % ts;			\
		if ((end - __start) % ts) {				\
			mask = ~((~(type) 0) << (end - __start));	\
			cmask &= mask;					\
		}							\
		__v = _bt_piecewise_lshift(__v, end - __start);		\
		__v |= _bt_unsigned_cast(typeof(__v), cmask);		\
		*__vptr = __v;						\
		break;							\
	}								\
	if (__start % ts) {						\
		cshift = __start % ts;					\
		mask = ~((~(type) 0) << (ts - cshift));			\
		cmask = __ptr[this_unit];				\
		cmask &= mask;						\
		__v = _bt_piecewise_lshift(__v, ts - cshift);		\
		__v |= _bt_unsigned_cast(typeof(__v), cmask);		\
		__start += ts - cshift;					\
		this_unit++;						\
	}								\
	for (; this_unit < end_unit - 1; this_unit++) {			\
		__v = _bt_piecewise_lshift(__v, ts);			\
		__v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\
		__start += ts;						\
	}								\
	if (end % ts) {							\
		mask = ~((~(type) 0) << (end % ts));			\
		cmask = __ptr[this_unit];				\
		cmask >>= ts - (end % ts);				\
		cmask &= mask;						\
		__v = _bt_piecewise_lshift(__v, end % ts);		\
		__v |= _bt_unsigned_cast(typeof(__v), cmask);		\
	} else {							\
		__v = _bt_piecewise_lshift(__v, ts);			\
		__v |= _bt_unsigned_cast(typeof(__v), __ptr[this_unit]);\
	}								\
	*__vptr = __v;							\
} while (0)

/*
 * bt_bitfield_read - read integer from a bitfield in native endianness
 * bt_bitfield_read_le - read integer from a bitfield in little endian
 * bt_bitfield_read_be - read integer from a bitfield in big endian
 */

#if (__BYTE_ORDER == __LITTLE_ENDIAN)

#define bt_bitfield_read(_ptr, type, _start, _length, _vptr)		\
	_bt_bitfield_read_le(_ptr, type, _start, _length, _vptr)

#define bt_bitfield_read_le(_ptr, type, _start, _length, _vptr)		\
	_bt_bitfield_read_le(_ptr, type, _start, _length, _vptr)
	
#define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr)		\
	_bt_bitfield_read_be(_ptr, unsigned char, _start, _length, _vptr)

#elif (__BYTE_ORDER == __BIG_ENDIAN)

#define bt_bitfield_read(_ptr, type, _start, _length, _vptr)		\
	_bt_bitfield_read_be(_ptr, type, _start, _length, _vptr)

#define bt_bitfield_read_le(_ptr, type, _start, _length, _vptr)		\
	_bt_bitfield_read_le(_ptr, unsigned char, _start, _length, _vptr)
	
#define bt_bitfield_read_be(_ptr, type, _start, _length, _vptr)		\
	_bt_bitfield_read_be(_ptr, type, _start, _length, _vptr)

#else /* (__BYTE_ORDER == __PDP_ENDIAN) */

#error "Byte order not supported"

#endif

#endif /* _BABELTRACE_BITFIELD_H */