Created
June 4, 2011 04:02
-
-
Save landonf/1007564 to your computer and use it in GitHub Desktop.
Deadlocking a signal handler by using ObjC (ARM / x86-32)
This file contains hidden or 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
#import <Foundation/Foundation.h> | |
static void unsafe_signal_handler (int signo) { | |
signal(signo, SIG_DFL); | |
/* Attempt to use ObjC to fetch the backtrace. Will trigger deadlock. */ | |
[NSThread callStackSymbols]; | |
} | |
int main(int argc, char *argv[]) { | |
signal(SIGSEGV, unsafe_signal_handler); | |
void *cache[] = { | |
NULL, NULL, NULL | |
}; | |
/* Some random data array */ | |
void *displayStrings[6] = { | |
"This little piggy went to the market", | |
"This little piggy stayed at home", | |
cache, | |
"This little piggy had roast beef.", | |
"This little piggy had none.", | |
"And this little piggy went 'Wee! Wee! Wee!' all the way home", | |
}; | |
/* A corrupted/under-retained/re-used piece of memory */ | |
struct { | |
void *isa; | |
} corruptObj; | |
corruptObj.isa = displayStrings; | |
/* Attempting to message an invalid/corrupt object */ | |
[(id)&corruptObj class]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment