-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasm] Addressing System.Runtime.Extensions failures (#38996)
Co-authored-by: Mitchell Hwang <mitchell.hwang@microsoft.com> Co-authored-by: Steve Pfister <steve.pfister@microsoft.com> Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
- Loading branch information
1 parent
fff0ec3
commit 927ced1
Showing
13 changed files
with
170 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System | ||
{ | ||
public static partial class Environment | ||
{ | ||
// Emscripten VFS mounts at / and is the only drive | ||
public static string[] GetLogicalDrives() => new string[] { "/" }; | ||
|
||
// In the mono runtime, this maps to gethostname, which returns 'emscripten'. | ||
// Returning the value here allows us to exclude more of the runtime. | ||
public static string MachineName => "localhost"; | ||
|
||
// Matching what we returned for an earlier release. There isn't an established equivalent | ||
// on wasm. | ||
public static long WorkingSet => 0; | ||
|
||
public static string UserName => "Browser"; | ||
|
||
private static OperatingSystem GetOSVersion() | ||
{ | ||
return new OperatingSystem(PlatformID.Other, new Version(1, 0, 0, 0)); | ||
} | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
src/libraries/System.Private.CoreLib/src/System/Environment.OSVersion.Browser.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/libraries/System.Private.CoreLib/src/System/Environment.UnixOrBrowser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
namespace System | ||
{ | ||
public static partial class Environment | ||
{ | ||
public static bool UserInteractive => true; | ||
|
||
private static string CurrentDirectoryCore | ||
{ | ||
get => Interop.Sys.GetCwd(); | ||
set => Interop.CheckIo(Interop.Sys.ChDir(value), value, isDirectory: true); | ||
} | ||
|
||
private static string ExpandEnvironmentVariablesCore(string name) | ||
{ | ||
var result = new ValueStringBuilder(stackalloc char[128]); | ||
|
||
int lastPos = 0, pos; | ||
while (lastPos < name.Length && (pos = name.IndexOf('%', lastPos + 1)) >= 0) | ||
{ | ||
if (name[lastPos] == '%') | ||
{ | ||
string key = name.Substring(lastPos + 1, pos - lastPos - 1); | ||
string? value = GetEnvironmentVariable(key); | ||
if (value != null) | ||
{ | ||
result.Append(value); | ||
lastPos = pos + 1; | ||
continue; | ||
} | ||
} | ||
result.Append(name.AsSpan(lastPos, pos - lastPos)); | ||
lastPos = pos; | ||
} | ||
result.Append(name.AsSpan(lastPos)); | ||
|
||
return result.ToString(); | ||
} | ||
|
||
private static bool Is64BitOperatingSystemWhen32BitProcess => false; | ||
|
||
private static int GetCurrentProcessId() => Interop.Sys.GetPid(); | ||
|
||
internal const string NewLineConst = "\n"; | ||
|
||
public static string SystemDirectory => GetFolderPathCore(SpecialFolder.System, SpecialFolderOption.None); | ||
|
||
public static int SystemPageSize => CheckedSysConf(Interop.Sys.SysConfName._SC_PAGESIZE); | ||
|
||
public static string UserDomainName => MachineName; | ||
|
||
/// <summary>Invoke <see cref="Interop.Sys.SysConf"/>, throwing if it fails.</summary> | ||
private static int CheckedSysConf(Interop.Sys.SysConfName name) | ||
{ | ||
long result = Interop.Sys.SysConf(name); | ||
if (result == -1) | ||
{ | ||
Interop.ErrorInfo errno = Interop.Sys.GetLastErrorInfo(); | ||
throw errno.Error == Interop.Error.EINVAL ? | ||
new ArgumentOutOfRangeException(nameof(name), name, errno.GetErrorMessage()) : | ||
Interop.GetIOException(errno); | ||
} | ||
return (int)result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.