From 53532829c4c9a9c22eccc72cd84bf5b0b57b33e0 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 13 May 2011 07:14:05 -0400 Subject: [PATCH] Add alignment power of two check Signed-off-by: Mathieu Desnoyers --- .../ctf-test/succeed/ctf-embedded-1.txt | 49 +++++++++++++++++++ .../metadata/ctf-visitor-generate-io-struct.c | 12 +++++ 2 files changed, 61 insertions(+) diff --git a/formats/ctf/metadata/ctf-test/succeed/ctf-embedded-1.txt b/formats/ctf/metadata/ctf-test/succeed/ctf-embedded-1.txt index 4a97cdf7..27af7233 100644 --- a/formats/ctf/metadata/ctf-test/succeed/ctf-embedded-1.txt +++ b/formats/ctf/metadata/ctf-test/succeed/ctf-embedded-1.txt @@ -33,3 +33,52 @@ stream { event { name = invalid; id = 0; }; event { name = func_enter; id = 1; }; event { name = func_exit; id = 2; }; + +event { + name = timer_tick; /* or sync_point... */ + id = 3; + fields := { + uint64_t monotonic_value; + uint64_t tsc_value; + uint32_t seqnum; + }; +}; + +event { + name = freq_change; + id = 4; + fields := { + uint64_t new_freq; + }; +} + +clock { + name = monotonic; + uuid = ; +}; + +clock { + name = seqnum; + uuid = ; +}; + +clock { + name = tsc; + sync_points = { + map { + parent.clock = monotonic; + parent.value = event.timer_tick.monotonic_value; + value = event.timer_tick.tsc_value; + }; + map { + parent.clock = seqnum; + parent.value = event.timer_tick.seqnum; + value = event.timer_tick.tsc_value; + }; + }; + + freq = { + update = event.freq_change.new_freq; + }; + uuid = ; +}; diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 9da7d0d8..37d17f58 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -1088,6 +1088,12 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, return NULL; } alignment = right->u.unary_expression.u.unsigned_constant; + /* Make sure alignment is a power of two */ + if (alignment == 0 || (alignment & (alignment - 1)) != 0) { + fprintf(fd, "[error] %s: align: expecting power of two\n", + __func__); + return NULL; + } has_alignment = 1; } else { fprintf(fd, "[error] %s: unknown attribute name %s\n", @@ -1156,6 +1162,12 @@ struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth, return NULL; } alignment = right->u.unary_expression.u.unsigned_constant; + /* Make sure alignment is a power of two */ + if (alignment == 0 || (alignment & (alignment - 1)) != 0) { + fprintf(fd, "[error] %s: align: expecting power of two\n", + __func__); + return NULL; + } has_alignment = 1; } else { fprintf(fd, "[error] %s: unknown attribute name %s\n", -- 2.34.1