Skip to content

Commit 2bac544

Browse files
committed
Implement get_sigframe_ip on x86
1 parent 3da48d2 commit 2bac544

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

src/RecordSession.cc

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,15 +1609,42 @@ static ssize_t get_sigframe_size(SupportedArch arch) {
16091609
}
16101610
}
16111611

1612-
static remote_code_ptr get_sigframe_ip(RecordTask *t, remote_ptr<ARM64Arch::rt_sigframe> frame_ptr)
1612+
template <typename Arch>
1613+
static remote_ptr<typename Arch::unsigned_long> get_sigframe_ip_ptr(remote_ptr<typename Arch::rt_sigframe> frame_ptr);
1614+
1615+
template <>
1616+
remote_ptr<ARM64Arch::unsigned_long> get_sigframe_ip_ptr<ARM64Arch>(remote_ptr<ARM64Arch::rt_sigframe> frame_ptr) {
1617+
return REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), regs), pc);
1618+
}
1619+
1620+
template <>
1621+
remote_ptr<X86Arch::unsigned_long> get_sigframe_ip_ptr<X86Arch>(remote_ptr<X86Arch::rt_sigframe> frame_ptr) {
1622+
return REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), ip);
1623+
}
1624+
1625+
template <>
1626+
remote_ptr<X64Arch::unsigned_long> get_sigframe_ip_ptr<X64Arch>(remote_ptr<X64Arch::rt_sigframe> frame_ptr) {
1627+
return REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), ip);
1628+
}
1629+
1630+
template <typename Arch>
1631+
static remote_code_ptr get_sigframe_ip_arch(RecordTask *t, remote_ptr<typename Arch::rt_sigframe> frame_ptr)
16131632
{
1614-
return t->read_mem(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), regs), pc));
1633+
return t->read_mem(get_sigframe_ip_ptr<Arch>(frame_ptr));
1634+
}
1635+
1636+
static remote_code_ptr get_sigframe_ip(RecordTask *t, remote_ptr<void> frame_ptr) {
1637+
RR_ARCH_FUNCTION(get_sigframe_ip_arch, t->arch(), t, frame_ptr.as_int());
16151638
}
16161639

1617-
static void set_sigframe_ip(RecordTask *t, remote_ptr<ARM64Arch::rt_sigframe> frame_ptr, remote_code_ptr ip)
1640+
template <typename Arch>
1641+
static void set_sigframe_ip_arch(RecordTask *t, remote_ptr<typename Arch::rt_sigframe> frame_ptr, remote_code_ptr ip)
16181642
{
1619-
t->write_mem(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), regs), pc),
1620-
ip.register_value());
1643+
t->write_mem(get_sigframe_ip_ptr<Arch>(frame_ptr), (typename Arch::unsigned_long)ip.register_value());
1644+
}
1645+
1646+
static void set_sigframe_ip(RecordTask *t, remote_ptr<void> frame_ptr, remote_code_ptr ip) {
1647+
RR_ARCH_FUNCTION(set_sigframe_ip_arch, t->arch(), t, frame_ptr.as_int(), ip);
16211648
}
16221649

16231650
/**

src/kernel_abi.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,21 @@ struct X64Arch : public BaseArch<SupportedArch::x86_64, WordSize64Defs> {
20512051
};
20522052
RR_VERIFY_TYPE_ARCH(SupportedArch::x86_64, ::sigcontext, sigcontext);
20532053

2054+
struct ucontext {
2055+
unsigned_long uc_flags;
2056+
ptr<struct ucontext> uc_link;
2057+
stack_t uc_stack;
2058+
struct sigcontext uc_mcontext;
2059+
kernel_sigset_t uc_sigmask;
2060+
};
2061+
2062+
struct rt_sigframe {
2063+
ptr<char> pretcode;
2064+
struct ucontext uc;
2065+
siginfo_t info;
2066+
// Extended ISA state follows
2067+
};
2068+
20542069
struct user_fpregs_struct {
20552070
uint16_t cwd;
20562071
uint16_t swd;
@@ -2274,6 +2289,21 @@ struct X86Arch : public BaseArch<SupportedArch::x86, WordSize32Defs> {
22742289
};
22752290
RR_VERIFY_TYPE_ARCH(SupportedArch::x86, ::sigcontext, sigcontext);
22762291

2292+
struct ucontext {
2293+
unsigned int uc_flags;
2294+
unsigned int uc_link;
2295+
stack_t uc_stack;
2296+
struct sigcontext uc_mcontext;
2297+
kernel_sigset_t uc_sigmask;
2298+
};
2299+
2300+
struct rt_sigframe {
2301+
ptr<char> pretcode;
2302+
struct ucontext uc;
2303+
siginfo_t info;
2304+
// Extended ISA state follows
2305+
};
2306+
22772307
struct user {
22782308
user_regs_struct regs;
22792309
int u_fpvalid;

0 commit comments

Comments
 (0)