2011-10-14 23:38:50 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2020-05-22 17:38:59 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc alloc_page
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
push ebx
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [pg_data.pages_free], 1
|
|
|
|
jle .out_of_memory
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov ebx, [page_start]
|
|
|
|
mov ecx, [page_end]
|
|
|
|
.l1:
|
|
|
|
bsf eax, [ebx];
|
|
|
|
jnz .found
|
|
|
|
add ebx, 4
|
|
|
|
cmp ebx, ecx
|
|
|
|
jb .l1
|
|
|
|
pop ebx
|
|
|
|
popfd
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
.found:
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
dec [pg_data.pages_free]
|
|
|
|
jz .out_of_memory
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
btr [ebx], eax
|
|
|
|
mov [page_start], ebx
|
|
|
|
sub ebx, sys_pgmap
|
|
|
|
lea eax, [eax+ebx*8]
|
|
|
|
shl eax, 12
|
2020-07-16 15:51:29 +02:00
|
|
|
; dec [pg_data.pages_free]
|
2011-10-14 23:38:50 +02:00
|
|
|
pop ebx
|
|
|
|
popfd
|
|
|
|
ret
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
.out_of_memory:
|
|
|
|
mov [pg_data.pages_free], 1
|
|
|
|
xor eax, eax
|
|
|
|
pop ebx
|
|
|
|
popfd
|
|
|
|
ret
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc alloc_pages stdcall, count:dword
|
|
|
|
pushfd
|
|
|
|
push ebx
|
|
|
|
push edi
|
|
|
|
cli
|
|
|
|
mov eax, [count]
|
|
|
|
add eax, 7
|
|
|
|
shr eax, 3
|
|
|
|
mov [count], eax
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ebx, [pg_data.pages_free]
|
|
|
|
sub ebx, 9
|
|
|
|
js .out_of_memory
|
|
|
|
shr ebx, 3
|
|
|
|
cmp eax, ebx
|
|
|
|
jg .out_of_memory
|
2020-07-16 15:51:29 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, [page_start]
|
|
|
|
mov ebx, [page_end]
|
|
|
|
.find:
|
|
|
|
mov edx, [count]
|
|
|
|
mov edi, ecx
|
2020-05-22 17:38:59 +02:00
|
|
|
.match:
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp byte [ecx], 0xFF
|
|
|
|
jne .next
|
|
|
|
dec edx
|
|
|
|
jz .ok
|
|
|
|
inc ecx
|
|
|
|
cmp ecx, ebx
|
|
|
|
jb .match
|
2020-05-22 17:38:59 +02:00
|
|
|
.out_of_memory:
|
|
|
|
.fail:
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
popfd
|
|
|
|
ret
|
2020-05-22 17:38:59 +02:00
|
|
|
.next:
|
2011-10-14 23:38:50 +02:00
|
|
|
inc ecx
|
|
|
|
cmp ecx, ebx
|
|
|
|
jb .find
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
popfd
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2020-05-22 17:38:59 +02:00
|
|
|
.ok:
|
2011-10-14 23:38:50 +02:00
|
|
|
sub ecx, edi
|
|
|
|
inc ecx
|
|
|
|
push esi
|
|
|
|
mov esi, edi
|
|
|
|
xor eax, eax
|
|
|
|
rep stosb
|
|
|
|
sub esi, sys_pgmap
|
|
|
|
shl esi, 3+12
|
|
|
|
mov eax, esi
|
|
|
|
mov ebx, [count]
|
|
|
|
shl ebx, 3
|
|
|
|
sub [pg_data.pages_free], ebx
|
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2014-01-02 20:43:51 +01:00
|
|
|
;proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
|
|
|
|
map_page:
|
2011-10-14 23:38:50 +02:00
|
|
|
push ebx
|
2015-01-06 16:24:09 +01:00
|
|
|
mov eax, [esp+12] ; phis_addr
|
2014-01-02 20:43:51 +01:00
|
|
|
or eax, [esp+16] ; flags
|
2015-01-06 16:24:09 +01:00
|
|
|
and eax, [pte_valid_mask]
|
2014-01-02 20:43:51 +01:00
|
|
|
mov ebx, [esp+8] ; lin_addr
|
2011-10-14 23:38:50 +02:00
|
|
|
shr ebx, 12
|
|
|
|
mov [page_tabs+ebx*4], eax
|
2014-01-02 20:43:51 +01:00
|
|
|
mov eax, [esp+8] ; lin_addr
|
2011-10-14 23:38:50 +02:00
|
|
|
pop ebx
|
2014-01-02 20:43:51 +01:00
|
|
|
invlpg [eax]
|
|
|
|
ret 12
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
map_space: ;not implemented
|
|
|
|
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc free_page
|
|
|
|
;arg: eax page address
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
shr eax, 12 ;page index
|
|
|
|
bts dword [sys_pgmap], eax ;that's all!
|
|
|
|
cmc
|
|
|
|
adc [pg_data.pages_free], 0
|
|
|
|
shr eax, 3
|
|
|
|
and eax, not 3 ;dword offset from page_map
|
|
|
|
add eax, sys_pgmap
|
|
|
|
cmp [page_start], eax
|
|
|
|
ja @f
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
mov [page_start], eax
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2012-02-28 09:36:15 +01:00
|
|
|
align 4
|
2011-10-14 23:38:50 +02:00
|
|
|
proc map_io_mem stdcall, base:dword, size:dword, flags:dword
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
push edi
|
|
|
|
mov eax, [size]
|
|
|
|
add eax, [base]
|
|
|
|
add eax, 4095
|
|
|
|
and eax, -4096
|
|
|
|
mov ecx, [base]
|
|
|
|
and ecx, -4096
|
|
|
|
sub eax, ecx
|
|
|
|
mov [size], eax
|
|
|
|
|
|
|
|
stdcall alloc_kernel_space, eax
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
push eax
|
|
|
|
|
|
|
|
mov edi, 0x1000
|
|
|
|
mov ebx, eax
|
|
|
|
mov ecx, [size]
|
|
|
|
mov edx, [base]
|
|
|
|
shr eax, 12
|
|
|
|
shr ecx, 12
|
|
|
|
or edx, [flags]
|
2015-01-06 16:24:09 +01:00
|
|
|
and edx, [pte_valid_mask]
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
mov [page_tabs+eax*4], edx
|
|
|
|
invlpg [ebx]
|
|
|
|
inc eax
|
|
|
|
add ebx, edi
|
|
|
|
add edx, edi
|
|
|
|
loop @B
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
mov edx, [base]
|
|
|
|
and edx, 4095
|
|
|
|
add eax, edx
|
|
|
|
.fail:
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= page base + page flags
|
|
|
|
; ebx= linear address
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
align 4
|
|
|
|
commit_pages:
|
|
|
|
test ecx, ecx
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
push edi
|
|
|
|
push eax
|
|
|
|
push ecx
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_lock
|
|
|
|
pop ecx
|
|
|
|
pop eax
|
|
|
|
|
2015-01-06 16:24:09 +01:00
|
|
|
and eax, [pte_valid_mask ]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov edi, ebx
|
|
|
|
shr edi, 12
|
|
|
|
lea edi, [page_tabs+edi*4]
|
|
|
|
@@:
|
|
|
|
stosd
|
|
|
|
invlpg [ebx]
|
|
|
|
add eax, 0x1000
|
|
|
|
add ebx, 0x1000
|
|
|
|
loop @B
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_unlock
|
|
|
|
.fail:
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= base
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
align 4
|
|
|
|
release_pages:
|
|
|
|
|
|
|
|
push ebp
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
push ebx
|
|
|
|
|
|
|
|
mov esi, eax
|
|
|
|
mov edi, eax
|
|
|
|
|
|
|
|
shr esi, 12
|
|
|
|
lea esi, [page_tabs+esi*4]
|
|
|
|
|
|
|
|
push ecx
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_lock
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
mov ebp, [pg_data.pages_free]
|
|
|
|
mov ebx, [page_start]
|
|
|
|
mov edx, sys_pgmap
|
|
|
|
@@:
|
|
|
|
xor eax, eax
|
|
|
|
xchg eax, [esi]
|
|
|
|
invlpg [edi]
|
|
|
|
|
|
|
|
test eax, 1
|
|
|
|
jz .next
|
|
|
|
|
|
|
|
shr eax, 12
|
|
|
|
bts [edx], eax
|
|
|
|
cmc
|
|
|
|
adc ebp, 0
|
|
|
|
shr eax, 3
|
|
|
|
and eax, -4
|
|
|
|
add eax, edx
|
|
|
|
cmp eax, ebx
|
|
|
|
jae .next
|
|
|
|
|
|
|
|
mov ebx, eax
|
|
|
|
.next:
|
|
|
|
add edi, 0x1000
|
|
|
|
add esi, 4
|
|
|
|
loop @B
|
|
|
|
|
|
|
|
mov [pg_data.pages_free], ebp
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_unlock
|
|
|
|
|
|
|
|
pop ebx
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebp
|
|
|
|
ret
|
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= base
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
align 4
|
|
|
|
unmap_pages:
|
|
|
|
|
|
|
|
push edi
|
|
|
|
|
|
|
|
mov edi, eax
|
|
|
|
mov edx, eax
|
|
|
|
|
|
|
|
shr edi, 10
|
|
|
|
add edi, page_tabs
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
@@:
|
|
|
|
stosd
|
|
|
|
invlpg [edx]
|
|
|
|
add edx, 0x1000
|
|
|
|
loop @b
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc map_page_table stdcall, lin_addr:dword, phis_addr:dword
|
|
|
|
push ebx
|
|
|
|
mov ebx, [lin_addr]
|
|
|
|
shr ebx, 22
|
|
|
|
mov eax, [phis_addr]
|
|
|
|
and eax, not 0xFFF
|
2015-01-09 03:20:21 +01:00
|
|
|
or eax, PG_UWR
|
2011-10-14 23:38:50 +02:00
|
|
|
mov dword [master_tab+ebx*4], eax
|
|
|
|
mov eax, [lin_addr]
|
|
|
|
shr eax, 10
|
|
|
|
add eax, page_tabs
|
|
|
|
invlpg [eax]
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2014-08-25 11:49:27 +02:00
|
|
|
uglobal
|
|
|
|
sb16_buffer_allocated db 0
|
|
|
|
endg
|
|
|
|
|
|
|
|
; Allocates [.size] bytes so that the target memory block
|
|
|
|
; is inside one 64K page for 24-bit DMA controller,
|
|
|
|
; that is, somewhere between 00xx0000h and 00xxFFFFh.
|
|
|
|
proc alloc_dma24
|
|
|
|
; Implementation note.
|
|
|
|
; The only user of that function is SB16 driver,
|
|
|
|
; so just return a statically allocated buffer.
|
|
|
|
virtual at esp
|
|
|
|
dd ? ; return address
|
|
|
|
.size dd ?
|
|
|
|
end virtual
|
|
|
|
cmp [sb16_buffer_allocated], 0
|
|
|
|
jnz .fail
|
|
|
|
inc [sb16_buffer_allocated]
|
|
|
|
mov eax, SB16Buffer
|
|
|
|
ret 4
|
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
|
|
|
ret 4
|
|
|
|
endp
|
|
|
|
|
2014-08-15 13:18:27 +02:00
|
|
|
; Allocates a physical page for master page table
|
|
|
|
; that duplicates first Mb of OS_BASE at address 0;
|
|
|
|
; used for starting APs and for shutting down,
|
|
|
|
; where it is important to execute code in trivial-mapped pages.
|
|
|
|
; Returns eax = allocated physical page.
|
|
|
|
proc create_trampoline_pgmap
|
|
|
|
; The only non-trivial moment:
|
|
|
|
; we need a linear address to fill information,
|
|
|
|
; but we don't need it outside of this function,
|
|
|
|
; so we're returning physical address.
|
|
|
|
; Therefore, allocate memory with kernel_alloc,
|
|
|
|
; this will allocate physical page and a linear address somewhere,
|
|
|
|
; and deallocate only linear address with free_kernel_space.
|
|
|
|
stdcall kernel_alloc, 0x1000
|
|
|
|
mov edi, eax
|
|
|
|
mov esi, master_tab
|
|
|
|
mov ecx, 1024
|
|
|
|
rep movsd
|
|
|
|
mov ecx, [master_tab+(OS_BASE shr 20)]
|
|
|
|
mov [eax], ecx
|
|
|
|
mov edi, eax
|
|
|
|
call get_pg_addr
|
|
|
|
push eax
|
|
|
|
stdcall free_kernel_space, edi
|
|
|
|
pop eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
proc new_mem_resize stdcall, new_size:dword
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
mov edx, [current_slot]
|
2014-09-18 09:58:56 +02:00
|
|
|
mov ebx, [edx+APPDATA.process]
|
|
|
|
|
|
|
|
cmp [ebx+PROC.heap_base], 0
|
2012-04-09 15:19:32 +02:00
|
|
|
jne .exit
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov edi, [new_size]
|
|
|
|
add edi, 4095
|
|
|
|
and edi, not 4095
|
|
|
|
mov [new_size], edi
|
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov esi, [ebx+PROC.mem_used]
|
2011-10-14 23:38:50 +02:00
|
|
|
add esi, 4095
|
|
|
|
and esi, not 4095
|
|
|
|
|
|
|
|
cmp edi, esi
|
2012-04-09 15:19:32 +02:00
|
|
|
ja .expand
|
|
|
|
je .exit
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
mov ebx, edi
|
2011-10-14 23:38:50 +02:00
|
|
|
shr edi, 12
|
|
|
|
shr esi, 12
|
2012-04-09 15:19:32 +02:00
|
|
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_lock
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
mov eax, [app_page_tabs+edi*4]
|
|
|
|
test eax, 1
|
|
|
|
jz .next
|
2012-04-09 15:19:32 +02:00
|
|
|
|
|
|
|
mov dword [app_page_tabs+edi*4], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
invlpg [ebx]
|
|
|
|
call free_page
|
|
|
|
|
|
|
|
.next:
|
2012-04-09 15:19:32 +02:00
|
|
|
inc edi
|
2012-04-09 17:19:40 +02:00
|
|
|
add ebx, 0x1000
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp edi, esi
|
|
|
|
jb @B
|
|
|
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_unlock
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
.update_size:
|
|
|
|
mov edx, [current_slot]
|
|
|
|
mov ebx, [new_size]
|
2014-09-18 09:58:56 +02:00
|
|
|
mov edx, [edx+APPDATA.process]
|
|
|
|
mov [edx+PROC.mem_used], ebx
|
2012-04-09 15:19:32 +02:00
|
|
|
.exit:
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2012-04-09 15:19:32 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
.expand:
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_lock
|
|
|
|
|
|
|
|
xchg esi, edi
|
|
|
|
|
|
|
|
push esi ;new size
|
|
|
|
push edi ;old size
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
add edi, 0x3FFFFF
|
|
|
|
and edi, not(0x3FFFFF)
|
|
|
|
add esi, 0x3FFFFF
|
|
|
|
and esi, not(0x3FFFFF)
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
cmp edi, esi
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .grow
|
2012-04-09 15:19:32 +02:00
|
|
|
@@:
|
2011-10-14 23:38:50 +02:00
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
2012-04-09 15:19:32 +02:00
|
|
|
jz .exit_fail
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
stdcall map_page_table, edi, eax
|
|
|
|
|
|
|
|
push edi
|
|
|
|
shr edi, 10
|
|
|
|
add edi, page_tabs
|
|
|
|
mov ecx, 1024
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
add edi, 0x00400000
|
|
|
|
cmp edi, esi
|
|
|
|
jb @B
|
|
|
|
.grow:
|
2012-04-09 15:19:32 +02:00
|
|
|
pop edi ;old size
|
|
|
|
pop ecx ;new size
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
shr edi, 10
|
|
|
|
shr ecx, 10
|
|
|
|
sub ecx, edi
|
|
|
|
shr ecx, 2 ;pages count
|
|
|
|
mov eax, 2
|
|
|
|
|
|
|
|
add edi, app_page_tabs
|
2011-10-14 23:38:50 +02:00
|
|
|
rep stosd
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_unlock
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
jmp .update_size
|
2012-04-09 15:19:32 +02:00
|
|
|
|
|
|
|
.exit_fail:
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
call mutex_unlock
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
add esp, 8
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2012-04-09 15:19:32 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
; param
|
|
|
|
; eax= linear address
|
|
|
|
;
|
|
|
|
; retval
|
2020-07-16 15:51:29 +02:00
|
|
|
; eax= physical page address
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
get_pg_addr:
|
2013-01-14 10:39:51 +01:00
|
|
|
sub eax, OS_BASE
|
|
|
|
cmp eax, 0x400000
|
|
|
|
jb @f
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 12
|
2013-01-14 10:39:51 +01:00
|
|
|
mov eax, [page_tabs+(eax+(OS_BASE shr 12))*4]
|
|
|
|
@@:
|
2011-10-14 23:38:50 +02:00
|
|
|
and eax, 0xFFFFF000
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
; Now it is called from core/sys32::exc_c (see stack frame there)
|
|
|
|
proc page_fault_handler
|
|
|
|
|
|
|
|
.err_addr equ ebp-4
|
|
|
|
|
|
|
|
push ebx ;save exception number (#PF)
|
|
|
|
mov ebp, esp
|
|
|
|
mov ebx, cr2
|
|
|
|
push ebx ;that is locals: .err_addr = cr2
|
|
|
|
inc [pg_data.pages_faults]
|
|
|
|
|
|
|
|
mov eax, [pf_err_code]
|
|
|
|
|
|
|
|
cmp ebx, OS_BASE ;ebx == .err_addr
|
2020-07-16 15:51:29 +02:00
|
|
|
jb .user_space ;page in application memory
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
cmp ebx, page_tabs
|
2020-07-16 15:51:29 +02:00
|
|
|
jb .kernel_space ;page in kernel memory
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
cmp ebx, kernel_tabs
|
2020-07-16 15:51:29 +02:00
|
|
|
jb .alloc;.app_tabs ;page tables of application ;
|
|
|
|
;simply create one
|
2011-10-14 23:38:50 +02:00
|
|
|
.core_tabs:
|
|
|
|
.fail: ;simply return to caller
|
|
|
|
mov esp, ebp
|
|
|
|
pop ebx ;restore exception number (#PF)
|
|
|
|
ret
|
|
|
|
|
|
|
|
.user_space:
|
2015-01-06 15:53:54 +01:00
|
|
|
test eax, PG_READ
|
2020-07-16 15:51:29 +02:00
|
|
|
jnz .err_access ;Page presents
|
|
|
|
;Access error ?
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
shr ebx, 12
|
|
|
|
mov ecx, ebx
|
|
|
|
shr ecx, 10
|
|
|
|
mov edx, [master_tab+ecx*4]
|
2015-01-06 15:53:54 +01:00
|
|
|
test edx, PG_READ
|
2020-07-16 15:51:29 +02:00
|
|
|
jz .fail ;page table is not created
|
|
|
|
;incorrect address in program
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov eax, [page_tabs+ebx*4]
|
|
|
|
test eax, 2
|
2020-07-16 15:51:29 +02:00
|
|
|
jz .fail ;address is not reserved for usage. Error
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
.alloc:
|
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, [.err_addr], eax, PG_UWR
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov edi, [.err_addr]
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
mov ecx, 1024
|
|
|
|
xor eax, eax
|
|
|
|
;cld ;caller is duty for this
|
|
|
|
rep stosd
|
|
|
|
.exit: ;iret with repeat fault instruction
|
|
|
|
add esp, 12;clear in stack: locals(.err_addr) + #PF + ret_to_caller
|
|
|
|
restore_ring3_context
|
|
|
|
iretd
|
|
|
|
|
|
|
|
.err_access:
|
|
|
|
; access denied? this may be a result of copy-on-write protection for DLL
|
|
|
|
; check list of HDLLs
|
|
|
|
and ebx, not 0xFFF
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [current_process]
|
|
|
|
mov eax, [eax+PROC.dlls_list_ptr]
|
2011-10-14 23:38:50 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
mov esi, [eax+HDLL.fd]
|
|
|
|
.scan_hdll:
|
|
|
|
cmp esi, eax
|
|
|
|
jz .fail
|
|
|
|
mov edx, ebx
|
|
|
|
sub edx, [esi+HDLL.base]
|
|
|
|
cmp edx, [esi+HDLL.size]
|
|
|
|
jb .fault_in_hdll
|
|
|
|
.scan_hdll.next:
|
|
|
|
mov esi, [esi+HDLL.fd]
|
|
|
|
jmp .scan_hdll
|
|
|
|
.fault_in_hdll:
|
|
|
|
; allocate new page, map it as rw and copy data
|
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, ebx, eax, PG_UWR
|
2011-10-14 23:38:50 +02:00
|
|
|
mov edi, ebx
|
|
|
|
mov ecx, 1024
|
|
|
|
sub ebx, [esi+HDLL.base]
|
|
|
|
mov esi, [esi+HDLL.parent]
|
|
|
|
mov esi, [esi+DLLDESCR.data]
|
|
|
|
add esi, ebx
|
|
|
|
rep movsd
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.kernel_space:
|
2015-01-06 15:53:54 +01:00
|
|
|
test eax, PG_READ
|
2020-07-16 15:51:29 +02:00
|
|
|
jz .fail ;page does not present
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
test eax, 12 ;U/S (+below)
|
2020-07-16 15:51:29 +02:00
|
|
|
jnz .fail ;application requested kernel memory
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
;test eax, 8
|
2020-07-16 15:51:29 +02:00
|
|
|
;jnz .fail ;the reserved bit is set in page tables. Added in P4/Xeon
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2020-07-16 15:51:29 +02:00
|
|
|
;an attempt to write to a protected kernel page
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
cmp ebx, tss._io_map_0
|
|
|
|
jb .fail
|
|
|
|
|
|
|
|
cmp ebx, tss._io_map_0+8192
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
; io permission map
|
|
|
|
; copy-on-write protection
|
|
|
|
|
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
push eax
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, [.err_addr], eax, dword PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
pop eax
|
|
|
|
mov edi, [.err_addr]
|
|
|
|
and edi, -4096
|
|
|
|
lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0
|
|
|
|
|
|
|
|
mov ebx, esi
|
|
|
|
shr ebx, 12
|
|
|
|
mov edx, [current_slot]
|
2015-01-06 15:53:54 +01:00
|
|
|
or eax, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [edx+APPDATA.io_map+ebx*4], eax
|
|
|
|
|
|
|
|
add esi, [default_io_map]
|
|
|
|
mov ecx, 4096/4
|
|
|
|
;cld ;caller is duty for this
|
|
|
|
rep movsd
|
|
|
|
jmp .exit
|
|
|
|
endp
|
|
|
|
|
|
|
|
; returns number of mapped bytes
|
2014-09-18 09:58:56 +02:00
|
|
|
proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\
|
2011-10-14 23:38:50 +02:00
|
|
|
ofs:dword,buf_size:dword,req_access:dword
|
2014-09-18 09:58:56 +02:00
|
|
|
locals
|
|
|
|
count dd ?
|
|
|
|
process dd ?
|
|
|
|
endl
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [count], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [buf_size], 0
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
mov eax, [slot]
|
|
|
|
shl eax, 8
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.process]
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [process], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ebx, [ofs]
|
|
|
|
shr ebx, 22
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table
|
|
|
|
mov esi, [ipc_ptab]
|
2011-10-14 23:38:50 +02:00
|
|
|
and eax, 0xFFFFF000
|
|
|
|
jz .exit
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, esi, eax, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
mov edi, [lin_addr]
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
mov ecx, [buf_size]
|
|
|
|
add ecx, 4095
|
|
|
|
shr ecx, 12
|
2014-09-18 09:58:56 +02:00
|
|
|
inc ecx ; ???????????
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov edx, [ofs]
|
|
|
|
shr edx, 12
|
|
|
|
and edx, 0x3FF
|
|
|
|
.map:
|
|
|
|
stdcall safe_map_page, [slot], [req_access], [ofs]
|
|
|
|
jnc .exit
|
2014-09-18 09:58:56 +02:00
|
|
|
add [count], PAGE_SIZE
|
|
|
|
add [ofs], PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
dec ecx
|
|
|
|
jz .exit
|
2014-09-18 09:58:56 +02:00
|
|
|
|
|
|
|
add edi, PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2014-09-18 09:58:56 +02:00
|
|
|
cmp edx, 1024
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .map
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
inc ebx
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [process]
|
|
|
|
mov eax, [eax+PROC.pdt_0+ebx*4]
|
2011-10-14 23:38:50 +02:00
|
|
|
and eax, 0xFFFFF000
|
|
|
|
jz .exit
|
2014-09-18 09:58:56 +02:00
|
|
|
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, esi, eax, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
xor edx, edx
|
|
|
|
jmp .map
|
|
|
|
.exit:
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [count]
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
|
|
|
|
ofs:dword,buf_size:dword,req_access:dword
|
2014-09-18 09:58:56 +02:00
|
|
|
locals
|
|
|
|
count dd ?
|
|
|
|
process dd ?
|
|
|
|
endl
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [count], 0
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [buf_size], 0
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
mov eax, [slot]
|
|
|
|
shl eax, 8
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.process]
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov [process], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
mov ebx, [ofs]
|
|
|
|
shr ebx, 22
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table
|
|
|
|
mov esi, [proc_mem_tab]
|
2011-10-14 23:38:50 +02:00
|
|
|
and eax, 0xFFFFF000
|
|
|
|
jz .exit
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, esi, eax, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
mov edi, [lin_addr]
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
mov ecx, [buf_size]
|
|
|
|
add ecx, 4095
|
|
|
|
shr ecx, 12
|
2014-09-18 09:58:56 +02:00
|
|
|
inc ecx ; ???????????
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov edx, [ofs]
|
|
|
|
shr edx, 12
|
|
|
|
and edx, 0x3FF
|
|
|
|
.map:
|
|
|
|
stdcall safe_map_page, [slot], [req_access], [ofs]
|
|
|
|
jnc .exit
|
2014-09-18 09:58:56 +02:00
|
|
|
add [count], PAGE_SIZE
|
|
|
|
add [ofs], PAGE_SIZE
|
2011-10-14 23:38:50 +02:00
|
|
|
dec ecx
|
2014-09-18 09:58:56 +02:00
|
|
|
jz .exit
|
|
|
|
|
|
|
|
add edi, PAGE_SIZE
|
|
|
|
inc edx
|
|
|
|
cmp edx, 1024
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .map
|
2014-09-18 09:58:56 +02:00
|
|
|
|
|
|
|
inc ebx
|
|
|
|
mov eax, [process]
|
|
|
|
mov eax, [eax+PROC.pdt_0+ebx*4]
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
jz .exit
|
|
|
|
|
2015-01-06 15:53:54 +01:00
|
|
|
stdcall map_page, esi, eax, PG_SWR
|
2014-09-18 09:58:56 +02:00
|
|
|
xor edx, edx
|
|
|
|
jmp .map
|
2011-10-14 23:38:50 +02:00
|
|
|
.exit:
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [count]
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
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]
|
2015-01-06 15:53:54 +01:00
|
|
|
test al, PG_READ
|
2011-10-14 23:38:50 +02:00
|
|
|
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
|
2015-01-06 15:53:54 +01:00
|
|
|
or al, PG_UWR
|
2011-10-14 23:38:50 +02:00
|
|
|
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
|
2014-09-18 09:58:56 +02:00
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.process]
|
|
|
|
mov eax, [eax+PROC.dlls_list_ptr]
|
2011-10-14 23:38:50 +02:00
|
|
|
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
|
2015-01-06 15:53:54 +01:00
|
|
|
or al, PG_UWR
|
2011-10-14 23:38:50 +02:00
|
|
|
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:
|
|
|
|
;input:
|
|
|
|
; ebx=1 - set ipc buffer area
|
|
|
|
; ecx=address of buffer
|
|
|
|
; edx=size of buffer
|
|
|
|
; eax=2 - send message
|
|
|
|
; ebx=PID
|
|
|
|
; ecx=address of message
|
|
|
|
; edx=size of message
|
|
|
|
|
|
|
|
dec ebx
|
|
|
|
jnz @f
|
|
|
|
|
|
|
|
mov eax, [current_slot]
|
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
mov [eax+APPDATA.ipc_start], ecx ;set fields in extended information area
|
|
|
|
mov [eax+APPDATA.ipc_size], edx
|
|
|
|
|
|
|
|
add edx, ecx
|
|
|
|
add edx, 4095
|
|
|
|
and edx, not 4095
|
|
|
|
|
|
|
|
.touch:
|
|
|
|
mov eax, [ecx]
|
|
|
|
add ecx, 0x1000
|
|
|
|
cmp ecx, edx
|
|
|
|
jb .touch
|
|
|
|
|
|
|
|
popf
|
|
|
|
mov [esp+32], ebx ;ebx=0
|
|
|
|
ret
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;2
|
|
|
|
@@:
|
|
|
|
dec ebx
|
|
|
|
jnz @f
|
|
|
|
|
|
|
|
stdcall sys_ipc_send, ecx, edx, esi
|
|
|
|
mov [esp+32], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
or eax, -1
|
|
|
|
mov [esp+32], eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
|
|
|
locals
|
|
|
|
dst_slot dd ?
|
|
|
|
dst_offset dd ?
|
|
|
|
buf_size dd ?
|
|
|
|
used_buf dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
|
|
|
|
mov eax, [PID]
|
|
|
|
call pid_to_slot
|
|
|
|
test eax, eax
|
|
|
|
jz .no_pid
|
|
|
|
|
|
|
|
mov [dst_slot], eax
|
|
|
|
shl eax, 8
|
2014-09-18 09:58:56 +02:00
|
|
|
mov edi, [eax+SLOT_BASE+APPDATA.ipc_start] ;is ipc area defined?
|
2011-10-14 23:38:50 +02:00
|
|
|
test edi, edi
|
|
|
|
jz .no_ipc_area
|
|
|
|
|
|
|
|
mov ebx, edi
|
|
|
|
and ebx, 0xFFF
|
|
|
|
mov [dst_offset], ebx
|
|
|
|
|
2014-09-18 09:58:56 +02:00
|
|
|
mov esi, [eax+SLOT_BASE+APPDATA.ipc_size]
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [buf_size], esi
|
|
|
|
|
|
|
|
mov ecx, [ipc_tmp]
|
|
|
|
cmp esi, 0x40000-0x1000; size of [ipc_tmp] minus one page
|
|
|
|
jbe @f
|
|
|
|
push esi edi
|
|
|
|
add esi, 0x1000
|
|
|
|
stdcall alloc_kernel_space, esi
|
|
|
|
mov ecx, eax
|
|
|
|
pop edi esi
|
|
|
|
@@:
|
|
|
|
mov [used_buf], ecx
|
2014-09-18 09:58:56 +02:00
|
|
|
stdcall map_mem_ipc, ecx, [dst_slot], \
|
2015-01-06 15:53:54 +01:00
|
|
|
edi, esi, PG_SWR
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
mov edi, [dst_offset]
|
|
|
|
add edi, [used_buf]
|
|
|
|
cmp dword [edi], 0
|
|
|
|
jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now
|
|
|
|
|
|
|
|
mov edx, dword [edi+4]
|
|
|
|
lea ebx, [edx+8]
|
|
|
|
add ebx, [msg_size]
|
|
|
|
cmp ebx, [buf_size]
|
|
|
|
ja .buffer_overflow ;esi<0 - not enough memory in buffer
|
|
|
|
|
|
|
|
mov dword [edi+4], ebx
|
2022-02-06 21:33:29 +01:00
|
|
|
mov eax, [current_slot]
|
|
|
|
mov eax, [eax + APPDATA.tid] ;eax - our PID
|
2011-10-14 23:38:50 +02:00
|
|
|
add edi, edx
|
|
|
|
mov [edi], eax
|
|
|
|
mov ecx, [msg_size]
|
|
|
|
|
|
|
|
mov [edi+4], ecx
|
|
|
|
add edi, 8
|
|
|
|
mov esi, [msg_addr]
|
|
|
|
; add esi, new_app_base
|
|
|
|
cld
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
mov ebx, [ipc_tmp]
|
|
|
|
mov edx, ebx
|
|
|
|
shr ebx, 12
|
|
|
|
xor eax, eax
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
mov ebx, [ipc_pdir]
|
|
|
|
mov edx, ebx
|
|
|
|
shr ebx, 12
|
|
|
|
xor eax, eax
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
mov ebx, [ipc_ptab]
|
|
|
|
mov edx, ebx
|
|
|
|
shr ebx, 12
|
|
|
|
xor eax, eax
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
mov eax, [dst_slot]
|
2021-06-19 10:41:09 +02:00
|
|
|
shl eax, BSF sizeof.APPDATA
|
|
|
|
or [eax+SLOT_BASE+APPDATA.occurred_events], EVENT_IPC
|
2011-10-14 23:38:50 +02:00
|
|
|
push 0
|
|
|
|
jmp .ret
|
|
|
|
.no_pid:
|
|
|
|
popf
|
|
|
|
mov eax, 4
|
|
|
|
ret
|
|
|
|
.no_ipc_area:
|
|
|
|
popf
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
ret
|
|
|
|
.ipc_blocked:
|
|
|
|
push 2
|
|
|
|
jmp .ret
|
|
|
|
.buffer_overflow:
|
|
|
|
push 3
|
|
|
|
.ret:
|
|
|
|
mov eax, [used_buf]
|
|
|
|
cmp eax, [ipc_tmp]
|
2014-09-18 09:58:56 +02:00
|
|
|
je @f
|
2011-10-14 23:38:50 +02:00
|
|
|
stdcall free_kernel_space, eax
|
|
|
|
@@:
|
|
|
|
pop eax
|
|
|
|
popf
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
sysfn_meminfo:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
mov eax, [pg_data.pages_count]
|
|
|
|
mov [ecx], eax
|
|
|
|
shl eax, 12
|
|
|
|
mov [esp+32], eax
|
|
|
|
mov eax, [pg_data.pages_free]
|
|
|
|
mov [ecx+4], eax
|
|
|
|
mov eax, [pg_data.pages_faults]
|
|
|
|
mov [ecx+8], eax
|
|
|
|
mov eax, [heap_size]
|
|
|
|
mov [ecx+12], eax
|
|
|
|
mov eax, [heap_free]
|
|
|
|
mov [ecx+16], eax
|
|
|
|
mov eax, [heap_blocks]
|
|
|
|
mov [ecx+20], eax
|
|
|
|
mov eax, [free_blocks]
|
|
|
|
mov [ecx+24], eax
|
|
|
|
ret
|
|
|
|
.fail:
|
|
|
|
or dword [esp+32], -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
f68:
|
|
|
|
cmp ebx, 4
|
|
|
|
jbe sys_sheduler
|
|
|
|
cmp ebx, 11
|
2016-10-16 22:32:10 +02:00
|
|
|
jb undefined_syscall
|
2021-12-18 23:46:36 +01:00
|
|
|
cmp ebx, 31
|
2016-10-16 22:32:10 +02:00
|
|
|
ja undefined_syscall
|
2016-12-09 10:48:32 +01:00
|
|
|
xor eax, eax
|
2011-10-14 23:38:50 +02:00
|
|
|
jmp dword [f68call+ebx*4-11*4]
|
|
|
|
.11:
|
|
|
|
call init_heap
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.12:
|
|
|
|
stdcall user_alloc, ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.13:
|
|
|
|
stdcall user_free, ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.14:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
mov edi, ecx
|
|
|
|
call get_event_ex
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.16:
|
|
|
|
test ecx, ecx
|
|
|
|
jz .fail
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
stdcall get_service, ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.17:
|
|
|
|
call srv_handlerEx ;ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
2016-12-15 18:38:17 +01:00
|
|
|
.18:
|
|
|
|
mov eax, edx
|
2011-10-14 23:38:50 +02:00
|
|
|
.19:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
2016-12-09 10:48:32 +01:00
|
|
|
stdcall load_library, ecx, eax
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.20:
|
|
|
|
mov eax, edx
|
|
|
|
mov ebx, ecx
|
|
|
|
call user_realloc ;in: eax = pointer, ebx = new size
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.21:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
2012-04-25 23:35:25 +02:00
|
|
|
cmp edx, OS_BASE
|
2011-10-14 23:38:50 +02:00
|
|
|
jae .fail
|
2013-12-30 12:18:33 +01:00
|
|
|
stdcall load_pe_driver, ecx, edx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.22:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
stdcall shmem_open, ecx, edx, esi
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._edx], edx
|
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.23:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
stdcall shmem_close, ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.24:
|
|
|
|
mov eax, [current_slot]
|
|
|
|
xchg ecx, [eax+APPDATA.exc_handler]
|
|
|
|
xchg edx, [eax+APPDATA.except_mask]
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._ebx], edx
|
|
|
|
mov [esp+SYSCALL_STACK._eax], ecx
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
.25:
|
|
|
|
cmp ecx, 32
|
|
|
|
jae .fail
|
|
|
|
mov eax, [current_slot]
|
|
|
|
btr [eax+APPDATA.except_mask], ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
setc byte[esp+SYSCALL_STACK._eax]
|
2011-10-14 23:38:50 +02:00
|
|
|
jecxz @f
|
|
|
|
bts [eax+APPDATA.except_mask], ecx
|
|
|
|
@@:
|
|
|
|
ret
|
2012-02-24 22:47:01 +01:00
|
|
|
.26:
|
|
|
|
stdcall user_unmap, ecx, edx, esi
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2012-02-24 22:47:01 +01:00
|
|
|
ret
|
2013-07-09 14:38:05 +02:00
|
|
|
.27:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
stdcall load_file_umode, ecx
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._edx], edx
|
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2013-07-09 14:38:05 +02:00
|
|
|
ret
|
2016-12-15 18:38:17 +01:00
|
|
|
.28:
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
push ecx edx
|
|
|
|
stdcall kernel_alloc, maxPathLength
|
|
|
|
mov edi, eax
|
|
|
|
pop eax esi
|
|
|
|
push edi
|
|
|
|
call getFullPath
|
|
|
|
pop ebp
|
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
stdcall load_file_umode, ebp
|
|
|
|
mov [esp+SYSCALL_STACK._edx], edx
|
|
|
|
@@:
|
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
|
|
|
stdcall kernel_free, ebp
|
|
|
|
ret
|
2013-07-09 14:38:05 +02:00
|
|
|
|
2020-05-22 17:38:59 +02:00
|
|
|
.29:
|
|
|
|
stdcall user_ring, ecx
|
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
|
|
|
ret
|
|
|
|
|
2021-12-18 19:11:03 +01:00
|
|
|
; unload driver
|
|
|
|
.30: ; ecx = handl driver edx = cmdline
|
|
|
|
mov eax, -1
|
|
|
|
cmp edx, OS_BASE
|
|
|
|
jae .fail
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
jbe .fail
|
2021-12-18 23:46:36 +01:00
|
|
|
cmp [ecx+SRV.magic], ' SRV'
|
|
|
|
jne .fail
|
|
|
|
cmp [ecx+SRV.size], sizeof.SRV
|
|
|
|
jne .fail
|
2021-12-18 19:11:03 +01:00
|
|
|
|
|
|
|
mov eax, [ecx+SRV.entry]
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
push ecx ;save handl
|
|
|
|
|
|
|
|
push edx ;cmdline
|
|
|
|
push DRV_EXIT
|
|
|
|
call eax ;the result is not checked
|
|
|
|
lea esp, [esp+8]
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov ebx, [ecx+SRV.base]
|
|
|
|
mov eax, -2 ;error free RAM
|
|
|
|
test ebx, ebx
|
|
|
|
jz .fail
|
|
|
|
stdcall kernel_free, ebx ;del driver
|
|
|
|
|
|
|
|
mov eax, [ecx+SRV.fd]
|
|
|
|
mov edx, [ecx+SRV.bk]
|
|
|
|
mov [edx+SRV.fd], eax
|
|
|
|
mov [eax+SRV.bk], edx
|
|
|
|
stdcall free, ecx
|
|
|
|
;dec [count_services]
|
|
|
|
|
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
|
|
|
ret
|
2021-12-18 23:46:36 +01:00
|
|
|
.31: ; get list service
|
|
|
|
test ecx, ecx
|
|
|
|
jz .fail ; get count
|
|
|
|
dec ecx
|
|
|
|
jnz @f ;1 - get pointer first and last structure
|
|
|
|
|
|
|
|
mov ebx, [srv.fd]
|
|
|
|
mov ecx, [srv.bk]
|
|
|
|
mov [esp+SYSCALL_STACK._ebx], ebx ;fd
|
|
|
|
mov [esp+SYSCALL_STACK._ecx], ecx ;bk
|
|
|
|
mov [esp+SYSCALL_STACK._eax], 0
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
dec ecx
|
|
|
|
jnz .fail ; 2 - get info for SRV structure
|
|
|
|
|
|
|
|
mov eax, -1
|
2021-12-19 00:39:17 +01:00
|
|
|
cmp edx, OS_BASE ; edx = pointer on structure
|
2021-12-18 23:46:36 +01:00
|
|
|
jbe .fail
|
2021-12-19 00:39:17 +01:00
|
|
|
stdcall is_region_userspace, edi, 40 ;16+4*6=40 <-max size buffer
|
|
|
|
jnz .fail ; edi = pointer on buffer
|
|
|
|
cmp [edx+SRV.magic], ' SRV'
|
2021-12-18 23:46:36 +01:00
|
|
|
jne .fail
|
2021-12-19 00:39:17 +01:00
|
|
|
cmp [edx+SRV.size], sizeof.SRV
|
2021-12-18 23:46:36 +01:00
|
|
|
jne .fail
|
|
|
|
|
2021-12-19 00:39:17 +01:00
|
|
|
mov esi, edx
|
2021-12-18 23:46:36 +01:00
|
|
|
movsd ; name service 16 byte
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
2021-12-19 00:39:17 +01:00
|
|
|
lea esi, [edx+SRV.fd]
|
2021-12-18 23:46:36 +01:00
|
|
|
movsd ; SRV.fd
|
|
|
|
movsd ; SRV.bk
|
|
|
|
movsd ; SRV.base
|
|
|
|
movsd ; SRV.entry
|
|
|
|
movsd ; SRV.srv_proc
|
|
|
|
;movsd ; SRV.srv_proc_ex
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
|
|
|
ret
|
2011-10-14 23:38:50 +02:00
|
|
|
.fail:
|
2016-10-16 22:32:10 +02:00
|
|
|
mov [esp+SYSCALL_STACK._eax], eax
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
f68call: ; keep this table closer to main code
|
|
|
|
|
|
|
|
dd f68.11 ; init_heap
|
|
|
|
dd f68.12 ; user_alloc
|
|
|
|
dd f68.13 ; user_free
|
|
|
|
dd f68.14 ; get_event_ex
|
|
|
|
dd f68.fail ; moved to f68.24
|
|
|
|
dd f68.16 ; get_service
|
|
|
|
dd f68.17 ; call_service
|
2016-12-15 18:38:17 +01:00
|
|
|
dd f68.18 ; loadLibUnicode
|
2011-10-14 23:38:50 +02:00
|
|
|
dd f68.19 ; load_dll
|
|
|
|
dd f68.20 ; user_realloc
|
|
|
|
dd f68.21 ; load_driver
|
|
|
|
dd f68.22 ; shmem_open
|
|
|
|
dd f68.23 ; shmem_close
|
2012-02-24 22:47:01 +01:00
|
|
|
dd f68.24 ; set exception handler
|
|
|
|
dd f68.25 ; unmask exception
|
|
|
|
dd f68.26 ; user_unmap
|
2013-07-09 14:38:05 +02:00
|
|
|
dd f68.27 ; load_file_umode
|
2016-12-15 18:38:17 +01:00
|
|
|
dd f68.28 ; loadFileUnicode
|
2020-05-22 17:38:59 +02:00
|
|
|
dd f68.29 ; user_ring
|
2021-12-18 19:11:03 +01:00
|
|
|
dd f68.30 ; unload_driver
|
2021-12-18 23:46:36 +01:00
|
|
|
dd f68.31 ; get_driver_info
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
align 4
|
2013-12-30 12:18:33 +01:00
|
|
|
proc load_pe_driver stdcall, file:dword, cmdline:dword
|
|
|
|
push esi
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
stdcall load_PE, [file]
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
mov esi, eax
|
2021-12-07 03:49:57 +01:00
|
|
|
push ebx ; base addres driver
|
2013-12-30 12:18:33 +01:00
|
|
|
push [cmdline]
|
|
|
|
push DRV_ENTRY
|
|
|
|
call eax
|
|
|
|
pop ecx
|
|
|
|
pop ecx
|
2021-12-07 03:49:57 +01:00
|
|
|
pop ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
test eax, eax
|
2021-12-07 03:49:57 +01:00
|
|
|
jz .fail_init
|
2011-10-14 23:38:50 +02:00
|
|
|
|
2021-12-18 12:12:02 +01:00
|
|
|
mov [eax+SRV.base], ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [eax+SRV.entry], esi
|
2013-12-30 12:18:33 +01:00
|
|
|
pop esi
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
2021-12-07 03:49:57 +01:00
|
|
|
.fail_init:
|
|
|
|
stdcall kernel_free, ebx ;clear memory driver
|
2011-10-14 23:38:50 +02:00
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
2013-12-30 12:18:33 +01:00
|
|
|
pop esi
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc create_ring_buffer stdcall, size:dword, flags:dword
|
|
|
|
locals
|
|
|
|
buf_ptr dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
mov eax, [size]
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
add eax, eax
|
|
|
|
stdcall alloc_kernel_space, eax
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
|
|
|
|
mov [buf_ptr], eax
|
|
|
|
|
|
|
|
mov ebx, [size]
|
|
|
|
shr ebx, 12
|
|
|
|
push ebx
|
|
|
|
|
|
|
|
stdcall alloc_pages, ebx
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
jz .mm_fail
|
|
|
|
|
|
|
|
push edi
|
|
|
|
|
|
|
|
or eax, [flags]
|
|
|
|
mov edi, [buf_ptr]
|
|
|
|
mov ebx, [buf_ptr]
|
|
|
|
mov edx, ecx
|
|
|
|
shl edx, 2
|
|
|
|
shr edi, 10
|
|
|
|
@@:
|
|
|
|
mov [page_tabs+edi], eax
|
|
|
|
mov [page_tabs+edi+edx], eax
|
|
|
|
invlpg [ebx]
|
|
|
|
invlpg [ebx+0x10000]
|
|
|
|
add eax, 0x1000
|
|
|
|
add ebx, 0x1000
|
|
|
|
add edi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
mov eax, [buf_ptr]
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
ret
|
|
|
|
.mm_fail:
|
|
|
|
stdcall free_kernel_space, [buf_ptr]
|
|
|
|
xor eax, eax
|
|
|
|
pop ebx
|
|
|
|
.fail:
|
|
|
|
ret
|
|
|
|
endp
|
2012-03-15 14:05:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc print_mem
|
2017-12-17 03:12:53 +01:00
|
|
|
mov edi, BOOT.memmap_blocks
|
2012-03-15 14:05:45 +01:00
|
|
|
mov ecx, [edi-4]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .done
|
|
|
|
|
|
|
|
@@:
|
|
|
|
mov eax, [edi]
|
|
|
|
mov edx, [edi+4]
|
|
|
|
add eax, [edi+8]
|
|
|
|
adc edx, [edi+12]
|
|
|
|
|
|
|
|
DEBUGF 1, "K : E820 %x%x - %x%x type %d\n", \
|
|
|
|
[edi+4], [edi],\
|
|
|
|
edx, eax, [edi+16]
|
|
|
|
add edi, 20
|
|
|
|
dec ecx
|
|
|
|
jnz @b
|
|
|
|
.done:
|
|
|
|
ret
|
|
|
|
endp
|