Skip to content

Commit e20f9b3

Browse files
committed
um: add mmap/mremap OS calls
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 <[email protected]>
1 parent 5cde609 commit e20f9b3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

arch/um/include/shared/os.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ extern int os_eventfd(unsigned int initval, int flags);
181181
extern int os_sendmsg_fds(int fd, const void *buf, unsigned int len,
182182
const int *fds, unsigned int fds_num);
183183
int os_poll(unsigned int n, const int *fds);
184+
void *os_mmap_rw_shared(int fd, size_t size);
185+
void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size);
184186

185187
/* start_up.c */
186188
extern void os_early_checks(void);

arch/um/os-Linux/file.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <sys/stat.h>
1818
#include <sys/sysmacros.h>
1919
#include <sys/un.h>
20+
#include <sys/mman.h>
2021
#include <sys/types.h>
2122
#include <sys/eventfd.h>
2223
#include <poll.h>
@@ -718,3 +719,25 @@ int os_poll(unsigned int n, const int *fds)
718719

719720
return -EIO;
720721
}
722+
723+
void *os_mmap_rw_shared(int fd, size_t size)
724+
{
725+
void *res = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
726+
727+
if (res == MAP_FAILED)
728+
return NULL;
729+
730+
return res;
731+
}
732+
733+
void *os_mremap_rw_shared(void *old_addr, size_t old_size, size_t new_size)
734+
{
735+
void *res;
736+
737+
res = mremap(old_addr, old_size, new_size, MREMAP_MAYMOVE, NULL);
738+
739+
if (res == MAP_FAILED)
740+
return NULL;
741+
742+
return res;
743+
}

0 commit comments

Comments
 (0)