News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

VARARG in StaticMethod macro error

Started by a1sbofo, September 30, 2022, 07:01:04 PM

Previous topic - Next topic

a1sbofo

Hello
I recently change my workspace from ObjAsm32+Masm32 to UAsm+Objasm_C1.1
Perhaps there is a problem with VARARG option in 'StaticMethod' macro,
or I am wrong.
I change register ecx to register eax for total number of passed arguments
but trying:
 StaticMethod   xTrace            , dword, PSTRING, ?

   OCall xTrace, TRACE_TJS, Addr szHdr1, Addr szVersion                  ; (1)
   OCall xTrace, TRACE_TJS, Addr szHdr2                              ; (2)
   OCall xTrace, TRACE_TJS, Addr szHdr3, Addr [esi].szDate, Addr [esi].szHeure ; (3)
   ...
   ...
   Method TestParams.xTrace, uses esi edi, dNiv:dword, pMask:PSTRING, args:VARARG
   ...
   MethodEnd 

      
On return, esp register is wrong.

On (1)  <<<OCall xTrace, TRACE_TJS, Addr szHdr1, Addr szVersion>>>
Address   Hex dump          Command                                  Comments
006917F1  |.  68 30806900   PUSH OFFSET _szVersion                   ; UNICODE "2.0.0"
006917F6  |.  68 08816900   PUSH OFFSET _szHdr1                      ; UNICODE "TestParams                           Version %s "
006917FB  |.  68 00000000   PUSH 0
00691800  |.  FF75 08       PUSH DWORD PTR SS:[EBP+8]
00691803  |.  B8 03000000   MOV EAX,3
00691808  |.  E8 4F010000   CALL _OA_TestParams_xTrace
0069180D  |.  83C4 10       ADD ESP,10

   Ok: the last instruction remove four parameters from stack

On (2) <<<OCall xTrace, TRACE_TJS, Addr szHdr2>>>
00691810  |.  68 6C816900   PUSH OFFSET _szHdr2
00691815  |.  68 00000000   PUSH 0
0069181A  |.  FF75 08       PUSH DWORD PTR SS:[EBP+8]
0069181D  |.  B8 02000000   MOV EAX,2
00691822  |.  E8 35010000   CALL _OA_TestParams_xTrace

   Not ok: there is no instruction to remove parameters from stack !!!

On (2) <<<OCall xTrace, TRACE_TJS, Addr szHdr3, Addr [esi].szDate, Addr [esi].szHeure>>>
00691827  |.  8D46 40       LEA EAX,[ESI+40]
0069182A  |.  50            PUSH EAX
0069182B  |.  8D46 20       LEA EAX,[ESI+20]
0069182E  |.  50            PUSH EAX
0069182F  |.  68 B0816900   PUSH OFFSET _szHdr3
00691834  |.  68 00000000   PUSH 0
00691839  |.  FF75 08       PUSH DWORD PTR SS:[EBP+8]
0069183C  |.  B8 04000000   MOV EAX,4
00691841  |.  E8 16010000   CALL _OA_TestParams_xTrace
00691846  |.  83C4 14       ADD ESP,14

   Ok: the last instruction remove five parameters from stack


I am using Objects macro:
; ==================================================================================================
; Title:      Objects.inc
; Author:     G. Friedrich
; Version:    C.1.4
; Purpose:    ObjAsm object support using MASM compatible assembers (UASM, ASMC, JWASM, ML)
; Notes:      Version C.1.0, October 2017
;               - First release.
;             Version C.1.1, September 2019
;               - Method "uses": skip 64 bit registers in 32 bit mode.
;               - Undefined symbol warning added in $PushMethodArgs.
;             Version C.1.2, December 2020
;               - $MethodAddr can handle addresses of embedded objects.
;             Version C.1.3, May 2021
;               - VARARG stack correction bug corrected.
;               - dup spacing issue coorected.
;             Version C.1.4, August 2022
;               - Mitigation measures against multiple inclusion of object definition files.
; ==================================================================================================

What is wrong?

Changing line 2676 in this macro from 
       %exitm <@WordSize*(??ParamCount + ArgCount + 1)>  ;;Return number of bytes to remove
to
      %exitm <@WordSize*(??ParamCount  + 1)>  ;;Return number of bytes to remove @FB
this seems to solve the problem.

jj2007

Welcome to the Forum, a1sbofo :thup:

Can't help you with your specific problem, but I just wanted to say hi ;-)

Quote from: a1sbofo on September 30, 2022, 07:01:04 PM
On return, esp register is wrong.

Changing line 2676 in this macro from 
       %exitm <@WordSize*(??ParamCount + ArgCount + 1)>  ;;Return number of bytes to remove
to
      %exitm <@WordSize*(??ParamCount  + 1)>  ;;Return number of bytes to remove @FB
this seems to solve the problem.

Try this, before the exitm:
tmp$ CATSTR <the count is >, %ArgCount
% echo tmp$


If you don't see the count is 0 then you know that ArgCount is the culprit.

Biterider

Hi a1sbofo
Thank you for your feedback.  :thumbsup:

In the meantime I was able to reproduce the problem and can confirm the incorrect behavior.
I'll come up with a fix soon.

Biterider

Biterider

Hi a1sbofo
I fixed the stack balancing issue when using vararg and attached a new version.
Please try again and tell me if it solved the problem.  :biggrin:

Biterider

a1sbofo

Hi
Objects.inc : "Version C.1.5, September 2022"  is ok for my two little testing progs and one other.
Thanks