libc/{i386,amd64}: Do not export .cerror when building WITHOUT_SYMVER
[freebsd-src.git] / usr.bin / truss / aarch64-freebsd.c
blob534441c60b8cfedd8a59a6648e441b476a251107
1 /*
2 * Copyright (c) 2015 The FreeBSD Foundation
4 * Portions of this software were developed by Konstantin Belousov
5 * under sponsorship from the FreeBSD Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 /* FreeBSD/arm64-specific system call handling. */
34 #include <sys/ptrace.h>
35 #include <sys/syscall.h>
37 #include <machine/reg.h>
38 #include <machine/armreg.h>
39 #include <machine/ucontext.h>
41 #include <stdio.h>
42 #include <sysdecode.h>
44 #include "truss.h"
46 static int
47 aarch64_fetch_args(struct trussinfo *trussinfo, u_int narg)
49 struct reg regs;
50 struct current_syscall *cs;
51 lwpid_t tid;
52 u_int i, reg, syscall_num;
54 tid = trussinfo->curthread->tid;
55 cs = &trussinfo->curthread->cs;
56 if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
57 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
58 return (-1);
62 * FreeBSD has two special kinds of system call redirections --
63 * SYS_syscall, and SYS___syscall. The former is the old syscall()
64 * routine, basically; the latter is for quad-aligned arguments.
66 * The system call argument count and code from ptrace() already
67 * account for these, but we need to skip over the first argument.
69 syscall_num = regs.x[8];
70 if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
71 reg = 1;
72 syscall_num = regs.x[0];
73 } else {
74 reg = 0;
77 for (i = 0; i < narg && reg < 8; i++, reg++)
78 cs->args[i] = regs.x[reg];
79 return (0);
82 static int
83 aarch64_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp)
85 struct reg regs;
86 lwpid_t tid;
88 tid = trussinfo->curthread->tid;
89 if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
90 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
91 return (-1);
94 retval[0] = regs.x[0];
95 retval[1] = regs.x[1];
96 *errorp = !!(regs.spsr & PSR_C);
97 return (0);
100 static struct procabi aarch64_freebsd = {
101 "FreeBSD ELF64",
102 SYSDECODE_ABI_FREEBSD,
103 aarch64_fetch_args,
104 aarch64_fetch_retval
107 PROCABI(aarch64_freebsd);