* fixed copy-on-write for kernel accesses from other threads

* fixed return value of read/write_process_memory
* fixed sysfunction 39.4 broken in rev. 1304
* more safe and slightly more effective FDO


git-svn-id: svn://kolibrios.org@1314 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2009-12-12 00:16:39 +00:00
parent 5da0aff00a
commit d5cbc5f493
4 changed files with 148 additions and 45 deletions

View File

@ -714,14 +714,17 @@ end if
jmp .exit jmp .exit
endp endp
align 4 ; returns number of mapped bytes
proc map_mem stdcall, lin_addr:dword,pdir:dword,\ proc map_mem stdcall, lin_addr:dword,slot:dword,\
ofs:dword,buf_size:dword ofs:dword,buf_size:dword,req_access:dword
mov eax, [buf_size] push 0 ; initialize number of mapped bytes
test eax, eax
cmp [buf_size], 0
jz .exit jz .exit
mov eax, [pdir] mov eax, [slot]
shl eax, 8
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
and eax, 0xFFFFF000 and eax, 0xFFFFF000
stdcall map_page,[ipc_pdir],eax,PG_UW stdcall map_page,[ipc_pdir],eax,PG_UW
@ -753,10 +756,11 @@ proc map_mem stdcall, lin_addr:dword,pdir:dword,\
and edx, 0x3FF and edx, 0x3FF
mov esi, [ipc_ptab] mov esi, [ipc_ptab]
.map: mov eax, [esi+edx*4] .map:
and eax, 0xFFFFF000 stdcall safe_map_page,[slot],[req_access],[ofs]
jz .exit jnc .exit
stdcall map_page,edi,eax,PG_UW add dword [ebp-4], 4096
add [ofs], 4096
dec ecx dec ecx
jz .exit jz .exit
add edi, 0x1000 add edi, 0x1000
@ -773,20 +777,23 @@ proc map_mem stdcall, lin_addr:dword,pdir:dword,\
jmp .map jmp .map
.exit: .exit:
pop eax
ret ret
endp endp
align 4 proc map_memEx stdcall, lin_addr:dword,slot:dword,\
proc map_memEx stdcall, lin_addr:dword,pdir:dword,\ ofs:dword,buf_size:dword,req_access:dword
ofs:dword,buf_size:dword push 0 ; initialize number of mapped bytes
mov eax, [buf_size]
test eax, eax cmp [buf_size], 0
jz .exit jz .exit
mov eax, [pdir] mov eax, [slot]
shl eax, 8
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
and eax, 0xFFFFF000 and eax, 0xFFFFF000
stdcall map_page,[proc_mem_pdir],eax,dword PG_UW stdcall map_page,[proc_mem_pdir],eax,PG_UW
mov ebx, [ofs] mov ebx, [ofs]
shr ebx, 22 shr ebx, 22
mov esi, [proc_mem_pdir] mov esi, [proc_mem_pdir]
@ -795,7 +802,7 @@ proc map_memEx stdcall, lin_addr:dword,pdir:dword,\
and eax, 0xFFFFF000 and eax, 0xFFFFF000
test eax, eax test eax, eax
jz .exit jz .exit
stdcall map_page,edi,eax,dword PG_UW stdcall map_page,edi,eax,PG_UW
@@: mov edi, [lin_addr] @@: mov edi, [lin_addr]
and edi, 0xFFFFF000 and edi, 0xFFFFF000
@ -809,21 +816,101 @@ proc map_memEx stdcall, lin_addr:dword,pdir:dword,\
and edx, 0x3FF and edx, 0x3FF
mov esi, [proc_mem_tab] mov esi, [proc_mem_tab]
.map: mov eax, [esi+edx*4] .map:
; and eax, 0xFFFFF000 stdcall safe_map_page,[slot],[req_access],[ofs]
; test eax, eax jnc .exit
; jz .exit add dword [ebp-4], 0x1000
stdcall map_page,edi,eax,dword PG_UW
add edi, 0x1000 add edi, 0x1000
add [ofs], 0x1000
inc edx inc edx
dec ecx dec ecx
jnz .map jnz .map
.exit: .exit:
pop eax
ret ret
endp endp
; in: esi+edx*4 = pointer to page table entry
; in: [slot], [req_access], [ofs] on the stack
; in: edi = linear address to map
; out: CF cleared <=> failed
; destroys: only eax
proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword
mov eax, [esi+edx*4]
test al, PG_MAP
jz .not_present
test al, PG_WRITE
jz .resolve_readonly
; normal case: writable page, just map with requested access
.map:
stdcall map_page, edi, eax, [req_access]
stc
.fail:
ret
.not_present:
; check for alloc-on-demand page
test al, 2
jz .fail
; allocate new page, save it to source page table
push ecx
call alloc_page
pop ecx
test eax, eax
jz .fail
or al, PG_UW
mov [esi+edx*4], eax
jmp .map
.resolve_readonly:
; readonly page, probably copy-on-write
; check: readonly request of readonly page is ok
test [req_access], PG_WRITE
jz .map
; find control structure for this page
pushf
cli
cld
push ebx ecx
mov eax, [slot]
shl eax, 8
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
test eax, eax
jz .no_hdll
mov ecx, [eax+HDLL.fd]
.scan_hdll:
cmp ecx, eax
jz .no_hdll
mov ebx, [ofs]
and ebx, not 0xFFF
sub ebx, [ecx+HDLL.base]
cmp ebx, [ecx+HDLL.size]
jb .hdll_found
mov ecx, [ecx+HDLL.fd]
jmp .scan_hdll
.no_hdll:
pop ecx ebx
popf
clc
ret
.hdll_found:
; allocate page, save it in page table, map it, copy contents from base
mov eax, [ecx+HDLL.parent]
add ebx, [eax+DLLDESCR.data]
call alloc_page
test eax, eax
jz .no_hdll
or al, PG_UW
mov [esi+edx*4], eax
stdcall map_page, edi, eax, [req_access]
push esi edi
mov esi, ebx
mov ecx, 4096/4
rep movsd
pop edi esi
pop ecx ebx
popf
stc
ret
endp
sys_IPC: sys_IPC:
;input: ;input:
@ -907,15 +994,15 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
mov ecx, [ipc_tmp] mov ecx, [ipc_tmp]
cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page
jbe @f jbe @f
push eax esi edi push esi edi
add esi,0x1000 add esi,0x1000
stdcall alloc_kernel_space,esi stdcall alloc_kernel_space,esi
mov ecx, eax mov ecx, eax
pop edi esi eax pop edi esi
@@: @@:
mov [used_buf], ecx mov [used_buf], ecx
stdcall map_mem, ecx, [SLOT_BASE+eax+0xB8],\ stdcall map_mem, ecx, [dst_slot],\
edi, esi edi, esi, PG_SW
mov edi, [dst_offset] mov edi, [dst_offset]
add edi, [used_buf] add edi, [used_buf]

