[Dlang-internal] Modifying vtbl in ClassInfo

Jean-Louis Leroy via Dlang-internal dlang-internal at puremagic.com
Mon Jun 26 15:19:43 PDT 2017


I realize I am doing bad things, anyway...

I'd like to modify the vtbl inside ClassInfo. My goal is to stick 
a pointer inside each instance of a series of types, and I 
thought I'd reserve a slot in the vtbl and put the pointer in 
place of the function, like this:

import std.stdio;

class MethObject
{
   void methSlotTable() { }
}

int[] a_slots = [ 0, 1 ];

void main()
{
   int firstUserVFunc = 5;
   assert(MethObject.classinfo.vtbl[firstUserVFunc] == 
&MethObject.methSlotTable);
   writeln(MethObject.classinfo.vtbl);
   MethObject.classinfo.vtbl[firstUserVFunc] = cast(void*) 
a_slots.ptr;
}

Not so surprisingly, I get a segfault:
ldc2 -unittest --run abi.d
[624230, 40CC50, 40C9E0, 40CC70, 40CB70, 40CED0]
Error: abi failed with status: -2
Error: message: Segmentation fault (core dumped)
Error: program received signal 2 (Interrupt)

Is the vtbl mprotected? Is there a chance of making this work?



More information about the Dlang-internal mailing list