Click here to Skip to main content
15,888,171 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
assume that we have a single thread program and we hope to capture the value of program counter (PC) when a predefined interrupt occurs (like a timer interrupt).
It seems easy as you know we just write a specific assembly code using a special keyword "__asm__" and pop the value on the top of the stack after making a shift 4 byte.
What about Multithreaded programs ?
How can we get values of all threads from another thread which run in the same process? (It seems extremely incredible to get values from thread which run on a separate core in multi-core processors).
(in multithreaded programs, every thread has its stack and registers too).

-------------------------------------

C#
I would  implement a saboteur thread.
in order to perform fault injection in the target multi-threaded program, the model of fault is SEU (single error upset) which means that an arbitrary bit in the program counter register modified randomly (bit-flip) causing to violate the right program sequence. therefore, control flow error (CFE)  occurs.
Since our target program is a multi-threaded program, we have to perform fault injection on all threads' PC. This is the task of saboteur tread. It should be able  to obtain threads' PC to perform fault injection.
assume we have this code,
main ()
{
foo
}

void foo()
{
__asm__{
pop "%eax"
pop "%ebx" // now ebx holds porgram counter value (for main thread)
// her code injection like  00000111 XOR ebx for example
push ...
push ...
};
}

If our program was a multithreaded program.
is it means that we have more than one stack? 
when OS perform context switching, it means that the stack and registers of the thread that was running moved to some place in the memory. Does this mean that if we want to get the values of the program counter for those threads, we find them in memory? where? and is it possible during run-time?




any help, I am grateful to you.

What I have tried:

by using __asm__ , we can get the value of PC of the main thread.
Posted
Updated 24-Jun-16 9:59am
v3

AFAIK, no.
The problem is that you don't know when your thread is running: let alone what other thread are running at the same time. And in modern processors, that could indeed be "at the same time" - multiple cores means multiple simultaneous threads, and each core could easily be running it's thread purely from cache, so...your interrupt would only be running on one core, and you have no idea what thread is running on the other(s).
Even on a single threaded app, you have no guarantee that the core the interrupt is running on is the same core as your app!
And if a thread is stalled, it's in memory (or even paged to disk) along with its registers - and you probably won't have access to that memory, even if you know where it is because it's outside "your" address space.
 
Share this answer
 
Comments
HusseinAl-haj 24-Jun-16 15:29pm    
I would implement a saboteur thread.
in order to perform fault injection in the target multi-threaded program, the model of fault is SEU (single error upset) which means that an arbitrary bit in the program counter register modified randomly (bit-flip) causing to violate the right program sequence. therefore, control flow error (CFE) occurs.
Since our target program is a multi-threaded program, we have to perform fault injection on all threads' PC. This is the task of saboteur tread. It should be able to obtain threads' PC to perform fault injection.
assume we have this code,
main ()
{
foo
}

void foo()
{
__asm__{
pop "%eax"
pop "%ebx" // now ebx holds porgram counter value (for main thread)
// her code injection like 00000111 XOR ebx for example
push ...
push ...
};
}

If our program was a multithreaded program.
is it means that we have more than one stack?
when OS perform context switching, it means that the stack and registers of the thread that was running moved to some place in the memory. Does this mean that if we want to get the values of the program counter for those threads, we find them in memory? where? and is it possible during run-time?
thanks alot.
It's possible to get the context, but setting it is not recommended on a running thread as behavior is unpredictable.

See GetThreadContext function (Windows)[^].

That is the only hint you're going to get and this is as far as I go. I will not help on this any further. You are on your own from this point on.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900