--- /dev/null
+BabelTrace - Trace Format Babel Tower
+Mathieu Desnoyers, EfficiOS Inc.
+September 2010
+
+This project provides trace read and write libraries, as well as a trace
+converter. A plugin can be created for any trace format to allow its conversion
+to/from another trace format.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <ctf/ctf-types.h>
+#include <babeltrace/ctf/types.h>
#include <stdint.h>
#include <glib.h>
* Reference: ISO C99 standard 5.2.4
*/
-#include <ctf/ctf-types.h>
+#include <babeltrace/ctf/types.h>
#include <glib.h>
#include <float.h> /* C99 floating point definitions */
#include <endian.h>
}
/* sign */
- tmp.u = bitfield_unsigned_read(ptr, srcpos.sign_start, 1,
- src->byte_order);
- bitfield_unsigned_write(&u.bits, destpos.sign_start, 1,
- dest->byte_order, tmp.u);
+ tmp.u = ctf_bitfield_unsigned_read(ptr, srcpos.sign_start, 1,
+ src->byte_order);
+ ctf_bitfield_unsigned_write(&u.bits, destpos.sign_start, 1,
+ dest->byte_order, tmp.u);
/* mantissa (without leading 1). No sign extend. */
- tmp.u = bitfield_unsigned_read(ptr, srcpos.mantissa_start,
- src->mantissa_len - 1, src->byte_order);
- bitfield_unsigned_write(&u.bits, destpos.mantissa_start,
- dest->mantissa_len - 1, dest->byte_order, tmp.u);
+ tmp.u = ctf_bitfield_unsigned_read(ptr, srcpos.mantissa_start,
+ src->mantissa_len - 1,
+ src->byte_order);
+ ctf_bitfield_unsigned_write(&u.bits, destpos.mantissa_start,
+ dest->mantissa_len - 1, dest->byte_order,
+ tmp.u);
/* exponent, with sign-extend. */
- tmp.s = bitfield_signed_read(ptr, srcpos.exp_start, src->exp_len,
- src->byte_order);
- bitfield_signed_write(&u.bits, destpos.exp_start, dest->exp_len,
- dest->byte_order, tmp.s);
+ tmp.s = ctf_bitfield_signed_read(ptr, srcpos.exp_start, src->exp_len,
+ src->byte_order);
+ ctf_bitfield_signed_write(&u.bits, destpos.exp_start, dest->exp_len,
+ dest->byte_order, tmp.s);
}
double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
.byte_order = BYTE_ORDER,
};
- float_copy(&u.bits, &dest, ptr, src);
+ ctf_float_copy(&u.bits, &dest, ptr, src);
return u.v;
}
if (!ptr)
goto end;
u.v = v;
- float_copy(ptr, dest, &u.bits, &src);
+ ctf_float_copy(ptr, dest, &u.bits, &src);
end:
return len;
}
.byte_order = BYTE_ORDER,
};
- float_copy(&u.bits, &dest, ptr, src);
+ ctf_float_copy(&u.bits, &dest, ptr, src);
return u.v;
}
if (!ptr)
goto end;
u.v = v;
- float_copy(ptr, dest, &u.bits, &src);
+ ctf_float_copy(ptr, dest, &u.bits, &src);
end:
return len;
}
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <ctf/ctf-types.h>
+#include <babeltrace/ctf/types.h>
#include <string.h>
size_t string_copy(char *dest, const char *src)
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <ctf/ctf-types.h>
+#include <babeltrace/ctf/types.h>
#include <glib.h>
--- /dev/null
+#ifndef _BABELTRACE_ALIGN_H
+#define _BABELTRACE_ALIGN_H
+
+/*
+ * BabelTrace align.h - alignment header
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <ctf/compiler.h>
+
+#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a))
+#define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
+#define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
+#define PTR_ALIGN_FLOOR(p, a) \
+ ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
+#define IS_ALIGNED(x, a) (((x) & ((typeof(x)) (a) - 1)) == 0)
+
+/*
+ * Align pointer on natural object alignment.
+ */
+#define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
+#define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
+
+/**
+ * offset_align - Calculate the offset needed to align an object on its natural
+ * alignment towards higher addresses.
+ * @align_drift: object offset from an "alignment"-aligned address.
+ * @alignment: natural object alignment. Must be non-zero, power of 2.
+ *
+ * Returns the offset that must be added to align towards higher
+ * addresses.
+ */
+#define offset_align(align_drift, alignment) \
+ ({ \
+ MAYBE_BUILD_BUG_ON((alignment) == 0 \
+ || ((alignment) & ((alignment) - 1))); \
+ (((alignment) - (align_drift)) & ((alignment) - 1)); \
+ })
+
+/**
+ * offset_align_floor - Calculate the offset needed to align an object
+ * on its natural alignment towards lower addresses.
+ * @align_drift: object offset from an "alignment"-aligned address.
+ * @alignment: natural object alignment. Must be non-zero, power of 2.
+ *
+ * Returns the offset that must be substracted to align towards lower addresses.
+ */
+#define offset_align_floor(align_drift, alignment) \
+ ({ \
+ MAYBE_BUILD_BUG_ON((alignment) == 0 \
+ || ((alignment) & ((alignment) - 1))); \
+ (((align_drift) - (alignment)) & ((alignment) - 1); \
+ })
+
+#endif /* _BABELTRACE_ALIGN_H */
--- /dev/null
+#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.
+ */
+
+#include <stdint.h> /* C99 5.2.4.2 Numerical limits */
+#include <limits.h> /* C99 5.2.4.2 Numerical limits */
+#include <endian.h> /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */
+#include <assert.h>
+
+/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */
+#define _bt_piecewise_rshift(v, shift) \
+({ \
+ unsigned long sb = (shift) / (sizeof(v) * CHAR_BIT - 1); \
+ unsigned long final = (shift) % (sizeof(v) * CHAR_BIT - 1); \
+ typeof(v) _v = (v); \
+ \
+ for (; sb; sb--) \
+ _v >>= sizeof(v) * CHAR_BIT - 1; \
+ _v >>= final; \
+})
+
+#define _bt_piecewise_lshift(v, shift) \
+({ \
+ unsigned long sb = (shift) / (sizeof(v) * CHAR_BIT - 1); \
+ unsigned long final = (shift) % (sizeof(v) * CHAR_BIT - 1); \
+ typeof(v) _v = (v); \
+ \
+ 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, _start, _length, _v) \
+do { \
+ typeof(_v) v = (_v); \
+ typeof(*(ptr)) mask, cmask; \
+ unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
+ unsigned long start = (_start), length = (_length); \
+ 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 = ~((~(typeof(*(ptr))) 0) << (start % ts)); \
+ if (end % ts) \
+ mask |= (~(typeof(*(ptr))) 0) << (end % ts); \
+ cmask = (typeof(*(ptr))) v << (start % ts); \
+ cmask &= ~mask; \
+ (ptr)[this_unit] &= mask; \
+ (ptr)[this_unit] |= cmask; \
+ break; \
+ } \
+ if (start % ts) { \
+ cshift = start % ts; \
+ mask = ~((~(typeof(*(ptr))) 0) << cshift); \
+ cmask = (typeof(*(ptr))) 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] = (typeof(*(ptr))) v; \
+ v = _bt_piecewise_rshift(v, ts); \
+ start += ts; \
+ } \
+ if (end % ts) { \
+ mask = (~(typeof(*(ptr))) 0) << (end % ts); \
+ cmask = (typeof(*(ptr))) v; \
+ cmask &= ~mask; \
+ (ptr)[this_unit] &= mask; \
+ (ptr)[this_unit] |= cmask; \
+ } else \
+ (ptr)[this_unit] = (typeof(*(ptr))) v; \
+} while (0)
+
+#define _bt_bitfield_write_be(ptr, _start, _length, _v) \
+do { \
+ typeof(_v) v = (_v); \
+ typeof(*(ptr)) mask, cmask; \
+ unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
+ unsigned long start = _start, length = _length; \
+ 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 = ~((~(typeof(*(ptr))) 0) << ((ts - (end % ts)) % ts)); \
+ if (start % ts) \
+ mask |= (~((typeof(*(ptr))) 0)) << (ts - (start % ts)); \
+ cmask = (typeof(*(ptr))) v << ((ts - (end % ts)) % ts); \
+ cmask &= ~mask; \
+ (ptr)[this_unit] &= mask; \
+ (ptr)[this_unit] |= cmask; \
+ break; \
+ } \
+ if (end % ts) { \
+ cshift = end % ts; \
+ mask = ~((~(typeof(*(ptr))) 0) << (ts - cshift)); \
+ cmask = (typeof(*(ptr))) 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] = (typeof(*(ptr))) v; \
+ v = _bt_piecewise_rshift(v, ts); \
+ end -= ts; \
+ } \
+ if (start % ts) { \
+ mask = (~(typeof(*(ptr))) 0) << (ts - (start % ts)); \
+ cmask = (typeof(*(ptr))) v; \
+ cmask &= ~mask; \
+ (ptr)[this_unit] &= mask; \
+ (ptr)[this_unit] |= cmask; \
+ } else \
+ (ptr)[this_unit] = (typeof(*(ptr))) 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, _start, _length, _v) \
+ _bt_bitfield_write_le(ptr, _start, _length, _v)
+
+#define bt_bitfield_write_le(ptr, _start, _length, _v) \
+ _bt_bitfield_write_le(ptr, _start, _length, _v)
+
+#define bt_bitfield_write_be(ptr, _start, _length, _v) \
+ _bt_bitfield_write_be((unsigned char *) (ptr), _start, _length, _v)
+
+#elif (BYTE_ORDER == BIG_ENDIAN)
+
+#define bt_bitfield_write(ptr, _start, _length, _v) \
+ _bt_bitfield_write_be(ptr, _start, _length, _v)
+
+#define bt_bitfield_write_le(ptr, _start, _length, _v) \
+ _bt_bitfield_write_le((unsigned char *) (ptr), _start, _length, _v)
+
+#define bt_bitfield_write_be(ptr, _start, _length, _v) \
+ _bt_bitfield_write_be(ptr, _start, _length, _v)
+
+#else /* (BYTE_ORDER == PDP_ENDIAN) */
+
+#error "Byte order not supported"
+
+#endif
+
+#define _bt_bitfield_read_le(ptr, _start, _length, vptr) \
+do { \
+ typeof(*(vptr)) v; \
+ typeof(*(ptr)) mask, cmask; \
+ unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
+ unsigned long start = _start, length = _length; \
+ 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] & ((typeof(*(ptr))) 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 = ~((~(typeof(*(ptr))) 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 = ~((~(typeof(*(ptr))) 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 = ~((~(typeof(*(ptr))) 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, _start, _length, vptr) \
+do { \
+ typeof(*(vptr)) v; \
+ typeof(*(ptr)) mask, cmask; \
+ unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
+ unsigned long start = _start, length = _length; \
+ 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] & ((typeof(*(ptr))) 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 = ~((~(typeof(*(ptr))) 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) { \
+ mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \
+ cmask = (ptr)[this_unit]; \
+ cmask &= mask; \
+ v = _bt_piecewise_lshift(v, ts - (start % ts)); \
+ v |= _bt_unsigned_cast(typeof(v), cmask); \
+ start += ts - (start % ts); \
+ 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 = ~((~(typeof(*(ptr))) 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, _start, _length, _vptr) \
+ _bt_bitfield_read_le(ptr, _start, _length, _vptr)
+
+#define bt_bitfield_read_le(ptr, _start, _length, _vptr) \
+ _bt_bitfield_read_le(ptr, _start, _length, _vptr)
+
+#define bt_bitfield_read_be(ptr, _start, _length, _vptr) \
+ _bt_bitfield_read_be((const unsigned char *) (ptr), _start, _length, _vptr)
+
+#elif (BYTE_ORDER == BIG_ENDIAN)
+
+#define bt_bitfield_read(ptr, _start, _length, _vptr) \
+ _bt_bitfield_read_be(ptr, _start, _length, _vptr)
+
+#define bt_bitfield_read_le(ptr, _start, _length, _vptr) \
+ _bt_bitfield_read_le((const unsigned char *) (ptr), _start, _length, _vptr)
+
+#define bt_bitfield_read_be(ptr, _start, _length, _vptr) \
+ _bt_bitfield_read_be(ptr, _start, _length, _vptr)
+
+#else /* (BYTE_ORDER == PDP_ENDIAN) */
+
+#error "Byte order not supported"
+
+#endif
+
+#endif /* _BABELTRACE_BITFIELD_H */
--- /dev/null
+#ifndef _BABELTRACE_COMPILER_H
+#define _BABELTRACE_COMPILER_H
+
+#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
+
+#endif /* _BABELTRACE_COMPILER_H */
--- /dev/null
+#ifndef _BABELTRACE_CTF_TYPES_BITFIELD_H
+#define _BABELTRACE_CTF_TYPES_BITFIELD_H
+
+/*
+ * Common Trace Format
+ *
+ * Bitfields read/write functions.
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <ctf/bitfield.h>
+#include <endian.h>
+
+static inline
+uint64_t ctf_bitfield_unsigned_read(const unsigned char *ptr,
+ unsigned long start, unsigned long len,
+ int byte_order)
+{
+ uint64_t v;
+
+ if (byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_read_le(ptr, start, len, &v);
+ else
+ ctf_bitfield_read_be(ptr, start, len, &v);
+ return v;
+}
+
+static inline
+int64_t ctf_bitfield_signed_read(const unsigned char *ptr,
+ unsigned long start, unsigned long len,
+ int byte_order)
+{
+ int64_t v;
+
+ if (byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_read_le(ptr, start, len, &v);
+ else
+ ctf_bitfield_read_be(ptr, start, len, &v);
+ return v;
+}
+
+static inline
+size_t ctf_bitfield_unsigned_write(unsigned char *ptr,
+ unsigned long start, unsigned long len,
+ int byte_order, uint64_t v)
+{
+ if (!ptr)
+ goto end;
+ if (byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_write_le(ptr, start, len, v);
+ else
+ ctf_bitfield_write_be(ptr, start, len, v);
+end:
+ return len;
+}
+
+static inline
+size_t ctf_bitfield_signed_write(unsigned char *ptr,
+ unsigned long start, unsigned long len,
+ int byte_order, int64_t v)
+{
+ if (!ptr)
+ goto end;
+ if (byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_write_le(ptr, start, len, v);
+ else
+ ctf_bitfield_write_be(ptr, start, len, v);
+end:
+ return len;
+}
+
+#endif /* _BABELTRACE_CTF_TYPES_BITFIELD_H */
--- /dev/null
+#ifndef _BABELTRACE_CTF_TYPES_H
+#define _BABELTRACE_CTF_TYPES_H
+
+/*
+ * Common Trace Format
+ *
+ * Type header
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+#include <glib.h>
+
+/*
+ * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
+ * *not* in bytes.
+ *
+ * All write primitives, as well as read for dynamically sized entities, can
+ * receive a NULL ptr/dest parameter. In this case, no write is performed, but
+ * the size is returned.
+ */
+
+uint64_t ctf_uint_read(const unsigned char *ptr, int byte_order, size_t len);
+int64_t ctf_int_read(const unsigned char *ptr, int byte_order, size_t len);
+size_t ctf_uint_write(unsigned char *ptr, int byte_order, size_t len, uint64_t v);
+size_t ctf_int_write(unsigned char *ptr, int byte_order, size_t len, int64_t v);
+
+/*
+ * ctf-types-bitfield.h declares:
+ *
+ * ctf_bitfield_unsigned_read
+ * ctf_bitfield_signed_read
+ * ctf_bitfield_unsigned_write
+ * ctf_bitfield_signed_write
+ */
+#include <ctf/ctf-types-bitfield.h>
+
+double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
+size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest,
+ double v);
+long double ctf_ldouble_read(const unsigned char *ptr,
+ const struct ctf_float *src)
+size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest,
+ long double v);
+struct ctf_float {
+ size_t exp_len;
+ size_t mantissa_len; /* Including sign bit */
+ int byte_order;
+};
+void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
+ const unsigned char *srcp, const struct ctf_float *src);
+
+size_t ctf_string_copy(unsigned char *dest, const unsigned char *src);
+
+/*
+ * A GQuark can be translated to/from strings with g_quark_from_string() and
+ * g_quark_to_string().
+ */
+GQuark ctf_enum_uint_to_quark(const struct enum_table *table, uint64_t v);
+GQuark ctf_enum_int_to_quark(const struct enum_table *table, uint64_t v);
+uint64_t ctf_enum_quark_to_uint(size_t len, int byte_order, GQuark q);
+int64_t ctf_enum_quark_to_int(size_t len, int byte_order, GQuark q);
+void ctf_enum_signed_insert(struct enum_table *table, int64_t v, GQuark q);
+void ctf_enum_unsigned_insert(struct enum_table *table, uint64_t v, GQuark q);
+struct enum_table *ctf_enum_new(void);
+void ctf_enum_destroy(struct enum_table *table);
+
+#endif /* _BABELTRACE_CTF_TYPES_H */
--- /dev/null
+#ifndef _BABELTRACE_TYPES_H
+#define _BABELTRACE_TYPES_H
+
+/*
+ * BabelTrace
+ *
+ * Type header
+ *
+ * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#endif /* _BABELTRACE_TYPES_H */
+++ /dev/null
-#ifndef _CTF_ALIGN_H
-#define _CTF_ALIGN_H
-
-/*
- * align.h - alignment header
- *
- * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <ctf/compiler.h>
-
-#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
-#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
-#define PTR_ALIGN(p, a) ((typeof(p)) ALIGN((unsigned long) (p), a))
-#define ALIGN_FLOOR(x, a) __ALIGN_FLOOR_MASK(x, (typeof(x)) (a) - 1)
-#define __ALIGN_FLOOR_MASK(x, mask) ((x) & ~(mask))
-#define PTR_ALIGN_FLOOR(p, a) \
- ((typeof(p)) ALIGN_FLOOR((unsigned long) (p), a))
-#define IS_ALIGNED(x, a) (((x) & ((typeof(x)) (a) - 1)) == 0)
-
-/*
- * Align pointer on natural object alignment.
- */
-#define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
-#define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
-
-/**
- * offset_align - Calculate the offset needed to align an object on its natural
- * alignment towards higher addresses.
- * @align_drift: object offset from an "alignment"-aligned address.
- * @alignment: natural object alignment. Must be non-zero, power of 2.
- *
- * Returns the offset that must be added to align towards higher
- * addresses.
- */
-#define offset_align(align_drift, alignment) \
- ({ \
- MAYBE_BUILD_BUG_ON((alignment) == 0 \
- || ((alignment) & ((alignment) - 1))); \
- (((alignment) - (align_drift)) & ((alignment) - 1)); \
- })
-
-/**
- * offset_align_floor - Calculate the offset needed to align an object
- * on its natural alignment towards lower addresses.
- * @align_drift: object offset from an "alignment"-aligned address.
- * @alignment: natural object alignment. Must be non-zero, power of 2.
- *
- * Returns the offset that must be substracted to align towards lower addresses.
- */
-#define offset_align_floor(align_drift, alignment) \
- ({ \
- MAYBE_BUILD_BUG_ON((alignment) == 0 \
- || ((alignment) & ((alignment) - 1))); \
- (((align_drift) - (alignment)) & ((alignment) - 1); \
- })
-
-#endif /* _CTF_ALIGN_H */
+++ /dev/null
-#ifndef _CTF_BITFIELD_H
-#define _CTF_BITFIELD_H
-
-/*
- * Common Trace Format
- *
- * 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.
- */
-
-#include <stdint.h> /* C99 5.2.4.2 Numerical limits */
-#include <limits.h> /* C99 5.2.4.2 Numerical limits */
-#include <endian.h> /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */
-#include <assert.h>
-
-/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */
-#define _ctf_piecewise_rshift(v, shift) \
-({ \
- unsigned long sb = (shift) / (sizeof(v) * CHAR_BIT - 1); \
- unsigned long final = (shift) % (sizeof(v) * CHAR_BIT - 1); \
- typeof(v) _v = (v); \
- \
- for (; sb; sb--) \
- _v >>= sizeof(v) * CHAR_BIT - 1; \
- _v >>= final; \
-})
-
-#define _ctf_piecewise_lshift(v, shift) \
-({ \
- unsigned long sb = (shift) / (sizeof(v) * CHAR_BIT - 1); \
- unsigned long final = (shift) % (sizeof(v) * CHAR_BIT - 1); \
- typeof(v) _v = (v); \
- \
- for (; sb; sb--) \
- _v <<= sizeof(v) * CHAR_BIT - 1; \
- _v <<= final; \
-})
-
-#define _ctf_is_signed_type(type) (((type)(-1)) < 0)
-
-#define _ctf_unsigned_cast(type, v) \
-({ \
- (sizeof(v) < sizeof(type)) ? \
- ((type) (v)) & (~(~(type) 0 << (sizeof(v) * CHAR_BIT))) : \
- (type) (v); \
-})
-
-/*
- * ctf_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 _ctf_bitfield_write_le(ptr, _start, _length, _v) \
-do { \
- typeof(_v) v = (_v); \
- typeof(*(ptr)) mask, cmask; \
- unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
- unsigned long start = (_start), length = (_length); \
- 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 = ~((~(typeof(*(ptr))) 0) << (start % ts)); \
- if (end % ts) \
- mask |= (~(typeof(*(ptr))) 0) << (end % ts); \
- cmask = (typeof(*(ptr))) v << (start % ts); \
- cmask &= ~mask; \
- (ptr)[this_unit] &= mask; \
- (ptr)[this_unit] |= cmask; \
- break; \
- } \
- if (start % ts) { \
- cshift = start % ts; \
- mask = ~((~(typeof(*(ptr))) 0) << cshift); \
- cmask = (typeof(*(ptr))) v << cshift; \
- cmask &= ~mask; \
- (ptr)[this_unit] &= mask; \
- (ptr)[this_unit] |= cmask; \
- v = _ctf_piecewise_rshift(v, ts - cshift); \
- start += ts - cshift; \
- this_unit++; \
- } \
- for (; this_unit < end_unit - 1; this_unit++) { \
- (ptr)[this_unit] = (typeof(*(ptr))) v; \
- v = _ctf_piecewise_rshift(v, ts); \
- start += ts; \
- } \
- if (end % ts) { \
- mask = (~(typeof(*(ptr))) 0) << (end % ts); \
- cmask = (typeof(*(ptr))) v; \
- cmask &= ~mask; \
- (ptr)[this_unit] &= mask; \
- (ptr)[this_unit] |= cmask; \
- } else \
- (ptr)[this_unit] = (typeof(*(ptr))) v; \
-} while (0)
-
-#define _ctf_bitfield_write_be(ptr, _start, _length, _v) \
-do { \
- typeof(_v) v = (_v); \
- typeof(*(ptr)) mask, cmask; \
- unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
- unsigned long start = _start, length = _length; \
- 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 = ~((~(typeof(*(ptr))) 0) << ((ts - (end % ts)) % ts)); \
- if (start % ts) \
- mask |= (~((typeof(*(ptr))) 0)) << (ts - (start % ts)); \
- cmask = (typeof(*(ptr))) v << ((ts - (end % ts)) % ts); \
- cmask &= ~mask; \
- (ptr)[this_unit] &= mask; \
- (ptr)[this_unit] |= cmask; \
- break; \
- } \
- if (end % ts) { \
- cshift = end % ts; \
- mask = ~((~(typeof(*(ptr))) 0) << (ts - cshift)); \
- cmask = (typeof(*(ptr))) v << (ts - cshift); \
- cmask &= ~mask; \
- (ptr)[this_unit] &= mask; \
- (ptr)[this_unit] |= cmask; \
- v = _ctf_piecewise_rshift(v, cshift); \
- end -= cshift; \
- this_unit--; \
- } \
- for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \
- (ptr)[this_unit] = (typeof(*(ptr))) v; \
- v = _ctf_piecewise_rshift(v, ts); \
- end -= ts; \
- } \
- if (start % ts) { \
- mask = (~(typeof(*(ptr))) 0) << (ts - (start % ts)); \
- cmask = (typeof(*(ptr))) v; \
- cmask &= ~mask; \
- (ptr)[this_unit] &= mask; \
- (ptr)[this_unit] |= cmask; \
- } else \
- (ptr)[this_unit] = (typeof(*(ptr))) v; \
-} while (0)
-
-/*
- * ctf_bitfield_write - write integer to a bitfield in native endianness
- * ctf_bitfield_write_le - write integer to a bitfield in little endian
- * ctf_bitfield_write_be - write integer to a bitfield in big endian
- */
-
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-
-#define ctf_bitfield_write(ptr, _start, _length, _v) \
- _ctf_bitfield_write_le(ptr, _start, _length, _v)
-
-#define ctf_bitfield_write_le(ptr, _start, _length, _v) \
- _ctf_bitfield_write_le(ptr, _start, _length, _v)
-
-#define ctf_bitfield_write_be(ptr, _start, _length, _v) \
- _ctf_bitfield_write_be((unsigned char *) (ptr), _start, _length, _v)
-
-#elif (BYTE_ORDER == BIG_ENDIAN)
-
-#define ctf_bitfield_write(ptr, _start, _length, _v) \
- _ctf_bitfield_write_be(ptr, _start, _length, _v)
-
-#define ctf_bitfield_write_le(ptr, _start, _length, _v) \
- _ctf_bitfield_write_le((unsigned char *) (ptr), _start, _length, _v)
-
-#define ctf_bitfield_write_be(ptr, _start, _length, _v) \
- _ctf_bitfield_write_be(ptr, _start, _length, _v)
-
-#else /* (BYTE_ORDER == PDP_ENDIAN) */
-
-#error "Byte order not supported"
-
-#endif
-
-#define _ctf_bitfield_read_le(ptr, _start, _length, vptr) \
-do { \
- typeof(*(vptr)) v; \
- typeof(*(ptr)) mask, cmask; \
- unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
- unsigned long start = _start, length = _length; \
- 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 (_ctf_is_signed_type(typeof(v)) \
- && ((ptr)[this_unit] & ((typeof(*(ptr))) 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 = ~((~(typeof(*(ptr))) 0) << (end - start)); \
- cmask &= mask; \
- } \
- v = _ctf_piecewise_lshift(v, end - start); \
- v |= _ctf_unsigned_cast(typeof(v), cmask); \
- *(vptr) = v; \
- break; \
- } \
- if (end % ts) { \
- cshift = end % ts; \
- mask = ~((~(typeof(*(ptr))) 0) << cshift); \
- cmask = (ptr)[this_unit]; \
- cmask &= mask; \
- v = _ctf_piecewise_lshift(v, cshift); \
- v |= _ctf_unsigned_cast(typeof(v), cmask); \
- end -= cshift; \
- this_unit--; \
- } \
- for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \
- v = _ctf_piecewise_lshift(v, ts); \
- v |= _ctf_unsigned_cast(typeof(v), (ptr)[this_unit]); \
- end -= ts; \
- } \
- if (start % ts) { \
- mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \
- cmask = (ptr)[this_unit]; \
- cmask >>= (start % ts); \
- cmask &= mask; \
- v = _ctf_piecewise_lshift(v, ts - (start % ts)); \
- v |= _ctf_unsigned_cast(typeof(v), cmask); \
- } else { \
- v = _ctf_piecewise_lshift(v, ts); \
- v |= _ctf_unsigned_cast(typeof(v), (ptr)[this_unit]); \
- } \
- *(vptr) = v; \
-} while (0)
-
-#define _ctf_bitfield_read_be(ptr, _start, _length, vptr) \
-do { \
- typeof(*(vptr)) v; \
- typeof(*(ptr)) mask, cmask; \
- unsigned long ts = sizeof(typeof(*(ptr))) * CHAR_BIT; /* type size */ \
- unsigned long start = _start, length = _length; \
- 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 (_ctf_is_signed_type(typeof(v)) \
- && ((ptr)[this_unit] & ((typeof(*(ptr))) 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 = ~((~(typeof(*(ptr))) 0) << (end - start)); \
- cmask &= mask; \
- } \
- v = _ctf_piecewise_lshift(v, end - start); \
- v |= _ctf_unsigned_cast(typeof(v), cmask); \
- *(vptr) = v; \
- break; \
- } \
- if (start % ts) { \
- mask = ~((~(typeof(*(ptr))) 0) << (ts - (start % ts))); \
- cmask = (ptr)[this_unit]; \
- cmask &= mask; \
- v = _ctf_piecewise_lshift(v, ts - (start % ts)); \
- v |= _ctf_unsigned_cast(typeof(v), cmask); \
- start += ts - (start % ts); \
- this_unit++; \
- } \
- for (; this_unit < end_unit - 1; this_unit++) { \
- v = _ctf_piecewise_lshift(v, ts); \
- v |= _ctf_unsigned_cast(typeof(v), (ptr)[this_unit]); \
- start += ts; \
- } \
- if (end % ts) { \
- mask = ~((~(typeof(*(ptr))) 0) << (end % ts)); \
- cmask = (ptr)[this_unit]; \
- cmask >>= ts - (end % ts); \
- cmask &= mask; \
- v = _ctf_piecewise_lshift(v, end % ts); \
- v |= _ctf_unsigned_cast(typeof(v), cmask); \
- } else { \
- v = _ctf_piecewise_lshift(v, ts); \
- v |= _ctf_unsigned_cast(typeof(v), (ptr)[this_unit]); \
- } \
- *(vptr) = v; \
-} while (0)
-
-/*
- * ctf_bitfield_read - read integer from a bitfield in native endianness
- * ctf_bitfield_read_le - read integer from a bitfield in little endian
- * ctf_bitfield_read_be - read integer from a bitfield in big endian
- */
-
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-
-#define ctf_bitfield_read(ptr, _start, _length, _vptr) \
- _ctf_bitfield_read_le(ptr, _start, _length, _vptr)
-
-#define ctf_bitfield_read_le(ptr, _start, _length, _vptr) \
- _ctf_bitfield_read_le(ptr, _start, _length, _vptr)
-
-#define ctf_bitfield_read_be(ptr, _start, _length, _vptr) \
- _ctf_bitfield_read_be((const unsigned char *) (ptr), _start, _length, _vptr)
-
-#elif (BYTE_ORDER == BIG_ENDIAN)
-
-#define ctf_bitfield_read(ptr, _start, _length, _vptr) \
- _ctf_bitfield_read_be(ptr, _start, _length, _vptr)
-
-#define ctf_bitfield_read_le(ptr, _start, _length, _vptr) \
- _ctf_bitfield_read_le((const unsigned char *) (ptr), _start, _length, _vptr)
-
-#define ctf_bitfield_read_be(ptr, _start, _length, _vptr) \
- _ctf_bitfield_read_be(ptr, _start, _length, _vptr)
-
-#else /* (BYTE_ORDER == PDP_ENDIAN) */
-
-#error "Byte order not supported"
-
-#endif
-
-#endif /* _CTF_BITFIELD_H */
+++ /dev/null
-#ifndef _CTF_COMPILER_H
-#define _CTF_COMPILER_H
-
-#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
-
-#endif /* _CTF_COMPILER_H */
+++ /dev/null
-#ifndef _CTF_TYPES_BITFIELD_H
-#define _CTF_TYPES_BITFIELD_H
-
-/*
- * Common Trace Format
- *
- * Bitfields read/write functions.
- *
- * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <ctf/bitfield.h>
-#include <endian.h>
-
-static inline
-uint64_t ctf_bitfield_unsigned_read(const unsigned char *ptr,
- unsigned long start, unsigned long len,
- int byte_order)
-{
- uint64_t v;
-
- if (byte_order == LITTLE_ENDIAN)
- ctf_bitfield_read_le(ptr, start, len, &v);
- else
- ctf_bitfield_read_be(ptr, start, len, &v);
- return v;
-}
-
-static inline
-int64_t ctf_bitfield_signed_read(const unsigned char *ptr,
- unsigned long start, unsigned long len,
- int byte_order)
-{
- int64_t v;
-
- if (byte_order == LITTLE_ENDIAN)
- ctf_bitfield_read_le(ptr, start, len, &v);
- else
- ctf_bitfield_read_be(ptr, start, len, &v);
- return v;
-}
-
-static inline
-size_t ctf_bitfield_unsigned_write(unsigned char *ptr,
- unsigned long start, unsigned long len,
- int byte_order, uint64_t v)
-{
- if (!ptr)
- goto end;
- if (byte_order == LITTLE_ENDIAN)
- ctf_bitfield_write_le(ptr, start, len, v);
- else
- ctf_bitfield_write_be(ptr, start, len, v);
-end:
- return len;
-}
-
-static inline
-size_t ctf_bitfield_signed_write(unsigned char *ptr,
- unsigned long start, unsigned long len,
- int byte_order, int64_t v)
-{
- if (!ptr)
- goto end;
- if (byte_order == LITTLE_ENDIAN)
- ctf_bitfield_write_le(ptr, start, len, v);
- else
- ctf_bitfield_write_be(ptr, start, len, v);
-end:
- return len;
-}
-
-#endif /* _CTF_TYPES_BITFIELD_H */
+++ /dev/null
-#ifndef _CTF_TYPES_H
-#define _CTF_TYPES_H
-
-/*
- * Common Trace Format
- *
- * Type header
- *
- * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <stdint.h>
-#include <glib.h>
-
-/*
- * IMPORTANT: All lengths (len) and offsets (start, end) are expressed in bits,
- * *not* in bytes.
- *
- * All write primitives, as well as read for dynamically sized entities, can
- * receive a NULL ptr/dest parameter. In this case, no write is performed, but
- * the size is returned.
- */
-
-uint64_t ctf_uint_read(const unsigned char *ptr, int byte_order, size_t len);
-int64_t ctf_int_read(const unsigned char *ptr, int byte_order, size_t len);
-size_t ctf_uint_write(unsigned char *ptr, int byte_order, size_t len, uint64_t v);
-size_t ctf_int_write(unsigned char *ptr, int byte_order, size_t len, int64_t v);
-
-/*
- * ctf-types-bitfield.h declares:
- *
- * ctf_bitfield_unsigned_read
- * ctf_bitfield_signed_read
- * ctf_bitfield_unsigned_write
- * ctf_bitfield_signed_write
- */
-#include <ctf/ctf-types-bitfield.h>
-
-double ctf_double_read(const unsigned char *ptr, const struct ctf_float *src)
-size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest,
- double v);
-long double ctf_ldouble_read(const unsigned char *ptr,
- const struct ctf_float *src)
-size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest,
- long double v);
-struct ctf_float {
- size_t exp_len;
- size_t mantissa_len; /* Including sign bit */
- int byte_order;
-};
-void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest,
- const unsigned char *srcp, const struct ctf_float *src);
-
-size_t ctf_string_copy(unsigned char *dest, const unsigned char *src);
-
-/*
- * A GQuark can be translated to/from strings with g_quark_from_string() and
- * g_quark_to_string().
- */
-GQuark ctf_enum_uint_to_quark(const struct enum_table *table, uint64_t v);
-GQuark ctf_enum_int_to_quark(const struct enum_table *table, uint64_t v);
-uint64_t ctf_enum_quark_to_uint(size_t len, int byte_order, GQuark q);
-int64_t ctf_enum_quark_to_int(size_t len, int byte_order, GQuark q);
-void ctf_enum_signed_insert(struct enum_table *table, int64_t v, GQuark q);
-void ctf_enum_unsigned_insert(struct enum_table *table, uint64_t v, GQuark q);
-struct enum_table *ctf_enum_new(void);
-void ctf_enum_destroy(struct enum_table *table);
-
-#endif /* _CTF_TYPES_H */
/*
* test-bitfield.c
*
- * Common Trace Format - bitfield test program
+ * BabelTrace - bitfield test program
*
* Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
*/
#define _GNU_SOURCE
-#include <ctf/bitfield.h>
+#include <babeltrace/bitfield.h>
#include <stdio.h>
unsigned int glob;
*/
void fct(void)
{
- ctf_bitfield_write(&glob, 12, 15, 0x12345678);
+ bt_bitfield_write(&glob, 12, 15, 0x12345678);
}
/* Test array size, in bytes */
for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0xFF);
- ctf_bitfield_write(target.c, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.c, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (bytewise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0xFF);
- ctf_bitfield_write(target.s, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.s, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (shortwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0xFF);
- ctf_bitfield_write(target.i, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.i, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (intwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0xFF);
- ctf_bitfield_write(target.l, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.l, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (longwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0xFF);
- ctf_bitfield_write(target.ll, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.ll, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (longlongwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
for (s = 0; s < 8 * TEST_LEN; s++) {
for (l = nrbits; l < (8 * TEST_LEN) - s; l++) {
init_byte_array(target.c, TEST_LEN, 0x0);
- ctf_bitfield_write(target.c, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.c, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (bytewise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0x0);
- ctf_bitfield_write(target.s, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.s, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (shortwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0x0);
- ctf_bitfield_write(target.i, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.i, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (intwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0x0);
- ctf_bitfield_write(target.l, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.l, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (longwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
}
init_byte_array(target.c, TEST_LEN, 0x0);
- ctf_bitfield_write(target.ll, s, l, src);
- ctf_bitfield_read(target.c, s, l, &readval);
+ bt_bitfield_write(target.ll, s, l, src);
+ bt_bitfield_read(target.c, s, l, &readval);
if (readval != src) {
printf("Error (longlongwise) src %lX read %llX shift %d len %d\n",
src, readval, s, l);
target.i[0] = 0xFFFFFFFF;
target.i[1] = 0xFFFFFFFF;
- ctf_bitfield_write(target.c, shift, len, src);
+ bt_bitfield_write(target.c, shift, len, src);
printf("bytewise\n");
print_byte_array(target.c, 8);
target.i[0] = 0xFFFFFFFF;
target.i[1] = 0xFFFFFFFF;
- ctf_bitfield_write(target.s, shift, len, src);
+ bt_bitfield_write(target.s, shift, len, src);
printf("shortwise\n");
print_byte_array(target.c, 8);
target.i[0] = 0xFFFFFFFF;
target.i[1] = 0xFFFFFFFF;
- ctf_bitfield_write(target.i, shift, len, src);
+ bt_bitfield_write(target.i, shift, len, src);
printf("intwise\n");
print_byte_array(target.c, 8);
target.i[0] = 0xFFFFFFFF;
target.i[1] = 0xFFFFFFFF;
- ctf_bitfield_write(target.l, shift, len, src);
+ bt_bitfield_write(target.l, shift, len, src);
printf("longwise\n");
print_byte_array(target.c, 8);
target.i[0] = 0xFFFFFFFF;
target.i[1] = 0xFFFFFFFF;
- ctf_bitfield_write(target.ll, shift, len, src);
+ bt_bitfield_write(target.ll, shift, len, src);
printf("lluwise\n");
print_byte_array(target.c, 8);
- ctf_bitfield_read(target.c, shift, len, &readval);
+ bt_bitfield_read(target.c, shift, len, &readval);
printf("read: %llX\n", readval);
ret = run_test();
/*
- * Common Trace Format - Converter
+ * BabelTrace - Converter
*
* Types registry.
*