Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ else()
add_link_options(-Wno-unused-command-line-argument)
add_link_options(-Wl,-error-limit=0)

add_link_options(-nostdlib)
add_link_options(-lbulkmemory)
add_link_options(-lstubs)
add_link_options(-lc)
add_link_options(-lmalloc)
add_link_options(-lcompiler_rt)
add_link_options(-lc++)
add_link_options(-lc++abi)
add_link_options(-lunwind)

add_compile_options(-fwasm-exceptions)
add_compile_options(-mbulk-memory)
add_compile_options(-msimd128)
Expand Down
6 changes: 5 additions & 1 deletion eng/native/tryrun.browser.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# Automatically applied when building for browser-wasm. No special flags needed:
# ./build.sh -subset clr.runtime -os browser -arch wasm -c Debug
#
# OVERRIDES:
# We don't want to use all emulators which are available in Emscripten.
# - HAVE_SYS_SOCKET_H
#
# VERSION TRACKING:
# The TRYRUN_BROWSER_EMSCRIPTEN_VERSION variable at the top of this file tracks
# which Emscripten version this cache was generated for. The build system
Expand Down Expand Up @@ -326,7 +330,7 @@ set(HAVE_SYS_POLL_H "" CACHE INTERNAL "")
set(HAVE_SYS_PROCINFO_H "" CACHE INTERNAL "")
set(HAVE_SYS_PTRACE_H "" CACHE INTERNAL "")
set(HAVE_SYS_SDT_H "" CACHE INTERNAL "")
set(HAVE_SYS_SOCKET_H 1 CACHE INTERNAL "")
set(HAVE_SYS_SOCKET_H "" CACHE INTERNAL "")
set(HAVE_SYS_SOCKIO_H "" CACHE INTERNAL "")
set(HAVE_SYS_STATFS_H 1 CACHE INTERNAL "")
set(HAVE_SYS_STATVFS_H 1 CACHE INTERNAL "")
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/clrdefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ endif(FEATURE_EVENTSOURCE_XPLAT)
if(NOT CLR_CMAKE_TARGET_NETBSD AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
add_definitions(-DFEATURE_HIJACK)
endif(NOT CLR_CMAKE_TARGET_NETBSD AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
if(FEATURE_SINGLE_THREADED)
add_definitions(-DFEATURE_SINGLE_THREADED)
endif(FEATURE_SINGLE_THREADED)
if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386 OR CLR_CMAKE_TARGET_ARCH_ARM64))
add_definitions(-DFEATURE_INTEROP_DEBUGGING)
endif (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386 OR CLR_CMAKE_TARGET_ARCH_ARM64))
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ endif(CLR_CMAKE_TARGET_APPLE)
if (FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
add_definitions(-DFEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
endif(FEATURE_ENABLE_NO_ADDRESS_SPACE_RANDOMIZATION)
if(FEATURE_SINGLE_THREADED)
add_definitions(-DFEATURE_SINGLE_THREADED)
endif(FEATURE_SINGLE_THREADED)
add_definitions(-DLP64COMPATIBLE)
add_definitions(-DCORECLR)
add_definitions(-DPIC)
Expand Down
72 changes: 72 additions & 0 deletions src/libraries/Common/src/System/Net/SocketAddressPal.Browser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers.Binary;
using System.Net.Sockets;

namespace System.Net
{
internal static class SocketAddressPal
{
public const int IPv6AddressSize = 28;
public const int IPv4AddressSize = 16;
public const int UdsAddressSize = 110;
public const int MaxAddressSize = 128;

public static AddressFamily GetAddressFamily(ReadOnlySpan<byte> buffer)
{
return (AddressFamily)BinaryPrimitives.ReadUInt16LittleEndian(buffer);
}

public static void SetAddressFamily(Span<byte> buffer, AddressFamily family)
{
if ((int)(family) > ushort.MaxValue)
{
// For legacy values family maps directly to Winsock value.
// Other values will need mapping if/when supported.
throw new PlatformNotSupportedException();
}

BinaryPrimitives.WriteUInt16LittleEndian(buffer, (ushort)family);
}

public static ushort GetPort(ReadOnlySpan<byte> buffer)
=> BinaryPrimitives.ReadUInt16BigEndian(buffer.Slice(2));

public static void SetPort(Span<byte> buffer, ushort port)
=> BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(2), port);

public static uint GetIPv4Address(ReadOnlySpan<byte> buffer)
=> BinaryPrimitives.ReadUInt32LittleEndian(buffer.Slice(4));

public static void GetIPv6Address(ReadOnlySpan<byte> buffer, Span<byte> address, out uint scope)
{
buffer.Slice(8, address.Length).CopyTo(address);
scope = BinaryPrimitives.ReadUInt32LittleEndian(buffer.Slice(24));
}

public static void SetIPv4Address(Span<byte> buffer, uint address)
{
BinaryPrimitives.WriteUInt32LittleEndian(buffer.Slice(4), address);
}

public static void SetIPv6Address(Span<byte> buffer, Span<byte> address, uint scope)
{
// No handling for Flow Information
BinaryPrimitives.WriteUInt32LittleEndian(buffer.Slice(4), 0);

// Scope serialization
BinaryPrimitives.WriteUInt32LittleEndian(buffer.Slice(24), scope);

// Address serialization
address.CopyTo(buffer.Slice(8));
}

public static void Clear(Span<byte> buffer)
{
AddressFamily family = GetAddressFamily(buffer);
buffer.Clear();
SetAddressFamily(buffer, family);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix' or '$(TargetPlatformIdentifier)' == 'browser' or '$(TargetPlatformIdentifier)' == 'wasi'">
<Compile Include="System\Net\SocketException.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Unix.cs"
Link="Common\System\Net\SocketAddressPal.Unix.cs" />
Link="Common\System\Net\SocketAddressPal.Unix.cs"
Condition="'$(TargetPlatformIdentifier)' != 'browser'" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketErrorPal.Unix.cs"
Link="Common\System\Net\Sockets\SocketErrorPal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Expand Down Expand Up @@ -162,6 +163,11 @@
Link="Common\System\Net\NetworkInformation\InterfaceInfoPal.Browser.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'browser'">
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Browser.cs"
Link="Common\System\Net\SocketAddressPal.Browser.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Primitives\src\Microsoft.Win32.Primitives.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\src\System.Collections.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
<Compile Include="..\..\src\System\Net\SocketException.Unix.cs"
Link="ProductionCode\System\Net\SocketException.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Unix.cs"
Link="Common\System\Net\SocketAddressPal.Unix.cs" />
Link="Common\System\Net\SocketAddressPal.Unix.cs"
Condition="'$(TargetPlatformIdentifier)' != 'browser'" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketErrorPal.Unix.cs"
Link="Common\System\Net\Sockets\SocketErrorPal.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Expand All @@ -105,7 +106,12 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.IPAddress.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.IPAddress.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SocketAddress.cs"
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.SocketAddress.cs" />
Link="ProductionCode\Common\Interop\Unix\System.Native\Interop.SocketAddress.cs"
Condition="'$(TargetPlatformIdentifier)' != 'browser'" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'browser'">
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Browser.cs"
Link="Common\System\Net\SocketAddressPal.Browser.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'unix'">
<Compile Include="InterfaceInfoPalTest.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-wasi;$(NetCoreAppCurrent)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi;$(NetCoreAppCurrent)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- SYSTEM_NET_SOCKETS_DLL is required to allow source-level code sharing for types defined within the
System.Net.Internals namespace. -->
Expand All @@ -12,12 +12,12 @@
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.SystemNetSockets_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == 'browser' or '$(TargetPlatformIdentifier)' == ''">SR.SystemNetSockets_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
<IsApplePlatform Condition="'$(TargetPlatformIdentifier)' == 'osx' or '$(TargetPlatformIdentifier)' == 'ios' or '$(TargetPlatformIdentifier)' == 'tvos'">true</IsApplePlatform>
<DefineConstants Condition="'$(IsApplePlatform)' == 'true'">$(DefineConstants);SYSTEM_NET_SOCKETS_APPLE_PLATFROM</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'browser'">
<!-- All configurations -->
<Compile Include="System\Net\Sockets\ConnectAlgorithm.cs" />
<Compile Include="System\Net\Sockets\SocketReceiveFromResult.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/cfgdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <glib.h>
#include <mono/metadata/class-internals.h>

#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
Expand Down
5 changes: 3 additions & 2 deletions src/mono/mono/profiler/aot.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#ifndef HOST_WIN32
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#else
#endif
#ifdef HOST_WIN32
#define sleep(t) Sleep((t) * 1000)
#endif
#include <glib.h>
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/profiler/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include <errno.h>
#include <glib.h>

#ifndef HOST_WIN32
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifndef HOST_WIN32
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HOST_WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/profiler/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#ifndef HOST_WIN32
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifndef DISABLE_LOG_PROFILER_GZ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ public async Task ExtraEmccFlagsSetButNoRealChange(Configuration config, bool ao

var newStat = StatFilesAfterRebuild(pathsDict);
CompareStat(originalStat, newStat, pathsDict);


// check that emscripten emulator for sockets and pipe was trimmed from dotnet.native.js
if (config == Configuration.Release)
{
Assert.True(newStat.TryGetValue("dotnet.native.js", out var dotnetNativeJsStat));
var dotnetNativeJs = File.ReadAllText(dotnetNativeJsStat.FullPath);
Assert.DoesNotContain("var SOCKFS", dotnetNativeJs);
Assert.DoesNotContain("var PIPEFS", dotnetNativeJs);
}

// cflags: pinvoke get's compiled, but doesn't overwrite pinvoke.o
// and thus doesn't cause relinking
TestUtils.AssertSubstring("pinvoke.c -> pinvoke.o", output, contains: extraCFlags.Length > 0);
Expand Down
22 changes: 0 additions & 22 deletions src/native/corehost/browserhost/libBrowserHost.footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,6 @@ function libBrowserHostFactory() {

autoAddDeps(mergeBrowserHost, "$BROWSER_HOST");
addToLibrary(mergeBrowserHost);

function trim() {
return -1;
}

// TODO-WASM: fix PAL https://github.com/dotnet/runtime/issues/122506
if (LibraryManager.library.__syscall_pipe) {
LibraryManager.library.__syscall_pipe = trim;
delete LibraryManager.library.__syscall_pipe__deps;
}
if (LibraryManager.library.__syscall_connect) {
LibraryManager.library.__syscall_connect = trim;
delete LibraryManager.library.__syscall_connect__deps;
}
if (LibraryManager.library.__syscall_sendto) {
LibraryManager.library.__syscall_sendto = trim;
delete LibraryManager.library.__syscall_sendto__deps;
}
if (LibraryManager.library.__syscall_socket) {
LibraryManager.library.__syscall_socket = trim;
delete LibraryManager.library.__syscall_socket__deps;
}
}

libBrowserHostFactory();
12 changes: 9 additions & 3 deletions src/native/libs/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ endif ()

set(NATIVE_SOURCES
pal_errno.c
pal_interfaceaddresses.c
pal_io.c
pal_maphardwaretype.c
pal_memory.c
pal_networking.c
pal_networkstatistics.c
pal_random.c
pal_runtimeinformation.c
pal_string.c
Expand All @@ -24,7 +21,10 @@ set(NATIVE_SOURCES
if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
list (APPEND NATIVE_SOURCES
pal_dynamicload.c
pal_interfaceaddresses.c
pal_mount.c
pal_networking.c
pal_networkstatistics.c
pal_process.c
pal_signal.c
pal_threading.c
Expand All @@ -33,7 +33,10 @@ if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
elseif (CLR_CMAKE_TARGET_BROWSER)
list (APPEND NATIVE_SOURCES
pal_dynamicload_wasm.c
pal_interfaceaddresses_browser.c
pal_mount.c
pal_networking_browser.c
pal_networkstatistics_wasm.c
pal_process.c
pal_signal_wasm.c
pal_threading.c
Expand All @@ -42,7 +45,10 @@ elseif (CLR_CMAKE_TARGET_BROWSER)
else() # WASI
list (APPEND NATIVE_SOURCES
pal_dynamicload_wasm.c
pal_interfaceaddresses.c
pal_mount_wasi.c
pal_networking.c
pal_networkstatistics_wasm.c
pal_process_wasi.c
pal_signal_wasm.c
pal_threading_wasi.c
Expand Down
48 changes: 48 additions & 0 deletions src/native/libs/System.Native/pal_interfaceaddresses_browser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Stub implementations of interface address functions for browser target.

#include "pal_config.h"
#include "pal_interfaceaddresses.h"
#include "pal_utilities.h"

#include <errno.h>
#include <string.h>
#include <stdlib.h>

int32_t SystemNative_EnumerateInterfaceAddresses(
void* context, IPv4AddressFound onIpv4Found, IPv6AddressFound onIpv6Found, LinkLayerAddressFound onLinkLayerFound)
{
(void)context;
(void)onIpv4Found;
(void)onIpv6Found;
(void)onLinkLayerFound;
// Return success but don't enumerate any interfaces
return 0;
}

int32_t SystemNative_GetNetworkInterfaces(int32_t* interfaceCount, NetworkInterfaceInfo** interfaces, int32_t* addressCount, IpAddressInfo** addressList)
{
if (interfaceCount == NULL || interfaces == NULL || addressCount == NULL || addressList == NULL)
{
errno = EFAULT;
return -1;
}

// Return empty lists
*interfaceCount = 0;
*interfaces = NULL;
*addressCount = 0;
*addressList = NULL;
return 0;
}

int32_t SystemNative_EnumerateGatewayAddressesForInterface(void* context, uint32_t interfaceIndex, GatewayAddressFound onGatewayFound)
{
(void)context;
(void)interfaceIndex;
(void)onGatewayFound;
// Return success but don't enumerate any gateways
return 0;
}
Loading
Loading