Created
July 5, 2017 23:45
-
-
Save XanClic/0b37d9b7c7443f5d073f96f26b14e959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format ELF64 | |
public main | |
extrn printf | |
extrn pthread_create | |
extrn pthread_exit | |
use64 | |
section '.text' executable | |
main: | |
push rbx | |
xor rbx, rbx | |
mov rdi, pthread | |
xor rsi, rsi | |
mov rdx, thread_entry | |
xor rcx, rcx | |
call pthread_create | |
jmp old_thread | |
thread_entry: | |
mov rbx, 1 | |
old_thread: | |
xor rsi, rsi | |
full_loop: | |
cmp [other_shared], 0 | |
jne quit_loop | |
xbegin abort_vector | |
mov [shared], 42 | |
call qword bar | |
xend | |
add rsi, 1 | |
jmp full_loop | |
quit_loop: | |
jmp done | |
abort_vector: | |
mov rdi, stuff | |
call printf | |
mov [other_shared], 1 | |
done: | |
test rbx, rbx | |
jz do_exit | |
xor rdi, rdi | |
call pthread_exit | |
do_exit: | |
pop rbx | |
xor rax, rax | |
ret | |
bar: | |
ret | |
section '.rodata' | |
stuff db 'Times looped: %i', 10, 0 | |
section '.data' | |
shared dq 0 | |
pthread: times 64 db 0 | |
other_shared db 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment