forked from KolibriOS/kolibrios
kolibri-process: destroy_thread and destroy_process
git-svn-id: svn://kolibrios.org@4459 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
05540e25ea
commit
800498080b
@ -1492,59 +1492,10 @@ dereference_dll:
|
|||||||
|
|
||||||
destroy_hdll:
|
destroy_hdll:
|
||||||
push ebx ecx esi edi
|
push ebx ecx esi edi
|
||||||
push eax
|
|
||||||
mov ebx, [eax+HDLL.base]
|
mov ebx, [eax+HDLL.base]
|
||||||
mov esi, [eax+HDLL.parent]
|
mov esi, [eax+HDLL.parent]
|
||||||
mov edx, [esi+DLLDESCR.size]
|
mov edx, [esi+DLLDESCR.size]
|
||||||
; The following actions require the context of application where HDLL is mapped.
|
|
||||||
; However, destroy_hdll can be called in the context of OS thread when
|
|
||||||
; cleaning up objects created by the application which is destroyed.
|
|
||||||
; So remember current cr3 and set it to page table of target.
|
|
||||||
mov eax, [ecx+APPDATA.process]
|
|
||||||
; Because we cheat with cr3, disable interrupts: task switch would restore
|
|
||||||
; page table from APPDATA of current thread.
|
|
||||||
; Also set [current_slot] because it is used by user_free.
|
|
||||||
pushf
|
|
||||||
cli
|
|
||||||
push [current_slot]
|
|
||||||
mov [current_slot], ecx
|
|
||||||
mov ecx, cr3
|
|
||||||
push ecx
|
|
||||||
mov cr3, eax
|
|
||||||
push ebx ; argument for user_free
|
|
||||||
mov eax, ebx
|
|
||||||
shr ebx, 12
|
|
||||||
push ebx
|
|
||||||
mov esi, [esi+DLLDESCR.data]
|
|
||||||
shr esi, 12
|
|
||||||
.unmap_loop:
|
|
||||||
push eax
|
|
||||||
mov eax, 2
|
|
||||||
xchg eax, [page_tabs+ebx*4]
|
|
||||||
mov ecx, [page_tabs+esi*4]
|
|
||||||
and eax, not 0xFFF
|
|
||||||
and ecx, not 0xFFF
|
|
||||||
cmp eax, ecx
|
|
||||||
jz @f
|
|
||||||
call free_page
|
|
||||||
@@:
|
|
||||||
pop eax
|
|
||||||
invlpg [eax]
|
|
||||||
add eax, 0x1000
|
|
||||||
inc ebx
|
|
||||||
inc esi
|
|
||||||
sub edx, 0x1000
|
|
||||||
ja .unmap_loop
|
|
||||||
pop ebx
|
|
||||||
and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK
|
|
||||||
call user_free
|
|
||||||
; Restore context.
|
|
||||||
pop eax
|
|
||||||
mov cr3, eax
|
|
||||||
pop [current_slot]
|
|
||||||
popf
|
|
||||||
; Ok, cheating is done.
|
|
||||||
pop eax
|
|
||||||
push eax
|
push eax
|
||||||
mov esi, [eax+HDLL.parent]
|
mov esi, [eax+HDLL.parent]
|
||||||
mov eax, [eax+HDLL.refcount]
|
mov eax, [eax+HDLL.refcount]
|
||||||
|
@ -418,6 +418,8 @@ destroy_thread:
|
|||||||
.slot equ esp+4 ;locals
|
.slot equ esp+4 ;locals
|
||||||
.process equ esp ;ptr to parent process
|
.process equ esp ;ptr to parent process
|
||||||
|
|
||||||
|
xchg bx, bx
|
||||||
|
|
||||||
push esi ;save .slot
|
push esi ;save .slot
|
||||||
|
|
||||||
shl esi, 8
|
shl esi, 8
|
||||||
@ -751,13 +753,12 @@ destroy_thread:
|
|||||||
|
|
||||||
bts [thr_slot_map], esi
|
bts [thr_slot_map], esi
|
||||||
|
|
||||||
mov ebx, [.process]
|
mov ecx, [.process]
|
||||||
add ebx, PROC.thr_list
|
lea eax, [ecx+PROC.thr_list]
|
||||||
cmp ebx, [ebx+LHEAD.next]
|
cmp eax, [eax+LHEAD.next]
|
||||||
jne @F
|
jne @F
|
||||||
|
|
||||||
DEBUGF 1,"%s",msg_process_destroy
|
call destroy_process.internal
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
sti ; .. and life goes on
|
sti ; .. and life goes on
|
||||||
|
|
||||||
@ -778,9 +779,6 @@ destroy_thread:
|
|||||||
restore .slot
|
restore .slot
|
||||||
restore .process
|
restore .process
|
||||||
|
|
||||||
msg_process_destroy: db 'K: destroy process', 0x0d, 0x0a,0
|
|
||||||
|
|
||||||
|
|
||||||
; Three following procedures are used to guarantee that
|
; Three following procedures are used to guarantee that
|
||||||
; some part of kernel code will not be terminated from outside
|
; some part of kernel code will not be terminated from outside
|
||||||
; while it is running.
|
; while it is running.
|
||||||
|
@ -587,6 +587,8 @@ proc destroy_page_table stdcall, pg_tab:dword
|
|||||||
mov eax, [esi]
|
mov eax, [esi]
|
||||||
test eax, 1
|
test eax, 1
|
||||||
jz .next
|
jz .next
|
||||||
|
test eax, 2
|
||||||
|
jz .next
|
||||||
test eax, 1 shl 9
|
test eax, 1 shl 9
|
||||||
jnz .next ;skip shared pages
|
jnz .next ;skip shared pages
|
||||||
call free_page
|
call free_page
|
||||||
@ -599,46 +601,25 @@ proc destroy_page_table stdcall, pg_tab:dword
|
|||||||
endp
|
endp
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword
|
destroy_process: ;fastcall ecx= ptr to process
|
||||||
|
|
||||||
xor edx, edx
|
lea eax, [ecx+PROC.thr_list]
|
||||||
push edx
|
cmp eax, [eax+LHEAD.next]
|
||||||
mov eax, 0x1
|
jne .exit
|
||||||
mov ebx, [pg_dir]
|
|
||||||
.loop:
|
|
||||||
;eax = current slot of process
|
|
||||||
mov ecx, eax
|
|
||||||
shl ecx, 5
|
|
||||||
cmp byte [CURRENT_TASK+ecx+0xa], 9;if process running?
|
|
||||||
jz @f ;skip empty slots
|
|
||||||
shl ecx, 3
|
|
||||||
add ecx, SLOT_BASE
|
|
||||||
cmp [ecx+APPDATA.process], ebx;compare page directory addresses
|
|
||||||
jnz @f
|
|
||||||
mov [ebp-4], ecx
|
|
||||||
inc edx ;thread found
|
|
||||||
@@:
|
|
||||||
inc eax
|
|
||||||
cmp eax, [TASK_COUNT] ;exit loop if we look through all processes
|
|
||||||
jle .loop
|
|
||||||
|
|
||||||
;edx = number of threads
|
align 4
|
||||||
;our process is zombi so it isn't counted
|
.internal:
|
||||||
pop ecx
|
push ecx
|
||||||
cmp edx, 1
|
|
||||||
jg .ret
|
|
||||||
;if there isn't threads then clear memory.
|
|
||||||
mov esi, [dlls_list]
|
|
||||||
call destroy_all_hdlls;ecx=APPDATA
|
|
||||||
|
|
||||||
mov ecx, pg_data.mutex
|
mov esi, [ecx+PROC.dlls_list_ptr]
|
||||||
call mutex_lock
|
call destroy_all_hdlls
|
||||||
|
|
||||||
mov eax, [pg_dir]
|
; mov ecx, pg_data.mutex
|
||||||
and eax, not 0xFFF
|
; call mutex_lock
|
||||||
; stdcall map_page, [tmp_task_pdir], eax, PG_SW
|
|
||||||
; mov esi, [tmp_task_pdir]
|
mov esi, [esp]
|
||||||
mov edi, (OS_BASE shr 20)/4
|
add esi, PROC.pdt_0
|
||||||
|
mov edi, (0x80000000 shr 20)/4
|
||||||
.destroy:
|
.destroy:
|
||||||
mov eax, [esi]
|
mov eax, [esi]
|
||||||
test eax, 1
|
test eax, 1
|
||||||
@ -653,16 +634,13 @@ proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword
|
|||||||
dec edi
|
dec edi
|
||||||
jnz .destroy
|
jnz .destroy
|
||||||
|
|
||||||
mov eax, [pg_dir]
|
call kernel_free ;ecx still in stack
|
||||||
call free_page
|
|
||||||
.exit:
|
|
||||||
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
|
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
|
||||||
; stdcall map_page, [tmp_task_pdir], 0, PG_UNMAP
|
; mov ecx, pg_data.mutex
|
||||||
mov ecx, pg_data.mutex
|
; call mutex_unlock
|
||||||
call mutex_unlock
|
|
||||||
.ret:
|
.exit:
|
||||||
ret
|
ret
|
||||||
endp
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
get_pid:
|
get_pid:
|
||||||
@ -986,7 +964,7 @@ proc new_sys_threads
|
|||||||
|
|
||||||
lea ebx, [edx+APPDATA.list]
|
lea ebx, [edx+APPDATA.list]
|
||||||
lea ecx, [eax+PROC.thr_list]
|
lea ecx, [eax+PROC.thr_list]
|
||||||
list_add_tail edx, ecx ;add thread to process child's list
|
list_add_tail ebx, ecx ;add thread to process child's list
|
||||||
|
|
||||||
mov eax, [ebx+APPDATA.tls_base]
|
mov eax, [ebx+APPDATA.tls_base]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
|
Loading…
Reference in New Issue
Block a user