flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [bug] Error with procedure definition macros in PROC64.INC

Author
Thread Post new topic Reply to topic
Bird of Hermes



Joined: 02 Nov 2024
Posts: 4
Location: Russia
Bird of Hermes 02 Nov 2024, 09:19
Because the stdcall fix fastcall line is after the define@proc macro definition, if we define a procedure with the stdcall calling convention, it will be impossible to call functions using standard macros inside such a procedure. The reason for this is that in the define@proc macro, stdcall is not yet replaced with fastcall, so the macro looks for the stdcall convention, and when using the macro, the replacement of stdcall with fastcall is already performed, so the macro receives fastcall as a parameter and turns it into a procedure argument. Here is an example of code that can cause the error
Code:
proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp
    

To solve this problem, change the order of the definition in the standard distribution or make stdcall a macro.
Post 02 Nov 2024, 09:19
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 02 Nov 2024, 14:52
I can't reproduce this with the standard PROC64.INC file from fasmw17332.zip dated 21 Sep 2024 12:13:15 UTC.
Code:
~ $ cat test_proc.asm
use64
include 'PROC64.INC'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp
~ $ fasm test_proc.asm test_proc
flat assembler  version 1.73.30  (16384 kilobytes memory)
1 passes, 0 bytes.    
Post 02 Nov 2024, 14:52
View user's profile Send private message Reply with quote
Bird of Hermes



Joined: 02 Nov 2024
Posts: 4
Location: Russia
Bird of Hermes 02 Nov 2024, 18:59
macomics wrote:
I can't reproduce this with the standard PROC64.INC file from fasmw17332.zip dated 21 Sep 2024 12:13:15 UTC.
Code:
~ $ cat test_proc.asm
use64
include 'PROC64.INC'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp
~ $ fasm test_proc.asm test_proc
flat assembler  version 1.73.30  (16384 kilobytes memory)
1 passes, 0 bytes.    

Aren't you confused by the fact that the output file contains 0 bytes? Try adding the line a = proc2 to the code.

_________________
If something can't be done with macros, then there were too few macros.
Post 02 Nov 2024, 18:59
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 02 Nov 2024, 19:50
Ok. Well
Code:
~ $ cat test_proc.asm
use64
include 'PROC64.INC'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp

a = proc2
~ $ fasm -m 102400 test_proc.asm test_proc
flat assembler  version 1.73.30  (102400 kilobytes memory)
test_proc.asm [9]:
        fastcall proc1
PROC64.INC [300] fastcall [292]:
    call proc
processed: ..arg?I proc1
error: illegal instruction.    


But!
Code:
~ $ cat test_proc.asm
use64
include 'PROC64.INC'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp

        call proc2
~ $ fasm -m 102400 test_proc.asm test_proc
flat assembler  version 1.73.30  (102400 kilobytes memory)
test_proc.asm [13]:
        call proc2
processed: ..arg?I proc2
error: illegal instruction.    
That is, the proc2 label was not even generated
Post 02 Nov 2024, 19:50
View user's profile Send private message Reply with quote
Bird of Hermes



Joined: 02 Nov 2024
Posts: 4
Location: Russia
Bird of Hermes 03 Nov 2024, 07:59
macomics wrote:
Ok. Well
Code:
~ $ cat test_proc.asm
use64
include 'PROC64.INC'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp

a = proc2
~ $ fasm -m 102400 test_proc.asm test_proc
flat assembler  version 1.73.30  (102400 kilobytes memory)
test_proc.asm [9]:
        fastcall proc1
PROC64.INC [300] fastcall [292]:
    call proc
processed: ..arg?I proc1
error: illegal instruction.    


But!
Code:
~ $ cat test_proc.asm
use64
include 'PROC64.INC'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp

        call proc2
~ $ fasm -m 102400 test_proc.asm test_proc
flat assembler  version 1.73.30  (102400 kilobytes memory)
test_proc.asm [13]:
        call proc2
processed: ..arg?I proc2
error: illegal instruction.    
That is, the proc2 label was not even generated

Use jmp instead. Because the proc macro tried to convert fastcall to a local variable using equ, the fastcall macro was called instead and converted call to a local variable

_________________
If something can't be done with macros, then there were too few macros.
Post 03 Nov 2024, 07:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 03 Nov 2024, 09:47
Replacing stdcall fix fastcall in proc64.inc with macro stdcall arg& { fastcall args } appears to fix the problem.
Code:
~ cat test.asm 
use64
include 'macro/proc64.inc'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp

jmp proc2
call proc2
a = proc2

~ fasm test.asm 
flat assembler  version 1.73.31  (16384 kilobytes memory)
4 passes, 32 bytes.

~    
Post 03 Nov 2024, 09:47
View user's profile Send private message Visit poster's website Reply with quote
Bird of Hermes



Joined: 02 Nov 2024
Posts: 4
Location: Russia
Bird of Hermes 04 Nov 2024, 09:42
revolution wrote:
Replacing stdcall fix fastcall in proc64.inc with macro stdcall arg& { fastcall args } appears to fix the problem.
Code:
~ cat test.asm 
use64
include 'macro/proc64.inc'

proc proc1
        ret
endp

proc proc2 stdcall
        fastcall proc1
        ret
endp

jmp proc2
call proc2
a = proc2

~ fasm test.asm 
flat assembler  version 1.73.31  (16384 kilobytes memory)
4 passes, 32 bytes.

~    

Yes, as I said at the very beginning, it works, but I would like this error be fixed in the official package

_________________
If something can't be done with macros, then there were too few macros.
Post 04 Nov 2024, 09:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 04 Nov 2024, 10:20
This thread has been stickied and marked with [bug], so it has the best chance to get the attention of the author.
Post 04 Nov 2024, 10:20
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.