summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_common_interceptors_vfork_x86_64.inc.S
blob: 8147cdd0924730b39eca04e4c2b66a6d08787bc2 (plain)
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
41
#if defined(__x86_64__) && defined(__linux__)

#include "sanitizer_common/sanitizer_asm.h"

.comm _ZN14__interception10real_vforkE,8,8
.globl ASM_WRAPPER_NAME(vfork)
ASM_TYPE_FUNCTION(ASM_WRAPPER_NAME(vfork))
ASM_WRAPPER_NAME(vfork):
        // Store return address in the spill area and tear down the stack frame.
        push    %rcx
        call    COMMON_INTERCEPTOR_SPILL_AREA
        pop     %rcx
        pop     %rdi
        mov     %rdi, (%rax)

        call    *_ZN14__interception10real_vforkE(%rip)

        // Restore return address from the spill area.
        push    %rcx
        push    %rax
        call    COMMON_INTERCEPTOR_SPILL_AREA
        mov     (%rax), %rdx
        mov     %rdx, 8(%rsp)
        mov     (%rsp), %rax

        // Call handle_vfork in the parent process (%rax != 0).
        test    %rax, %rax
        je      .L_exit

        lea     16(%rsp), %rdi
        call    COMMON_INTERCEPTOR_HANDLE_VFORK@PLT

.L_exit:
        pop     %rax
        ret
ASM_SIZE(vfork)

.weak vfork
.set vfork, ASM_WRAPPER_NAME(vfork)

#endif