Browse Source

upgrade cswin32 + fix build (#65516)

Korolev Dmitry 1 week ago
parent
commit
db50e77917

+ 1 - 1
eng/Versions.props

@@ -164,7 +164,7 @@
     <MicrosoftIdentityWebGraphServiceClientVersion>3.14.1</MicrosoftIdentityWebGraphServiceClientVersion>
     <MicrosoftIdentityWebUIVersion>3.14.1</MicrosoftIdentityWebUIVersion>
     <MicrosoftIdentityWebDownstreamApiVersion>3.14.1</MicrosoftIdentityWebDownstreamApiVersion>
-    <MicrosoftWindowsCsWin32Version>0.3.46-beta</MicrosoftWindowsCsWin32Version>
+    <MicrosoftWindowsCsWin32Version>0.3.269</MicrosoftWindowsCsWin32Version>
     <MessagePackAnalyzerVersion>$(MessagePackVersion)</MessagePackAnalyzerVersion>
     <MoqVersion>4.10.0</MoqVersion>
     <MonoCecilVersion>0.11.2</MonoCecilVersion>

+ 1 - 2
src/Servers/HttpSys/src/HttpSysListener.cs

@@ -344,7 +344,6 @@ internal sealed partial class HttpSysListener : IDisposable
 
         httpResponse.Base.StatusCode = checked((ushort)httpStatusCode);
         var statusDescription = ReasonPhrases.GetReasonPhrase(httpStatusCode);
-        uint dataWritten = 0;
         uint statusCode;
 
         bytes = allocator.GetHeaderEncodedBytes(statusDescription, out bytesLength);
@@ -367,7 +366,7 @@ internal sealed partial class HttpSysListener : IDisposable
             0,
             httpResponse,
             null,
-            &dataWritten,
+            out _,
             null,
             null);
         if (statusCode != ErrorCodes.ERROR_SUCCESS)

+ 3 - 2
src/Servers/HttpSys/src/NativeInterop/RequestQueue.cs

@@ -147,7 +147,7 @@ internal sealed partial class RequestQueue
 
         var result = PInvoke.HttpSetRequestQueueProperty(Handle,
             HTTP_SERVER_PROPERTY.HttpServerQueueLengthProperty,
-            &length, (uint)Marshal.SizeOf<long>());
+            new ReadOnlySpan<byte>(&length, sizeof(long)));
 
         if (result != 0)
         {
@@ -161,9 +161,10 @@ internal sealed partial class RequestQueue
         Debug.Assert(Created);
         CheckDisposed();
 
+        var verbosityLong = (long)verbosity;
         var result = PInvoke.HttpSetRequestQueueProperty(Handle,
             HTTP_SERVER_PROPERTY.HttpServer503VerbosityProperty,
-            &verbosity, (uint)Marshal.SizeOf<long>());
+            new ReadOnlySpan<byte>(&verbosityLong, sizeof(long)));
 
         if (result != 0)
         {

+ 2 - 3
src/Servers/HttpSys/src/RequestProcessing/RequestContext.cs

@@ -192,7 +192,7 @@ internal partial class RequestContext : NativeRequestContext, IThreadPoolWorkIte
     }
 
     // The request is being aborted, but large writes may be in progress. Cancel them.
-    internal void ForceCancelRequest()
+    internal unsafe void ForceCancelRequest()
     {
         try
         {
@@ -202,8 +202,7 @@ internal partial class RequestContext : NativeRequestContext, IThreadPoolWorkIte
                 return;
             }
 
-            var statusCode = PInvoke.HttpCancelHttpRequest(Server.RequestQueue.Handle,
-                _requestId.Value, default);
+            var statusCode = PInvoke.HttpCancelHttpRequest(Server.RequestQueue.Handle, _requestId.Value, default);
 
             // Either the connection has already dropped, or the last write is in progress.
             // The requestId becomes invalid as soon as the last Content-Length write starts.

+ 9 - 20
src/Servers/HttpSys/src/RequestProcessing/RequestStream.cs

@@ -120,32 +120,21 @@ internal sealed partial class RequestStream : Stream
 
         if (_dataChunkIndex == -1 && dataRead == 0)
         {
-            uint statusCode = 0;
-            uint extraDataRead = 0;
-
             // the http.sys team recommends that we limit the size to 128kb
             if (size > MaxReadSize)
             {
                 size = MaxReadSize;
             }
 
-            fixed (byte* pBuffer = buffer)
-            {
-                // issue unmanaged blocking call
-
-                uint flags = 0;
-
-                statusCode = PInvoke.HttpReceiveRequestEntityBody(
-                    RequestQueueHandle,
-                    RequestId,
-                    flags,
-                    (pBuffer + offset),
-                    (uint)size,
-                    &extraDataRead,
-                    default);
-
-                dataRead += extraDataRead;
-            }
+            uint flags = 0;
+            var statusCode = PInvoke.HttpReceiveRequestEntityBody(
+                RequestQueueHandle,
+                RequestId,
+                flags,
+                buffer.AsSpan(offset, size),
+                out var extraDataRead);
+
+            dataRead += extraDataRead;
 
             // Zero-byte reads
             if (statusCode == ErrorCodes.ERROR_MORE_DATA && size == 0)

+ 1 - 8
src/Servers/HttpSys/src/RequestProcessing/ResponseBody.cs

@@ -151,14 +151,7 @@ internal sealed partial class ResponseBody : Stream
             }
             else
             {
-                statusCode = PInvoke.HttpSendResponseEntityBody(
-                    RequestQueueHandle,
-                    RequestId,
-                    flags,
-                    dataChunks,
-                    null,
-                    null,
-                    null);
+                statusCode = PInvoke.HttpSendResponseEntityBody(RequestQueueHandle, RequestId, flags, dataChunks);
             }
         }
         finally

+ 7 - 8
src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs

@@ -311,17 +311,16 @@ public class DelegateTests : LoggedTest
         AssertPermissions(destination.Queue.Handle);
         unsafe void AssertPermissions(SafeHandle handle)
         {
-            PSECURITY_DESCRIPTOR pSecurityDescriptor = new();
-
             WIN32_ERROR result = PInvoke.GetSecurityInfo(
                 handle,
                 Windows.Win32.Security.Authorization.SE_OBJECT_TYPE.SE_KERNEL_OBJECT,
-                4, // DACL_SECURITY_INFORMATION
-                null,
-                null,
-                null,
-                null,
-                &pSecurityDescriptor);
+                OBJECT_SECURITY_INFORMATION.DACL_SECURITY_INFORMATION,
+                out _,
+                out _,
+                out _,
+                out _,
+                out var pSecurityDescriptor);
+            Assert.Equal(WIN32_ERROR.ERROR_SUCCESS, result);
 
             var length = (int)PInvoke.GetSecurityDescriptorLength(pSecurityDescriptor);