system calls
Posted: Thu Apr 19, 2007 6:04 pm
Is there any way other than interrupts to return control to the kernel for a system call?
On the x86 architecture you can use call-gates.anon19287473 wrote:Is there any way other than interrupts to return control to the kernel for a system call?
Software interrupts aren't masked by IF, so you can use interrupts for system calls whether or not you have hardware interrupts enabled.pcmattman wrote:What's wrong with interrupts? The only problem I can think of is needing interrupts enabled (which they won't be during an ISR).
There's 5 methods...anon19287473 wrote:Is there any way other than interrupts to return control to the kernel for a system call?
Code: Select all
API_softwareInterruptHandler:
call [API_callTable + eax * 4]
iretd
API_callGateHandler:
call [API_callTable + eax * 4]
retf
API_sysCallHandler:
call [API_callTable + eax * 4]
sysret
API_sysEnterHandler:
call [API_callTable + eax * 4]
sysexit
undefined_opcode_exception_handler:
if( user code caused exception) {
switch( opcode ) {
case WAS_SYSCALL:
call [API_callTable + eax * 4]
iretd
case WAS_SYSENTER:
call [API_callTable + eax * 4]
iretd
default:
criticalError(UNDEFINED_OPCODE, USER_MODE):
} else {
criticalError(UNDEFINED_OPCODE, KERNEL_MODE):
}
Yes, really. Same as exceptions. If you think of it, it makes perfect sense that way. The purpose of the IF-flag is to prevent interrupts when the currently running code can't deal with them. You might not have a valid IDT, or you might not have a valid stack (say when you are switching threads in scheduler). Or you might want to prevent a new interrupt when you've just unmasked PIC but not yet returned, so that you don't end up growing stack by unnecessarily nesting interrupts. Life is also greatly simplified if you can avoid interrupts when you are doing processor synchronization (spinlocks) or some other such situation.pcmattman wrote:Really?
That's something I wish I had have known before...