Skip to content

Commit

Permalink
8307955: Prefer to PTRACE_GETREGSET instead of PTRACE_GETREGS in meth…
Browse files Browse the repository at this point in the history
…od 'ps_proc.c::process_get_lwp_regs'

Reviewed-by: cjplummer, kevinw
  • Loading branch information
lgxbslgx committed May 17, 2023
1 parent d3e5065 commit 2f1c654
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ static bool process_write_data(struct ps_prochandle* ph,
static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct user_regs_struct *user) {
// we have already attached to all thread 'pid's, just use ptrace call
// to get regset now. Note that we don't cache regset upfront for processes.
// Linux on x86 and sparc are different. On x86 ptrace(PTRACE_GETREGS, ...)
// uses pointer from 4th argument and ignores 3rd argument. On sparc it uses
// pointer from 3rd argument and ignores 4th argument
#define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, data, addr)

#if defined(_LP64) && defined(PTRACE_GETREGS64)
#define PTRACE_GETREGS_REQ PTRACE_GETREGS64
Expand All @@ -138,22 +134,22 @@ static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct use
#define PTRACE_GETREGS_REQ PT_GETREGS
#endif

#ifdef PTRACE_GETREGS_REQ
if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
#if defined(PTRACE_GETREGSET)
struct iovec iov;
iov.iov_base = user;
iov.iov_len = sizeof(*user);
if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void*) &iov) < 0) {
print_debug("ptrace(PTRACE_GETREGSET, ...) failed for lwp %d\n", pid);
return false;
}
return true;
#elif defined(PTRACE_GETREGS_REQ)
if (ptrace(PTRACE_GETREGS_REQ, pid, NULL, user) < 0) {
print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp(%d) errno(%d) \"%s\"\n", pid,
errno, strerror(errno));
return false;
}
return true;
#elif defined(PTRACE_GETREGSET)
struct iovec iov;
iov.iov_base = user;
iov.iov_len = sizeof(*user);
if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, (void*) &iov) < 0) {
print_debug("ptrace(PTRACE_GETREGSET, ...) failed for lwp %d\n", pid);
return false;
}
return true;
#else
print_debug("ptrace(PTRACE_GETREGS, ...) not supported\n");
return false;
Expand Down

3 comments on commit 2f1c654

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgxbslgx
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport riscv-port-jdk17u

@openjdk
Copy link

@openjdk openjdk bot commented on 2f1c654 May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgxbslgx The target repository riscv-port-jdk17u is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk19u, openjdk/jdk20u, openjdk/jdk7u, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/jfx, openjdk/jfx20u, openjdk/shenandoah-jdk8u, openjdk/shenandoah-jdk8u-dev.
Supplying the organization/group prefix is optional.

Please sign in to comment.