flat assembler
Message board for the users of flat assembler.

Index > Windows > multithread

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
Could someone post a simple exmple that demonstrates how to use multiple threads in a windows app?
Post 12 Sep 2009, 23:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Have a look at this post: http://board.flatassembler.net/topic.php?p=71735#71735

I just upload the simple thread tester again.
Post 13 Sep 2009, 03:36
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
If an argument is passed to a thread in CreateThread, how can the thread access this argument?

This is what I've got:

Code:
        sub     rsp,6*8
        mov     rcx,0
        mov     rdx,0
        lea     r8,[Thread]
        mov     r9,arg
        mov     qword [rsp+4*8],CREATE_SUSPENDED
        mov     qword [rsp+5*8],0
        call    [CreateThread]
        add     rsp,6*8 
...

Thread:
  where is arg?
....
        mov     rcx,0
        call    [ExitThread]
    
Post 14 Sep 2009, 04:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
It is on that stack as the first parameter.
Win32 manual wrote:
DWORD WINAPI ThreadFunc( LPVOID lpParam )
Post 14 Sep 2009, 04:34
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
am I doing something wrong? it doesn't seem to be working

Code:
        mov     [var],7

        sub     rsp,6*8
        mov     rcx,0 
        mov     rdx,0 
        lea     r8,[Thread] 
        lea     r9,[var]
        mov     qword [rsp+4*8],CREATE_SUSPENDED 
        mov     qword [rsp+5*8],0 
        call    [CreateThread] 
        add     rsp,6*8  
... 

Thread: 
        mov     rax,[rsp]
        mov     rax,[rax]
        rax = 7 ?      
Post 14 Sep 2009, 05:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Well since you seem to be using 64bit Windows then the first parameter is of course in a register (complying to the fastcall standard). IIRC it will be in rcx? Anyhow check the fastcall standard to confirm which register the first parameter is placed into.

BTW: For stdcall (with all parameters on the stack) the first parameter is [esp+4]. The return address is always at [esp] (and [rsp])
Post 14 Sep 2009, 05:36
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
great! I wouldn't have though it would be just like other function calls too. (I kept looking for it somewhere on the stack)
Quote:
IIRC it will be in rcx?

Yeah, arguments should be passed in
Code:
rcx, rdx, r8, r9, [rsp+8*4], [rsp+8*5],...    

and r12-r15 should be preserved by the function.
Post 14 Sep 2009, 06:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.