News:

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

Main Menu

How to use thread local storage

Started by markallyn, February 06, 2018, 05:59:36 AM

Previous topic - Next topic

markallyn

Good morning, Hutch

When I first opened up a 64 bit executable with x64dbg I saw code that I hadn't put there:  the clever work of STACKFRAME.  It took me longer than it should to tumble to the fact that STACKFRAME was built into masm64rt.inc. 

After discovering this very important fact I then debated whether or not it was better to construct my own stacks instead and invoke NOSTACKFRAME.  I've tried both ways of going about matters, but more often then not I do as you advise.

I'm still playing around with movs instead of push/pop's for parameters in excess of 4.  And there is still the deuced question of where the heck they are when the callee hunts for them.

The STACKFRAME macro is hard to follow.  I've tried more than once, partly to see how to better construct my own stacks. 

Thanks for elucidating the macro.  Much appreciated.

Mark

morgot

Hello
why does this code show me a messagebox 5-6 times? I re-write source from previous page.

.686                   
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\macros\macros.asm
uselib kernel32,user32
   
PUBLIC   _tls_index
PUBLIC   _tls_used

.data     

msg   BYTE "Hello World!",0   
tlsmsg   BYTE "I'm the TLS callback function.",0
label2  BYTE "Command line is",0

.code
   main   PROC   
   
   call GetCommandLineA
   
   invoke MessageBoxA,0,eax,chr$("main proc"),MB_OK
   

   ret
main   ENDP
   
   
tlsfunc    PROC
   
invoke MessageBoxA,0,addr tlsmsg,addr msg,MB_OK
   

   ret
tlsfunc   ENDP

;===============================================

.data     
_tls_index DWORD 0
array_tls_index DWORD _tls_index, 0
array_tls_func DWORD tlsfunc, 0

;===============================================
;THIS IS WHAT the struct initialization now looks like.  Thanks to aw27.

_tls_used   IMAGE_TLS_DIRECTORY <0,0,array_tls_index,array_tls_func,0,0>   



END main
Sorry for the bad English

six_L

@morgot:
TLS callback function would be to call on:
1,main process create;
2,main thread create;
3,main process exit.
so you list how many messageboxs will be created.
Say you, Say me, Say the codes together for ever.