Hi all,
When user code runs out of stack space the program is terminated.
Checking through my code I realised that an interrupt using the stack could throw the user's stack into an exception (stack exception, followed by user program termination), causing OS dramas.
I have programmed around it and was wondering if anyone has an elegant solution?
As an example it would be possible for a user to use all their stack space and then an ethernet interrupt is fired.
Ideas I have are:
1. Set a bool on interrupt call for CPU and test inside page exception, then allocate another page and set another bool to remove page after interrupt call.
2. Change RSP on interrupt call, storing RAX, RSP in specific memory locations per CPU and/or per interrupt.
3. Inside interrupt use syscall...
What ideas are out there?
How to handle Interrupt Stack in Userspace (RSP)
Re: How to handle Interrupt Stack in Userspace (RSP)
Interrupts must run on their own kernel stack. I don't recall the 64-bit details, but in 32-bit mode external interrupts cause a switch from user mode to kernel mode, which switches the stack to SS0:ESP0 from the current TSS. There must be a similar mechanism in 64-bit mode. Check the CPU documentation.
Re: How to handle Interrupt Stack in Userspace (RSP)
Yes thanks. I my ?WISE? decision, I am not using TSS, but I am currently looking to see if I can get it to fit my requirements.alexfru wrote:Interrupts must run on their own kernel stack. I don't recall the 64-bit details, but in 32-bit mode external interrupts cause a switch from user mode to kernel mode, which switches the stack to SS0:ESP0 from the current TSS. There must be a similar mechanism in 64-bit mode. Check the CPU documentation.
Re: How to handle Interrupt Stack in Userspace (RSP)
For 64-bits x86_64 the cpu loads rsp from TSS.rsp0 or from IST depends on your IDT entry.
And no, you can't skip the TSS, to use user-mode you need to setup at least one TSS.
By "not using TSS" people indeed usually mean they do not switch task with TSS - but you still need to initialise it once.
And no, you can't skip the TSS, to use user-mode you need to setup at least one TSS.
By "not using TSS" people indeed usually mean they do not switch task with TSS - but you still need to initialise it once.
Re: How to handle Interrupt Stack in Userspace (RSP)
Yes that is what I thought, just trying to find where I set it up. LOL.bluemoon wrote:For 64-bits x86_64 the cpu loads rsp from TSS.rsp0 or from IST depends on your IDT entry.
And no, you can't skip the TSS, to use user-mode you need to setup at least one TSS.
By "not using TSS" people indeed usually mean they do not switch task with TSS - but you still need to initialise it once.
Re: How to handle Interrupt Stack in Userspace (RSP)
Hi, found it. I am not using "User Mode", I remember my decision now.bluemoon wrote:For 64-bits x86_64 the cpu loads rsp from TSS.rsp0 or from IST depends on your IDT entry.
And no, you can't skip the TSS, to use user-mode you need to setup at least one TSS.
By "not using TSS" people indeed usually mean they do not switch task with TSS - but you still need to initialise it once.
All programs are running on CPL0.
I have not loaded TSS or IST.
It was good to see the assembly code again, with no comments? LOL
Re: How to handle Interrupt Stack in Userspace (RSP)
It looks like I am doing things against the "grain" so to speak, so I will have to accept my work-around code.