Subversion Repositories Kolibri OS

Rev

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

  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.  
  13. include '../../../proc32.inc'
  14. include '../../../macros.inc'
  15.  
  16. section '.flat' code readable align 16
  17.  
  18. app_version       equ word[8]
  19. i_table_min_size  =   1
  20.  
  21. sizeof.kx_header  =   8
  22.  
  23. APP_STARTUP_THUNK:
  24.     ; First make shure that app
  25.     ; have header version 2.0 or more
  26.     cmp app_version,2
  27.     jl .denied            ; App with app_version < 2 shouldn't be here
  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
  35.     mov dword[eax-4],0  
  36.    
  37.    ; Early app initialization
  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
  49.    
  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
  56.    test eax, eax
  57.    jz  .app_start           ; i_table_ptr = 0 ?
  58.    ;js      .error
  59.    mov esi, [0x10]
  60.    cmp esi, eax
  61.    jbe @f           ; i_table_ptr >= img_size ?
  62.    mov ebx, eax
  63.    add ebx, i_table_min_size
  64.    cmp esi, ebx
  65.    jb @f           ; i_table_ptr + i_table_min_size > img_size ?
  66.    
  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.            
  70.    stdcall dll.Load,eax
  71.    test eax, eax
  72.    jnz  .import_error
  73. .app_start:  
  74.    ; Start of app code
  75.    mov  eax, [0x0C]
  76.    ; TODO: test start_ptr + min_code_size < img_size    
  77.    call eax
  78. @@:
  79.    mov eax, -1
  80.    int 0x40
  81. .import_error:
  82.   ; Run @NOTIFY and tell user then error occured
  83.   ; BOARD will contaits details
  84.   jmp @b
  85. .denied:
  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
  91.  
  92.  
  93. ; WARNING! This code must be after app initialization thunk!
  94. include '../../../dll.inc'
  95. align 4
  96. ;dd 0xdeadbeef
  97. dd APP_STARTUP_THUNK
  98. @EXPORT:
  99. export                              \
  100.     dll.Load,           'dll_load',  \
  101.     dll.Link,           'dll_link',  \
  102.     dll.GetProcAddress, 'dll_sym' ;