Skip to content

Commit

Permalink
#32: more fixes
Browse files Browse the repository at this point in the history
This change fixes:
 - 32 bit v4.x node binaries with improper JSTypedArray length offset.
 - v4.0.0 and v4.1.1 node binaries that miss Map's bit_field3's type
   metadata by hardcoding its type.
  • Loading branch information
Julien Gilli committed Sep 22, 2015
1 parent 19bf5ed commit 966bf63
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/mdb_v8.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,15 @@ static v8_offset_t v8_offsets[] = {
"SlicedString", "parent", B_TRUE },
{ &V8_OFF_STRING_LENGTH,
"String", "length" },
#ifdef _LP64
{ &V8_OFF_JSTYPEDARRAY_LENGTH,
"JSTypedArray", "length",
B_FALSE, V8_CONSTANT_FALLBACK(4, 5), 55 },
#else
{ &V8_OFF_JSTYPEDARRAY_LENGTH,
"JSTypedArray", "length",
B_FALSE, V8_CONSTANT_FALLBACK(4, 5), 27 },
#endif
};

static int v8_noffsets = sizeof (v8_offsets) / sizeof (v8_offsets[0]);
Expand Down Expand Up @@ -1020,6 +1026,8 @@ conf_update_field(v8_cfg_t *cfgp, const char *symbol)
intptr_t offset;
char *pp, *qq, *tt;
char buf[128];
int is_map_bitfield3_smi = 0;
int is_v8_bitfield3_actually_int = 0;

(void) strlcpy(buf, symbol, sizeof (buf));

Expand All @@ -1038,11 +1046,28 @@ conf_update_field(v8_cfg_t *cfgp, const char *symbol)
(flp = conf_field_create(clp, qq, (size_t)offset)) == NULL)
return (-1);

if (strcmp(tt, "int") == 0)
flp->v8f_isbyte = B_TRUE;
is_map_bitfield3_smi = strcmp(pp, "Map") == 0 &&
strcmp(qq, "bit_field3") == 0 && strcmp(tt, "SMI") == 0;

if (strcmp(tt, "char") == 0)
/*
* node v4.0.0 and v4.1.0 were released without the proper post-mortem
* metadata for Map's bit_field3 type, so we hardcode its actual type
* when V8's version is between the version that introduced the change
* from SMI to int and the version where the proper metadata was added
* (inclusive, since several node versions with the same V8 version
* exist and some of them have the proper metadata, some of them don't).
*/
if (is_map_bitfield3_smi)
is_v8_bitfield3_actually_int =
(v8_major == 3 && v8_minor >= 28) ||
(v8_major == 4 && v8_minor <= 5);

if (strcmp(tt, "int") == 0 ||
(is_map_bitfield3_smi && is_v8_bitfield3_actually_int)) {
flp->v8f_isbyte = B_TRUE;
} else if (strcmp(tt, "char") == 0) {
flp->v8f_isstr = B_TRUE;
}

return (0);
}
Expand Down

0 comments on commit 966bf63

Please sign in to comment.