mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibCore: Don’t pass O_CLOEXEC to shm_open
Bug: Ladybird crashes on launch on macOS 26.4+ with “UNEXPECTED ERROR: close: Bad file descriptor” in SharedVersion.cpp — because AnonymousBuffer creation fails. Cause: anon_create() passed O_CLOEXEC in the oflag argument to shm_open. macOS 26.4+ rejects that with EINVAL. POSIX only specifies O_RDONLY, O_RDWR, O_CREAT, O_EXCL, and O_TRUNC as valid shm_open flags; on earlier macOS versions, O_CLOEXEC just happened to also be silently accepted. Fix: Filter O_CLOEXEC from the oflag argument we pass to shm_open flags, and instead set FD_CLOEXEC via fcntl — after opening.
This commit is contained in:
committed by
Luke Wilde
parent
201e615aad
commit
d7053a8eb8
Notes:
github-actions[bot]
2026-03-31 16:22:31 +00:00
Author: https://github.com/sideshowbarker Commit: https://github.com/LadybirdBrowser/ladybird/commit/d7053a8eb87 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8614 Reviewed-by: https://github.com/Lubrsi ✅ Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/trflynn89
@@ -155,13 +155,24 @@ ErrorOr<int> anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int opti
|
||||
static size_t shared_memory_id = 0;
|
||||
|
||||
auto name = ByteString::formatted("/shm-{}-{}", getpid(), shared_memory_id++);
|
||||
fd = shm_open(name.characters(), O_RDWR | O_CREAT | options, 0600);
|
||||
// Passing O_CLOEXEC to shm_open in the oflag argument isn't POSIX-compliant and is known to be rejected
|
||||
// in macOS 26.4+. So we filter it out here, and instead set FD_CLOEXEC via fcntl after opening.
|
||||
fd = shm_open(name.characters(), O_RDWR | O_CREAT | (options & ~O_CLOEXEC), 0600);
|
||||
|
||||
if (shm_unlink(name.characters()) == -1) {
|
||||
auto saved_errno = errno;
|
||||
TRY(close(fd));
|
||||
if (fd >= 0)
|
||||
TRY(close(fd));
|
||||
return Error::from_errno(saved_errno);
|
||||
}
|
||||
|
||||
if (fd >= 0 && (options & O_CLOEXEC)) {
|
||||
if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
||||
auto saved_errno = errno;
|
||||
TRY(close(fd));
|
||||
return Error::from_errno(saved_errno);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (fd < 0)
|
||||
return Error::from_errno(errno);
|
||||
|
||||
Reference in New Issue
Block a user