-
-
Save maxmcd/3935a559f9029c17adbfa60b70dc89c5 to your computer and use it in GitHub Desktop.
Pfft, crashes are for chumps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static jmp_buf jmpEnv; | |
enum { | |
kPrepareBinaryAddress = 0x44dd, | |
kMutexBinaryAddress = 0x9090 | |
}; | |
void signal_handler(int n, siginfo_t *info, void *context) | |
{ | |
longjmp(jmpEnv, 1); | |
} | |
static int hwc_wrap_prepare(hwc_composer_device_1_t *dev, size_t numDisplays, hwc_display_contents_1_t **displays) | |
{ | |
if (numDisplays == 0) { | |
return 0; | |
} | |
int result = 0; | |
struct sigaction oldAction; | |
struct sigaction action; | |
memset(&oldAction, 0, sizeof(struct sigaction)); | |
memset(&action, 0, sizeof(struct sigaction)); | |
sigemptyset(&action.sa_mask); | |
action.sa_sigaction = signal_handler; | |
action.sa_flags = SA_RESTART | SA_SIGINFO; | |
// Use the alternate signal stack if available so we can catch stack overflows. | |
action.sa_flags |= SA_ONSTACK; | |
sigaction(SIGSEGV, &action, &oldAction); | |
if (setjmp(jmpEnv)) { | |
// One of the first/last things prepare() does it lock/unlock a mutex. We're going to assume we failed whilst the mutex was locked. | |
// So let's unlock it... using crazy hacks. | |
pthread_mutex_t *mstarHwcMutex = (pthread_mutex_t *)((size_t)dev->wrapper.device->prepare - kPrepareBinaryAddress + kMutexBinaryAddress); | |
pthread_mutex_unlock(mstarHwcMutex); | |
} else { | |
result = dev->wrapper.device->prepare(dev->wrapper.device, numDisplays, displays); | |
if (result != 0) { | |
ALOGE("hwc_wrap_prepare - numDisplays: %d - Failed with error: %d", numDisplays, result); | |
} | |
} | |
// Restore original SIGSEGV handler | |
sigaction(SIGSEGV, &oldAction, NULL); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment