The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: HSE on May 05, 2021, 06:15:42 AM

Title: Invoke macro reading prototypes
Post by: HSE on May 05, 2021, 06:15:42 AM
Hi All!

This is an update of Invoke macro for ML64 that can read prototypes to detect errors in type and number of arguments and allow or not to promotion.

H2incX @DefProto macro is used for still undeclared procs and a more simple macro @DefProtoE for procs already declared in Hutch's includes:    @DefProtoE macro ApiQual, ProcName, CallConv, NameSuffix, Params, DecorSuffix
      ifdif <CallConv>, <vectorcall>
        ??CallConv equ <fastcall>
      else
        ??CallConv equ <&CallConv>
      endif

      ifndef __JWASM__
      ProcName&ProtoConv equ <??CallConv>
      ProcName&ProtoParams textequ <&Params>
      endif
    endm

@DefProtoE DllImport, fptoa, WIN_STD_CALL_CONV,,<:REAL8,:QWORD>
@DefProtoE DllImport, vc__i64toa, WIN_STD_CALL_CONV,, <:SQWORD, :PTR SBYTE, :SDWORD>
@DefProtoE DllImport, __imp_sprintf, WIN_STD_CALL_CONV,, <:VARARG>, 4
@DefProtoE DllImport, ExitProcess, WIN_STD_CALL_CONV,, <:UINT>, 4



You can see it's no so automatic to write proc name because can be expanded or not. Because in the example Invoke is forced to expansion vc_sprintf don't work and must be __imp_sprintf.

Variable AllowPromotions can be TRUE or FALSE and control promotions. If FALSE you have to manually convert for example a BYTE in QWORD, if function is Unprototyped or Vararg. If TRUE that is maked by Invoke macro.

Obviously is just a beginning  :biggrin:

First test (testxmm64) show if Invoke still work, and also VARARG. Here you can see what happen if you change AllowPromotions to FALSE.

Second test (Hutch2) show some error detections already working:
hutch2.asm(163) : error A2052:forced error :  Too many arguments (>2)

hutch2.asm(164) : error A2052:forced error : Argument for rcx is incorrect

hutch2.asm(164) : error A2052:forced error : Argument for rdx is incorrect

hutch2.asm(168) : error A2052:forced error : Argument (1) is missing

Title: Re: Invoke macro reading prototypes
Post by: jj2007 on May 05, 2021, 08:31:42 AM
Congrats, Hector :thumbsup:

My Dual 64- and 32-bit Assembly package (http://masm32.com/board/index.php?topic=9266.0) works, too, but I am in the process of generating the args info directly from the GCC headers, and currently a little bit stuck - too little time, too much distraction. We'll see :biggrin:
Title: Re: Invoke macro reading prototypes
Post by: HSE on May 05, 2021, 09:41:23 AM
Quote from: jj2007 on May 05, 2021, 08:31:42 AM
but I am in the process of generating the args info directly from the GCC headers
:biggrin: Another includes!   Well... Good luck  :thumbsup:
Title: Re: Invoke macro reading prototypes
Post by: LiaoMi on May 05, 2021, 11:28:38 PM
Quote from: jj2007 on May 05, 2021, 08:31:42 AM
Congrats, Hector :thumbsup:

My Dual 64- and 32-bit Assembly package (http://masm32.com/board/index.php?topic=9266.0) works, too, but I am in the process of generating the args info directly from the GCC headers, and currently a little bit stuck - too little time, too much distraction. We'll see :biggrin:

Hi jj2007,

your experience can be transferred to the creation of UASM SDK for Linux :tongue: