Strange register (or stack?) clobber problem.
Posted: Fri Jul 15, 2011 8:00 am
Hi!
I have implemented kernel threads in my x86_64 kernel recently, and it's finally (sort of) working... I can start a few dozen threads, and they get scheduled alright. But after a while, threads start to die... All the threads do is write to the screen in a tight loop. somewhere in the logging functions, all of a sudden parameters are 0 (or some other random value) where they shouldn't.
I suspect that a timer interrupt occurs somewhere in a bad place, and somehow clobbers the registers used for parameter passing. i triple checked the thread state saving and restoring code [1], but cannot seem to find a problem there. also, i checked whether a nested interrupt could have confused some code, but in [2] the interrupt handlers are completely locked (i have only the BSP running so far) by disabling interrupts.
i also disabled the red-zone, so that should not be the problem. when disassembling the method that crashes, i can see, that the compiler generates code to save the register used to pass in the parameter to the stack. right after that, if i check the value, it's zero.... i debugged this for a while now (which is pretty much impossible, since the timer tends to fire faster than i can debug ) and am out of ideas. any suggestion what i could look out for would be appreciated...
[1] https://github.com/mduft/tachyon3/blob/ ... 64/state.S
[2] https://github.com/mduft/tachyon3/blob/ ... 6_64/idt.S - line 49
did i forget to mention something...?
thanks for the help
markus
I have implemented kernel threads in my x86_64 kernel recently, and it's finally (sort of) working... I can start a few dozen threads, and they get scheduled alright. But after a while, threads start to die... All the threads do is write to the screen in a tight loop. somewhere in the logging functions, all of a sudden parameters are 0 (or some other random value) where they shouldn't.
I suspect that a timer interrupt occurs somewhere in a bad place, and somehow clobbers the registers used for parameter passing. i triple checked the thread state saving and restoring code [1], but cannot seem to find a problem there. also, i checked whether a nested interrupt could have confused some code, but in [2] the interrupt handlers are completely locked (i have only the BSP running so far) by disabling interrupts.
i also disabled the red-zone, so that should not be the problem. when disassembling the method that crashes, i can see, that the compiler generates code to save the register used to pass in the parameter to the stack. right after that, if i check the value, it's zero.... i debugged this for a while now (which is pretty much impossible, since the timer tends to fire faster than i can debug ) and am out of ideas. any suggestion what i could look out for would be appreciated...
[1] https://github.com/mduft/tachyon3/blob/ ... 64/state.S
[2] https://github.com/mduft/tachyon3/blob/ ... 6_64/idt.S - line 49
did i forget to mention something...?
thanks for the help
markus