git.ucc.asn.au
/
tpg
/
acess2.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
270e5fe
)
Cleaned up places where MM_Allocate was used without checks
author
John Hodge
<
[email protected]
>
Sat, 12 Feb 2011 02:25:00 +0000
(10:25 +0800)
committer
John Hodge
<
[email protected]
>
Sat, 12 Feb 2011 02:25:00 +0000
(10:25 +0800)
Kernel/arch/x86/include/mm_virt.h
patch
|
blob
|
history
Kernel/arch/x86/mm_phys.c
patch
|
blob
|
history
Kernel/arch/x86/proc.c
patch
|
blob
|
history
Kernel/heap.c
patch
|
blob
|
history
Kernel/syscalls.c
patch
|
blob
|
history
Kernel/threads.c
patch
|
blob
|
history
Kernel/vfs/handle.c
patch
|
blob
|
history
Usermode/Applications/bomb_src/main.c
patch
|
blob
|
history
diff --git
a/Kernel/arch/x86/include/mm_virt.h
b/Kernel/arch/x86/include/mm_virt.h
index
5e4712f
..
84b088c
100644
(file)
--- a/
Kernel/arch/x86/include/mm_virt.h
+++ b/
Kernel/arch/x86/include/mm_virt.h
@@
-27,7
+27,7
@@
// === FUNCTIONS ===
extern void MM_FinishVirtualInit(void);
extern void MM_SetCR3(Uint CR3);
// === 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);
extern void MM_Deallocate(tVAddr VAddr);
extern int MM_Map(tVAddr VAddr, tPAddr PAddr);
extern tPAddr MM_Clone(void);
diff --git
a/Kernel/arch/x86/mm_phys.c
b/Kernel/arch/x86/mm_phys.c
index
ef289ac
..
faef2b3
100644
(file)
--- a/
Kernel/arch/x86/mm_phys.c
+++ b/
Kernel/arch/x86/mm_phys.c
@@
-107,7
+107,11
@@
void MM_Install(tMBoot_Info *MBoot)
//LOG("Reference Pages %i", (giPageCount*4+0xFFF)>>12);
for(num = 0; num < (giPageCount*4+0xFFF)>>12; num++)
{
//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");
}
//LOG("Filling");
diff --git
a/Kernel/arch/x86/proc.c
b/Kernel/arch/x86/proc.c
index
4812609
..
55b9b17
100644
(file)
--- a/
Kernel/arch/x86/proc.c
+++ b/
Kernel/arch/x86/proc.c
@@
-368,7
+368,10
@@
void ArchThreads_Init(void)
#endif
// Create Per-Process Data Block
#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();
// Change Stacks
Proc_ChangeStack();
@@
-707,7
+710,13
@@
Uint Proc_MakeUserStack(void)
// Allocate Stack - Allocate incrementally to clean up MM_Dump output
for( i = 0; i < USER_STACK_SZ/0x1000; i++ )
// 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;
}
return base + USER_STACK_SZ;
}
diff --git
a/Kernel/heap.c
b/Kernel/heap.c
index
34dd5f2
..
8a7adec
100644
(file)
--- a/
Kernel/heap.c
+++ b/
Kernel/heap.c
@@
-69,8
+69,14
@@
void *Heap_Extend(int Bytes)
}
// Heap expands in pages
}
// 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;
// Increas heap end
gHeapEnd += i << 12;
diff --git
a/Kernel/syscalls.c
b/Kernel/syscalls.c
index
6e8d60e
..
95ad2e5
100644
(file)
--- a/
Kernel/syscalls.c
+++ b/
Kernel/syscalls.c
@@
-311,8
+311,10
@@
void SyscallHandler(tSyscallRegs *Regs)
// -- Debug
//#if DEBUG_BUILD
case SYS_DEBUG:
// -- 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);
Regs->Arg2, Regs->Arg3, Regs->Arg4, Regs->Arg5, Regs->Arg6);
+ LogF("\n");
break;
//#endif
break;
//#endif
diff --git
a/Kernel/threads.c
b/Kernel/threads.c
index
5d15c92
..
13914a8
100644
(file)
--- a/
Kernel/threads.c
+++ b/
Kernel/threads.c
@@
-465,6
+465,7
@@
void Threads_Exit(int TID, int Status)
void Threads_Kill(tThread *Thread, int Status)
{
tMsg *msg;
void Threads_Kill(tThread *Thread, int Status)
{
tMsg *msg;
+ int isCurThread = Thread == Proc_GetCurThread();
// TODO: Kill all children
#if 1
// TODO: Kill all children
#if 1
@@
-529,6
+530,7
@@
void Threads_Kill(tThread *Thread, int Status)
);
}
break;
);
}
break;
+ // Kill it while it sleeps!
case THREAD_STAT_SLEEPING:
if( !Threads_int_DelFromQueue( &gSleepingThreads, Thread ) )
{
case THREAD_STAT_SLEEPING:
if( !Threads_int_DelFromQueue( &gSleepingThreads, Thread ) )
{
@@
-538,6
+540,15
@@
void Threads_Kill(tThread *Thread, int Status)
);
}
break;
);
}
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);
default:
Log_Warning("Threads", "Threads_Kill - BUG Un-checked status (%i)",
Thread->Status);
@@
-565,7
+576,7
@@
void Threads_Kill(tThread *Thread, int Status)
SHORTREL( &Thread->IsLocked ); // TODO: We may not actually be released...
// And, reschedule
SHORTREL( &Thread->IsLocked ); // TODO: We may not actually be released...
// And, reschedule
- if(
Status != -1
) {
+ if(
isCurThread
) {
for( ;; )
HALT();
}
for( ;; )
HALT();
}
diff --git
a/Kernel/vfs/handle.c
b/Kernel/vfs/handle.c
index
4a8d478
..
21a98e0
100644
(file)
--- a/
Kernel/vfs/handle.c
+++ b/
Kernel/vfs/handle.c
@@
-60,7
+60,13
@@
int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
Uint addr, size;
size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
for(addr = 0; addr < size; addr += 0x1000)
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
memset( gaUserHandles, 0, size );
}
// Get a handle
@@
-81,7
+87,13
@@
int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
Uint addr, size;
size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
for(addr = 0; addr < size; addr += 0x1000)
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
memset( gaKernelHandles, 0, size );
}
// Get a handle
diff --git
a/Usermode/Applications/bomb_src/main.c
b/Usermode/Applications/bomb_src/main.c
index
944d6c3
..
af5d094
100644
(file)
--- a/
Usermode/Applications/bomb_src/main.c
+++ b/
Usermode/Applications/bomb_src/main.c
@@
-57,6
+57,7
@@
int main(int argc, char *argv[])
return 0;
}
tid = clone(0, stack+stackSize-stackOffset);
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)
if( tid == 0 )
{
// Sleep forever (TODO: Fix up the stack so it can nuke)
@@
-66,7
+67,6
@@
int main(int argc, char *argv[])
printf("Clone failed\n");
return 0;
}
printf("Clone failed\n");
return 0;
}
- printf("stack = %p, tid = %i\n", stack, tid);
}
}
}
}
UCC
git Repository :: git.ucc.asn.au