Listing 3: signals.c Source for signal DLL
#define STRICT 1 #include <windows.h> #include <stdio.h> #include <winioctl.h> #include <string.h> #include <stdlib.h> #include "..\driver\sigdrv.h" #define SIGNALSLIBAPI __declspec(dllexport) #include "signals.h" /* Global array of signal handler */ VOID (__stdcall *functable[MAX_SIGNALS])(VOID); /* Handle to the device driver */ HANDLE hDevice; /* Set a signal thread */ DWORD SetSignalHandler(DWORD SignalNumber, PVOID f) { if (SignalNumber < MAX_SIGNALS) { functable[SignalNumber] = f; return 0; } return 1; } /* Call the appropriate signal handler */ DWORD WINAPI SignalsDriverRoutine(DWORD SignalNumber) { if (functable[SignalNumber] != NULL) (functable[SignalNumber])(); else printf("NULL signal function...!\n"); return 0; } /* this information is sent to the device driver */ typedef struct _SIGINFO { HANDLE hThread; /* target thread */ ULONG SigNo; /* signal number */ ULONG SigFunc; /* address of DriverRoutine */ } SIGINFO, *PSIGINFO; SIGINFO siginfo; /* Send a signal to the targer thread */ DWORD SendSignalToThread(HANDLE hThread, DWORD SignalNumber) { DWORD cbReturned; /* Initialize a SIGINFO structure */ siginfo.hThread = hThread; siginfo.SigNo = SignalNumber; siginfo.SigFunc = (unsigned long)SignalsDriverRoutine; /* Send the information to the driver */ if (!DeviceIoControl (hDevice, (DWORD)IOCTL_SIGDRV_SEND_SIGNAL, (PSIGINFO) &siginfo, sizeof(SIGINFO), NULL, 0, &cbReturned, 0 ) ) { return 1; } return 0; } BOOL WINAPI DllMain(HINSTANCE hDllInst, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: if ((hDevice = CreateFile( "\\\\.\\Global\\SIGDRV", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL )) == INVALID_HANDLE_VALUE) { printf ("Can't get a handle to the driver\n"); return FALSE; } break; case DLL_PROCESS_DETACH: CloseHandle(hDevice); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } return TRUE; } /* End of File */