working gentest
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 11 Nov 2005 16:02:47 +0000 (16:02 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 11 Nov 2005 16:02:47 +0000 (16:02 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@1319 04897980-b3bd-0310-b5e0-8ef037075253

genevent-new/gentest.c [new file with mode: 0644]
genevent-new/ltt-facility-test-template.h

diff --git a/genevent-new/gentest.c b/genevent-new/gentest.c
new file mode 100644 (file)
index 0000000..4f12814
--- /dev/null
@@ -0,0 +1,413 @@
+
+#include <assert.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#define min(a,b) (((a)<(b))?a:b)
+#define max(a,b) (((a)>(b))?a:b)
+#define BUG_ON(a) assert(!(a))
+
+/* Calculate the offset needed to align the type */
+static inline unsigned int ltt_align(size_t align_drift,
+                                                                                                                                                size_t size_of_type)
+{
+       size_t alignment = min(sizeof(void*), size_of_type);
+
+       return ((alignment - align_drift) & (alignment-1));
+}
+
+
+/* TEMPLATE */
+
+enum lttng_tasklet_priority {
+       LTTNG_LOW,
+       LTTNG_HIGH,
+};
+
+enum lttng_irq_mode {
+       LTTNG_user,
+       LTTNG_kernel,
+};
+
+struct lttng_mystruct2 {
+       unsigned int irq_id;
+       enum lttng_irq_mode mode;
+       //struct lttng_mystruct teststr1;
+};
+
+
+size_t lttng_get_size_mystruct2(
+               struct lttng_mystruct2 *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+       
+       locsize = sizeof(enum lttng_irq_mode);
+       size += ltt_align(size, locsize) + locsize;
+
+       BUG_ON(sizeof(struct lttng_mystruct2) != size);
+
+       return sizeof(struct lttng_mystruct2);
+}
+
+size_t lttng_get_alignment_mystruct2(
+               struct lttng_mystruct2 *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       return align;
+}
+
+void lttng_write_mystruct2(void **to,
+               void **from,
+               size_t *len,
+               struct lttng_mystruct2 *obj)
+{
+       size_t align, size;
+
+       align = lttng_get_alignment_mystruct2(obj);
+       size = lttng_get_size_mystruct2(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+
+#define LTTNG_ARRAY_SIZE_mystruct_myarray 10
+typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
+
+size_t lttng_get_size_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(uint64_t);
+       /* ltt_align == 0 always*/
+       //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+       BUG_ON(ltt_align(size, locsize) != 0);
+       size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
+
+       BUG_ON(size != LTTNG_ARRAY_SIZE_mystruct_myarray * sizeof(uint64_t));
+
+       return size;
+}
+
+size_t lttng_get_alignment_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(uint64_t);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_array_mystruct_myarray(void **to,
+               void **from,
+               size_t *len,
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_array_mystruct_myarray(obj);
+       size = lttng_get_size_array_mystruct_myarray(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+typedef struct lttng_sequence_mystruct_mysequence lttng_sequence_mystruct_mysequence;
+struct lttng_sequence_mystruct_mysequence {
+       unsigned int len;
+       double *array;
+};
+
+
+size_t lttng_get_size_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+
+       locsize = sizeof(double);
+       size += ltt_align(size, locsize) + (obj->len * locsize);
+
+       return size;
+}
+
+size_t lttng_get_alignment_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_sequence_mystruct_mysequence(void **to,
+               void **from,
+               size_t *len,
+               lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align, size;
+       void *varfrom;
+       size_t varlen=0;
+       
+       /* Flush pending memcpy */
+       if(*len != 0) {
+               memcpy(*to, *from, *len);
+               *to += *len;
+               *len = 0;
+       }
+
+       align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
+       //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
+
+       /* Align output */
+       *to += ltt_align((size_t)(*to), align);
+       
+       /* Copy members */
+       *to += ltt_align((size_t)*to, sizeof(unsigned int));
+       varfrom = &obj->len;
+       varlen += sizeof(unsigned int);
+       memcpy(*to, varfrom, varlen);
+       *to += varlen;
+       varlen = 0;
+
+       *to += ltt_align((size_t)*to, sizeof(double));
+       varfrom = obj->array;
+       varlen += obj->len * sizeof(double);
+       memcpy(*to, varfrom, varlen);
+       *to += varlen;
+       varlen = 0;
+
+       /* Put source *from just after the C sequence */
+       *from = obj+1;
+}
+
+
+
+union lttng_mystruct_myunion {
+       double myfloat;
+       unsigned long myulong;
+};
+
+
+size_t lttng_get_size_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t size=0, locsize;
+       
+       locsize = sizeof(double);
+       size = max(size, locsize);
+
+       locsize = sizeof(unsigned long);
+       size = max(size, locsize);
+
+       BUG_ON(size != sizeof(union lttng_mystruct_myunion));
+
+       return size;
+}
+
+
+size_t lttng_get_alignment_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       localign = sizeof(unsigned long);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_mystruct_myunion(void **to,
+               void **from,
+               size_t *len,
+               union lttng_mystruct_myunion *obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_mystruct_myunion(obj);
+       size = lttng_get_size_mystruct_myunion(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       *len += size;
+}
+
+
+struct lttng_mystruct {
+       unsigned int irq_id;
+       enum lttng_irq_mode mode;
+       struct lttng_mystruct2 teststr;
+       lttng_array_mystruct_myarray myarray;
+       lttng_sequence_mystruct_mysequence mysequence;
+       union lttng_mystruct_myunion myunion;
+};
+
+size_t lttng_get_size_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t size=0, locsize, localign;
+       
+       locsize = sizeof(unsigned int);
+       size += ltt_align(size, locsize) + locsize;
+       
+       locsize = sizeof(enum lttng_irq_mode);
+       size += ltt_align(size, locsize) + locsize;
+
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       locsize = lttng_get_size_mystruct2(&obj->teststr);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
+       size += ltt_align(size, localign) + locsize;
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
+       size += ltt_align(size, localign) + locsize;
+
+       return size;
+}
+
+
+size_t lttng_get_alignment_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       align = max(align, localign);
+
+       return align;
+}
+
+void lttng_write_mystruct(void **to,
+               void **from,
+               size_t *len,
+               struct lttng_mystruct *obj)
+{
+       size_t align, size;
+       
+       align = lttng_get_alignment_mystruct(obj);
+       // no need : contains variable size fields.
+       // locsize = lttng_get_size_mystruct(obj);
+
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
+       } else {
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
+       }
+       
+       /* Contains variable sized fields : must explode the structure */
+       
+       size = sizeof(unsigned int);
+       *len += ltt_align((size_t)(*to+*len), size) + size;
+       
+       size = sizeof(enum lttng_irq_mode);
+       *len += ltt_align((size_t)(*to+*len), size) + size;
+
+       lttng_write_mystruct2(to, from, len, &obj->teststr);
+
+       lttng_write_array_mystruct_myarray(to, from, len, obj->myarray);
+
+       /* Variable length field */
+       lttng_write_sequence_mystruct_mysequence(to, from, len, &obj->mysequence);
+       
+       lttng_write_mystruct_myunion(to, from, len, &obj->myunion);
+
+       /* Don't forget to flush last write..... */
+}
+
+
+
+
+
+
+void main()
+{
+       struct lttng_mystruct test;
+       test.mysequence.len = 20;
+       test.mysequence.array = malloc(20);
+
+       size_t size = lttng_get_size_mystruct(&test);
+       size_t align = lttng_get_alignment_mystruct(&test);
+
+       void *buf = malloc(align + size);
+       void *to = buf;
+       void *from = &test;
+       size_t len = 0;
+
+       lttng_write_mystruct(&to, &from, &len, &test);
+       /* Final flush */
+       /* Flush pending memcpy */
+       if(len != 0) {
+               memcpy(to, from, len);
+               to += len;
+               from += len;
+               len = 0;
+       }
+       
+       free(test.mysequence.array);
+       free(buf);
+}
index c7e50ca48527d9bb5aac1da4336f59e0124d06c0..b5efa41cce630cf2350064a5fa7a501b86b07598 100644 (file)
@@ -7,6 +7,7 @@
 
 /* Named types */
 
+
 enum lttng_tasklet_priority {
        LTTNG_LOW,
        LTTNG_HIGH,
@@ -23,42 +24,54 @@ struct lttng_mystruct2 {
        //struct lttng_mystruct teststr1;
 };
 
-size_t lttng_get_size_mystruct2(size_t *ret_align,
+
+size_t lttng_get_size_mystruct2(
                struct lttng_mystruct2 *obj)
 {
-       size_t size=0, align=0, locsize, localign;
+       size_t size=0, locsize;
        
        locsize = sizeof(unsigned int);
-       align = max(align, locsize);
        size += ltt_align(size, locsize) + locsize;
        
        locsize = sizeof(enum lttng_irq_mode);
-       align = max(align, locsize);
        size += ltt_align(size, locsize) + locsize;
 
-       *ret_align = align;
+       BUG_ON(sizeof(struct lttng_mystruct2) != size);
+
+       return sizeof(struct lttng_mystruct2);
+}
+
+size_t lttng_get_alignment_mystruct2(
+               struct lttng_mystruct2 *obj)
+{
+       size_t align=0, localign;
        
-       return size;
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
+
+       return align;
 }
 
-void lttng_write_mystruct2(void **ws,
-               void **we,
+void lttng_write_mystruct2(void **to,
+               void **from,
+               size_t *len,
                struct lttng_mystruct2 *obj)
 {
-       size_t align=0, locsize, localign;
+       size_t align, size;
 
-       locsize = lttng_get_size_mystruct2(&align, 
-               obj);
+       align = lttng_get_alignment_mystruct2(obj);
+       size = lttng_get_size_mystruct2(obj);
 
-       if(*ws == *we) {
-               *we += ltt_align(*we, align);
-               *ws = *we;
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
        } else {
-               *we += ltt_align(*we, align);   /* C alignment, ok to do a memcpy of it */
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
        }
        
-       BUG_ON(locsize != sizeof(struct lttng_mystruct2));
-       *we += locsize;
+       *len += size;
 }
 
 
@@ -66,39 +79,51 @@ void lttng_write_mystruct2(void **ws,
 #define LTTNG_ARRAY_SIZE_mystruct_myarray 10
 typedef uint64_t lttng_array_mystruct_myarray[LTTNG_ARRAY_SIZE_mystruct_myarray];
 
-size_t lttng_get_size_array_mystruct_myarray(size_t *ret_align,
+size_t lttng_get_size_array_mystruct_myarray(
                lttng_array_mystruct_myarray obj)
 {
-       size_t size=0, align=0, locsize, localign;
+       size_t size=0, locsize;
        
        locsize = sizeof(uint64_t);
-       align = max(align, locsize);
-       size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+       /* ltt_align == 0 always*/
+       //size += ltt_align(size, locsize) + (LTTNG_ARRAY_SIZE_mystruct_myarray * locsize);
+       BUG_ON(ltt_align(size, locsize) != 0);
+       size += LTTNG_ARRAY_SIZE_mystruct_myarray * locsize;
+
+       BUG_ON(size != LTTNG_ARRAY_SIZE_mystruct_myarray * sizeof(uint64_t));
 
-       *ret_align = align;
-       
        return size;
 }
 
-void lttng_write_array_mystruct_myarray(void **ws,
-               void **we,
-               struct lttng_mystruct2 *obj)
+size_t lttng_get_alignment_array_mystruct_myarray(
+               lttng_array_mystruct_myarray obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(uint64_t);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_array_mystruct_myarray(void **to,
+               void **from,
+               size_t *len,
+               lttng_array_mystruct_myarray obj)
 {
-       size_t align=0, locsize, localign;
+       size_t align, size;
        
-       locsize = lttng_get_size_array_mystruct_myarray(&align, 
-               obj);
+       align = lttng_get_alignment_array_mystruct_myarray(obj);
+       size = lttng_get_size_array_mystruct_myarray(obj);
 
-       if(*ws == *we) {
-               *we += ltt_align(*we, align);
-               *ws = *we;
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
        } else {
-               *we += ltt_align(*we, align);   /* C alignment, ok to do a memcpy of it */
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
        }
        
-       BUG_ON(locsize != LTTNG_ARRAY_SIZE_mystruct_myarray * sizeof(uint64_t));
-
-       *we += locsize;
+       *len += size;
 }
 
 
@@ -109,53 +134,74 @@ struct lttng_sequence_mystruct_mysequence {
 };
 
 
-size_t lttng_get_size_sequence_mystruct_mysequence(size_t *ret_align,
+size_t lttng_get_size_sequence_mystruct_mysequence(
                                                                                                                                 lttng_sequence_mystruct_mysequence *obj)
 {
-       size_t size=0, align=0, locsize, localign;
+       size_t size=0, locsize;
        
        locsize = sizeof(unsigned int);
-       align = max(align, locsize);
        size += ltt_align(size, locsize) + locsize;
 
        locsize = sizeof(double);
-       align = max(align, locsize);
        size += ltt_align(size, locsize) + (obj->len * locsize);
 
-       *ret_align = align;
-
        return size;
 }
 
-void lttng_write_sequence_mystruct_mysequence(void **ws,
-               void **we,
+size_t lttng_get_alignment_sequence_mystruct_mysequence(
+                                                                                                                                lttng_sequence_mystruct_mysequence *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_sequence_mystruct_mysequence(void **to,
+               void **from,
+               size_t *len,
                lttng_sequence_mystruct_mysequence *obj)
 {
-       size_t align=0, locsize, localign;
+       size_t align, size;
+       void *varfrom;
+       size_t varlen=0;
        
        /* Flush pending memcpy */
-       if(*ws != *we) {
-               memcpy(*ws, obj, *we-*ws);
-               *ws = *we;
+       if(*len != 0) {
+               memcpy(*to, *from, *len);
+               *to += *len;
+               *len = 0;
        }
-       
-       lttng_get_size_sequence_mystruct_mysequence(&align, 
-               obj);
 
-       *we += ltt_align(*we, align);
-       *ws = *we;
+       align = lttng_get_alignment_sequence_mystruct_mysequence(obj);
+       //no need size = lttng_get_size_sequence_mystruct_mysequence(obj);
+
+       /* Align output */
+       *to += ltt_align((size_t)(*to), align);
        
-       *we += ltt_align(*we, sizeof(unsigned int));
-       *ws = *we;
-       *we += sizeof(unsigned int);
-       memcpy(*ws, &obj->len, *we-*ws);
-       *ws = *we;
+       /* Copy members */
+       *to += ltt_align((size_t)*to, sizeof(unsigned int));
+       varfrom = &obj->len;
+       varlen += sizeof(unsigned int);
+       memcpy(*to, varfrom, varlen);
+       *to += varlen;
+       varlen = 0;
+
+       *to += ltt_align((size_t)*to, sizeof(double));
+       varfrom = obj->array;
+       varlen += obj->len * sizeof(double);
+       memcpy(*to, varfrom, varlen);
+       *to += varlen;
+       varlen = 0;
 
-       *we += ltt_align(*we, sizeof(double));
-       *ws = *we;
-       *we += obj->len * sizeof(double);
-       memcpy(*ws, obj->array, *we-*ws);
-       *ws = *we;
+       /* Put source *from just after the C sequence */
+       *from = obj+1;
 }
 
 
@@ -165,44 +211,56 @@ union lttng_mystruct_myunion {
        unsigned long myulong;
 };
 
-size_t lttng_get_size_mystruct_myunion(size_t *ret_align,
+
+size_t lttng_get_size_mystruct_myunion(
                                                                                                                                 union lttng_mystruct_myunion *obj)
 {
-       size_t size=0, align=0, locsize, localign;
+       size_t size=0, locsize;
        
        locsize = sizeof(double);
-       align = max(align, locsize);
        size = max(size, locsize);
 
        locsize = sizeof(unsigned long);
-       align = max(align, locsize);
        size = max(size, locsize);
 
-       *ret_align = align;
+       BUG_ON(size != sizeof(union lttng_mystruct_myunion));
 
        return size;
 }
 
 
-void lttng_write_mystruct_myunion(void **ws,
-               void **we,
+size_t lttng_get_alignment_mystruct_myunion(
+                                                                                                                                union lttng_mystruct_myunion *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(double);
+       align = max(align, localign);
+
+       localign = sizeof(unsigned long);
+       align = max(align, localign);
+
+       return align;
+}
+
+
+void lttng_write_mystruct_myunion(void **to,
+               void **from,
+               size_t *len,
                union lttng_mystruct_myunion *obj)
 {
-       size_t align=0, locsize, localign;
+       size_t align, size;
        
-       locsize = lttng_get_size_mystruct_myunion(&align, 
-               obj);
+       align = lttng_get_alignment_mystruct_myunion(obj);
+       size = lttng_get_size_mystruct_myunion(obj);
 
-       if(*ws == *we) {
-               *we += ltt_align(*we, align);
-               *ws = *we;
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
        } else {
-               *we += ltt_align(*we, align);   /* C alignment, ok to do a memcpy of it */
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
        }
        
-       BUG_ON(locsize != sizeof(union lttng_mystruct_myunion));
-
-       *we += locsize;
+       *len += size;
 }
 
 
@@ -215,94 +273,103 @@ struct lttng_mystruct {
        union lttng_mystruct_myunion myunion;
 };
 
-size_t lttng_get_size_mystruct(size_t *ret_align,
+size_t lttng_get_size_mystruct(
                struct lttng_mystruct *obj)
 {
-       size_t size=0, align=0, locsize, localign;
+       size_t size=0, locsize, localign;
        
        locsize = sizeof(unsigned int);
-       align = max(align, locsize);
        size += ltt_align(size, locsize) + locsize;
        
        locsize = sizeof(enum lttng_irq_mode);
-       align = max(align, locsize);
        size += ltt_align(size, locsize) + locsize;
 
-       locsize = lttng_get_size_mystruct2(&localign,
-                       &obj->teststr);
-       align = max(align, localign);
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       locsize = lttng_get_size_mystruct2(&obj->teststr);
        size += ltt_align(size, localign) + locsize;
        
-       locsize = lttng_get_size_array_mystruct_myarray(&localign,
-                       obj->myarray);
-       align = max(align, localign);
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       locsize = lttng_get_size_array_mystruct_myarray(obj->myarray);
        size += ltt_align(size, localign) + locsize;
        
-       locsize = lttng_get_size_sequence_mystruct_mysequence(&localign,
-                       &obj->mysequence);
-       align = max(align, localign);
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       locsize = lttng_get_size_sequence_mystruct_mysequence(&obj->mysequence);
        size += ltt_align(size, localign) + locsize;
        
-       locsize = lttng_get_size_mystruct_myunion(&localign,
-                       &obj->myunion);
-       align = max(align, localign);
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       locsize = lttng_get_size_mystruct_myunion(&obj->myunion);
        size += ltt_align(size, localign) + locsize;
 
-       *ret_align = align;
-
        return size;
 }
 
-struct lttng_mystruct {
-       unsigned int irq_id;
-       enum lttng_irq_mode mode;
-       struct lttng_mystruct2 teststr;
-       lttng_array_mystruct_myarray myarray;
-       lttng_sequence_mystruct_mysequence mysequence;
-       union lttng_mystruct_myunion myunion;
-};
 
+size_t lttng_get_alignment_mystruct(
+               struct lttng_mystruct *obj)
+{
+       size_t align=0, localign;
+       
+       localign = sizeof(unsigned int);
+       align = max(align, localign);
+       
+       localign = sizeof(enum lttng_irq_mode);
+       align = max(align, localign);
 
-void lttng_write_mystruct(void **ws,
-               void **we,
+       localign = lttng_get_alignment_mystruct2(&obj->teststr);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_array_mystruct_myarray(obj->myarray);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_sequence_mystruct_mysequence(&obj->mysequence);
+       align = max(align, localign);
+       
+       localign = lttng_get_alignment_mystruct_myunion(&obj->myunion);
+       align = max(align, localign);
+
+       return align;
+}
+
+void lttng_write_mystruct(void **to,
+               void **from,
+               size_t *len,
                struct lttng_mystruct *obj)
 {
-       size_t align=0, locsize, localign;
+       size_t align, size;
        
-       lttng_get_size_mystruct(&align, 
-               obj);
+       align = lttng_get_alignment_mystruct(obj);
+       // no need : contains variable size fields.
+       // locsize = lttng_get_size_mystruct(obj);
 
-       if(*ws == *we) {
-               *we += ltt_align(*we, align);
-               *ws = *we;
+       if(*len == 0) {
+               *to += ltt_align((size_t)(*to), align); /* align output */
        } else {
-               *we += ltt_align(*we, align);   /* C alignment, ok to do a memcpy of it */
+               *len += ltt_align((size_t)(*to+*len), align);   /* C alignment, ok to do a memcpy of it */
        }
        
-       locsize = sizeof(unsigned int);
-       *we += ltt_align(*we, locsize) + locsize;
+       /* Contains variable sized fields : must explode the structure */
        
-       locsize = sizeof(enum lttng_irq_mode);
-       *we += ltt_align(*we, locsize) + locsize;
+       size = sizeof(unsigned int);
+       *len += ltt_align((size_t)(*to+*len), size) + size;
+       
+       size = sizeof(enum lttng_irq_mode);
+       *len += ltt_align((size_t)(*to+*len), size) + size;
 
-       lttng_write_mystruct2(ws, we, 
-                       &obj->teststr);
+       lttng_write_mystruct2(to, from, len, &obj->teststr);
 
-       lttng_write_array_mystruct_myarray(ws, we, 
-                       obj->myarray);
+       lttng_write_array_mystruct_myarray(to, from, len, obj->myarray);
 
        /* Variable length field */
-       lttng_write_sequence_mystruct_mysequence(ws, we, 
-                       &obj->mysequence);
+       lttng_write_sequence_mystruct_mysequence(to, from, len, &obj->mysequence);
        
-       lttng_write_mystruct_myunion(ws, we, 
-                       obj->myunion);
+       lttng_write_mystruct_myunion(to, from, len, &obj->myunion);
 
        /* Don't forget to flush last write..... */
 }
 
 
 
+
 /* Event syscall_entry structures */
 
 /* Event syscall_entry logging function */
This page took 0.033486 seconds and 4 git commands to generate.