]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
um: add mmap/mremap OS calls
authorJohannes Berg <johannes.berg@intel.com>
Tue, 2 Jul 2024 17:21:20 +0000 (19:21 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 3 Jul 2024 10:24:48 +0000 (12:24 +0200)
For the upcoming shared-memory time-travel external
optimisations, we need to be able to mmap/mremap.
Add the necessary OS calls.

Link: https://patch.msgid.link/20240702192118.ca4472963638.Ic2da1d3a983fe57340c1b693badfa9c5bd2d8c61@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
arch/um/include/shared/os.h
arch/um/os-Linux/file.c

index fc4091c127c89fa7c0d1c22a4a80cf12bf92f30a..d269637adcd67a7c5b1be558c846b7b0cd9467d3 100644 (file)
@@ -181,6 +181,8 @@ extern int os_eventfd(unsigned int initval, int flags);
 extern int os_sendmsg_fds(int fd, const void *buf, unsigned int len,
                          const int *fds, unsigned int fds_num);
 int os_poll(unsigned int n, const int *fds);
+void *os_mmap_rw_shared(int fd, size_t size);
+void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size);
 
 /* start_up.c */
 extern void os_early_checks(void);
index 6d3c7391094624830300003c4751dc2849defc4b..5adf8f630049ec147c3e6dec19f47517681d3a52 100644 (file)
@@ -17,6 +17,7 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 #include <sys/un.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/eventfd.h>
 #include <poll.h>
@@ -718,3 +719,25 @@ int os_poll(unsigned int n, const int *fds)
 
        return -EIO;
 }
+
+void *os_mmap_rw_shared(int fd, size_t size)
+{
+       void *res = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+       if (res == MAP_FAILED)
+               return NULL;
+
+       return res;
+}
+
+void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size)
+{
+       void *res;
+
+       res = mremap(old_addr, old_size, new_size, MREMAP_MAYMOVE, NULL);
+
+       if (res == MAP_FAILED)
+               return NULL;
+
+       return res;
+}