commit:     3e60745c278248baa9cac3da0b4ed3f7dcd96501
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 26 02:56:41 2021 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Tue Oct 26 02:56:41 2021 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=3e60745c

libsandbox: port ptrace to aarch64

Seems to pass (almost all) unittests on Linux 4.19.  The unlink_static
doesn't seem to actually block the call, but it blocks others.  Still,
better than nothing at all at this point.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

 libsandbox/trace/linux/aarch64.c | 31 +++++++++++++++++++++++++++++++
 libsandbox/trace/linux/arch.c    |  2 ++
 2 files changed, 33 insertions(+)

diff --git a/libsandbox/trace/linux/aarch64.c b/libsandbox/trace/linux/aarch64.c
new file mode 100644
index 0000000..d056259
--- /dev/null
+++ b/libsandbox/trace/linux/aarch64.c
@@ -0,0 +1,31 @@
+#define trace_reg_ret regs[0]  /* x0 */
+#define trace_reg_sysnum regs[8]  /* w0 */
+
+#undef trace_get_regs
+static long trace_get_regs(void *vregs)
+{
+       struct iovec iov_regs = {
+               .iov_base = vregs,
+               .iov_len = sizeof(trace_regs),
+       };
+       return do_ptrace(PTRACE_GETREGSET, (void *)(uintptr_t)NT_PRSTATUS, 
&iov_regs);
+}
+
+#undef trace_set_regs
+static long trace_set_regs(void *vregs)
+{
+       struct iovec iov_regs = {
+               .iov_base = vregs,
+               .iov_len = sizeof(trace_regs),
+       };
+       return do_ptrace(PTRACE_SETREGSET, (void *)(uintptr_t)NT_PRSTATUS, 
&iov_regs);
+}
+
+static unsigned long trace_arg(void *vregs, int num)
+{
+       trace_regs *regs = vregs;
+       if (num < 7)
+               return regs->regs[num - 1];  /* x0 - x5 */
+       else
+               return -1;
+}

diff --git a/libsandbox/trace/linux/arch.c b/libsandbox/trace/linux/arch.c
index fd2d0de..16cdf9b 100644
--- a/libsandbox/trace/linux/arch.c
+++ b/libsandbox/trace/linux/arch.c
@@ -7,6 +7,8 @@
 #if !defined(HAVE_PTRACE) || !defined(HAVE_SYS_PTRACE_H) || \
     !defined(HAVE_SYS_USER_H) || !defined(PTRACE_SETOPTIONS)
 # define SB_NO_TRACE_ARCH
+#elif defined(__aarch64__)
+# include "aarch64.c"
 #elif defined(__alpha__)
 # include "alpha.c"
 #elif defined(__arm__)

Reply via email to