- union ldoubleIEEE754 u;
- struct definition *tmpdef =
- static_ldouble_declaration->p.definition_new(&static_ldouble_declaration->p,
- NULL, 0, 0);
- struct definition_float *tmpfloat =
- container_of(tmpdef, struct definition_float, p);
- struct ctf_stream_pos srcp;
-
- ctf_init_pos(&srcp, -1, O_RDONLY);
- srcp.base = (char *) u.bits;
-
- u.v = float_definition->value;
- ctf_align_pos(pos, float_declaration->p.alignment);
- _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
- definition_unref(tmpdef);
+ union doubleIEEE754 u;
+ struct bt_definition *tmpdef;
+ struct definition_float *tmpfloat;
+ struct ctf_stream_pos srcp = { { 0 } };
+ struct mmap_align mma;
+ int ret;
+
+ float_lock();
+ switch (float_declaration->mantissa->len + 1) {
+ case FLT_MANT_DIG:
+ tmpdef = static_float_declaration->p.definition_new(
+ &static_float_declaration->p,
+ NULL, 0, 0, "__tmpfloat");
+ break;
+ case DBL_MANT_DIG:
+ tmpdef = static_double_declaration->p.definition_new(
+ &static_double_declaration->p,
+ NULL, 0, 0, "__tmpfloat");
+ break;
+ default:
+ ret = -EINVAL;
+ goto end;
+ }
+ tmpfloat = container_of(tmpdef, struct definition_float, p);
+ ctf_init_pos(&srcp, NULL, -1, O_RDONLY);
+ mmap_align_set_addr(&mma, (char *) u.bits);
+ srcp.base_mma = &mma;
+ srcp.packet_size = sizeof(u) * CHAR_BIT;
+ switch (float_declaration->mantissa->len + 1) {
+ case FLT_MANT_DIG:
+ u.vf = float_definition->value;
+ break;
+ case DBL_MANT_DIG:
+ u.vd = float_definition->value;
+ break;
+ default:
+ ret = -EINVAL;
+ goto end_unref;
+ }
+ if (!ctf_align_pos(pos, float_declaration->p.alignment)) {
+ ret = -EFAULT;
+ goto end_unref;
+ }
+ ret = _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
+
+end_unref:
+ bt_definition_unref(tmpdef);
+end:
+ float_unlock();
+ return ret;