2007-03-26 14:18:08 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2009-11-28 00:49:47 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
|
2007-03-26 14:18:08 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2006-11-20 08:06:00 +01:00
|
|
|
|
2007-07-27 15:52:03 +02:00
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
DRV_COMPAT equ 5 ;minimal required drivers version
|
2011-08-21 14:26:22 +02:00
|
|
|
DRV_CURRENT equ 6 ;current drivers model version
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
|
|
DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT
|
2008-05-02 09:27:54 +02:00
|
|
|
PID_KERNEL equ 1 ;os_idle thread
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
align 4
|
2008-03-18 18:19:08 +01:00
|
|
|
proc attach_int_handler stdcall, irq:dword, handler:dword, access_rights:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2011-08-21 14:26:22 +02:00
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
|
2008-12-23 17:29:05 +01:00
|
|
|
push ebx
|
|
|
|
|
2008-06-09 14:12:09 +02:00
|
|
|
mov ebx, [irq] ;irq num
|
2008-11-17 13:04:16 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .err
|
2008-06-09 14:12:09 +02:00
|
|
|
cmp ebx, 15 ; hidnplayr says: we only have 16 IRQ's
|
2008-11-17 13:04:16 +01:00
|
|
|
ja .err
|
|
|
|
mov eax, [handler]
|
|
|
|
test eax, eax
|
|
|
|
jz .err
|
2008-03-18 18:19:08 +01:00
|
|
|
|
2008-11-17 13:04:16 +01:00
|
|
|
mov [irq_tab+ebx*4], eax
|
|
|
|
stdcall enable_irq, [irq]
|
2008-12-23 17:29:05 +01:00
|
|
|
pop ebx
|
2008-06-09 14:12:09 +02:00
|
|
|
mov eax, 1
|
2011-08-21 14:26:22 +02:00
|
|
|
popfd
|
2008-11-17 13:04:16 +01:00
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.err:
|
2008-12-23 17:29:05 +01:00
|
|
|
pop ebx
|
2008-11-17 13:04:16 +01:00
|
|
|
xor eax, eax
|
2011-08-21 14:26:22 +02:00
|
|
|
popfd
|
2008-11-17 13:04:16 +01:00
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
2011-08-22 11:49:26 +02:00
|
|
|
align 4
|
2008-03-18 18:19:08 +01:00
|
|
|
proc get_int_handler stdcall, irq:dword
|
|
|
|
|
2011-08-22 11:49:26 +02:00
|
|
|
mov eax, [irq]
|
|
|
|
cmp eax, 15
|
|
|
|
ja .fail
|
|
|
|
mov eax, [irq_tab + 4 * eax]
|
|
|
|
ret
|
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2008-03-18 18:19:08 +01:00
|
|
|
endp
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
|
|
|
proc detach_int_handler
|
|
|
|
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc enable_irq stdcall, irq_line:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [irq_line]
|
|
|
|
mov edx, 0x21
|
|
|
|
cmp ebx, 8
|
|
|
|
jb @F
|
|
|
|
mov edx, 0xA1
|
|
|
|
sub ebx,8
|
2006-10-06 08:09:41 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
in al,dx
|
|
|
|
btr eax, ebx
|
|
|
|
out dx, al
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 16
|
|
|
|
;; proc irq_serv
|
|
|
|
|
|
|
|
irq_serv:
|
|
|
|
|
|
|
|
.irq_1:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 1
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_2:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 2
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_3:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 3
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_4:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 4
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_5:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 5
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
2011-07-01 12:03:33 +02:00
|
|
|
align 4
|
|
|
|
.irq_6:
|
|
|
|
push 6
|
|
|
|
jmp .main
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
|
|
|
.irq_7:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 7
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_8:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 8
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_9:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 9
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_10:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 10
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_11:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 11
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_12:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 12
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
2008-12-17 19:59:45 +01:00
|
|
|
; align 4
|
|
|
|
; .irq_13:
|
|
|
|
; push 13
|
|
|
|
; jmp .main
|
2011-06-29 13:57:56 +02:00
|
|
|
align 4
|
|
|
|
.irq_14:
|
|
|
|
push 14
|
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_15:
|
|
|
|
push 15
|
|
|
|
jmp .main
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
align 16
|
|
|
|
.main:
|
|
|
|
save_ring3_context
|
2008-03-13 21:23:15 +01:00
|
|
|
mov eax, [esp + 32]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov bx, app_data ;os_data
|
2006-10-06 08:09:41 +02:00
|
|
|
mov ds, bx
|
|
|
|
mov es, bx
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp [v86_irqhooks+eax*8], 0
|
|
|
|
jnz v86_irq
|
2008-02-04 16:31:59 +01:00
|
|
|
|
2011-07-01 12:03:33 +02:00
|
|
|
cmp al, 6
|
|
|
|
jnz @f
|
|
|
|
push eax
|
|
|
|
call [fdc_irq_func]
|
|
|
|
pop eax
|
|
|
|
@@:
|
|
|
|
|
2011-06-29 13:57:56 +02:00
|
|
|
cmp al, 14
|
|
|
|
jnz @f
|
|
|
|
push eax
|
|
|
|
call [irq14_func]
|
|
|
|
pop eax
|
|
|
|
@@:
|
|
|
|
cmp al, 15
|
|
|
|
jnz @f
|
|
|
|
push eax
|
|
|
|
call [irq15_func]
|
|
|
|
pop eax
|
|
|
|
@@:
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
mov ebx, [irq_tab+eax*4]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .exit
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
call ebx
|
|
|
|
mov [check_idle_semaphore],5
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
.exit:
|
|
|
|
|
2011-08-21 14:26:22 +02:00
|
|
|
cmp dword [esp + 32], 8
|
2006-10-06 08:09:41 +02:00
|
|
|
mov al, 0x20
|
2007-11-15 20:43:35 +01:00
|
|
|
jb @f
|
2011-08-21 14:26:22 +02:00
|
|
|
out 0xa0, al
|
2006-10-06 08:09:41 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
out 0x20, al
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
restore_ring3_context
|
|
|
|
add esp, 4
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
iret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_notify stdcall, p_ev:dword
|
|
|
|
|
|
|
|
.wait:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx,[current_slot]
|
|
|
|
test dword [ebx+APPDATA.event_mask],EVENT_NOTIFY
|
2006-10-06 08:09:41 +02:00
|
|
|
jz @f
|
2007-11-15 20:43:35 +01:00
|
|
|
and dword [ebx+APPDATA.event_mask], not EVENT_NOTIFY
|
2006-10-06 08:09:41 +02:00
|
|
|
mov edi, [p_ev]
|
|
|
|
mov dword [edi], EV_INTR
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [ebx+APPDATA.event]
|
2006-10-06 08:09:41 +02:00
|
|
|
mov dword [edi+4], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
call change_task
|
|
|
|
jmp .wait
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 6
|
2006-10-06 08:09:41 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
call pci_read_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-06-27 01:33:43 +02:00
|
|
|
align 4
|
|
|
|
proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 5
|
2007-06-27 01:33:43 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
call pci_read_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
|
|
|
proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 4
|
2006-10-06 08:09:41 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
call pci_read_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 8
|
2006-10-06 08:09:41 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, [val]
|
|
|
|
call pci_write_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-06-27 01:33:43 +02:00
|
|
|
align 4
|
|
|
|
proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 9
|
2007-06-27 01:33:43 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, [val]
|
|
|
|
call pci_write_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
align 4
|
|
|
|
proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
|
|
|
mov al, 10
|
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
mov ecx, [val]
|
|
|
|
call pci_write_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
handle equ IOCTL.handle
|
|
|
|
io_code equ IOCTL.io_code
|
|
|
|
input equ IOCTL.input
|
|
|
|
inp_size equ IOCTL.inp_size
|
|
|
|
output equ IOCTL.output
|
|
|
|
out_size equ IOCTL.out_size
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc srv_handler stdcall, ioctl:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, [ioctl]
|
|
|
|
test esi, esi
|
|
|
|
jz .err
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edi, [esi+handle]
|
|
|
|
cmp [edi+SRV.magic], ' SRV'
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2009-11-16 12:28:19 +01:00
|
|
|
cmp [edi+SRV.size], SRV.sizeof
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall [edi+SRV.srv_proc], esi
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
mov [esi+output], eax
|
|
|
|
mov [esi+out_size], 4
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.err:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
2007-02-26 13:40:37 +01:00
|
|
|
; param
|
2010-01-02 06:49:10 +01:00
|
|
|
; ecx= io_control
|
2007-02-26 13:40:37 +01:00
|
|
|
;
|
|
|
|
; retval
|
|
|
|
; eax= error code
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
2007-02-26 13:40:37 +01:00
|
|
|
srv_handlerEx:
|
2010-01-02 06:49:10 +01:00
|
|
|
cmp ecx, OS_BASE
|
2007-11-15 20:43:35 +01:00
|
|
|
jae .fail
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2010-01-02 06:49:10 +01:00
|
|
|
mov eax, [ecx+handle]
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [eax+SRV.magic], ' SRV'
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2009-11-16 12:28:19 +01:00
|
|
|
cmp [eax+SRV.size], SRV.sizeof
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2010-01-02 06:49:10 +01:00
|
|
|
stdcall [eax+SRV.srv_proc], ecx
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
restore handle
|
|
|
|
restore io_code
|
|
|
|
restore input
|
|
|
|
restore inp_size
|
|
|
|
restore output
|
|
|
|
restore out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_service stdcall, sz_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [sz_name]
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [srv.fd]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp edx, srv.fd-SRV_FD_OFFSET
|
|
|
|
je .not_load
|
2007-01-18 03:06:00 +01:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall strncmp, edx, [sz_name], 16
|
|
|
|
test eax, eax
|
|
|
|
je .ok
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [edx+SRV.fd]
|
|
|
|
jmp @B
|
2006-10-06 08:09:41 +02:00
|
|
|
.not_load:
|
2007-11-15 20:43:35 +01:00
|
|
|
pop ebp
|
|
|
|
jmp load_driver
|
2006-10-06 08:09:41 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, edx
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2008-02-15 17:15:47 +01:00
|
|
|
proc reg_service stdcall, name:dword, handler:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-07-04 22:44:53 +02:00
|
|
|
push ebx
|
|
|
|
|
|
|
|
xor eax, eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp [name], eax
|
|
|
|
je .fail
|
2008-02-15 17:15:47 +01:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp [handler], eax
|
|
|
|
je .fail
|
2008-02-15 17:15:47 +01:00
|
|
|
|
2009-11-16 12:28:19 +01:00
|
|
|
mov eax, SRV.sizeof
|
|
|
|
call malloc
|
2006-10-06 08:09:41 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
push esi
|
|
|
|
push edi
|
2006-10-06 08:09:41 +02:00
|
|
|
mov edi, eax
|
2008-03-13 21:23:15 +01:00
|
|
|
mov esi, [name]
|
2009-11-16 12:28:19 +01:00
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
|
|
|
movsd
|
2008-03-13 21:23:15 +01:00
|
|
|
pop edi
|
|
|
|
pop esi
|
2007-11-15 20:43:35 +01:00
|
|
|
|
|
|
|
mov [eax+SRV.magic], ' SRV'
|
2009-11-16 12:28:19 +01:00
|
|
|
mov [eax+SRV.size], SRV.sizeof
|
2007-11-15 20:43:35 +01:00
|
|
|
|
|
|
|
mov ebx, srv.fd-SRV_FD_OFFSET
|
|
|
|
mov edx, [ebx+SRV.fd]
|
|
|
|
mov [eax+SRV.fd], edx
|
|
|
|
mov [eax+SRV.bk], ebx
|
|
|
|
mov [ebx+SRV.fd], eax
|
|
|
|
mov [edx+SRV.bk], eax
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
mov ecx, [handler]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [eax+SRV.srv_proc], ecx
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
2008-07-04 22:44:53 +02:00
|
|
|
pop ebx
|
2008-03-13 21:23:15 +01:00
|
|
|
ret
|
2008-02-15 17:15:47 +01:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_proc stdcall, exp:dword, sz_name:dword
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [exp]
|
2006-10-06 08:09:41 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx]
|
|
|
|
test eax, eax
|
|
|
|
jz .end
|
|
|
|
|
|
|
|
push edx
|
|
|
|
stdcall strncmp, eax, [sz_name], 16
|
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jz .ok
|
|
|
|
|
|
|
|
add edx,8
|
|
|
|
jmp .next
|
2006-10-06 08:09:41 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx+4]
|
2006-10-06 08:09:41 +02:00
|
|
|
.end:
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword
|
|
|
|
|
|
|
|
@@:
|
|
|
|
stdcall strncmp, [pSym], [sz_sym], 8
|
|
|
|
test eax,eax
|
|
|
|
jz .ok
|
|
|
|
add [pSym], 18
|
|
|
|
dec [count]
|
|
|
|
jnz @b
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
.ok:
|
2009-11-28 00:49:47 +01:00
|
|
|
mov eax, [pSym]
|
|
|
|
mov eax, [eax+8]
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2006-10-20 16:02:26 +02:00
|
|
|
proc get_curr_task
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax,[CURRENT_TASK]
|
|
|
|
shl eax, 8
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc get_fileinfo stdcall, file_name:dword, info:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
cmd dd ?
|
|
|
|
offset dd ?
|
|
|
|
dd ?
|
|
|
|
count dd ?
|
|
|
|
buff dd ?
|
|
|
|
db ?
|
|
|
|
name dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov ebx, [file_name]
|
|
|
|
mov ecx, [info]
|
|
|
|
|
|
|
|
mov [cmd], 5
|
|
|
|
mov [offset], eax
|
|
|
|
mov [offset+4], eax
|
|
|
|
mov [count], eax
|
|
|
|
mov [buff], ecx
|
|
|
|
mov byte [buff+4], al
|
|
|
|
mov [name], ebx
|
|
|
|
|
|
|
|
mov eax, 70
|
|
|
|
lea ebx, [cmd]
|
|
|
|
int 0x40
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc read_file stdcall,file_name:dword, buffer:dword, off:dword,\
|
2007-11-15 20:43:35 +01:00
|
|
|
bytes:dword
|
|
|
|
locals
|
|
|
|
cmd dd ?
|
|
|
|
offset dd ?
|
|
|
|
dd ?
|
|
|
|
count dd ?
|
|
|
|
buff dd ?
|
|
|
|
db ?
|
|
|
|
name dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov ebx, [file_name]
|
|
|
|
mov ecx, [off]
|
|
|
|
mov edx, [bytes]
|
|
|
|
mov esi, [buffer]
|
|
|
|
|
|
|
|
mov [cmd], eax
|
|
|
|
mov [offset], ecx
|
|
|
|
mov [offset+4], eax
|
|
|
|
mov [count], edx
|
|
|
|
mov [buff], esi
|
|
|
|
mov byte [buff+4], al
|
|
|
|
mov [name], ebx
|
|
|
|
|
|
|
|
pushad
|
2010-06-11 16:07:06 +02:00
|
|
|
lea ebx, [cmd]
|
2007-11-15 20:43:35 +01:00
|
|
|
call file_system_lfn
|
|
|
|
popad
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-02-19 09:22:55 +01:00
|
|
|
; description
|
|
|
|
; allocate kernel memory and loads the specified file
|
|
|
|
;
|
|
|
|
; param
|
|
|
|
; file_name= full path to file
|
|
|
|
;
|
|
|
|
; retval
|
|
|
|
; eax= file image in kernel memory
|
|
|
|
; ebx= size of file
|
|
|
|
;
|
|
|
|
; warging
|
|
|
|
; You mast call kernel_free() to delete each file
|
|
|
|
; loaded by the load_file() function
|
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc load_file stdcall, file_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
attr dd ?
|
|
|
|
flags dd ?
|
|
|
|
cr_time dd ?
|
|
|
|
cr_date dd ?
|
|
|
|
acc_time dd ?
|
|
|
|
acc_date dd ?
|
|
|
|
mod_time dd ?
|
|
|
|
mod_date dd ?
|
|
|
|
file_size dd ?
|
|
|
|
|
|
|
|
file dd ?
|
|
|
|
file2 dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
lea eax, [attr]
|
|
|
|
stdcall get_fileinfo, [file_name], eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .fail
|
|
|
|
|
|
|
|
mov eax, [file_size]
|
|
|
|
cmp eax, 1024*1024*16
|
|
|
|
ja .fail
|
|
|
|
|
|
|
|
stdcall kernel_alloc, [file_size]
|
|
|
|
mov [file], eax
|
2010-04-18 20:14:03 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2007-11-15 20:43:35 +01:00
|
|
|
|
|
|
|
stdcall read_file, [file_name], eax, dword 0, [file_size]
|
|
|
|
cmp ebx, [file_size]
|
|
|
|
jne .cleanup
|
|
|
|
|
|
|
|
mov eax, [file]
|
|
|
|
cmp dword [eax], 0x4B43504B
|
|
|
|
jne .exit
|
|
|
|
mov ebx, [eax+4]
|
|
|
|
mov [file_size], ebx
|
|
|
|
stdcall kernel_alloc, ebx
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
jz .cleanup
|
|
|
|
|
|
|
|
mov [file2], eax
|
2009-11-16 12:28:19 +01:00
|
|
|
pushfd
|
|
|
|
cli
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall unpack, [file], eax
|
2009-11-16 12:28:19 +01:00
|
|
|
popfd
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free, [file]
|
|
|
|
mov eax, [file2]
|
|
|
|
mov ebx, [file_size]
|
2006-11-16 06:47:31 +01:00
|
|
|
.exit:
|
2007-11-15 20:43:35 +01:00
|
|
|
push eax
|
|
|
|
lea edi, [eax+ebx] ;cleanup remain space
|
|
|
|
mov ecx, 4096 ;from file end
|
|
|
|
and ebx, 4095
|
|
|
|
jz @f
|
|
|
|
sub ecx, ebx
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosb
|
2007-05-24 13:27:05 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [file_size]
|
|
|
|
pop eax
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
.cleanup:
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free, [file]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc get_proc_ex stdcall, proc_name:dword, imports:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
.look_up:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [imports]
|
|
|
|
test edx, edx
|
|
|
|
jz .end
|
|
|
|
mov edx, [edx]
|
|
|
|
test edx, edx
|
|
|
|
jz .end
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx]
|
|
|
|
test eax, eax
|
|
|
|
jz .next_table
|
|
|
|
|
|
|
|
push edx
|
2008-11-10 07:18:02 +01:00
|
|
|
stdcall strncmp, eax, [proc_name], 256
|
2007-11-15 20:43:35 +01:00
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jz .ok
|
|
|
|
|
|
|
|
add edx,8
|
|
|
|
jmp .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.next_table:
|
2007-11-15 20:43:35 +01:00
|
|
|
add [imports], 4
|
|
|
|
jmp .look_up
|
2006-10-20 16:02:26 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx+4]
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
.end:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
2009-11-28 00:49:47 +01:00
|
|
|
proc fix_coff_symbols stdcall uses ebx esi, sec:dword, symbols:dword,\
|
2007-11-15 20:43:35 +01:00
|
|
|
sym_count:dword, strings:dword, imports:dword
|
|
|
|
locals
|
|
|
|
retval dd ?
|
|
|
|
endl
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edi, [symbols]
|
|
|
|
mov [retval], 1
|
2006-10-20 16:02:26 +02:00
|
|
|
.fix:
|
2007-11-15 20:43:35 +01:00
|
|
|
movzx ebx, [edi+CSYM.SectionNumber]
|
|
|
|
test ebx, ebx
|
|
|
|
jnz .internal
|
|
|
|
mov eax, dword [edi+CSYM.Name]
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
|
|
|
|
|
|
|
mov edi, [edi+4]
|
|
|
|
add edi, [strings]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
push edi
|
|
|
|
stdcall get_proc_ex, edi,[imports]
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
xor ebx, ebx
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
|
|
|
|
|
|
|
mov esi, msg_unresolved
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, edi
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
|
|
|
|
mov [retval],0
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edi, [symbols]
|
|
|
|
mov [edi+CSYM.Value], eax
|
|
|
|
jmp .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.internal:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp bx, -1
|
|
|
|
je .next
|
|
|
|
cmp bx, -2
|
|
|
|
je .next
|
|
|
|
|
|
|
|
dec ebx
|
|
|
|
shl ebx, 3
|
|
|
|
lea ebx, [ebx+ebx*4]
|
|
|
|
add ebx, [sec]
|
|
|
|
|
|
|
|
mov eax, [ebx+CFS.VirtualAddress]
|
|
|
|
add [edi+CSYM.Value], eax
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, CSYM_SIZE
|
|
|
|
mov [symbols], edi
|
|
|
|
dec [sym_count]
|
|
|
|
jnz .fix
|
|
|
|
mov eax, [retval]
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2009-11-28 00:49:47 +01:00
|
|
|
proc fix_coff_relocs stdcall uses ebx esi, coff:dword, sym:dword, \
|
|
|
|
delta:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
locals
|
2007-11-15 20:43:35 +01:00
|
|
|
n_sec dd ?
|
2006-10-06 08:09:41 +02:00
|
|
|
endl
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [coff]
|
|
|
|
movzx ebx, [eax+CFH.nSections]
|
|
|
|
mov [n_sec], ebx
|
2009-11-28 00:49:47 +01:00
|
|
|
lea esi, [eax+20]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fix_sec:
|
2006-10-06 08:09:41 +02:00
|
|
|
mov edi, [esi+CFS.PtrReloc]
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, [coff]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
movzx ecx, [esi+CFS.NumReloc]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .next
|
2009-11-28 00:49:47 +01:00
|
|
|
.reloc_loop:
|
2006-10-06 08:09:41 +02:00
|
|
|
mov ebx, [edi+CRELOC.SymIndex]
|
|
|
|
add ebx,ebx
|
|
|
|
lea ebx,[ebx+ebx*8]
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, [sym]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [ebx+CSYM.Value]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [edi+CRELOC.Type], 6
|
|
|
|
je .dir_32
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [edi+CRELOC.Type], 20
|
|
|
|
jne .next_reloc
|
2006-10-20 16:02:26 +02:00
|
|
|
.rel_32:
|
2006-10-06 08:09:41 +02:00
|
|
|
mov eax, [edi+CRELOC.VirtualAddress]
|
2007-11-15 20:43:35 +01:00
|
|
|
add eax, [esi+CFS.VirtualAddress]
|
|
|
|
sub edx, eax
|
|
|
|
sub edx, 4
|
|
|
|
jmp .fix
|
2006-10-20 16:02:26 +02:00
|
|
|
.dir_32:
|
|
|
|
mov eax, [edi+CRELOC.VirtualAddress]
|
2007-11-15 20:43:35 +01:00
|
|
|
add eax, [esi+CFS.VirtualAddress]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fix:
|
2009-11-28 00:49:47 +01:00
|
|
|
add eax, [delta]
|
2007-11-15 20:43:35 +01:00
|
|
|
add [eax], edx
|
2009-11-28 00:49:47 +01:00
|
|
|
.next_reloc:
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, 10
|
|
|
|
dec ecx
|
2009-11-28 00:49:47 +01:00
|
|
|
jnz .reloc_loop
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2009-11-28 00:49:47 +01:00
|
|
|
add esi, COFF_SECTION_SIZE
|
|
|
|
dec [n_sec]
|
|
|
|
jnz .fix_sec
|
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
proc rebase_coff stdcall uses ebx esi, coff:dword, sym:dword, \
|
|
|
|
delta:dword
|
|
|
|
locals
|
|
|
|
n_sec dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
mov eax, [coff]
|
|
|
|
movzx ebx, [eax+CFH.nSections]
|
|
|
|
mov [n_sec], ebx
|
|
|
|
lea esi, [eax+20]
|
|
|
|
mov edx, [delta]
|
|
|
|
.fix_sec:
|
|
|
|
mov edi, [esi+CFS.PtrReloc]
|
|
|
|
add edi, [coff]
|
|
|
|
|
|
|
|
movzx ecx, [esi+CFS.NumReloc]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .next
|
|
|
|
.reloc_loop:
|
|
|
|
cmp [edi+CRELOC.Type], 6
|
|
|
|
jne .next_reloc
|
|
|
|
.dir_32:
|
|
|
|
mov eax, [edi+CRELOC.VirtualAddress]
|
|
|
|
add eax, [esi+CFS.VirtualAddress]
|
|
|
|
add [eax+edx], edx
|
|
|
|
.next_reloc:
|
|
|
|
add edi, 10
|
|
|
|
dec ecx
|
|
|
|
jnz .reloc_loop
|
|
|
|
.next:
|
|
|
|
add esi, COFF_SECTION_SIZE
|
2007-11-15 20:43:35 +01:00
|
|
|
dec [n_sec]
|
|
|
|
jnz .fix_sec
|
2006-10-06 08:09:41 +02:00
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
2007-02-14 17:01:07 +01:00
|
|
|
proc load_driver stdcall, driver_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
coff dd ?
|
|
|
|
sym dd ?
|
|
|
|
strings dd ?
|
|
|
|
img_size dd ?
|
|
|
|
img_base dd ?
|
|
|
|
start dd ?
|
|
|
|
|
|
|
|
exports dd ? ;fake exports table
|
|
|
|
dd ?
|
|
|
|
file_name rb 13+16+4+1 ; '/sys/drivers/<up-to-16-chars>.obj'
|
|
|
|
endl
|
|
|
|
|
|
|
|
lea edx, [file_name]
|
|
|
|
mov dword [edx], '/sys'
|
|
|
|
mov dword [edx+4], '/dri'
|
|
|
|
mov dword [edx+8], 'vers'
|
|
|
|
mov byte [edx+12], '/'
|
|
|
|
mov esi, [driver_name]
|
2009-01-31 07:09:36 +01:00
|
|
|
.redo:
|
|
|
|
lea edx, [file_name]
|
2007-11-15 20:43:35 +01:00
|
|
|
lea edi, [edx+13]
|
|
|
|
mov ecx, 16
|
2007-02-14 17:01:07 +01:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz @f
|
|
|
|
stosb
|
|
|
|
loop @b
|
2007-02-14 17:01:07 +01:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov dword [edi], '.obj'
|
|
|
|
mov byte [edi+4], 0
|
|
|
|
stdcall load_file, edx
|
2006-11-20 08:06:00 +01:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [coff], eax
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
movzx ecx, [eax+CFH.nSections]
|
|
|
|
xor ebx, ebx
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
lea edx, [eax+20]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, [edx+CFS.SizeOfRawData]
|
|
|
|
add ebx, 15
|
|
|
|
and ebx, not 15
|
|
|
|
add edx, COFF_SECTION_SIZE
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
|
|
|
mov [img_size], ebx
|
|
|
|
|
|
|
|
stdcall kernel_alloc, ebx
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
mov [img_base], eax
|
|
|
|
|
|
|
|
mov edi, eax
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, [img_size]
|
|
|
|
add ecx, 4095
|
|
|
|
and ecx, not 4095
|
|
|
|
shr ecx, 2
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
mov edx, [coff]
|
|
|
|
movzx ebx, [edx+CFH.nSections]
|
|
|
|
mov edi, [img_base]
|
|
|
|
lea eax, [edx+20]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [eax+CFS.VirtualAddress], edi
|
|
|
|
mov esi, [eax+CFS.PtrRawData]
|
|
|
|
test esi, esi
|
|
|
|
jnz .copy
|
|
|
|
add edi, [eax+CFS.SizeOfRawData]
|
|
|
|
jmp .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.copy:
|
2007-11-15 20:43:35 +01:00
|
|
|
add esi, edx
|
|
|
|
mov ecx, [eax+CFS.SizeOfRawData]
|
|
|
|
cld
|
|
|
|
rep movsb
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, 15
|
|
|
|
and edi, not 15
|
|
|
|
add eax, COFF_SECTION_SIZE
|
|
|
|
dec ebx
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
mov ebx, [edx+CFH.pSymTable]
|
|
|
|
add ebx, edx
|
|
|
|
mov [sym], ebx
|
|
|
|
mov ecx, [edx+CFH.nSymbols]
|
|
|
|
add ecx,ecx
|
|
|
|
lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE
|
|
|
|
add ecx, [sym]
|
|
|
|
mov [strings], ecx
|
|
|
|
|
|
|
|
lea ebx, [exports]
|
|
|
|
mov dword [ebx], kernel_export
|
|
|
|
mov dword [ebx+4], 0
|
|
|
|
lea eax, [edx+20]
|
|
|
|
|
|
|
|
stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\
|
|
|
|
[strings], ebx
|
|
|
|
test eax, eax
|
|
|
|
jz .link_fail
|
|
|
|
|
|
|
|
mov ebx, [coff]
|
2009-11-28 00:49:47 +01:00
|
|
|
stdcall fix_coff_relocs, ebx, [sym], 0
|
2007-11-15 20:43:35 +01:00
|
|
|
|
|
|
|
stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szVersion
|
|
|
|
test eax, eax
|
|
|
|
jz .link_fail
|
|
|
|
|
|
|
|
mov eax, [eax]
|
|
|
|
shr eax, 16
|
|
|
|
cmp eax, DRV_COMPAT
|
|
|
|
jb .ver_fail
|
|
|
|
|
|
|
|
cmp eax, DRV_CURRENT
|
|
|
|
ja .ver_fail
|
|
|
|
|
|
|
|
mov ebx, [coff]
|
|
|
|
stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szSTART
|
|
|
|
mov [start], eax
|
|
|
|
|
|
|
|
stdcall kernel_free, [coff]
|
|
|
|
|
|
|
|
mov ebx, [start]
|
|
|
|
stdcall ebx, DRV_ENTRY
|
|
|
|
test eax, eax
|
|
|
|
jnz .ok
|
|
|
|
|
|
|
|
stdcall kernel_free, [img_base]
|
2009-01-31 07:09:36 +01:00
|
|
|
cmp dword [file_name+13], 'SOUN'
|
|
|
|
jnz @f
|
|
|
|
cmp dword [file_name+17], 'D.ob'
|
|
|
|
jnz @f
|
|
|
|
cmp word [file_name+21], 'j'
|
|
|
|
jnz @f
|
|
|
|
mov esi, aSis
|
|
|
|
jmp .redo
|
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [img_base]
|
|
|
|
mov [eax+SRV.base], ebx
|
|
|
|
mov ecx, [start]
|
|
|
|
mov [eax+SRV.entry], ecx
|
|
|
|
ret
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
|
|
.ver_fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, [driver_name]
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_version
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_www
|
|
|
|
call sys_msg_board_str
|
|
|
|
jmp .cleanup
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
|
|
.link_fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, msg_module
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, [driver_name]
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
2006-12-02 09:18:48 +01:00
|
|
|
.cleanup:
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free,[img_base]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free, [coff]
|
2006-12-02 09:18:48 +01:00
|
|
|
.exit:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
2009-11-28 17:13:10 +01:00
|
|
|
; in: edx -> COFF_SECTION struct
|
|
|
|
; out: eax = alignment as mask for bits to drop
|
|
|
|
coff_get_align:
|
|
|
|
; Rules:
|
|
|
|
; - if alignment is not given, use default = 4K;
|
|
|
|
; - if alignment is given and is no more than 4K, use it;
|
|
|
|
; - if alignment is more than 4K, revert to 4K.
|
|
|
|
push ecx
|
|
|
|
mov cl, byte [edx+CFS.Characteristics+2]
|
|
|
|
mov eax, 1
|
|
|
|
shr cl, 4
|
|
|
|
dec cl
|
|
|
|
js .default
|
|
|
|
cmp cl, 12
|
|
|
|
jbe @f
|
|
|
|
.default:
|
|
|
|
mov cl, 12
|
|
|
|
@@:
|
|
|
|
shl eax, cl
|
|
|
|
pop ecx
|
|
|
|
dec eax
|
|
|
|
ret
|
|
|
|
|
2006-10-27 17:08:19 +02:00
|
|
|
align 4
|
|
|
|
proc load_library stdcall, file_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
2009-11-28 00:49:47 +01:00
|
|
|
fullname rb 260
|
|
|
|
fileinfo rb 40
|
2007-11-15 20:43:35 +01:00
|
|
|
coff dd ?
|
|
|
|
img_base dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
cli
|
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; resolve file name
|
|
|
|
mov ebx, [file_name]
|
|
|
|
lea edi, [fullname+1]
|
|
|
|
mov byte [edi-1], '/'
|
|
|
|
stdcall get_full_file_name, edi, 259
|
|
|
|
test al, al
|
2007-11-15 20:43:35 +01:00
|
|
|
jz .fail
|
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; scan for required DLL in list of already loaded for this process,
|
|
|
|
; ignore timestamp
|
|
|
|
mov esi, [CURRENT_TASK]
|
|
|
|
shl esi, 8
|
|
|
|
lea edi, [fullname]
|
2009-12-09 00:36:12 +01:00
|
|
|
mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .not_in_process
|
|
|
|
mov esi, [ebx+HDLL.fd]
|
2009-11-28 00:49:47 +01:00
|
|
|
.scan_in_process:
|
|
|
|
cmp esi, ebx
|
|
|
|
jz .not_in_process
|
|
|
|
mov eax, [esi+HDLL.parent]
|
|
|
|
add eax, DLLDESCR.name
|
|
|
|
stdcall strncmp, eax, edi, -1
|
|
|
|
test eax, eax
|
|
|
|
jnz .next_in_process
|
|
|
|
; simple variant: load DLL which is already loaded in this process
|
|
|
|
; just increment reference counters and return address of exports table
|
|
|
|
inc [esi+HDLL.refcount]
|
|
|
|
mov ecx, [esi+HDLL.parent]
|
|
|
|
inc [ecx+DLLDESCR.refcount]
|
|
|
|
mov eax, [ecx+DLLDESCR.exports]
|
|
|
|
sub eax, [ecx+DLLDESCR.defaultbase]
|
|
|
|
add eax, [esi+HDLL.base]
|
|
|
|
ret
|
|
|
|
.next_in_process:
|
2009-12-09 00:36:12 +01:00
|
|
|
mov esi, [esi+HDLL.fd]
|
2009-11-28 00:49:47 +01:00
|
|
|
jmp .scan_in_process
|
|
|
|
.not_in_process:
|
|
|
|
|
|
|
|
; scan in full list, compare timestamp
|
|
|
|
lea eax, [fileinfo]
|
|
|
|
stdcall get_fileinfo, edi, eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .fail
|
|
|
|
mov esi, [dll_list.fd]
|
|
|
|
.scan_for_dlls:
|
|
|
|
cmp esi, dll_list
|
|
|
|
jz .load_new
|
|
|
|
lea eax, [esi+DLLDESCR.name]
|
|
|
|
stdcall strncmp, eax, edi, -1
|
|
|
|
test eax, eax
|
|
|
|
jnz .continue_scan
|
|
|
|
.test_prev_dll:
|
|
|
|
mov eax, dword [fileinfo+24] ; last modified time
|
|
|
|
mov edx, dword [fileinfo+28] ; last modified date
|
|
|
|
cmp dword [esi+DLLDESCR.timestamp], eax
|
|
|
|
jnz .continue_scan
|
|
|
|
cmp dword [esi+DLLDESCR.timestamp+4], edx
|
|
|
|
jz .dll_already_loaded
|
|
|
|
.continue_scan:
|
|
|
|
mov esi, [esi+DLLDESCR.fd]
|
|
|
|
jmp .scan_for_dlls
|
|
|
|
|
|
|
|
; new DLL
|
|
|
|
.load_new:
|
|
|
|
; load file
|
|
|
|
stdcall load_file, edi
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [coff], eax
|
2009-11-28 00:49:47 +01:00
|
|
|
mov dword [fileinfo+32], ebx
|
|
|
|
|
|
|
|
; allocate DLLDESCR struct; size is DLLDESCR.sizeof plus size of DLL name
|
|
|
|
mov esi, edi
|
|
|
|
mov ecx, -1
|
|
|
|
xor eax, eax
|
|
|
|
repnz scasb
|
|
|
|
not ecx
|
|
|
|
lea eax, [ecx+DLLDESCR.sizeof]
|
|
|
|
push ecx
|
|
|
|
call malloc
|
|
|
|
pop ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .fail_and_free_coff
|
|
|
|
; save timestamp
|
|
|
|
lea edi, [eax+DLLDESCR.name]
|
|
|
|
rep movsb
|
|
|
|
mov esi, eax
|
|
|
|
mov eax, dword [fileinfo+24]
|
|
|
|
mov dword [esi+DLLDESCR.timestamp], eax
|
|
|
|
mov eax, dword [fileinfo+28]
|
|
|
|
mov dword [esi+DLLDESCR.timestamp+4], eax
|
|
|
|
; initialize DLLDESCR struct
|
|
|
|
and dword [esi+DLLDESCR.refcount], 0 ; no HDLLs yet; later it will be incremented
|
|
|
|
mov [esi+DLLDESCR.fd], dll_list
|
|
|
|
mov eax, [dll_list.bk]
|
|
|
|
mov [dll_list.bk], esi
|
|
|
|
mov [esi+DLLDESCR.bk], eax
|
|
|
|
mov [eax+DLLDESCR.fd], esi
|
|
|
|
|
|
|
|
; calculate size of loaded DLL
|
|
|
|
mov edx, [coff]
|
|
|
|
movzx ecx, [edx+CFH.nSections]
|
2007-11-15 20:43:35 +01:00
|
|
|
xor ebx, ebx
|
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
add edx, 20
|
2006-10-27 17:08:19 +02:00
|
|
|
@@:
|
2009-11-28 17:13:10 +01:00
|
|
|
call coff_get_align
|
|
|
|
add ebx, eax
|
|
|
|
not eax
|
|
|
|
and ebx, eax
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, [edx+CFS.SizeOfRawData]
|
|
|
|
add edx, COFF_SECTION_SIZE
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
2009-11-28 00:49:47 +01:00
|
|
|
; it must be nonzero and not too big
|
|
|
|
mov [esi+DLLDESCR.size], ebx
|
|
|
|
test ebx, ebx
|
|
|
|
jz .fail_and_free_dll
|
|
|
|
cmp ebx, MAX_DEFAULT_DLL_ADDR-MIN_DEFAULT_DLL_ADDR
|
|
|
|
ja .fail_and_free_dll
|
|
|
|
; allocate memory for kernel-side image
|
|
|
|
stdcall kernel_alloc, ebx
|
2007-11-15 20:43:35 +01:00
|
|
|
test eax, eax
|
2009-11-28 00:49:47 +01:00
|
|
|
jz .fail_and_free_dll
|
|
|
|
mov [esi+DLLDESCR.data], eax
|
|
|
|
; calculate preferred base address
|
|
|
|
add ebx, 0x1FFF
|
|
|
|
and ebx, not 0xFFF
|
|
|
|
mov ecx, [dll_cur_addr]
|
|
|
|
lea edx, [ecx+ebx]
|
|
|
|
cmp edx, MAX_DEFAULT_DLL_ADDR
|
|
|
|
jb @f
|
|
|
|
mov ecx, MIN_DEFAULT_DLL_ADDR
|
|
|
|
lea edx, [ecx+ebx]
|
|
|
|
@@:
|
|
|
|
mov [esi+DLLDESCR.defaultbase], ecx
|
|
|
|
mov [dll_cur_addr], edx
|
2007-11-15 20:43:35 +01:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; copy sections and set correct values for VirtualAddress'es in headers
|
|
|
|
push esi
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [coff]
|
|
|
|
movzx ebx, [edx+CFH.nSections]
|
2009-11-28 00:49:47 +01:00
|
|
|
mov edi, eax
|
|
|
|
add edx, 20
|
|
|
|
cld
|
2006-10-27 17:08:19 +02:00
|
|
|
@@:
|
2009-11-28 17:13:10 +01:00
|
|
|
call coff_get_align
|
|
|
|
add ecx, eax
|
|
|
|
add edi, eax
|
|
|
|
not eax
|
|
|
|
and ecx, eax
|
|
|
|
and edi, eax
|
2009-11-28 00:49:47 +01:00
|
|
|
mov [edx+CFS.VirtualAddress], ecx
|
|
|
|
add ecx, [edx+CFS.SizeOfRawData]
|
|
|
|
mov esi, [edx+CFS.PtrRawData]
|
|
|
|
push ecx
|
|
|
|
mov ecx, [edx+CFS.SizeOfRawData]
|
2007-11-15 20:43:35 +01:00
|
|
|
test esi, esi
|
|
|
|
jnz .copy
|
2009-11-28 17:13:10 +01:00
|
|
|
xor eax, eax
|
2009-11-28 00:49:47 +01:00
|
|
|
rep stosb
|
2007-11-15 20:43:35 +01:00
|
|
|
jmp .next
|
2006-10-27 17:08:19 +02:00
|
|
|
.copy:
|
2009-11-28 00:49:47 +01:00
|
|
|
add esi, [coff]
|
2007-11-15 20:43:35 +01:00
|
|
|
rep movsb
|
2006-10-27 17:08:19 +02:00
|
|
|
.next:
|
2009-11-28 00:49:47 +01:00
|
|
|
pop ecx
|
|
|
|
add edx, COFF_SECTION_SIZE
|
2007-11-15 20:43:35 +01:00
|
|
|
dec ebx
|
|
|
|
jnz @B
|
2009-11-28 00:49:47 +01:00
|
|
|
pop esi
|
2007-11-15 20:43:35 +01:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; save some additional data from COFF file
|
|
|
|
; later we will use COFF header, headers for sections and symbol table
|
|
|
|
; and also relocations table for all sections
|
|
|
|
mov edx, [coff]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [edx+CFH.pSymTable]
|
2009-11-28 00:49:47 +01:00
|
|
|
mov edi, dword [fileinfo+32]
|
|
|
|
sub edi, ebx
|
|
|
|
jc .fail_and_free_data
|
|
|
|
mov [esi+DLLDESCR.symbols_lim], edi
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, edx
|
2009-11-28 00:49:47 +01:00
|
|
|
movzx ecx, [edx+CFH.nSections]
|
|
|
|
lea ecx, [ecx*5]
|
|
|
|
lea edi, [edi+ecx*8+20]
|
|
|
|
add edx, 20
|
|
|
|
@@:
|
|
|
|
movzx eax, [edx+CFS.NumReloc]
|
|
|
|
lea eax, [eax*5]
|
|
|
|
lea edi, [edi+eax*2]
|
|
|
|
add edx, COFF_SECTION_SIZE
|
|
|
|
sub ecx, 5
|
|
|
|
jnz @b
|
|
|
|
stdcall kernel_alloc, edi
|
|
|
|
test eax, eax
|
|
|
|
jz .fail_and_free_data
|
|
|
|
mov edx, [coff]
|
|
|
|
movzx ecx, [edx+CFH.nSections]
|
|
|
|
lea ecx, [ecx*5]
|
|
|
|
lea ecx, [ecx*2+5]
|
|
|
|
mov [esi+DLLDESCR.coff_hdr], eax
|
|
|
|
push esi
|
|
|
|
mov esi, edx
|
|
|
|
mov edi, eax
|
|
|
|
rep movsd
|
|
|
|
pop esi
|
|
|
|
mov [esi+DLLDESCR.symbols_ptr], edi
|
|
|
|
push esi
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, [edx+CFH.nSymbols]
|
2009-11-28 00:49:47 +01:00
|
|
|
mov [esi+DLLDESCR.symbols_num], ecx
|
|
|
|
mov ecx, [esi+DLLDESCR.symbols_lim]
|
|
|
|
mov esi, ebx
|
|
|
|
rep movsb
|
|
|
|
pop esi
|
|
|
|
mov ebx, [esi+DLLDESCR.coff_hdr]
|
|
|
|
push esi
|
|
|
|
movzx eax, [edx+CFH.nSections]
|
|
|
|
lea edx, [ebx+20]
|
|
|
|
@@:
|
|
|
|
movzx ecx, [edx+CFS.NumReloc]
|
|
|
|
lea ecx, [ecx*5]
|
|
|
|
mov esi, [edx+CFS.PtrReloc]
|
|
|
|
mov [edx+CFS.PtrReloc], edi
|
|
|
|
sub [edx+CFS.PtrReloc], ebx
|
|
|
|
add esi, [coff]
|
|
|
|
shr ecx, 1
|
|
|
|
rep movsd
|
|
|
|
adc ecx, ecx
|
|
|
|
rep movsw
|
|
|
|
add edx, COFF_SECTION_SIZE
|
|
|
|
dec eax
|
|
|
|
jnz @b
|
|
|
|
pop esi
|
2007-11-15 20:43:35 +01:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; fixup symbols
|
|
|
|
mov edx, ebx
|
|
|
|
mov eax, [ebx+CFH.nSymbols]
|
|
|
|
add edx, 20
|
|
|
|
mov ecx, [esi+DLLDESCR.symbols_num]
|
|
|
|
lea ecx, [ecx*9]
|
|
|
|
add ecx, ecx
|
|
|
|
add ecx, [esi+DLLDESCR.symbols_ptr]
|
|
|
|
|
|
|
|
stdcall fix_coff_symbols, edx, [esi+DLLDESCR.symbols_ptr], eax,\
|
|
|
|
ecx, 0
|
|
|
|
; test eax, eax
|
|
|
|
; jnz @F
|
|
|
|
;
|
|
|
|
;@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
stdcall get_coff_sym,[esi+DLLDESCR.symbols_ptr],[ebx+CFH.nSymbols],szEXPORTS
|
2007-11-15 20:43:35 +01:00
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
stdcall get_coff_sym,[esi+DLLDESCR.symbols_ptr],[ebx+CFH.nSymbols],sz_EXPORTS
|
2006-10-27 17:08:19 +02:00
|
|
|
@@:
|
2009-11-28 00:49:47 +01:00
|
|
|
mov [esi+DLLDESCR.exports], eax
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; fix relocs in the hidden copy in kernel memory to default address
|
|
|
|
; it is first fix; usually this will be enough, but second fix
|
|
|
|
; can be necessary if real load address will not equal assumption
|
|
|
|
mov eax, [esi+DLLDESCR.data]
|
|
|
|
sub eax, [esi+DLLDESCR.defaultbase]
|
|
|
|
stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
stdcall kernel_free, [coff]
|
|
|
|
|
|
|
|
.dll_already_loaded:
|
|
|
|
inc [esi+DLLDESCR.refcount]
|
|
|
|
push esi
|
|
|
|
call init_heap
|
|
|
|
pop esi
|
2008-11-10 07:18:02 +01:00
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
mov edi, [esi+DLLDESCR.size]
|
|
|
|
stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi
|
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
stdcall user_alloc, edi
|
|
|
|
test eax, eax
|
|
|
|
jz .fail_and_dereference
|
2008-11-10 21:37:53 +01:00
|
|
|
@@:
|
2009-11-28 00:49:47 +01:00
|
|
|
mov [img_base], eax
|
2009-12-09 00:36:12 +01:00
|
|
|
mov eax, HDLL.sizeof
|
|
|
|
call malloc
|
|
|
|
test eax, eax
|
|
|
|
jz .fail_and_free_user
|
2009-11-28 00:49:47 +01:00
|
|
|
mov ebx, [CURRENT_TASK]
|
|
|
|
shl ebx, 5
|
2009-12-09 00:36:12 +01:00
|
|
|
mov edx, [CURRENT_TASK+ebx+TASKDATA.pid]
|
|
|
|
mov [eax+HDLL.pid], edx
|
|
|
|
push eax
|
|
|
|
call init_dlls_in_thread
|
|
|
|
pop ebx
|
2009-11-28 00:49:47 +01:00
|
|
|
test eax, eax
|
2009-12-09 00:36:12 +01:00
|
|
|
jz .fail_and_free_user
|
|
|
|
mov edx, [eax+HDLL.fd]
|
|
|
|
mov [ebx+HDLL.fd], edx
|
|
|
|
mov [ebx+HDLL.bk], eax
|
|
|
|
mov [eax+HDLL.fd], ebx
|
|
|
|
mov [edx+HDLL.bk], ebx
|
|
|
|
mov eax, ebx
|
2009-11-28 00:49:47 +01:00
|
|
|
mov ebx, [img_base]
|
|
|
|
mov [eax+HDLL.base], ebx
|
|
|
|
mov [eax+HDLL.size], edi
|
|
|
|
mov [eax+HDLL.refcount], 1
|
|
|
|
mov [eax+HDLL.parent], esi
|
|
|
|
mov edx, ebx
|
|
|
|
shr edx, 12
|
|
|
|
or dword [page_tabs+(edx-1)*4], DONT_FREE_BLOCK
|
|
|
|
; copy entries of page table from kernel-side image to usermode
|
|
|
|
; use copy-on-write for user-mode image, so map as readonly
|
|
|
|
xor edi, edi
|
|
|
|
mov ecx, [esi+DLLDESCR.data]
|
|
|
|
shr ecx, 12
|
|
|
|
.map_pages_loop:
|
|
|
|
mov eax, [page_tabs+ecx*4]
|
|
|
|
and eax, not 0xFFF
|
|
|
|
or al, PG_USER
|
|
|
|
xchg eax, [page_tabs+edx*4]
|
|
|
|
test al, 1
|
|
|
|
jz @f
|
|
|
|
call free_page
|
|
|
|
@@:
|
|
|
|
invlpg [ebx+edi]
|
|
|
|
inc ecx
|
|
|
|
inc edx
|
|
|
|
add edi, 0x1000
|
|
|
|
cmp edi, [esi+DLLDESCR.size]
|
|
|
|
jb .map_pages_loop
|
|
|
|
|
|
|
|
; if real user-mode base is not equal to preferred base, relocate image
|
|
|
|
sub ebx, [esi+DLLDESCR.defaultbase]
|
|
|
|
jz @f
|
|
|
|
stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx
|
|
|
|
@@:
|
|
|
|
|
|
|
|
mov eax, [esi+DLLDESCR.exports]
|
|
|
|
sub eax, [esi+DLLDESCR.defaultbase]
|
|
|
|
add eax, [img_base]
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2009-11-28 00:49:47 +01:00
|
|
|
.fail_and_free_data:
|
|
|
|
stdcall kernel_free, [esi+DLLDESCR.data]
|
|
|
|
.fail_and_free_dll:
|
|
|
|
mov eax, esi
|
|
|
|
call free
|
|
|
|
.fail_and_free_coff:
|
|
|
|
stdcall kernel_free, [coff]
|
2006-10-27 17:08:19 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2009-11-28 00:49:47 +01:00
|
|
|
.fail_and_free_user:
|
|
|
|
stdcall user_free, [img_base]
|
|
|
|
.fail_and_dereference:
|
|
|
|
mov eax, 1 ; delete 1 reference
|
|
|
|
call dereference_dll
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-27 17:08:19 +02:00
|
|
|
endp
|
|
|
|
|
2009-12-09 00:36:12 +01:00
|
|
|
; initialize [APPDATA.dlls_list_ptr] for given thread
|
|
|
|
; DLL is per-process object, so APPDATA.dlls_list_ptr must be
|
|
|
|
; kept in sync for all threads of one process.
|
|
|
|
; out: eax = APPDATA.dlls_list_ptr if all is OK,
|
|
|
|
; NULL if memory allocation failed
|
|
|
|
init_dlls_in_thread:
|
|
|
|
mov ebx, [current_slot]
|
|
|
|
mov eax, [ebx+APPDATA.dlls_list_ptr]
|
|
|
|
test eax, eax
|
|
|
|
jnz .ret
|
|
|
|
push [ebx+APPDATA.dir_table]
|
|
|
|
mov eax, 8
|
|
|
|
call malloc
|
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jz .ret
|
|
|
|
mov [eax], eax
|
|
|
|
mov [eax+4], eax
|
|
|
|
mov ecx, [TASK_COUNT]
|
|
|
|
mov ebx, SLOT_BASE+256
|
|
|
|
.set:
|
|
|
|
cmp [ebx+APPDATA.dir_table], edx
|
|
|
|
jnz @f
|
|
|
|
mov [ebx+APPDATA.dlls_list_ptr], eax
|
|
|
|
@@:
|
|
|
|
add ebx, 256
|
|
|
|
dec ecx
|
|
|
|
jnz .set
|
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
|
2009-11-28 00:49:47 +01:00
|
|
|
; in: eax = number of references to delete, esi -> DLLDESCR struc
|
|
|
|
dereference_dll:
|
|
|
|
sub [esi+DLLDESCR.refcount], eax
|
|
|
|
jnz .ret
|
|
|
|
mov eax, [esi+DLLDESCR.fd]
|
|
|
|
mov edx, [esi+DLLDESCR.bk]
|
|
|
|
mov [eax+DLLDESCR.bk], edx
|
|
|
|
mov [edx+DLLDESCR.fd], eax
|
2009-11-28 12:46:46 +01:00
|
|
|
stdcall kernel_free, [esi+DLLDESCR.coff_hdr]
|
2009-11-28 00:49:47 +01:00
|
|
|
stdcall kernel_free, [esi+DLLDESCR.data]
|
|
|
|
mov eax, esi
|
|
|
|
call free
|
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
|
|
|
|
destroy_hdll:
|
2009-12-09 00:36:12 +01:00
|
|
|
push ebx ecx esi edi
|
2009-11-28 00:49:47 +01:00
|
|
|
push eax
|
|
|
|
mov ebx, [eax+HDLL.base]
|
|
|
|
mov esi, [eax+HDLL.parent]
|
|
|
|
mov edx, [esi+DLLDESCR.size]
|
2009-11-28 12:46:46 +01:00
|
|
|
; 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.
|
2009-12-09 00:36:12 +01:00
|
|
|
mov eax, [ecx+APPDATA.dir_table]
|
2009-11-28 12:46:46 +01:00
|
|
|
; 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]
|
2009-12-09 00:36:12 +01:00
|
|
|
mov [current_slot], ecx
|
|
|
|
mov ecx, cr3
|
|
|
|
push ecx
|
|
|
|
mov cr3, eax
|
2009-11-28 12:46:46 +01:00
|
|
|
push ebx ; argument for user_free
|
2009-11-28 00:49:47 +01:00
|
|
|
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]
|
2009-11-28 12:46:46 +01:00
|
|
|
mov ecx, [page_tabs+esi*4]
|
|
|
|
and eax, not 0xFFF
|
|
|
|
and ecx, not 0xFFF
|
|
|
|
cmp eax, ecx
|
|
|
|
jz @f
|
2009-11-28 00:49:47 +01:00
|
|
|
call free_page
|
|
|
|
@@:
|
|
|
|
pop eax
|
|
|
|
invlpg [eax]
|
|
|
|
add eax, 0x1000
|
|
|
|
inc ebx
|
|
|
|
inc esi
|
|
|
|
sub edx, 0x1000
|
|
|
|
ja .unmap_loop
|
2009-11-28 12:46:46 +01:00
|
|
|
pop ebx
|
2009-11-28 00:49:47 +01:00
|
|
|
and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK
|
2009-11-28 12:46:46 +01:00
|
|
|
call user_free
|
|
|
|
; Restore context.
|
|
|
|
pop eax
|
|
|
|
mov cr3, eax
|
|
|
|
pop [current_slot]
|
|
|
|
popf
|
|
|
|
; Ok, cheating is done.
|
|
|
|
pop eax
|
|
|
|
push eax
|
2009-11-28 00:49:47 +01:00
|
|
|
mov esi, [eax+HDLL.parent]
|
|
|
|
mov eax, [eax+HDLL.refcount]
|
|
|
|
call dereference_dll
|
|
|
|
pop eax
|
2009-12-09 00:36:12 +01:00
|
|
|
mov edx, [eax+HDLL.bk]
|
|
|
|
mov ebx, [eax+HDLL.fd]
|
|
|
|
mov [ebx+HDLL.bk], edx
|
|
|
|
mov [edx+HDLL.fd], ebx
|
|
|
|
call free
|
|
|
|
pop edi esi ecx ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
; ecx -> APPDATA for slot, esi = dlls_list_ptr
|
|
|
|
destroy_all_hdlls:
|
|
|
|
test esi, esi
|
|
|
|
jz .ret
|
|
|
|
.loop:
|
|
|
|
mov eax, [esi+HDLL.fd]
|
|
|
|
cmp eax, esi
|
|
|
|
jz free
|
|
|
|
call destroy_hdll
|
|
|
|
jmp .loop
|
|
|
|
.ret:
|
2009-11-28 00:49:47 +01:00
|
|
|
ret
|
|
|
|
|
2006-11-20 08:06:00 +01:00
|
|
|
align 4
|
2009-11-16 12:28:19 +01:00
|
|
|
stop_all_services:
|
|
|
|
push ebp
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [srv.fd]
|
2006-11-20 08:06:00 +01:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp edx, srv.fd-SRV_FD_OFFSET
|
|
|
|
je .done
|
|
|
|
cmp [edx+SRV.magic], ' SRV'
|
|
|
|
jne .next
|
2009-11-16 12:28:19 +01:00
|
|
|
cmp [edx+SRV.size], SRV.sizeof
|
2007-11-15 20:43:35 +01:00
|
|
|
jne .next
|
2008-02-11 13:24:57 +01:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
mov ebx, [edx+SRV.entry]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [edx+SRV.fd]
|
2008-03-13 21:23:15 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .next
|
2008-02-11 13:24:57 +01:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
push edx
|
2009-12-13 01:16:34 +01:00
|
|
|
mov ebp, esp
|
|
|
|
push 0
|
|
|
|
push -1
|
|
|
|
call ebx
|
|
|
|
mov esp, ebp
|
2007-11-15 20:43:35 +01:00
|
|
|
pop edx
|
|
|
|
jmp .next
|
2007-01-18 03:06:00 +01:00
|
|
|
.done:
|
2009-11-16 12:28:19 +01:00
|
|
|
pop ebp
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2006-11-20 08:06:00 +01:00
|
|
|
|
2007-01-19 04:58:46 +01:00
|
|
|
; param
|
2007-01-23 15:55:03 +01:00
|
|
|
; eax= size
|
|
|
|
; ebx= pid
|
2007-01-19 04:58:46 +01:00
|
|
|
|
|
|
|
align 4
|
|
|
|
create_kernel_object:
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
push ebx
|
|
|
|
call malloc
|
|
|
|
pop ebx
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
mov ecx,[current_slot]
|
|
|
|
add ecx, APP_OBJ_OFFSET
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov edx, [ecx+APPOBJ.fd]
|
|
|
|
mov [eax+APPOBJ.fd], edx
|
|
|
|
mov [eax+APPOBJ.bk], ecx
|
|
|
|
mov [eax+APPOBJ.pid], ebx
|
|
|
|
|
|
|
|
mov [ecx+APPOBJ.fd], eax
|
|
|
|
mov [edx+APPOBJ.bk], eax
|
|
|
|
popfd
|
2007-01-19 04:58:46 +01:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2007-01-19 04:58:46 +01:00
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= object
|
|
|
|
|
|
|
|
align 4
|
|
|
|
destroy_kernel_object:
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov ebx, [eax+APPOBJ.fd]
|
|
|
|
mov ecx, [eax+APPOBJ.bk]
|
|
|
|
mov [ebx+APPOBJ.bk], ecx
|
|
|
|
mov [ecx+APPOBJ.fd], ebx
|
|
|
|
popfd
|
|
|
|
|
|
|
|
xor edx, edx ;clear common header
|
|
|
|
mov [eax], edx
|
|
|
|
mov [eax+4], edx
|
|
|
|
mov [eax+8], edx
|
|
|
|
mov [eax+12], edx
|
|
|
|
mov [eax+16], edx
|
|
|
|
|
|
|
|
call free ;release object memory
|
|
|
|
ret
|
2007-01-19 04:58:46 +01:00
|
|
|
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
if 0
|
|
|
|
|
|
|
|
irq:
|
|
|
|
|
|
|
|
.irq0:
|
2007-11-15 20:43:35 +01:00
|
|
|
pusfd
|
|
|
|
pushad
|
|
|
|
push IRQ_0
|
|
|
|
jmp .master
|
2007-04-18 08:37:14 +02:00
|
|
|
.irq_1:
|
2007-11-15 20:43:35 +01:00
|
|
|
pusfd
|
|
|
|
pushad
|
|
|
|
push IRQ_1
|
|
|
|
jmp .master
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
.master:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ax, app_data
|
|
|
|
mov ds, eax
|
|
|
|
mov es, eax
|
|
|
|
mov ebx, [esp+4] ;IRQ_xx
|
|
|
|
mov eax, [irq_handlers+ebx+4]
|
|
|
|
call intr_handler
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
cmp [irq_actids+ecx*4], 0
|
|
|
|
je @F
|
|
|
|
in al, 0x21
|
|
|
|
bts eax, ecx
|
|
|
|
out 0x21, al
|
|
|
|
mov al, 0x20
|
|
|
|
out 0x20, al
|
|
|
|
jmp .restart
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
.slave:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ax, app_data
|
|
|
|
mov ds, eax
|
|
|
|
mov es, eax
|
|
|
|
mov ebx, [esp+4] ;IRQ_xx
|
|
|
|
mov eax, [irq_handlers+ebx+4]
|
|
|
|
call intr_handler
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
sub ecx, 8
|
|
|
|
cmp [irq_actids+ecx*4], 0
|
|
|
|
je @F
|
|
|
|
in al, 0xA1
|
|
|
|
bts eax, ecx
|
|
|
|
out 0xA1, al
|
|
|
|
mov al, 0x20
|
|
|
|
out 0xA0, al
|
|
|
|
out 0x20, al
|
2007-04-18 08:37:14 +02:00
|
|
|
.restart:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [next_slot]
|
|
|
|
test ebx, ebx
|
|
|
|
jz @F
|
|
|
|
mov [next_task],0
|
|
|
|
mov esi, [prev_slot]
|
|
|
|
call do_change_task
|
|
|
|
add esp, 4
|
|
|
|
iretd
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
|