Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: libsandbox/trace/linux/, libsandbox/
Date: Sun, 20 Dec 2015 21:36:10
Message-Id: 1450647321.e99597cc31b454f97d2629f17d3d6f5145f978d7.vapier@gentoo
1 commit: e99597cc31b454f97d2629f17d3d6f5145f978d7
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Sun Dec 20 21:35:21 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 20 21:35:21 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=e99597cc
7
8 libsandbox: new ia64 ptrace port
9
10 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
11
12 libsandbox/trace.c | 1 +
13 libsandbox/trace/linux/arch.c | 2 ++
14 libsandbox/trace/linux/ia64.c | 81 +++++++++++++++++++++++++++++++++++++++++++
15 3 files changed, 84 insertions(+)
16
17 diff --git a/libsandbox/trace.c b/libsandbox/trace.c
18 index 5ccda2a..fb1fc32 100644
19 --- a/libsandbox/trace.c
20 +++ b/libsandbox/trace.c
21 @@ -9,6 +9,7 @@
22 #include "wrappers.h"
23 #include "sb_nr.h"
24
25 +static long do_peekdata(long offset);
26 static long _do_ptrace(enum __ptrace_request request, const char *srequest, void *addr, void *data);
27 #define do_ptrace(request, addr, data) _do_ptrace(request, #request, addr, data)
28 #define _trace_possible(data) true
29
30 diff --git a/libsandbox/trace/linux/arch.c b/libsandbox/trace/linux/arch.c
31 index fbf5b79..4b3d615 100644
32 --- a/libsandbox/trace/linux/arch.c
33 +++ b/libsandbox/trace/linux/arch.c
34 @@ -17,6 +17,8 @@
35 # include "hppa.c"
36 #elif defined(__i386__)
37 # include "i386.c"
38 +#elif defined(__ia64__)
39 +# include "ia64.c"
40 #elif defined(__powerpc__)
41 # include "powerpc.c"
42 #elif defined(__s390__)
43
44 diff --git a/libsandbox/trace/linux/ia64.c b/libsandbox/trace/linux/ia64.c
45 new file mode 100644
46 index 0000000..5029994
47 --- /dev/null
48 +++ b/libsandbox/trace/linux/ia64.c
49 @@ -0,0 +1,81 @@
50 +#include <asm/ptrace_offsets.h>
51 +#include <asm/rse.h>
52 +
53 +/* We only care about two ptrace regs, so extract them ourselves rather than
54 + * get the "full" set via GETREGS. We still need to extract the out regs by
55 + * hand either way.
56 + */
57 +#undef trace_regs
58 +struct sb_ia64_trace_regs {
59 + unsigned long r8, r10, r15;
60 + unsigned long out[6];
61 +};
62 +#define trace_regs struct sb_ia64_trace_regs
63 +
64 +#define trace_reg_sysnum r15
65 +
66 +static unsigned long trace_arg(void *vregs, int num)
67 +{
68 + trace_regs *regs = vregs;
69 + if (num < 7)
70 + return regs->out[num - 1];
71 + else
72 + return -1;
73 +}
74 +
75 +static long do_peekuser(long offset)
76 +{
77 + return do_ptrace(PTRACE_PEEKUSER, (void *)offset, NULL);
78 +}
79 +
80 +static long do_pokeuser(long offset, long val)
81 +{
82 + return do_ptrace(PTRACE_POKEUSER, (void *)offset, (void *)val);
83 +}
84 +
85 +#undef trace_get_regs
86 +static long trace_get_regs(void *vregs)
87 +{
88 + trace_regs *regs = vregs;
89 + size_t i;
90 + unsigned long *out0, cfm, sof, sol;
91 + long rbs_end;
92 +
93 + regs->r15 = do_peekuser(PT_R15);
94 +
95 + /* Here there be gremlins! */
96 + rbs_end = do_peekuser(PT_AR_BSP);
97 + cfm = do_peekuser(PT_CFM);
98 + sof = (cfm >> 0) & 0x7f;
99 + sol = (cfm >> 7) & 0x7f;
100 + out0 = ia64_rse_skip_regs((unsigned long *)rbs_end, -sof + sol);
101 + for (i = 0; i < 7; ++i)
102 + regs->out[i] = do_peekdata((uintptr_t)ia64_rse_skip_regs(out0, i));
103 +
104 + return 0;
105 +}
106 +
107 +#undef trace_set_regs
108 +static long trace_set_regs(void *vregs)
109 +{
110 + trace_regs *regs = vregs;
111 + /* We only support rewriting of syscall/err # currently (not args). */
112 + do_pokeuser(PT_R8, regs->r8);
113 + do_pokeuser(PT_R10, regs->r10);
114 + do_pokeuser(PT_R15, regs->r15);
115 + return 0;
116 +}
117 +
118 +static long trace_raw_ret(void *vregs)
119 +{
120 + trace_regs *regs = vregs;
121 + return regs->r8;
122 +}
123 +
124 +static void trace_set_ret(void *vregs, int err)
125 +{
126 + trace_regs *regs = vregs;
127 + regs->r8 = err;
128 + regs->r10 = -1;
129 + trace_set_regs(regs);
130 +}