2011-10-15 01:38:50 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2024-05-22 18:15:14 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2016-08-25 22:30:08 +03:00
|
|
|
;; Distributed under terms of the GNU General Public License. ;;
|
2011-10-15 01:38:50 +04:00
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
2017-12-20 04:07:10 +03:00
|
|
|
GREEDY_KERNEL = 0
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2012-02-23 22:52:13 +04:00
|
|
|
struct APP_HEADER_01_
|
|
|
|
banner dq ?
|
|
|
|
version dd ? ;+8
|
|
|
|
start dd ? ;+12
|
|
|
|
i_end dd ? ;+16
|
|
|
|
mem_size dd ? ;+20
|
|
|
|
stack_top dd ? ;+24
|
|
|
|
i_param dd ? ;+28
|
|
|
|
i_icon dd ? ;+32
|
|
|
|
ends
|
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
struct APP_HDR
|
|
|
|
cmdline rd 1 ;0x00
|
|
|
|
path rd 1 ;0x04
|
|
|
|
eip rd 1 ;0x08
|
|
|
|
esp rd 1 ;0x0C
|
|
|
|
_edata rd 1 ;0x10
|
|
|
|
_emem rd 1 ;0x14
|
|
|
|
img_base rd 1 ;0x18
|
|
|
|
img_size rd 1
|
|
|
|
filename_size rd 1
|
|
|
|
cmdline_size rd 1
|
2016-08-25 22:30:08 +03:00
|
|
|
path_string rd 1
|
2012-02-23 22:52:13 +04:00
|
|
|
ends
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
macro _clear_ op
|
|
|
|
{ mov ecx, op/4
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
}
|
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
align 4
|
|
|
|
_strnlen:
|
|
|
|
mov edx, ecx
|
|
|
|
xor eax, eax
|
|
|
|
repne scasb
|
|
|
|
jne @F
|
|
|
|
inc ecx
|
|
|
|
@@:
|
|
|
|
mov eax, edx
|
|
|
|
sub eax, ecx
|
|
|
|
retn
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
fs_execute_from_sysdir:
|
|
|
|
xor ebx, ebx
|
|
|
|
fs_execute_from_sysdir_param:
|
2016-12-09 12:48:32 +03:00
|
|
|
stdcall kernel_alloc, maxPathLength
|
|
|
|
push eax ebx
|
|
|
|
mov esi, ebp
|
|
|
|
mov edi, eax
|
|
|
|
xor eax, eax
|
|
|
|
call getFullPath
|
|
|
|
pop ecx ebx
|
2011-10-15 01:38:50 +04:00
|
|
|
xor edx, edx
|
2021-07-08 20:55:19 +03:00
|
|
|
; @brief Executes a program
|
|
|
|
; @param edx Flags
|
|
|
|
; @param ecx Commandline
|
|
|
|
; @param ebx Absolute file path
|
|
|
|
; @param eax String length
|
2021-07-08 21:08:28 +03:00
|
|
|
; @returns Negated error code or new process number
|
2011-10-15 01:38:50 +04:00
|
|
|
proc fs_execute
|
2016-08-25 22:30:08 +03:00
|
|
|
locals
|
|
|
|
cmdline rd 1
|
|
|
|
flags rd 1
|
2021-02-14 16:21:22 +03:00
|
|
|
slot rd 1 ; index of new thread slot
|
2021-02-14 02:42:08 +03:00
|
|
|
slot_base rd 1 ; base address of it
|
2016-08-25 22:30:08 +03:00
|
|
|
; app header data
|
|
|
|
hdr_cmdline rd 1
|
|
|
|
hdr_path rd 1
|
|
|
|
hdr_eip rd 1
|
|
|
|
hdr_esp rd 1
|
|
|
|
hdr_edata rd 1
|
|
|
|
hdr_emem rd 1
|
|
|
|
file_base rd 1
|
|
|
|
file_size rd 1
|
|
|
|
filename_size rd 1
|
|
|
|
cmdline_size rd 1
|
|
|
|
path_string rd 1
|
|
|
|
endl
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2021-11-05 00:45:55 +03:00
|
|
|
and edx, 1 ;clear flags user. TODO: add api for start apps with user flags
|
2011-10-15 01:38:50 +04:00
|
|
|
mov [flags], edx
|
2016-12-09 12:48:32 +03:00
|
|
|
mov [cmdline], ecx
|
|
|
|
mov [path_string], ebx
|
|
|
|
mov [filename_size], eax
|
|
|
|
mov esi, -ERROR_FILE_NOT_FOUND
|
2016-08-25 22:30:08 +03:00
|
|
|
test eax, eax
|
|
|
|
jz .err_file
|
2016-12-09 12:48:32 +03:00
|
|
|
stdcall load_file, ebx
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .err_file
|
|
|
|
|
|
|
|
mov [file_base], eax
|
|
|
|
mov [file_size], ebx
|
|
|
|
lea ebx, [hdr_cmdline]
|
2021-02-14 16:21:22 +03:00
|
|
|
call test_app_header ; fill our app header data locals with values from header of given program (if its correct)
|
2021-07-08 23:04:59 +03:00
|
|
|
mov esi, -TASKMAN_ERROR_NOT_A_EXECUTABLE
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .err_hdr
|
|
|
|
|
2013-05-27 13:02:35 +04:00
|
|
|
call lock_application_table
|
2021-02-14 02:42:08 +03:00
|
|
|
call alloc_thread_slot ; create a slot for new thread
|
2021-07-08 23:04:59 +03:00
|
|
|
mov esi, -TASKMAN_ERROR_TOO_MANY_PROCESSES
|
2016-03-13 09:08:07 +03:00
|
|
|
test eax, eax
|
|
|
|
jz .err_0
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov [slot], eax
|
2022-02-12 20:27:41 +03:00
|
|
|
shl eax, BSF sizeof.APPDATA
|
|
|
|
lea edi, [SLOT_BASE + eax]
|
2016-03-13 09:08:07 +03:00
|
|
|
mov [slot_base], edi
|
2016-08-25 22:30:08 +03:00
|
|
|
; clean extended information about process
|
2020-10-12 05:54:44 +03:00
|
|
|
mov ecx, sizeof.APPDATA/4
|
2016-03-13 09:08:07 +03:00
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
2021-02-14 02:42:08 +03:00
|
|
|
; write application name ( APPDATA.appname )
|
2016-08-25 22:30:08 +03:00
|
|
|
stdcall strrchr, [path_string], '/'
|
|
|
|
lea esi, [eax+1] ; -> name without path
|
|
|
|
mov ecx, 11
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edi, [slot_base]
|
2016-08-25 22:30:08 +03:00
|
|
|
@@:
|
|
|
|
call utf8to16
|
|
|
|
call uni2ansi_char
|
2011-10-15 01:38:50 +04:00
|
|
|
cmp al, '.'
|
2016-08-25 22:30:08 +03:00
|
|
|
jz @f
|
2011-10-15 01:38:50 +04:00
|
|
|
test al, al
|
2016-08-25 22:30:08 +03:00
|
|
|
jz @f
|
2011-10-15 01:38:50 +04:00
|
|
|
stosb
|
2016-08-25 22:30:08 +03:00
|
|
|
loop @b
|
|
|
|
@@:
|
2016-03-13 09:08:07 +03:00
|
|
|
mov edi, [cmdline]
|
|
|
|
xor eax, eax
|
|
|
|
test edi, edi
|
2016-08-25 22:30:08 +03:00
|
|
|
jz @f
|
2016-03-13 09:08:07 +03:00
|
|
|
mov ecx, 65535
|
|
|
|
call _strnlen
|
|
|
|
cmp eax, 256
|
2016-08-25 22:30:08 +03:00
|
|
|
jb @f
|
2021-02-14 02:42:08 +03:00
|
|
|
; if cmdline length >= 256 then increase needed memory size by this length
|
2016-03-13 09:08:07 +03:00
|
|
|
lea ebx, [eax+1]
|
|
|
|
add [hdr_emem], ebx
|
|
|
|
@@:
|
|
|
|
mov [cmdline_size], eax
|
2021-02-14 02:42:08 +03:00
|
|
|
stdcall create_process, [hdr_emem] ; create a new process
|
2021-07-08 23:04:59 +03:00
|
|
|
mov esi, -TASKMAN_ERROR_OUT_OF_MEMORY
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, eax
|
2016-03-13 09:08:07 +03:00
|
|
|
jz .err_hdr
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2021-02-14 02:42:08 +03:00
|
|
|
; add new process to the list
|
2022-02-12 20:27:41 +03:00
|
|
|
mov ebx, [sys_proc + LHEAD.prev]
|
2016-02-20 12:57:44 +03:00
|
|
|
__list_add eax, ebx, sys_proc
|
2021-02-14 02:42:08 +03:00
|
|
|
; fill the structure fields:
|
2016-03-13 09:08:07 +03:00
|
|
|
mov ebx, [hdr_emem]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [eax + PROC.mem_used], ebx
|
2021-02-14 02:42:08 +03:00
|
|
|
|
|
|
|
; write that main thread of app belongs to new process
|
2011-10-15 01:38:50 +04:00
|
|
|
mov ebx, [slot_base]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APPDATA.process], eax
|
2021-02-14 02:42:08 +03:00
|
|
|
|
|
|
|
; initialize the thread list of process: at this moment it consists only of one main thread
|
2022-02-12 20:27:41 +03:00
|
|
|
lea edx, [ebx + APPDATA.list]
|
|
|
|
lea ecx, [eax + PROC.thr_list]
|
2014-09-18 11:58:56 +04:00
|
|
|
list_add_tail edx, ecx
|
2021-02-14 02:42:08 +03:00
|
|
|
|
|
|
|
; allocate space and copy app header data locals and cmdline string there, put pointer to exec_params of new thread
|
2016-08-25 22:30:08 +03:00
|
|
|
mov eax, [cmdline_size]
|
|
|
|
add eax, sizeof.APP_HDR
|
|
|
|
stdcall kernel_alloc, eax
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APPDATA.exec_params], eax
|
2016-03-13 09:08:07 +03:00
|
|
|
mov edi, eax
|
|
|
|
lea esi, [hdr_cmdline]
|
|
|
|
mov ecx, sizeof.APP_HDR/4
|
|
|
|
rep movsd
|
|
|
|
mov ecx, [cmdline_size]
|
|
|
|
mov esi, [cmdline]
|
|
|
|
rep movsb
|
2021-02-14 02:42:08 +03:00
|
|
|
; set other parameters of application
|
2011-10-15 01:38:50 +04:00
|
|
|
lea eax, [hdr_cmdline]
|
2016-03-13 09:08:07 +03:00
|
|
|
stdcall set_app_params , [slot], eax, [flags]
|
2021-02-14 02:42:08 +03:00
|
|
|
mov eax, [process_number] ; return process number
|
2013-05-27 13:02:35 +04:00
|
|
|
call unlock_application_table
|
2016-03-13 09:08:07 +03:00
|
|
|
ret
|
2012-03-24 00:13:09 +04:00
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
.err_0:
|
|
|
|
call unlock_application_table
|
2011-10-15 01:38:50 +04:00
|
|
|
.err_hdr:
|
|
|
|
stdcall kernel_free, [file_base]
|
|
|
|
.err_file:
|
2016-08-25 22:30:08 +03:00
|
|
|
stdcall kernel_free, [path_string]
|
2011-10-15 01:38:50 +04:00
|
|
|
mov eax, esi
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
test_app_header:
|
|
|
|
virtual at eax
|
2012-02-23 22:52:13 +04:00
|
|
|
APP_HEADER_01 APP_HEADER_01_
|
2011-10-15 01:38:50 +04:00
|
|
|
end virtual
|
|
|
|
|
|
|
|
cmp dword [eax], 'MENU'
|
|
|
|
jne .fail
|
|
|
|
cmp word [eax+4], 'ET'
|
|
|
|
jne .fail
|
|
|
|
|
|
|
|
cmp [eax+6], word '01'
|
|
|
|
je @f
|
|
|
|
cmp [eax+6], word '02'
|
|
|
|
jne .fail
|
|
|
|
@@:
|
|
|
|
mov ecx, [APP_HEADER_01.start]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + 0x08], ecx
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edx, [APP_HEADER_01.mem_size]
|
|
|
|
|
|
|
|
; \begin{diamond}[20.08.2006]
|
|
|
|
; sanity check (functions 19,58 load app_i_end bytes and that must
|
|
|
|
; fit in allocated memory to prevent kernel faults)
|
|
|
|
cmp edx, [APP_HEADER_01.i_end]
|
|
|
|
jb .fail
|
|
|
|
; \end{diamond}[20.08.2006]
|
2022-04-26 16:09:12 +03:00
|
|
|
cmp edx, OS_BASE ;check memory
|
|
|
|
jae .fail
|
|
|
|
mov ecx, [pg_data.pages_free]
|
|
|
|
shl ecx, 12 ; ecx * 4kb
|
|
|
|
cmp edx, ecx
|
|
|
|
jae .fail
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APP_HDR._emem], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
mov ecx, [APP_HEADER_01.stack_top]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APP_HDR.esp], ecx
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edx, [APP_HEADER_01.i_param]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APP_HDR.cmdline], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
mov ecx, [APP_HEADER_01.i_icon]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APP_HDR.path], ecx
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edx, [APP_HEADER_01.i_end]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APP_HDR._edata], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
2014-09-18 11:58:56 +04:00
|
|
|
alloc_thread_slot:
|
2011-10-15 01:38:50 +04:00
|
|
|
;input:
|
|
|
|
; none
|
|
|
|
;result:
|
2014-09-18 11:58:56 +04:00
|
|
|
; eax=[new_thread_slot]<>0 - ok
|
2011-10-15 01:38:50 +04:00
|
|
|
; 0 - failed.
|
|
|
|
;This function find least empty slot.
|
2021-06-16 13:04:10 +03:00
|
|
|
;It doesn't increase [thread_count]!
|
2014-09-18 11:58:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
mov edx, thr_slot_map
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
.l1:
|
|
|
|
bsf eax, [edx]
|
|
|
|
jnz .found
|
|
|
|
add edx, 4
|
2022-02-12 20:27:41 +03:00
|
|
|
cmp edx, thr_slot_map + 32
|
2014-09-18 11:58:56 +04:00
|
|
|
jb .l1
|
|
|
|
|
|
|
|
popfd
|
2011-10-15 01:38:50 +04:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2014-09-18 11:58:56 +04:00
|
|
|
.found:
|
|
|
|
btr [edx], eax
|
|
|
|
sub edx, thr_slot_map
|
2022-02-12 20:27:41 +03:00
|
|
|
lea eax, [eax + edx*8]
|
2014-09-18 11:58:56 +04:00
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
align 4
|
2016-03-13 09:08:07 +03:00
|
|
|
proc create_process stdcall, app_size:dword
|
2011-10-15 01:38:50 +04:00
|
|
|
locals
|
2014-09-18 11:58:56 +04:00
|
|
|
process dd ?
|
2011-10-15 01:38:50 +04:00
|
|
|
app_tabs dd ?
|
|
|
|
endl
|
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
xor eax, eax
|
2014-09-18 11:58:56 +04:00
|
|
|
mov [process], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov eax, [app_size]
|
2016-03-13 09:08:07 +03:00
|
|
|
add eax, 0x3FFFFF
|
|
|
|
shr eax, 22
|
|
|
|
mov [app_tabs], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
stdcall kernel_alloc, 0x2000
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2014-09-18 11:58:56 +04:00
|
|
|
mov [process], eax
|
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
lea edi, [eax + PROC.heap_lock]
|
|
|
|
mov ecx, (PROC.ht_free - PROC.heap_lock)/4
|
2014-09-18 11:58:56 +04:00
|
|
|
|
|
|
|
list_init eax
|
|
|
|
add eax, PROC.thr_list
|
|
|
|
list_init eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
|
2015-07-22 14:17:45 +03:00
|
|
|
mov [edi], dword (PROC.pdt_0 - PROC.htab)/4 - 3
|
|
|
|
mov [edi+4], dword 3 ;reserve handles for stdin stdout and stderr
|
2014-12-01 07:35:53 +03:00
|
|
|
mov ecx, (PROC.pdt_0 - PROC.htab)/4
|
2015-07-22 14:17:45 +03:00
|
|
|
add edi, 8
|
|
|
|
inc eax
|
2014-12-01 07:35:53 +03:00
|
|
|
@@:
|
|
|
|
stosd
|
|
|
|
inc eax
|
|
|
|
cmp eax, ecx
|
|
|
|
jbe @B
|
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
mov eax, edi
|
|
|
|
call get_pg_addr
|
2023-02-15 02:26:59 +03:00
|
|
|
mov [edi - PAGE_SIZE + PROC.pdt_0_phys], eax
|
2014-09-18 11:58:56 +04:00
|
|
|
|
|
|
|
mov ecx, (OS_BASE shr 20)/4
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
mov ecx, (OS_BASE shr 20)/4
|
2022-02-12 20:27:41 +03:00
|
|
|
mov esi, sys_proc + PROC.pdt_0 + (OS_BASE shr 20)
|
2011-10-15 01:38:50 +04:00
|
|
|
rep movsd
|
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov eax, [edi - 8192 + PROC.pdt_0_phys]
|
2015-01-06 17:53:54 +03:00
|
|
|
or eax, PG_SWR
|
2023-02-15 02:26:59 +03:00
|
|
|
mov [edi - PAGE_SIZE + (page_tabs shr 20)], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2023-02-15 02:26:59 +03:00
|
|
|
lea edx, [edi - PAGE_SIZE]
|
2016-03-13 09:08:07 +03:00
|
|
|
mov esi, [app_tabs]
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
.alloc_page_dir:
|
2011-10-15 01:38:50 +04:00
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2016-03-13 09:08:07 +03:00
|
|
|
or eax, PG_UWR
|
|
|
|
mov [edx], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
mov edi, [tmp_task_ptab]
|
|
|
|
stdcall map_page, edi, eax, PG_SWR
|
2023-08-21 00:54:50 +03:00
|
|
|
mov ecx, PAGE_SIZE/4
|
2011-10-15 01:38:50 +04:00
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
add edx, 4
|
|
|
|
dec esi
|
|
|
|
jnz .alloc_page_dir
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
|
2014-09-18 11:58:56 +04:00
|
|
|
mov eax, [process]
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
.fail:
|
2016-03-13 09:08:07 +03:00
|
|
|
mov ecx, [process]
|
|
|
|
jcxz @F
|
|
|
|
|
|
|
|
call destroy_process
|
2011-10-15 01:38:50 +04:00
|
|
|
@@:
|
|
|
|
xor eax, eax
|
2014-09-18 11:58:56 +04:00
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc destroy_page_table stdcall, pg_tab:dword
|
|
|
|
|
|
|
|
push esi
|
|
|
|
|
|
|
|
mov esi, [pg_tab]
|
|
|
|
mov ecx, 1024
|
|
|
|
.free:
|
|
|
|
mov eax, [esi]
|
|
|
|
test eax, 1
|
|
|
|
jz .next
|
2014-09-18 11:58:56 +04:00
|
|
|
test eax, 2
|
|
|
|
jz .next
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, 1 shl 9
|
|
|
|
jnz .next ;skip shared pages
|
|
|
|
call free_page
|
|
|
|
.next:
|
|
|
|
add esi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz .free
|
|
|
|
pop esi
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2014-09-18 11:58:56 +04:00
|
|
|
destroy_process: ;fastcall ecx= ptr to process
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
lea eax, [ecx+PROC.thr_list]
|
|
|
|
cmp eax, [eax+LHEAD.next]
|
|
|
|
jne .exit
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
align 4
|
|
|
|
.internal:
|
|
|
|
push ecx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2016-02-20 12:57:44 +03:00
|
|
|
mov esi, ecx
|
|
|
|
list_del esi
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov esi, [esi + PROC.dlls_list_ptr]
|
2016-02-20 12:57:44 +03:00
|
|
|
call destroy_all_hdlls
|
2014-09-18 11:58:56 +04:00
|
|
|
|
|
|
|
mov esi, [esp]
|
|
|
|
add esi, PROC.pdt_0
|
|
|
|
mov edi, (0x80000000 shr 20)/4
|
2011-10-15 01:38:50 +04:00
|
|
|
.destroy:
|
|
|
|
mov eax, [esi]
|
|
|
|
test eax, 1
|
|
|
|
jz .next
|
2023-02-15 02:26:59 +03:00
|
|
|
and eax, -PAGE_SIZE
|
2015-01-06 17:53:54 +03:00
|
|
|
stdcall map_page, [tmp_task_ptab], eax, PG_SWR
|
2011-10-15 01:38:50 +04:00
|
|
|
stdcall destroy_page_table, [tmp_task_ptab]
|
|
|
|
mov eax, [esi]
|
|
|
|
call free_page
|
|
|
|
.next:
|
|
|
|
add esi, 4
|
|
|
|
dec edi
|
|
|
|
jnz .destroy
|
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
call kernel_free ;ecx still in stack
|
2011-10-15 01:38:50 +04:00
|
|
|
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
|
2014-09-18 11:58:56 +04:00
|
|
|
.exit:
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
get_pid:
|
2022-01-11 13:50:30 +03:00
|
|
|
mov eax, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov eax, [eax + APPDATA.tid]
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
pid_to_slot:
|
|
|
|
;Input:
|
|
|
|
; eax - pid of process
|
|
|
|
;Output:
|
|
|
|
; eax - slot of process or 0 if process don't exists
|
|
|
|
;Search process by PID.
|
|
|
|
push ebx
|
|
|
|
push ecx
|
2021-06-16 13:04:10 +03:00
|
|
|
mov ebx, [thread_count]
|
2022-02-09 20:07:51 +03:00
|
|
|
shl ebx, BSF sizeof.APPDATA ; multiply by size
|
2021-06-14 14:48:48 +03:00
|
|
|
; skip first process in the task table
|
2022-02-09 20:07:51 +03:00
|
|
|
mov ecx, sizeof.APPDATA
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
.loop:
|
2021-06-14 14:48:48 +03:00
|
|
|
;ecx = offset of current process info entry
|
|
|
|
;ebx = maximum permitted offset
|
2022-02-09 20:07:51 +03:00
|
|
|
cmp [SLOT_BASE + ecx + APPDATA.state], TSTATE_FREE
|
2011-10-15 01:38:50 +04:00
|
|
|
jz .endloop ;skip empty slots
|
2022-02-12 20:27:41 +03:00
|
|
|
cmp [SLOT_BASE + ecx + APPDATA.tid], eax
|
2022-02-06 23:33:29 +03:00
|
|
|
jz .pid_found
|
2011-10-15 01:38:50 +04:00
|
|
|
.endloop:
|
2022-02-09 20:07:51 +03:00
|
|
|
add ecx, sizeof.APPDATA
|
2011-10-15 01:38:50 +04:00
|
|
|
cmp ecx, ebx
|
|
|
|
jle .loop
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.pid_found:
|
2022-02-09 20:07:51 +03:00
|
|
|
shr ecx, BSF sizeof.APPDATA ; divide by size
|
2011-10-15 01:38:50 +04:00
|
|
|
mov eax, ecx ;convert offset to index of slot
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc read_process_memory
|
|
|
|
;Input:
|
|
|
|
; eax - process slot
|
|
|
|
; ecx - buffer address
|
|
|
|
; edx - buffer size
|
|
|
|
; esi - start address in other process
|
|
|
|
;Output:
|
|
|
|
; eax - number of bytes read.
|
|
|
|
locals
|
|
|
|
slot dd ?
|
|
|
|
buff dd ?
|
|
|
|
r_count dd ?
|
|
|
|
offset dd ?
|
|
|
|
tmp_r_cnt dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
mov [slot], eax
|
|
|
|
mov [buff], ecx
|
|
|
|
and [r_count], 0
|
|
|
|
mov [tmp_r_cnt], edx
|
|
|
|
mov [offset], esi
|
|
|
|
|
|
|
|
pushad
|
|
|
|
.read_mem:
|
|
|
|
mov edx, [offset]
|
|
|
|
mov ebx, [tmp_r_cnt]
|
|
|
|
|
|
|
|
mov ecx, 0x400000
|
|
|
|
and edx, 0x3FFFFF
|
|
|
|
sub ecx, edx
|
|
|
|
cmp ecx, ebx
|
|
|
|
jbe @f
|
|
|
|
mov ecx, ebx
|
|
|
|
@@:
|
|
|
|
cmp ecx, 0x8000
|
|
|
|
jna @F
|
|
|
|
mov ecx, 0x8000
|
|
|
|
@@:
|
|
|
|
mov ebx, [offset]
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
stdcall map_memEx, [proc_mem_map], \
|
2015-01-06 17:53:54 +03:00
|
|
|
[slot], ebx, ecx, PG_READ
|
2011-10-15 01:38:50 +04:00
|
|
|
pop ecx
|
|
|
|
|
|
|
|
mov esi, [offset]
|
|
|
|
and esi, 0xfff
|
|
|
|
sub eax, esi
|
|
|
|
jbe .ret
|
|
|
|
cmp ecx, eax
|
|
|
|
jbe @f
|
|
|
|
mov ecx, eax
|
|
|
|
mov [tmp_r_cnt], eax
|
|
|
|
@@:
|
|
|
|
add esi, [proc_mem_map]
|
|
|
|
mov edi, [buff]
|
|
|
|
mov edx, ecx
|
|
|
|
rep movsb
|
|
|
|
add [r_count], edx
|
|
|
|
|
|
|
|
add [offset], edx
|
|
|
|
sub [tmp_r_cnt], edx
|
|
|
|
jnz .read_mem
|
|
|
|
.ret:
|
|
|
|
popad
|
|
|
|
mov eax, [r_count]
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc write_process_memory
|
|
|
|
;Input:
|
|
|
|
; eax - process slot
|
|
|
|
; ecx - buffer address
|
|
|
|
; edx - buffer size
|
|
|
|
; esi - start address in other process
|
|
|
|
;Output:
|
|
|
|
; eax - number of bytes written
|
|
|
|
|
|
|
|
locals
|
|
|
|
slot dd ?
|
|
|
|
buff dd ?
|
|
|
|
w_count dd ?
|
|
|
|
offset dd ?
|
|
|
|
tmp_w_cnt dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
mov [slot], eax
|
|
|
|
mov [buff], ecx
|
|
|
|
and [w_count], 0
|
|
|
|
mov [tmp_w_cnt], edx
|
|
|
|
mov [offset], esi
|
|
|
|
|
|
|
|
pushad
|
|
|
|
.read_mem:
|
|
|
|
mov edx, [offset]
|
|
|
|
mov ebx, [tmp_w_cnt]
|
|
|
|
|
|
|
|
mov ecx, 0x400000
|
|
|
|
and edx, 0x3FFFFF
|
|
|
|
sub ecx, edx
|
|
|
|
cmp ecx, ebx
|
|
|
|
jbe @f
|
|
|
|
mov ecx, ebx
|
|
|
|
@@:
|
|
|
|
cmp ecx, 0x8000
|
|
|
|
jna @F
|
|
|
|
mov ecx, 0x8000
|
|
|
|
@@:
|
|
|
|
mov ebx, [offset]
|
|
|
|
push ecx
|
|
|
|
stdcall map_memEx, [proc_mem_map], \
|
2015-01-06 17:53:54 +03:00
|
|
|
[slot], ebx, ecx, PG_SWR
|
2011-10-15 01:38:50 +04:00
|
|
|
pop ecx
|
|
|
|
|
|
|
|
mov edi, [offset]
|
|
|
|
and edi, 0xfff
|
|
|
|
sub eax, edi
|
|
|
|
jbe .ret
|
|
|
|
cmp ecx, eax
|
|
|
|
jbe @f
|
|
|
|
mov ecx, eax
|
|
|
|
mov [tmp_w_cnt], eax
|
|
|
|
@@:
|
|
|
|
add edi, [proc_mem_map]
|
|
|
|
mov esi, [buff]
|
|
|
|
mov edx, ecx
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
add [w_count], edx
|
|
|
|
add [offset], edx
|
|
|
|
sub [tmp_w_cnt], edx
|
|
|
|
jnz .read_mem
|
|
|
|
.ret:
|
|
|
|
popad
|
|
|
|
mov eax, [w_count]
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2013-10-26 20:11:59 +04:00
|
|
|
;ebx = 1 - kernel thread
|
|
|
|
;ecx=thread entry point
|
|
|
|
;edx=thread stack pointer
|
|
|
|
;creation flags 0x01 - debugged
|
|
|
|
; 0x02 - kernel
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
align 4
|
|
|
|
proc new_sys_threads
|
|
|
|
locals
|
2013-10-26 20:11:59 +04:00
|
|
|
slot dd ?
|
|
|
|
flags dd ?
|
2011-10-15 01:38:50 +04:00
|
|
|
app_cmdline dd ? ;0x00
|
|
|
|
app_path dd ? ;0x04
|
|
|
|
app_eip dd ? ;0x08
|
|
|
|
app_esp dd ? ;0x0C
|
|
|
|
app_mem dd ? ;0x10
|
|
|
|
endl
|
|
|
|
|
2013-10-26 20:11:59 +04:00
|
|
|
shl ebx, 1
|
|
|
|
mov [flags], ebx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [app_eip], ecx
|
|
|
|
mov [app_cmdline], eax
|
|
|
|
mov [app_esp], edx
|
|
|
|
mov [app_path], eax
|
2013-10-26 20:11:59 +04:00
|
|
|
|
2013-05-27 13:02:35 +04:00
|
|
|
call lock_application_table
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2014-09-18 11:58:56 +04:00
|
|
|
call alloc_thread_slot
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .failed
|
|
|
|
|
|
|
|
mov [slot], eax
|
|
|
|
|
|
|
|
mov esi, [current_slot]
|
2023-09-22 19:31:40 +03:00
|
|
|
mov ebx, esi ;ebx=esi - pointer to information about current thread
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov edi, eax
|
2022-02-12 20:27:41 +03:00
|
|
|
shl edi, BSF sizeof.APPDATA
|
2011-10-15 01:38:50 +04:00
|
|
|
add edi, SLOT_BASE
|
2023-09-22 19:31:40 +03:00
|
|
|
mov edx, edi ;edx=edi - pointer to infomation about new thread
|
2020-10-12 05:54:44 +03:00
|
|
|
mov ecx, sizeof.APPDATA/4
|
2011-10-15 01:38:50 +04:00
|
|
|
xor eax, eax
|
|
|
|
cld
|
2023-09-22 19:31:40 +03:00
|
|
|
rep stosd ;clean information about new thread
|
2011-10-15 01:38:50 +04:00
|
|
|
mov esi, ebx
|
|
|
|
mov edi, edx
|
|
|
|
mov ecx, 11
|
|
|
|
rep movsb ;copy process name
|
|
|
|
|
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov eax, [ebx + APPDATA.tls_base]
|
2011-10-15 01:38:50 +04:00
|
|
|
test eax, eax
|
|
|
|
jz @F
|
|
|
|
|
|
|
|
push edx
|
2023-02-15 02:26:59 +03:00
|
|
|
stdcall user_alloc, PAGE_SIZE
|
2011-10-15 01:38:50 +04:00
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jz .failed1;eax=0
|
|
|
|
@@:
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [edx + APPDATA.tls_base], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov eax, [ebx + APPDATA.process]
|
|
|
|
mov [edx + APPDATA.process], eax
|
2016-01-23 13:08:21 +03:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
lea ebx, [edx + APPDATA.list]
|
|
|
|
lea ecx, [eax + PROC.thr_list]
|
2016-01-23 13:08:21 +03:00
|
|
|
list_add_tail ebx, ecx ;add thread to process child's list
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
lea eax, [app_cmdline]
|
2016-03-13 09:08:07 +03:00
|
|
|
stdcall set_app_params , [slot], eax, [flags]
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov eax, [process_number] ;set result
|
2013-05-27 13:02:35 +04:00
|
|
|
call unlock_application_table
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
.failed:
|
|
|
|
xor eax, eax
|
|
|
|
.failed1:
|
2013-05-27 13:02:35 +04:00
|
|
|
call unlock_application_table
|
2011-10-15 01:38:50 +04:00
|
|
|
dec eax ;-1
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
proc map_process_image stdcall, img_size:dword, file_base:dword, file_size:dword
|
|
|
|
|
|
|
|
mov edx, [img_size]
|
|
|
|
mov esi, [file_base]
|
|
|
|
mov ecx, [file_size]
|
2023-02-15 02:26:59 +03:00
|
|
|
add edx, PAGE_SIZE-1
|
|
|
|
add ecx, PAGE_SIZE-1
|
2016-03-13 09:08:07 +03:00
|
|
|
shr edx, 12 ; total pages
|
|
|
|
shr ecx, 12 ; image pages
|
|
|
|
|
|
|
|
mov edi, page_tabs
|
|
|
|
shr esi, 10
|
|
|
|
add esi, edi
|
|
|
|
|
|
|
|
.map_image:
|
|
|
|
lodsd
|
2023-02-15 02:26:59 +03:00
|
|
|
and eax, -PAGE_SIZE
|
2016-03-13 09:08:07 +03:00
|
|
|
or eax, PG_UWR
|
|
|
|
stosd
|
|
|
|
dec edx
|
|
|
|
loop .map_image
|
|
|
|
|
|
|
|
test edx, edx
|
|
|
|
jz .done
|
|
|
|
.map_bss:
|
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
or eax, PG_UWR
|
|
|
|
stosd
|
|
|
|
dec edx
|
|
|
|
jnz .map_bss
|
|
|
|
|
|
|
|
mov edi, [file_size]
|
|
|
|
mov ecx, [img_size]
|
2023-02-15 02:26:59 +03:00
|
|
|
add edi, PAGE_SIZE-1
|
|
|
|
and edi, -PAGE_SIZE
|
|
|
|
add ecx, PAGE_SIZE-1
|
|
|
|
and ecx, -PAGE_SIZE
|
2016-03-13 09:08:07 +03:00
|
|
|
sub ecx, edi
|
|
|
|
shr ecx, 2
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
|
|
|
.done:
|
|
|
|
.fail:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
align 4
|
2016-03-13 09:08:07 +03:00
|
|
|
common_app_entry:
|
|
|
|
mov ebp, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov ebp, [ebp + APPDATA.exec_params]
|
2016-03-13 09:08:07 +03:00
|
|
|
test ebp, ebp
|
|
|
|
jz .exit
|
2021-05-01 19:17:27 +03:00
|
|
|
; APPDATA.exec_params have first thread only,
|
2024-05-22 18:15:14 +03:00
|
|
|
; so second and next threads don't get here (they jump to .exit)
|
2022-02-12 20:27:41 +03:00
|
|
|
stdcall map_process_image, [ebp + APP_HDR._emem],\
|
|
|
|
[ebp + APP_HDR.img_base], [ebp + APP_HDR.img_size]
|
|
|
|
mov esi, [ebp + APP_HDR.path_string]
|
|
|
|
mov edi, [ebp + APP_HDR.path]
|
|
|
|
mov ecx, [ebp + APP_HDR.filename_size]
|
2016-11-25 18:11:25 +03:00
|
|
|
cmp ecx, 1023
|
|
|
|
jc @f
|
|
|
|
mov ecx, 1022
|
|
|
|
@@:
|
2016-08-25 22:30:08 +03:00
|
|
|
push esi
|
2016-03-13 09:08:07 +03:00
|
|
|
test edi, edi
|
2016-08-25 22:30:08 +03:00
|
|
|
jz @f
|
2022-02-12 20:27:41 +03:00
|
|
|
stdcall is_region_userspace, edi, [ebp + APP_HDR.filename_size]
|
2021-07-09 12:22:44 +03:00
|
|
|
jnz @f
|
2016-11-25 18:11:25 +03:00
|
|
|
mov al, '/'
|
|
|
|
stosb
|
2016-03-13 09:08:07 +03:00
|
|
|
rep movsb
|
2016-08-25 22:30:08 +03:00
|
|
|
mov byte [edi], 0
|
|
|
|
@@:
|
|
|
|
call kernel_free
|
2022-02-12 20:27:41 +03:00
|
|
|
mov edi, [ebp + APP_HDR.cmdline]
|
2016-03-13 09:08:07 +03:00
|
|
|
test edi, edi
|
|
|
|
jz .check_tls_header
|
2022-02-12 20:27:41 +03:00
|
|
|
lea esi, [ebp + sizeof.APP_HDR]
|
|
|
|
mov ecx, [ebp + APP_HDR.cmdline_size]
|
2016-03-13 09:08:07 +03:00
|
|
|
cmp ecx, 256
|
|
|
|
jb .copy_cmdline
|
2022-02-12 20:27:41 +03:00
|
|
|
mov edi, [ebp + APP_HDR._emem]
|
2023-02-15 02:26:59 +03:00
|
|
|
add edi, PAGE_SIZE-1
|
|
|
|
and edi, -PAGE_SIZE
|
2016-03-13 09:08:07 +03:00
|
|
|
sub edi, ecx
|
|
|
|
dec edi
|
2024-04-07 19:15:57 +03:00
|
|
|
|
2016-03-13 09:08:07 +03:00
|
|
|
mov [APP_HEADER_01_.i_param], edi
|
|
|
|
.copy_cmdline:
|
2021-02-14 16:21:22 +03:00
|
|
|
inc ecx ; keep in mind about 0 in the end
|
|
|
|
stdcall is_region_userspace, edi, ecx
|
2021-07-09 12:22:44 +03:00
|
|
|
jnz .check_tls_header
|
2021-02-14 16:21:22 +03:00
|
|
|
dec ecx
|
2016-03-13 09:08:07 +03:00
|
|
|
rep movsb
|
2016-08-25 22:30:08 +03:00
|
|
|
mov byte [edi], 0
|
2016-03-13 09:08:07 +03:00
|
|
|
.check_tls_header:
|
|
|
|
cmp word [6], '02'
|
2021-04-17 11:52:27 +03:00
|
|
|
jne .try_load_dll ;.cleanup
|
2011-10-15 01:38:50 +04:00
|
|
|
call init_heap
|
2023-02-15 02:26:59 +03:00
|
|
|
stdcall user_alloc, PAGE_SIZE
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edx, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [edx + APPDATA.tls_base], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
mov [tls_data_l+2], ax
|
|
|
|
shr eax, 16
|
|
|
|
mov [tls_data_l+4], al
|
|
|
|
mov [tls_data_l+7], ah
|
|
|
|
mov dx, app_tls
|
2024-05-22 18:15:14 +03:00
|
|
|
mov fs, dx
|
|
|
|
; { Patch by Coldy, For DLL autoload
|
|
|
|
.try_load_dll:
|
|
|
|
; Test app header version
|
2022-02-12 20:27:41 +03:00
|
|
|
mov ecx, dword[ebp + APP_HDR.img_base]
|
2021-04-17 11:52:27 +03:00
|
|
|
cmp dword[ecx+8], 2
|
|
|
|
jne .cleanup
|
2021-05-01 19:17:27 +03:00
|
|
|
;if APP_HEADER.version = 2 => load lib/dll.obj & change eip to APP_STARTUP_THUNK
|
2021-04-17 11:52:27 +03:00
|
|
|
DEBUGF 1, 'K : App header version 2\n'
|
|
|
|
stdcall load_library, dll_lib_path, 0
|
|
|
|
cmp eax, 0
|
|
|
|
jne @f
|
2024-05-22 18:15:14 +03:00
|
|
|
; Something went wrong (TODO: Next 2 line is code copy after .cleanup)
|
2021-04-17 11:52:27 +03:00
|
|
|
stdcall free_kernel_space, [ebp+APP_HDR.img_base]
|
|
|
|
stdcall kernel_free, ebp
|
2021-05-01 19:17:27 +03:00
|
|
|
DEBUGF 1, 'K : DLL.OBJ not found! Terminate application!\n'
|
2021-04-17 11:52:27 +03:00
|
|
|
mov ebx, dll_error_msg
|
|
|
|
mov ebp, notifyapp
|
|
|
|
call fs_execute_from_sysdir_param
|
2024-05-22 18:15:14 +03:00
|
|
|
; Terminate process (TODO: Need jump to .cleanup after sys_end ?)
|
2021-04-17 11:52:27 +03:00
|
|
|
call sys_end
|
2024-05-22 18:15:14 +03:00
|
|
|
|
|
|
|
@@:
|
2021-05-01 19:17:27 +03:00
|
|
|
; Find APP_STARTUP_THUNK in DLL.OBJ
|
2021-04-17 11:52:27 +03:00
|
|
|
sub eax, 4
|
2021-05-01 19:17:27 +03:00
|
|
|
mov eax, [eax]
|
2024-05-22 18:15:14 +03:00
|
|
|
|
2021-04-17 11:52:27 +03:00
|
|
|
;.change_eip:
|
|
|
|
mov ecx, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov ecx, [ecx + APPDATA.pl0_stack]
|
2021-04-17 11:52:27 +03:00
|
|
|
mov [ecx+REG_EIP], eax
|
2024-05-22 18:15:14 +03:00
|
|
|
|
2021-04-17 11:52:27 +03:00
|
|
|
; } End patch by Coldy, For DLL autoload
|
2016-03-13 09:08:07 +03:00
|
|
|
.cleanup:
|
|
|
|
stdcall free_kernel_space, [ebp+APP_HDR.img_base]
|
|
|
|
stdcall kernel_free, ebp
|
2016-03-16 11:48:55 +03:00
|
|
|
mov ebx, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
cmp [ebx + APPDATA.debugger_slot], 0
|
2016-03-16 11:48:55 +03:00
|
|
|
je .exit
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + APPDATA.state], TSTATE_RUN_SUSPENDED
|
2022-02-09 20:07:51 +03:00
|
|
|
mov [ebx + APPDATA.state], TSTATE_RUN_SUSPENDED
|
2016-03-16 11:48:55 +03:00
|
|
|
call change_task
|
2016-03-13 09:08:07 +03:00
|
|
|
.exit:
|
2011-10-15 01:38:50 +04:00
|
|
|
popad
|
|
|
|
iretd
|
|
|
|
|
2017-12-20 04:07:10 +03:00
|
|
|
EFL_IF = 0x0200
|
|
|
|
EFL_IOPL1 = 0x1000
|
|
|
|
EFL_IOPL2 = 0x2000
|
|
|
|
EFL_IOPL3 = 0x3000
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
align 4
|
2016-03-13 09:08:07 +03:00
|
|
|
proc set_app_params stdcall,slot:dword, params:dword, flags:dword
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
locals
|
|
|
|
pl0_stack dd ?
|
|
|
|
endl
|
|
|
|
|
2017-12-05 08:24:21 +03:00
|
|
|
mov eax, [xsave_area_size]
|
|
|
|
add eax, RING0_STACK_SIZE
|
|
|
|
stdcall kernel_alloc, eax
|
2011-10-15 01:38:50 +04:00
|
|
|
mov [pl0_stack], eax
|
|
|
|
|
|
|
|
lea edi, [eax+RING0_STACK_SIZE]
|
|
|
|
|
|
|
|
mov eax, [slot]
|
|
|
|
mov ebx, eax
|
|
|
|
|
2022-02-09 20:07:51 +03:00
|
|
|
shl eax, BSF sizeof.APPDATA
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + eax + APPDATA.fpu_state], edi
|
|
|
|
mov [SLOT_BASE + eax + APPDATA.exc_handler], 0
|
|
|
|
mov [SLOT_BASE + eax + APPDATA.except_mask], 0
|
|
|
|
mov [SLOT_BASE + eax + APPDATA.terminate_protection], 80000001h
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
;set default io permission map
|
2022-02-12 20:27:41 +03:00
|
|
|
mov ecx, [SLOT_BASE + sizeof.APPDATA + APPDATA.io_map]
|
|
|
|
mov [SLOT_BASE + eax + APPDATA.io_map], ecx
|
|
|
|
mov ecx, [SLOT_BASE + sizeof.APPDATA + APPDATA.io_map + 4]
|
|
|
|
mov [SLOT_BASE + eax + APPDATA.io_map + 4], ecx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov esi, fpu_data
|
2018-02-19 19:35:45 +03:00
|
|
|
mov ecx, [xsave_area_size]
|
|
|
|
add ecx, 3
|
|
|
|
shr ecx, 2
|
2011-10-15 01:38:50 +04:00
|
|
|
rep movsd
|
|
|
|
|
2021-06-16 13:04:10 +03:00
|
|
|
cmp [thread_count], ebx
|
2021-06-16 16:57:17 +03:00
|
|
|
adc [thread_count], 0 ; update number of processes
|
2022-02-09 20:07:51 +03:00
|
|
|
shl ebx, BSF sizeof.APPDATA
|
2022-02-12 20:27:41 +03:00
|
|
|
lea edx, [SLOT_BASE + ebx + APP_EV_OFFSET]
|
|
|
|
mov [SLOT_BASE + ebx + APPDATA.fd_ev], edx
|
|
|
|
mov [SLOT_BASE + ebx + APPDATA.bk_ev], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
add edx, APP_OBJ_OFFSET - APP_EV_OFFSET
|
|
|
|
mov [SLOT_BASE + ebx + APPDATA.fd_obj], edx
|
|
|
|
mov [SLOT_BASE + ebx + APPDATA.bk_obj], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov eax, [pl0_stack]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.pl0_stack], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
add eax, RING0_STACK_SIZE
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.saved_esp0], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
push ebx
|
2023-06-22 06:32:33 +03:00
|
|
|
stdcall kernel_alloc, maxPathLength ;TODO
|
2011-10-15 01:38:50 +04:00
|
|
|
pop ebx
|
|
|
|
mov esi, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov esi, [esi + APPDATA.cur_dir]
|
2016-08-25 22:30:08 +03:00
|
|
|
mov ecx, maxPathLength/4
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edi, eax
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.cur_dir], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
rep movsd
|
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.event_mask], dword 1+2+4;set default event flags (see 40 function)
|
2022-01-11 13:50:30 +03:00
|
|
|
inc dword [process_number]
|
|
|
|
mov eax, [process_number]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.tid], eax ;set TID
|
2013-07-20 11:36:53 +04:00
|
|
|
|
2022-01-10 19:52:37 +03:00
|
|
|
mov eax, [slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.wnd_number], al
|
2023-08-18 23:51:33 +03:00
|
|
|
;mov ebx, eax
|
|
|
|
shl eax, BSF sizeof.WDATA
|
|
|
|
add eax, window_data
|
|
|
|
mov ecx, eax
|
|
|
|
mov [SLOT_BASE + ebx + APPDATA.window], eax
|
|
|
|
mov [eax + WDATA.thread], ebx
|
|
|
|
add [eax + WDATA.thread], SLOT_BASE
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
; set window state to 'normal' (non-minimized/maximized/rolled-up) state
|
2023-08-18 23:51:33 +03:00
|
|
|
mov [eax + WDATA.fl_wstate], WSTATE_NORMAL + WSTATE_USED
|
|
|
|
mov [eax + WDATA.fl_redraw], WSTATE_REDRAW
|
|
|
|
|
|
|
|
mov edx, [def_cursor]
|
|
|
|
mov [eax + WDATA.cursor], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
;set draw data to full screen
|
|
|
|
xor eax, eax
|
2024-03-23 22:19:24 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.def_priority], al
|
2023-08-18 23:51:33 +03:00
|
|
|
mov [ecx + WDATA.draw_data.left], eax
|
|
|
|
mov [ecx + WDATA.draw_data.top], eax
|
2015-01-05 20:18:45 +03:00
|
|
|
mov eax, [screen_workarea.right]
|
2023-08-18 23:51:33 +03:00
|
|
|
mov [ecx + WDATA.draw_data.right], eax
|
2015-01-05 20:18:45 +03:00
|
|
|
mov eax, [screen_workarea.bottom]
|
2023-08-18 23:51:33 +03:00
|
|
|
mov [ecx + WDATA.draw_data.bottom], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
|
|
|
|
mov ebx, [pl0_stack]
|
|
|
|
mov esi, [params]
|
2022-02-12 20:27:41 +03:00
|
|
|
lea ecx, [ebx + REG_EIP]
|
2011-10-15 01:38:50 +04:00
|
|
|
xor eax, eax
|
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + REG_RET], dword common_app_entry
|
|
|
|
mov [ebx + REG_EDI], eax
|
|
|
|
mov [ebx + REG_ESI], eax
|
|
|
|
mov [ebx + REG_EBP], eax
|
|
|
|
mov [ebx + REG_ESP], ecx;ebx+REG_EIP
|
|
|
|
mov [ebx + REG_EBX], eax
|
|
|
|
mov [ebx + REG_EDX], eax
|
|
|
|
mov [ebx + REG_ECX], eax
|
|
|
|
mov [ebx + REG_EAX], eax
|
|
|
|
|
|
|
|
mov eax, [esi + APP_HDR.eip]
|
|
|
|
mov [ebx + REG_EIP], eax
|
|
|
|
mov [ebx + REG_CS], dword app_code
|
2013-05-27 13:02:35 +04:00
|
|
|
mov ecx, USER_PRIORITY
|
2013-10-26 20:11:59 +04:00
|
|
|
|
|
|
|
test byte [flags], 2
|
|
|
|
jz @F
|
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + REG_CS], dword os_code ; kernel thread
|
2013-05-27 13:02:35 +04:00
|
|
|
mov ecx, MAX_PRIORITY
|
2013-03-04 17:58:55 +04:00
|
|
|
@@:
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [ebx + REG_EFLAGS], dword EFL_IOPL1+EFL_IF
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
mov eax, [esi + APP_HDR.esp]
|
|
|
|
mov [ebx + REG_APP_ESP], eax
|
|
|
|
mov [ebx + REG_SS], dword app_data
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2022-02-12 20:27:41 +03:00
|
|
|
lea edx, [ebx + REG_RET]
|
2011-10-15 01:38:50 +04:00
|
|
|
mov ebx, [slot]
|
2022-02-09 20:07:51 +03:00
|
|
|
shl ebx, BSF sizeof.APPDATA
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.saved_esp], edx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2013-05-27 13:02:35 +04:00
|
|
|
xor edx, edx; process state - running
|
2011-10-15 01:38:50 +04:00
|
|
|
; set if debuggee
|
|
|
|
test byte [flags], 1
|
|
|
|
jz .no_debug
|
2021-06-17 12:41:16 +03:00
|
|
|
mov eax, [current_slot_idx]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.debugger_slot], eax
|
2011-10-15 01:38:50 +04:00
|
|
|
.no_debug:
|
2022-02-09 20:07:51 +03:00
|
|
|
mov [SLOT_BASE + ebx + APPDATA.state], dl
|
2022-02-12 20:27:41 +03:00
|
|
|
lea edx, [SLOT_BASE + ebx]
|
2013-05-27 13:02:35 +04:00
|
|
|
call scheduler_add_thread
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
get_stack_base:
|
|
|
|
mov eax, [current_slot]
|
2022-02-12 20:27:41 +03:00
|
|
|
mov eax, [eax + APPDATA.pl0_stack]
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
|
|
|
|
2022-06-07 00:51:08 +03:00
|
|
|
align 4
|
|
|
|
get_curr_slot:
|
|
|
|
mov eax, [current_slot]
|
|
|
|
ret
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2023-04-09 21:19:13 +03:00
|
|
|
pid_to_appdata:
|
|
|
|
;Input:
|
|
|
|
; eax - pid of process
|
|
|
|
;Output:
|
|
|
|
; eax - 0 - not found or pointer on APPDATA
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
mov ebx, [thread_count]
|
|
|
|
shl ebx, BSF sizeof.APPDATA ; multiply by size
|
|
|
|
; skip first process in the task table
|
2023-08-21 00:54:50 +03:00
|
|
|
mov ecx, SLOT_BASE
|
|
|
|
add ebx, ecx
|
2023-04-09 21:19:13 +03:00
|
|
|
.loop:
|
|
|
|
add ecx, sizeof.APPDATA
|
2023-08-21 00:54:50 +03:00
|
|
|
cmp [ecx + APPDATA.state], TSTATE_FREE
|
2023-06-22 06:32:33 +03:00
|
|
|
jz @f ;skip empty slots
|
2023-08-21 00:54:50 +03:00
|
|
|
cmp [ecx + APPDATA.tid], eax
|
2023-04-09 21:19:13 +03:00
|
|
|
jz .pid_found
|
2023-06-22 06:32:33 +03:00
|
|
|
@@:
|
2023-04-09 21:19:13 +03:00
|
|
|
cmp ecx, ebx
|
|
|
|
jb .loop
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
.pid_found:
|
|
|
|
mov eax, ecx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
|
2011-10-15 01:38:50 +04:00
|
|
|
include "debug.inc"
|