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

Fix illumos build regressions #55916

Merged
merged 9 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12742,6 +12742,8 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)

CM_ADD_OP:

FALLTHROUGH;

case GT_OR:
case GT_XOR:
case GT_AND:
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/minipal/Unix/doublemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu

#ifdef TARGET_FREEBSD
int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU);
#elif defined(TARGET_SUNOS) // has POSIX implementation
char anonName[24];
sprintf(anonName, "/shm-dotnet-%d", getpid());
anonName[sizeof(anonName) - 1] = '\0';
shm_unlink(anonName);
int fd = shm_open(anonName, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
#else // TARGET_FREEBSD
int fd = memfd_create("doublemapper", MFD_CLOEXEC);
#endif // TARGET_FREEBSD
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

internal static partial class Interop
{
internal static partial class Sys
Expand Down Expand Up @@ -131,15 +128,5 @@ internal enum UnixFileSystemTypes : long
xia = 0x012FD16D,
zfs = 0x2FC12FC1,
}

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")]
private static extern long GetFileSystemType(SafeFileHandle fd);

internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType)
{
long fstatfsResult = GetFileSystemType(fd);
fileSystemType = (UnixFileSystemTypes)fstatfsResult;
return fstatfsResult != -1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemType")]
private static extern long GetFileSystemType(SafeFileHandle fd);

internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType)
{
long fstatfsResult = GetFileSystemType(fd);
fileSystemType = (UnixFileSystemTypes)fstatfsResult;
return fstatfsResult != -1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFileSystemTypeAsString")]
private static extern string GetFileSystemTypeAsString(SafeFileHandle fd);

internal static bool TryGetFileSystemType(SafeFileHandle fd, out UnixFileSystemTypes fileSystemType) =>
Enum.TryParse<UnixFileSystemTypes>(GetFileSystemTypeAsString(fd), out fileSystemType);
am11 marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ if(CLR_CMAKE_TARGET_UNIX)
else()
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
if(CLR_CMAKE_TARGET_SUNOS)
add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS)
add_definitions(-D__EXTENSIONS__ -D_XPG4_2 -D_POSIX_PTHREAD_SEMANTICS -DTARGET_SUNOS)
else()
# -z,now is required for full relro.
# see https://www.redhat.com/en/blog/hardening-elf-binaries-using-relocation-read-only-relro
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Native/Unix/System.Native/entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static const Entry s_sysNative[] =
DllImportEntry(SystemNative_RealPath)
DllImportEntry(SystemNative_GetPeerID)
DllImportEntry(SystemNative_GetFileSystemType)
DllImportEntry(SystemNative_GetFileSystemTypeAsString)
DllImportEntry(SystemNative_LockFileRegion)
DllImportEntry(SystemNative_LChflags)
DllImportEntry(SystemNative_LChflagsCanSetHiddenFlag)
Expand Down
26 changes: 25 additions & 1 deletion src/libraries/Native/Unix/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@
#include <sys/vfs.h>
#elif HAVE_STATFS_MOUNT // BSD
#include <sys/mount.h>
#elif !HAVE_NON_LEGACY_STATFS // SunOS
#include <sys/types.h>
#include <sys/statvfs.h>
#include <sys/vfs.h>
#endif

