*
* 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 <babeltrace/ctf/types.h>
*/
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);
struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
- ctf_align_pos(pos, integer_declaration->p.alignment);
+ if (!ctf_align_pos(pos, integer_declaration->p.alignment))
+ return -EFAULT;
if (!ctf_pos_access_ok(pos, integer_declaration->len))
return -EFAULT;
assert(0);
}
}
- ctf_move_pos(pos, integer_declaration->len);
+ if (!ctf_move_pos(pos, integer_declaration->len))
+ return -EFAULT;
return 0;
}
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);
struct ctf_stream_pos *pos = ctf_pos(ppos);
int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */
- ctf_align_pos(pos, integer_declaration->p.alignment);
+ if (!ctf_align_pos(pos, integer_declaration->p.alignment))
+ return -EFAULT;
if (!ctf_pos_access_ok(pos, integer_declaration->len))
return -EFAULT;
}
}
end:
- ctf_move_pos(pos, integer_declaration->len);
+ if (!ctf_move_pos(pos, integer_declaration->len))
+ return -EFAULT;
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);
return _aligned_integer_read(ppos, definition);
}
- ctf_align_pos(pos, integer_declaration->p.alignment);
+ if (!ctf_align_pos(pos, integer_declaration->p.alignment))
+ return -EFAULT;
if (!ctf_pos_access_ok(pos, integer_declaration->len))
return -EFAULT;
if (!integer_declaration->signedness) {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_read_le(mmap_align_addr(pos->base_mma), 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(mmap_align_addr(pos->base_mma), 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(mmap_align_addr(pos->base_mma), 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(mmap_align_addr(pos->base_mma), 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);
}
- ctf_move_pos(pos, integer_declaration->len);
+ if (!ctf_move_pos(pos, integer_declaration->len))
+ return -EFAULT;
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);
return _aligned_integer_write(ppos, definition);
}
- ctf_align_pos(pos, integer_declaration->p.alignment);
+ if (!ctf_align_pos(pos, integer_declaration->p.alignment))
+ return -EFAULT;
if (!ctf_pos_access_ok(pos, integer_declaration->len))
return -EFAULT;
goto end;
if (!integer_declaration->signedness) {
if (integer_declaration->byte_order == LITTLE_ENDIAN)
- bt_bitfield_write_le(mmap_align_addr(pos->base_mma), 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(mmap_align_addr(pos->base_mma), 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(mmap_align_addr(pos->base_mma), 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(mmap_align_addr(pos->base_mma), 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);
}
end:
- ctf_move_pos(pos, integer_declaration->len);
+ if (!ctf_move_pos(pos, integer_declaration->len))
+ return -EFAULT;
return 0;
}