| 52 | |
| 53 | |
| 54 | static void ExecuteAction(void* ctxt) |
| 55 | { |
| 56 | MainThreadActionContext* action = (MainThreadActionContext*)ctxt; |
| 57 | |
| 58 | // We can't throw across a thread and *certainly* not across the api boundary |
| 59 | // But how do we deal with exceptions thrown in main thread callbacks if the caller doesn't wait for them? |
| 60 | // Likely the only good solution is abort() |
| 61 | try |
| 62 | { |
| 63 | action->action(); |
| 64 | } |
| 65 | catch (const std::exception& e) |
| 66 | { |
| 67 | LogError("Exception in main thread handler: %s", e.what()); |
| 68 | fprintf(stderr, "Exception in main thread handler: %s\n", e.what()); |
| 69 | abort(); |
| 70 | } |
| 71 | catch (...) |
| 72 | { |
| 73 | LogError("Exception in main thread handler: <unknown exception>"); |
| 74 | fprintf(stderr, "Exception in main thread handler: <unknown exception>\n"); |
| 75 | abort(); |
| 76 | } |
| 77 | delete action; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | Ref<MainThreadAction> BinaryNinja::ExecuteOnMainThread(const function<void()>& action) |