1// Copyright 2017 The Fuchsia 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#include <asm.h>
6
7// These could be in C if we compiled the one file without
8// -fsanitize-coverage.  But they are trivial enough in assembly.
9
10.macro trap
11#ifdef __x86_64__
12    ud2
13#elif defined(__aarch64__)
14    brk #1000
15#else
16# error unsupported architecture
17#endif
18.endm
19
20// This should never be called, because the runtime should have been
21// loaded before any module initializers get called.
22ENTRY(__sanitizer_cov_trace_pc_guard_init)
23    trap
24END(__sanitizer_cov_trace_pc_guard_init)
25.weak __sanitizer_cov_trace_pc_guard_init
26
27// This is called only from __asan_early_init, which is the only thing
28// called during dynamic linker startup before the runtime has been
29// loaded that's outside dynlink.c, where _dynlink_sancov_trampoline
30// short-circuits before calling here.  Just sanity-check that we
31// aren't getting here after module initializers have run.
32ENTRY(__sanitizer_cov_trace_pc_guard)
33#ifdef __x86_64__
34    cmpl $0, (%rdi)
35    jne 0f
36    ret
37#elif defined(__aarch64__)
38    ldr w16, [x0]
39    cbnz w16, 0f
40    ret
41#else
42# error unsupported architecture
43#endif
440:  trap
45END(__sanitizer_cov_trace_pc_guard)
46.weak __sanitizer_cov_trace_pc_guard
47