flat assembler
Message board for the users of flat assembler.
Index
> Linux > convert win64 api calls to linux syscalls |
Author |
|
typedef 07 Jan 2014, 02:23
just use POSIX functions.
|
|||
07 Jan 2014, 02:23 |
|
HaHaAnonymous 07 Jan 2014, 03:53
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:35; edited 1 time in total |
|||
07 Jan 2014, 03:53 |
|
randall 07 Jan 2014, 11:00
This is simple code framework which shows how to implement 'CreateThread', 'WaitForMultipleObjects' and 'VirtualAlloc' on Linux 64.
|
|||||||||||
07 Jan 2014, 11:00 |
|
tthsqe 07 Jan 2014, 14:36
OK, thanks! I see that you wait for each thread in sequence in place of one call to waitformultipleobjects. Also, I see that you didn't pass any arguments to the thread but do use xadd [#],1 to get the tile number. Is there a directly way of passing parameters to threads (i.e. in registers)?
|
|||
07 Jan 2014, 14:36 |
|
gens 07 Jan 2014, 19:18
afaik no
linux has only basic threading in kernel so you need to use clone(like_randall_does) to get a "full" thread bdw POSIX threads in glibc are done using clone() + http://www.akkadia.org/drepper/futex.pdf again, like randall does |
|||
07 Jan 2014, 19:18 |
|
randall 08 Jan 2014, 07:29
Yes, it is possible to pass parameters to the threads via registers (code from http://board.flatassembler.net/topic.php?t=14227):
Code: ; rsi ptr to function, rdi arg to function , rdx top of stack ; returns pid in eax start_thread: push rbp mov rbp,rsp mov rsp, rdx; push rdi rsi sub rdx,16 ; adjust stack for thread mov rsp,rbp sys_clone rdx test eax,eax jnz .L0 ; child pop rsi rdi call rsi sys_exit 0 .L0: ; parent pop rbp ret |
|||
08 Jan 2014, 07:29 |
|
gens 08 Jan 2014, 09:51
oh
ye that was dumb of me since the whole program gets copied so do the registers rbx, rbp, rsp and r12-15 survive syscalls (and can be used) http://www.logix.cz/michal/devel/amd64-regs/ i will need to test all this thou |
|||
08 Jan 2014, 09:51 |
|
randall 08 Jan 2014, 10:33
gens wrote: oh Yes, in my code I use rbx and it works. |
|||
08 Jan 2014, 10:33 |
|
tthsqe 08 Jan 2014, 17:44
great, I will start compiling a list of equivalent functions and see if they work. Fell free to comment. Should there be an analogue of GetStdHandles? or are these always 0,1, and 2?
Code: _ExitProcess: ; rcx is exit code mov eax,60 mov edi,ecx syscall _VirtualAlloc: ; rcx is size push rsi rdi mov eax,9 ; sys_mmap mov rsi,rcx ; length xor edi,edi ; addr mov edx,0x1+0x2 ; PROT_READ | PROT_WRITE mov r10d,0x02+0x20 ; MAP_PRIVATE | MAP_ANONYMOUS or r8,-1 ; fd xor r9d,r9d ; offset syscall pop rdi rsi ret |
|||
08 Jan 2014, 17:44 |
|
randall 09 Jan 2014, 07:28
Always 0, 1, 2.
|
|||
09 Jan 2014, 07:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.