View File

@ -751,18 +751,22 @@ proc read_process_memory
jna @F jna @F
mov ecx, 0x8000 mov ecx, 0x8000
@@: @@:
mov eax, [slot]
shl eax,8
mov ebx, [offset] mov ebx, [offset]
push ecx push ecx
stdcall map_memEx, [proc_mem_map],\ stdcall map_memEx, [proc_mem_map],\
[SLOT_BASE+eax+0xB8],\ [slot], ebx, ecx, PG_MAP
ebx, ecx
pop ecx pop ecx
mov esi, [offset] mov esi, [offset]
and esi, 0xfff 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] add esi, [proc_mem_map]
mov edi, [buff] mov edi, [buff]
mov edx, ecx mov edx, ecx
@ -772,7 +776,7 @@ proc read_process_memory
add [offset], edx add [offset], edx
sub [tmp_r_cnt], edx sub [tmp_r_cnt], edx
jnz .read_mem jnz .read_mem
.ret:
popad popad
mov eax, [r_count] mov eax, [r_count]
ret ret
@ -818,18 +822,22 @@ proc write_process_memory
jna @F jna @F
mov ecx, 0x8000 mov ecx, 0x8000
@@: @@:
mov eax, [slot]
shl eax,8
mov ebx, [offset] mov ebx, [offset]
; add ebx, new_app_base ; add ebx, new_app_base
push ecx push ecx
stdcall map_memEx, [proc_mem_map],\ stdcall map_memEx, [proc_mem_map],\
[SLOT_BASE+eax+0xB8],\ [slot], ebx, ecx, PG_SW
ebx, ecx
pop ecx pop ecx
mov edi, [offset] mov edi, [offset]
and edi, 0xfff 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] add edi, [proc_mem_map]
mov esi, [buff] mov esi, [buff]
mov edx, ecx mov edx, ecx
@ -839,7 +847,7 @@ proc write_process_memory
add [offset], edx add [offset], edx
sub [tmp_w_cnt], edx sub [tmp_w_cnt], edx
jnz .read_mem jnz .read_mem
.ret:
popad popad
mov eax, [w_count] mov eax, [w_count]
ret ret

View File

@ -6,6 +6,7 @@
$Revision$ $Revision$
_esp equ esp
; ;
; Formatted Debug Output (FDO) ; Formatted Debug Output (FDO)
@ -61,9 +62,11 @@ macro DEBUGS_N _sign,_num,[_str] {
jmp ..label jmp ..label
..str db _str,0 ..str db _str,0
..label: ..label:
add esp,4*8+4 ; add esp,4*8+4
esp equ esp+4*8+4
mov edx,..str mov edx,..str
sub esp,4*8+4 esp equ _esp
; sub esp,4*8+4
else else
mov edx,_str mov edx,_str
end if end if
@ -147,7 +150,8 @@ macro DEBUGD_N _sign,_num,_dec {
else if _dec eqtype 0 else if _dec eqtype 0
mov eax,_dec mov eax,_dec
else else
add esp,4*8+4 ; add esp,4*8+4
esp equ esp+4*8+4
if _num eq if _num eq
mov eax,dword _dec mov eax,dword _dec
else if _num = 1 else if _num = 1
@ -165,7 +169,8 @@ macro DEBUGD_N _sign,_num,_dec {
else else
mov eax,dword _dec mov eax,dword _dec
end if end if
sub esp,4*8+4 esp equ _esp
; sub esp,4*8+4
end if end if
mov cl,_sign mov cl,_sign
call fdo_debug_outdec call fdo_debug_outdec
@ -215,9 +220,11 @@ macro DEBUGH_N _sign,_num,_hex {
else if _hex eqtype 0 else if _hex eqtype 0
mov eax,_hex mov eax,_hex
else else
add esp,4*8+4 ; add esp,4*8+4
esp equ esp+4*8+4
mov eax,dword _hex mov eax,dword _hex
sub esp,4*8+4 esp equ _esp
; sub esp,4*8+4
end if end if
if ~_num eq if ~_num eq
mov edx,_num mov edx,_num

View File

@ -2604,6 +2604,7 @@ nogb1:
nogb2: nogb2:
; cmp eax,4 ; TILED / STRETCHED ; cmp eax,4 ; TILED / STRETCHED
dec ebx
dec ebx dec ebx
jnz nogb4 jnz nogb4
mov eax,[BgrDrawMode] mov eax,[BgrDrawMode]