Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Remove usage of getcontext #2254

Merged
merged 1 commit into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#cmakedefine01 HAVE_PTHREAD_SIGQUEUE
#cmakedefine01 HAVE_SIGRETURN
#cmakedefine01 HAVE__THREAD_SYS_SIGRETURN
#cmakedefine01 HAVE_SETCONTEXT
#cmakedefine01 HAVE_GETCONTEXT
#cmakedefine01 HAVE_COPYSIGN
#cmakedefine01 HAVE_FSYNC
#cmakedefine01 HAVE_FUTIMES
Expand Down
2 changes: 0 additions & 2 deletions src/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
check_library_exists(pthread pthread_sigqueue "" HAVE_PTHREAD_SIGQUEUE)
check_function_exists(sigreturn HAVE_SIGRETURN)
check_function_exists(_thread_sys_sigreturn HAVE__THREAD_SYS_SIGRETURN)
check_function_exists(setcontext HAVE_SETCONTEXT)
check_function_exists(getcontext HAVE_GETCONTEXT)
check_function_exists(copysign HAVE_COPYSIGN)
check_function_exists(fsync HAVE_FSYNC)
check_function_exists(futimes HAVE_FUTIMES)
Expand Down
56 changes: 10 additions & 46 deletions src/pal/src/thread/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ Abstract

Parameter
processId: process ID
registers: reg structure in which the machine registers value will be returned.
lpContext: context structure in which the machine registers value will be returned.
Return
returns TRUE if it succeeds, FALSE otherwise
--*/
BOOL CONTEXT_GetRegisters(DWORD processId, ucontext_t *registers)
BOOL CONTEXT_GetRegisters(DWORD processId, LPCONTEXT lpContext)
{
#if HAVE_BSD_REGS_T
int regFd = -1;
Expand All @@ -186,46 +186,11 @@ BOOL CONTEXT_GetRegisters(DWORD processId, ucontext_t *registers)

if (processId == GetCurrentProcessId())
{
#if HAVE_GETCONTEXT
if (getcontext(registers) != 0)
{
ASSERT("getcontext() failed %d (%s)\n", errno, strerror(errno));
return FALSE;
}
#elif HAVE_BSD_REGS_T
char buf[MAX_PATH];
struct reg bsd_registers;

sprintf_s(buf, sizeof(buf), "/proc/%d/regs", processId);

if ((regFd = PAL__open(buf, O_RDONLY)) == -1)
{
ASSERT("PAL__open() failed %d (%s) \n", errno, strerror(errno));
return FALSE;
}

if (lseek(regFd, 0, 0) == -1)
{
ASSERT("lseek() failed %d (%s)\n", errno, strerror(errno));
goto EXIT;
}

if (read(regFd, &bsd_registers, sizeof(bsd_registers)) != sizeof(bsd_registers))
{
ASSERT("read() failed %d (%s)\n", errno, strerror(errno));
goto EXIT;
}

#define ASSIGN_REG(reg) MCREG_##reg(registers->uc_mcontext) = BSDREG_##reg(bsd_registers);
ASSIGN_ALL_REGS
#undef ASSIGN_REG

#else
#error "Don't know how to get current context on this platform!"
#endif
CONTEXT_CaptureContext(lpContext);
}
else
{
ucontext_t registers;
#if HAVE_PT_REGS
struct pt_regs ptrace_registers;
if (ptrace((__ptrace_request)PT_GETREGS, processId, (caddr_t) &ptrace_registers, 0) == -1)
Expand All @@ -239,16 +204,18 @@ BOOL CONTEXT_GetRegisters(DWORD processId, ucontext_t *registers)
}

#if HAVE_PT_REGS
#define ASSIGN_REG(reg) MCREG_##reg(registers->uc_mcontext) = PTREG_##reg(ptrace_registers);
#define ASSIGN_REG(reg) MCREG_##reg(registers.uc_mcontext) = PTREG_##reg(ptrace_registers);
#elif HAVE_BSD_REGS_T
#define ASSIGN_REG(reg) MCREG_##reg(registers->uc_mcontext) = BSDREG_##reg(ptrace_registers);
#define ASSIGN_REG(reg) MCREG_##reg(registers.uc_mcontext) = BSDREG_##reg(ptrace_registers);
#else
#define ASSIGN_REG(reg)
ASSERT("Don't know how to get the context of another process on this platform!");
return bRet;
#endif
ASSIGN_ALL_REGS
#undef ASSIGN_REG

CONTEXTFromNativeContext(&registers, lpContext, lpContext->ContextFlags);
}

bRet = TRUE;
Expand All @@ -275,7 +242,6 @@ CONTEXT_GetThreadContext(
LPCONTEXT lpContext)
{
BOOL ret = FALSE;
ucontext_t registers;

if (lpContext == NULL)
{
Expand Down Expand Up @@ -317,13 +283,11 @@ CONTEXT_GetThreadContext(
if (lpContext->ContextFlags &
(CONTEXT_CONTROL | CONTEXT_INTEGER))
{
if (CONTEXT_GetRegisters(dwProcessId, &registers) == FALSE)
if (CONTEXT_GetRegisters(dwProcessId, lpContext) == FALSE)
{
SetLastError(ERROR_INTERNAL_ERROR);
goto EXIT;
}

CONTEXTFromNativeContext(&registers, lpContext, lpContext->ContextFlags);
}
}

ret = TRUE;
Expand Down