Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port CoreCLR to SunOS #35173

Merged
merged 3 commits into from
Apr 22, 2020
Merged

Port CoreCLR to SunOS #35173

merged 3 commits into from
Apr 22, 2020

Conversation

am11
Copy link
Member

@am11 am11 commented Apr 19, 2020

With these changes, CoreCLR compiles on SmartOS 20190829T000927Z x86_64, Global Zone (GZ).

Libunwid changes are left out from this PR branch, as it is awaiting @jasonbking's PR merge upstream with Illumos fixes: libunwind/libunwind#171. I have a separate branch that has latest libunwind with Jason's PR changes, and CoreCLR CMake config updates: am11@3180b6c.

Here are the steps to build with libunwind changes branch:

# new machine, after bootstrapping pkgsrc

# dependencies
sudo pkgin -y update
sudo pkgin -y install git gcc7 mozilla-rootcerts cmake icu py37-expat gmake

git clone https://github.com/am11/runtime -b feature/solaris/coreclr-port --depth 1 --single-branch
cd runtime
./src/coreclr/build-runtime.sh -gcc

cc @jkotas, @janvorli

Contributes to #34944

@ghost
Copy link

ghost commented Apr 19, 2020

Tagging subscribers to this area: @ViktorHofer
Notify danmosemsft if you want to be subscribed.

#else
#warning
#error DAC_CS_NATIVE_DATA_SIZE is not defined for this architecture
#error DAC_CS_NATIVE_DATA_SIZE is not defined for this architecture. This should be same value as PAL_CS_NATIVE_DATA_SIZE (aka sizeof(PAL_CS_NATIVE_DATA)).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smadala, I have appended the error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you wanted to notify @sdmaclea instead

inline WCHAR *PAL_wcspbrk(WCHAR* S, const WCHAR* P)
{return ((WCHAR *)PAL_wcspbrk((const WCHAR *)S, P)); }
inline WCHAR *PAL_wcsstr(WCHAR* S, const WCHAR* P)
{return ((WCHAR *)PAL_wcsstr((const WCHAR *)S, P)); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_S etc. are defined by some system headers, so renamed these without underscore, rather than undef'ing.

PALIMPORT float __cdecl atanf(float)
#ifndef __sun
THROW_DECL
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these do not have throw() semantics on Illumos.

@am11 am11 marked this pull request as ready for review April 19, 2020 07:42
@@ -221,6 +225,8 @@ GetSystemInfo(
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) VM_MAXUSER_ADDRESS;
#elif defined(__linux__)
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47);
#elif defined(__sun)
lpSystemInfo->lpMaximumApplicationAddress = (PVOID) 0xfffffd7fffe00000ul;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value was copied from https://github.com/illumos/illumos-gate/blob/4e0c5eff9af325c80994e9527b7cb8b3a1ffd1d4/usr/src/uts/i86pc/sys/machparam.h#L235, unfortunately that header is not included in the base box. After some discussion in #illumos channel over at freenode IRC, we may get a helper function like getusrstack() (similar to getpagesize()) in the future, rather than a hardcoded value macro.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on SunOS, the user code can live even in such a high address range?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @janvorli, that's correct (at least as far as illumos is concerned, I work on that but cannot speak for Oracle Solaris). Though this value can shift a bit. For example, on my system it's currently 0xfffffc7fffe00000 and that's because @am11 used a slightly older base of illumos where we had to shift that due to part of our KPTI mitigations. However, it is different in different situations. For example if running inside of Xen pv (though that's rather uncommon) that today is 0x00007fffffe00000, e.g. below the VA hole. Those are values on x86. On SPARC right now the user limit is 0xFFFFFFFF80000000.

I'm looking at adding a sysconf style interface to get the maximum mapable address. I suspect on other systems with the advent of 5-level paging the maximum address may shift, though that may not matter for most consumers of the CLR. I would suggest limiting it at the VA hole on amd64 until such time as we have that available and falling back to the VA hole when not available.

@am11
Copy link
Member Author

am11 commented Apr 19, 2020

CI failures are unrealted:

src/coreclr/src/dlls/dbgshim/CMakeLists.txt Outdated Show resolved Hide resolved
src/coreclr/src/pal/src/exception/seh.cpp Outdated Show resolved Hide resolved
src/coreclr/src/pal/src/exception/seh.cpp Outdated Show resolved Hide resolved
src/coreclr/src/pal/src/thread/context.cpp Outdated Show resolved Hide resolved
Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@rmustacc
Copy link

rmustacc commented Apr 21, 2020

Hi @janvorli, @am11, it looks like this went back (or at least still has) with the wrong value for the maximum usable address. I would still recommend tracking the VA hole here, but if you want to use the maximum value that can change, I'd strongly recommend at least using the current max on x86, instead of one from a few years ago (before KPTI).

@am11
Copy link
Member Author

am11 commented Apr 21, 2020

@rmustacc, I took the lpMaximumApplicationAddress value from latest master of Illumos-gate USERLIMIT, is it incorrect?

@rmustacc
Copy link

@rmustacc, I took the lpMaximumApplicationAddress value from latest master of Illumos-gate USERLIMIT, is it incorrect?

So at least on systems I was looking at the, the actual value that was being applied was the lower one I mentioned. The fundamental problem is that this isn't a committed value. If things change, the maximum address will be pushed down and if a hardcoded value is used, things may change. I guess the problem with using the hole address is that it may mean the initial stack is outside of this.

@am11
Copy link
Member Author

am11 commented Apr 21, 2020

@rmustacc, thanks. I have restricted this value to USERLIMIT32, the lowest value on x64.

I'm looking at adding a sysconf style interface to get the maximum mapable address.

Once we have such interface available, we can replace this hard-coded value with the function call. I have added a comment to that effect.

@rmustacc
Copy link

rmustacc commented Apr 21, 2020 via email

@janvorli
Copy link
Member

I'd use the low side of the VA hole as a maximum value

I agree, we should not limit it to 32 bits. Basically, this needs to be the maximum address any memory mapped into the user process can have. It is currently used at three places. At ClrVirtualAllocWithinRange, ClrVirtualAlloc and isRetAddr. The first one tries to allocate virtual memory from a specified range clipped by the memory top and bottom. This is not critical, if it fails to get memory allocated from the range, it will use whatever mmap returns. The second is just for debugging purposes. The third one needs a real top limit. It is used to check that an address in code is below the maximum address.

@am11
Copy link
Member Author

am11 commented Apr 21, 2020

@janvorli, thanks. I have reverted the last commit so we use the current highest value defined in illumos-gate: https://github.com/illumos/illumos-gate/blob/4e0c5eff9af325c80994e9527b7cb8b3a1ffd1d4/usr/src/uts/i86pc/sys/machparam.h#L235.

@janvorli janvorli merged commit 84ec25f into dotnet:master Apr 22, 2020
@am11 am11 deleted the feature/solaris/coreclr-port-without-libunwind-changes branch April 22, 2020 11:49
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants