X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Ftypes%2Finteger.c;h=257341adfa41ce6320a68a00e04cf6bc4d43490f;hb=5491476845938cd48837a072b0df55ffa7210e77;hp=9b918954d269dbb4d04c83f2f4146cec7a5b83f1;hpb=c5e74408f9786219f6b44400dcf2098ab9cc78fb;p=babeltrace.git diff --git a/formats/ctf/types/integer.c b/formats/ctf/types/integer.c index 9b918954..257341ad 100644 --- a/formats/ctf/types/integer.c +++ b/formats/ctf/types/integer.c @@ -3,7 +3,9 @@ * * Integers read/write functions. * - * Copyright 2010 - Mathieu Desnoyers + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation + * + * Author: 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 @@ -14,13 +16,21 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include #include #include #include -#include +#include /* * The aligned read/write functions are expected to be faster than the @@ -29,8 +39,8 @@ */ static -int _aligned_integer_read(struct stream_pos *ppos, - struct definition *definition) +int _aligned_integer_read(struct bt_stream_pos *ppos, + struct bt_definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -40,11 +50,11 @@ int _aligned_integer_read(struct stream_pos *ppos, int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */ ctf_align_pos(pos, integer_declaration->p.alignment); - assert(!(pos->offset % CHAR_BIT)); if (!ctf_pos_access_ok(pos, integer_declaration->len)) return -EFAULT; + assert(!(pos->offset % CHAR_BIT)); if (!integer_declaration->signedness) { switch (integer_declaration->len) { case 8: @@ -101,7 +111,7 @@ int _aligned_integer_read(struct stream_pos *ppos, v = *(const int16_t *) ctf_get_pos_addr(pos); integer_definition->value._signed = - rbo ? GUINT16_SWAP_LE_BE(v) : v; + rbo ? (int16_t) GUINT16_SWAP_LE_BE(v) : v; break; } case 32: @@ -110,7 +120,7 @@ int _aligned_integer_read(struct stream_pos *ppos, v = *(const int32_t *) ctf_get_pos_addr(pos); integer_definition->value._signed = - rbo ? GUINT32_SWAP_LE_BE(v) : v; + rbo ? (int32_t) GUINT32_SWAP_LE_BE(v) : v; break; } case 64: @@ -119,7 +129,7 @@ int _aligned_integer_read(struct stream_pos *ppos, v = *(const int64_t *) ctf_get_pos_addr(pos); integer_definition->value._signed = - rbo ? GUINT64_SWAP_LE_BE(v) : v; + rbo ? (int64_t) GUINT64_SWAP_LE_BE(v) : v; break; } default: @@ -131,8 +141,8 @@ int _aligned_integer_read(struct stream_pos *ppos, } static -int _aligned_integer_write(struct stream_pos *ppos, - struct definition *definition) +int _aligned_integer_write(struct bt_stream_pos *ppos, + struct bt_definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -142,11 +152,11 @@ int _aligned_integer_write(struct stream_pos *ppos, int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */ ctf_align_pos(pos, integer_declaration->p.alignment); - assert(!(pos->offset % CHAR_BIT)); if (!ctf_pos_access_ok(pos, integer_declaration->len)) return -EFAULT; + assert(!(pos->offset % CHAR_BIT)); if (pos->dummy) goto end; if (!integer_declaration->signedness) { @@ -180,12 +190,12 @@ int _aligned_integer_write(struct stream_pos *ppos, break; case 16: *(int16_t *) ctf_get_pos_addr(pos) = rbo ? - GUINT16_SWAP_LE_BE((int16_t) v) : + (int16_t) GUINT16_SWAP_LE_BE((int16_t) v) : (int16_t) v; break; case 32: *(int32_t *) ctf_get_pos_addr(pos) = rbo ? - GUINT32_SWAP_LE_BE((int32_t) v) : + (int32_t) GUINT32_SWAP_LE_BE((int32_t) v) : (int32_t) v; break; case 64: @@ -201,7 +211,7 @@ end: return 0; } -int ctf_integer_read(struct stream_pos *ppos, struct definition *definition) +int ctf_integer_read(struct bt_stream_pos *ppos, struct bt_definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -221,20 +231,24 @@ int ctf_integer_read(struct stream_pos *ppos, struct definition *definition) if (!integer_declaration->signedness) { if (integer_declaration->byte_order == LITTLE_ENDIAN) - bt_bitfield_read_le(pos->base, unsigned long, + bt_bitfield_read_le(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, &integer_definition->value._unsigned); else - bt_bitfield_read_be(pos->base, unsigned long, + bt_bitfield_read_be(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, &integer_definition->value._unsigned); } else { if (integer_declaration->byte_order == LITTLE_ENDIAN) - bt_bitfield_read_le(pos->base, unsigned long, + bt_bitfield_read_le(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, &integer_definition->value._signed); else - bt_bitfield_read_be(pos->base, unsigned long, + bt_bitfield_read_be(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, &integer_definition->value._signed); } @@ -242,7 +256,7 @@ int ctf_integer_read(struct stream_pos *ppos, struct definition *definition) return 0; } -int ctf_integer_write(struct stream_pos *ppos, struct definition *definition) +int ctf_integer_write(struct bt_stream_pos *ppos, struct bt_definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -264,20 +278,24 @@ int ctf_integer_write(struct stream_pos *ppos, struct definition *definition) goto end; if (!integer_declaration->signedness) { if (integer_declaration->byte_order == LITTLE_ENDIAN) - bt_bitfield_write_le(pos->base, unsigned long, + bt_bitfield_write_le(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, integer_definition->value._unsigned); else - bt_bitfield_write_be(pos->base, unsigned long, + bt_bitfield_write_be(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, integer_definition->value._unsigned); } else { if (integer_declaration->byte_order == LITTLE_ENDIAN) - bt_bitfield_write_le(pos->base, unsigned long, + bt_bitfield_write_le(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, integer_definition->value._signed); else - bt_bitfield_write_be(pos->base, unsigned long, + bt_bitfield_write_be(mmap_align_addr(pos->base_mma) + + pos->mmap_base_offset, unsigned long, pos->offset, integer_declaration->len, integer_definition->value._signed); }