v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
push_registers_asm.cc
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Push all callee-saved registers to get them on the stack for conservative
6// stack scanning.
7//
8// We cannot rely on clang generating the function and right symbol mangling
9// as `__attribute__((naked))` does not prevent clang from generating TSAN
10// function entry stubs (`__tsan_func_entry`). Even with
11// `__attribute__((no_sanitize_thread)` annotation clang generates the entry
12// stub.
13// See https://bugs.llvm.org/show_bug.cgi?id=45400.
14
15// Do not depend on V8_TARGET_OS_* defines as some embedders may override the
16// GN toolchain (e.g. ChromeOS) and not provide them.
17
18// We maintain 16-byte alignment at calls. There is an 8-byte return address
19// on the stack and we push 56 bytes which maintains 16-byte stack alignment
20// at the call.
21// Source: https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf
22
23#ifdef _WIN64
24#error "The masm based version must be used for Windows"
25#endif
26
27asm(
28#ifdef __APPLE__
29 ".globl _PushAllRegistersAndIterateStack \n"
30 ".private_extern _PushAllRegistersAndIterateStack \n"
31 "_PushAllRegistersAndIterateStack: \n"
32#else // !__APPLE__
33 ".globl PushAllRegistersAndIterateStack \n"
34 ".type PushAllRegistersAndIterateStack, %function \n"
35 ".hidden PushAllRegistersAndIterateStack \n"
36 "PushAllRegistersAndIterateStack: \n"
37#endif // !__APPLE__
38 // rbp is callee-saved. Maintain proper frame pointer for debugging.
39 " push %rbp \n"
40 " mov %rsp, %rbp \n"
41 // Dummy for alignment.
42 " push $0xCDCDCD \n"
43 " push %rbx \n"
44 " push %r12 \n"
45 " push %r13 \n"
46 " push %r14 \n"
47 " push %r15 \n"
48 // Pass 1st parameter (rdi) unchanged (Stack*).
49 // Pass 2nd parameter (rsi) unchanged (StackVisitor*).
50 // Save 3rd parameter (rdx; IterateStackCallback)
51 " mov %rdx, %r8 \n"
52 // Pass 3rd parameter as rsp (stack pointer).
53 " mov %rsp, %rdx \n"
54 // Call the callback.
55 " call *%r8 \n"
56 // Pop the callee-saved registers.
57 " add $48, %rsp \n"
58 // Restore rbp as it was used as frame pointer.
59 " pop %rbp \n"
60 " ret \n"
61#if !defined(__APPLE__)
62 ".Lfunc_end0: \n"
63 ".size PushAllRegistersAndIterateStack, "
64 ".Lfunc_end0-PushAllRegistersAndIterateStack \n"
65#endif // !defined(__APPLE__)
66 );