X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fproc.c;h=45c5a56126ce89fb453b42e54ff9369d3ace3216;hb=f73bf5f5cf0e188bafe905091aa311627af54b76;hp=3b5ceb2fbfd4edf8060a1699b306d99c7b2c3e61;hpb=54746c855c6e2fe42fde9f93b0ce3f41aeefc2e5;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 3b5ceb2f..45c5a561 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -26,7 +26,7 @@ extern void APStartup(); // 16-bit AP startup code extern Uint GetEIP(); // start.asm extern Uint32 gaInitPageDir[1024]; // start.asm extern void Kernel_Stack_Top; -extern volatile int giThreadListLock; +extern tSpinlock glThreadListLock; extern int giNumCPUs; extern int giNextTID; extern int giTotalTickets; @@ -39,6 +39,7 @@ extern tThread *Threads_GetNextToRun(int CPU); extern void Threads_Dump(); extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags); extern void Isr8(); // Double Fault +extern void Proc_ReturnToUser(); // === PROTOTYPES === void ArchThreads_Init(); @@ -51,6 +52,7 @@ tThread *Proc_GetCurThread(); void Proc_ChangeStack(); int Proc_Clone(Uint *Err, Uint Flags); void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP); +void Proc_CallFaultHandler(tThread *Thread); void Proc_Scheduler(); // === GLOBALS === @@ -693,6 +695,18 @@ int Proc_Demote(Uint *Err, int Dest, tRegs *Regs) return 0; } +/** + * \brief Calls a signal handler in user mode + * \note Used for signals + */ +void Proc_CallFaultHandler(tThread *Thread) +{ + // Rewinds the stack and calls the user function + // Never returns + __asm__ __volatile__ ("mov %0, %%ebp;\n\tcall Proc_ReturnToUser" :: "r"(Thread->FaultHandler)); + for(;;); +} + /** * \fn void Proc_Scheduler(int CPU) * \brief Swap current thread and clears dead threads @@ -703,7 +717,7 @@ void Proc_Scheduler(int CPU) tThread *thread; // If the spinlock is set, let it complete - if(giThreadListLock) return; + if(IS_LOCKED(&glThreadListLock)) return; // Clear Delete Queue while(gDeleteThreads) @@ -779,6 +793,14 @@ void Proc_Scheduler(int CPU) #else __asm__ __volatile__ ("mov %0, %%cr3"::"a"(thread->MemState.CR3)); #endif + + #if 0 + if(thread->SavedState.ESP > 0xC0000000 + && thread->SavedState.ESP < thread->KernelStack-0x2000) { + Log_Warning("Proc", "Possible bad ESP %p (PID %i)", thread->SavedState.ESP); + } + #endif + // Switch threads __asm__ __volatile__ ( "mov %1, %%esp\n\t" // Restore ESP