Re: Phix+EuGTK
- Posted by petelomax Dec 15, 2020
- 2232 views
Two more in pcfunc.e. line 206
#ilASM{ [PE32] mov eax,[filename] push ebx --(=0) (for fild qword) shl eax,2 push eax -- lpLibFileName call "kernel32.dll","LoadLibraryA" push eax lea edi,[res] fild qword[esp] add esp,8 call :%pStoreFlt -- ([edi]:=ST0) [PE64] mov rcx,rsp -- put 2 copies of rsp onto the stack... push rsp push rcx or rsp,8 -- [rsp] is now 1st or 2nd copy: -- if on entry rsp was xxx8: both copies remain on the stack -- if on entry rsp was xxx0: or rsp,8 effectively pops one of them (+8) -- obviously rsp is now xxx8, whatever alignment we started with mov rcx,[filename] sub rsp,8*5 -- minimum 4 param shadow space, and align shl rcx,2 -- lpLibFileName call "kernel32.dll","LoadLibraryA" mov [rsp],rax lea rdi,[res] fild qword[rsp] -- add rsp,8*5 -- pop rsp mov rsp,[rsp+8*5] -- equivalent to the add/pop call :%pStoreFlt -- ([rdi]:=ST0) [ELF32] mov eax,[filename] -- push 1 -- flags (RTLD_LAZY) push 0x00101 -- flags (RTLD_GLOBAL|RTLD_LAZY) shl eax,2 -- ref->raw push eax -- library name call "libdl.so.2", "dlopen" add esp,8 lea edi,[res] call :%pStoreMint -- [edi]:=eax, as float if rqd [ELF64] mov rdi,[filename] mov rsi,0x00101 -- flags (RTLD_GLOBAL|RTLD_LAZY) shl rdi,2 -- ref->raw (library name) call "libdl.so.2", "dlopen" lea rdi,[res] call :%pStoreMint -- [rdi]:=rax, as float if rqd [] }
should be replaced with this
#ilASM{ [PE32] mov eax,[filename] push ebx --(=0) (for fild qword) shl eax,2 push eax -- lpLibFileName call "kernel32.dll","LoadLibraryA" push eax lea edi,[res] fild qword[esp] add esp,8 call :%pStoreFlt -- ([edi]:=ST0) [ELF32] mov eax,[filename] push 0x00101 -- flags (RTLD_GLOBAL|RTLD_LAZY) shl eax,2 -- ref->raw push eax -- library name call "libdl.so.2", "dlopen" add esp,8 lea edi,[res] call :%pStoreMint -- [e/rdi]:=e/rax, as float if rqd [64] mov rcx,rsp -- put 2 copies of rsp onto the stack... push rsp push rcx or rsp,8 -- [rsp] is now 1st or 2nd copy: -- if on entry rsp was xxx8: both copies remain on the stack -- if on entry rsp was xxx0: or rsp,8 effectively pops one of them (+8) -- obviously rsp is now xxx8, whatever alignment we started with [PE64] mov rcx,[filename] sub rsp,8*5 -- minimum 4 param shadow space, and align shl rcx,2 -- lpLibFileName call "kernel32.dll","LoadLibraryA" [ELF64] mov rdi,[filename] sub rsp,8*5 -- minimum 4 param shadow space, and align mov rsi,0x00101 -- flags (RTLD_GLOBAL|RTLD_LAZY) shl rdi,2 -- ref->raw (library name) call "libdl.so.2", "dlopen" [64] lea rdi,[res] -- add rsp,8*5 -- pop rsp mov rsp,[rsp+8*5] -- equivalent to the add/pop call :%pStoreMint -- [e/rdi]:=e/rax, as float if rqd [] }
and in call(), line 900ish, there are two [PE64] which should be deleted (and then no need to repeat the [64] guards after the first one)
There is a mmap call in builtins\VM\pHeap.e line 1058, and a pthread_exit call in builtins\VM\pThreadN.e line 322 that may need stack alignment, but I have left them alone for now.
Otherwise (surprisingly) I think that's it for the stack alignment issues