Annotation of truecrypt/driver vxd/ifshook.c, revision 1.1.1.1

1.1       root        1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org
                      2:    This product uses components written by Paul Le Roux <[email protected]> */
                      3: 
                      4: #include "TCdefs.h"
                      5: 
                      6: #pragma VxD_LOCKED_CODE_SEG
                      7: #pragma VxD_LOCKED_DATA_SEG
                      8: 
                      9: #include "crypto.h"
                     10: #include "apidrvr.h"
                     11: #include "tc9x.h"
                     12: #include "queue.h"
                     13: #include "ifshook.h"
                     14: 
                     15: extern int bAllowFastShutdown;
                     16: extern cryptvol *cryptvols[];
                     17: extern char *transferbuffer;
                     18: 
                     19: extern ppIFSFileHookFunc IFSMgr_InstallFileSystemApiHook (pIFSFileHookFunc fcn);
                     20: extern int SHELLHookBroadcast (void *haddress, int ref);
                     21: 
                     22: ppIFSFileHookFunc prevhook = NULL;     /* address of previous IFS handler */
                     23: int threadid = -1;             /* Handle to the ring0 IO thread */
                     24: int nSemaphore = 0;            /* Sync object for the ring0 IO thread */
                     25: int terminatethread = 0;       /* Used when application reads disk drive.... */
                     26: 
                     27: int
                     28: HookProc (pIFSFunc fsdproc, int fcn, int drive, int flags, int cp, pioreq pir)
                     29: {
                     30:        int x, y;
                     31:        unsigned int fp;
                     32:        char *p;
                     33: 
                     34:        if (fcn < 2)            /* read or write */
                     35:        {
                     36:                if (pir->ir_data == (void *) transferbuffer)
                     37:                {
                     38:                        y = pir->ir_options;
                     39:                        pir->ir_options |= R0_MM_READ_WRITE;
                     40:                        x = (**prevhook) (fsdproc, fcn, drive, flags, cp, pir);
                     41:                        pir->ir_options = y;
                     42:                        return x;
                     43:                }
                     44:                else
                     45:                {
                     46:                        fp = pir->ir_pos;
                     47:                        p = (char *) pir->ir_data;
                     48:                        y = pir->ir_length;
                     49:                        x = (**prevhook) (fsdproc, fcn, drive, flags, cp, pir);
                     50: 
                     51:                        return x;
                     52: 
                     53:                }
                     54:        }
                     55: 
                     56:        return (**prevhook) (fsdproc, fcn, drive, flags, cp, pir);
                     57: }
                     58: 
                     59: int
                     60: BroadcastMon (int msg, int wparam, int lparam, int ref)
                     61: {
                     62:        cryptvol *cv;
                     63:        int c;
                     64: 
                     65:        if (msg == 0x16)        /* is it WM_ENDSESSION ? */
                     66:        {
                     67:                if (lparam < 0x80000000)        /* 0x80000000 is log off */
                     68:                {
                     69:                        if (bAllowFastShutdown)
                     70:                                return 1;
                     71: 
                     72:                        for (c = 0; c < 8; c++)
                     73:                        {
                     74:                                cv = cryptvols[c];
                     75:                                if (cv->booted)
                     76:                                {
                     77:                                        return 0;
                     78:                                }
                     79: 
                     80:                        }
                     81: 
                     82: 
                     83:                        OnSystemExit ();        /* only if NOT log off */
                     84:                }
                     85: 
                     86: 
                     87:        }
                     88: 
                     89:        if (msg == 0x11 && lparam < 0x80000000) /* is it WM_QUERYENDSESSION ? */
                     90:        {
                     91:                if (bAllowFastShutdown)
                     92:                        return 1;
                     93: 
                     94:                for (c = 0; c < 8; c++)
                     95:                {
                     96:                        cv = cryptvols[c];
                     97:                        if (cv->booted)
                     98:                        {
                     99:                                Post_message ("Please dismount all TC drives before attempting to shutdown Windows.", "TC drives still mounted!");
                    100:                                return 0;       /* This will NOT stop
                    101:                                                   WM_ENDSESSION! */
                    102:                        }
                    103:                }
                    104:        }
                    105: 
                    106: 
                    107:        return 1;
                    108: }
                    109: 
                    110: void
                    111: installhook (void)
                    112: {
                    113:        if (prevhook == NULL)
                    114:        {
                    115:                prevhook = IFSMgr_InstallFileSystemApiHook (HookProc);
                    116:                SHELLHookBroadcast (&BroadcastMon, 0);
                    117:        }
                    118: }
                    119: 
                    120: void
                    121: InstallTCThread (void)
                    122: {
                    123:        if (threadid == -1)
                    124:                threadid = installthread (&TCRing0Thread);
                    125: }
                    126: 
                    127: 
                    128: /* called when TC IO initially queued to wake up our ring 0 thread to handle
                    129:    the IO for us */
                    130: 
                    131: void
                    132: wakethread (void)
                    133: {
                    134:        Signal_Semaphore (nSemaphore);
                    135: }
                    136: 
                    137: 
                    138: /* called from broadcast handler */
                    139: void
                    140: killthread (void)
                    141: {
                    142:        if (threadid == -1)
                    143:                return;
                    144:        terminatethread = 1;
                    145:        Signal_Semaphore (nSemaphore);
                    146: }
                    147: 
                    148: 
                    149: /* This Ring 0 thread handles all TC IO, rather than schedule on global
                    150:    events which seem to cause trouble on Win98 */
                    151: 
                    152: void
                    153: TCRing0Thread (void)
                    154: {
                    155:        nSemaphore = Create_Semaphore (1);      /* task Sleep semaphore */
                    156: 
                    157:        while (1)
                    158:        {
                    159:                Wait_Semaphore (nSemaphore, BLOCK_THREAD_IDLE);
                    160:                if (terminatethread)
                    161:                        break;
                    162:                DeQueueIOP ();
                    163:                if (terminatethread)
                    164:                        break;  /* May have come in here too! */
                    165:        }
                    166: 
                    167:        threadid = -1;
                    168:        Destroy_Semaphore (nSemaphore);
                    169: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.