Skip to content

Commit

Permalink
Merge remote-tracking branch 'pavelsavara/wasi_build' into wasi_build…
Browse files Browse the repository at this point in the history
…_macos
  • Loading branch information
mkhamoyan committed Nov 14, 2022
2 parents fc47c61 + 9cd708b commit 5a85971
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 168 deletions.
18 changes: 15 additions & 3 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2509,15 +2509,27 @@ bool GenTree::Compare(GenTree* op1, GenTree* op2, bool swapOK)

case GT_BLK:
case GT_OBJ:
if ((op1->gtFlags & (GTF_IND_FLAGS)) != (op2->gtFlags & (GTF_IND_FLAGS)))
if (op1->AsBlk()->GetLayout() != op2->AsBlk()->GetLayout())
{
return false;
}

if ((op1->gtFlags & GTF_IND_FLAGS) != (op2->gtFlags & GTF_IND_FLAGS))
{
return false;
}
FALLTHROUGH;

break;

case GT_IND:
case GT_NULLCHECK:
if ((op1->gtFlags & (GTF_IND_FLAGS)) != (op2->gtFlags & (GTF_IND_FLAGS)))
if (op1->TypeIs(TYP_STRUCT))
{
// Rare case -- need contextual information to check equality in some cases.
return false;
}

