2021-02-08 17:19:00 +00:00
|
|
|
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
|
|
|
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
2020-06-15 14:18:57 +00:00
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
2021-02-08 17:19:00 +00:00
|
|
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-03-01 07:42:35 +00:00
|
|
|
#include "libc/macros.internal.h"
|
2021-02-08 17:19:00 +00:00
|
|
|
.privileged
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-02-08 17:19:00 +00:00
|
|
|
ftrace_hook:
|
2023-05-09 08:56:56 +00:00
|
|
|
#ifdef __x86_64__
|
|
|
|
|
2022-05-18 23:41:29 +00:00
|
|
|
cmp $0,__ftrace(%rip)
|
2023-06-07 02:46:56 +00:00
|
|
|
jle 1f
|
|
|
|
push %rbp
|
2021-02-08 17:19:00 +00:00
|
|
|
mov %rsp,%rbp
|
|
|
|
push %rax
|
|
|
|
push %rax
|
|
|
|
push %rdi
|
|
|
|
push %rsi
|
|
|
|
push %rdx
|
|
|
|
push %rcx
|
|
|
|
push %r8
|
|
|
|
push %r9
|
2021-07-12 06:17:47 +00:00
|
|
|
call ftracer
|
2021-02-08 17:19:00 +00:00
|
|
|
pop %r9
|
|
|
|
pop %r8
|
|
|
|
pop %rcx
|
|
|
|
pop %rdx
|
|
|
|
pop %rsi
|
|
|
|
pop %rdi
|
|
|
|
pop %rax
|
|
|
|
pop %rax
|
2023-06-06 18:10:38 +00:00
|
|
|
pop %rbp
|
2023-06-07 02:46:56 +00:00
|
|
|
1: ret
|
2023-05-09 08:56:56 +00:00
|
|
|
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
|
2023-06-06 06:35:31 +00:00
|
|
|
adrp x9,__ftrace
|
|
|
|
ldr w9,[x9,#:lo12:__ftrace]
|
2023-06-07 02:46:56 +00:00
|
|
|
cmp w9,0
|
|
|
|
ble 1f
|
|
|
|
stp x29,x30,[sp,-96]!
|
2023-06-06 06:35:31 +00:00
|
|
|
mov x29,sp
|
|
|
|
stp x0,x1,[sp,16]
|
|
|
|
stp x2,x3,[sp,32]
|
|
|
|
stp x4,x5,[sp,48]
|
|
|
|
stp x6,x7,[sp,64]
|
|
|
|
str x8,[sp,80]
|
2023-05-09 08:56:56 +00:00
|
|
|
bl ftracer
|
2023-06-06 06:35:31 +00:00
|
|
|
ldr x8,[sp,80]
|
|
|
|
ldp x6,x7,[sp,64]
|
|
|
|
ldp x4,x5,[sp,48]
|
|
|
|
ldp x2,x3,[sp,32]
|
|
|
|
ldp x0,x1,[sp,16]
|
|
|
|
ldp x29,x30,[sp],96
|
2023-06-07 02:46:56 +00:00
|
|
|
1: ret
|
2023-05-09 08:56:56 +00:00
|
|
|
|
|
|
|
#endif /* __x86_64__ */
|
2021-02-08 17:19:00 +00:00
|
|
|
.endfn ftrace_hook,globl
|