1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

LibCore: Use SHM_ANON for anon_create() when available

On FreeBSD and GNU/Hurd, SHM_ANON is a nice way to create anonymous
files using the usual shm_open() API. This is a lot like the fallback
shm_open() branch that follows, except we don't have to fool around
with choosing a unique name (with retrying) and unlinking the file
afterwards; it just does the right thing. Isn't this nice?
This commit is contained in:
Sergey Bugaev 2023-09-03 22:34:26 +03:00 committed by Andrew Kaster
parent ec68979483
commit cee38cf1e5

View file

@ -479,6 +479,15 @@ ErrorOr<int> anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int opti
TRY(close(fd));
return Error::from_errno(saved_errno);
}
#elif defined(SHM_ANON)
fd = shm_open(SHM_ANON, O_RDWR | O_CREAT | options, 0600);
if (fd < 0)
return Error::from_errno(errno);
if (::ftruncate(fd, size) < 0) {
auto saved_errno = errno;
TRY(close(fd));
return Error::from_errno(saved_errno);
}
#elif defined(AK_OS_BSD_GENERIC) || defined(AK_OS_EMSCRIPTEN)
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);