From 1e36f2a2c888af4ab38af58416d3388939e22948 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Sat, 26 Oct 2013 16:11:59 +0000 Subject: [PATCH] Kernel: export new_sys_threads as CreateThread. Remove hack in set_app_params that allowed creating threads in kernel context under certain conditions git-svn-id: svn://kolibrios.org@4105 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/exports.inc | 2 ++ kernel/trunk/core/taskman.inc | 37 ++++++++++++++++++----------------- kernel/trunk/kernel.asm | 6 +++--- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/kernel/trunk/core/exports.inc b/kernel/trunk/core/exports.inc index af0bdde39f..02e18a5250 100644 --- a/kernel/trunk/core/exports.inc +++ b/kernel/trunk/core/exports.inc @@ -81,6 +81,8 @@ __exports: register_keyboard, 'RegKeyboard', \ delete_keyboard, 'DelKeyboard', \ get_cpu_freq, 'GetCpuFreq', \ +\ + new_sys_threads, 'CreateThread', \ ; ebx, ecx, edx \ srv_handler, 'ServiceHandler', \ fpu_save, 'FpuSave', \ diff --git a/kernel/trunk/core/taskman.inc b/kernel/trunk/core/taskman.inc index 2f60efcc2f..1e7731bbdf 100644 --- a/kernel/trunk/core/taskman.inc +++ b/kernel/trunk/core/taskman.inc @@ -924,10 +924,17 @@ proc write_process_memory ret endp +;ebx = 1 - kernel thread +;ecx=thread entry point +;edx=thread stack pointer +;creation flags 0x01 - debugged +; 0x02 - kernel + align 4 proc new_sys_threads locals - slot dd ? + slot dd ? + flags dd ? app_cmdline dd ? ;0x00 app_path dd ? ;0x04 app_eip dd ? ;0x08 @@ -935,16 +942,15 @@ proc new_sys_threads app_mem dd ? ;0x10 endl - cmp ebx, 1 - jne .failed ;other subfunctions + shl ebx, 1 + mov [flags], ebx xor eax, eax mov [app_eip], ecx mov [app_cmdline], eax mov [app_esp], edx mov [app_path], eax - ;mov esi,new_process_loading - ;call sys_msg_board_str + call lock_application_table call get_new_process_place @@ -998,10 +1004,8 @@ proc new_sys_threads lea eax, [app_cmdline] stdcall set_app_params , [slot], eax, dword 0, \ - dword 0,dword 0 + dword 0, [flags] - ;mov esi,new_process_running - ;call sys_msg_board_str ;output information about succefull startup mov eax, [process_number] ;set result call unlock_application_table ret @@ -1203,18 +1207,17 @@ proc set_app_params stdcall,slot:dword, params:dword,\ mov [ebx+REG_ECX], eax mov [ebx+REG_EAX], eax - mov eax, [esi+0x08] ;app_eip - mov [ebx+REG_EIP], eax;app_entry + mov eax, [esi+0x08] ;app_eip + mov [ebx+REG_EIP], eax ;app_entry mov [ebx+REG_CS], dword app_code mov ecx, USER_PRIORITY - mov eax, [CURRENT_TASK] - shl eax, 8 ; created by kernel? - cmp [SLOT_BASE+eax+APPDATA.dir_table], sys_pgdir - OS_BASE - jnz @f - cmp [app_path], 0 ; it is a thread? - jnz @f + + test byte [flags], 2 + jz @F + mov [ebx+REG_CS], dword os_code ; kernel thread mov ecx, MAX_PRIORITY + @@: mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF @@ -1238,8 +1241,6 @@ proc set_app_params stdcall,slot:dword, params:dword,\ mov [CURRENT_TASK+ebx+TASKDATA.state], dl lea edx, [SLOT_BASE+ebx*8] call scheduler_add_thread - ;mov esi,new_process_running - ;call sys_msg_board_str ;output information about succefull startup ret endp diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index e6cee14eb1..8689d63c1f 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -5568,13 +5568,13 @@ syscall_reserveportarea: ; ReservePortArea and FreePortArea align 4 syscall_threads: ; CreateThreads -; eax=1 create thread ; -; ebx=thread start -; ecx=thread stack value +; ecx=thread entry point +; edx=thread stack pointer ; ; on return : eax = pid + xor ebx, ebx call new_sys_threads mov [esp+32], eax