diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2015-12-07 15:34:49 +0100 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2015-12-07 15:34:49 +0100 |
commit | 49f5b95ee35535189229525947cdb9af245bb4f9 (patch) | |
tree | a8f8a33f6031a48925c63ca958d707ed33ae149a | |
parent | 6333a4a9eaeb85b03d8afe7d50d9a7dca7bba829 (diff) | |
parent | d37c575cb2be8c11aca3a5572ce7e05455dca93f (diff) | |
download | coreclr-49f5b95ee35535189229525947cdb9af245bb4f9.tar.gz coreclr-49f5b95ee35535189229525947cdb9af245bb4f9.tar.bz2 coreclr-49f5b95ee35535189229525947cdb9af245bb4f9.zip |
Merge pull request #2254 from benpye/no-getcontext
Remove usage of getcontext
-rw-r--r-- | src/pal/src/config.h.in | 2 | ||||
-rw-r--r-- | src/pal/src/configure.cmake | 2 | ||||
-rw-r--r-- | src/pal/src/thread/context.cpp | 56 |
3 files changed, 10 insertions, 50 deletions
diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in index f3274076e8..143679d5a7 100644 --- a/src/pal/src/config.h.in +++ b/src/pal/src/config.h.in @@ -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 diff --git a/src/pal/src/configure.cmake b/src/pal/src/configure.cmake index 4b09fc0492..333f0094c5 100644 --- a/src/pal/src/configure.cmake +++ b/src/pal/src/configure.cmake @@ -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) diff --git a/src/pal/src/thread/context.cpp b/src/pal/src/thread/context.cpp index f945c427e4..ebd4383a71 100644 --- a/src/pal/src/thread/context.cpp +++ b/src/pal/src/thread/context.cpp @@ -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; @@ -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) @@ -239,9 +204,9 @@ 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!"); @@ -249,6 +214,8 @@ BOOL CONTEXT_GetRegisters(DWORD processId, ucontext_t *registers) #endif ASSIGN_ALL_REGS #undef ASSIGN_REG + + CONTEXTFromNativeContext(®isters, lpContext, lpContext->ContextFlags); } bRet = TRUE; @@ -275,7 +242,6 @@ CONTEXT_GetThreadContext( LPCONTEXT lpContext) { BOOL ret = FALSE; - ucontext_t registers; if (lpContext == NULL) { @@ -317,13 +283,11 @@ CONTEXT_GetThreadContext( if (lpContext->ContextFlags & (CONTEXT_CONTROL | CONTEXT_INTEGER)) { - if (CONTEXT_GetRegisters(dwProcessId, ®isters) == FALSE) + if (CONTEXT_GetRegisters(dwProcessId, lpContext) == FALSE) { SetLastError(ERROR_INTERNAL_ERROR); goto EXIT; - } - - CONTEXTFromNativeContext(®isters, lpContext, lpContext->ContextFlags); + } } ret = TRUE; |