From d235c8914ce6dc8e57e5da130274149f8c0f7af7 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Sat, 1 Feb 2025 02:53:14 +0000 Subject: [PATCH] Fix ghost threads in CPU * kernel: Make sf9 return TSTATE_FREE for invalid slots: 0, >255, free. * menu: Ignore free slots even if other fields of proc_info look valid. Documentation (sysfuncs.txt) clearly states all the other info as invalid when slot_state is TSTATE_FREE. * taskbar: Same as menu. * cmm/lib/*: Same as menu. * programs/macros.inc: Add TSTATE_* macros. --- kernel/trunk/kernel.asm | 19 +++++----------- programs/cmm/lib/kolibri.h | 1 + programs/cmm/lib/patterns/restart_process.h | 25 ++++++++++++--------- programs/macros.inc | 11 ++++++++- programs/system/menu/trunk/menu.asm | 9 ++++---- programs/system/taskbar/trunk/drawappl.inc | 2 ++ 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 3be8af1b0..68c8ac4b2 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -2320,23 +2320,16 @@ sys_cpuusage: jne .no_who_am_i mov ecx, [current_slot_idx] .no_who_am_i: - jecxz .empty_slot + ; default value for (slot == 0) and (slot > 255) + mov [ebx+process_information.slot_state], TSTATE_FREE + test ecx, ecx + jz .nofillbuf cmp ecx, max_processes - ja .empty_slot + ja .nofillbuf mov edx, ecx shl edx, BSF sizeof.APPDATA cmp [SLOT_BASE+edx+APPDATA.state], TSTATE_FREE - jnz .thread_found -.empty_slot: - ; zero buffer for an empty slot - push edi - xor eax, eax - mov edi, ebx - movi ecx, sizeof.process_information - rep stosb - pop edi - jmp .nofillbuf -.thread_found: + jz .nofillbuf ; +4: word: position of the window of thread in the window stack mov ax, [WIN_STACK + ecx * 2] mov [ebx+process_information.window_stack_position], ax diff --git a/programs/cmm/lib/kolibri.h b/programs/cmm/lib/kolibri.h index 46c036861..b8f063ee7 100644 --- a/programs/cmm/lib/kolibri.h +++ b/programs/cmm/lib/kolibri.h @@ -79,6 +79,7 @@ dword I_Path = #__path; #define CLOSE_BTN 1 +#define TSTATE_FREE 9 //------------------------------------------------------------------------- #include "../lib/system.h" diff --git a/programs/cmm/lib/patterns/restart_process.h b/programs/cmm/lib/patterns/restart_process.h index 29c00bbb8..f4ad3d754 100644 --- a/programs/cmm/lib/patterns/restart_process.h +++ b/programs/cmm/lib/patterns/restart_process.h @@ -15,10 +15,12 @@ enum { :bool CheckProcessExists(dword proc_name) { int i; proc_info Process; - for (i=0; iprocess info ; out: ZF set <=> do not draw + cmp byte [ebx + process_information.slot_state], TSTATE_FREE + jz .nodraw cmp byte [ebx + process_information.process_name], '@' jz .nodraw ; do not draw undefined (zero-sized) windows