Skip to content
Draft
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4fa0d88
Fix handling of `readdir` giving `EINTR`
hamarb123 Jul 7, 2025
0049bf3
Fix handling of `opendir` giving `EINTR`
hamarb123 Jul 7, 2025
a9793f8
Ensure handling of `fcntl` giving `EINTR` is consistent
hamarb123 Jul 7, 2025
ec72822
Ensure handling of `fsync` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
7e0a56d
Ensure handling of `chmod` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
d6a331a
Ensure handling of `ftruncate` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
aa891dd
Ensure handling of `flock` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
b159416
Ensure handling of `poll` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
143b964
Ensure handling of `waitpid` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
42f82c9
Ensure handling of `getpwuid` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
7516565
Ensure handling of `recvmsg` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
73d7e28
Ensure handling of `stat` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
7e013bf
Ensure handling of variants of `stat` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
085fd17
Ensure handling of `unlink` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
9776101
Ensure handling of `shm_unlink` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
651d928
Ensure handling of `pipe{2}` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
f4cb957
Ensure handling of `mkdir` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
1465bf9
Ensure handling of `chdir` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
f671ff1
Ensure handling of `mkfifo` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
e01584a
Ensure handling of `rename` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
33759b6
Ensure handling of `rmdir` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
ddec1a9
Ensure handling of `ioctl` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
8779bb6
Ensure handling of all variants of `statfs` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
36f241d
Ensure handling of `sendmsg` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
dfd3972
Ensure handling of `accept` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
a395f6e
Ensure handling of `connect` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
c791791
Ensure handling of `kevent` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
aa5f35c
Ensure handling of `dup2` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
400e7f6
Ensure handling of `remove` giving `EINTR` is consistent
hamarb123 Jul 8, 2025
d5024c5
Ensure handling of `lseek` & variants giving `EINTR` is consistent
hamarb123 Jul 18, 2025
143d9ce
Ensure handling of `open` & variants giving `EINTR` is consistent
hamarb123 Jul 18, 2025
3aa031f
Ensure we handle `EINTR` & partial operations more consistently for `…
hamarb123 Jul 30, 2025
8987634
Fix handling of `closedir` giving `EINTR`
hamarb123 Jul 30, 2025
e99a739
Ensure we handle EINTR & partial operations more consistently for pread
hamarb123 Oct 2, 2025
ae26757
Ensure we handle EINTR & partial operations more consistently for read
hamarb123 Oct 2, 2025
b6f7090
Merge remote-tracking branch 'upstream/main' into main28
hamarb123 Oct 3, 2025
6752334
Fix first set of build failures
hamarb123 Oct 3, 2025
23b6275
Fix build failures
hamarb123 Oct 3, 2025
70051f4
Fix build failures
hamarb123 Oct 3, 2025
ffc73d2
Fix build failures
hamarb123 Oct 3, 2025
67adb47
Fix build failures
hamarb123 Oct 3, 2025
85267d7
Merge remote-tracking branch 'upstream/main' into main28
hamarb123 Oct 7, 2025
8f0530e
Fix build errors
hamarb123 Oct 7, 2025
fa92a01
Merge branch 'main' into main28
hamarb123 Oct 7, 2025
7a0a208
Fix build error
hamarb123 Oct 7, 2025
7185b99
Fix compiler error
hamarb123 Oct 7, 2025
3f850e7
typo
hamarb123 Oct 7, 2025
7018912
Fix build errors
hamarb123 Oct 7, 2025
b2952f5
Remove unrelated whitespace changes VSC added
hamarb123 Oct 7, 2025
9d34503
Fix compile error
hamarb123 Oct 7, 2025
a130b68
Remove unrelated whitespace changes VSC added
hamarb123 Oct 7, 2025
80e4581
Fix compile error
hamarb123 Oct 7, 2025
0cb50d0
Merge branch 'main' into main28
hamarb123 Oct 7, 2025
f83da62
Fix compile error
hamarb123 Oct 7, 2025
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
18 changes: 14 additions & 4 deletions src/coreclr/debug/createdump/crashinfounix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ CrashInfo::CleanupAndResumeProcess()
if (ptrace(PTRACE_DETACH, thread->Tid(), nullptr, nullptr) != -1)
{
int waitStatus;
waitpid(thread->Tid(), &waitStatus, __WALL);
while (-1 == waitpid(thread->Tid(), &waitStatus, __WALL) && errno == EINTR);
}
}
if (m_fdMem != -1)
Expand Down Expand Up @@ -113,24 +113,34 @@ CrashInfo::EnumerateAndSuspendThreads()
return false;
}

DIR* taskDir = opendir(taskPath);
DIR* taskDir;
while ((taskDir = opendir(taskPath)) == nullptr && errno == EINTR);

if (taskDir == nullptr)
{
printf_error("Problem enumerating threads: opendir(%s) FAILED %s (%d)\n", taskPath, strerror(errno), errno);
return false;
}

struct dirent* entry;
while ((entry = readdir(taskDir)) != nullptr)
while (true)
{
do
{
errno = 0;
entry = readdir(taskDir);
}
while (entry == nullptr && errno == EINTR);
if (entry == nullptr) break;

pid_t tid = static_cast<pid_t>(strtol(entry->d_name, nullptr, 10));
if (tid != 0)
{
// Reference: http://stackoverflow.com/questions/18577956/how-to-use-ptrace-to-get-a-consistent-view-of-multiple-threads
if (ptrace(PTRACE_ATTACH, tid, nullptr, nullptr) != -1)
{
int waitStatus;
waitpid(tid, &waitStatus, __WALL);
while (-1 == waitpid(tid, &waitStatus, __WALL) && errno == EINTR);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/crashreportwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CrashReportWriter::WriteCrashReport(const std::string& dumpFileName)
printf_error("Writing the crash report file FAILED\n");

// Delete the partial json file on error
remove(crashReportFile.c_str());
while (-1 == remove(crashReportFile.c_str()) && errno == EINTR);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/createdumpunix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ CreateDump(const CreateDumpOptions& options)
printf_error("Writing dump FAILED\n");

// Delete the partial dump file on error
remove(dumpPath.c_str());
while (-1 == remove(dumpPath.c_str()) && errno == EINTR);
goto exit;
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/coreclr/debug/debug-pal/unix/twowaypipe.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include <errno.h>
#include <pal.h>
#include <unistd.h>
#include <fcntl.h>
Expand All @@ -22,19 +23,22 @@ bool TwoWayPipe::CreateServer(const ProcessDescriptor& pd)
PAL_GetTransportPipeName(m_inPipeName, pd.m_Pid, pd.m_ApplicationGroupId, "in");
PAL_GetTransportPipeName(m_outPipeName, pd.m_Pid, pd.m_ApplicationGroupId, "out");

unlink(m_inPipeName);
while (-1 == unlink(m_inPipeName) && errno == EINTR);

if (mkfifo(m_inPipeName, S_IRWXU) == -1)
int mkfifo_result;
while (-1 == (mkfifo_result = mkfifo(m_inPipeName, S_IRWXU)) && errno == EINTR);
if (mkfifo_result == -1)
{
return false;
}


unlink(m_outPipeName);
while (-1 == unlink(m_outPipeName) && errno == EINTR);

if (mkfifo(m_outPipeName, S_IRWXU) == -1)
while (-1 == (mkfifo_result = mkfifo(m_outPipeName, S_IRWXU)) && errno == EINTR);
if (mkfifo_result == -1)
{
unlink(m_inPipeName);
while (-1 == unlink(m_inPipeName) && errno == EINTR);
return false;
}

Expand Down Expand Up @@ -166,8 +170,8 @@ bool TwoWayPipe::Disconnect()

if (m_state == ServerConnected || m_state == Created)
{
unlink(m_inPipeName);
unlink(m_outPipeName);
while (-1 == unlink(m_inPipeName) && errno == EINTR);
while (-1 == unlink(m_outPipeName) && errno == EINTR);
}

m_state = NotInitialized;
Expand All @@ -178,6 +182,6 @@ bool TwoWayPipe::Disconnect()
// and semaphores when the debugger detects the debuggee process exited.
void TwoWayPipe::CleanupTargetProcess()
{
unlink(m_inPipeName);
unlink(m_outPipeName);
while (-1 == unlink(m_inPipeName) && errno == EINTR);
while (-1 == unlink(m_outPipeName) && errno == EINTR);
}
3 changes: 2 additions & 1 deletion src/coreclr/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class CGroup
#else

struct statfs stats;
int result = statfs("/sys/fs/cgroup", &stats);
int result;
while (-1 == (result = statfs("/sys/fs/cgroup", &stats)) && errno == EINTR);
if (result != 0)
return 0;

Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/gc/unix/numasupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ static int GetNodeNum(const char* path, bool firstOnly)
struct dirent *entry;
int result = -1;

dir = opendir(path);
while ((dir = opendir(path)) == nullptr && errno == EINTR);
if (dir)
{
while ((entry = readdir(dir)) != NULL)
while (true)
{
do
{
errno = 0;
entry = readdir(dir);
}
while (entry == nullptr && errno == EINTR);
if (entry == nullptr) break;

if (strncmp(entry->d_name, "node", STRING_LENGTH("node")))
continue;

Expand Down
22 changes: 18 additions & 4 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ namespace pal
{
// Check if the specified path exists
struct stat sb;
if (stat(file_path, &sb) == -1)
int result;
while (-1 == (result = stat(file_path, &sb)) && errno == EINTR);
if (result == -1)
{
perror(W("Path not found"));
return false;
Expand Down Expand Up @@ -470,7 +472,9 @@ namespace pal
return false;

struct stat buf;
if (fstat(fd, &buf) == -1)
int fstat_result;
while (-1 == (fstat_result = fstat(fd, &buf)) && errno == EINTR);
if (fstat_result == -1)
{
close(fd);
return false;
Expand Down Expand Up @@ -504,16 +508,26 @@ namespace pal
assert(ext != nullptr);
const size_t ext_len = pal::strlen(ext);

DIR* dir = opendir(directory.c_str());
DIR* dir;
while ((dir = opendir(directory.c_str())) == nullptr && errno == EINTR);

if (dir == nullptr)
return {};

stringstream_t file_list;

// For all entries in the directory
struct dirent* entry;
while ((entry = readdir(dir)) != nullptr)
while (true)
{
do
{
errno = 0;
entry = readdir(dir);
}
while (entry == nullptr && errno == EINTR);
if (entry == nullptr) break;

#if HAVE_DIRENT_D_TYPE
int dirEntryType = entry->d_type;
#else
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/ilasm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "clrversion.h"

#include "strsafe.h"
#include <errno.h>
#define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS((expr))

WCHAR* EqualOrColon(_In_ __nullterminated WCHAR* szArg)
Expand Down Expand Up @@ -844,7 +845,7 @@ extern "C" int _cdecl wmain(int argc, _In_ WCHAR **argv)
MAKE_UTF8PTR_FROMWIDE_NOTHROW(szOutputFilename, wzOutputFilename);
if (szOutputFilename != NULL)
{
remove(szOutputFilename);
while (-1 == remove(szOutputFilename) && errno == EINTR);
}
#endif
}
Expand Down
16 changes: 10 additions & 6 deletions src/coreclr/minipal/Unix/doublemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
char name[24];
sprintf(name, "/shm-dotnet-%d", getpid());
name[sizeof(name) - 1] = '\0';
shm_unlink(name);
while (-1 == shm_unlink(name) && errno == EINTR);
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
shm_unlink(name);
while (-1 == shm_unlink(name) && errno == EINTR);
}
#endif // !TARGET_ANDROID

Expand All @@ -82,7 +82,9 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
}
#endif

if (ftruncate(fd, MaxDoubleMappedSize) == -1)
int ftruncate_result;
while (-1 == (ftruncate_result = ftruncate(fd, MaxDoubleMappedSize)) && errno == EINTR);
if (ftruncate_result == -1)
{
close(fd);
return false;
Expand Down Expand Up @@ -381,16 +383,18 @@ TemplateThunkMappingData *InitializeTemplateThunkMappingData(void* pTemplate)
char name[24];
sprintf(name, "/shm-dotnet-template-%d", getpid());
name[sizeof(name) - 1] = '\0';
shm_unlink(name);
while (-1 == shm_unlink(name) && errno == EINTR);
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
shm_unlink(name);
while (-1 == shm_unlink(name) && errno == EINTR);
}
#endif // !TARGET_ANDROID
#endif
if (fd != -1)
{
off_t maxFileSize = MAX_TEMPLATE_THUNK_TYPES * 0x10000; // The largest page size we support currently is 64KB.
if (ftruncate(fd, maxFileSize) == -1) // Reserve a decent size chunk of logical memory for these things.
int ftruncate_result;
while (-1 == (ftruncate_result = ftruncate(fd, maxFileSize)) && errno == EINTR);
if (ftruncate_result == -1) // Reserve a decent size chunk of logical memory for these things.
{
close(fd);
}
Expand Down
13 changes: 9 additions & 4 deletions src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ CreateCrashDump(
int cbErrorMessageBuffer)
{
int pipe_descs[2];
if (pipe(pipe_descs) == -1)
int pipe_result;
while (-1 == (pipe_result = pipe(pipe_descs)) && errno == EINTR);
if (pipe_result == -1)
{
if (errorMessageBuffer != nullptr)
{
Expand Down Expand Up @@ -248,7 +250,7 @@ CreateCrashDump(
// Only dup the child's stderr if there is error buffer
if (errorMessageBuffer != nullptr)
{
dup2(child_pipe, STDERR_FILENO);
while (-1 == dup2(child_pipe, STDERR_FILENO) && errno == EINTR);
}
// Execute the createdump program
if (execv(argv[0], (char* const *)argv) == -1)
Expand Down Expand Up @@ -292,7 +294,8 @@ CreateCrashDump(

// Parent waits until the child process is done
int wstatus = 0;
int result = waitpid(childpid, &wstatus, 0);
int result;
while (-1 == (result = waitpid(childpid, &wstatus, 0)) && errno == EINTR);
if (result != childpid)
{
fprintf(stderr, "Problem waiting for createdump: waitpid() FAILED result %d wstatus %08x errno %s (%d)\n",
Expand Down Expand Up @@ -571,7 +574,9 @@ PalCreateDumpInitialize()
strncat(program, DumpGeneratorName, programLen);

struct stat fileData;
if (stat(program, &fileData) == -1 || !S_ISREG(fileData.st_mode))
int stat_result;
while (-1 == (stat_result = stat(program, &fileData)) && errno == EINTR);
if (stat_result == -1 || !S_ISREG(fileData.st_mode))
{
fprintf(stderr, "DOTNET_DbgEnableMiniDump is set and the createdump binary does not exist: %s\n", program);
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class CGroup
#else

struct statfs stats;
int result = statfs("/sys/fs/cgroup", &stats);
int result;
while (-1 == (result = statfs("/sys/fs/cgroup", &stats)) && errno == EINTR);
if (result != 0)
return 0;

Expand Down
14 changes: 10 additions & 4 deletions src/coreclr/pal/src/file/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ RemoveDirectoryHelper (
{
struct stat stat_data;

if ( stat( lpPathName, &stat_data) == 0 &&
int stat_result;
while (-1 == (stat_result = stat( lpPathName, &stat_data)) && stat_result == EINTR);
if ( stat_result == 0 &&
(stat_data.st_mode & S_IFMT) == S_IFREG )
{
/* Not a directory, it is a file. */
Expand Down Expand Up @@ -455,7 +457,9 @@ CreateDirectoryA(
// Canonicalize the path so we can determine its length.
FILECanonicalizePath(realPathBuf);

if ( mkdir(realPathBuf, mode) != 0 )
int mkdir_result;
while (-1 == (mkdir_result = mkdir(realPathBuf, mode)) && errno == EINTR);
if ( mkdir_result != 0 )
{
TRACE("Creation of directory [%s] was unsuccessful, errno = %d.\n",
unixPathName, errno);
Expand Down Expand Up @@ -522,7 +526,7 @@ SetCurrentDirectoryA(
}

TRACE("Attempting to open Unix dir [%s]\n", lpPathName);
result = chdir(lpPathName);
while (-1 == (result = chdir (lpPathName)) && errno == EINTR);

if ( result == 0 )
{
Expand All @@ -534,7 +538,9 @@ SetCurrentDirectoryA(
{
struct stat stat_data;

if ( stat( lpPathName, &stat_data) == 0 &&
int stat_result;
while (-1 == (stat_result = stat( lpPathName, &stat_data)) && errno == EINTR);
if ( stat_result == 0 &&
(stat_data.st_mode & S_IFMT) == S_IFREG )
{
/* Not a directory, it is a file. */
Expand Down
Loading
Loading