From 149b37ab41da1105db27303b38c43eb237b779da Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 22 Sep 2009 21:21:12 +0800 Subject: [PATCH] Fixed bug in libc.so/brk(), fixed support for VT100 escape codes --- Kernel/drv/vterm.c | 1 + Usermode/Libraries/libacess.so_src/core.asm | 2 + .../libacess.so_src/syscalls.inc.asm | 49 +++++++++++++++++++ Usermode/Libraries/libc.so_src/heap.c | 19 ++++--- Usermode/include/acess/sys.h | 1 + 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index 4b5a2317..d945bda3 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -332,6 +332,7 @@ void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) { if( Buffer[i] == 0x1B ) // Escape Sequence { + i ++; i += VT_int_ParseEscape(Term, (char*)&Buffer[i]); continue; } diff --git a/Usermode/Libraries/libacess.so_src/core.asm b/Usermode/Libraries/libacess.so_src/core.asm index 22a2aa08..97403223 100644 --- a/Usermode/Libraries/libacess.so_src/core.asm +++ b/Usermode/Libraries/libacess.so_src/core.asm @@ -43,3 +43,5 @@ SYSCALL3 SysSpawn, SYS_SPAWN SYSCALL3 execve, SYS_EXECVE SYSCALL2 SysLoadBin, SYS_LOADBIN + +SYSCALL6 _SysDebug, 0x100 diff --git a/Usermode/Libraries/libacess.so_src/syscalls.inc.asm b/Usermode/Libraries/libacess.so_src/syscalls.inc.asm index fc0b9c05..c6e11df0 100644 --- a/Usermode/Libraries/libacess.so_src/syscalls.inc.asm +++ b/Usermode/Libraries/libacess.so_src/syscalls.inc.asm @@ -87,3 +87,52 @@ pop ebp ret %endmacro + +; System Call - 5 Arguments +%macro SYSCALL5 2 +[global %1:func] +%1: + push ebp + mov ebp, esp + push ebx + push edi + push esi + mov eax, %2 + mov ebx, [ebp+8] + mov ecx, [ebp+12] + mov edx, [ebp+16] + mov edi, [ebp+20] + mov esi, [ebp+24] + int 0xAC + mov [_errno], ebx + pop esi + pop edi + pop ebx + pop ebp + ret +%endmacro + +; System Call - 6 Arguments +%macro SYSCALL6 2 +[global %1:func] +%1: + push ebp + mov ebp, esp + push ebx + push edi + push esi + mov eax, %2 + mov ebx, [ebp+8] + mov ecx, [ebp+12] + mov edx, [ebp+16] + mov edi, [ebp+20] + mov esi, [ebp+24] + mov ebp, [ebp+28] + int 0xAC + mov [_errno], ebx + pop esi + pop edi + pop ebx + pop ebp + ret +%endmacro diff --git a/Usermode/Libraries/libc.so_src/heap.c b/Usermode/Libraries/libc.so_src/heap.c index 23df92a7..6832738c 100644 --- a/Usermode/Libraries/libc.so_src/heap.c +++ b/Usermode/Libraries/libc.so_src/heap.c @@ -34,7 +34,7 @@ EXPORT void free(void *mem); EXPORT void *realloc(void *mem, Uint bytes); EXPORT void *sbrk(int increment); LOCAL void *extendHeap(int bytes); -LOCAL uint brk(int delta); +LOCAL uint brk(Uint newpos); //Code @@ -260,7 +260,7 @@ EXPORT void *sbrk(int increment) static size_t oldEnd = 0; static size_t curEnd = 0; - //SysDebug("sbrk: (increment=%i)\n", increment); + //_SysDebug("sbrk: (increment=%i)\n", increment); if (oldEnd == 0) curEnd = oldEnd = brk(0); @@ -328,20 +328,25 @@ static void *FindHeapBase() return NULL; } -LOCAL uint brk(int delta) +LOCAL uint brk(Uint newpos) { static uint curpos; uint pages; uint ret = curpos; + int delta; + + //_SysDebug("brk: (newpos=0x%x)", newpos); // Find initial position if(curpos == 0) curpos = (uint)FindHeapBase(); // Get Current Position - if(delta == 0) - { - return curpos; - } + if(newpos == 0) return curpos; + + if(newpos < curpos) return newpos; + + delta = newpos - curpos; + //_SysDebug(" brk: delta = 0x%x", delta); // Do we need to add pages if(curpos & 0xFFF && (curpos & 0xFFF) + delta < 0x1000) diff --git a/Usermode/include/acess/sys.h b/Usermode/include/acess/sys.h index d0b45307..4431e0b9 100644 --- a/Usermode/include/acess/sys.h +++ b/Usermode/include/acess/sys.h @@ -30,6 +30,7 @@ struct s_sysFInfo { typedef struct s_sysFInfo t_sysFInfo; // === FUNCTIONS === +void _SysDebug(char *str, ...); // --- Proc --- void sleep(); int clone(int flags, void *stack); -- 2.20.1