Fasm not correctly initializes in structure "Elf64_Rela".
FreeBSD7_amd64.
fasm - 1.67.26
typedef struct {
Elf64_Addr r_offset;
Elf64_Xword r_info;
Elf64_Sxword r_addend;
<--Does not initialize.
} Elf64_Rela;
;Dynamic Kernel Linker Facility - KLD.
;http://www.freebsd.org.ua/doc/ru_RU.KOI8-R/books/arch-handbook/driverbasics-kld.html
;KLD driver "Skelet" for FreeBSD_amd64.
;++++++++++++++++++++++++++++++++++++++++++++
format ELF64 ;+
section '.text' executable ;+
;===========================
extrn uprintf
extrn module_register_init
;=========================== ;+
;++++++++++++++++++++++++++++++++++++++++++++
Start:
push rbp ;
test esi,esi
mov rbp,rsp
jnz NextZapros
mov rdi,MesLoad ;1-----LINK "00h"
NextEnter:
xor eax,eax ;?
call uprintf ;2-----LINK "fffffffffffffffch"
;=============
xor eax,eax
;^^^^^^^^^^^
ExitModul:
leave
ret
;----------------------------
NextZapros:
dec esi
mov eax,16h
jnz ExitModul
mov rdi,MesUnload ;3-----LINK "13h"
jmp NextEnter
db (10h-(($-Start)and 0Fh))and 0Fh dup (0CCh)
;**************************START*****************************
;>>>>>>>>>>>>>>>>>>>>>>.rodata.str1.1<<<<<<<<<<<<<<<<<<<<<<<*
;**************************START*****************************
section '.rodata.str1.1'
rodata_start:
;+++++++++++++++++++++++++++
MesLoad db 'Skelet KLD loaded',0Ah,0 ;Skelet KLD load
MesUnload db 'Skelet KLD unloaded',0Ah,0 ;13h
NameModul db 'SKELET',0 ; 28h
db (10h-(($-rodata_start)and 0Fh))and 0Fh dup ('?')
;################################END################################
;;>>>>>>>>>>>>>>>>>>>>>>>>>.rodata.str1.1<<<<<<<<<<<<<<<<<<<<<<<<<<#
;################################END################################
section '.data' writeable
SKELETmodule_sys_init dd 02000000h ;SI_SUB_KLD
dd 0FFFFFFFh ;SI_ORDER_ANY
dq module_register_init ;4----LINK "0"
dq moduledata_SKELET ;5----LINK "30h"
_mod_metadata_md_SKELET dd 00000001h ;
dd 00000002h ;
dq moduledata_SKELET ;6----LINK 30h
dq NameModul ;7----LINK "28h"
moduledata_SKELET dq NameModul ;8----LINK "28h"
dq Start ; ;9----LINK "0"
dq 0 ;Null
dq 0
;#####################################################################
section 'set_sysinit_set'
__set_sysinit_set_sym_SKELETmodule_sys_init dq SKELETmodule_sys_init
section 'set_modmetadata_set'
__set_modmetadata_set_sym__mod_metadata_md_SKELET dq _mod_metadata_md_SKELET
;Fix address for driver works.
;1--LINK qword [120h]=0
;2---LINK qword [138h]=fffffffffffffffch
;3----LINK qword [150h]=13h
;4-----LINK qword [168h]=0
;5------LINK qword [180h]=30h
;6-------LINK qword [198h]=30h
;7--------LINK qword [1B0h]=28h
;8---------LINK qword [1C8h]=28h
;9----------LINK qword [1E0h]=0
;10----------LINK qword [1F8h]=0
;11-----------LINK qword [210h]=18h