flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > fasm DLL bugs

Author
Thread Post new topic Reply to topic
lorph



Joined: 19 Nov 2008
Posts: 1
lorph 19 Nov 2008, 08:48
Hello, I am trying to load fasm.dll through python by a stdcall function call.

However, I think there is something wrong with the stack or preprocessor. The function fasm_Assemble does not return correctly.

Upon further inspection of the DLL code at fasm.asm, I noticed that if you call the function fasm_Assemble, it never restores the stack pointer before quitting.

It seemed to be missing the statement "mov esp, [esp_save]" that was present if you returned from general_error and assembler_error, so I put this statement right above the "done:" label.

However, even with this change I am still getting an error. I tried to zero in on it by moving the statement "retn 20" around and I think it happens right in "call preprocessor".

Can anyone help me out with this?



**Update**

I found out the problem was that some of the registers were expected to be restored.

When I manually tweaked the source to restore the ebx and esi registers, it worked without errors.

So even though it works with assembler as-is, I think there might be some problem getting it to load with other languages.

**Update 2**

I decided to try to fix the code so it safely restores the general purpose registers esp, ebp, edi, esi, ebx. The assembler does not seem to change all of them, but it may change in the future. Hopefully any other miscellaneous registers do not need to be restored.

Code:
;find this in fasm.asm for the DLL
  mov     [display_pipe],eax
  push    ebp  

;change this to save the registers
 mov     [display_pipe],eax
 push    ebp
 push    ebx
 push    esi
 push    edi  

;find the done label

done:
 mov     eax,[ebx+FASM_STATE.condition]

;change to this
 mov     esp,[esp_save]
done:
  mov     eax,[ebx+FASM_STATE.condition]
  pop     edi
  pop     esi
  pop     ebx
  pop     ebp
    
Post 19 Nov 2008, 08:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.