From 59315b183d678a8bb973ba4222a0ca83656d3b44 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Mon, 30 Jan 2023 03:33:03 +0000 Subject: [PATCH] [kernel] Fix reading from empty board buffer (sf63.2) Syscall 63.2, reading from the board buffer, was overwriting registers edx and ebp when the buffer was empty. Now it sets eax and ebx according to the kernel API. Because of this ancient bug BOARD checks the status of sf63.2 syscall this way: mcall 63, 2 cmp ebx, 1 jne no_data ; when the buffer is empty, ebx is untouched, i.e. still 2, haha ; edx and ebp are destroyed, the code is lucky not to use them By the way, the bug was found using umka tool. git-svn-id: svn://kolibrios.org@9897 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/kernel.asm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 4c4ca3bf16..81d3bdcbbb 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -3377,7 +3377,7 @@ align 4 set_app_param: mov edi, [current_slot] xchg ebx, [edi + APPDATA.event_mask] ; set new event mask - mov [esp + SYSCALL_STACK.eax], ebx ; return old mask value + mov [esp + SYSCALL_STACK.eax], ebx ; return old mask value ret ;----------------------------------------------------------------------------- @@ -3393,7 +3393,6 @@ if 1 align 4 delay_hs: ; delay in 1/100 secs ; ebx = delay time - pushad push ebx xor esi, esi @@ -4226,24 +4225,23 @@ end if pop ebx eax ret -@@: - mov [esp + SYSCALL_STACK.eax], ecx - mov [esp+20], ecx - jmp .ret - .read: cmp eax, 2 jne .ret - test ecx, ecx - jz @b add esp, 8 ; returning data in ebx and eax, so no need to restore them + test ecx, ecx + jnz @f + mov [esp + SYSCALL_STACK.eax], ecx + mov [esp + SYSCALL_STACK.ebx], ecx + ret +@@: mov eax, msg_board_data+1 mov ebx, msg_board_data movzx edx, byte [ebx] call memmove dec [msg_board_count] - mov [esp + SYSCALL_STACK.eax], edx ;eax - mov [esp + 20], dword 1 + mov [esp + SYSCALL_STACK.eax], edx + mov [esp + SYSCALL_STACK.ebx], 1 ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;