Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ elseif(CLR_CMAKE_HOST_APPLE)
add_definitions(-D_XOPEN_SOURCE)
# enable support for Darwin extension APIs, like pthread_getthreadid_np
add_definitions(-D_DARWIN_C_SOURCE)
# enable the non-cancellable versions of APIs with $NOCANCEL variants, like close(2)
add_definitions(-D__DARWIN_NON_CANCELABLE=1)

if(CLR_CMAKE_HOST_OSX)
# the new linker in Xcode 15 (ld_new/ld_prime) deprecated the -bind_at_load flag for macOS which causes a warning
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/pal/src/misc/perfjitdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifdef JITDUMP_SUPPORTED

#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -355,7 +356,7 @@ struct PerfJitDumpState

result = close(fd);

if (result == -1)
if (result == -1 && errno != EINTR)
return FatalError();

fd = -1;
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/pal/src/sharedmemory/sharedmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,7 @@ int SharedMemoryHelpers::CreateOrOpenFile(
void SharedMemoryHelpers::CloseFile(int fileDescriptor)
{
_ASSERTE(fileDescriptor != -1);

int closeResult;
do
{
closeResult = close(fileDescriptor);
} while (closeResult != 0 && errno == EINTR);
close(fileDescriptor);
}

int SharedMemoryHelpers::ChangeMode(LPCSTR path, mode_t mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ private static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int
return handle;
}

// Each thread will have its own copy. This prevents race conditions if the handle had the last error.
[ThreadStatic]
internal static Interop.ErrorInfo? t_lastCloseErrorInfo;

protected override bool ReleaseHandle()
{
// If DeleteOnClose was requested when constructed, delete the file now.
Expand All @@ -152,15 +148,8 @@ protected override bool ReleaseHandle()
_isLocked = false;
}

// Close the descriptor. Although close is documented to potentially fail with EINTR, we never want
// to retry, as the descriptor could actually have been closed, been subsequently reassigned, and
// be in use elsewhere in the process. Instead, we simply check whether the call was successful.
int result = Interop.Sys.Close(handle);
if (result != 0)
{
t_lastCloseErrorInfo = Interop.Sys.GetLastErrorInfo();
}
return result == 0;
// Close the descriptor.
return Interop.Sys.Close(handle) == 0;
}

public override bool IsInvalid
Expand Down
3 changes: 1 addition & 2 deletions src/mono/mono/sgen/sgen-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ close_binary_protocol_file (void)
#if defined(HOST_WIN32)
CloseHandle (binary_protocol_file);
#elif defined(HAVE_UNISTD_H)
while (close (binary_protocol_file) == -1 && errno == EINTR)
;
close (binary_protocol_file);
#endif
binary_protocol_file = invalid_file_value;
}
Expand Down
4 changes: 1 addition & 3 deletions src/native/eventpipe/ds-ipc-pal-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,7 @@ ipc_socket_close (ds_ipc_socket_t s)
#ifdef HOST_WIN32
result_close = closesocket (s);
#else
do {
result_close = close (s);
} while (ipc_retry_syscall (result_close));
result_close = close (s);
#endif
DS_EXIT_BLOCKING_PAL_SECTION;
return result_close;
Expand Down
4 changes: 3 additions & 1 deletion src/native/libs/System.IO.Ports.Native/pal_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ int SystemIoPortsNative_SerialPortClose(intptr_t handle)

// ignoring the error - best effort
ioctl(fd, TIOCNXCL);
return close(fd);
int result = close(fd);
if (result < 0 && errno == EINTR) result = 0; // on all supported platforms, close(2) returning EINTR still means it was released
return result;
}

int32_t SystemIoPortsNative_Read(intptr_t fd, void* buffer, int32_t bufferSize)
Expand Down
4 changes: 3 additions & 1 deletion src/native/libs/System.Native/pal_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ intptr_t SystemNative_Open(const char* path, int32_t flags, int32_t mode)

int32_t SystemNative_Close(intptr_t fd)
{
return close(ToFileDescriptor(fd));
int result = close(ToFileDescriptor(fd));
if (result < 0 && errno == EINTR) result = 0; // on all supported platforms, close(2) returning EINTR still means it was released
return result;
}

intptr_t SystemNative_Dup(intptr_t oldfd)
Expand Down
Loading