Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8708 → Rev 8709

/programs/develop/libraries/dll/ReadMe.txt
0,0 → 1,105
 
---
History
 
0.1 + First realised, kernel load dll.obj at runtime as starting point berfore app startup
dll.obj process app import table, but not depended librarys, after that app gots control in his starting point
 
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)
 
---
Purpose
Automatically libraries loads and linking imports.
 
---
Limitations
 
 
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
 
- in app:
1) In the version field of a header, (after MENUET0x) you must specify the number 2
2) After existing header add KX header extension as descriprion bellow
3) Specify imported libraries. Currentry format of import table same as in case of using dll.Load
4) Add code, without connecting dll.inc and, accordingly, without calling dll.Load. The heap initialization function (f. 68.11) does not need to be called either.
 
5) Compile the app and run. If everything is done correctly, then on startup the debug board will display the message "App header version 2"
If the DLL.OBJ library is missing, a message will be displayed, incl. via @NOTIFY. If you get a page error make sure you have completed steps 2 and 3
 
- in lib (obj):
Not supported yet, will be realized later.
1) Field optHeader of COFF header need set in 8+n*4, where n is count of fields after KX header
2) After COFF header add KX header extension (in general same as in case for app)
 
---
Descriprion of KX header extension (alpha).
 
TBD is meaning that this feature to be determined leter, and not supported yet.
By default all offsets and sizes given in bytes, for Flags field offsets and size given in bits.
Offset 4.x meaning offset 4 bit x
Fields between offset 8 and at end of KX header may be added later.
 
Offset Size Field Meaning
 
Signature:
 
0 2 SigMagic Module identifier with the value "KX"
 
2 1 SigRevision This field should be 0.
In the future, it can take on the revision value
(but can't take values higher than 64)
 
3 1 SigArch This field should be 0.
 
 
4 2 Flags:
 
4.0 2b F_ImageType TBD, this field should be 0
4.2 1b F_SectionMode TBD, this field should be 0
 
4.3 1b F_Const TBD, this field should be 0
 
4.4 1b F_Data TBD, this field should be 0
4.5 1b F_Export Module has export table, and pointer after header (see below)
 
4.6 1b F_Import Module has import table
 
4.7 1b F_Reserved Reserved, this field should be 0
 
4.8 1b F_BoundImport TBD, this field should be 0
4.9 1b F_BSS TBD, this field should be 0
 
4.10 1b F_TLS TBD, this field should be 0
 
1.11 5b F_Reserved Reserved, this field should be 0
 
 
6 2 Reserved Reserved, this field should be 0
... TBD Fields in this place may be added later
 
if(F_Export) {
? 4 ExportsHeader Pointer to export header (exists if F_Export=1), KX style export table not supported yet. Currently by backward compatibility reason used legacy style of export table, this field pointed to it
}
 
if(F_Import) {
? 4 ImportsHeader Pointer to imports header (exists if F_Import=1), KX style import table not supported yet. Currently by backward compatibility reason used legacy style of import table, this field pointed to it
}
 
... TBD Fields in this place may be added later
 
---
EOF
/programs/develop/libraries/dll/dll.asm
10,8 → 10,8
format MS COFF
public @EXPORT as 'EXPORTS'
 
include '../../../proc32.inc'
include '../../../macros.inc'
include '../../proc32.inc'
include '../../macros.inc'
 
section '.flat' code readable align 16
 
18,11 → 18,13
app_version equ word[8]
i_table_min_size = 1
 
APP_START_THUNK:
sizeof.kx_header = 8
 
APP_STARTUP_THUNK:
; First make shure that app
; have header version 2.0 or more
cmp app_version,2
jl .denied
jl .denied ; App with app_version < 2 shouldn't be here
; Then make shure that we first
mov eax, @EXPORT
34,10 → 36,26
; Early app initialization
; Test import table
mov eax, [0x24] ; i_table_ptr
;{ Test KX header
;xor eax, eax
mov esi,0x24
lodsw
cmp ax, 'KX'
jne @f ; Not KX
lodsw
cmp ax, 0
jne @f ; Bad magic
lodsw
bt ax, 6 ; Have import?
jnc .app_start
;}
; Test import table (use legacy style)
mov eax, [sizeof.kx_header + 0x24] ; i_table_ptr
test eax, eax
jz @f
jz .app_start ; i_table_ptr = 0 ?
;js .error
mov esi, [0x10]
cmp esi, eax
jbe @f ; i_table_ptr >= img_size ?
44,12 → 62,15
mov ebx, eax
add ebx, i_table_min_size
cmp esi, ebx
jbe @f ; i_table_ptr + i_table_min_size >= img_size ?
jb @f ; i_table_ptr + i_table_min_size > img_size ?
; Link app import table with DLL's exoport table
; 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)
stdcall dll.Load,eax
test eax, eax
jnz @f
jnz .import_error
.app_start:
; Start of app code
mov eax, [0x0C]
; TODO: test start_ptr + min_code_size < img_size
57,16 → 78,23
@@:
mov eax, -1
int 0x40
.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
; So just alert and return
;DEBUGF 1, 'APP_STARTUP_THUNK@dll.obj: App twice/with app_version < 2 has entered!\n'
ret
; } APP_START_THUNK
; } APP_STARTUP_THUNK
 
 
; WARNING! This code must be after app initialization thunk!
include '../../../dll.inc'
include '../../dll.inc'
align 4
;dd 0xdeadbeef
dd APP_START_THUNK
dd APP_STARTUP_THUNK
@EXPORT:
export \
dll.Load, 'dll_load', \