"Fossies" - the Fresh Open Source Software Archive

Member "src/Driver/EncryptedIoQueue.h" (10 Oct 2018, 3890 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "EncryptedIoQueue.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_DRIVER_ENCRYPTED_IO_QUEUE
   14 #define TC_HEADER_DRIVER_ENCRYPTED_IO_QUEUE
   15 
   16 #include "TCdefs.h"
   17 #include "Apidrvr.h"
   18 
   19 #if 0
   20 #   define TC_TRACE_IO_QUEUE
   21 #endif
   22 
   23 #define TC_ENC_IO_QUEUE_MAX_FRAGMENT_SIZE (256 * 1024)
   24 
   25 #define TC_ENC_IO_QUEUE_PREALLOCATED_ITEM_COUNT 8
   26 #define TC_ENC_IO_QUEUE_PREALLOCATED_IO_REQUEST_COUNT 16
   27 
   28 
   29 typedef struct EncryptedIoQueueBufferStruct
   30 {
   31     struct EncryptedIoQueueBufferStruct *NextBuffer;
   32 
   33     void *Address;
   34     ULONG Size;
   35     BOOL InUse;
   36 
   37 } EncryptedIoQueueBuffer;
   38 
   39 
   40 typedef struct
   41 {
   42     PDEVICE_OBJECT DeviceObject;
   43 
   44     KMUTEX BufferPoolMutex;
   45     EncryptedIoQueueBuffer *FirstPoolBuffer;
   46 
   47     CRYPTO_INFO *CryptoInfo;
   48 
   49     // File-handle-based IO
   50     HANDLE HostFileHandle;
   51     int64 VirtualDeviceLength;
   52     SECURITY_CLIENT_CONTEXT *SecurityClientContext;
   53 
   54     // Filter device
   55     BOOL IsFilterDevice;
   56     PDEVICE_OBJECT LowerDeviceObject;
   57     int64 EncryptedAreaStart;
   58     volatile int64 EncryptedAreaEnd;
   59     volatile BOOL EncryptedAreaEndUpdatePending;
   60     BOOL RemapEncryptedArea;
   61     int64 RemappedAreaOffset;
   62     int64 RemappedAreaDataUnitOffset;
   63     IO_REMOVE_LOCK RemoveLock;
   64 
   65     // Main tread
   66     PKTHREAD MainThread;
   67     LIST_ENTRY MainThreadQueue;
   68     KSPIN_LOCK MainThreadQueueLock;
   69     KEVENT MainThreadQueueNotEmptyEvent;
   70 
   71     // IO thread
   72     PKTHREAD IoThread;
   73     LIST_ENTRY IoThreadQueue;
   74     KSPIN_LOCK IoThreadQueueLock;
   75     KEVENT IoThreadQueueNotEmptyEvent;
   76 
   77     // Completion thread
   78     PKTHREAD CompletionThread;
   79     LIST_ENTRY CompletionThreadQueue;
   80     KSPIN_LOCK CompletionThreadQueueLock;
   81     KEVENT CompletionThreadQueueNotEmptyEvent;
   82 
   83     // Fragment buffers
   84     byte *FragmentBufferA;
   85     byte *FragmentBufferB;
   86     KEVENT FragmentBufferAFreeEvent;
   87     KEVENT FragmentBufferBFreeEvent;
   88 
   89     // Read-ahead buffer
   90     BOOL ReadAheadBufferValid;
   91     LARGE_INTEGER LastReadOffset;
   92     ULONG LastReadLength;
   93     LARGE_INTEGER ReadAheadOffset;
   94     ULONG ReadAheadLength;
   95     byte *ReadAheadBuffer;
   96     LARGE_INTEGER MaxReadAheadOffset;
   97 
   98     LONG OutstandingIoCount;
   99     KEVENT NoOutstandingIoEvent;
  100     LONG IoThreadPendingRequestCount;
  101 
  102     KEVENT PoolBufferFreeEvent;
  103 
  104     __int64 TotalBytesRead;
  105     __int64 TotalBytesWritten;
  106 
  107     volatile BOOL StartPending;
  108     volatile BOOL ThreadExitRequested;
  109 
  110     volatile BOOL Suspended;
  111     volatile BOOL SuspendPending;
  112     volatile BOOL StopPending;
  113 
  114     KEVENT QueueResumedEvent;
  115 
  116 #ifdef TC_TRACE_IO_QUEUE
  117     LARGE_INTEGER LastPerformanceCounter;
  118 #endif
  119 
  120     byte*  SecRegionData;
  121     SIZE_T SecRegionSize;
  122 }  EncryptedIoQueue;
  123 
  124 
  125 typedef struct
  126 {
  127     EncryptedIoQueue *Queue;
  128     PIRP OriginalIrp;
  129     BOOL Write;
  130     ULONG OriginalLength;
  131     LARGE_INTEGER OriginalOffset;
  132     NTSTATUS Status;
  133 
  134 #ifdef TC_TRACE_IO_QUEUE
  135     LARGE_INTEGER OriginalIrpOffset;
  136 #endif
  137 
  138 } EncryptedIoQueueItem;
  139 
  140 
  141 typedef struct
  142 {
  143     EncryptedIoQueueItem *Item;
  144 
  145     BOOL CompleteOriginalIrp;
  146     LARGE_INTEGER Offset;
  147     ULONG Length;
  148     int64 EncryptedOffset;
  149     ULONG EncryptedLength;
  150     byte *Data;
  151     byte *OrigDataBufferFragment;
  152 
  153     LIST_ENTRY ListEntry;
  154     LIST_ENTRY CompletionListEntry;
  155 } EncryptedIoRequest;
  156 
  157 
  158 NTSTATUS EncryptedIoQueueAddIrp (EncryptedIoQueue *queue, PIRP irp);
  159 BOOL EncryptedIoQueueIsRunning (EncryptedIoQueue *queue);
  160 BOOL EncryptedIoQueueIsSuspended (EncryptedIoQueue *queue);
  161 NTSTATUS EncryptedIoQueueResumeFromHold (EncryptedIoQueue *queue);
  162 NTSTATUS EncryptedIoQueueStart (EncryptedIoQueue *queue);
  163 NTSTATUS EncryptedIoQueueStop (EncryptedIoQueue *queue);
  164 NTSTATUS EncryptedIoQueueHoldWhenIdle (EncryptedIoQueue *queue, int64 timeout);
  165 
  166 
  167 #endif // TC_HEADER_DRIVER_ENCRYPTED_IO_QUEUE