Bug 8449

Summary: Definition of System.Threading.NativeOverlapped structure does not correspond to Win32 OVERLAPPED
Product: [Mono] Class Libraries Reporter: Alex <alexander_savov>
Component: SystemAssignee: Bugzilla <bugzilla>
Status: VERIFIED FIXED    
Severity: normal CC: jonp, masafa, mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: Untriaged   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:

Description Alex 2012-11-15 21:59:01 UTC
Hi,

NativeOverlapped should represent a Win32 OVERLAPPED structure. In Mono it is declared as follows

public struct NativeOverlapped {
	public IntPtr EventHandle;
	public IntPtr InternalHigh;
	public IntPtr InternalLow;
	public int OffsetHigh;
	public int OffsetLow;
	// additional fields
}

however Win32 OVERLAPPED is

typedef struct _OVERLAPPED {
  ULONG_PTR Internal;
  ULONG_PTR InternalHigh;
  union {
    struct {
      DWORD Offset;
      DWORD OffsetHigh;
    };
    PVOID  Pointer;
  };
  HANDLE    hEvent;
} OVERLAPPED, *LPOVERLAPPED;

therefore definition of NativeOverlapped should be something like

public struct NativeOverlapped
{ 
    public IntPtr  InternalLow; 
    public IntPtr  InternalHigh;
    public int     OffsetLow; 
    public int     OffsetHigh;
    public IntPtr  EventHandle;
    // additional fields
}


Win32 overlapped IO depends on NativeOverlapped, particularly the SerialPort class is affected - it is not possible to run concurrent reads and writes on serial ports. Please correct the order of fields of NativeOverlapped.
Comment 1 Jonathan Pryor 2012-11-15 23:38:07 UTC
For reference, the WinAPI documentation for OVERLAPPED:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684342(v=vs.85).aspx
Comment 2 Marek Safar 2012-11-20 07:04:59 UTC
Fixed in master