Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9669 → Rev 9668

/programs/develop/libraries/dll/strhlp.inc
File deleted
/programs/develop/libraries/dll/dll.inc
File deleted
/programs/develop/libraries/dll/external.inc
File deleted
\ No newline at end of file
/programs/develop/libraries/dll/strings.rus
File deleted
\ No newline at end of file
/programs/develop/libraries/dll/dll.asm
1,35 → 1,25
;
; Support for Dll auto load & linking
; KolibriOS Dll load support
;
; (C) 2020-2022 Coldy
; (C) 2020-2021 Coldy
; Thank's you for use this code and software based on it!
; I will glad if it's will be helpful.
;
; Distributed under terms of GPL
;
 
format MS COFF
public @EXPORT as 'EXPORTS'
section '.flat' code readable align 16
 
include 'external.inc'
include 'dll.inc'
include '../../../proc32.inc'
include '../../../macros.inc'
 
; This need for @notyfy pre/postformat
STR_BUILD_OFFSET = 1
STR_BUILD_EXTRA = 5
section '.flat' code readable align 16
 
mem_alloc = mem.Alloc
 
include 'strhlp.inc'
 
app_version equ word[8]
i_table_min_size = 1
 
sizeof.kx_header = 8
 
ERROR_BAD_IMAGE = 0x010
 
APP_STARTUP_THUNK:
; First make shure that app
; have header version 2.0 or more
51,10 → 41,10
mov esi,0x24
lodsw
cmp ax, 'KX'
jne .image_error ; Not KX
jne @f ; Not KX
lodsw
cmp ax, 0
jne .image_error ; Bad magic
jne @f ; Bad magic
lodsw
bt ax, 6 ; Have import?
64,15 → 54,15
; Test import table (use legacy style)
mov eax, [sizeof.kx_header + 0x24] ; i_table_ptr
test eax, eax
jz .image_error;.import_error;.app_start ; i_table_ptr = 0 ? => Bad image
jz .app_start ; i_table_ptr = 0 ?
;js .error
mov esi, [0x10]
cmp esi, eax
jbe .image_error;@f ; i_table_ptr >= img_size ?
jbe @f ; i_table_ptr >= img_size ?
mov ebx, eax
add ebx, i_table_min_size
cmp esi, ebx
jb .image_error;@f ; i_table_ptr + i_table_min_size > img_size ?
jb @f ; i_table_ptr + i_table_min_size > img_size ?
; Link app/dependent libs import tables with libs export table
; TODO: need revision of the exists lib format and dll.Load (for libs import binds)
79,7 → 69,7
stdcall dll.Load,eax
test eax, eax
jnz .link_error;.import_error
jnz .import_error
.app_start:
; Start of app code
mov eax, [0x0C]
88,11 → 78,9
@@:
mov eax, -1
int 0x40
.image_error:
mov eax, ERROR_BAD_IMAGE
.link_error:
; Run @NOTIFY and tell user then error occurred
call show_error
.import_error:
; Run @NOTIFY and tell user then error occured
; BOARD will contaits details
jmp @b
.denied:
; Kolibri has no ability kill app if this enter from no from main thread
102,67 → 90,8
; } APP_STARTUP_THUNK
 
 
; eax = error code (see ERROR_xxx above in this and dll.inc files)
 
show_error:
 
; Store error code
mov edx, eax
 
; Get app name
sub esp,1024
mov eax, 9
mov ebx, esp
mov ecx, -1
int 0x40
;
mov esi, esp
add esi, 10 ; esi = app name
 
cmp edx, ERROR_ENTRY_NOT_FOUND
je .entry_not_found
; Init heap not needed
; (kernel already initialized heap implicitly when load dll.obj)
cmp edx, ERROR_LIBRARY_NOT_LOAD
je .library_not_loaded
ccall str_build, szWrongFormat, esi, szBanner
jmp @f
 
.library_not_loaded:
ccall str_build, szLibraryNotLoaded, esi, szBanner, s_libdir.fname
jmp @f
.entry_not_found:
mov eax, [szEntryName]
ccall str_build, szEntryNotFound, esi, szBanner, eax, s_libdir.fname
@@:
add esp, 1024
 
mov byte[eax],'"'
mov byte[edi],'"'
mov dword[edi+1],"-tdE" ; with title, disable autoclose, error icon
mov esi, eax
; Display error
mov [pNotify.params], eax
mov ebx, pNotify
mov eax, 70
int 0x40
stdcall mem.Free, esi
.exit:
ret
 
 
; WARNING! This code must be after app initialization thunk!
include '../../../dll.inc'
align 4
;dd 0xdeadbeef
dd APP_STARTUP_THUNK
170,30 → 99,4
export \
dll.Load, 'dll_load', \
dll.Link, 'dll_link', \
dll.GetProcAddress, 'dll_sym'
pNotify:
dd 7, 0
.params dd 0
dd 0, 0
db "/sys/@notify", 0
; { Strings
if defined LANG_RUS
include 'strings.rus'
;elseif defined LANG_xxx
; TODO: Add another supported languges here
; - Copy 'elseif defined LANG_xxx', change xxx here and below to the
; corresponded constat of you languge
; - Create strings.xxx in the root of this project and do translate,
; follow the format message below.
; - add include 'strings.xxx'
else ; Default languge (English)
szBanner db "Error!\n",0
szWrongFormat db "$ - $Application has wrong format!",0
szLibraryNotLoaded db "$ - $Can't load library $", 0
szEntryNotFound db "$ - $Entry $\nin library $\nnot found!",0
 
end if
; } Strings
dll.GetProcAddress, 'dll_sym' ;
/programs/develop/libraries/dll/ReadMe.txt
8,23 → 8,21
0.2 + Introduced new KX header as extension for current format (see decription below)
+ Add KX header processing
+ Improved import table test logic, no reason to kill app for import absence - skip import processing (tnx ProMiNick)
+ Added ReadMe.txt (this doc)
 
0.2.1 + Branch from dll.inc, now this file is not external. Improved error handling. Now dll.Load return 0 in success only
Added corrsponding error codes if one of library or entry not found
+ Added error handling with detailed inform user which error occurred through @notyfy.
Now application is not crashed if bad format, can't load library or no found entry
 
 
---
Purpose
Automatically libraries loads and linking imports.
 
---
TODO
Limitations
 
1) The library format needs to be improved, see intorduction of KX header extension bellow
 
1) No error messages are issued if the library or symbol in the library is not found or somthing went wrong
 
 
2) There is no autoloading of dependent libraries (the library format needs to be improved, see intorduction of KX header extension bellow)
 
---
How to use