Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.7 KiB

  1. /**************************************************************************
  2. * SIGNAL.C
  3. *
  4. * Routines used to clean up on a forced KERNEL termination of a
  5. * TOOLHELP using app.
  6. *
  7. **************************************************************************/
  8. #include <string.h>
  9. #include "toolpriv.h"
  10. /* ----- Global variables ----- */
  11. WORD wSignalInstalled;
  12. SIGNAL NEAR *npSignalHead;
  13. /* SignalRegister
  14. * Registers a default signal proc to a task. This signal proc is
  15. * called when the task is about to be terminated and is called before
  16. * the USER signal proc is called. The registered callback is
  17. * called HelperSignalProc() [HELPER.ASM] and chains to the USER signal
  18. * proc (if any) instead of returning.
  19. */
  20. BOOL PASCAL SignalRegister(
  21. HANDLE hTask)
  22. {
  23. SIGNAL *pSig;
  24. SIGNAL *pTemp;
  25. /* NULL hTask means current task */
  26. if (!hTask)
  27. hTask = GetCurrentTask();
  28. /* Check to see if this task is already registered */
  29. for (pSig = npSignalHead ; pSig ; pSig = pSig->pNext)
  30. if (pSig->hTask == hTask)
  31. return FALSE;
  32. /* Allocate a new SIGNAL structure */
  33. pSig = (SIGNAL *)LocalAlloc(LMEM_FIXED, sizeof (SIGNAL));
  34. if (!pSig)
  35. return FALSE;
  36. /* Fill in the useful fields */
  37. pSig->hTask = hTask;
  38. pSig->lpfn = (LPFNCALLBACK)HelperSignalProc;
  39. pSig->lpfnOld = (LPFNCALLBACK)
  40. HelperSetSignalProc(hTask, (DWORD)HelperSignalProc);
  41. /* If this is the only handler, just insert it */
  42. if (!npSignalHead)
  43. {
  44. pSig->pNext = npSignalHead;
  45. npSignalHead = pSig;
  46. }
  47. /* Otherwise, insert at the end of the list */
  48. else
  49. {
  50. for (pTemp = npSignalHead ; pTemp->pNext ; pTemp = pTemp->pNext)
  51. ;
  52. pSig->pNext = pTemp->pNext;
  53. pTemp->pNext = pSig;
  54. }
  55. return TRUE;
  56. }
  57. /* SignalUnRegister
  58. * Called by an app whose callback is no longer to be used.
  59. * NULL hTask uses current task.
  60. */
  61. BOOL PASCAL SignalUnRegister(
  62. HANDLE hTask)
  63. {
  64. SIGNAL *pSig;
  65. SIGNAL *pBefore;
  66. /* NULL hTask means current task */
  67. if (!hTask)
  68. hTask = GetCurrentTask();
  69. /* First try to find the task */
  70. pBefore = NULL;
  71. for (pSig = npSignalHead ; pSig ; pSig = pSig->pNext)
  72. if (pSig->hTask == hTask)
  73. break;
  74. else
  75. pBefore = pSig;
  76. if (!pSig)
  77. return FALSE;
  78. /* Remove it from the list */
  79. if (!pBefore)
  80. npSignalHead = pSig->pNext;
  81. else
  82. pBefore->pNext = pSig->pNext;
  83. /* Replace the old signal proc */
  84. HelperSetSignalProc(hTask, (DWORD)pSig->lpfnOld);
  85. /* Free the structure */
  86. LocalFree((HANDLE)pSig);
  87. return TRUE;
  88. }