Skip to content

Updating cswin32 package for HttpSys & IIS#65516

Merged
DeagleGross merged 3 commits intodotnet:mainfrom
DeagleGross:dmkorolev/cswin32-update
Feb 24, 2026
Merged

Updating cswin32 package for HttpSys & IIS#65516
DeagleGross merged 3 commits intodotnet:mainfrom
DeagleGross:dmkorolev/cswin32-update

Conversation

@DeagleGross
Copy link
Copy Markdown
Member

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

Copilot AI review requested due to automatic review settings February 23, 2026 17:06
@DeagleGross DeagleGross self-assigned this Feb 23, 2026
@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Feb 23, 2026
@DeagleGross DeagleGross enabled auto-merge (squash) February 23, 2026 17:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.CsWin32 to 0.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_INFORMATION enum.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed now?

Copy link
Copy Markdown
Member Author

@DeagleGross DeagleGross Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved unsafe to the method declaration - it look prettier now

(uint)size,
&extraDataRead,
default);
buffer.AsSpan(offset, size),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the generator creating code to pin this buffer now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
	}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still simplified unsafe here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants