1 /* 2 * Copyright 2008, Michael Lotz, mmlr@mlotz.ch 3 * Distributed under the terms of the MIT License. 4 */ 5 #include <debug.h> 6 #include <signal.h> 7 8 9 static sem_id sRequestSem = -1; 10 11 12 static int32 13 invalidate_loop(void *data) 14 { 15 while (true) { 16 if (acquire_sem(sRequestSem) != B_OK) 17 break; 18 19 uint32 message[3]; 20 message[0] = sizeof(message); // size 21 message[1] = 'KDLE'; // message code 22 message[2] = 0; // flags 23 24 // where "d:0:baron' stands for desktop x of user y which both 25 // currently are hardcoded and where '_PTL' is the port link code 26 write_port(find_port("d:0:baron"), '_PTL', &message, sizeof(message)); 27 } 28 29 return 0; 30 } 31 32 33 static void 34 exit_debugger() 35 { 36 release_sem_etc(sRequestSem, 1, B_DO_NOT_RESCHEDULE); 37 } 38 39 40 static status_t 41 std_ops(int32 op, ...) 42 { 43 if (op == B_MODULE_INIT) { 44 sRequestSem = create_sem(0, "invalidate_loop_request"); 45 if (sRequestSem < B_OK) 46 return sRequestSem; 47 48 thread_id thread = spawn_kernel_thread(&invalidate_loop, 49 "invalidate_loop", B_NORMAL_PRIORITY, NULL); 50 if (thread < B_OK) 51 return thread; 52 53 send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); 54 return B_OK; 55 } else if (op == B_MODULE_UNINIT) { 56 // deleting the sem will also cause the thread to exit 57 delete_sem(sRequestSem); 58 sRequestSem = -1; 59 return B_OK; 60 } 61 62 return B_BAD_VALUE; 63 } 64 65 66 static struct debugger_module_info sModuleInfo = { 67 { 68 "debugger/invalidate_on_exit/v1", 69 B_KEEP_LOADED, 70 &std_ops 71 }, 72 73 NULL, 74 exit_debugger, 75 NULL, 76 NULL 77 }; 78 79 module_info *modules[] = { 80 (module_info *)&sModuleInfo, 81 NULL 82 }; 83