Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Expand Up @@ -165,6 +165,7 @@ private static DriveType GetDriveType(string fileSystemName)
case "qnx6":
case "reiserfs":
case "rpc_pipefs":
case "sffs":
case "smackfs":
case "squashfs":
case "swap":
Expand All @@ -179,6 +180,8 @@ private static DriveType GetDriveType(string fileSystemName)
case "umsdos":
case "umview-mod-umfuseext2":
case "v9fs":
case "vagrant":
case "vboxfs":
case "vxfs":
case "vxfs_olt":
case "vzfs":
Expand Down Expand Up @@ -304,6 +307,7 @@ private static DriveType GetDriveType(string fileSystemName)
case "sockfs":
case "sysfs":
case "tmpfs":
case "udev":
case "usbdev":
case "usbdevfs":
return DriveType.Ram;
Expand All @@ -314,8 +318,8 @@ private static DriveType GetDriveType(string fileSystemName)
case "vfat":
return DriveType.Removable;

// Categorize as "Unknown" everything else not explicitly
// recognized as a particular drive type.
// Categorize as "Unknown" everything else not explicitly
// recognized as a particular drive type.
default:
return DriveType.Unknown;
}
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 @@ -38,8 +35,11 @@ internal enum UnixFileSystemTypes : long
coda = 0x73757245,
coherent = 0x012FF7B7,
configfs = 0x62656570,
cpuset = 0x01021994, // same as tmpfs
cramfs = 0x28CD3D45,
ctfs = 0x01021994, // same as tmpfs
debugfs = 0x64626720,
dev = 0x1373, // same as devfs
devfs = 0x1373,
devpts = 0x1CD1,
ecryptfs = 0xF15F,
Expand Down Expand Up @@ -81,15 +81,17 @@ internal enum UnixFileSystemTypes : long
minix2 = 0x2468, /* minix V2 */
minix2v2 = 0x2478, /* MINIX V2, 30 char names */
minix3 = 0x4D5A,
mntfs = 0x01021994, // same as tmpfs
mqueue = 0x19800202,
msdos = 0x4D44,
nfs = 0x6969,
nfsd = 0x6E667364,
nilfs = 0x3434,
novell = 0x564C,
ntfs = 0x5346544E,
openprom = 0x9FA1,
objfs = 0x01021994, // same as tmpfs
ocfs2 = 0x7461636F,
openprom = 0x9FA1,
omfs = 0xC2993D87,
overlay = 0x794C7630,
overlayfs = 0x794C764F,
Expand All @@ -107,6 +109,8 @@ internal enum UnixFileSystemTypes : long
samba = 0x517B,
securityfs = 0x73636673,
selinux = 0xF97CFF8C,
sffs = 0x786F4256, // same as vboxfs
sharefs = 0x01021994, // same as tmpfs
smb = 0x517B,
smb2 = 0xFE534D42,
sockfs = 0x534F434B,
Expand All @@ -122,24 +126,17 @@ internal enum UnixFileSystemTypes : long
ufs2 = 0x19540119,
usbdevice = 0x9FA2,
v9fs = 0x01021997,
vagrant = 0x786F4256, // same as vboxfs
vboxfs = 0x786F4256,
vmhgfs = 0xBACBACBC,
vxfs = 0xA501FCF5,
vzfs = 0x565A4653,
xenfs = 0xABBA1974,
xenix = 0x012FF7B4,
xfs = 0x58465342,
xia = 0x012FD16D,
udev = 0x01021994, // same as tmpfs
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);
}
}
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;
#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);
#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
#include <alloca.h>
#endif

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