Skip to content

Commit

Permalink
Implement get_sigframe_ip on x86
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Jul 9, 2022
1 parent 3da48d2 commit 2bac544
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/RecordSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1609,15 +1609,42 @@ static ssize_t get_sigframe_size(SupportedArch arch) {
}
}

static remote_code_ptr get_sigframe_ip(RecordTask *t, remote_ptr<ARM64Arch::rt_sigframe> frame_ptr)
template <typename Arch>
static remote_ptr<typename Arch::unsigned_long> get_sigframe_ip_ptr(remote_ptr<typename Arch::rt_sigframe> frame_ptr);

template <>
remote_ptr<ARM64Arch::unsigned_long> get_sigframe_ip_ptr<ARM64Arch>(remote_ptr<ARM64Arch::rt_sigframe> frame_ptr) {
return REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), regs), pc);
}

template <>
remote_ptr<X86Arch::unsigned_long> get_sigframe_ip_ptr<X86Arch>(remote_ptr<X86Arch::rt_sigframe> frame_ptr) {
return REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), ip);
}

template <>
remote_ptr<X64Arch::unsigned_long> get_sigframe_ip_ptr<X64Arch>(remote_ptr<X64Arch::rt_sigframe> frame_ptr) {
return REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), ip);
}

template <typename Arch>
static remote_code_ptr get_sigframe_ip_arch(RecordTask *t, remote_ptr<typename Arch::rt_sigframe> frame_ptr)
{
return t->read_mem(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), regs), pc));
return t->read_mem(get_sigframe_ip_ptr<Arch>(frame_ptr));
}

static remote_code_ptr get_sigframe_ip(RecordTask *t, remote_ptr<void> frame_ptr) {
RR_ARCH_FUNCTION(get_sigframe_ip_arch, t->arch(), t, frame_ptr.as_int());
}

static void set_sigframe_ip(RecordTask *t, remote_ptr<ARM64Arch::rt_sigframe> frame_ptr, remote_code_ptr ip)
template <typename Arch>
static void set_sigframe_ip_arch(RecordTask *t, remote_ptr<typename Arch::rt_sigframe> frame_ptr, remote_code_ptr ip)
{
t->write_mem(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(REMOTE_PTR_FIELD(frame_ptr, uc), uc_mcontext), regs), pc),
ip.register_value());
t->write_mem(get_sigframe_ip_ptr<Arch>(frame_ptr), (typename Arch::unsigned_long)ip.register_value());
}

static void set_sigframe_ip(RecordTask *t, remote_ptr<void> frame_ptr, remote_code_ptr ip) {
RR_ARCH_FUNCTION(set_sigframe_ip_arch, t->arch(), t, frame_ptr.as_int(), ip);
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/kernel_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,21 @@ struct X64Arch : public BaseArch<SupportedArch::x86_64, WordSize64Defs> {
};
RR_VERIFY_TYPE_ARCH(SupportedArch::x86_64, ::sigcontext, sigcontext);

struct ucontext {
unsigned_long uc_flags;
ptr<struct ucontext> uc_link;
stack_t uc_stack;
struct sigcontext uc_mcontext;
kernel_sigset_t uc_sigmask;
};

struct rt_sigframe {
ptr<char> pretcode;
struct ucontext uc;
siginfo_t info;
// Extended ISA state follows
};

struct user_fpregs_struct {
uint16_t cwd;
uint16_t swd;
Expand Down Expand Up @@ -2274,6 +2289,21 @@ struct X86Arch : public BaseArch<SupportedArch::x86, WordSize32Defs> {
};
RR_VERIFY_TYPE_ARCH(SupportedArch::x86, ::sigcontext, sigcontext);

struct ucontext {
unsigned int uc_flags;
unsigned int uc_link;
stack_t uc_stack;
struct sigcontext uc_mcontext;
kernel_sigset_t uc_sigmask;
};

struct rt_sigframe {
ptr<char> pretcode;
struct ucontext uc;
siginfo_t info;
// Extended ISA state follows
};

struct user {
user_regs_struct regs;
int u_fpvalid;
Expand Down

0 comments on commit 2bac544

Please sign in to comment.