From: Mathieu Desnoyers Date: Tue, 28 Sep 2010 20:05:27 +0000 (-0400) Subject: Move to babeltrace namespace X-Git-Tag: v0.1~236 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=d79865b92da224131f58ab311e75e49043b62c7a Move to babeltrace namespace Signed-off-by: Mathieu Desnoyers --- diff --git a/README b/README new file mode 100644 index 00000000..e72ece8a --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +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. diff --git a/formats/ctf/types/enum.c b/formats/ctf/types/enum.c index 507d0c35..5e0fda7d 100644 --- a/formats/ctf/types/enum.c +++ b/formats/ctf/types/enum.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include #include #include diff --git a/formats/ctf/types/float.c b/formats/ctf/types/float.c index eb0291ec..a26e94cc 100644 --- a/formats/ctf/types/float.c +++ b/formats/ctf/types/float.c @@ -22,7 +22,7 @@ * Reference: ISO C99 standard 5.2.4 */ -#include +#include #include #include /* C99 floating point definitions */ #include @@ -103,22 +103,24 @@ void ctf_float_copy(unsigned char *destp, const struct ctf_float *dest, } /* 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) @@ -130,7 +132,7 @@ 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; } @@ -147,7 +149,7 @@ size_t ctf_double_write(unsigned char *ptr, const struct ctf_float *dest, 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; } @@ -162,7 +164,7 @@ long double ctf_ldouble_read(const unsigned char *ptr, .byte_order = BYTE_ORDER, }; - float_copy(&u.bits, &dest, ptr, src); + ctf_float_copy(&u.bits, &dest, ptr, src); return u.v; } @@ -179,7 +181,7 @@ size_t ctf_ldouble_write(unsigned char *ptr, const struct ctf_float *dest, 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; } diff --git a/formats/ctf/types/string.c b/formats/ctf/types/string.c index 578388d1..65018c74 100644 --- a/formats/ctf/types/string.c +++ b/formats/ctf/types/string.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include #include size_t string_copy(char *dest, const char *src) diff --git a/formats/ctf/types/struct.c b/formats/ctf/types/struct.c index 3aa8d587..8d248da1 100644 --- a/formats/ctf/types/struct.c +++ b/formats/ctf/types/struct.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include #include diff --git a/include/babeltrace/align.h b/include/babeltrace/align.h new file mode 100644 index 00000000..85ee42fa --- /dev/null +++ b/include/babeltrace/align.h @@ -0,0 +1,72 @@ +#ifndef _BABELTRACE_ALIGN_H +#define _BABELTRACE_ALIGN_H + +/* + * BabelTrace align.h - alignment header + * + * Copyright (c) 2010 Mathieu Desnoyers + * + * 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 + +#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 */ diff --git a/include/babeltrace/bitfield.h b/include/babeltrace/bitfield.h new file mode 100644 index 00000000..74d8228c --- /dev/null +++ b/include/babeltrace/bitfield.h @@ -0,0 +1,390 @@ +#ifndef _BABELTRACE_BITFIELD_H +#define _BABELTRACE_BITFIELD_H + +/* + * BabelTrace + * + * Bitfields read/write functions. + * + * Copyright 2010 - Mathieu Desnoyers + * + * 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 /* C99 5.2.4.2 Numerical limits */ +#include /* C99 5.2.4.2 Numerical limits */ +#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ +#include + +/* 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 */ diff --git a/include/babeltrace/compiler.h b/include/babeltrace/compiler.h new file mode 100644 index 00000000..7850ded6 --- /dev/null +++ b/include/babeltrace/compiler.h @@ -0,0 +1,6 @@ +#ifndef _BABELTRACE_COMPILER_H +#define _BABELTRACE_COMPILER_H + +#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) + +#endif /* _BABELTRACE_COMPILER_H */ diff --git a/include/babeltrace/ctf/types-bitfield.h b/include/babeltrace/ctf/types-bitfield.h new file mode 100644 index 00000000..c425a8e2 --- /dev/null +++ b/include/babeltrace/ctf/types-bitfield.h @@ -0,0 +1,87 @@ +#ifndef _BABELTRACE_CTF_TYPES_BITFIELD_H +#define _BABELTRACE_CTF_TYPES_BITFIELD_H + +/* + * Common Trace Format + * + * Bitfields read/write functions. + * + * Copyright (c) 2010 Mathieu Desnoyers + * + * 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 +#include + +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 */ diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h new file mode 100644 index 00000000..276152db --- /dev/null +++ b/include/babeltrace/ctf/types.h @@ -0,0 +1,83 @@ +#ifndef _BABELTRACE_CTF_TYPES_H +#define _BABELTRACE_CTF_TYPES_H + +/* + * Common Trace Format + * + * Type header + * + * Copyright (c) 2010 Mathieu Desnoyers + * + * 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 +#include + +/* + * 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 + +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 */ diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h new file mode 100644 index 00000000..23fec0fc --- /dev/null +++ b/include/babeltrace/types.h @@ -0,0 +1,26 @@ +#ifndef _BABELTRACE_TYPES_H +#define _BABELTRACE_TYPES_H + +/* + * BabelTrace + * + * Type header + * + * Copyright (c) 2010 Mathieu Desnoyers + * + * 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 */ diff --git a/include/ctf/align.h b/include/ctf/align.h deleted file mode 100644 index 5adac7f3..00000000 --- a/include/ctf/align.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef _CTF_ALIGN_H -#define _CTF_ALIGN_H - -/* - * align.h - alignment header - * - * Copyright (c) 2010 Mathieu Desnoyers - * - * 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 - -#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 */ diff --git a/include/ctf/bitfield.h b/include/ctf/bitfield.h deleted file mode 100644 index e1eb3abc..00000000 --- a/include/ctf/bitfield.h +++ /dev/null @@ -1,390 +0,0 @@ -#ifndef _CTF_BITFIELD_H -#define _CTF_BITFIELD_H - -/* - * Common Trace Format - * - * Bitfields read/write functions. - * - * Copyright 2010 - Mathieu Desnoyers - * - * 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 /* C99 5.2.4.2 Numerical limits */ -#include /* C99 5.2.4.2 Numerical limits */ -#include /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */ -#include - -/* 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 */ diff --git a/include/ctf/compiler.h b/include/ctf/compiler.h deleted file mode 100644 index eadef213..00000000 --- a/include/ctf/compiler.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _CTF_COMPILER_H -#define _CTF_COMPILER_H - -#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) - -#endif /* _CTF_COMPILER_H */ diff --git a/include/ctf/ctf-types-bitfield.h b/include/ctf/ctf-types-bitfield.h deleted file mode 100644 index 82ee1120..00000000 --- a/include/ctf/ctf-types-bitfield.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _CTF_TYPES_BITFIELD_H -#define _CTF_TYPES_BITFIELD_H - -/* - * Common Trace Format - * - * Bitfields read/write functions. - * - * Copyright (c) 2010 Mathieu Desnoyers - * - * 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 -#include - -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 */ diff --git a/include/ctf/ctf-types.h b/include/ctf/ctf-types.h deleted file mode 100644 index 25ec3466..00000000 --- a/include/ctf/ctf-types.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef _CTF_TYPES_H -#define _CTF_TYPES_H - -/* - * Common Trace Format - * - * Type header - * - * Copyright (c) 2010 Mathieu Desnoyers - * - * 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 -#include - -/* - * 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 - -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 */ diff --git a/tests/test-bitfield.c b/tests/test-bitfield.c index 5911eb46..f8b63853 100644 --- a/tests/test-bitfield.c +++ b/tests/test-bitfield.c @@ -1,7 +1,7 @@ /* * test-bitfield.c * - * Common Trace Format - bitfield test program + * BabelTrace - bitfield test program * * Copyright 2010 - Mathieu Desnoyers * @@ -21,7 +21,7 @@ */ #define _GNU_SOURCE -#include +#include #include unsigned int glob; @@ -32,7 +32,7 @@ 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 */ @@ -139,8 +139,8 @@ int run_test_unsigned(void) 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); @@ -149,8 +149,8 @@ int run_test_unsigned(void) } 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); @@ -159,8 +159,8 @@ int run_test_unsigned(void) } 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); @@ -169,8 +169,8 @@ int run_test_unsigned(void) } 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); @@ -179,8 +179,8 @@ int run_test_unsigned(void) } 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); @@ -221,8 +221,8 @@ int run_test_signed(void) 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); @@ -231,8 +231,8 @@ int run_test_signed(void) } 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); @@ -241,8 +241,8 @@ int run_test_signed(void) } 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); @@ -251,8 +251,8 @@ int run_test_signed(void) } 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); @@ -261,8 +261,8 @@ int run_test_signed(void) } 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); @@ -335,35 +335,35 @@ int main(int argc, char **argv) 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(); diff --git a/types/types.c b/types/types.c index f4843e6a..28242d23 100644 --- a/types/types.c +++ b/types/types.c @@ -1,5 +1,5 @@ /* - * Common Trace Format - Converter + * BabelTrace - Converter * * Types registry. *