git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Trying to reduce the ability for a fork bomb to fault the kernel
[tpg/acess2.git]
/
Kernel
/
arch
/
x86
/
vm8086.c
diff --git
a/Kernel/arch/x86/vm8086.c
b/Kernel/arch/x86/vm8086.c
index
1f4f1f4
..
5253a62
100644
(file)
--- a/
Kernel/arch/x86/vm8086.c
+++ b/
Kernel/arch/x86/vm8086.c
@@
-44,7
+44,7
@@
tVM8086 *VM8086_Init(void);
// === GLOBALS ===
MODULE_DEFINE(0, 0x100, VM8086, VM8086_Install, NULL, NULL);
// === GLOBALS ===
MODULE_DEFINE(0, 0x100, VM8086, VM8086_Install, NULL, NULL);
-t
Spinlock
glVM8086_Process;
+t
Mutex
glVM8086_Process;
tPID gVM8086_WorkerPID;
tTID gVM8086_CallingThread;
tVM8086 volatile * volatile gpVM8086_State = (void*)-1; // Set to -1 to avoid race conditions
tPID gVM8086_WorkerPID;
tTID gVM8086_CallingThread;
tVM8086 volatile * volatile gpVM8086_State = (void*)-1; // Set to -1 to avoid race conditions
@@
-55,7
+55,7
@@
int VM8086_Install(char **Arguments)
tPID pid;
// Lock to avoid race conditions
tPID pid;
// Lock to avoid race conditions
-
LOCK
( &glVM8086_Process );
+
Mutex_Acquire
( &glVM8086_Process );
// Create BIOS Call process
pid = Proc_Clone(NULL, CLONE_VM);
// Create BIOS Call process
pid = Proc_Clone(NULL, CLONE_VM);
@@
-130,7
+130,8
@@
int VM8086_Install(char **Arguments)
gVM8086_WorkerPID = pid;
Log_Log("VM8086", "gVM8086_WorkerPID = %i", pid);
gVM8086_WorkerPID = pid;
Log_Log("VM8086", "gVM8086_WorkerPID = %i", pid);
- Threads_Yield(); // Yield to allow the child to initialise
+ while( gpVM8086_State != NULL )
+ Threads_Yield(); // Yield to allow the child to initialise
return MODULE_ERR_OK;
}
return MODULE_ERR_OK;
}
@@
-146,9
+147,11
@@
void VM8086_GPF(tRegs *Regs)
{
if( gpVM8086_State == (void*)-1 ) {
Log_Log("VM8086", "Worker thread ready and waiting");
{
if( gpVM8086_State == (void*)-1 ) {
Log_Log("VM8086", "Worker thread ready and waiting");
-
RELEASE( &glVM8086_Process );
// Release lock obtained in VM8086_Install
+
Mutex_Release( &glVM8086_Process );
// Release lock obtained in VM8086_Install
gpVM8086_State = NULL;
}
gpVM8086_State = NULL;
}
+ //Log_Log("VM8086", "gpVM8086_State = %p, gVM8086_CallingThread = %i",
+ // gpVM8086_State, gVM8086_CallingThread);
if( gpVM8086_State ) {
gpVM8086_State->AX = Regs->eax; gpVM8086_State->CX = Regs->ecx;
gpVM8086_State->DX = Regs->edx; gpVM8086_State->BX = Regs->ebx;
if( gpVM8086_State ) {
gpVM8086_State->AX = Regs->eax; gpVM8086_State->CX = Regs->ecx;
gpVM8086_State->DX = Regs->edx; gpVM8086_State->BX = Regs->ebx;
@@
-156,7
+159,9
@@
void VM8086_GPF(tRegs *Regs)
gpVM8086_State->SI = Regs->esi; gpVM8086_State->DI = Regs->edi;
gpVM8086_State->DS = Regs->ds; gpVM8086_State->ES = Regs->es;
gpVM8086_State = NULL;
gpVM8086_State->SI = Regs->esi; gpVM8086_State->DI = Regs->edi;
gpVM8086_State->DS = Regs->ds; gpVM8086_State->ES = Regs->es;
gpVM8086_State = NULL;
- Threads_WakeTID(gVM8086_CallingThread);
+ // Ensure the caller wakes
+ //while(Threads_WakeTID(gVM8086_CallingThread) == -EALREADY)
+ // Threads_Yield();
}
//Log_Log("VM8086", "Waiting for something to do");
}
//Log_Log("VM8086", "Waiting for something to do");
@@
-396,13
+401,13
@@
void VM8086_Int(tVM8086 *State, Uint8 Interrupt)
State->IP = *(Uint16*)(KERNEL_BASE+4*Interrupt);
State->CS = *(Uint16*)(KERNEL_BASE+4*Interrupt+2);
State->IP = *(Uint16*)(KERNEL_BASE+4*Interrupt);
State->CS = *(Uint16*)(KERNEL_BASE+4*Interrupt+2);
-
LOCK
( &glVM8086_Process );
+
Mutex_Acquire
( &glVM8086_Process );
gpVM8086_State = State;
gVM8086_CallingThread = Threads_GetTID();
Threads_WakeTID( gVM8086_WorkerPID );
while( gpVM8086_State != NULL )
gpVM8086_State = State;
gVM8086_CallingThread = Threads_GetTID();
Threads_WakeTID( gVM8086_WorkerPID );
while( gpVM8086_State != NULL )
- Threads_
Sleep
();
+ Threads_
Yield
();
-
RELEASE
( &glVM8086_Process );
+
Mutex_Release
( &glVM8086_Process );
}
}
UCC
git Repository :: git.ucc.asn.au