// === FUNCTIONS ===
extern void MM_FinishVirtualInit(void);
extern void MM_SetCR3(Uint CR3);
-extern tPAddr MM_Allocate(tVAddr VAddr);
+extern tPAddr MM_Allocate(tVAddr VAddr) __attribute__ ((warn_unused_result));
extern void MM_Deallocate(tVAddr VAddr);
extern int MM_Map(tVAddr VAddr, tPAddr PAddr);
extern tPAddr MM_Clone(void);
//LOG("Reference Pages %i", (giPageCount*4+0xFFF)>>12);
for(num = 0; num < (giPageCount*4+0xFFF)>>12; num++)
{
- MM_Allocate( REFERENCE_BASE + (num<<12) );
+ if( !MM_Allocate( REFERENCE_BASE + (num<<12) ) )
+ {
+ Panic("Oh, ****, no space for the reference pages, that's bad");
+ for(;;);
+ }
}
//LOG("Filling");
#endif
// Create Per-Process Data Block
- MM_Allocate(MM_PPD_CFG);
+ if( !MM_Allocate(MM_PPD_CFG) )
+ {
+ Panic("OOM - No space for initiali Per-Process Config");
+ }
// Change Stacks
Proc_ChangeStack();
// Allocate Stack - Allocate incrementally to clean up MM_Dump output
for( i = 0; i < USER_STACK_SZ/0x1000; i++ )
- MM_Allocate( base + (i<<12) );
+ {
+ if( !MM_Allocate( base + (i<<12) ) )
+ {
+ Warning("OOM: Proc_MakeUserStack");
+ return 0;
+ }
+ }
return base + USER_STACK_SZ;
}
}
// Heap expands in pages
- for(i=0;i<(Bytes+0xFFF)>>12;i++)
- MM_Allocate( (tVAddr)gHeapEnd+(i<<12) );
+ for( i = 0; i < (Bytes+0xFFF) >> 12; i ++ )
+ {
+ if( !MM_Allocate( (tVAddr)gHeapEnd+(i<<12) ) )
+ {
+ Warning("OOM - Heap_Extend");
+ return NULL;
+ }
+ }
// Increas heap end
gHeapEnd += i << 12;
// -- Debug
//#if DEBUG_BUILD
case SYS_DEBUG:
- Log((char*)Regs->Arg1,
+ LogF("Log: [%i] ", Threads_GetTID());
+ LogF((char*)Regs->Arg1,
Regs->Arg2, Regs->Arg3, Regs->Arg4, Regs->Arg5, Regs->Arg6);
+ LogF("\n");
break;
//#endif
void Threads_Kill(tThread *Thread, int Status)
{
tMsg *msg;
+ int isCurThread = Thread == Proc_GetCurThread();
// TODO: Kill all children
#if 1
);
}
break;
+ // Kill it while it sleeps!
case THREAD_STAT_SLEEPING:
if( !Threads_int_DelFromQueue( &gSleepingThreads, Thread ) )
{
);
}
break;
+
+ // Brains!... You cannot kill
+ case THREAD_STAT_ZOMBIE:
+ Log_Warning("Threads", "Threads_Kill - Thread %p(%i,%s) is undead, you cannot kill it",
+ Thread, Thread->TID, Thread->ThreadName);
+ SHORTREL( &glThreadListLock );
+ SHORTREL( &Thread->IsLocked );
+ return ;
+
default:
Log_Warning("Threads", "Threads_Kill - BUG Un-checked status (%i)",
Thread->Status);
SHORTREL( &Thread->IsLocked ); // TODO: We may not actually be released...
// And, reschedule
- if(Status != -1) {
+ if(isCurThread) {
for( ;; )
HALT();
}
Uint addr, size;
size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
for(addr = 0; addr < size; addr += 0x1000)
- MM_Allocate( (Uint)gaUserHandles + addr );
+ {
+ if( !MM_Allocate( (Uint)gaUserHandles + addr ) )
+ {
+ Warning("OOM - VFS_AllocHandle");
+ Threads_Exit(0, 0xFF); // Terminate user
+ }
+ }
memset( gaUserHandles, 0, size );
}
// Get a handle
Uint addr, size;
size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
for(addr = 0; addr < size; addr += 0x1000)
- MM_Allocate( (Uint)gaKernelHandles + addr );
+ {
+ if( !MM_Allocate( (Uint)gaKernelHandles + addr ) )
+ {
+ Panic("OOM - VFS_AllocHandle");
+ Threads_Exit(0, 0xFF); // Terminate application (get some space back)
+ }
+ }
memset( gaKernelHandles, 0, size );
}
// Get a handle
return 0;
}
tid = clone(0, stack+stackSize-stackOffset);
+ //_SysDebug("tid = %i", tid);
if( tid == 0 )
{
// Sleep forever (TODO: Fix up the stack so it can nuke)
printf("Clone failed\n");
return 0;
}
- printf("stack = %p, tid = %i\n", stack, tid);
}
}