Skip to content

Commit b02019a

Browse files
Handle clang/gcc defining "unix" during compilation (#121097)
The clang and gcc tool chains defines 'unix' during compilation - clang doesn't on macOS. This means that during the data contract generation the "unix" string was converted to "1" and interpreted as "windows". See `./src/mono/browser/emsdk/emscripten/emcc -dM -E - < /dev/null | grep unix` or `clang -dM -E - < /dev/null | grep unix` on a linux distro. The first step is to create a specific OS for the browser and then make all string definitions case sensitive so the "unix" define doesn't convert. We also place some defensive checks in place for the OS names that aren't all that unique either.
1 parent 7201a39 commit b02019a

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

src/coreclr/vm/datadescriptor/datadescriptor.inc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,21 @@ CDAC_TYPES_END()
989989

990990
CDAC_GLOBALS_BEGIN()
991991

992-
#if defined(TARGET_UNIX)
993-
CDAC_GLOBAL_STRING(OperatingSystem, unix)
992+
#if defined(TARGET_BROWSER)
993+
#ifdef Browser
994+
#error Handle 'Browser' define
995+
#endif // Browser
996+
CDAC_GLOBAL_STRING(OperatingSystem, Browser)
997+
#elif defined(TARGET_UNIX)
998+
#ifdef Unix
999+
#error Handle 'Unix' define
1000+
#endif // Unix
1001+
CDAC_GLOBAL_STRING(OperatingSystem, Unix)
9941002
#elif defined(TARGET_WINDOWS)
995-
CDAC_GLOBAL_STRING(OperatingSystem, windows)
1003+
#ifdef Windows
1004+
#error Handle 'Windows' define
1005+
#endif // Windows
1006+
CDAC_GLOBAL_STRING(OperatingSystem, Windows)
9961007
#else
9971008
#error TARGET_{OS} define is not recognized by the cDAC. Update this switch and the enum values in IRuntimeInfo.cs
9981009
#endif

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum RuntimeInfoOperatingSystem : uint
2626
Unknown = 0,
2727
Windows,
2828
Unix,
29+
Browser,
2930
}
3031

3132
public interface IRuntimeInfo : IContract

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/AMD64/AMD64Unwinder.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class AMD64Unwinder(Target target)
3131
private readonly Target _target = target;
3232
private readonly IExecutionManager _eman = target.Contracts.ExecutionManager;
3333

34-
private readonly bool _unix = target.Contracts.RuntimeInfo.GetTargetOperatingSystem() == RuntimeInfoOperatingSystem.Unix;
34+
private readonly bool _unixAMD64ABI = target.Contracts.RuntimeInfo.GetTargetOperatingSystem() != RuntimeInfoOperatingSystem.Windows;
3535

3636
public bool Unwind(ref AMD64Context context)
3737
{
@@ -97,7 +97,7 @@ public bool Unwind(ref AMD64Context context)
9797
{
9898
frameOffset = unwindInfo.FrameOffset;
9999

100-
if (_unix)
100+
if (_unixAMD64ABI)
101101
{
102102
// If UnwindInfo->FrameOffset == 15 (the maximum value), then there might be a UWOP_SET_FPREG_LARGE.
103103
// However, it is still legal for a UWOP_SET_FPREG to set UnwindInfo->FrameOffset == 15 (since this
@@ -133,7 +133,7 @@ public bool Unwind(ref AMD64Context context)
133133
unwindOp = GetUnwindCode(unwindInfo, index);
134134
if (unwindOp.UnwindOp == UnwindCode.OpCodes.UWOP_SET_FPREG)
135135
break;
136-
if (_unix)
136+
if (_unixAMD64ABI)
137137
{
138138
if (unwindOp.UnwindOp == UnwindCode.OpCodes.UWOP_SET_FPREG_LARGE)
139139
{
@@ -835,7 +835,7 @@ private bool UnwindPrologue(
835835

836836
UnwindCode unwindOp = GetUnwindCode(unwindInfo, index);
837837

838-
if (_unix)
838+
if (_unixAMD64ABI)
839839
{
840840
if (unwindOp.UnwindOp > UnwindCode.OpCodes.UWOP_SET_FPREG_LARGE)
841841
{
@@ -845,7 +845,8 @@ private bool UnwindPrologue(
845845
}
846846
else
847847
{
848-
if (unwindOp.UnwindOp == UnwindCode.OpCodes.UWOP_SET_FPREG_LARGE)
848+
Debug.Assert(_target.Contracts.RuntimeInfo.GetTargetOperatingSystem() == RuntimeInfoOperatingSystem.Windows);
849+
if (unwindOp.UnwindOp > UnwindCode.OpCodes.UWOP_PUSH_MACHFRAME)
849850
{
850851
Debug.Fail("Expected unwind code");
851852
return false;
@@ -929,7 +930,7 @@ private bool UnwindPrologue(
929930
//
930931
case UnwindCode.OpCodes.UWOP_SET_FPREG_LARGE:
931932
{
932-
UnwinderAssert(_unix);
933+
UnwinderAssert(_unixAMD64ABI);
933934
UnwinderAssert(unwindInfo.FrameOffset == 15);
934935
uint frameOffset = GetUnwindCode(unwindInfo, index + 1).FrameOffset;
935936
frameOffset += (uint)(GetUnwindCode(unwindInfo, index + 2).FrameOffset << 16);

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/X86/X86Unwinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class X86Unwinder(Target target)
3434
private readonly Target _target = target;
3535
private readonly uint _pointerSize = (uint)target.PointerSize;
3636
private readonly bool _updateAllRegs = true;
37-
private readonly bool _unixX86ABI = target.Contracts.RuntimeInfo.GetTargetOperatingSystem() == RuntimeInfoOperatingSystem.Unix;
37+
private readonly bool _unixX86ABI = target.Contracts.RuntimeInfo.GetTargetOperatingSystem() != RuntimeInfoOperatingSystem.Windows;
3838

3939
private static readonly RegMask[] registerOrder =
4040
[

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,10 @@ int ISOSDacInterface.GetClrWatsonBuckets(ClrDataAddress thread, void* pGenericMo
589589
byte[] buckets = Array.Empty<byte>();
590590
try
591591
{
592-
if (_target.Contracts.RuntimeInfo.GetTargetOperatingSystem() == RuntimeInfoOperatingSystem.Unix)
592+
if (_target.Contracts.RuntimeInfo.GetTargetOperatingSystem() != RuntimeInfoOperatingSystem.Windows)
593593
throw Marshal.GetExceptionForHR(HResults.E_FAIL)!;
594-
else if (thread == 0 || pGenericModeBlock == null)
594+
595+
if (thread == 0 || pGenericModeBlock == null)
595596
throw new ArgumentException();
596597

597598
buckets = threadContract.GetWatsonBuckets(thread.ToTargetPointer(_target));

0 commit comments

Comments
 (0)