From: Ben Pye Date: Sat, 5 Dec 2015 17:05:29 +0000 (+0000) Subject: Remove usage of getcontext X-Git-Tag: accepted/tizen/base/20180629.140029~6055^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d37c575cb2be8c11aca3a5572ce7e05455dca93f;p=platform%2Fupstream%2Fcoreclr.git Remove usage of getcontext --- diff --git a/src/pal/src/config.h.in b/src/pal/src/config.h.in index f327407..143679d 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 4b09fc0..333f009 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 f945c42..ebd4383 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;