News:

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

Main Menu

Stack issues

Started by aw27, July 20, 2017, 12:11:18 AM

Previous topic - Next topic

aw27

A few stack related issues:


; x64

option casemap:none

.code

proc1 proc
ret
proc1 endp

main proc

; Stack is not realigned on entry

invoke proc1

ret
main endp

end ;main

end

COMMENT &
proc1
00000001`3ffa1000 4883c408   add     rsp,8 <- ????????????????????????
00000001`3ffa1004 c3              ret
main
               Stack is not realigned on entry
00000001`3ffa1005 4883ec20   sub    rsp,20h
00000001`3ffa1009 e8f2ffffff     call    test+0x1000 (00000001`3ffa1000)
00000001`3ffa100e 4883c420   add    rsp,20h
00000001`3ffa1021 4883c408   add    rsp,8 <- ????????????????????
00000001`3ffa1025 c3              ret
&

johnsa

Hi,

This one is already fixed in 2.38 which will be out soon :)

aw27

Quote from: johnsa on July 20, 2017, 06:06:48 PM
Hi,

This one is already fixed in 2.38 which will be out soon :)
:t

johnsa

2.38 for (win32 and win64) is up, please test :)

jj2007

Spits loads of errors: \masm32\include\windows.inc(20234) : Error A2279: EVEX encoding not enabled. Use option evex directive?

johnsa

Found the issue, due to improvements in the handling of evex instructions which use { } has caused this regression, will fix and update asap.

johnsa

Packages are updated on the site, dated today the 27th. Please try again.

Thanks,
John

jj2007

Thanks, now it works perfectly, tested on 1.5MB of sources :t

LiaoMi

Hi,

