Re: linux-specific behavior, or coincidence?
- From: The Natural Philosopher <a@xxx>
- Date: Fri, 16 Mar 2007 08:48:58 +0000
Sir Jackery wrote:
On Thu, 15 Mar 2007, The Natural Philosopher wrote:
Sir Jackery wrote:On Thu, 15 Mar 2007, The Natural Philosopher wrote:Asynchronous.
Amadeus W.M. wrote:synchronous interrupt.What happens if you put another function call between "x = foobar();"
and "y=x[0]". I suspect you're just seeing the fact that the stack
hasn't been reused yet. Try putting a 'printf("hello there\n");' in
there.
Of course, calling something else between x=foobar() and y=*x forces the stack to be reused. Is there any circumstance when the stack is overwritten even if I don't force it with another function call? For instance (however unlikely), could the system choose to run another process in between the two instructions? What happens then with the stack? It's not going to stay the same, is it?
An asynchronous interrupt MIGHT cause the stack to get trashed..
Strictly synchronous interrupts aren't interrupts at all.
How can you say that? Synchronous interrupts (deterministic) are functions of memory state like program overflow. Asynchronous interrupts (nondeterministic) are external device or hardware related interrupts. It is highly unlikely that a nondeterministic interrupt would corrupt the stack, but deterministic ones possible could.
Ah..thats becase I am an hardware guy,..
the normal mechanism for an asynchronous interrupt is that the processor will *at the least push* the program counter into the current stack, and jump to the interrupt service routine.
I haver seen SOME hardware designs where the program counter is stored in a separate interrupt stack, but its not that common.
For re-entrancy, the ISR itself will normally also push any registers it needs to use into the stack..so you tend to use ate least 4-5 stack locations in the current stack under an asynchronous interrupt from e.g. an IO or timer interrupt.
'Intrerrupts' that are triggered by the code thread itself are not what I call interrupts at all really, they are just a different sort of subroutine call.
And they wont happen in general between two lines of C code. Its normally something that is built into the kernel. The possible exception being a call to memory that is illegal..resulting in a trap type instruction.
However the code shown by the OP is not exactly accessing illegal memory in that sense. Few processors check for access to the stack below the current stack pointer rather than above.
The code fragment presented is a use of memory whose location is not illegal, but whose content is highly implementation specific and potentially transitory, that's all.
If his original declaration was for a character array that was - say - a megabyte deep instead of a few characters, then x[0] might well be deeper than almost anything would carry the stack pointer, and he would stand a good chance of better persistence of the data.
Or he might instantly overflow the stack area with such a declaration :-)
.
--
Sir Jackery
- References:
- linux-specific behavior, or coincidence?
- From: Amadeus W.M.
- Re: linux-specific behavior, or coincidence?
- From: Steve Wampler
- Re: linux-specific behavior, or coincidence?
- From: Amadeus W.M.
- Re: linux-specific behavior, or coincidence?
- From: The Natural Philosopher
- Re: linux-specific behavior, or coincidence?
- From: Sir Jackery
- Re: linux-specific behavior, or coincidence?
- From: The Natural Philosopher
- Re: linux-specific behavior, or coincidence?
- From: Sir Jackery
- linux-specific behavior, or coincidence?
- Prev by Date: Re: Document in Linux.
- Next by Date: Re: linux-specific behavior, or coincidence?
- Previous by thread: Re: linux-specific behavior, or coincidence?
- Next by thread: Re: linux-specific behavior, or coincidence?
- Index(es):
Relevant Pages
|