site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com User-agent: Mozilla Thunderbird 1.0 (X11/20041206) Rick Steele wrote: Forgive the ignorance but, if one has a function like this within an application: void SumFunction(){ How about this snippet: -------------------------------- #include <signal.h> #include <stdlib.h> #include <unistd.h> typedef void (*full_sighandler_t)(int,siginfo_t*,void*); void installSignalHandler(int sig, full_sighandler_t handler) { struct sigaction temp; sigaction(sig, 0, &temp); // Set the SA_SIGINFO flag so that sa_sigaction may be safely used. temp.sa_flags = SA_SIGINFO; temp.sa_sigaction = handler; sigemptyset(&temp.sa_mask); sigaction(sig, &temp, NULL); } write(1, sig_message, sizeof(sig_message)); exit(1); } int main(int argc, char** argv) { installSignalHandler(SIGSEGV, &fatalSigHandler); installSignalHandler(SIGBUS, &fatalSigHandler); int* foo = NULL; *foo = 0; exit(0); } -------------------------------- You should read the man pages for signal and sigaction. -Kevin- _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Ptr pPtr = -1L; //create something that will obviously crash if deferenced char pSomethingElse; pSomethingElse = (*pPtr); // Causing the error } how would some one catch the signal that would inevitable occur so the app might be able to close down gracefully? Try 0 (or NULL) -- it should cause a SIGSEGV or SIGBUS (depending on the platform), whereas -1L could (potentially) be a valid chunk of memory. void fatalSigHandler(int sig, siginfo_t* info, void* context) { // We are very limited in what we are allowed to do in a signal handler. // Memory should not be allocated, and most libc functions should not be used. static char sig_message[] = "Aborting: Fatal signal occurred!\n"; This email sent to site_archiver@lists.apple.com
participants (1)
-
Kevin Harris