Updating cswin32 package for HttpSys & IIS#65516
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the repo’s Microsoft.Windows.CsWin32 dependency and adjusts HttpSys interop call sites (and a functional test) to use the newer generated APIs/overloads instead of older signatures and hardcoded constants.
Changes:
- Bump
Microsoft.Windows.CsWin32to0.3.269. - Modernize HttpSys P/Invoke call sites to newer overloads (Span/out-based signatures, fewer optional parameters).
- Replace a hardcoded security info flag in a functional test with the typed
OBJECT_SECURITY_INFORMATIONenum.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs | Updates GetSecurityInfo usage to new signature and typed security-info enum. |
| src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs | Switches to newer HttpSendResponseEntityBody overload. |
| src/Servers/HttpSys/src/RequestProcessing/RequestStream.cs | Switches receive-body call to Span/out overload. |
| src/Servers/HttpSys/src/RequestProcessing/RequestContext.cs | Wraps cancellation P/Invoke in unsafe for updated signature requirements. |
| src/Servers/HttpSys/src/NativeInterop/RequestQueue.cs | Updates queue property setters to pass property values via ReadOnlySpan<byte>. |
| src/Servers/HttpSys/src/HttpSysListener.cs | Updates HttpSendHttpResponse call to use out bytes-written parameter. |
| eng/Versions.props | Updates the central CsWin32 version property. |
| var statusCode = PInvoke.HttpCancelHttpRequest(Server.RequestQueue.Handle, | ||
| _requestId.Value, default); | ||
| uint statusCode; | ||
| unsafe |
There was a problem hiding this comment.
new overload has this signature:
internal static unsafe uint HttpCancelHttpRequest(
SafeHandle RequestQueueHandle,
ulong RequestId,
[Optional] NativeOverlapped* Overlapped)and default arg value corresponds to the unsafe pointer, so has to be called from unsafe context.
Old API was safe:
internal static unsafe uint HttpCancelHttpRequest(
SafeHandle RequestQueueHandle,
ulong RequestId,
NativeOverlapped? Overlapped)There was a problem hiding this comment.
I moved unsafe to the method declaration - it look prettier now
| (uint)size, | ||
| &extraDataRead, | ||
| default); | ||
| buffer.AsSpan(offset, size), |
There was a problem hiding this comment.
Is the generator creating code to pin this buffer now?
There was a problem hiding this comment.
yes, that is pinned. Below is the generated code. See fixed (byte* EntityBufferLocal = EntityBuffer).
/// <inheritdoc cref="HttpReceiveRequestEntityBody(winmdroot.Foundation.HANDLE, ulong, uint, void*, uint, uint*, global::System.Threading.NativeOverlapped*)"/>
[SupportedOSPlatform("windows6.0.6000")]
internal static unsafe uint HttpReceiveRequestEntityBody(SafeHandle RequestQueueHandle, ulong RequestId, uint Flags, Span<byte> EntityBuffer, out uint BytesReturned, [Optional] global::System.Threading.NativeOverlapped* Overlapped)
{
bool RequestQueueHandleAddRef = false;
try
{
fixed (uint* BytesReturnedLocal = &BytesReturned)
{
fixed (byte* EntityBufferLocal = EntityBuffer)
{
winmdroot.Foundation.HANDLE RequestQueueHandleLocal;
if (RequestQueueHandle is object)
{
RequestQueueHandle.DangerousAddRef(ref RequestQueueHandleAddRef);
RequestQueueHandleLocal = (winmdroot.Foundation.HANDLE)RequestQueueHandle.DangerousGetHandle();
}
else
throw new ArgumentNullException(nameof(RequestQueueHandle));
uint __result = PInvoke.HttpReceiveRequestEntityBody(RequestQueueHandleLocal, RequestId, Flags, (void* )EntityBufferLocal, (uint )EntityBuffer.Length, BytesReturnedLocal, Overlapped);
return __result;
}
}
}
finally
{
if (RequestQueueHandleAddRef)
RequestQueueHandle.DangerousRelease();
}
}There was a problem hiding this comment.
still simplified unsafe here
We've been running on an old version of the package for a while, updated to the latest one and fixed build issues (used new APIs where possible)
Related #63686