diff options
author | Frederik Carlier <frederik.carlier@quamotion.mobi> | 2017-02-23 02:09:24 -0800 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2017-02-23 11:09:24 +0100 |
commit | 08581d8e9515ef1a348e7509785ea29195a9de37 (patch) | |
tree | 511e0204781ba1d70a45e6514db665de637136d7 /src/pal/src | |
parent | 6af4182d058df3520103d81c3912899e8d29f884 (diff) | |
download | coreclr-08581d8e9515ef1a348e7509785ea29195a9de37.tar.gz coreclr-08581d8e9515ef1a348e7509785ea29195a9de37.tar.bz2 coreclr-08581d8e9515ef1a348e7509785ea29195a9de37.zip |
Android: workaround absence of getcontext/setcontext (#9725)
* Android: workaround absence of getcontext/setcontext
use RtlCaptureContext and RtlRestoreContext
Diffstat (limited to 'src/pal/src')
-rw-r--r-- | src/pal/src/exception/signal.cpp | 27 | ||||
-rw-r--r-- | src/pal/src/include/pal/context.h | 6 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/pal/src/exception/signal.cpp b/src/pal/src/exception/signal.cpp index d442afaf4c..ee7f7ce85f 100644 --- a/src/pal/src/exception/signal.cpp +++ b/src/pal/src/exception/signal.cpp @@ -47,6 +47,33 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do #include "pal/context.h" +#ifdef __ANDROID__ +// getcontext and setcontext are not available natively on Android +int getcontext(ucontext_t *ucp) +{ + CONTEXT context; + RtlCaptureContext(&context); + CONTEXTToNativeContext(&context, ucp); + + return 0; +} + +int setcontext(const ucontext_t *ucp) +{ + CONTEXT context; + ULONG contextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT; + +#if defined(_AMD64_) + contextFlags |= CONTEXT_XSTATE; +#endif + + CONTEXTFromNativeContext(ucp, &context, contextFlags); + RtlRestoreContext(&context, NULL); + + return 0; +} +#endif + using namespace CorUnix; #ifdef SIGRTMIN diff --git a/src/pal/src/include/pal/context.h b/src/pal/src/include/pal/context.h index db6d69579a..782a51bcba 100644 --- a/src/pal/src/include/pal/context.h +++ b/src/pal/src/include/pal/context.h @@ -29,6 +29,12 @@ extern "C" #include <signal.h> #include <pthread.h> +#ifdef __ANDROID__ +// getcontext and setcontext are not available natively on Android +int setcontext(const ucontext_t *ucp); +int getcontext(ucontext_t* ucp); +#endif + #if !HAVE_MACH_EXCEPTIONS /* A type to wrap the native context type, which is ucontext_t on some * platforms and another type elsewhere. */ |