Revert buffer alignment in NativeRequestContext

The buffer alignment will be set to zero so that WebListener will work
properly in all environment except ARM
This commit is contained in:
Troy Dai 2016-09-01 09:45:46 -07:00
parent b31ec7d7a7
commit 735366ff3f
1 changed files with 11 additions and 3 deletions

View File

@ -132,10 +132,18 @@ namespace Microsoft.Net.Http.Server
_nativeOverlapped = new SafeNativeOverlapped(boundHandle,
boundHandle.AllocateNativeOverlapped(AsyncAcceptContext.IOCallback, _acceptResult, _backingBuffer));
// HttpReceiveHttpRequest expects the request pointer to be 8-byte-aligned or it fails. On ARM
// CLR creates buffers that are 4-byte-aligned so we need force 8-byte alignment.
var requestAddress = Marshal.UnsafeAddrOfPinnedArrayElement(_backingBuffer, 0);
_bufferAlignment = (int)(requestAddress.ToInt64() & 0x07);
// TODO:
// Apparently the HttpReceiveHttpRequest memory alignment requirements for non - ARM processors
// are different than for ARM processors. We have seen 4 - byte - aligned buffers allocated on
// virtual x64/x86 machines which were accepted by HttpReceiveHttpRequest without errors. In
// these cases the buffer alignment may cause reading values at invalid offset. Setting buffer
// alignment to 0 for now.
//
// _bufferAlignment = (int)(requestAddress.ToInt64() & 0x07);
_bufferAlignment = 0;
_nativeRequest = (HttpApi.HTTP_REQUEST*)(requestAddress + _bufferAlignment);
}