if ((op1->gtFlags & GTF_IND_FLAGS) != (op2->gtFlags & GTF_IND_FLAGS))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace System.IO.Tests
{
public class DirectoryInfo_Name : FileSystemTest
{
[Fact]
public void Ctor_NullArgument_Throws()
{
AssertExtensions.Throws<ArgumentNullException>("path", () => new DirectoryInfo(null));
}

[Fact]
public void CurrentDirectory()
{
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/System.IO.FileSystem/tests/FileInfo/Name.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace System.IO.Tests
{
public class FileInfo_Name : FileSystemTest
{
[Fact]
public void Ctor_NullArgument_Throws()
{
AssertExtensions.Throws<ArgumentNullException>("fileName", () => new FileInfo(null));
}

[Fact]
public void ValidCase()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed partial class DirectoryInfo : FileSystemInfo

public DirectoryInfo(string path)
{
ArgumentNullException.ThrowIfNull(path);
Init(originalPath: path,
fullPath: Path.GetFullPath(path),
isNormalized: true);
Expand All @@ -27,8 +28,6 @@ internal DirectoryInfo(string originalPath, string? fullPath = null, string? fil

private void Init(string originalPath, string? fullPath = null, string? fileName = null, bool isNormalized = false)
{
ArgumentNullException.ThrowIfNull(originalPath);

OriginalPath = originalPath;

fullPath ??= originalPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ public sealed class FileInfo : FileSystemInfo
private FileInfo() { }

public FileInfo(string fileName)
: this(fileName, isNormalized: false)
: this(fileName ?? throw new ArgumentNullException(nameof(fileName)), isNormalized: false)
{
}

internal FileInfo(string originalPath, string? fullPath = null, string? fileName = null, bool isNormalized = false)
{
ArgumentNullException.ThrowIfNull(originalPath);

// Want to throw the original argument name
OriginalPath = originalPath;

fullPath ??= originalPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ public static DateTimeOffset GetCreationTime(string fullPath) =>
public static DateTimeOffset GetCreationTime(SafeFileHandle fileHandle) =>
GetAttributeData(fileHandle).ftCreationTime.ToDateTimeOffset();

public static FileSystemInfo GetFileSystemInfo(string fullPath, bool asDirectory)
{
return asDirectory ?
(FileSystemInfo)new DirectoryInfo(fullPath, null) :
(FileSystemInfo)new FileInfo(fullPath, null);
}

public static DateTimeOffset GetLastAccessTime(string fullPath) =>
GetAttributeData(fullPath).ftLastAccessTime.ToDateTimeOffset();

Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasi/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ target_compile_options(dotnet PUBLIC @${NATIVE_BIN_DIR}/src/wasi-default.rsp @${
set_target_properties(dotnet PROPERTIES COMPILE_FLAGS ${CONFIGURATION_WASICC_FLAGS})

target_link_libraries(dotnet
${ICU_LIB_DIR}/libicuuc.a
${ICU_LIB_DIR}/libicui18n.a
#TODOWASI ${ICU_LIB_DIR}/libicuuc.a
#TODOWASI ${ICU_LIB_DIR}/libicui18n.a
${MONO_ARTIFACTS_DIR}/libmono-component-hot_reload-static.a
${MONO_ARTIFACTS_DIR}/libmono-component-debugger-static.a
${MONO_ARTIFACTS_DIR}/libmono-component-diagnostics_tracing-stub-static.a
Expand Down
167 changes: 17 additions & 150 deletions src/mono/wasi/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,161 +179,22 @@ mono_wasm_add_satellite_assembly (const char *name, const char *culture, const u
}

static void *sysglobal_native_handle;
int32_t SystemNative_LChflagsCanSetHiddenFlag(void);
char* SystemNative_GetEnv(char* name);
char* SystemNative_GetEnviron(char* name);
void SystemNative_FreeEnviron(char* name);
intptr_t SystemNative_Dup(intptr_t oldfd);
int32_t SystemNative_Write(intptr_t fd, const void* buffer, int32_t bufferSize);
int64_t SystemNative_GetSystemTimeAsTicks();
int32_t SystemNative_Stat(const char* path, void* output);
int32_t SystemNative_LStat(const char* path, void* output);
int32_t SystemNative_ConvertErrorPlatformToPal(int32_t platformErrno);
void* SystemNative_LowLevelMonitor_Create();
void SystemNative_LowLevelMonitor_Acquire(void* monitor);
void SystemNative_LowLevelMonitor_Release(void* monitor);
int32_t SystemNative_LowLevelMonitor_TimedWait(void *monitor, int32_t timeoutMilliseconds);
void SystemNative_LowLevelMonitor_Wait(void* monitor);
int SystemNative_GetErrNo();
void SystemNative_SetErrNo(int value);
char* SystemNative_GetCwd();
void SystemNative_GetNonCryptographicallySecureRandomBytes();
void SystemNative_GetCryptographicallySecureRandomBytes();
int32_t SystemNative_Open(const char* path, int x, int y);
void SystemNative_ConvertErrorPalToPlatform();
void SystemNative_StrErrorR();
void SystemNative_Close();
void SystemNative_FStat();
void SystemNative_LSeek();
void SystemNative_PRead();
void SystemNative_CanGetHiddenFlag();
int32_t SystemNative_Access(const char* path, int32_t mode);
void SystemNative_Malloc();
void SystemNative_Free();
void SystemNative_SysLog();

#define PAL_O_RDONLY 0x0000
#define PAL_O_WRONLY 0x0001
#define PAL_O_RDWR 0x0002
#define PAL_O_ACCESS_MODE_MASK 0x000F

int32_t SystemNative_Open2(const char* path, int flags, int mode) {
//printf ("In SystemNative_Open2 for %s\n", path);
// The implementation in libSystemNative tries to use PAL_O_CLOEXEC, which isn't supported here, so override it
if ((flags & PAL_O_ACCESS_MODE_MASK) == PAL_O_RDONLY) {
flags = O_RDONLY;
} else if ((flags & PAL_O_ACCESS_MODE_MASK) == PAL_O_RDWR) {
flags = O_RDWR;
} else if ((flags & PAL_O_ACCESS_MODE_MASK) == PAL_O_WRONLY) {
flags = O_WRONLY;
}

int result;
while ((result = open(path, flags, (mode_t)mode)) < 0 && errno == EINTR);
return result;
}

int32_t SystemNative_Stat2(const char* path, FileStatus* output)
{
// For some reason the libSystemNative SystemNative_Stat doesn't seem to work. Maybe I did something wrong elsewhere,
// or maybe it's hardcoded to something specific to browser wasm
struct stat stat_result;
int ret;
while ((ret = stat(path, &stat_result)) < 0 && errno == EINTR);

output->Size = stat_result.st_size;
output->ATime = stat_result.st_atime;
output->MTime = stat_result.st_mtime;
output->CTime = stat_result.st_ctime;
output->Mode = S_ISDIR (stat_result.st_mode)
? 0x4000 // Dir
: 0x8000; // File

// Never fail when looking for the root directory. Even if the WASI host isn't giving us filesystem access
// (which is the default), we need the root directory to appear to exist, otherwise things like ASP.NET Core
// will fail by default, whether or not it needs to read anything from the filesystem.
if (ret != 0 && path[0] == '/' && path[1] == 0) {
output->Mode = 0x4000; // Dir
return 0;
}

//printf("SystemNative_Stat2 for %s has ISDIR=%i and will return mode %i; ret=%i\n", path, S_ISDIR (stat_result.st_mode), output->Mode, ret);

return ret;
}

int32_t SystemNative_Write2(intptr_t fd, const void* buffer, int32_t bufferSize) {
// Not sure why, but am getting fd=-1 when trying to write to stdout (which fails), so here's a workaround
return SystemNative_Write((int)fd == -1 ? 1: fd, buffer, bufferSize);
}

int64_t SystemNative_GetTimestamp2() {
// libSystemNative's implementation of SystemNative_GetTimestamp causes the process to exit. It probably
// relies on calling into JS.
struct timeval time;
return (gettimeofday(&time, NULL) == 0)
? (int64_t)(time.tv_sec) * 1000000000 + (time.tv_usec * 1000)
: 0;
}

// TODOWASI replace with native libs
static PinvokeImport SystemNativeImports [] = {
{"SystemNative_GetEnv", SystemNative_GetEnv },
{"SystemNative_GetEnviron", SystemNative_GetEnviron },
{"SystemNative_FreeEnviron", SystemNative_FreeEnviron },
{"SystemNative_LChflagsCanSetHiddenFlag", SystemNative_LChflagsCanSetHiddenFlag },
{"SystemNative_Dup", SystemNative_Dup},
{"SystemNative_Write", SystemNative_Write2},
{"SystemNative_GetSystemTimeAsTicks", SystemNative_GetSystemTimeAsTicks},
{"SystemNative_LStat", SystemNative_Stat2},
{"SystemNative_FStat", SystemNative_FStat},
{"SystemNative_LSeek", SystemNative_LSeek},
{"SystemNative_ConvertErrorPlatformToPal", SystemNative_ConvertErrorPlatformToPal},
{"SystemNative_LowLevelMonitor_Create", SystemNative_LowLevelMonitor_Create},
{"SystemNative_LowLevelMonitor_Acquire", SystemNative_LowLevelMonitor_Acquire},
{"SystemNative_LowLevelMonitor_Release", SystemNative_LowLevelMonitor_Release},
{"SystemNative_LowLevelMonitor_TimedWait", SystemNative_LowLevelMonitor_TimedWait},
{"SystemNative_LowLevelMonitor_Wait", SystemNative_LowLevelMonitor_Wait},
{"SystemNative_GetErrNo", SystemNative_GetErrNo},
{"SystemNative_SetErrNo", SystemNative_SetErrNo},
{"SystemNative_GetCwd", SystemNative_GetCwd},
{"SystemNative_GetNonCryptographicallySecureRandomBytes", SystemNative_GetNonCryptographicallySecureRandomBytes},
{"SystemNative_GetCryptographicallySecureRandomBytes", SystemNative_GetCryptographicallySecureRandomBytes},
{"SystemNative_Stat", SystemNative_Stat2},
{"SystemNative_Open", SystemNative_Open2},
{"SystemNative_Close", SystemNative_Close},
{"SystemNative_ConvertErrorPalToPlatform", SystemNative_ConvertErrorPalToPlatform},
{"SystemNative_StrErrorR", SystemNative_StrErrorR},
{"SystemNative_PRead", SystemNative_PRead},
{"SystemNative_CanGetHiddenFlag", SystemNative_CanGetHiddenFlag},
{"SystemNative_GetTimestamp", SystemNative_GetTimestamp2},
{"SystemNative_Access", SystemNative_Access},
{"SystemNative_Malloc", SystemNative_Malloc},
{"SystemNative_Free", SystemNative_Free},
{"SystemNative_SysLog", SystemNative_SysLog},
{NULL, NULL}
};

void GlobalizationNative_LoadICU() {
assert(0);
}

static PinvokeImport SystemGlobalizationNativeImports [] = {
{"GlobalizationNative_LoadICU", GlobalizationNative_LoadICU },
{NULL, NULL}
};

static void*
wasm_dl_load (const char *name, int flags, char **err, void *user_data)
{
printf("In wasm_dl_load for name %s\n", name);
if (!strcmp (name, "libSystem.Native"))
return SystemNativeImports;
if (!strcmp (name, "libSystem.Globalization.Native"))
return SystemGlobalizationNativeImports;
void* handle = wasm_dl_lookup_pinvoke_table (name);
if (handle)
return handle;

if (!strcmp (name, "System.Globalization.Native"))
return sysglobal_native_handle;

//printf("In wasm_dl_load for name %s but treating as NOT FOUND\n", name);
return 0;
#if WASM_SUPPORTS_DLOPEN
return dlopen(name, flags);
#endif

return NULL;
}

static void*
Expand All @@ -342,6 +203,12 @@ wasm_dl_symbol (void *handle, const char *name, char **err, void *user_data)
if (handle == sysglobal_native_handle)
assert (0);

#if WASM_SUPPORTS_DLOPEN
if (!wasm_dl_is_pinvoke_tables (handle)) {
return dlsym (handle, name);
}
#endif

PinvokeImport *table = (PinvokeImport*)handle;
for (int i = 0; table [i].name; ++i) {
if (!strcmp (table [i].name, name))
Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasi/wasi.proj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
<ItemGroup>
<WasmPInvokeModule Include="libSystem.Native" />
<WasmPInvokeModule Include="libSystem.IO.Compression.Native" />
<!--
<WasmPInvokeModule Include="libSystem.Globalization.Native" />
-->
<WasmPInvokeAssembly Include="@(LibrariesRuntimeFiles)" Condition="'%(Extension)' == '.dll' and '%(IsNative)' != 'true'" />
</ItemGroup>

Expand Down
5 changes: 5 additions & 0 deletions src/native/libs/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,11 @@ int64_t SystemNative_PWriteV(intptr_t fd, IOVector* vectors, int32_t vectorCount

#else /* TARGET_WASI */

int32_t SystemNative_Link(const char* source, const char* linkTarget)
{
return -1;
}

int32_t SystemNative_Stat(const char* path, FileStatus* output)
{
return -1;
Expand Down
72 changes: 72 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_78310/Runtime_78310.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.

// Adapted from:
// Generated by Fuzzlyn v1.5 on 2022-11-14 02:52:08
// Run on Arm64 Windows
// Seed: 11038715273855459808
// Reduced from 96.6 KiB to 0.9 KiB in 00:08:38
// Debug: Outputs 0
// Release: Outputs 1
using System;
using System.Runtime.CompilerServices;

public struct S0
{
public long F;
public byte FB;
}

public struct S1
{
public S0 S;
public long LastField;
}

public class Runtime_78310
{
public static int Main()
{
S1 lhs = new S1 { S = { F = 1 }, LastField = 2 };
S1 rhs = new S1 { S = { F = 3 }, LastField = 4 };
Copy(true, ref lhs, rhs);

int result = 100;
if (lhs.S.F != 3 || lhs.LastField != 2)
{
Console.WriteLine("FAIL: After small copy is {0}, {1}", lhs.S.F, lhs.LastField);
result = -1;
}

lhs = new S1 { S = { F = 5 }, LastField = 6 };
rhs = new S1 { S = { F = 7 }, LastField = 8 };
Copy(false, ref lhs, rhs);
if (lhs.S.F != 7 || lhs.LastField != 8)
{
Console.WriteLine("FAIL: After large copy is {0}, {1}", lhs.S.F, lhs.LastField);
result = -1;
}

return result;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Copy(bool small, ref S1 lhs, S1 rhs)
{
if (small)
{
lhs.S = rhs.S;
}
else
{
lhs = rhs;
}

Foo();
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Foo()
{
}
}
Loading

0 comments on commit 5a85971

Please sign in to comment.