|
About
TODO
Blog
RSS
Old blog
Projects
Gallery
Notes
Wed, 24 Jan 2007
I congratulate Grange with his birthday!
Climbing evening.
Execution different function after returning from signal handler. struct sigframe *frame = (void *)get_ebp + sizeof(void *); struct sigcontext *sc = &frame->sc;Above is correct at least on x86 and x86_64 (except that register is %rbp),
although above structures are cpu-specific. If %eip (or %rip)
is changed in signal handler to pointer to the new function, it will be called instead
of function, which is supposed to run in that context.Here is a log: main 1814: scheduling first, context size: 88, fpstte: 624. call_me_func: ebp: 0xb7f19ff8, stack: 0xb7f1a008, diff: 16. call_me_func: esp: 0xb7f19fb0, stack: 0xb7f1a008, diff: 88. 1169655167: th: 0x8049c00, stack: 0xb7efa008, id: 1, esp: b7f19fb0, ebp: b7f19ff8. alarm_sighandler: ebp: 0xb7f19b08, esp: 0xb7f19ad0, func: 0x804868a, frame: 0xb7f19b0c, call_me_func: 0x804856c. alarm_sighandler: prev: esp: b7f19de8, ebp: b7f19fa8, eip: 3404db. alarm_sighandler: eip set to 804865a. sched_return: func: 0x804865a, ebp: b7f19de4, esp: b7f19dcc. 1169655168: th: 0x8049c00, stack: 0xb7efa008, id: 2, esp: b7f19fb0, ebp: b7f19ff8. 1169655171: th: 0x8049c00, stack: 0xb7efa008, id: 3, esp: b7f19fb0, ebp: b7f19ff8. 1169655174: th: 0x8049c00, stack: 0xb7efa008, id: 4, esp: b7f19fb0, ebp: b7f19ff8.As you can see, sched_return() is called instead of old function,
which prints next string since sched_return() returns.To implement correct userspace scheduling I only need to replace the whole struct sigframe
function with context from different thread. So far this looks simple,
how it will be in practice I will check tomorrow, and now I need some climbing.P.S. in previous story about how signals work I made a mistake saying that new signal stack is allocated - no, the same process' stack is used, or alternative one if it is available and thus special flag is set. /devel/threading :: Link / Comments (0) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||