Note that there are some explanatory texts on larger screens.

plurals
  1. POthe stack and vtable [re]location
    primarykey
    data
    text
    <p><strong>NOTE:</strong> To understand my question, you <em>might</em> need to know about my project and the problem. If not, skip right to the "QUESTION" section at the bottom.<br/><br/></p> <p><hr/><strong>PROJECT</strong><br/><br/> I'm working on a writing a C++ class that enables its parent to act like synchronous/blocking threads by having Pause() and Resume(). <br/><br/> Here's an example of how it would work.</p> <pre><code>class BlockingThread : public BlockingThreadBase // all the Asm magic happens in BlockingThreadBase { void StartStopHere(void) // called upon the first Resume() call (pure virtual in base) { printf("1"); Pause(); printf("3"); Pause(); printf("5"); Pause(); } }; int main(void) { BlockingThread obj; obj.Resume(); printf("2"); obj.Resume(); printf("4"); obj.Resume(); printf("6"); return 0; } // OUTPUT: 123456 </code></pre> <p>I've tried true threading and several novel ideas but they ended up too slow to transfer between code locations <strong>21 million times per second.</strong></p> <p>My latest idea is use chunks of the stack (stack buffers) to create the illusion of multiple stacks. When obj1.Resume() is called, it would return to location of its personal stack, <code>New #1 Stack</code>, execute until Pause() and then return to the previous stack location it was at.</p> <p><hr/><strong>ILLUSTRATIONS</strong><br/><br/></p> <p>How the stack would look without any<code>BlockingThread</code> objects in main().</p> <pre><code> _________________ | Normal | Stack | | Stack | Buffer | |________|________| </code></pre> <p>How a<code>BlockingThread</code> object in main() would look like on the stack.</p> <pre><code> ___________________________________ | Normal | Stack | New #1 | Stack | | Stack | Buffer | Stack | Buffer | |________|________|________|________| </code></pre> <p>How <strong>two</strong><code>BlockingThread</code> objects in main() would look like on the stack.</p> <pre><code> _____________________________________________________ | Normal | Stack | New #1 | Stack | New #2 | Stack | | Stack | Buffer | Stack | Buffer | Stack | Buffer | |________|________|________|________|________|________| </code></pre> <p><hr/><strong>PROBLEM</strong><br/><br/></p> <p>When moving to a "new" stack, and then calling obj.Resume() (from main) which in turn call StartStopHere() causes a segfault at the point of calling StartStopHere(). GDB says <code>can't find linker symbol for virtual table for 'BlockingThreadBase' value</code> when I try to get the value of a member variable from BlockingThreadBase. This is why I suspect it has the same problem when trying to find the location of StartStopHere() when it's called.</p> <p><hr/><strong>QUESTION</strong><br/><br/></p> <p>(ignore the italics words if you didn't read the other sections)</p> <p>How can I find [<em>and move or copy</em>] the vtable (or its location if that's what's stored) of the class in the [<em>normal</em>] stack [<em>to a new stack</em>]?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload