cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

io.h (9011B)


      1/**
      2 * WinPR: Windows Portable Runtime
      3 * Asynchronous I/O Functions
      4 *
      5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *     http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 */
     19
     20#ifndef WINPR_IO_H
     21#define WINPR_IO_H
     22
     23#include <winpr/winpr.h>
     24#include <winpr/wtypes.h>
     25
     26#ifdef _WIN32
     27
     28#include <winioctl.h>
     29
     30#else
     31
     32#include <winpr/nt.h>
     33
     34typedef struct _OVERLAPPED
     35{
     36	ULONG_PTR Internal;
     37	ULONG_PTR InternalHigh;
     38	union {
     39		struct
     40		{
     41			DWORD Offset;
     42			DWORD OffsetHigh;
     43		};
     44		PVOID Pointer;
     45	};
     46	HANDLE hEvent;
     47} OVERLAPPED, *LPOVERLAPPED;
     48
     49typedef struct _OVERLAPPED_ENTRY
     50{
     51	ULONG_PTR lpCompletionKey;
     52	LPOVERLAPPED lpOverlapped;
     53	ULONG_PTR Internal;
     54	DWORD dwNumberOfBytesTransferred;
     55} OVERLAPPED_ENTRY, *LPOVERLAPPED_ENTRY;
     56
     57#ifdef __cplusplus
     58extern "C"
     59{
     60#endif
     61
     62	WINPR_API BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
     63	                                   LPDWORD lpNumberOfBytesTransferred, BOOL bWait);
     64
     65	WINPR_API BOOL GetOverlappedResultEx(HANDLE hFile, LPOVERLAPPED lpOverlapped,
     66	                                     LPDWORD lpNumberOfBytesTransferred, DWORD dwMilliseconds,
     67	                                     BOOL bAlertable);
     68
     69	WINPR_API BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer,
     70	                               DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
     71	                               LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
     72
     73	WINPR_API HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
     74	                                        ULONG_PTR CompletionKey,
     75	                                        DWORD NumberOfConcurrentThreads);
     76
     77	WINPR_API BOOL GetQueuedCompletionStatus(HANDLE CompletionPort,
     78	                                         LPDWORD lpNumberOfBytesTransferred,
     79	                                         PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,
     80	                                         DWORD dwMilliseconds);
     81
     82	WINPR_API BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort,
     83	                                           LPOVERLAPPED_ENTRY lpCompletionPortEntries,
     84	                                           ULONG ulCount, PULONG ulNumEntriesRemoved,
     85	                                           DWORD dwMilliseconds, BOOL fAlertable);
     86
     87	WINPR_API BOOL PostQueuedCompletionStatus(HANDLE CompletionPort,
     88	                                          DWORD dwNumberOfBytesTransferred,
     89	                                          ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped);
     90
     91	WINPR_API BOOL CancelIo(HANDLE hFile);
     92
     93	WINPR_API BOOL CancelIoEx(HANDLE hFile, LPOVERLAPPED lpOverlapped);
     94
     95	WINPR_API BOOL CancelSynchronousIo(HANDLE hThread);
     96
     97#ifdef __cplusplus
     98}
     99#endif
    100
    101#define DEVICE_TYPE ULONG
    102
    103#define FILE_DEVICE_BEEP 0x00000001
    104#define FILE_DEVICE_CD_ROM 0x00000002
    105#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
    106#define FILE_DEVICE_CONTROLLER 0x00000004
    107#define FILE_DEVICE_DATALINK 0x00000005
    108#define FILE_DEVICE_DFS 0x00000006
    109#define FILE_DEVICE_DISK 0x00000007
    110#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
    111#define FILE_DEVICE_FILE_SYSTEM 0x00000009
    112#define FILE_DEVICE_INPORT_PORT 0x0000000a
    113#define FILE_DEVICE_KEYBOARD 0x0000000b
    114#define FILE_DEVICE_MAILSLOT 0x0000000c
    115#define FILE_DEVICE_MIDI_IN 0x0000000d
    116#define FILE_DEVICE_MIDI_OUT 0x0000000e
    117#define FILE_DEVICE_MOUSE 0x0000000f
    118#define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
    119#define FILE_DEVICE_NAMED_PIPE 0x00000011
    120#define FILE_DEVICE_NETWORK 0x00000012
    121#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
    122#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
    123#define FILE_DEVICE_NULL 0x00000015
    124#define FILE_DEVICE_PARALLEL_PORT 0x00000016
    125#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
    126#define FILE_DEVICE_PRINTER 0x00000018
    127#define FILE_DEVICE_SCANNER 0x00000019
    128#define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
    129#define FILE_DEVICE_SERIAL_PORT 0x0000001b
    130#define FILE_DEVICE_SCREEN 0x0000001c
    131#define FILE_DEVICE_SOUND 0x0000001d
    132#define FILE_DEVICE_STREAMS 0x0000001e
    133#define FILE_DEVICE_TAPE 0x0000001f
    134#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
    135#define FILE_DEVICE_TRANSPORT 0x00000021
    136#define FILE_DEVICE_UNKNOWN 0x00000022
    137#define FILE_DEVICE_VIDEO 0x00000023
    138#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
    139#define FILE_DEVICE_WAVE_IN 0x00000025
    140#define FILE_DEVICE_WAVE_OUT 0x00000026
    141#define FILE_DEVICE_8042_PORT 0x00000027
    142#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
    143#define FILE_DEVICE_BATTERY 0x00000029
    144#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
    145#define FILE_DEVICE_MODEM 0x0000002b
    146#define FILE_DEVICE_VDM 0x0000002c
    147#define FILE_DEVICE_MASS_STORAGE 0x0000002d
    148#define FILE_DEVICE_SMB 0x0000002e
    149#define FILE_DEVICE_KS 0x0000002f
    150#define FILE_DEVICE_CHANGER 0x00000030
    151#define FILE_DEVICE_SMARTCARD 0x00000031
    152#define FILE_DEVICE_ACPI 0x00000032
    153#define FILE_DEVICE_DVD 0x00000033
    154#define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
    155#define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
    156#define FILE_DEVICE_DFS_VOLUME 0x00000036
    157#define FILE_DEVICE_SERENUM 0x00000037
    158#define FILE_DEVICE_TERMSRV 0x00000038
    159#define FILE_DEVICE_KSEC 0x00000039
    160#define FILE_DEVICE_FIPS 0x0000003A
    161#define FILE_DEVICE_INFINIBAND 0x0000003B
    162#define FILE_DEVICE_VMBUS 0x0000003E
    163#define FILE_DEVICE_CRYPT_PROVIDER 0x0000003F
    164#define FILE_DEVICE_WPD 0x00000040
    165#define FILE_DEVICE_BLUETOOTH 0x00000041
    166#define FILE_DEVICE_MT_COMPOSITE 0x00000042
    167#define FILE_DEVICE_MT_TRANSPORT 0x00000043
    168#define FILE_DEVICE_BIOMETRIC 0x00000044
    169#define FILE_DEVICE_PMI 0x00000045
    170
    171#define CTL_CODE(DeviceType, Function, Method, Access) \
    172	(((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
    173
    174#define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((DWORD)(ctrlCode & 0xFFFF0000)) >> 16)
    175
    176#define METHOD_FROM_CTL_CODE(ctrlCode) ((DWORD)(ctrlCode & 3))
    177
    178#define METHOD_BUFFERED 0
    179#define METHOD_IN_DIRECT 1
    180#define METHOD_OUT_DIRECT 2
    181#define METHOD_NEITHER 3
    182
    183#define FILE_ANY_ACCESS 0
    184#define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
    185#define FILE_READ_ACCESS (0x0001)
    186#define FILE_WRITE_ACCESS (0x0002)
    187
    188/*
    189 * WinPR I/O Manager Custom API
    190 */
    191
    192typedef HANDLE PDRIVER_OBJECT_EX;
    193typedef HANDLE PDEVICE_OBJECT_EX;
    194
    195WINPR_API NTSTATUS _IoCreateDeviceEx(PDRIVER_OBJECT_EX DriverObject, ULONG DeviceExtensionSize,
    196                                     PUNICODE_STRING DeviceName, DEVICE_TYPE DeviceType,
    197                                     ULONG DeviceCharacteristics, BOOLEAN Exclusive,
    198                                     PDEVICE_OBJECT_EX* DeviceObject);
    199
    200WINPR_API VOID _IoDeleteDeviceEx(PDEVICE_OBJECT_EX DeviceObject);
    201
    202#endif
    203
    204#ifdef _UWP
    205
    206#ifdef __cplusplus
    207extern "C"
    208{
    209#endif
    210
    211	WINPR_API BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
    212	                                   LPDWORD lpNumberOfBytesTransferred, BOOL bWait);
    213
    214	WINPR_API BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer,
    215	                               DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
    216	                               LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
    217
    218	WINPR_API HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
    219	                                        ULONG_PTR CompletionKey,
    220	                                        DWORD NumberOfConcurrentThreads);
    221
    222	WINPR_API BOOL GetQueuedCompletionStatus(HANDLE CompletionPort,
    223	                                         LPDWORD lpNumberOfBytesTransferred,
    224	                                         PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,
    225	                                         DWORD dwMilliseconds);
    226
    227	WINPR_API BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort,
    228	                                           LPOVERLAPPED_ENTRY lpCompletionPortEntries,
    229	                                           ULONG ulCount, PULONG ulNumEntriesRemoved,
    230	                                           DWORD dwMilliseconds, BOOL fAlertable);
    231
    232	WINPR_API BOOL PostQueuedCompletionStatus(HANDLE CompletionPort,
    233	                                          DWORD dwNumberOfBytesTransferred,
    234	                                          ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped);
    235
    236	WINPR_API BOOL CancelIo(HANDLE hFile);
    237
    238	WINPR_API BOOL CancelSynchronousIo(HANDLE hThread);
    239
    240#ifdef __cplusplus
    241}
    242#endif
    243
    244#endif
    245
    246/**
    247 * Extended API
    248 */
    249
    250#define ACCESS_FROM_CTL_CODE(ctrlCode) ((DWORD)((ctrlCode >> 14) & 0x3))
    251#define FUNCTION_FROM_CTL_CODE(ctrlCode) ((DWORD)((ctrlCode >> 2) & 0xFFF))
    252
    253#endif /* WINPR_IO_H */