quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

ares_event_win32.h (5774B)


      1 /* MIT License
      2  *
      3  * Copyright (c) 2024 Brad House
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a copy
      6  * of this software and associated documentation files (the "Software"), to deal
      7  * in the Software without restriction, including without limitation the rights
      8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9  * copies of the Software, and to permit persons to whom the Software is
     10  * furnished to do so, subject to the following conditions:
     11  *
     12  * The above copyright notice and this permission notice (including the next
     13  * paragraph) shall be included in all copies or substantial portions of the
     14  * Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     22  * SOFTWARE.
     23  *
     24  * SPDX-License-Identifier: MIT
     25  */
     26 #ifndef __ARES_EVENT_WIN32_H
     27 #define __ARES_EVENT_WIN32_H
     28 
     29 #ifdef _WIN32
     30 #  ifdef HAVE_WINSOCK2_H
     31 #    include <winsock2.h>
     32 #  endif
     33 #  ifdef HAVE_WS2TCPIP_H
     34 #    include <ws2tcpip.h>
     35 #  endif
     36 #  ifdef HAVE_MSWSOCK_H
     37 #    include <mswsock.h>
     38 #  endif
     39 #  ifdef HAVE_WINDOWS_H
     40 #    include <windows.h>
     41 #  endif
     42 
     43 /* From winternl.h */
     44 
     45 /* If WDK is not installed and not using MinGW, provide the needed definitions
     46  */
     47 typedef LONG NTSTATUS;
     48 
     49 typedef struct _IO_STATUS_BLOCK {
     50   union {
     51     NTSTATUS Status;
     52     PVOID    Pointer;
     53   };
     54 
     55   ULONG_PTR Information;
     56 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
     57 
     58 typedef VOID(NTAPI *PIO_APC_ROUTINE)(PVOID            ApcContext,
     59                                      PIO_STATUS_BLOCK IoStatusBlock,
     60                                      ULONG            Reserved);
     61 
     62 /* From ntstatus.h */
     63 #  define STATUS_SUCCESS ((NTSTATUS)0x00000000)
     64 #  ifndef STATUS_PENDING
     65 #    define STATUS_PENDING ((NTSTATUS)0x00000103L)
     66 #  endif
     67 #  define STATUS_CANCELLED ((NTSTATUS)0xC0000120L)
     68 #  define STATUS_NOT_FOUND ((NTSTATUS)0xC0000225L)
     69 
     70 typedef struct _UNICODE_STRING {
     71   USHORT  Length;
     72   USHORT  MaximumLength;
     73   LPCWSTR Buffer;
     74 } UNICODE_STRING, *PUNICODE_STRING;
     75 
     76 typedef struct _OBJECT_ATTRIBUTES {
     77   ULONG           Length;
     78   HANDLE          RootDirectory;
     79   PUNICODE_STRING ObjectName;
     80   ULONG           Attributes;
     81   PVOID           SecurityDescriptor;
     82   PVOID           SecurityQualityOfService;
     83 } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES;
     84 
     85 #  ifndef FILE_OPEN
     86 #    define FILE_OPEN 0x00000001UL
     87 #  endif
     88 
     89 /* Not sure what headers might have these */
     90 #  define IOCTL_AFD_POLL 0x00012024
     91 
     92 #  define AFD_POLL_RECEIVE_BIT           0
     93 #  define AFD_POLL_RECEIVE               (1 << AFD_POLL_RECEIVE_BIT)
     94 #  define AFD_POLL_RECEIVE_EXPEDITED_BIT 1
     95 #  define AFD_POLL_RECEIVE_EXPEDITED     (1 << AFD_POLL_RECEIVE_EXPEDITED_BIT)
     96 #  define AFD_POLL_SEND_BIT              2
     97 #  define AFD_POLL_SEND                  (1 << AFD_POLL_SEND_BIT)
     98 #  define AFD_POLL_DISCONNECT_BIT        3
     99 #  define AFD_POLL_DISCONNECT            (1 << AFD_POLL_DISCONNECT_BIT)
    100 #  define AFD_POLL_ABORT_BIT             4
    101 #  define AFD_POLL_ABORT                 (1 << AFD_POLL_ABORT_BIT)
    102 #  define AFD_POLL_LOCAL_CLOSE_BIT       5
    103 #  define AFD_POLL_LOCAL_CLOSE           (1 << AFD_POLL_LOCAL_CLOSE_BIT)
    104 #  define AFD_POLL_CONNECT_BIT           6
    105 #  define AFD_POLL_CONNECT               (1 << AFD_POLL_CONNECT_BIT)
    106 #  define AFD_POLL_ACCEPT_BIT            7
    107 #  define AFD_POLL_ACCEPT                (1 << AFD_POLL_ACCEPT_BIT)
    108 #  define AFD_POLL_CONNECT_FAIL_BIT      8
    109 #  define AFD_POLL_CONNECT_FAIL          (1 << AFD_POLL_CONNECT_FAIL_BIT)
    110 #  define AFD_POLL_QOS_BIT               9
    111 #  define AFD_POLL_QOS                   (1 << AFD_POLL_QOS_BIT)
    112 #  define AFD_POLL_GROUP_QOS_BIT         10
    113 #  define AFD_POLL_GROUP_QOS             (1 << AFD_POLL_GROUP_QOS_BIT)
    114 
    115 #  define AFD_NUM_POLL_EVENTS 11
    116 #  define AFD_POLL_ALL        ((1 << AFD_NUM_POLL_EVENTS) - 1)
    117 
    118 typedef struct _AFD_POLL_HANDLE_INFO {
    119   HANDLE   Handle;
    120   ULONG    Events;
    121   NTSTATUS Status;
    122 } AFD_POLL_HANDLE_INFO, *PAFD_POLL_HANDLE_INFO;
    123 
    124 typedef struct _AFD_POLL_INFO {
    125   LARGE_INTEGER        Timeout;
    126   ULONG                NumberOfHandles;
    127   ULONG                Exclusive;
    128   AFD_POLL_HANDLE_INFO Handles[1];
    129 } AFD_POLL_INFO, *PAFD_POLL_INFO;
    130 
    131 /* Prototypes for dynamically loaded functions from ntdll.dll */
    132 typedef NTSTATUS(NTAPI *NtCancelIoFileEx_t)(HANDLE           FileHandle,
    133                                             PIO_STATUS_BLOCK IoRequestToCancel,
    134                                             PIO_STATUS_BLOCK IoStatusBlock);
    135 typedef NTSTATUS(NTAPI *NtDeviceIoControlFile_t)(
    136   HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext,
    137   PIO_STATUS_BLOCK IoStatusBlock, ULONG IoControlCode, PVOID InputBuffer,
    138   ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength);
    139 
    140 typedef NTSTATUS(NTAPI *NtCreateFile_t)(
    141   PHANDLE FileHandle, ACCESS_MASK DesiredAccess,
    142   POBJECT_ATTRIBUTES ObjectAttributes, PIO_STATUS_BLOCK IoStatusBlock,
    143   PLARGE_INTEGER AllocationSize, ULONG FileAttributes, ULONG ShareAccess,
    144   ULONG CreateDisposition, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength);
    145 
    146 /* On UWP/Windows Store, these definitions aren't there for some reason */
    147 #  ifndef SIO_BSP_HANDLE_POLL
    148 #    define SIO_BSP_HANDLE_POLL 0x4800001D
    149 #  endif
    150 
    151 #  ifndef SIO_BASE_HANDLE
    152 #    define SIO_BASE_HANDLE 0x48000022
    153 #  endif
    154 
    155 #  ifndef HANDLE_FLAG_INHERIT
    156 #    define HANDLE_FLAG_INHERIT 0x00000001
    157 #  endif
    158 
    159 #endif /* _WIN32 */
    160 
    161 #endif /* __ARES_EVENT_WIN32_H */