why does an exception occur when I call the MessageBox? In the first experiment, I manually do the alignment, in the other I hope that uasm64 will do it, but something is not going according to plan :( Two binary files can be downloaded below .. In general, I have noticed before that uasm does not align stack ?! Or I'm wrong?

.686
.MMX
.XMM
.x64

option casemap:none
option win64:15;win64:11
option frame:auto
option stackbase:rsp
option dotname
option evex:1
option proc:private
WIN32_LEAN_AND_MEAN equ 1
.nolist
.nocref

    include C:\masm64\VS2017\include_x86_x64\translate64.inc
    include C:\masm64\sdkrc100\um\windows.inc
    include macros64_Uasm.inc
;MessageBox proto :QWORD,:QWORD,:QWORD,:DWORD
;ExitProcess proto :DWORD
; -----------------------------------------
  ; non branching version with no ELSE clause
  ; -----------------------------------------
      chr$ MACRO any_text:VARARG
        LOCAL txtname
        .data
          IFDEF __UNICODE__
            WSTR txtname,any_text
            ;align 4
            .code
            EXITM <OFFSET txtname>
          ENDIF

          txtname db any_text,0
          ;align 4
          .code
          EXITM <OFFSET txtname>
      ENDM

      memalign MACRO reg, number
        sub reg, 8
        add reg, number - 1
        and reg, -number
      ENDM

Prologue64 MACRO       
                push        rdi 
sub         rsp, 100h 
mov         rdi, rsp
ENDM

Epilogue64 MACRO
add       rsp, 100h
                    pop       rdi 
          ENDM

;     ~~~~~~~~~
;     libraries
;     ~~~~~~~~~
    ; ------------------------------------------
    ; import libraries for Windows API functions
    ; ------------------------------------------

includelib Kernel32.lib
includelib  User32.lib
includelib  Msimg32.lib         
includelib  Comctl32.lib
includelib  Comdlg32.lib
includelib  Shell32.lib           
includelib  OleAut32.lib             
includelib  Ole32.lib
includelib  Advapi32.lib

.data
Me db "Test UASM Debug Compiling",0
.code

Main proc FRAME
    ;Prologue64
    invoke MessageBox,0,chr$("Test UASM Debug Compiling"),chr$("Test"),0
    ;Epilogue64
    ret
Main endp


start:
    enter 16,0
    ;memalign rsp,16
    invoke Main
    invoke ExitProcess,0
    leave
end start

hutch--

Give this technique a blast in UASM, I can only test in MASM but I have turned off the automatic stack frame and have coded it manually and I think UASM produces the same start alignment at the entry point.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

NOSTACKFRAME

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    push rbp
    mov rbp, rsp
    sub rsp, 128

    call testproc
    invoke ExitProcess,0

    leave
    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

testproc proc

    push rbp
    mov rbp, rsp
    sub rsp, 32

    invoke MessageBox,0,"Called within a stack frame","Title",MB_OK

    leave
    ret

testproc endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

STACKFRAME

    end

LiaoMi

Quote from: hutch-- on September 22, 2018, 04:10:01 AM
Give this technique a blast in UASM

Hi Hutch,

of course, I can do so, but by default the binary file is not working. Here are the differences of the binary files that the dumpbin utility was able to create ..

aw27

@LiaoMi

You are putting too much irrelevant code into your demo. After stripping most of the unneeded code, some still there, I can not second your claim - it does indeed align the stack. This works.



.686
.MMX
.XMM
.x64

option casemap:none
option win64:15;win64:11
option frame:auto
option stackbase:rsp
option dotname
option evex:1
option proc:private
WIN32_LEAN_AND_MEAN equ 1
.nolist
.nocref

HWND typedef ptr
includelib \masm32\lib64\kernel32.lib
ExitProcess proto :dword
includelib \masm32\lib64\user32.lib
MessageBoxA proto :HWND,:PTR,:PTR,:DWORD

; -----------------------------------------
  ; non branching version with no ELSE clause
  ; -----------------------------------------
      chr$ MACRO any_text:VARARG
        LOCAL txtname
        .data
          IFDEF __UNICODE__
            WSTR txtname,any_text
            ;align 4
            .code
            EXITM <OFFSET txtname>
          ENDIF

          txtname db any_text,0
          ;align 4
          .code
          EXITM <OFFSET txtname>
      ENDM


.data
Me db "Test UASM Debug Compiling",0
.code

Main proc FRAME
    invoke MessageBoxA,0,chr$("Test UASM Debug Compiling"),chr$("Test"),0
    ret
Main endp


start:
    enter 16,0
    invoke Main
    invoke ExitProcess,0
    leave
end start


LiaoMi

Quote from: AW on September 22, 2018, 08:03:58 PM
@LiaoMi

You are putting too much irrelevant code into your demo. After stripping most of the unneeded code, some still there, I can not second your claim - it does indeed align the stack. This works.



.686
.MMX
.XMM
.x64

option casemap:none
option win64:15;win64:11
option frame:auto
option stackbase:rsp
option dotname
option evex:1
option proc:private
WIN32_LEAN_AND_MEAN equ 1
.nolist
.nocref

HWND typedef ptr
includelib \masm32\lib64\kernel32.lib
ExitProcess proto :dword
includelib \masm32\lib64\user32.lib
MessageBoxA proto :HWND,:PTR,:PTR,:DWORD

; -----------------------------------------
  ; non branching version with no ELSE clause
  ; -----------------------------------------
      chr$ MACRO any_text:VARARG
        LOCAL txtname
        .data
          IFDEF __UNICODE__
            WSTR txtname,any_text
            ;align 4
            .code
            EXITM <OFFSET txtname>
          ENDIF

          txtname db any_text,0
          ;align 4
          .code
          EXITM <OFFSET txtname>
      ENDM


.data
Me db "Test UASM Debug Compiling",0
.code

Main proc FRAME
    invoke MessageBoxA,0,chr$("Test UASM Debug Compiling"),chr$("Test"),0
    ret
Main endp


start:
    enter 16,0
    invoke Main
    invoke ExitProcess,0
    leave
end start


Hi AW,

that's right, the code like yours is the same as my working example, now try to compile the same code, only without enter 16,0 and leave frame.

nidud

#13
deleted

LiaoMi

Quote from: nidud on September 22, 2018, 09:31:17 PM
Quote from: LiaoMi on September 22, 2018, 09:16:06 PMnow try to compile the same code, only without enter 16,0 and leave frame.

There's no real alignment done by assemblers or compilers so this is based serialization: one misaligned call will destroy the whole chain.

Hi nidud,

but in 32-bit version its possible without alignment?!  :icon_redface: I dont remember that I had such problems, this feature is only for x64 systems?!