Author Topic: How to use thread local storage  (Read 2869 times)

markallyn

  • Member
  • **
  • Posts: 203
Re: How to use thread local storage
« Reply #15 on: February 09, 2018, 08:20:53 AM »
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

  • Member
  • **
  • Posts: 62
Re: How to use thread local storage
« Reply #16 on: June 26, 2020, 07:45:04 AM »
Hello
why does this code show me a messagebox 5-6 times? I re-write source from previous page.
Code: [Select]
.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

  • Member
  • **
  • Posts: 175
Re: How to use thread local storage
« Reply #17 on: June 26, 2020, 06:41:50 PM »
@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.