about summary refs log tree commit diff
path: root/rt
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-01-30 15:52:16 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-02-01 23:36:11 +0100
commita979b72747e34add3433a23c0966490cd809120f (patch)
tree45d4888dc9ee62a8d851dc27b435516f827718b5 /rt
parent65392c84782a53b0d7705ca0207c95c3da41c7dc (diff)
downloadglibc-a979b72747e34add3433a23c0966490cd809120f.tar.gz
glibc-a979b72747e34add3433a23c0966490cd809120f.tar.xz
glibc-a979b72747e34add3433a23c0966490cd809120f.zip
hurd: Implement SHM_ANON
This adds a special SHM_ANON value that can be passed into shm_open ()
in place of a name. When called in this way, shm_open () will create a
new anonymous shared memory file. The file will be created in the same
way that other shared memory files are created (i.e., under /dev/shm/),
except that it is not given a name and therefore cannot be reached from
the file system, nor by other calls to shm_open (). This is accomplished
by utilizing O_TMPFILE.

This is intended to be compatible with FreeBSD's API of the same name.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230130125216.6254-4-bugaevc@gmail.com>
Diffstat (limited to 'rt')
-rw-r--r--rt/shm_open.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/rt/shm_open.c b/rt/shm_open.c
index 48970bbc81..6c1f4d604f 100644
--- a/rt/shm_open.c
+++ b/rt/shm_open.c
@@ -23,6 +23,7 @@
 #include <shlib-compat.h>
 #include <shm-directory.h>
 #include <unistd.h>
+#include <sys/mman.h>
 
 /* Open shared memory object.  */
 int
@@ -36,6 +37,10 @@ __shm_open (const char *name, int oflag, mode_t mode)
     }
 
   oflag |= O_NOFOLLOW | O_CLOEXEC;
+#if defined (SHM_ANON) && defined (O_TMPFILE)
+  if (name == SHM_ANON)
+    oflag |= O_TMPFILE;
+#endif
 
   int fd = __open64_nocancel (dirname.name, oflag, mode);
   if (fd == -1 && __glibc_unlikely (errno == EISDIR))