@@ -198,6 +198,7 @@ ssize_t V8_OFF_JSOBJECT_PROPERTIES;
198
198
ssize_t V8_OFF_MAP_CONSTRUCTOR ;
199
199
ssize_t V8_OFF_MAP_CONSTRUCTOR_OR_BACKPOINTER ;
200
200
ssize_t V8_OFF_MAP_INOBJECT_PROPERTIES ;
201
+ ssize_t V8_OFF_MAP_INOBJECT_PROPERTIES_OR_CTOR_FUN_INDEX ;
201
202
ssize_t V8_OFF_MAP_INSTANCE_ATTRIBUTES ;
202
203
ssize_t V8_OFF_MAP_INSTANCE_DESCRIPTORS ;
203
204
ssize_t V8_OFF_MAP_INSTANCE_SIZE ;
@@ -224,6 +225,9 @@ ssize_t V8_OFF_SLICEDSTRING_PARENT;
224
225
ssize_t V8_OFF_SLICEDSTRING_OFFSET ;
225
226
ssize_t V8_OFF_STRING_LENGTH ;
226
227
ssize_t V8_OFF_JSTYPEDARRAY_LENGTH ;
228
+ ssize_t V8_OFF_JSARRAYBUFFER_BACKINGSTORE ;
229
+ ssize_t V8_OFF_JSARRAYBUFFERVIEW_BUFFER ;
230
+ ssize_t V8_OFF_JSARRAYBUFFERVIEW_CONTENT_OFFSET ;
227
231
228
232
/* see node_string.h */
229
233
#define NODE_OFF_EXTSTR_DATA sizeof (uintptr_t)
@@ -424,7 +428,17 @@ static v8_offset_t v8_offsets[] = {
424
428
"Map" , "constructor_or_backpointer" ,
425
429
B_FALSE , V8_CONSTANT_ADDED_SINCE (4 , 3 )},
426
430
{ & V8_OFF_MAP_INOBJECT_PROPERTIES ,
427
- "Map" , "inobject_properties" },
431
+ "Map" , "inobject_properties" ,
432
+ B_FALSE , V8_CONSTANT_REMOVED_SINCE (4 , 6 ) },
433
+ #ifdef _LP64
434
+ { & V8_OFF_MAP_INOBJECT_PROPERTIES_OR_CTOR_FUN_INDEX ,
435
+ "Map" , "inobject_properties_or_constructor_function_index" ,
436
+ B_FALSE , V8_CONSTANT_FALLBACK (4 , 6 ), 8 },
437
+ #else
438
+ { & V8_OFF_MAP_INOBJECT_PROPERTIES_OR_CTOR_FUN_INDEX ,
439
+ "Map" , "inobject_properties_or_constructor_function_index" ,
440
+ B_FALSE , V8_CONSTANT_FALLBACK (4 , 6 ), 4 },
441
+ #endif
428
442
{ & V8_OFF_MAP_INSTANCE_ATTRIBUTES ,
429
443
"Map" , "instance_attributes" },
430
444
{ & V8_OFF_MAP_INSTANCE_DESCRIPTORS ,
@@ -482,6 +496,26 @@ static v8_offset_t v8_offsets[] = {
482
496
"JSTypedArray" , "length" ,
483
497
B_FALSE , V8_CONSTANT_FALLBACK (4 , 5 ), 27 },
484
498
#endif
499
+ #ifdef _LP64
500
+ { & V8_OFF_JSARRAYBUFFER_BACKINGSTORE ,
501
+ "JSArrayBuffer" , "backing_store" ,
502
+ B_FALSE , V8_CONSTANT_FALLBACK (4 , 6 ), 23 },
503
+ #else
504
+ { & V8_OFF_JSARRAYBUFFER_BACKINGSTORE ,
505
+ "JSArrayBuffer" , "backing_store" ,
506
+ B_FALSE , V8_CONSTANT_FALLBACK (4 , 6 ), 11 },
507
+ #endif
508
+ { & V8_OFF_JSARRAYBUFFERVIEW_BUFFER ,
509
+ "JSArrayBufferView" , "buffer" },
510
+ #ifdef _LP64
511
+ { & V8_OFF_JSARRAYBUFFERVIEW_CONTENT_OFFSET ,
512
+ "JSArrayBufferView" , "byte_offset" ,
513
+ B_FALSE , V8_CONSTANT_FALLBACK (4 , 6 ), 31 },
514
+ #else
515
+ { & V8_OFF_JSARRAYBUFFERVIEW_CONTENT_OFFSET ,
516
+ "JSArrayBufferView" , "byte_offset" ,
517
+ B_FALSE , V8_CONSTANT_FALLBACK (4 , 6 ), 15 },
518
+ #endif
485
519
};
486
520
487
521
static int v8_noffsets = sizeof (v8_offsets ) / sizeof (v8_offsets [0 ]);
@@ -877,6 +911,10 @@ autoconfigure(v8_cfg_t *cfgp)
877
911
if (V8_OFF_MAP_CONSTRUCTOR_OR_BACKPOINTER != -1 )
878
912
V8_OFF_MAP_CONSTRUCTOR = V8_OFF_MAP_CONSTRUCTOR_OR_BACKPOINTER ;
879
913
914
+ if (V8_OFF_MAP_INOBJECT_PROPERTIES_OR_CTOR_FUN_INDEX != -1 )
915
+ V8_OFF_MAP_INOBJECT_PROPERTIES =
916
+ V8_OFF_MAP_INOBJECT_PROPERTIES_OR_CTOR_FUN_INDEX ;
917
+
880
918
return (failed ? -1 : 0 );
881
919
}
882
920
@@ -5420,6 +5458,8 @@ dcmd_nodebuffer(uintptr_t addr, uint_t flags, int argc,
5420
5458
char * bufp = buf ;
5421
5459
size_t len = sizeof (buf );
5422
5460
uintptr_t elts , rawbuf ;
5461
+ uintptr_t arraybuffer_view_buffer ;
5462
+ uintptr_t arraybufferview_content_offset ;
5423
5463
5424
5464
/*
5425
5465
* The undocumented "-f" option allows users to override constructor
@@ -5440,21 +5480,63 @@ dcmd_nodebuffer(uintptr_t addr, uint_t flags, int argc,
5440
5480
}
5441
5481
}
5442
5482
5443
- /*
5444
- * This works for Buffer instance in node < 4.0 because they use
5445
- * elements slots to reference the backing storage. It also works
5446
- * with Buffer in node >= 4.0 because they actually are typed arrays
5447
- * and typed arrays use elements slots to store the external data.
5448
- * We could use the "backing_store" member of the JSArrayBuffer
5449
- * associated to a typed array instead, but using elements for
5450
- * both "old" Buffer instances and new ones has the benefit of
5451
- * being able to reuse more code.
5452
- */
5453
- if (read_heap_ptr (& elts , addr , V8_OFF_JSOBJECT_ELEMENTS ) != 0 )
5454
- return (DCMD_ERR );
5483
+ if (strcmp (buf , "Buffer" ) == 0 ||
5484
+ V8_OFF_JSARRAYBUFFER_BACKINGSTORE == -1 ) {
5485
+ /*
5486
+ * This works for Buffer instances in node < 4.0 because they
5487
+ * use elements slots to reference the backing storage. If
5488
+ * the constructor name is not "Buffer" but "Uint8Array" and
5489
+ * V8_OFF_JSARRAYBUFFER_BACKINGSTORE == -1, it means we are in
5490
+ * the range of node versions >= 4.0 and <= 4.1 that ship with
5491
+ * V8 4.5.x. For these versions, it also works because Buffer
5492
+ * instances are actually typed arrays but their backing storage
5493
+ * an ExternalUint8Arrayelements whose address is stored in the
5494
+ * first element's slot.
5495
+ */
5496
+ if (read_heap_ptr (& elts , addr , V8_OFF_JSOBJECT_ELEMENTS ) != 0 )
5497
+ return (DCMD_ERR );
5455
5498
5456
- if (obj_v8internal (elts , 0 , & rawbuf ) != 0 )
5457
- return (DCMD_ERR );
5499
+ if (obj_v8internal (elts , 0 , & rawbuf ) != 0 )
5500
+ return (DCMD_ERR );
5501
+ } else {
5502
+ /*
5503
+ * The buffer instance's constructor name is Uint8Array, and
5504
+ * V8_OFF_JSARRAYBUFFER_BACKINGSTORE != -1, which means that
5505
+ * we're dealing with a node version that ships with V8 4.6 or
5506
+ * later. For these versions, buffer instances store their data
5507
+ * as a typed array, but this time instead of having the backing
5508
+ * store as an ExternalUint8Array referenced from an element
5509
+ * slot, it can be found at two different locations:
5510
+ *
5511
+ * 1. As a FixedTypedArray casted as a FixedTypedArrayBase in an
5512
+ * element slot.
5513
+ *
5514
+ * 2. As the "backing_store" property of the corresponding
5515
+ * JSArrayBuffer.
5516
+ *
5517
+ * The second way to retrieve the backing store seems like
5518
+ * it will be less likely to change, and is thus the one we're
5519
+ * using.
5520
+ */
5521
+ if (V8_OFF_JSARRAYBUFFER_BACKINGSTORE == -1 ||
5522
+ V8_OFF_JSARRAYBUFFERVIEW_BUFFER == -1 ||
5523
+ V8_OFF_JSARRAYBUFFERVIEW_CONTENT_OFFSET == -1 )
5524
+ return (DCMD_ERR );
5525
+
5526
+ if (read_heap_ptr (& arraybuffer_view_buffer , addr ,
5527
+ V8_OFF_JSARRAYBUFFERVIEW_BUFFER ) != 0 )
5528
+ return (DCMD_ERR );
5529
+
5530
+ if (read_heap_ptr (& rawbuf , arraybuffer_view_buffer ,
5531
+ V8_OFF_JSARRAYBUFFER_BACKINGSTORE ) != 0 )
5532
+ return (DCMD_ERR );
5533
+
5534
+ if (read_heap_smi (& arraybufferview_content_offset , addr ,
5535
+ V8_OFF_JSARRAYBUFFERVIEW_CONTENT_OFFSET ) != 0 )
5536
+ return (DCMD_ERR );
5537
+
5538
+ rawbuf += arraybufferview_content_offset ;
5539
+ }
5458
5540
5459
5541
mdb_printf ("%p\n" , rawbuf );
5460
5542
return (DCMD_OK );
0 commit comments