Skip to content

Commit

Permalink
Consume latest source generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT committed May 26, 2022
1 parent 2d11979 commit a544b08
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 56 deletions.
2 changes: 1 addition & 1 deletion eng/tools/HelixTestRunner/ProcessUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace HelixTestRunner;

public static partial class ProcessUtil
{
[LibraryImportAttribute("libc", SetLastError = true, EntryPoint = "kill")]
[LibraryImport("libc", SetLastError = true, EntryPoint = "kill")]
private static partial int sys_kill(int pid, int sig);

public static Task CaptureDumpAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/HttpSys/src/NativeInterop/HttpApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal static unsafe partial class HttpApi

[LibraryImport(HTTPAPI, SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
internal static unsafe partial uint HttpCreateRequestQueue(HTTPAPI_VERSION version, string? pName,
UnsafeNclNativeMethods.SECURITY_ATTRIBUTES? pSecurityAttributes, HTTP_CREATE_REQUEST_QUEUE_FLAG flags, out HttpRequestQueueV2Handle pReqQueueHandle);
IntPtr pSecurityAttributes, HTTP_CREATE_REQUEST_QUEUE_FLAG flags, out HttpRequestQueueV2Handle pReqQueueHandle);

[LibraryImport(HTTPAPI, SetLastError = true)]
internal static unsafe partial uint HttpCloseRequestQueue(IntPtr pReqQueueHandle);
Expand Down
4 changes: 2 additions & 2 deletions src/Servers/HttpSys/src/NativeInterop/RequestQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private RequestQueue(string? requestQueueName, RequestQueueMode mode, ILogger lo
var statusCode = HttpApi.HttpCreateRequestQueue(
HttpApi.Version,
requestQueueName,
null,
IntPtr.Zero,
flags,
out var requestQueueHandle);

Expand All @@ -56,7 +56,7 @@ private RequestQueue(string? requestQueueName, RequestQueueMode mode, ILogger lo
statusCode = HttpApi.HttpCreateRequestQueue(
HttpApi.Version,
requestQueueName,
null,
IntPtr.Zero,
flags,
out requestQueueHandle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public async Task Server_CreateOrAttach_NoUrlPrefix_NewUrlPrefixWorks()
var statusCode = HttpApi.HttpCreateRequestQueue(
HttpApi.Version,
queueName,
null,
IntPtr.Zero,
0,
out requestQueueHandle);

Expand Down
2 changes: 1 addition & 1 deletion src/Servers/HttpSys/test/FunctionalTests/ServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task Server_ConnectExistingQueueName_Success(RequestQueueMode queue
var statusCode = HttpApi.HttpCreateRequestQueue(
HttpApi.Version,
queueName,
null,
IntPtr.Zero,
0,
out requestQueueHandle);

Expand Down
1 change: 1 addition & 0 deletions src/Servers/IIS/IIS/src/Core/IISConfigurationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Microsoft.AspNetCore.Server.IIS.Core;

[NativeMarshalling(typeof(Native))]
[StructLayout(LayoutKind.Sequential)]
internal struct IISConfigurationData
{
Expand Down
39 changes: 4 additions & 35 deletions src/Servers/IIS/IIS/src/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Microsoft.AspNetCore.HttpSys.Internal;
using Microsoft.AspNetCore.Server.IIS.Core;

Expand Down Expand Up @@ -89,13 +88,13 @@ private static unsafe partial int register_callbacks(NativeSafeHandle pInProcess
private static partial int http_set_managed_context(NativeSafeHandle pInProcessHandler, IntPtr pvManagedContext);

[LibraryImport(AspNetCoreModuleDll)]
private static partial int http_get_application_properties([MarshalUsing(typeof(IISConfigurationData.Native))] ref IISConfigurationData iiConfigData);
private static partial int http_get_application_properties(out IISConfigurationData iiConfigData);

[LibraryImport(AspNetCoreModuleDll)]
private static partial int http_get_server_variable(
NativeSafeHandle pInProcessHandler,
[MarshalAs(UnmanagedType.LPStr)] string variableName,
[MarshalUsing(typeof(BstrStringMarshaller))] out string value);
[MarshalAs(UnmanagedType.BStr)] out string value);

[LibraryImport(AspNetCoreModuleDll)]
private static partial int http_set_server_variable(
Expand Down Expand Up @@ -149,7 +148,7 @@ private static unsafe partial int http_websockets_write_bytes(
private static unsafe partial int http_response_set_known_header(NativeSafeHandle pInProcessHandler, int headerId, byte* pHeaderValue, ushort length, [MarshalAs(UnmanagedType.Bool)] bool fReplace);

[LibraryImport(AspNetCoreModuleDll)]
private static partial int http_get_authentication_information(NativeSafeHandle pInProcessHandler, [MarshalUsing(typeof(BstrStringMarshaller))] out string authType, out IntPtr token);
private static partial int http_get_authentication_information(NativeSafeHandle pInProcessHandler, [MarshalAs(UnmanagedType.BStr)] out string authType, out IntPtr token);

[LibraryImport(AspNetCoreModuleDll)]
private static unsafe partial int http_set_startup_error_page_content(byte* content, int contentLength);
Expand Down Expand Up @@ -228,8 +227,7 @@ public static void HttpSetManagedContext(NativeSafeHandle pInProcessHandler, Int

internal static IISConfigurationData HttpGetApplicationProperties()
{
var iisConfigurationData = new IISConfigurationData();
Validate(http_get_application_properties(ref iisConfigurationData));
Validate(http_get_application_properties(out IISConfigurationData iisConfigurationData));
return iisConfigurationData;
}

Expand Down Expand Up @@ -341,33 +339,4 @@ private static void Validate(int hr)
throw Marshal.GetExceptionForHR(hr)!;
}
}

/// <summary>
/// Marshaller for BSTR strings
/// </summary>
[CustomTypeMarshaller(typeof(string),
Features = CustomTypeMarshallerFeatures.UnmanagedResources | CustomTypeMarshallerFeatures.TwoStageMarshalling)]
internal ref struct BstrStringMarshaller
{
private IntPtr _allocated;

public BstrStringMarshaller(string? str)
{
_allocated = Marshal.StringToBSTR(str);
}

public IntPtr ToNativeValue() => _allocated;

public void FromNativeValue(IntPtr value) => _allocated = value;

public string? ToManaged() => Marshal.PtrToStringBSTR(_allocated);

public void FreeNative()
{
if (_allocated != IntPtr.Zero)
{
Marshal.FreeBSTR(_allocated);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="..\..\..\..\build\testsite.props" />

<PropertyGroup>
Expand All @@ -7,6 +7,7 @@
<DefineConstants>FORWARDCOMPAT</DefineConstants>
<CompileUsingReferenceAssemblies>false</CompileUsingReferenceAssemblies>
<ImplicitUsings>disable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Security.Principal;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -179,12 +180,12 @@ public void CompressedData(IApplicationBuilder builder)
});
}

[DllImport("kernel32.dll")]
static extern uint GetDllDirectory(uint nBufferLength, [Out] StringBuilder lpBuffer);
[LibraryImport("kernel32.dll", StringMarshalling = StringMarshalling.Utf16)]
private static partial uint GetDllDirectory(uint nBufferLength, [Out] char[] lpBuffer);

private async Task DllDirectory(HttpContext context)
{
var builder = new StringBuilder(1024);
var builder = new char[1024];
GetDllDirectory(1024, builder);
await context.Response.WriteAsync(builder.ToString());
}
Expand Down
11 changes: 0 additions & 11 deletions src/Shared/HttpSys/NativeInterop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,4 @@ internal unsafe struct TOKENBINDING_RESULT_LIST
public TOKENBINDING_RESULT_DATA* resultData;
}
}

// DACL related stuff

[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated natively")]
[StructLayout(LayoutKind.Sequential)]
internal struct SECURITY_ATTRIBUTES
{
public uint nLength;
public IntPtr lpSecurityDescriptor;
public int bInheritHandle;
}
}

0 comments on commit a544b08

Please sign in to comment.