aboutsummaryrefslogtreecommitdiff
blob: acbf894e30aaa73c8406eb5483775b613d6594e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#undef _trace_possible
#define _trace_possible _trace_possible

#ifdef SB_SCHIZO

static const struct syscall_entry syscall_table_32[] = {
#ifdef SB_SCHIZO_s390
#define S(s) { SB_SYS_s390_##s, SB_NR_##s, #s },
#include "trace_syscalls_s390.h"
#undef S
#endif
	{ SB_NR_UNDEF, SB_NR_UNDEF, NULL },
};
static const struct syscall_entry syscall_table_64[] = {
#ifdef SB_SCHIZO_s390x
#define S(s) { SB_SYS_s390x_##s, SB_NR_##s, #s },
#include "trace_syscalls_s390x.h"
#undef S
#endif
	{ SB_NR_UNDEF, SB_NR_UNDEF, NULL },
};

static bool pers_is_31(trace_regs *regs)
{
	return regs->psw.mask & 0x100000000ul ? false : true;
}

static const struct syscall_entry *trace_check_personality(void *vregs)
{
	trace_regs *regs = vregs;
	return pers_is_31(regs) ? syscall_table_32 : syscall_table_64;
}

static bool _trace_possible(const void *data)
{
	return true;
}

#else

static bool _trace_possible(const void *data)
{
# ifdef __s390x__
#  define ELFCLASS ELFCLASS64
# else
#  define ELFCLASS ELFCLASS32
# endif
	const Elf64_Ehdr *ehdr = data;
	return (ehdr->e_ident[EI_CLASS] == ELFCLASS) &&
		(ehdr->e_machine == EM_S390);
}

#endif

#undef trace_get_regs
static long trace_get_regs(void *vregs)
{
	ptrace_area parea = {
		/* Most regs we want are at the start (pswmask, pswaddr, and gpr0...gpr7,
		 * but the orig_gpr2 is much further along in the area. */
		.len = PT_ORIGGPR2 + sizeof(long),
		.kernel_addr = PT_PSWMASK,
		.process_addr = (uintptr_t)vregs,
	};
	do_ptrace(PTRACE_PEEKUSR_AREA, &parea, NULL);
	return 0;
}

#undef trace_set_regs
static long trace_set_regs(void *vregs)
{
	ptrace_area parea = {
		/* Most regs we want are at the start (pswmask, pswaddr, and gpr0...gpr7,
		 * but the orig_gpr2 is much further along in the area. */
		.len = PT_ORIGGPR2 + sizeof(long),
		.kernel_addr = PT_PSWMASK,
		.process_addr = (uintptr_t)vregs,
	};
	do_ptrace(PTRACE_POKEUSR_AREA, &parea, NULL);
	return 0;
}

#define trace_reg_sysnum gprs[2]
#define trace_reg_ret gprs[2]

static unsigned long trace_arg(void *vregs, int num)
{
	trace_regs *regs = vregs;
	if (num == 1)
		return regs->orig_gpr2;
	else if (num < 7)
		return regs->gprs[2 + num - 1];
	else
		return -1;
}