#ifdef _AIX
#include <alloca.h>
// Somehow, AIX mangles the definition for this behind a C++ def
// Redeclare it here
extern int getpeereid(int, uid_t *__restrict__, gid_t *__restrict__);
#elif defined(__sun)
#elif defined(TARGET_SUNOS)
#ifndef _KERNEL
#define _KERNEL
#define UNDEF_KERNEL
Expand Down Expand Up @@ -1405,11 +1409,31 @@ int64_t SystemNative_GetFileSystemType(intptr_t fd)
// which got deprecated in macOS 10.6, in favor of statfs
while ((statfsRes = fstatfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ;
return statfsRes == -1 ? (int64_t)-1 : (int64_t)statfsArgs.f_type;
#elif defined(TARGET_SUNOS) // we use statvfs (see SystemNative_GetFileSystemTypeAsString) on SunOS
(void)fd; // unused
return -1;
am11 marked this conversation as resolved.
Show resolved Hide resolved
#else
#error "Platform doesn't support fstatfs"
#endif
}

char* SystemNative_GetFileSystemTypeAsString(intptr_t fd)
{
#if !HAVE_NON_LEGACY_STATFS
int statfsRes;
struct statvfs statfsArgs;
while ((statfsRes = fstatvfs(ToFileDescriptor(fd), &statfsArgs)) == -1 && errno == EINTR) ;
return statfsRes == -1 ? NULL : strdup(statfsArgs.f_basetype);
am11 marked this conversation as resolved.
Show resolved Hide resolved
#else
(void)fd; // unused
return NULL;
#endif
}

#if !HAVE_STATFS_VFS && !HAVE_STATFS_MOUNT && HAVE_NON_LEGACY_STATFS
#error "Platform doesn't support fstatfs or fstatvfs"
#endif

int32_t SystemNative_LockFileRegion(intptr_t fd, int64_t offset, int64_t length, int16_t lockType)
{
int16_t unixLockType = ConvertLockType(lockType);
Expand Down
5 changes: 5 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,11 @@ PALEXPORT int32_t SystemNative_GetPeerID(intptr_t socket, uid_t* euid);
*/
PALEXPORT int64_t SystemNative_GetFileSystemType(intptr_t fd);

/**
* Returns file system type name on success, or NULL on error.
*/
PALEXPORT char* SystemNative_GetFileSystemTypeAsString(intptr_t fd);

/**
* Attempts to lock/unlock the region of the file "fd" specified by the offset and length. lockType
* can be set to F_UNLCK (2) for unlock or F_WRLCK (3) for lock.
Expand Down
13 changes: 6 additions & 7 deletions src/libraries/Native/Unix/System.Native/pal_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

#if HAVE_MALLOC_SIZE
#include <malloc/malloc.h>
#define MALLOC_SIZE(s) malloc_size(s)
#elif HAVE_MALLOC_USABLE_SIZE
#include <malloc.h>
#define MALLOC_SIZE(s) malloc_usable_size(s)
#elif HAVE_MALLOC_USABLE_SIZE_NP
#include <malloc_np.h>
#define MALLOC_SIZE(s) malloc_usable_size(s)
#elif defined(TARGET_SUNOS)
#define MALLOC_SIZE(s) (*((size_t*)(s)-1))
#else
#error "Platform doesn't support malloc_usable_size or malloc_size"
#endif
Expand Down Expand Up @@ -67,13 +72,7 @@ void SystemNative_Free(void* ptr)

uintptr_t SystemNative_GetUsableSize(void* ptr)
{
#if HAVE_MALLOC_SIZE
return malloc_size(ptr);
#elif HAVE_MALLOC_USABLE_SIZE || HAVE_MALLOC_USABLE_SIZE_NP
return malloc_usable_size(ptr);
#else
#error "Platform doesn't support malloc_usable_size or malloc_size"
#endif
return MALLOC_SIZE(ptr);
}

void* SystemNative_Malloc(uintptr_t size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
<Nullable>enable</Nullable>
<UseStatvfs Condition="'$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'">true</UseStatvfs>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\IO\DriveInfo.cs" />
Expand Down Expand Up @@ -58,6 +59,12 @@
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs"
Link="Common\Interop\Unix\Interop.UnixFileSystemTypes.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.statfs.cs"
Condition="'$(UseStatvfs)' != 'true'"
Link="Common\Interop\Unix\Interop.UnixFileSystemTypes.statfs.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.statvfs.cs"
Condition="'$(UseStatvfs)' == 'true'"
Link="Common\Interop\Unix\Interop.UnixFileSystemTypes.statvfs.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.IOErrors.cs"
Link="Common\Interop\Unix\Interop.IOErrors.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.Unix.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<IsBigEndian Condition="'$(Platform)' == 's390x'">true</IsBigEndian>
<Is64Bit Condition="'$(Platform)' == 'arm64' or '$(Platform)' == 'x64' or '$(Platform)' == 's390x'">true</Is64Bit>
<UseMinimalGlobalizationData Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsBrowser)' == 'true'">true</UseMinimalGlobalizationData>
<UseStatvfs Condition="'$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'">true</UseStatvfs>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(IsBigEndian)' == 'true'">$(DefineConstants);BIGENDIAN</DefineConstants>
Expand Down Expand Up @@ -1943,6 +1944,12 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs">
<Link>Common\Interop\Unix\System.Native\Interop.UnixFileSystemTypes.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.statfs.cs"
Condition="'$(UseStatvfs)' != 'true'"
Link="Common\Interop\Unix\Interop.UnixFileSystemTypes.statfs.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.UnixFileSystemTypes.statvfs.cs"
Condition="'$(UseStatvfs)' == 'true'"
Link="Common\Interop\Unix\Interop.UnixFileSystemTypes.statvfs.cs" />
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.FLock.cs">
<Link>Common\Interop\Unix\System.Native\Interop.FLock.cs</Link>
</Compile>
Expand Down Expand Up @@ -2324,4 +2331,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryNegationOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryPlusOperators.cs" />
</ItemGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions src/native/corehost/bundle/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "pal.h"
#include "utils.h"

#ifdef __sun
am11 marked this conversation as resolved.
Show resolved Hide resolved
#include <alloca.h>
#endif

#if defined(NATIVE_LIBS_EMBEDDED)
extern "C"
{
Expand Down