Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a07b70c

Browse files
authored
[wasm] Address TODO in pal_runtimeinformation.c (dotnet#40133)
The WASM architecture wasn't added there since we already hardcode the architecture to wasm in the managed layer. For consistency we should still define it in the PAL though and address the TODO comment. Also added a test that verifies we indeed get the correct wasm architecture on the Browser platform.
1 parent 2892bd0 commit a07b70c

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/libraries/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ internal enum ProcessorArchitecture
1313
x86,
1414
x64,
1515
ARM,
16-
ARM64
16+
ARM64,
17+
WASM
1718
}
1819
}
1920
}

src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ int32_t SystemNative_GetUnixVersion(char* version, int* capacity)
4141
0 - x86
4242
1 - x64
4343
2 - ARM
44-
3 - ARM64 */
44+
3 - ARM64
45+
4 - WASM */
4546
int32_t SystemNative_GetOSArchitecture()
4647
{
4748
#if defined(TARGET_ARM)
@@ -50,8 +51,10 @@ int32_t SystemNative_GetOSArchitecture()
5051
return ARCH_ARM64;
5152
#elif defined(TARGET_AMD64)
5253
return ARCH_X64;
53-
#elif defined(TARGET_X86) || defined(TARGET_WASM) // TODO: add arch for WASM
54+
#elif defined(TARGET_X86)
5455
return ARCH_X86;
56+
#elif defined(TARGET_WASM)
57+
return ARCH_WASM;
5558
#else
5659
#error Unidentified Architecture
5760
#endif
@@ -61,7 +64,8 @@ int32_t SystemNative_GetOSArchitecture()
6164
0 - x86
6265
1 - x64
6366
2 - ARM
64-
3 - ARM64 */
67+
3 - ARM64
68+
4 - WASM */
6569
int32_t SystemNative_GetProcessArchitecture()
6670
{
6771
#if defined(TARGET_ARM)
@@ -70,8 +74,10 @@ int32_t SystemNative_GetProcessArchitecture()
7074
return ARCH_ARM64;
7175
#elif defined(TARGET_AMD64)
7276
return ARCH_X64;
73-
#elif defined(TARGET_X86) || defined(TARGET_WASM) // TODO: add arch for WASM
77+
#elif defined(TARGET_X86)
7478
return ARCH_X86;
79+
#elif defined(TARGET_WASM)
80+
return ARCH_WASM;
7581
#else
7682
#error Unidentified Architecture
7783
#endif

src/libraries/Native/Unix/System.Native/pal_runtimeinformation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ enum
2121
ARCH_X86,
2222
ARCH_X64,
2323
ARCH_ARM,
24-
ARCH_ARM64
24+
ARCH_ARM64,
25+
ARCH_WASM
2526
};

src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.Unix.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ private static Architecture Map(Interop.Sys.ProcessorArchitecture arch)
3434
return Architecture.X64;
3535
case Interop.Sys.ProcessorArchitecture.ARM64:
3636
return Architecture.Arm64;
37+
case Interop.Sys.ProcessorArchitecture.WASM:
38+
return Architecture.Wasm;
3739
case Interop.Sys.ProcessorArchitecture.x86:
3840
default:
3941
Debug.Assert(arch == Interop.Sys.ProcessorArchitecture.x86, "Unidentified Architecture");

src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckArchitectureTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,13 @@ public void VerifyArchitecture()
4444
Assert.Equal(osArch, RuntimeInformation.OSArchitecture);
4545
Assert.Equal(processArch, RuntimeInformation.ProcessArchitecture);
4646
}
47+
48+
[Fact]
49+
[PlatformSpecific(TestPlatforms.Browser)]
50+
public void VerifyBrowserArchitecture()
51+
{
52+
Assert.Equal(Architecture.Wasm, RuntimeInformation.OSArchitecture);
53+
Assert.Equal(Architecture.Wasm, RuntimeInformation.ProcessArchitecture);
54+
}
4755
}
4856
}

0 commit comments

Comments
 (0)