Subversion Repositories Kolibri OS

Rev

Rev 8710 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8672 Coldy 1
;
2
;  KolibriOS Dll load support
3
;
4
;  (C) 2020-2021 Coldy
5
;  Thank's you for use this code and software based on it!
6
;  I will glad if it's will be helpful.
7
;
8
;  Distributed under terms of GPL
9
;
10
format MS COFF
11
public @EXPORT as 'EXPORTS'
12
 
8710 Coldy 13
include '../../../proc32.inc'
14
include '../../../macros.inc'
8672 Coldy 15
 
16
section '.flat' code readable align 16
17
 
8709 Coldy 18
app_version       equ word[8]
8672 Coldy 19
i_table_min_size  =   1
20
 
8709 Coldy 21
sizeof.kx_header  =   8
22
 
23
APP_STARTUP_THUNK:
8672 Coldy 24
    ; First make shure that app
25
    ; have header version 2.0 or more
26
    cmp app_version,2
8709 Coldy 27
    jl .denied            ; App with app_version < 2 shouldn't be here
8672 Coldy 28
 
29
    ; Then make shure that we first
30
    mov eax, @EXPORT
31
    cmp dword[eax-4],0
32
    je .denied
33
 
34
    ; Don't allow second time
8709 Coldy 35
    mov dword[eax-4],0
8672 Coldy 36
 
37
   ; Early app initialization
8709 Coldy 38
 
39
;{ Test KX header
40
   ;xor  eax, eax
41
   mov	esi,0x24
42
   lodsw
43
   cmp ax, 'KX'
44
   jne @f ; Not KX
45
   lodsw
46
   cmp ax, 0
47
   jne @f ; Bad magic
48
   lodsw
8672 Coldy 49
 
8709 Coldy 50
   bt ax, 6 ; Have import?
51
   jnc .app_start
52
;}
53
 
54
   ; Test import table (use legacy style)
55
   mov  eax, [sizeof.kx_header + 0x24] ; i_table_ptr
8672 Coldy 56
   test eax, eax
8709 Coldy 57
   jz  .app_start           ; i_table_ptr = 0 ?
58
   ;js      .error
8672 Coldy 59
   mov esi, [0x10]
60
   cmp esi, eax
8709 Coldy 61
   jbe @f           ; i_table_ptr >= img_size ?
8672 Coldy 62
   mov ebx, eax
63
   add ebx, i_table_min_size
64
   cmp esi, ebx
8709 Coldy 65
   jb @f           ; i_table_ptr + i_table_min_size > img_size ?
8672 Coldy 66
 
8709 Coldy 67
   ; Link app/dependent libs import tables with libs export table
68
   ; TODO: need revision of the exists lib format and dll.Load (for libs import binds)
69
 
8672 Coldy 70
   stdcall dll.Load,eax
8709 Coldy 71
   test	eax, eax
72
   jnz	.import_error
73
.app_start:
8672 Coldy 74
   ; Start of app code
8709 Coldy 75
   mov  eax, [0x0C]
76
   ; TODO: test start_ptr + min_code_size < img_size
8672 Coldy 77
   call eax
78
@@:
79
   mov eax, -1
80
   int 0x40
8709 Coldy 81
.import_error:
82
  ; Run @NOTIFY and tell user then error occured
83
  ; BOARD will contaits details
84
  jmp @b
8672 Coldy 85
.denied:
8709 Coldy 86
    ; Kolibri has no ability kill app if this enter from no from main thread
87
    ; So just alert and return
88
    ;DEBUGF	1, 'APP_STARTUP_THUNK@dll.obj: App twice/with app_version < 2 has entered!\n'
89
    ret
90
; } APP_STARTUP_THUNK
8672 Coldy 91
 
92
 
93
; WARNING! This code must be after app initialization thunk!
8724 dunkaist 94
include '../../../dll.inc'
8672 Coldy 95
align 4
96
;dd 0xdeadbeef
8709 Coldy 97
dd APP_STARTUP_THUNK
8672 Coldy 98
@EXPORT:
8709 Coldy 99
export                              \
100
    dll.Load,           'dll_load',  \
101
    dll.Link,           'dll_link',  \
8672 Coldy 102
    dll.GetProcAddress, 'dll_sym' ;