-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathl3.S
40 lines (39 loc) · 1.8 KB
/
l3.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
.globl l3_log_fn // l3_log_fn(msg)
.extern l3_log
.extern __libc_single_threaded
l3_log_fn:
mov %fs:l3_my_tid@tpoff,%eax // Fetch the TLS-stashed TID into %eax
cmp $0, %eax // Is the TID already stashed?
jnz .tid_stashed // yes: skip the call to gettid
mov $186, %eax // syscall number for gettid
push %rcx
syscall
pop %rcx
mov %eax, %fs:l3_my_tid@tpoff // store the TID in TLS.
.tid_stashed:
mov %rax, %r10 // get the TID into %r10
mov l3_log(%rip), %r8 // fetch ptr to the global l3_log into register r8
mov $1, %r9 // prepare to increment the index
cmpb $0, __libc_single_threaded(%rip) // Are we single-threaded?
jne .single_threaded // __libc_single_threaded != 0 so skip the lock prefix
lock
.single_threaded:
xadd %r9,(%r8)
add $32, %r8 // point r8 at the beginning of the l3_log.slots array.
and $0x3fff, %r9 // idx %= L3_NUM_SLOTS
shl $5, %r9 // scale the index by sizeof(L3_ENTRY)
add %r9, %r8 // point r8 at our entry in the slots array.
mov %eax, (%r8) // The tid is in %eax from the call to to gettid above.
#ifdef L3_LOC_ENABLED
add $4, %r8 // Point r8 at the loc field of the slot.
mov %ecx, (%r8) // Stash the LOC value.
add $4, %r8 // Point r8 at the msg field of the slot.
#else
add $8, %r8 // Point r8 at the msg field of the slot.
#endif // L3_LOC_ENABLED
mov %rdi, (%r8) // Stash the msg arg in the slot.
add $8, %r8 // Point r8 at the arg1 field in the slot.
movq %rsi, (%r8) // Stash arg1 in the slot
add $8, %r8 // Point r8 at the arg2 field in the slot.
movq %rdx, (%r8) // Stash arg2 in the slot.
ret