| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | |
| 6 | /*============================================================ |
| 7 | ** |
| 8 | ** Header: COMNativeOverlapped.h |
| 9 | ** |
| 10 | ** Purpose: Native methods for allocating and freeing NativeOverlapped |
| 11 | ** |
| 12 | |
| 13 | ** |
| 14 | ===========================================================*/ |
| 15 | |
| 16 | #ifndef _OVERLAPPED_H |
| 17 | #define _OVERLAPPED_H |
| 18 | |
| 19 | struct NATIVEOVERLAPPED_AND_HANDLE |
| 20 | { |
| 21 | OVERLAPPED m_overlapped; |
| 22 | OBJECTHANDLE m_handle; |
| 23 | }; |
| 24 | |
| 25 | // This should match the managed Overlapped object. |
| 26 | // If you make any change here, you need to change the managed part Overlapped. |
| 27 | class OverlappedDataObject : public Object |
| 28 | { |
| 29 | public: |
| 30 | // OverlappedDataObject is very special. An async pin handle keeps it alive. |
| 31 | // During GC, we also make sure |
| 32 | // 1. m_userObject itself does not move if m_userObject is not array |
| 33 | // 2. Every object pointed by m_userObject does not move if m_userObject is array |
| 34 | OBJECTREF m_asyncResult; |
| 35 | OBJECTREF m_callback; |
| 36 | OBJECTREF m_overlapped; |
| 37 | OBJECTREF m_userObject; |
| 38 | LPOVERLAPPED m_pNativeOverlapped; |
| 39 | ULONG_PTR m_eventHandle; |
| 40 | int m_offsetLow; |
| 41 | int m_offsetHigh; |
| 42 | |
| 43 | #ifndef DACCESS_COMPILE |
| 44 | static OverlappedDataObject* GetOverlapped(LPOVERLAPPED nativeOverlapped) |
| 45 | { |
| 46 | LIMITED_METHOD_CONTRACT; |
| 47 | STATIC_CONTRACT_SO_TOLERANT; |
| 48 | |
| 49 | _ASSERTE (nativeOverlapped != NULL); |
| 50 | return (OverlappedDataObject*)OBJECTREFToObject(ObjectFromHandle(((NATIVEOVERLAPPED_AND_HANDLE*)nativeOverlapped)->m_handle)); |
| 51 | } |
| 52 | |
| 53 | // Return the raw OverlappedDataObject* without going into cooperative mode for tracing |
| 54 | static OverlappedDataObject* GetOverlappedForTracing(LPOVERLAPPED nativeOverlapped) |
| 55 | { |
| 56 | LIMITED_METHOD_CONTRACT; |
| 57 | STATIC_CONTRACT_SO_TOLERANT; |
| 58 | |
| 59 | _ASSERTE(nativeOverlapped != NULL); |
| 60 | return *(OverlappedDataObject**)(((NATIVEOVERLAPPED_AND_HANDLE*)nativeOverlapped)->m_handle); |
| 61 | } |
| 62 | #endif // DACCESS_COMPILE |
| 63 | }; |
| 64 | |
| 65 | #ifdef USE_CHECKED_OBJECTREFS |
| 66 | |
| 67 | typedef REF<OverlappedDataObject> OVERLAPPEDDATAREF; |
| 68 | #define ObjectToOVERLAPPEDDATAREF(obj) (OVERLAPPEDDATAREF(obj)) |
| 69 | #define OVERLAPPEDDATAREFToObject(objref) (OBJECTREFToObject (objref)) |
| 70 | |
| 71 | #else |
| 72 | |
| 73 | typedef OverlappedDataObject* OVERLAPPEDDATAREF; |
| 74 | #define ObjectToOVERLAPPEDDATAREF(obj) ((OverlappedDataObject*) (obj)) |
| 75 | #define OVERLAPPEDDATAREFToObject(objref) ((OverlappedDataObject*) (objref)) |
| 76 | |
| 77 | #endif |
| 78 | |
| 79 | FCDECL3(void, CheckVMForIOPacket, LPOVERLAPPED* lpOverlapped, DWORD* errorCode, DWORD* numBytes); |
| 80 | FCDECL1(LPOVERLAPPED, AllocateNativeOverlapped, OverlappedDataObject* overlapped); |
| 81 | FCDECL1(void, FreeNativeOverlapped, LPOVERLAPPED lpOverlapped); |
| 82 | FCDECL1(OverlappedDataObject*, GetOverlappedFromNative, LPOVERLAPPED lpOverlapped); |
| 83 | |
| 84 | #endif |
| 85 | |